base_from_ths_hf_classify.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. package data
  2. import (
  3. "errors"
  4. "eta/eta_api/models/data_manage"
  5. "eta/eta_api/models/system"
  6. "eta/eta_api/utils"
  7. "fmt"
  8. "time"
  9. )
  10. // GetThsHfClassifyTreeRecursive 递归获取分类树形结构
  11. func GetThsHfClassifyTreeRecursive(list []*data_manage.BaseFromThsHfClassifyItem, parentId int) []*data_manage.BaseFromThsHfClassifyItem {
  12. res := make([]*data_manage.BaseFromThsHfClassifyItem, 0)
  13. for _, v := range list {
  14. if v.ParentId == parentId {
  15. t := GetThsHfClassifyTreeRecursive(list, v.ClassifyId)
  16. v.Children = nil // 这一步是方便前端组件判断null...
  17. if len(t) > 0 {
  18. v.Children = t
  19. }
  20. res = append(res, v)
  21. }
  22. }
  23. return res
  24. }
  25. // ThsHfMoveClassify 移动指标分类
  26. func ThsHfMoveClassify(req data_manage.BaseFromThsHfClassifyMoveReq, sysUser *system.Admin) (err error, errMsg string) {
  27. // req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId
  28. classifyId := req.ClassifyId
  29. parentClassifyId := req.ParentClassifyId
  30. prevClassifyId := req.PrevClassifyId
  31. nextClassifyId := req.NextClassifyId
  32. itemId := req.ItemId
  33. prevItemId := req.PrevItemId
  34. nextItemId := req.NextItemId
  35. //首先确定移动的对象是分类还是指标
  36. //判断上一个节点是分类还是指标
  37. //判断下一个节点是分类还是指标
  38. //同时更新分类目录下的分类sort和指标sort
  39. //更新当前移动的分类或者指标sort
  40. var parentEdbClassifyInfo *data_manage.BaseFromThsHfClassify
  41. if parentClassifyId > 0 {
  42. parentEdbClassifyInfo, err = data_manage.GetThsHfClassifyById(parentClassifyId)
  43. if err != nil {
  44. errMsg = "移动失败"
  45. err = errors.New("获取上级分类信息失败,Err:" + err.Error())
  46. return
  47. }
  48. }
  49. //如果有传入 上一个兄弟节点分类id
  50. var (
  51. edbClassifyInfo *data_manage.BaseFromThsHfClassify
  52. prevClassify *data_manage.BaseFromThsHfClassify
  53. nextClassify *data_manage.BaseFromThsHfClassify
  54. edbInfo *data_manage.BaseFromThsHfIndex
  55. prevEdbInfo *data_manage.BaseFromThsHfIndex
  56. nextEdbInfo *data_manage.BaseFromThsHfIndex
  57. prevSort int
  58. nextSort int
  59. )
  60. // 移动对象为分类, 判断权限
  61. if itemId == 0 {
  62. edbClassifyInfo, err = data_manage.GetThsHfClassifyById(classifyId)
  63. if err != nil {
  64. if err.Error() == utils.ErrNoRow() {
  65. errMsg = "当前分类不存在"
  66. err = errors.New("获取分类信息失败,Err:" + err.Error())
  67. return
  68. }
  69. errMsg = "移动失败"
  70. err = errors.New("获取分类信息失败,Err:" + err.Error())
  71. return
  72. }
  73. if parentClassifyId > 0 && parentEdbClassifyInfo.Level == 6 {
  74. errMsg = "最高只支持添加6级分类"
  75. err = errors.New(errMsg)
  76. return
  77. }
  78. // 如果是移动目录, 那么校验一下父级目录下是否有重名目录
  79. exists, e := data_manage.GetEdbClassifyByParentIdAndName(parentClassifyId, edbClassifyInfo.ClassifyName, classifyId)
  80. if e != nil && e.Error() != utils.ErrNoRow() {
  81. errMsg = "移动失败"
  82. err = fmt.Errorf("获取父级分类下的同名分类失败, Err: %s", e.Error())
  83. return
  84. }
  85. if exists != nil {
  86. errMsg = "移动失败,分类名称已存在"
  87. return
  88. }
  89. } else {
  90. edbInfo, err = data_manage.GetThsHfIndexById(req.ItemId)
  91. if err != nil {
  92. if err.Error() == utils.ErrNoRow() {
  93. errMsg = "当前指标不存在"
  94. err = errors.New("获取分类信息失败,Err:" + err.Error())
  95. return
  96. }
  97. errMsg = "移动失败"
  98. err = errors.New("获取分类信息失败,Err:" + err.Error())
  99. return
  100. }
  101. if parentClassifyId == 0 {
  102. errMsg = "移动失败,指标必须挂在分类下"
  103. err = errors.New(errMsg)
  104. return
  105. }
  106. //// 移动权限校验
  107. //button := GetEdbOpButton(sysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  108. //if !button.MoveButton {
  109. // errMsg = "无操作权限"
  110. // err = errors.New(errMsg)
  111. // return
  112. //}
  113. }
  114. if prevClassifyId > 0 {
  115. prevClassify, err = data_manage.GetThsHfClassifyById(prevClassifyId)
  116. if err != nil {
  117. errMsg = "移动失败"
  118. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  119. return
  120. }
  121. prevSort = prevClassify.Sort
  122. } else if prevItemId > 0 {
  123. prevEdbInfo, err = data_manage.GetThsHfIndexById(prevItemId)
  124. if err != nil {
  125. errMsg = "移动失败"
  126. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  127. return
  128. }
  129. prevSort = prevEdbInfo.Sort
  130. }
  131. if nextClassifyId > 0 {
  132. //下一个兄弟节点
  133. nextClassify, err = data_manage.GetThsHfClassifyById(nextClassifyId)
  134. if err != nil {
  135. errMsg = "移动失败"
  136. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  137. return
  138. }
  139. nextSort = nextClassify.Sort
  140. } else if nextItemId > 0 {
  141. //下一个兄弟节点
  142. nextEdbInfo, err = data_manage.GetThsHfIndexById(nextItemId)
  143. if err != nil {
  144. errMsg = "移动失败"
  145. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  146. return
  147. }
  148. nextSort = nextEdbInfo.Sort
  149. }
  150. err, errMsg = thsHfMoveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify, edbInfo, prevEdbInfo, nextEdbInfo, parentClassifyId, prevSort, nextSort)
  151. return
  152. }
  153. // thsHfMoveEdbClassify 移动指标分类
  154. func thsHfMoveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify *data_manage.BaseFromThsHfClassify, edbInfo, prevEdbInfo, nextEdbInfo *data_manage.BaseFromThsHfIndex, parentClassifyId int, prevSort, nextSort int) (err error, errMsg string) {
  155. updateCol := make([]string, 0)
  156. // 移动对象为分类, 判断分类是否存在
  157. if edbClassifyInfo != nil {
  158. oldParentId := edbClassifyInfo.ParentId
  159. oldLevel := edbClassifyInfo.Level
  160. var classifyIds []int
  161. if oldParentId != parentClassifyId {
  162. //更新子分类对应的level
  163. childList, e, m := GetThsHfChildClassifyByClassifyId(edbClassifyInfo.BaseFromThsHfClassifyId)
  164. if e != nil {
  165. errMsg = "移动失败"
  166. err = errors.New("查询子分类失败,Err:" + e.Error() + m)
  167. return
  168. }
  169. if len(childList) > 0 {
  170. for _, v := range childList {
  171. if v.BaseFromThsHfClassifyId == edbClassifyInfo.BaseFromThsHfClassifyId {
  172. continue
  173. }
  174. classifyIds = append(classifyIds, v.BaseFromThsHfClassifyId)
  175. }
  176. }
  177. }
  178. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  179. if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
  180. if edbClassifyInfo.Level != parentEdbClassifyInfo.Level+1 { //禁止层级调整
  181. errMsg = "移动失败"
  182. err = errors.New("不支持目录层级变更")
  183. return
  184. }
  185. edbClassifyInfo.ParentId = parentEdbClassifyInfo.BaseFromThsHfClassifyId
  186. edbClassifyInfo.RootId = parentEdbClassifyInfo.RootId
  187. edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  188. edbClassifyInfo.ModifyTime = time.Now()
  189. // 更改层级路径
  190. edbClassifyInfo.LevelPath = fmt.Sprintf("%s,%d", parentEdbClassifyInfo.LevelPath, edbClassifyInfo.BaseFromThsHfClassifyId)
  191. updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime", "LevelPath")
  192. } else if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
  193. errMsg = "移动失败"
  194. err = errors.New("不支持目录层级变更")
  195. return
  196. }
  197. if prevSort > 0 {
  198. //如果是移动在两个兄弟节点之间
  199. if nextSort > 0 {
  200. //下一个兄弟节点
  201. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  202. if prevSort == nextSort || prevSort == edbClassifyInfo.Sort {
  203. //变更兄弟节点的排序
  204. updateSortStr := `sort + 2`
  205. //变更分类
  206. if prevClassify != nil {
  207. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, prevClassify.BaseFromThsHfClassifyId, prevClassify.Sort, updateSortStr)
  208. } else {
  209. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr)
  210. }
  211. //变更指标
  212. if prevEdbInfo != nil {
  213. //变更兄弟节点的排序
  214. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.BaseFromThsHfIndexId, updateSortStr)
  215. } else {
  216. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  217. }
  218. } else {
  219. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  220. if nextSort-prevSort == 1 {
  221. //变更兄弟节点的排序
  222. updateSortStr := `sort + 1`
  223. //变更分类
  224. if prevClassify != nil {
  225. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, prevClassify.BaseFromThsHfClassifyId, prevSort, updateSortStr)
  226. } else {
  227. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr)
  228. }
  229. //变更指标
  230. if prevEdbInfo != nil {
  231. //变更兄弟节点的排序
  232. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.BaseFromThsHfIndexId, updateSortStr)
  233. } else {
  234. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  235. }
  236. }
  237. }
  238. }
  239. edbClassifyInfo.Sort = prevSort + 1
  240. edbClassifyInfo.ModifyTime = time.Now()
  241. updateCol = append(updateCol, "Sort", "ModifyTime")
  242. } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
  243. //处理只拖动到目录里,默认放到目录底部的情况
  244. var maxSort int
  245. maxSort, err = GetThsHfClassifyMaxSort(parentClassifyId)
  246. if err != nil {
  247. errMsg = "移动失败"
  248. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  249. return
  250. }
  251. edbClassifyInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  252. edbClassifyInfo.ModifyTime = time.Now()
  253. updateCol = append(updateCol, "Sort", "ModifyTime")
  254. } else {
  255. // 拖动到父级分类的第一位
  256. firstClassify, tmpErr := data_manage.GetFirstThsHfClassifyByParentId(parentClassifyId)
  257. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  258. errMsg = "移动失败"
  259. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  260. return
  261. }
  262. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  263. if firstClassify != nil && firstClassify.Sort == 0 {
  264. updateSortStr := ` sort + 1 `
  265. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, firstClassify.BaseFromThsHfClassifyId-1, 0, updateSortStr)
  266. //该分类下的所有指标也需要+1
  267. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
  268. } else {
  269. //如果该分类下存在指标,且第一个指标的排序等于0,那么需要调整排序
  270. firstEdb, tErr := data_manage.GetFirstThsHfIndexByClassifyId(parentClassifyId)
  271. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  272. errMsg = "移动失败"
  273. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  274. return
  275. }
  276. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  277. if firstEdb != nil && firstEdb.Sort == 0 {
  278. updateSortStr := ` sort + 1 `
  279. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, 0, firstEdb.BaseFromThsHfIndexId-1, updateSortStr)
  280. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr)
  281. }
  282. }
  283. edbClassifyInfo.Sort = 0 //那就是排在第一位
  284. edbClassifyInfo.ModifyTime = time.Now()
  285. updateCol = append(updateCol, "Sort", "ModifyTime")
  286. }
  287. //更新
  288. if len(updateCol) > 0 {
  289. err = edbClassifyInfo.Update(updateCol)
  290. if err != nil {
  291. errMsg = "移动失败"
  292. err = errors.New("修改失败,Err:" + err.Error())
  293. return
  294. }
  295. //更新对应分类的root_id和层级
  296. if oldParentId != parentClassifyId {
  297. if len(classifyIds) > 0 {
  298. levelStep := edbClassifyInfo.Level - oldLevel
  299. err = data_manage.UpdateThsHfClassifyChildByParentClassifyId(classifyIds, edbClassifyInfo.RootId, levelStep)
  300. if err != nil {
  301. errMsg = "移动失败"
  302. err = errors.New("更新子分类失败,Err:" + err.Error())
  303. return
  304. }
  305. }
  306. }
  307. }
  308. } else {
  309. if edbInfo == nil {
  310. errMsg = "当前指标不存在"
  311. err = errors.New(errMsg)
  312. return
  313. }
  314. //如果改变了分类,那么移动该指标数据
  315. if edbInfo.BaseFromThsHfClassifyId != parentClassifyId {
  316. edbInfo.BaseFromThsHfClassifyId = parentClassifyId
  317. edbInfo.ModifyTime = time.Now()
  318. updateCol = append(updateCol, "BaseFromThsHfClassifyId", "ModifyTime")
  319. }
  320. if prevSort > 0 {
  321. //如果是移动在两个兄弟节点之间
  322. if nextSort > 0 {
  323. //下一个兄弟节点
  324. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  325. if prevSort == nextSort || prevSort == edbInfo.Sort {
  326. //变更兄弟节点的排序
  327. updateSortStr := `sort + 2`
  328. //变更分类
  329. if prevClassify != nil {
  330. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, prevClassify.BaseFromThsHfClassifyId, prevClassify.Sort, updateSortStr)
  331. } else {
  332. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr)
  333. }
  334. //变更指标
  335. if prevEdbInfo != nil {
  336. //变更兄弟节点的排序
  337. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.BaseFromThsHfIndexId, updateSortStr)
  338. } else {
  339. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  340. }
  341. } else {
  342. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  343. if nextSort-prevSort == 1 {
  344. //变更兄弟节点的排序
  345. updateSortStr := `sort + 1`
  346. //变更分类
  347. if prevClassify != nil {
  348. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, prevClassify.BaseFromThsHfClassifyId, prevSort, updateSortStr)
  349. } else {
  350. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr)
  351. }
  352. //变更指标
  353. if prevEdbInfo != nil {
  354. //变更兄弟节点的排序
  355. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.BaseFromThsHfIndexId, updateSortStr)
  356. } else {
  357. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  358. }
  359. }
  360. }
  361. }
  362. edbInfo.Sort = prevSort + 1
  363. edbInfo.ModifyTime = time.Now()
  364. updateCol = append(updateCol, "Sort", "ModifyTime")
  365. } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
  366. //处理只拖动到目录里,默认放到目录底部的情况
  367. var maxSort int
  368. classifyOb := new(data_manage.BaseFromThsHfClassify)
  369. maxSort, err = classifyOb.GetSortMax(parentClassifyId)
  370. if err != nil {
  371. errMsg = "移动失败"
  372. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  373. return
  374. }
  375. edbInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  376. edbInfo.ModifyTime = time.Now()
  377. updateCol = append(updateCol, "Sort", "ModifyTime")
  378. } else {
  379. // 拖动到父级分类的第一位
  380. firstClassify, tmpErr := data_manage.GetFirstThsHfClassifyByParentId(parentClassifyId)
  381. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  382. errMsg = "移动失败"
  383. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  384. return
  385. }
  386. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  387. if firstClassify != nil && firstClassify.Sort == 0 {
  388. updateSortStr := ` sort + 1 `
  389. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, firstClassify.BaseFromThsHfClassifyId-1, 0, updateSortStr)
  390. //该分类下的所有指标也需要+1
  391. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
  392. } else {
  393. //如果该分类下存在指标,且第一个指标的排序等于0,那么需要调整排序
  394. firstEdb, tErr := data_manage.GetFirstThsHfIndexByClassifyId(parentClassifyId)
  395. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  396. errMsg = "移动失败"
  397. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  398. return
  399. }
  400. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  401. if firstEdb != nil && firstEdb.Sort == 0 {
  402. updateSortStr := ` sort + 1 `
  403. _ = data_manage.UpdateThsHfIndexSortByClassifyId(parentClassifyId, 0, firstEdb.BaseFromThsHfIndexId-1, updateSortStr)
  404. _ = data_manage.UpdateThsHfClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr)
  405. }
  406. }
  407. edbInfo.Sort = 0 //那就是排在第一位
  408. edbInfo.ModifyTime = time.Now()
  409. updateCol = append(updateCol, "Sort", "ModifyTime")
  410. }
  411. //更新
  412. if len(updateCol) > 0 {
  413. err = edbInfo.Update(updateCol)
  414. if err != nil {
  415. errMsg = "移动失败"
  416. err = errors.New("修改失败,Err:" + err.Error())
  417. return
  418. }
  419. }
  420. }
  421. return
  422. }
  423. func GetThsHfChildClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.BaseFromThsHfClassify, err error, errMsg string) {
  424. //判断是否是挂在顶级目录下
  425. targetClassify, err := data_manage.GetThsHfClassifyById(targetClassifyId)
  426. if err != nil {
  427. if err.Error() == utils.ErrNoRow() {
  428. errMsg = "当前分类不存在"
  429. err = errors.New(errMsg)
  430. return
  431. }
  432. errMsg = "获取失败"
  433. err = errors.New("获取分类信息失败,Err:" + err.Error())
  434. return
  435. }
  436. orderStr := ` order by level asc, sort asc, base_from_ths_hf_classify_id asc`
  437. tmpList, err := data_manage.GetThsHfClassifyByRootIdLevel(targetClassify.RootId, orderStr)
  438. if err != nil && err.Error() != utils.ErrNoRow() {
  439. errMsg = "获取失败"
  440. err = errors.New("获取数据失败,Err:" + err.Error())
  441. return
  442. }
  443. idMap := make(map[int]struct{})
  444. if len(tmpList) > 0 {
  445. for _, v := range tmpList {
  446. if v.BaseFromThsHfClassifyId == targetClassify.BaseFromThsHfClassifyId {
  447. idMap[v.BaseFromThsHfClassifyId] = struct{}{}
  448. }
  449. }
  450. for _, v := range tmpList {
  451. if _, ok := idMap[v.ParentId]; ok {
  452. idMap[v.BaseFromThsHfClassifyId] = struct{}{}
  453. }
  454. }
  455. for _, v := range tmpList {
  456. if _, ok := idMap[v.BaseFromThsHfClassifyId]; ok {
  457. targetItem := new(data_manage.BaseFromThsHfClassify)
  458. targetItem.BaseFromThsHfClassifyId = v.BaseFromThsHfClassifyId
  459. targetItem.ParentId = v.ParentId
  460. targetItem.RootId = v.RootId
  461. //targetItem.UniqueCode = v.UniqueCode
  462. targetItem.Level = v.Level
  463. targetItem.ClassifyName = v.ClassifyName
  464. //targetItem.IsJoinPermission = v.IsJoinPermission
  465. targetList = append(targetList, targetItem)
  466. }
  467. }
  468. }
  469. return
  470. }
  471. func GetThsHfClassifyMaxSort(parentId int) (maxSort int, err error) {
  472. //获取该层级下最大的排序数
  473. classifyOb := new(data_manage.BaseFromThsHfClassify)
  474. classifyMaxSort, err := classifyOb.GetSortMax(parentId)
  475. if err != nil {
  476. return
  477. }
  478. maxSort = classifyMaxSort
  479. edbMaxSort, err := data_manage.GetThsHfIndexMaxSortByClassifyId(parentId)
  480. if err != nil {
  481. return
  482. }
  483. if maxSort < edbMaxSort {
  484. maxSort = edbMaxSort
  485. }
  486. return
  487. }