Browse Source

系统参数

urbanu 1 month ago
parent
commit
dc40d870e2
1 changed files with 40 additions and 2 deletions
  1. 40 2
      service/daytask/dt_system.go

+ 40 - 2
service/daytask/dt_system.go

@@ -257,7 +257,6 @@ func (s *DtConfigService) Find(c *gin.Context) {
 	if req.Status != nil {
 		db = db.Where("status", req.Status)
 	}
-	db = db.Order("`group` ASC, sort ASC")
 
 	colInfo := s.GetColumnCommentFromStruct(model.DtConfig{})
 	resp, err := base.NewQueryBaseHandler(model.NewDtConfig()).List(db, req)
@@ -279,7 +278,46 @@ func (s *DtConfigService) Create(c *gin.Context) {
 
 func (s *DtConfigService) Update(c *gin.Context) {
 	s.SetDbAlias("daytask")
-	base.NewBaseHandler(model.NewDtConfig()).UpdateOne(c, s.DB())
+	var req model.DtConfig
+	if err := c.ShouldBindJSON(&req); err != nil {
+		response.Resp(c, err.Error())
+		return
+	}
+	if req.Id == 0 {
+		response.Resp(c, "id is zero")
+		return
+	}
+	var existing model.DtConfig
+	if err := s.DB().First(&existing, req.Id).Error; err != nil {
+		response.Resp(c, err.Error())
+		return
+	}
+	dbEx := s.DB().Model(&existing).Updates(map[string]interface{}{
+		"group":       req.Group,
+		"key":         req.Key,
+		"value":       req.Value,
+		"type":        req.Type,
+		"name":        req.Name,
+		"description": req.Description,
+		"status":      req.Status,
+		"sort":        req.Sort,
+	})
+	if dbEx.Error != nil {
+		response.Resp(c, dbEx.Error.Error())
+		return
+	}
+	if dbEx.RowsAffected == 0 {
+		response.Resp(c, "update fail")
+		return
+	}
+	if err := s.DB().First(&existing, req.Id).Error; err != nil {
+		response.Resp(c, err.Error())
+		return
+	}
+	response.Resp(c, map[string]any{
+		"info":         existing,
+		"rowsAffected": dbEx.RowsAffected,
+	})
 }
 
 func (s *DtConfigService) Delete(c *gin.Context) {