edb_classify.go 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  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. {
  709. ob := new(excel.ExcelInfo)
  710. cond := ` AND extra_config LIKE ?`
  711. keyword := fmt.Sprintf(`"BaseEdbInfoId":%d`, edbInfoId)
  712. keyword = fmt.Sprint("%", keyword, "%")
  713. pars := make([]interface{}, 0)
  714. pars = append(pars, keyword)
  715. count, e := ob.GetCountByCondition(cond, pars)
  716. if e != nil {
  717. errMsg = "删除失败"
  718. err = fmt.Errorf("获取指标是否用于持仓分析-相关性表格失败, err: %v", e)
  719. return
  720. }
  721. if count > 0 {
  722. deleteStatus = 3
  723. tipsMsg = "当前指标已用于持仓分析相关性表格, 不可删除"
  724. return
  725. }
  726. }
  727. }
  728. return
  729. }
  730. // Delete 删除分类/指标
  731. func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, requestUrl string) (nextItem *data_manage.EdbInfo, tableList []*data_manage.ExcelBaseInfo, err error, errMsg string) {
  732. //删除分类
  733. if classifyId > 0 && edbInfoId == 0 {
  734. // 查找分类
  735. item, tmpErr := data_manage.GetEdbClassifyById(classifyId)
  736. if tmpErr != nil {
  737. errMsg = `查找分类失败`
  738. err = tmpErr
  739. return
  740. }
  741. // 已授权分类id
  742. permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
  743. if tmpErr != nil {
  744. errMsg = "删除失败"
  745. err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
  746. return
  747. }
  748. // 权限校验
  749. {
  750. // 数据权限
  751. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ClassifyId, permissionClassifyIdList)
  752. if item.ClassifyType == 0 { // 普通指标
  753. button := GetEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
  754. if !button.DeleteButton {
  755. errMsg = "无操作权限"
  756. err = errors.New(errMsg)
  757. return
  758. }
  759. } else if item.ClassifyType == 1 { // 预测指标
  760. button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
  761. if !button.DeleteButton {
  762. errMsg = "无操作权限"
  763. err = errors.New(errMsg)
  764. return
  765. }
  766. }
  767. }
  768. //判断是否含有指标
  769. count, tmpErr := data_manage.GetEdbInfoCountByClassifyId(classifyId)
  770. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  771. errMsg = "删除失败"
  772. err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
  773. return
  774. }
  775. if count > 0 {
  776. errMsg = "该目录下存在关联指标,不可删除"
  777. return
  778. }
  779. tmpErr = data_manage.DeleteEdbClassify(classifyId)
  780. if tmpErr != nil {
  781. errMsg = "删除失败"
  782. err = errors.New("删除失败,Err:" + tmpErr.Error())
  783. return
  784. }
  785. }
  786. //删除指标
  787. if edbInfoId > 0 {
  788. edbInfo, tmpErr := data_manage.GetEdbInfoById(edbInfoId)
  789. if tmpErr != nil {
  790. if tmpErr.Error() == utils.ErrNoRow() {
  791. errMsg = "指标已删除,请刷新页面"
  792. err = errors.New("指标不存在,Err:" + tmpErr.Error())
  793. return
  794. } else {
  795. errMsg = "删除失败"
  796. err = errors.New("删除失败,获取指标信息失败,Err:" + tmpErr.Error())
  797. return
  798. }
  799. }
  800. if edbInfo == nil {
  801. errMsg = "指标已删除,请刷新页面"
  802. return
  803. }
  804. //判断指标是否用于作图,如果用于作图,则不可删除
  805. chartCount, tmpErr := data_manage.GetChartEdbMappingCount(edbInfoId)
  806. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  807. errMsg = "删除失败"
  808. err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
  809. return
  810. }
  811. if chartCount > 0 {
  812. errMsg = "当前指标已用作画图,不可删除"
  813. return
  814. }
  815. // 查询是否用于相关性图表
  816. correlationChart := new(data_manage.ChartInfoCorrelation)
  817. correlationChartCount, tmpErr := correlationChart.GetChartEdbMappingCount(edbInfoId)
  818. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  819. errMsg = "删除失败"
  820. err = errors.New("判断指标是否被用于相关性图表失败,Err:" + tmpErr.Error())
  821. return
  822. }
  823. if correlationChartCount > 0 {
  824. errMsg = "当前指标已用作画图,不可删除"
  825. return
  826. }
  827. //如果是普通指标,那么还需要判断是否被预测指标作为源指标
  828. if edbInfo.EdbInfoType == 0 {
  829. predictEdbInfoCount, tmpErr := data_manage.GetPredictEdbConfCount(edbInfoId)
  830. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  831. errMsg = "删除失败"
  832. err = errors.New("判断指标是否被用于预测指标失败,Err:" + tmpErr.Error())
  833. return
  834. }
  835. if predictEdbInfoCount > 0 {
  836. errMsg = "当前指标已用作预测指标,不可删除"
  837. return
  838. }
  839. }
  840. //判断指标是否用作其他指标的计算
  841. {
  842. calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
  843. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  844. errMsg = "删除失败"
  845. err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
  846. return
  847. }
  848. if calculateCount > 0 {
  849. errMsg = "当前指标已用作,指标运算,不可删除"
  850. return
  851. }
  852. }
  853. // 判断指标是否用作表格引用
  854. {
  855. tableItems, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
  856. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  857. errMsg = "删除失败"
  858. err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
  859. return
  860. }
  861. //英文翻译:
  862. //1、当前指标已用作画图,不可删除:The current metric is in use for charting and cannot be deleted
  863. //2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
  864. //3、删除失败:Deletion failed
  865. //4、知道了:Understood
  866. if len(tableItems) > 0 {
  867. errMsg = "当前指标已被表格引用,不可删除"
  868. return
  869. }
  870. }
  871. // 判断指标是否用作跨品种图表使用
  872. {
  873. // todo 如果绑定的标签未画图,则允许删除绑定
  874. // 查询跨品种的图表
  875. tagXList, tmpErr := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
  876. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  877. errMsg = "删除失败"
  878. err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByXEdbInfoId Err:" + tmpErr.Error())
  879. return
  880. }
  881. if len(tagXList) > 0 {
  882. errMsg = "当前指标已添加到跨品种分析,不可删除"
  883. return
  884. }
  885. tagYList, tmpErr := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
  886. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  887. errMsg = "删除失败"
  888. err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByYEdbInfoId Err:" + tmpErr.Error())
  889. return
  890. }
  891. if len(tagYList) > 0 {
  892. errMsg = "当前指标已添加到跨品种分析,不可删除"
  893. return
  894. }
  895. /*calculateCount, tmpErr := cross_variety.GetCountByEdbInfoId(edbInfoId)
  896. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  897. errMsg = "删除失败"
  898. err = errors.New("判断指标是否用作跨品种图表使用,GetCountByEdbInfoId Err:" + tmpErr.Error())
  899. return
  900. }
  901. if calculateCount > 0 {
  902. errMsg = "当前指标已添加到跨品种分析,不可删除"
  903. return
  904. }*/
  905. }
  906. //真实删除
  907. tmpErr = data_manage.DeleteEdbInfoAndData(edbInfo.EdbInfoId, edbInfo.Source, edbInfo.SubSource)
  908. if tmpErr != nil {
  909. errMsg = "删除失败"
  910. err = errors.New("删除失败,Err:" + tmpErr.Error())
  911. return
  912. }
  913. // 如果是同花顺高频数据或类似数据, 还需要删除base_from_edb_mapping对应关系
  914. baseMappingOb := new(data_manage.BaseFromEdbMapping)
  915. {
  916. cond := fmt.Sprintf(" %s = ? AND %s = ? AND %s = ?", baseMappingOb.Cols().EdbCode, baseMappingOb.Cols().Source, baseMappingOb.Cols().SubSource)
  917. pars := make([]interface{}, 0)
  918. pars = append(pars, edbInfo.EdbCode, edbInfo.Source, edbInfo.SubSource)
  919. if e := baseMappingOb.RemoveByCondition(cond, pars); e != nil {
  920. errMsg = "删除失败"
  921. err = fmt.Errorf("删除源指标映射失败, %v", e)
  922. return
  923. }
  924. }
  925. go data_stat.AddEdbDeleteLog(edbInfo, sysUser)
  926. // 删除指标后的操作
  927. go handleByDelEdbInfo(edbInfo)
  928. // 返回下一个表格的信息
  929. {
  930. var condition string
  931. var pars []interface{}
  932. condition += " AND edb_info_type=? AND classify_id=? "
  933. pars = append(pars, edbInfo.EdbInfoType, edbInfo.ClassifyId)
  934. condition += " AND (sort>? OR (sort=? AND edb_info_id<?) ) "
  935. pars = append(pars, edbInfo.Sort, edbInfo.Sort, edbInfo.EdbInfoId)
  936. nextItem, tmpErr = data_manage.GetNextEdbInfoByCondition(condition, pars)
  937. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  938. errMsg = "删除失败"
  939. err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
  940. return
  941. }
  942. // 如果没找到,那么查找下一个分类的第一个表格
  943. if nextItem == nil {
  944. currClassifyInfo, tmpErr := data_manage.GetEdbClassifyById(edbInfo.ClassifyId)
  945. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  946. errMsg = "删除失败"
  947. err = errors.New("获取当前预测指标分类信息失败,Err:" + tmpErr.Error())
  948. return
  949. }
  950. nextItem, err = data_manage.GetNextEdbInfo(edbInfo.ClassifyId, currClassifyInfo.Sort, int(currClassifyInfo.ClassifyType), edbInfo.EdbInfoType)
  951. if err != nil && err.Error() != utils.ErrNoRow() {
  952. errMsg = "删除失败"
  953. err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
  954. return
  955. }
  956. }
  957. }
  958. //新增操作日志
  959. {
  960. edbLog := new(data_manage.EdbInfoLog)
  961. edbLog.EdbInfoId = edbInfo.EdbInfoId
  962. edbLog.SourceName = edbInfo.SourceName
  963. edbLog.Source = edbInfo.Source
  964. edbLog.EdbCode = edbInfo.EdbCode
  965. edbLog.EdbName = edbInfo.EdbName
  966. edbLog.ClassifyId = edbInfo.ClassifyId
  967. edbLog.SysUserId = sysUser.AdminId
  968. edbLog.SysUserRealName = sysUser.RealName
  969. edbLog.CreateTime = time.Now()
  970. edbLog.Content = requestBody
  971. edbLog.Status = "删除指标"
  972. edbLog.Method = requestUrl
  973. go data_manage.AddEdbInfoLog(edbLog)
  974. }
  975. // 删除es中的数据
  976. DeleteEdbInfoToEs(edbInfoId)
  977. }
  978. return
  979. }
  980. // MoveEdbClassify 移动指标分类
  981. func MoveEdbClassify(req data_manage.MoveEdbClassifyReq, sysUser *system.Admin, classifyType uint8) (err error, errMsg string) {
  982. // req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId
  983. classifyId := req.ClassifyId
  984. parentClassifyId := req.ParentClassifyId
  985. prevClassifyId := req.PrevClassifyId
  986. nextClassifyId := req.NextClassifyId
  987. edbInfoId := req.EdbInfoId
  988. prevEdbInfoId := req.PrevEdbInfoId
  989. nextEdbInfoId := req.NextEdbInfoId
  990. //首先确定移动的对象是分类还是指标
  991. //判断上一个节点是分类还是指标
  992. //判断下一个节点是分类还是指标
  993. //同时更新分类目录下的分类sort和指标sort
  994. //更新当前移动的分类或者指标sort
  995. var parentEdbClassifyInfo *data_manage.EdbClassify
  996. if parentClassifyId > 0 {
  997. parentEdbClassifyInfo, err = data_manage.GetEdbClassifyById(parentClassifyId)
  998. if err != nil {
  999. errMsg = "移动失败"
  1000. err = errors.New("获取上级分类信息失败,Err:" + err.Error())
  1001. return
  1002. }
  1003. }
  1004. //如果有传入 上一个兄弟节点分类id
  1005. var (
  1006. edbClassifyInfo *data_manage.EdbClassify
  1007. prevClassify *data_manage.EdbClassify
  1008. nextClassify *data_manage.EdbClassify
  1009. edbInfo *data_manage.EdbInfo
  1010. prevEdbInfo *data_manage.EdbInfo
  1011. nextEdbInfo *data_manage.EdbInfo
  1012. prevSort int
  1013. nextSort int
  1014. )
  1015. // 移动对象为分类, 判断权限
  1016. if edbInfoId == 0 {
  1017. edbClassifyInfo, err = data_manage.GetEdbClassifyById(classifyId)
  1018. if err != nil {
  1019. if err.Error() == utils.ErrNoRow() {
  1020. errMsg = "当前分类不存在"
  1021. err = errors.New("获取分类信息失败,Err:" + err.Error())
  1022. return
  1023. }
  1024. errMsg = "移动失败"
  1025. err = errors.New("获取分类信息失败,Err:" + err.Error())
  1026. return
  1027. }
  1028. if parentClassifyId > 0 && parentEdbClassifyInfo.Level == 6 {
  1029. errMsg = "最高只支持添加6级分类"
  1030. err = errors.New(errMsg)
  1031. return
  1032. }
  1033. // 如果是移动目录, 那么校验一下父级目录下是否有重名目录
  1034. exists, e := data_manage.GetEdbClassifyByParentIdAndName(parentClassifyId, edbClassifyInfo.ClassifyName, classifyId)
  1035. if e != nil && e.Error() != utils.ErrNoRow() {
  1036. errMsg = "移动失败"
  1037. err = fmt.Errorf("获取父级分类下的同名分类失败, Err: %s", e.Error())
  1038. return
  1039. }
  1040. if exists != nil {
  1041. errMsg = "移动失败,分类名称已存在"
  1042. return
  1043. }
  1044. // 权限校验
  1045. {
  1046. // 已授权分类id
  1047. permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
  1048. if tmpErr != nil {
  1049. errMsg = "移动失败"
  1050. err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
  1051. return
  1052. }
  1053. // 数据权限
  1054. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(edbClassifyInfo.IsJoinPermission, edbClassifyInfo.ClassifyId, permissionClassifyIdList)
  1055. if edbClassifyInfo.ClassifyType == 0 { // 普通指标
  1056. button := GetEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId, haveOperaAuth)
  1057. if !button.MoveButton {
  1058. errMsg = "无操作权限"
  1059. err = errors.New(errMsg)
  1060. return
  1061. }
  1062. } else if edbClassifyInfo.ClassifyType == 1 { // 预测指标
  1063. button := GetPredictEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId, haveOperaAuth)
  1064. if !button.MoveButton {
  1065. errMsg = "无操作权限"
  1066. err = errors.New(errMsg)
  1067. return
  1068. }
  1069. }
  1070. }
  1071. } else {
  1072. edbInfo, err = data_manage.GetEdbInfoById(req.EdbInfoId)
  1073. if err != nil {
  1074. if err.Error() == utils.ErrNoRow() {
  1075. errMsg = "当前指标不存在"
  1076. err = errors.New("获取分类信息失败,Err:" + err.Error())
  1077. return
  1078. }
  1079. errMsg = "移动失败"
  1080. err = errors.New("获取分类信息失败,Err:" + err.Error())
  1081. return
  1082. }
  1083. if parentClassifyId == 0 {
  1084. errMsg = "移动失败,指标必须挂在分类下"
  1085. err = errors.New(errMsg)
  1086. return
  1087. }
  1088. var haveOperaAuth bool
  1089. // 权限校验
  1090. {
  1091. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, sysUser.AdminId)
  1092. if err != nil {
  1093. errMsg = "移动失败"
  1094. err = errors.New("获取指标权限信息失败,Err:" + err.Error())
  1095. return
  1096. }
  1097. }
  1098. // 移动权限校验
  1099. button := GetEdbOpButton(sysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  1100. if !button.MoveButton {
  1101. errMsg = "无操作权限"
  1102. err = errors.New(errMsg)
  1103. return
  1104. }
  1105. }
  1106. if prevClassifyId > 0 {
  1107. prevClassify, err = data_manage.GetEdbClassifyById(prevClassifyId)
  1108. if err != nil {
  1109. errMsg = "移动失败"
  1110. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  1111. return
  1112. }
  1113. prevSort = prevClassify.Sort
  1114. } else if prevEdbInfoId > 0 {
  1115. prevEdbInfo, err = data_manage.GetEdbInfoById(prevEdbInfoId)
  1116. if err != nil {
  1117. errMsg = "移动失败"
  1118. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  1119. return
  1120. }
  1121. prevSort = prevEdbInfo.Sort
  1122. }
  1123. if nextClassifyId > 0 {
  1124. //下一个兄弟节点
  1125. nextClassify, err = data_manage.GetEdbClassifyById(nextClassifyId)
  1126. if err != nil {
  1127. errMsg = "移动失败"
  1128. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  1129. return
  1130. }
  1131. nextSort = nextClassify.Sort
  1132. } else if nextEdbInfoId > 0 {
  1133. //下一个兄弟节点
  1134. nextEdbInfo, err = data_manage.GetEdbInfoById(nextEdbInfoId)
  1135. if err != nil {
  1136. errMsg = "移动失败"
  1137. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  1138. return
  1139. }
  1140. nextSort = nextEdbInfo.Sort
  1141. }
  1142. err, errMsg = moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify, edbInfo, prevEdbInfo, nextEdbInfo, parentClassifyId, prevSort, nextSort, classifyType)
  1143. return
  1144. }
  1145. // moveEdbClassify 移动指标分类
  1146. 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) {
  1147. updateCol := make([]string, 0)
  1148. // 移动对象为分类, 判断分类是否存在
  1149. if edbClassifyInfo != nil {
  1150. oldParentId := edbClassifyInfo.ParentId
  1151. oldLevel := edbClassifyInfo.Level
  1152. var classifyIds []int
  1153. if oldParentId != parentClassifyId {
  1154. //更新子分类对应的level
  1155. childList, e, m := GetChildClassifyByClassifyId(edbClassifyInfo.ClassifyId)
  1156. if e != nil {
  1157. errMsg = "移动失败"
  1158. err = errors.New("查询子分类失败,Err:" + e.Error() + m)
  1159. return
  1160. }
  1161. if len(childList) > 0 {
  1162. for _, v := range childList {
  1163. if v.ClassifyId == edbClassifyInfo.ClassifyId {
  1164. continue
  1165. }
  1166. classifyIds = append(classifyIds, v.ClassifyId)
  1167. }
  1168. }
  1169. }
  1170. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  1171. if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
  1172. if edbClassifyInfo.Level != parentEdbClassifyInfo.Level+1 { //禁止层级调整
  1173. errMsg = "移动失败"
  1174. err = errors.New("不支持目录层级变更")
  1175. return
  1176. }
  1177. edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  1178. edbClassifyInfo.RootId = parentEdbClassifyInfo.RootId
  1179. edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  1180. edbClassifyInfo.ModifyTime = time.Now()
  1181. updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
  1182. } else if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
  1183. errMsg = "移动失败"
  1184. err = errors.New("不支持目录层级变更")
  1185. return
  1186. }
  1187. if prevSort > 0 {
  1188. //如果是移动在两个兄弟节点之间
  1189. if nextSort > 0 {
  1190. //下一个兄弟节点
  1191. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1192. if prevSort == nextSort || prevSort == edbClassifyInfo.Sort {
  1193. //变更兄弟节点的排序
  1194. updateSortStr := `sort + 2`
  1195. //变更分类
  1196. if prevClassify != nil {
  1197. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr, classifyType)
  1198. } else {
  1199. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  1200. }
  1201. //变更指标
  1202. if prevEdbInfo != nil {
  1203. //变更兄弟节点的排序
  1204. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  1205. } else {
  1206. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  1207. }
  1208. } else {
  1209. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1210. if nextSort-prevSort == 1 {
  1211. //变更兄弟节点的排序
  1212. updateSortStr := `sort + 1`
  1213. //变更分类
  1214. if prevClassify != nil {
  1215. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
  1216. } else {
  1217. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  1218. }
  1219. //变更指标
  1220. if prevEdbInfo != nil {
  1221. //变更兄弟节点的排序
  1222. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  1223. } else {
  1224. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  1225. }
  1226. }
  1227. }
  1228. }
  1229. edbClassifyInfo.Sort = prevSort + 1
  1230. edbClassifyInfo.ModifyTime = time.Now()
  1231. updateCol = append(updateCol, "Sort", "ModifyTime")
  1232. } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
  1233. //处理只拖动到目录里,默认放到目录底部的情况
  1234. var maxSort int
  1235. maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
  1236. if err != nil {
  1237. errMsg = "移动失败"
  1238. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  1239. return
  1240. }
  1241. edbClassifyInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  1242. edbClassifyInfo.ModifyTime = time.Now()
  1243. updateCol = append(updateCol, "Sort", "ModifyTime")
  1244. } else {
  1245. // 拖动到父级分类的第一位
  1246. firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)
  1247. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1248. errMsg = "移动失败"
  1249. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  1250. return
  1251. }
  1252. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1253. if firstClassify != nil && firstClassify.Sort == 0 {
  1254. updateSortStr := ` sort + 1 `
  1255. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, firstClassify.ClassifyId-1, 0, updateSortStr, classifyType)
  1256. //该分类下的所有指标也需要+1
  1257. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
  1258. } else {
  1259. //如果该分类下存在指标,且第一个指标的排序等于0,那么需要调整排序
  1260. firstEdb, tErr := data_manage.GetFirstEdbInfoByClassifyId(parentClassifyId)
  1261. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  1262. errMsg = "移动失败"
  1263. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  1264. return
  1265. }
  1266. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1267. if firstEdb != nil && firstEdb.Sort == 0 {
  1268. updateSortStr := ` sort + 1 `
  1269. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, firstEdb.EdbInfoId-1, updateSortStr)
  1270. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr, classifyType)
  1271. }
  1272. }
  1273. edbClassifyInfo.Sort = 0 //那就是排在第一位
  1274. edbClassifyInfo.ModifyTime = time.Now()
  1275. updateCol = append(updateCol, "Sort", "ModifyTime")
  1276. }
  1277. //更新
  1278. if len(updateCol) > 0 {
  1279. err = edbClassifyInfo.Update(updateCol)
  1280. if err != nil {
  1281. errMsg = "移动失败"
  1282. err = errors.New("修改失败,Err:" + err.Error())
  1283. return
  1284. }
  1285. //更新对应分类的root_id和层级
  1286. if oldParentId != parentClassifyId {
  1287. if len(classifyIds) > 0 {
  1288. levelStep := edbClassifyInfo.Level - oldLevel
  1289. err = data_manage.UpdateEdbClassifyChildByParentClassifyId(classifyIds, edbClassifyInfo.RootId, levelStep)
  1290. if err != nil {
  1291. errMsg = "移动失败"
  1292. err = errors.New("更新子分类失败,Err:" + err.Error())
  1293. return
  1294. }
  1295. }
  1296. }
  1297. }
  1298. } else {
  1299. if edbInfo == nil {
  1300. errMsg = "当前指标不存在"
  1301. err = errors.New(errMsg)
  1302. return
  1303. }
  1304. //如果改变了分类,那么移动该指标数据
  1305. if edbInfo.ClassifyId != parentClassifyId {
  1306. edbInfo.ClassifyId = parentClassifyId
  1307. edbInfo.ModifyTime = time.Now()
  1308. updateCol = append(updateCol, "ClassifyId", "ModifyTime")
  1309. }
  1310. if prevSort > 0 {
  1311. //如果是移动在两个兄弟节点之间
  1312. if nextSort > 0 {
  1313. //下一个兄弟节点
  1314. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1315. if prevSort == nextSort || prevSort == edbInfo.Sort {
  1316. //变更兄弟节点的排序
  1317. updateSortStr := `sort + 2`
  1318. //变更分类
  1319. if prevClassify != nil {
  1320. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr, classifyType)
  1321. } else {
  1322. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  1323. }
  1324. //变更指标
  1325. if prevEdbInfo != nil {
  1326. //变更兄弟节点的排序
  1327. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  1328. } else {
  1329. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  1330. }
  1331. } else {
  1332. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1333. if nextSort-prevSort == 1 {
  1334. //变更兄弟节点的排序
  1335. updateSortStr := `sort + 1`
  1336. //变更分类
  1337. if prevClassify != nil {
  1338. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
  1339. } else {
  1340. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
  1341. }
  1342. //变更指标
  1343. if prevEdbInfo != nil {
  1344. //变更兄弟节点的排序
  1345. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
  1346. } else {
  1347. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
  1348. }
  1349. }
  1350. }
  1351. }
  1352. edbInfo.Sort = prevSort + 1
  1353. edbInfo.ModifyTime = time.Now()
  1354. updateCol = append(updateCol, "Sort", "ModifyTime")
  1355. } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
  1356. //处理只拖动到目录里,默认放到目录底部的情况
  1357. var maxSort int
  1358. maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
  1359. if err != nil {
  1360. errMsg = "移动失败"
  1361. err = errors.New("查询组内排序信息失败,Err:" + err.Error())
  1362. return
  1363. }
  1364. edbInfo.Sort = maxSort + 1 //那就是排在组内最后一位
  1365. edbInfo.ModifyTime = time.Now()
  1366. updateCol = append(updateCol, "Sort", "ModifyTime")
  1367. } else {
  1368. // 拖动到父级分类的第一位
  1369. firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)
  1370. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1371. errMsg = "移动失败"
  1372. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  1373. return
  1374. }
  1375. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1376. if firstClassify != nil && firstClassify.Sort == 0 {
  1377. updateSortStr := ` sort + 1 `
  1378. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, firstClassify.ClassifyId-1, 0, updateSortStr, classifyType)
  1379. //该分类下的所有指标也需要+1
  1380. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
  1381. } else {
  1382. //如果该分类下存在指标,且第一个指标的排序等于0,那么需要调整排序
  1383. firstEdb, tErr := data_manage.GetFirstEdbInfoByClassifyId(parentClassifyId)
  1384. if tErr != nil && tErr.Error() != utils.ErrNoRow() {
  1385. errMsg = "移动失败"
  1386. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
  1387. return
  1388. }
  1389. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1390. if firstEdb != nil && firstEdb.Sort == 0 {
  1391. updateSortStr := ` sort + 1 `
  1392. _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, firstEdb.EdbInfoId-1, updateSortStr)
  1393. _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr, classifyType)
  1394. }
  1395. }
  1396. edbInfo.Sort = 0 //那就是排在第一位
  1397. edbInfo.ModifyTime = time.Now()
  1398. updateCol = append(updateCol, "Sort", "ModifyTime")
  1399. }
  1400. //更新
  1401. if len(updateCol) > 0 {
  1402. err = edbInfo.Update(updateCol)
  1403. if err != nil {
  1404. errMsg = "移动失败"
  1405. err = errors.New("修改失败,Err:" + err.Error())
  1406. return
  1407. }
  1408. }
  1409. }
  1410. return
  1411. }
  1412. // GetEdbOpButton 获取ETA指标的操作权限
  1413. func GetEdbOpButton(sysUser *system.Admin, belongUserId, edbType, edbInfoType int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
  1414. // 没有数据权限就直接返回
  1415. if !haveOperaAuth {
  1416. return
  1417. }
  1418. //2、用户对于自己添加的分类,有权限编辑、移动和删除该分类;
  1419. //3、ficc管理员和超管对所有分类有编辑、移动和删除权限;
  1420. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.EdbPermission == 1 {
  1421. button.AddButton = true
  1422. button.OpButton = true
  1423. button.DeleteButton = true
  1424. button.MoveButton = true
  1425. }
  1426. // ETA指标的基础指标才允许插入值
  1427. if edbInfoType == 0 && edbType == 1 {
  1428. button.InsertNewDataButton = true
  1429. }
  1430. button.ShowEdbRelation = true
  1431. button.ShowChartRelation = true
  1432. return
  1433. }
  1434. // GetEdbClassifyOpButton 获取ETA指标分类的操作权限
  1435. func GetEdbClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
  1436. // 没有数据权限就直接返回
  1437. if !haveOperaAuth {
  1438. return
  1439. }
  1440. //ficc管理员和超管和ficc研究员有权限创建和管理分类,可以编辑分类名称(分类名称不允许重复),可以拖动分类,改变分类顺序,可以拖动分类下模型,改变顺序,可以删除分类,若分类下有预测指标,则不允许删除;
  1441. //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) {
  1442. button.AddButton = true
  1443. button.OpButton = true
  1444. button.DeleteButton = true
  1445. button.MoveButton = true
  1446. //}
  1447. return
  1448. }
  1449. // GetPredictEdbOpButton 获取ETA预测指标的操作权限
  1450. func GetPredictEdbOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
  1451. // 没有数据权限就直接返回
  1452. if !haveOperaAuth {
  1453. return
  1454. }
  1455. //预测指标的添加人对该预测指标有全部操作权限,ficc管理员、超管对所有预测指标有全部操作权限;
  1456. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.PredictEdbPermission == 1 {
  1457. button.AddButton = true
  1458. button.OpButton = true
  1459. button.DeleteButton = true
  1460. button.MoveButton = true
  1461. }
  1462. button.ShowEdbRelation = true
  1463. button.ShowChartRelation = true
  1464. return
  1465. }
  1466. // GetPredictEdbClassifyOpButton 获取ETA预测指标分类的操作权限
  1467. func GetPredictEdbClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
  1468. // 没有数据权限就直接返回
  1469. if !haveOperaAuth {
  1470. return
  1471. }
  1472. //ficc管理员和超管和ficc研究员有权限创建和管理分类,可以编辑分类名称(分类名称不允许重复),可以拖动分类,改变分类顺序,可以拖动分类下模型,改变顺序,可以删除分类,若分类下有预测指标,则不允许删除;
  1473. //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) {
  1474. button.AddButton = true
  1475. button.OpButton = true
  1476. button.DeleteButton = true
  1477. button.MoveButton = true
  1478. //}
  1479. return
  1480. }
  1481. func GetEdbClassifyMaxSort(parentId int, classifyType uint8) (maxSort int, err error) {
  1482. //获取该层级下最大的排序数
  1483. classifyMaxSort, err := data_manage.GetEdbClassifyMaxSort(parentId, classifyType)
  1484. if err != nil {
  1485. return
  1486. }
  1487. maxSort = classifyMaxSort
  1488. edbMaxSort, err := data_manage.GetEdbInfoMaxSortByClassifyId(parentId)
  1489. if err != nil {
  1490. return
  1491. }
  1492. if maxSort < edbMaxSort {
  1493. maxSort = edbMaxSort
  1494. }
  1495. return
  1496. }
  1497. func GetEdbClassifyByIsMe(adminId, parentId, edbInfoType int, classifyList []*data_manage.EdbClassifyItems) (list []*data_manage.EdbClassifyItems, err error) {
  1498. edbInfoList, err := data_manage.GetEdbInfoListByUserId([]int{adminId}, edbInfoType)
  1499. if err != nil {
  1500. return
  1501. }
  1502. classifyIdList := make([]int, 0)
  1503. for _, edbInfo := range edbInfoList {
  1504. if edbInfo.ClassifyId > 0 {
  1505. classifyIdList = append(classifyIdList, edbInfo.ClassifyId)
  1506. }
  1507. }
  1508. if parentId > 0 {
  1509. for _, v := range classifyList {
  1510. if v.ClassifyId > 0 && v.EdbInfoId == 0 {
  1511. classifyItems, er, _ := GetChildClassifyByClassifyId(v.ClassifyId)
  1512. if er != nil {
  1513. err = er
  1514. return
  1515. }
  1516. existClassifyMap := make(map[int]struct{})
  1517. for _, classify := range classifyItems {
  1518. existClassifyMap[classify.ClassifyId] = struct{}{}
  1519. }
  1520. for _, edb := range edbInfoList {
  1521. if _, ok := existClassifyMap[edb.ClassifyId]; ok {
  1522. list = append(list, v)
  1523. break
  1524. }
  1525. }
  1526. } else {
  1527. list = append(list, v)
  1528. }
  1529. }
  1530. } else {
  1531. edbInfoClassifyList, er := data_manage.GetEdbClassifyByIdList(classifyIdList)
  1532. if er != nil {
  1533. err = er
  1534. return
  1535. }
  1536. existClassifyIdMap := make(map[int]struct{})
  1537. for _, classify := range edbInfoClassifyList {
  1538. existClassifyIdMap[classify.RootId] = struct{}{}
  1539. }
  1540. for _, classify := range classifyList {
  1541. if _, ok := existClassifyIdMap[classify.ClassifyId]; ok {
  1542. list = append(list, classify)
  1543. }
  1544. }
  1545. }
  1546. return
  1547. }
  1548. // GetEdbClassifyChildrenRecursive 根据父目录递归子级目录
  1549. func GetEdbClassifyChildrenRecursive(list []*data_manage.EdbClassifyItems, parentId int) []*data_manage.EdbClassifyItems {
  1550. var res []*data_manage.EdbClassifyItems
  1551. for _, v := range list {
  1552. if v.ParentId == parentId {
  1553. // 递归调用以获取更深层次的子级
  1554. children := GetEdbClassifyChildrenRecursive(list, v.ClassifyId)
  1555. // 将当前节点和所有子节点添加到结果中
  1556. res = append(res, v)
  1557. res = append(res, children...)
  1558. } else if v.ClassifyId == parentId {
  1559. // 将当前节点添加到结果中
  1560. res = append(res, v)
  1561. }
  1562. }
  1563. return res
  1564. }
  1565. // GetEdbClassifyChildrenRecursiveByParentIds 根据父目录递归子级目录
  1566. func GetEdbClassifyChildrenRecursiveByParentIds(list []*data_manage.EdbClassifyItems, parentIds []string) []*data_manage.EdbClassifyItems{
  1567. var res []*data_manage.EdbClassifyItems
  1568. for _, v := range list {
  1569. for _, id := range parentIds {
  1570. parentId, _ := strconv.Atoi(id)
  1571. if v.ParentId == parentId || v.ClassifyId == parentId {
  1572. // 递归调用以获取更深层次的子级
  1573. children := GetEdbClassifyChildrenRecursive(list, v.ClassifyId)
  1574. // 将当前节点和所有子节点添加到结果中
  1575. res = append(res, v)
  1576. res = append(res, children...)
  1577. }
  1578. }
  1579. }
  1580. return res
  1581. }