| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package controller
- import (
- "github.com/kataras/iris/v12/mvc"
- "xps/pkg/system/datamodel"
- "xps/pkg/system/service"
- )
- type GroupController struct {
- Base
- Service service.GroupService
- }
- func (c *GroupController) BeforeActivation(b mvc.BeforeActivation) {
- b.Handle("GET", "/", "GetList" )
- b.Handle("GET", "/{groupId:int64}", "GetById" )
- b.Handle("GET", "/view", "GetTreeView" )
- b.Handle("POST", "/add", "Create" )
- b.Handle("PUT", "/update", "Update" )
- b.Handle("DELETE", "/{groupId:int64}", "DeleteById" )
- }
- func (c *GroupController) GetList() *JsonResult {
- ocId := c.GetCurOcId()
- params := c.buildParams()
- params["ocId"] = ocId
- data, err := c.Service.GetList(params)
- if err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("获取成功", data)
- }
- }
- func (c *GroupController) GetTreeView() *JsonResult {
- ocId := c.GetCurOcId()
- data, err := c.Service.GetTreeView(ocId)
- if err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("获取成功", data)
- }
- }
- func (c *GroupController) GetById(groupId int64) *JsonResult {
- ocId := c.GetCurOcId()
- data, err := c.Service.GetById(ocId, groupId)
- if err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("获取成功", data)
- }
- }
- func (c *GroupController) Create() *JsonResult {
- ocId := c.GetCurOcId()
- userId := c.GetCurUserId()
- group := datamodel.Group{}
- if err := c.Ctx.ReadJSON(&group); err != nil {
- return ResultErr("读取数据失败", nil)
- }
- group.OcId = ocId
- group.CreatedBy = userId
- if err := c.Service.Create(&group); err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("新增成功", nil)
- }
- }
- func (c *GroupController) Update() *JsonResult {
- ocId := c.GetCurOcId()
- userId := c.GetCurUserId()
- group := datamodel.Group{}
- if err := c.Ctx.ReadJSON(&group); err != nil {
- return ResultErr("读取数据失败", nil)
- }
- group.OcId = ocId
- group.UpdatedBy = userId
- if err := c.Service.Update(&group); err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("更新成功", nil)
- }
- }
- func (c *GroupController) DeleteById(groupId int64) *JsonResult {
- ocId := c.GetCurOcId()
- userId := c.GetCurUserId()
- m := make(map[string]interface{})
- m["ocId"] = ocId
- m["groupId"] = groupId
- m["deletedBy"] = userId
- if err := c.Service.Delete(m); err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("删除成功", nil)
- }
- }
|