package controllers import ( "github.com/kataras/iris/v12/mvc" "xps/service/system" "xps/viewmodels" ) type UserController struct { Base Service system.UserService } func (c *UserController) BeforeActivation(b mvc.BeforeActivation) { b.Handle("GET", "/page", "GetByPage") b.Handle("GET", "/{groupId:int64}/{accountId:int64}", "GetById") b.Handle("POST", "/add", "Create") b.Handle("PUT", "/update", "Update") b.Handle("DELETE", "/{accountId:int64}", "DeleteById") } func (c *UserController) 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 *UserController) GetById(groupId, accountId int64) *JsonResult { ocId := c.GetCurOcId() data, err := c.Service.GetById(ocId, groupId, accountId) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("获取成功", data) } } func (c *UserController) Create() *JsonResult { ocId := c.GetCurOcId() ocTypeId := c.GetOcTypeId() user := &viewmodels.UserInfo{} err := c.Ctx.ReadJSON(user) if err != nil { return ResultErr("读取数据失败", nil) } user.OcId = ocId err = c.Service.Create(ocTypeId, user) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("新增成功", nil) } } func (c *UserController) Update() *JsonResult { user := &viewmodels.UserInfo{} err := c.Ctx.ReadJSON(user) if err != nil { return ResultErr("读取数据失败", nil) } err = c.Service.Update(user) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("更新成功", nil) } } func (c *UserController) DeleteById(accountId int64) *JsonResult { ocId := c.GetCurOcId() userId := c.GetCurUserId() var m = make(map[string]interface{}) m["ocId"] = ocId m["accountId"] = accountId m["deletedBy"] = userId err := c.Service.Delete(m) if err != nil { return ResultErr(err.Error(), nil) } else { return ResultOk("删除成功", nil) } }