permission_service.go
6.1 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/permission/command"
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type PermissionService struct {
}
func NewPermissionService() *PermissionService {
newPermissionService := &PermissionService{}
return newPermissionService
}
func (rs *PermissionService) Update(in *command.UpdatePermissionCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
// 获取权限配置
_, permissions, err := permissionRepository.Find(map[string]interface{}{"companyId": in.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(permissions) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "权限配置数据错误")
}
permission := permissions[0]
permission.OptHrScore = in.OptHrScore
permission.OptEvalScore = in.OptEvalScore
// 超级管理员权限传参
if in.OptConfirmPerf > 0 || in.CycleDeadLine != nil {
superAdmin, err := service.GetSuperAdmin(transactionContext, int(in.CompanyId), int(in.UserId))
if err != nil {
return nil, err
}
if superAdmin != domain.RoleTypeSuperAdmin {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
}
switch in.OptConfirmPerf {
case domain.PermissionOff, domain.PermissionOn:
default:
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "是否需要员工确认绩效参数错误")
}
var cycleDeadLine = in.CycleDeadLine
var allMinuteSelf = cycleDeadLine.AssessmentSelf.Hour*60 + cycleDeadLine.AssessmentSelf.Minute
var allMinute360 = cycleDeadLine.AssessmentAll.Hour*60 + cycleDeadLine.AssessmentAll.Minute
//var allMinuteHr = cycleDeadLine.AssessmentHr.Hour*60 + cycleDeadLine.AssessmentHr.Minute
var allMinuteSuperior = cycleDeadLine.AssessmentSuperior.Hour*60 + cycleDeadLine.AssessmentSuperior.Minute
var allMinuteMy = cycleDeadLine.ViewMyPerf.Hour*60 + cycleDeadLine.ViewMyPerf.Minute
// 注. 360和人资评估时间截止是相同的(前端只传递一个360评估参数)
cycleDeadLine.AssessmentHr.Hour = cycleDeadLine.AssessmentAll.Hour
cycleDeadLine.AssessmentHr.Minute = cycleDeadLine.AssessmentAll.Minute
if allMinuteSelf > allMinute360 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "截止时间:[360评估]不能小于[综合自评]")
}
if allMinute360 > allMinuteSuperior {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "截止时间:[上级评估]不能小于[360评估]")
}
if allMinuteSuperior > allMinuteMy {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "截止时间:[查看我的绩效]不能小于[上级评估]")
}
permission.OptConfirmPerf = in.OptConfirmPerf
permission.CycleDeadLine = in.CycleDeadLine
}
permission, err = permissionRepository.Insert(permission)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return permission, nil
}
func (rs *PermissionService) Get(in *command.GetPermissionCommand) (*domain.Permission, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
permissionRepository := factory.CreatePermissionRepository(map[string]interface{}{"transactionContext": transactionContext})
// 获取权限配置
_, permissions, err := permissionRepository.Find(map[string]interface{}{"companyId": in.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var permission *domain.Permission
if len(permissions) == 0 { // 不存在时,新增权限配置
value := &domain.Permission{
Id: 0,
CompanyId: in.CompanyId,
OptHrScore: domain.PermissionOff,
OptEvalScore: domain.PermissionOff,
OptConfirmPerf: domain.PermissionOff,
CycleDeadLine: rs.defaultCycleDeadline(),
}
permission, err = permissionRepository.Insert(value)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
} else {
permission = permissions[0]
// 纠正数据
var isChange = false
if permission.OptHrScore == 0 {
isChange = true
permission.OptHrScore = domain.PermissionOff
}
if permission.OptEvalScore == 0 {
isChange = true
permission.OptEvalScore = domain.PermissionOff
}
if permission.OptConfirmPerf == 0 {
isChange = true
permission.OptConfirmPerf = domain.PermissionOff
}
if permission.CycleDeadLine == nil {
isChange = true
permission.CycleDeadLine = rs.defaultCycleDeadline()
}
if isChange {
permission, err = permissionRepository.Insert(permission)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return permission, nil
}
// 创建默认周期截止时间
func (rs *PermissionService) defaultCycleDeadline() *domain.CycleDeadline {
return &domain.CycleDeadline{
AssessmentSelf: domain.DeadlineTime{
Hour: 3 * 24,
Minute: 0,
},
AssessmentAll: domain.DeadlineTime{
Hour: 5 * 24,
Minute: 0,
},
AssessmentHr: domain.DeadlineTime{
Hour: 5 * 24,
Minute: 0,
},
AssessmentSuperior: domain.DeadlineTime{
Hour: 7 * 24,
Minute: 0,
},
ViewMyPerf: domain.DeadlineTime{
Hour: 9 * 24,
Minute: 0,
},
}
}