edb_classify.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "hongze/hz_eta_api/controllers"
  5. "hongze/hz_eta_api/models"
  6. "hongze/hz_eta_api/models/data_manage"
  7. "hongze/hz_eta_api/models/system"
  8. "hongze/hz_eta_api/services/data"
  9. "hongze/hz_eta_api/utils"
  10. )
  11. // EdbClassifyController 数据管理-分类模块
  12. type EdbClassifyController struct {
  13. controllers.BaseAuthController
  14. }
  15. //
  16. //// @Title 分类列表
  17. //// @Description 分类列表接口
  18. //// @Success 200 {object} data_manage.EdbClassifyListResp
  19. //// @router /classify/list [get]
  20. //func (this *EdbClassifyController) List() {
  21. // br := new(models.BaseResponse).Init()
  22. // defer func() {
  23. // this.Data["json"] = br
  24. // this.ServeJSON()
  25. // }()
  26. // rootList, err := data_manage.GetEdbClassifyByParentId(0)
  27. // if err != nil {
  28. // br.Msg = "获取失败"
  29. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  30. // return
  31. // }
  32. //
  33. // classifyAll, err := data_manage.GetEdbClassifyAll()
  34. // if err != nil {
  35. // br.Msg = "获取失败"
  36. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  37. // return
  38. // }
  39. //
  40. // fmt.Println("start:", time.Now())
  41. // nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  42. // for k := range rootList {
  43. // rootNode := rootList[k]
  44. // data.EdbClassifyListMakeTree(classifyAll, rootNode)
  45. // nodeAll = append(nodeAll, rootNode)
  46. // }
  47. // fmt.Println("end:", time.Now())
  48. // resp := new(data_manage.EdbClassifyListResp)
  49. // resp.AllNodes = nodeAll
  50. // br.Ret = 200
  51. // br.Success = true
  52. // br.Msg = "获取成功"
  53. // br.Data = resp
  54. //}
  55. // ListV2
  56. // @Title 分类列表
  57. // @Description 分类列表接口
  58. // @Success 200 {object} data_manage.EdbClassifyListResp
  59. // @router /classify/list [get]
  60. func (this *EdbClassifyController) ListV2() {
  61. br := new(models.BaseResponse).Init()
  62. defer func() {
  63. this.Data["json"] = br
  64. this.ServeJSON()
  65. }()
  66. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  67. if err != nil && err.Error() != utils.ErrNoRow() {
  68. br.Msg = "获取失败"
  69. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  70. return
  71. }
  72. classifyAll, err := data_manage.GetEdbClassifyAll()
  73. if err != nil && err.Error() != utils.ErrNoRow() {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  76. return
  77. }
  78. // 获取当前账号的不可见指标
  79. obj := data_manage.EdbInfoNoPermissionAdmin{}
  80. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  81. if err != nil && err.Error() != utils.ErrNoRow() {
  82. br.Msg = "获取失败"
  83. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  84. return
  85. }
  86. noPermissionEdbInfoIdMap := make(map[int]bool)
  87. for _, v := range confList {
  88. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  89. }
  90. allEdbInfo, err := data_manage.GetEdbInfoAll(utils.EDB_INFO_TYPE)
  91. if err != nil && err.Error() != utils.ErrNoRow() {
  92. br.Msg = "获取失败"
  93. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  94. return
  95. }
  96. edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  97. for _, v := range allEdbInfo {
  98. // 如果指标不可见,那么就不返回该指标
  99. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  100. continue
  101. }
  102. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE)
  103. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  104. v.Button = button
  105. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  106. }
  107. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  108. for _, v := range classifyAll {
  109. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  110. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  111. v.Button = button
  112. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  113. if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  114. v.Children = existItems
  115. } else {
  116. items := make([]*data_manage.EdbClassifyItems, 0)
  117. v.Children = items
  118. }
  119. }
  120. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  121. for _, v := range rootList {
  122. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  123. v.Button = button
  124. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  125. v.Children = existItems
  126. } else {
  127. items := make([]*data_manage.EdbClassifyItems, 0)
  128. v.Children = items
  129. }
  130. nodeAll = append(nodeAll, v)
  131. }
  132. resp := new(data_manage.EdbClassifyListResp)
  133. resp.AllNodes = nodeAll
  134. br.Ret = 200
  135. br.Success = true
  136. br.Msg = "获取成功"
  137. br.Data = resp
  138. }
  139. // @Title 获取所有分类接口-不包含指标
  140. // @Description 获取所有分类接口-不包含指标
  141. // @Success 200 {object} data_manage.EdbClassifyListResp
  142. // @router /classify/items [get]
  143. func (this *EdbClassifyController) Items() {
  144. br := new(models.BaseResponse).Init()
  145. defer func() {
  146. this.Data["json"] = br
  147. this.ServeJSON()
  148. }()
  149. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  150. if err != nil {
  151. br.Msg = "获取失败"
  152. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  153. return
  154. }
  155. classifyAll, err := data_manage.GetEdbClassifyAll()
  156. if err != nil {
  157. br.Msg = "获取失败"
  158. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  159. return
  160. }
  161. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  162. for k := range rootList {
  163. rootNode := rootList[k]
  164. data.EdbClassifyItemsMakeTree(classifyAll, rootNode)
  165. nodeAll = append(nodeAll, rootNode)
  166. }
  167. resp := new(data_manage.EdbClassifyListResp)
  168. resp.AllNodes = nodeAll
  169. br.Ret = 200
  170. br.Success = true
  171. br.Msg = "获取成功"
  172. br.Data = resp
  173. }
  174. // @Title 新增分类
  175. // @Description 新增分类接口
  176. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  177. // @Success 200 Ret=200 保存成功
  178. // @router /classify/add [post]
  179. func (this *EdbClassifyController) AddEdbClassify() {
  180. br := new(models.BaseResponse).Init()
  181. defer func() {
  182. this.Data["json"] = br
  183. this.ServeJSON()
  184. }()
  185. var req data_manage.AddEdbClassifyReq
  186. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  187. if err != nil {
  188. br.Msg = "参数解析异常!"
  189. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  190. return
  191. }
  192. if req.ClassifyName == "" {
  193. br.Msg = "请输入分类名称"
  194. br.IsSendEmail = false
  195. return
  196. }
  197. if req.ParentId < 0 {
  198. br.Msg = "参数错误"
  199. br.IsSendEmail = false
  200. return
  201. }
  202. //添加指标
  203. _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, 0, this.SysUser.AdminId, this.SysUser.AdminName)
  204. if errMsg != `` {
  205. br.Msg = errMsg
  206. br.ErrMsg = errMsg
  207. if err != nil {
  208. br.ErrMsg = errMsg + ";Err:" + err.Error()
  209. } else {
  210. br.IsSendEmail = false
  211. }
  212. return
  213. }
  214. //count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, req.ParentId)
  215. //if err != nil {
  216. // br.Msg = "判断名称是否已存在失败"
  217. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  218. // return
  219. //}
  220. //if count > 0 {
  221. // br.Msg = "分类名称已存在,请重新输入"
  222. // br.IsSendEmail = false
  223. // return
  224. //}
  225. ////获取该层级下最大的排序数
  226. //maxSort, err := data_manage.GetEdbClassifyMaxSort(req.ParentId, req.ClassifyType)
  227. //
  228. //classify := new(data_manage.EdbClassify)
  229. //classify.ClassifyType = req.ClassifyType
  230. //classify.ParentId = req.ParentId
  231. //classify.ClassifyName = req.ClassifyName
  232. //classify.HasData = 0
  233. //classify.CreateTime = time.Now()
  234. //classify.ModifyTime = time.Now()
  235. //classify.SysUserId = this.SysUser.AdminId
  236. //classify.SysUserRealName = this.SysUser.RealName
  237. //classify.Level = req.Level + 1
  238. //timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  239. //classify.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  240. //classify.Sort = maxSort
  241. //
  242. //_, err = data_manage.AddEdbClassify(classify)
  243. //if err != nil {
  244. // br.Msg = "保存分类失败"
  245. // br.ErrMsg = "保存分类失败,Err:" + err.Error()
  246. // return
  247. //}
  248. br.Ret = 200
  249. br.Msg = "保存成功"
  250. br.Success = true
  251. br.IsAddLog = true
  252. }
  253. // @Title 修改分类
  254. // @Description 修改分类接口
  255. // @Param request body data_manage.EditEdbClassifyReq true "type json string"
  256. // @Success 200 Ret=200 修改成功
  257. // @router /classify/edit [post]
  258. func (this *EdbClassifyController) EditEdbClassify() {
  259. br := new(models.BaseResponse).Init()
  260. defer func() {
  261. this.Data["json"] = br
  262. this.ServeJSON()
  263. }()
  264. var req data_manage.EditEdbClassifyReq
  265. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  266. if err != nil {
  267. br.Msg = "参数解析异常!"
  268. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  269. return
  270. }
  271. if req.ClassifyName == "" {
  272. br.Msg = "请输入分类名称"
  273. br.IsSendEmail = false
  274. return
  275. }
  276. if req.ClassifyId < 0 {
  277. br.Msg = "参数错误"
  278. br.IsSendEmail = false
  279. return
  280. }
  281. err, errMsg := data.EditEdbClassify(req.ClassifyId, req.ClassifyName)
  282. if errMsg != `` {
  283. br.Msg = errMsg
  284. br.ErrMsg = errMsg
  285. if err != nil {
  286. br.ErrMsg = errMsg + ";Err:" + err.Error()
  287. } else {
  288. br.IsSendEmail = false
  289. }
  290. return
  291. }
  292. //item, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  293. //if err != nil {
  294. // br.Msg = "保存失败"
  295. // br.Msg = "获取分类信息失败,Err:" + err.Error()
  296. // return
  297. //}
  298. //
  299. //if item.ClassifyName != req.ClassifyName {
  300. // count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, item.ParentId)
  301. // if err != nil {
  302. // br.Msg = "判断名称是否已存在失败"
  303. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  304. // return
  305. // }
  306. // if count > 0 {
  307. // br.Msg = "分类名称已存在,请重新输入"
  308. // br.IsSendEmail = false
  309. // return
  310. // }
  311. //
  312. // err = data_manage.EditEdbClassify(req.ClassifyId, req.ClassifyName)
  313. // if err != nil {
  314. // br.Msg = "保存失败"
  315. // br.ErrMsg = "保存失败,Err:" + err.Error()
  316. // return
  317. // }
  318. //}
  319. br.Ret = 200
  320. br.Msg = "保存成功"
  321. br.Success = true
  322. }
  323. // @Title 删除检测接口
  324. // @Description 删除检测接口
  325. // @Param request body data_manage.ClassifyDeleteCheckReq true "type json string"
  326. // @Success 200 Ret=200 检测成功
  327. // @router /classify/delete/check [post]
  328. func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
  329. br := new(models.BaseResponse).Init()
  330. defer func() {
  331. this.Data["json"] = br
  332. this.ServeJSON()
  333. }()
  334. var req data_manage.ClassifyDeleteCheckReq
  335. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  336. if err != nil {
  337. br.Msg = "参数解析异常!"
  338. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  339. return
  340. }
  341. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  342. br.Msg = "参数错误"
  343. br.IsSendEmail = false
  344. return
  345. }
  346. deleteStatus, tipsMsg, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId)
  347. if errMsg != `` {
  348. br.Msg = errMsg
  349. br.ErrMsg = errMsg
  350. if err != nil {
  351. br.ErrMsg = err.Error()
  352. } else {
  353. br.IsSendEmail = false
  354. }
  355. return
  356. }
  357. //var deleteStatus int
  358. //var tipsMsg string
  359. ////删除分类
  360. //if req.ClassifyId > 0 && req.EdbInfoId == 0 {
  361. // //判断分类下,是否含有指标
  362. // count, err := data_manage.GetEdbInfoCountByClassifyId(req.ClassifyId)
  363. // if err != nil {
  364. // br.Msg = "删除失败"
  365. // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  366. // return
  367. // }
  368. //
  369. // if count > 0 {
  370. // deleteStatus = 1
  371. // tipsMsg = "若目录关联指标不可删除"
  372. // }
  373. //}
  374. //
  375. //if deleteStatus != 1 && req.EdbInfoId == 0 {
  376. // classifyCount, err := data_manage.GetClassifyCountByClassifyId(req.ClassifyId)
  377. // if err != nil && err.Error() != utils.ErrNoRow() {
  378. // br.Msg = "删除失败"
  379. // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  380. // return
  381. // }
  382. // if classifyCount > 0 {
  383. // deleteStatus = 2
  384. // tipsMsg = "确认删除当前目录及包含的子目录吗"
  385. // }
  386. //}
  387. //
  388. ////删除指标
  389. //if req.EdbInfoId > 0 {
  390. // //判断指标是否用于作图,如果用于作图,则不可删除
  391. // chartCount, err := data_manage.GetChartEdbMappingCount(req.EdbInfoId)
  392. // if err != nil && err.Error() != utils.ErrNoRow() {
  393. // br.Msg = "删除失败"
  394. // br.ErrMsg = "判断指标是否被用于作图失败,Err:" + err.Error()
  395. // return
  396. // }
  397. // if chartCount > 0 {
  398. // deleteStatus = 3
  399. // tipsMsg = "当前指标已用作画图,不可删除"
  400. // }
  401. // //判断指标是否用于计算
  402. // {
  403. // calculateCount, err := data_manage.GetEdbInfoCalculateMappingCount(req.EdbInfoId)
  404. // if err != nil && err.Error() != utils.ErrNoRow() {
  405. // br.Msg = "删除失败"
  406. // br.ErrMsg = "判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + err.Error()
  407. // return
  408. // }
  409. // if calculateCount > 0 {
  410. // deleteStatus = 4
  411. // tipsMsg = "当前指标已用作,指标运算,不可删除"
  412. // }
  413. // }
  414. //}
  415. resp := new(data_manage.ClassifyDeleteCheckResp)
  416. resp.DeleteStatus = deleteStatus
  417. resp.TipsMsg = tipsMsg
  418. br.Ret = 200
  419. br.Msg = "检测成功"
  420. br.Success = true
  421. br.Data = resp
  422. }
  423. // @Title 删除分类/指标
  424. // @Description 删除分类/指标接口
  425. // @Param request body data_manage.DeleteEdbClassifyReq true "type json string"
  426. // @Success 200 Ret=200 新增成功
  427. // @router /classify/delete [post]
  428. func (this *EdbClassifyController) DeleteEdbClassify() {
  429. br := new(models.BaseResponse).Init()
  430. defer func() {
  431. this.Data["json"] = br
  432. this.ServeJSON()
  433. }()
  434. sysUser := this.SysUser
  435. if sysUser == nil {
  436. br.Msg = "请登录"
  437. br.ErrMsg = "请登录,SysUser Is Empty"
  438. br.Ret = 408
  439. return
  440. }
  441. var req data_manage.DeleteEdbClassifyReq
  442. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  443. if err != nil {
  444. br.Msg = "参数解析异常!"
  445. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  446. return
  447. }
  448. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  449. br.Msg = "参数错误"
  450. br.IsSendEmail = false
  451. return
  452. }
  453. nextItem, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser.AdminId, sysUser.RealName, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  454. if errMsg != `` {
  455. br.Msg = errMsg
  456. br.ErrMsg = errMsg
  457. if err != nil {
  458. br.ErrMsg = err.Error()
  459. } else {
  460. br.IsSendEmail = false
  461. }
  462. return
  463. }
  464. resp := data_manage.AddEdbInfoResp{}
  465. if nextItem != nil {
  466. resp = data_manage.AddEdbInfoResp{
  467. EdbInfoId: nextItem.EdbInfoId,
  468. UniqueCode: nextItem.UniqueCode,
  469. }
  470. }
  471. br.Ret = 200
  472. br.Msg = "删除成功"
  473. br.Success = true
  474. br.IsAddLog = true
  475. br.Data = resp
  476. }
  477. // EdbClassifyMove
  478. // @Title 分类移动接口
  479. // @Description 分类移动接口
  480. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  481. // @router /edb_classify/move [post]
  482. func (this *EdbClassifyController) EdbClassifyMove() {
  483. br := new(models.BaseResponse).Init()
  484. defer func() {
  485. this.Data["json"] = br
  486. this.ServeJSON()
  487. }()
  488. sysUser := this.SysUser
  489. if sysUser == nil {
  490. br.Msg = "请登录"
  491. br.ErrMsg = "请登录,SysUser Is Empty"
  492. br.Ret = 408
  493. return
  494. }
  495. var req data_manage.MoveEdbClassifyReq
  496. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  497. if err != nil {
  498. br.Msg = "参数解析异常!"
  499. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  500. return
  501. }
  502. if req.ClassifyId <= 0 {
  503. br.Msg = "参数错误"
  504. br.ErrMsg = "分类id小于等于0"
  505. return
  506. }
  507. err, errMsg := data.MoveEdbClassify(req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId)
  508. if errMsg != `` {
  509. br.Msg = errMsg
  510. br.ErrMsg = errMsg
  511. if err != nil {
  512. br.ErrMsg = err.Error()
  513. } else {
  514. br.IsSendEmail = false
  515. }
  516. return
  517. }
  518. ////判断分类是否存在
  519. //edbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  520. //if err != nil {
  521. // br.Msg = "移动失败"
  522. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  523. // return
  524. //}
  525. //updateCol := make([]string, 0)
  526. //
  527. ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  528. //if edbClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  529. // parentEdbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ParentClassifyId)
  530. // if err != nil {
  531. // br.Msg = "移动失败"
  532. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  533. // return
  534. // }
  535. // edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  536. // edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  537. // edbClassifyInfo.ModifyTime = time.Now()
  538. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  539. //}
  540. //
  541. ////如果有传入 上一个兄弟节点分类id
  542. //if req.PrevClassifyId > 0 {
  543. // prevClassify, err := data_manage.GetEdbClassifyById(req.PrevClassifyId)
  544. // if err != nil {
  545. // br.Msg = "移动失败"
  546. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  547. // return
  548. // }
  549. //
  550. // //如果是移动在两个兄弟节点之间
  551. // if req.NextClassifyId > 0 {
  552. // //下一个兄弟节点
  553. // nextClassify, err := data_manage.GetEdbClassifyById(req.NextClassifyId)
  554. // if err != nil {
  555. // br.Msg = "移动失败"
  556. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  557. // return
  558. // }
  559. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  560. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort {
  561. // //变更兄弟节点的排序
  562. // updateSortStr := `sort + 2`
  563. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
  564. // } else {
  565. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  566. // if nextClassify.Sort-prevClassify.Sort == 1 {
  567. // //变更兄弟节点的排序
  568. // updateSortStr := `sort + 1`
  569. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  570. // }
  571. // }
  572. // }
  573. //
  574. // edbClassifyInfo.Sort = prevClassify.Sort + 1
  575. // edbClassifyInfo.ModifyTime = time.Now()
  576. // updateCol = append(updateCol, "Sort", "ModifyTime")
  577. //} else {
  578. // firstClassify, err := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId)
  579. // if err != nil && err.Error() != utils.ErrNoRow() {
  580. // br.Msg = "移动失败"
  581. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  582. // return
  583. // }
  584. //
  585. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  586. // if firstClassify != nil && firstClassify.Sort == 0 {
  587. // updateSortStr := ` sort + 1 `
  588. // _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr)
  589. // }
  590. //
  591. // edbClassifyInfo.Sort = 0 //那就是排在第一位
  592. // edbClassifyInfo.ModifyTime = time.Now()
  593. // updateCol = append(updateCol, "Sort", "ModifyTime")
  594. //}
  595. //
  596. ////更新
  597. //if len(updateCol) > 0 {
  598. // err = edbClassifyInfo.Update(updateCol)
  599. // if err != nil {
  600. // br.Msg = "移动失败"
  601. // br.ErrMsg = "修改失败,Err:" + err.Error()
  602. // return
  603. // }
  604. //}
  605. br.Ret = 200
  606. br.Success = true
  607. br.Msg = "移动成功"
  608. }
  609. // ItemsV2
  610. // @Title 分类列表
  611. // @Description 分类列表接口
  612. // @Success 200 {object} data_manage.EdbClassifyListResp
  613. // @router /classify/items/v2 [get]
  614. func (this *EdbClassifyController) ItemsV2() {
  615. br := new(models.BaseResponse).Init()
  616. defer func() {
  617. this.Data["json"] = br
  618. this.ServeJSON()
  619. }()
  620. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  621. if err != nil && err.Error() != utils.ErrNoRow() {
  622. br.Msg = "获取失败"
  623. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  624. return
  625. }
  626. classifyAll, err := data_manage.GetEdbClassifyAll()
  627. if err != nil && err.Error() != utils.ErrNoRow() {
  628. br.Msg = "获取失败"
  629. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  630. return
  631. }
  632. //allEdbInfo, err := data_manage.GetEdbInfoAll(0)
  633. //if err != nil && err.Error() != utils.ErrNoRow() {
  634. // br.Msg = "获取失败"
  635. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  636. // return
  637. //}
  638. //edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  639. //for _, v := range allEdbInfo {
  640. // button := data.GetEdbOpButton(this.SysUser, v.SysUserId)
  641. // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  642. // v.Button = button
  643. // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  644. //}
  645. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  646. for _, v := range classifyAll {
  647. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  648. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  649. v.Button = button
  650. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  651. //if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  652. // v.Children = existItems
  653. //} else {
  654. // items := make([]*data_manage.EdbClassifyItems, 0)
  655. // v.Children = items
  656. //}
  657. }
  658. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  659. for _, v := range rootList {
  660. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
  661. v.Button = button
  662. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  663. v.Children = existItems
  664. } else {
  665. items := make([]*data_manage.EdbClassifyItems, 0)
  666. v.Children = items
  667. }
  668. nodeAll = append(nodeAll, v)
  669. }
  670. language := `CN`
  671. // 指标显示的语言
  672. {
  673. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  674. if configDetail != nil {
  675. language = configDetail.ConfigValue
  676. } else {
  677. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  678. if configDetail != nil {
  679. language = configDetail.ConfigValue
  680. }
  681. }
  682. }
  683. // 是否允许添加分类
  684. canOpClassify := true
  685. // 如果不是 超管 或者 ficc管理员,那么就没有权限
  686. if this.SysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && this.SysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_ADMIN {
  687. canOpClassify = false
  688. }
  689. resp := new(data_manage.EdbClassifyListResp)
  690. resp.AllNodes = nodeAll
  691. resp.Language = language
  692. resp.CanOpClassify = canOpClassify
  693. br.Ret = 200
  694. br.Success = true
  695. br.Msg = "获取成功"
  696. br.Data = resp
  697. }
  698. // @Title 获取分类下指标接口
  699. // @Description 获取分类下指标接口
  700. // @Param ClassifyId query int true "分类id"
  701. // @Success 200 {object} data_manage.EdbClassifyListResp
  702. // @router /classify/edb_info/list [get]
  703. func (this *EdbClassifyController) ClassifyEdbInfoList() {
  704. br := new(models.BaseResponse).Init()
  705. defer func() {
  706. this.Data["json"] = br
  707. this.ServeJSON()
  708. }()
  709. classifyId, _ := this.GetInt("ClassifyId")
  710. if classifyId <= 0 {
  711. br.Msg = "参数错误,请刷新页面"
  712. return
  713. }
  714. // 获取当前账号的不可见指标
  715. obj := data_manage.EdbInfoNoPermissionAdmin{}
  716. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  717. if err != nil && err.Error() != utils.ErrNoRow() {
  718. br.Msg = "获取失败"
  719. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  720. return
  721. }
  722. noPermissionEdbInfoIdMap := make(map[int]bool)
  723. for _, v := range confList {
  724. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  725. }
  726. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(classifyId, 0)
  727. if err != nil && err.Error() != utils.ErrNoRow() {
  728. br.Msg = "获取失败"
  729. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  730. return
  731. }
  732. list := make([]*data_manage.EdbClassifyItems, 0)
  733. for _, v := range allEdbInfo {
  734. // 如果指标不可见,那么就不返回该指标
  735. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  736. continue
  737. }
  738. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE)
  739. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  740. v.Button = button
  741. list = append(list, v)
  742. }
  743. resp := new(data_manage.ClassifyEdbInfoListResp)
  744. resp.EdbInfoList = list
  745. br.Ret = 200
  746. br.Success = true
  747. br.Msg = "获取成功"
  748. br.Data = resp
  749. }