作者 郑周

Merge remote-tracking branch 'origin/test' into test

@@ -57,7 +57,6 @@ type AssessCountLeveltItem struct { @@ -57,7 +57,6 @@ type AssessCountLeveltItem struct {
57 57
58 // 评级数量 58 // 评级数量
59 type LevalCodeCount struct { 59 type LevalCodeCount struct {
60 - Code string `json:"code"` //评级代码  
61 - Number int `json:"number"` //数量  
62 - ItemList []string `json:"itemList"` //对应的评估项名称 60 + Code string `json:"code"` //评级代码
  61 + Number int `json:"number"` //数量
63 } 62 }
@@ -3,6 +3,6 @@ package query @@ -3,6 +3,6 @@ package query
3 type ListTargetUserCycleQuery struct { 3 type ListTargetUserCycleQuery struct {
4 PageNumber int `json:"pageNumber"` 4 PageNumber int `json:"pageNumber"`
5 PageSize int `json:"pageSize"` 5 PageSize int `json:"pageSize"`
6 - CompanyId int `json:"companyId"` // 6 + CompanyId int `json:"-"` //
7 TargetUserId int `json:"targetUserId,string"` //评估的执行人,必填 7 TargetUserId int `json:"targetUserId,string"` //评估的执行人,必填
8 } 8 }
@@ -17,7 +17,7 @@ type ExportUserAssess2Commad struct { @@ -17,7 +17,7 @@ type ExportUserAssess2Commad struct {
17 17
18 type StaffAsessSelfCountLevel struct { 18 type StaffAsessSelfCountLevel struct {
19 CompanyId int `cname:"公司ID" json:"-"` 19 CompanyId int `cname:"公司ID" json:"-"`
20 - TargetUserId int `json:"targetUserId"` 20 + TargetUserId int `json:"targetUserId,string"`
21 ProjectId int `json:"projectId,string"` 21 ProjectId int `json:"projectId,string"`
22 CycleId int `cname:"周期ID" json:"cycleId,string"` 22 CycleId int `cname:"周期ID" json:"cycleId,string"`
23 } 23 }
1 -package service  
2 -  
3 -// // excel表头部字段  
4 -// type excelTableHeader struct {  
5 -// Level1 string  
6 -// Level2 string  
7 -// Level3 string  
8 -// Level4 string  
9 -// }  
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "strconv" 5 "strconv"
6 "time" 6 "time"
7 7
  8 + "github.com/linmadan/egglib-go/core/application"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
@@ -18,25 +19,24 @@ func TaskSendSummaryEvaluationV2() error { @@ -18,25 +19,24 @@ func TaskSendSummaryEvaluationV2() error {
18 str := fmt.Sprintf("下发周期评估耗时%.2f s", time.Since(nowTime).Seconds()) 19 str := fmt.Sprintf("下发周期评估耗时%.2f s", time.Since(nowTime).Seconds())
19 log.Logger.Info(str) 20 log.Logger.Info(str)
20 }() 21 }()
21 - var newPublisher summaryEvaluationPublisher  
22 for { 22 for {
23 - projectList, err := getPrepareSummaryEvaluation() 23 + cycleList, err := getPrepareEvaluationCycle()
24 if err != nil { 24 if err != nil {
25 return err 25 return err
26 } 26 }
27 - if len(projectList) == 0 { 27 + if len(cycleList) == 0 {
28 break 28 break
29 } 29 }
30 - newPublisher = summaryEvaluationPublisher{}  
31 - for _, val := range projectList {  
32 - err = newPublisher.sendSummaryEvaluationV2(val) 30 + err = sendSummaryEvaluationByCycle(cycleList[0])
  31 + if err != nil {
33 return err 32 return err
34 } 33 }
35 } 34 }
36 return nil 35 return nil
37 } 36 }
38 37
39 -func getPrepareSummaryEvaluation() ([]*domain.EvaluationProject, error) { 38 +// 获取周期
  39 +func getPrepareEvaluationCycle() ([]*domain.EvaluationCycle, error) {
40 transactionContext, err := factory.CreateTransactionContext(nil) 40 transactionContext, err := factory.CreateTransactionContext(nil)
41 if err != nil { 41 if err != nil {
42 return nil, err 42 return nil, err
@@ -47,56 +47,131 @@ func getPrepareSummaryEvaluation() ([]*domain.EvaluationProject, error) { @@ -47,56 +47,131 @@ func getPrepareSummaryEvaluation() ([]*domain.EvaluationProject, error) {
47 defer func() { 47 defer func() {
48 _ = transactionContext.RollbackTransaction() 48 _ = transactionContext.RollbackTransaction()
49 }() 49 }()
  50 + cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
  51 + cycleList, err := cycleRepo.FindCycleEnd(1)
  52 + if err != nil {
  53 + return nil, fmt.Errorf("获取可用的周期数据,%s", err)
  54 + }
  55 + if err := transactionContext.CommitTransaction(); err != nil {
  56 + return nil, err
  57 + }
  58 + return cycleList, nil
  59 +}
  60 +
  61 +// 获取可用的项目
  62 +// func getPrepareSummaryEvaluation(cycleId int) ([]*domain.EvaluationProject, error) {
  63 +// transactionContext, err := factory.CreateTransactionContext(nil)
  64 +// if err != nil {
  65 +// return nil, err
  66 +// }
  67 +// if err := transactionContext.StartTransaction(); err != nil {
  68 +// return nil, err
  69 +// }
  70 +// defer func() {
  71 +// _ = transactionContext.RollbackTransaction()
  72 +// }()
  73 +// projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
  74 +// "transactionContext": transactionContext,
  75 +// })
  76 +// // 获取项目数据总数
  77 +// _, projectList, err := projectRepo.Find(map[string]interface{}{
  78 +// "cycleId": cycleId,
  79 +// "summaryState": domain.ProjectSummaryStateNo,
  80 +// "state": domain.ProjectStateEnable,
  81 +// "limit": 200,
  82 +// }, "template")
  83 +// if err != nil {
  84 +// return nil, fmt.Errorf("获取可用的项目数据,%s", err)
  85 +// }
  86 +// if err := transactionContext.CommitTransaction(); err != nil {
  87 +// return nil, err
  88 +// }
  89 +// return projectList, nil
  90 +// }
  91 +
  92 +// 按周期下发 综合评估任务
  93 +func sendSummaryEvaluationByCycle(cycleParam *domain.EvaluationCycle) error {
  94 + transactionContext, err := factory.CreateTransactionContext(nil)
  95 + if err != nil {
  96 + return err
  97 + }
  98 + if err := transactionContext.StartTransaction(); err != nil {
  99 + return err
  100 + }
  101 + defer func() {
  102 + _ = transactionContext.RollbackTransaction()
  103 + }()
  104 +
50 projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{ 105 projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
51 "transactionContext": transactionContext, 106 "transactionContext": transactionContext,
52 }) 107 })
53 // 获取项目数据总数 108 // 获取项目数据总数
54 _, projectList, err := projectRepo.Find(map[string]interface{}{ 109 _, projectList, err := projectRepo.Find(map[string]interface{}{
55 - "endTime": time.Now(), 110 + "cycleId": cycleParam.Id,
56 "summaryState": domain.ProjectSummaryStateNo, 111 "summaryState": domain.ProjectSummaryStateNo,
57 "state": domain.ProjectStateEnable, 112 "state": domain.ProjectStateEnable,
58 - "limit": 200, 113 + "limit": 500,
59 }, "template") 114 }, "template")
60 if err != nil { 115 if err != nil {
61 - return nil, fmt.Errorf("获取可用的项目数据,%s", err) 116 + return fmt.Errorf("获取可用的项目数据,%s", err)
  117 + }
  118 + var newEvaluationList []domain.SummaryEvaluation
  119 + newPublisher := summaryEvaluationPublisher{}
  120 + for _, val := range projectList {
  121 + evaluationList, err := newPublisher.sendSummaryEvaluationV2(transactionContext, val, cycleParam)
  122 + if err != nil {
  123 + return fmt.Errorf("按项目下发综合评估任务数据,%s", err)
  124 + }
  125 + newEvaluationList = append(newEvaluationList, evaluationList...)
  126 + }
  127 + // 回填周期的状态
  128 + cycleDao := dao.NewEvaluationCycleDao(map[string]interface{}{"transactionContext": transactionContext})
  129 + err = cycleDao.UpdateSummaryState(cycleParam.Id, domain.ProjectSummaryStateYes)
  130 + if err != nil {
  131 + return fmt.Errorf("保存项目周期状态%s", err)
62 } 132 }
63 if err := transactionContext.CommitTransaction(); err != nil { 133 if err := transactionContext.CommitTransaction(); err != nil {
64 - return nil, err 134 + return err
  135 + }
  136 + err = sendSmsEvalation(newEvaluationList)
  137 + if err != nil {
  138 + return fmt.Errorf("设置短信消息%s", err)
65 } 139 }
66 - return projectList, nil 140 + return nil
67 } 141 }
68 142
69 // 下发周期综合评估 143 // 下发周期综合评估
70 type summaryEvaluationPublisher struct { 144 type summaryEvaluationPublisher struct {
71 userCache map[int64]*domain.User 145 userCache map[int64]*domain.User
72 departCache map[int]*domain.Department 146 departCache map[int]*domain.Department
73 - cycleCache map[int64]*domain.EvaluationCycle  
74 } 147 }
75 148
76 -func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *domain.EvaluationProject) error {  
77 - transactionContext, err := factory.CreateTransactionContext(nil)  
78 - if err != nil {  
79 - return err  
80 - }  
81 - if err := transactionContext.StartTransaction(); err != nil {  
82 - return err  
83 - }  
84 - defer func() {  
85 - _ = transactionContext.RollbackTransaction()  
86 - }() 149 +func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(
  150 + transactionContext application.TransactionContext,
  151 + projectParam *domain.EvaluationProject, cycleData *domain.EvaluationCycle,
  152 +) ([]domain.SummaryEvaluation, error) {
  153 + // transactionContext, err := factory.CreateTransactionContext(nil)
  154 + // if err != nil {
  155 + // return err
  156 + // }
  157 + // if err := transactionContext.StartTransaction(); err != nil {
  158 + // return err
  159 + // }
  160 + // defer func() {
  161 + // _ = transactionContext.RollbackTransaction()
  162 + // }()
87 userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext}) 163 userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
88 departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext}) 164 departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
89 - cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})  
90 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext}) 165 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
91 _, evaluationItemList, err := evaluationItemRepo.Find(map[string]interface{}{ 166 _, evaluationItemList, err := evaluationItemRepo.Find(map[string]interface{}{
92 "evaluationProjectId": projectParam.Id, 167 "evaluationProjectId": projectParam.Id,
93 "nodeType": int(domain.LinkNodeSelfAssessment), 168 "nodeType": int(domain.LinkNodeSelfAssessment),
94 }) 169 })
95 if err != nil { 170 if err != nil {
96 - return err 171 + return nil, err
97 } 172 }
98 if len(evaluationItemList) == 0 { 173 if len(evaluationItemList) == 0 {
99 - return nil 174 + return nil, nil
100 } 175 }
101 nodeId := evaluationItemList[0].NodeId 176 nodeId := evaluationItemList[0].NodeId
102 executor360Map := map[int64]*domain.User{} 177 executor360Map := map[int64]*domain.User{}
@@ -111,20 +186,12 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *doma @@ -111,20 +186,12 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *doma
111 } 186 }
112 user360, err := se.getUserData(userRepo, int64(v.EvaluatorId)) 187 user360, err := se.getUserData(userRepo, int64(v.EvaluatorId))
113 if err != nil { 188 if err != nil {
114 - return fmt.Errorf("获取360用户%s", err) 189 + return nil, fmt.Errorf("获取360用户%s", err)
115 } 190 }
116 executor360Map[user360.Id] = user360 191 executor360Map[user360.Id] = user360
117 } 192 }
118 - //获取周期  
119 - cycleData, err := se.getCycleData(cycleRepo, projectParam.CycleId)  
120 - if err != nil {  
121 - return err  
122 - }  
123 - if cycleData == nil {  
124 - return nil  
125 - }  
126 if cycleData.TimeEnd == nil { 193 if cycleData.TimeEnd == nil {
127 - return fmt.Errorf("周期%d:%s 结束时间错误", cycleData.Id, cycleData.Name) 194 + return nil, fmt.Errorf("周期%d:%s 结束时间错误", cycleData.Id, cycleData.Name)
128 } 195 }
129 //自评的时间范围 196 //自评的时间范围
130 beginTimeSelf := *cycleData.TimeEnd 197 beginTimeSelf := *cycleData.TimeEnd
@@ -166,14 +233,14 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *doma @@ -166,14 +233,14 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *doma
166 } 233 }
167 targetUser, err := se.getUserData(userRepo, targetUserId) 234 targetUser, err := se.getUserData(userRepo, targetUserId)
168 if err != nil { 235 if err != nil {
169 - return fmt.Errorf("获取员工数据%s", err) 236 + return nil, fmt.Errorf("获取员工数据%s", err)
170 } 237 }
171 if targetUser == nil { 238 if targetUser == nil {
172 continue 239 continue
173 } 240 }
174 targetUserDepartment, err := se.getDepartmentData(departmentRepo, targetUser.DepartmentId) 241 targetUserDepartment, err := se.getDepartmentData(departmentRepo, targetUser.DepartmentId)
175 if err != nil { 242 if err != nil {
176 - return fmt.Errorf("获取员工的部门数据%s", err) 243 + return nil, fmt.Errorf("获取员工的部门数据%s", err)
177 } 244 }
178 evaluationTemp.TargetDepartment = []domain.StaffDepartment{} 245 evaluationTemp.TargetDepartment = []domain.StaffDepartment{}
179 evaluationTemp.Types = domain.EvaluationSelf 246 evaluationTemp.Types = domain.EvaluationSelf
@@ -254,39 +321,38 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *doma @@ -254,39 +321,38 @@ func (se *summaryEvaluationPublisher) sendSummaryEvaluationV2(projectParam *doma
254 for i := range newEvaluationList { 321 for i := range newEvaluationList {
255 err = summaryEvaluationRepo.Save(&newEvaluationList[i]) 322 err = summaryEvaluationRepo.Save(&newEvaluationList[i])
256 if err != nil { 323 if err != nil {
257 - return fmt.Errorf("保存周期综合评估%s", err) 324 + return nil, fmt.Errorf("保存周期综合评估%s", err)
258 } 325 }
259 } 326 }
260 //回填项目的状态 327 //回填项目的状态
261 projectDao := dao.NewEvaluationProjectDao(map[string]interface{}{"transactionContext": transactionContext}) 328 projectDao := dao.NewEvaluationProjectDao(map[string]interface{}{"transactionContext": transactionContext})
262 err = projectDao.UpdateSummaryState(projectParam.Id, domain.ProjectSummaryStateYes) 329 err = projectDao.UpdateSummaryState(projectParam.Id, domain.ProjectSummaryStateYes)
263 if err != nil { 330 if err != nil {
264 - return fmt.Errorf("保存项目状态%s", err)  
265 - }  
266 - if err := transactionContext.CommitTransaction(); err != nil {  
267 - return err 331 + return nil, fmt.Errorf("保存项目状态%s", err)
268 } 332 }
269 - err = sendSmsEvalation(newEvaluationList)  
270 - return fmt.Errorf("设置短信发送%s", err) 333 + // if err := transactionContext.CommitTransaction(); err != nil {
  334 + // return err
  335 + // }
  336 + return newEvaluationList, fmt.Errorf("设置短信发送%s", err)
271 } 337 }
272 338
273 // 获取周期设置数据 339 // 获取周期设置数据
274 -func (se *summaryEvaluationPublisher) getCycleData(cycleRepo domain.EvaluationCycleRepository, cycleId int64) (*domain.EvaluationCycle, error) {  
275 - var cycleData *domain.EvaluationCycle  
276 - if val, ok := se.cycleCache[cycleId]; ok {  
277 - cycleData = val  
278 - } else {  
279 - _, cycleList, err := cycleRepo.Find(map[string]interface{}{"id": cycleId})  
280 - if err != nil {  
281 - return nil, err  
282 - }  
283 - if len(cycleList) == 0 {  
284 - return nil, nil  
285 - }  
286 - cycleData = cycleList[0]  
287 - }  
288 - return cycleData, nil  
289 -} 340 +// func (se *summaryEvaluationPublisher) getCycleData(cycleRepo domain.EvaluationCycleRepository, cycleId int64) (*domain.EvaluationCycle, error) {
  341 +// var cycleData *domain.EvaluationCycle
  342 +// if val, ok := se.cycleCache[cycleId]; ok {
  343 +// cycleData = val
  344 +// } else {
  345 +// _, cycleList, err := cycleRepo.Find(map[string]interface{}{"id": cycleId})
  346 +// if err != nil {
  347 +// return nil, err
  348 +// }
  349 +// if len(cycleList) == 0 {
  350 +// return nil, nil
  351 +// }
  352 +// cycleData = cycleList[0]
  353 +// }
  354 +// return cycleData, nil
  355 +// }
