chart_edb_config.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/data_manage"
  6. "eta_gn/eta_api/models/data_manage/request"
  7. "eta_gn/eta_api/models/data_manage/response"
  8. "eta_gn/eta_api/models/system"
  9. "eta_gn/eta_api/services/data"
  10. "eta_gn/eta_api/utils"
  11. )
  12. // @router /edb_no_permission/list [get]
  13. func (this *EdbInfoController) EdbNoPermissionList() {
  14. br := new(models.BaseResponse).Init()
  15. defer func() {
  16. this.Data["json"] = br
  17. this.ServeJSON()
  18. }()
  19. sysUser := this.SysUser
  20. if sysUser == nil {
  21. br.Msg = "请登录"
  22. br.ErrMsg = "请登录,SysUser Is Empty"
  23. br.Ret = 408
  24. return
  25. }
  26. edbInfoId, _ := this.GetInt("EdbInfoId")
  27. if edbInfoId <= 0 {
  28. br.Msg = "请选择指标"
  29. br.IsSendEmail = false
  30. return
  31. }
  32. resp := response.EdbNoPermissionAdminResp{}
  33. list := make([]response.Admin, 0)
  34. obj := data_manage.EdbInfoNoPermissionAdmin{}
  35. tmpList, err := obj.GetAllListByEdbInfoId(edbInfoId)
  36. if err != nil {
  37. br.Msg = "获取失败"
  38. br.ErrMsg = "获取配置失败,Err:" + err.Error()
  39. return
  40. }
  41. if len(tmpList) > 0 {
  42. adminIdList := make([]int, 0)
  43. for _, v := range tmpList {
  44. adminIdList = append(adminIdList, v.AdminId)
  45. }
  46. adminList, err := system.GetAdminListByIdList(adminIdList)
  47. if err != nil {
  48. br.Msg = "获取失败"
  49. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  50. }
  51. groupMap := make(map[int]*system.SysFullGroup)
  52. if len(adminList) > 0 {
  53. groupList, err := system.GetFullGroup()
  54. if err != nil {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "查询分组失败,err:" + err.Error()
  57. return
  58. }
  59. for _, v := range groupList {
  60. groupMap[v.GroupId] = v
  61. }
  62. }
  63. for _, v := range adminList {
  64. var secondName string
  65. if v.GroupId != 0 {
  66. if fullGroup, ok := groupMap[v.GroupId]; ok {
  67. secondName = fullGroup.ParentGroupName
  68. }
  69. }
  70. departmentGroup := ``
  71. if v.DepartmentName != "" {
  72. if v.GroupName == "" {
  73. departmentGroup = v.DepartmentName
  74. } else if secondName != `` {
  75. departmentGroup = v.DepartmentName + "/" + secondName + "/" + v.GroupName
  76. } else {
  77. departmentGroup = v.DepartmentName + "/" + v.GroupName
  78. }
  79. }
  80. list = append(list, response.Admin{
  81. AdminId: v.AdminId,
  82. RealName: v.RealName,
  83. RoleName: v.RoleName,
  84. DepartmentGroup: departmentGroup,
  85. })
  86. }
  87. }
  88. resp.List = list
  89. br.Ret = 200
  90. br.Success = true
  91. br.Msg = "获取成功"
  92. br.Data = resp
  93. }
  94. // @router /edb_no_permission/modify [post]
  95. func (this *EdbInfoController) ModifyNoPermissionAdmin() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. this.Data["json"] = br
  99. this.ServeJSON()
  100. }()
  101. sysUser := this.SysUser
  102. if sysUser == nil {
  103. br.Msg = "请登录"
  104. br.ErrMsg = "请登录,SysUser Is Empty"
  105. br.Ret = 408
  106. return
  107. }
  108. var req request.ModifyEdbNoPermissionAdminReq
  109. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  110. if err != nil {
  111. br.Msg = "参数解析异常!"
  112. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  113. return
  114. }
  115. if req.EdbInfoId <= 0 {
  116. br.Msg = "请选择指标"
  117. br.IsSendEmail = false
  118. return
  119. }
  120. if len(req.AdminIdList) <= 0 {
  121. br.Msg = "请选择用户"
  122. br.IsSendEmail = false
  123. return
  124. }
  125. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  126. if err != nil {
  127. br.Msg = "修改失败"
  128. if utils.IsErrNoRow(err) {
  129. br.Msg = "找不到该指标"
  130. br.IsSendEmail = false
  131. }
  132. br.ErrMsg = "修改失败,Err:" + err.Error()
  133. return
  134. }
  135. obj := data_manage.EdbInfoNoPermissionAdmin{}
  136. err = obj.ModifyByEdbInfoId(edbInfo.EdbInfoId, req.AdminIdList)
  137. if err != nil {
  138. br.Msg = "修改失败"
  139. br.ErrMsg = "修改失败,Err:" + err.Error()
  140. return
  141. }
  142. br.Ret = 200
  143. br.Success = true
  144. br.Msg = "配置成功"
  145. }
  146. // @router /edb_no_permission/delete [post]
  147. func (this *EdbInfoController) DelNoPermissionAdmin() {
  148. br := new(models.BaseResponse).Init()
  149. defer func() {
  150. this.Data["json"] = br
  151. this.ServeJSON()
  152. }()
  153. sysUser := this.SysUser
  154. if sysUser == nil {
  155. br.Msg = "请登录"
  156. br.ErrMsg = "请登录,SysUser Is Empty"
  157. br.Ret = 408
  158. return
  159. }
  160. var req request.DelEdbNoPermissionAdminReq
  161. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  162. if err != nil {
  163. br.Msg = "参数解析异常!"
  164. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  165. return
  166. }
  167. if req.EdbInfoId <= 0 {
  168. br.Msg = "请选择指标"
  169. br.IsSendEmail = false
  170. return
  171. }
  172. if req.AdminId <= 0 {
  173. br.Msg = "请选择用户"
  174. br.IsSendEmail = false
  175. return
  176. }
  177. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  178. if err != nil {
  179. br.Msg = "删除失败"
  180. if utils.IsErrNoRow(err) {
  181. br.Msg = "找不到该指标"
  182. br.IsSendEmail = false
  183. }
  184. br.ErrMsg = "删除失败,Err:" + err.Error()
  185. return
  186. }
  187. obj := data_manage.EdbInfoNoPermissionAdmin{}
  188. err = obj.DeleteByEdbInfoIdAndAdminId(edbInfo.EdbInfoId, req.AdminId)
  189. if err != nil {
  190. br.Msg = "删除失败"
  191. br.ErrMsg = "删除失败,Err:" + err.Error()
  192. return
  193. }
  194. br.Ret = 200
  195. br.Success = true
  196. br.Msg = "删除成功"
  197. }
  198. // @router /edb_no_permission/batch_add [post]
  199. func (this *EdbInfoController) BatchAddNoPermissionAdmin() {
  200. br := new(models.BaseResponse).Init()
  201. defer func() {
  202. this.Data["json"] = br
  203. this.ServeJSON()
  204. }()
  205. sysUser := this.SysUser
  206. if sysUser == nil {
  207. br.Msg = "请登录"
  208. br.ErrMsg = "请登录,SysUser Is Empty"
  209. br.Ret = 408
  210. return
  211. }
  212. var req request.BatchAddEdbNoPermissionAdminReq
  213. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  214. if err != nil {
  215. br.Msg = "参数解析异常!"
  216. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  217. return
  218. }
  219. if len(req.EdbInfoIdList) <= 0 {
  220. br.Msg = "请选择指标"
  221. br.IsSendEmail = false
  222. return
  223. }
  224. if len(req.AdminIdList) <= 0 {
  225. br.Msg = "请选择用户"
  226. br.IsSendEmail = false
  227. return
  228. }
  229. err = data.BatchAddNoPermissionAdmin(req.EdbInfoIdList, req.AdminIdList)
  230. if err != nil {
  231. br.Msg = "配置失败"
  232. br.ErrMsg = "配置失败,Err:" + err.Error()
  233. return
  234. }
  235. br.Ret = 200
  236. br.Success = true
  237. br.Msg = "配置成功"
  238. }