作者 tangxvhui

日常保存

  1 +package query
  2 +
  3 +type ListAssessCycleDay struct {
  4 + CompanyId int `json:"companyId"`
  5 + CycleId int `json:"cycleId,string"`
  6 +}
@@ -1726,12 +1726,11 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma @@ -1726,12 +1726,11 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
1726 continue 1726 continue
1727 } 1727 }
1728 v.Value = item.Value 1728 v.Value = item.Value
1729 - //填入评估值描述  
1730 - reteResult, err := v.Rule.ScoreOrRating(&v.Value) 1729 + //转换填入的评估值
  1730 + err = v.TransformValue()
1731 if err != nil { 1731 if err != nil {
1732 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1732 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
1733 } 1733 }
1734 - v.ReteResult = reteResult  
1735 for ii := range v.Remark { 1734 for ii := range v.Remark {
1736 for _, vvv := range item.Remark { 1735 for _, vvv := range item.Remark {
1737 if v.Remark[ii].Title == vvv.Title { 1736 if v.Remark[ii].Title == vvv.Title {
@@ -1740,7 +1739,6 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma @@ -1740,7 +1739,6 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma
1740 } 1739 }
1741 } 1740 }
1742 } 1741 }
1743 -  
1744 } 1742 }
1745 //保存信息 1743 //保存信息
1746 for i := range assessContentList { 1744 for i := range assessContentList {
1 package service 1 package service
2 2
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
  8 +)
  9 +
3 //员工绩效-项目管理 10 //员工绩效-项目管理
4 11
5 //获取已被执行的周期列表 12 //获取已被执行的周期列表
6 -func (srv StaffAssessServeice) GetAllAssessCycleName() { 13 +func (srv StaffAssessServeice) ListAllAssessCycle(companyid int) (map[string]interface{}, error) {
  14 + transactionContext, err := factory.CreateTransactionContext(nil)
  15 + if err != nil {
  16 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  17 + }
  18 + if err := transactionContext.StartTransaction(); err != nil {
  19 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  20 + }
  21 + defer func() {
  22 + _ = transactionContext.RollbackTransaction()
  23 + }()
  24 + assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  25 + "transactionContext": transactionContext,
  26 + })
  27 + cycleList, err := assessDao.AllAssessCycleList(companyid)
  28 + if err != nil {
  29 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取周期列表"+err.Error())
  30 + }
  31 + if err := transactionContext.CommitTransaction(); err != nil {
  32 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  33 + }
  34 + result := map[string]interface{}{
  35 + "list": cycleList,
  36 + }
  37 + return result, nil
7 38
8 } 39 }
9 40
10 //获取周期内的考核日期 41 //获取周期内的考核日期
  42 +func (srv StaffAssessServeice) ListAllAssessCycleDay(param *query.ListAssessCycleDay) (map[string]interface{}, error) {
  43 + transactionContext, err := factory.CreateTransactionContext(nil)
  44 + if err != nil {
  45 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  46 + }
  47 + if err := transactionContext.StartTransaction(); err != nil {
  48 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  49 + }
  50 + defer func() {
  51 + _ = transactionContext.RollbackTransaction()
  52 + }()
  53 + assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  54 + "transactionContext": transactionContext,
  55 + })
  56 + cycleDayList, err := assessDao.AllAssessCycleDayList(param.CompanyId, param.CycleId)
  57 + if err != nil {
  58 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取周期列表"+err.Error())
  59 + }
  60 + if err := transactionContext.CommitTransaction(); err != nil {
  61 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  62 + }
  63 + result := map[string]interface{}{
  64 + "list": cycleDayList,
  65 + }
  66 + return result, nil
  67 +}
