edb_permission.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. package data_manage_permission
  2. import (
  3. "eta/eta_api/models/data_manage"
  4. "eta/eta_api/models/data_manage/data_manage_permission"
  5. "eta/eta_api/models/data_manage/excel"
  6. "eta/eta_api/models/system"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "github.com/rdlucklib/rdluck_tools/uuid"
  10. "strings"
  11. )
  12. // SetEdbChartPermission
  13. // @Description: 单独给资产(指标、图表、ETA表格)设置权限
  14. // @author: Roc
  15. // @datetime 2024-03-27 10:52:32
  16. // @param source int
  17. // @param subSource int
  18. // @param userId int
  19. // @param authUserList []int
  20. // @param isSelectAll bool
  21. // @param dataId []string
  22. // @param noDataId []string
  23. // @param keyword string
  24. // @param classify string
  25. // @param opUserId int 操作人
  26. // @return err error
  27. // @return errMsg string
  28. func SetEdbChartPermission(source, subSource, userId int, authUserList []int, isSelectAll bool, dataIdList, noDataIdList []string, keyword, classify string, opUserId int) (err error, errMsg string) {
  29. // 如果勾选全部数据,那么
  30. if isSelectAll {
  31. // 找出不要的指标ID列表
  32. noDataIdMap := make(map[string]string, 0)
  33. for _, v := range noDataIdList {
  34. noDataIdMap[v] = v
  35. }
  36. // 需要转义的指标/图表ID列表
  37. dataIdList = make([]string, 0)
  38. // 获取所有指标/图表
  39. list, _, tmpErr := GetMoveEdbChartList(source, subSource, userId, keyword, classify, 0, 100000)
  40. if tmpErr != nil {
  41. err = tmpErr
  42. return
  43. }
  44. for _, v := range list {
  45. if _, ok := noDataIdMap[v.DataId]; !ok {
  46. dataIdList = append(dataIdList, v.DataId)
  47. }
  48. }
  49. }
  50. // dataIdList 做3000条限制
  51. if len(dataIdList) > 3000 {
  52. err = fmt.Errorf("数据量条数不要超过3000,请分批设置")
  53. errMsg = err.Error()
  54. return
  55. }
  56. if len(authUserList) <= 0 {
  57. // 说明是取消权限管控
  58. }
  59. uniqueCode := uuid.NewUUID().Hex32()
  60. title := `数据权限变更`
  61. content := `数据权限`
  62. dataList := make([]data_manage_permission.DataItem, 0)
  63. switch source {
  64. case 3, 4:
  65. //ETA指标库、ETA预测指标
  66. if source == 3 {
  67. content += `(ETA指标库)`
  68. } else {
  69. content += `(ETA预测指标)`
  70. }
  71. tmpList, tmpErr := data_manage.GetEdbInfoListByEdbInfoId(dataIdList)
  72. if tmpErr != nil {
  73. err = tmpErr
  74. return
  75. }
  76. dataIdList = make([]string, 0)
  77. if len(tmpList) > 0 {
  78. for _, v := range tmpList {
  79. dataList = append(dataList, data_manage_permission.DataItem{
  80. DataId: v.EdbInfoId,
  81. DataCode: v.EdbCode,
  82. DataName: v.EdbName,
  83. })
  84. dataIdList = append(dataIdList, fmt.Sprint(v.EdbInfoId))
  85. }
  86. // 重新设置权限
  87. edbInfoType := 0
  88. if source == 4 {
  89. edbInfoType = 1
  90. }
  91. err = data_manage_permission.SetPermissionByEdbIdList(dataIdList, authUserList, edbInfoType)
  92. }
  93. case 5:
  94. //图库
  95. content += `(ETA图库)`
  96. tmpList, tmpErr := data_manage.GetChartInfoListByChartIdList(dataIdList)
  97. if tmpErr != nil {
  98. err = tmpErr
  99. return
  100. }
  101. if len(tmpList) > 0 {
  102. dataIdList = make([]string, 0)
  103. for _, v := range tmpList {
  104. dataList = append(dataList, data_manage_permission.DataItem{
  105. DataId: v.ChartInfoId,
  106. DataCode: fmt.Sprint(v.ChartInfoId),
  107. DataName: v.ChartName,
  108. })
  109. dataIdList = append(dataIdList, fmt.Sprint(v.ChartInfoId))
  110. }
  111. // 重新设置权限
  112. chartSource := utils.CHART_SOURCE_DEFAULT
  113. err = data_manage_permission.SetPermissionByChartIdList(dataIdList, authUserList, chartSource)
  114. }
  115. case 6:
  116. // ETA表格
  117. content += `(ETA表格)`
  118. tmpList := make([]*excel.MyExcelInfoList, 0)
  119. var tmpErr error
  120. if subSource == utils.BALANCE_TABLE {
  121. tmpList, tmpErr = excel.GetNoContentExcelListByExcelInfoIdAndParentId(dataIdList)
  122. } else {
  123. tmpList, tmpErr = excel.GetNoContentExcelListByExcelInfoIdList(dataIdList)
  124. }
  125. if tmpErr != nil {
  126. err = tmpErr
  127. return
  128. }
  129. if len(tmpList) > 0 {
  130. dataIdList = make([]string, 0)
  131. for _, v := range tmpList {
  132. dataList = append(dataList, data_manage_permission.DataItem{
  133. DataId: v.ExcelInfoId,
  134. DataCode: fmt.Sprint(v.ExcelInfoId),
  135. DataName: v.ExcelName,
  136. })
  137. dataIdList = append(dataIdList, fmt.Sprint(v.ExcelInfoId))
  138. }
  139. // 重新设置权限
  140. err = data_manage_permission.SetPermissionByExcelIdList(dataIdList, authUserList, subSource)
  141. }
  142. default:
  143. return
  144. }
  145. if err != nil {
  146. return
  147. }
  148. var authRecordErr error
  149. defer func() {
  150. if authRecordErr != nil {
  151. utils.FileLog.Error(fmt.Sprintf("记录未设置记录资产权限的记录失败:%s;source:%d;sub_source:%d;数据ID列表:%s;授权人列表:%v", authRecordErr.Error(), source, subSource, strings.Join(dataIdList, ","), authUserList))
  152. }
  153. }()
  154. // 获取所有在用的用户
  155. cond := ` AND enabled = 1`
  156. pars := make([]interface{}, 0)
  157. adminList, authRecordErr := system.GetSysAdminList(cond, pars, []string{}, "")
  158. if authRecordErr != nil {
  159. return
  160. }
  161. // 如果没有授权人,那么就删除未授权记录
  162. if len(authUserList) < 0 {
  163. authRecordErr = data_manage_permission.DeleteRecordBySourceAndDataIdList(source, subSource, dataIdList)
  164. return
  165. }
  166. userIdMap := make(map[int]int)
  167. for _, tmpUserId := range authUserList {
  168. userIdMap[tmpUserId] = tmpUserId
  169. }
  170. noAuthUserIdList := make([]int, 0)
  171. for _, v := range adminList {
  172. if _, ok := userIdMap[v.AdminId]; !ok {
  173. noAuthUserIdList = append(noAuthUserIdList, v.AdminId)
  174. }
  175. }
  176. content += "已关闭"
  177. // 添加未授权记录
  178. authRecordErr = data_manage_permission.AddRecordBySourceAndDataIdList(source, subSource, dataList, noAuthUserIdList, authUserList, uniqueCode, title, content, opUserId)
  179. return
  180. }
  181. // SetDataClassifyIsPermission
  182. // @Description: 设置资产(指标、图表、ETA表格)分类是否涉密
  183. // @author: Roc
  184. // @datetime 2024-03-27 10:52:32
  185. // @param source int
  186. // @param subSource int
  187. // @param dataId []string
  188. // @param opUserId int 操作人id
  189. // @return err error
  190. // @return errMsg string
  191. func SetDataClassifyIsPermission(source, subSource int, classifyIdList []int, opUserId int) (err error, errMsg string) {
  192. uniqueCode := uuid.NewUUID().Hex32()
  193. title := `数据权限变更`
  194. content := `分类权限`
  195. classifyDataList := make([]data_manage_permission.ClassifyDataItem, 0)
  196. switch source {
  197. case 3, 4:
  198. //ETA指标库、ETA预测指标
  199. if source == 3 {
  200. content += `(ETA指标库)`
  201. } else {
  202. content += `(ETA预测指标)`
  203. }
  204. {
  205. // 分类信息
  206. classifyInfoList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  207. if tmpErr != nil {
  208. err = tmpErr
  209. return
  210. }
  211. for _, v := range classifyInfoList {
  212. classifyDataList = append(classifyDataList, data_manage_permission.ClassifyDataItem{
  213. ClassifyId: v.ClassifyId,
  214. ClassifyName: v.ClassifyName,
  215. })
  216. }
  217. }
  218. // 重新设置权限
  219. classifyType := 0
  220. if source == 4 {
  221. classifyType = 1
  222. }
  223. err = data_manage_permission.SetIsPermissionEdbChartByEdbClassifyIdList(classifyIdList, classifyType)
  224. case 5:
  225. //图库
  226. content += `(ETA图库)`
  227. {
  228. // 分类信息
  229. classifyInfoList, tmpErr := data_manage.GetChartClassifyByIdList(classifyIdList)
  230. if tmpErr != nil {
  231. err = tmpErr
  232. return
  233. }
  234. for _, v := range classifyInfoList {
  235. classifyDataList = append(classifyDataList, data_manage_permission.ClassifyDataItem{
  236. ClassifyId: v.ChartClassifyId,
  237. ClassifyName: v.ChartClassifyName,
  238. })
  239. }
  240. }
  241. // 重新设置权限
  242. chartClassifySource := utils.CHART_SOURCE_DEFAULT
  243. err = data_manage_permission.SetIsPermissionByChartClassifyIdList(classifyIdList, chartClassifySource)
  244. case 6:
  245. // ETA表格
  246. content += `(ETA表格)`
  247. {
  248. // 分类信息
  249. classifyInfoList, tmpErr := excel.GetExcelClassifyByIdList(classifyIdList)
  250. if tmpErr != nil {
  251. err = tmpErr
  252. return
  253. }
  254. for _, v := range classifyInfoList {
  255. classifyDataList = append(classifyDataList, data_manage_permission.ClassifyDataItem{
  256. ClassifyId: v.ExcelClassifyId,
  257. ClassifyName: v.ExcelClassifyName,
  258. })
  259. }
  260. }
  261. // 重新设置权限
  262. err = data_manage_permission.SetIsPermissionByExcelClassifyIdList(classifyIdList, subSource)
  263. default:
  264. return
  265. }
  266. if err != nil {
  267. return
  268. }
  269. var authRecordErr error
  270. defer func() {
  271. if authRecordErr != nil {
  272. utils.FileLog.Error(fmt.Sprintf("记录未设置记录资产权限的记录失败:%s;source:%d;sub_source:%d;分类ID列表:%v", authRecordErr.Error(), source, subSource, classifyIdList))
  273. }
  274. }()
  275. // 如果没有涉密的分类,那么就移除所有删除未授权记录
  276. if len(classifyIdList) <= 0 {
  277. authRecordErr = data_manage_permission.DeleteClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource)
  278. return
  279. }
  280. // 获取所有在用的用户
  281. cond := ` AND enabled = 1`
  282. pars := make([]interface{}, 0)
  283. adminList, authRecordErr := system.GetSysAdminList(cond, pars, []string{}, "")
  284. if authRecordErr != nil {
  285. return
  286. }
  287. noAuthUserIdList := make([]int, 0)
  288. for _, v := range adminList {
  289. noAuthUserIdList = append(noAuthUserIdList, v.AdminId)
  290. }
  291. content += "已关闭"
  292. // 添加未授权记录
  293. authRecordErr = data_manage_permission.AddClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource, classifyDataList, noAuthUserIdList, uniqueCode, title, content, opUserId)
  294. return
  295. }
  296. // SetEdbChartClassifyPermission
  297. // @Description: 给用户设置涉密分类的权限
  298. // @author: Roc
  299. // @datetime 2024-03-28 14:22:30
  300. // @param source int
  301. // @param subSource int
  302. // @param authUserList []int
  303. // @param classifyIdList []int
  304. // @param opUserId int 操作人id
  305. // @return err error
  306. // @return errMsg string
  307. func SetEdbChartClassifyPermission(source, subSource int, authUserList []int, classifyIdList []int, opUserId int) (err error, errMsg string) {
  308. uniqueCode := uuid.NewUUID().Hex32()
  309. title := `数据权限变更`
  310. content := `分类权限`
  311. secretClassifyInfoList := make([]data_manage_permission.ClassifyDataItem, 0)
  312. if len(classifyIdList) <= 0 {
  313. // 说明是取消权限管控
  314. }
  315. // 先获取所有的涉密分类,然后根据用户去判断那些分类给权限了
  316. switch source {
  317. case 3, 4: //ETA指标库、ETA预测指标
  318. //ETA指标库、ETA预测指标
  319. if source == 3 {
  320. content += `(ETA指标库)`
  321. } else {
  322. content += `(ETA预测指标)`
  323. }
  324. classifyType := 0
  325. if source == 4 {
  326. classifyType = 1
  327. }
  328. {
  329. // 获取已经设置加密的分类信息
  330. classifyInfoList, tmpErr := data_manage.GetEdbClassifyByClassifyTypeAndIsJoinPermission(classifyType, 1)
  331. if tmpErr != nil {
  332. err = tmpErr
  333. return
  334. }
  335. for _, v := range classifyInfoList {
  336. secretClassifyInfoList = append(secretClassifyInfoList, data_manage_permission.ClassifyDataItem{
  337. ClassifyId: v.ClassifyId,
  338. ClassifyName: v.ClassifyName,
  339. })
  340. }
  341. }
  342. // 重新设置权限
  343. err = data_manage_permission.SetPermissionByEdbClassifyIdList(classifyIdList, authUserList, classifyType)
  344. case 5:
  345. subSource = utils.CHART_SOURCE_DEFAULT
  346. //图库
  347. content += `(ETA图库)`
  348. {
  349. // 分类信息
  350. classifyInfoList, tmpErr := data_manage.GetChartClassifyBySourceAndIsJoinPermission(subSource, 1)
  351. if tmpErr != nil {
  352. err = tmpErr
  353. return
  354. }
  355. for _, v := range classifyInfoList {
  356. secretClassifyInfoList = append(secretClassifyInfoList, data_manage_permission.ClassifyDataItem{
  357. ClassifyId: v.ChartClassifyId,
  358. ClassifyName: v.ChartClassifyName,
  359. })
  360. }
  361. }
  362. // 重新设置权限
  363. err = data_manage_permission.SetPermissionByChartClassifyIdList(classifyIdList, authUserList, subSource)
  364. case 6:
  365. // ETA表格
  366. content += `(ETA表格)`
  367. {
  368. // 分类信息
  369. classifyInfoList, tmpErr := excel.GetExcelClassifyBySourceAndIsJoinPermission(subSource, 1)
  370. if tmpErr != nil {
  371. err = tmpErr
  372. return
  373. }
  374. for _, v := range classifyInfoList {
  375. secretClassifyInfoList = append(secretClassifyInfoList, data_manage_permission.ClassifyDataItem{
  376. ClassifyId: v.ExcelClassifyId,
  377. ClassifyName: v.ExcelClassifyName,
  378. })
  379. }
  380. }
  381. err = data_manage_permission.SetPermissionByExcelClassifyIdList(classifyIdList, authUserList, subSource)
  382. default:
  383. return
  384. }
  385. if err != nil {
  386. return
  387. }
  388. var authRecordErr error
  389. defer func() {
  390. if authRecordErr != nil {
  391. utils.FileLog.Error(fmt.Sprintf("记录未设置记录资产权限的记录失败:%s;source:%d;sub_source:%d;分类ID列表:%v", authRecordErr.Error(), source, subSource, classifyIdList))
  392. }
  393. }()
  394. content += "已关闭"
  395. authClassifyIdMap := make(map[int]int)
  396. for _, v := range classifyIdList {
  397. authClassifyIdMap[v] = v
  398. }
  399. noAuthClassifyMap := make(map[int]data_manage_permission.ClassifyDataItem)
  400. for _, classifyInfo := range secretClassifyInfoList {
  401. if _, ok := authClassifyIdMap[classifyInfo.ClassifyId]; !ok {
  402. noAuthClassifyMap[classifyInfo.ClassifyId] = classifyInfo
  403. }
  404. }
  405. // 添加未授权记录
  406. authRecordErr = data_manage_permission.AddClassifyNoAuthRecordBySourceAndUserIdList(source, subSource, noAuthClassifyMap, authUserList, uniqueCode, title, content, opUserId)
  407. return
  408. }
  409. // GetEdbChartClassifyIdListPermissionByUserId
  410. // @Description: 根据用户id获取已经配置的分类id列表
  411. // @author: Roc
  412. // @datetime 2024-03-29 16:26:10
  413. // @param source int
  414. // @param subSource int
  415. // @param userId int
  416. // @return idList []int
  417. // @return err error
  418. func GetEdbChartClassifyIdListPermissionByUserId(source, subSource, userId int) (idList []int, err error) {
  419. switch source {
  420. case 3, 4: //ETA指标库、ETA预测指标
  421. //tmpList, tmpErr := data_manage.GetEdbInfoListGroupByUserId(dataId)
  422. //if tmpErr != nil {
  423. // err = tmpErr
  424. // return
  425. //}
  426. //if len(tmpList) > 0 {
  427. //}
  428. // 重新设置权限
  429. classifyType := 0
  430. if source == 4 {
  431. classifyType = 1
  432. }
  433. idList, err = data_manage_permission.GetPermissionEdbClassifyIdListByUserId(userId, classifyType)
  434. case 5:
  435. //图库
  436. chartClassifySource := utils.CHART_SOURCE_DEFAULT
  437. idList, err = data_manage_permission.GetPermissionChartClassifyIdListByUserId(userId, chartClassifySource)
  438. case 6:
  439. // ETA表格
  440. idList, err = data_manage_permission.GetPermissionExcelClassifyIdListByUserId(userId, subSource)
  441. default:
  442. return
  443. }
  444. return
  445. }
  446. // GetUserIdListPermissionByDataId
  447. // @Description: 根据资产(指标、图表、表格)id获取已经配置的用户id
  448. // @author: Roc
  449. // @datetime 2024-03-29 16:26:10
  450. // @param source int
  451. // @param subSource int
  452. // @param dataId int
  453. // @return idList []int
  454. // @return err error
  455. func GetUserIdListPermissionByDataId(source, subSource, dataId int) (idList []int, err error) {
  456. switch source {
  457. case 3, 4:
  458. // ETA指标库、ETA预测指标
  459. edbInfoType := 0
  460. if source == 4 {
  461. edbInfoType = 1
  462. }
  463. idList, err = data_manage_permission.GetPermissionUserIdListByEdbId(dataId, edbInfoType)
  464. case 5:
  465. // 图库
  466. chartClassifySource := utils.CHART_SOURCE_DEFAULT
  467. idList, err = data_manage_permission.GetPermissionUserIdListByChartId(dataId, chartClassifySource)
  468. case 6:
  469. // ETA表格
  470. idList, err = data_manage_permission.GetPermissionUserIdListByExcelId(dataId, subSource)
  471. default:
  472. return
  473. }
  474. return
  475. }
  476. // GetUserIdListNoPermissionByDataId
  477. // @Description: 根据资产(指标、图表、表格)id获取没有该资产分类权限的用户id
  478. // @author: Roc
  479. // @datetime 2024-03-29 16:26:10
  480. // @param source int
  481. // @param subSource int
  482. // @param dataId int
  483. // @return idList []int
  484. // @return err error
  485. func GetUserIdListNoPermissionByDataId(source, subSource, dataId int) (idList []int, err error) {
  486. // 已经授权的用户map
  487. authIdList := make([]int, 0)
  488. switch source {
  489. case 3, 4:
  490. // ETA指标库、ETA预测指标
  491. edbInfoType := 0
  492. if source == 4 {
  493. edbInfoType = 1
  494. }
  495. // 获取指标
  496. edbInfoItem, tmpErr := data_manage.GetEdbInfoById(dataId)
  497. if tmpErr != nil {
  498. err = tmpErr
  499. return
  500. }
  501. // 获取分类
  502. classifyItem, tmpErr := data_manage.GetEdbClassifyById(edbInfoItem.ClassifyId)
  503. if tmpErr != nil {
  504. err = tmpErr
  505. return
  506. }
  507. // 判断分类是否涉密,不涉密就直接返回
  508. if classifyItem.IsJoinPermission == 0 {
  509. return
  510. }
  511. // 获取已经配置分类权限的用户ID列表
  512. authIdList, err = data_manage_permission.GetPermissionUserIdListByEdbClassifyId(dataId, edbInfoType)
  513. case 5:
  514. // 图库
  515. // 获取图表
  516. chartInfoItem, tmpErr := data_manage.GetChartInfoById(dataId)
  517. if tmpErr != nil {
  518. err = tmpErr
  519. return
  520. }
  521. // 获取分类
  522. classifyItem, tmpErr := data_manage.GetChartClassifyById(chartInfoItem.ChartClassifyId)
  523. if tmpErr != nil {
  524. err = tmpErr
  525. return
  526. }
  527. // 判断分类是否涉密,不涉密就直接返回
  528. if classifyItem.IsJoinPermission == 0 {
  529. return
  530. }
  531. chartClassifySource := utils.CHART_SOURCE_DEFAULT
  532. authIdList, err = data_manage_permission.GetPermissionUserIdListByChartClassifyId(dataId, chartClassifySource)
  533. case 6:
  534. // ETA表格
  535. // 获取图表
  536. excelInfoItem, tmpErr := excel.GetNoContentExcelInfoByExcelId(dataId)
  537. if tmpErr != nil {
  538. err = tmpErr
  539. return
  540. }
  541. // 获取分类
  542. classifyItem, tmpErr := excel.GetExcelClassifyById(excelInfoItem.ExcelClassifyId)
  543. if tmpErr != nil {
  544. err = tmpErr
  545. return
  546. }
  547. // 判断分类是否涉密,不涉密就直接返回
  548. if classifyItem.IsJoinPermission == 0 {
  549. return
  550. }
  551. authIdList, err = data_manage_permission.GetPermissionUserIdListByExcelClassifyId(dataId, subSource)
  552. default:
  553. return
  554. }
  555. // 已经授权的用户map
  556. authUserIdMap := make(map[int]int)
  557. for _, v := range authIdList {
  558. authUserIdMap[v] = v
  559. }
  560. // 获取所有在用的用户
  561. cond := ` AND enabled = 1`
  562. pars := make([]interface{}, 0)
  563. adminList, authRecordErr := system.GetSysAdminList(cond, pars, []string{}, "")
  564. if authRecordErr != nil {
  565. return
  566. }
  567. for _, v := range adminList {
  568. if _, ok := authUserIdMap[v.AdminId]; !ok {
  569. idList = append(idList, v.AdminId)
  570. }
  571. }
  572. return
  573. }
  574. // InheritParentClassify
  575. // @Description: 继承父级分类的涉密权限
  576. // @author: Roc
  577. // @datetime 2024-04-07 21:09:16
  578. // @param source int
  579. // @param subSource int
  580. // @param classifyId int
  581. // @param parentClassifyId int
  582. // @param classifyName string
  583. func InheritParentClassify(source, subSource, classifyId, parentClassifyId int, classifyName string) {
  584. var err error
  585. defer func() {
  586. if err != nil {
  587. fmt.Println(fmt.Sprintf("继承父级分类失败:%s;source:%d;sub_source:%d;分类ID列表:%v", err.Error(), source, subSource, classifyId))
  588. utils.FileLog.Error(fmt.Sprintf("继承父级分类失败:%s;source:%d;sub_source:%d;分类ID列表:%v", err.Error(), source, subSource, classifyId))
  589. }
  590. }()
  591. // 一级分类不用继承
  592. if parentClassifyId <= 0 {
  593. return
  594. }
  595. uniqueCode := uuid.NewUUID().Hex32()
  596. switch source {
  597. case 3, 4:
  598. //ETA指标库、ETA预测指标
  599. // 分类信息
  600. parentClassifyInfo, tmpErr := data_manage.GetEdbClassifyById(parentClassifyId)
  601. if tmpErr != nil {
  602. err = tmpErr
  603. return
  604. }
  605. // 没有标记涉密那么就忽略
  606. if parentClassifyInfo.IsJoinPermission == 0 {
  607. return
  608. }
  609. // 重新设置权限
  610. classifyType := 0
  611. if source == 4 {
  612. classifyType = 1
  613. }
  614. err = data_manage_permission.InheritParentClassifyByEdbClassifyId(source, classifyType, classifyId, parentClassifyId, classifyName, uniqueCode)
  615. case 5:
  616. //图库
  617. // 分类信息
  618. parentClassifyInfo, tmpErr := data_manage.GetChartClassifyById(parentClassifyId)
  619. if tmpErr != nil {
  620. err = tmpErr
  621. return
  622. }
  623. // 没有标记涉密那么就忽略
  624. if parentClassifyInfo.IsJoinPermission == 0 {
  625. return
  626. }
  627. // 重新设置权限
  628. chartClassifySource := utils.CHART_SOURCE_DEFAULT
  629. err = data_manage_permission.InheritParentClassifyByChartClassifyId(source, chartClassifySource, classifyId, parentClassifyId, classifyName, uniqueCode)
  630. case 6:
  631. // ETA表格
  632. // 分类信息
  633. parentClassifyInfo, tmpErr := excel.GetExcelClassifyById(parentClassifyId)
  634. if tmpErr != nil {
  635. err = tmpErr
  636. return
  637. }
  638. // 没有标记涉密那么就忽略
  639. if parentClassifyInfo.IsJoinPermission == 0 {
  640. return
  641. }
  642. // 重新设置权限
  643. err = data_manage_permission.InheritParentClassifyByExcelClassifyId(source, subSource, classifyId, parentClassifyId, classifyName, uniqueCode)
  644. default:
  645. return
  646. }
  647. }