chart_edb_config.go 7.1 KB

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