edb_permission.go 22 KB

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