...
|
...
|
@@ -494,6 +494,7 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
chance *models.Chance
|
|
|
mapChance = make(map[string]interface{})
|
|
|
approveData protocol.ApproveData
|
|
|
result *protocol.ChanceCalculateScoreResponse
|
|
|
)
|
|
|
if chance, err = models.GetChanceByIdAndEnable(request.ChanceId); err != nil {
|
|
|
err = protocol.NewErrWithMessage(5101) //不存在
|
...
|
...
|
@@ -503,6 +504,13 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
err = protocol.NewErrWithMessage(5205)
|
|
|
return
|
|
|
}
|
|
|
if result, err = ChanceCalculateScore(header, &protocol.ChanceCalculateScoreRequest{Score: request.Score}); err != nil {
|
|
|
log.Error("计算发现分错误:", err)
|
|
|
//err = protocol.NewErrWithMessage(5511)
|
|
|
return
|
|
|
}
|
|
|
request.Score.DiscoveryScore = result.DiscoveryScore
|
|
|
request.Score.DiscoveryScorePercent = result.DiscoveryScorePercent
|
|
|
//TODO:角色检查权限
|
|
|
if e := json.Unmarshal([]byte(chance.ApproveData), &approveData); e == nil {
|
|
|
approveData.Score = request.Score
|
...
|
...
|
@@ -512,7 +520,7 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
mapChance["BasicScore"] = request.Score.BasicScore
|
|
|
mapChance["ExtraScore"] = request.Score.ExtraScore
|
|
|
mapChance["ValueScore"] = request.Score.ValueScore
|
|
|
mapChance["DiscoveryScore"] = request.Score.DiscoveryScore
|
|
|
mapChance["DiscoveryScore"] = result.DiscoveryScore
|
|
|
}
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
...
|
...
|
@@ -528,10 +536,60 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
|
|
|
//计算发现分
|
|
|
func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.ChanceCalculateScoreRequest) (rsp *protocol.ChanceCalculateScoreResponse, err error) {
|
|
|
var ()
|
|
|
//TODO:取配置数据
|
|
|
var (
|
|
|
config *models.SysConfig
|
|
|
scoreConfig protocol.ScoreConfig
|
|
|
sum float64
|
|
|
)
|
|
|
rsp = &protocol.ChanceCalculateScoreResponse{}
|
|
|
rsp.DiscoveryScore = request.Score.BasicScore*1.0 + request.Score.ExtraScore*1.0 + request.Score.ValueScore*1.0
|
|
|
if config, err = models.GetSysConfigByCompanyId(int(header.CompanyId), models.KeyScore); err != nil {
|
|
|
err = protocol.NewErrWithMessage(5510)
|
|
|
log.Error(header.CompanyId, err)
|
|
|
return
|
|
|
}
|
|
|
if err = json.Unmarshal([]byte(config.Content), &scoreConfig); err != nil {
|
|
|
err = protocol.NewErrWithMessage(5510)
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
{
|
|
|
basic := request.Score.BasicScore
|
|
|
if basic < scoreConfig.BasicScore.Min || basic > scoreConfig.BasicScore.Max {
|
|
|
err = protocol.NewErrWithMessage(5501)
|
|
|
log.Error(fmt.Sprintf("%v out range[%v:%v]", basic, scoreConfig.BasicScore.Min, scoreConfig.BasicScore.Max))
|
|
|
return
|
|
|
}
|
|
|
sum += scoreConfig.BasicScore.Max * scoreConfig.DiscoveryScore.BasicFactor
|
|
|
}
|
|
|
{
|
|
|
extral := request.Score.ExtraScore
|
|
|
if extral < scoreConfig.ExtraScore.Min || extral > scoreConfig.ExtraScore.Max {
|
|
|
err = protocol.NewErrWithMessage(5502)
|
|
|
log.Error(fmt.Sprintf("%v out range[%v:%v]", extral, scoreConfig.ExtraScore.Min, scoreConfig.ExtraScore.Max))
|
|
|
return
|
|
|
}
|
|
|
sum += scoreConfig.ExtraScore.Max * scoreConfig.DiscoveryScore.ExtraFactor
|
|
|
}
|
|
|
{
|
|
|
value := request.Score.ValueScore
|
|
|
if value < scoreConfig.ValueScore.Min || value > scoreConfig.ValueScore.Max {
|
|
|
err = protocol.NewErrWithMessage(5502)
|
|
|
log.Error(fmt.Sprintf("%v out range[%v:%v]", value, scoreConfig.ValueScore.Min, scoreConfig.ValueScore.Max))
|
|
|
return
|
|
|
}
|
|
|
sum += scoreConfig.ValueScore.Max * scoreConfig.DiscoveryScore.ValueFactor
|
|
|
}
|
|
|
rsp.DiscoveryScore = request.Score.BasicScore*scoreConfig.DiscoveryScore.BasicFactor + request.Score.ExtraScore*scoreConfig.DiscoveryScore.ExtraFactor + request.Score.ValueScore*scoreConfig.DiscoveryScore.ValueFactor
|
|
|
rsp.DiscoveryScorePercent = int((rsp.DiscoveryScore / sum) * 100)
|
|
|
log.Debug(fmt.Sprintf("计算发现-> score_config:%v score:%v 总分:%v 发现分:%v 发现分百分比:%v", common.AssertJson(scoreConfig), common.AssertJson(request.Score), sum, rsp.DiscoveryScore, rsp.DiscoveryScorePercent))
|
|
|
//发现分不为0
|
|
|
if request.Score.DiscoveryScore != 0 {
|
|
|
if request.Score.DiscoveryScore != 0 && rsp.DiscoveryScore != request.Score.DiscoveryScore {
|
|
|
log.Error(fmt.Sprintf("input :%v out:%v want:%v", request.Score.DiscoveryScore, rsp.DiscoveryScore, request.Score.DiscoveryScore))
|
|
|
err = protocol.NewErrWithMessage(5511)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
|