作者 yangfu

计算发现分 发现分百分比

... ... @@ -369,6 +369,7 @@ type ChanceCalculateScoreRequest struct {
}
type ChanceCalculateScoreResponse struct {
DiscoveryScore float64 `json:"discoveryScore"` //发现分
DiscoveryScorePercent int `json:"discoveryScorePercent"` //发现分-百分比
}
/*ChanceDelete 机会删除*/
... ...
... ... @@ -94,4 +94,5 @@ type Score struct {
ExtraScore float64 `json:"extraScore"` //额外分
ValueScore float64 `json:"valueScore"` //价值分
DiscoveryScore float64 `json:"discoveryScore"` //发现分
DiscoveryScorePercent int `json:"discoveryScorePercent"` //发现分-百分比
}
... ...
... ... @@ -13,3 +13,11 @@ func Test_Err(t *testing.T) {
bt2, _ := json.Marshal(normalmsg)
t.Log(string(bt2))
}
func Test_Ceil(t *testing.T) {
value := 90.12
intValue := int(value)
t.Log(intValue)
t.Log(0.38 * 0.3)
}
... ...
... ... @@ -49,6 +49,14 @@ var errmessge ErrorMap = map[int]string{
//消息相关
5401: "消息不存在",
//评分相关
5501: "基础评分不符合要求",
5502: "附加评分不符合要求",
5503: "价值评分不符合要求",
5510: "评分配置不存在,请联系管理员",
5511: "发现分计算不一致,请重新提交",
}
const (
... ...
... ... @@ -274,6 +274,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
approveItemResponse ApproveItemResponse
mapProcess = make(map[string]interface{})
mapChance = make(map[string]interface{})
result *protocol.ChanceCalculateScoreResponse
)
rsp = &protocol.ChanceApproveResponse{}
//TODO:测试注入
... ... @@ -307,6 +308,16 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
return
}
{
//计算发现分
if result, err = ChanceCalculateScore(header, &protocol.ChanceCalculateScoreRequest{Score: request.ApproveData.Score}); err != nil {
log.Error("计算发现分错误:", err)
//err = protocol.NewErrWithMessage(5511)
return
}
request.ApproveData.Score.DiscoveryScore = result.DiscoveryScore
request.ApproveData.Score.DiscoveryScorePercent = result.DiscoveryScorePercent
}
{
mapProcess["ReviewStatus"] = int8(request.ReviewStatus)
mapProcess["ApproveTime"] = time.Now()
if request.ReviewStatus == protocol.ReviewStatusPass {
... ...
... ... @@ -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
}
... ...