edb_classify.go 42 KB

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