|
@@ -0,0 +1,114 @@
|
|
|
+package controller
|
|
|
+
|
|
|
+import (
|
|
|
+ "Panel_development/app/e"
|
|
|
+ "Panel_development/app/model"
|
|
|
+ "Panel_development/app/service"
|
|
|
+ "Panel_development/unity"
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
+ "github.com/go-playground/validator/v10"
|
|
|
+ "strconv"
|
|
|
+)
|
|
|
+
|
|
|
+var ComponentList service.ComponentList = &model.ComponentList{}
|
|
|
+
|
|
|
+// GetComponentList 根据ID获取组件列表
|
|
|
+func GetComponentList(c *gin.Context) {
|
|
|
+ value := c.Query("id")
|
|
|
+ s := c.Query("id")
|
|
|
+ validate := validator.New()
|
|
|
+ err := validate.Var(s, "required,numeric")
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, "id不能为空")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ atoi, _ := strconv.Atoi(value)
|
|
|
+ id, err := unity.GetById(atoi, model.ComponentList{})
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, "获取失败当前数据不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.ResponseSuccess(c, id)
|
|
|
+}
|
|
|
+
|
|
|
+// ComponentListAll 获取组件列表
|
|
|
+func ComponentListAll(c *gin.Context) {
|
|
|
+ var page unity.QueryPageParams
|
|
|
+ if err := c.ShouldBindJSON(&page); err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 查询条件:查询name
|
|
|
+ queryCond := "name like ?"
|
|
|
+ page.Query = "%" + page.Query + "%"
|
|
|
+ result, total, err := unity.PaginateWithCondition(page, model.ComponentList{}, queryCond)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.ResPonsePage(c, result, total, page)
|
|
|
+}
|
|
|
+
|
|
|
+// AddComponentList 添加组件列表
|
|
|
+func AddComponentList(c *gin.Context) {
|
|
|
+ var componentList model.ComponentList
|
|
|
+ if err := c.ShouldBindJSON(&componentList); err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err := validator.New().Struct(&componentList)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ add, err := unity.Add(&componentList)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.ResponseSuccess(c, add)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// UpdateComponentList 根据ID更新组件列表
|
|
|
+func UpdateComponentList(c *gin.Context) {
|
|
|
+ var componentList model.ComponentList
|
|
|
+ s := c.Query("id")
|
|
|
+ err := c.ShouldBindJSON(&componentList)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ validate := validator.New()
|
|
|
+ err = validate.Var(s, "required,numeric")
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, "id不能为空")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ atoi, _ := strconv.Atoi(s)
|
|
|
+ componentList, err = unity.UpdateById(atoi, componentList)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.ResponseSuccess(c, componentList)
|
|
|
+}
|
|
|
+
|
|
|
+// DeleteComponentList 根据ID删除组件列表
|
|
|
+func DeleteComponentList(c *gin.Context) {
|
|
|
+ s := c.Query("id")
|
|
|
+ validate := validator.New()
|
|
|
+ err := validate.Var(s, "required,numeric")
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, "id不能为空")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ atoi, _ := strconv.Atoi(s)
|
|
|
+ _, err = unity.DeleteById(atoi, model.ComponentList{})
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.DELETEFAIL, e.DELETEFAIL.GetMsg())
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ e.ResponseSuccess(c, nil)
|
|
|
+ }
|
|
|
+}
|