edb_classify.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. package data
  2. import (
  3. "errors"
  4. "eta/eta_mobile/models/data_manage"
  5. "eta/eta_mobile/models/system"
  6. "eta/eta_mobile/services/data_stat"
  7. "eta/eta_mobile/utils"
  8. "strconv"
  9. "time"
  10. )
  11. //func EdbClassifyListMakeTree(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) {
  12. // childs, _ := edbClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  13. // allEdbInfo, _ := GetEdbClassifyEdbInfo()
  14. // if len(childs) > 0 {
  15. // node.Children = append(node.Children, childs[0:]...) //添加子节点
  16. // for _, v := range childs { //查询子节点的子节点,并添加到子节点
  17. // _, has := edbClassifyHaveChild(allNode, v)
  18. // if has {
  19. // EdbClassifyListMakeTree(allNode, v) //递归添加节点
  20. // } else {
  21. // edbInfoList := allEdbInfo[v.ClassifyId]
  22. // v.Children = edbInfoList
  23. // if v.Children == nil {
  24. // childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  25. // v.Children = childrenArr
  26. // }
  27. // }
  28. // }
  29. // } else {
  30. // childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  31. // node.Children = childrenArr
  32. // }
  33. //}
  34. func edbClassifyHaveChild(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) (childs []*data_manage.EdbClassifyItems, yes bool) {
  35. for _, v := range allNode {
  36. if v.ParentId == node.ClassifyId {
  37. childs = append(childs, v)
  38. }
  39. }
  40. if len(childs) > 0 {
  41. yes = true
  42. }
  43. return
  44. }
  45. //func GetEdbClassifyEdbInfo() (result map[int][]*data_manage.EdbClassifyItems, err error) {
  46. // cMap := make(map[int][]*data_manage.EdbClassifyItems)
  47. // items, err := data_manage.GetEdbInfoAll(0)
  48. // if err != nil {
  49. // return
  50. // }
  51. // for _, v := range items {
  52. // childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  53. // v.Children = childrenArr
  54. // if items, ok := cMap[v.ClassifyId]; ok {
  55. // items = append(items, v)
  56. // cMap[v.ClassifyId] = items
  57. // } else {
  58. // infoList := make([]*data_manage.EdbClassifyItems, 0)
  59. // infoList = append(infoList, v)
  60. // cMap[v.ClassifyId] = infoList
  61. // }
  62. // }
  63. // result = cMap
  64. // return
  65. //}
  66. //func EdbClassifyItemsMakeTree(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) {
  67. // childs, _ := edbClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  68. // if len(childs) > 0 {
  69. // node.Children = append(node.Children, childs[0:]...) //添加子节点
  70. // for _, v := range childs { //查询子节点的子节点,并添加到子节点
  71. // _, has := edbClassifyHaveChild(allNode, v)
  72. // if has {
  73. // EdbClassifyItemsMakeTree(allNode, v) //递归添加节点
  74. // } else {
  75. // childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  76. // v.Children = childrenArr
  77. // }
  78. // }
  79. // } else {
  80. // childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  81. // node.Children = childrenArr
  82. // }
  83. //}
  84. // GetEdbClassifyListByAdminId 根据账户类型获取分类id集合
  85. //func GetEdbClassifyListByAdminId(adminId int64) (classifyIdList []string, err error) {
  86. // list, err := models.GetEdbdataClassify(adminId)
  87. // if err != nil {
  88. // return
  89. // }
  90. // for _, parent := range list {
  91. // if parent.Child != nil {
  92. // for _, classify := range parent.Child {
  93. // classifyIdList = append(classifyIdList, fmt.Sprint(classify.ClassifyId))
  94. // }
  95. // }
  96. // }
  97. // return
  98. //}
  99. // GetEdbClassifyNameListByAdminId 根据账户类型获取分类名称集合
  100. //func GetEdbClassifyNameListByAdminId(adminId int64) (classifyNameList []string, edbDataClassifyMap map[string]*models.EdbdataClassify, err error) {
  101. // list, err := models.GetEdbdataClassify(adminId)
  102. // edbDataClassifyMap = make(map[string]*models.EdbdataClassify)
  103. // if err != nil {
  104. // return
  105. // }
  106. // for _, parent := range list {
  107. // if parent.Child != nil {
  108. // for _, classify := range parent.Child {
  109. // classifyNameList = append(classifyNameList, classify.ClassifyName)
  110. // edbDataClassifyMap[classify.ClassifyName] = classify
  111. // }
  112. // }
  113. // }
  114. // return
  115. //}
  116. // AddEdbClassify 添加指标分类
  117. func AddEdbClassify(classifyName string, parentId, level int, classifyType uint8, sysUserId int, sysUserName string) (classifyInfo *data_manage.EdbClassify, err error, errMsg string) {
  118. count, err := data_manage.GetEdbClassifyCount(classifyName, parentId, classifyType)
  119. if err != nil {
  120. errMsg = `判断名称是否已存在失败`
  121. return
  122. }
  123. if count > 0 {
  124. errMsg = `分类名称已存在,请重新输入`
  125. return
  126. }
  127. if level > 6 {
  128. errMsg = `最高只支持添加6级分类`
  129. return
  130. }
  131. //获取该层级下最大的排序数
  132. maxSort, err := GetEdbClassifyMaxSort(parentId, classifyType)
  133. if err != nil {
  134. errMsg = "获取失败"
  135. err = errors.New("查询排序信息失败,Err:" + err.Error())
  136. return
  137. }
  138. //查询顶级rootId
  139. rootId := 0
  140. if parentId > 0 {
  141. parentClassify, tErr := data_manage.GetEdbClassifyById(parentId)
  142. if tErr != nil {
  143. if tErr.Error() == utils.ErrNoRow() {
  144. errMsg = "父级分类不存在"
  145. err = errors.New(errMsg)
  146. return
  147. }
  148. errMsg = "获取失败"
  149. err = errors.New("获取分类信息失败,Err:" + tErr.Error())
  150. return
  151. }
  152. rootId = parentClassify.RootId
  153. }
  154. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  155. classifyInfo = &data_manage.EdbClassify{
  156. //ClassifyId: 0,
  157. ClassifyType: classifyType,
  158. ClassifyName: classifyName,
  159. ParentId: parentId,
  160. RootId: rootId,
  161. HasData: 0,
  162. CreateTime: time.Now(),
  163. ModifyTime: time.Now(),
  164. SysUserId: sysUserId,
  165. SysUserRealName: sysUserName,
  166. Level: level + 1,
  167. UniqueCode: utils.MD5(utils.DATA_PREFIX + "_" + timestamp),
  168. Sort: maxSort + 1,
  169. }
  170. newId, err := data_manage.AddEdbClassify(classifyInfo)
  171. if err != nil {
  172. errMsg = "保存分类失败"
  173. return
  174. }
  175. if parentId == 0 { //一级目录的rootId等于自己本身
  176. classifyInfo.ClassifyId = int(newId)
  177. classifyInfo.RootId = int(newId)
  178. err = classifyInfo.Update([]string{"RootId"})
  179. if err != nil {
  180. errMsg = "更新分类失败"
  181. return
  182. }
  183. }
  184. return
  185. }
  186. // EditEdbClassify 编辑指标分类
  187. func EditEdbClassify(classifyId int, classifyName string, sysUser *system.Admin) (err error, errMsg string) {
  188. item, err := data_manage.GetEdbClassifyById(classifyId)
  189. if err != nil {
  190. errMsg = `保存失败`
  191. return
  192. }
  193. // 权限校验
  194. {
  195. if item.ClassifyType == 0 { // 普通指标
  196. button := GetEdbClassifyOpButton(sysUser, item.SysUserId)
  197. if !button.OpButton {
  198. errMsg = "无操作权限"
  199. err = errors.New(errMsg)
  200. return
  201. }
  202. } else if item.ClassifyType == 1 { // 预测指标
  203. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId)
  204. if !button.OpButton {
  205. errMsg = "无操作权限"
  206. err = errors.New(errMsg)
  207. return
  208. }
  209. }
  210. }
  211. // 名字相同,那么就直接返回
  212. if item.ClassifyName == classifyName {
  213. return
  214. }
  215. // 判断名称是否已存在
  216. count, err := data_manage.GetEdbClassifyCount(classifyName, item.ParentId, item.ClassifyType)
  217. if err != nil {
  218. errMsg = "判断名称是否已存在失败"
  219. return
  220. }
  221. if count > 0 {
  222. errMsg = "分类名称已存在,请重新输入"
  223. return
  224. }
  225. // 修改数据
  226. err = data_manage.EditEdbClassify(classifyId, classifyName)
  227. if err != nil {
  228. errMsg = "保存失败"
  229. }
  230. return
  231. }
  232. // DeleteCheck 删除检测
  233. func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, err error, errMsg string) {
  234. //删除分类
  235. if classifyId > 0 && edbInfoId == 0 {
  236. // 查找分类
  237. item, tmpErr := data_manage.GetEdbClassifyById(classifyId)
  238. if tmpErr != nil {
  239. errMsg = `查找分类失败`
  240. err = tmpErr
  241. return
  242. }
  243. // 权限校验
  244. {
  245. if item.ClassifyType == 0 { // 普通指标
  246. button := GetEdbClassifyOpButton(sysUser, item.SysUserId)
  247. if !button.DeleteButton {
  248. errMsg = "无操作权限"
  249. err = errors.New(errMsg)
  250. return
  251. }
  252. } else if item.ClassifyType == 1 { // 预测指标
  253. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId)
  254. if !button.DeleteButton {
  255. errMsg = "无操作权限"
  256. err = errors.New(errMsg)
  257. return
  258. }
  259. }
  260. }
  261. //判断分类下,是否含有指标
  262. count, tmpErr := data_manage.GetEdbInfoCountByClassifyId(classifyId)
  263. if tmpErr != nil {
  264. errMsg = "删除失败"
  265. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  266. return
  267. }
  268. if count > 0 {
  269. deleteStatus = 1
  270. tipsMsg = "若目录关联指标不可删除"
  271. }
  272. }
  273. if deleteStatus != 1 && edbInfoId == 0 {
  274. classifyCount, tmpErr := data_manage.GetClassifyCountByClassifyId(classifyId)
  275. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  276. errMsg = "删除失败"
  277. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  278. return
  279. }
  280. if classifyCount > 0 {
  281. deleteStatus = 2
  282. tipsMsg = "确认删除当前目录及包含的子目录吗"
  283. }
  284. }
  285. //删除指标
  286. if edbInfoId > 0 {
  287. //判断指标是否用于作图,如果用于作图,则不可删除
  288. chartCount, tmpErr := data_manage.GetChartEdbMappingCount(edbInfoId)
  289. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  290. errMsg = "删除失败"
  291. err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
  292. return
  293. }
  294. if chartCount > 0 {
  295. deleteStatus = 3
  296. tipsMsg = "当前指标已用作画图,不可删除"
  297. }
  298. //判断指标是否用于计算
  299. {
  300. calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
  301. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  302. errMsg = "删除失败"
  303. err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
  304. return
  305. }
  306. if calculateCount > 0 {
  307. deleteStatus = 4
  308. tipsMsg = "当前指标已用作,指标运算,不可删除"
  309. }
  310. }
  311. }
  312. return
  313. }
  314. // Delete 删除分类/指标
  315. func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, requestUrl string) (nextItem *data_manage.EdbInfo, err error, errMsg string) {
  316. //删除分类
  317. if classifyId > 0 && edbInfoId == 0 {
  318. // 查找分类
  319. item, tmpErr := data_manage.GetEdbClassifyById(classifyId)
  320. if tmpErr != nil {
  321. errMsg = `查找分类失败`
  322. err = tmpErr
  323. return
  324. }
  325. // 权限校验
  326. {
  327. if item.ClassifyType == 0 { // 普通指标
  328. button := GetEdbClassifyOpButton(sysUser, item.SysUserId)
  329. if !button.DeleteButton {
  330. errMsg = "无操作权限"
  331. err = errors.New(errMsg)
  332. return
  333. }
  334. } else if item.ClassifyType == 1 { // 预测指标
  335. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId)
  336. if !button.DeleteButton {
  337. errMsg = "无操作权限"
  338. err = errors.New(errMsg)
  339. return
  340. }
  341. }
  342. }
  343. //判断是否含有指标
  344. count, tmpErr := data_manage.GetEdbInfoCountByClassifyId(classifyId)
  345. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  346. errMsg = "删除失败"
  347. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  348. return
  349. }
  350. if count > 0 {
  351. errMsg = "该目录下存在关联指标,不可删除"
  352. return
  353. }
  354. tmpErr = data_manage.DeleteEdbClassify(classifyId)
  355. if tmpErr != nil {
  356. errMsg = "删除失败"
  357. err = errors.New("删除失败,Err:" + tmpErr.Error())
  358. return
  359. }
  360. }
  361. //删除指标
  362. if edbInfoId > 0 {
  363. edbInfo, tmpErr := data_manage.GetEdbInfoById(edbInfoId)
  364. if tmpErr != nil {
  365. if tmpErr.Error() == utils.ErrNoRow() {
  366. errMsg = "指标已删除,请刷新页面"
  367. err = errors.New("指标不存在,Err:" + tmpErr.Error())
  368. return
  369. } else {
  370. errMsg = "删除失败"
  371. err = errors.New("删除失败,获取指标信息失败,Err:" + tmpErr.Error())
  372. return
  373. }
  374. }
  375. if edbInfo == nil {
  376. errMsg = "指标已删除,请刷新页面"
  377. return
  378. }
  379. //判断指标是否用于作图,如果用于作图,则不可删除
  380. chartCount, tmpErr := data_manage.GetChartEdbMappingCount(edbInfoId)
  381. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  382. errMsg = "删除失败"
  383. err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
  384. return
  385. }
  386. if chartCount > 0 {
  387. errMsg = "当前指标已用作画图,不可删除"
  388. return
  389. }
  390. //如果是普通指标,那么还需要判断是否被预测指标作为源指标
  391. if edbInfo.EdbInfoType == 0 {
  392. predictEdbInfoCount, tmpErr := data_manage.GetPredictEdbConfCount(edbInfoId)
  393. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  394. errMsg = "删除失败"
  395. err = errors.New("判断指标是否被用于预测指标失败,Err:" + tmpErr.Error())
  396. return
  397. }
  398. if predictEdbInfoCount > 0 {
  399. errMsg = "当前指标已用作预测指标,不可删除"
  400. return
  401. }
  402. }
  403. //判断指标是否用作其他指标的计算
  404. {
  405. calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
  406. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  407. errMsg = "删除失败"
  408. err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
  409. return
  410. }
  411. if calculateCount > 0 {
  412. errMsg = "当前指标已用作,指标运算,不可删除"
  413. return
  414. }
  415. }
  416. //真实删除
  417. tmpErr = data_manage.DeleteEdbInfoAndData(edbInfo.EdbInfoId, edbInfo.Source, edbInfo.SubSource)
  418. if tmpErr != nil {
  419. errMsg = "删除失败"
  420. err = errors.New("删除失败,Err:" + tmpErr.Error())
  421. return
  422. }
  423. go data_stat.AddEdbDeleteLog(edbInfo, sysUser)
  424. // 返回下一个表格的信息
  425. {
  426. var condition string
  427. var pars []interface{}
  428. condition += " AND edb_info_type=? AND classify_id=? "
  429. pars = append(pars, edbInfo.EdbInfoType, edbInfo.ClassifyId)
  430. condition += " AND (sort>? OR (sort=? AND edb_info_id<?) ) "
  431. pars = append(pars, edbInfo.Sort, edbInfo.Sort, edbInfo.EdbInfoId)
  432. nextItem, tmpErr = data_manage.GetNextEdbInfoByCondition(condition, pars)
  433. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  434. errMsg = "删除失败"
  435. err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
  436. return
  437. }
  438. // 如果没找到,那么查找下一个分类的第一个表格
  439. if nextItem == nil {
  440. currClassifyInfo, tmpErr := data_manage.GetEdbClassifyById(edbInfo.ClassifyId)
  441. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  442. errMsg = "删除失败"
  443. err = errors.New("获取当前预测指标分类信息失败,Err:" + tmpErr.Error())
  444. return
  445. }
  446. nextItem, err = data_manage.GetNextEdbInfo(edbInfo.ClassifyId, currClassifyInfo.Sort, int(currClassifyInfo.ClassifyType), edbInfo.EdbInfoType)
  447. if err != nil && err.Error() != utils.ErrNoRow() {
  448. errMsg = "删除失败"
  449. err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
  450. return
  451. }
  452. }
  453. }
  454. //新增操作日志
  455. {
  456. edbLog := new(data_manage.EdbInfoLog)
  457. edbLog.EdbInfoId = edbInfo.EdbInfoId
  458. edbLog.SourceName = edbInfo.SourceName
  459. edbLog.Source = edbInfo.Source
  460. edbLog.EdbCode = edbInfo.EdbCode
  461. edbLog.EdbName = edbInfo.EdbName
  462. edbLog.ClassifyId = edbInfo.ClassifyId
  463. edbLog.SysUserId = sysUser.AdminId
  464. edbLog.SysUserRealName = sysUser.RealName
  465. edbLog.CreateTime = time.Now()
  466. edbLog.Content = requestBody
  467. edbLog.Status = "删除指标"
  468. edbLog.Method = requestUrl
  469. go data_manage.AddEdbInfoLog(edbLog)
  470. }
  471. // 删除es中的数据
  472. DeleteEdbInfoToEs(edbInfoId)
  473. }
  474. return
  475. }
  476. // MoveEdbClassify 移动指标分类
  477. func MoveEdbClassify(req data_manage.MoveEdbClassifyReq, sysUser *system.Admin, classifyType uint8) (err error, errMsg string) {
  478. // req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId
  479. classifyId := req.ClassifyId
  480. parentClassifyId := req.ParentClassifyId
  481. prevClassifyId := req.PrevClassifyId
  482. nextClassifyId := req.NextClassifyId
  483. edbInfoId := req.EdbInfoId
  484. prevEdbInfoId := req.PrevEdbInfoId
  485. nextEdbInfoId := req.NextEdbInfoId
  486. //首先确定移动的对象是分类还是指标
  487. //判断上一个节点是分类还是指标
  488. //判断下一个节点是分类还是指标
  489. //同时更新分类目录下的分类sort和指标sort
  490. //更新当前移动的分类或者指标sort
  491. var parentEdbClassifyInfo *data_manage.EdbClassify
  492. if parentClassifyId > 0 {
  493. parentEdbClassifyInfo, err = data_manage.GetEdbClassifyById(parentClassifyId)
  494. if err != nil {
  495. errMsg = "移动失败"
  496. err = errors.New("获取上级分类信息失败,Err:" + err.Error())
  497. return
  498. }
  499. }
  500. //如果有传入 上一个兄弟节点分类id
  501. var (
  502. edbClassifyInfo *data_manage.EdbClassify
  503. prevClassify *data_manage.EdbClassify
  504. nextClassify *data_manage.EdbClassify
  505. edbInfo *data_manage.EdbInfo
  506. prevEdbInfo *data_manage.EdbInfo
  507. nextEdbInfo *data_manage.EdbInfo
  508. prevSort int
  509. nextSort int
  510. )
  511. // 移动对象为分类, 判断权限
  512. if edbInfoId == 0 {
  513. edbClassifyInfo, err = data_manage.GetEdbClassifyById(classifyId)
  514. if err != nil {
  515. if err.Error() == utils.ErrNoRow() {
  516. errMsg = "当前分类不存在"
  517. err = errors.New("获取分类信息失败,Err:" + err.Error())
  518. return
  519. }
  520. errMsg = "移动失败"
  521. err = errors.New("获取分类信息失败,Err:" + err.Error())
  522. return
  523. }
  524. if parentClassifyId > 0 && parentEdbClassifyInfo.Level == 6 {
  525. errMsg = "最高只支持添加6级分类"
  526. err = errors.New(errMsg)
  527. return
  528. }
  529. // 权限校验
  530. {
  531. if edbClassifyInfo.ClassifyType == 0 { // 普通指标
  532. button := GetEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId)
  533. if !button.MoveButton {
  534. errMsg = "无操作权限"
  535. err = errors.New(errMsg)
  536. return
  537. }
  538. } else if edbClassifyInfo.ClassifyType == 1 { // 预测指标
  539. button := GetPredictEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId)
  540. if !button.MoveButton {
  541. errMsg = "无操作权限"
  542. err = errors.New(errMsg)
  543. return
  544. }
  545. }
  546. }
  547. } else {
  548. edbInfo, err = data_manage.GetEdbInfoById(req.EdbInfoId)
  549. if err != nil {
  550. if err.Error() == utils.ErrNoRow() {
  551. errMsg = "当前指标不存在"
  552. err = errors.New("获取分类信息失败,Err:" + err.Error())
  553. return
  554. }
  555. errMsg = "移动失败"
  556. err = errors.New("获取分类信息失败,Err:" + err.Error())
  557. return
  558. }
  559. if parentClassifyId == 0 {
  560. errMsg = "移动失败,指标必须挂在分类下"
  561. err = errors.New(errMsg)
  562. return
  563. }
  564. // 移动权限校验
  565. button := GetEdbOpButton(sysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType)
  566. if !button.MoveButton {
  567. errMsg = "无操作权限"
  568. err = errors.New(errMsg)
  569. return
  570. }
  571. }
  572. if prevClassifyId > 0 {
  573. prevClassify, err = data_manage.GetEdbClassifyById(prevClassifyId)
  574. if err != nil {
  575. errMsg = "移动失败"
  576. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  577. return
  578. }
  579. prevSort = prevClassify.Sort
  580. } else if prevEdbInfoId > 0 {
  581. prevEdbInfo, err = data_manage.GetEdbInfoById(prevEdbInfoId)
  582. if err != nil {
  583. errMsg = "移动失败"
  584. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  585. return
  586. }
  587. prevSort = prevEdbInfo.Sort
  588. }
  589. if nextClassifyId > 0 {
  590. //下一个兄弟节点
  591. nextClassify, err = data_manage.GetEdbClassifyById(nextClassifyId)
  592. if err != nil {
  593. errMsg = "移动失败"
  594. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  595. return
  596. }
  597. nextSort = nextClassify.Sort
  598. } else if nextEdbInfoId > 0 {
  599. //下一个兄弟节点
  600. nextEdbInfo, err = data_manage.GetEdbInfoById(nextEdbInfoId)
  601. if err != nil {
  602. errMsg = "移动失败"
  603. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  604. return
  605. }
  606. nextSort = nextEdbInfo.Sort
  607. }
  608. err, errMsg = moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify, edbInfo, prevEdbInfo, nextEdbInfo, parentClassifyId, prevSort, nextSort, classifyType)
  609. return
  610. }
  611. // moveEdbClassify 移动指标分类
  612. func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify *data_manage.EdbClassify, edbInfo, prevEdbInfo, nextEdbInfo *data_manage.EdbInfo, parentClassifyId int, prevSort, nextSort int, classifyType uint8) (err error, errMsg string) {
  613. updateCol := make([]string, 0)
  614. // 移动对象为分类, 判断分类是否存在
  615. if edbClassifyInfo != nil {
  616. oldParentId := edbClassifyInfo.ParentId
  617. oldLevel := edbClassifyInfo.Level
  618. var classifyIds []int
  619. if oldParentId != parentClassifyId {
  620. //更新子分类对应的level
  621. childList, e, m := GetChildClassifyByClassifyId(edbClassifyInfo.ClassifyId)
  622. if e != nil {
  623. errMsg = "移动失败"
  624. err = errors.New("查询子分类失败,Err:" + e.Error() + m)
  625. return
  626. }
  627. if len(childList) > 0 {
  628. for _, v := range childList {
  629. if v.ClassifyId == edbClassifyInfo.ClassifyId {
  630. continue
  631. }
  632. classifyIds = append(classifyIds, v.ClassifyId)
  633. }
  634. }
  635. }
  636. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  637. if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
  638. if edbClassifyInfo.Level != parentEdbClassifyInfo.Level+1 { //禁止层级调整
  639. errMsg = "移动失败"
  640. err = errors.New("不支持目录层级变更")
  641. return
  642. }
  643. edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  644. edbClassifyInfo.RootId = parentEdbClassifyInfo.RootId
  645. edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  646. edbClassifyInfo.ModifyTime = time.Now()
  647. updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
  648. } else if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
  649. errMsg = "移动失败"
  650. err = errors.New("不支持目录层级变更")
  651. return
  652. }
  653. if prevSort > 0 {
  654. //如果是移动在两个兄弟节点之间
  655. if nextSort > 0 {
  656. //下一个兄弟节点
  657. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  658. if prevSort == nextSort || prevSort == edbClassifyInfo.Sort {
  659. //变更兄弟节点的排序
  660. updateSortStr := `sort + 2`
  661. //变更分类
  662. if prevClassify != nil {
  663. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr, classifyType)
  664. } else {
  665. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  666. }
  667. //变更指标
  668. if prevEdbInfo != nil {
  669. //变更兄弟节点的排序
  670. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  671. } else {
  672. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  673. }
  674. } else {
  675. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  676. if nextSort-prevSort == 1 {
  677. //变更兄弟节点的排序
  678. updateSortStr := `sort + 1`
  679. //变更分类
  680. if prevClassify != nil {
  681. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
  682. } else {
  683. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  684. }
  685. //变更指标
  686. if prevEdbInfo != nil {
  687. //变更兄弟节点的排序
  688. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  689. } else {
  690. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  691. }
  692. }
  693. }
  694. }
  695. edbClassifyInfo.Sort = prevSort + 1
  696. edbClassifyInfo.ModifyTime = time.Now()
  697. updateCol = append(updateCol, "Sort", "ModifyTime")
  698. } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
  699. //处理只拖动到目录里,默认放到目录底部的情况
  700. var maxSort int
  701. maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
  702. if err != nil {
  703. errMsg = "移动失败"
  704. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  705. return
  706. }
  707. edbClassifyInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  708. edbClassifyInfo.ModifyTime = time.Now()
  709. updateCol = append(updateCol, "Sort", "ModifyTime")
  710. } else {
  711. // 拖动到父级分类的第一位
  712. firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)
  713. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  714. errMsg = "移动失败"
  715. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  716. return
  717. }
  718. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  719. if firstClassify != nil && firstClassify.Sort == 0 {
  720. updateSortStr := ` sort + 1 `
  721. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, firstClassify.ClassifyId-1, 0, updateSortStr, classifyType)
  722. //该分类下的所有指标也需要+1
  723. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
  724. } else {
  725. //如果该分类下存在指标,且第一个指标的排序等于0,那么需要调整排序
  726. firstEdb, tErr := data_manage.GetFirstEdbInfoByClassifyId(parentClassifyId)
  727. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  728. errMsg = "移动失败"
  729. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  730. return
  731. }
  732. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  733. if firstEdb != nil && firstEdb.Sort == 0 {
  734. updateSortStr := ` sort + 1 `
  735. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, firstEdb.EdbInfoId-1, updateSortStr)
  736. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr, classifyType)
  737. }
  738. }
  739. edbClassifyInfo.Sort = 0 //那就是排在第一位
  740. edbClassifyInfo.ModifyTime = time.Now()
  741. updateCol = append(updateCol, "Sort", "ModifyTime")
  742. }
  743. //更新
  744. if len(updateCol) > 0 {
  745. err = edbClassifyInfo.Update(updateCol)
  746. if err != nil {
  747. errMsg = "移动失败"
  748. err = errors.New("修改失败,Err:" + err.Error())
  749. return
  750. }
  751. //更新对应分类的root_id和层级
  752. if oldParentId != parentClassifyId {
  753. if len(classifyIds) > 0 {
  754. levelStep := edbClassifyInfo.Level - oldLevel
  755. err = data_manage.UpdateEdbClassifyChildByParentClassifyId(classifyIds, edbClassifyInfo.RootId, levelStep)
  756. if err != nil {
  757. errMsg = "移动失败"
  758. err = errors.New("更新子分类失败,Err:" + err.Error())
  759. return
  760. }
  761. }
  762. }
  763. }
  764. } else {
  765. if edbInfo == nil {
  766. errMsg = "当前指标不存在"
  767. err = errors.New(errMsg)
  768. return
  769. }
  770. //如果改变了分类,那么移动该指标数据
  771. if edbInfo.ClassifyId != parentClassifyId {
  772. edbInfo.ClassifyId = parentClassifyId
  773. edbInfo.ModifyTime = time.Now()
  774. updateCol = append(updateCol, "ClassifyId", "ModifyTime")
  775. }
  776. if prevSort > 0 {
  777. //如果是移动在两个兄弟节点之间
  778. if nextSort > 0 {
  779. //下一个兄弟节点
  780. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  781. if prevSort == nextSort || prevSort == edbInfo.Sort {
  782. //变更兄弟节点的排序
  783. updateSortStr := `sort + 2`
  784. //变更分类
  785. if prevClassify != nil {
  786. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr, classifyType)
  787. } else {
  788. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  789. }
  790. //变更指标
  791. if prevEdbInfo != nil {
  792. //变更兄弟节点的排序
  793. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  794. } else {
  795. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  796. }
  797. } else {
  798. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  799. if nextSort-prevSort == 1 {
  800. //变更兄弟节点的排序
  801. updateSortStr := `sort + 1`
  802. //变更分类
  803. if prevClassify != nil {
  804. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
  805. } else {
  806. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  807. }
  808. //变更指标
  809. if prevEdbInfo != nil {
  810. //变更兄弟节点的排序
  811. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  812. } else {
  813. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  814. }
  815. }
  816. }
  817. }
  818. edbInfo.Sort = prevSort + 1
  819. edbInfo.ModifyTime = time.Now()
  820. updateCol = append(updateCol, "Sort", "ModifyTime")
  821. } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
  822. //处理只拖动到目录里,默认放到目录底部的情况
  823. var maxSort int
  824. maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
  825. if err != nil {
  826. errMsg = "移动失败"
  827. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  828. return
  829. }
  830. edbInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  831. edbInfo.ModifyTime = time.Now()
  832. updateCol = append(updateCol, "Sort", "ModifyTime")
  833. } else {
  834. // 拖动到父级分类的第一位
  835. firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)
  836. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  837. errMsg = "移动失败"
  838. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  839. return
  840. }
  841. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  842. if firstClassify != nil && firstClassify.Sort == 0 {
  843. updateSortStr := ` sort + 1 `
  844. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, firstClassify.ClassifyId-1, 0, updateSortStr, classifyType)
  845. //该分类下的所有指标也需要+1
  846. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
  847. } else {
  848. //如果该分类下存在指标,且第一个指标的排序等于0,那么需要调整排序
  849. firstEdb, tErr := data_manage.GetFirstEdbInfoByClassifyId(parentClassifyId)
  850. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  851. errMsg = "移动失败"
  852. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  853. return
  854. }
  855. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  856. if firstEdb != nil && firstEdb.Sort == 0 {
  857. updateSortStr := ` sort + 1 `
  858. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, firstEdb.EdbInfoId-1, updateSortStr)
  859. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr, classifyType)
  860. }
  861. }
  862. edbInfo.Sort = 0 //那就是排在第一位
  863. edbInfo.ModifyTime = time.Now()
  864. updateCol = append(updateCol, "Sort", "ModifyTime")
  865. }
  866. //更新
  867. if len(updateCol) > 0 {
  868. err = edbInfo.Update(updateCol)
  869. if err != nil {
  870. errMsg = "移动失败"
  871. err = errors.New("修改失败,Err:" + err.Error())
  872. return
  873. }
  874. }
  875. }
  876. return
  877. }
  878. // GetEdbOpButton 获取ETA指标的操作权限
  879. func GetEdbOpButton(sysUser *system.Admin, belongUserId, edbType, edbInfoType int) (button data_manage.EdbClassifyItemsButton) {
  880. //2、用户对于自己添加的分类,有权限编辑、移动和删除该分类;
  881. //3、ficc管理员和超管对所有分类有编辑、移动和删除权限;
  882. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.EdbPermission == 1 {
  883. button.AddButton = true
  884. button.OpButton = true
  885. button.DeleteButton = true
  886. button.MoveButton = true
  887. // ETA指标的基础指标才允许插入值
  888. if edbInfoType == 0 && edbType == 1 {
  889. button.InsertNewDataButton = true
  890. }
  891. }
  892. button.ShowEdbRelation = true
  893. button.ShowChartRelation = true
  894. return
  895. }
  896. // GetEdbClassifyOpButton 获取ETA指标分类的操作权限
  897. func GetEdbClassifyOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.EdbClassifyItemsButton) {
  898. //ficc管理员和超管和ficc研究员有权限创建和管理分类,可以编辑分类名称(分类名称不允许重复),可以拖动分类,改变分类顺序,可以拖动分类下模型,改变顺序,可以删除分类,若分类下有预测指标,则不允许删除;
  899. //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) {
  900. button.AddButton = true
  901. button.OpButton = true
  902. button.DeleteButton = true
  903. button.MoveButton = true
  904. //}
  905. return
  906. }
  907. // GetPredictEdbOpButton 获取ETA预测指标的操作权限
  908. //func GetPredictEdbOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.EdbClassifyItemsButton) {
  909. // //预测指标的添加人对该预测指标有全部操作权限,ficc管理员、超管对所有预测指标有全部操作权限;
  910. // if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.PredictEdbPermission == 1 {
  911. // button.AddButton = true
  912. // button.OpButton = true
  913. // button.DeleteButton = true
  914. // button.MoveButton = true
  915. // }
  916. // button.ShowEdbRelation = true
  917. // button.ShowChartRelation = true
  918. //
  919. // return
  920. //}
  921. // GetPredictEdbClassifyOpButton 获取ETA预测指标分类的操作权限
  922. func GetPredictEdbClassifyOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.EdbClassifyItemsButton) {
  923. //ficc管理员和超管和ficc研究员有权限创建和管理分类,可以编辑分类名称(分类名称不允许重复),可以拖动分类,改变分类顺序,可以拖动分类下模型,改变顺序,可以删除分类,若分类下有预测指标,则不允许删除;
  924. //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) {
  925. button.AddButton = true
  926. button.OpButton = true
  927. button.DeleteButton = true
  928. button.MoveButton = true
  929. //}
  930. return
  931. }
  932. // GetClassifyTreeRecursive 递归获取分类树形结构
  933. func GetClassifyTreeRecursive(list []*data_manage.EdbClassifyItems, parentId int) []*data_manage.EdbClassifyItems {
  934. res := make([]*data_manage.EdbClassifyItems, 0)
  935. for _, v := range list {
  936. if v.ParentId == parentId {
  937. v.Children = GetClassifyTreeRecursive(list, v.ClassifyId)
  938. res = append(res, v)
  939. }
  940. }
  941. return res
  942. }
  943. func GetFullClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.EdbClassifyIdItems, err error, errMsg string) {
  944. //判断是否是挂在顶级目录下
  945. targetClassify, err := data_manage.GetEdbClassifyById(targetClassifyId)
  946. if err != nil {
  947. if err.Error() == utils.ErrNoRow() {
  948. errMsg = "当前分类不存在"
  949. err = errors.New(errMsg)
  950. return
  951. }
  952. errMsg = "获取失败"
  953. err = errors.New("获取分类信息失败,Err:" + err.Error())
  954. return
  955. }
  956. if targetClassify.ParentId == 0 {
  957. targetItem := new(data_manage.EdbClassifyIdItems)
  958. targetItem.ClassifyId = targetClassify.ClassifyId
  959. targetItem.ParentId = targetClassify.ParentId
  960. targetItem.RootId = targetClassify.RootId
  961. targetItem.UniqueCode = targetClassify.UniqueCode
  962. targetItem.Level = targetClassify.Level
  963. targetItem.ClassifyName = targetClassify.ClassifyName
  964. targetList = append(targetList, targetItem)
  965. return
  966. }
  967. tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, "")
  968. if err != nil && err.Error() != utils.ErrNoRow() {
  969. errMsg = "获取失败"
  970. err = errors.New("获取数据失败,Err:" + err.Error())
  971. return
  972. }
  973. idMap := make(map[int]struct{})
  974. if len(tmpList) > 0 {
  975. for _, v := range tmpList {
  976. if v.ClassifyId == targetClassify.ClassifyId {
  977. idMap[v.ClassifyId] = struct{}{}
  978. idMap[v.ParentId] = struct{}{}
  979. }
  980. }
  981. for _, v := range tmpList {
  982. if _, ok := idMap[v.ClassifyId]; ok {
  983. idMap[v.ParentId] = struct{}{}
  984. }
  985. }
  986. for _, v := range tmpList {
  987. if _, ok := idMap[v.ClassifyId]; ok {
  988. targetItem := new(data_manage.EdbClassifyIdItems)
  989. targetItem.ClassifyId = v.ClassifyId
  990. targetItem.ParentId = v.ParentId
  991. targetItem.RootId = v.RootId
  992. targetItem.UniqueCode = v.UniqueCode
  993. targetItem.Level = v.Level
  994. targetItem.ClassifyName = v.ClassifyName
  995. targetList = append(targetList, targetItem)
  996. }
  997. }
  998. }
  999. return
  1000. }
  1001. func GetChildClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.EdbClassifyIdItems, err error, errMsg string) {
  1002. //判断是否是挂在顶级目录下
  1003. targetClassify, err := data_manage.GetEdbClassifyById(targetClassifyId)
  1004. if err != nil {
  1005. if err.Error() == utils.ErrNoRow() {
  1006. errMsg = "当前分类不存在"
  1007. err = errors.New(errMsg)
  1008. return
  1009. }
  1010. errMsg = "获取失败"
  1011. err = errors.New("获取分类信息失败,Err:" + err.Error())
  1012. return
  1013. }
  1014. orderStr := ` order by level asc, sort asc, classify_id asc`
  1015. tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, orderStr)
  1016. if err != nil && err.Error() != utils.ErrNoRow() {
  1017. errMsg = "获取失败"
  1018. err = errors.New("获取数据失败,Err:" + err.Error())
  1019. return
  1020. }
  1021. idMap := make(map[int]struct{})
  1022. if len(tmpList) > 0 {
  1023. for _, v := range tmpList {
  1024. if v.ClassifyId == targetClassify.ClassifyId {
  1025. idMap[v.ClassifyId] = struct{}{}
  1026. }
  1027. }
  1028. for _, v := range tmpList {
  1029. if _, ok := idMap[v.ParentId]; ok {
  1030. idMap[v.ClassifyId] = struct{}{}
  1031. }
  1032. }
  1033. for _, v := range tmpList {
  1034. if _, ok := idMap[v.ClassifyId]; ok {
  1035. targetItem := new(data_manage.EdbClassifyIdItems)
  1036. targetItem.ClassifyId = v.ClassifyId
  1037. targetItem.ParentId = v.ParentId
  1038. targetItem.RootId = v.RootId
  1039. targetItem.UniqueCode = v.UniqueCode
  1040. targetItem.Level = v.Level
  1041. targetItem.ClassifyName = v.ClassifyName
  1042. targetList = append(targetList, targetItem)
  1043. }
  1044. }
  1045. }
  1046. return
  1047. }
  1048. func GetEdbClassifyMaxSort(parentId int, classifyType uint8) (maxSort int, err error) {
  1049. //获取该层级下最大的排序数
  1050. classifyMaxSort, err := data_manage.GetEdbClassifyMaxSort(parentId, classifyType)
  1051. if err != nil {
  1052. return
  1053. }
  1054. maxSort = classifyMaxSort
  1055. edbMaxSort, err := data_manage.GetEdbInfoMaxSortByClassifyId(parentId)
  1056. if err != nil {
  1057. return
  1058. }
  1059. if maxSort < edbMaxSort {
  1060. maxSort = edbMaxSort
  1061. }
  1062. return
  1063. }