|
@@ -8,7 +8,9 @@ import (
|
|
|
"fmt"
|
|
|
"jyBXCore/rpc/bxcore"
|
|
|
IC "jyBXCore/rpc/init"
|
|
|
+ "jyBXCore/rpc/model/es"
|
|
|
"log"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -89,12 +91,23 @@ func (in *ParticipateStatistics) GetSourceItem(entId, positionId int) (result []
|
|
|
return
|
|
|
}
|
|
|
for i := 0; i < len(*rs); i++ {
|
|
|
- value := common.IntAll((*rs)[i][""])
|
|
|
- if name, ok := SelectItemMap[value]; ok {
|
|
|
- result = append(result, &bxcore.SourceItem{
|
|
|
- Name: name,
|
|
|
- Value: int64(value),
|
|
|
- })
|
|
|
+ value := common.ObjToString((*rs)[i]["source"])
|
|
|
+ if value == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ splitSource := strings.Split(value, ",")
|
|
|
+ for j := 0; j < len(splitSource); j++ {
|
|
|
+ sourceValue, err := strconv.Atoi(splitSource[j])
|
|
|
+ if err != nil {
|
|
|
+ log.Println("类型转换错误:", err, splitSource[j])
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if name, ok := SelectItemMap[sourceValue]; ok {
|
|
|
+ result = append(result, &bxcore.SourceItem{
|
|
|
+ Name: name,
|
|
|
+ Value: int64(sourceValue),
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if len(result) > 0 {
|
|
@@ -504,10 +517,206 @@ func QueryHandle(isAdmin bool, startTime, endTime int64, personArrStr string, so
|
|
|
sourceValue += fmt.Sprint(source[i]) + ","
|
|
|
}
|
|
|
sourceValue = sourceValue[:len(sourceValue)-1]
|
|
|
- query = append(query, fmt.Sprintf("source in ( %s )", sourceValue))
|
|
|
+ query = append(query, fmt.Sprintf(" FIND_IN_SET('%s', a.source)", sourceValue))
|
|
|
}
|
|
|
if bidWay != 0 {
|
|
|
query = append(query, fmt.Sprintf("bid_way = %d", bidWay))
|
|
|
}
|
|
|
return query
|
|
|
}
|
|
|
+func (in *ParticipateStatistics) ProjectDetails(entUserIdArr []string, detailReq *bxcore.ProjectDetailsReq) (result bxcore.DetailData) {
|
|
|
+ //判断是企业、部门还是个人
|
|
|
+ isAdmin, personArrStr, _ := in.PersonHandle(entUserIdArr)
|
|
|
+ queryType := GetQueryType(detailReq)
|
|
|
+ query, countQuery := GetDetailQuery(isAdmin, personArrStr, detailReq, queryType)
|
|
|
+ totalCount := IC.BaseMysql.CountBySql(countQuery)
|
|
|
+ if totalCount == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 处理数据 这里只是筛选出项目id和阶段信息
|
|
|
+ dataList := IC.BaseMysql.SelectBySql(query)
|
|
|
+ if dataList == nil && len(*dataList) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 处理数据 补充项目名称、推送表字段 格式化数据
|
|
|
+ rs := ProjectDetailHandle(*dataList, in.EntId)
|
|
|
+ result = bxcore.DetailData{
|
|
|
+ List: rs,
|
|
|
+ Total: totalCount,
|
|
|
+ }
|
|
|
+ // 处理数据
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// todo 查询条件待重新处理 现在不对
|
|
|
+func GetDetailQuery(isAdmin bool, personArrStr string, req *bxcore.ProjectDetailsReq, queryType int) (string, string) {
|
|
|
+ joinStr := ""
|
|
|
+ switch queryType {
|
|
|
+ case 0:
|
|
|
+ joinStr = " union "
|
|
|
+ case 1:
|
|
|
+ joinStr = " left join "
|
|
|
+ case 2:
|
|
|
+ joinStr = " right join "
|
|
|
+ case 3:
|
|
|
+ joinStr = " inner join "
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ query := []string{}
|
|
|
+ if isAdmin {
|
|
|
+ //是管理员
|
|
|
+ query = append(query, fmt.Sprintf(" a.ent_user_id in (%s) ", personArrStr))
|
|
|
+ } else {
|
|
|
+ //不是管理员
|
|
|
+ query = append(query, fmt.Sprintf(" a.position_id = %s ", personArrStr))
|
|
|
+ }
|
|
|
+ //// 标讯推送时间
|
|
|
+ if req.StartTime == 0 && req.EndTime == 0 && req.BidUpdateStartTime == "" && req.BidUpdateEndTime == "" {
|
|
|
+ //没有传时间,默认时间处理
|
|
|
+ var start = time.Now().AddDate(0, 0, -30)
|
|
|
+ query = append(query, fmt.Sprintf(" a.ymd >= %s ", start.Format("20060102")))
|
|
|
+ }
|
|
|
+ if req.StartTime != 0 {
|
|
|
+ query = append(query, fmt.Sprintf(" a.ymd >= %d ", req.StartTime))
|
|
|
+ }
|
|
|
+ if req.EndTime != 0 {
|
|
|
+ query = append(query, fmt.Sprintf(" a.ymd <= %d ", req.EndTime))
|
|
|
+ }
|
|
|
+ // 标讯/项目来源
|
|
|
+ if len(req.Source) > 0 {
|
|
|
+ sourceValue := ""
|
|
|
+ for i := 0; i < len(req.Source); i++ {
|
|
|
+ sourceValue += fmt.Sprint(req.Source[i]) + ","
|
|
|
+ }
|
|
|
+ sourceValue = sourceValue[:len(sourceValue)-1]
|
|
|
+ query = append(query, fmt.Sprintf(" FIND_IN_SET('%s', a.source)", sourceValue))
|
|
|
+ }
|
|
|
+ // 投标类型 投标方式;1:直接投标 2:渠道投标',
|
|
|
+ if req.BidWay != 0 {
|
|
|
+ query = append(query, fmt.Sprintf("a.bid_way = %d", req.BidWay))
|
|
|
+ }
|
|
|
+ //参标状态:-1全部,0未参标、1已参标
|
|
|
+ if req.IsParticipate != -1 {
|
|
|
+ query = append(query, fmt.Sprintf("a.isparticipate = %d", req.IsParticipate))
|
|
|
+ }
|
|
|
+ // 参标状态更新时间
|
|
|
+ if req.BidUpdateStartTime != "" {
|
|
|
+ query = append(query, fmt.Sprintf("b.update_date > %s", req.BidUpdateStartTime))
|
|
|
+ }
|
|
|
+ if req.BidUpdateEndTime != "" {
|
|
|
+ query = append(query, fmt.Sprintf("b.update_date > %s", req.BidUpdateStartTime))
|
|
|
+ }
|
|
|
+
|
|
|
+ q := "select distinct(a.project_id),b.stage from participate_push_statistics a ," + joinStr + " participate_stage_statistics b on(b.project_id=a.project_id and b.ent_id=a.ent_id) %s"
|
|
|
+ q2 := "select count(distinct(a.project_id),b.stage) from participate_push_statistics a ," + joinStr + " participate_stage_statistics b on(b.project_id=a.project_id and b.ent_id=a.ent_id) %s"
|
|
|
+ if len(query) > 0 {
|
|
|
+ q += " where "
|
|
|
+ q2 += " where "
|
|
|
+ q = fmt.Sprintf(q, strings.Join(query, " and "))
|
|
|
+ q2 = fmt.Sprintf(q2, strings.Join(query, " and "))
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理分页
|
|
|
+ if req.PageNum == 0 && req.PageSize == 0 {
|
|
|
+ req.PageNum = 1
|
|
|
+ req.PageNum = 50
|
|
|
+ }
|
|
|
+ q = fmt.Sprintf("%s limit %d,%d", q, (req.PageNum-1)*req.PageSize, req.PageSize)
|
|
|
+ return q, q2
|
|
|
+}
|
|
|
+
|
|
|
+type PushInfoStruct struct {
|
|
|
+ Source string
|
|
|
+ VisitDate string
|
|
|
+ DisDate string
|
|
|
+ IsDistribute int
|
|
|
+}
|
|
|
+
|
|
|
+func ProjectDetailHandle(dataList []map[string]interface{}, entId int64) []*bxcore.ProjectDetailData {
|
|
|
+ //dataList 里面包含 项目id、各阶段勾选时间、
|
|
|
+ // 处理项目名称
|
|
|
+ projectIdList := []string{}
|
|
|
+ for i := 0; i < len(dataList); i++ {
|
|
|
+ projectIdList = append(projectIdList, common.ObjToString(dataList[i]["project_id"]))
|
|
|
+
|
|
|
+ }
|
|
|
+ // 项目名称处理成map用于后续使用
|
|
|
+ projectNameMap := map[string]string{}
|
|
|
+ projectNameRs := es.GetProjectNameByProjectId(projectIdList)
|
|
|
+ if projectNameRs != nil && len(*projectNameRs) > 0 {
|
|
|
+ for i := 0; i < len(*projectNameRs); i++ {
|
|
|
+ projectId_ := common.ObjToString((*projectNameRs)[i]["_id"])
|
|
|
+ projectName_ := (*projectNameRs)[i]["projectname"]
|
|
|
+ projectNameMap[projectId_] = common.ObjToString(projectName_)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获取推送最新状态
|
|
|
+ newPushInfo := getNewPushInfo(projectIdList, int(entId))
|
|
|
+
|
|
|
+ newPushInfoMap := map[string]PushInfoStruct{}
|
|
|
+ // 处理推送最新状态
|
|
|
+ if newPushInfo != nil && len(*newPushInfo) > 0 {
|
|
|
+ for i := 0; i < len(*newPushInfo); i++ {
|
|
|
+ project_ := common.ObjToString((*newPushInfo)[i]["project_id"])
|
|
|
+ info := PushInfoStruct{
|
|
|
+ Source: common.ObjToString((*newPushInfo)[i]["source"]),
|
|
|
+ VisitDate: common.ObjToString((*newPushInfo)[i]["visit_date"]),
|
|
|
+ DisDate: common.ObjToString((*newPushInfo)[i]["dis_date"]),
|
|
|
+ IsDistribute: common.IntAll((*newPushInfo)[i]["is_distribute"]),
|
|
|
+ }
|
|
|
+ newPushInfoMap[project_] = info
|
|
|
+ }
|
|
|
+ }
|
|
|
+ results := []*bxcore.ProjectDetailData{}
|
|
|
+ // 处理成最后的数据
|
|
|
+ for i := 0; i < len(dataList); i++ {
|
|
|
+ projectId := common.ObjToString(dataList[i]["project_id"])
|
|
|
+ tmp := bxcore.ProjectDetailData{
|
|
|
+ ProjectName: projectNameMap[projectId],
|
|
|
+ }
|
|
|
+ // 处理推送表相关字段
|
|
|
+ if pushInfo_, ok := newPushInfoMap[projectId]; ok {
|
|
|
+ tmp.Source = pushInfo_.Source // todo 处理成中文
|
|
|
+ tmp.ViewDate = pushInfo_.VisitDate
|
|
|
+ tmp.IsDistribute = int64(pushInfo_.IsDistribute)
|
|
|
+ tmp.DisDate = pushInfo_.DisDate
|
|
|
+ }
|
|
|
+ // todo 投标状态和投标类型需要加字段
|
|
|
+ // 处理阶段勾选信息和参标、终止参标信息 todo 参标和终止参标不放在stage
|
|
|
+ stageInfo := map[string]string{}
|
|
|
+ err := json.Unmarshal(dataList[i]["stage"].([]byte), &stageInfo)
|
|
|
+ if err != nil {
|
|
|
+ tmp.ParticipateDate = common.ObjToString(stageInfo["参标"])
|
|
|
+ tmp.StopParticipateDate = stageInfo["终止参标"]
|
|
|
+ delete(stageInfo, "参标")
|
|
|
+ delete(stageInfo, "终止参标")
|
|
|
+ tmp.Stage = stageInfo
|
|
|
+ }
|
|
|
+ results = append(results, &tmp)
|
|
|
+ }
|
|
|
+ return results
|
|
|
+}
|
|
|
+
|
|
|
+// 获取项目的最新推送状态信息
|
|
|
+func getNewPushInfo(projectIds []string, entId int) *[]map[string]interface{} {
|
|
|
+ sql := `select project_id,source,visit_date,dis_date,is_distribute from participate_push_statistics where id in (SELECT max(id) from participate_push_statistics where ent_id=%d and project_id in ( "` + strings.Join(projectIds, "\",\"") + `" ) group by project_id); `
|
|
|
+ query := fmt.Sprintf(sql, entId)
|
|
|
+ return IC.BaseMysql.SelectBySql(query)
|
|
|
+}
|
|
|
+
|
|
|
+// GetQueryType 查询类型 0空搜索 1左连接 2右连接 3内连接
|
|
|
+func GetQueryType(in *bxcore.ProjectDetailsReq) int {
|
|
|
+ // TODO 调整
|
|
|
+ if in.BidUpdateStartTime == "" && in.BidUpdateEndTime == "" && in.StartTime == 0 && in.EndTime == 0 && in.IsParticipate == -1 && in.BidWay == 0 && len(in.Source) == 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ if (in.BidUpdateStartTime != "" || in.BidUpdateEndTime != "") && (in.StartTime != 0 || in.EndTime != 0 || in.IsParticipate != -1 || in.BidWay != 0 || len(in.Source) != 0) {
|
|
|
+ return 3
|
|
|
+ }
|
|
|
+ if (in.BidUpdateStartTime != "" || in.BidUpdateEndTime != "") && (in.StartTime == 0 && in.EndTime == 0 && in.IsParticipate == -1 && in.BidWay == 0 && len(in.Source) == 0) {
|
|
|
+ return 2
|
|
|
+ }
|
|
|
+ return 1
|
|
|
+}
|