| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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", "GetPage" )
- 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) GetPage() *JsonResult {
- params := c.buildParams()
- data, err := c.Service.GetPage(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()
-
- 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)
- }
- }
|