瀏覽代碼

feat:模块计算优化2

wangshan 1 年之前
父節點
當前提交
e94c54ac75
共有 3 個文件被更改,包括 324 次插入120 次删除
  1. 300 96
      internal/dao/internal/userTask.go
  2. 18 18
      internal/model/entity/result.go
  3. 6 6
      utility/userTask.go

+ 300 - 96
internal/dao/internal/userTask.go

@@ -217,27 +217,27 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 		//项目信息结果时间在原始查询条件范围内
 		if utility.DateIsIn(ut.StartTime, ut.EndTime, pt.JgTime, 0) {
 			if pt.Buyer != "" {
-				scale.MarketProfile.Buyercount += 1
+				scale.MarketProfile.Buyercount++
 			}
-			scale.MarketProfile.ProjectCount += 1
+			scale.MarketProfile.ProjectCount++
 			if pt.Winners != "" {
 				scale.MarketProfile.Winnercount += len(strings.Split(pt.Winners, ","))
 			}
 			scale.MarketProfile.Projctamout += pt.Sortprice
-			scale.MarketProfile.Projectavgmoney = utility.Sequential(scale.MarketProfile.Projctamout, float64(scale.MarketProfile.ProjectCount)) //项目平均金额(万)
+			scale.MarketProfile.Projectavgmoney = utility.Formula(scale.MarketProfile.Projctamout, float64(scale.MarketProfile.ProjectCount)) //项目平均金额(万)
 		}
 		//是否需要进行环比
 		if ut.IsRatio {
-			scale.ProjectInfoAll.ProjectCount += 1
+			scale.ProjectInfoAll.ProjectCount++
 			scale.ProjectInfoAll.Projctamout += pt.Sortprice
 			if pt.Buyer != "" {
-				scale.ProjectInfoAll.Buyercount += 1
+				scale.ProjectInfoAll.Buyercount++
 			}
 			if pt.Winners != "" {
 				scale.ProjectInfoAll.Winnercount += len(strings.Split(pt.Winners, ","))
 			}
 			//项目平均金额(万)
-			scale.ProjectInfoAll.Projectavgmoney = utility.Sequential(scale.ProjectInfoAll.Projctamout, float64(scale.ProjectInfoAll.ProjectCount))
+			scale.ProjectInfoAll.Projectavgmoney = utility.Formula(scale.ProjectInfoAll.Projctamout, float64(scale.ProjectInfoAll.ProjectCount))
 			//采购单位项目数量环比
 			scale.MarketProfile.BuyercountRatio = utility.Sequential(float64(scale.MarketProfile.Buyercount), float64(scale.ProjectInfoAll.Buyercount))
 			//项目金额环比
@@ -258,7 +258,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 				eDCount.Minth = mdv.Key
 				if utility.DateIsIn(mdv.From, mdv.To, pt.JgTime, 0) {
 					eDAmount.Value += pt.Sortprice
-					eDCount.Value += 1
+					eDCount.Value++
 					if ut.IsRatio && mdk > 0 {
 						//计算环比
 						eDAmount.Ratio = utility.Sequential(eDAmount.Value, scale.MonthDistribution.ProjectAmount[mdk-1].Value)
@@ -278,7 +278,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 				eDCount.Minth = ydv.Key
 				if utility.DateIsIn(ydv.From, ydv.To, pt.JgTime, 0) {
 					eDAmount.Value += pt.Sortprice
-					eDCount.Value += 1
+					eDCount.Value++
 					if ut.IsRatio && ydk > 0 {
 						//计算环比
 						eDAmount.Ratio = utility.Sequential(eDAmount.Value, scale.YearDistribution.ProjectAmount[ydk-1].Value)
@@ -301,6 +301,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 				entIdList = pt.Entidlist
 			)
 			if len(pt.Entidlist) > 0 {
+				//加密
 				for _, entId := range pt.Entidlist {
 					entIdList = append(entIdList, utility.EncodeId(entId))
 				}
@@ -334,7 +335,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 		}()
 		//地区分布
 		var areaInfoFunc = func() {
-			areaInfoKey := utility.GetJudgmentPrevKey(consts.JudgmentPrev1, pt.Area)
+			areaInfoKey := utility.GetJudgmentPrevKey(consts.JudgmentPrev0, pt.Area)
 			cityInfoKey := utility.GetJudgmentPrevKey(consts.JudgmentPrev1, fmt.Sprintf("%s_%s", pt.Area, pt.City))
 			if !ut.JudgmentMap[areaInfoKey] {
 				ut.JudgmentMap[areaInfoKey] = true
@@ -352,27 +353,45 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 					Total: 1,
 				})
 			} else {
+				var (
+					wc       = make(chan bool, common.If(len(pad.AreaInfos) > 10, consts.JudgmentPrev3, 1).(int))
+					wg       = &sync.WaitGroup{}
+					stopLoop = false
+				)
 				for _, ai := range pad.AreaInfos {
-					if ai.Area == pt.Area {
-						if !ut.JudgmentMap[cityInfoKey] {
-							ut.JudgmentMap[cityInfoKey] = true
-							ai.AreaDetails = append(ai.AreaDetails, &entity.AreaDetailsS{
-								Amount: pt.Sortprice,
-								City:   pt.City,
-								Total:  1,
-							})
-						} else {
-							for _, ci := range ai.AreaDetails {
-								if ci.City == pt.City {
-									ci.Amount += pt.Sortprice
-									ci.Total += 1
-									break
+					if stopLoop {
+						break
+					}
+					wc <- true
+					wg.Add(1)
+					go func(ai *entity.AreaInfosS) {
+						defer func() {
+							wg.Done()
+							<-wc
+						}()
+						if ai.Area == pt.Area {
+							stopLoop = true
+							if !ut.JudgmentMap[cityInfoKey] {
+								ut.JudgmentMap[cityInfoKey] = true
+								ai.AreaDetails = append(ai.AreaDetails, &entity.AreaDetailsS{
+									Amount: pt.Sortprice,
+									City:   pt.City,
+									Total:  1,
+								})
+							} else {
+								for _, ci := range ai.AreaDetails {
+									if ci.City == pt.City {
+										ci.Amount += pt.Sortprice
+										ci.Total++
+										break
+									}
 								}
 							}
+							return
 						}
-						break
-					}
+					}(ai)
 				}
+				wg.Wait()
 			}
 		}
 		areaInfoFunc()
@@ -394,7 +413,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 						}
 					} else {
 						pad.CustomerScaleOther.Amount += pt.Sortprice
-						pad.CustomerScaleOther.Total += 1
+						pad.CustomerScaleOther.Total++
 					}
 				} else {
 					//客户分布
@@ -406,13 +425,31 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 							Total:    1,
 						})
 					} else {
+						var (
+							wc       = make(chan bool, common.If(len(pad.CustomerScale) > 10, consts.JudgmentPrev3, 1).(int))
+							wg       = &sync.WaitGroup{}
+							stopLoop = false
+						)
 						for _, csm := range pad.CustomerScale {
-							if csm.Buyclass == bc {
-								csm.Amount += pt.Sortprice
-								csm.Total += 1
+							if stopLoop {
 								break
 							}
+							wc <- true
+							wg.Add(1)
+							go func(csm *entity.CustomerScaleS) {
+								defer func() {
+									wg.Done()
+									<-wc
+								}()
+								if csm.Buyclass == bc {
+									stopLoop = true
+									csm.Amount += pt.Sortprice
+									csm.Total++
+									return
+								}
+							}(csm)
 						}
+						wg.Wait()
 					}
 				}
 				top3Key := utility.GetJudgmentPrevKey(consts.JudgmentPrev3, fmt.Sprintf("%s_top3", bc))
