作者 yangfu

计算发现分 发现分百分比

@@ -369,6 +369,7 @@ type ChanceCalculateScoreRequest struct { @@ -369,6 +369,7 @@ type ChanceCalculateScoreRequest struct {
369 } 369 }
370 type ChanceCalculateScoreResponse struct { 370 type ChanceCalculateScoreResponse struct {
371 DiscoveryScore float64 `json:"discoveryScore"` //发现分 371 DiscoveryScore float64 `json:"discoveryScore"` //发现分
  372 + DiscoveryScorePercent int `json:"discoveryScorePercent"` //发现分-百分比
372 } 373 }
373 374
374 /*ChanceDelete 机会删除*/ 375 /*ChanceDelete 机会删除*/
@@ -94,4 +94,5 @@ type Score struct { @@ -94,4 +94,5 @@ type Score struct {
94 ExtraScore float64 `json:"extraScore"` //额外分 94 ExtraScore float64 `json:"extraScore"` //额外分
95 ValueScore float64 `json:"valueScore"` //价值分 95 ValueScore float64 `json:"valueScore"` //价值分
96 DiscoveryScore float64 `json:"discoveryScore"` //发现分 96 DiscoveryScore float64 `json:"discoveryScore"` //发现分
  97 + DiscoveryScorePercent int `json:"discoveryScorePercent"` //发现分-百分比
97 } 98 }
@@ -13,3 +13,11 @@ func Test_Err(t *testing.T) { @@ -13,3 +13,11 @@ func Test_Err(t *testing.T) {
13 bt2, _ := json.Marshal(normalmsg) 13 bt2, _ := json.Marshal(normalmsg)
14 t.Log(string(bt2)) 14 t.Log(string(bt2))
15 } 15 }
  16 +
  17 +func Test_Ceil(t *testing.T) {
  18 + value := 90.12
  19 + intValue := int(value)
  20 + t.Log(intValue)
  21 +
  22 + t.Log(0.38 * 0.3)
  23 +}
@@ -49,6 +49,14 @@ var errmessge ErrorMap = map[int]string{ @@ -49,6 +49,14 @@ var errmessge ErrorMap = map[int]string{
49 49
50 //消息相关 50 //消息相关
51 5401: "消息不存在", 51 5401: "消息不存在",
  52 +
  53 + //评分相关
  54 + 5501: "基础评分不符合要求",
  55 + 5502: "附加评分不符合要求",
  56 + 5503: "价值评分不符合要求",
  57 +
  58 + 5510: "评分配置不存在,请联系管理员",
  59 + 5511: "发现分计算不一致,请重新提交",
52 } 60 }
53 61
54 const ( 62 const (
@@ -274,6 +274,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -274,6 +274,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
274 approveItemResponse ApproveItemResponse 274 approveItemResponse ApproveItemResponse
275 mapProcess = make(map[string]interface{}) 275 mapProcess = make(map[string]interface{})
276 mapChance = make(map[string]interface{}) 276 mapChance = make(map[string]interface{})
  277 + result *protocol.ChanceCalculateScoreResponse
277 ) 278 )
278 rsp = &protocol.ChanceApproveResponse{} 279 rsp = &protocol.ChanceApproveResponse{}
279 //TODO:测试注入 280 //TODO:测试注入
@@ -307,6 +308,16 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -307,6 +308,16 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
307 return 308 return
308 } 309 }
309 { 310 {
  311 + //计算发现分
  312 + if result, err = ChanceCalculateScore(header, &protocol.ChanceCalculateScoreRequest{Score: request.ApproveData.Score}); err != nil {
  313 + log.Error("计算发现分错误:", err)
  314 + //err = protocol.NewErrWithMessage(5511)
  315 + return
  316 + }
  317 + request.ApproveData.Score.DiscoveryScore = result.DiscoveryScore
  318 + request.ApproveData.Score.DiscoveryScorePercent = result.DiscoveryScorePercent
  319 + }
  320 + {
310 mapProcess["ReviewStatus"] = int8(request.ReviewStatus) 321 mapProcess["ReviewStatus"] = int8(request.ReviewStatus)
311 mapProcess["ApproveTime"] = time.Now() 322 mapProcess["ApproveTime"] = time.Now()
312 if request.ReviewStatus == protocol.ReviewStatusPass { 323 if request.ReviewStatus == protocol.ReviewStatusPass {
@@ -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