浏览代码

feat:列表参标信息提交

fuwencai 2 年之前
父节点
当前提交
e43ba7021b
共有 2 个文件被更改,包括 360 次插入2 次删除
  1. 54 2
      jyBXCore/rpc/internal/logic/participateshowlogic.go
  2. 306 0
      jyBXCore/rpc/service/participateBid.go

+ 54 - 2
jyBXCore/rpc/internal/logic/participateshowlogic.go

@@ -2,6 +2,10 @@ package logic
 
 import (
 	"context"
+	"jyBXCore/entity"
+	"jyBXCore/rpc/service"
+	"jyBXCore/rpc/util"
+	"strconv"
 
 	"jyBXCore/rpc/internal/svc"
 	"jyBXCore/rpc/type/bxcore"
@@ -25,7 +29,55 @@ func NewParticipateShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *P
 
 //  列表数据参标信息接口
 func (l *ParticipateShowLogic) ParticipateShow(in *bxcore.ParticipateShowReq) (*bxcore.ParticipateShowRes, error) {
-	// todo: add your logic here and delete this line
+	result := bxcore.ParticipateShowRes{
+		ErrMsg:  "",
+		ErrCode: 0,
+		Data:    []*bxcore.ShowInfo{},
+	}
+	// 1. 判断身份是否有权限 不是超级订阅也不是大会员  则直接返回不展示
+	baseUserId, _ := strconv.ParseInt(in.NewUserId, 10, 64)
+	accountId, _ := strconv.ParseInt(in.AccountId, 10, 64)
+	userInfoRpc := entity.UserInfoRpc{
+		AppId:        in.AppId,
+		UserId:       in.UserId,
+		BaseUserId:   baseUserId,
+		EntId:        in.EntId,
+		EntUserId:    in.EntUserId,
+		AccountId:    accountId,
+		PositionType: in.PositionType,
+		PositionId:   in.PositionId,
+		MgoUserId:    in.MgoUserId,
+	}
+	participateService := service.NewParticipateBid(int(in.EntId), int(in.EntUserId), int(in.PositionType), int(in.PositionId))
+	if participateService.ParticipatePowerCheck(userInfoRpc) {
+		return &result, nil
+	}
 
-	return &bxcore.ParticipateShowRes{}, nil
+	// 2. 根据标讯id 查询项目信息 拿到有效的项目id (无项目信息或者已经过开标时间  则不展示按钮  在开标时间内或者没有开标时间字段需要展示)
+	// 信息id解密
+	infoList, infoSet := service.DecodeId(in.Ids)
+	if len(infoList) == 0 {
+		return &result, nil
+	}
+	// 查有效项目id信息
+	projectInfos := participateService.GetProjectByInfoId(infoList)
+	if projectInfos == nil || len(*projectInfos) == 0 {
+		return &result, nil
+	}
+	// 记录信息id和项目id的映射  用于最后处理返回数据
+	infoM, projectIds := service.HandlerProjectId(*projectInfos, infoSet)
+	// 3. 查询参标信息 处理按钮 区分个人和企业
+	var formatList []*bxcore.ShowInfo
+	switch int(in.PositionType) {
+	case service.PositionTypePersonal:
+		existList := participateService.PersonalExistProject(projectIds)
+		formatList = participateService.ListPersonalFormat(existList, infoM)
+	case service.PositionTypeEnt:
+		partUser := util.NewPartUserInfo(in.EntId, in.EntUserId, in.PositionId, in.PositionType)
+		isAllow := partUser.IsALLow()
+		existList := participateService.EntExistProject(projectIds)              // 查询出已经存在的
+		formatList = participateService.ListEntFormat(existList, infoM, isAllow) // 格式化数据
+	}
+	result.Data = formatList
+	return &result, nil
 }

+ 306 - 0
jyBXCore/rpc/service/participateBid.go

@@ -0,0 +1,306 @@
+package service
+
+import (
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/encrypt"
+	elastic "app.yhyue.com/moapp/jybase/esv7"
+	"fmt"
+	"jyBXCore/entity"
+	"jyBXCore/rpc/init"
+	"jyBXCore/rpc/type/bxcore"
+	"strings"
+	"time"
+)
+
+const (
+	IndexProjectSet         = "projectset" // 项目信息es index
+	TypeProjectSet          = "projectset" // 项目信息es type
+	PositionTypeEnt         = 1            // 职位类型企业
+	PositionTypePersonal    = 0            // 职位类型个人
+	ButtonValueParticipate  = 0            // 参标按钮 显示值 0-参标
+	ButtonValueParticipated = 1            // 按钮显示值 列表页面 1-已参标 详情页 1-终止参标
+	RoleEntManager          = 1            //  企业管理员角色
+	RoleDepartManager       = 2            //  部门管理员角色
+)
+
+type ParticipateBid struct {
+	EntId        int
+	EntUserId    int
+	PositionType int
+	PositionId   int
+	EntRoleId    int64 // 角色
+}
+
+func NewParticipateBid(entId, entUserId, positionType, positionId int) ParticipateBid {
+	return ParticipateBid{
+		EntId:        entId,
+		EntUserId:    entUserId,
+		PositionType: positionType,
+		PositionId:   positionId,
+	}
+}
+
+// ParticipatePowerCheck 身份验证
+func (p *ParticipateBid) ParticipatePowerCheck(userInfoRpc entity.UserInfoRpc) bool {
+	userInfo := userInfoRpc.GetUserPowers()
+	p.EntRoleId = userInfo.Ent.EntRoleId
+	if userInfo.Member.Status > 0 || userInfo.Vip.Status > 0 {
+		return true
+	}
+	return false
+}
+
+// GetProjectByInfoId 根据查询有效的参标项目id(未到开标时间及开标时间不存在的)
+func (p *ParticipateBid) GetProjectByInfoId(infoIds []string) *[]map[string]interface{} {
+	if len(infoIds) == 0 {
+		return nil
+	}
+	nowTime := time.Now()
+	query := `{"_source":["_id","list.infoid"],"query": {"bool": {"must": [{"terms": {"list.infoid": [` + fmt.Sprint(infoIds) + `]}},
+        {"bool": {"should": [{"range": {"bidopentime": {"lte": ` + fmt.Sprint(nowTime) + `}}},
+        {"constant_score": {"filter": {"missing": {"field": "projectset.bidopentime"
+                    } } } }] }}]}}}`
+
+	projectResult := elastic.Get(IndexProjectSet, TypeProjectSet, query)
+	return projectResult
+
+}
+
+// HandlerProjectId 返回信息的映射集合,项目id列表
+func HandlerProjectId(projectInfos []map[string]interface{}, infoIds map[string]struct{}) (map[string]string, []string) {
+	result := map[string]string{}
+	projectIdList := []string{}
+	//  记录infoid 和项目id 对应关系  用于最后处理返回的数据
+	for i := 0; i < len(projectInfos); i++ {
+		_id := common.ObjToString(projectInfos[i]["_id"])
+		projectIdList = append(projectIdList, _id)
+		list, b := projectInfos[i]["list"].([]interface{})
+		if !b {
+			continue
+		}
+		for j := 0; j < len(list); j++ {
+			infoidMap := common.ObjToMap(list[j])
+			if infoidMap == nil {
+				continue
+			}
+			infoid := common.ObjToString((*infoidMap)["infoid"])
+			if _, ok := infoIds[infoid]; ok && infoid != "" {
+				result[infoid] = _id
+				break
+			}
+		}
+	}
+	return result, projectIdList
+
+}
+
+// PersonalExistProject 个人版要展示的参标按钮  查询出已经参标的项目信息 用于后边格式化数据
+func (p *ParticipateBid) PersonalExistProject(projectId []string) map[string]struct{} {
+	// 1. 查询出已经参标的
+	var arg []string
+	var value []interface{}
+	value = append(value, p.PositionId)
+	for i := 0; i < len(projectId); i++ {
+		arg = append(arg, "?")
+		value = append(value, projectId[i])
+	}
+	argStr := strings.Join(arg, ",")
+	query := "select project_id from participate_user where position_id = ? and project_id in (%s)  and state>=0"
+	rs := init.MainMysql.SelectBySql(query, fmt.Sprintf(query, argStr), value)
+	existProjectSet := map[string]struct{}{}
+	if rs != nil && len(*rs) > 0 { // 如果查到了  说明已经参标 这部分应该显示已参标
+		// 处理成map
+		for i := 0; i < len(*rs); i++ {
+			existId := common.ObjToString((*rs)[i]["project_id"])
+			existProjectSet[existId] = struct{}{}
+		}
+	}
+	return existProjectSet
+}
+
+// ListPersonalFormat 列表页个人 参标按钮 格式化数据
+func (p *ParticipateBid) ListPersonalFormat(existProjectSet map[string]struct{}, infoM map[string]string) []*bxcore.ShowInfo {
+	// 处理成 要返回的返回数据
+	var formatList []*bxcore.ShowInfo
+	for k, v := range infoM {
+		buttonValue := ButtonValueParticipate // 不存在应该显示参标
+		if _, ok := existProjectSet[v]; ok {  // 存在说明应该显示已参标
+			buttonValue = ButtonValueParticipated
+		}
+		formatList = append(formatList, &bxcore.ShowInfo{
+			Id:    encrypt.EncodeArticleId2ByCheck(k),
+			Value: int64(buttonValue),
+		})
+	}
+	return formatList
+}
+
+// DetailPersonalFormat 详情页 按钮格式化数据 infoM里面只会有一条数据
+func (p *ParticipateBid) DetailPersonalFormat(existProjectSet map[string]struct{}) bxcore.ParticipateDetailInfo {
+	// 处理成 要返回的返回数据
+	formatData := bxcore.ParticipateDetailInfo{
+		ShowParticipate: true,
+	}
+	// 存在在说明已经参标  展示未终止参标
+	if len(existProjectSet) > 0 {
+		formatData.ShowValue = ButtonValueParticipated
+	} else {
+		// 不存在则说明 未参标 展示为参标
+		formatData.ShowValue = ButtonValueParticipate
+	}
+	return formatData
+}
+
+// EntExistProject 企业版 查出来企业下已经参标的这个项目的以及参标人信息  用于后边格式化数据判断有没有自己
+func (p *ParticipateBid) EntExistProject(projectId []string) map[string]string {
+	var arg []string
+	var value []interface{}
+	value = append(value, p.EntId)
+	for i := 0; i < len(projectId); i++ {
+		arg = append(arg, "?")
+		value = append(value, p.PositionId)
+	}
+	argStr := strings.Join(arg, ",")
+	query := "select GROUP_CONCAT(ent_user_id) as personIds ,project_id from participate_user where ent_id=? and  project_id in (%s) and state>=0  group by project_id "
+	rs := init.MainMysql.SelectBySql(query, fmt.Sprintf(query, argStr), value)
+	existProjectMap := map[string]string{}
+	if rs != nil && len(*rs) > 0 { // 如果查到了  说明这个项目公司里面已经参标 处理一下信息用于后边判断是否是自己参标
+		// 处理成map
+		for i := 0; i < len(*rs); i++ {
+			existId := common.ObjToString((*rs)[i]["project_id"])
+			personIds := common.ObjToString((*rs)[i]["personIds"])
+			existProjectMap[existId] = personIds
+		}
+	}
+	return existProjectMap
+}
+
+// ListEntFormat 企业版 列表页数据格式化
+//     判断企业下是否有参标人
+//     - 无参标人   展示参标按钮
+//     - 有参标人   判断是否包含自己
+//                 如果包含自己   显示已参标
+//                 不包含自己     则判断企业是否允许多人参标 允许 则显示参标按钮 不允许 则不显示
+func (p ParticipateBid) ListEntFormat(existProjectMap, infoM map[string]string, isAllow bool) []*bxcore.ShowInfo {
+	// 处理成 要返回的返回数据
+	var formatList []*bxcore.ShowInfo
+	for k, v := range infoM {
+		buttonValue := ButtonValueParticipate      // 不存在时-显示参标
+		if userIds, ok := existProjectMap[v]; ok { // 存在时 说明项目在企业下已经参标 需要进一步判断
+			// 判断已经存在的参标人中是否包含自己 // 包含时 显示成已参标
+			if ContainId(userIds, common.InterfaceToStr(p.EntUserId)) {
+				buttonValue = ButtonValueParticipated
+			} else if isAllow { // 不包含自己时需要 进一步判断公司设置是否允许多人参标
+				// 允许时显示成 参标
+				buttonValue = ButtonValueParticipate
+			} else { // 不允许时 跳过该条信息
+				continue
+			}
+
+		}
+		formatList = append(formatList, &bxcore.ShowInfo{
+			Id:    encrypt.EncodeArticleId2ByCheck(k),
+			Value: int64(buttonValue),
+		})
+	}
+	return formatList
+
+}
+func (p ParticipateBid) DetailEntFormat(existProjectMap map[string]string, isAllow bool) (formatData bxcore.ParticipateDetailInfo) {
+	// 处理成 要返回的返回数据
+	formatData = bxcore.ParticipateDetailInfo{
+		ShowParticipate: true,
+	}
+	if len(existProjectMap) == 0 {
+		// 不存在则说明 未参标 展示为参标
+		formatData.ShowValue = ButtonValueParticipate
+		return
+	}
+	persons := ""
+	for _, v := range existProjectMap {
+		persons = v
+		break
+	}
+	// 判断是不是自己
+	// 是自己则展示终止参标
+
+	if ContainId(persons, fmt.Sprint(p.EntUserId)) {
+		formatData.ShowValue = ButtonValueParticipated
+		return
+	}
+	// 不是自己则需要再 判断身份   员工  / 企业管理员 部门管理员
+	switch p.EntRoleId {
+	case RoleEntManager:
+		// 如果是企业管理员  显示 终止参标
+		formatData.ShowValue = ButtonValueParticipated
+
+	case RoleDepartManager:
+		// 如果是部门管理员 判断是否包含该部门下的 如果是 显示终止参标  如果不是 判断是否允许多人参标  允许 显示参标 不允许 则不显示
+
+	default:
+		// 如果是员工  判断是否允许多人
+		if isAllow {
+			formatData.ShowValue = ButtonValueParticipate // 是 -显示参标
+		} else {
+			formatData.ShowParticipate = false // 否  不显示按钮
+		}
+
+	}
+
+	return
+
+}
+
+// DecodeId  解密标讯id 返回一个信息id的列表 和 集合
+func DecodeId(ids string) (result []string, resultSet map[string]struct{}) {
+	idList := strings.Split(ids, ",")
+	resultSet = map[string]struct{}{}
+	for i := 0; i < len(idList); i++ {
+		decodeArray := encrypt.DecodeArticleId2ByCheck(idList[i])
+		if len(decodeArray) == 1 && decodeArray[0] != "" {
+			result = append(result, decodeArray[0])
+			resultSet[decodeArray[0]] = struct{}{}
+		}
+	}
+	return
+}
+
+// ContainId 用于判断已经参标的用户中是否包含自己
+func ContainId(ids string, objId string) bool {
+	list := strings.Split(ids, ",")
+	for i := 0; i < len(list); i++ {
+		if list[i] == objId {
+			return true
+		}
+	}
+	return false
+
+}
+
+/*
+ 详情页参标信息展示
+ 参标按钮:
+1. 判断身份 2. 根据标讯id 查询项目信息 同上
+3. 项目信息存在  则区分  个人 和 企业
+个人:
+	参标按钮 :项目参标人为空 否则展示终止参标
+    参标人姓名 : 不展示
+    转给同事按钮:不展示
+企业身份:
+    参标按钮:
+    判断企业下是否有参标人
+     - 无参标人   展示参标按钮
+     - 有参标人   当前用户是企业管理员 显示终止参标
+                当前用户是部门管理员  如果参标人中有该部门的人员  显示终止参标  否则 判断是否允许多人参标 允许多人参标 显示参标按钮 否则不显示
+                不是管理员:判断是否包含本人  包含则展示 终止参标按钮
+                          不包含则判断是否允许多人参标  允许多人则展示 参标  不允许多人则不展示按钮
+     参标人姓名 :有参标人则展示
+     转给同事按钮 :判断是否是管理员(部门管理员/企业管理员)
+				 是管理员则展示 否 则不展示
+*/
+
+/*
+投标状态更新
+1. 验证参标人
+2. 更新 存操作记录
+*/