Browse Source

feat:一个项目针对多个用户划转

wangshan 2 years ago
parent
commit
76f8e94e28
2 changed files with 63 additions and 55 deletions
  1. 62 48
      jyBXCore/rpc/model/mysql/participateBid.go
  2. 1 7
      jyBXCore/rpc/service/participate.go

+ 62 - 48
jyBXCore/rpc/model/mysql/participateBid.go

@@ -49,13 +49,13 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 	//保存或更新新跟踪人
 	if !IC.BaseMysql.ExecTx("划转参标信息", func(tx *sql.Tx) bool {
 		var (
-			b1            = true
-			b2, b3        bool
-			now           = time.Now()
-			content       = "%s划转给%s%s"
-			lastNotes     = ",保留原参标人"
-			fromUserNames []string
-			ids           []int
+			b1                                             = true
+			b2, b3                                         bool
+			now                                            = time.Now()
+			content                                        = "%s划转给%s%s"
+			lastNotes                                      = ",保留原参标人"
+			fromEntUserNames, toEntUserNames, toEntUserIds []string
+			ids                                            []int
 		)
 		partInfo := IC.BaseMysql.SelectBySqlByTx(tx, "SELECT id,position_id FROM "+ParticipateUserTable+" WHERE  project_id = ?  AND ent_id = ? AND state > -1", projectId, in.EntId)
 		if partInfo == nil || len(*partInfo) == 0 {
@@ -67,11 +67,11 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 				positionId := MC.Int64All(v["position_id"])
 				userInfo := IC.Middleground.UserCenter.IdentityByPositionId(positionId)
 				if userInfo.EntUserName != "" {
-					fromUserNames = append(fromUserNames, userInfo.EntUserName)
+					fromEntUserNames = append(fromEntUserNames, userInfo.EntUserName)
 				}
 			}
 		}
-		if len(fromUserNames) == 0 {
+		if len(fromEntUserNames) == 0 {
 			logx.Info("原参标人信息查询有误")
 			return false
 		}
@@ -89,48 +89,62 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 				"update_date": date.FormatDate(&now, date.Date_Full_Layout),
 			})
 		}
-		//查询划转人信息
-		entUserId, _ := strconv.ParseInt(in.ToEntUserId, 10, 64)
-		userInfo := IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
-		positionId := userInfo.PositionId
-		content = fmt.Sprintf(content, strings.Join(fromUserNames, ","), userInfo.EntUserName, lastNotes)
+		//移动端 划转对象是多选
+		//划转对象entuserid 解密
+		for _, toEntUserId := range strings.Split(in.ToEntUserId, ",") {
+			toEntUserId = encrypt.SE.Decode4HexByCheck(toEntUserId)
+			if toEntUserId == "" {
+				logx.Info("划转对象不能为空", in.ProjectIds, in.EntId)
+				continue
+			}
+			//查询划转人信息
+			entUserId, _ := strconv.ParseInt(toEntUserId, 10, 64)
+			userInfo := IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
+			positionId := userInfo.PositionId
+			//保存参标--participate_user
+			//查看是否参标过当前项目
+			if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM "+ParticipateUserTable+" WHERE position_id = ? AND project_id = ?  AND ent_id = ?", positionId, projectId, in.EntId); c > 0 {
+				//更新
+				b3 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, map[string]interface{}{
+					"position_id": positionId,
+					"project_id":  projectId,
+					"ent_id":      in.EntId,
+				}, map[string]interface{}{
+					"state":       0,
+					"mark":        1, //0:参标;1:被划入;-1:终止参标;-2:被划走
+					"update_date": date.FormatDate(&now, date.Date_Full_Layout),
+				})
+			} else {
+				//保存
+				b3 = IC.BaseMysql.InsertByTx(tx, ParticipateUserTable, map[string]interface{}{
+					"ent_id":      in.EntId,
+					"ent_user_id": entUserId,
+					"position_id": positionId,
+					"project_id":  projectId,
+					"user_id":     in.MgoUserId,
+					"state":       0,
+					"mark":        1, //0:参标;1:被划入;-1:终止参标;-2:被划走
+					"create_date": date.FormatDate(&now, date.Date_Full_Layout),
+					"update_date": date.FormatDate(&now, date.Date_Full_Layout),
+				}) > 0
+			}
+			if b3 {
+				toEntUserIds = append(toEntUserIds, toEntUserId)
+				toEntUserNames = append(toEntUserNames, userInfo.EntUserName)
+			}
+		}
 		//划转记录
 		b2 = IC.BaseMysql.InsertByTx(tx, ParticipateBidRecordsTable, map[string]interface{}{
-			"ent_id":         in.EntId,
-			"ent_user_id":    entUserId,
-			"position_id":    positionId,
-			"project_id":     projectId,
-			"record_type":    0,
-			"record_content": content,
-			"create_date":    date.FormatDate(&now, date.Date_Full_Layout),
+			"ent_id":               in.EntId,
+			"ent_user_id":          in.EntUserId,
+			"position_id":          in.PositionId,
+			"project_id":           projectId,
+			"record_type":          0,
+			"transfer_ent_user_id": strings.Join(toEntUserIds, ","),
+			"record_content":       fmt.Sprintf(content, strings.Join(fromEntUserNames, "、"), strings.Join(toEntUserNames, "、"), lastNotes),
+			"create_date":          date.FormatDate(&now, date.Date_Full_Layout),
 		}) > 0
