Browse Source

system: 部门新增bug问题

Yi 11 months ago
parent
commit
74f381daed
2 changed files with 9 additions and 2 deletions
  1. 1 2
      http/handler/system/dept.go
  2. 8 0
      module/backend/system_service.go

+ 1 - 2
http/handler/system/dept.go

@@ -59,10 +59,9 @@ func DepIsShow(c *gin.Context) {
 func DepCreateOrUpdate(c *gin.Context) {
 	var req pasturePb.SearchDeptRequest
 	if err := ginutil.BindProto(c, &req); err != nil {
-		apierr.AbortBadRequest(c, http.StatusOK, err)
+		apierr.ClassifiedAbort(c, err)
 		return
 	}
-
 	if err := middleware.Dependency(c).StoreEventHub.OpsService.SystemDeptCreateOrUpdate(c, &req); err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return

+ 8 - 0
module/backend/system_service.go

@@ -627,6 +627,14 @@ func (s *StoreEntry) SystemDepDelete(ctx context.Context, id int64) error {
 }
 
 func (s *StoreEntry) SystemDeptCreateOrUpdate(ctx context.Context, req *pasturePb.SearchDeptRequest) error {
+	if req.Id > 0 {
+		barn := &model.SystemDept{Id: int64(req.Id)}
+		if err := s.DB.Model(&model.SystemDept{}).First(barn).Error; err != nil {
+			if !errors.Is(err, gorm.ErrRecordNotFound) {
+				return xerr.WithStack(err)
+			}
+		}
+	}
 	if err := s.DB.Model(&model.SystemDept{}).Where(map[string]interface{}{
 		"id": req.Id,
 	}).Assign(map[string]interface{}{