@@ -436,28 +473,45 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 					//项目数量TOP3客户类型的重点中标单位
 					for _, sbct := range pad.ScaleBuyclassCountTop {
 						if sbct.Name == bc {
-							sbct.BuyclassCount += 1
+							sbct.BuyclassCount++
 							sbct.BuyclassScale = utility.Formula(float64(sbct.BuyclassCount), float64(scale.MarketProfile.ProjectCount))
 							if len(sbct.Winner) > 0 {
 								var (
 									wnMap     = map[string]int{}
 									winners   = strings.Split(pt.Winners, ",")
 									winnerNum int
+
+									wc       = make(chan bool, common.If(len(sbct.Winner) > 10, consts.JudgmentPrev3, 1).(int))
+									wg       = &sync.WaitGroup{}
+									stopLoop = false
 								)
 								for wi, wn := range sbct.Winner {
-									if strings.Contains(pt.Winners, wn.Winner) {
-										winnerNum++
-										wnMap[wn.Winner] = wi + 1
-									}
-									if winnerNum == len(winners) {
+									if stopLoop {
 										break
 									}
+									wc <- true
+									wg.Add(1)
+									go func(wn *entity.WinnerTotalS, wi int) {
+										defer func() {
+											wg.Done()
+											<-wc
+										}()
+										if strings.Contains(pt.Winners, wn.Winner) {
+											winnerNum++
+											wnMap[wn.Winner] = wi + 1
+										}
+										if winnerNum == len(winners) {
+											stopLoop = true
+											return
+										}
+									}(wn, wi)
 								}
+								wg.Wait()
 								for wk, wd := range winners {
 									if wnMap[wd] > 0 {
-										sbct.Winner[wnMap[wd]-1].WinnerTotal += 1
+										sbct.Winner[wnMap[wd]-1].WinnerTotal++
 									} else {
-										sbct.Winner = append(sbct.Winner, &entity.WinnerTotal{
+										sbct.Winner = append(sbct.Winner, &entity.WinnerTotalS{
 											Id:          common.If(len(pt.Entidlist) > wk, encrypt.EncodeArticleId2ByCheck(pt.Entidlist[wk]), "").(string),
 											Winner:      wd,
 											WinnerTotal: 1,
@@ -476,6 +530,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 									sbct.Winner = sbct.Winner[:consts.Top3]
 								}
 							}
+							break
 						}
 					}
 					/*-------------排序----------------*/
@@ -497,21 +552,37 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 									wnMap     = map[string]int{}
 									winners   = strings.Split(pt.Winners, ",")
 									winnerNum int
+									wc        = make(chan bool, common.If(len(sbat.Winner) > 10, consts.JudgmentPrev3, 1).(int))
+									wg        = &sync.WaitGroup{}
+									stopLoop  = false
 								)
 								for wi, wn := range sbat.Winner {
-									if strings.Contains(pt.Winners, wn.Winner) {
-										winnerNum++
-										wnMap[wn.Winner] = wi + 1
-									}
-									if winnerNum == len(winners) {
+									if stopLoop {
 										break
 									}
+									wc <- true
+									wg.Add(1)
+									go func(wn *entity.WinnerAmountS, wi int) {
+										defer func() {
+											wg.Done()
+											<-wc
+										}()
+										if strings.Contains(pt.Winners, wn.Winner) {
+											winnerNum++
+											wnMap[wn.Winner] = wi + 1
+										}
+										if winnerNum == len(winners) {
+											stopLoop = true
+											return
+										}
+									}(wn, wi)
 								}
+								wg.Wait()
 								for wk, wd := range winners {
 									if wnMap[wd] > 0 {
 										sbat.Winner[wnMap[wd]-1].WinnerAmount += pt.Sortprice
 									} else {
-										sbat.Winner = append(sbat.Winner, &entity.WinnerAmount{
+										sbat.Winner = append(sbat.Winner, &entity.WinnerAmountS{
 											Id:           common.If(len(pt.Entidlist) > wk, encrypt.EncodeArticleId2ByCheck(pt.Entidlist[wk]), "").(string),
 											Winner:       wd,
 											WinnerAmount: pt.Sortprice,
@@ -566,7 +637,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 			} else {
 				for _, ps := range pad.ProjectScale {
 					if ps.Name == psk {
-						ps.Count += 1
+						ps.Count++
 						ps.Amount += pt.Sortprice
 						ps.PersentC = utility.Formula(ps.Amount, scale.MarketProfile.Projctamout)
 						ps.PersentA = utility.Formula(float64(ps.Count), float64(scale.MarketProfile.ProjectCount))
@@ -608,21 +679,37 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 								wnMap     = map[string]int{}
 								winners   = strings.Split(pt.Winners, ",")
 								winnerNum int
+								wc        = make(chan bool, common.If(len(saat.Winner) > 10, consts.JudgmentPrev3, 1).(int))
+								wg        = &sync.WaitGroup{}
+								stopLoop  = false
 							)
 							for wi, wn := range saat.Winner {
-								if strings.Contains(pt.Winners, wn.Winner) {
-									winnerNum++
-									wnMap[wn.Winner] = wi + 1
-								}
-								if winnerNum == len(winners) {
+								if stopLoop {
 									break
 								}
+								wc <- true
+								wg.Add(1)
+								go func(wn *entity.WinnerAmountS, wi int) {
+									defer func() {
+										wg.Done()
+										<-wc
+									}()
+									if strings.Contains(pt.Winners, wn.Winner) {
+										winnerNum++
+										wnMap[wn.Winner] = wi + 1
+									}
+									if winnerNum == len(winners) {
+										stopLoop = true
+										return
+									}
+								}(wn, wi)
 							}
+							wg.Wait()
 							for wk, wd := range winners {
 								if wnMap[wd] > 0 {
 									saat.Winner[wnMap[wd]-1].WinnerAmount += pt.Sortprice
 								} else {
-									saat.Winner = append(saat.Winner, &entity.WinnerAmount{
+									saat.Winner = append(saat.Winner, &entity.WinnerAmountS{
 										Id:           common.If(len(pt.Entidlist) > wk, encrypt.EncodeArticleId2ByCheck(pt.Entidlist[wk]), "").(string),
 										Winner:       wd,
 										WinnerAmount: pt.Sortprice,
@@ -655,28 +742,44 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 				//项目数量---TOP3地区的重点中标单位
 				for _, sact := range pad.ScaleAreaCountTop {
 					if sact.Name == pt.Area {
-						sact.AreaCount += 1
+						sact.AreaCount++
 						sact.AreaScale = utility.Formula(float64(sact.AreaCount), scale.MarketProfile.Projctamout)
 						if len(sact.Winner) > 0 {
 							var (
 								wnMap     = map[string]int{}
 								winners   = strings.Split(pt.Winners, ",")
 								winnerNum int
+								wc        = make(chan bool, common.If(len(sact.Winner) > 10, consts.JudgmentPrev3, 1).(int))
+								wg        = &sync.WaitGroup{}
+								stopLoop  = false
 							)
 							for wi, wn := range sact.Winner {
-								if strings.Contains(pt.Winners, wn.Winner) {
-									winnerNum++
-									wnMap[wn.Winner] = wi + 1
-								}
-								if winnerNum == len(winners) {
+								if stopLoop {
 									break
 								}
+								wc <- true
+								wg.Add(1)
+								go func(wn *entity.WinnerTotalS, wi int) {
+									defer func() {
+										wg.Done()
+										<-wc
+									}()
+									if strings.Contains(pt.Winners, wn.Winner) {
+										winnerNum++
+										wnMap[wn.Winner] = wi + 1
+									}
+									if winnerNum == len(winners) {
+										stopLoop = true
+										return
+									}
+								}(wn, wi)
 							}
+							wg.Wait()
 							for wk, wd := range winners {
 								if wnMap[wd] > 0 {
-									sact.Winner[wnMap[wd]-1].WinnerTotal += 1
+									sact.Winner[wnMap[wd]-1].WinnerTotal++
 								} else {
-									sact.Winner = append(sact.Winner, &entity.WinnerTotal{
+									sact.Winner = append(sact.Winner, &entity.WinnerTotalS{
 										Id:          common.If(len(pt.Entidlist) > wk, encrypt.EncodeArticleId2ByCheck(pt.Entidlist[wk]), "").(string),
 										Winner:      wd,
 										WinnerTotal: 1,
@@ -746,10 +849,10 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 							TopList: utility.GetWinnerInfoTopList(pt, pt.Sortprice, scale.MarketProfile.Projctamout),
 						})
 					} else {
-						//订阅分类
+						//订阅分类  300+
 						for _, sra := range sr.ScaleRefineAll {
 							if sra.Name == itemName {
-								sra.Total += 1
+								sra.Total++
 								sra.Amount += pt.Sortprice
 								break
 							}
@@ -757,26 +860,43 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 						//重点中标单位-项目数量
 						for _, srtt := range sr.ScaleRefineTotalTop {
 							if srtt.Name == itemName {
-								srtt.Value += 1
+								srtt.Value++
 								srtt.Prop = utility.Formula(float64(srtt.Value), float64(scale.MarketProfile.ProjectCount))
 								if len(srtt.TopList) > 0 {
 									var (
 										wnMap     = map[string]int{}
 										winners   = strings.Split(pt.Winners, ",")
 										winnerNum int
+										wc        = make(chan bool, common.If(len(srtt.TopList) > 10, consts.JudgmentPrev3, 1).(int))
+										wg        = &sync.WaitGroup{}
+										stopLoop  = false
 									)
 									for wi, wn := range srtt.TopList {
-										if strings.Contains(pt.Winners, wn.Name) {
-											winnerNum++
-											wnMap[wn.Name] = wi + 1
-										}
-										if winnerNum == len(winners) {
+										if stopLoop {
 											break
 										}
+										wc <- true
+										wg.Add(1)
+										go func(wn *entity.TopListS, wi int) {
+											defer func() {
+												wg.Done()
+												<-wc
+											}()
+
+											if strings.Contains(pt.Winners, wn.Name) {
+												winnerNum++
+												wnMap[wn.Name] = wi + 1
+											}
+											if winnerNum == len(winners) {
+												stopLoop = true
+												return
+											}
+										}(wn, wi)
 									}
+									wg.Wait()
 									for wk, wd := range winners {
 										if wnMap[wd] > 0 {
-											srtt.TopList[wnMap[wd]-1].Value += 1
+											srtt.TopList[wnMap[wd]-1].Value++
 											srtt.TopList[wnMap[wd]-1].Prop = utility.Formula(srtt.TopList[wnMap[wd]-1].Value, float64(scale.MarketProfile.ProjectCount))
 										} else {
 											srtt.TopList = append(srtt.TopList, &entity.TopListS{
@@ -811,16 +931,32 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 										wnMap     = map[string]int{}
 										winners   = strings.Split(pt.Winners, ",")
 										winnerNum int
+										wc        = make(chan bool, common.If(len(srat.TopList) > 10, consts.JudgmentPrev3, 1).(int))
+										wg        = &sync.WaitGroup{}
+										stopLoop  = false
 									)
 									for wi, wn := range srat.TopList {
-										if strings.Contains(pt.Winners, wn.Name) {
-											winnerNum++
-											wnMap[wn.Name] = wi + 1
-										}
-										if winnerNum == len(winners) {
+										if stopLoop {
 											break
 										}
+										wc <- true
+										wg.Add(1)
+										go func(wn *entity.TopListS, wi int) {
+											defer func() {
+												wg.Done()
+												<-wc
+											}()
+											if strings.Contains(pt.Winners, wn.Name) {
+												winnerNum++
+												wnMap[wn.Name] = wi + 1
+											}
+											if winnerNum == len(winners) {
+												stopLoop = true
+												return
+											}
+										}(wn, wi)
 									}
+									wg.Wait()
 									for wk, wd := range winners {
 										if wnMap[wd] > 0 {
 											srat.TopList[wnMap[wd]-1].Value += pt.Sortprice
@@ -882,7 +1018,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 				//项目数量TOP30采购单位及其重点合作中标单位
 				for _, bct := range baw.BuyerCountTop3 {
 					if bct.Name == pt.Buyer {
-						bct.Number += 1
+						bct.Number++
 						if len(bct.Winnertop3) == 0 {
 							bct.Winnertop3 = utility.GetWinnerInfoOfBuyerCount(pt)
 						} else {
@@ -890,19 +1026,35 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 								wnMap     = map[string]int{}
 								winners   = strings.Split(pt.Winners, ",")
 								winnerNum int
+								wc        = make(chan bool, common.If(len(bct.Winnertop3) > 10, consts.JudgmentPrev3, 1).(int))
+								wg        = &sync.WaitGroup{}
+								stopLoop  = false
 							)
 							for wi, wn := range bct.Winnertop3 {
-								if strings.Contains(pt.Winners, wn.Name) {
-									winnerNum++
-									wnMap[wn.Name] = wi + 1
-								}
-								if winnerNum == len(winners) {
+								if stopLoop {
 									break
 								}
+								wc <- true
+								wg.Add(1)
+								go func(wn *entity.Winnertop3Number, wi int) {
+									defer func() {
+										wg.Done()
+										<-wc
+									}()
+									if strings.Contains(pt.Winners, wn.Name) {
+										winnerNum++
+										wnMap[wn.Name] = wi + 1
+									}
+									if winnerNum == len(winners) {
+										stopLoop = true
+										return
+									}
+								}(wn, wi)
 							}
+							wg.Wait()
 							for wk, wd := range winners {
 								if wnMap[wd] > 0 {
-									bct.Winnertop3[wnMap[wd]-1].Number += 1
+									bct.Winnertop3[wnMap[wd]-1].Number++
 								} else {
 									bct.Winnertop3 = append(bct.Winnertop3, &entity.Winnertop3Number{
 										Id:     common.If(len(pt.Entidlist) > wk, encrypt.EncodeArticleId2ByCheck(pt.Entidlist[wk]), "").(string),
@@ -926,16 +1078,32 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 								wnMap     = map[string]int{}
 								winners   = strings.Split(pt.Winners, ",")
 								winnerNum int
+								wc        = make(chan bool, common.If(len(bat.Winnertop3) > 10, consts.JudgmentPrev3, 1).(int))
+								wg        = &sync.WaitGroup{}
+								stopLoop  = false
 							)
 							for wi, wn := range bat.Winnertop3 {
-								if strings.Contains(pt.Winners, wn.Name) {
-									winnerNum++
-									wnMap[wn.Name] = wi + 1
-								}
-								if winnerNum == len(winners) {
+								if stopLoop {
 									break
 								}
+								wc <- true
+								wg.Add(1)
+								go func(wn *entity.Winnertop3Amount, wi int) {
+									defer func() {
+										wg.Done()
+										<-wc
+									}()
+									if strings.Contains(pt.Winners, wn.Name) {
+										winnerNum++
+										wnMap[wn.Name] = wi + 1
+									}
+									if winnerNum == len(winners) {
+										stopLoop = true
+										return
+									}
+								}(wn, wi)
 							}
+							wg.Wait()
 							for wk, wd := range winners {
 								if wnMap[wd] > 0 {
 									bat.Winnertop3[wnMap[wd]-1].Amount += pt.Sortprice
@@ -952,7 +1120,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 					}
 				}
 			}
-			//采购规模分布
+			//采购规模分布 --7
 			var psk = ""
 			for _, cp := range consts.ProjectScale {
 				if cp.From < pt.Sortprice && common.If(cp.To > 0, cp.To > pt.Sortprice, true).(bool) {
@@ -972,7 +1140,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 			} else {
 				for _, ps := range baw.BuyerTimeDistribution {
 					if ps.Key == psk {
-						ps.Number += 1
+						ps.Number++
 						ps.Amount += pt.Sortprice
 						ps.TotalAmount = utility.Formula(ps.Amount, scale.MarketProfile.Projctamout)
 						ps.TotalNumber = utility.Formula(ps.Number, float64(scale.MarketProfile.ProjectCount))
@@ -1006,19 +1174,37 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 					//项目数量TOP30中标单位及其重点合作采购单位
 					for _, wct := range baw.WinnerCountTop3 {
 						if wct.Name == winner {
-							wct.Number += 1
+							wct.Number++
 							if len(wct.Buyertop3) == 0 {
 								wct.Buyertop3 = utility.GetWinnerInfoOfWinnerCount(pt)
 							} else {
-								var wnMap = map[string]int{}
+								var (
+									wnMap    = map[string]int{}
+									wc       = make(chan bool, common.If(len(wct.Buyertop3) > 10, consts.JudgmentPrev3, 1).(int))
+									wg       = &sync.WaitGroup{}
+									stopLoop = false
+								)
 								for wi, wn := range wct.Buyertop3 {
-									if wn.Name == pt.Buyer {
-										wnMap[wn.Name] = wi + 1
+									if stopLoop {
 										break
 									}
+									wc <- true
+									wg.Add(1)
+									go func(wn *entity.Buyertop3Number, wi int) {
+										defer func() {
+											wg.Done()
+											<-wc
+										}()
+										if wn.Name == pt.Buyer {
+											wnMap[wn.Name] = wi + 1
+											stopLoop = true
+											return
+										}
+									}(wn, wi)
 								}
+								wg.Wait()
 								if wnMap[pt.Buyer] > 0 {
-									wct.Buyertop3[wnMap[pt.Buyer]-1].Number += 1
+									wct.Buyertop3[wnMap[pt.Buyer]-1].Number++
 								} else {
 									wct.Buyertop3 = append(wct.Buyertop3, &entity.Buyertop3Number{
 										Name:   pt.Buyer,
@@ -1036,12 +1222,31 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 							if len(wat.Buyertop3) == 0 {
 								wat.Buyertop3 = utility.GetWinnerInfoOfWinnerAmount(pt)
 							} else {
-								var wnMap = map[string]int{}
+								var (
+									wnMap    = map[string]int{}
+									wc       = make(chan bool, common.If(len(wat.Buyertop3) > 10, consts.JudgmentPrev3, 1).(int))
+									wg       = &sync.WaitGroup{}
+									stopLoop = false
+								)
 								for wi, wn := range wat.Buyertop3 {
-									if wn.Name == pt.Buyer {
-										wnMap[wn.Name] = wi + 1
+									if stopLoop {
+										break
 									}
+									wc <- true
+									wg.Add(1)
+									go func(wn *entity.Buyertop3Amount, wi int) {
+										defer func() {
+											wg.Done()
+											<-wc
+										}()
+										if wn.Name == pt.Buyer {
+											wnMap[wn.Name] = wi + 1
+											stopLoop = true
+											return
+										}
+									}(wn, wi)
 								}
+								wg.Wait()
 								if wnMap[pt.Buyer] > 0 {
 									wat.Buyertop3[wnMap[pt.Buyer]-1].Amount += pt.Sortprice
 								} else {
@@ -1076,7 +1281,7 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 			} else {
 				for _, ps := range baw.WinnerTimeDistribution {
 					if ps.Key == psk {
-						ps.Number += 1
+						ps.Number++
 						ps.Amount += pt.Sortprice
 						ps.TotalAmount = utility.Formula(ps.Amount, scale.MarketProfile.Projctamout)
 						ps.TotalNumber = utility.Formula(ps.Number, float64(scale.MarketProfile.ProjectCount))
@@ -1100,7 +1305,6 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
 	}
 	scaleFunc()
 	nextFunc()
-
 }
 
 // ResultSave  结果保存

+ 18 - 18
internal/model/entity/result.go

@@ -93,7 +93,7 @@ type ProjectScaleS struct {
 }
 
 // 中标单位信息-金额
-type WinnerAmount struct {
+type WinnerAmountS struct {
 	Id           string  `json:"id"`            //中标单位id
 	Winner       string  `json:"winner"`        //中标单位名称
 	WinnerAmount float64 `json:"winner_amount"` //中标单位中标金额
@@ -101,14 +101,14 @@ type WinnerAmount struct {
 
 // 项目金额TOP3地区的重点中标单位
 type ScaleAreaAmountTopS struct {
-	AreaAmount float64         `json:"area_amount"` //地区总金额
-	AreaScale  float64         `json:"area_scale"`  //地区环比
-	Name       string          `json:"name"`        //省份
-	Winner     []*WinnerAmount `json:"winner"`      //中标单位信息
+	AreaAmount float64          `json:"area_amount"` //地区总金额
+	AreaScale  float64          `json:"area_scale"`  //地区环比
+	Name       string           `json:"name"`        //省份
+	Winner     []*WinnerAmountS `json:"winner"`      //中标单位信息
 }
 
 // 中标单位信息-项目数量
-type WinnerTotal struct {
+type WinnerTotalS struct {
 	Id          string `json:"id"`           //中标企业id
 	Winner      string `json:"winner"`       //中标企业名称
 	WinnerTotal int    `json:"winner_total"` //中标项目数量
@@ -116,26 +116,26 @@ type WinnerTotal struct {
 
 // 项目数量TOP3地区的重点中标单位
 type ScaleAreaCountTopS struct {
-	AreaCount int            `json:"area_count"` //项目数量
-	AreaScale float64        `json:"area_scale"` //项目数量占比
-	Name      string         `json:"name"`       //城市
-	Winner    []*WinnerTotal `json:"winner"`     //中标企业集合
+	AreaCount int             `json:"area_count"` //项目数量
+	AreaScale float64         `json:"area_scale"` //项目数量占比
+	Name      string          `json:"name"`       //城市
+	Winner    []*WinnerTotalS `json:"winner"`     //中标企业集合
 }
 
 // 项目金额TOP3客户类型的重点中标单位
 type ScaleBuyclassAmountTopS struct {
-	BuyclassAmount float64         `json:"buyclass_amount"` //采购单位类型总金额
-	BuyclassScale  float64         `json:"buyclass_scale"`  //采购单位类型金额占比
-	Name           string          `json:"name"`            //采购单位类型名称
-	Winner         []*WinnerAmount `json:"winner"`          //中标企业集合
+	BuyclassAmount float64          `json:"buyclass_amount"` //采购单位类型总金额
+	BuyclassScale  float64          `json:"buyclass_scale"`  //采购单位类型金额占比
+	Name           string           `json:"name"`            //采购单位类型名称
+	Winner         []*WinnerAmountS `json:"winner"`          //中标企业集合
 }
 
 // 项目数量TOP3客户类型的重点中标单位
 type ScaleBuyclassCountTopS struct {
-	BuyclassCount int            `json:"buyclass_count"` //采购单位项目数量
-	BuyclassScale float64        `json:"buyclass_scale"` //采购单位数量环比
-	Name          string         `json:"name"`           //采购单位名称
-	Winner        []*WinnerTotal `json:"winner"`         //中标企业集合
+	BuyclassCount int             `json:"buyclass_count"` //采购单位项目数量
+	BuyclassScale float64         `json:"buyclass_scale"` //采购单位数量环比
+	Name          string          `json:"name"`           //采购单位名称
+	Winner        []*WinnerTotalS `json:"winner"`         //中标企业集合
 }
 type MarketProjectAllData struct {
 	//地区分布

+ 6 - 6
utility/userTask.go

@@ -186,11 +186,11 @@ func EncodeId(sid string) string {
 }
 
 // 项目金额---TOP3地区的重点中标单位
-func GetWinnerInfoOfAmount(pt *entity.ProjectInfo) []*entity.WinnerAmount {
-	var winnerAmount []*entity.WinnerAmount
+func GetWinnerInfoOfAmount(pt *entity.ProjectInfo) []*entity.WinnerAmountS {
+	var winnerAmount []*entity.WinnerAmountS
 	if pt.Winners != "" {
 		for k, w := range strings.Split(pt.Winners, ",") {
-			winnerAmount = append(winnerAmount, &entity.WinnerAmount{
+			winnerAmount = append(winnerAmount, &entity.WinnerAmountS{
 				Id:           common.If(len(pt.Entidlist) > k, encrypt.EncodeArticleId2ByCheck(pt.Entidlist[k]), "").(string),
 				Winner:       w,
 				WinnerAmount: pt.Sortprice,
@@ -201,11 +201,11 @@ func GetWinnerInfoOfAmount(pt *entity.ProjectInfo) []*entity.WinnerAmount {
 }
 
 // 项目数量---TOP3地区的重点中标单位
-func GetWinnerInfoOfCount(pt *entity.ProjectInfo) []*entity.WinnerTotal {
-	var winnerCount []*entity.WinnerTotal
+func GetWinnerInfoOfCount(pt *entity.ProjectInfo) []*entity.WinnerTotalS {
+	var winnerCount []*entity.WinnerTotalS
 	if pt.Winners != "" {
 		for k, w := range strings.Split(pt.Winners, ",") {
-			winnerCount = append(winnerCount, &entity.WinnerTotal{
+			winnerCount = append(winnerCount, &entity.WinnerTotalS{
 				Id:          common.If(len(pt.Entidlist) > k, encrypt.EncodeArticleId2ByCheck(pt.Entidlist[k]), "").(string),
 				Winner:      w,
 				WinnerTotal: 1,