data_move.go 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  1. package data_manage_permission
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/data_manage"
  6. "eta/eta_mobile/models/data_manage/data_manage_permission"
  7. "eta/eta_mobile/models/data_manage/excel"
  8. "eta/eta_mobile/models/system"
  9. "eta/eta_mobile/utils"
  10. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/uuid"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // GetEdbChartClassifyList
  17. // @Description: 获取数据权限那边的分类列表
  18. // @author: Roc
  19. // @datetime 2024-04-01 09:46:29
  20. // @param source int
  21. // @param subSource int
  22. // @return resp data_manage.EdbChartClassifyResp
  23. // @return err error
  24. func GetEdbChartClassifyList(source, subSource int) (resp data_manage.EdbChartClassifyResp, err error) {
  25. switch source {
  26. case 1: //手工数据指标
  27. list, e := models.GetEdbdataClassify(0)
  28. if e != nil {
  29. err = e
  30. return
  31. }
  32. for _, v := range list {
  33. item := data_manage.EdbChartClassify{
  34. ClassifyId: v.ClassifyId,
  35. ClassifyName: v.ClassifyName,
  36. ParentId: v.ParentId,
  37. }
  38. for _, v2 := range v.Child {
  39. child := data_manage.EdbChartClassify{
  40. ClassifyId: v2.ClassifyId,
  41. ClassifyName: v2.ClassifyName,
  42. ParentId: v2.ParentId,
  43. }
  44. item.Child = append(item.Child, &child)
  45. }
  46. resp.List = append(resp.List, &item)
  47. }
  48. case 2: //上海钢联数据库
  49. rootList, e := data_manage.GetBaseFromMysteelChemicalClassifyByParentId(0)
  50. if e != nil && e.Error() != utils.ErrNoRow() {
  51. err = e
  52. return
  53. }
  54. classifyAll, e := data_manage.GetAllBaseFromMysteelChemicalClassify()
  55. if e != nil && e.Error() != utils.ErrNoRow() {
  56. err = e
  57. return
  58. }
  59. rootChildMap := make(map[int][]*data_manage.BaseFromMysteelChemicalClassifyItems)
  60. for _, v := range classifyAll {
  61. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  62. }
  63. nodeAll := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
  64. for _, v := range rootList {
  65. if existItems, ok := rootChildMap[v.BaseFromMysteelChemicalClassifyId]; ok {
  66. v.Children = existItems
  67. } else {
  68. items := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
  69. v.Children = items
  70. }
  71. nodeAll = append(nodeAll, v)
  72. }
  73. for _, v := range nodeAll {
  74. item := data_manage.EdbChartClassify{
  75. ClassifyId: v.BaseFromMysteelChemicalClassifyId,
  76. ClassifyName: v.ClassifyName,
  77. ParentId: v.ParentId,
  78. }
  79. for _, v2 := range v.Children {
  80. child := data_manage.EdbChartClassify{
  81. ClassifyId: v2.BaseFromMysteelChemicalClassifyId,
  82. ClassifyName: v2.ClassifyName,
  83. ParentId: v2.ParentId,
  84. }
  85. item.Child = append(item.Child, &child)
  86. }
  87. resp.List = append(resp.List, &item)
  88. }
  89. case 3:
  90. //ETA指标库
  91. //rootList, e := data_manage.GetEdbClassifyByParentId(0, 0)
  92. //if e != nil && e.Error() != utils.ErrNoRow() {
  93. // err = e
  94. // return
  95. //}
  96. // 考虑到后面可以会迭代到10层, 这里直接用递归处理
  97. classifyAll, e := data_manage.GetAllEdbClassifyByType(0)
  98. if e != nil && e.Error() != utils.ErrNoRow() {
  99. err = e
  100. return
  101. }
  102. resp.List = GetEdbMenuTreeRecursive(classifyAll, 0)
  103. case 4:
  104. //ETA预测指标
  105. // 考虑到后面可以会迭代到10层, 这里直接用递归
  106. classifyAll, e := data_manage.GetAllEdbClassifyByType(1)
  107. if e != nil && e.Error() != utils.ErrNoRow() {
  108. err = e
  109. return
  110. }
  111. resp.List = GetEdbMenuTreeRecursive(classifyAll, 0)
  112. case 5: //图库
  113. // 考虑到后面可以会迭代到10层, 这里直接用递归处理
  114. classifyAll, e := data_manage.GetAllChartClassifyItemsBySource(1)
  115. if e != nil && e.Error() != utils.ErrNoRow() {
  116. err = e
  117. return
  118. }
  119. resp.List = GetChartMenuTreeRecursive(classifyAll, 0)
  120. // 将数据加入缓存
  121. //if utils.Re == nil {
  122. // utils.Rc.Delete(key)
  123. //}
  124. case 6:
  125. // ETA表格
  126. // 考虑到后面可以会迭代到10层, 这里直接用递归处理
  127. classifyAll, e := excel.GetExcelClassifyBySourceOrderByLevel(subSource)
  128. if e != nil && e.Error() != utils.ErrNoRow() {
  129. err = e
  130. return
  131. }
  132. resp.List = GetExcelMenuTreeRecursive(classifyAll, 0)
  133. default:
  134. return
  135. }
  136. return
  137. }
  138. // GetEdbMenuTreeRecursive 递归指标库菜单树
  139. func GetEdbMenuTreeRecursive(list []*data_manage.EdbClassifyItems, parentId int) []*data_manage.EdbChartClassify {
  140. res := make([]*data_manage.EdbChartClassify, 0)
  141. for _, v := range list {
  142. t := new(data_manage.EdbChartClassify)
  143. t.ClassifyId = v.ClassifyId
  144. t.ClassifyName = v.ClassifyName
  145. t.ParentId = v.ParentId
  146. t.IsJoinPermission = v.IsJoinPermission
  147. if v.ParentId == parentId {
  148. t.Child = GetEdbMenuTreeRecursive(list, v.ClassifyId)
  149. res = append(res, t)
  150. }
  151. }
  152. return res
  153. }
  154. // GetChartMenuTreeRecursive 递归指标库菜单树
  155. func GetChartMenuTreeRecursive(list []*data_manage.ChartClassifyItems, parentId int) []*data_manage.EdbChartClassify {
  156. res := make([]*data_manage.EdbChartClassify, 0)
  157. for _, v := range list {
  158. t := new(data_manage.EdbChartClassify)
  159. t.ClassifyId = v.ChartClassifyId
  160. t.ClassifyName = v.ChartClassifyName
  161. t.ParentId = v.ParentId
  162. t.IsJoinPermission = v.IsJoinPermission
  163. if v.ParentId == parentId {
  164. t.Child = GetChartMenuTreeRecursive(list, v.ChartClassifyId)
  165. res = append(res, t)
  166. }
  167. }
  168. return res
  169. }
  170. // GetExcelMenuTreeRecursive
  171. // @Description: 递归ETA表格菜单树
  172. // @author: Roc
  173. // @datetime 2024-03-27 10:30:32
  174. // @param list []*data_manage.ChartClassifyItems
  175. // @param parentId int
  176. // @return []*data_manage.EdbChartClassify
  177. func GetExcelMenuTreeRecursive(list []*excel.ExcelClassifyItems, parentId int) []*data_manage.EdbChartClassify {
  178. res := make([]*data_manage.EdbChartClassify, 0)
  179. for _, v := range list {
  180. t := new(data_manage.EdbChartClassify)
  181. t.ClassifyId = v.ExcelClassifyId
  182. t.ClassifyName = v.ExcelClassifyName
  183. t.ParentId = v.ParentId
  184. t.IsJoinPermission = v.IsJoinPermission
  185. if v.ParentId == parentId {
  186. t.Child = GetExcelMenuTreeRecursive(list, v.ExcelClassifyId)
  187. res = append(res, t)
  188. }
  189. }
  190. return res
  191. }
  192. // GetMoveEdbChartList 获取待转移的指标/图表列表
  193. // @param source 来源 :1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
  194. func GetMoveEdbChartList(source, subSource, userId int, keyword, classify string, startSize, pageSize int) (list []data_manage.MoveEdbChartList, total int, err error) {
  195. var condition string
  196. var pars []interface{}
  197. switch source {
  198. case 1: //手工数据指标
  199. if keyword != "" {
  200. condition += ` AND (a.SEC_NAME LIKE ? OR a.TRADE_CODE like ? ) `
  201. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  202. }
  203. if userId > 0 {
  204. condition += ` AND a.user_id = ? `
  205. pars = append(pars, userId)
  206. }
  207. if classify != "" {
  208. condition += ` AND a.classify_id IN (` + classify + `) `
  209. }
  210. total, err = models.GetEdbinfoListCount(condition, pars, "", 0)
  211. if err != nil {
  212. return
  213. }
  214. tmpList, tmpErr := models.GetEdbinfoList(condition, pars, startSize, pageSize, "", 0)
  215. if tmpErr != nil {
  216. err = tmpErr
  217. return
  218. }
  219. if len(tmpList) > 0 {
  220. adminIdList := make([]int, 0)
  221. for _, v := range tmpList {
  222. adminIdList = append(adminIdList, v.UserId)
  223. }
  224. adminList, tmpErr := system.GetAdminListByIdListWithoutEnable(adminIdList)
  225. if tmpErr != nil {
  226. err = tmpErr
  227. return
  228. }
  229. adminMap := make(map[int]string)
  230. for _, adminInfo := range adminList {
  231. adminMap[adminInfo.AdminId] = adminInfo.RealName
  232. }
  233. for _, v := range tmpList {
  234. list = append(list, data_manage.MoveEdbChartList{
  235. DataId: v.TradeCode,
  236. Code: v.TradeCode,
  237. Name: v.SecName,
  238. ClassifyName: v.ClassifyName,
  239. NameEn: v.SecName,
  240. ClassifyNameEn: v.ClassifyName,
  241. CreateUserId: v.UserId,
  242. CreateUserName: adminMap[v.UserId],
  243. })
  244. }
  245. }
  246. case 2: //上海钢联数据库
  247. if keyword != `` {
  248. condition += " AND (index_name like ? OR index_code like ? OR sys_user_real_name like ? ) "
  249. pars = utils.GetLikeKeywordPars(pars, keyword, 3)
  250. }
  251. if userId > 0 {
  252. condition += ` AND sys_user_id = ? `
  253. pars = append(pars, userId)
  254. }
  255. if classify != "" {
  256. condition += ` AND base_from_mysteel_chemical_classify_id IN (` + classify + `) `
  257. }
  258. total, err = data_manage.GetMysteelChemicalIndexCount(condition, pars)
  259. if err != nil {
  260. return
  261. }
  262. tmpList, tmpErr := data_manage.GetMysteelChemicalIndexList(condition, pars, startSize, pageSize, "DESC")
  263. if tmpErr != nil {
  264. err = tmpErr
  265. return
  266. }
  267. for _, v := range tmpList {
  268. list = append(list, data_manage.MoveEdbChartList{
  269. DataId: strconv.Itoa(v.BaseFromMysteelChemicalIndexId),
  270. Code: v.IndexCode,
  271. Name: v.IndexName,
  272. NameEn: v.IndexName,
  273. //ClassifyName: v.,
  274. CreateUserId: v.SysUserId,
  275. CreateUserName: v.SysUserRealName,
  276. })
  277. }
  278. case 3, 4: //ETA指标库、ETA预测指标
  279. if keyword != `` {
  280. condition += " AND (edb_code like ? OR edb_name like ? OR edb_name_en like ? OR sys_user_real_name like ? ) "
  281. pars = utils.GetLikeKeywordPars(pars, keyword, 4)
  282. }
  283. if userId > 0 {
  284. condition += ` AND sys_user_id = ? `
  285. pars = append(pars, userId)
  286. }
  287. if classify != "" {
  288. condition += ` AND classify_id IN (` + classify + `) `
  289. }
  290. edbInfoType := 0 //ETA指标库
  291. if source == 4 { //ETA预测指标
  292. edbInfoType = 1
  293. }
  294. condition += ` AND edb_info_type = ? `
  295. pars = append(pars, edbInfoType)
  296. total, err = data_manage.GetEdbInfoByConditionCount(condition, pars)
  297. if err != nil {
  298. return
  299. }
  300. tmpList, tmpErr := data_manage.GetEdbInfoListByCondition(condition, pars, startSize, pageSize, "DESC")
  301. if tmpErr != nil {
  302. err = tmpErr
  303. return
  304. }
  305. for _, v := range tmpList {
  306. list = append(list, data_manage.MoveEdbChartList{
  307. DataId: strconv.Itoa(v.EdbInfoId),
  308. Code: v.EdbCode,
  309. Name: v.EdbName,
  310. NameEn: v.EdbNameEn,
  311. //ClassifyName: v.,
  312. CreateUserId: v.SysUserId,
  313. CreateUserName: v.SysUserRealName,
  314. })
  315. }
  316. case 5: //图库
  317. // 只展示eta图库
  318. condition += ` AND source = ? `
  319. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  320. // 关键字搜索
  321. if keyword != `` {
  322. condition += " AND (chart_name like ? or chart_name_en like ? OR sys_user_real_name like ? ) "
  323. pars = utils.GetLikeKeywordPars(pars, keyword, 3)
  324. }
  325. if userId > 0 {
  326. condition += ` AND sys_user_id = ? `
  327. pars = append(pars, userId)
  328. }
  329. if classify != "" {
  330. condition += ` AND chart_classify_id IN (` + classify + `) `
  331. }
  332. total, err = data_manage.GetChartInfoCountByCondition(condition, pars)
  333. if err != nil {
  334. return
  335. }
  336. tmpList, tmpErr := data_manage.GetChartInfoListByCondition(condition, pars, startSize, pageSize)
  337. if tmpErr != nil {
  338. err = tmpErr
  339. return
  340. }
  341. // 获取所有的图表分类
  342. firstClassifyList, tmpErr := data_manage.GetChartClassifyByParentId(0, 1)
  343. if tmpErr != nil {
  344. err = tmpErr
  345. return
  346. }
  347. firstClassifyNameMap := make(map[int]string)
  348. firstClassifyNameEnMap := make(map[int]string)
  349. for _, v := range firstClassifyList {
  350. firstClassifyNameMap[v.ChartClassifyId] = v.ChartClassifyName
  351. firstClassifyNameEnMap[v.ChartClassifyId] = v.ChartClassifyNameEn
  352. }
  353. secondClassList, tmpErr := data_manage.GetChartClassifyAll(1)
  354. if tmpErr != nil {
  355. err = tmpErr
  356. return
  357. }
  358. secondClassifyNameMap := make(map[int]string)
  359. secondClassifyNameEnMap := make(map[int]string)
  360. for _, v := range secondClassList {
  361. firstName := firstClassifyNameMap[v.ParentId]
  362. firstNameEn := firstClassifyNameEnMap[v.ParentId]
  363. if firstName != `` {
  364. firstName = firstName + " / "
  365. }
  366. if firstNameEn != `` {
  367. firstNameEn = firstNameEn + " / "
  368. }
  369. secondClassifyNameMap[v.ChartClassifyId] = firstName + v.ChartClassifyName
  370. secondClassifyNameEnMap[v.ChartClassifyId] = firstNameEn + v.ChartClassifyNameEn
  371. }
  372. for _, v := range tmpList {
  373. list = append(list, data_manage.MoveEdbChartList{
  374. DataId: strconv.Itoa(v.ChartInfoId),
  375. Name: v.ChartName,
  376. ClassifyName: secondClassifyNameMap[v.ChartClassifyId],
  377. NameEn: v.ChartNameEn,
  378. ClassifyNameEn: secondClassifyNameEnMap[v.ChartClassifyId],
  379. CreateUserId: v.SysUserId,
  380. CreateUserName: v.SysUserRealName,
  381. })
  382. }
  383. case 6: //ETA表格
  384. if keyword != `` {
  385. condition += " AND (excel_name like ? OR sys_user_real_name like ? ) "
  386. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  387. }
  388. if userId > 0 {
  389. condition += ` AND sys_user_id = ? `
  390. pars = append(pars, userId)
  391. }
  392. if classify != "" {
  393. condition += ` AND excel_classify_id IN (` + classify + `) `
  394. }
  395. condition += " AND source = ? "
  396. pars = append(pars, subSource)
  397. total, err = excel.GetExcelInfoCountByCondition(condition, pars)
  398. if err != nil {
  399. return
  400. }
  401. tmpList, tmpErr := excel.GetNoContentExcelInfoListByCondition(condition, pars, startSize, pageSize)
  402. if tmpErr != nil {
  403. err = tmpErr
  404. return
  405. }
  406. // 获取所有的图表分类
  407. firstClassifyList, tmpErr := excel.GetExcelClassifyByParentId(0, subSource)
  408. if tmpErr != nil {
  409. err = tmpErr
  410. return
  411. }
  412. firstClassifyNameMap := make(map[int]string)
  413. for _, v := range firstClassifyList {
  414. firstClassifyNameMap[v.ExcelClassifyId] = v.ExcelClassifyName
  415. }
  416. secondClassList, tmpErr := excel.GetExcelClassifyBySource(subSource)
  417. if tmpErr != nil {
  418. err = tmpErr
  419. return
  420. }
  421. secondClassifyNameMap := make(map[int]string)
  422. for _, v := range secondClassList {
  423. firstName := firstClassifyNameMap[v.ParentId]
  424. if firstName != `` {
  425. firstName = firstName + " / "
  426. }
  427. secondClassifyNameMap[v.ExcelClassifyId] = firstName + v.ExcelClassifyName
  428. }
  429. for _, v := range tmpList {
  430. list = append(list, data_manage.MoveEdbChartList{
  431. DataId: strconv.Itoa(v.ExcelInfoId),
  432. Name: v.ExcelClassifyName,
  433. ClassifyName: secondClassifyNameMap[v.ExcelClassifyId],
  434. NameEn: v.ExcelClassifyName,
  435. ClassifyNameEn: secondClassifyNameMap[v.ExcelClassifyId],
  436. CreateUserId: v.SysUserId,
  437. CreateUserName: v.SysUserRealName,
  438. })
  439. }
  440. default:
  441. return
  442. }
  443. return
  444. }
  445. // MoveEdbChart 转移指标/图表创建人
  446. // @param source 来源 :1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
  447. func MoveEdbChart(source, subSource, oldUserId, newUserId int, isSelectAll bool, dataId, noDataId []string, keyword, classify string, opUserId int) (err error, errMsg string) {
  448. adminInfo, err := system.GetSysAdminById(newUserId)
  449. if err != nil {
  450. return
  451. }
  452. // 如果勾选全部数据,那么
  453. if isSelectAll {
  454. // 找出不要的指标ID列表
  455. noDataIdMap := make(map[string]string, 0)
  456. for _, v := range noDataId {
  457. noDataIdMap[v] = v
  458. }
  459. // 需要转义的指标/图表ID列表
  460. dataId = make([]string, 0)
  461. // 获取所有指标/图表
  462. list, _, tmpErr := GetMoveEdbChartList(source, subSource, oldUserId, keyword, classify, 0, 100000)
  463. if tmpErr != nil {
  464. err = tmpErr
  465. return
  466. }
  467. for _, v := range list {
  468. if _, ok := noDataIdMap[v.DataId]; !ok {
  469. dataId = append(dataId, v.DataId)
  470. }
  471. }
  472. }
  473. // 操作记录
  474. dataPermissionMoveRecordList := make([]*data_manage_permission.DataPermissionMoveRecord, 0)
  475. uniqueCode := uuid.NewUUID().Hex32()
  476. title := `资产转移`
  477. content := `资产转入`
  478. switch source {
  479. case 1: //手工数据指标
  480. content += `(手工指标数据)`
  481. tmpList, tmpErr := models.GetEdbinfoListByCodeListByCodeIdList(dataId)
  482. if tmpErr != nil {
  483. err = tmpErr
  484. return
  485. }
  486. if len(tmpList) > 0 {
  487. for _, v := range tmpList {
  488. //if v.UserId == newUserId {
  489. // errMsg = "新创建人不可和原创建人一致"
  490. // err = errors.New(errMsg)
  491. // return
  492. //}
  493. // 操作记录
  494. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  495. DataPermissionMoveRecordId: 0,
  496. Source: int32(source),
  497. SubSource: int32(subSource),
  498. OpUniqueCode: uniqueCode,
  499. DataId: v.TradeCode,
  500. DataCode: v.TradeCode,
  501. DataName: v.SecName,
  502. OriginalUserId: int32(v.UserId),
  503. OriginalUserName: v.UserName,
  504. NewUserId: int32(adminInfo.AdminId),
  505. NewUserName: adminInfo.RealName,
  506. CreateTime: time.Now(),
  507. })
  508. }
  509. // 修改创建人
  510. err = models.ModifyEdbinfoUserIdByCodeList(dataId, newUserId)
  511. }
  512. case 2: //上海钢联数据库
  513. content += `(上海钢联数据库)`
  514. tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListByIndexId(dataId)
  515. if tmpErr != nil {
  516. err = tmpErr
  517. return
  518. }
  519. if len(tmpList) > 0 {
  520. for _, v := range tmpList {
  521. //if v.SysUserId == newUserId {
  522. // errMsg = "新创建人不可和原创建人一致"
  523. // err = errors.New(errMsg)
  524. // return
  525. //}
  526. // 操作记录
  527. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  528. DataPermissionMoveRecordId: 0,
  529. Source: int32(source),
  530. SubSource: int32(subSource),
  531. OpUniqueCode: uniqueCode,
  532. DataId: fmt.Sprint(v.BaseFromMysteelChemicalIndexId),
  533. DataCode: v.IndexCode,
  534. DataName: v.IndexName,
  535. OriginalUserId: int32(v.SysUserId),
  536. OriginalUserName: v.SysUserRealName,
  537. NewUserId: int32(adminInfo.AdminId),
  538. NewUserName: adminInfo.RealName,
  539. CreateTime: time.Now(),
  540. })
  541. }
  542. // 修改创建人
  543. err = data_manage.ModifyMysteelChemicalIndexUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
  544. }
  545. case 3, 4: //ETA指标库、ETA预测指标
  546. if source == 3 {
  547. content += `(ETA指标库)`
  548. } else {
  549. content += `(ETA预测指标)`
  550. }
  551. tmpList, tmpErr := data_manage.GetEdbInfoListByEdbInfoId(dataId)
  552. if tmpErr != nil {
  553. err = tmpErr
  554. return
  555. }
  556. if len(tmpList) > 0 {
  557. for _, v := range tmpList {
  558. //if v.SysUserId == newUserId {
  559. // errMsg = "新创建人不可和原创建人一致"
  560. // err = errors.New(errMsg)
  561. // return
  562. //}
  563. // 操作记录
  564. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  565. DataPermissionMoveRecordId: 0,
  566. Source: int32(source),
  567. SubSource: int32(subSource),
  568. OpUniqueCode: uniqueCode,
  569. DataId: fmt.Sprint(v.EdbInfoId),
  570. DataCode: v.EdbCode,
  571. DataName: v.EdbName,
  572. OriginalUserId: int32(v.SysUserId),
  573. OriginalUserName: v.SysUserRealName,
  574. NewUserId: int32(adminInfo.AdminId),
  575. NewUserName: adminInfo.RealName,
  576. CreateTime: time.Now(),
  577. })
  578. }
  579. // 修改创建人
  580. err = data_manage.ModifyEdbInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
  581. // 移除当前用户的不可操作权限
  582. {
  583. obj := data_manage.EdbInfoNoPermissionAdmin{}
  584. for _, v := range dataId {
  585. edbInfoId, _ := strconv.Atoi(v)
  586. go obj.DeleteByEdbInfoIdAndAdminId(edbInfoId, adminInfo.AdminId)
  587. }
  588. }
  589. }
  590. case 5: //图库
  591. content += `(ETA图库)`
  592. // 只展示eta图库
  593. subSource = utils.CHART_SOURCE_DEFAULT
  594. tmpList, tmpErr := data_manage.GetChartInfoListByChartIdList(dataId)
  595. if tmpErr != nil {
  596. err = tmpErr
  597. return
  598. }
  599. if len(tmpList) > 0 {
  600. for _, v := range tmpList {
  601. //if v.SysUserId == newUserId {
  602. // errMsg = "新创建人不可和原创建人一致"
  603. // err = errors.New(errMsg)
  604. // return
  605. //}
  606. // 操作记录
  607. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  608. DataPermissionMoveRecordId: 0,
  609. Source: int32(source),
  610. SubSource: int32(subSource),
  611. OpUniqueCode: uniqueCode,
  612. DataId: fmt.Sprint(v.ChartInfoId),
  613. DataCode: fmt.Sprint(v.ChartInfoId),
  614. DataName: v.ChartName,
  615. OriginalUserId: int32(v.SysUserId),
  616. OriginalUserName: v.SysUserRealName,
  617. NewUserId: int32(adminInfo.AdminId),
  618. NewUserName: adminInfo.RealName,
  619. CreateTime: time.Now(),
  620. })
  621. }
  622. // 修改创建人
  623. err = data_manage.ModifyChartInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
  624. }
  625. case 6: // ETA表格
  626. content += `(ETA表格)`
  627. tmpList, tmpErr := excel.GetNoContentExcelListByExcelInfoIdList(dataId)
  628. if tmpErr != nil {
  629. err = tmpErr
  630. return
  631. }
  632. if len(tmpList) > 0 {
  633. for _, v := range tmpList {
  634. //if v.SysUserId == newUserId {
  635. // errMsg = "新创建人不可和原创建人一致"
  636. // err = errors.New(errMsg)
  637. // return
  638. //}
  639. // 操作记录
  640. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  641. DataPermissionMoveRecordId: 0,
  642. Source: int32(source),
  643. SubSource: int32(subSource),
  644. OpUniqueCode: uniqueCode,
  645. DataId: fmt.Sprint(v.ExcelInfoId),
  646. DataCode: fmt.Sprint(v.ExcelInfoId),
  647. DataName: v.ExcelName,
  648. OriginalUserId: int32(v.SysUserId),
  649. OriginalUserName: v.SysUserRealName,
  650. NewUserId: int32(adminInfo.AdminId),
  651. NewUserName: adminInfo.RealName,
  652. CreateTime: time.Now(),
  653. })
  654. }
  655. // 修改创建人
  656. err = excel.ModifyExcelInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
  657. }
  658. default:
  659. return
  660. }
  661. // 转移失败了那么就直接返回了
  662. if err != nil {
  663. return
  664. }
  665. // 添加资产转移的记录
  666. dataPermissionMessage := &data_manage_permission.DataPermissionMessage{
  667. DataPermissionMessageId: 0,
  668. SendUserId: int32(opUserId),
  669. ReceiveUserId: int32(adminInfo.AdminId),
  670. Content: title,
  671. Remark: content,
  672. OpType: 1,
  673. Source: int32(source),
  674. SubSource: int32(subSource),
  675. OpUniqueCode: uniqueCode,
  676. IsRead: 0,
  677. CreateTime: time.Now(),
  678. ModifyTime: time.Now(),
  679. }
  680. tmpErr := data_manage_permission.AddDataPermissionMoveRecord(dataPermissionMoveRecordList, dataPermissionMessage)
  681. // 失败的话,日志记录
  682. if tmpErr != nil {
  683. // 序列化结构体为 JSON 数据
  684. recordListJsonBytes, tmpErr2 := json.Marshal(dataPermissionMoveRecordList)
  685. if tmpErr2 != nil {
  686. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;list转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  687. return
  688. }
  689. // 序列化结构体为 JSON 数据
  690. messageJsonBytes, tmpErr2 := json.Marshal(dataPermissionMessage)
  691. if tmpErr2 != nil {
  692. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;message转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  693. return
  694. }
  695. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;操作记录:%s;消息记录:%s", tmpErr.Error(), string(recordListJsonBytes), string(messageJsonBytes)))
  696. }
  697. return
  698. }
  699. // MoveAllEdbChartOld
  700. // @Description: 通过原创建人转移指标/图表创建人
  701. // @author: Roc
  702. // @datetime 2024-03-26 15:11:12
  703. // @param sourceList []int 1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
  704. // @param oldUserId []int
  705. // @param userId int
  706. // @param opUserId int
  707. // @return err error
  708. // @return errMsg string
  709. func MoveAllEdbChartOld(sourceList, oldUserIdList []int, userId, opUserId int) (err error, errMsg string) {
  710. adminInfo, err := system.GetSysAdminById(userId)
  711. if err != nil {
  712. return
  713. }
  714. // 操作记录
  715. dataPermissionMoveRecordList := make([]*data_manage_permission.DataPermissionMoveRecord, 0)
  716. uniqueCode := uuid.NewUUID().Hex32()
  717. title := `资产转移`
  718. content := `资产转入`
  719. sourceStrList := make([]string, 0)
  720. for _, source := range sourceList {
  721. switch source {
  722. case 1: //手工数据指标
  723. sourceStrList = append(sourceStrList, "手工指标数据")
  724. tmpList, tmpErr := models.GetEdbinfoListByCodeListByUserId(oldUserIdList)
  725. if tmpErr != nil {
  726. err = tmpErr
  727. return
  728. }
  729. if len(tmpList) > 0 {
  730. for _, v := range tmpList {
  731. // 操作记录
  732. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  733. DataPermissionMoveRecordId: 0,
  734. Source: int32(source),
  735. SubSource: 0,
  736. OpUniqueCode: uniqueCode,
  737. DataId: v.TradeCode,
  738. DataCode: v.TradeCode,
  739. DataName: v.SecName,
  740. OriginalUserId: int32(v.UserId),
  741. OriginalUserName: v.UserName,
  742. NewUserId: int32(adminInfo.AdminId),
  743. NewUserName: adminInfo.RealName,
  744. CreateTime: time.Now(),
  745. })
  746. }
  747. // 修改创建人
  748. err = models.ModifyEdbinfoUserIdByOldUserId(oldUserIdList, userId)
  749. }
  750. case 2: //上海钢联数据库
  751. sourceStrList = append(sourceStrList, "上海钢联数据库")
  752. tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListByUserId(oldUserIdList)
  753. if tmpErr != nil {
  754. err = tmpErr
  755. return
  756. }
  757. if len(tmpList) > 0 {
  758. for _, v := range tmpList {
  759. //if v.SysUserId == newUserId {
  760. // errMsg = "新创建人不可和原创建人一致"
  761. // err = errors.New(errMsg)
  762. // return
  763. //}
  764. // 操作记录
  765. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  766. DataPermissionMoveRecordId: 0,
  767. Source: int32(source),
  768. SubSource: 0,
  769. OpUniqueCode: uniqueCode,
  770. DataId: fmt.Sprint(v.BaseFromMysteelChemicalIndexId),
  771. DataCode: v.IndexCode,
  772. DataName: v.IndexName,
  773. OriginalUserId: int32(v.SysUserId),
  774. OriginalUserName: v.SysUserRealName,
  775. NewUserId: int32(adminInfo.AdminId),
  776. NewUserName: adminInfo.RealName,
  777. CreateTime: time.Now(),
  778. })
  779. }
  780. // 修改创建人
  781. err = data_manage.ModifyMysteelChemicalIndexUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName)
  782. }
  783. case 3: //ETA指标库
  784. sourceStrList = append(sourceStrList, "ETA指标库")
  785. edbInfoType := 0
  786. tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
  787. if tmpErr != nil {
  788. err = tmpErr
  789. return
  790. }
  791. if len(tmpList) > 0 {
  792. for _, v := range tmpList {
  793. // 操作记录
  794. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  795. DataPermissionMoveRecordId: 0,
  796. Source: int32(source),
  797. SubSource: int32(edbInfoType),
  798. OpUniqueCode: uniqueCode,
  799. DataId: fmt.Sprint(v.EdbInfoId),
  800. DataCode: v.EdbCode,
  801. DataName: v.EdbName,
  802. OriginalUserId: int32(v.SysUserId),
  803. OriginalUserName: v.SysUserRealName,
  804. NewUserId: int32(adminInfo.AdminId),
  805. NewUserName: adminInfo.RealName,
  806. CreateTime: time.Now(),
  807. })
  808. }
  809. // 修改创建人
  810. err = data_manage.ModifyEdbInfoUserIdByOldUserId(oldUserIdList, edbInfoType, adminInfo.AdminId, adminInfo.RealName)
  811. }
  812. case 4: //ETA预测指标
  813. sourceStrList = append(sourceStrList, "ETA预测指标")
  814. edbInfoType := 1
  815. tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
  816. if tmpErr != nil {
  817. err = tmpErr
  818. return
  819. }
  820. if len(tmpList) > 0 {
  821. for _, v := range tmpList {
  822. // 操作记录
  823. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  824. DataPermissionMoveRecordId: 0,
  825. Source: int32(source),
  826. SubSource: int32(edbInfoType),
  827. OpUniqueCode: uniqueCode,
  828. DataId: fmt.Sprint(v.EdbInfoId),
  829. DataCode: v.EdbCode,
  830. DataName: v.EdbName,
  831. OriginalUserId: int32(v.SysUserId),
  832. OriginalUserName: v.SysUserRealName,
  833. NewUserId: int32(adminInfo.AdminId),
  834. NewUserName: adminInfo.RealName,
  835. CreateTime: time.Now(),
  836. })
  837. }
  838. // 修改创建人
  839. err = data_manage.ModifyEdbInfoUserIdByOldUserId(oldUserIdList, edbInfoType, adminInfo.AdminId, adminInfo.RealName)
  840. }
  841. case 5: //ETA图库
  842. sourceStrList = append(sourceStrList, "ETA图库")
  843. // 只展示eta图库
  844. subSource := utils.CHART_SOURCE_DEFAULT
  845. tmpList, tmpErr := data_manage.GetChartInfoListByUserId(oldUserIdList, subSource)
  846. if tmpErr != nil {
  847. err = tmpErr
  848. return
  849. }
  850. if len(tmpList) > 0 {
  851. for _, v := range tmpList {
  852. // 操作记录
  853. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  854. DataPermissionMoveRecordId: 0,
  855. Source: int32(source),
  856. SubSource: int32(subSource),
  857. OpUniqueCode: uniqueCode,
  858. DataId: fmt.Sprint(v.ChartInfoId),
  859. DataCode: fmt.Sprint(v.ChartInfoId),
  860. DataName: v.ChartName,
  861. OriginalUserId: int32(v.SysUserId),
  862. OriginalUserName: v.SysUserRealName,
  863. NewUserId: int32(adminInfo.AdminId),
  864. NewUserName: adminInfo.RealName,
  865. CreateTime: time.Now(),
  866. })
  867. }
  868. // 修改创建人
  869. err = data_manage.ModifyChartInfoUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName)
  870. }
  871. case 6: // ETA表格
  872. sourceStrList = append(sourceStrList, "ETA表格")
  873. tmpList, tmpErr := excel.GetNoContentExcelListByUserId(oldUserIdList)
  874. if tmpErr != nil {
  875. err = tmpErr
  876. return
  877. }
  878. if len(tmpList) > 0 {
  879. for _, v := range tmpList {
  880. // 操作记录
  881. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  882. DataPermissionMoveRecordId: 0,
  883. Source: int32(source),
  884. SubSource: int32(v.Source),
  885. OpUniqueCode: uniqueCode,
  886. DataId: fmt.Sprint(v.ExcelInfoId),
  887. DataCode: fmt.Sprint(v.ExcelInfoId),
  888. DataName: v.ExcelName,
  889. OriginalUserId: int32(v.SysUserId),
  890. OriginalUserName: v.SysUserRealName,
  891. NewUserId: int32(adminInfo.AdminId),
  892. NewUserName: adminInfo.RealName,
  893. CreateTime: time.Now(),
  894. })
  895. }
  896. // 修改创建人
  897. err = excel.ModifyExcelInfoUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName)
  898. }
  899. default:
  900. }
  901. // 转移失败了那么就直接返回了
  902. if err != nil {
  903. return
  904. }
  905. }
  906. content += fmt.Sprintf("(%s)", strings.Join(sourceStrList, ","))
  907. // 添加资产转移的记录
  908. dataPermissionMessage := &data_manage_permission.DataPermissionMessage{
  909. DataPermissionMessageId: 0,
  910. SendUserId: int32(opUserId),
  911. ReceiveUserId: int32(adminInfo.AdminId),
  912. Content: title,
  913. Remark: content,
  914. OpType: 2,
  915. OpUniqueCode: uniqueCode,
  916. IsRead: 0,
  917. CreateTime: time.Now(),
  918. ModifyTime: time.Now(),
  919. }
  920. tmpErr := data_manage_permission.AddDataPermissionMoveRecord(dataPermissionMoveRecordList, dataPermissionMessage)
  921. // 失败的话,日志记录
  922. if tmpErr != nil {
  923. // 序列化结构体为 JSON 数据
  924. recordListJsonBytes, tmpErr2 := json.Marshal(dataPermissionMoveRecordList)
  925. if tmpErr2 != nil {
  926. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;list转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  927. return
  928. }
  929. // 序列化结构体为 JSON 数据
  930. messageJsonBytes, tmpErr2 := json.Marshal(dataPermissionMessage)
  931. if tmpErr2 != nil {
  932. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;message转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  933. return
  934. }
  935. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;操作记录:%s;消息记录:%s", tmpErr.Error(), string(recordListJsonBytes), string(messageJsonBytes)))
  936. }
  937. return
  938. }
  939. // MoveAllEdbChart
  940. // @Description: 通过原创建人转移指标/图表创建人
  941. // @author: Roc
  942. // @datetime 2024-03-26 15:11:12
  943. // @param sourceList []int 1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
  944. // @param oldUserId []int
  945. // @param userId int
  946. // @param opUserId int
  947. // @return err error
  948. // @return errMsg string
  949. func MoveAllEdbChart(sourceList, oldUserIdList []int, userId, opUserId int) (err error, errMsg string) {
  950. adminInfo, err := system.GetSysAdminById(userId)
  951. if err != nil {
  952. return
  953. }
  954. // 操作记录
  955. dataPermissionMoveRecordList := make([]*data_manage_permission.DataPermissionMoveRecord, 0)
  956. uniqueCode := uuid.NewUUID().Hex32()
  957. title := `资产转移`
  958. content := `资产转入`
  959. sourceStrList := make([]string, 0)
  960. var isMoveManual, isMoveMysteelChemical, isMoveEdb, isMovePredictEdb, isMoveChart, isMoveExcel bool
  961. // 遍历需要转移的模块,1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格,并找出当前需要转移的资产
  962. for _, source := range sourceList {
  963. switch source {
  964. case 1: //手工数据指标
  965. sourceStrList = append(sourceStrList, "手工指标数据")
  966. tmpList, tmpErr := models.GetEdbinfoListByCodeListByUserId(oldUserIdList)
  967. if tmpErr != nil {
  968. err = tmpErr
  969. return
  970. }
  971. if len(tmpList) > 0 {
  972. for _, v := range tmpList {
  973. // 操作记录
  974. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  975. DataPermissionMoveRecordId: 0,
  976. Source: int32(source),
  977. SubSource: 0,
  978. OpUniqueCode: uniqueCode,
  979. DataId: v.TradeCode,
  980. DataCode: v.TradeCode,
  981. DataName: v.SecName,
  982. OriginalUserId: int32(v.UserId),
  983. OriginalUserName: v.UserName,
  984. NewUserId: int32(adminInfo.AdminId),
  985. NewUserName: adminInfo.RealName,
  986. CreateTime: time.Now(),
  987. })
  988. }
  989. isMoveManual = true
  990. }
  991. case 2: //上海钢联数据库
  992. sourceStrList = append(sourceStrList, "上海钢联数据库")
  993. tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListByUserId(oldUserIdList)
  994. if tmpErr != nil {
  995. err = tmpErr
  996. return
  997. }
  998. if len(tmpList) > 0 {
  999. for _, v := range tmpList {
  1000. //if v.SysUserId == newUserId {
  1001. // errMsg = "新创建人不可和原创建人一致"
  1002. // err = errors.New(errMsg)
  1003. // return
  1004. //}
  1005. // 操作记录
  1006. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1007. DataPermissionMoveRecordId: 0,
  1008. Source: int32(source),
  1009. SubSource: 0,
  1010. OpUniqueCode: uniqueCode,
  1011. DataId: fmt.Sprint(v.BaseFromMysteelChemicalIndexId),
  1012. DataCode: v.IndexCode,
  1013. DataName: v.IndexName,
  1014. OriginalUserId: int32(v.SysUserId),
  1015. OriginalUserName: v.SysUserRealName,
  1016. NewUserId: int32(adminInfo.AdminId),
  1017. NewUserName: adminInfo.RealName,
  1018. CreateTime: time.Now(),
  1019. })
  1020. }
  1021. isMoveMysteelChemical = true
  1022. }
  1023. case 3: //ETA指标库
  1024. sourceStrList = append(sourceStrList, "ETA指标库")
  1025. edbInfoType := 0
  1026. tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
  1027. if tmpErr != nil {
  1028. err = tmpErr
  1029. return
  1030. }
  1031. if len(tmpList) > 0 {
  1032. for _, v := range tmpList {
  1033. // 操作记录
  1034. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1035. DataPermissionMoveRecordId: 0,
  1036. Source: int32(source),
  1037. SubSource: int32(edbInfoType),
  1038. OpUniqueCode: uniqueCode,
  1039. DataId: fmt.Sprint(v.EdbInfoId),
  1040. DataCode: v.EdbCode,
  1041. DataName: v.EdbName,
  1042. OriginalUserId: int32(v.SysUserId),
  1043. OriginalUserName: v.SysUserRealName,
  1044. NewUserId: int32(adminInfo.AdminId),
  1045. NewUserName: adminInfo.RealName,
  1046. CreateTime: time.Now(),
  1047. })
  1048. }
  1049. isMoveEdb = true
  1050. }
  1051. case 4: //ETA预测指标
  1052. sourceStrList = append(sourceStrList, "ETA预测指标")
  1053. edbInfoType := 1
  1054. tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
  1055. if tmpErr != nil {
  1056. err = tmpErr
  1057. return
  1058. }
  1059. if len(tmpList) > 0 {
  1060. for _, v := range tmpList {
  1061. // 操作记录
  1062. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1063. DataPermissionMoveRecordId: 0,
  1064. Source: int32(source),
  1065. SubSource: int32(edbInfoType),
  1066. OpUniqueCode: uniqueCode,
  1067. DataId: fmt.Sprint(v.EdbInfoId),
  1068. DataCode: v.EdbCode,
  1069. DataName: v.EdbName,
  1070. OriginalUserId: int32(v.SysUserId),
  1071. OriginalUserName: v.SysUserRealName,
  1072. NewUserId: int32(adminInfo.AdminId),
  1073. NewUserName: adminInfo.RealName,
  1074. CreateTime: time.Now(),
  1075. })
  1076. }
  1077. isMovePredictEdb = true
  1078. }
  1079. case 5: //ETA图库
  1080. sourceStrList = append(sourceStrList, "ETA图库")
  1081. // 只展示eta图库
  1082. subSource := utils.CHART_SOURCE_DEFAULT
  1083. tmpList, tmpErr := data_manage.GetChartInfoListByUserId(oldUserIdList, subSource)
  1084. if tmpErr != nil {
  1085. err = tmpErr
  1086. return
  1087. }
  1088. if len(tmpList) > 0 {
  1089. for _, v := range tmpList {
  1090. // 操作记录
  1091. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1092. DataPermissionMoveRecordId: 0,
  1093. Source: int32(source),
  1094. SubSource: int32(subSource),
  1095. OpUniqueCode: uniqueCode,
  1096. DataId: fmt.Sprint(v.ChartInfoId),
  1097. DataCode: fmt.Sprint(v.ChartInfoId),
  1098. DataName: v.ChartName,
  1099. OriginalUserId: int32(v.SysUserId),
  1100. OriginalUserName: v.SysUserRealName,
  1101. NewUserId: int32(adminInfo.AdminId),
  1102. NewUserName: adminInfo.RealName,
  1103. CreateTime: time.Now(),
  1104. })
  1105. }
  1106. isMoveChart = true
  1107. }
  1108. case 6: // ETA表格
  1109. sourceStrList = append(sourceStrList, "ETA表格")
  1110. tmpList, tmpErr := excel.GetNoContentExcelListByUserId(oldUserIdList)
  1111. if tmpErr != nil {
  1112. err = tmpErr
  1113. return
  1114. }
  1115. if len(tmpList) > 0 {
  1116. for _, v := range tmpList {
  1117. // 操作记录
  1118. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1119. DataPermissionMoveRecordId: 0,
  1120. Source: int32(source),
  1121. SubSource: int32(v.Source),
  1122. OpUniqueCode: uniqueCode,
  1123. DataId: fmt.Sprint(v.ExcelInfoId),
  1124. DataCode: fmt.Sprint(v.ExcelInfoId),
  1125. DataName: v.ExcelName,
  1126. OriginalUserId: int32(v.SysUserId),
  1127. OriginalUserName: v.SysUserRealName,
  1128. NewUserId: int32(adminInfo.AdminId),
  1129. NewUserName: adminInfo.RealName,
  1130. CreateTime: time.Now(),
  1131. })
  1132. }
  1133. isMoveExcel = true
  1134. }
  1135. default:
  1136. }
  1137. }
  1138. // 修改创建人
  1139. err = data_manage_permission.ModifyDataUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName, isMoveManual, isMoveMysteelChemical, isMoveEdb, isMovePredictEdb, isMoveChart, isMoveExcel)
  1140. // 转移失败了那么就直接返回了
  1141. if err != nil {
  1142. return
  1143. }
  1144. // 添加资产转移的记录
  1145. content += fmt.Sprintf("(%s)", strings.Join(sourceStrList, ","))
  1146. dataPermissionMessage := &data_manage_permission.DataPermissionMessage{
  1147. DataPermissionMessageId: 0,
  1148. SendUserId: int32(opUserId),
  1149. ReceiveUserId: int32(adminInfo.AdminId),
  1150. Content: title,
  1151. Remark: content,
  1152. OpType: 2,
  1153. OpUniqueCode: uniqueCode,
  1154. IsRead: 0,
  1155. CreateTime: time.Now(),
  1156. ModifyTime: time.Now(),
  1157. }
  1158. tmpErr := data_manage_permission.AddDataPermissionMoveRecord(dataPermissionMoveRecordList, dataPermissionMessage)
  1159. // 失败的话,日志记录
  1160. if tmpErr != nil {
  1161. // 序列化结构体为 JSON 数据
  1162. recordListJsonBytes, tmpErr2 := json.Marshal(dataPermissionMoveRecordList)
  1163. if tmpErr2 != nil {
  1164. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;list转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  1165. return
  1166. }
  1167. // 序列化结构体为 JSON 数据
  1168. messageJsonBytes, tmpErr2 := json.Marshal(dataPermissionMessage)
  1169. if tmpErr2 != nil {
  1170. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;message转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  1171. return
  1172. }
  1173. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;操作记录:%s;消息记录:%s", tmpErr.Error(), string(recordListJsonBytes), string(messageJsonBytes)))
  1174. }
  1175. return
  1176. }
  1177. // GetMoveEdbChartCount 获取待转移的指标/图表列表
  1178. // @param userId 用户
  1179. // @param countType 来源 :1:设置资产权限;2:设置数据权限
  1180. func GetMoveEdbChartCount(userId, countType int) (sourceMap map[int]int, err error) {
  1181. sourceMap = make(map[int]int)
  1182. {
  1183. // 手工数据指标
  1184. var condition string
  1185. var pars []interface{}
  1186. if userId > 0 {
  1187. condition += ` AND a.user_id = ? `
  1188. pars = append(pars, userId)
  1189. }
  1190. total, tmpErr := models.GetEdbinfoListCount(condition, pars, "", 0)
  1191. if tmpErr != nil {
  1192. err = tmpErr
  1193. return
  1194. }
  1195. sourceMap[1] = total
  1196. }
  1197. {
  1198. // 上海钢联数据库
  1199. var condition string
  1200. var pars []interface{}
  1201. if userId > 0 {
  1202. condition += ` AND sys_user_id = ? `
  1203. pars = append(pars, userId)
  1204. }
  1205. total, tmpErr := data_manage.GetMysteelChemicalIndexCount(condition, pars)
  1206. if tmpErr != nil {
  1207. err = tmpErr
  1208. return
  1209. }
  1210. sourceMap[2] = total
  1211. }
  1212. {
  1213. // ETA指标库
  1214. var condition string
  1215. var pars []interface{}
  1216. if userId > 0 {
  1217. condition += ` AND sys_user_id = ? `
  1218. pars = append(pars, userId)
  1219. }
  1220. //ETA指标库
  1221. condition += ` AND edb_info_type = ? `
  1222. pars = append(pars, 0)
  1223. total, tmpErr := data_manage.GetEdbInfoByConditionCount(condition, pars)
  1224. if tmpErr != nil {
  1225. err = tmpErr
  1226. return
  1227. }
  1228. sourceMap[3] = total
  1229. }
  1230. {
  1231. // ETA预测指标库
  1232. var condition string
  1233. var pars []interface{}
  1234. if userId > 0 {
  1235. condition += ` AND sys_user_id = ? `
  1236. pars = append(pars, userId)
  1237. }
  1238. //ETA预测指标
  1239. condition += ` AND edb_info_type = ? `
  1240. pars = append(pars, 1)
  1241. total, tmpErr := data_manage.GetEdbInfoByConditionCount(condition, pars)
  1242. if tmpErr != nil {
  1243. err = tmpErr
  1244. return
  1245. }
  1246. sourceMap[4] = total
  1247. }
  1248. {
  1249. // 图库
  1250. var condition string
  1251. var pars []interface{}
  1252. if userId > 0 {
  1253. condition += ` AND sys_user_id = ? `
  1254. pars = append(pars, userId)
  1255. }
  1256. total, tmpErr := data_manage.GetChartInfoCountByCondition(condition, pars)
  1257. if tmpErr != nil {
  1258. err = tmpErr
  1259. return
  1260. }
  1261. sourceMap[5] = total
  1262. }
  1263. {
  1264. // ETA表格
  1265. var condition string
  1266. var pars []interface{}
  1267. condition += ` AND is_delete = 0 `
  1268. if userId > 0 {
  1269. condition += ` AND sys_user_id = ? `
  1270. pars = append(pars, userId)
  1271. }
  1272. switch countType {
  1273. case 2:
  1274. condition += ` AND source in (2,3) `
  1275. default:
  1276. condition += ` AND source in (2,3,4) `
  1277. }
  1278. total, tmpErr := excel.GetExcelInfoCountByCondition(condition, pars)
  1279. if tmpErr != nil {
  1280. err = tmpErr
  1281. return
  1282. }
  1283. sourceMap[6] = total
  1284. }
  1285. return
  1286. }