wangshan 2 роки тому
батько
коміт
ae707c02e7
1 змінених файлів з 67 додано та 22 видалено
  1. 67 22
      jyBXCore/rpc/model/mysql/participateBid.go

+ 67 - 22
jyBXCore/rpc/model/mysql/participateBid.go

@@ -11,11 +11,31 @@ import (
 	IC "jyBXCore/rpc/init"
 	"jyBXCore/rpc/model/es"
 	"jyBXCore/rpc/type/bxcore"
+	"log"
 	"strconv"
 	"strings"
 	"time"
 )
 
+//投标状态更新内容
+type PartStatusContent struct {
+	BidStage      []string `json:"bidStage"`      //投标项目阶段
+	BidType       int64    `json:"bidType"`       //投标类型
+	ChannelName   string   `json:"channelName"`   //渠道名称
+	ChannelPerson string   `json:"channelPerson"` //联系人
+	ChannelPhone  string   `json:"channelPhone"`  //联系电话
+	IsWin         int64    `json:"isWin"`         //渠道是否中标
+	Winner        string   `json:"winner"`        //中标单位
+}
+
+//参标
+type RecordsContent struct {
+	After       PartStatusContent `json:"after"`       //更新前
+	Before      PartStatusContent `json:"before"`      //更新后
+	ChangeField []string          `json:"changeField"` //更新字段
+	Content     string            `json:"content"`     //更新内容
+}
+
 var (
 	PartTable                  = "participate"
 	ParticipateBidRecordsTable = "participate_bid_records"
@@ -36,7 +56,7 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 			fromUserNames []string
 			ids           []int
 		)
