|
@@ -4,10 +4,12 @@ import ( |
|
@@ -4,10 +4,12 @@ import ( |
4
|
"fmt"
|
4
|
"fmt"
|
5
|
"github.com/linmadan/egglib-go/core/application"
|
5
|
"github.com/linmadan/egglib-go/core/application"
|
6
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
6
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
7
|
+ "github.com/shopspring/decimal"
|
7
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/command"
|
8
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/command"
|
8
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/query"
|
9
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/query"
|
9
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
|
10
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
|
10
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
|
11
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
|
|
|
12
|
+ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
|
11
|
"time"
|
13
|
"time"
|
12
|
)
|
14
|
)
|
13
|
|
15
|
|
|
@@ -20,6 +22,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
|
@@ -20,6 +22,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
20
|
if err := createEmployeeCommand.ValidateCommand(); err != nil {
|
22
|
if err := createEmployeeCommand.ValidateCommand(); err != nil {
|
21
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
23
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
22
|
}
|
24
|
}
|
|
|
25
|
+
|
23
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
26
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
24
|
if err != nil {
|
27
|
if err != nil {
|
25
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
28
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
@@ -30,6 +33,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
|
@@ -30,6 +33,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
30
|
defer func() {
|
33
|
defer func() {
|
31
|
transactionContext.RollbackTransaction()
|
34
|
transactionContext.RollbackTransaction()
|
32
|
}()
|
35
|
}()
|
|
|
36
|
+
|
33
|
newEmployee := &domain.Employee{
|
37
|
newEmployee := &domain.Employee{
|
34
|
EmployeeInfo: &domain.EmployeeInfo{
|
38
|
EmployeeInfo: &domain.EmployeeInfo{
|
35
|
Uid: createEmployeeCommand.Uid,
|
39
|
Uid: createEmployeeCommand.Uid,
|
|
@@ -40,6 +44,8 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
|
@@ -40,6 +44,8 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
40
|
CreateTime: time.Now(),
|
44
|
CreateTime: time.Now(),
|
41
|
}
|
45
|
}
|
42
|
var employeeRepository domain.EmployeeRepository
|
46
|
var employeeRepository domain.EmployeeRepository
|
|
|
47
|
+
|
|
|
48
|
+ // 创建员工工厂初始化
|
43
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
49
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
44
|
"transactionContext": transactionContext,
|
50
|
"transactionContext": transactionContext,
|
45
|
}); err != nil {
|
51
|
}); err != nil {
|
|
@@ -47,6 +53,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
|
@@ -47,6 +53,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co |
47
|
} else {
|
53
|
} else {
|
48
|
employeeRepository = value
|
54
|
employeeRepository = value
|
49
|
}
|
55
|
}
|
|
|
56
|
+
|
50
|
if employee, err := employeeRepository.Save(newEmployee); err != nil {
|
57
|
if employee, err := employeeRepository.Save(newEmployee); err != nil {
|
51
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
58
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
52
|
} else {
|
59
|
} else {
|
|
@@ -62,6 +69,7 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
|
@@ -62,6 +69,7 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
62
|
if err := getEmployeeQuery.ValidateQuery(); err != nil {
|
69
|
if err := getEmployeeQuery.ValidateQuery(); err != nil {
|
63
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
70
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
64
|
}
|
71
|
}
|
|
|
72
|
+
|
65
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
73
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
66
|
if err != nil {
|
74
|
if err != nil {
|
67
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
75
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
@@ -72,6 +80,8 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
|
@@ -72,6 +80,8 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
72
|
defer func() {
|
80
|
defer func() {
|
73
|
transactionContext.RollbackTransaction()
|
81
|
transactionContext.RollbackTransaction()
|
74
|
}()
|
82
|
}()
|
|
|
83
|
+
|
|
|
84
|
+ // 员工仓储初始化
|
75
|
var employeeRepository domain.EmployeeRepository
|
85
|
var employeeRepository domain.EmployeeRepository
|
76
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
86
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
77
|
"transactionContext": transactionContext,
|
87
|
"transactionContext": transactionContext,
|
|
@@ -80,6 +90,23 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
|
@@ -80,6 +90,23 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
80
|
} else {
|
90
|
} else {
|
81
|
employeeRepository = value
|
91
|
employeeRepository = value
|
82
|
}
|
92
|
}
|
|
|
93
|
+
|
|
|
94
|
+ // 员工DAO初始化
|
|
|
95
|
+ var employeeDao *dao.EmployeeDao
|
|
|
96
|
+ if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
97
|
+ "transactionContext": transactionContext,
|
|
|
98
|
+ }); err != nil {
|
|
|
99
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
100
|
+ } else {
|
|
|
101
|
+ employeeDao = value
|
|
|
102
|
+ }
|
|
|
103
|
+
|
|
|
104
|
+ var employeeSpecific map[string]interface{}
|
|
|
105
|
+
|
|
|
106
|
+ // 默认查询时间
|
|
|
107
|
+ transactionStartTime := time.Time{}
|
|
|
108
|
+ transactionEndTime := time.Now()
|
|
|
109
|
+
|
83
|
employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": getEmployeeQuery.Uid})
|
110
|
employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": getEmployeeQuery.Uid})
|
84
|
if err != nil {
|
111
|
if err != nil {
|
85
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
112
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -87,10 +114,39 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
|
@@ -87,10 +114,39 @@ func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetE |
87
|
if employee == nil {
|
114
|
if employee == nil {
|
88
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getEmployeeQuery.Uid)))
|
115
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getEmployeeQuery.Uid)))
|
89
|
} else {
|
116
|
} else {
|
|
|
117
|
+ var contributions float64
|
|
|
118
|
+ calculateResult, err := employeeDao.CalculateContributionsTransactionRecord(employee.EmployeeInfo.Uid, transactionStartTime, transactionEndTime)
|
|
|
119
|
+ if err != nil {
|
|
|
120
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
121
|
+ }
|
|
|
122
|
+ if calculateResult == nil {
|
|
|
123
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
124
|
+ }
|
|
|
125
|
+ suMoney, _ := decimal.NewFromFloatWithExponent(employee.SuMoney, -2).Float64()
|
|
|
126
|
+ if calculateResult["contributions"] != nil {
|
|
|
127
|
+ contributions, _ = decimal.NewFromFloatWithExponent(calculateResult["contributions"].(float64), -2).Float64()
|
|
|
128
|
+ }
|
|
|
129
|
+ employeeSpecific = map[string]interface{} {
|
|
|
130
|
+ "employeeId": employee.EmployeeId,
|
|
|
131
|
+ "companyId": employee.CompanyId,
|
|
|
132
|
+ "employeeInfo": map[string]interface{}{
|
|
|
133
|
+ "uid": employee.EmployeeInfo.Uid,
|
|
|
134
|
+ "employeeName": employee.EmployeeInfo.EmployeeName,
|
|
|
135
|
+ "employeeAccount": employee.EmployeeInfo.EmployeeAccount,
|
|
|
136
|
+ "employeeAvatarUrl": employee.EmployeeInfo.EmployeeAvatarUrl,
|
|
|
137
|
+ "isPrincipal": employee.EmployeeInfo.IsPrincipal,
|
|
|
138
|
+ },
|
|
|
139
|
+ "suMoney": suMoney,
|
|
|
140
|
+ "contributions": contributions,
|
|
|
141
|
+ "status": employee.Status,
|
|
|
142
|
+ "permissions": employee.Permissions,
|
|
|
143
|
+ "createTime": employee.CreateTime.Local(),
|
|
|
144
|
+ }
|
|
|
145
|
+
|
90
|
if err := transactionContext.CommitTransaction(); err != nil {
|
146
|
if err := transactionContext.CommitTransaction(); err != nil {
|
91
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
147
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
92
|
}
|
148
|
}
|
93
|
- return employee, nil
|
149
|
+ return employeeSpecific, nil
|
94
|
}
|
150
|
}
|
95
|
}
|
151
|
}
|
96
|
|
152
|
|
|
@@ -99,6 +155,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co |
|
@@ -99,6 +155,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co |
99
|
if err := updateEmployeeCommand.ValidateCommand(); err != nil {
|
155
|
if err := updateEmployeeCommand.ValidateCommand(); err != nil {
|
100
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
156
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
101
|
}
|
157
|
}
|
|
|
158
|
+
|
102
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
159
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
103
|
if err != nil {
|
160
|
if err != nil {
|
104
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
161
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
@@ -109,6 +166,8 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co |
|
@@ -109,6 +166,8 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co |
109
|
defer func() {
|
166
|
defer func() {
|
110
|
transactionContext.RollbackTransaction()
|
167
|
transactionContext.RollbackTransaction()
|
111
|
}()
|
168
|
}()
|
|
|
169
|
+
|
|
|
170
|
+ // 员工仓储初始化
|
112
|
var employeeRepository domain.EmployeeRepository
|
171
|
var employeeRepository domain.EmployeeRepository
|
113
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
172
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
114
|
"transactionContext": transactionContext,
|
173
|
"transactionContext": transactionContext,
|
|
@@ -117,6 +176,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co |
|
@@ -117,6 +176,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co |
117
|
} else {
|
176
|
} else {
|
118
|
employeeRepository = value
|
177
|
employeeRepository = value
|
119
|
}
|
178
|
}
|
|
|
179
|
+
|
120
|
employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": updateEmployeeCommand.Uid})
|
180
|
employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": updateEmployeeCommand.Uid})
|
121
|
if err != nil {
|
181
|
if err != nil {
|
122
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
182
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -195,6 +255,7 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li |
|
@@ -195,6 +255,7 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li |
195
|
transactionContext.RollbackTransaction()
|
255
|
transactionContext.RollbackTransaction()
|
196
|
}()
|
256
|
}()
|
197
|
|
257
|
|
|
|
258
|
+ // 员工仓储初始化
|
198
|
var employeeRepository domain.EmployeeRepository
|
259
|
var employeeRepository domain.EmployeeRepository
|
199
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
260
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
200
|
"transactionContext": transactionContext,
|
261
|
"transactionContext": transactionContext,
|
|
@@ -204,6 +265,22 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li |
|
@@ -204,6 +265,22 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li |
204
|
employeeRepository = value
|
265
|
employeeRepository = value
|
205
|
}
|
266
|
}
|
206
|
|
267
|
|
|
|
268
|
+ // 员工DAO初始化
|
|
|
269
|
+ var employeeDao *dao.EmployeeDao
|
|
|
270
|
+ if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
271
|
+ "transactionContext": transactionContext,
|
|
|
272
|
+ }); err != nil {
|
|
|
273
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
274
|
+ } else {
|
|
|
275
|
+ employeeDao = value
|
|
|
276
|
+ }
|
|
|
277
|
+
|
|
|
278
|
+ // 默认查询时间
|
|
|
279
|
+ transactionStartTime := time.Time{}
|
|
|
280
|
+ transactionEndTime := time.Now()
|
|
|
281
|
+
|
|
|
282
|
+ var employeesSpecific []interface{}
|
|
|
283
|
+
|
207
|
if count, employees, err := employeeRepository.Find(map[string]interface{}{
|
284
|
if count, employees, err := employeeRepository.Find(map[string]interface{}{
|
208
|
"companyId": listEmployeeQuery.CompanyId,
|
285
|
"companyId": listEmployeeQuery.CompanyId,
|
209
|
"employeeNameMatch": listEmployeeQuery.EmployeeNameMatch,
|
286
|
"employeeNameMatch": listEmployeeQuery.EmployeeNameMatch,
|
|
@@ -212,12 +289,46 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li |
|
@@ -212,12 +289,46 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li |
212
|
}); err != nil {
|
289
|
}); err != nil {
|
213
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
290
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
214
|
} else {
|
291
|
} else {
|
|
|
292
|
+ for _ , employee := range employees {
|
|
|
293
|
+ calculateResult, err := employeeDao.CalculateContributionsTransactionRecord(employee.EmployeeInfo.Uid, transactionStartTime, transactionEndTime)
|
|
|
294
|
+ if err != nil {
|
|
|
295
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
296
|
+ }
|
|
|
297
|
+ if calculateResult == nil {
|
|
|
298
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
299
|
+ }
|
|
|
300
|
+
|
|
|
301
|
+ suMoney, _ := decimal.NewFromFloatWithExponent(employee.SuMoney, -2).Float64()
|
|
|
302
|
+ var contributions float64
|
|
|
303
|
+ if calculateResult["contributions"] != nil {
|
|
|
304
|
+ contributions, _ = decimal.NewFromFloatWithExponent(calculateResult["contributions"].(float64), -2).Float64()
|
|
|
305
|
+ }
|
|
|
306
|
+
|
|
|
307
|
+ employeeSpecific := map[string]interface{}{
|
|
|
308
|
+ "employeeId": employee.EmployeeId,
|
|
|
309
|
+ "companyId": employee.CompanyId,
|
|
|
310
|
+ "employeeInfo": map[string]interface{}{
|
|
|
311
|
+ "uid": employee.EmployeeInfo.Uid,
|
|
|
312
|
+ "employeeName": employee.EmployeeInfo.EmployeeName,
|
|
|
313
|
+ "employeeAccount": employee.EmployeeInfo.EmployeeAccount,
|
|
|
314
|
+ "employeeAvatarUrl": employee.EmployeeInfo.EmployeeAvatarUrl,
|
|
|
315
|
+ "isPrincipal": employee.EmployeeInfo.IsPrincipal,
|
|
|
316
|
+ },
|
|
|
317
|
+ "suMoney": suMoney,
|
|
|
318
|
+ "contributions": contributions,
|
|
|
319
|
+ "status": employee.Status,
|
|
|
320
|
+ "permissions": employee.Permissions,
|
|
|
321
|
+ "createTime": employee.CreateTime.Local(),
|
|
|
322
|
+ }
|
|
|
323
|
+ employeesSpecific = append(employeesSpecific, employeeSpecific)
|
|
|
324
|
+ }
|
|
|
325
|
+
|
215
|
if err := transactionContext.CommitTransaction(); err != nil {
|
326
|
if err := transactionContext.CommitTransaction(); err != nil {
|
216
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
327
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
217
|
}
|
328
|
}
|
218
|
return map[string]interface{}{
|
329
|
return map[string]interface{}{
|
219
|
"count": count,
|
330
|
"count": count,
|
220
|
- "employees": employees,
|
331
|
+ "employees": employeesSpecific,
|
221
|
}, nil
|
332
|
}, nil
|
222
|
}
|
333
|
}
|
223
|
}
|
334
|
}
|