2026-01-23 18:05:36 +08:00
|
|
|
|
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) {
|
2026-01-27 10:42:21 +08:00
|
|
|
|
plan, err := a.core.AddVqdTimeTemplate(c.Request.Context(), in)
|
2026-01-23 18:05:36 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`add vqdcms err [%s]`, err.Error()))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-27 10:42:21 +08:00
|
|
|
|
out, _, err := a.core.FindVqdPlanID(c.Request.Context(), plan.ID)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find plan all err [%s]`, err.Error()))
|
|
|
|
|
|
}
|
|
|
|
|
|
for _, task := range out {
|
|
|
|
|
|
err = a.vqdSdkCore.UpdateTaskVqd(task.ID)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-23 18:05:36 +08:00
|
|
|
|
return gin.H{"data": "OK!"}, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a VqdTaskAPI) editVqdTimeTemplate(c *gin.Context, in *vqd.EditVqdTimeTemplateInput) (any, error) {
|
|
|
|
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
2026-01-27 10:42:21 +08:00
|
|
|
|
plan, err := a.core.GetVqdTimeTemplate(c.Request.Context(), ID)
|
2026-01-23 18:05:36 +08:00
|
|
|
|
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()))
|
|
|
|
|
|
}
|
2026-01-27 10:42:21 +08:00
|
|
|
|
out, _, err := a.core.FindVqdPlanID(c.Request.Context(), plan.ID)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find plan all err [%s]`, err.Error()))
|
|
|
|
|
|
}
|
|
|
|
|
|
for _, task := range out {
|
|
|
|
|
|
err = a.vqdSdkCore.UpdateTaskVqd(task.ID)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-23 18:05:36 +08:00
|
|
|
|
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 {
|
2026-01-27 10:42:21 +08:00
|
|
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`计划模板不支持删除 [%s] `, info.Name))
|
|
|
|
|
|
}
|
|
|
|
|
|
planInfo, err := a.core.FindVqdTaskPlanID(c.Request.Context(), ID)
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
if planInfo != nil {
|
|
|
|
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`计划关联【%s】任务,需先清理【%s】任务后才能删除模板!`, planInfo.Name, planInfo.Name))
|
|
|
|
|
|
}
|
2026-01-23 18:05:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
_, 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
|
|
|
|
|
|
}
|