edb_classify.go 21 KB

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