chart_classify.go 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. package data
  2. import (
  3. "errors"
  4. "eta/eta_api/models/data_manage"
  5. "eta/eta_api/models/system"
  6. "eta/eta_api/services/data/data_manage_permission"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "strconv"
  10. "time"
  11. )
  12. func chartClassifyHaveChild(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) (childs []*data_manage.ChartClassifyItems, yes bool) {
  13. for _, v := range allNode {
  14. if v.ParentId == node.ChartClassifyId {
  15. childs = append(childs, v)
  16. }
  17. }
  18. if len(childs) > 0 {
  19. yes = true
  20. }
  21. return
  22. }
  23. func ChartClassifyItemsMakeTree(sysUser *system.Admin, allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems, permissionClassifyIdList []int, level int) {
  24. node.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(node.IsJoinPermission, node.ChartClassifyId, permissionClassifyIdList)
  25. button := GetChartClassifyOpButton(sysUser, node.SysUserId, node.HaveOperaAuth)
  26. node.Button = button
  27. node.Disable = true
  28. if node.Level == level {
  29. node.Disable = false
  30. }
  31. childs, _ := chartClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  32. if len(childs) > 0 {
  33. for _, child := range childs {
  34. child.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(child.IsJoinPermission, child.ChartClassifyId, permissionClassifyIdList)
  35. childButton := GetChartClassifyOpButton(sysUser, child.SysUserId, child.HaveOperaAuth)
  36. if child.Level == 6 {
  37. childButton.AddButton = false //第六级的话,默认图表都是没有添加按钮的
  38. }
  39. child.Disable = true
  40. if child.Level == level {
  41. child.Disable = false
  42. }
  43. child.Button = childButton
  44. //node.Children = append(node.Children, child)
  45. }
  46. node.Children = append(node.Children, childs[0:]...) //添加子节点
  47. for _, v := range childs {
  48. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ChartClassifyId, permissionClassifyIdList)
  49. //查询子节点的子节点,并添加到子节点
  50. _, has := chartClassifyHaveChild(allNode, v)
  51. if has {
  52. ChartClassifyItemsMakeTree(sysUser, allNode, v, permissionClassifyIdList, level) //递归添加节点
  53. } else {
  54. if level > 0 {
  55. v.Children = nil
  56. } else {
  57. childrenArr := make([]*data_manage.ChartClassifyItems, 0)
  58. v.Children = childrenArr
  59. }
  60. }
  61. }
  62. } else {
  63. if level > 0 {
  64. node.Children = nil
  65. } else {
  66. childrenArr := make([]*data_manage.ChartClassifyItems, 0)
  67. node.Children = childrenArr
  68. }
  69. }
  70. }
  71. func FixChartClassify() {
  72. //新增三级分类
  73. list, err := data_manage.GetChartClassifyByLevel(2, 1)
  74. if err != nil {
  75. return
  76. }
  77. for _, v := range list {
  78. classify := new(data_manage.ChartClassify)
  79. classify.ParentId = v.ChartClassifyId
  80. classify.ChartClassifyName = v.ChartClassifyName
  81. classify.HasData = 0
  82. classify.CreateTime = time.Now()
  83. classify.ModifyTime = time.Now()
  84. if utils.RunMode == "debug" {
  85. classify.SysUserId = 11
  86. } else {
  87. classify.SysUserId = 163
  88. }
  89. classify.SysUserRealName = "admin"
  90. classify.Level = 3
  91. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  92. classify.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  93. classify.Sort = v.Sort
  94. classify.Source = utils.CHART_SOURCE_DEFAULT
  95. id, err := data_manage.AddChartClassify(classify)
  96. if err != nil {
  97. return
  98. }
  99. err = data_manage.FIXChartClassifyId(int(id), v.ChartClassifyId)
  100. if err != nil {
  101. return
  102. }
  103. }
  104. }
  105. func FixChartClassifySysUserId() {
  106. //获取所有父级分类信息
  107. list, err := data_manage.GetChartClassifyByLevel(2, 1)
  108. if err != nil {
  109. return
  110. }
  111. for _, v := range list {
  112. err := data_manage.EditChartClassifySysUser(v.ChartClassifyId, v.SysUserId, v.SysUserRealName)
  113. if err != nil {
  114. return
  115. }
  116. fmt.Println("ChartClassifyId:", v.ChartClassifyId)
  117. }
  118. fmt.Println("FixChartClassifySysUserId end")
  119. }
  120. // GetChartClassifyOpButton 获取ETA图库分类的操作权限
  121. func GetChartClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.ChartClassifyItemsButton) {
  122. // 没有数据权限就直接返回
  123. if !haveOperaAuth {
  124. return
  125. }
  126. //ficc管理员和超管和ficc研究员有权限创建和管理分类,可以编辑分类名称(分类名称不允许重复),可以拖动分类,改变分类顺序,可以拖动分类下模型,改变顺序,可以删除分类,若分类下有预测指标,则不允许删除;
  127. //if utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RESEARCHR, utils.ROLE_TYPE_CODE_FICC_RESEARCHR}, sysUser.RoleTypeCode) {
  128. button.AddButton = true
  129. button.OpButton = true
  130. button.DeleteButton = true
  131. button.MoveButton = true
  132. //}
  133. return
  134. }
  135. // GetCanOpChartClassify 获取是否允许添加图表分类
  136. func GetCanOpChartClassify(roleTypeCode string) (canOpClassify bool) {
  137. // 如果不是 超管 或者 ficc管理员 或者 ficc研究员,那么就没有权限
  138. if utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RESEARCHR, utils.ROLE_TYPE_CODE_FICC_RESEARCHR}, roleTypeCode) {
  139. canOpClassify = true
  140. }
  141. return
  142. }
  143. // GetChartOpButton 获取ETA图库的操作权限
  144. func GetChartOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.ChartClassifyItemsButton) {
  145. // 数据权限判断
  146. if !haveOperaAuth {
  147. return
  148. }
  149. //预测指标的添加人对该预测指标有全部操作权限,ficc管理员、超管对所有预测指标有全部操作权限;
  150. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.PredictEdbPermission == 1 {
  151. button.AddButton = true
  152. button.OpButton = true
  153. button.DeleteButton = true
  154. button.MoveButton = true
  155. }
  156. return
  157. }
  158. // HandleNoPermissionChart 图表列表返回,将没有权限的图表移除
  159. func HandleNoPermissionChart(allNodes []*data_manage.ChartClassifyItems, noPermissionChartIdMap map[int]bool, sysUserId int) (newAllNodes []*data_manage.ChartClassifyItems) {
  160. // 涉及分类id
  161. classifyIdList := make([]int, 0)
  162. // 移除没有权限的图表
  163. newAllNodes = make([]*data_manage.ChartClassifyItems, 0)
  164. for _, node := range allNodes {
  165. // 二级分类
  166. tmpNodeInfo := *node
  167. tmpNodeList := make([]*data_manage.ChartClassifyItems, 0)
  168. if node.Children != nil {
  169. for _, chartInfo := range node.Children {
  170. // 如果指标不可见,那么就不返回该指标
  171. if _, ok := noPermissionChartIdMap[chartInfo.ChartInfoId]; ok {
  172. continue
  173. }
  174. tmpNodeList = append(tmpNodeList, chartInfo)
  175. classifyIdList = append(classifyIdList, chartInfo.ChartClassifyId)
  176. }
  177. }
  178. tmpNodeInfo.Children = tmpNodeList
  179. newAllNodes = append(newAllNodes, &tmpNodeInfo)
  180. classifyIdList = append(classifyIdList, node.ChartClassifyId)
  181. }
  182. // 数据权限
  183. if len(classifyIdList) > 0 {
  184. // 图表分类
  185. chartClassifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  186. if err != nil {
  187. return
  188. }
  189. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  190. for _, v := range chartClassifyList {
  191. chartClassifyMap[v.ChartClassifyId] = v
  192. }
  193. // 已授权分类id
  194. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUserId, 0, 0)
  195. if err != nil {
  196. return
  197. }
  198. for _, node := range newAllNodes {
  199. if node.Children != nil {
  200. for _, chartInfo := range node.Children {
  201. if currClassify, ok := chartClassifyMap[chartInfo.ChartClassifyId]; ok {
  202. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, currClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  203. }
  204. }
  205. }
  206. if currClassify, ok := chartClassifyMap[node.ChartClassifyId]; ok {
  207. node.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(node.IsJoinPermission, currClassify.IsJoinPermission, node.ChartInfoId, node.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  208. }
  209. }
  210. }
  211. return
  212. }
  213. // AddChartClassify
  214. // @Description: 添加图表分类
  215. // @author: Roc
  216. // @datetime 2024-04-17 14:48:23
  217. // @param chartClassifyName string
  218. // @param parentId int
  219. // @param level int
  220. // @param source int
  221. // @param lang string
  222. // @param sysUser *system.Admin
  223. // @return classifyInfo *data_manage.ChartClassify
  224. // @return err error
  225. // @return errMsg string
  226. // @return isSendEmail bool
  227. func AddChartClassify(chartClassifyName string, parentId, level, source int, lang string, sysUser *system.Admin) (classifyInfo *data_manage.ChartClassify, err error, errMsg string, isSendEmail bool) {
  228. isSendEmail = true
  229. errMsg = "保存分类失败"
  230. // 校验分类名称相同的数量
  231. {
  232. var count int
  233. switch lang {
  234. case utils.EnLangVersion:
  235. count, err = data_manage.GetChartClassifyEnCount(chartClassifyName, parentId, source)
  236. default:
  237. count, err = data_manage.GetChartClassifyCount(chartClassifyName, parentId, source)
  238. }
  239. if err != nil {
  240. errMsg = "判断名称是否已存在失败"
  241. return
  242. }
  243. if count > 0 {
  244. errMsg = "分类名称已存在,请重新输入"
  245. err = errors.New(errMsg)
  246. isSendEmail = false
  247. return
  248. }
  249. }
  250. if level > 5 {
  251. errMsg = `最高只支持添加6级分类`
  252. return
  253. }
  254. //获取该层级下最大的排序数
  255. maxSort, err := data_manage.GetChartClassifyMaxSort(parentId, source)
  256. if err != nil {
  257. errMsg = "获取失败"
  258. err = errors.New("查询排序信息失败,Err:" + err.Error())
  259. return
  260. }
  261. //查询顶级rootId
  262. rootId := 0
  263. if parentId > 0 {
  264. parentClassify, tErr := data_manage.GetChartClassifyById(parentId)
  265. if tErr != nil {
  266. if tErr.Error() == utils.ErrNoRow() {
  267. errMsg = "父级分类不存在"
  268. err = errors.New(errMsg)
  269. return
  270. }
  271. errMsg = "获取失败"
  272. err = errors.New("获取分类信息失败,Err:" + tErr.Error())
  273. return
  274. }
  275. rootId = parentClassify.RootId
  276. }
  277. classifyInfo = new(data_manage.ChartClassify)
  278. classifyInfo.ParentId = parentId
  279. classifyInfo.ChartClassifyName = chartClassifyName
  280. classifyInfo.ChartClassifyNameEn = chartClassifyName
  281. classifyInfo.HasData = 0
  282. classifyInfo.CreateTime = time.Now()
  283. classifyInfo.ModifyTime = time.Now()
  284. classifyInfo.SysUserId = sysUser.AdminId
  285. classifyInfo.SysUserRealName = sysUser.RealName
  286. classifyInfo.Level = level + 1
  287. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  288. classifyInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  289. classifyInfo.Sort = maxSort + 1
  290. classifyInfo.Source = source
  291. classifyInfo.RootId = rootId
  292. newId, err := data_manage.AddChartClassify(classifyInfo)
  293. if err != nil {
  294. return
  295. }
  296. if parentId == 0 { //一级目录的rootId等于自己本身
  297. classifyInfo.RootId = int(newId)
  298. err = classifyInfo.Update([]string{"RootId"})
  299. if err != nil {
  300. errMsg = "更新分类失败"
  301. return
  302. }
  303. }
  304. // 目前只有ETA图库需要继承分类权限
  305. if classifyInfo.Source == utils.CHART_SOURCE_DEFAULT {
  306. go data_manage_permission.InheritParentClassify(5, classifyInfo.Source, classifyInfo.ChartClassifyId, classifyInfo.ParentId, classifyInfo.ChartClassifyName)
  307. }
  308. return
  309. }
  310. // EditChartClassify
  311. // @Description: 修改图表分类
  312. // @author: Roc
  313. // @datetime 2024-04-17 14:59:37
  314. // @param chartClassifyId int
  315. // @param source int
  316. // @param chartClassifyName string
  317. // @param lang string
  318. // @param sysUser *system.Admin
  319. // @return classifyInfo *data_manage.ChartClassify
  320. // @return err error
  321. // @return errMsg string
  322. // @return isSendEmail bool
  323. func EditChartClassify(chartClassifyId, source int, chartClassifyName, lang string, sysUser *system.Admin) (classifyInfo *data_manage.ChartClassify, err error, errMsg string, isSendEmail bool) {
  324. isSendEmail = true
  325. errMsg = "保存失败"
  326. // 获取分类信息
  327. classifyInfo, err = data_manage.GetChartClassifyById(chartClassifyId)
  328. if err != nil {
  329. return
  330. }
  331. // 分类来源校验
  332. if classifyInfo.Source != source {
  333. errMsg = "图表分类异常"
  334. err = errors.New(fmt.Sprintf("图表分类来源异常,修改来源:%d,分类来源:%d", source, classifyInfo.Source))
  335. isSendEmail = false
  336. return
  337. }
  338. // 需要变更的字段
  339. updateCols := make([]string, 0)
  340. // 语言版本校验
  341. switch lang {
  342. case utils.EnLangVersion:
  343. if classifyInfo.ChartClassifyNameEn != chartClassifyName {
  344. count, tmpErr := data_manage.GetChartClassifyEnCount(chartClassifyName, classifyInfo.ParentId, source)
  345. if tmpErr != nil {
  346. errMsg = "判断名称是否已存在失败"
  347. err = errors.New("判断名称是否已存在失败,Err:" + tmpErr.Error())
  348. return
  349. }
  350. if count > 0 {
  351. errMsg = "分类名称已存在,请重新输入"
  352. err = errors.New(errMsg)
  353. isSendEmail = false
  354. return
  355. }
  356. classifyInfo.ChartClassifyNameEn = chartClassifyName
  357. classifyInfo.ModifyTime = time.Now()
  358. updateCols = append(updateCols, "ChartClassifyNameEn", "ModifyTime")
  359. }
  360. default:
  361. if classifyInfo.ChartClassifyName != chartClassifyName {
  362. count, tmpErr := data_manage.GetChartClassifyCount(chartClassifyName, classifyInfo.ParentId, source)
  363. if tmpErr != nil {
  364. errMsg = "判断名称是否已存在失败"
  365. err = errors.New("判断名称是否已存在失败,Err:" + tmpErr.Error())
  366. return
  367. }
  368. if count > 0 {
  369. errMsg = "分类名称已存在,请重新输入"
  370. err = errors.New(errMsg)
  371. isSendEmail = false
  372. return
  373. }
  374. classifyInfo.ChartClassifyName = chartClassifyName
  375. classifyInfo.ModifyTime = time.Now()
  376. updateCols = append(updateCols, "ChartClassifyName", "ModifyTime")
  377. }
  378. }
  379. if len(updateCols) > 0 {
  380. err = classifyInfo.Update(updateCols)
  381. }
  382. return
  383. }
  384. // MoveChartClassify 移动图表分类
  385. func MoveChartClassify(req data_manage.MoveChartClassifyReq, sysUser *system.Admin, source int) (err error, errMsg string) {
  386. classifyId := req.ClassifyId
  387. parentClassifyId := req.ParentClassifyId
  388. prevClassifyId := req.PrevClassifyId
  389. nextClassifyId := req.NextClassifyId
  390. chartInfoId := req.ChartInfoId
  391. prevChartInfoId := req.PrevChartInfoId
  392. nextChartInfoId := req.NextChartInfoId
  393. //首先确定移动的对象是分类还是指标
  394. //判断上一个节点是分类还是指标
  395. //判断下一个节点是分类还是指标
  396. //同时更新分类目录下的分类sort和指标sort
  397. //更新当前移动的分类或者指标sort
  398. var parentChartClassifyInfo *data_manage.ChartClassify
  399. if parentClassifyId > 0 {
  400. parentChartClassifyInfo, err = data_manage.GetChartClassifyById(parentClassifyId)
  401. if err != nil {
  402. errMsg = "移动失败"
  403. err = errors.New("获取上级分类信息失败,Err:" + err.Error())
  404. return
  405. }
  406. }
  407. //如果有传入 上一个兄弟节点分类id
  408. var (
  409. chartClassifyInfo *data_manage.ChartClassify
  410. prevClassify *data_manage.ChartClassify
  411. nextClassify *data_manage.ChartClassify
  412. chartInfo *data_manage.ChartInfo
  413. prevChartInfo *data_manage.ChartInfo
  414. nextChartInfo *data_manage.ChartInfo
  415. prevSort int
  416. nextSort int
  417. )
  418. // 移动对象为分类, 判断权限
  419. if chartInfoId == 0 {
  420. chartClassifyInfo, err = data_manage.GetChartClassifyById(classifyId)
  421. if err != nil {
  422. if err.Error() == utils.ErrNoRow() {
  423. errMsg = "当前分类不存在"
  424. err = errors.New("获取分类信息失败,Err:" + err.Error())
  425. return
  426. }
  427. errMsg = "移动失败"
  428. err = errors.New("获取分类信息失败,Err:" + err.Error())
  429. return
  430. }
  431. if parentClassifyId > 0 && parentChartClassifyInfo.Level == 6 {
  432. errMsg = "最高只支持添加6级分类"
  433. err = errors.New(errMsg)
  434. return
  435. }
  436. // 如果是移动目录, 那么校验一下父级目录下是否有重名目录
  437. exists, e := data_manage.GetChartClassifyByParentIdAndName(parentClassifyId, chartClassifyInfo.ChartClassifyName, classifyId)
  438. if e != nil && e.Error() != utils.ErrNoRow() {
  439. errMsg = "移动失败"
  440. err = fmt.Errorf("获取父级分类下的同名分类失败, Err: %s", e.Error())
  441. return
  442. }
  443. if exists != nil {
  444. errMsg = "移动失败,分类名称已存在"
  445. return
  446. }
  447. // 权限校验
  448. {
  449. // 已授权分类id
  450. permissionClassifyIdList, tmpErr := data_manage_permission.GetUserChartClassifyPermissionList(sysUser.AdminId, classifyId)
  451. if tmpErr != nil {
  452. errMsg = "移动失败"
  453. err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
  454. return
  455. }
  456. // 数据权限
  457. haveOperaAuth := data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(chartClassifyInfo.IsJoinPermission, chartClassifyInfo.ChartClassifyId, permissionClassifyIdList)
  458. button := GetChartClassifyOpButton(sysUser, chartClassifyInfo.SysUserId, haveOperaAuth)
  459. if !button.MoveButton {
  460. errMsg = "无操作权限"
  461. err = errors.New(errMsg)
  462. return
  463. }
  464. }
  465. } else {
  466. chartInfo, err = data_manage.GetChartInfoById(req.ChartInfoId)
  467. if err != nil {
  468. if err.Error() == utils.ErrNoRow() {
  469. errMsg = "当前图表不存在"
  470. err = errors.New("获取分类信息失败,Err:" + err.Error())
  471. return
  472. }
  473. errMsg = "移动失败"
  474. err = errors.New("获取分类信息失败,Err:" + err.Error())
  475. return
  476. }
  477. if parentClassifyId == 0 {
  478. errMsg = "移动失败,图表必须挂在分类下"
  479. err = errors.New(errMsg)
  480. return
  481. }
  482. var haveOperaAuth bool
  483. // 权限校验
  484. {
  485. haveOperaAuth, err = data_manage_permission.CheckChartPermissionByChartInfoId(chartInfo.ChartInfoId, chartInfo.ChartClassifyId, chartInfo.IsJoinPermission, sysUser.AdminId)
  486. if err != nil {
  487. errMsg = "移动失败"
  488. err = errors.New("获取图表权限信息失败,Err:" + err.Error())
  489. return
  490. }
  491. }
  492. // 移动权限校验
  493. button := GetChartOpButton(sysUser, chartInfo.SysUserId, haveOperaAuth)
  494. if !button.MoveButton {
  495. errMsg = "无操作权限"
  496. err = errors.New(errMsg)
  497. return
  498. }
  499. }
  500. if prevClassifyId > 0 {
  501. prevClassify, err = data_manage.GetChartClassifyById(prevClassifyId)
  502. if err != nil {
  503. errMsg = "移动失败"
  504. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  505. return
  506. }
  507. prevSort = prevClassify.Sort
  508. } else if prevChartInfoId > 0 {
  509. prevChartInfo, err = data_manage.GetChartInfoById(prevChartInfoId)
  510. if err != nil {
  511. errMsg = "移动失败"
  512. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  513. return
  514. }
  515. prevSort = prevChartInfo.Sort
  516. }
  517. if nextClassifyId > 0 {
  518. //下一个兄弟节点
  519. nextClassify, err = data_manage.GetChartClassifyById(nextClassifyId)
  520. if err != nil {
  521. errMsg = "移动失败"
  522. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  523. return
  524. }
  525. nextSort = nextClassify.Sort
  526. } else if nextChartInfoId > 0 {
  527. //下一个兄弟节点
  528. nextChartInfo, err = data_manage.GetChartInfoById(nextChartInfoId)
  529. if err != nil {
  530. errMsg = "移动失败"
  531. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  532. return
  533. }
  534. nextSort = nextChartInfo.Sort
  535. }
  536. err, errMsg = moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify, chartInfo, prevChartInfo, nextChartInfo, parentClassifyId, prevSort, nextSort, source)
  537. return
  538. }
  539. // moveChartClassify 移动图表分类
  540. func moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify *data_manage.ChartClassify, chartInfo, prevChartInfo, nextChartInfo *data_manage.ChartInfo, parentClassifyId, prevSort, nextSort, source int) (err error, errMsg string) {
  541. updateCol := make([]string, 0)
  542. // 移动对象为分类, 判断分类是否存在
  543. if chartClassifyInfo != nil {
  544. oldParentId := chartClassifyInfo.ParentId
  545. oldLevel := chartClassifyInfo.Level
  546. var classifyIds []int
  547. if oldParentId != parentClassifyId {
  548. //更新子分类对应的level
  549. childList, e, m := GetChildChartClassifyByClassifyId(chartClassifyInfo.ChartClassifyId)
  550. if e != nil {
  551. errMsg = "移动失败"
  552. err = errors.New("查询子分类失败,Err:" + e.Error() + m)
  553. return
  554. }
  555. if len(childList) > 0 {
  556. for _, v := range childList {
  557. if v.ChartClassifyId == chartClassifyInfo.ChartClassifyId {
  558. continue
  559. }
  560. classifyIds = append(classifyIds, v.ChartClassifyId)
  561. }
  562. }
  563. }
  564. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  565. if chartClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
  566. if chartClassifyInfo.Level != parentChartClassifyInfo.Level+1 { //禁止层级调整
  567. errMsg = "移动失败"
  568. err = errors.New("不支持目录层级变更")
  569. return
  570. }
  571. chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  572. chartClassifyInfo.RootId = parentChartClassifyInfo.RootId
  573. chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  574. chartClassifyInfo.ModifyTime = time.Now()
  575. updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
  576. } else if chartClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
  577. errMsg = "移动失败"
  578. err = errors.New("不支持目录层级变更")
  579. return
  580. }
  581. if prevSort > 0 {
  582. //如果是移动在两个兄弟节点之间
  583. if nextSort > 0 {
  584. //下一个兄弟节点
  585. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  586. if prevSort == nextSort || prevSort == chartClassifyInfo.Sort {
  587. //变更兄弟节点的排序
  588. updateSortStr := `sort + 2`
  589. //变更分类
  590. if prevClassify != nil {
  591. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr, source)
  592. } else {
  593. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
  594. }
  595. //变更图表
  596. if prevChartInfo != nil {
  597. //变更兄弟节点的排序
  598. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
  599. } else {
  600. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
  601. }
  602. } else {
  603. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  604. if nextSort-prevSort == 1 {
  605. //变更兄弟节点的排序
  606. updateSortStr := `sort + 1`
  607. //变更分类
  608. if prevClassify != nil {
  609. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevSort, updateSortStr, source)
  610. } else {
  611. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
  612. }
  613. //变更图表
  614. if prevChartInfo != nil {
  615. //变更兄弟节点的排序
  616. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
  617. } else {
  618. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
  619. }
  620. }
  621. }
  622. }
  623. chartClassifyInfo.Sort = prevSort + 1
  624. chartClassifyInfo.ModifyTime = time.Now()
  625. updateCol = append(updateCol, "Sort", "ModifyTime")
  626. } else if prevClassify == nil && nextClassify == nil && prevChartInfo == nil && nextChartInfo == nil && parentClassifyId > 0 {
  627. //处理只拖动到目录里,默认放到目录底部的情况
  628. var maxSort int
  629. maxSort, err = GetChartClassifyMaxSort(parentClassifyId, source)
  630. if err != nil {
  631. errMsg = "移动失败"
  632. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  633. return
  634. }
  635. chartClassifyInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  636. chartClassifyInfo.ModifyTime = time.Now()
  637. updateCol = append(updateCol, "Sort", "ModifyTime")
  638. } else {
  639. // 拖动到父级分类的第一位
  640. firstClassify, tmpErr := data_manage.GetFirstChartClassifyByParentId(parentClassifyId)
  641. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  642. errMsg = "移动失败"
  643. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  644. return
  645. }
  646. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  647. if firstClassify != nil && firstClassify.Sort == 0 {
  648. updateSortStr := ` sort + 1 `
  649. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
  650. //该分类下的所有图表也需要+1
  651. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
  652. } else {
  653. //如果该分类下存在图表,且第一个图表的排序等于0,那么需要调整排序
  654. firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
  655. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  656. errMsg = "移动失败"
  657. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  658. return
  659. }
  660. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  661. if firstEdb != nil && firstEdb.Sort == 0 {
  662. updateSortStr := ` sort + 1 `
  663. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, firstEdb.ChartInfoId-1, updateSortStr)
  664. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, 0, updateSortStr, source)
  665. }
  666. }
  667. chartClassifyInfo.Sort = 0 //那就是排在第一位
  668. chartClassifyInfo.ModifyTime = time.Now()
  669. updateCol = append(updateCol, "Sort", "ModifyTime")
  670. }
  671. //更新
  672. if len(updateCol) > 0 {
  673. err = chartClassifyInfo.Update(updateCol)
  674. if err != nil {
  675. errMsg = "移动失败"
  676. err = errors.New("修改失败,Err:" + err.Error())
  677. return
  678. }
  679. //更新对应分类的root_id和层级
  680. if oldParentId != parentClassifyId {
  681. if len(classifyIds) > 0 {
  682. levelStep := chartClassifyInfo.Level - oldLevel
  683. err = data_manage.UpdateEdbClassifyChildByParentClassifyId(classifyIds, chartClassifyInfo.RootId, levelStep)
  684. if err != nil {
  685. errMsg = "移动失败"
  686. err = errors.New("更新子分类失败,Err:" + err.Error())
  687. return
  688. }
  689. }
  690. }
  691. }
  692. } else {
  693. if chartInfo == nil {
  694. errMsg = "当前图表不存在"
  695. err = errors.New(errMsg)
  696. return
  697. }
  698. //如果改变了分类,那么移动该图表数据
  699. if chartInfo.ChartClassifyId != parentClassifyId {
  700. chartInfo.ChartClassifyId = parentClassifyId
  701. chartInfo.ModifyTime = time.Now()
  702. updateCol = append(updateCol, "ChartClassifyId", "ModifyTime")
  703. }
  704. if prevSort > 0 {
  705. //如果是移动在两个兄弟节点之间
  706. if nextSort > 0 {
  707. //下一个兄弟节点
  708. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  709. if prevSort == nextSort || prevSort == chartInfo.Sort {
  710. //变更兄弟节点的排序
  711. updateSortStr := `sort + 2`
  712. //变更分类
  713. if prevClassify != nil {
  714. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr, source)
  715. } else {
  716. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
  717. }
  718. //变更图表
  719. if prevChartInfo != nil {
  720. //变更兄弟节点的排序
  721. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
  722. } else {
  723. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
  724. }
  725. } else {
  726. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  727. if nextSort-prevSort == 1 {
  728. //变更兄弟节点的排序
  729. updateSortStr := `sort + 1`
  730. //变更分类
  731. if prevClassify != nil {
  732. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevSort, updateSortStr, source)
  733. } else {
  734. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
  735. }
  736. //变更图表
  737. if prevChartInfo != nil {
  738. //变更兄弟节点的排序
  739. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
  740. } else {
  741. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
  742. }
  743. }
  744. }
  745. }
  746. chartInfo.Sort = prevSort + 1
  747. chartInfo.ModifyTime = time.Now()
  748. updateCol = append(updateCol, "Sort", "ModifyTime")
  749. } else if prevClassify == nil && nextClassify == nil && prevChartInfo == nil && nextChartInfo == nil && parentClassifyId > 0 {
  750. //处理只拖动到目录里,默认放到目录底部的情况
  751. var maxSort int
  752. maxSort, err = GetChartClassifyMaxSort(parentClassifyId, source)
  753. if err != nil {
  754. errMsg = "移动失败"
  755. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  756. return
  757. }
  758. chartInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  759. chartInfo.ModifyTime = time.Now()
  760. updateCol = append(updateCol, "Sort", "ModifyTime")
  761. } else {
  762. // 拖动到父级分类的第一位
  763. firstClassify, tmpErr := data_manage.GetFirstChartClassifyByParentId(parentClassifyId)
  764. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  765. errMsg = "移动失败"
  766. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  767. return
  768. }
  769. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  770. if firstClassify != nil && firstClassify.Sort == 0 {
  771. updateSortStr := ` sort + 1 `
  772. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
  773. //该分类下的所有图表也需要+1
  774. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
  775. } else {
  776. //如果该分类下存在图表,且第一个图表的排序等于0,那么需要调整排序
  777. firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
  778. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  779. errMsg = "移动失败"
  780. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  781. return
  782. }
  783. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  784. if firstEdb != nil && firstEdb.Sort == 0 {
  785. updateSortStr := ` sort + 1 `
  786. _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, firstEdb.ChartInfoId-1, updateSortStr)
  787. _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, 0, updateSortStr, source)
  788. }
  789. }
  790. chartInfo.Sort = 0 //那就是排在第一位
  791. chartInfo.ModifyTime = time.Now()
  792. updateCol = append(updateCol, "Sort", "ModifyTime")
  793. }
  794. //更新
  795. if len(updateCol) > 0 {
  796. err = chartInfo.Update(updateCol)
  797. if err != nil {
  798. errMsg = "移动失败"
  799. err = errors.New("修改失败,Err:" + err.Error())
  800. return
  801. }
  802. }
  803. }
  804. return
  805. }
  806. func GetChildChartClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.ChartClassifyIdItems, err error, errMsg string) {
  807. //判断是否是挂在顶级目录下
  808. targetClassify, err := data_manage.GetChartClassifyById(targetClassifyId)
  809. if err != nil {
  810. if err.Error() == utils.ErrNoRow() {
  811. errMsg = "当前分类不存在"
  812. err = errors.New(errMsg)
  813. return
  814. }
  815. errMsg = "获取失败"
  816. err = errors.New("获取分类信息失败,Err:" + err.Error())
  817. return
  818. }
  819. orderStr := ` order by level asc, sort asc, chart_classify_id asc`
  820. tmpList, err := data_manage.GetChartClassifyByRootIdLevel(targetClassify.RootId, targetClassify.Source, orderStr)
  821. if err != nil && err.Error() != utils.ErrNoRow() {
  822. errMsg = "获取失败"
  823. err = errors.New("获取数据失败,Err:" + err.Error())
  824. return
  825. }
  826. idMap := make(map[int]struct{})
  827. if len(tmpList) > 0 {
  828. for _, v := range tmpList {
  829. if v.ChartClassifyId == targetClassify.ChartClassifyId {
  830. idMap[v.ChartClassifyId] = struct{}{}
  831. }
  832. }
  833. for _, v := range tmpList {
  834. if _, ok := idMap[v.ParentId]; ok {
  835. idMap[v.ChartClassifyId] = struct{}{}
  836. }
  837. }
  838. for _, v := range tmpList {
  839. if _, ok := idMap[v.ChartClassifyId]; ok {
  840. targetItem := new(data_manage.ChartClassifyIdItems)
  841. targetItem.ChartClassifyId = v.ChartClassifyId
  842. targetItem.ParentId = v.ParentId
  843. targetItem.RootId = v.RootId
  844. targetItem.UniqueCode = v.UniqueCode
  845. targetItem.Level = v.Level
  846. targetItem.ChartClassifyName = v.ChartClassifyName
  847. targetItem.IsJoinPermission = v.IsJoinPermission
  848. targetList = append(targetList, targetItem)
  849. }
  850. }
  851. }
  852. return
  853. }
  854. func GetChartClassifyMaxSort(parentId, source int) (maxSort int, err error) {
  855. //获取该层级下最大的排序数
  856. classifyMaxSort, err := data_manage.GetChartClassifyMaxSort(parentId, source)
  857. if err != nil {
  858. return
  859. }
  860. maxSort = classifyMaxSort
  861. edbMaxSort, err := data_manage.GetChartInfoMaxSortByClassifyId(parentId)
  862. if err != nil {
  863. return
  864. }
  865. if maxSort < edbMaxSort {
  866. maxSort = edbMaxSort
  867. }
  868. return
  869. }
  870. // GetChartClassifyTreeRecursive 递归获取分类树形结构
  871. func GetChartClassifyTreeRecursive(list []*data_manage.ChartClassifyItems, parentId int) []*data_manage.ChartClassifyItems {
  872. res := make([]*data_manage.ChartClassifyItems, 0)
  873. for _, v := range list {
  874. if v.ParentId == parentId {
  875. v.Children = GetChartClassifyTreeRecursive(list, v.ChartClassifyId)
  876. res = append(res, v)
  877. }
  878. }
  879. return res
  880. }
  881. // GetChartClassifyParentRecursive 根据子目录递归父级目录
  882. func GetChartClassifyParentRecursive(list []*data_manage.ChartClassifyItems, classifyId int) []*data_manage.ChartClassifyItems {
  883. res := make([]*data_manage.ChartClassifyItems, 0)
  884. for _, v := range list {
  885. if v.ChartClassifyId == classifyId {
  886. if v.ParentId > 0 {
  887. res = GetChartClassifyParentRecursive(list, v.ParentId)
  888. }
  889. res = append(res, v)
  890. }
  891. }
  892. return res
  893. }
  894. // 修改图表分类,可以修改父级
  895. func EditChartClassifyV2(chartClassifyId, praentId, source int, chartClassifyName, lang string) (classifyInfo *data_manage.ChartClassify, err error, errMsg string, isSendEmail bool) {
  896. isSendEmail = true
  897. errMsg = "保存失败"
  898. // 获取分类信息
  899. classifyInfo, err = data_manage.GetChartClassifyById(chartClassifyId)
  900. if err != nil {
  901. return
  902. }
  903. if praentId != classifyInfo.ParentId {
  904. parentClassifyInfo, e := data_manage.GetChartClassifyById(praentId)
  905. if e != nil {
  906. err = e
  907. return
  908. }
  909. if classifyInfo.Level != parentClassifyInfo.Level - 1 {
  910. err = errors.New("父级分类层级异常")
  911. }
  912. }
  913. // 分类来源校验
  914. if classifyInfo.Source != source {
  915. errMsg = "图表分类异常"
  916. err = errors.New(fmt.Sprintf("图表分类来源异常,修改来源:%d,分类来源:%d", source, classifyInfo.Source))
  917. isSendEmail = false
  918. return
  919. }
  920. // 需要变更的字段
  921. updateCols := make([]string, 0)
  922. if praentId != classifyInfo.ParentId {
  923. classifyInfo.ParentId = praentId
  924. classifyInfo.ModifyTime = time.Now()
  925. updateCols = append(updateCols, "ParentId")
  926. }
  927. // 语言版本校验
  928. switch lang {
  929. case utils.EnLangVersion:
  930. if classifyInfo.ChartClassifyNameEn != chartClassifyName {
  931. count, tmpErr := data_manage.GetChartClassifyEnCount(chartClassifyName, classifyInfo.ParentId, source)
  932. if tmpErr != nil {
  933. errMsg = "判断名称是否已存在失败"
  934. err = errors.New("判断名称是否已存在失败,Err:" + tmpErr.Error())
  935. return
  936. }
  937. if count > 0 {
  938. errMsg = "分类名称已存在,请重新输入"
  939. err = errors.New(errMsg)
  940. isSendEmail = false
  941. return
  942. }
  943. classifyInfo.ChartClassifyNameEn = chartClassifyName
  944. classifyInfo.ModifyTime = time.Now()
  945. updateCols = append(updateCols, "ChartClassifyNameEn", "ModifyTime")
  946. }
  947. default:
  948. if classifyInfo.ChartClassifyName != chartClassifyName {
  949. count, tmpErr := data_manage.GetChartClassifyCount(chartClassifyName, classifyInfo.ParentId, source)
  950. if tmpErr != nil {
  951. errMsg = "判断名称是否已存在失败"
  952. err = errors.New("判断名称是否已存在失败,Err:" + tmpErr.Error())
  953. return
  954. }
  955. if count > 0 {
  956. errMsg = "分类名称已存在,请重新输入"
  957. err = errors.New(errMsg)
  958. isSendEmail = false
  959. return
  960. }
  961. classifyInfo.ChartClassifyName = chartClassifyName
  962. classifyInfo.ModifyTime = time.Now()
  963. updateCols = append(updateCols, "ChartClassifyName", "ModifyTime")
  964. }
  965. }
  966. if len(updateCols) > 0 {
  967. err = classifyInfo.Update(updateCols)
  968. }
  969. return
  970. }
  971. // RemoveNotChartClassifyItemsMakeTree
  972. // @Description: 过滤名下没有自己图表的分类,并生成树形结构
  973. // @author: Roc
  974. // @datetime 2024-09-11 16:59:39
  975. // @param node *data_manage.ChartClassifyItems
  976. // @param selfChartClassifyIdList []int
  977. // @return isSelf bool
  978. func RemoveNotChartClassifyItemsMakeTree(node *data_manage.ChartClassifyItems, selfChartClassifyIdList []int) (isSelf bool) {
  979. if utils.InArrayByInt(selfChartClassifyIdList, node.ChartClassifyId) {
  980. return true
  981. }
  982. childrenList := make([]*data_manage.ChartClassifyItems, 0)
  983. for _, child := range node.Children {
  984. if tmpIsSelf := RemoveNotChartClassifyItemsMakeTree(child, selfChartClassifyIdList); tmpIsSelf {
  985. childrenList = append(childrenList, child)
  986. isSelf = tmpIsSelf
  987. }
  988. }
  989. node.Children = childrenList
  990. return
  991. }
  992. // GetChartClassifyChildrenRecursive 根据父目录递归子级目录
  993. func GetChartClassifyChildrenRecursive(list []*data_manage.ChartClassifyItems, parentId int) []*data_manage.ChartClassifyItems {
  994. var res []*data_manage.ChartClassifyItems
  995. for _, v := range list {
  996. if v.ParentId == parentId {
  997. // 递归调用以获取更深层次的子级
  998. children := GetChartClassifyChildrenRecursive(list, v.ChartClassifyId)
  999. // 将当前节点和所有子节点添加到结果中
  1000. res = append(res, v)
  1001. res = append(res, children...)
  1002. } else if v.ChartClassifyId == parentId {
  1003. // 将当前节点添加到结果中
  1004. res = append(res, v)
  1005. }
  1006. }
  1007. return res
  1008. }
  1009. // GetChartClassifyChildrenRecursiveByParentIds 根据父目录递归子级目录
  1010. func GetChartClassifyChildrenRecursiveByParentIds(list []*data_manage.ChartClassifyItems, parentIds []string) []*data_manage.ChartClassifyItems {
  1011. var res []*data_manage.ChartClassifyItems
  1012. for _, v := range list {
  1013. for _, id := range parentIds {
  1014. parentId, _ := strconv.Atoi(id)
  1015. if v.ParentId == parentId || v.ChartClassifyId == parentId {
  1016. // 递归调用以获取更深层次的子级
  1017. children := GetChartClassifyChildrenRecursive(list, v.ChartClassifyId)
  1018. // 将当前节点和所有子节点添加到结果中
  1019. res = append(res, v)
  1020. res = append(res, children...)
  1021. }
  1022. }
  1023. }
  1024. return res
  1025. }