service_2.go
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package service
import (
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
//调试用,手动调用CreateStaffAssessTask
func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
data, err := srv.CreateStaffAssessTask(transactionContext, param)
if err != nil {
return nil, err
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return data, nil
}
//保存员工绩效评估填写过程中即写即存的内容
func (srv StaffAssessServeice) SaveAssessContentTemp(param *command.SaveAssessInfoCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//获取旧的临时数据内容
contentTempRepo := factory.CreateStaffAssessContentTempRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取评估填写的内容
// assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessData, err := assessRepo.FindOne(map[string]interface{}{
"id": param.AssessId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
}
// staffAssessId
_, contentTempList, err := contentTempRepo.Find(map[string]interface{}{
"staffAssessId": param.AssessId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取临时保存的内容"+err.Error())
}
nowTime := time.Now()
if len(contentTempList) == 0 {
//获取评估模板
assessContentList, err := srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估模板,"+err.Error())
}
//转填入临时的数据
for _, v := range assessContentList {
item := &domain.StaffAssessContentTemp{
Id: 0,
StaffAssessId: v.StaffAssessId,
SortBy: v.SortBy,
Category: v.Category,
Name: v.Name,
Remark: v.Remark,
Value: "",
CreatedAt: nowTime,
UpdatedAt: nowTime,
}
contentTempList = append(contentTempList, item)
}
}
//更新assessContentTemp
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil, nil
}
//获取员工绩效评估填写内容
//临时数据存在时就获取临时数据
//不存在就获取实际保存的数据
func (srv StaffAssessServeice) GetAssessContentTemp(param *command.SaveAssessInfoCommand) (*adapter.AssessInfoResp, error) {
//将临时保存的数据填入模板中
return nil, nil
}