96 lines
3.1 KiB
Go
96 lines
3.1 KiB
Go
|
|
package api
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"easyvqd/internal/core/vqd"
|
|||
|
|
"fmt"
|
|||
|
|
"git.lnton.com/lnton/pkg/reason"
|
|||
|
|
"github.com/gin-gonic/gin"
|
|||
|
|
"strconv"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
func (a VqdTaskAPI) findVqdTimeTemplate(c *gin.Context, in *vqd.FindVqdTimeTemplateInput) (any, error) {
|
|||
|
|
items, total, err := a.core.FindVqdTimeTemplate(c.Request.Context(), in)
|
|||
|
|
rows := make([]map[string]interface{}, 0)
|
|||
|
|
|
|||
|
|
for _, item := range items {
|
|||
|
|
//row := structs.Map(item)
|
|||
|
|
row := make(map[string]interface{})
|
|||
|
|
row["id"] = item.ID
|
|||
|
|
row["name"] = item.Name
|
|||
|
|
row["des"] = item.Des
|
|||
|
|
row["plans"] = item.Plans
|
|||
|
|
row["enable"] = item.Enable
|
|||
|
|
row["is_default"] = item.IsDefault
|
|||
|
|
row["created_at"] = item.CreatedAt
|
|||
|
|
row["updated_at"] = item.UpdatedAt
|
|||
|
|
|
|||
|
|
rows = append(rows, row)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return gin.H{"items": rows, "total": total}, err
|
|||
|
|
}
|
|||
|
|
func (a VqdTaskAPI) getVqdTimeTemplate(c *gin.Context, _ *struct{}) (any, error) {
|
|||
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
|||
|
|
item, err := a.core.GetVqdTimeTemplate(c.Request.Context(), ID)
|
|||
|
|
if err != nil {
|
|||
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find vqdcms [%d] err [%s]`, ID, err.Error()))
|
|||
|
|
}
|
|||
|
|
row := make(map[string]interface{})
|
|||
|
|
|
|||
|
|
row["id"] = item.ID
|
|||
|
|
row["name"] = item.Name
|
|||
|
|
row["is_default"] = item.IsDefault
|
|||
|
|
row["des"] = item.Des
|
|||
|
|
row["plans"] = item.Plans
|
|||
|
|
row["enable"] = item.Enable
|
|||
|
|
row["created_at"] = item.CreatedAt
|
|||
|
|
row["updated_at"] = item.UpdatedAt
|
|||
|
|
|
|||
|
|
return gin.H{"data": row}, err
|
|||
|
|
}
|
|||
|
|
func (a VqdTaskAPI) addVqdTimeTemplate(c *gin.Context, in *vqd.AddVqdTimeTemplateInput) (any, error) {
|
|||
|
|
_, err := a.core.AddVqdTimeTemplate(c.Request.Context(), in)
|
|||
|
|
if err != nil {
|
|||
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`add vqdcms err [%s]`, err.Error()))
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return gin.H{"data": "OK!"}, err
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (a VqdTaskAPI) editVqdTimeTemplate(c *gin.Context, in *vqd.EditVqdTimeTemplateInput) (any, error) {
|
|||
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
|||
|
|
_, err := a.core.GetVqdTimeTemplate(c.Request.Context(), ID)
|
|||
|
|
if err != nil {
|
|||
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find vqdcms [%d] err [%s]`, ID, err.Error()))
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_, err = a.core.EditVqdTimeTemplate(c.Request.Context(), in, ID)
|
|||
|
|
if err != nil {
|
|||
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`edit vqdcms err [%s]`, err.Error()))
|
|||
|
|
}
|
|||
|
|
return gin.H{"data": "OK!"}, err
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (a VqdTaskAPI) delVqdTimeTemplate(c *gin.Context, _ *struct{}) (any, error) {
|
|||
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
|||
|
|
info, err := a.core.GetVqdTimeTemplate(c.Request.Context(), ID)
|
|||
|
|
if err != nil {
|
|||
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find vqdcms [%d] err [%s]`, ID, err.Error()))
|
|||
|
|
}
|
|||
|
|
if info.IsDefault {
|
|||
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`默认模板不支持删除 [%s] `, info.Name))
|
|||
|
|
}
|
|||
|
|
//templateInfo, err := a.core.FindVqdTimeTemplateID(c.Request.Context(), ID)
|
|||
|
|
//if err == nil {
|
|||
|
|
// if templateInfo != nil {
|
|||
|
|
// return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`模板关联【%s】任务,需先清理【%s】任务后才能删除模板!`, templateInfo.Name, templateInfo.Name))
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
_, err = a.core.DelVqdTimeTemplate(c.Request.Context(), ID)
|
|||
|
|
if err != nil {
|
|||
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`del vqdcms [%d] err [%s]`, ID, err.Error()))
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return gin.H{"data": "OK!"}, err
|
|||
|
|
}
|