-		partInfo := IC.BaseMysql.SelectBySqlByTx(tx, "SELECT id,position_id FROM `participate_user` WHERE  project_id = ?  AND ent_id = ? AND state > -1", projectId, in.EntId)
+		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 {
 			logx.Info("当前项目不满足划转条件")
 			return false
@@ -59,7 +79,7 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 			lastNotes = ""
 			//不保留 原参标人,获取把原参标人信息
 			//当前项目有参标人 更新参标人状态
-			b1 = IC.BaseMysql.UpdateByTx(tx, "participate_user", map[string]interface{}{
+			b1 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, map[string]interface{}{
 				"ent_id":     in.EntId,
 				"project_id": projectId,
 			}, map[string]interface{}{
@@ -74,19 +94,20 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 		positionId := userInfo.PositionId
 		content = fmt.Sprintf(content, strings.Join(fromUserNames, ","), userInfo.EntUserName, lastNotes)
 		//划转记录
-		b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
+		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),
 		}) > 0
 		//保存参标--participate_user
 		//查看是否参标过当前项目
-		if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM `participate_user` WHERE position_id = ? AND project_id = ?  AND ent_id = ?", positionId, projectId, in.EntId); c > 0 {
+		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, "participate_user", map[string]interface{}{
+			b3 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, map[string]interface{}{
 				"position_id": positionId,
 				"project_id":  projectId,
 				"ent_id":      in.EntId,
@@ -97,7 +118,7 @@ func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq)
 			})
 		} else {
 			//保存
-			b3 = IC.BaseMysql.InsertByTx(tx, "participate_user", map[string]interface{}{
+			b3 = IC.BaseMysql.InsertByTx(tx, ParticipateUserTable, map[string]interface{}{
 				"ent_id":      in.EntId,
 				"ent_user_id": entUserId,
 				"position_id": positionId,
@@ -141,13 +162,14 @@ func CancelParticipateInfo(in *bxcore.ParticipateActionReq, roleId int64) error
 			"update_date": date.FormatDate(&now, date.Date_Full_Layout),
 		}
 		//更新参标participate_user
-		b1 = IC.BaseMysql.UpdateByTx(tx, "participate_user", query, insert)
+		b1 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, query, insert)
 		//保存参标记录--participate_bid_records
-		b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
+		b2 = IC.BaseMysql.InsertByTx(tx, ParticipateBidRecordsTable, map[string]interface{}{
 			"ent_id":         in.EntId,
 			"ent_user_id":    in.EntUserId,
 			"position_id":    in.PositionId,
 			"project_id":     in.ProjectIds,
+			"record_type":    0,
 			"record_content": tip,
 			"create_date":    date.FormatDate(&now, date.Date_Full_Layout),
 		}) > 0
@@ -169,9 +191,9 @@ func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
 		)
 		//保存参标--participate_user
 		//查看是否参标过当前项目
-		if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM `participate_user` WHERE position_id = ? AND project_id = ?  AND ent_id = ?", in.PositionId, in.ProjectIds, in.EntId); c > 0 {
+		if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM "+ParticipateUserTable+" WHERE position_id = ? AND project_id = ?  AND ent_id = ?", in.PositionId, in.ProjectIds, in.EntId); c > 0 {
 			//更新
-			b1 = IC.BaseMysql.UpdateByTx(tx, "participate_user", map[string]interface{}{
+			b1 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, map[string]interface{}{
 				"state":       0,
 				"mark":        0,
 				"update_date": date.FormatDate(&now, date.Date_Full_Layout),
@@ -182,7 +204,7 @@ func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
 			})
 		} else {
 			//保存
-			b1 = IC.BaseMysql.InsertByTx(tx, "participate_user", map[string]interface{}{
+			b1 = IC.BaseMysql.InsertByTx(tx, ParticipateUserTable, map[string]interface{}{
 				"ent_id":      in.EntId,
 				"ent_user_id": in.EntUserId,
 				"position_id": in.PositionId,
@@ -197,11 +219,12 @@ func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
 			return false
 		}
 		//保存参标记录participate_bid_records
-		b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
+		b2 = IC.BaseMysql.InsertByTx(tx, ParticipateBidRecordsTable, map[string]interface{}{
 			"ent_id":         in.EntId,
 			"ent_user_id":    in.EntUserId,
 			"position_id":    in.PositionId,
 			"project_id":     in.ProjectIds,
+			"record_type":    0,
 			"record_content": "参标",
 			"create_date":    date.FormatDate(&now, date.Date_Full_Layout),
 		}) > 0
@@ -223,7 +246,7 @@ func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
 func IsParticipatedByBidId(in *bxcore.ParticipateActionReq) bool {
 	defer MC.Catch()
 	//如果不允许多人参标 当前项目是否已经有企业其他人员参标
-	query := fmt.Sprintf(`SELECT count(id) FROM participate_user WHERE %s AND project_id = %s AND state >-1`, "%s", in.BidIds)
+	query := fmt.Sprintf(`SELECT count(id) FROM `+ParticipateUserTable+` WHERE %s AND project_id = %s AND state >-1`, "%s", in.BidIds)
 	if in.PositionType > 0 { //企业版
 		query = fmt.Sprintf(query, fmt.Sprintf("ent_id = %d", in.EntId))
 	} else { //个人版
@@ -505,7 +528,7 @@ func SingleParticipateList(in *bxcore.ParticipateListReq, otherSql string) (data
 		List:  []*bxcore.ParticipateList{},
 	}
 	//员工|个人列表
-	singlePersonSql := `SELECT %s FROM participate_user pug LEFT JOIN project pt ON pug.project_id = pt.id WHERE pug.position_id = ? `
+	singlePersonSql := `SELECT %s FROM ` + ParticipateUserTable + ` pug LEFT JOIN project pt ON pug.project_id = pt.id WHERE pug.position_id = ? `
 	singlePersonSql += otherSql
 	countSql := fmt.Sprintf(singlePersonSql, " COUNT(pt.id) ")
 	count := IC.BaseMysql.CountBySql(countSql, in.PositionId)
@@ -526,7 +549,7 @@ func SingleParticipateList(in *bxcore.ParticipateListReq, otherSql string) (data
 					BidEndTime:       MC.ObjToString(v["bid_end_time"]),
 					BidOpenTime:      MC.ObjToString(v["bid_open_time"]),
 					UpdateStatusTime: MC.ObjToString(v["update_date"]),
-					UpdateStatusCon:  GetParticipateContent(in.PositionId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新,
+					UpdateStatusCon:  GetParticipateContent("s", in.PositionId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新,
 				})
 			}
 			return data, nil
@@ -543,7 +566,7 @@ func AdminParticipateList(in *bxcore.ParticipateListReq, otherSql string) (data
 		Count: 0,
 		List:  []*bxcore.ParticipateList{},
 	}
-	adminSql := `SELECT %s FROM (SELECT pu.ent_id, pu.project_id, GROUP_CONCAT(pu.ent_user_id SEPARATOR ',') ent_user_id, MAX(pu.update_date) update_date FROM participate_user pu WHERE pu.ent_id = ? AND NOT EXISTS ( SELECT 1 FROM participate_user WHERE project_id = pu.project_id AND state > pu. state ) GROUP BY pu.project_id ) pug LEFT JOIN project pt ON pug.project_id = pt.id`
+	adminSql := `SELECT %s FROM (SELECT pu.ent_id, pu.project_id, GROUP_CONCAT(pu.ent_user_id SEPARATOR ',') ent_user_id, MAX(pu.update_date) update_date FROM ` + ParticipateUserTable + ` pu WHERE pu.ent_id = ? AND NOT EXISTS ( SELECT 1 FROM ` + ParticipateUserTable + ` WHERE project_id = pu.project_id AND state > pu. state ) GROUP BY pu.project_id ) pug LEFT JOIN project pt ON pug.project_id = pt.id`
 	adminSql += otherSql
 	adminCountSql := fmt.Sprintf(adminSql, "COUNT(pt.id)")
 	count := IC.BaseMysql.CountBySql(adminCountSql, in.EntId)
@@ -562,8 +585,8 @@ func AdminParticipateList(in *bxcore.ParticipateListReq, otherSql string) (data
 					BidEndTime:       MC.ObjToString(v["bid_end_time"]),
 					BidOpenTime:      MC.ObjToString(v["bid_open_time"]),
 					UpdateStatusTime: MC.ObjToString(v["update_date"]),
-					UpdateStatusCon:  GetParticipateContent(in.EntId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新
-					Participants:     GetParticipateUserName(MC.ObjToString(v["ent_user_id"])), //参标人信息
+					UpdateStatusCon:  GetParticipateContent("e", in.EntId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新
+					Participants:     GetParticipateUserName(MC.ObjToString(v["ent_user_id"])),      //参标人信息
 				})
 			}
 			return data, nil
@@ -574,12 +597,34 @@ func AdminParticipateList(in *bxcore.ParticipateListReq, otherSql string) (data
 }
 
 //获取最新参标 更新内容
-func GetParticipateContent(userId int64, projectId string) string {
-	recordsSql := `SELECT record_content FROM participate_bid_records WHERE (ent_id = ? OR position_id = ?) AND project_id = ? ORDER BY create_date DESC LIMIT 1;`
-	records := IC.BaseMysql.SelectBySql(recordsSql, userId, userId, projectId)
+func GetParticipateContent(s string, id int64, projectId string) string {
+	identitySql := `ent_id = ?`
+	if s == "s" {
+		identitySql = `position_id = ?`
+	}
+	recordsSql := `SELECT record_content,record_type FROM ` + ParticipateBidRecordsTable + ` WHERE ` + identitySql + ` AND project_id = ? ORDER BY create_date DESC LIMIT 1;`
+	records := IC.BaseMysql.SelectBySql(recordsSql, id, projectId)
 	if records != nil && len(*records) > 0 {
 		rec := (*records)[0]
-		return MC.ObjToString(rec["record_content"])
+		switch MC.IntAll(rec["record_type"]) {
+		case 0:
+			return MC.ObjToString(rec["record_content"])
+		case 1:
+			recordContent := *MC.ObjToMap(rec["record_content"])
+			rb, err := json.Marshal(recordContent)
+			if err != nil {
+				log.Println(err.Error())
+				return ""
+			}
+			var rc = RecordsContent{
+				After:  PartStatusContent{},
+				Before: PartStatusContent{},
+			}
+			err1 := json.Unmarshal(rb, &rc)
+			if err1 == nil {
+				return rc.Content
+			}
+		}
 	}
 	return ""
 }