123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/services"
- "eta/eta_api/utils"
- )
- // ChartPermissionController 品种列表
- type ChartPermissionController struct {
- BaseAuthController
- }
- // List
- // @Title 品种列表
- // @Description 品种列表
- // @Param Keyword query string false "关键词"
- // @Success 200 Ret=200 操作成功
- // @router /list [get]
- func (this *ChartPermissionController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- cond := ` and product_id=1`
- pars := make([]interface{}, 0)
- list, e := services.GetChartPermissionList(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取品种列表失败, Err: " + e.Error()
- return
- }
- // 品种树
- resp := make([]*models.ChartPermissionItem, 0)
- childMap := make(map[int][]*models.ChartPermissionItem)
- for _, v := range list {
- t := new(models.ChartPermissionItem)
- t.PermissionId = v.ChartPermissionId
- t.PermissionName = v.PermissionName
- t.ParentId = v.ParentId
- t.IsPublic = v.IsPublic
- t.Enabled = v.Enabled
- t.Sort = v.Sort
- t.CreateTime = v.CreatedTime.Format(utils.FormatDateTime)
- t.Child = make([]*models.ChartPermissionItem, 0)
- if v.ParentId == 0 {
- resp = append(resp, t)
- continue
- }
- if v.ParentId > 0 {
- if childMap[v.ParentId] == nil {
- childMap[v.ParentId] = make([]*models.ChartPermissionItem, 0)
- }
- childMap[v.ParentId] = append(childMap[v.ParentId], t)
- }
- }
- for _, r := range resp {
- r.Child = childMap[r.PermissionId]
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Add
- // @Title 新增品种列表
- // @Description 新增品种列表
- // @Param request body models.PermissionAddReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /add [post]
- func (this *ChartPermissionController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.PermissionAddReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.PermissionName == "" {
- br.Msg = "请输入品种名称"
- return
- }
- e, msg := services.AddChartPermission(req)
- if e != nil {
- br.Msg = msg
- br.ErrMsg = "新增品种失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Edit
- // @Title 编辑品种
- // @Description 编辑品种
- // @Param request body models.PermissionEditReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /edit [post]
- func (this *ChartPermissionController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.PermissionEditReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.PermissionId <= 0 {
- br.Msg = "请选择要编辑的品种"
- return
- }
- if req.PermissionName == "" {
- br.Msg = "请输入品种名称"
- return
- }
- e, msg := services.EditChartPermission(req)
- if e != nil {
- br.Msg = msg
- br.ErrMsg = "编辑品种失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Move
- // @Title 移动品种
- // @Description 移动品种
- // @Param request body models.PermissionMoveReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /move [post]
- func (this *ChartPermissionController) Move() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.PermissionMoveReq
- // todo 限制修改一级品种
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.PermissionId == 0 {
- br.Msg = "请选择要移动的品种"
- return
- }
- e, msg := services.MoveChartPermission(req)
- if e != nil {
- br.Msg = msg
- br.ErrMsg = "移动品种失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // SetEnabled
- // @Title 启用/禁用品种
- // @Description 启用/禁用品种
- // @Param request body models.PermissionEnabledReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /enabled/set [post]
- func (this *ChartPermissionController) SetEnabled() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.PermissionEnabledReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.PermissionId <= 0 {
- br.Msg = "请选择要编辑的品种"
- return
- }
- if req.Enabled != 0 && req.Enabled != 1 {
- br.Msg = "请选择正确的启用禁用状态"
- return
- }
- e, msg := services.SetEnabledChartPermission(req)
- if e != nil {
- br.Msg = msg
- br.ErrMsg = "编辑品种失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|