Explorar el Código

Merge branch 'dev/v1.1.20_fuwencai' of http://192.168.3.207:8080/BaseService/jyMicroservices into dev/v1.1.20_fuwencai

fuwencai hace 2 años
padre
commit
d6799df0b2
Se han modificado 2 ficheros con 101 adiciones y 50 borrados
  1. 74 35
      jyBXCore/rpc/model/tidb/tidb.go
  2. 27 15
      jyBXCore/rpc/service/participate.go

+ 74 - 35
jyBXCore/rpc/model/tidb/tidb.go

@@ -10,6 +10,7 @@ import (
 	IC "jyBXCore/rpc/init"
 	"jyBXCore/rpc/type/bxcore"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -18,33 +19,36 @@ var (
 )
 
 //划转参标信息
-func TransferParticipate(in *bxcore.ParticipateActionReq) error {
+func TransferParticipateInfo(in *bxcore.ParticipateActionReq) error {
 	//保存或更新新跟踪人
 	if !IC.BaseMysql.ExecTx("划转参标信息", func(tx *sql.Tx) bool {
 		var (
-			b       = true
-			b2, b3  bool
-			now     = time.Now()
-			content = "%s划转给%s"
+			b1            = true
+			b2, b3        bool
+			now           = time.Now()
+			content       = "%s划转给%s"
+			fromUserNames []string
+			ids           []int
 		)
 		//是否保留原参标人
 		if !in.IsRetain {
-			content = fmt.Sprintf(content, "", "%s")
-			b = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf(`UPDATE participate_user SET state = -2 ,update_date = %s WHERE ent_id = ? AND project_id = ?`, date.FormatDate(&now, date.Date_Full_Layout)), in.EntId, in.BidId) > 0
 			//不保留 原参标人,获取把原参标人信息
-		} else {
-			entUserId, _ := strconv.ParseInt(in.ToEntUserId, 10, 64)
-			IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
-		}
-		//查询原跟踪人信息
-		if entUserInfos := IC.MainMysql.SelectBySql(`SELECT name FROM entniche_user WHERE id = ? LIMIT 1`, in.ToEntUserId); entUserInfos != nil && len(*entUserInfos) > 0 {
-			entUserInfo := (*entUserInfos)[0]
-			//用户名称
-			if name := MC.ObjToString(entUserInfo["name"]); name != "" {
-				b2 = true
-				content = fmt.Sprintf(content, name)
+			partInfo := IC.BaseMysql.SelectBySqlByTx(tx, "SELECT id,position_id FROM `participate_user` WHERE  project_id = ?  AND ent_id = ? AND state > -1", in.BidId, in.EntId)
+			if partInfo != nil && len(*partInfo) > 0 {
+				for _, v := range *partInfo {
+					ids = append(ids, MC.IntAll(v["id"]))
+					positionId := MC.Int64All(v["position_id"])
+					userInfo := IC.Middleground.UserCenter.IdentityByPositionId(positionId)
+					fromUserNames = append(fromUserNames, userInfo.EntUserName)
+				}
 			}
+			b1 = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf(`UPDATE participate_user SET state = -2 ,update_date = %s WHERE ent_id = ? AND project_id = ?`, date.FormatDate(&now, date.Date_Full_Layout)), in.EntId, in.BidId) > 0
 		}
+		//查询划转人信息
+		entUserId, _ := strconv.ParseInt(in.ToEntUserId, 10, 64)
+		userInfo := IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
+		in.PositionId = userInfo.PositionId
+		content = fmt.Sprintf(content, strings.Join(fromUserNames, ","), userInfo.EntUserName)
 		//
 		//保存参标--participate_user
 		b3 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
@@ -55,7 +59,7 @@ func TransferParticipate(in *bxcore.ParticipateActionReq) error {
 			"record_content": content,
 			"create_date":    date.FormatDate(&now, date.Date_Full_Layout),
 		}) > 0
-		return b && b2 && b3
+		return b1 && b2 && b3
 	}) {
 		logx.Info(in.PositionId, "---终止---", in.BidId)
 		return fmt.Errorf("终止参标更新信息出错")
@@ -63,25 +67,40 @@ func TransferParticipate(in *bxcore.ParticipateActionReq) error {
 	return nil
 }
 
-//更新参标信息
-func UpdateParticipateInfo(in *bxcore.ParticipateActionReq) error {
+//终止参标
+func CancelParticipateInfo(in *bxcore.ParticipateActionReq, roleId int64) error {
 	if !IC.BaseMysql.ExecTx("终止参标", func(tx *sql.Tx) bool {
 		var (
-			ppu, pph bool
-			now      = time.Now()
+			b1, b2 bool
+			now    = time.Now()
+			tip    = "终止参标(被)"
 		)
+		//管理员终止:当前项目 其他参标人也被终止
+		query := map[string]interface{}{
+			"project_id": in.BidId,
+			"ent_id":     in.EntId,
+		}
+		//个人终止:仅仅终止本人参标项目
+		if roleId == 0 {
+			query["position_id"] = in.PositionId
+			tip = "终止参标"
+		}
+		insert := map[string]interface{}{
+			"state":       -1,
+			"update_date": date.FormatDate(&now, date.Date_Full_Layout),
+		}
 		//更新参标participate_user
-		ppu = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf(`UPDATE participate_user SET state = -1 ,update_date = %s WHERE position_id = ? AND ent_id = ? AND project_id = ?`, date.FormatDate(&now, date.Date_Full_Layout)), in.PositionId, in.EntId, in.BidId) > 0
+		b1 = IC.BaseMysql.UpdateByTx(tx, "participate_user", query, insert)
 		//保存参标记录--participate_bid_records
-		pph = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
+		b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
 			"ent_id":         in.EntId,
 			"ent_user_id":    in.EntUserId,
 			"position_id":    in.PositionId,
 			"project_id":     in.BidId,
-			"record_content": "终止参标",
+			"record_content": tip,
 			"create_date":    date.FormatDate(&now, date.Date_Full_Layout),
 		}) > 0
-		return ppu && pph
+		return b1 && b2
 	}) {
 		logx.Info(in.PositionId, "---终止---", in.BidId)
 		return fmt.Errorf("终止参标更新信息出错")
@@ -93,15 +112,28 @@ func UpdateParticipateInfo(in *bxcore.ParticipateActionReq) error {
 func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
 	if !IC.BaseMysql.ExecTx("保存|更新参标信息及保存参标记录", func(tx *sql.Tx) bool {
 		var (
-			ppu, pph bool
-			now      = time.Now()
+			b1, b2 bool
+			now    = time.Now()
 		)
-		//保存参标记录participate_bid_records
+		//保存参标--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.BidId, in.EntId); c > 0 {
-			ppu = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf(`UPDATE participate_user SET state = 0 ,update_date = %s WHERE position_id = ? AND ent_id = ? AND project_id = ?`, date.FormatDate(&now, date.Date_Full_Layout)), in.PositionId, in.EntId, in.BidId) > 0
+			//更新
+			b1 = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf(`UPDATE participate_user SET state = 0 ,update_date = %s WHERE position_id = ? AND ent_id = ? AND project_id = ?`, date.FormatDate(&now, date.Date_Full_Layout)), in.PositionId, in.EntId, in.BidId) > 0
+		} else {
+			//保存
+			b1 = IC.BaseMysql.InsertByTx(tx, "participate_user", map[string]interface{}{
+				"ent_id":      in.EntId,
+				"ent_user_id": in.EntUserId,
+				"position_id": in.PositionId,
+				"project_id":  in.PositionId,
+				"state":       0,
+				"create_date": date.FormatDate(&now, date.Date_Full_Layout),
+				"update_date": date.FormatDate(&now, date.Date_Full_Layout),
+			}) > 0
 		}
-		//保存参标--participate_user
-		pph = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
+		//保存参标记录participate_bid_records
+		b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
 			"ent_id":         in.EntId,
 			"ent_user_id":    in.EntUserId,
 			"position_id":    in.PositionId,
@@ -109,7 +141,7 @@ func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
 			"record_content": "参标",
 			"create_date":    date.FormatDate(&now, date.Date_Full_Layout),
 		}) > 0
