edb_classify.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. package data
  2. import (
  3. "errors"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/system"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "strconv"
  10. "time"
  11. )
  12. func EdbClassifyListMakeTree(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) {
  13. childs, _ := edbClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  14. allEdbInfo, _ := GetEdbClassifyEdbInfo()
  15. if len(childs) > 0 {
  16. node.Children = append(node.Children, childs[0:]...) //添加子节点
  17. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  18. _, has := edbClassifyHaveChild(allNode, v)
  19. if has {
  20. EdbClassifyListMakeTree(allNode, v) //递归添加节点
  21. } else {
  22. edbInfoList := allEdbInfo[v.ClassifyId]
  23. v.Children = edbInfoList
  24. if v.Children == nil {
  25. childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  26. v.Children = childrenArr
  27. }
  28. }
  29. }
  30. } else {
  31. childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  32. node.Children = childrenArr
  33. }
  34. }
  35. func edbClassifyHaveChild(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) (childs []*data_manage.EdbClassifyItems, yes bool) {
  36. for _, v := range allNode {
  37. if v.ParentId == node.ClassifyId {
  38. childs = append(childs, v)
  39. }
  40. }
  41. if len(childs) > 0 {
  42. yes = true
  43. }
  44. return
  45. }
  46. func GetEdbClassifyEdbInfo() (result map[int][]*data_manage.EdbClassifyItems, err error) {
  47. cMap := make(map[int][]*data_manage.EdbClassifyItems)
  48. items, err := data_manage.GetEdbInfoAll(0)
  49. if err != nil {
  50. return
  51. }
  52. for _, v := range items {
  53. childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  54. v.Children = childrenArr
  55. if items, ok := cMap[v.ClassifyId]; ok {
  56. items = append(items, v)
  57. cMap[v.ClassifyId] = items
  58. } else {
  59. infoList := make([]*data_manage.EdbClassifyItems, 0)
  60. infoList = append(infoList, v)
  61. cMap[v.ClassifyId] = infoList
  62. }
  63. }
  64. result = cMap
  65. return
  66. }
  67. func EdbClassifyItemsMakeTree(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) {
  68. childs, _ := edbClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  69. if len(childs) > 0 {
  70. node.Children = append(node.Children, childs[0:]...) //添加子节点
  71. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  72. _, has := edbClassifyHaveChild(allNode, v)
  73. if has {
  74. EdbClassifyItemsMakeTree(allNode, v) //递归添加节点
  75. } else {
  76. childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  77. v.Children = childrenArr
  78. }
  79. }
  80. } else {
  81. childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  82. node.Children = childrenArr
  83. }
  84. }
  85. // GetEdbClassifyListByAdminId 根据账户类型获取分类id集合
  86. func GetEdbClassifyListByAdminId(adminId int64) (classifyIdList []string, err error) {
  87. list, err := models.GetEdbdataClassify(adminId)
  88. if err != nil {
  89. return
  90. }
  91. for _, parent := range list {
  92. if parent.Child != nil {
  93. for _, classify := range parent.Child {
  94. classifyIdList = append(classifyIdList, fmt.Sprint(classify.ClassifyId))
  95. }
  96. }
  97. }
  98. return
  99. }
  100. // GetEdbClassifyNameListByAdminId 根据账户类型获取分类名称集合
  101. func GetEdbClassifyNameListByAdminId(adminId int64) (classifyNameList []string, edbDataClassifyMap map[string]*models.EdbdataClassify, err error) {
  102. list, err := models.GetEdbdataClassify(adminId)
  103. edbDataClassifyMap = make(map[string]*models.EdbdataClassify)
  104. if err != nil {
  105. return
  106. }
  107. for _, parent := range list {
  108. if parent.Child != nil {
  109. for _, classify := range parent.Child {
  110. classifyNameList = append(classifyNameList, classify.ClassifyName)
  111. edbDataClassifyMap[classify.ClassifyName] = classify
  112. }
  113. }
  114. }
  115. return
  116. }
  117. // AddEdbClassify 添加指标分类
  118. func AddEdbClassify(classifyName string, parentId, level int, classifyType uint8, sysUserId int, sysUserName string) (classifyInfo *data_manage.EdbClassify, err error, errMsg string) {
  119. count, err := data_manage.GetEdbClassifyCount(classifyName, parentId, classifyType)
  120. if err != nil {
  121. errMsg = `判断名称是否已存在失败`
  122. return
  123. }
  124. if count > 0 {
  125. errMsg = `分类名称已存在,请重新输入`
  126. return
  127. }
  128. //获取该层级下最大的排序数
  129. maxSort, err := data_manage.GetEdbClassifyMaxSort(parentId, classifyType)
  130. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  131. classifyInfo = &data_manage.EdbClassify{
  132. //ClassifyId: 0,
  133. ClassifyType: classifyType,
  134. ClassifyName: classifyName,
  135. ParentId: parentId,
  136. HasData: 0,
  137. CreateTime: time.Now(),
  138. ModifyTime: time.Now(),
  139. SysUserId: sysUserId,
  140. SysUserRealName: sysUserName,
  141. Level: level + 1,
  142. UniqueCode: utils.MD5(utils.DATA_PREFIX + "_" + timestamp),
  143. Sort: maxSort,
  144. }
  145. _, err = data_manage.AddEdbClassify(classifyInfo)
  146. if err != nil {
  147. errMsg = "保存分类失败"
  148. }
  149. return
  150. }
  151. // EditEdbClassify 编辑指标分类
  152. func EditEdbClassify(classifyId int, classifyName string, sysUser *system.Admin) (err error, errMsg string) {
  153. item, err := data_manage.GetEdbClassifyById(classifyId)
  154. if err != nil {
  155. errMsg = `保存失败`
  156. return
  157. }
  158. // 权限校验
  159. {
  160. if item.ClassifyType == 0 { // 普通指标
  161. button := GetEdbClassifyOpButton(sysUser, item.SysUserId)
  162. if !button.OpButton {
  163. errMsg = "无操作权限"
  164. err = errors.New(errMsg)
  165. return
  166. }
  167. } else if item.ClassifyType == 1 { // 预测指标
  168. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId)
  169. if !button.OpButton {
  170. errMsg = "无操作权限"
  171. err = errors.New(errMsg)
  172. return
  173. }
  174. }
  175. }
  176. // 名字相同,那么就直接返回
  177. if item.ClassifyName == classifyName {
  178. return
  179. }
  180. // 判断名称是否已存在
  181. count, err := data_manage.GetEdbClassifyCount(classifyName, item.ParentId, item.ClassifyType)
  182. if err != nil {
  183. errMsg = "判断名称是否已存在失败"
  184. return
  185. }
  186. if count > 0 {
  187. errMsg = "分类名称已存在,请重新输入"
  188. return
  189. }
  190. // 修改数据
  191. err = data_manage.EditEdbClassify(classifyId, classifyName)
  192. if err != nil {
  193. errMsg = "保存失败"
  194. }
  195. return
  196. }
  197. // DeleteCheck 删除检测
  198. func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, err error, errMsg string) {
  199. //删除分类
  200. if classifyId > 0 && edbInfoId == 0 {
  201. // 查找分类
  202. item, tmpErr := data_manage.GetEdbClassifyById(classifyId)
  203. if tmpErr != nil {
  204. errMsg = `查找分类失败`
  205. err = tmpErr
  206. return
  207. }
  208. // 权限校验
  209. {
  210. if item.ClassifyType == 0 { // 普通指标
  211. button := GetEdbClassifyOpButton(sysUser, item.SysUserId)
  212. if !button.DeleteButton {
  213. errMsg = "无操作权限"
  214. err = errors.New(errMsg)
  215. return
  216. }
  217. } else if item.ClassifyType == 1 { // 预测指标
  218. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId)
  219. if !button.DeleteButton {
  220. errMsg = "无操作权限"
  221. err = errors.New(errMsg)
  222. return
  223. }
  224. }
  225. }
  226. //判断分类下,是否含有指标
  227. count, tmpErr := data_manage.GetEdbInfoCountByClassifyId(classifyId)
  228. if tmpErr != nil {
  229. errMsg = "删除失败"
  230. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  231. return
  232. }
  233. if count > 0 {
  234. deleteStatus = 1
  235. tipsMsg = "若目录关联指标不可删除"
  236. }
  237. }
  238. if deleteStatus != 1 && edbInfoId == 0 {
  239. classifyCount, tmpErr := data_manage.GetClassifyCountByClassifyId(classifyId)
  240. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  241. errMsg = "删除失败"
  242. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  243. return
  244. }
  245. if classifyCount > 0 {
  246. deleteStatus = 2
  247. tipsMsg = "确认删除当前目录及包含的子目录吗"
  248. }
  249. }
  250. //删除指标
  251. if edbInfoId > 0 {
  252. //判断指标是否用于作图,如果用于作图,则不可删除
  253. chartCount, tmpErr := data_manage.GetChartEdbMappingCount(edbInfoId)
  254. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  255. errMsg = "删除失败"
  256. err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
  257. return
  258. }
  259. if chartCount > 0 {
  260. deleteStatus = 3
  261. tipsMsg = "当前指标已用作画图,不可删除"
  262. }
  263. //判断指标是否用于计算
  264. {
  265. calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
  266. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  267. errMsg = "删除失败"
  268. err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
  269. return
  270. }
  271. if calculateCount > 0 {
  272. deleteStatus = 4
  273. tipsMsg = "当前指标已用作,指标运算,不可删除"
  274. }
  275. }
  276. }
  277. return
  278. }
  279. // Delete 删除分类/指标
  280. func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, requestUrl string) (nextItem *data_manage.EdbInfo, err error, errMsg string) {
  281. //删除分类
  282. if classifyId > 0 && edbInfoId == 0 {
  283. // 查找分类
  284. item, tmpErr := data_manage.GetEdbClassifyById(classifyId)
  285. if tmpErr != nil {
  286. errMsg = `查找分类失败`
  287. err = tmpErr
  288. return
  289. }
  290. // 权限校验
  291. {
  292. if item.ClassifyType == 0 { // 普通指标
  293. button := GetEdbClassifyOpButton(sysUser, item.SysUserId)
  294. if !button.DeleteButton {
  295. errMsg = "无操作权限"
  296. err = errors.New(errMsg)
  297. return
  298. }
  299. } else if item.ClassifyType == 1 { // 预测指标
  300. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId)
  301. if !button.DeleteButton {
  302. errMsg = "无操作权限"
  303. err = errors.New(errMsg)
  304. return
  305. }
  306. }
  307. }
  308. //判断是否含有指标
  309. count, tmpErr := data_manage.GetEdbInfoCountByClassifyId(classifyId)
  310. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  311. errMsg = "删除失败"
  312. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  313. return
  314. }
  315. if count > 0 {
  316. errMsg = "该目录下存在关联指标,不可删除"
  317. return
  318. }
  319. tmpErr = data_manage.DeleteEdbClassify(classifyId)
  320. if tmpErr != nil {
  321. errMsg = "删除失败"
  322. err = errors.New("删除失败,Err:" + tmpErr.Error())
  323. return
  324. }
  325. }
  326. //删除指标
  327. if edbInfoId > 0 {
  328. edbInfo, tmpErr := data_manage.GetEdbInfoById(edbInfoId)
  329. if tmpErr != nil {
  330. if tmpErr.Error() == utils.ErrNoRow() {
  331. errMsg = "指标已删除,请刷新页面"
  332. err = errors.New("指标不存在,Err:" + tmpErr.Error())
  333. return
  334. } else {
  335. errMsg = "删除失败"
  336. err = errors.New("删除失败,获取指标信息失败,Err:" + tmpErr.Error())
  337. return
  338. }
  339. }
  340. if edbInfo == nil {
  341. errMsg = "指标已删除,请刷新页面"
  342. return
  343. }
  344. //判断指标是否用于作图,如果用于作图,则不可删除
  345. chartCount, tmpErr := data_manage.GetChartEdbMappingCount(edbInfoId)
  346. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  347. errMsg = "删除失败"
  348. err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
  349. return
  350. }
  351. if chartCount > 0 {
  352. errMsg = "当前指标已用作画图,不可删除"
  353. return
  354. }
  355. //如果是普通指标,那么还需要判断是否被预测指标作为源指标
  356. if edbInfo.EdbInfoType == 0 {
  357. predictEdbInfoCount, tmpErr := data_manage.GetPredictEdbConfCount(edbInfoId)
  358. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  359. errMsg = "删除失败"
  360. err = errors.New("判断指标是否被用于预测指标失败,Err:" + tmpErr.Error())
  361. return
  362. }
  363. if predictEdbInfoCount > 0 {
  364. errMsg = "当前指标已用作预测指标,不可删除"
  365. return
  366. }
  367. }
  368. //判断指标是否用作其他指标的计算
  369. {
  370. calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
  371. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  372. errMsg = "删除失败"
  373. err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
  374. return
  375. }
  376. if calculateCount > 0 {
  377. errMsg = "当前指标已用作,指标运算,不可删除"
  378. return
  379. }
  380. }
  381. //真实删除
  382. tmpErr = data_manage.DeleteEdbInfoAndData(edbInfo.EdbInfoId, edbInfo.Source)
  383. if tmpErr != nil {
  384. errMsg = "删除失败"
  385. err = errors.New("删除失败,Err:" + tmpErr.Error())
  386. return
  387. }
  388. // 返回下一个表格的信息
  389. {
  390. var condition string
  391. var pars []interface{}
  392. condition += " AND edb_info_type=? AND classify_id=? "
  393. pars = append(pars, edbInfo.EdbInfoType, edbInfo.ClassifyId)
  394. condition += " AND (sort>? OR (sort=? AND edb_info_id<?) ) "
  395. pars = append(pars, edbInfo.Sort, edbInfo.Sort, edbInfo.EdbInfoId)
  396. nextItem, tmpErr = data_manage.GetNextEdbInfoByCondition(condition, pars)
  397. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  398. errMsg = "删除失败"
  399. err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
  400. return
  401. }
  402. // 如果没找到,那么查找下一个分类的第一个表格
  403. if nextItem == nil {
  404. currClassifyInfo, tmpErr := data_manage.GetEdbClassifyById(edbInfo.ClassifyId)
  405. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  406. errMsg = "删除失败"
  407. err = errors.New("获取当前预测指标分类信息失败,Err:" + tmpErr.Error())
  408. return
  409. }
  410. nextItem, err = data_manage.GetNextEdbInfo(edbInfo.ClassifyId, currClassifyInfo.Sort, int(currClassifyInfo.ClassifyType), edbInfo.EdbInfoType)
  411. if err != nil && err.Error() != utils.ErrNoRow() {
  412. errMsg = "删除失败"
  413. err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
  414. return
  415. }
  416. }
  417. }
  418. //新增操作日志
  419. {
  420. edbLog := new(data_manage.EdbInfoLog)
  421. edbLog.EdbInfoId = edbInfo.EdbInfoId
  422. edbLog.SourceName = edbInfo.SourceName
  423. edbLog.Source = edbInfo.Source
  424. edbLog.EdbCode = edbInfo.EdbCode
  425. edbLog.EdbName = edbInfo.EdbName
  426. edbLog.ClassifyId = edbInfo.ClassifyId
  427. edbLog.SysUserId = sysUser.AdminId
  428. edbLog.SysUserRealName = sysUser.RealName
  429. edbLog.CreateTime = time.Now()
  430. edbLog.Content = requestBody
  431. edbLog.Status = "删除指标"
  432. edbLog.Method = requestUrl
  433. go data_manage.AddEdbInfoLog(edbLog)
  434. }
  435. // 删除es中的数据
  436. DeleteEdbInfoToEs(edbInfoId)
  437. }
  438. return
  439. }
  440. // MoveEdbClassify 移动指标分类
  441. func MoveEdbClassify(classifyId, parentClassifyId, prevClassifyId, nextClassifyId int, sysUser *system.Admin) (err error, errMsg string) {
  442. //判断分类是否存在
  443. edbClassifyInfo, err := data_manage.GetEdbClassifyById(classifyId)
  444. if err != nil {
  445. errMsg = "移动失败"
  446. err = errors.New("获取分类信息失败,Err:" + err.Error())
  447. return
  448. }
  449. // 权限校验
  450. {
  451. if edbClassifyInfo.ClassifyType == 0 { // 普通指标
  452. button := GetEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId)
  453. if !button.MoveButton {
  454. errMsg = "无操作权限"
  455. err = errors.New(errMsg)
  456. return
  457. }
  458. } else if edbClassifyInfo.ClassifyType == 1 { // 预测指标
  459. button := GetPredictEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId)
  460. if !button.MoveButton {
  461. errMsg = "无操作权限"
  462. err = errors.New(errMsg)
  463. return
  464. }
  465. }
  466. }
  467. updateCol := make([]string, 0)
  468. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  469. if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
  470. parentEdbClassifyInfo, tmpErr := data_manage.GetEdbClassifyById(parentClassifyId)
  471. if tmpErr != nil {
  472. errMsg = "移动失败"
  473. err = errors.New("获取上级分类信息失败,Err:" + tmpErr.Error())
  474. return
  475. }
  476. edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  477. edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  478. edbClassifyInfo.ModifyTime = time.Now()
  479. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  480. }
  481. //如果有传入 上一个兄弟节点分类id
  482. if prevClassifyId > 0 {
  483. prevClassify, tmpErr := data_manage.GetEdbClassifyById(prevClassifyId)
  484. if tmpErr != nil {
  485. errMsg = "移动失败"
  486. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + tmpErr.Error())
  487. return
  488. }
  489. //如果是移动在两个兄弟节点之间
  490. if nextClassifyId > 0 {
  491. //下一个兄弟节点
  492. nextClassify, tmpErr := data_manage.GetEdbClassifyById(nextClassifyId)
  493. if tmpErr != nil {
  494. errMsg = "移动失败"
  495. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + tmpErr.Error())
  496. return
  497. }
  498. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  499. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort {
  500. //变更兄弟节点的排序
  501. updateSortStr := `sort + 2`
  502. _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr, edbClassifyInfo.ClassifyType)
  503. } else {
  504. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  505. if nextClassify.Sort-prevClassify.Sort == 1 {
  506. //变更兄弟节点的排序
  507. updateSortStr := `sort + 1`
  508. _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr, edbClassifyInfo.ClassifyType)
  509. }
  510. }
  511. }
  512. edbClassifyInfo.Sort = prevClassify.Sort + 1
  513. edbClassifyInfo.ModifyTime = time.Now()
  514. updateCol = append(updateCol, "Sort", "ModifyTime")
  515. } else {
  516. firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId)
  517. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  518. errMsg = "移动失败"
  519. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  520. return
  521. }
  522. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  523. if firstClassify != nil && firstClassify.Sort == 0 {
  524. updateSortStr := ` sort + 1 `
  525. _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr, edbClassifyInfo.ClassifyType)
  526. }
  527. edbClassifyInfo.Sort = 0 //那就是排在第一位
  528. edbClassifyInfo.ModifyTime = time.Now()
  529. updateCol = append(updateCol, "Sort", "ModifyTime")
  530. }
  531. //更新
  532. if len(updateCol) > 0 {
  533. err = edbClassifyInfo.Update(updateCol)
  534. if err != nil {
  535. errMsg = "移动失败"
  536. err = errors.New("修改失败,Err:" + err.Error())
  537. return
  538. }
  539. }
  540. return
  541. }
  542. // GetEdbOpButton 获取ETA指标的操作权限
  543. func GetEdbOpButton(sysUser *system.Admin, belongUserId, edbType, edbInfoType int) (button data_manage.EdbClassifyItemsButton) {
  544. //2、用户对于自己添加的分类,有权限编辑、移动和删除该分类;
  545. //3、ficc管理员和超管对所有分类有编辑、移动和删除权限;
  546. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.EdbPermission == 1 {
  547. button.AddButton = true
  548. button.OpButton = true
  549. button.DeleteButton = true
  550. button.MoveButton = true
  551. // ETA指标的基础指标才允许插入值
  552. if edbInfoType == 0 && edbType == 1 {
  553. button.InsertNewDataButton = true
  554. }
  555. }
  556. button.ShowEdbRelation = true
  557. button.ShowChartRelation = true
  558. return
  559. }
  560. // GetEdbClassifyOpButton 获取ETA指标分类的操作权限
  561. func GetEdbClassifyOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.EdbClassifyItemsButton) {
  562. //ficc管理员和超管和ficc研究员有权限创建和管理分类,可以编辑分类名称(分类名称不允许重复),可以拖动分类,改变分类顺序,可以拖动分类下模型,改变顺序,可以删除分类,若分类下有预测指标,则不允许删除;
  563. //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) {
  564. button.AddButton = true
  565. button.OpButton = true
  566. button.DeleteButton = true
  567. button.MoveButton = true
  568. //}
  569. return
  570. }
  571. // GetPredictEdbOpButton 获取ETA预测指标的操作权限
  572. func GetPredictEdbOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.EdbClassifyItemsButton) {
  573. //预测指标的添加人对该预测指标有全部操作权限,ficc管理员、超管对所有预测指标有全部操作权限;
  574. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.PredictEdbPermission == 1 {
  575. button.AddButton = true
  576. button.OpButton = true
  577. button.DeleteButton = true
  578. button.MoveButton = true
  579. }
  580. button.ShowEdbRelation = true
  581. button.ShowChartRelation = true
  582. return
  583. }
  584. // GetPredictEdbClassifyOpButton 获取ETA预测指标分类的操作权限
  585. func GetPredictEdbClassifyOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.EdbClassifyItemsButton) {
  586. //ficc管理员和超管和ficc研究员有权限创建和管理分类,可以编辑分类名称(分类名称不允许重复),可以拖动分类,改变分类顺序,可以拖动分类下模型,改变顺序,可以删除分类,若分类下有预测指标,则不允许删除;
  587. //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) {
  588. button.AddButton = true
  589. button.OpButton = true
  590. button.DeleteButton = true
  591. button.MoveButton = true
  592. //}
  593. return
  594. }