fix.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. package controllers
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "eta_gn/eta_api/services/data"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. "sort"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // init
  13. // @Description: 数据修复
  14. // @author: Roc
  15. // @datetime 2024-12-02 09:29:56
  16. func init() {
  17. // ### 1、先修复指标分类完整路径
  18. //initFixEdbClassifyPath()
  19. // ### 2、再修复个人分类、删除不存在指标的分类
  20. // ### 2.1 数据加工
  21. //initFixSelfEdbClassify(utils.EdbClassifyTypeCalculate)
  22. //
  23. //// ### 2.2 衍生指标
  24. //initFixSelfEdbClassify(utils.EdbClassifyTypePredict)
  25. //
  26. // 开始图表数据了
  27. // ### 3、修复图表分类完整路径
  28. //initFixChartClassifyPath()
  29. // ### 4、修复图表分类完整路径
  30. //initFixSelfChartClassify()
  31. // ### 5、修复ES数据
  32. //initEs()
  33. //fmt.Println("修复完成")
  34. }
  35. // initFixEdbClassifyPath
  36. // @Description: 修复分类完整路径
  37. // @author: Roc
  38. // @datetime 2024-11-26 15:40:57
  39. func initFixEdbClassifyPath() {
  40. allList := make([]*data_manage.EdbClassifyItems, 0)
  41. allList, e := data_manage.GetEdbClassifyByClassifyTypes([]int{utils.EdbClassifyTypeBase, utils.EdbClassifyTypePredict, utils.EdbClassifyTypeCalculate}, 0)
  42. if e != nil {
  43. fmt.Println("获取分类失败", e)
  44. return
  45. }
  46. var sortList data_manage.EdbClassifyItemList
  47. allList = data.GetClassifyTreeRecursive(allList, 0)
  48. //根据sort值排序
  49. sortList = allList
  50. sort.Sort(sortList)
  51. for _, v := range sortList {
  52. updateEdbPath(v, "", "")
  53. }
  54. fmt.Println("修复分类路径完成")
  55. }
  56. func updateEdbPath(item *data_manage.EdbClassifyItems, classifyNamePath, classifyIdPath string) {
  57. if classifyNamePath == `` {
  58. classifyNamePath = item.ClassifyName
  59. classifyIdPath = fmt.Sprint(item.ClassifyId)
  60. } else {
  61. classifyNamePath = fmt.Sprint(classifyNamePath, "|", item.ClassifyName)
  62. classifyIdPath = fmt.Sprint(classifyIdPath, ",", item.ClassifyId)
  63. }
  64. err := data_manage.UpdateEdbClassify(item.ClassifyId, classifyNamePath, classifyIdPath)
  65. if err != nil {
  66. fmt.Println(item.ClassifyId, ";更新失败", err)
  67. }
  68. if item.Children != nil {
  69. for _, v := range item.Children {
  70. updateEdbPath(v, classifyNamePath, classifyIdPath)
  71. }
  72. }
  73. }
  74. // initFixSelfEdbClassify
  75. // @Description: initFixUserClassify
  76. // @author: Roc
  77. // @datetime 2024-11-29 16:57:54
  78. func initFixSelfEdbClassify(classifyType int) {
  79. // 指标数据明细
  80. condition := ` AND edb_info_type = 0 and edb_type = 2 `
  81. if classifyType == utils.EdbClassifyTypePredict {
  82. condition = ` AND edb_info_type = 1 `
  83. }
  84. pars := make([]interface{}, 0)
  85. edbList, err := data_manage.GetEdbInfoListByCond(condition, pars)
  86. if err != nil {
  87. fmt.Println("查找指标加工数据失败", err.Error())
  88. return
  89. }
  90. edbClassifyIdMap := make(map[int]bool)
  91. classifyIdList := make([]int, 0)
  92. edbUserMap := make(map[int]string)
  93. for _, v := range edbList {
  94. if _, ok := edbClassifyIdMap[v.ClassifyId]; !ok {
  95. classifyIdList = append(classifyIdList, v.ClassifyId)
  96. edbClassifyIdMap[v.ClassifyId] = true
  97. }
  98. edbUserMap[v.SysUserId] = v.SysUserRealName
  99. }
  100. // 获取所有数据加工的分类
  101. classifyList, err := data_manage.GetAllEdbClassifyByType(classifyType, 0)
  102. if err != nil {
  103. fmt.Println("获取数据加工分类失败", err.Error())
  104. return
  105. }
  106. hasClassifyIdStrList := make([]string, 0)
  107. for _, v := range classifyList {
  108. // 判断当前分类id是否加到指标中,如果加进去了,那么才处理
  109. _, ok := edbClassifyIdMap[v.ClassifyId]
  110. if !ok {
  111. continue
  112. }
  113. hasClassifyIdStrList = append(hasClassifyIdStrList, v.ClassifyIdPath)
  114. }
  115. classifyIdStrList := make([]string, 0)
  116. if len(hasClassifyIdStrList) > 0 {
  117. classifyIdStrList = strings.Split(strings.Join(hasClassifyIdStrList, ","), ",")
  118. }
  119. classifyIdMap := make(map[string]bool)
  120. for _, v := range classifyIdStrList {
  121. classifyIdMap[v] = true
  122. }
  123. newClassifyList := make([]*data_manage.EdbClassifyItems, 0)
  124. newClassifyMap := make(map[string]bool)
  125. for _, v := range classifyList {
  126. classifyIdStr := fmt.Sprint(v.ClassifyId)
  127. // 是否在关联指标的map里面,如果不在的话,那么就过滤
  128. _, ok := classifyIdMap[classifyIdStr]
  129. if !ok {
  130. continue
  131. }
  132. // 是否已经加到需要关联指标分类的map里面,如果已经在了,那么也过滤
  133. _, ok = newClassifyMap[classifyIdStr]
  134. if ok {
  135. continue
  136. }
  137. newClassifyMap[classifyIdStr] = true
  138. newClassifyList = append(newClassifyList, v)
  139. }
  140. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType), 0)
  141. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  142. for k := range rootList {
  143. rootNode := rootList[k]
  144. data.EdbClassifyItemsMakeTree(newClassifyList, rootNode)
  145. nodeAll = append(nodeAll, rootNode)
  146. }
  147. // 创建新的分类
  148. // [用户id][原分类id][新分类id]
  149. userClassifyIdMap := make(map[int]map[int]int)
  150. for userId, sysUserName := range edbUserMap {
  151. classifyRelationMap := make(map[int]int)
  152. for _, v := range nodeAll {
  153. createNewEdbClassify(userId, 0, 0, 0, sysUserName, ``, ``, v, classifyRelationMap)
  154. }
  155. userClassifyIdMap[userId] = classifyRelationMap
  156. }
  157. // ##### 第二步,指标数据迁移
  158. // 指标数据迁移
  159. for _, v := range edbList {
  160. userClassifyMap, ok := userClassifyIdMap[v.SysUserId]
  161. if !ok {
  162. fmt.Println("找不到该用户所属的分类,userId:", v.SysUserId)
  163. continue
  164. }
  165. newClassifyId, ok := userClassifyMap[v.ClassifyId]
  166. if !ok {
  167. fmt.Println("找不到该用户所属的分类,classifyId:", v.ClassifyId)
  168. continue
  169. }
  170. // 开始迁移指标数据
  171. err = data_manage.UpdateClassifyIdByEdbInfoId(v.EdbInfoId, newClassifyId)
  172. if err != nil {
  173. fmt.Println("指标数据迁移失败", err.Error())
  174. }
  175. }
  176. // ##### 3、开始删除没有指标的分类
  177. deleteNullEdbClassify(classifyType)
  178. return
  179. }
  180. func deleteNullEdbClassify(classifyType int) {
  181. // 指标列表数据
  182. condition := ` AND edb_info_type = 0 and edb_type = 2 `
  183. if classifyType == utils.EdbClassifyTypePredict {
  184. condition = ` AND edb_info_type = 1 `
  185. }
  186. pars := make([]interface{}, 0)
  187. edbList, err := data_manage.GetEdbInfoListByCond(condition, pars)
  188. if err != nil {
  189. fmt.Println("查找指标加工数据失败", err.Error())
  190. return
  191. }
  192. edbClassifyIdMap := make(map[int]bool)
  193. classifyIdList := make([]int, 0)
  194. for _, v := range edbList {
  195. if _, ok := edbClassifyIdMap[v.ClassifyId]; !ok {
  196. classifyIdList = append(classifyIdList, v.ClassifyId)
  197. edbClassifyIdMap[v.ClassifyId] = true
  198. }
  199. }
  200. // 获取所有数据加工的分类
  201. classifyList, err := data_manage.GetAllEdbClassifyByType(classifyType, 0)
  202. if err != nil {
  203. fmt.Println("获取数据加工分类失败", err.Error())
  204. return
  205. }
  206. // 存在指标的分类
  207. hasEdbClassifyList := make([]*data_manage.EdbClassifyItems, 0)
  208. for _, v := range classifyList {
  209. if _, ok := edbClassifyIdMap[v.ClassifyId]; ok {
  210. hasEdbClassifyList = append(hasEdbClassifyList, v)
  211. }
  212. }
  213. // 待删除的分类id集合
  214. deleteClassifyIdMap := make(map[int]int)
  215. // 全部的分类id集合
  216. for _, v := range classifyList {
  217. deleteClassifyIdMap[v.ClassifyId] = v.ClassifyId
  218. }
  219. // 存在指标的的分类id集合
  220. hasClassifyIdStrList := make([]string, 0)
  221. for _, v := range hasEdbClassifyList {
  222. hasClassifyIdStrList = append(hasClassifyIdStrList, v.ClassifyIdPath)
  223. }
  224. classifyIdStrList := make([]string, 0)
  225. if len(hasClassifyIdStrList) > 0 {
  226. classifyIdStrList = strings.Split(strings.Join(hasClassifyIdStrList, ","), ",")
  227. }
  228. for _, v := range classifyIdStrList {
  229. classifyId, err := strconv.Atoi(v)
  230. if err != nil {
  231. fmt.Println("分类字符串转int失败,", err.Error())
  232. return
  233. }
  234. delete(deleteClassifyIdMap, classifyId)
  235. }
  236. // 删除空分类
  237. if len(deleteClassifyIdMap) > 0 {
  238. deleteClassifyIdList := make([]int, 0)
  239. for _, v := range deleteClassifyIdMap {
  240. deleteClassifyIdList = append(deleteClassifyIdList, v)
  241. }
  242. err = data_manage.DelEdbClassifyByIdList(deleteClassifyIdList)
  243. if err != nil {
  244. fmt.Println("删除空分类失败", err.Error())
  245. return
  246. }
  247. }
  248. }
  249. // createNewEdbClassify
  250. // @Description: 创建分类
  251. // @author: Roc
  252. // @datetime 2024-11-29 17:57:47
  253. // @param userId int
  254. // @param parentId int
  255. // @param rootId int
  256. // @param level int
  257. // @param sysUserName string
  258. // @param parentClassifyNamePath string
  259. // @param parentClassifyIdPath string
  260. // @param node *data_manage.EdbClassifyItems
  261. // @param classifyRelationMap map[int]int
  262. func createNewEdbClassify(userId, parentId, rootId, level int, sysUserName, parentClassifyNamePath, parentClassifyIdPath string, node *data_manage.EdbClassifyItems, classifyRelationMap map[int]int) {
  263. var classifyNamePath, classifyIdPath string
  264. if parentId > 0 {
  265. classifyNamePath = fmt.Sprint(parentClassifyNamePath, "|", node.ClassifyName)
  266. classifyIdPath = fmt.Sprint(parentClassifyIdPath, ",")
  267. } else {
  268. classifyNamePath = node.ClassifyName
  269. }
  270. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  271. classifyInfo := &data_manage.EdbClassify{
  272. //ClassifyId: 0,
  273. ClassifyType: node.ClassifyType,
  274. ClassifyName: node.ClassifyName,
  275. ClassifyNameEn: node.ClassifyNameEn,
  276. ParentId: parentId,
  277. RootId: rootId,
  278. HasData: 1,
  279. CreateTime: time.Now(),
  280. ModifyTime: time.Now(),
  281. SysUserId: userId,
  282. SysUserRealName: sysUserName,
  283. Level: level + 1,
  284. UniqueCode: utils.MD5(utils.DATA_PREFIX + "_" + timestamp),
  285. Sort: node.Sort,
  286. ClassifyNamePath: classifyNamePath,
  287. }
  288. err := data_manage.AddEdbClassify(classifyInfo)
  289. if err != nil {
  290. fmt.Println("创建分类失败:", err.Error())
  291. return
  292. }
  293. updateCols := []string{"ClassifyIdPath"}
  294. // 更改分类id完整路径path
  295. classifyInfo.ClassifyIdPath = fmt.Sprint(classifyIdPath, classifyInfo.ClassifyId)
  296. if rootId <= 0 {
  297. rootId = classifyInfo.ClassifyId
  298. classifyInfo.RootId = classifyInfo.ClassifyId
  299. updateCols = append(updateCols, "RootId")
  300. }
  301. _ = classifyInfo.Update(updateCols)
  302. classifyRelationMap[node.ClassifyId] = classifyInfo.ClassifyId
  303. level = classifyInfo.Level
  304. if node.Children == nil {
  305. return
  306. }
  307. if len(node.Children) <= 0 {
  308. return
  309. }
  310. for _, child := range node.Children {
  311. createNewEdbClassify(userId, classifyInfo.ClassifyId, rootId, level, sysUserName, classifyNamePath, classifyInfo.ClassifyIdPath, child, classifyRelationMap)
  312. }
  313. return
  314. }
  315. // initFixChartClassifyPath
  316. // @Description: 修复图表分类完整路径
  317. // @author: Roc
  318. // @datetime 2024-11-26 15:40:57
  319. func initFixChartClassifyPath() {
  320. fmt.Println("开始修复图表分类路径,请稍等...")
  321. allList := make([]*data_manage.ChartClassifyItems, 0)
  322. allList, e := data_manage.GetAllChartClassify()
  323. if e != nil {
  324. fmt.Println("获取分类失败", e)
  325. return
  326. }
  327. allList = data.GetChartClassifyTreeRecursive(allList, 0)
  328. //根据sort值排序
  329. for _, v := range allList {
  330. updateChartPath(v, "", "")
  331. }
  332. fmt.Println("修复图表分类路径完成")
  333. }
  334. // initFixSelfChartClassify
  335. // @Description: 修复用户图表分类信息
  336. // @author: Roc
  337. // @datetime 2024-11-29 16:57:54
  338. func initFixSelfChartClassify() {
  339. fmt.Println("修复用户图表分类信息开始,请稍后...")
  340. // 图表数据明细
  341. condition := ``
  342. pars := make([]interface{}, 0)
  343. chartList, err := data_manage.GetChartListByCondition(condition, pars, 0, 1000000)
  344. if err != nil {
  345. fmt.Println("查找用户图表列表数据失败", err.Error())
  346. return
  347. }
  348. chartClassifyIdMap := make(map[int]bool)
  349. classifyIdList := make([]int, 0)
  350. edbUserMap := make(map[int]string)
  351. for _, v := range chartList {
  352. if _, ok := chartClassifyIdMap[v.ChartClassifyId]; !ok {
  353. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  354. chartClassifyIdMap[v.ChartClassifyId] = true
  355. }
  356. edbUserMap[v.SysUserId] = v.SysUserRealName
  357. }
  358. // 获取所有图表的分类
  359. classifyList, err := data_manage.GetAllChartClassify()
  360. if err != nil {
  361. fmt.Println("获取图表分类失败", err.Error())
  362. return
  363. }
  364. hasClassifyIdStrList := make([]string, 0)
  365. for _, v := range classifyList {
  366. // 判断当前分类id是否加到指标中,如果加进去了,那么才处理
  367. _, ok := chartClassifyIdMap[v.ChartClassifyId]
  368. if !ok {
  369. continue
  370. }
  371. hasClassifyIdStrList = append(hasClassifyIdStrList, v.ChartClassifyIdPath)
  372. }
  373. classifyIdStrList := make([]string, 0)
  374. if len(hasClassifyIdStrList) > 0 {
  375. classifyIdStrList = strings.Split(strings.Join(hasClassifyIdStrList, ","), ",")
  376. }
  377. classifyIdMap := make(map[string]bool)
  378. for _, v := range classifyIdStrList {
  379. classifyIdMap[v] = true
  380. }
  381. newClassifyList := make([]*data_manage.ChartClassifyItems, 0)
  382. newClassifyMap := make(map[string]bool)
  383. for _, v := range classifyList {
  384. classifyIdStr := fmt.Sprint(v.ChartClassifyId)
  385. // 是否在关联指标的map里面,如果不在的话,那么就过滤
  386. _, ok := classifyIdMap[classifyIdStr]
  387. if !ok {
  388. continue
  389. }
  390. // 是否已经加到需要关联指标分类的map里面,如果已经在了,那么也过滤
  391. _, ok = newClassifyMap[classifyIdStr]
  392. if ok {
  393. continue
  394. }
  395. newClassifyMap[classifyIdStr] = true
  396. newClassifyList = append(newClassifyList, v)
  397. }
  398. rootList, err := data_manage.GetAllChartClassifyByParentId(0)
  399. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  400. for k := range rootList {
  401. rootNode := rootList[k]
  402. data.ChartClassifyItemsMakeTreeV2(newClassifyList, rootNode)
  403. nodeAll = append(nodeAll, rootNode)
  404. }
  405. // 创建新的分类
  406. // [用户id][原分类id][新分类id]
  407. userClassifyIdMap := make(map[int]map[int]int)
  408. for userId, sysUserName := range edbUserMap {
  409. classifyRelationMap := make(map[int]int)
  410. for _, v := range nodeAll {
  411. createNewChartClassify(userId, 0, 0, 0, sysUserName, ``, ``, v, classifyRelationMap)
  412. }
  413. userClassifyIdMap[userId] = classifyRelationMap
  414. }
  415. // ##### 第二步,图表数据迁移
  416. // 指标数据迁移
  417. for _, v := range chartList {
  418. userClassifyMap, ok := userClassifyIdMap[v.SysUserId]
  419. if !ok {
  420. fmt.Println("找不到该用户所属的分类,userId:", v.SysUserId)
  421. continue
  422. }
  423. newClassifyId, ok := userClassifyMap[v.ChartClassifyId]
  424. if !ok {
  425. fmt.Println("找不到该用户所属的图表分类,classifyId:", v.ChartClassifyId)
  426. continue
  427. }
  428. // 开始迁移指标数据
  429. err = data_manage.UpdateClassifyIdByChartInfoId(v.ChartInfoId, newClassifyId)
  430. if err != nil {
  431. fmt.Println("图表数据迁移失败", err.Error())
  432. }
  433. }
  434. // ##### 3、开始删除没有图表的分类
  435. deleteNullChartClassify()
  436. fmt.Println("修复用户图表分类信息完成")
  437. return
  438. }
  439. func deleteNullChartClassify() {
  440. // 图表数据明细
  441. condition := ``
  442. pars := make([]interface{}, 0)
  443. chartList, err := data_manage.GetChartListByCondition(condition, pars, 0, 1000000)
  444. if err != nil {
  445. fmt.Println("查找指标加工数据失败", err.Error())
  446. return
  447. }
  448. chartClassifyIdMap := make(map[int]bool)
  449. classifyIdList := make([]int, 0)
  450. for _, v := range chartList {
  451. if _, ok := chartClassifyIdMap[v.ChartClassifyId]; !ok {
  452. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  453. chartClassifyIdMap[v.ChartClassifyId] = true
  454. }
  455. }
  456. // 获取所有数据加工的分类
  457. classifyList, err := data_manage.GetAllChartClassify()
  458. if err != nil {
  459. fmt.Println("获取数据加工分类失败", err.Error())
  460. return
  461. }
  462. // 存在图表的分类
  463. hasEdbClassifyList := make([]*data_manage.ChartClassifyItems, 0)
  464. for _, v := range classifyList {
  465. if _, ok := chartClassifyIdMap[v.ChartClassifyId]; ok {
  466. hasEdbClassifyList = append(hasEdbClassifyList, v)
  467. }
  468. }
  469. // 待删除的分类id集合
  470. deleteClassifyIdMap := make(map[int]int)
  471. // 全部的分类id集合
  472. for _, v := range classifyList {
  473. deleteClassifyIdMap[v.ChartClassifyId] = v.ChartClassifyId
  474. }
  475. // 存在指标的的分类id集合
  476. hasClassifyIdStrList := make([]string, 0)
  477. for _, v := range hasEdbClassifyList {
  478. hasClassifyIdStrList = append(hasClassifyIdStrList, v.ChartClassifyIdPath)
  479. }
  480. classifyIdStrList := make([]string, 0)
  481. if len(hasClassifyIdStrList) > 0 {
  482. classifyIdStrList = strings.Split(strings.Join(hasClassifyIdStrList, ","), ",")
  483. }
  484. for _, v := range classifyIdStrList {
  485. classifyId, err := strconv.Atoi(v)
  486. if err != nil {
  487. fmt.Println("分类字符串转int失败,", err.Error())
  488. return
  489. }
  490. delete(deleteClassifyIdMap, classifyId)
  491. }
  492. // 删除空分类
  493. if len(deleteClassifyIdMap) > 0 {
  494. deleteClassifyIdList := make([]int, 0)
  495. for _, v := range deleteClassifyIdMap {
  496. deleteClassifyIdList = append(deleteClassifyIdList, v)
  497. }
  498. err = data_manage.DelChartClassifyByIdList(deleteClassifyIdList)
  499. if err != nil {
  500. fmt.Println("删除空分类失败", err.Error())
  501. return
  502. }
  503. }
  504. }
  505. // createNewChartClassify
  506. // @Description: 创建图表分类
  507. // @author: Roc
  508. // @datetime 2024-11-29 17:57:47
  509. // @param userId int
  510. // @param parentId int
  511. // @param rootId int
  512. // @param level int
  513. // @param sysUserName string
  514. // @param parentClassifyNamePath string
  515. // @param parentClassifyIdPath string
  516. // @param node *data_manage.EdbClassifyItems
  517. // @param classifyRelationMap map[int]int
  518. func createNewChartClassify(userId, parentId, rootId, level int, sysUserName, parentClassifyNamePath, parentClassifyIdPath string, node *data_manage.ChartClassifyItems, classifyRelationMap map[int]int) {
  519. var classifyNamePath, classifyIdPath string
  520. if parentId > 0 {
  521. classifyNamePath = fmt.Sprint(parentClassifyNamePath, "|", node.ChartClassifyName)
  522. classifyIdPath = fmt.Sprint(parentClassifyIdPath, ",")
  523. } else {
  524. classifyNamePath = node.ChartClassifyName
  525. }
  526. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  527. classifyInfo := &data_manage.ChartClassify{
  528. ChartClassifyId: 0,
  529. ChartClassifyName: node.ChartClassifyName,
  530. ParentId: parentId,
  531. HasData: 1,
  532. CreateTime: time.Now(),
  533. ModifyTime: time.Now(),
  534. SysUserId: userId,
  535. SysUserRealName: sysUserName,
  536. Level: level + 1,
  537. UniqueCode: utils.MD5(utils.CHART_PREFIX + "_" + timestamp),
  538. Sort: node.Sort,
  539. Source: node.Source,
  540. //IsJoinPermission: 0,
  541. ChartClassifyNameEn: node.ChartClassifyNameEn,
  542. RootId: rootId,
  543. ChartClassifyNamePath: classifyNamePath,
  544. ChartClassifyIdPath: "",
  545. }
  546. err := data_manage.AddChartClassify(classifyInfo)
  547. if err != nil {
  548. fmt.Println("创建分类失败:", err.Error())
  549. return
  550. }
  551. updateCols := []string{"ChartClassifyIdPath"}
  552. // 更改分类id完整路径path
  553. classifyInfo.ChartClassifyIdPath = fmt.Sprint(classifyIdPath, classifyInfo.ChartClassifyId)
  554. if rootId <= 0 {
  555. rootId = classifyInfo.ChartClassifyId
  556. classifyInfo.RootId = classifyInfo.ChartClassifyId
  557. updateCols = append(updateCols, "RootId")
  558. }
  559. _ = classifyInfo.Update(updateCols)
  560. classifyRelationMap[node.ChartClassifyId] = classifyInfo.ChartClassifyId
  561. level = classifyInfo.Level
  562. if node.Children == nil {
  563. return
  564. }
  565. if len(node.Children) <= 0 {
  566. return
  567. }
  568. for _, child := range node.Children {
  569. createNewChartClassify(userId, classifyInfo.ChartClassifyId, rootId, level, sysUserName, classifyNamePath, classifyInfo.ChartClassifyIdPath, child, classifyRelationMap)
  570. }
  571. return
  572. }
  573. // updateChartPath
  574. // @Description: 更新图表分类的完整路径
  575. // @author: Roc
  576. // @datetime 2024-12-09 10:30:16
  577. // @param item *data_manage.ChartClassifyItems
  578. // @param classifyNamePath string
  579. // @param classifyIdPath string
  580. func updateChartPath(item *data_manage.ChartClassifyItems, classifyNamePath, classifyIdPath string) {
  581. if classifyNamePath == `` {
  582. classifyNamePath = item.ChartClassifyName
  583. classifyIdPath = fmt.Sprint(item.ChartClassifyId)
  584. } else {
  585. classifyNamePath = fmt.Sprint(classifyNamePath, "|", item.ChartClassifyName)
  586. classifyIdPath = fmt.Sprint(classifyIdPath, ",", item.ChartClassifyId)
  587. }
  588. err := data_manage.UpdateChartClassify(item.ChartClassifyId, classifyNamePath, classifyIdPath)
  589. if err != nil {
  590. fmt.Println(item.ChartClassifyId, ";更新失败", err)
  591. }
  592. if item.Children != nil {
  593. for _, v := range item.Children {
  594. updateChartPath(v, classifyNamePath, classifyIdPath)
  595. }
  596. }
  597. }
  598. // initEs
  599. // @Description: 修复ES中的指标和图表数据
  600. // @author: Roc
  601. // @datetime 2024-11-29 16:18:02
  602. func initEs() {
  603. // 更新ES中的指标数据
  604. //data.AddOrEditAllEdbInfoToEs()
  605. // 更新es中的图表数据
  606. data.AddAllChartInfo()
  607. fmt.Println("全部es数据修复完成")
  608. }