作者 tangxvhui

更新综合自评

@@ -12,7 +12,7 @@ type EvaluationInfoAdapter struct { @@ -12,7 +12,7 @@ type EvaluationInfoAdapter struct {
12 BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05 12 BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05
13 EndTime string `json:"endTime"` //结束时间 2006-01-02 15:04:05 13 EndTime string `json:"endTime"` //结束时间 2006-01-02 15:04:05
14 Status string `json:"status"` //完成状态 14 Status string `json:"status"` //完成状态
15 - EvaluationItems []EvaluationItemAdapter `json:"assessContent"` 15 + EvaluationItems []EvaluationItemAdapter `json:"evaluationItems"`
16 } 16 }
17 17
18 type EvaluationItemAdapter struct { 18 type EvaluationItemAdapter struct {
@@ -28,6 +28,6 @@ type EvaluationItemAdapter struct { @@ -28,6 +28,6 @@ type EvaluationItemAdapter struct {
28 Weight float64 `json:"weight"` //"权重" 28 Weight float64 `json:"weight"` //"权重"
29 Required int `json:"required"` // 必填项 29 Required int `json:"required"` // 必填项
30 Value string `json:"value"` //评估填写的评分 30 Value string `json:"value"` //评估填写的评分
31 - Score string `json:"score"` //评定得分 31 + Score string `json:"score"` //计算的评定得分
32 Remark string `json:"remark"` //填写的内容反馈 32 Remark string `json:"remark"` //填写的内容反馈
33 } 33 }
@@ -7,6 +7,6 @@ type EditEvaluationValue struct { @@ -7,6 +7,6 @@ type EditEvaluationValue struct {
7 EvaluationItems []struct { 7 EvaluationItems []struct {
8 Value string `json:"value"` 8 Value string `json:"value"`
9 Remark string `json:"remark"` 9 Remark string `json:"remark"`
10 - EvaluationItemId string `json:"evaluationItemId"` 10 + EvaluationItemId int `json:"evaluationItemId,string"`
11 } `json:"evaluationItems"` 11 } `json:"evaluationItems"`
12 } 12 }
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "time"
  5 +
4 "github.com/linmadan/egglib-go/core/application" 6 "github.com/linmadan/egglib-go/core/application"
5 "github.com/linmadan/egglib-go/utils/tool_funs" 7 "github.com/linmadan/egglib-go/utils/tool_funs"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
@@ -313,7 +315,6 @@ func (srv *SummaryEvaluationServeice) GetEvaluationSelf(param *command.QueryEval @@ -313,7 +315,6 @@ func (srv *SummaryEvaluationServeice) GetEvaluationSelf(param *command.QueryEval
313 _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{ 315 _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
314 "evaluationProjectId": evaluationData.EvaluationProjectId, 316 "evaluationProjectId": evaluationData.EvaluationProjectId,
315 "nodeType": int(domain.LinkNodeSelfAssessment), 317 "nodeType": int(domain.LinkNodeSelfAssessment),
316 - "limit": 300,  
317 }) 318 })
318 if err != nil { 319 if err != nil {
319 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 320 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -375,19 +376,64 @@ func (srv *SummaryEvaluationServeice) EditEvaluationSelf(param *command.EditEval @@ -375,19 +376,64 @@ func (srv *SummaryEvaluationServeice) EditEvaluationSelf(param *command.EditEval
375 if err != nil { 376 if err != nil {
376 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 377 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
377 } 378 }
  379 + if evaluationData.Executor.UserId != param.ExecutorId {
  380 +
  381 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  382 + }
  383 +
  384 + if evaluationData.CompanyId != param.CompanyId {
  385 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  386 + }
378 387
379 _, itemList, err := itemUsedRepo.Find(map[string]interface{}{ 388 _, itemList, err := itemUsedRepo.Find(map[string]interface{}{
380 - "evaluationProjectId": int(domain.LinkNodeSelfAssessment),  
381 - "limit": 300, 389 + "evaluationProjectId": evaluationData.EvaluationProjectId,
  390 + })
  391 + if err != nil {
  392 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  393 + }
  394 +
  395 + _, itemValueList, err := itemValueRepo.Find(map[string]interface{}{
  396 + "summaryEvaluationId": evaluationData.Id,
382 }) 397 })
  398 +
383 if err != nil { 399 if err != nil {
384 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 400 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
385 } 401 }
386 - _ = itemValueRepo  
387 - _ = evaluationData  
388 - _ = itemList 402 +
  403 + evaluationValueMap := map[int]*domain.SummaryEvaluationValue{}
  404 + for _, v := range itemList {
  405 + newValue := &domain.SummaryEvaluationValue{}
  406 + newValue.SetBlankValue(evaluationData, v)
  407 + evaluationValueMap[v.Id] = newValue
  408 + }
  409 + for _, v := range itemValueList {
  410 + if mValue, ok := evaluationValueMap[v.EvaluationItemId]; ok {
  411 + mValue.Id = v.Id
  412 + }
  413 + }
  414 +
  415 + nowTime := time.Now()
  416 + for _, v := range param.EvaluationItems {
  417 + updatedData, ok := evaluationValueMap[v.EvaluationItemId]
  418 + if !ok {
  419 + updatedData.UpdatedAt = nowTime
  420 + updatedData.Value = v.Value
  421 + updatedData.Remark = v.Remark
  422 + }
  423 + }
  424 + evaluationValueList := []*domain.SummaryEvaluationValue{}
  425 + for _, v := range evaluationValueMap {
  426 + err = itemValueRepo.Save(v)
  427 + if err != nil {
  428 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  429 + }
  430 + evaluationValueList = append(evaluationValueList, v)
  431 + }
389 if err := transactionContext.CommitTransaction(); err != nil { 432 if err := transactionContext.CommitTransaction(); err != nil {
390 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 433 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
391 } 434 }
392 - return nil, nil 435 + itemValueAdapter := srv.buildSummaryItemValue(itemList, evaluationValueList)
  436 + return map[string][]adapter.EvaluationItemAdapter{
  437 + "EvaluationItems": itemValueAdapter,
  438 + }, nil
393 } 439 }
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "time"
  5 +)
4 6
5 // 实际被应用的评估条目 7 // 实际被应用的评估条目
6 type EvaluationItemUsed struct { 8 type EvaluationItemUsed struct {
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "fmt"
  5 + "time"
  6 +)
4 7
5 // 周综合评估 8 // 周综合评估
6 type SummaryEvaluation struct { 9 type SummaryEvaluation struct {
@@ -56,3 +59,18 @@ type SummaryEvaluationRepository interface { @@ -56,3 +59,18 @@ type SummaryEvaluationRepository interface {
56 FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error) 59 FindOne(queryOptions map[string]interface{}) (*SummaryEvaluation, error)
57 Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error) 60 Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluation, error)
58 } 61 }
  62 +
  63 +// 计算总分。TotalScore 保留1位小数
  64 +func (evaluation *SummaryEvaluation) EvaluationTotalScore(valueList []*SummaryEvaluationValue) error {
  65 + var totalScore float64
  66 + for _, v := range valueList {
  67 + score, err := v.SumScore(v.Weight, v.Value)
  68 + if err != nil {
  69 + return err
  70 + }
  71 +
  72 + totalScore += score
  73 + }
  74 + evaluation.TotalScore = fmt.Sprintf("%.2f", totalScore)
  75 + return nil
  76 +}
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "fmt"
  5 + "strconv"
  6 + "time"
  7 +)
4 8
5 // 周期综合评估填写的内容 9 // 周期综合评估填写的内容
6 type SummaryEvaluationValue struct { 10 type SummaryEvaluationValue struct {
@@ -11,6 +15,7 @@ type SummaryEvaluationValue struct { @@ -11,6 +15,7 @@ type SummaryEvaluationValue struct {
11 Score string `json:"score"` //评定得分 15 Score string `json:"score"` //评定得分
12 Types EvaluationType `json:"types"` //评估类型 16 Types EvaluationType `json:"types"` //评估类型
13 Remark string `json:"remark"` //填写的内容反馈 17 Remark string `json:"remark"` //填写的内容反馈
  18 + Weight float64 `json:"weight"` //"权重"
14 CreatedAt time.Time `json:"createdAt"` //数据创建时间 19 CreatedAt time.Time `json:"createdAt"` //数据创建时间
15 UpdatedAt time.Time `json:"updatedAt"` //数据更新时间 20 UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
16 DeletedAt *time.Time `json:"deletedAt"` //数据删除时间 21 DeletedAt *time.Time `json:"deletedAt"` //数据删除时间
@@ -22,3 +27,42 @@ type SummaryEvaluationValueRepository interface { @@ -22,3 +27,42 @@ type SummaryEvaluationValueRepository interface {
22 FindOne(queryOptions map[string]interface{}) (*SummaryEvaluationValue, error) 27 FindOne(queryOptions map[string]interface{}) (*SummaryEvaluationValue, error)
23 Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluationValue, error) 28 Find(queryOptions map[string]interface{}) (int, []*SummaryEvaluationValue, error)
24 } 29 }
  30 +
  31 +// 计算周期评估
  32 +// 当指标项没有权重的时候,还是进行评级操作,不计算分数
  33 +// 分数保留2位小数
  34 +func (itemValue *SummaryEvaluationValue) SummaryEvaluationScore() error {
  35 + //计算方式
  36 + score, err := itemValue.SumScore(itemValue.Weight, itemValue.Value)
  37 + if err != nil {
  38 + return err
  39 + }
  40 + itemValue.Score = fmt.Sprintf("%.2f", score)
  41 + return nil
  42 +}
  43 +
  44 +func (item *SummaryEvaluationValue) SumScore(weight float64, value string) (float64, error) {
  45 + if item.Weight == 0 {
  46 + return 0, nil
  47 + }
  48 + valueFloat, err := strconv.ParseFloat(item.Value, 64)
  49 + if err != nil {
  50 + return 0, fmt.Errorf("条目%d系数值异常,%s", item.Id, item.Value)
  51 + }
  52 + //计算方式
  53 + score := item.Weight * valueFloat
  54 + return score, nil
  55 +}
  56 +
  57 +// 初始化一个空的value
  58 +func (itemValue *SummaryEvaluationValue) SetBlankValue(evaluation *SummaryEvaluation, item *EvaluationItemUsed) {
  59 + itemValue.EvaluationItemId = item.Id
  60 + itemValue.SummaryEvaluationId = evaluation.Id
  61 + itemValue.Value = ""
  62 + itemValue.Score = ""
  63 + itemValue.Remark = ""
  64 + itemValue.Types = evaluation.Types
  65 + itemValue.Weight = item.Weight
  66 + itemValue.CreatedAt = time.Now()
  67 + itemValue.UpdatedAt = time.Now()
  68 +}
@@ -71,7 +71,7 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface @@ -71,7 +71,7 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface
71 tx := repo.transactionContext.PgTx 71 tx := repo.transactionContext.PgTx
72 var m []*models.EvaluationItemUsed 72 var m []*models.EvaluationItemUsed
73 query := tx.Model(&m). 73 query := tx.Model(&m).
74 - Where("deleted_at isnull").Limit(20) 74 + Where("deleted_at isnull")
75 if v, ok := queryOptions["limit"].(int); ok { 75 if v, ok := queryOptions["limit"].(int); ok {
76 query.Limit(v) 76 query.Limit(v)
77 } 77 }
@@ -98,13 +98,16 @@ func (repo *SummaryEvaluationValueRepository) Find(queryOptions map[string]inter @@ -98,13 +98,16 @@ func (repo *SummaryEvaluationValueRepository) Find(queryOptions map[string]inter
98 tx := repo.transactionContext.PgTx 98 tx := repo.transactionContext.PgTx
99 var m []*models.SummaryEvaluationValue 99 var m []*models.SummaryEvaluationValue
100 query := tx.Model(&m). 100 query := tx.Model(&m).
101 - Where("deleted_at isnull").Limit(20) 101 + Where("deleted_at isnull")
102 if v, ok := queryOptions["limit"].(int); ok { 102 if v, ok := queryOptions["limit"].(int); ok {
103 query.Limit(v) 103 query.Limit(v)
104 } 104 }
105 if v, ok := queryOptions["offset"].(int); ok { 105 if v, ok := queryOptions["offset"].(int); ok {
106 query.Offset(v) 106 query.Offset(v)
107 } 107 }
  108 + if v, ok := queryOptions["summaryEvaluationId"]; ok {
  109 + query.Where("summary_evaluation_id=?", v)
  110 + }
108 count, err := query.SelectAndCount() 111 count, err := query.SelectAndCount()
109 if err != nil { 112 if err != nil {
110 return 0, nil, err 113 return 0, nil, err