edb_permission.go 22 KB

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