edb_permission.go 20 KB

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