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