data_move.go 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  1. package data_manage_permission
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/data_manage_permission"
  7. "eta/eta_api/models/data_manage/excel"
  8. "eta/eta_api/models/system"
  9. "eta/eta_api/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.GetEdbinfoItemList(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. if subSource == utils.BALANCE_TABLE {
  398. condition += " AND parent_id = 0 AND balance_type = 0 "
  399. }
  400. total, err = excel.GetExcelInfoCountByCondition(condition, pars)
  401. if err != nil {
  402. return
  403. }
  404. tmpList, tmpErr := excel.GetNoContentExcelInfoListByCondition(condition, pars, startSize, pageSize)
  405. if tmpErr != nil {
  406. err = tmpErr
  407. return
  408. }
  409. // 获取所有的图表分类
  410. firstClassifyList, tmpErr := excel.GetExcelClassifyByParentId(0, subSource)
  411. if tmpErr != nil {
  412. err = tmpErr
  413. return
  414. }
  415. firstClassifyNameMap := make(map[int]string)
  416. for _, v := range firstClassifyList {
  417. firstClassifyNameMap[v.ExcelClassifyId] = v.ExcelClassifyName
  418. }
  419. secondClassList, tmpErr := excel.GetExcelClassifyBySource(subSource)
  420. if tmpErr != nil {
  421. err = tmpErr
  422. return
  423. }
  424. secondClassifyNameMap := make(map[int]string)
  425. for _, v := range secondClassList {
  426. firstName := firstClassifyNameMap[v.ParentId]
  427. if firstName != `` {
  428. firstName = firstName + " / "
  429. }
  430. secondClassifyNameMap[v.ExcelClassifyId] = firstName + v.ExcelClassifyName
  431. }
  432. for _, v := range tmpList {
  433. list = append(list, data_manage.MoveEdbChartList{
  434. DataId: strconv.Itoa(v.ExcelInfoId),
  435. Name: v.ExcelClassifyName,
  436. ClassifyName: secondClassifyNameMap[v.ExcelClassifyId],
  437. NameEn: v.ExcelClassifyName,
  438. ClassifyNameEn: secondClassifyNameMap[v.ExcelClassifyId],
  439. CreateUserId: v.SysUserId,
  440. CreateUserName: v.SysUserRealName,
  441. })
  442. }
  443. default:
  444. return
  445. }
  446. return
  447. }
  448. // MoveEdbChart 转移指标/图表创建人
  449. // @param source 来源 :1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
  450. func MoveEdbChart(source, subSource, oldUserId, newUserId int, isSelectAll bool, dataId, noDataId []string, keyword, classify string, opUserId int, opUserName string) (err error, errMsg string) {
  451. adminInfo, err := system.GetSysAdminById(newUserId)
  452. if err != nil {
  453. return
  454. }
  455. // 如果勾选全部数据,那么
  456. if isSelectAll {
  457. // 找出不要的指标ID列表
  458. noDataIdMap := make(map[string]string, 0)
  459. for _, v := range noDataId {
  460. noDataIdMap[v] = v
  461. }
  462. // 需要转义的指标/图表ID列表
  463. dataId = make([]string, 0)
  464. // 获取所有指标/图表
  465. list, _, tmpErr := GetMoveEdbChartList(source, subSource, oldUserId, keyword, classify, 0, 100000)
  466. if tmpErr != nil {
  467. err = tmpErr
  468. return
  469. }
  470. for _, v := range list {
  471. if _, ok := noDataIdMap[v.DataId]; !ok {
  472. dataId = append(dataId, v.DataId)
  473. }
  474. }
  475. }
  476. // 操作记录
  477. dataPermissionMoveRecordList := make([]*data_manage_permission.DataPermissionMoveRecord, 0)
  478. uniqueCode := uuid.NewUUID().Hex32()
  479. title := `资产转移`
  480. content := `资产转入`
  481. switch source {
  482. case 1: //手工数据指标
  483. content += `(手工指标数据)`
  484. tmpList, tmpErr := models.GetEdbinfoListByCodeListByCodeIdList(dataId)
  485. if tmpErr != nil {
  486. err = tmpErr
  487. return
  488. }
  489. if len(tmpList) > 0 {
  490. for _, v := range tmpList {
  491. //if v.UserId == newUserId {
  492. // errMsg = "新创建人不可和原创建人一致"
  493. // err = errors.New(errMsg)
  494. // return
  495. //}
  496. // 操作记录
  497. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  498. DataPermissionMoveRecordId: 0,
  499. Source: int32(source),
  500. SubSource: int32(subSource),
  501. OpUniqueCode: uniqueCode,
  502. DataId: v.TradeCode,
  503. DataCode: v.TradeCode,
  504. DataName: v.SecName,
  505. OriginalUserId: int32(v.UserId),
  506. OriginalUserName: v.UserName,
  507. NewUserId: int32(adminInfo.AdminId),
  508. NewUserName: adminInfo.RealName,
  509. CreateTime: time.Now(),
  510. })
  511. }
  512. // 修改创建人
  513. err = models.ModifyEdbinfoUserIdByCodeList(dataId, newUserId, adminInfo.RealName)
  514. // 如果移动成功了,需要记录该指标的操作记录
  515. if err == nil && len(tmpList) > 0 {
  516. go afterMoveManualEdb(tmpList, adminInfo, opUserId, opUserName)
  517. }
  518. }
  519. case 2: //上海钢联数据库
  520. content += `(上海钢联数据库)`
  521. tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListByIndexId(dataId)
  522. if tmpErr != nil {
  523. err = tmpErr
  524. return
  525. }
  526. if len(tmpList) > 0 {
  527. for _, v := range tmpList {
  528. //if v.SysUserId == newUserId {
  529. // errMsg = "新创建人不可和原创建人一致"
  530. // err = errors.New(errMsg)
  531. // return
  532. //}
  533. // 操作记录
  534. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  535. DataPermissionMoveRecordId: 0,
  536. Source: int32(source),
  537. SubSource: int32(subSource),
  538. OpUniqueCode: uniqueCode,
  539. DataId: fmt.Sprint(v.BaseFromMysteelChemicalIndexId),
  540. DataCode: v.IndexCode,
  541. DataName: v.IndexName,
  542. OriginalUserId: int32(v.SysUserId),
  543. OriginalUserName: v.SysUserRealName,
  544. NewUserId: int32(adminInfo.AdminId),
  545. NewUserName: adminInfo.RealName,
  546. CreateTime: time.Now(),
  547. })
  548. }
  549. // 修改创建人
  550. err = data_manage.ModifyMysteelChemicalIndexUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
  551. }
  552. case 3, 4: //ETA指标库、ETA预测指标
  553. if source == 3 {
  554. content += `(ETA指标库)`
  555. } else {
  556. content += `(ETA预测指标)`
  557. }
  558. tmpList, tmpErr := data_manage.GetEdbInfoListByEdbInfoId(dataId)
  559. if tmpErr != nil {
  560. err = tmpErr
  561. return
  562. }
  563. if len(tmpList) > 0 {
  564. for _, v := range tmpList {
  565. //if v.SysUserId == newUserId {
  566. // errMsg = "新创建人不可和原创建人一致"
  567. // err = errors.New(errMsg)
  568. // return
  569. //}
  570. // 操作记录
  571. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  572. DataPermissionMoveRecordId: 0,
  573. Source: int32(source),
  574. SubSource: int32(subSource),
  575. OpUniqueCode: uniqueCode,
  576. DataId: fmt.Sprint(v.EdbInfoId),
  577. DataCode: v.EdbCode,
  578. DataName: v.EdbName,
  579. OriginalUserId: int32(v.SysUserId),
  580. OriginalUserName: v.SysUserRealName,
  581. NewUserId: int32(adminInfo.AdminId),
  582. NewUserName: adminInfo.RealName,
  583. CreateTime: time.Now(),
  584. })
  585. }
  586. // 修改创建人
  587. err = data_manage.ModifyEdbInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
  588. // 移除当前用户的不可操作权限
  589. {
  590. obj := data_manage.EdbInfoNoPermissionAdmin{}
  591. for _, v := range dataId {
  592. edbInfoId, _ := strconv.Atoi(v)
  593. go obj.DeleteByEdbInfoIdAndAdminId(edbInfoId, adminInfo.AdminId)
  594. }
  595. }
  596. }
  597. case 5: //图库
  598. content += `(ETA图库)`
  599. // 只展示eta图库
  600. subSource = utils.CHART_SOURCE_DEFAULT
  601. tmpList, tmpErr := data_manage.GetChartInfoListByChartIdList(dataId)
  602. if tmpErr != nil {
  603. err = tmpErr
  604. return
  605. }
  606. if len(tmpList) > 0 {
  607. for _, v := range tmpList {
  608. //if v.SysUserId == newUserId {
  609. // errMsg = "新创建人不可和原创建人一致"
  610. // err = errors.New(errMsg)
  611. // return
  612. //}
  613. // 操作记录
  614. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  615. DataPermissionMoveRecordId: 0,
  616. Source: int32(source),
  617. SubSource: int32(subSource),
  618. OpUniqueCode: uniqueCode,
  619. DataId: fmt.Sprint(v.ChartInfoId),
  620. DataCode: fmt.Sprint(v.ChartInfoId),
  621. DataName: v.ChartName,
  622. OriginalUserId: int32(v.SysUserId),
  623. OriginalUserName: v.SysUserRealName,
  624. NewUserId: int32(adminInfo.AdminId),
  625. NewUserName: adminInfo.RealName,
  626. CreateTime: time.Now(),
  627. })
  628. }
  629. // 修改创建人
  630. err = data_manage.ModifyChartInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
  631. }
  632. case 6: // ETA表格
  633. content += `(ETA表格)`
  634. tmpList, tmpErr := excel.GetNoContentExcelListByExcelInfoIdList(dataId)
  635. if tmpErr != nil {
  636. err = tmpErr
  637. return
  638. }
  639. var customAnalysisIds []int
  640. if len(tmpList) > 0 {
  641. for _, v := range tmpList {
  642. //if v.SysUserId == newUserId {
  643. // errMsg = "新创建人不可和原创建人一致"
  644. // err = errors.New(errMsg)
  645. // return
  646. //}
  647. // 操作记录
  648. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  649. DataPermissionMoveRecordId: 0,
  650. Source: int32(source),
  651. SubSource: int32(subSource),
  652. OpUniqueCode: uniqueCode,
  653. DataId: fmt.Sprint(v.ExcelInfoId),
  654. DataCode: fmt.Sprint(v.ExcelInfoId),
  655. DataName: v.ExcelName,
  656. OriginalUserId: int32(v.SysUserId),
  657. OriginalUserName: v.SysUserRealName,
  658. NewUserId: int32(adminInfo.AdminId),
  659. NewUserName: adminInfo.RealName,
  660. CreateTime: time.Now(),
  661. })
  662. if v.Source == utils.CUSTOM_ANALYSIS_TABLE {
  663. customAnalysisIds = append(customAnalysisIds, v.ExcelInfoId)
  664. }
  665. }
  666. // 修改创建人
  667. err = excel.ModifyExcelInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
  668. if err != nil {
  669. return
  670. }
  671. // 由于自定义分析表分类私有化, 如果转移的是自定义分析表, 那么需要将excel转移至未分类下
  672. if len(customAnalysisIds) > 0 {
  673. err = MoveCustomAnalysisExcel2DefaultClassify(customAnalysisIds, adminInfo.AdminId, adminInfo.RealName)
  674. }
  675. }
  676. default:
  677. return
  678. }
  679. // 转移失败了那么就直接返回了
  680. if err != nil {
  681. return
  682. }
  683. // 添加资产转移的记录
  684. dataPermissionMessage := &data_manage_permission.DataPermissionMessage{
  685. DataPermissionMessageId: 0,
  686. SendUserId: int32(opUserId),
  687. ReceiveUserId: int32(adminInfo.AdminId),
  688. Content: title,
  689. Remark: content,
  690. OpType: 1,
  691. Source: int32(source),
  692. SubSource: int32(subSource),
  693. OpUniqueCode: uniqueCode,
  694. IsRead: 0,
  695. CreateTime: time.Now(),
  696. ModifyTime: time.Now(),
  697. }
  698. tmpErr := data_manage_permission.AddDataPermissionMoveRecord(dataPermissionMoveRecordList, dataPermissionMessage)
  699. // 失败的话,日志记录
  700. if tmpErr != nil {
  701. // 序列化结构体为 JSON 数据
  702. recordListJsonBytes, tmpErr2 := json.Marshal(dataPermissionMoveRecordList)
  703. if tmpErr2 != nil {
  704. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;list转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  705. return
  706. }
  707. // 序列化结构体为 JSON 数据
  708. messageJsonBytes, tmpErr2 := json.Marshal(dataPermissionMessage)
  709. if tmpErr2 != nil {
  710. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;message转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  711. return
  712. }
  713. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;操作记录:%s;消息记录:%s", tmpErr.Error(), string(recordListJsonBytes), string(messageJsonBytes)))
  714. }
  715. return
  716. }
  717. // MoveAllEdbChartOld
  718. // @Description: 通过原创建人转移指标/图表创建人
  719. // @author: Roc
  720. // @datetime 2024-03-26 15:11:12
  721. // @param sourceList []int 1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
  722. // @param oldUserId []int
  723. // @param userId int
  724. // @param opUserId int
  725. // @return err error
  726. // @return errMsg string
  727. func MoveAllEdbChartOld(sourceList, oldUserIdList []int, userId, opUserId int) (err error, errMsg string) {
  728. adminInfo, err := system.GetSysAdminById(userId)
  729. if err != nil {
  730. return
  731. }
  732. // 操作记录
  733. dataPermissionMoveRecordList := make([]*data_manage_permission.DataPermissionMoveRecord, 0)
  734. uniqueCode := uuid.NewUUID().Hex32()
  735. title := `资产转移`
  736. content := `资产转入`
  737. sourceStrList := make([]string, 0)
  738. for _, source := range sourceList {
  739. switch source {
  740. case 1: //手工数据指标
  741. sourceStrList = append(sourceStrList, "手工指标数据")
  742. tmpList, tmpErr := models.GetEdbinfoListByCodeListByUserId(oldUserIdList)
  743. if tmpErr != nil {
  744. err = tmpErr
  745. return
  746. }
  747. if len(tmpList) > 0 {
  748. for _, v := range tmpList {
  749. // 操作记录
  750. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  751. DataPermissionMoveRecordId: 0,
  752. Source: int32(source),
  753. SubSource: 0,
  754. OpUniqueCode: uniqueCode,
  755. DataId: v.TradeCode,
  756. DataCode: v.TradeCode,
  757. DataName: v.SecName,
  758. OriginalUserId: int32(v.UserId),
  759. OriginalUserName: v.UserName,
  760. NewUserId: int32(adminInfo.AdminId),
  761. NewUserName: adminInfo.RealName,
  762. CreateTime: time.Now(),
  763. })
  764. }
  765. // 修改创建人
  766. err = models.ModifyEdbinfoUserIdByOldUserId(oldUserIdList, userId)
  767. }
  768. case 2: //上海钢联数据库
  769. sourceStrList = append(sourceStrList, "上海钢联数据库")
  770. tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListByUserId(oldUserIdList)
  771. if tmpErr != nil {
  772. err = tmpErr
  773. return
  774. }
  775. if len(tmpList) > 0 {
  776. for _, v := range tmpList {
  777. //if v.SysUserId == newUserId {
  778. // errMsg = "新创建人不可和原创建人一致"
  779. // err = errors.New(errMsg)
  780. // return
  781. //}
  782. // 操作记录
  783. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  784. DataPermissionMoveRecordId: 0,
  785. Source: int32(source),
  786. SubSource: 0,
  787. OpUniqueCode: uniqueCode,
  788. DataId: fmt.Sprint(v.BaseFromMysteelChemicalIndexId),
  789. DataCode: v.IndexCode,
  790. DataName: v.IndexName,
  791. OriginalUserId: int32(v.SysUserId),
  792. OriginalUserName: v.SysUserRealName,
  793. NewUserId: int32(adminInfo.AdminId),
  794. NewUserName: adminInfo.RealName,
  795. CreateTime: time.Now(),
  796. })
  797. }
  798. // 修改创建人
  799. err = data_manage.ModifyMysteelChemicalIndexUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName)
  800. }
  801. case 3: //ETA指标库
  802. sourceStrList = append(sourceStrList, "ETA指标库")
  803. edbInfoType := 0
  804. tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
  805. if tmpErr != nil {
  806. err = tmpErr
  807. return
  808. }
  809. if len(tmpList) > 0 {
  810. for _, v := range tmpList {
  811. // 操作记录
  812. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  813. DataPermissionMoveRecordId: 0,
  814. Source: int32(source),
  815. SubSource: int32(edbInfoType),
  816. OpUniqueCode: uniqueCode,
  817. DataId: fmt.Sprint(v.EdbInfoId),
  818. DataCode: v.EdbCode,
  819. DataName: v.EdbName,
  820. OriginalUserId: int32(v.SysUserId),
  821. OriginalUserName: v.SysUserRealName,
  822. NewUserId: int32(adminInfo.AdminId),
  823. NewUserName: adminInfo.RealName,
  824. CreateTime: time.Now(),
  825. })
  826. }
  827. // 修改创建人
  828. err = data_manage.ModifyEdbInfoUserIdByOldUserId(oldUserIdList, edbInfoType, adminInfo.AdminId, adminInfo.RealName)
  829. }
  830. case 4: //ETA预测指标
  831. sourceStrList = append(sourceStrList, "ETA预测指标")
  832. edbInfoType := 1
  833. tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
  834. if tmpErr != nil {
  835. err = tmpErr
  836. return
  837. }
  838. if len(tmpList) > 0 {
  839. for _, v := range tmpList {
  840. // 操作记录
  841. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  842. DataPermissionMoveRecordId: 0,
  843. Source: int32(source),
  844. SubSource: int32(edbInfoType),
  845. OpUniqueCode: uniqueCode,
  846. DataId: fmt.Sprint(v.EdbInfoId),
  847. DataCode: v.EdbCode,
  848. DataName: v.EdbName,
  849. OriginalUserId: int32(v.SysUserId),
  850. OriginalUserName: v.SysUserRealName,
  851. NewUserId: int32(adminInfo.AdminId),
  852. NewUserName: adminInfo.RealName,
  853. CreateTime: time.Now(),
  854. })
  855. }
  856. // 修改创建人
  857. err = data_manage.ModifyEdbInfoUserIdByOldUserId(oldUserIdList, edbInfoType, adminInfo.AdminId, adminInfo.RealName)
  858. }
  859. case 5: //ETA图库
  860. sourceStrList = append(sourceStrList, "ETA图库")
  861. // 只展示eta图库
  862. subSource := utils.CHART_SOURCE_DEFAULT
  863. tmpList, tmpErr := data_manage.GetChartInfoListByUserId(oldUserIdList, subSource)
  864. if tmpErr != nil {
  865. err = tmpErr
  866. return
  867. }
  868. if len(tmpList) > 0 {
  869. for _, v := range tmpList {
  870. // 操作记录
  871. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  872. DataPermissionMoveRecordId: 0,
  873. Source: int32(source),
  874. SubSource: int32(subSource),
  875. OpUniqueCode: uniqueCode,
  876. DataId: fmt.Sprint(v.ChartInfoId),
  877. DataCode: fmt.Sprint(v.ChartInfoId),
  878. DataName: v.ChartName,
  879. OriginalUserId: int32(v.SysUserId),
  880. OriginalUserName: v.SysUserRealName,
  881. NewUserId: int32(adminInfo.AdminId),
  882. NewUserName: adminInfo.RealName,
  883. CreateTime: time.Now(),
  884. })
  885. }
  886. // 修改创建人
  887. err = data_manage.ModifyChartInfoUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName)
  888. }
  889. case 6: // ETA表格
  890. sourceStrList = append(sourceStrList, "ETA表格")
  891. tmpList, tmpErr := excel.GetNoContentExcelListByUserId(oldUserIdList)
  892. if tmpErr != nil {
  893. err = tmpErr
  894. return
  895. }
  896. if len(tmpList) > 0 {
  897. for _, v := range tmpList {
  898. // 操作记录
  899. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  900. DataPermissionMoveRecordId: 0,
  901. Source: int32(source),
  902. SubSource: int32(v.Source),
  903. OpUniqueCode: uniqueCode,
  904. DataId: fmt.Sprint(v.ExcelInfoId),
  905. DataCode: fmt.Sprint(v.ExcelInfoId),
  906. DataName: v.ExcelName,
  907. OriginalUserId: int32(v.SysUserId),
  908. OriginalUserName: v.SysUserRealName,
  909. NewUserId: int32(adminInfo.AdminId),
  910. NewUserName: adminInfo.RealName,
  911. CreateTime: time.Now(),
  912. })
  913. }
  914. // 修改创建人
  915. err = excel.ModifyExcelInfoUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName)
  916. }
  917. default:
  918. }
  919. // 转移失败了那么就直接返回了
  920. if err != nil {
  921. return
  922. }
  923. }
  924. content += fmt.Sprintf("(%s)", strings.Join(sourceStrList, ","))
  925. // 添加资产转移的记录
  926. dataPermissionMessage := &data_manage_permission.DataPermissionMessage{
  927. DataPermissionMessageId: 0,
  928. SendUserId: int32(opUserId),
  929. ReceiveUserId: int32(adminInfo.AdminId),
  930. Content: title,
  931. Remark: content,
  932. OpType: 2,
  933. OpUniqueCode: uniqueCode,
  934. IsRead: 0,
  935. CreateTime: time.Now(),
  936. ModifyTime: time.Now(),
  937. }
  938. tmpErr := data_manage_permission.AddDataPermissionMoveRecord(dataPermissionMoveRecordList, dataPermissionMessage)
  939. // 失败的话,日志记录
  940. if tmpErr != nil {
  941. // 序列化结构体为 JSON 数据
  942. recordListJsonBytes, tmpErr2 := json.Marshal(dataPermissionMoveRecordList)
  943. if tmpErr2 != nil {
  944. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;list转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  945. return
  946. }
  947. // 序列化结构体为 JSON 数据
  948. messageJsonBytes, tmpErr2 := json.Marshal(dataPermissionMessage)
  949. if tmpErr2 != nil {
  950. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;message转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  951. return
  952. }
  953. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;操作记录:%s;消息记录:%s", tmpErr.Error(), string(recordListJsonBytes), string(messageJsonBytes)))
  954. }
  955. return
  956. }
  957. // MoveAllEdbChart
  958. // @Description: 通过原创建人转移指标/图表创建人
  959. // @author: Roc
  960. // @datetime 2024-03-26 15:11:12
  961. // @param sourceList []int 1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
  962. // @param oldUserId []int
  963. // @param userId int
  964. // @param opUserId int
  965. // @return err error
  966. // @return errMsg string
  967. func MoveAllEdbChart(sourceList, oldUserIdList []int, userId, opUserId int) (err error, errMsg string) {
  968. adminInfo, err := system.GetSysAdminById(userId)
  969. if err != nil {
  970. return
  971. }
  972. // 操作记录
  973. dataPermissionMoveRecordList := make([]*data_manage_permission.DataPermissionMoveRecord, 0)
  974. uniqueCode := uuid.NewUUID().Hex32()
  975. title := `资产转移`
  976. content := `资产转入`
  977. sourceStrList := make([]string, 0)
  978. var isMoveManual, isMoveMysteelChemical, isMoveEdb, isMovePredictEdb, isMoveChart, isMoveExcel bool
  979. var customAnalysisIds []int
  980. // 遍历需要转移的模块,1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格,并找出当前需要转移的资产
  981. for _, source := range sourceList {
  982. switch source {
  983. case 1: //手工数据指标
  984. sourceStrList = append(sourceStrList, "手工指标数据")
  985. tmpList, tmpErr := models.GetEdbinfoListByCodeListByUserId(oldUserIdList)
  986. if tmpErr != nil {
  987. err = tmpErr
  988. return
  989. }
  990. if len(tmpList) > 0 {
  991. for _, v := range tmpList {
  992. // 操作记录
  993. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  994. DataPermissionMoveRecordId: 0,
  995. Source: int32(source),
  996. SubSource: 0,
  997. OpUniqueCode: uniqueCode,
  998. DataId: v.TradeCode,
  999. DataCode: v.TradeCode,
  1000. DataName: v.SecName,
  1001. OriginalUserId: int32(v.UserId),
  1002. OriginalUserName: v.UserName,
  1003. NewUserId: int32(adminInfo.AdminId),
  1004. NewUserName: adminInfo.RealName,
  1005. CreateTime: time.Now(),
  1006. })
  1007. }
  1008. isMoveManual = true
  1009. }
  1010. case 2: //上海钢联数据库
  1011. sourceStrList = append(sourceStrList, "上海钢联数据库")
  1012. tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListByUserId(oldUserIdList)
  1013. if tmpErr != nil {
  1014. err = tmpErr
  1015. return
  1016. }
  1017. if len(tmpList) > 0 {
  1018. for _, v := range tmpList {
  1019. //if v.SysUserId == newUserId {
  1020. // errMsg = "新创建人不可和原创建人一致"
  1021. // err = errors.New(errMsg)
  1022. // return
  1023. //}
  1024. // 操作记录
  1025. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1026. DataPermissionMoveRecordId: 0,
  1027. Source: int32(source),
  1028. SubSource: 0,
  1029. OpUniqueCode: uniqueCode,
  1030. DataId: fmt.Sprint(v.BaseFromMysteelChemicalIndexId),
  1031. DataCode: v.IndexCode,
  1032. DataName: v.IndexName,
  1033. OriginalUserId: int32(v.SysUserId),
  1034. OriginalUserName: v.SysUserRealName,
  1035. NewUserId: int32(adminInfo.AdminId),
  1036. NewUserName: adminInfo.RealName,
  1037. CreateTime: time.Now(),
  1038. })
  1039. }
  1040. isMoveMysteelChemical = true
  1041. }
  1042. case 3: //ETA指标库
  1043. sourceStrList = append(sourceStrList, "ETA指标库")
  1044. edbInfoType := 0
  1045. tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
  1046. if tmpErr != nil {
  1047. err = tmpErr
  1048. return
  1049. }
  1050. if len(tmpList) > 0 {
  1051. for _, v := range tmpList {
  1052. // 操作记录
  1053. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1054. DataPermissionMoveRecordId: 0,
  1055. Source: int32(source),
  1056. SubSource: int32(edbInfoType),
  1057. OpUniqueCode: uniqueCode,
  1058. DataId: fmt.Sprint(v.EdbInfoId),
  1059. DataCode: v.EdbCode,
  1060. DataName: v.EdbName,
  1061. OriginalUserId: int32(v.SysUserId),
  1062. OriginalUserName: v.SysUserRealName,
  1063. NewUserId: int32(adminInfo.AdminId),
  1064. NewUserName: adminInfo.RealName,
  1065. CreateTime: time.Now(),
  1066. })
  1067. }
  1068. isMoveEdb = true
  1069. }
  1070. case 4: //ETA预测指标
  1071. sourceStrList = append(sourceStrList, "ETA预测指标")
  1072. edbInfoType := 1
  1073. tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
  1074. if tmpErr != nil {
  1075. err = tmpErr
  1076. return
  1077. }
  1078. if len(tmpList) > 0 {
  1079. for _, v := range tmpList {
  1080. // 操作记录
  1081. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1082. DataPermissionMoveRecordId: 0,
  1083. Source: int32(source),
  1084. SubSource: int32(edbInfoType),
  1085. OpUniqueCode: uniqueCode,
  1086. DataId: fmt.Sprint(v.EdbInfoId),
  1087. DataCode: v.EdbCode,
  1088. DataName: v.EdbName,
  1089. OriginalUserId: int32(v.SysUserId),
  1090. OriginalUserName: v.SysUserRealName,
  1091. NewUserId: int32(adminInfo.AdminId),
  1092. NewUserName: adminInfo.RealName,
  1093. CreateTime: time.Now(),
  1094. })
  1095. }
  1096. isMovePredictEdb = true
  1097. }
  1098. case 5: //ETA图库
  1099. sourceStrList = append(sourceStrList, "ETA图库")
  1100. // 只展示eta图库
  1101. subSource := utils.CHART_SOURCE_DEFAULT
  1102. tmpList, tmpErr := data_manage.GetChartInfoListByUserId(oldUserIdList, subSource)
  1103. if tmpErr != nil {
  1104. err = tmpErr
  1105. return
  1106. }
  1107. if len(tmpList) > 0 {
  1108. for _, v := range tmpList {
  1109. // 操作记录
  1110. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1111. DataPermissionMoveRecordId: 0,
  1112. Source: int32(source),
  1113. SubSource: int32(subSource),
  1114. OpUniqueCode: uniqueCode,
  1115. DataId: fmt.Sprint(v.ChartInfoId),
  1116. DataCode: fmt.Sprint(v.ChartInfoId),
  1117. DataName: v.ChartName,
  1118. OriginalUserId: int32(v.SysUserId),
  1119. OriginalUserName: v.SysUserRealName,
  1120. NewUserId: int32(adminInfo.AdminId),
  1121. NewUserName: adminInfo.RealName,
  1122. CreateTime: time.Now(),
  1123. })
  1124. }
  1125. isMoveChart = true
  1126. }
  1127. case 6: // ETA表格
  1128. sourceStrList = append(sourceStrList, "ETA表格")
  1129. tmpList, tmpErr := excel.GetNoContentExcelListByUserId(oldUserIdList)
  1130. if tmpErr != nil {
  1131. err = tmpErr
  1132. return
  1133. }
  1134. if len(tmpList) > 0 {
  1135. for _, v := range tmpList {
  1136. // 操作记录
  1137. dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
  1138. DataPermissionMoveRecordId: 0,
  1139. Source: int32(source),
  1140. SubSource: int32(v.Source),
  1141. OpUniqueCode: uniqueCode,
  1142. DataId: fmt.Sprint(v.ExcelInfoId),
  1143. DataCode: fmt.Sprint(v.ExcelInfoId),
  1144. DataName: v.ExcelName,
  1145. OriginalUserId: int32(v.SysUserId),
  1146. OriginalUserName: v.SysUserRealName,
  1147. NewUserId: int32(adminInfo.AdminId),
  1148. NewUserName: adminInfo.RealName,
  1149. CreateTime: time.Now(),
  1150. })
  1151. if v.Source == utils.CUSTOM_ANALYSIS_TABLE {
  1152. customAnalysisIds = append(customAnalysisIds, v.ExcelInfoId)
  1153. }
  1154. }
  1155. isMoveExcel = true
  1156. }
  1157. default:
  1158. }
  1159. }
  1160. // 修改创建人
  1161. err = data_manage_permission.ModifyDataUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName, isMoveManual, isMoveMysteelChemical, isMoveEdb, isMovePredictEdb, isMoveChart, isMoveExcel)
  1162. // 转移失败了那么就直接返回了
  1163. if err != nil {
  1164. return
  1165. }
  1166. // 由于自定义分析表分类私有化, 如果转移的含自定义分析表, 那么需要将excel转移至未分类下
  1167. if len(customAnalysisIds) > 0 {
  1168. err = MoveCustomAnalysisExcel2DefaultClassify(customAnalysisIds, adminInfo.AdminId, adminInfo.RealName)
  1169. if err != nil {
  1170. err = fmt.Errorf("MoveCustomAnalysisExcel2DefaultClassify, err: %v", err)
  1171. return
  1172. }
  1173. }
  1174. // 添加资产转移的记录
  1175. content += fmt.Sprintf("(%s)", strings.Join(sourceStrList, ","))
  1176. dataPermissionMessage := &data_manage_permission.DataPermissionMessage{
  1177. DataPermissionMessageId: 0,
  1178. SendUserId: int32(opUserId),
  1179. ReceiveUserId: int32(adminInfo.AdminId),
  1180. Content: title,
  1181. Remark: content,
  1182. OpType: 2,
  1183. OpUniqueCode: uniqueCode,
  1184. IsRead: 0,
  1185. CreateTime: time.Now(),
  1186. ModifyTime: time.Now(),
  1187. }
  1188. tmpErr := data_manage_permission.AddDataPermissionMoveRecord(dataPermissionMoveRecordList, dataPermissionMessage)
  1189. // 失败的话,日志记录
  1190. if tmpErr != nil {
  1191. // 序列化结构体为 JSON 数据
  1192. recordListJsonBytes, tmpErr2 := json.Marshal(dataPermissionMoveRecordList)
  1193. if tmpErr2 != nil {
  1194. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;list转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  1195. return
  1196. }
  1197. // 序列化结构体为 JSON 数据
  1198. messageJsonBytes, tmpErr2 := json.Marshal(dataPermissionMessage)
  1199. if tmpErr2 != nil {
  1200. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;message转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
  1201. return
  1202. }
  1203. utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;操作记录:%s;消息记录:%s", tmpErr.Error(), string(recordListJsonBytes), string(messageJsonBytes)))
  1204. }
  1205. return
  1206. }
  1207. // GetMoveEdbChartCount 获取待转移的指标/图表列表
  1208. // @param userId 用户
  1209. // @param countType 来源 :1:设置资产权限;2:设置数据权限
  1210. func GetMoveEdbChartCount(userId, countType int) (sourceMap map[int]int, err error) {
  1211. sourceMap = make(map[int]int)
  1212. {
  1213. // 手工数据指标
  1214. var condition string
  1215. var pars []interface{}
  1216. if userId > 0 {
  1217. condition += ` AND a.user_id = ? `
  1218. pars = append(pars, userId)
  1219. }
  1220. total, tmpErr := models.GetEdbinfoListCount(condition, pars, "", 0)
  1221. if tmpErr != nil {
  1222. err = tmpErr
  1223. return
  1224. }
  1225. sourceMap[1] = total
  1226. }
  1227. {
  1228. // 上海钢联数据库
  1229. var condition string
  1230. var pars []interface{}
  1231. if userId > 0 {
  1232. condition += ` AND sys_user_id = ? `
  1233. pars = append(pars, userId)
  1234. }
  1235. total, tmpErr := data_manage.GetMysteelChemicalIndexCount(condition, pars)
  1236. if tmpErr != nil {
  1237. err = tmpErr
  1238. return
  1239. }
  1240. sourceMap[2] = total
  1241. }
  1242. {
  1243. // ETA指标库
  1244. var condition string
  1245. var pars []interface{}
  1246. if userId > 0 {
  1247. condition += ` AND sys_user_id = ? `
  1248. pars = append(pars, userId)
  1249. }
  1250. //ETA指标库
  1251. condition += ` AND edb_info_type = ? `
  1252. pars = append(pars, 0)
  1253. total, tmpErr := data_manage.GetEdbInfoByConditionCount(condition, pars)
  1254. if tmpErr != nil {
  1255. err = tmpErr
  1256. return
  1257. }
  1258. sourceMap[3] = total
  1259. }
  1260. {
  1261. // ETA预测指标库
  1262. var condition string
  1263. var pars []interface{}
  1264. if userId > 0 {
  1265. condition += ` AND sys_user_id = ? `
  1266. pars = append(pars, userId)
  1267. }
  1268. //ETA预测指标
  1269. condition += ` AND edb_info_type = ? `
  1270. pars = append(pars, 1)
  1271. total, tmpErr := data_manage.GetEdbInfoByConditionCount(condition, pars)
  1272. if tmpErr != nil {
  1273. err = tmpErr
  1274. return
  1275. }
  1276. sourceMap[4] = total
  1277. }
  1278. {
  1279. // 图库
  1280. var condition string
  1281. var pars []interface{}
  1282. if userId > 0 {
  1283. condition += ` AND sys_user_id = ? `
  1284. pars = append(pars, userId)
  1285. }
  1286. total, tmpErr := data_manage.GetChartInfoCountByCondition(condition, pars)
  1287. if tmpErr != nil {
  1288. err = tmpErr
  1289. return
  1290. }
  1291. sourceMap[5] = total
  1292. }
  1293. {
  1294. // ETA表格
  1295. var condition string
  1296. var pars []interface{}
  1297. condition += ` AND is_delete = 0 `
  1298. if userId > 0 {
  1299. condition += ` AND sys_user_id = ? `
  1300. pars = append(pars, userId)
  1301. }
  1302. switch countType {
  1303. case 2:
  1304. condition += ` AND source in (2,3) `
  1305. default:
  1306. condition += ` AND source in (2,3,4) `
  1307. }
  1308. total, tmpErr := excel.GetExcelInfoCountByCondition(condition, pars)
  1309. if tmpErr != nil {
  1310. err = tmpErr
  1311. return
  1312. }
  1313. sourceMap[6] = total
  1314. }
  1315. return
  1316. }
  1317. // afterMoveManualEdb
  1318. // @Description: 手工数据移动后的操作
  1319. // @author: Roc
  1320. // @datetime 2024-08-01 13:55:59
  1321. // @param tmpList []*models.Edbinfo
  1322. // @param adminInfo *system.Admin
  1323. // @param opUserId int
  1324. // @param opUserName string
  1325. func afterMoveManualEdb(tmpList []*models.Edbinfo, adminInfo *system.Admin, opUserId int, opUserName string) {
  1326. recordList := make([]*models.EdbinfoOpRecord, 0)
  1327. for _, tmpManualInfo := range tmpList {
  1328. remark := fmt.Sprintf("数据资产由%s转移给%s", tmpManualInfo.UserName, adminInfo.RealName)
  1329. recordList = append(recordList, &models.EdbinfoOpRecord{
  1330. TradeCode: tmpManualInfo.TradeCode,
  1331. Remark: remark,
  1332. UserId: opUserId,
  1333. UserName: opUserName,
  1334. CreateTime: time.Now(),
  1335. })
  1336. }
  1337. obj := models.EdbinfoOpRecord{}
  1338. _ = obj.MulCreate(recordList)
  1339. }
  1340. // MoveCustomAnalysisExcel2DefaultClassify 移动表格至用户未分类目录下
  1341. func MoveCustomAnalysisExcel2DefaultClassify(excelIds []int, adminId int, realName string) (err error) {
  1342. if len(excelIds) == 0 {
  1343. return
  1344. }
  1345. var moveClassifyId int
  1346. // 查询默认分类
  1347. cond := ` AND excel_classify_name = ? AND sys_user_id = ?`
  1348. pars := make([]interface{}, 0)
  1349. pars = append(pars, "未分类", adminId)
  1350. classify, e := excel.GetExcelClassifyByCondition(cond, pars)
  1351. if e != nil && e.Error() != utils.ErrNoRow() {
  1352. err = fmt.Errorf("获取默认分类失败, %v", e)
  1353. return
  1354. }
  1355. if classify != nil {
  1356. moveClassifyId = classify.ExcelClassifyId
  1357. }
  1358. // 新增一个新的分类
  1359. if classify == nil {
  1360. classifyNew := &excel.ExcelClassify{
  1361. ExcelClassifyName: "未分类",
  1362. Source: utils.CUSTOM_ANALYSIS_TABLE,
  1363. SysUserId: adminId,
  1364. SysUserRealName: realName,
  1365. Level: 1,
  1366. UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + strconv.FormatInt(time.Now().UnixNano(), 10)),
  1367. CreateTime: time.Now(),
  1368. ModifyTime: time.Now(),
  1369. }
  1370. if _, e = excel.AddExcelClassify(classifyNew); e != nil {
  1371. err = fmt.Errorf("新增默认分类失败, %v", e)
  1372. return
  1373. }
  1374. moveClassifyId = classifyNew.ExcelClassifyId
  1375. }
  1376. if moveClassifyId <= 0 {
  1377. err = fmt.Errorf("移动分类ID有误")
  1378. return
  1379. }
  1380. // 更新表格分类ID
  1381. if e = excel.UpdateExcelInfoClassifyIdByIds(moveClassifyId, excelIds); e != nil {
  1382. err = fmt.Errorf("移动多表格分类失败, %v", e)
  1383. return
  1384. }
  1385. return
  1386. }