瀏覽代碼

Merge branch 'dev/v1.1.36_fuwencai' of https://jygit.jydev.jianyu360.cn/BaseService/jyMicroservices into dev/v1.1.36_fuwencai

fuwencai 1 年之前
父節點
當前提交
953f60d60c
共有 2 個文件被更改,包括 131 次插入62 次删除
  1. 20 15
      jyBXCore/rpc/model/mysql/participateBid.go
  2. 111 47
      jyBXCore/rpc/model/mysql/participateStage.go

+ 20 - 15
jyBXCore/rpc/model/mysql/participateBid.go

@@ -54,13 +54,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                                      = ",保留原参标人"
-			fromEntUserNames, toEntUserNames, toEntUserIds []string
-			ids                                            []int
+			b1                                                             = true
+			b2, b3                                                         bool
+			now                                                            = time.Now()
+			content                                                        = "从%s名下划转给%s%s"
+			lastNotes                                                      = ",保留原参标人"
+			fromEntUserNames, fromEntUserIds, 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 {
@@ -73,6 +73,7 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 				userInfo := IC.Middleground.UserCenter.IdentityByPositionId(positionId)
 				if userInfo.EntUserName != "" {
 					fromEntUserNames = append(fromEntUserNames, userInfo.EntUserName)
+					fromEntUserIds = append(fromEntUserIds, strconv.FormatInt(userInfo.EntUserId, 10))
 				}
 			}
 		}
@@ -93,6 +94,9 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 				"mark":        -2, //0:参标;1:被划入;-1:终止参标;-2:被划走
 				"update_date": date.FormatDate(&now, date.Date_Full_Layout),
 			})
+		} else {
+			//划转参标项目,如果不保留原参标人,原参标人 更新参标记录表
+			fromEntUserIds = []string{}
 		}
 		//移动端 划转对象是多选
 		//划转对象entuserid 解密