-		return ppu && pph
+		return b1 && b2
 	}) {
 		logx.Info(in.PositionId, "---保存---", in.BidId)
 		return fmt.Errorf("保存参标信息出错")
@@ -118,7 +150,14 @@ func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
 }
 
 //查询当前招标信息是否已被参标
-func IsParticipatedByBidId(query string) bool {
+func IsParticipatedByBidId(in *bxcore.ParticipateActionReq) bool {
+	//如果不允许多人参标 当前项目是否已经有企业其他人员参标
+	query := fmt.Sprintf(`SELECT count(id) FROM participate_user WHERE %s AND project_id = %s AND state >-1`, "%s", in.BidId)
+	if in.PositionType > 0 {
+		query = fmt.Sprintf(query, fmt.Sprintf("ent_id = %d", in.EntId))
+	} else {
+		query = fmt.Sprintf(query, fmt.Sprintf("position_id = %d", in.PositionId))
+	}
 	return IC.BaseMysql.CountBySql(query) > 0
 }
 

+ 27 - 15
jyBXCore/rpc/service/participate.go

@@ -10,6 +10,16 @@ import (
 	"jyBXCore/rpc/util"
 )
 
+//更新数据 加锁。。。。。
+/*
+已过投标截止日期项目
+(1)	不显示终止投标倒计时
+(2)	显示参标人信息
+(3)	无终止参标操作入口
+(4)	不能划转
+(5)	不能参标
+*/
+
 //参标动作:参标、终止参标、划转:in:参标;out:终止参标;transfer:划转
 func ParticipateDo(in *bxcore.ParticipateActionReq) (*bxcore.ParticipateActionRes, error) {
 	//招标信息解密
@@ -21,7 +31,14 @@ func ParticipateDo(in *bxcore.ParticipateActionReq) (*bxcore.ParticipateActionRe
 	participateBid := NewParticipateBid(in.EntId, in.EntUserId, in.PositionType, in.PositionId)
 	projectInfos := participateBid.GetProjectByInfoId([]string{in.BidId})
 	if projectInfos == nil || len(*projectInfos) == 0 {
-		return nil, fmt.Errorf("当前项目信息不满足参标条件")
+		tip := "参标"
+		switch in.ActionType {
+		case "out":
+			tip = "终止参标"
+		case "transfer":
+			tip = "划转"
+		}
+		return nil, fmt.Errorf(fmt.Sprintf("当前项目信息不满足%s条件", tip))
 	}
 	//符合参标项目id
 	projectInfo := (*projectInfos)[0]
@@ -30,18 +47,14 @@ func ParticipateDo(in *bxcore.ParticipateActionReq) (*bxcore.ParticipateActionRe
 	} else {
 		return nil, fmt.Errorf("当前项目信息有误")
 	}
+	//企业版 判断是否是管理员
+	//判断用户身份
+	userInfo := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
 	switch in.ActionType {
 	case "in":
 		//是否允许多人参标
 		if isAllow := util.NewPartUserInfo(in.EntId, in.EntUserId, in.PositionId, in.PositionType).IsALLow(); !isAllow {
-			//如果不允许多人参标 当前项目是否已经有企业其他人员参标
-			query := fmt.Sprintf(`SELECT count(id) FROM participate_user WHERE %s AND project_id = %s AND state >-1`, "%s", in.BidId)
-			if in.PositionType > 0 {
-				query = fmt.Sprintf(query, fmt.Sprintf("ent_id = %d", in.EntId))
-			} else {
-				query = fmt.Sprintf(query, fmt.Sprintf("position_id = %d", in.PositionId))
-			}
-			if ok := tidb.IsParticipatedByBidId(query); ok {
+			if ok := tidb.IsParticipatedByBidId(in); ok {
 				return nil, fmt.Errorf("当前项目不允许多人参标")
 			}
 		}
@@ -50,27 +63,26 @@ func ParticipateDo(in *bxcore.ParticipateActionReq) (*bxcore.ParticipateActionRe
 			return nil, err
 		}
 	case "out": //终止参标
-		if err := tidb.UpdateParticipateInfo(in); err != nil {
+		if err := tidb.CancelParticipateInfo(in, userInfo.Ent.EntRoleId); err != nil {
 			return nil, err
 		}
 	case "transfer":
+		//个人版
 		if in.PositionType == 0 {
 			return nil, fmt.Errorf("当前企业身份有误")
 		}
-		//企业版 判断是否是管理员
-		//判断用户身份
-		userInfo := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
+		//非管理员
 		if userInfo.Ent.EntRoleId == 0 { //1:企业管理员;2:部门管理员
 			return nil, fmt.Errorf("当前企业身份无权限")
 		}
 		//是否保留原跟踪人?
 		partUser := util.NewPartUserInfo(in.EntId, in.EntUserId, in.PositionId, in.PositionType)
 		isAllow := partUser.IsALLow()
-		if !isAllow && in.IsRetain {
+		if in.IsRetain && !isAllow {
 			//不允许多人参标,但是前端参数又是保留原参标人 互相矛盾
 			return nil, fmt.Errorf("当前项目只允许一人参标")
 		}
-		if err := tidb.TransferParticipate(in); err != nil {
+		if err := tidb.TransferParticipateInfo(in); err != nil {
 			return nil, err
 		}
 	}