edb_classify.go 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572
  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/data/data_manage_permission"
  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. targetItem.ClassifyNameEn = targetClassify.ClassifyNameEn
  83. targetItem.IsJoinPermission = targetClassify.IsJoinPermission
  84. targetList = append(targetList, targetItem)
  85. return
  86. }
  87. tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, "")
  88. if err != nil && err.Error() != utils.ErrNoRow() {
  89. errMsg = "获取失败"
  90. err = errors.New("获取数据失败,Err:" + err.Error())
  91. return
  92. }
  93. idMap := make(map[int]struct{})
  94. if len(tmpList) > 0 {
  95. for _, v := range tmpList {
  96. if v.ClassifyId == targetClassify.ClassifyId {
  97. idMap[v.ClassifyId] = struct{}{}
  98. idMap[v.ParentId] = struct{}{}
  99. }
  100. }
  101. for _, v := range tmpList {
  102. if _, ok := idMap[v.ClassifyId]; ok {
  103. idMap[v.ParentId] = struct{}{}
  104. }
  105. }
  106. for _, v := range tmpList {
  107. if _, ok := idMap[v.ClassifyId]; ok {
  108. targetItem := new(data_manage.EdbClassifyIdItems)
  109. targetItem.ClassifyId = v.ClassifyId
  110. targetItem.ParentId = v.ParentId
  111. targetItem.RootId = v.RootId
  112. targetItem.UniqueCode = v.UniqueCode
  113. targetItem.Level = v.Level
  114. targetItem.ClassifyName = v.ClassifyName
  115. targetItem.ClassifyNameEn = v.ClassifyNameEn
  116. targetItem.IsJoinPermission = v.IsJoinPermission
  117. targetList = append(targetList, targetItem)
  118. }
  119. }
  120. }
  121. return
  122. }
  123. // GetFullClassifyByRootId 查询指标列表里的分类信息
  124. func GetFullClassifyByRootId(targetClassify *data_manage.EdbClassify, tmpList []*data_manage.EdbClassifyItems) (targetList []*data_manage.EdbClassifyIdItems, err error, errMsg string) {
  125. if targetClassify.ParentId == 0 {
  126. targetItem := new(data_manage.EdbClassifyIdItems)
  127. targetItem.ClassifyId = targetClassify.ClassifyId
  128. targetItem.ParentId = targetClassify.ParentId
  129. targetItem.RootId = targetClassify.RootId
  130. targetItem.UniqueCode = targetClassify.UniqueCode
  131. targetItem.Level = targetClassify.Level
  132. targetItem.ClassifyName = targetClassify.ClassifyName
  133. targetItem.ClassifyName = targetClassify.ClassifyName
  134. targetItem.IsJoinPermission = targetClassify.IsJoinPermission
  135. targetList = append(targetList, targetItem)
  136. return
  137. }
  138. idMap := make(map[int]struct{})
  139. if len(tmpList) > 0 {
  140. for _, v := range tmpList {
  141. if v.ClassifyId == targetClassify.ClassifyId {
  142. idMap[v.ClassifyId] = struct{}{}
  143. idMap[v.ParentId] = struct{}{}
  144. }
  145. }
  146. for _, v := range tmpList {
  147. if _, ok := idMap[v.ClassifyId]; ok {
  148. idMap[v.ParentId] = 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. targetItem.IsJoinPermission = v.IsJoinPermission
  161. targetList = append(targetList, targetItem)
  162. }
  163. }
  164. }
  165. return
  166. }
  167. func GetChildClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.EdbClassifyIdItems, err error, errMsg string) {
  168. //判断是否是挂在顶级目录下
  169. targetClassify, err := data_manage.GetEdbClassifyById(targetClassifyId)
  170. if err != nil {
  171. if err.Error() == utils.ErrNoRow() {
  172. errMsg = "当前分类不存在"
  173. err = errors.New(errMsg)
  174. return
  175. }
  176. errMsg = "获取失败"
  177. err = errors.New("获取分类信息失败,Err:" + err.Error())
  178. return
  179. }
  180. orderStr := ` order by level asc, sort asc, classify_id asc`
  181. tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, orderStr)
  182. if err != nil && err.Error() != utils.ErrNoRow() {
  183. errMsg = "获取失败"
  184. err = errors.New("获取数据失败,Err:" + err.Error())
  185. return
  186. }
  187. idMap := make(map[int]struct{})
  188. if len(tmpList) > 0 {
  189. for _, v := range tmpList {
  190. if v.ClassifyId == targetClassify.ClassifyId {
  191. idMap[v.ClassifyId] = struct{}{}
  192. }
  193. }
  194. for _, v := range tmpList {
  195. if _, ok := idMap[v.ParentId]; ok {
  196. idMap[v.ClassifyId] = struct{}{}
  197. }
  198. }
  199. for _, v := range tmpList {
  200. if _, ok := idMap[v.ClassifyId]; ok {
  201. targetItem := new(data_manage.EdbClassifyIdItems)
  202. targetItem.ClassifyId = v.ClassifyId
  203. targetItem.ParentId = v.ParentId
  204. targetItem.RootId = v.RootId
  205. targetItem.UniqueCode = v.UniqueCode
  206. targetItem.Level = v.Level
  207. targetItem.ClassifyName = v.ClassifyName
  208. targetItem.IsJoinPermission = v.IsJoinPermission
  209. targetList = append(targetList, targetItem)
  210. }
  211. }
  212. }
  213. return
  214. }
  215. func GetEdbClassifyEdbInfo() (result map[int][]*data_manage.EdbClassifyItems, err error) {
  216. cMap := make(map[int][]*data_manage.EdbClassifyItems)
  217. items, err := data_manage.GetEdbInfoAll(0)
  218. if err != nil {
  219. return
  220. }
  221. for _, v := range items {
  222. childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  223. v.Children = childrenArr
  224. if items, ok := cMap[v.ClassifyId]; ok {
  225. items = append(items, v)
  226. cMap[v.ClassifyId] = items
  227. } else {
  228. infoList := make([]*data_manage.EdbClassifyItems, 0)
  229. infoList = append(infoList, v)
  230. cMap[v.ClassifyId] = infoList
  231. }
  232. }
  233. result = cMap
  234. return
  235. }
  236. func EdbClassifyItemsMakeTree(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) {
  237. childs, _ := edbClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  238. if len(childs) > 0 {
  239. node.Children = append(node.Children, childs[0:]...) //添加子节点
  240. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  241. _, has := edbClassifyHaveChild(allNode, v)
  242. if has {
  243. EdbClassifyItemsMakeTree(allNode, v) //递归添加节点
  244. } else {
  245. childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  246. v.Children = childrenArr
  247. }
  248. }
  249. } else {
  250. childrenArr := make([]*data_manage.EdbClassifyItems, 0)
  251. node.Children = childrenArr
  252. }
  253. }
  254. // GetEdbClassifyListByAdminId 根据账户类型获取分类id集合
  255. func GetEdbClassifyListByAdminId(adminId int64) (classifyIdList []string, err error) {
  256. list, err := models.GetEdbdataClassify(adminId)
  257. if err != nil {
  258. return
  259. }
  260. for _, parent := range list {
  261. if parent.Child != nil {
  262. for _, classify := range parent.Child {
  263. classifyIdList = append(classifyIdList, fmt.Sprint(classify.ClassifyId))
  264. }
  265. }
  266. }
  267. return
  268. }
  269. // GetEdbClassifyNameListByAdminId 根据账户类型获取分类名称集合
  270. func GetEdbClassifyNameListByAdminId(adminId int64) (classifyNameList []string, edbDataClassifyMap map[string]*models.EdbdataClassify, err error) {
  271. list, err := models.GetEdbdataClassify(adminId)
  272. edbDataClassifyMap = make(map[string]*models.EdbdataClassify)
  273. if err != nil {
  274. return
  275. }
  276. for _, parent := range list {
  277. if parent.Child != nil {
  278. for _, classify := range parent.Child {
  279. classifyNameList = append(classifyNameList, classify.ClassifyName)
  280. edbDataClassifyMap[classify.ClassifyName] = classify
  281. }
  282. }
  283. }
  284. return
  285. }
  286. // AddEdbClassify 添加指标分类
  287. func AddEdbClassify(classifyName string, parentId, level int, classifyType uint8, sysUserId int, sysUserName, lang string) (classifyInfo *data_manage.EdbClassify, err error, errMsg string) {
  288. // 校验分类名称相同的数量
  289. {
  290. var count int
  291. switch lang {
  292. case utils.EnLangVersion:
  293. count, err = data_manage.GetEdbClassifyEnCount(classifyName, parentId, classifyType)
  294. default:
  295. count, err = data_manage.GetEdbClassifyCount(classifyName, parentId, classifyType)
  296. }
  297. if err != nil {
  298. errMsg = `判断名称是否已存在失败`
  299. return
  300. }
  301. if count > 0 {
  302. errMsg = `分类名称已存在,请重新输入`
  303. err = errors.New(errMsg)
  304. return
  305. }
  306. }
  307. // 层级校验
  308. if level > 6 {
  309. errMsg = `最高只支持添加6级分类`
  310. return
  311. }
  312. //获取该层级下最大的排序数
  313. maxSort, err := GetEdbClassifyMaxSort(parentId, classifyType)
  314. if err != nil {
  315. errMsg = "获取失败"
  316. err = errors.New("查询排序信息失败,Err:" + err.Error())
  317. return
  318. }
  319. //查询顶级rootId
  320. rootId := 0
  321. if parentId > 0 {
  322. parentClassify, tErr := data_manage.GetEdbClassifyById(parentId)
  323. if tErr != nil {
  324. if tErr.Error() == utils.ErrNoRow() {
  325. errMsg = "父级分类不存在"
  326. err = errors.New(errMsg)
  327. return
  328. }
  329. errMsg = "获取失败"
  330. err = errors.New("获取分类信息失败,Err:" + tErr.Error())
  331. return
  332. }
  333. rootId = parentClassify.RootId
  334. }
  335. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  336. classifyInfo = &data_manage.EdbClassify{
  337. //ClassifyId: 0,
  338. ClassifyType: classifyType,
  339. ClassifyName: classifyName,
  340. ClassifyNameEn: classifyName,
  341. ParentId: parentId,
  342. RootId: rootId,
  343. HasData: 0,
  344. CreateTime: time.Now(),
  345. ModifyTime: time.Now(),
  346. SysUserId: sysUserId,
  347. SysUserRealName: sysUserName,
  348. Level: level + 1,
  349. UniqueCode: utils.MD5(utils.DATA_PREFIX + "_" + timestamp),
  350. Sort: maxSort + 1,
  351. }
  352. newId, err := data_manage.AddEdbClassify(classifyInfo)
  353. if err != nil {
  354. errMsg = "保存分类失败"
  355. return
  356. }
  357. // 继承分类权限
  358. {
  359. source := 3
  360. if classifyType == 1 {
  361. source = 4
  362. }
  363. go data_manage_permission.InheritParentClassify(source, int(classifyType), int(newId), classifyInfo.ParentId, classifyInfo.ClassifyName)
  364. }
  365. if parentId == 0 { //一级目录的rootId等于自己本身
  366. classifyInfo.ClassifyId = int(newId)
  367. classifyInfo.RootId = int(newId)
  368. err = classifyInfo.Update([]string{"RootId"})
  369. if err != nil {
  370. errMsg = "更新分类失败"
  371. return
  372. }
  373. }
  374. return
  375. }
  376. // EditEdbClassify 编辑指标分类
  377. func EditEdbClassify(classifyId int, classifyName, lang string, sysUser *system.Admin) (err error, errMsg string) {
  378. item, err := data_manage.GetEdbClassifyById(classifyId)
  379. if err != nil {
  380. errMsg = `保存失败`
  381. return
  382. }
  383. // 权限校验
  384. {
  385. // 已授权分类id
  386. permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
  387. if tmpErr != nil {
  388. errMsg = "保存失败"
  389. err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
  390. return
  391. }
  392. // 数据权限
  393. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ClassifyId, permissionClassifyIdList)
  394. if item.ClassifyType == 0 { // 普通指标
  395. button := GetEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
  396. if !button.OpButton {
  397. errMsg = "无操作权限"
  398. err = errors.New(errMsg)
  399. return
  400. }
  401. } else if item.ClassifyType == 1 { // 预测指标
  402. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
  403. if !button.OpButton {
  404. errMsg = "无操作权限"
  405. err = errors.New(errMsg)
  406. return
  407. }
  408. }
  409. }
  410. // 需要变更的字段
  411. updateCols := make([]string, 0)
  412. switch lang {
  413. case utils.EnLangVersion:
  414. // 名字相同,那么就直接返回
  415. if item.ClassifyNameEn == classifyName {
  416. return
  417. }
  418. // 判断名称是否已存在
  419. count, tmpErr := data_manage.GetEdbClassifyEnCount(classifyName, item.ParentId, item.ClassifyType)
  420. if tmpErr != nil {
  421. err = tmpErr
  422. errMsg = "判断名称是否已存在失败"
  423. return
  424. }
  425. if count > 0 {
  426. errMsg = "分类名称已存在,请重新输入"
  427. err = errors.New(errMsg)
  428. return
  429. }
  430. item.ClassifyNameEn = classifyName
  431. item.LastModifyUserId = sysUser.AdminId
  432. item.LastModifyUserRealName = sysUser.RealName
  433. updateCols = append(updateCols, "ClassifyNameEn", "LastModifyUserId", "LastModifyUserRealName")
  434. default:
  435. // 名字相同,那么就直接返回
  436. if item.ClassifyName == classifyName {
  437. return
  438. }
  439. // 判断名称是否已存在
  440. count, tmpErr := data_manage.GetEdbClassifyCount(classifyName, item.ParentId, item.ClassifyType)
  441. if tmpErr != nil {
  442. err = tmpErr
  443. errMsg = "判断名称是否已存在失败"
  444. return
  445. }
  446. if count > 0 {
  447. errMsg = "分类名称已存在,请重新输入"
  448. err = errors.New(errMsg)
  449. return
  450. }
  451. item.ClassifyName = classifyName
  452. item.LastModifyUserId = sysUser.AdminId
  453. item.LastModifyUserRealName = sysUser.RealName
  454. updateCols = append(updateCols, "ClassifyName", "LastModifyUserId", "LastModifyUserRealName")
  455. }
  456. // 修改数据
  457. if len(updateCols) > 0 {
  458. err = item.Update(updateCols)
  459. if err != nil {
  460. errMsg = "保存失败"
  461. }
  462. }
  463. return
  464. }
  465. // DeleteCheck 删除检测
  466. func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, tableList []*data_manage.ExcelBaseInfo, err error, errMsg string) {
  467. //删除分类
  468. if classifyId > 0 && edbInfoId == 0 {
  469. // 查找分类
  470. item, tmpErr := data_manage.GetEdbClassifyById(classifyId)
  471. if tmpErr != nil {
  472. errMsg = `查找分类失败`
  473. err = tmpErr
  474. return
  475. }
  476. // 已授权分类id
  477. permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
  478. if tmpErr != nil {
  479. errMsg = "删除检测失败"
  480. err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
  481. return
  482. }
  483. // 权限校验
  484. {
  485. // 数据权限
  486. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ClassifyId, permissionClassifyIdList)
  487. if item.ClassifyType == 0 { // 普通指标
  488. button := GetEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
  489. if !button.DeleteButton {
  490. errMsg = "无操作权限"
  491. err = errors.New(errMsg)
  492. return
  493. }
  494. } else if item.ClassifyType == 1 { // 预测指标
  495. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
  496. if !button.DeleteButton {
  497. errMsg = "无操作权限"
  498. err = errors.New(errMsg)
  499. return
  500. }
  501. }
  502. }
  503. //判断分类下,是否含有指标
  504. count, tmpErr := data_manage.GetEdbInfoCountByClassifyId(classifyId)
  505. if tmpErr != nil {
  506. errMsg = "删除失败"
  507. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  508. return
  509. }
  510. if count > 0 {
  511. deleteStatus = 1
  512. tipsMsg = "若目录关联指标不可删除"
  513. }
  514. }
  515. if deleteStatus != 1 && edbInfoId == 0 {
  516. classifyCount, tmpErr := data_manage.GetClassifyCountByClassifyId(classifyId)
  517. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  518. errMsg = "删除失败"
  519. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  520. return
  521. }
  522. if classifyCount > 0 {
  523. deleteStatus = 2
  524. tipsMsg = "确认删除当前目录及包含的子目录吗"
  525. }
  526. }
  527. //删除指标
  528. if edbInfoId > 0 {
  529. edbInfo, tmpErr := data_manage.GetEdbInfoById(edbInfoId)
  530. if tmpErr != nil {
  531. if tmpErr.Error() == utils.ErrNoRow() {
  532. errMsg = "指标已删除,请刷新页面"
  533. err = errors.New("指标不存在,Err:" + tmpErr.Error())
  534. return
  535. } else {
  536. errMsg = "删除失败"
  537. err = errors.New("删除失败,获取指标信息失败,Err:" + tmpErr.Error())
  538. return
  539. }
  540. }
  541. if edbInfo == nil {
  542. errMsg = "指标已删除,请刷新页面"
  543. return
  544. }
  545. //判断指标是否用于作图,如果用于作图,则不可删除
  546. chartCount, tmpErr := data_manage.GetChartEdbMappingCount(edbInfoId)
  547. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  548. errMsg = "删除失败"
  549. err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
  550. return
  551. }
  552. if chartCount > 0 {
  553. deleteStatus = 3
  554. tipsMsg = "当前指标已用作画图,不可删除"
  555. return
  556. }
  557. // 查询是否用于相关性图表
  558. correlationChart := new(data_manage.ChartInfoCorrelation)
  559. correlationChartCount, tmpErr := correlationChart.GetChartEdbMappingCount(edbInfoId)
  560. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  561. errMsg = "删除失败"
  562. err = errors.New("判断指标是否被用于相关性图表失败,Err:" + tmpErr.Error())
  563. return
  564. }
  565. if correlationChartCount > 0 {
  566. deleteStatus = 3
  567. tipsMsg = "当前指标已用作画图,不可删除"
  568. return
  569. }
  570. //判断指标是否用于计算
  571. {
  572. calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
  573. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  574. errMsg = "删除失败"
  575. err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
  576. return
  577. }
  578. if calculateCount > 0 {
  579. deleteStatus = 4
  580. tipsMsg = "当前指标已用作指标运算,不可删除"
  581. return
  582. }
  583. }
  584. //如果是普通指标,那么还需要判断是否被预测指标作为源指标
  585. if edbInfo.EdbInfoType == 0 {
  586. predictEdbInfoCount, tmpErr := data_manage.GetPredictEdbConfCount(edbInfoId)
  587. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  588. errMsg = "删除失败"
  589. err = errors.New("判断指标是否被用于预测指标失败,Err:" + tmpErr.Error())
  590. return
  591. }
  592. if predictEdbInfoCount > 0 {
  593. deleteStatus = 5
  594. tipsMsg = "当前指标已用作预测指标,不可删除"
  595. return
  596. }
  597. }
  598. // 判断指标是否用作表格引用
  599. {
  600. tableItems, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
  601. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  602. errMsg = "删除失败"
  603. err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
  604. return
  605. }
  606. //英文翻译:
  607. //1、当前指标已用作画图,不可删除:The current metric is in use for charting and cannot be deleted
  608. //2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
  609. //3、删除失败:Deletion failed
  610. //4、知道了:Understood
  611. if len(tableItems) > 0 {
  612. deleteStatus = 6
  613. tipsMsg = "当前指标已被表格引用,不可删除"
  614. var excelIds []int
  615. for _, tableItem := range tableItems {
  616. if tableItem.ParentId > 0 {
  617. excelIds = append(excelIds, tableItem.ParentId)
  618. } else {
  619. excelIds = append(excelIds, tableItem.ExcelInfoId)
  620. }
  621. }
  622. tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
  623. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  624. errMsg = "删除失败"
  625. err = errors.New("判断指标是否用作表格引用,GetExcelBaseInfoByExcelInfoIdList Err:" + tmpErr.Error())
  626. return
  627. }
  628. return
  629. }
  630. }
  631. // 判断指标是否用作跨品种图表使用
  632. {
  633. // todo 如果绑定的标签未画图,则允许删除绑定
  634. // 查询跨品种的图表
  635. tagXList, tmpErr := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
  636. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  637. errMsg = "删除失败"
  638. err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByXEdbInfoId Err:" + tmpErr.Error())
  639. return
  640. }
  641. if len(tagXList) > 0 {
  642. deleteStatus = 7
  643. tipsMsg = "当前指标已添加到跨品种分析,不可删除"
  644. return
  645. }
  646. tagYList, tmpErr := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
  647. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  648. errMsg = "删除失败"
  649. err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByYEdbInfoId Err:" + tmpErr.Error())
  650. return
  651. }
  652. if len(tagYList) > 0 {
  653. deleteStatus = 7
  654. tipsMsg = "当前指标已添加到跨品种分析,不可删除"
  655. return
  656. }
  657. /*calculateCount, tmpErr := cross_variety.GetCountByEdbInfoId(edbInfoId)
  658. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  659. errMsg = "删除失败"
  660. err = errors.New("判断指标是否用作跨品种图表使用,GetCountByEdbInfoId Err:" + tmpErr.Error())
  661. return
  662. }
  663. if calculateCount > 0 {
  664. deleteStatus = 3
  665. tipsMsg = "当前指标已添加到跨品种分析,不可删除"
  666. return
  667. }*/
  668. }
  669. // 判断指标是否用于因子指标系列
  670. {
  671. ob := new(data_manage.FactorEdbSeriesMapping)
  672. cond := fmt.Sprintf(" AND %s = ?", ob.Cols().EdbInfoId)
  673. pars := make([]interface{}, 0)
  674. pars = append(pars, edbInfoId)
  675. count, e := ob.GetCountByCondition(cond, pars)
  676. if e != nil {
  677. errMsg = "删除失败"
  678. err = fmt.Errorf("获取指标是否用于系列失败, err: %v", e)
  679. return
  680. }
  681. if count > 0 {
  682. deleteStatus = 3
  683. tipsMsg = "当前指标已用于因子指标系列, 不可删除"
  684. return
  685. }
  686. }
  687. }
  688. return
  689. }
  690. // Delete 删除分类/指标
  691. func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, requestUrl string) (nextItem *data_manage.EdbInfo, tableList []*data_manage.ExcelBaseInfo, err error, errMsg string) {
  692. //删除分类
  693. if classifyId > 0 && edbInfoId == 0 {
  694. // 查找分类
  695. item, tmpErr := data_manage.GetEdbClassifyById(classifyId)
  696. if tmpErr != nil {
  697. errMsg = `查找分类失败`
  698. err = tmpErr
  699. return
  700. }
  701. // 已授权分类id
  702. permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
  703. if tmpErr != nil {
  704. errMsg = "删除失败"
  705. err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
  706. return
  707. }
  708. // 权限校验
  709. {
  710. // 数据权限
  711. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ClassifyId, permissionClassifyIdList)
  712. if item.ClassifyType == 0 { // 普通指标
  713. button := GetEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
  714. if !button.DeleteButton {
  715. errMsg = "无操作权限"
  716. err = errors.New(errMsg)
  717. return
  718. }
  719. } else if item.ClassifyType == 1 { // 预测指标
  720. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
  721. if !button.DeleteButton {
  722. errMsg = "无操作权限"
  723. err = errors.New(errMsg)
  724. return
  725. }
  726. }
  727. }
  728. //判断是否含有指标
  729. count, tmpErr := data_manage.GetEdbInfoCountByClassifyId(classifyId)
  730. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  731. errMsg = "删除失败"
  732. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  733. return
  734. }
  735. if count > 0 {
  736. errMsg = "该目录下存在关联指标,不可删除"
  737. return
  738. }
  739. tmpErr = data_manage.DeleteEdbClassify(classifyId)
  740. if tmpErr != nil {
  741. errMsg = "删除失败"
  742. err = errors.New("删除失败,Err:" + tmpErr.Error())
  743. return
  744. }
  745. }
  746. //删除指标
  747. if edbInfoId > 0 {
  748. edbInfo, tmpErr := data_manage.GetEdbInfoById(edbInfoId)
  749. if tmpErr != nil {
  750. if tmpErr.Error() == utils.ErrNoRow() {
  751. errMsg = "指标已删除,请刷新页面"
  752. err = errors.New("指标不存在,Err:" + tmpErr.Error())
  753. return
  754. } else {
  755. errMsg = "删除失败"
  756. err = errors.New("删除失败,获取指标信息失败,Err:" + tmpErr.Error())
  757. return
  758. }
  759. }
  760. if edbInfo == nil {
  761. errMsg = "指标已删除,请刷新页面"
  762. return
  763. }
  764. //判断指标是否用于作图,如果用于作图,则不可删除
  765. chartCount, tmpErr := data_manage.GetChartEdbMappingCount(edbInfoId)
  766. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  767. errMsg = "删除失败"
  768. err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
  769. return
  770. }
  771. if chartCount > 0 {
  772. errMsg = "当前指标已用作画图,不可删除"
  773. return
  774. }
  775. // 查询是否用于相关性图表
  776. correlationChart := new(data_manage.ChartInfoCorrelation)
  777. correlationChartCount, tmpErr := correlationChart.GetChartEdbMappingCount(edbInfoId)
  778. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  779. errMsg = "删除失败"
  780. err = errors.New("判断指标是否被用于相关性图表失败,Err:" + tmpErr.Error())
  781. return
  782. }
  783. if correlationChartCount > 0 {
  784. errMsg = "当前指标已用作画图,不可删除"
  785. return
  786. }
  787. //如果是普通指标,那么还需要判断是否被预测指标作为源指标
  788. if edbInfo.EdbInfoType == 0 {
  789. predictEdbInfoCount, tmpErr := data_manage.GetPredictEdbConfCount(edbInfoId)
  790. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  791. errMsg = "删除失败"
  792. err = errors.New("判断指标是否被用于预测指标失败,Err:" + tmpErr.Error())
  793. return
  794. }
  795. if predictEdbInfoCount > 0 {
  796. errMsg = "当前指标已用作预测指标,不可删除"
  797. return
  798. }
  799. }
  800. //判断指标是否用作其他指标的计算
  801. {
  802. calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
  803. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  804. errMsg = "删除失败"
  805. err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
  806. return
  807. }
  808. if calculateCount > 0 {
  809. errMsg = "当前指标已用作,指标运算,不可删除"
  810. return
  811. }
  812. }
  813. // 判断指标是否用作表格引用
  814. {
  815. tableItems, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
  816. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  817. errMsg = "删除失败"
  818. err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
  819. return
  820. }
  821. //英文翻译:
  822. //1、当前指标已用作画图,不可删除:The current metric is in use for charting and cannot be deleted
  823. //2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
  824. //3、删除失败:Deletion failed
  825. //4、知道了:Understood
  826. if len(tableItems) > 0 {
  827. errMsg = "当前指标已被表格引用,不可删除"
  828. return
  829. }
  830. }
  831. // 判断指标是否用作跨品种图表使用
  832. {
  833. // todo 如果绑定的标签未画图,则允许删除绑定
  834. // 查询跨品种的图表
  835. tagXList, tmpErr := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
  836. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  837. errMsg = "删除失败"
  838. err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByXEdbInfoId Err:" + tmpErr.Error())
  839. return
  840. }
  841. if len(tagXList) > 0 {
  842. errMsg = "当前指标已添加到跨品种分析,不可删除"
  843. return
  844. }
  845. tagYList, tmpErr := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
  846. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  847. errMsg = "删除失败"
  848. err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByYEdbInfoId Err:" + tmpErr.Error())
  849. return
  850. }
  851. if len(tagYList) > 0 {
  852. errMsg = "当前指标已添加到跨品种分析,不可删除"
  853. return
  854. }
  855. /*calculateCount, tmpErr := cross_variety.GetCountByEdbInfoId(edbInfoId)
  856. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  857. errMsg = "删除失败"
  858. err = errors.New("判断指标是否用作跨品种图表使用,GetCountByEdbInfoId Err:" + tmpErr.Error())
  859. return
  860. }
  861. if calculateCount > 0 {
  862. errMsg = "当前指标已添加到跨品种分析,不可删除"
  863. return
  864. }*/
  865. }
  866. //真实删除
  867. tmpErr = data_manage.DeleteEdbInfoAndData(edbInfo.EdbInfoId, edbInfo.Source, edbInfo.SubSource)
  868. if tmpErr != nil {
  869. errMsg = "删除失败"
  870. err = errors.New("删除失败,Err:" + tmpErr.Error())
  871. return
  872. }
  873. // 如果是同花顺高频数据或类似数据, 还需要删除base_from_edb_mapping对应关系
  874. baseMappingOb := new(data_manage.BaseFromEdbMapping)
  875. {
  876. cond := fmt.Sprintf(" %s = ? AND %s = ? AND %s = ?", baseMappingOb.Cols().EdbCode, baseMappingOb.Cols().Source, baseMappingOb.Cols().SubSource)
  877. pars := make([]interface{}, 0)
  878. pars = append(pars, edbInfo.EdbCode, edbInfo.Source, edbInfo.SubSource)
  879. if e := baseMappingOb.RemoveByCondition(cond, pars); e != nil {
  880. errMsg = "删除失败"
  881. err = fmt.Errorf("删除源指标映射失败, %v", e)
  882. return
  883. }
  884. }
  885. go data_stat.AddEdbDeleteLog(edbInfo, sysUser)
  886. // 删除指标后的操作
  887. go handleByDelEdbInfo(edbInfo)
  888. // 返回下一个表格的信息
  889. {
  890. var condition string
  891. var pars []interface{}
  892. condition += " AND edb_info_type=? AND classify_id=? "
  893. pars = append(pars, edbInfo.EdbInfoType, edbInfo.ClassifyId)
  894. condition += " AND (sort>? OR (sort=? AND edb_info_id<?) ) "
  895. pars = append(pars, edbInfo.Sort, edbInfo.Sort, edbInfo.EdbInfoId)
  896. nextItem, tmpErr = data_manage.GetNextEdbInfoByCondition(condition, pars)
  897. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  898. errMsg = "删除失败"
  899. err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
  900. return
  901. }
  902. // 如果没找到,那么查找下一个分类的第一个表格
  903. if nextItem == nil {
  904. currClassifyInfo, tmpErr := data_manage.GetEdbClassifyById(edbInfo.ClassifyId)
  905. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  906. errMsg = "删除失败"
  907. err = errors.New("获取当前预测指标分类信息失败,Err:" + tmpErr.Error())
  908. return
  909. }
  910. nextItem, err = data_manage.GetNextEdbInfo(edbInfo.ClassifyId, currClassifyInfo.Sort, int(currClassifyInfo.ClassifyType), edbInfo.EdbInfoType)
  911. if err != nil && err.Error() != utils.ErrNoRow() {
  912. errMsg = "删除失败"
  913. err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
  914. return
  915. }
  916. }
  917. }
  918. //新增操作日志
  919. {
  920. edbLog := new(data_manage.EdbInfoLog)
  921. edbLog.EdbInfoId = edbInfo.EdbInfoId
  922. edbLog.SourceName = edbInfo.SourceName
  923. edbLog.Source = edbInfo.Source
  924. edbLog.EdbCode = edbInfo.EdbCode
  925. edbLog.EdbName = edbInfo.EdbName
  926. edbLog.ClassifyId = edbInfo.ClassifyId
  927. edbLog.SysUserId = sysUser.AdminId
  928. edbLog.SysUserRealName = sysUser.RealName
  929. edbLog.CreateTime = time.Now()
  930. edbLog.Content = requestBody
  931. edbLog.Status = "删除指标"
  932. edbLog.Method = requestUrl
  933. go data_manage.AddEdbInfoLog(edbLog)
  934. }
  935. // 删除es中的数据
  936. DeleteEdbInfoToEs(edbInfoId)
  937. }
  938. return
  939. }
  940. // MoveEdbClassify 移动指标分类
  941. func MoveEdbClassify(req data_manage.MoveEdbClassifyReq, sysUser *system.Admin, classifyType uint8) (err error, errMsg string) {
  942. // req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId
  943. classifyId := req.ClassifyId
  944. parentClassifyId := req.ParentClassifyId
  945. prevClassifyId := req.PrevClassifyId
  946. nextClassifyId := req.NextClassifyId
  947. edbInfoId := req.EdbInfoId
  948. prevEdbInfoId := req.PrevEdbInfoId
  949. nextEdbInfoId := req.NextEdbInfoId
  950. //首先确定移动的对象是分类还是指标
  951. //判断上一个节点是分类还是指标
  952. //判断下一个节点是分类还是指标
  953. //同时更新分类目录下的分类sort和指标sort
  954. //更新当前移动的分类或者指标sort
  955. var parentEdbClassifyInfo *data_manage.EdbClassify
  956. if parentClassifyId > 0 {
  957. parentEdbClassifyInfo, err = data_manage.GetEdbClassifyById(parentClassifyId)
  958. if err != nil {
  959. errMsg = "移动失败"
  960. err = errors.New("获取上级分类信息失败,Err:" + err.Error())
  961. return
  962. }
  963. }
  964. //如果有传入 上一个兄弟节点分类id
  965. var (
  966. edbClassifyInfo *data_manage.EdbClassify
  967. prevClassify *data_manage.EdbClassify
  968. nextClassify *data_manage.EdbClassify
  969. edbInfo *data_manage.EdbInfo
  970. prevEdbInfo *data_manage.EdbInfo
  971. nextEdbInfo *data_manage.EdbInfo
  972. prevSort int
  973. nextSort int
  974. )
  975. // 移动对象为分类, 判断权限
  976. if edbInfoId == 0 {
  977. edbClassifyInfo, err = data_manage.GetEdbClassifyById(classifyId)
  978. if err != nil {
  979. if err.Error() == utils.ErrNoRow() {
  980. errMsg = "当前分类不存在"
  981. err = errors.New("获取分类信息失败,Err:" + err.Error())
  982. return
  983. }
  984. errMsg = "移动失败"
  985. err = errors.New("获取分类信息失败,Err:" + err.Error())
  986. return
  987. }
  988. if parentClassifyId > 0 && parentEdbClassifyInfo.Level == 6 {
  989. errMsg = "最高只支持添加6级分类"
  990. err = errors.New(errMsg)
  991. return
  992. }
  993. // 如果是移动目录, 那么校验一下父级目录下是否有重名目录
  994. exists, e := data_manage.GetEdbClassifyByParentIdAndName(parentClassifyId, edbClassifyInfo.ClassifyName, classifyId)
  995. if e != nil && e.Error() != utils.ErrNoRow() {
  996. errMsg = "移动失败"
  997. err = fmt.Errorf("获取父级分类下的同名分类失败, Err: %s", e.Error())
  998. return
  999. }
  1000. if exists != nil {
  1001. errMsg = "移动失败,分类名称已存在"
  1002. return
  1003. }
  1004. // 权限校验
  1005. {
  1006. // 已授权分类id
  1007. permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
  1008. if tmpErr != nil {
  1009. errMsg = "移动失败"
  1010. err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
  1011. return
  1012. }
  1013. // 数据权限
  1014. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(edbClassifyInfo.IsJoinPermission, edbClassifyInfo.ClassifyId, permissionClassifyIdList)
  1015. if edbClassifyInfo.ClassifyType == 0 { // 普通指标
  1016. button := GetEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId, haveOperaAuth)
  1017. if !button.MoveButton {
  1018. errMsg = "无操作权限"
  1019. err = errors.New(errMsg)
  1020. return
  1021. }
  1022. } else if edbClassifyInfo.ClassifyType == 1 { // 预测指标
  1023. button := GetPredictEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId, haveOperaAuth)
  1024. if !button.MoveButton {
  1025. errMsg = "无操作权限"
  1026. err = errors.New(errMsg)
  1027. return
  1028. }
  1029. }
  1030. }
  1031. } else {
  1032. edbInfo, err = data_manage.GetEdbInfoById(req.EdbInfoId)
  1033. if err != nil {
  1034. if err.Error() == utils.ErrNoRow() {
  1035. errMsg = "当前指标不存在"
  1036. err = errors.New("获取分类信息失败,Err:" + err.Error())
  1037. return
  1038. }
  1039. errMsg = "移动失败"
  1040. err = errors.New("获取分类信息失败,Err:" + err.Error())
  1041. return
  1042. }
  1043. if parentClassifyId == 0 {
  1044. errMsg = "移动失败,指标必须挂在分类下"
  1045. err = errors.New(errMsg)
  1046. return
  1047. }
  1048. var haveOperaAuth bool
  1049. // 权限校验
  1050. {
  1051. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, sysUser.AdminId)
  1052. if err != nil {
  1053. errMsg = "移动失败"
  1054. err = errors.New("获取指标权限信息失败,Err:" + err.Error())
  1055. return
  1056. }
  1057. }
  1058. // 移动权限校验
  1059. button := GetEdbOpButton(sysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  1060. if !button.MoveButton {
  1061. errMsg = "无操作权限"
  1062. err = errors.New(errMsg)
  1063. return
  1064. }
  1065. }
  1066. if prevClassifyId > 0 {
  1067. prevClassify, err = data_manage.GetEdbClassifyById(prevClassifyId)
  1068. if err != nil {
  1069. errMsg = "移动失败"
  1070. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  1071. return
  1072. }
  1073. prevSort = prevClassify.Sort
  1074. } else if prevEdbInfoId > 0 {
  1075. prevEdbInfo, err = data_manage.GetEdbInfoById(prevEdbInfoId)
  1076. if err != nil {
  1077. errMsg = "移动失败"
  1078. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  1079. return
  1080. }
  1081. prevSort = prevEdbInfo.Sort
  1082. }
  1083. if nextClassifyId > 0 {
  1084. //下一个兄弟节点
  1085. nextClassify, err = data_manage.GetEdbClassifyById(nextClassifyId)
  1086. if err != nil {
  1087. errMsg = "移动失败"
  1088. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  1089. return
  1090. }
  1091. nextSort = nextClassify.Sort
  1092. } else if nextEdbInfoId > 0 {
  1093. //下一个兄弟节点
  1094. nextEdbInfo, err = data_manage.GetEdbInfoById(nextEdbInfoId)
  1095. if err != nil {
  1096. errMsg = "移动失败"
  1097. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  1098. return
  1099. }
  1100. nextSort = nextEdbInfo.Sort
  1101. }
  1102. err, errMsg = moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify, edbInfo, prevEdbInfo, nextEdbInfo, parentClassifyId, prevSort, nextSort, classifyType)
  1103. return
  1104. }
  1105. // moveEdbClassify 移动指标分类
  1106. 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) {
  1107. updateCol := make([]string, 0)
  1108. // 移动对象为分类, 判断分类是否存在
  1109. if edbClassifyInfo != nil {
  1110. oldParentId := edbClassifyInfo.ParentId
  1111. oldLevel := edbClassifyInfo.Level
  1112. var classifyIds []int
  1113. if oldParentId != parentClassifyId {
  1114. //更新子分类对应的level
  1115. childList, e, m := GetChildClassifyByClassifyId(edbClassifyInfo.ClassifyId)
  1116. if e != nil {
  1117. errMsg = "移动失败"
  1118. err = errors.New("查询子分类失败,Err:" + e.Error() + m)
  1119. return
  1120. }
  1121. if len(childList) > 0 {
  1122. for _, v := range childList {
  1123. if v.ClassifyId == edbClassifyInfo.ClassifyId {
  1124. continue
  1125. }
  1126. classifyIds = append(classifyIds, v.ClassifyId)
  1127. }
  1128. }
  1129. }
  1130. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  1131. if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
  1132. if edbClassifyInfo.Level != parentEdbClassifyInfo.Level+1 { //禁止层级调整
  1133. errMsg = "移动失败"
  1134. err = errors.New("不支持目录层级变更")
  1135. return
  1136. }
  1137. edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  1138. edbClassifyInfo.RootId = parentEdbClassifyInfo.RootId
  1139. edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  1140. edbClassifyInfo.ModifyTime = time.Now()
  1141. updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
  1142. } else if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
  1143. errMsg = "移动失败"
  1144. err = errors.New("不支持目录层级变更")
  1145. return
  1146. }
  1147. if prevSort > 0 {
  1148. //如果是移动在两个兄弟节点之间
  1149. if nextSort > 0 {
  1150. //下一个兄弟节点
  1151. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1152. if prevSort == nextSort || prevSort == edbClassifyInfo.Sort {
  1153. //变更兄弟节点的排序
  1154. updateSortStr := `sort + 2`
  1155. //变更分类
  1156. if prevClassify != nil {
  1157. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr, classifyType)
  1158. } else {
  1159. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  1160. }
  1161. //变更指标
  1162. if prevEdbInfo != nil {
  1163. //变更兄弟节点的排序
  1164. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  1165. } else {
  1166. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  1167. }
  1168. } else {
  1169. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1170. if nextSort-prevSort == 1 {
  1171. //变更兄弟节点的排序
  1172. updateSortStr := `sort + 1`
  1173. //变更分类
  1174. if prevClassify != nil {
  1175. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
  1176. } else {
  1177. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  1178. }
  1179. //变更指标
  1180. if prevEdbInfo != nil {
  1181. //变更兄弟节点的排序
  1182. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  1183. } else {
  1184. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  1185. }
  1186. }
  1187. }
  1188. }
  1189. edbClassifyInfo.Sort = prevSort + 1
  1190. edbClassifyInfo.ModifyTime = time.Now()
  1191. updateCol = append(updateCol, "Sort", "ModifyTime")
  1192. } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
  1193. //处理只拖动到目录里,默认放到目录底部的情况
  1194. var maxSort int
  1195. maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
  1196. if err != nil {
  1197. errMsg = "移动失败"
  1198. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  1199. return
  1200. }
  1201. edbClassifyInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  1202. edbClassifyInfo.ModifyTime = time.Now()
  1203. updateCol = append(updateCol, "Sort", "ModifyTime")
  1204. } else {
  1205. // 拖动到父级分类的第一位
  1206. firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)
  1207. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1208. errMsg = "移动失败"
  1209. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  1210. return
  1211. }
  1212. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1213. if firstClassify != nil && firstClassify.Sort == 0 {
  1214. updateSortStr := ` sort + 1 `
  1215. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, firstClassify.ClassifyId-1, 0, updateSortStr, classifyType)
  1216. //该分类下的所有指标也需要+1
  1217. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
  1218. } else {
  1219. //如果该分类下存在指标,且第一个指标的排序等于0,那么需要调整排序
  1220. firstEdb, tErr := data_manage.GetFirstEdbInfoByClassifyId(parentClassifyId)
  1221. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  1222. errMsg = "移动失败"
  1223. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  1224. return
  1225. }
  1226. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1227. if firstEdb != nil && firstEdb.Sort == 0 {
  1228. updateSortStr := ` sort + 1 `
  1229. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, firstEdb.EdbInfoId-1, updateSortStr)
  1230. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr, classifyType)
  1231. }
  1232. }
  1233. edbClassifyInfo.Sort = 0 //那就是排在第一位
  1234. edbClassifyInfo.ModifyTime = time.Now()
  1235. updateCol = append(updateCol, "Sort", "ModifyTime")
  1236. }
  1237. //更新
  1238. if len(updateCol) > 0 {
  1239. err = edbClassifyInfo.Update(updateCol)
  1240. if err != nil {
  1241. errMsg = "移动失败"
  1242. err = errors.New("修改失败,Err:" + err.Error())
  1243. return
  1244. }
  1245. //更新对应分类的root_id和层级
  1246. if oldParentId != parentClassifyId {
  1247. if len(classifyIds) > 0 {
  1248. levelStep := edbClassifyInfo.Level - oldLevel
  1249. err = data_manage.UpdateEdbClassifyChildByParentClassifyId(classifyIds, edbClassifyInfo.RootId, levelStep)
  1250. if err != nil {
  1251. errMsg = "移动失败"
  1252. err = errors.New("更新子分类失败,Err:" + err.Error())
  1253. return
  1254. }
  1255. }
  1256. }
  1257. }
  1258. } else {
  1259. if edbInfo == nil {
  1260. errMsg = "当前指标不存在"
  1261. err = errors.New(errMsg)
  1262. return
  1263. }
  1264. //如果改变了分类,那么移动该指标数据
  1265. if edbInfo.ClassifyId != parentClassifyId {
  1266. edbInfo.ClassifyId = parentClassifyId
  1267. edbInfo.ModifyTime = time.Now()
  1268. updateCol = append(updateCol, "ClassifyId", "ModifyTime")
  1269. }
  1270. if prevSort > 0 {
  1271. //如果是移动在两个兄弟节点之间
  1272. if nextSort > 0 {
  1273. //下一个兄弟节点
  1274. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1275. if prevSort == nextSort || prevSort == edbInfo.Sort {
  1276. //变更兄弟节点的排序
  1277. updateSortStr := `sort + 2`
  1278. //变更分类
  1279. if prevClassify != nil {
  1280. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr, classifyType)
  1281. } else {
  1282. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  1283. }
  1284. //变更指标
  1285. if prevEdbInfo != nil {
  1286. //变更兄弟节点的排序
  1287. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  1288. } else {
  1289. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  1290. }
  1291. } else {
  1292. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1293. if nextSort-prevSort == 1 {
  1294. //变更兄弟节点的排序
  1295. updateSortStr := `sort + 1`
  1296. //变更分类
  1297. if prevClassify != nil {
  1298. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
  1299. } else {
  1300. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  1301. }
  1302. //变更指标
  1303. if prevEdbInfo != nil {
  1304. //变更兄弟节点的排序
  1305. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  1306. } else {
  1307. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  1308. }
  1309. }
  1310. }
  1311. }
  1312. edbInfo.Sort = prevSort + 1
  1313. edbInfo.ModifyTime = time.Now()
  1314. updateCol = append(updateCol, "Sort", "ModifyTime")
  1315. } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
  1316. //处理只拖动到目录里,默认放到目录底部的情况
  1317. var maxSort int
  1318. maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
  1319. if err != nil {
  1320. errMsg = "移动失败"
  1321. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  1322. return
  1323. }
  1324. edbInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  1325. edbInfo.ModifyTime = time.Now()
  1326. updateCol = append(updateCol, "Sort", "ModifyTime")
  1327. } else {
  1328. // 拖动到父级分类的第一位
  1329. firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)
  1330. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1331. errMsg = "移动失败"
  1332. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  1333. return
  1334. }
  1335. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1336. if firstClassify != nil && firstClassify.Sort == 0 {
  1337. updateSortStr := ` sort + 1 `
  1338. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, firstClassify.ClassifyId-1, 0, updateSortStr, classifyType)
  1339. //该分类下的所有指标也需要+1
  1340. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
  1341. } else {
  1342. //如果该分类下存在指标,且第一个指标的排序等于0,那么需要调整排序
  1343. firstEdb, tErr := data_manage.GetFirstEdbInfoByClassifyId(parentClassifyId)
  1344. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  1345. errMsg = "移动失败"
  1346. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  1347. return
  1348. }
  1349. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1350. if firstEdb != nil && firstEdb.Sort == 0 {
  1351. updateSortStr := ` sort + 1 `
  1352. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, firstEdb.EdbInfoId-1, updateSortStr)
  1353. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr, classifyType)
  1354. }
  1355. }
  1356. edbInfo.Sort = 0 //那就是排在第一位
  1357. edbInfo.ModifyTime = time.Now()
  1358. updateCol = append(updateCol, "Sort", "ModifyTime")
  1359. }
  1360. //更新
  1361. if len(updateCol) > 0 {
  1362. err = edbInfo.Update(updateCol)
  1363. if err != nil {
  1364. errMsg = "移动失败"
  1365. err = errors.New("修改失败,Err:" + err.Error())
  1366. return
  1367. }
  1368. }
  1369. }
  1370. return
  1371. }
  1372. // GetEdbOpButton 获取ETA指标的操作权限
  1373. func GetEdbOpButton(sysUser *system.Admin, belongUserId, edbType, edbInfoType int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
  1374. // 没有数据权限就直接返回
  1375. if !haveOperaAuth {
  1376. return
  1377. }
  1378. //2、用户对于自己添加的分类,有权限编辑、移动和删除该分类;
  1379. //3、ficc管理员和超管对所有分类有编辑、移动和删除权限;
  1380. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.EdbPermission == 1 {
  1381. button.AddButton = true
  1382. button.OpButton = true
  1383. button.DeleteButton = true
  1384. button.MoveButton = true
  1385. }
  1386. // ETA指标的基础指标才允许插入值
  1387. if edbInfoType == 0 && edbType == 1 {
  1388. button.InsertNewDataButton = true
  1389. }
  1390. button.ShowEdbRelation = true
  1391. button.ShowChartRelation = true
  1392. return
  1393. }
  1394. // GetEdbClassifyOpButton 获取ETA指标分类的操作权限
  1395. func GetEdbClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
  1396. // 没有数据权限就直接返回
  1397. if !haveOperaAuth {
  1398. return
  1399. }
  1400. //ficc管理员和超管和ficc研究员有权限创建和管理分类,可以编辑分类名称(分类名称不允许重复),可以拖动分类,改变分类顺序,可以拖动分类下模型,改变顺序,可以删除分类,若分类下有预测指标,则不允许删除;
  1401. //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) {
  1402. button.AddButton = true
  1403. button.OpButton = true
  1404. button.DeleteButton = true
  1405. button.MoveButton = true
  1406. //}
  1407. return
  1408. }
  1409. // GetPredictEdbOpButton 获取ETA预测指标的操作权限
  1410. func GetPredictEdbOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
  1411. // 没有数据权限就直接返回
  1412. if !haveOperaAuth {
  1413. return
  1414. }
  1415. //预测指标的添加人对该预测指标有全部操作权限,ficc管理员、超管对所有预测指标有全部操作权限;
  1416. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.PredictEdbPermission == 1 {
  1417. button.AddButton = true
  1418. button.OpButton = true
  1419. button.DeleteButton = true
  1420. button.MoveButton = true
  1421. }
  1422. button.ShowEdbRelation = true
  1423. button.ShowChartRelation = true
  1424. return
  1425. }
  1426. // GetPredictEdbClassifyOpButton 获取ETA预测指标分类的操作权限
  1427. func GetPredictEdbClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
  1428. // 没有数据权限就直接返回
  1429. if !haveOperaAuth {
  1430. return
  1431. }
  1432. //ficc管理员和超管和ficc研究员有权限创建和管理分类,可以编辑分类名称(分类名称不允许重复),可以拖动分类,改变分类顺序,可以拖动分类下模型,改变顺序,可以删除分类,若分类下有预测指标,则不允许删除;
  1433. //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) {
  1434. button.AddButton = true
  1435. button.OpButton = true
  1436. button.DeleteButton = true
  1437. button.MoveButton = true
  1438. //}
  1439. return
  1440. }
  1441. func GetEdbClassifyMaxSort(parentId int, classifyType uint8) (maxSort int, err error) {
  1442. //获取该层级下最大的排序数
  1443. classifyMaxSort, err := data_manage.GetEdbClassifyMaxSort(parentId, classifyType)
  1444. if err != nil {
  1445. return
  1446. }
  1447. maxSort = classifyMaxSort
  1448. edbMaxSort, err := data_manage.GetEdbInfoMaxSortByClassifyId(parentId)
  1449. if err != nil {
  1450. return
  1451. }
  1452. if maxSort < edbMaxSort {
  1453. maxSort = edbMaxSort
  1454. }
  1455. return
  1456. }