|
@@ -41,6 +41,7 @@ type UserTask struct {
|
|
|
MonthDistributionKey []entity.DateSpan //月度分配key
|
|
|
YearDistributionKey []entity.DateSpan //年度分配key
|
|
|
JudgmentMap map[string]bool //地区分布|城市分布|客户 项目规模 地区top3|订阅分类|一个就行
|
|
|
+ JudgmentLock sync.Mutex
|
|
|
CalculateWG sync.WaitGroup
|
|
|
}
|
|
|
|
|
@@ -249,6 +250,24 @@ func (ut *UserTask) KeysMatch(matchObject string) (b bool) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// GetMap
|
|
|
+func (ut *UserTask) GetJudgmentMap(key string) (b bool) {
|
|
|
+ ut.JudgmentLock.Lock()
|
|
|
+ defer ut.JudgmentLock.Unlock()
|
|
|
+ b = ut.JudgmentMap[key]
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// SetMap
|
|
|
+func (ut *UserTask) SetJudgmentMap(keys ...string) (b bool) {
|
|
|
+ ut.JudgmentLock.Lock()
|
|
|
+ defer ut.JudgmentLock.Unlock()
|
|
|
+ for _, key := range keys {
|
|
|
+ ut.JudgmentMap[key] = true
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// Calculate 模块计算逻辑
|
|
|
func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
//市场概况+时间分布
|
|
@@ -268,8 +287,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
if len(ut.MonthDistributionKey) > 0 {
|
|
|
if monthKey := ut.GetMonthDistributionKey(pt.JgTime); monthKey != "" {
|
|
|
monthKeyPrev := utility.GetJudgmentPrevKey(consts.JudgmentPrev11, monthKey)
|
|
|
- if !ut.JudgmentMap[monthKeyPrev] {
|
|
|
- ut.JudgmentMap[monthKeyPrev] = true
|
|
|
+ if !ut.GetJudgmentMap(monthKeyPrev) {
|
|
|
+ ut.SetJudgmentMap(monthKeyPrev)
|
|
|
//金额
|
|
|
scale.MonthDistribution.ProjectAmount = append(scale.MonthDistribution.ProjectAmount, &entity.Distribution{
|
|
|
Minth: monthKey,
|
|
@@ -301,8 +320,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
if len(ut.YearDistributionKey) > 0 {
|
|
|
if yearKey := ut.GetYearDistributionKey(pt.JgTime); yearKey != "" {
|
|
|
yearKeyPrev := utility.GetJudgmentPrevKey(consts.JudgmentPrev11, yearKey)
|
|
|
- if !ut.JudgmentMap[yearKeyPrev] {
|
|
|
- ut.JudgmentMap[yearKeyPrev] = true
|
|
|
+ if !ut.GetJudgmentMap(yearKeyPrev) {
|
|
|
+ ut.SetJudgmentMap(yearKeyPrev)
|
|
|
//金额
|
|
|
scale.YearDistribution.ProjectAmount = append(scale.YearDistribution.ProjectAmount, &entity.Distribution{
|
|
|
Minth: yearKey,
|
|
@@ -388,9 +407,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
var areaInfoFunc = func() {
|
|
|
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
|
|
|
- ut.JudgmentMap[cityInfoKey] = true
|
|
|
+ if !ut.GetJudgmentMap(areaInfoKey) {
|
|
|
+ ut.SetJudgmentMap(areaInfoKey, cityInfoKey)
|
|
|
pad.AreaInfos = append(pad.AreaInfos, &entity.AreaInfosS{
|
|
|
Amount: pt.Sortprice,
|
|
|
Area: pt.Area,
|
|
@@ -422,8 +440,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
}()
|
|
|
if ai.Area == pt.Area {
|
|
|
stopLoop = true
|
|
|
- if !ut.JudgmentMap[cityInfoKey] {
|
|
|
- ut.JudgmentMap[cityInfoKey] = true
|
|
|
+ if !ut.GetJudgmentMap(cityInfoKey) {
|
|
|
+ ut.SetJudgmentMap(cityInfoKey)
|
|
|
ai.AreaDetails = append(ai.AreaDetails, &entity.AreaDetailsS{
|
|
|
Amount: pt.Sortprice,
|
|
|
City: pt.City,
|
|
@@ -454,8 +472,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
customerKey := utility.GetJudgmentPrevKey(consts.JudgmentPrev2, bc)
|
|
|
if bc == "其它" {
|
|
|
//客户分布(其它)
|
|
|
- if !ut.JudgmentMap[customerKey] {
|
|
|
- ut.JudgmentMap[customerKey] = true
|
|
|
+ if !ut.GetJudgmentMap(customerKey) {
|
|
|
+ ut.SetJudgmentMap(customerKey)
|
|
|
//客户分布 其它
|
|
|
pad.CustomerScaleOther = &entity.CustomerScaleS{
|
|
|
Amount: pt.Sortprice,
|
|
@@ -468,8 +486,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
}
|
|
|
} else {
|
|
|
//客户分布
|
|
|
- if !ut.JudgmentMap[customerKey] {
|
|
|
- ut.JudgmentMap[customerKey] = true
|
|
|
+ if !ut.GetJudgmentMap(customerKey) {
|
|
|
+ ut.SetJudgmentMap(customerKey)
|
|
|
pad.CustomerScale = append(pad.CustomerScale, &entity.CustomerScaleS{
|
|
|
Amount: pt.Sortprice,
|
|
|
Buyclass: bc,
|
|
@@ -509,8 +527,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
//-------------redis----sorted---- 中标企业--score---项目金额TOP3客户类型的重点中标单位
|
|
|
utility.UpdateWinnerInfoOfScore(utility.GetSortedKeyOfRedis(consts.JudgmentPrev3, "sbat", ut.MgoUserId, bc), pt, pt.Sortprice)
|
|
|
top3Key := utility.GetJudgmentPrevKey(consts.JudgmentPrev3, fmt.Sprintf("%s_top3", bc))
|
|
|
- if !ut.JudgmentMap[top3Key] {
|
|
|
- ut.JudgmentMap[top3Key] = true
|
|
|
+ if !ut.GetJudgmentMap(top3Key) {
|
|
|
+ ut.SetJudgmentMap(top3Key)
|
|
|
//项目数量TOP3客户类型的重点中标单位
|
|
|
pad.ScaleBuyclassCountTop = append(pad.ScaleBuyclassCountTop, &entity.ScaleBuyclassCountTopS{
|
|
|
BuyclassCount: 1,
|
|
@@ -551,8 +569,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
}
|
|
|
}
|
|
|
scaleKey := utility.GetJudgmentPrevKey(consts.JudgmentPrev4, psk)
|
|
|
- if !ut.JudgmentMap[scaleKey] {
|
|
|
- ut.JudgmentMap[scaleKey] = true
|
|
|
+ if !ut.GetJudgmentMap(scaleKey) {
|
|
|
+ ut.SetJudgmentMap(scaleKey)
|
|
|
pad.ProjectScale = append(pad.ProjectScale, &entity.ProjectScaleS{
|
|
|
Name: psk,
|
|
|
Count: 1,
|
|
@@ -576,8 +594,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
//-------------redis----sorted---- 中标企业--score---项目数量---TOP3地区的重点中标单位
|
|
|
utility.UpdateWinnerInfoOfScore(utility.GetSortedKeyOfRedis(consts.JudgmentPrev5, "sact", ut.MgoUserId, pt.Area), pt, 1)
|
|
|
saaactKey := utility.GetJudgmentPrevKey(consts.JudgmentPrev5, pt.Area)
|
|
|
- if !ut.JudgmentMap[saaactKey] {
|
|
|
- ut.JudgmentMap[saaactKey] = true
|
|
|
+ if !ut.GetJudgmentMap(saaactKey) {
|
|
|
+ ut.SetJudgmentMap(saaactKey)
|
|
|
//项目金额---TOP3地区的重点中标单位
|
|
|
pad.ScaleAreaAmountTop = append(pad.ScaleAreaAmountTop, &entity.ScaleAreaAmountTopS{
|
|
|
AreaAmount: pt.Sortprice,
|
|
@@ -624,8 +642,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
utility.UpdateWinnerInfoOfScore(utility.GetSortedKeyOfRedis(consts.JudgmentPrev6, "srtt", ut.MgoUserId, itemName), pt, 1)
|
|
|
//-------------redis----sorted---- 中标企业--score---重点中标单位-金额
|
|
|
utility.UpdateWinnerInfoOfScore(utility.GetSortedKeyOfRedis(consts.JudgmentPrev6, "srat", ut.MgoUserId, itemName), pt, pt.Sortprice)
|
|
|
- if !ut.JudgmentMap[itemNameKey] {
|
|
|
- ut.JudgmentMap[itemNameKey] = true
|
|
|
+ if !ut.GetJudgmentMap(itemNameKey) {
|
|
|
+ ut.SetJudgmentMap(itemNameKey)
|
|
|
//订阅分类
|
|
|
sr.ScaleRefineAll = append(sr.ScaleRefineAll, &entity.ScaleRefineAllS{
|
|
|
Amount: pt.Sortprice,
|
|
@@ -695,8 +713,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
}
|
|
|
}
|
|
|
scaleKey := utility.GetJudgmentPrevKey(consts.JudgmentPrev8, psk)
|
|
|
- if !ut.JudgmentMap[scaleKey] {
|
|
|
- ut.JudgmentMap[scaleKey] = true
|
|
|
+ if !ut.GetJudgmentMap(scaleKey) {
|
|
|
+ ut.SetJudgmentMap(scaleKey)
|
|
|
baw.BuyerTimeDistribution = append(baw.BuyerTimeDistribution, &entity.BuyerAndWinnerTimeDistributionS{
|
|
|
Key: psk,
|
|
|
Amount: pt.Sortprice,
|
|
@@ -735,8 +753,8 @@ func (ut *UserTask) Calculate(pt *entity.ProjectInfo) {
|
|
|
}
|
|
|
}
|
|
|
scaleKey := utility.GetJudgmentPrevKey(consts.JudgmentPrev10, psk)
|
|
|
- if !ut.JudgmentMap[scaleKey] {
|
|
|
- ut.JudgmentMap[scaleKey] = true
|
|
|
+ if !ut.GetJudgmentMap(scaleKey) {
|
|
|
+ ut.SetJudgmentMap(scaleKey)
|
|
|
baw.WinnerTimeDistribution = append(baw.WinnerTimeDistribution, &entity.BuyerAndWinnerTimeDistributionS{
|
|
|
Key: psk,
|
|
|
Amount: pt.Sortprice,
|