fix.go 20 KB

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