Browse Source

feat:参标阶段默认值、明细sql调整及来源处理、日期格式调整

fuwencai 1 year ago
parent
commit
800afae8b2

+ 3 - 0
jyBXCore/rpc/model/mysql/participateStage.go

@@ -80,6 +80,9 @@ func (p *ParStage) UpdateStage() {
 			)
 			lastDate = common.If(cdTime.Unix() > lastDate, cdTime.Unix(), lastDate).(int64)
 			createDate = common.If(cdStr != "", cdStr, createDate).(string)
+			if createDate != "" {
+				createDate = strings.ReplaceAll(createDate, "-", ".")
+			}
 			if ok {
 				contentMap = gconv.Map(content)
 				if contentMap["afterMap"] != nil {

+ 131 - 97
jyBXCore/rpc/service/participateStatistics.go

@@ -669,7 +669,7 @@ func (in *ParticipateStatistics) ProjectDetails(entUserIdArr []string, detailReq
 		return
 	}
 	// 处理数据 补充项目名称、推送表字段 、格式化数据
-	rs := ProjectDetailHandle(*dataList, in.EntId, int(detailReq.PositionId), int(detailReq.PositionType))
+	rs := ProjectDetailHandle(detailReq, *dataList)
 	result = bxcore.DetailData{
 		List:  rs,
 		Total: totalCount,
@@ -679,7 +679,7 @@ func (in *ParticipateStatistics) ProjectDetails(entUserIdArr []string, detailReq
 }
 
 // 这个查询只用查出符合筛选条件的项目id 以及该项目对应的stage
-// 查询类型  0空搜索 全连接 1查左边 连右表查stage 2只查右表 3内连接
+// 查询类型   1查左边 连右表查stage 2只查右表 3内连接
 func GetDetailQuery(isEnt bool, personArrStr string, req *bxcore.ProjectDetailsReq, queryType int) (string, string) {
 	// 处理分页
 	if req.PageNum == 0 || req.PageSize == 0 {
@@ -688,100 +688,116 @@ func GetDetailQuery(isEnt bool, personArrStr string, req *bxcore.ProjectDetailsR
 	}
 	// 这是因为数据库中 0是未参标 1是已参标, 接收参数时和其他默认参数保持一致 0-全部 1 是未参标 2 是已参标
 	req.IsParticipate -= 1
-	if queryType == 0 {
-		// 空搜索调整
-		query1, query2 := []string{}, []string{}
-		query3 := ""
-		//没有传时间,默认时间处理
-		var start = time.Now().AddDate(0, 0, -10)
-		query1 = append(query1, fmt.Sprintf(" a.ymd >= %s ", start.Local().Format("20060102")))
-		query2 = append(query2, fmt.Sprintf(" b.update_date >= '%s' ", start.Local().Format(date.Date_Full_Layout)))
-		if isEnt {
-			//是企业版
-			query1 = append(query1, fmt.Sprintf(" a.ent_user_id in (%s) ", personArrStr))
-			personArr := []string{}
-			personArrStrSplit := strings.Split(personArrStr, ",")
-			for i := 0; i < len(personArrStrSplit); i++ {
-				personArr = append(personArr, fmt.Sprintf(" FIND_IN_SET('%s', b.ent_user_ids)", personArrStrSplit[i]))
-			}
-			if len(personArr) > 0 {
-				personStr := strings.Join(personArr, " or ")
-				query2 = append(query2, fmt.Sprintf(" (%s)", personStr))
-			}
-			query3 = fmt.Sprintf("b.ent_id='%d'", req.EntId) // 连接时右表的条件
-		} else {
-			//不是企业版
-			query1 = append(query1, fmt.Sprintf(" a.position_id = %s ", personArrStr))
-			personArr := []string{}
-			personArrStrSplit := strings.Split(personArrStr, ",")
-			for i := 0; i < len(personArrStrSplit); i++ {
-				personArr = append(personArr, fmt.Sprintf(" FIND_IN_SET('%s', b.position_ids)", personArrStrSplit[i]))
-			}
-			if len(personArr) > 0 {
-				personStr := strings.Join(personArr, " or ")
-				query2 = append(query2, fmt.Sprintf(" (%s)", personStr))
-			}
-			query3 = fmt.Sprintf("b.position_ids='%d'", req.PositionId) // 连接时右表的条件
-		}
-		q := `SELECT A.project_id, B.stage
-				FROM
-				(SELECT DISTINCT(project_id)
-				FROM
-					(SELECT project_id FROM participate_push_statistics a
-					WHERE %s UNION 
-					SELECT project_id
-					FROM participate_stage_statistics b
-					WHERE %s) order by project_id
-				LIMIT %d , %d) A
-                LEFT JOIN
-				participate_stage_statistics B ON A.project_id = B.project_id and  %s` // and 连接前对右表过滤
-		q2 := "select count(project_id) from (select distinct(project_id) from participate_push_statistics a where %s union select project_id from participate_stage_statistics b where %s )"
-		q1Str := strings.Join(query1, " and ")
-		q2Str := strings.Join(query2, " and ")
-		return fmt.Sprintf(q, q1Str, q2Str, (req.PageNum-1)*req.PageSize, req.PageSize, query3), fmt.Sprintf(q2, q1Str, q2Str)
-	}
+	//if queryType == 0 {
+	//	// 空搜索调整
+	//	query1, query2 := []string{}, []string{}
+	//	query3 := ""
+	//	//没有传时间,默认时间处理
+	//	var start = time.Now().AddDate(0, 0, -10)
+	//	query1 = append(query1, fmt.Sprintf(" a.ymd >= %s ", start.Local().Format("20060102")))
+	//	query2 = append(query2, fmt.Sprintf(" b.update_date >= '%s' ", start.Local().Format(date.Date_Full_Layout)))
+	//	if isEnt {
+	//		//是企业版
+	//		query1 = append(query1, fmt.Sprintf(" a.ent_user_id in (%s) ", personArrStr))
+	//		personArr := []string{}
+	//		personArrStrSplit := strings.Split(personArrStr, ",")
+	//		for i := 0; i < len(personArrStrSplit); i++ {
+	//			personArr = append(personArr, fmt.Sprintf(" FIND_IN_SET('%s', b.ent_user_ids)", personArrStrSplit[i]))
+	//		}
+	//		if len(personArr) > 0 {
+	//			personStr := strings.Join(personArr, " or ")
+	//			query2 = append(query2, fmt.Sprintf(" (%s)", personStr))
+	//		}
+	//		query3 = fmt.Sprintf("b.ent_id='%d'", req.EntId) // 连接时右表的条件
+	//	} else {
+	//		//不是企业版
+	//		query1 = append(query1, fmt.Sprintf(" a.position_id = %s ", personArrStr))
+	//		personArr := []string{}
+	//		personArrStrSplit := strings.Split(personArrStr, ",")
+	//		for i := 0; i < len(personArrStrSplit); i++ {
+	//			personArr = append(personArr, fmt.Sprintf(" FIND_IN_SET('%s', b.position_ids)", personArrStrSplit[i]))
+	//		}
+	//		if len(personArr) > 0 {
+	//			personStr := strings.Join(personArr, " or ")
+	//			query2 = append(query2, fmt.Sprintf(" (%s)", personStr))
+	//		}
+	//		query3 = fmt.Sprintf("b.position_ids='%d'", req.PositionId) // 连接时右表的条件
+	//	}
+	//	q := `SELECT A.project_id, B.stage
+	//			FROM
+	//			(SELECT DISTINCT(project_id)
+	//			FROM
+	//				(SELECT project_id FROM participate_push_statistics a
+	//				WHERE %s UNION
+	//				SELECT project_id
+	//				FROM participate_stage_statistics b
+	//				WHERE %s) order by project_id
+	//			LIMIT %d , %d) A
+	//            LEFT JOIN
+	//			participate_stage_statistics B ON A.project_id = B.project_id and  %s` // and 连接前对右表过滤
+	//	q2 := "select count(project_id) from (select distinct(project_id) from participate_push_statistics a where %s union select project_id from participate_stage_statistics b where %s )"
+	//	q1Str := strings.Join(query1, " and ")
+	//	q2Str := strings.Join(query2, " and ")
+	//	return fmt.Sprintf(q, q1Str, q2Str, (req.PageNum-1)*req.PageSize, req.PageSize, query3), fmt.Sprintf(q2, q1Str, q2Str)
+	//}
 	var q, qCount string
 	query := []string{}
 	joinStr := ""
+	particiLeftJoin := ""
 	if queryType == 1 {
 		if isEnt {
 			//是企业版
-			query = append(query, fmt.Sprintf(" a.ent_user_id in (%s) ", personArrStr))
-			joinStr = "and a.ent_id = b.ent_id"
+			query = append(query, fmt.Sprintf(" pps.ent_user_id in (%s) ", personArrStr))
+			joinStr = fmt.Sprintf("and pss.ent_id = %d", req.EntId)
 		} else {
-			query = append(query, fmt.Sprintf(" a.position_id = %s ", personArrStr))
+			query = append(query, fmt.Sprintf(" pps.position_id = %s ", personArrStr))
 			//不是企业版
-			joinStr = "and a.position_id = b.position_ids"
-		}
-		if req.StartTime == 0 && req.EndTime == 0 {
-			//没有传时间,默认时间处理
-			var start = time.Now().AddDate(0, 0, -30)
-			query = append(query, fmt.Sprintf(" a.ymd >= %s ", start.Local().Format("20060102")))
+			joinStr = fmt.Sprintf("and pss.position_ids =%d", req.PositionId)
 		}
 		if req.StartTime != 0 {
-			query = append(query, fmt.Sprintf(" a.ymd >= %d ", req.StartTime))
+			query = append(query, fmt.Sprintf(" pps.ymd >= %d ", req.StartTime))
 		}
 		if req.EndTime != 0 {
-			query = append(query, fmt.Sprintf(" a.ymd <= %d ", req.EndTime))
+			query = append(query, fmt.Sprintf(" pps.ymd <= %d ", req.EndTime))
+		}
+		if req.StartTime == 0 && req.EndTime == 0 {
+			//没有传时间,默认时间处理
+			var start = time.Now().AddDate(0, 0, -30)
+			query = append(query, fmt.Sprintf(" pps.ymd >= %s ", start.Local().Format("20060102")))
 		}
 		// 标讯/项目来源
 		if len(req.Source) > 0 {
 			sourceArr := []string{}
 			for i := 0; i < len(req.Source); i++ {
 				if req.Source[i] == 0 {
-					sourceArr = append(sourceArr, "NOT FIND_IN_SET('3', a.source)")
+					sourceArr = append(sourceArr, "NOT FIND_IN_SET('3', pps.source)")
 				} else {
-					sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', a.source)", req.Source[i]))
+					sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', pps.source)", req.Source[i]))
 				}
 			}
 			query = append(query, fmt.Sprintf(" (%s) ", strings.Join(sourceArr, " or ")))
 		}
 		//参标状态:-1全部,0未参标、1已参标
 		if req.IsParticipate != -1 {
-			query = append(query, " (b.project_id is null or b.is_participate=0)")
+			query = append(query, " (pss.project_id is null or pss.is_participate=0)")
+			particiLeftJoin = fmt.Sprintf(" left join participate_stage_statistics pss on  (pps.project_id=pss.project_id  %s)", joinStr)
 		}
-		q = "select distinct(a.project_id),b.stage,a.ymd,b.update_date   from participate_push_statistics a left join participate_stage_statistics b on(a.project_id=b.project_id %s ) where %s order by a.ymd desc,b.update_date desc"
-		qCount = "select count(distinct(a.project_id))   from participate_push_statistics a left join participate_stage_statistics b on(a.project_id=b.project_id %s) where %s"
+		q = `select A.project_id, pss.stage from (SELECT project_id, MAX(ymd) as max_ymd
+			FROM (
+				SELECT DISTINCT pps.project_id, pps.ymd
+				FROM participate_push_statistics pps %s
+				WHERE %s
+			) AS subquery
+			GROUP BY project_id
+			ORDER BY max_ymd ,project_id DESC limit %d,%d) A left join participate_stage_statistics pss on (A.project_id=pss.project_id  %s);`
+		qCount = `SELECT 
+					COUNT(DISTINCT (pps.project_id))
+				  FROM
+					participate_push_statistics pps
+					   %s where %s`
+		q = fmt.Sprintf(q, particiLeftJoin, strings.Join(query, " and "), (req.PageNum-1)*req.PageSize, req.PageSize, joinStr)
+		qCount = fmt.Sprintf(qCount, particiLeftJoin, strings.Join(query, " and "))
+		return q, qCount
 	} else if queryType == 2 {
 		if isEnt {
 			//是企业版
@@ -890,7 +906,7 @@ func GetDetailQuery(isEnt bool, personArrStr string, req *bxcore.ProjectDetailsR
 			bidEnd := date.FormatDate(&bidEnd_, date.Date_Full_Layout)
 			query = append(query, fmt.Sprintf("b.update_date <= '%s'", bidEnd))
 		}
-		q = "select distinct(a.project_id),b.stage,a.ymd,b.update_date   from participate_push_statistics a inner join  participate_stage_statistics b on(b.project_id=a.project_id %s) where %s order by a.ymd desc,b.update_date desc"
+		q = "select distinct(a.project_id),b.stage,b.update_date   from participate_push_statistics a inner join  participate_stage_statistics b on(b.project_id=a.project_id %s) where %s order by  b.update_date desc"
 		qCount = "select count(distinct(a.project_id))   from participate_push_statistics a inner join participate_stage_statistics b on(b.project_id=a.project_id %s) where %s"
 	}
 	if len(query) > 0 {
@@ -908,7 +924,7 @@ type PushInfoStruct struct {
 	IsDistribute int
 }
 
-func ProjectDetailHandle(dataList []map[string]interface{}, entId int64, positionId, positionType int) []*bxcore.ProjectDetailData {
+func ProjectDetailHandle(req *bxcore.ProjectDetailsReq, dataList []map[string]interface{}) []*bxcore.ProjectDetailData {
 	//dataList 里面包含 项目id、各阶段信息
 	// 处理项目名称
 	projectIdList := []string{}
@@ -926,7 +942,7 @@ func ProjectDetailHandle(dataList []map[string]interface{}, entId int64, positio
 		}
 	}
 	// 获取推送最新状态
-	newPushInfo := getNewPushInfo(projectIdList, int(entId), positionId, positionType)
+	newPushInfo := getNewPushInfo(projectIdList, req)
 	newPushInfoMap := map[string]PushInfoStruct{}
 	// 处理推送最新状态
 	if newPushInfo != nil && len(*newPushInfo) > 0 {
@@ -951,14 +967,18 @@ func ProjectDetailHandle(dataList []map[string]interface{}, entId int64, positio
 		// 处理推送表相关字段
 		if pushInfo_, ok := newPushInfoMap[projectId]; ok {
 			sourceStr := []string{}
+			sourceExist := map[string]struct{}{}
 			if pushInfo_.Source != "" {
 				isDistribute_ = "未分发"
 				sourceSplit := strings.Split(pushInfo_.Source, ",")
 				for j := 0; j < len(sourceSplit); j++ {
+					if _, ok := sourceExist[sourceSplit[j]]; ok {
+						continue
+					}
+					sourceExist[sourceSplit[j]] = struct{}{}
 					if sourceSplit[j] == "3" {
 						isDistribute_ = "已分发"
 					}
-
 					if sourceName, ok := SourceMap[sourceSplit[j]]; ok {
 						sourceStr = append(sourceStr, sourceName)
 					}
@@ -970,14 +990,13 @@ func ProjectDetailHandle(dataList []map[string]interface{}, entId int64, positio
 			tmp.DisDate = pushInfo_.DisDate
 		} //
 		// 处理阶段勾选信息和参标、终止参标信息
-
-		if dataList[i]["stage"] != nil {
-			s := common.ObjToString(dataList[i]["stage"])
-			err := json.Unmarshal([]byte(strings.Replace(s, "'", "\"", -1)), &tmp.Stage)
-			if err != nil {
-				log.Println("stage 反序列失败", err)
-			}
-
+		s := common.ObjToString(dataList[i]["stage"])
+		if s == "" {
+			s = `[{"name":"参标状态","value":"-","date":""},{"name":"投标类型","value":"-","date":""},{"name":"已报名(阶段)","value":"-","date":""},{"name":"投标决策(阶段)","value":"-","date":""},{"name":"编制投标文件(阶段)","value":"-","date":""},{"name":"递交投标文件(阶段)","value":"-","date":""},{"name":"中标公示(阶段)","value":"-","date":""},{"name":"签合同(阶段)","value":"已完成","date":""},{"name":"已结束","value":"-","date":""},{"name":"终止参标","value":"-","date":""}]`
+		}
+		err := json.Unmarshal([]byte(strings.Replace(s, "'", "\"", -1)), &tmp.Stage)
+		if err != nil {
+			log.Println("stage 反序列失败", err)
 		}
 		tmp.Id = encrypt.EncodeArticleId2ByCheck(projectId)
 		results = append(results, &tmp)
@@ -986,35 +1005,50 @@ func ProjectDetailHandle(dataList []map[string]interface{}, entId int64, positio
 }
 
 // 获取项目的最新推送状态信息
-func getNewPushInfo(projectIds []string, entId int, positionId int, positionType int) *[]map[string]interface{} {
-	s := ""
-	if positionType == 0 {
-		s = fmt.Sprintf("position_id=%d", positionId)
+func getNewPushInfo(projectIds []string, req *bxcore.ProjectDetailsReq) *[]map[string]interface{} {
+	q := []string{}
+	if req.PositionType == 0 {
+		q = append(q, fmt.Sprintf("position_id=%d", req.PositionId))
 	} else {
-		s = fmt.Sprintf("ent_id=%d", entId)
+		q = append(q, fmt.Sprintf("ent_id=%d", req.EntId))
+	}
+	if req.StartTime == 0 && req.EndTime == 0 {
+		//没有传时间,默认时间处理
+		var start = time.Now().AddDate(0, 0, -30)
+		q = append(q, fmt.Sprintf(" ymd >= %s ", start.Local().Format("20060102")))
 	}
+	if req.StartTime != 0 {
+		q = append(q, fmt.Sprintf(" ymd >= %d ", req.StartTime))
+
+	}
+	if req.EndTime != 0 {
+		q = append(q, fmt.Sprintf(" ymd <= %d ", req.EndTime))
+
+	}
+	s := strings.Join(q, " and ")
 	sql := `
 SELECT 
-    A.project_id, A.source,DATE_FORMAT(A.visit_date,'%%Y-%%m-%%d') as visit_date, DATE_FORMAT(A.dis_date,'%%Y-%%m-%%d') as dis_date,A.id,A.ymd,B.ymd
-FROM  participate_push_statistics A inner join (SELECT 
-            project_id,MAX(ymd) as ymd
-        FROM
-            participate_push_statistics
+     project_id,
+  GROUP_CONCAT(distinct(source)) ,
+    DATE_FORMAT(min(visit_date), '%%Y-%%m-%%d') AS visit_date,
+  DATE_FORMAT( min(dis_date), '%%Y-%%m-%%d') AS dis_date
+FROM  participate_push_statistics 
         WHERE
             %s
             AND project_id IN ( "` + strings.Join(projectIds, "\",\"") + `" )
-        GROUP BY project_id) B  on (A.project_id=B.project_id and A.ymd=b.ymd) and  A.%s
+        GROUP BY project_id
 `
-	query := fmt.Sprintf(sql, s, s)
+
+	query := fmt.Sprintf(sql, s)
 	return IC.BaseMysql.SelectBySql(query)
 }
 
-// GetQueryType 查询类型  0空搜索  1查左边 连右表查stage 2只查右表 3内连接
+// GetQueryType 查询类型    1查左边 连右表查stage 2只查右表 3内连接
 // IsParticipate 接收参数时 0 全部 1 未参标 2已参标  数据库中 未参标是0
 func GetQueryType(in *bxcore.ProjectDetailsReq) int {
-	//
+	// 空搜索  查左边  加时间范围
 	if in.BidUpdateStartTime == 0 && in.BidUpdateEndTime == 0 && in.StartTime == 0 && in.EndTime == 0 && in.IsParticipate == 0 && in.BidWay == 0 && len(in.Source) == 0 {
-		return 0
+		return 1
 	}
 	if in.IsParticipate == 1 {
 		// 未参标只筛选推送表 右表条件无效