edb_classify.go 22 KB

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