package controller import ( "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "project_management/app/e" "project_management/app/model" "project_management/app/services" ) var ApplyCap services.ApplyCap = &model.ApplyCap{} // ApplyAddCap 添加应用能力 func ApplyAddCap(c *gin.Context) { var applyCap model.ApplyCapabilities if err := c.ShouldBindJSON(&applyCap); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } validate := validator.New() if err := validate.Struct(applyCap); err != nil { e.ResponseWithMsg(c, e.ERROR, "请检查必填项") return } addCap := ApplyCap.ApplyAddCap(applyCap) if addCap != e.SUCCESS { e.ResponseWithMsg(c, addCap, addCap.GetMsg()) return } e.ResponseSuccess(c, nil) } // GetApplyCapList 获取应用能力列表 func GetApplyCapList(c *gin.Context) { appid := c.Query("appid") validate := validator.New() err := validate.Var(appid, "required") if err != nil { e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg()) return } applycap, err := ApplyCap.ApplyCapList(appid) if err != nil { e.ResponseWithMsg(c, e.SUCCESS, err.Error()) return } e.ResponseSuccess(c, applycap) } // UpDateApplyCap 更新应用能力 func UpDateApplyCap(c *gin.Context) { var applyCap model.ApplyCap if err := c.ShouldBindJSON(&applyCap); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } validate := validator.New() if err := validate.Struct(applyCap); err != nil { e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg()) return } dateApplyCap := ApplyCap.UpDateApplyCap(applyCap) if dateApplyCap != e.SUCCESS { e.ResponseWithMsg(c, dateApplyCap, dateApplyCap.GetMsg()) return } e.ResponseSuccess(c, nil) } // UpDateApplyCapSort 拖拽排序 func UpDateApplyCapSort(c *gin.Context) { var applyCap model.ApplyCap if err := c.ShouldBindJSON(&applyCap); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } validate := validator.New() if err := validate.Struct(applyCap); err != nil { e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg()) return } dateApplyCap := ApplyCap.UpdateApplyCapSort(applyCap) if dateApplyCap != e.SUCCESS { e.ResponseWithMsg(c, dateApplyCap, dateApplyCap.GetMsg()) return } e.ResponseSuccess(c, nil) } // DeleteApplyCap 删除应用能力 func DeleteApplyCap(c *gin.Context) { var applyCap model.ApplyCapabilities if err := c.ShouldBindJSON(&applyCap); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } validate := validator.New() if err := validate.Struct(applyCap); err != nil { e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg()) return } dateApplyCap := ApplyCap.DeleteApplyCAp(applyCap) if dateApplyCap != e.SUCCESS { e.ResponseWithMsg(c, dateApplyCap, dateApplyCap.GetMsg()) return } e.ResponseSuccess(c, nil) } // GetCapDetailByCapID 根据capID获取应用能力详情 func GetCapDetailByCapID(c *gin.Context) { capid := c.Query("capid") validate := validator.New() err := validate.Var(capid, "required") if err != nil { e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg()) return } id, rescode := Capabilities.GetCapabilitiesById(capid) if rescode != e.SUCCESS { e.ResponseWithMsg(c, rescode, rescode.GetMsg()) return } e.ResponseSuccess(c, id) }