|
@@ -494,6 +494,7 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
@@ -494,6 +494,7 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
494
|
chance *models.Chance
|
494
|
chance *models.Chance
|
495
|
mapChance = make(map[string]interface{})
|
495
|
mapChance = make(map[string]interface{})
|
496
|
approveData protocol.ApproveData
|
496
|
approveData protocol.ApproveData
|
|
|
497
|
+ result *protocol.ChanceCalculateScoreResponse
|
497
|
)
|
498
|
)
|
498
|
if chance, err = models.GetChanceByIdAndEnable(request.ChanceId); err != nil {
|
499
|
if chance, err = models.GetChanceByIdAndEnable(request.ChanceId); err != nil {
|
499
|
err = protocol.NewErrWithMessage(5101) //不存在
|
500
|
err = protocol.NewErrWithMessage(5101) //不存在
|
|
@@ -503,6 +504,13 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
@@ -503,6 +504,13 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
503
|
err = protocol.NewErrWithMessage(5205)
|
504
|
err = protocol.NewErrWithMessage(5205)
|
504
|
return
|
505
|
return
|
505
|
}
|
506
|
}
|
|
|
507
|
+ if result, err = ChanceCalculateScore(header, &protocol.ChanceCalculateScoreRequest{Score: request.Score}); err != nil {
|
|
|
508
|
+ log.Error("计算发现分错误:", err)
|
|
|
509
|
+ //err = protocol.NewErrWithMessage(5511)
|
|
|
510
|
+ return
|
|
|
511
|
+ }
|
|
|
512
|
+ request.Score.DiscoveryScore = result.DiscoveryScore
|
|
|
513
|
+ request.Score.DiscoveryScorePercent = result.DiscoveryScorePercent
|
506
|
//TODO:角色检查权限
|
514
|
//TODO:角色检查权限
|
507
|
if e := json.Unmarshal([]byte(chance.ApproveData), &approveData); e == nil {
|
515
|
if e := json.Unmarshal([]byte(chance.ApproveData), &approveData); e == nil {
|
508
|
approveData.Score = request.Score
|
516
|
approveData.Score = request.Score
|
|
@@ -512,7 +520,7 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
@@ -512,7 +520,7 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
512
|
mapChance["BasicScore"] = request.Score.BasicScore
|
520
|
mapChance["BasicScore"] = request.Score.BasicScore
|
513
|
mapChance["ExtraScore"] = request.Score.ExtraScore
|
521
|
mapChance["ExtraScore"] = request.Score.ExtraScore
|
514
|
mapChance["ValueScore"] = request.Score.ValueScore
|
522
|
mapChance["ValueScore"] = request.Score.ValueScore
|
515
|
- mapChance["DiscoveryScore"] = request.Score.DiscoveryScore
|
523
|
+ mapChance["DiscoveryScore"] = result.DiscoveryScore
|
516
|
}
|
524
|
}
|
517
|
orm := orm.NewOrm()
|
525
|
orm := orm.NewOrm()
|
518
|
orm.Begin()
|
526
|
orm.Begin()
|
|
@@ -528,10 +536,60 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
@@ -528,10 +536,60 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
528
|
|
536
|
|
529
|
//计算发现分
|
537
|
//计算发现分
|
530
|
func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.ChanceCalculateScoreRequest) (rsp *protocol.ChanceCalculateScoreResponse, err error) {
|
538
|
func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.ChanceCalculateScoreRequest) (rsp *protocol.ChanceCalculateScoreResponse, err error) {
|
531
|
- var ()
|
|
|
532
|
- //TODO:取配置数据
|
539
|
+ var (
|
|
|
540
|
+ config *models.SysConfig
|
|
|
541
|
+ scoreConfig protocol.ScoreConfig
|
|
|
542
|
+ sum float64
|
|
|
543
|
+ )
|
533
|
rsp = &protocol.ChanceCalculateScoreResponse{}
|
544
|
rsp = &protocol.ChanceCalculateScoreResponse{}
|
534
|
- rsp.DiscoveryScore = request.Score.BasicScore*1.0 + request.Score.ExtraScore*1.0 + request.Score.ValueScore*1.0
|
545
|
+ if config, err = models.GetSysConfigByCompanyId(int(header.CompanyId), models.KeyScore); err != nil {
|
|
|
546
|
+ err = protocol.NewErrWithMessage(5510)
|
|
|
547
|
+ log.Error(header.CompanyId, err)
|
|
|
548
|
+ return
|
|
|
549
|
+ }
|
|
|
550
|
+ if err = json.Unmarshal([]byte(config.Content), &scoreConfig); err != nil {
|
|
|
551
|
+ err = protocol.NewErrWithMessage(5510)
|
|
|
552
|
+ log.Error(err)
|
|
|
553
|
+ return
|
|
|
554
|
+ }
|
|
|
555
|
+ {
|
|
|
556
|
+ basic := request.Score.BasicScore
|
|
|
557
|
+ if basic < scoreConfig.BasicScore.Min || basic > scoreConfig.BasicScore.Max {
|
|
|
558
|
+ err = protocol.NewErrWithMessage(5501)
|
|
|
559
|
+ log.Error(fmt.Sprintf("%v out range[%v:%v]", basic, scoreConfig.BasicScore.Min, scoreConfig.BasicScore.Max))
|
|
|
560
|
+ return
|
|
|
561
|
+ }
|
|
|
562
|
+ sum += scoreConfig.BasicScore.Max * scoreConfig.DiscoveryScore.BasicFactor
|
|
|
563
|
+ }
|
|
|
564
|
+ {
|
|
|
565
|
+ extral := request.Score.ExtraScore
|
|
|
566
|
+ if extral < scoreConfig.ExtraScore.Min || extral > scoreConfig.ExtraScore.Max {
|
|
|
567
|
+ err = protocol.NewErrWithMessage(5502)
|
|
|
568
|
+ log.Error(fmt.Sprintf("%v out range[%v:%v]", extral, scoreConfig.ExtraScore.Min, scoreConfig.ExtraScore.Max))
|
|
|
569
|
+ return
|
|
|
570
|
+ }
|
|
|
571
|
+ sum += scoreConfig.ExtraScore.Max * scoreConfig.DiscoveryScore.ExtraFactor
|
|
|
572
|
+ }
|
|
|
573
|
+ {
|
|
|
574
|
+ value := request.Score.ValueScore
|
|
|
575
|
+ if value < scoreConfig.ValueScore.Min || value > scoreConfig.ValueScore.Max {
|
|
|
576
|
+ err = protocol.NewErrWithMessage(5502)
|
|
|
577
|
+ log.Error(fmt.Sprintf("%v out range[%v:%v]", value, scoreConfig.ValueScore.Min, scoreConfig.ValueScore.Max))
|
|
|
578
|
+ return
|
|
|
579
|
+ }
|
|
|
580
|
+ sum += scoreConfig.ValueScore.Max * scoreConfig.DiscoveryScore.ValueFactor
|
|
|
581
|
+ }
|
|
|
582
|
+ rsp.DiscoveryScore = request.Score.BasicScore*scoreConfig.DiscoveryScore.BasicFactor + request.Score.ExtraScore*scoreConfig.DiscoveryScore.ExtraFactor + request.Score.ValueScore*scoreConfig.DiscoveryScore.ValueFactor
|
|
|
583
|
+ rsp.DiscoveryScorePercent = int((rsp.DiscoveryScore / sum) * 100)
|
|
|
584
|
+ log.Debug(fmt.Sprintf("计算发现-> score_config:%v score:%v 总分:%v 发现分:%v 发现分百分比:%v", common.AssertJson(scoreConfig), common.AssertJson(request.Score), sum, rsp.DiscoveryScore, rsp.DiscoveryScorePercent))
|
|
|
585
|
+ //发现分不为0
|
|
|
586
|
+ if request.Score.DiscoveryScore != 0 {
|
|
|
587
|
+ if request.Score.DiscoveryScore != 0 && rsp.DiscoveryScore != request.Score.DiscoveryScore {
|
|
|
588
|
+ log.Error(fmt.Sprintf("input :%v out:%v want:%v", request.Score.DiscoveryScore, rsp.DiscoveryScore, request.Score.DiscoveryScore))
|
|
|
589
|
+ err = protocol.NewErrWithMessage(5511)
|
|
|
590
|
+ return
|
|
|
591
|
+ }
|
|
|
592
|
+ }
|
535
|
return
|
593
|
return
|
536
|
}
|
594
|
}
|
537
|
|
595
|
|