move.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package data_manage_permission
  2. import (
  3. "eta/eta_mobile/utils"
  4. "github.com/beego/beego/v2/client/orm"
  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, tmpErr := orm.NewOrmUsingDB("edb").Begin()
  24. if tmpErr != nil {
  25. return
  26. }
  27. defer func() {
  28. if err != nil {
  29. _ = edbTo.Rollback()
  30. } else {
  31. _ = edbTo.Commit()
  32. }
  33. }()
  34. sql := `UPDATE edbinfo SET user_id=? WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
  35. _, err = edbTo.Raw(sql, userId, oldUserIdList).Exec()
  36. if err != nil {
  37. return
  38. }
  39. }
  40. // ETA指标库
  41. o, err := orm.NewOrmUsingDB("data").Begin()
  42. if err != nil {
  43. return
  44. }
  45. defer func() {
  46. if err != nil {
  47. _ = o.Rollback()
  48. } else {
  49. _ = o.Commit()
  50. }
  51. }()
  52. // 上海钢联数据库
  53. if isMoveMysteelChemical {
  54. sql := `UPDATE base_from_mysteel_chemical_index SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  55. _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
  56. if err != nil {
  57. return
  58. }
  59. }
  60. // ETA指标库
  61. if isMoveEdb {
  62. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) and edb_info_type = ?`
  63. _, err = o.Raw(sql, userId, userName, oldUserIdList, 0).Exec()
  64. if err != nil {
  65. return
  66. }
  67. }
  68. // 预测指标
  69. if isMovePredictEdb {
  70. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) and edb_info_type = ?`
  71. _, err = o.Raw(sql, userId, userName, oldUserIdList, 1).Exec()
  72. if err != nil {
  73. return
  74. }
  75. }
  76. // ETA表格
  77. if isMoveChart {
  78. sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  79. _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
  80. if err != nil {
  81. return
  82. }
  83. }
  84. // ETA表格
  85. if isMoveExcel {
  86. sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  87. _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
  88. if err != nil {
  89. return
  90. }
  91. }
  92. return
  93. }