data_move.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. package data_manage_permission
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. data_manage_permissionModel "eta/eta_api/models/data_manage/data_manage_permission"
  7. "eta/eta_api/services/data/data_manage_permission"
  8. "eta/eta_api/utils"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. )
  11. // EdbChartClassifyList
  12. // @Title 获取指标/图表分类列表数据接口
  13. // @Description 获取指标/图表分类列表数据接口
  14. // @Param Source query int false "来源 :1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格"
  15. // @Param SubSource query int false "子来源 :ETA表格中的各种表格类型,以及图表的来源(这个是后续的扩展方向)"
  16. // @Success 200 {object} data_manage.ChartListResp
  17. // @router /edb_chart/classify [get]
  18. func (c *DataMangePermissionController) EdbChartClassifyList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. c.Data["json"] = br
  22. c.ServeJSON()
  23. }()
  24. sysUser := c.SysUser
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. source, _ := c.GetInt("Source")
  32. if source <= 0 || source > 6 {
  33. br.Msg = "错误的来源"
  34. br.IsSendEmail = false
  35. return
  36. }
  37. // 子来源(目前作用于ETA表格,2024-3-26 14:12:09)
  38. subSource, _ := c.GetInt("SubSource")
  39. if source == 6 && (subSource <= utils.EXCEL_DEFAULT || subSource > utils.BALANCE_TABLE) {
  40. br.Msg = "错误的子来源"
  41. br.IsSendEmail = false
  42. return
  43. }
  44. list, err := data_manage_permission.GetEdbChartClassifyList(source, subSource)
  45. if err != nil {
  46. //br.Success = true
  47. br.Msg = "获取失败"
  48. br.ErrMsg = "获取失败,Err:" + err.Error()
  49. return
  50. }
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = list
  55. }
  56. // SecretEdbChartClassifyList
  57. // @Title 获取涉密的指标/图表分类列表数据接口
  58. // @Description 获取指标/图表分类列表数据接口
  59. // @Param Source query int false "来源 :1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格"
  60. // @Param SubSource query int false "子来源 :ETA表格中的各种表格类型,以及图表的来源(这个是后续的扩展方向)"
  61. // @Success 200 {object} data_manage.ChartListResp
  62. // @router /edb_chart/classify/secret [get]
  63. func (c *DataMangePermissionController) SecretEdbChartClassifyList() {
  64. br := new(models.BaseResponse).Init()
  65. defer func() {
  66. c.Data["json"] = br
  67. c.ServeJSON()
  68. }()
  69. sysUser := c.SysUser
  70. if sysUser == nil {
  71. br.Msg = "请登录"
  72. br.ErrMsg = "请登录,SysUser Is Empty"
  73. br.Ret = 408
  74. return
  75. }
  76. source, _ := c.GetInt("Source")
  77. if source <= 0 || source > 6 {
  78. br.Msg = "错误的来源"
  79. br.IsSendEmail = false
  80. return
  81. }
  82. // 子来源(目前作用于ETA表格,2024-3-26 14:12:09)
  83. subSource, _ := c.GetInt("SubSource")
  84. if source == 6 && (subSource <= utils.EXCEL_DEFAULT || subSource > utils.BALANCE_TABLE) {
  85. br.Msg = "错误的子来源"
  86. br.IsSendEmail = false
  87. return
  88. }
  89. resp, err := data_manage_permission.GetEdbChartClassifyList(source, subSource)
  90. if err != nil {
  91. //br.Success = true
  92. br.Msg = "获取失败"
  93. br.ErrMsg = "获取失败,Err:" + err.Error()
  94. return
  95. }
  96. resp.List = removeNodesWithNoJoinPermissionAndEmptyChildRecursively(resp.List)
  97. br.Ret = 200
  98. br.Success = true
  99. br.Msg = "获取成功"
  100. br.Data = resp
  101. }
  102. func removeNodesWithNoJoinPermissionAndEmptyChildRecursively(nodes []*data_manage.EdbChartClassify) []*data_manage.EdbChartClassify {
  103. var newListNode []*data_manage.EdbChartClassify
  104. for _, node := range nodes {
  105. if node.Child != nil {
  106. node.Child = removeNodesWithNoJoinPermissionAndEmptyChildRecursively(node.Child)
  107. }
  108. if node.IsJoinPermission != 0 || (node.Child != nil && len(node.Child) > 0) {
  109. newListNode = append(newListNode, node)
  110. }
  111. }
  112. return newListNode
  113. }
  114. // MoveEdbChartList
  115. // @Title 获取指标/图表创建人列表数据接口
  116. // @Description 获取指标/图表创建人列表数据接口
  117. // @Param PageSize query int true "每页数据条数"
  118. // @Param CurrentIndex query int true "当前页页码,从1开始"
  119. // @Param Source query int false "来源 :1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格"
  120. // @Param SubSource query int false "子来源 :目前作用于ETA表格,2024-3-26 14:12:09"
  121. // @Param Keyword query string false "关键字,code或者名称"
  122. // @Param Classify query string false "分类id"
  123. // @Param UserId query int false "创建人id"
  124. // @Success 200 {object} data_manage.ChartListResp
  125. // @router /edb_chart/list [get]
  126. func (c *DataMangePermissionController) MoveEdbChartList() {
  127. br := new(models.BaseResponse).Init()
  128. defer func() {
  129. c.Data["json"] = br
  130. c.ServeJSON()
  131. }()
  132. sysUser := c.SysUser
  133. if sysUser == nil {
  134. br.Msg = "请登录"
  135. br.ErrMsg = "请登录,SysUser Is Empty"
  136. br.Ret = 408
  137. return
  138. }
  139. source, _ := c.GetInt("Source")
  140. if source <= 0 || source > 6 {
  141. br.Msg = "错误的来源"
  142. br.IsSendEmail = false
  143. return
  144. }
  145. // 子来源(目前作用于ETA表格,2024-3-26 14:12:09)
  146. subSource, _ := c.GetInt("SubSource")
  147. if source == 6 && (subSource <= utils.EXCEL_DEFAULT || subSource > utils.BALANCE_TABLE) {
  148. br.Msg = "错误的子来源"
  149. br.IsSendEmail = false
  150. return
  151. }
  152. userId, _ := c.GetInt("UserId")
  153. keyword := c.GetString("Keyword")
  154. classify := c.GetString("Classify")
  155. pageSize, _ := c.GetInt("PageSize")
  156. currentIndex, _ := c.GetInt("CurrentIndex")
  157. var startSize int
  158. if pageSize <= 0 {
  159. pageSize = utils.PageSize20
  160. }
  161. if currentIndex <= 0 {
  162. currentIndex = 1
  163. }
  164. startSize = paging.StartIndex(currentIndex, pageSize)
  165. resp := data_manage.MoveEdbChartListResp{}
  166. var total int
  167. page := paging.GetPaging(currentIndex, pageSize, total)
  168. defaultList := make([]data_manage.MoveEdbChartList, 0)
  169. resp.List = defaultList
  170. resp.Paging = page
  171. // 没有传入条件,那就默认自动返回
  172. //if userId <= 0 && keyword == `` && classify == `` {
  173. // br.Ret = 200
  174. // br.Success = true
  175. // br.Msg = "获取成功"
  176. // br.Data = resp
  177. // return
  178. //}
  179. list, total, err := data_manage_permission.GetMoveEdbChartList(source, subSource, userId, keyword, classify, startSize, pageSize)
  180. if err != nil {
  181. //br.Success = true
  182. br.Msg = "获取失败"
  183. br.ErrMsg = "获取失败,Err:" + err.Error()
  184. return
  185. }
  186. if list == nil {
  187. list = defaultList
  188. }
  189. page = paging.GetPaging(currentIndex, pageSize, total)
  190. resp.Paging = page
  191. resp.List = list
  192. br.Ret = 200
  193. br.Success = true
  194. br.Msg = "获取成功"
  195. br.IsAddLog = false
  196. br.Data = resp
  197. }
  198. // MoveEdbChartUser
  199. // @Title 指标/图表创建人变更接口
  200. // @Description 指标/图表创建人变更接口
  201. // @Param request body data_manage_permissionModel.MoveEdbChartReq true "type json string"
  202. // @Success 200 {object} data_manage.ChartListResp
  203. // @router /edb_chart/change_user [post]
  204. func (c *DataMangePermissionController) MoveEdbChartUser() {
  205. br := new(models.BaseResponse).Init()
  206. defer func() {
  207. c.Data["json"] = br
  208. c.ServeJSON()
  209. }()
  210. sysUser := c.SysUser
  211. if sysUser == nil {
  212. br.Msg = "请登录"
  213. br.ErrMsg = "请登录,SysUser Is Empty"
  214. br.Ret = 408
  215. return
  216. }
  217. var req data_manage_permissionModel.MoveEdbChartReq
  218. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  219. if err != nil {
  220. br.Msg = "参数解析异常!"
  221. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  222. return
  223. }
  224. if req.Source <= 0 || req.Source > 6 {
  225. br.Msg = "错误的来源"
  226. br.IsSendEmail = false
  227. return
  228. }
  229. // 子来源(目前作用于ETA表格,2024-3-26 14:12:09)
  230. if req.Source == 6 && (req.SubSource <= utils.EXCEL_DEFAULT || req.SubSource > utils.BALANCE_TABLE) {
  231. br.Msg = "错误的子来源"
  232. br.IsSendEmail = false
  233. return
  234. }
  235. if !req.IsSelectAll && len(req.DataIdList) <= 0 {
  236. br.Msg = "请勾选数据项"
  237. br.IsSendEmail = false
  238. return
  239. }
  240. if req.NewUserId <= 0 {
  241. br.Msg = "请选择新的创建人"
  242. br.IsSendEmail = false
  243. return
  244. }
  245. err, errMsg := data_manage_permission.MoveEdbChart(req.Source, req.SubSource, req.UserId, req.NewUserId, req.IsSelectAll, req.DataIdList, req.NoDataIdList, req.Keyword, req.Classify, sysUser.AdminId, sysUser.RealName)
  246. if err != nil {
  247. //br.Success = true
  248. br.Msg = "移动失败"
  249. if errMsg != `` {
  250. br.Msg = errMsg
  251. }
  252. br.ErrMsg = "移动失败,Err:" + err.Error()
  253. return
  254. }
  255. br.Ret = 200
  256. br.IsAddLog = true
  257. br.Success = true
  258. br.Msg = "修改成功"
  259. }
  260. // MoveAllEdbChartUser
  261. // @Title 通过原创建人转移指标/图表创建人接口
  262. // @Description 通过原创建人转移指标/图表创建人接口
  263. // @Param request body data_manage_permission.MoveAllEdbChartReq true "type json string"
  264. // @Success 200 {object} data_manage.ChartListResp
  265. // @router /edb_chart/all/change_user [post]
  266. func (c *DataMangePermissionController) MoveAllEdbChartUser() {
  267. br := new(models.BaseResponse).Init()
  268. defer func() {
  269. c.Data["json"] = br
  270. c.ServeJSON()
  271. }()
  272. sysUser := c.SysUser
  273. if sysUser == nil {
  274. br.Msg = "请登录"
  275. br.ErrMsg = "请登录,SysUser Is Empty"
  276. br.Ret = 408
  277. return
  278. }
  279. var req data_manage_permissionModel.MoveAllEdbChartReq
  280. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  281. if err != nil {
  282. br.Msg = "参数解析异常!"
  283. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  284. return
  285. }
  286. if len(req.Source) <= 0 {
  287. br.Msg = "请选择来源"
  288. br.IsSendEmail = false
  289. return
  290. }
  291. if len(req.OldUserId) <= 0 {
  292. br.Msg = "请选择旧的创建人"
  293. br.IsSendEmail = false
  294. return
  295. }
  296. if req.NewUserId <= 0 {
  297. br.Msg = "请选择新的创建人"
  298. br.IsSendEmail = false
  299. return
  300. }
  301. err, errMsg := data_manage_permission.MoveAllEdbChart(req.Source, req.OldUserId, req.NewUserId, sysUser.AdminId)
  302. if err != nil {
  303. //br.Success = true
  304. br.Msg = "移动失败"
  305. if errMsg != `` {
  306. br.Msg = errMsg
  307. }
  308. br.ErrMsg = "移动失败,Err:" + err.Error()
  309. return
  310. }
  311. br.Ret = 200
  312. br.IsAddLog = true
  313. br.Success = true
  314. br.Msg = "移动成功"
  315. }
  316. // MoveEdbChartCount
  317. // @Title 获取指标/图表创建人汇总数据接口
  318. // @Description 获取指标/图表创建人汇总数据接口
  319. // @Param UserId query int false "创建人id"
  320. // @Param CountType query int false "来源 :1:设置资产权限;2:设置数据权限"
  321. // @Success 200 {object} data_manage.ChartListResp
  322. // @router /edb_chart/count [get]
  323. func (c *DataMangePermissionController) MoveEdbChartCount() {
  324. br := new(models.BaseResponse).Init()
  325. defer func() {
  326. c.Data["json"] = br
  327. c.ServeJSON()
  328. }()
  329. sysUser := c.SysUser
  330. if sysUser == nil {
  331. br.Msg = "请登录"
  332. br.ErrMsg = "请登录,SysUser Is Empty"
  333. br.Ret = 408
  334. return
  335. }
  336. userId, _ := c.GetInt("UserId")
  337. countType, _ := c.GetInt("CountType", 1)
  338. // 没有传入条件,那就默认自动返回
  339. if userId <= 0 {
  340. br.Ret = 200
  341. br.Success = true
  342. br.Msg = "获取成功"
  343. //br.Data = resp
  344. return
  345. }
  346. resp, err := data_manage_permission.GetMoveEdbChartCount(userId, countType)
  347. if err != nil {
  348. //br.Success = true
  349. br.Msg = "获取失败"
  350. br.ErrMsg = "获取失败,Err:" + err.Error()
  351. return
  352. }
  353. br.Ret = 200
  354. br.Success = true
  355. br.Msg = "获取成功"
  356. br.Data = resp
  357. }