@@ -148,14 +152,15 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 		//个人版 根据职位id 和项目id查询划转记录
 		//划转记录
 		b2 = IC.BaseMysql.InsertByTx(tx, ParticipateBidRecordsTable, map[string]interface{}{
-			"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),
+			"ent_id":                in.EntId,
+			"ent_user_id":           in.EntUserId,
+			"position_id":           in.PositionId,
+			"project_id":            projectId,
+			"record_type":           0,
+			"transfer_from_user_id": strings.Join(fromEntUserIds, ","),
+			"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
 		log.Println(b1, "--", b2, "--", b3)
 		return b1 && b2 && b3

+ 111 - 47
jyBXCore/rpc/model/mysql/participateStage.go

@@ -1,12 +1,15 @@
 package mysql
 
 import (
+	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
 	"encoding/json"
 	"fmt"
 	"github.com/gogf/gf/v2/util/gconv"
 	IC "jyBXCore/rpc/init"
 	"jyBXCore/rpc/util"
+	"log"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -16,75 +19,128 @@ type ParStage struct {
 	EntUserId  int64
 	PositionId int64
 	ProjectId  string
-	Stage      string //参标、终止参标(划转没有记录)
 }
 
-func NewParStage(entId int64, projectId, stage string) *ParStage {
+func NewParStage(entId, entUserId, positionId int64, projectId string) *ParStage {
 	return &ParStage{
-		EntId:     entId,
-		ProjectId: projectId,
-		Stage:     stage,
+		EntId:      entId,
+		EntUserId:  entUserId,
+		PositionId: positionId,
+		ProjectId:  projectId,
 	}
 }
 
+type StageInfo struct {
+	Value string
+	Date  string
+}
+
 func (p *ParStage) UpdateStage() {
 	var (
-		recordsMap      = map[string]string{}
+		recordsMap      = map[string]*StageInfo{}
 		updateInsertMap = map[string]interface{}{
 			"ent_id":     p.EntId,
 			"project_id": p.ProjectId,
 		}
-		now        = time.Now()
-		createDate string
+		now                     = time.Now()
+		createDate              string
+		entUserIdBool           = map[string]bool{}
+		positionIdBool          = map[string]bool{}
+		entUserIds, positionIds []string
+		findSql                 = map[string]interface{}{
+			"project_id": p.ProjectId,
+			"ent_id":     p.EntId,
+		}
+		state         = "已完成"
+		isParticipate bool
 	)
-	if p.Stage == "参标" {
-		recordsMap["参标"] = date.FormatDate(&now, date.Date_Full_Layout)
-	} else {
-		recordsContentData := IC.BaseMysql.SelectBySql(`SELECT * FROM  participate_bid_records WHERE  position_id =? and project_id =?  order by  create_date `, p.PositionId, p.ProjectId)
-		if recordsContentData != nil && len(*recordsContentData) > 0 {
-			for _, rv := range *recordsContentData {
-				var (
-					recordContent = gconv.String(rv["record_content"])
-					content, ok   = util.ConvertJSONString(recordContent)
-					contentMap    = map[string]interface{}{}
-					contentStr    string
-				)
-				createDate = gconv.String(rv["create_date"])
-				if ok {
-					contentMap = gconv.Map(content)
-				} else {
-					contentStr = gconv.String(content)
-				}
-				if strings.TrimSpace(contentStr) == "参标" || strings.Contains(contentStr, "终止参标") {
-					recordsMap[contentStr] = createDate
-				}
+	//个人版
+	if p.EntId == 0 {
+		findSql["position_id"] = p.PositionId
+	}
+	recordsContentData := IC.BaseMysql.Find(ParticipateBidRecordsTable, findSql, "", "create_date", -1, -1)
+	//判断 当前企业或用户是否已参标
+	findSql["state"] = 0
+	if count := IC.BaseMysql.Count("participate_user", findSql); count > 0 {
+		isParticipate = true
+	}
+	if recordsContentData != nil && len(*recordsContentData) > 0 {
+		for _, rv := range *recordsContentData {
+			var (
+				recordContent = gconv.String(rv["record_content"])
+				content, ok   = util.ConvertJSONString(recordContent)
+				contentMap    = map[string]interface{}{}
+				contentStr    string
+				entUserId     = strconv.FormatInt(gconv.Int64(rv["ent_user_id"]), 10)
+				positionId    = strconv.FormatInt(gconv.Int64(rv["position_id"]), 10)
+			)
+			createDate = gconv.String(rv["create_date"])
+			if ok {
+				contentMap = gconv.Map(content)
 				if contentMap["afterMap"] != nil {
-					after, _ := util.ConvertJSONString(gconv.String(contentMap["afterMap"]))
-					afterM := gconv.Map(after)
+					afterMap, _ := util.ConvertJSONString(gconv.String(contentMap["afterMap"]))
+					afterM := gconv.Map(afterMap)
 					if afterM != nil {
 						if bidStage := gconv.Map(afterM["bidStage"]); bidStage != nil {
 							status := gconv.String(bidStage["status"])
 							values := gconv.SliceStr(bidStage["value"])
 							if len(values) > 0 {
 								for _, bv := range values {
-									if status == "调整" || recordsMap[bv] == "" {
-										recordsMap[bv] = createDate
+									if status == "调整" || recordsMap[fmt.Sprintf("%s(阶段)", bv)].Date == "" {
+										recordsMap[fmt.Sprintf("%s(阶段)", bv)] = &StageInfo{
+											Value: state,
+											Date:  createDate,
+										}
 									}
 								}
 							}
 						}
 						if bidType := gconv.Map(afterM["bidType"]); bidType != nil {
-							values := gconv.String(bidType["value"])
-							if values != "" {
-								recordsMap[values] = createDate
+							value := gconv.String(bidType["value"])
+							if value != "" {
+								recordsMap["投标类型"] = &StageInfo{
+									Value: value,
+									Date:  createDate,
+								}
 							}
 						}
 					}
 				}
-				if p.Stage == "终止参标" {
-					recordsMap["终止参标"] = date.FormatDate(&now, date.Date_Full_Layout)
+				afterMap, _ := util.ConvertJSONString(gconv.String(contentMap["after"]))
+				afterM := gconv.Map(afterMap)
+				if afterM != nil {
+					updateInsertMap["bid_way"] = gconv.Int64(afterM["bidType"])
+				}
+			} else {
+				contentStr = gconv.String(content)
+				//参标:多人参标同一个项目,查看当前项目是否已被当前企业其他员工参标,如果已被其他员工参标,则参标时间不更新。
+				//参标后 未被 终止参标
+				if strings.TrimSpace(contentStr) == "参标" {
+					recordsMap["参标状态"] = &StageInfo{
+						Value: "已参标",
+						Date:  createDate,
+					}
+				}
+				//终止参标--
+				if strings.Contains(contentStr, "终止参标") {
+					if !isParticipate {
+						recordsMap[contentStr] = &StageInfo{
+							Value: "已终止",
+							Date:  createDate,
+						}
+					}
 				}
 			}
+			//entUserIds 操作和被操作企业用户id集合 408
+			if !entUserIdBool[entUserId] {
+				entUserIdBool[entUserId] = true
+				entUserIds = append(entUserIds, entUserId)
+			}
+			//职位id
+			if !positionIdBool[positionId] {
+				positionIdBool[positionId] = true
+				positionIds = append(positionIds, positionId)
+			}
 		}
 	}
 	if recordsMap != nil {
@@ -95,19 +151,27 @@ func (p *ParStage) UpdateStage() {
 			return
 		}
 		updateInsertMap["stage"] = string(jsonData)
-		if c := IC.BaseMysql.Count(ParticipateStage, map[string]interface{}{
-			"ent_id":     p.EntId,
-			"project_id": p.ProjectId,
-		}); c > 0 {
+		updateInsertMap["ent_user_ids"] = strings.Join(entUserIds, ",")
+		updateInsertMap["is_participate"] = common.If(isParticipate, 1, 0).(int)
+		updateInsertMap["position_ids"] = strings.Join(positionIds, ",")
+		updateSelectSlq := fmt.Sprintf(`SELECT * FROM %s WHERE ent_id = ? and project_id = ? `, ParticipateStage)
+		if p.EntId == 0 {
+			add := fmt.Sprintf(" and  FIND_IN_SET('%s', position_ids) > 0", strconv.FormatInt(p.PositionId, 10))
+			updateSelectSlq = fmt.Sprintf("%s%s", updateSelectSlq, add)
+		}
+		if s := IC.BaseMysql.SelectBySql(updateSelectSlq, p.EntId, p.ProjectId); len(*s) > 0 {
 			updateInsertMap["update_date"] = createDate
-			IC.BaseMysql.UpdateOrDeleteBySql(ParticipateStage, map[string]interface{}{
-				"ent_id":     p.EntId,
-				"project_id": p.ProjectId,
-			}, updateInsertMap)
+			if ok := IC.BaseMysql.Update(ParticipateStage, map[string]interface{}{
+				"id": gconv.Int64((*s)[0]["id"]),
+			}, updateInsertMap); !ok {
+				log.Println("参标操作记录 更新异常:", gconv.Int64((*s)[0]["id"]))
+			}
 		} else {
 			updateInsertMap["create_date"] = date.FormatDate(&now, date.Date_Full_Layout)
 			updateInsertMap["update_date"] = createDate
-			IC.BaseMysql.Insert(ParticipateStage, updateInsertMap)
+			if i := IC.BaseMysql.Insert(ParticipateStage, updateInsertMap); i == 0 {
+				log.Println("参标操作记录 插入异常:", updateInsertMap)
+			}
 		}
 	}
 }