1 package domain 1 package domain
2 2
3 import ( 3 import (
4 - "errors"  
5 - "fmt"  
6 - "strconv"  
7 "time" 4 "time"
8 ) 5 )
9 6
@@ -58,54 +55,54 @@ type EvaluationRule struct { @@ -58,54 +55,54 @@ type EvaluationRule struct {
58 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` 55 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
59 } 56 }
60 57
61 -// 根据评估填写的值,得出等级名称  
62 -// 如果 评估方式是评分,对评估填写的值的小数点后的位数进行处理,  
63 -// value 根据评估填写的值  
64 -func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) {  
65 - switch rule.Type {  
66 - case EvaluationTypeRating:  
67 - return rule.RatingValue(value)  
68 - case EvaluationTypeScore:  
69 - return rule.ScoreValue(value)  
70 - }  
71 - return "", errors.New("rule.Type 错误")  
72 -}  
73 -  
74 -//根据评估填写的值,得出等级名称,  
75 -func (rule *EvaluationRule) ScoreValue(value *string) (string, error) {  
76 - valueFloat, err := strconv.ParseFloat(*value, 64)  
77 - if err != nil {  
78 - return "", errors.New("评分填写的值错误")  
79 - }  
80 - if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {  
81 - return "", fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)  
82 - }  
83 - //保留小数处理  
84 - fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)  
85 - valueStr := fmt.Sprintf(fStr, valueFloat)  
86 - *value = valueStr  
87 - if rule.Score.IntervalState == 0 {  
88 - // 未开启按分数子区间匹配等级  
89 - return "", nil  
90 - }  
91 - valueDescrip := ""  
92 - for _, v := range rule.Score.Levels {  
93 - if valueFloat >= v.Start && valueFloat <= v.End {  
94 - valueDescrip = v.Name  
95 - }  
96 - }  
97 - return valueDescrip, nil  
98 -}  
99 -  
100 -//根据评估填写的值,得出等级名称,  
101 -func (rule *EvaluationRule) RatingValue(value *string) (string, error) {  
102 - for _, v := range rule.Rating.Levels {  
103 - if v.Code == *value {  
104 - return v.Name, nil  
105 - }  
106 - }  
107 - return "", errors.New("评估填写的值错误")  
108 -} 58 +// // 根据评估填写的值,得出等级名称和填写的值量化值
  59 +// // 如果 评估方式是评分,对评估填写的值的小数点后的位数进行处理,
  60 +// // value 根据评估填写的值
  61 +// func (rule *EvaluationRule) ScoreOrRating(value *string) (string, error) {
  62 +// switch rule.Type {
  63 +// case EvaluationTypeRating:
  64 +// return rule.RatingValue(value)
  65 +// case EvaluationTypeScore:
  66 +// return rule.ScoreValue(value)
  67 +// }
  68 +// return "", errors.New("rule.Type 错误")
  69 +// }
  70 +
  71 +// //根据评估填写的值,得出等级名称和填写的值量化值
  72 +// func (rule *EvaluationRule) ScoreValue(value *string) (string, error) {
  73 +// valueFloat, err := strconv.ParseFloat(*value, 64)
  74 +// if err != nil {
  75 +// return "", errors.New("评分填写的值错误")
  76 +// }
  77 +// if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
  78 +// return "", fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
  79 +// }
  80 +// //保留小数处理
  81 +// fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
  82 +// valueStr := fmt.Sprintf(fStr, valueFloat)
  83 +// *value = valueStr
  84 +// if rule.Score.IntervalState == 0 {
  85 +// // 未开启按分数子区间匹配等级
  86 +// return "", nil
  87 +// }
  88 +// valueDescrip := ""
  89 +// for _, v := range rule.Score.Levels {
  90 +// if valueFloat >= v.Start && valueFloat <= v.End {
  91 +// valueDescrip = v.Name
  92 +// }
  93 +// }
  94 +// return valueDescrip, nil
  95 +// }
  96 +
  97 +// //根据评估填写的值,得出等级名称,
  98 +// func (rule *EvaluationRule) RatingValue(value *string) (string, error) {
  99 +// for _, v := range rule.Rating.Levels {
  100 +// if v.Code == *value {
  101 +// return v.Name, nil
  102 +// }
  103 +// }
  104 +// return "", errors.New("评估填写的值错误")
  105 +// }
109 106
110 // GenerateSysRule 当前公司下的生成默认规则 107 // GenerateSysRule 当前公司下的生成默认规则
111 func GenerateSysRule(companyId int64) *EvaluationRule { 108 func GenerateSysRule(companyId int64) *EvaluationRule {
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "strconv"
  7 + "time"
  8 +)
4 9
5 //填写的评估内容 10 //填写的评估内容
6 type StaffAssessContent struct { 11 type StaffAssessContent struct {
@@ -13,6 +18,8 @@ type StaffAssessContent struct { @@ -13,6 +18,8 @@ type StaffAssessContent struct {
13 PromptText string `json:"promptText"` //提示项正文 18 PromptText string `json:"promptText"` //提示项正文
14 Remark []AssessContemtRemark `json:"remark"` //填写的反馈 19 Remark []AssessContemtRemark `json:"remark"` //填写的反馈
15 Value string `json:"value"` //评估填写的值 20 Value string `json:"value"` //评估填写的值
  21 + ScoreValue float64 `json:"scoreValue"` // 填写值按规则Rule转换为相应的量化值
  22 + LevelValue string `json:"levelValue"` // 填写值按规则Rule转换为相应的等级值
16 ReteResult string `json:"reteResult"` //评估的结果 23 ReteResult string `json:"reteResult"` //评估的结果
17 Rule EvaluationRule `json:"rule"` //评估的选项规则 24 Rule EvaluationRule `json:"rule"` //评估的选项规则
18 Weight int `json:"weight" ` //"权重" 25 Weight int `json:"weight" ` //"权重"
@@ -28,6 +35,63 @@ type AssessContemtRemark struct { @@ -28,6 +35,63 @@ type AssessContemtRemark struct {
28 RemarkText string `json:"remarkText"` // comment:"填写文本内容" 35 RemarkText string `json:"remarkText"` // comment:"填写文本内容"
29 } 36 }
30 37
  38 +//TransformValue
  39 +//根据规则 rule 转换评填写的值
  40 +func (content *StaffAssessContent) TransformValue() error {
  41 + switch content.Rule.Type {
  42 + case EvaluationTypeRating:
  43 + return content.ratingValue()
  44 + case EvaluationTypeScore:
  45 + return content.scoreValue()
  46 + }
  47 + return nil
  48 +}
  49 +
  50 +// 规则是评级方式
  51 +func (content *StaffAssessContent) ratingValue() error {
  52 + levels := content.Rule.Rating.Levels
  53 + for _, v := range levels {
  54 + if v.Code != content.Value {
  55 + continue
  56 + }
  57 + content.LevelValue = v.Code
  58 + content.ScoreValue = v.QuantizedValue
  59 + content.ReteResult = v.Name
  60 + return nil
  61 + }
  62 + return errors.New("评级填写的值错误")
  63 +}
  64 +
  65 +// 规则是评分方式
  66 +func (content *StaffAssessContent) scoreValue() error {
  67 + valueFloat, err := strconv.ParseFloat(content.Value, 64)
  68 + if err != nil {
  69 + return errors.New("评分填写的值错误")
  70 + }
  71 + rule := &content.Rule
  72 + if valueFloat < rule.Score.Min || valueFloat > rule.Score.Max {
  73 + return fmt.Errorf("评分填写的值超出限制,>=%f且<=%f", rule.Score.Min, rule.Score.Max)
  74 + }
  75 + //保留小数处理
  76 + fStr := fmt.Sprintf("%%.%df", rule.Score.DecimalPlaces)
  77 + valueStr := fmt.Sprintf(fStr, valueFloat)
  78 + content.Value = valueStr
  79 + if rule.Score.IntervalState == 0 {
  80 + // 未开启按分数子区间匹配等级
  81 + return nil
  82 + }
  83 + for _, v := range rule.Score.Levels {
  84 + if valueFloat < v.Start || valueFloat > v.End {
  85 + continue
  86 + }
  87 + content.LevelValue = v.Code
  88 + content.ScoreValue = valueFloat
  89 + content.ReteResult = v.Name
  90 + return nil
  91 + }
  92 + return errors.New("评分填写的值错误")
  93 +}
  94 +
31 type StaffAssessContentRepository interface { 95 type StaffAssessContentRepository interface {
32 Save(param *StaffAssessContent) (*StaffAssessContent, error) 96 Save(param *StaffAssessContent) (*StaffAssessContent, error)
33 Remove(id int) error 97 Remove(id int) error
@@ -153,3 +153,32 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As @@ -153,3 +153,32 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As
153 } 153 }
154 154
155 //根据周期的id和日期获取员工填写的评估内容 155 //根据周期的id和日期获取员工填写的评估内容
  156 +
  157 +/**
  158 +with assess_list as(
  159 +select
  160 + staff_assess.id as staff_assess_id,
  161 + staff_assess.target_user ->>'userId' as target_user_id,
  162 + staff_assess.target_user ->>'userName' as target_user_name,
  163 + staff_assess.evaluation_project_id,
  164 + to_char( staff_assess.begin_time,'YYYY-MM-DD') as begin_day
  165 +from staff_assess
  166 +where staff_assess.cycle_id = 1594521861704650752
  167 +and to_char( staff_assess.begin_time,'YYYY-MM-DD') ='2022-11-22'
  168 +and staff_assess."types" ='self'
  169 +limit 5 offset 0
  170 +)
  171 +select
  172 +assess_list.target_user_id,
  173 +assess_list.target_user_name,
  174 +assess_list.begin_day,
  175 +assess_list.evaluation_project_id,
  176 +staff_assess_content.value ,
  177 +staff_assess_content.sort_by ,
  178 +staff_assess_content.category ,
  179 +staff_assess_content."name" ,
  180 +staff_assess_content.weight
  181 +from staff_assess_content
  182 +right join assess_list on assess_list.staff_assess_id = staff_assess_content.staff_assess_id
  183 +
  184 +**/
@@ -14,6 +14,8 @@ type StaffAssessContent struct { @@ -14,6 +14,8 @@ type StaffAssessContent struct {
14 SortBy int //排序 14 SortBy int //排序
15 Category string //类别 15 Category string //类别
16 Name string //名称 16 Name string //名称
  17 + ScoreValue float64 // 填写值按规则Rule转换为相应的量化值
  18 + LevelValue string // 填写值按规则Rule转换为相应的等级值
17 PromptTitle string //问题标题 19 PromptTitle string //问题标题
18 PromptText string //提示项正文 20 PromptText string //提示项正文
19 Value string //评估填写的值 21 Value string //评估填写的值
@@ -32,6 +32,8 @@ func (repo *StaffAssessContentRepository) TransformToDomain(d *models.StaffAsses @@ -32,6 +32,8 @@ func (repo *StaffAssessContentRepository) TransformToDomain(d *models.StaffAsses
32 PromptText: d.PromptText, 32 PromptText: d.PromptText,
33 Remark: d.Remark, 33 Remark: d.Remark,
34 Value: d.Value, 34 Value: d.Value,
  35 + ScoreValue: d.ScoreValue,
  36 + LevelValue: d.LevelValue,
35 ReteResult: d.ReteResult, 37 ReteResult: d.ReteResult,
36 Rule: d.Rule, 38 Rule: d.Rule,
37 Weight: d.Weight, 39 Weight: d.Weight,
@@ -48,15 +50,17 @@ func (repo *StaffAssessContentRepository) Save(d *domain.StaffAssessContent) (*d @@ -48,15 +50,17 @@ func (repo *StaffAssessContentRepository) Save(d *domain.StaffAssessContent) (*d
48 SortBy: d.SortBy, 50 SortBy: d.SortBy,
49 Category: d.Category, 51 Category: d.Category,
50 Name: d.Name, 52 Name: d.Name,
  53 + ScoreValue: d.ScoreValue,
  54 + LevelValue: d.LevelValue,
51 PromptTitle: d.PromptTitle, 55 PromptTitle: d.PromptTitle,
52 PromptText: d.PromptText, 56 PromptText: d.PromptText,
53 - Remark: d.Remark,  
54 Value: d.Value, 57 Value: d.Value,
55 ReteResult: d.ReteResult, 58 ReteResult: d.ReteResult,
56 Rule: d.Rule, 59 Rule: d.Rule,
  60 + Remark: d.Remark,
  61 + Weight: d.Weight,
57 CreatedAt: d.CreatedAt, 62 CreatedAt: d.CreatedAt,
58 UpdatedAt: d.UpdatedAt, 63 UpdatedAt: d.UpdatedAt,
59 - Weight: d.Weight,  
60 DeletedAt: nil, 64 DeletedAt: nil,
61 } 65 }
62 tx := repo.transactionContext.PgTx 66 tx := repo.transactionContext.PgTx
@@ -279,3 +279,35 @@ func (c *StaffAssessController) ListTargetUserMeSupperAssess() { @@ -279,3 +279,35 @@ func (c *StaffAssessController) ListTargetUserMeSupperAssess() {
279 data, err := srv.ListTargetUserAssess(paramReq) 279 data, err := srv.ListTargetUserAssess(paramReq)
280 c.Response(data, err) 280 c.Response(data, err)
281 } 281 }
  282 +
  283 +//获取周期列表
  284 +func (c *StaffAssessController) ListAssessCycle() {
  285 + srv := service.NewStaffAssessServeice()
  286 + // paramReq := &query.ListTargetUserAssessQuery{}
  287 + // err := c.BindJSON(paramReq)
  288 + // if err != nil {
  289 + // e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  290 + // c.Response(nil, e)
  291 + // return
  292 + // }
  293 + userReq := middlewares.GetUser(c.Ctx)
  294 +
  295 + data, err := srv.ListAllAssessCycle(int(userReq.CompanyId))
  296 + c.Response(data, err)
  297 +}
  298 +
  299 +//获取周期里的考核日期
  300 +func (c *StaffAssessController) ListAssessCycleDay() {
  301 + srv := service.NewStaffAssessServeice()
  302 + paramReq := &query.ListAssessCycleDay{}
  303 + err := c.BindJSON(paramReq)
  304 + if err != nil {
  305 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  306 + c.Response(nil, e)
  307 + return
  308 + }
  309 + userReq := middlewares.GetUser(c.Ctx)
  310 + paramReq.CompanyId = int(userReq.CompanyId)
  311 + data, err := srv.ListAllAssessCycleDay(paramReq)
  312 + c.Response(data, err)
  313 +}
@@ -13,6 +13,8 @@ func init() { @@ -13,6 +13,8 @@ func init() {
13 web.NSCtrlPost("/search/me", (*controllers.StaffAssessController).SearchAssessTaskMe), //获取我参与过的评估项目列表 13 web.NSCtrlPost("/search/me", (*controllers.StaffAssessController).SearchAssessTaskMe), //获取我参与过的评估项目列表
14 web.NSCtrlPost("/desc/me", (*controllers.StaffAssessController).AssessTaskMeDesc), //获取我的项目评估进度描述 14 web.NSCtrlPost("/desc/me", (*controllers.StaffAssessController).AssessTaskMeDesc), //获取我的项目评估进度描述
15 web.NSCtrlPost("/", (*controllers.StaffAssessController).CreateStaffAssessTask), //创建员工的评估任务 15 web.NSCtrlPost("/", (*controllers.StaffAssessController).CreateStaffAssessTask), //创建员工的评估任务
  16 + web.NSCtrlGet("/cycle", (*controllers.StaffAssessController).ListAssessCycle), //获取周期列表
  17 + web.NSCtrlPost("/cycle/day", (*controllers.StaffAssessController).ListAssessCycleDay), //获取周期中的考核日期
16 ) 18 )
17 // /v1/staff-assess/self/me/list 19 // /v1/staff-assess/self/me/list
18 assessNS := web.NewNamespace("/v1/staff-assess", 20 assessNS := web.NewNamespace("/v1/staff-assess",