edb_classify.go 57 KB

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