base_from_sci.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. package data
  2. import (
  3. "errors"
  4. "eta/eta_api/models/data_manage"
  5. "eta/eta_api/models/system"
  6. "eta/eta_api/utils"
  7. "time"
  8. )
  9. // AddSciClassify 添加SCI分类
  10. func AddSciClassify(classifyName string, parentId, sysUserId int, sysUserName string) (classifyInfo *data_manage.BaseFromSciClassify, err error, errMsg string) {
  11. count, err := data_manage.GetBaseFromSciClassifyCount(classifyName, parentId)
  12. if err != nil {
  13. errMsg = `判断名称是否已存在失败`
  14. return
  15. }
  16. if count > 0 {
  17. errMsg = `分类名称已存在,请重新输入`
  18. return
  19. }
  20. level := 1
  21. if parentId > 0 {
  22. parentClassify, e := data_manage.GetBaseFromSciClassifyById(parentId)
  23. if e != nil {
  24. if e.Error() == utils.ErrNoRow() {
  25. err = e
  26. errMsg = `一级分类不存在`
  27. return
  28. }
  29. err = e
  30. errMsg = `查询一级分类失败`
  31. return
  32. }
  33. level = parentClassify.Level + 1
  34. }
  35. classifyInfo = &data_manage.BaseFromSciClassify{
  36. ClassifyName: classifyName,
  37. ParentId: parentId,
  38. SysUserId: sysUserId,
  39. SysUserRealName: sysUserName,
  40. Sort: 0,
  41. Level: level,
  42. ModifyTime: time.Now(),
  43. CreateTime: time.Now(),
  44. }
  45. classifyId, err := data_manage.AddBaseFromSciClassify(classifyInfo)
  46. if err != nil {
  47. errMsg = "保存分类失败"
  48. return
  49. }
  50. classifyInfo.ClassifyId = int(classifyId)
  51. //更新sort为classifyId
  52. err = data_manage.UpdateBaseFromSciClassifySort(int(classifyId))
  53. return
  54. }
  55. // EditSciClassify 编辑Sci分类
  56. func EditSciClassify(classifyId int, classifyName string, sysUser *system.Admin) (err error, errMsg string) {
  57. item, err := data_manage.GetBaseFromSciClassifyById(classifyId)
  58. if err != nil {
  59. errMsg = `保存失败`
  60. return
  61. }
  62. // 名字相同,那么就直接返回
  63. if item.ClassifyName == classifyName {
  64. return
  65. }
  66. // 判断名称是否已存在
  67. count, err := data_manage.GetBaseFromSciClassifyCount(classifyName, item.ParentId)
  68. if err != nil {
  69. errMsg = "判断名称是否已存在失败"
  70. return
  71. }
  72. if count > 0 {
  73. errMsg = "分类名称已存在,请重新输入"
  74. err = errors.New(errMsg)
  75. return
  76. }
  77. // 修改数据
  78. err = data_manage.EditBaseFromSciClassify(classifyId, classifyName)
  79. if err != nil {
  80. errMsg = "保存失败"
  81. }
  82. return
  83. }
  84. // MoveSciClassify 移动Sci分类
  85. func MoveSciClassify(classifyId, parentClassifyId, prevClassifyId, nextClassifyId int) (err error, errMsg string) {
  86. //判断分类是否存在
  87. classifyInfo, err := data_manage.GetBaseFromSciClassifyById(classifyId)
  88. if err != nil {
  89. errMsg = "移动失败"
  90. err = errors.New("获取分类信息失败,Err:" + err.Error())
  91. return
  92. }
  93. updateCol := make([]string, 0)
  94. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  95. if classifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
  96. parentClassifyInfo, tmpErr := data_manage.GetBaseFromSciClassifyById(parentClassifyId)
  97. if tmpErr != nil {
  98. errMsg = "移动失败"
  99. err = errors.New("获取上级分类信息失败,Err:" + tmpErr.Error())
  100. return
  101. }
  102. classifyInfo.ParentId = parentClassifyInfo.ClassifyId
  103. classifyInfo.Level = parentClassifyInfo.Level + 1
  104. updateCol = append(updateCol, "ParentId", "Level")
  105. }
  106. var currentSort, prevSort, nextSort int
  107. currentSort = classifyInfo.Sort
  108. var prevClassify *data_manage.BaseFromSciClassify
  109. var nextClassify *data_manage.BaseFromSciClassify
  110. //如果有传入 上一个兄弟节点分类id
  111. if prevClassifyId > 0 {
  112. prevClassify, err = data_manage.GetBaseFromSciClassifyById(prevClassifyId)
  113. if err != nil {
  114. if err.Error() == utils.ErrNoRow() {
  115. errMsg = "移动失败"
  116. err = errors.New("上一个兄弟节点分类信息不存在" + err.Error())
  117. return
  118. }
  119. errMsg = "移动失败"
  120. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
  121. return
  122. }
  123. prevSort = prevClassify.Sort
  124. }
  125. if nextClassifyId > 0 {
  126. //下一个兄弟节点
  127. nextClassify, err = data_manage.GetBaseFromSciClassifyById(nextClassifyId)
  128. if err != nil {
  129. if err.Error() == utils.ErrNoRow() {
  130. errMsg = "移动失败"
  131. err = errors.New("下一个兄弟节点分类信息不存在" + err.Error())
  132. return
  133. }
  134. errMsg = "移动失败"
  135. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
  136. return
  137. }
  138. nextSort = nextClassify.Sort
  139. }
  140. // 修改历史数据中的排序为0的情况
  141. if prevSort == 0 && nextSort == 0 { //目标是让当前分类处于目录的最顶部
  142. //更新为0排序的数据为当前最小排序
  143. if nextClassify != nil {
  144. minSort, e := data_manage.GetSciIndexClassifyMinSort(parentClassifyId)
  145. if e != nil {
  146. errMsg = "移动失败"
  147. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + e.Error())
  148. return
  149. }
  150. if minSort > 1 {
  151. minSort -= 1
  152. }
  153. nextClassify.Sort = minSort
  154. err = nextClassify.Update([]string{"Sort"})
  155. if err != nil {
  156. errMsg = "移动失败"
  157. err = errors.New("更新下一个兄弟节点分类信息失败,Err:" + err.Error())
  158. return
  159. }
  160. nextSort = minSort
  161. }
  162. }
  163. //移到两个排序值中间操作
  164. if prevSort >= currentSort {
  165. //往下移动
  166. err = data_manage.MoveDownSciIndexClassifyBySort(parentClassifyId, prevSort, currentSort)
  167. if err != nil {
  168. err = errors.New("向下移动出错:" + err.Error())
  169. return
  170. }
  171. classifyInfo.Sort = prevSort
  172. } else if nextSort <= currentSort && nextSort != 0 {
  173. //往上移动
  174. err = data_manage.MoveUpSciIndexClassifyBySort(parentClassifyId, nextSort, currentSort)
  175. if err != nil {
  176. err = errors.New("向上移动出错:" + err.Error())
  177. return
  178. }
  179. classifyInfo.Sort = nextSort
  180. }
  181. classifyInfo.ModifyTime = time.Now()
  182. updateCol = append(updateCol, "Sort", "ModifyTime")
  183. err = classifyInfo.Update(updateCol)
  184. if err != nil {
  185. errMsg = "移动失败"
  186. err = errors.New("修改失败,Err:" + err.Error())
  187. return
  188. }
  189. return
  190. }
  191. // DelSciClassify 删除SCI分类
  192. func DelSciClassify(classifyId int, sysUser *system.Admin) (err error, errMsg string) {
  193. //判断分类是否存在
  194. classifyInfo, err := data_manage.GetBaseFromSciClassifyById(classifyId)
  195. if err != nil {
  196. errMsg = "删除失败"
  197. err = errors.New("获取分类信息失败,Err:" + err.Error())
  198. return
  199. }
  200. // 需要删除的分类id集合
  201. classifyIdList := make([]int, 0)
  202. classifyIdList = append(classifyIdList, classifyId)
  203. // 查找所有的子集id
  204. if classifyInfo.ParentId <= 0 {
  205. childrenClassifyInfoList, tmpErr := data_manage.GetBaseFromSciClassifyByParentId(classifyId)
  206. if tmpErr != nil {
  207. errMsg = "删除失败"
  208. err = errors.New("获取分类信息失败,Err:" + tmpErr.Error())
  209. return
  210. }
  211. for _, v := range childrenClassifyInfoList {
  212. classifyIdList = append(classifyIdList, v.ClassifyId)
  213. }
  214. }
  215. // 获取分类下的所有指标
  216. count, err := data_manage.GetBaseFromSciIndexCountByClassifyIds(classifyIdList)
  217. if err != nil {
  218. errMsg = "删除失败"
  219. err = errors.New("获取分类下的指标信息失败,Err:" + err.Error())
  220. return
  221. }
  222. if count > 0 {
  223. errMsg = "该分类下有指标,不可删除"
  224. err = errors.New("该分类下有指标,不可删除")
  225. return
  226. }
  227. // 删除对应的分类
  228. err = data_manage.DeleteSciClassifyByClassifyId(classifyIdList)
  229. if err != nil {
  230. return
  231. }
  232. return
  233. }
  234. // MoveSciData 移动SCI指标
  235. func MoveSciData(indexId, classifyId, prevIndexId, nextIndexId int) (err error, errMsg string) {
  236. //分类信息
  237. sciIndex, err := data_manage.GetBaseFromSciIndexByIndexId(indexId)
  238. if err != nil {
  239. errMsg = `获取数据失败`
  240. if err.Error() == utils.ErrNoRow() {
  241. errMsg = `该指标未入库`
  242. err = nil
  243. }
  244. return
  245. }
  246. //判断分类是否存在
  247. if classifyId > 0 {
  248. _, err = data_manage.GetBaseFromSciClassifyById(classifyId)
  249. if err != nil {
  250. errMsg = "移动失败"
  251. err = errors.New("获取分类信息失败,Err:" + err.Error())
  252. if err.Error() == utils.ErrNoRow() {
  253. errMsg = "找不到该分类"
  254. err = nil
  255. }
  256. return
  257. }
  258. }
  259. //如果改变了分类,那么移动该图表数据
  260. if sciIndex.ClassifyId != classifyId {
  261. tmpErr := data_manage.MoveBaseFromSciIndex(indexId, classifyId)
  262. if tmpErr != nil {
  263. errMsg = "移动失败"
  264. err = errors.New("移动失败,Err:" + tmpErr.Error())
  265. return
  266. }
  267. }
  268. //移动排序
  269. updateCol := make([]string, 0)
  270. //如果有传入 上一个兄弟节点分类id
  271. if prevIndexId > 0 {
  272. prevIndex, tmpErr := data_manage.GetBaseFromSciIndexByIndexId(prevIndexId)
  273. if tmpErr != nil {
  274. errMsg = "移动失败"
  275. err = errors.New("获取上一个兄弟节点指标信息失败,Err:" + tmpErr.Error())
  276. return
  277. }
  278. //如果是移动在两个兄弟节点之间
  279. if nextIndexId > 0 {
  280. //下一个兄弟节点
  281. nextIndex, tmpErr := data_manage.GetBaseFromSciIndexByIndexId(nextIndexId)
  282. if tmpErr != nil {
  283. errMsg = "移动失败"
  284. err = errors.New("获取下一个兄弟节点指标信息失败,Err:" + tmpErr.Error())
  285. return
  286. }
  287. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  288. if prevIndex.Sort == nextIndex.Sort || prevIndex.Sort == sciIndex.Sort {
  289. //变更兄弟节点的排序
  290. updateSortStr := `sort + 2`
  291. err = data_manage.UpdateBaseFromSciIndexByClassifyId(prevIndex.ClassifyId, prevIndex.Sort, prevIndex.BaseFromSciIndexId, updateSortStr)
  292. if err != nil {
  293. errMsg = "移动失败"
  294. err = errors.New("变更兄弟节点排序指标信息失败,Err:" + err.Error())
  295. return
  296. }
  297. } else {
  298. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  299. if nextIndex.Sort-prevIndex.Sort == 1 {
  300. //变更兄弟节点的排序
  301. updateSortStr := `sort + 1`
  302. err = data_manage.UpdateBaseFromSciIndexByClassifyId(prevIndex.ClassifyId, prevIndex.Sort, prevIndex.BaseFromSciIndexId, updateSortStr)
  303. if err != nil {
  304. errMsg = "移动失败"
  305. err = errors.New("变更兄弟节点排序指标信息失败,Err:" + err.Error())
  306. return
  307. }
  308. }
  309. }
  310. }
  311. sciIndex.Sort = prevIndex.Sort + 1
  312. sciIndex.ModifyTime = time.Now()
  313. updateCol = append(updateCol, "Sort", "ModifyTime")
  314. } else {
  315. firstClassify, tmpErr := data_manage.GetFirstBaseFromSciIndexByClassifyId(classifyId)
  316. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  317. errMsg = "移动失败"
  318. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  319. return
  320. }
  321. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  322. if firstClassify != nil && firstClassify.Sort == 0 {
  323. updateSortStr := ` sort + 1 `
  324. _ = data_manage.UpdateBaseFromSciIndexByClassifyId(firstClassify.ClassifyId, 0, firstClassify.BaseFromSciIndexId-1, updateSortStr)
  325. }
  326. sciIndex.Sort = 0 //那就是排在第一位
  327. sciIndex.ModifyTime = time.Now()
  328. updateCol = append(updateCol, "Sort", "ModifyTime")
  329. }
  330. //更新
  331. if len(updateCol) > 0 {
  332. err = sciIndex.Update(updateCol)
  333. if err != nil {
  334. errMsg = "移动失败"
  335. err = errors.New("修改失败,Err:" + err.Error())
  336. return
  337. }
  338. }
  339. return
  340. }
  341. // MoveSciData2 移动SCI指标
  342. func MoveSciData2(indexId, classifyId, prevIndexId, nextIndexId int) (err error, errMsg string) {
  343. //分类信息
  344. sciIndex, err := data_manage.GetBaseFromSciIndexByIndexId(indexId)
  345. if err != nil {
  346. errMsg = `获取数据失败`
  347. if err.Error() == utils.ErrNoRow() {
  348. errMsg = `该指标未入库`
  349. err = nil
  350. }
  351. return
  352. }
  353. //判断分类是否存在
  354. if classifyId > 0 {
  355. _, err = data_manage.GetBaseFromSciClassifyById(classifyId)
  356. if err != nil {
  357. errMsg = "移动失败"
  358. err = errors.New("获取分类信息失败,Err:" + err.Error())
  359. if err.Error() == utils.ErrNoRow() {
  360. errMsg = "找不到该分类"
  361. err = nil
  362. }
  363. return
  364. }
  365. }
  366. //如果改变了分类,那么移动该图表数据
  367. if sciIndex.ClassifyId != classifyId {
  368. tmpErr := data_manage.MoveBaseFromSciIndex(indexId, classifyId)
  369. if tmpErr != nil {
  370. errMsg = "移动失败"
  371. err = errors.New("移动失败,Err:" + tmpErr.Error())
  372. return
  373. }
  374. }
  375. //移动排序
  376. updateCol := make([]string, 0)
  377. var currentSort, prevSort, nextSort int
  378. currentSort = sciIndex.Sort
  379. //如果有传入 上一个兄弟节点分类id
  380. var prevIndex *data_manage.BaseFromSciIndex
  381. var nextIndex *data_manage.BaseFromSciIndex
  382. if prevIndexId > 0 {
  383. prevIndex, err = data_manage.GetBaseFromSciIndexByIndexId(prevIndexId)
  384. if err != nil {
  385. if err.Error() == utils.ErrNoRow() {
  386. errMsg = "移动失败"
  387. err = errors.New("上一个兄弟节点指标信息不存在" + err.Error())
  388. return
  389. }
  390. errMsg = "移动失败"
  391. err = errors.New("获取上一个兄弟节点指标信息失败,Err:" + err.Error())
  392. return
  393. }
  394. prevSort = prevIndex.Sort
  395. }
  396. if nextIndexId > 0 {
  397. //下一个兄弟节点
  398. nextIndex, err = data_manage.GetBaseFromSciIndexByIndexId(nextIndexId)
  399. if err != nil {
  400. if err.Error() == utils.ErrNoRow() {
  401. errMsg = "移动失败"
  402. err = errors.New("下一个兄弟节点指标信息不存在" + err.Error())
  403. return
  404. }
  405. errMsg = "移动失败"
  406. err = errors.New("获取下一个兄弟节点指标信息失败,Err:" + err.Error())
  407. return
  408. }
  409. nextSort = nextIndex.Sort
  410. }
  411. // 修改历史数据中的排序为0的情况
  412. if prevSort == 0 && nextSort == 0 { //目标是让当前分类处于目录的最顶部, 但是历史数据里下个节点的sort为0的情况
  413. //更新为0排序的数据为当前最小排序
  414. if nextIndex != nil {
  415. minSort, e := data_manage.GetBaseFromSciIndexMinSortByClassifyId(classifyId)
  416. if e != nil {
  417. errMsg = "移动失败"
  418. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + e.Error())
  419. return
  420. }
  421. if minSort > 1 {
  422. minSort -= 1
  423. }
  424. nextIndex.Sort = minSort
  425. err = nextIndex.Update([]string{"Sort"})
  426. if err != nil {
  427. errMsg = "移动失败"
  428. err = errors.New("更新下一个兄弟节点分类信息失败,Err:" + err.Error())
  429. return
  430. }
  431. nextSort = minSort
  432. }
  433. }
  434. //移到两个排序值中间操作
  435. if prevSort >= currentSort {
  436. //往下移动
  437. err = data_manage.MoveDownSciIndexBySort(classifyId, prevSort, currentSort)
  438. if err != nil {
  439. err = errors.New("向下移动出错:" + err.Error())
  440. return
  441. }
  442. sciIndex.Sort = prevSort
  443. } else if nextSort <= currentSort && nextSort != 0 {
  444. //往上移动
  445. err = data_manage.MoveUpSciIndexBySort(classifyId, nextSort, currentSort)
  446. if err != nil {
  447. err = errors.New("向上移动出错:" + err.Error())
  448. return
  449. }
  450. sciIndex.Sort = nextSort
  451. }
  452. //更新
  453. sciIndex.ModifyTime = time.Now()
  454. updateCol = append(updateCol, "Sort", "ModifyTime")
  455. err = sciIndex.Update(updateCol)
  456. if err != nil {
  457. errMsg = "移动失败"
  458. err = errors.New("修改失败,Err:" + err.Error())
  459. return
  460. }
  461. return
  462. }
  463. // EditSciIndex 编辑SCI指标
  464. func EditSciIndex(indexId, classifyId int, sysUser *system.Admin) (baseFromSciIndex *data_manage.BaseFromSciIndex, err error, errMsg string) {
  465. baseFromSciIndex, err = data_manage.GetBaseFromSciIndexByIndexId(indexId)
  466. if err != nil {
  467. errMsg = `获取数据失败`
  468. if err.Error() == utils.ErrNoRow() {
  469. errMsg = `该指标未入库`
  470. err = nil
  471. }
  472. return
  473. }
  474. baseFromSciIndex.ClassifyId = classifyId
  475. baseFromSciIndex.ModifyTime = time.Now()
  476. err = baseFromSciIndex.Update([]string{"ClassifyId", "ModifyTime"})
  477. if err != nil {
  478. errMsg = "保存分类失败"
  479. }
  480. return
  481. }
  482. func InitBaseFromSciClassify() (err error) {
  483. //查询历史数据所有分类
  484. typeList, err := data_manage.GetBaseFromSciIndexType()
  485. if err != nil {
  486. return
  487. }
  488. classifyList := make([]*data_manage.BaseFromSciClassify, 0)
  489. classifyMap := make(map[string][]string, 0)
  490. parentClassifyMap := make(map[string]struct{}, 0)
  491. now := time.Now()
  492. for _, v := range typeList {
  493. if _, ok := parentClassifyMap[v.Type2]; !ok {
  494. parentClassifyMap[v.Type2] = struct{}{}
  495. tmp := new(data_manage.BaseFromSciClassify)
  496. tmp.ClassifyName = v.Type2
  497. tmp.Level = 1
  498. tmp.ModifyTime = now
  499. tmp.CreateTime = now
  500. classifyList = append(classifyList, tmp)
  501. }
  502. classifyMap[v.Type2] = append(classifyMap[v.Type2], v.Type3)
  503. }
  504. //添加一级分类
  505. err = data_manage.AddSciClassifyMulti(classifyList)
  506. if err != nil {
  507. err = errors.New("新增分类出错:" + err.Error())
  508. return
  509. }
  510. //查询分类表的所有父级
  511. rootList, err := data_manage.GetBaseFromSciClassifyByParentId(0)
  512. if err != nil {
  513. return
  514. }
  515. classifyIdMap := make(map[string]int)
  516. for _, v := range rootList {
  517. classifyIdMap[v.ClassifyName] = v.ClassifyId
  518. }
  519. classifyList2 := make([]*data_manage.BaseFromSciClassify, 0)
  520. for _, v := range typeList {
  521. if parentId, ok := classifyIdMap[v.Type2]; ok {
  522. tmp := new(data_manage.BaseFromSciClassify)
  523. tmp.ParentId = parentId
  524. tmp.ClassifyName = v.Type3
  525. tmp.Level = 2
  526. tmp.ModifyTime = now
  527. tmp.CreateTime = now
  528. classifyList2 = append(classifyList2, tmp)
  529. }
  530. }
  531. //添加二级分类
  532. err = data_manage.AddSciClassifyMulti(classifyList2)
  533. if err != nil {
  534. err = errors.New("新增二级分类出错:" + err.Error())
  535. return
  536. }
  537. //初始化sort字段
  538. err = data_manage.InitSciClassifySort()
  539. if err != nil {
  540. return
  541. }
  542. //更新index表里的分类id
  543. err = data_manage.InitSciIndexClassifyId()
  544. return
  545. }
  546. // DelSciData 删除SCI指标
  547. func DelSciData(indexId int) (err error, errMsg string) {
  548. baseFromSciIndex, err := data_manage.GetBaseFromSciIndexByIndexId(indexId)
  549. if err != nil {
  550. errMsg = `获取数据失败`
  551. if err.Error() == utils.ErrNoRow() {
  552. errMsg = `该指标未入库`
  553. err = nil
  554. }
  555. return
  556. }
  557. // 获取已经加入到EDB指标库的Sci指标
  558. edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_SCI, baseFromSciIndex.IndexCode)
  559. if err != nil && err.Error() != utils.ErrNoRow() {
  560. errMsg = "删除失败"
  561. err = errors.New("获取分类下的指标信息失败,Err:" + err.Error())
  562. return
  563. }
  564. if edbInfo != nil {
  565. errMsg = "当前指标已被引用,不可删除"
  566. err = nil
  567. return
  568. }
  569. // 删除对应的分类和指标
  570. err = data_manage.DeleteBaseFromSciIndexById(indexId)
  571. if err != nil {
  572. return
  573. }
  574. return
  575. }
  576. // ResetSciData 指标数据清除分类接口
  577. func ResetSciData(indexId int) (err error, errMsg string) {
  578. sciIndex, err := data_manage.GetBaseFromSciIndexByIndexId(indexId)
  579. if err != nil {
  580. errMsg = `获取数据失败`
  581. if err.Error() == utils.ErrNoRow() {
  582. errMsg = `该指标未入库`
  583. err = nil
  584. }
  585. return
  586. }
  587. // 更新指标在未分类下的排序,永远排在未分类的最后一个
  588. //移动排序
  589. classifyId := 0
  590. updateCol := make([]string, 0)
  591. var currentSort, prevSort int
  592. currentSort = sciIndex.Sort
  593. //未分类的最大的sort值
  594. prevSort, err = data_manage.GetBaseFromSciIndexMaxSortByClassifyId(classifyId)
  595. if err != nil {
  596. errMsg = "移动失败"
  597. err = errors.New("获取上一个兄弟节点指标信息失败,Err:" + err.Error())
  598. return
  599. }
  600. //如果前面一个节点的sort值比当前大,则当前节点往下移动
  601. if prevSort >= currentSort {
  602. //往下移动
  603. err = data_manage.MoveDownSciIndexBySort(classifyId, prevSort, currentSort)
  604. if err != nil {
  605. err = errors.New("向下移动出错:" + err.Error())
  606. return
  607. }
  608. sciIndex.Sort = prevSort
  609. }
  610. //更新
  611. sciIndex.ModifyTime = time.Now()
  612. sciIndex.ClassifyId = classifyId
  613. updateCol = append(updateCol, "Sort", "ModifyTime", "ClassifyId")
  614. err = sciIndex.Update(updateCol)
  615. if err != nil {
  616. errMsg = "移动失败"
  617. err = errors.New("修改失败,Err:" + err.Error())
  618. return
  619. }
  620. return
  621. }