package controllers import ( "github.com/kataras/iris/v12/mvc" "xps/datamodels" "xps/service/system" ) type AppCatController struct { Base Service system.AppCatService } func (c *AppCatController) BeforeActivation(b mvc.BeforeActivation) { b.Handle("GET", "/", "GetByList") b.Handle("GET", "/page", "GetByPage") b.Handle("GET", "/{appCatId:int64}", "GetById") b.Handle("POST", "/add", "Create") b.Handle("PUT", "/update", "Update") b.Handle("DELETE", "/{appCatId:int64}", "DeleteByID") } func (c *AppCatController) GetByList() *JsonResult { params := c.buildParams() data, err := c.Service.GetByList(params) if err != nil { return ResultErr(err.Error(), nil) } return ResultOk("获取成功", data) } func (c *AppCatController) GetByPage() *JsonResult { params := c.buildParams() data, err := c.Service.GetByPage(params) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("获取成功", data) } } func (c *AppCatController) GetById(appCatId int64) *JsonResult { ocId := c.GetCurOcId() data, err := c.Service.GetById(ocId, appCatId) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("获取成功", data) } } func (c *AppCatController) Create() *JsonResult { userId := c.GetCurUserId() appCat := datamodels.AppCat{} appCat.CreatedBy = userId err := c.Ctx.ReadJSON(&appCat) if err != nil { return ResultErr("读取数据失败", nil) } err = c.Service.Create(&appCat) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("新增成功", nil) } } func (c *AppCatController) Update() *JsonResult { userId := c.GetCurUserId() appCat := datamodels.AppCat{} if err := c.Ctx.ReadJSON(&appCat); err != nil { return ResultErr("读取数据失败", nil) } appCat.UpdatedBy = userId err := c.Service.Update(&appCat) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("更新成功", nil) } } func (c *AppCatController) DeleteByID(appCatId int64) *JsonResult { ocId := c.GetCurOcId() userId := c.GetCurUserId() var m = make(map[string]interface{}) m["ocId"] = ocId m["appCatId"]= appCatId m["deletedBy"] = userId err := c.Service.Delete(m) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("删除成功", nil) } }