move.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package data_manage_permission
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. )
  6. // ModifyDataUserIdByOldUserId
  7. // @Description: 根据旧用户id修改新用户id
  8. // @author: Roc
  9. // @datetime 2024-03-25 17:59:32
  10. // @param oldUserId int
  11. // @param userId int
  12. // @return err error
  13. func ModifyDataUserIdByOldUserId(oldUserIdList []int, userId int, userName string, isMoveManual, isMoveMysteelChemical, isMoveEdb, isMovePredictEdb, isMoveChart, isMoveExcel bool) (err error) {
  14. num := len(oldUserIdList)
  15. if num <= 0 {
  16. return
  17. }
  18. if userId <= 0 {
  19. return
  20. }
  21. // 手工指标库
  22. if isMoveManual {
  23. edbTo := global.DmSQL["edb"].Begin()
  24. defer func() {
  25. if err != nil {
  26. _ = edbTo.Rollback()
  27. } else {
  28. _ = edbTo.Commit()
  29. }
  30. }()
  31. sql := `UPDATE edbinfo SET user_id=? WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
  32. err = edbTo.Exec(sql, userId, oldUserIdList).Error
  33. if err != nil {
  34. return
  35. }
  36. }
  37. // ETA指标库
  38. o := global.DmSQL["data"].Begin()
  39. defer func() {
  40. if err != nil {
  41. _ = o.Rollback()
  42. } else {
  43. _ = o.Commit()
  44. }
  45. }()
  46. // 钢联化工数据库
  47. if isMoveMysteelChemical {
  48. sql := `UPDATE base_from_mysteel_chemical_index SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  49. err = o.Exec(sql, userId, userName, oldUserIdList).Error
  50. if err != nil {
  51. return
  52. }
  53. }
  54. // ETA指标库
  55. if isMoveEdb {
  56. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) and edb_info_type = ?`
  57. err = o.Exec(sql, userId, userName, oldUserIdList, 0).Error
  58. if err != nil {
  59. return
  60. }
  61. }
  62. // 预测指标
  63. if isMovePredictEdb {
  64. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) and edb_info_type = ?`
  65. err = o.Exec(sql, userId, userName, oldUserIdList, 1).Error
  66. if err != nil {
  67. return
  68. }
  69. }
  70. // ETA表格
  71. if isMoveChart {
  72. sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  73. err = o.Exec(sql, userId, userName, oldUserIdList).Error
  74. if err != nil {
  75. return
  76. }
  77. }
  78. // ETA表格
  79. if isMoveExcel {
  80. sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  81. err = o.Exec(sql, userId, userName, oldUserIdList).Error
  82. if err != nil {
  83. return
  84. }
  85. }
  86. return
  87. }