12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package data_manage_permission
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- )
- // ModifyDataUserIdByOldUserId
- // @Description: 根据旧用户id修改新用户id
- // @author: Roc
- // @datetime 2024-03-25 17:59:32
- // @param oldUserId int
- // @param userId int
- // @return err error
- func ModifyDataUserIdByOldUserId(oldUserIdList []int, userId int, userName string, isMoveManual, isMoveMysteelChemical, isMoveEdb, isMovePredictEdb, isMoveChart, isMoveExcel bool) (err error) {
- num := len(oldUserIdList)
- if num <= 0 {
- return
- }
- if userId <= 0 {
- return
- }
- // 手工指标库
- if isMoveManual {
- edbTo := global.DmSQL["edb"].Begin()
- defer func() {
- if err != nil {
- _ = edbTo.Rollback()
- } else {
- _ = edbTo.Commit()
- }
- }()
- sql := `UPDATE edbinfo SET user_id=? WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
- err = edbTo.Exec(sql, userId, oldUserIdList).Error
- if err != nil {
- return
- }
- }
- // ETA指标库
- o := global.DmSQL["data"].Begin()
- defer func() {
- if err != nil {
- _ = o.Rollback()
- } else {
- _ = o.Commit()
- }
- }()
- // 钢联化工数据库
- if isMoveMysteelChemical {
- sql := `UPDATE base_from_mysteel_chemical_index SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
- err = o.Exec(sql, userId, userName, oldUserIdList).Error
- if err != nil {
- return
- }
- }
- // ETA指标库
- if isMoveEdb {
- sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) and edb_info_type = ?`
- err = o.Exec(sql, userId, userName, oldUserIdList, 0).Error
- if err != nil {
- return
- }
- }
- // 预测指标
- if isMovePredictEdb {
- sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) and edb_info_type = ?`
- err = o.Exec(sql, userId, userName, oldUserIdList, 1).Error
- if err != nil {
- return
- }
- }
- // ETA表格
- if isMoveChart {
- sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
- err = o.Exec(sql, userId, userName, oldUserIdList).Error
- if err != nil {
- return
- }
- }
- // ETA表格
- if isMoveExcel {
- sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
- err = o.Exec(sql, userId, userName, oldUserIdList).Error
- if err != nil {
- return
- }
- }
- return
- }
|