合并分支 'dev' 到 'master'
Dev 优化贡献值展示 查看合并请求 !5
正在显示
11 个修改的文件
包含
187 行增加
和
21 行删除
@@ -10,7 +10,7 @@ COPY ./go.mod go.mod | @@ -10,7 +10,7 @@ COPY ./go.mod go.mod | ||
10 | COPY ./main.go main.go | 10 | COPY ./main.go main.go |
11 | RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"] | 11 | RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"] |
12 | ENV GO111MODULE on | 12 | ENV GO111MODULE on |
13 | -ENV GOPROXY https://goproxy.io | ||
14 | -#RUN ["go","mod","tidy"] | 13 | +ENV GOPROXY https://goproxy.cn |
14 | +RUN ["go","mod","tidy"] | ||
15 | RUN ["go","build"] | 15 | RUN ["go","build"] |
16 | ENTRYPOINT ["./mmm-worth"] | 16 | ENTRYPOINT ["./mmm-worth"] |
@@ -29,7 +29,6 @@ require ( | @@ -29,7 +29,6 @@ require ( | ||
29 | github.com/yudai/gojsondiff v1.0.0 // indirect | 29 | github.com/yudai/gojsondiff v1.0.0 // indirect |
30 | github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect | 30 | github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect |
31 | github.com/yudai/pp v2.0.1+incompatible // indirect | 31 | github.com/yudai/pp v2.0.1+incompatible // indirect |
32 | - golang.org/x/tools v0.0.0-20200117065230-39095c1d176c | ||
33 | ) | 32 | ) |
34 | 33 | ||
35 | replace gitlab.fjmaimaimai.com/linmadan/mmm-worth => ../mmm-worth | 34 | replace gitlab.fjmaimaimai.com/linmadan/mmm-worth => ../mmm-worth |
@@ -79,8 +79,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | @@ -79,8 +79,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
79 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | 79 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= |
80 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | 80 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= |
81 | github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | 81 | github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= |
82 | -github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 h1:zJZsqJ1wFMYb2yrja5S3OZ+oASx4irRksZ8+emFs56M= | ||
83 | -github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9/go.mod h1:S1zYn9bb6h+Qzu1aOO8raFhHniewOBaif3YvA9qA6lk= | ||
84 | github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb h1:Ocxw5BWyRrRkTHSsTmQx0UnGsAYZDOwa3K9oGlXF8Jo= | 82 | github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb h1:Ocxw5BWyRrRkTHSsTmQx0UnGsAYZDOwa3K9oGlXF8Jo= |
85 | github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb/go.mod h1:S1zYn9bb6h+Qzu1aOO8raFhHniewOBaif3YvA9qA6lk= | 83 | github.com/linmadan/egglib-go v0.0.0-20201125083542-25358a549edb/go.mod h1:S1zYn9bb6h+Qzu1aOO8raFhHniewOBaif3YvA9qA6lk= |
86 | github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= | 84 | github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= |
@@ -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,49 @@ func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.Li | @@ -212,12 +289,49 @@ 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 | } |
329 | + if len(employeesSpecific) == 0 { | ||
330 | + employeesSpecific = []interface{}{} | ||
331 | + } | ||
218 | return map[string]interface{}{ | 332 | return map[string]interface{}{ |
219 | "count": count, | 333 | "count": count, |
220 | - "employees": employees, | 334 | + "employees": employeesSpecific, |
221 | }, nil | 335 | }, nil |
222 | } | 336 | } |
223 | } | 337 | } |
@@ -3,12 +3,14 @@ package service | @@ -3,12 +3,14 @@ package service | ||
3 | import ( | 3 | import ( |
4 | "github.com/linmadan/egglib-go/core/application" | 4 | "github.com/linmadan/egglib-go/core/application" |
5 | "github.com/linmadan/egglib-go/utils/tool_funs" | 5 | "github.com/linmadan/egglib-go/utils/tool_funs" |
6 | + "github.com/shopspring/decimal" | ||
6 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" | 7 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" |
7 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command" | 8 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command" |
8 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query" | 9 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query" |
9 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" |
10 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" | 11 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" |
11 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" | 12 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" |
13 | + "time" | ||
12 | ) | 14 | ) |
13 | 15 | ||
14 | // 素币服务 | 16 | // 素币服务 |
@@ -291,7 +293,7 @@ func (suMoneyService *SuMoneyService) ContributionsTransactionRecordStatistics(c | @@ -291,7 +293,7 @@ func (suMoneyService *SuMoneyService) ContributionsTransactionRecordStatistics(c | ||
291 | } | 293 | } |
292 | 294 | ||
293 | // 根据uid获取员工素币(导出素币流水) | 295 | // 根据uid获取员工素币(导出素币流水) |
294 | -func (suMoneyService *SuMoneyService) ListSuMoneyById(exportSuMoneyCommand *command.ExportSuMoneyCommand) ([]*domain.Employee, error) { | 296 | +func (suMoneyService *SuMoneyService) ListSuMoneyById(exportSuMoneyCommand *command.ExportSuMoneyCommand) ([]interface{}, error) { |
295 | if err := exportSuMoneyCommand.ValidateCommand(); err != nil { | 297 | if err := exportSuMoneyCommand.ValidateCommand(); err != nil { |
296 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 298 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
297 | } | 299 | } |
@@ -321,13 +323,63 @@ func (suMoneyService *SuMoneyService) ListSuMoneyById(exportSuMoneyCommand *comm | @@ -321,13 +323,63 @@ func (suMoneyService *SuMoneyService) ListSuMoneyById(exportSuMoneyCommand *comm | ||
321 | employeeRepository = value | 323 | employeeRepository = value |
322 | } | 324 | } |
323 | 325 | ||
326 | + // 员工DAO初始化 | ||
327 | + var employeeDao *dao.EmployeeDao | ||
328 | + if value, err := factory.CreateEmployeeDao(map[string]interface{}{ | ||
329 | + "transactionContext": transactionContext, | ||
330 | + }); err != nil { | ||
331 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
332 | + } else { | ||
333 | + employeeDao = value | ||
334 | + } | ||
335 | + | ||
336 | + // 默认查询时间 | ||
337 | + transactionStartTime := time.Time{} | ||
338 | + transactionEndTime := time.Now() | ||
339 | + | ||
340 | + var employeesSpecific []interface{} | ||
341 | + | ||
324 | if _, employees, err := employeeRepository.FindByIds(tool_funs.SimpleStructToMap(exportSuMoneyCommand)); err != nil { | 342 | if _, employees, err := employeeRepository.FindByIds(tool_funs.SimpleStructToMap(exportSuMoneyCommand)); err != nil { |
325 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 343 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
326 | } else { | 344 | } else { |
345 | + for _ , employee := range employees { | ||
346 | + calculateResult, err := employeeDao.CalculateContributionsTransactionRecord(employee.EmployeeInfo.Uid, transactionStartTime, transactionEndTime) | ||
347 | + if err != nil { | ||
348 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
349 | + } | ||
350 | + if calculateResult == nil { | ||
351 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
352 | + } | ||
353 | + | ||
354 | + suMoney, _ := decimal.NewFromFloatWithExponent(employee.SuMoney, -2).Float64() | ||
355 | + var contributions float64 | ||
356 | + if calculateResult["contributions"] != nil { | ||
357 | + contributions, _ = decimal.NewFromFloatWithExponent(calculateResult["contributions"].(float64), -2).Float64() | ||
358 | + } | ||
359 | + | ||
360 | + employeeSpecific := map[string]interface{}{ | ||
361 | + "employeeId": employee.EmployeeId, | ||
362 | + "companyId": employee.CompanyId, | ||
363 | + "employeeInfo": map[string]interface{}{ | ||
364 | + "uid": employee.EmployeeInfo.Uid, | ||
365 | + "employeeName": employee.EmployeeInfo.EmployeeName, | ||
366 | + "employeeAccount": employee.EmployeeInfo.EmployeeAccount, | ||
367 | + "employeeAvatarUrl": employee.EmployeeInfo.EmployeeAvatarUrl, | ||
368 | + "isPrincipal": employee.EmployeeInfo.IsPrincipal, | ||
369 | + }, | ||
370 | + "suMoney": suMoney, | ||
371 | + "contributions": contributions, | ||
372 | + "status": employee.Status, | ||
373 | + "permissions": employee.Permissions, | ||
374 | + "createTime": employee.CreateTime.Local(), | ||
375 | + } | ||
376 | + employeesSpecific = append(employeesSpecific, employeeSpecific) | ||
377 | + } | ||
378 | + | ||
327 | if err := transactionContext.CommitTransaction(); err != nil { | 379 | if err := transactionContext.CommitTransaction(); err != nil { |
328 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 380 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
329 | } | 381 | } |
330 | - return employees, nil | 382 | + return employeesSpecific, nil |
331 | } | 383 | } |
332 | } | 384 | } |
333 | 385 |
@@ -2,7 +2,7 @@ package constant | @@ -2,7 +2,7 @@ package constant | ||
2 | 2 | ||
3 | import "os" | 3 | import "os" |
4 | 4 | ||
5 | -var POSTGRESQL_DB_NAME = "mmm-worth-test" | 5 | +var POSTGRESQL_DB_NAME = "mmm-worth" |
6 | var POSTGRESQL_USER = "postgres" | 6 | var POSTGRESQL_USER = "postgres" |
7 | var POSTGRESQL_PASSWORD = "1993618jack" | 7 | var POSTGRESQL_PASSWORD = "1993618jack" |
8 | var POSTGRESQL_HOST = "127.0.0.1" | 8 | var POSTGRESQL_HOST = "127.0.0.1" |
@@ -276,7 +276,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans | @@ -276,7 +276,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans | ||
276 | suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) | 276 | suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) |
277 | 277 | ||
278 | if transactionStartTime.IsZero() && transactionEndTime.IsZero() { | 278 | if transactionStartTime.IsZero() && transactionEndTime.IsZero() { |
279 | - transactionStartTime = time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local) | 279 | + transactionStartTime = time.Time{} |
280 | transactionEndTime = time.Now() | 280 | transactionEndTime = time.Now() |
281 | } | 281 | } |
282 | 282 | ||
@@ -303,6 +303,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans | @@ -303,6 +303,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans | ||
303 | return map[string]interface{}{ | 303 | return map[string]interface{}{ |
304 | "incomeContributions": incomeContributions, // 个人贡献值收入 | 304 | "incomeContributions": incomeContributions, // 个人贡献值收入 |
305 | "expendContributions": expendContributions, // 个人贡献支出 | 305 | "expendContributions": expendContributions, // 个人贡献支出 |
306 | + "contributions": incomeContributions - expendContributions, // 个人贡献值 | ||
306 | }, nil | 307 | }, nil |
307 | } | 308 | } |
308 | 309 |
@@ -233,6 +233,7 @@ func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeMode | @@ -233,6 +233,7 @@ func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeMode | ||
233 | SuMoney: employeeModel.SuMoney, | 233 | SuMoney: employeeModel.SuMoney, |
234 | Status: employeeModel.Status, | 234 | Status: employeeModel.Status, |
235 | Permissions: employeeModel.Permissions, | 235 | Permissions: employeeModel.Permissions, |
236 | + CreateTime: employeeModel.CreateTime, | ||
236 | }, nil | 237 | }, nil |
237 | } | 238 | } |
238 | 239 |
@@ -102,7 +102,7 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri | @@ -102,7 +102,7 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri | ||
102 | if uid, ok := queryOptions["uid"]; ok && (uid != int64(0)) { | 102 | if uid, ok := queryOptions["uid"]; ok && (uid != int64(0)) { |
103 | query = query.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid) | 103 | query = query.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid) |
104 | } | 104 | } |
105 | - if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (employeeMatchName != "") { | 105 | + if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (employeeMatchName.(string) != "") { |
106 | query = query.Where(`(su_money_transaction_record.employee->>'employeeName')::text LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string))) | 106 | query = query.Where(`(su_money_transaction_record.employee->>'employeeName')::text LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string))) |
107 | } | 107 | } |
108 | if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) { | 108 | if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) { |
@@ -2,8 +2,6 @@ package controllers | @@ -2,8 +2,6 @@ package controllers | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | 4 | "encoding/json" |
5 | - "fmt" | ||
6 | - | ||
7 | "github.com/astaxie/beego" | 5 | "github.com/astaxie/beego" |
8 | "github.com/linmadan/egglib-go/web/beego/utils" | 6 | "github.com/linmadan/egglib-go/web/beego/utils" |
9 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/command" | 7 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/command" |
@@ -92,7 +90,6 @@ func (controller *EmployeeController) ListEmployee() { | @@ -92,7 +90,6 @@ func (controller *EmployeeController) ListEmployee() { | ||
92 | listEmployeeQuery.Offset = offset | 90 | listEmployeeQuery.Offset = offset |
93 | limit, _ := controller.GetInt("limit") | 91 | limit, _ := controller.GetInt("limit") |
94 | listEmployeeQuery.Limit = limit | 92 | listEmployeeQuery.Limit = limit |
95 | - fmt.Print(listEmployeeQuery) | ||
96 | data, err := employeeService.ListEmployee(listEmployeeQuery) | 93 | data, err := employeeService.ListEmployee(listEmployeeQuery) |
97 | var response utils.JsonResponse | 94 | var response utils.JsonResponse |
98 | if err != nil { | 95 | if err != nil { |
@@ -682,20 +682,21 @@ func (controller *SuMoneyController) ExportSuMoney() { | @@ -682,20 +682,21 @@ func (controller *SuMoneyController) ExportSuMoney() { | ||
682 | json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportSuMoneyCommand) | 682 | json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportSuMoneyCommand) |
683 | // 列标题 | 683 | // 列标题 |
684 | titles := []string{ | 684 | titles := []string{ |
685 | - "员工姓名","手机账号","当前素币", | 685 | + "员工姓名","手机账号","贡献值","当前素币", |
686 | } | 686 | } |
687 | // 列单元 | 687 | // 列单元 |
688 | cells := []string{ | 688 | cells := []string{ |
689 | - "A","B","C", | 689 | + "A","B","C","D", |
690 | } | 690 | } |
691 | var response utils.JsonResponse | 691 | var response utils.JsonResponse |
692 | var data []map[string]interface{} | 692 | var data []map[string]interface{} |
693 | records, err := suMoneyService.ListSuMoneyById(exportSuMoneyCommand) | 693 | records, err := suMoneyService.ListSuMoneyById(exportSuMoneyCommand) |
694 | for _, record := range records { | 694 | for _, record := range records { |
695 | p := map[string]interface{} { | 695 | p := map[string]interface{} { |
696 | - "name": record.EmployeeInfo.EmployeeName, | ||
697 | - "account": record.EmployeeInfo.EmployeeAccount, | ||
698 | - "current_su_money": record.SuMoney, | 696 | + "name": record.(map[string]interface{})["employeeInfo"].(map[string]interface{})["employeeName"], |
697 | + "account": record.(map[string]interface{})["employeeInfo"].(map[string]interface{})["employeeAccount"], | ||
698 | + "current_contributions": record.(map[string]interface{})["contributions"], | ||
699 | + "current_su_money": record.(map[string]interface{})["suMoney"], | ||
699 | } | 700 | } |
700 | data = append(data, p) | 701 | data = append(data, p) |
701 | } | 702 | } |
@@ -730,8 +731,11 @@ func (controller *SuMoneyController) ExportSuMoney() { | @@ -730,8 +731,11 @@ func (controller *SuMoneyController) ExportSuMoney() { | ||
730 | break | 731 | break |
731 | case "C": | 732 | case "C": |
732 | sheetPosition := cell + row | 733 | sheetPosition := cell + row |
733 | - f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"]) | 734 | + f.SetCellValue("Sheet1", sheetPosition, v["current_contributions"]) |
734 | break | 735 | break |
736 | + case "D": | ||
737 | + sheetPosition := cell + row | ||
738 | + f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"]) | ||
735 | } | 739 | } |
736 | } | 740 | } |
737 | } | 741 | } |
-
请 注册 或 登录 后发表评论