Browse Source

Merge branch 'eta/1.7.6' into debug

Roc 1 year ago
parent
commit
471c17cfa3

+ 65 - 8
controllers/data_manage/edb_info.go

@@ -3967,10 +3967,7 @@ func (this *EdbInfoController) MoveEdbChartList() {
 // MoveEdbChartUser
 // @Title 指标/图表创建人变更接口
 // @Description 指标/图表创建人变更接口
-// @Param   PageSize   query   int  true       "每页数据条数"
-// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
-// @Param   EdbInfoId   query   int  true       "指标id"
-// @Param   IsShowMe   query   bool  true       "是否只看我的,true、false"
+// @Param	request	body data_manage.MoveEdbChartReq true "type json string"
 // @Success 200 {object} data_manage.ChartListResp
 // @router /edb_chart/change_user [post]
 func (this *EdbInfoController) MoveEdbChartUser() {
@@ -4001,7 +3998,7 @@ func (this *EdbInfoController) MoveEdbChartUser() {
 		return
 	}
 
-	if len(req.DataIdList) <= 0 {
+	if !req.IsSelectAll && len(req.DataIdList) <= 0 {
 		br.Msg = "请勾选数据项"
 		br.IsSendEmail = false
 		return
@@ -4012,14 +4009,14 @@ func (this *EdbInfoController) MoveEdbChartUser() {
 		return
 	}
 
-	err, errMsg := data.MoveEdbChart(req.Source, req.NewUserId, req.DataIdList)
+	err, errMsg := data.MoveEdbChart(req.Source, req.UserId, req.NewUserId, req.IsSelectAll, req.DataIdList, req.Keyword, req.ClassifyId)
 	if err != nil {
 		//br.Success = true
-		br.Msg = "获取失败"
+		br.Msg = "移动失败"
 		if errMsg != `` {
 			br.Msg = errMsg
 		}
-		br.ErrMsg = "获取失败,Err:" + err.Error()
+		br.ErrMsg = "移动失败,Err:" + err.Error()
 		return
 	}
 	br.Ret = 200
@@ -6018,3 +6015,63 @@ func (this *EdbInfoController) SmmEdbInfoBatchAdd() {
 	br.Data = resp
 	br.IsAddLog = true
 }
+
+// MoveAllEdbChartUser
+// @Title 通过原创建人转移指标/图表创建人接口
+// @Description 通过原创建人转移指标/图表创建人接口
+// @Param	request	body data_manage.MoveAllEdbChartReq true "type json string"
+// @Success 200 {object} data_manage.ChartListResp
+// @router /edb_chart/all/change_user [post]
+func (this *EdbInfoController) MoveAllEdbChartUser() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	var req data_manage.MoveAllEdbChartReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Source <= 0 || req.Source > 5 {
+		br.Msg = "错误的来源"
+		br.IsSendEmail = false
+		return
+	}
+	if req.OldUserId <= 0 {
+		br.Msg = "请选择旧的创建人"
+		br.IsSendEmail = false
+		return
+	}
+	if req.NewUserId <= 0 {
+		br.Msg = "请选择新的创建人"
+		br.IsSendEmail = false
+		return
+	}
+
+	err, errMsg := data.MoveAllEdbChart(req.Source, req.OldUserId, req.NewUserId)
+	if err != nil {
+		//br.Success = true
+		br.Msg = "移动失败"
+		if errMsg != `` {
+			br.Msg = errMsg
+		}
+		br.ErrMsg = "移动失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.IsAddLog = true
+	br.Success = true
+	br.Msg = "移动成功"
+}

+ 15 - 0
models/data_manage/chart_info.go

@@ -1614,6 +1614,21 @@ func ModifyChartInfoUserIdByCodeList(edbIdList []string, userId int, userName st
 	return
 }
 
+// ModifyChartInfoUserIdByOldUserId
+// @Description:  根据旧的用户id修改创建人
+// @author: Roc
+// @datetime 2024-03-25 19:14:59
+// @param oldUserId int
+// @param userId int
+// @param userName string
+// @return err error
+func ModifyChartInfoUserIdByOldUserId(oldUserId, userId int, userName string) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id=? `
+	_, err = o.Raw(sql, userId, userName, oldUserId).Exec()
+	return
+}
+
 // BarChartInfoReq 柱方图预览请求数据
 type BarChartInfoReq struct {
 	EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`

+ 29 - 3
models/data_manage/edb_info.go

@@ -1570,6 +1570,21 @@ func ModifyEdbInfoUserIdByCodeList(edbIdList []string, userId int, userName stri
 	return
 }
 
+// ModifyEdbInfoUserIdByOldUserId
+// @Description:  根据旧用户id修改新用户id
+// @author: Roc
+// @datetime 2024-03-25 19:17:09
+// @param edbIdList []string
+// @param userId int
+// @param userName string
+// @return err error
+func ModifyEdbInfoUserIdByOldUserId(oldUserId, edbInfoType, userId int, userName string) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id=? and edb_info_type = ?`
+	_, err = o.Raw(sql, userId, userName, oldUserId, edbInfoType).Exec()
+	return
+}
+
 // MoveEdbChartList 图表/指标信息
 type MoveEdbChartList struct {
 	DataId         string `description:"指标/图表唯一id"`
@@ -1588,9 +1603,20 @@ type MoveEdbChartListResp struct {
 
 // MoveEdbChartReq 转移指标/图表的请求
 type MoveEdbChartReq struct {
-	Source     int      `description:"来源id"`
-	DataIdList []string `description:"指标/图表唯一id列表"`
-	NewUserId  int      `description:"新的创建人id"`
+	Source      int      `description:"来源id"`
+	DataIdList  []string `description:"指标/图表唯一id列表"`
+	NewUserId   int      `description:"新的创建人id"`
+	IsSelectAll bool     `description:"是否选择所有指标"`
+	ClassifyId  string   `description:"分类id,支持多选,用英文,隔开"`
+	Keyword     string   `description:"关键字"`
+	UserId      int      `description:"旧的创建人id"`
+}
+
+// MoveAllEdbChartReq 转移所有的指标/图表的请求
+type MoveAllEdbChartReq struct {
+	Source    int `description:"来源id"`
+	OldUserId int `description:"旧的创建人id"`
+	NewUserId int `description:"新的创建人id"`
 }
 
 type EdbChartClassifyResp struct {

+ 15 - 0
models/data_manage/mysteel_chemical_index.go

@@ -318,6 +318,21 @@ func ModifyMysteelChemicalIndexUserIdByCodeList(edbIdList []string, userId int,
 	return
 }
 
+// ModifyMysteelChemicalIndexUserIdByOldUserId
+// @Description: 根据旧用户id修改新用户id
+// @author: Roc
+// @datetime 2024-03-25 17:59:08
+// @param oldUserId int
+// @param userId int
+// @param userName string
+// @return err error
+func ModifyMysteelChemicalIndexUserIdByOldUserId(oldUserId, userId int, userName string) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `UPDATE base_from_mysteel_chemical_index SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id=?  `
+	_, err = o.Raw(sql, userId, userName, oldUserId).Exec()
+	return
+}
+
 // GetMysteelChemicalIndexAdminList 获取所有指标创建人
 func GetMysteelChemicalIndexAdminList() (list []int, err error) {
 	o := orm.NewOrmUsingDB("data")

+ 14 - 0
models/target.go

@@ -1445,6 +1445,20 @@ func ModifyEdbinfoUserIdByCodeList(edbCodeList []string, userId int) (err error)
 	return
 }
 
+// ModifyEdbinfoUserIdByOldUserId
+// @Description:  根据旧用户id修改新用户id
+// @author: Roc
+// @datetime 2024-03-25 17:59:32
+// @param oldUserId int
+// @param userId int
+// @return err error
+func ModifyEdbinfoUserIdByOldUserId(oldUserId, userId int) (err error) {
+	o := orm.NewOrmUsingDB("edb")
+	sql := `UPDATE edbinfo SET user_id=? WHERE user_id=? `
+	_, err = o.Raw(sql, userId, oldUserId).Exec()
+	return
+}
+
 func GetEdbInfoAdminList() (list []int, err error) {
 	sql := `SELECT user_id FROM edbinfo GROUP BY user_id `
 	o := orm.NewOrmUsingDB("edb")

+ 9 - 0
routers/commentsRouter.go

@@ -2815,6 +2815,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoController"],
+        beego.ControllerComments{
+            Method: "MoveAllEdbChartUser",
+            Router: `/edb_chart/all/change_user`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoController"],
         beego.ControllerComments{
             Method: "MoveEdbChartUser",

+ 79 - 7
services/data/edb_info.go

@@ -1914,11 +1914,35 @@ func GetMoveEdbChartList(source, userId int, keyword, classify string, startSize
 
 // MoveEdbChart 转移指标/图表创建人
 // @param source 来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库
-func MoveEdbChart(source, userId int, dataId []string) (err error, errMsg string) {
-	adminInfo, err := system.GetSysAdminById(userId)
+func MoveEdbChart(source, oldUserId, newUserId int, isSelectAll bool, dataId []string, keyword, classify string) (err error, errMsg string) {
+	adminInfo, err := system.GetSysAdminById(newUserId)
 	if err != nil {
 		return
 	}
+
+	// 如果勾选全部数据,那么
+	if isSelectAll {
+		// 找出不要的指标ID列表
+		dataIdMap := make(map[string]string, 0)
+		for _, v := range dataId {
+			dataIdMap[v] = v
+		}
+
+		// 需要转义的指标/图表ID列表
+		dataId = make([]string, 0)
+		// 获取所有指标/图表
+		list, _, tmpErr := GetMoveEdbChartList(source, oldUserId, keyword, classify, 0, 100000)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		for _, v := range list {
+			if _, ok := dataIdMap[v.DataId]; !ok {
+				dataId = append(dataId, v.DataId)
+			}
+		}
+	}
+
 	switch source {
 	case 1: //手工数据指标
 		tmpList, tmpErr := models.GetEdbinfoListByCodeListGroupByUserId(dataId)
@@ -1929,14 +1953,14 @@ func MoveEdbChart(source, userId int, dataId []string) (err error, errMsg string
 
 		if len(tmpList) > 0 {
 			for _, v := range tmpList {
-				if v.UserId == userId {
+				if v.UserId == newUserId {
 					errMsg = "新创建人不可和原创建人一致"
 					err = errors.New(errMsg)
 					return
 				}
 			}
 			// 修改创建人
-			err = models.ModifyEdbinfoUserIdByCodeList(dataId, userId)
+			err = models.ModifyEdbinfoUserIdByCodeList(dataId, newUserId)
 		}
 
 	case 2: //钢联化工数据库
@@ -1947,7 +1971,7 @@ func MoveEdbChart(source, userId int, dataId []string) (err error, errMsg string
 		}
 		if len(tmpList) > 0 {
 			for _, v := range tmpList {
-				if v.SysUserId == userId {
+				if v.SysUserId == newUserId {
 					errMsg = "新创建人不可和原创建人一致"
 					err = errors.New(errMsg)
 					return
@@ -1964,7 +1988,7 @@ func MoveEdbChart(source, userId int, dataId []string) (err error, errMsg string
 		}
 		if len(tmpList) > 0 {
 			for _, v := range tmpList {
-				if v.SysUserId == userId {
+				if v.SysUserId == newUserId {
 					errMsg = "新创建人不可和原创建人一致"
 					err = errors.New(errMsg)
 					return
@@ -1990,7 +2014,7 @@ func MoveEdbChart(source, userId int, dataId []string) (err error, errMsg string
 		}
 		if len(tmpList) > 0 {
 			for _, v := range tmpList {
-				if v.SysUserId == userId {
+				if v.SysUserId == newUserId {
 					errMsg = "新创建人不可和原创建人一致"
 					err = errors.New(errMsg)
 					return
@@ -3257,3 +3281,51 @@ func EdbInfoSmmApiAdd(item *data_manage.EdbInfo) (edbInfo *data_manage.EdbInfo,
 	AddOrEditEdbInfoToEs(int(edbInfoId))
 	return
 }
+
+// MoveAllEdbChart 通过原创建人转移指标/图表创建人
+// @param source 来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库
+func MoveAllEdbChart(source, oldUserId, userId int) (err error, errMsg string) {
+	adminInfo, err := system.GetSysAdminById(userId)
+	if err != nil {
+		return
+	}
+
+	switch source {
+	case 1: //手工数据指标
+		// 修改创建人
+		err = models.ModifyEdbinfoUserIdByOldUserId(oldUserId, userId)
+
+	case 2: //钢联化工数据库
+		// 修改创建人
+		err = data_manage.ModifyMysteelChemicalIndexUserIdByOldUserId(oldUserId, adminInfo.AdminId, adminInfo.RealName)
+	case 3: //ETA指标库
+		// 修改创建人
+		err = data_manage.ModifyEdbInfoUserIdByOldUserId(oldUserId, 0, adminInfo.AdminId, adminInfo.RealName)
+		// 移除当前用户的不可操作权限
+		//{
+		//	obj := data_manage.EdbInfoNoPermissionAdmin{}
+		//	for _, v := range dataId {
+		//		edbInfoId, _ := strconv.Atoi(v)
+		//		go obj.DeleteByEdbInfoIdAndAdminId(edbInfoId, adminInfo.AdminId)
+		//	}
+		//}
+	case 4: //ETA预测指标
+		// 修改创建人
+		err = data_manage.ModifyEdbInfoUserIdByOldUserId(oldUserId, 1, adminInfo.AdminId, adminInfo.RealName)
+		// 移除当前用户的不可操作权限
+		//{
+		//	obj := data_manage.EdbInfoNoPermissionAdmin{}
+		//	for _, v := range dataId {
+		//		edbInfoId, _ := strconv.Atoi(v)
+		//		go obj.DeleteByEdbInfoIdAndAdminId(edbInfoId, adminInfo.AdminId)
+		//	}
+		//}
+	case 5: //图库
+		// 修改创建人
+		err = data_manage.ModifyChartInfoUserIdByOldUserId(oldUserId, adminInfo.AdminId, adminInfo.RealName)
+	default:
+		return
+	}
+
+	return
+}