290 356
291 // 获取用户数据 357 // 获取用户数据
292 func (se *summaryEvaluationPublisher) getUserData(userRepo domain.UserRepository, userId int64) (*domain.User, error) { 358 func (se *summaryEvaluationPublisher) getUserData(userRepo domain.UserRepository, userId int64) (*domain.User, error) {
@@ -21,16 +21,17 @@ type TemplateSimple struct { @@ -21,16 +21,17 @@ type TemplateSimple struct {
21 } 21 }
22 22
23 type EvaluationCycle struct { 23 type EvaluationCycle struct {
24 - Id int64 `json:"id,string" comment:"ID"`  
25 - Name string `json:"name" comment:"名称"`  
26 - TimeStart *time.Time `json:"timeStart" comment:"起始时间"`  
27 - TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`  
28 - CompanyId int64 `json:"companyId,string" comment:"公司ID"`  
29 - CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`  
30 - KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`  
31 - CreatedAt time.Time `json:"createdAt" comment:"创建时间"`  
32 - UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`  
33 - DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` 24 + Id int64 `json:"id,string" comment:"ID"`
  25 + Name string `json:"name" comment:"名称"`
  26 + TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
  27 + TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
  28 + CompanyId int64 `json:"companyId,string" comment:"公司ID"`
  29 + CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
  30 + KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
  31 + SummaryState ProjectSummaryState `json:"summaryState" comment:"周期评估是否下发"`
  32 + CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
  33 + UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
  34 + DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
34 } 35 }
35 36
36 type EvaluationCycleRepository interface { 37 type EvaluationCycleRepository interface {
@@ -39,4 +40,5 @@ type EvaluationCycleRepository interface { @@ -39,4 +40,5 @@ type EvaluationCycleRepository interface {
39 FindOne(queryOptions map[string]interface{}) (*EvaluationCycle, error) 40 FindOne(queryOptions map[string]interface{}) (*EvaluationCycle, error)
40 Find(queryOptions map[string]interface{}) (int64, []*EvaluationCycle, error) 41 Find(queryOptions map[string]interface{}) (int64, []*EvaluationCycle, error)
41 Count(queryOptions map[string]interface{}) (int64, error) 42 Count(queryOptions map[string]interface{}) (int64, error)
  43 + FindCycleEnd(limit int) ([]*EvaluationCycle, error) // 获取已结束的周期,且还没下发周期评估
42 } 44 }
@@ -34,6 +34,7 @@ type EvaluationProject struct { @@ -34,6 +34,7 @@ type EvaluationProject struct {
34 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` 34 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
35 } 35 }
36 36
  37 +// 周期评估的下发状态
37 type ProjectSummaryState int 38 type ProjectSummaryState int
38 39
39 const ( 40 const (
  1 +package dao
  2 +
  3 +import (
  4 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  5 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
  7 +)
  8 +
  9 +type EvaluationCycleDao struct {
  10 + transactionContext *pgTransaction.TransactionContext
  11 +}
  12 +
  13 +func NewEvaluationCycleDao(options map[string]interface{}) *EvaluationCycleDao {
  14 + var transactionContext *pgTransaction.TransactionContext
  15 + if value, ok := options["transactionContext"]; ok {
  16 + transactionContext = value.(*pgTransaction.TransactionContext)
  17 + }
  18 + return &EvaluationCycleDao{
  19 + transactionContext: transactionContext,
  20 + }
  21 +}
  22 +
  23 +func (d *EvaluationCycleDao) UpdateSummaryState(id int64, status domain.ProjectSummaryState) error {
  24 + db := d.transactionContext.PgTx
  25 + _, err := db.Model(&models.EvaluationCycle{}).
  26 + Where("id=?", id).
  27 + Set("summary_state=?", int(status)).
  28 + Update()
  29 + return err
  30 +}
@@ -1253,7 +1253,7 @@ group by level_value,category,"name" ` @@ -1253,7 +1253,7 @@ group by level_value,category,"name" `
1253 1253
1254 var result []AssessContentLevelCode 1254 var result []AssessContentLevelCode
1255 condition := []interface{}{ 1255 condition := []interface{}{
1256 - projectId, targetUserId, string(assessType), cycleId, 1256 + targetUserId, string(assessType), cycleId, projectId,
1257 } 1257 }
1258 tx := d.transactionContext.PgTx 1258 tx := d.transactionContext.PgTx
1259 _, err := tx.Query(&result, sqlStr, condition...) 1259 _, err := tx.Query(&result, sqlStr, condition...)
@@ -174,33 +174,32 @@ func (d *StaffAssessDao) catchProjectIdByPermission(companyId int, cycleId int, @@ -174,33 +174,32 @@ func (d *StaffAssessDao) catchProjectIdByPermission(companyId int, cycleId int,
174 } 174 }
175 175
176 type TargetUserCycleProject struct { 176 type TargetUserCycleProject struct {
177 - CycleId string `pg:"cycle_id" json:"cycleId"` //周期id  
178 - CycleName string `pg:"cycle_name" json:"cycleName"` //周期名称  
179 - EvaluationProjectIds []string `pg:"evaluation_project_ids" json:"evaluationProjectIds"` 177 + CycleId string `pg:"cycle_id" json:"cycleId"` //周期id
  178 + CycleName string `pg:"cycle_name" json:"cycleName"` //周期名称
  179 + EvaluationProjectId string `pg:"evaluation_project_id" json:"evaluationProjectId"`
  180 + EvaluationProjectName string `pg:"evaluation_project_name" json:"evaluationProjectName"`
  181 + TargetUserId string `pg:"target_user_id" json:"targetUserId"`
180 } 182 }
181 183
182 // 获取目标员工的自评周期和项目 184 // 获取目标员工的自评周期和项目
183 func (d *StaffAssessDao) SearchTargetUserCycleProject(companyId int, targetUserId int, limit int, offset int) ([]TargetUserCycleProject, error) { 185 func (d *StaffAssessDao) SearchTargetUserCycleProject(companyId int, targetUserId int, limit int, offset int) ([]TargetUserCycleProject, error) {
184 - sqlStr := ` with t_staff_assess as (  
185 - select distinct staff_assess.cycle_id ,  
186 - staff_assess.cycle_name,  
187 - staff_assess.evaluation_project_id  
188 - from staff_assess  
189 - where 1=1  
190 - and staff_assess."types" ='self'  
191 - and staff_assess.deleted_at isnull  
192 - and staff_assess.target_user ->>'userId'='?'  
193 - and staff_assess.company_id=?  
194 - )  
195 - select  
196 - t_staff_assess.cycle_id,  
197 - t_staff_assess.cycle_name,  
198 - array_agg(to_char(t_staff_assess.evaluation_project_id,'9999999999999999999')) as evaluation_project_ids  
199 - from t_staff_assess  
200 - group by cycle_id,cycle_name  
201 - limit ? offset ? 186 + sqlStr := `select distinct
  187 + staff_assess.cycle_name,
  188 + staff_assess.cycle_id ,
  189 + staff_assess.evaluation_project_id,
  190 + staff_assess.target_user ->>'userId' as target_user_id,
  191 + staff_assess.evaluation_project_name
  192 + from staff_assess ,staff_assess_task
  193 + where 1=1
  194 + and staff_assess_task.id =staff_assess.staff_assess_task_id
  195 + and staff_assess."types" ='self'
  196 + and staff_assess_task.deleted_at isnull
  197 + and staff_assess.deleted_at isnull
  198 + and staff_assess.target_user ->>'userId'='?'
  199 + and staff_assess.company_id=?
202 ` 200 `
203 - condition := []interface{}{companyId, targetUserId, limit, offset} 201 + sqlStr += ` order by cycle_id desc limit ? offset ? `
  202 + condition := []interface{}{targetUserId, companyId, limit, offset}
204 result := []TargetUserCycleProject{} 203 result := []TargetUserCycleProject{}
205 tx := d.transactionContext.PgTx 204 tx := d.transactionContext.PgTx
206 _, err := tx.Query(&result, sqlStr, condition...) 205 _, err := tx.Query(&result, sqlStr, condition...)
@@ -5,15 +5,16 @@ import ( @@ -5,15 +5,16 @@ import (
5 ) 5 )
6 6
7 type EvaluationCycle struct { 7 type EvaluationCycle struct {
8 - tableName struct{} `comment:"评估周期" pg:"evaluation_cycle"`  
9 - Id int64 `comment:"周期ID" pg:"pk:id"`  
10 - Name string `comment:"名称"`  
11 - TimeStart *time.Time `comment:"起始时间"`  
12 - TimeEnd *time.Time `comment:"截至时间"`  
13 - CompanyId int64 `comment:"公司ID"`  
14 - CreatorId int64 `comment:"创建人ID"`  
15 - KpiCycle int `comment:"考核周期(1日、2周、3月)"`  
16 - CreatedAt time.Time `comment:"创建时间"`  
17 - UpdatedAt time.Time `comment:"更新时间"`  
18 - DeletedAt *time.Time `comment:"删除时间"` 8 + tableName struct{} `comment:"评估周期" pg:"evaluation_cycle"`
  9 + Id int64 `comment:"周期ID" pg:"pk:id"`
  10 + Name string `comment:"名称"`
  11 + TimeStart *time.Time `comment:"起始时间"`
  12 + TimeEnd *time.Time `comment:"截至时间"`
  13 + CompanyId int64 `comment:"公司ID"`
  14 + CreatorId int64 `comment:"创建人ID"`
  15 + KpiCycle int `comment:"考核周期(1日、2周、3月)"`
  16 + SummaryState int `comment:"周期评估是否下发" pg:",use_zero"`
  17 + CreatedAt time.Time `comment:"创建时间"`
  18 + UpdatedAt time.Time `comment:"更新时间"`
  19 + DeletedAt *time.Time `comment:"删除时间"`
19 } 20 }
@@ -23,31 +23,33 @@ func NewEvaluationCycleRepository(transactionContext *pgTransaction.TransactionC @@ -23,31 +23,33 @@ func NewEvaluationCycleRepository(transactionContext *pgTransaction.TransactionC
23 23
24 func (repo *EvaluationCycleRepository) TransformToDomain(m *models.EvaluationCycle) domain.EvaluationCycle { 24 func (repo *EvaluationCycleRepository) TransformToDomain(m *models.EvaluationCycle) domain.EvaluationCycle {
25 return domain.EvaluationCycle{ 25 return domain.EvaluationCycle{
26 - Id: m.Id,  
27 - Name: m.Name,  
28 - TimeStart: m.TimeStart,  
29 - TimeEnd: m.TimeEnd,  
30 - CompanyId: m.CompanyId,  
31 - CreatorId: m.CreatorId,  
32 - KpiCycle: m.KpiCycle,  
33 - CreatedAt: m.CreatedAt.Local(),  
34 - UpdatedAt: m.UpdatedAt.Local(),  
35 - DeletedAt: m.DeletedAt, 26 + Id: m.Id,
  27 + Name: m.Name,
  28 + TimeStart: m.TimeStart,
  29 + TimeEnd: m.TimeEnd,
  30 + CompanyId: m.CompanyId,
  31 + CreatorId: m.CreatorId,
  32 + KpiCycle: m.KpiCycle,
  33 + SummaryState: domain.ProjectSummaryState(m.SummaryState),
  34 + CreatedAt: m.CreatedAt.Local(),
  35 + UpdatedAt: m.UpdatedAt.Local(),
  36 + DeletedAt: m.DeletedAt,
36 } 37 }
37 } 38 }
38 39
39 func (repo *EvaluationCycleRepository) TransformToModel(d *domain.EvaluationCycle) models.EvaluationCycle { 40 func (repo *EvaluationCycleRepository) TransformToModel(d *domain.EvaluationCycle) models.EvaluationCycle {
40 return models.EvaluationCycle{ 41 return models.EvaluationCycle{
41 - Id: d.Id,  
42 - Name: d.Name,  
43 - TimeStart: d.TimeStart,  
44 - TimeEnd: d.TimeEnd,  
45 - CompanyId: d.CompanyId,  
46 - CreatorId: d.CreatorId,  
47 - KpiCycle: d.KpiCycle,  
48 - CreatedAt: d.CreatedAt,  
49 - UpdatedAt: d.UpdatedAt,  
50 - DeletedAt: d.DeletedAt, 42 + Id: d.Id,
  43 + Name: d.Name,
  44 + TimeStart: d.TimeStart,
  45 + TimeEnd: d.TimeEnd,
  46 + CompanyId: d.CompanyId,
  47 + CreatorId: d.CreatorId,
  48 + KpiCycle: d.KpiCycle,
  49 + SummaryState: int(d.SummaryState),
  50 + CreatedAt: d.CreatedAt,
  51 + UpdatedAt: d.UpdatedAt,
  52 + DeletedAt: d.DeletedAt,
51 } 53 }
52 } 54 }
53 55
@@ -195,3 +197,25 @@ func (repo *EvaluationCycleRepository) Count(queryOptions map[string]interface{} @@ -195,3 +197,25 @@ func (repo *EvaluationCycleRepository) Count(queryOptions map[string]interface{}
195 } 197 }
196 return int64(count), nil 198 return int64(count), nil
197 } 199 }
  200 +
  201 +// 获取已结束的周期
  202 +func (repo *EvaluationCycleRepository) FindCycleEnd(limit int) ([]*domain.EvaluationCycle, error) {
  203 + tx := repo.transactionContext.PgTx
  204 + var m []*models.EvaluationCycle
  205 + query := tx.Model(&m).
  206 + Where("deleted_at isnull").
  207 + Where("time_end<=?", time.Now()).
  208 + Where("summary_state=0").
  209 + Limit(limit)
  210 +
  211 + err := query.Select()
  212 + if err != nil {
  213 + return nil, err
  214 + }
  215 + var arrays []*domain.EvaluationCycle
  216 + for _, v := range m {
  217 + d := repo.TransformToDomain(v)
  218 + arrays = append(arrays, &d)
  219 + }
  220 + return arrays, nil
  221 +}
@@ -337,7 +337,22 @@ func (c *StaffAssessController) ListTargetUserSelfCycle() { @@ -337,7 +337,22 @@ func (c *StaffAssessController) ListTargetUserSelfCycle() {
337 } 337 }
338 userReq := middlewares.GetUser(c.Ctx) 338 userReq := middlewares.GetUser(c.Ctx)
339 paramReq.CompanyId = int(userReq.CompanyId) 339 paramReq.CompanyId = int(userReq.CompanyId)
340 - paramReq.TargetUserId = int(userReq.UserId)  
341 data, err := srv.ListTargetUserSelfCycle(paramReq) 340 data, err := srv.ListTargetUserSelfCycle(paramReq)
342 c.Response(data, err) 341 c.Response(data, err)
343 } 342 }
  343 +
  344 +// ListTargetUserSelfCycle 按照周期获取员工的每日自评小结
  345 +func (c *StaffAssessController) GetStaffAsessSelfCountLevel() {
  346 + srv := service.NewStaffAssessServeice()
  347 + paramReq := &query.StaffAsessSelfCountLevel{}
  348 + err := c.BindJSON(paramReq)
  349 + if err != nil {
  350 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  351 + c.Response(nil, e)
  352 + return
  353 + }
  354 + userReq := middlewares.GetUser(c.Ctx)
  355 + paramReq.CompanyId = int(userReq.CompanyId)
  356 + data, err := srv.GetStaffAsessSelfCountLevel(paramReq)
  357 + c.Response(data, err)
  358 +}
@@ -20,7 +20,6 @@ func init() { @@ -20,7 +20,6 @@ func init() {
20 web.NSCtrlPost("/cycle/day/content/export", (*controllers.StaffAssessController).ExportAssessContentCycleDay), //根据周期里的考核日期,导出员工填写评估内容列表 20 web.NSCtrlPost("/cycle/day/content/export", (*controllers.StaffAssessController).ExportAssessContentCycleDay), //根据周期里的考核日期,导出员工填写评估内容列表
21 web.NSCtrlPost("/cycle/day/analysis", (*controllers.StaffAssessController).AnalysisData), //员工绩效-项目管理-矩阵分析 21 web.NSCtrlPost("/cycle/day/analysis", (*controllers.StaffAssessController).AnalysisData), //员工绩效-项目管理-矩阵分析
22 web.NSCtrlPost("/cycle/day/content/export2", (*controllers.StaffAssessController).ExportUserAssess2), //员工绩效-综合管理-导出绩效-个人 22 web.NSCtrlPost("/cycle/day/content/export2", (*controllers.StaffAssessController).ExportUserAssess2), //员工绩效-综合管理-导出绩效-个人
23 -  
24 ) 23 )
25 24
26 assessNS := web.NewNamespace("/v1/staff-assess", 25 assessNS := web.NewNamespace("/v1/staff-assess",
@@ -36,6 +35,7 @@ func init() { @@ -36,6 +35,7 @@ func init() {
36 web.NSCtrlPost("/summary/users-indicator", (*controllers.StaffAssessController).QueryMemberPerformanceIndicator), //员工绩效-综合管理-绩效导出指标 35 web.NSCtrlPost("/summary/users-indicator", (*controllers.StaffAssessController).QueryMemberPerformanceIndicator), //员工绩效-综合管理-绩效导出指标
37 web.NSCtrlPost("/summary/export-indicator", (*controllers.StaffAssessController).ExportPerformanceIndicator), //员工绩效-综合管理-绩效导出指标 36 web.NSCtrlPost("/summary/export-indicator", (*controllers.StaffAssessController).ExportPerformanceIndicator), //员工绩效-综合管理-绩效导出指标
38 web.NSCtrlPost("/target_user/self/cycle", (*controllers.StaffAssessController).ListTargetUserSelfCycle), //获取员工自评的周期下拉列表 37 web.NSCtrlPost("/target_user/self/cycle", (*controllers.StaffAssessController).ListTargetUserSelfCycle), //获取员工自评的周期下拉列表
  38 + web.NSCtrlPost("/target_user/self/summary", (*controllers.StaffAssessController).GetStaffAsessSelfCountLevel), //获取员工每日自评小结
39 ) 39 )
40 //v2 改版 40 //v2 改版
41 assessTaskV2NS := web.NewNamespace("/v2/staff-assess-task", 41 assessTaskV2NS := web.NewNamespace("/v2/staff-assess-task",
  1 +-- 添加summary_cycle 表字段
  2 +ALTER TABLE public.evaluation_cycle
  3 + ADD summary_state int4 NOT NULL DEFAULT 0;
  4 +
  5 +-- 初始化数据的值
  6 +UPDATE
  7 + public.evaluation_cycle
  8 +SET
  9 + summary_state = 1
  10 +WHERE
  11 + time_end <= now()
  12 + AND summary_state = 0;
  13 +