edb_classify.go 57 KB

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