-		//保存参标--participate_user
-		//查看是否参标过当前项目
-		if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM "+ParticipateUserTable+" WHERE position_id = ? AND project_id = ?  AND ent_id = ?", positionId, projectId, in.EntId); c > 0 {
-			//更新
-			b3 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, map[string]interface{}{
-				"position_id": positionId,
-				"project_id":  projectId,
-				"ent_id":      in.EntId,
-			}, map[string]interface{}{
-				"state":       0,
-				"mark":        1, //0:参标;1:被划入;-1:终止参标;-2:被划走
-				"update_date": date.FormatDate(&now, date.Date_Full_Layout),
-			})
-		} else {
-			//保存
-			b3 = IC.BaseMysql.InsertByTx(tx, ParticipateUserTable, map[string]interface{}{
-				"ent_id":      in.EntId,
-				"ent_user_id": entUserId,
-				"position_id": positionId,
-				"project_id":  projectId,
-				"user_id":     in.MgoUserId,
-				"state":       0,
-				"mark":        1, //0:参标;1:被划入;-1:终止参标;-2:被划走
-				"create_date": date.FormatDate(&now, date.Date_Full_Layout),
-				"update_date": date.FormatDate(&now, date.Date_Full_Layout),
-			}) > 0
-		}
+
 		return b1 && b2 && b3
 	}) {
 		logx.Info(in.PositionId, "---终止---", projectId)

+ 1 - 7
jyBXCore/rpc/service/participate.go

@@ -112,15 +112,9 @@ func ParticipateDo(in *bxcore.ParticipateActionReq) error {
 		if in.ToEntUserId == "" {
 			return fmt.Errorf("划转对象不能为空")
 		}
-		//移动端 划转对象是多选
-		//划转对象entuserid 解密
-		in.ToEntUserId = encrypt.SE.Decode4HexByCheck(in.ToEntUserId)
-		if in.ToEntUserId == "" {
-			return fmt.Errorf("划转对象不能为空")
-		}
 		//是否保留原跟踪人?
 		isAllow := util.IsALLow(in.EntId)
-		if in.IsRetain && !isAllow {
+		if (in.IsRetain || len(strings.Split(in.ToEntUserId, ",")) > 1) && !isAllow {
 			//不允许多人参标,但是前端参数又是保留原参标人 互相矛盾
 			return fmt.Errorf("当前项目只允许一人参标")
 		}