package service import ( "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/encrypt" elastic "app.yhyue.com/moapp/jybase/esv1" "fmt" IC "jyBXCore/rpc/init" "jyBXCore/rpc/type/bxcore" "strings" "time" ) const ( IndexProjectSet = "projectset" // 项目信息es index TypeProjectSet = "projectset" // 项目信息es type TableEntnicheUser = "entniche_user" // 企业用户表 PositionTypeEnt = 1 // 职位类型企业 PositionTypePersonal = 0 // 职位类型个人 ButtonValueParticipate = 0 // 参标按钮 显示值 0-参标 ButtonValueParticipated = 1 // 按钮显示值 列表页面 1-已参标 RoleEntManager = 1 // 企业管理员角色 RoleDepartManager = 2 // 部门管理员角色 ) type ParticipateBid struct { EntId int64 EntUserId int64 PositionType int64 PositionId int64 EntRoleId int64 // 角色 } func NewParticipateBid(entId, entUserId, positionType, positionId int64) ParticipateBid { return ParticipateBid{ EntId: entId, EntUserId: entUserId, PositionType: positionType, PositionId: positionId, } } // GetProjectByInfoId 根据查询有效的参标项目id(未到开标时间及开标时间不存在的) func (p *ParticipateBid) GetProjectByInfoId(infoIds []string) *[]map[string]interface{} { if len(infoIds) == 0 { return nil } nowTime := time.Now().Unix() query := `{"_source":["_id","list.infoid"],"query": {"bool": {"must": [{"terms": {"list.infoid": ["` + strings.Join(infoIds, "\",\"") + `"]}}, {"bool": {"should": [{"range": {"bidopentime": {"gte": ` + fmt.Sprint(nowTime) + `}}}, {"constant_score": {"filter": {"missing": {"field": "bidopentime" } } } }] }}]}}}` projectResult := elastic.Get(IndexProjectSet, TypeProjectSet, query) return projectResult } // GetProject 根据信息id查询项目id func (p *ParticipateBid) GetProject(infoIds []string) *[]map[string]interface{} { if len(infoIds) == 0 { return nil } query := `{"_source":["_id","list.infoid","ids","bidopentime"],"query":{"bool":{"must":[{"terms":{"list.infoid":["` + strings.Join(infoIds, "\",\"") + `"]}}]}}}` projectResult := elastic.Get(IndexProjectSet, TypeProjectSet, query) return projectResult } // 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 := IC.BaseMysql.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 } // 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, ",") // todo 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 := IC.BaseMysql.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 } // DetailEntFormat 企业版 详情页数据格式化 返回数据 参标按钮 终止参标按钮 转给同事按钮 参标人姓名 // 判断企业下是否有参标人 // - 无参标人&&没有到期 展示参标按钮 其余按钮不显示 // - 有参标人 展示参标人信息 // - 未到开标时间 // - 管理员 未到开标时间 展示 转给同事、终止参标 // - 包含自己 展示终止参标 不包含自己如果允许多人参标 展示参标按钮 // func (p *ParticipateBid) DetailEntFormat(existProjectMap map[string]string, isValid, isAllow bool) (formatData *bxcore.ParticipateDetailInfo) { // 处理成 要返回的返回数据 formatData = &bxcore.ParticipateDetailInfo{} if len(existProjectMap) == 0 && isValid { // 无参标人 展示参标按钮 其余按钮不显示 formatData.ShowParticipate = true return } persons := "" for _, v := range existProjectMap { // 这是为了取参标人id信息 列表页是多条数据 详情页这里 map里面只会有一条数据 persons = v break } // 参标人信息 处理成姓名 nameRs := GetNameByUserIds(persons) if nameRs != nil && len(*nameRs) > 0 { formatData.UserName = common.ObjToString((*nameRs)[0]["name"]) } if !isValid { return } // 如果是管理员 显示 终止参标按钮 、转给同事按钮 if p.EntRoleId == RoleEntManager || p.EntRoleId == RoleDepartManager { formatData.ShowStopParticipate = true formatData.ShowTransfer = true } // 如果包含自己 显示终止参标按钮 if ContainId(persons, common.InterfaceToStr(p.EntUserId)) { formatData.ShowStopParticipate = true } else if isAllow { // 如果允许多人 显示参标按钮 formatData.ShowParticipate = true } return } // DetailPersonalFormat 详情页个人版 按钮格式化数据 func (p *ParticipateBid) DetailPersonalFormat(existProjectSet map[string]struct{}, isValid bool) (formatData *bxcore.ParticipateDetailInfo) { // 处理成 要返回的返回数据 formatData = &bxcore.ParticipateDetailInfo{} if !isValid { return } // 存在在说明已经参标 显示终止参标 if len(existProjectSet) > 0 { formatData.ShowStopParticipate = true } else { // 不存在则说明 未参标 参标按钮展示 formatData.ShowParticipate = true } return } // 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 } // 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 } // GetNameByUserIds 获取用户名字符串 // 参数:逗号分割的用户id "11,22,333..." // 返回: "张三,李四,王五..." func GetNameByUserIds(ids string) *[]map[string]interface{} { query := "select group_concat( name) from" + TableEntnicheUser + "where id in (" + ids + ") " rs := IC.MainMysql.SelectBySql(query) return rs } /* 投标状态更新 1. 验证参标人 2. 更新 存操作记录 */