作者 陈志颖

feat:完成员工贡献值、财富值统计

@@ -3,10 +3,13 @@ package command @@ -3,10 +3,13 @@ package command
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/astaxie/beego/validation" 5 "github.com/astaxie/beego/validation"
  6 + "time"
6 ) 7 )
7 8
8 type EmployeesContributionsStatisticsCommand struct { 9 type EmployeesContributionsStatisticsCommand struct {
9 CompanyId int `json:"companyId" valid:"Required"` // 公司id 10 CompanyId int `json:"companyId" valid:"Required"` // 公司id
  11 + StartTime time.Time `json:"startTime"` // 年榜开始时间
  12 + EndTime time.Time `json:"EndTime"` // 年榜结束时间
10 } 13 }
11 14
12 func (employeesContributionsStatisticsCommand *EmployeesContributionsStatisticsCommand) ValidateCommand() error { 15 func (employeesContributionsStatisticsCommand *EmployeesContributionsStatisticsCommand) ValidateCommand() error {
@@ -2,12 +2,15 @@ package command @@ -2,12 +2,15 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
5 6
6 "github.com/astaxie/beego/validation" 7 "github.com/astaxie/beego/validation"
7 ) 8 )
8 9
9 type EmployeesSuMoneyStatisticsCommand struct { 10 type EmployeesSuMoneyStatisticsCommand struct {
10 CompanyId int `json:"companyId" valid:"Required"` // 公司id 11 CompanyId int `json:"companyId" valid:"Required"` // 公司id
  12 + StartTime time.Time `json:"startTime"` // 年榜开始时间
  13 + EndTime time.Time `json:"EndTime"` // 年榜结束时间
11 } 14 }
12 15
13 func (employeesSuMoneyStatisticsCommand *EmployeesSuMoneyStatisticsCommand) ValidateCommand() error { 16 func (employeesSuMoneyStatisticsCommand *EmployeesSuMoneyStatisticsCommand) ValidateCommand() error {
@@ -196,6 +196,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -196,6 +196,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
196 } 196 }
197 } 197 }
198 198
  199 +// 获取系统素币统计
199 func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand *command.SystemSuMoneyStatisticsCommand) (interface{}, error) { 200 func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand *command.SystemSuMoneyStatisticsCommand) (interface{}, error) {
200 if err := systemSuMoneyStatisticsCommand.ValidateCommand(); err != nil { 201 if err := systemSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
201 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 202 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -230,6 +231,7 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone @@ -230,6 +231,7 @@ func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMone
230 } 231 }
231 } 232 }
232 233
  234 +// 获取系统现金统计
233 func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStatisticsCommand *command.SystemCashStatisticsCommand) (interface{}, error) { 235 func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStatisticsCommand *command.SystemCashStatisticsCommand) (interface{}, error) {
234 if err := systemCashStatisticsCommand.ValidateCommand(); err != nil { 236 if err := systemCashStatisticsCommand.ValidateCommand(); err != nil {
235 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 237 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -264,19 +266,72 @@ func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStati @@ -264,19 +266,72 @@ func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStati
264 } 266 }
265 } 267 }
266 268
267 -// TODO 员工素币值统计 269 +// 获取员工财富值分组统计
268 func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand *command.EmployeesSuMoneyStatisticsCommand) (interface{}, error) { 270 func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand *command.EmployeesSuMoneyStatisticsCommand) (interface{}, error) {
269 -  
270 - return nil ,nil 271 + if err := employeesSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
  272 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  273 + }
  274 + transactionContext, err := factory.CreateTransactionContext(nil)
  275 + if err != nil {
  276 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  277 + }
  278 + if err := transactionContext.StartTransaction(); err != nil {
  279 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  280 + }
  281 + defer func() {
  282 + transactionContext.RollbackTransaction()
  283 + }()
  284 + var employeeDao *dao.EmployeeDao
  285 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  286 + "transactionContext": transactionContext,
  287 + }); err != nil {
  288 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  289 + } else {
  290 + employeeDao = value
  291 + }
  292 + if employeesSuMoneyStatistics, err := employeeDao.CalculateEmployeesSuMoney(employeesSuMoneyStatisticsCommand.CompanyId, employeesSuMoneyStatisticsCommand.StartTime, employeesSuMoneyStatisticsCommand.EndTime); err != nil {
  293 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  294 + } else {
  295 + if err := transactionContext.CommitTransaction(); err != nil {
  296 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  297 + }
  298 + return employeesSuMoneyStatistics, nil
  299 + }
271 } 300 }
272 301
273 -// TODO 员工贡献值统计 302 +// 获取员工贡献值分组统计
274 func (statisticsService *StatisticsService) EmployeesContributionsStatistics(employeesContributionsStatisticsCommand *command.EmployeesContributionsStatisticsCommand) (interface{}, error) { 303 func (statisticsService *StatisticsService) EmployeesContributionsStatistics(employeesContributionsStatisticsCommand *command.EmployeesContributionsStatisticsCommand) (interface{}, error) {
275 -  
276 - return nil, nil 304 + if err := employeesContributionsStatisticsCommand.ValidateCommand(); err != nil {
  305 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  306 + }
  307 + transactionContext, err := factory.CreateTransactionContext(nil)
  308 + if err != nil {
  309 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  310 + }
  311 + if err := transactionContext.StartTransaction(); err != nil {
  312 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  313 + }
  314 + defer func() {
  315 + transactionContext.RollbackTransaction()
  316 + }()
  317 + var employeeDao *dao.EmployeeDao
  318 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  319 + "transactionContext": transactionContext,
  320 + }); err != nil {
  321 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  322 + } else {
  323 + employeeDao = value
  324 + }
  325 + if employeesContributionsStatistics, err := employeeDao.CalculateEmployeesContributions(employeesContributionsStatisticsCommand.CompanyId, employeesContributionsStatisticsCommand.StartTime, employeesContributionsStatisticsCommand.EndTime); err != nil {
  326 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  327 + } else {
  328 + if err := transactionContext.CommitTransaction(); err != nil {
  329 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  330 + }
  331 + return employeesContributionsStatistics, nil
  332 + }
277 } 333 }
278 334
279 -  
280 func NewStatisticsService(options map[string]interface{}) *StatisticsService { 335 func NewStatisticsService(options map[string]interface{}) *StatisticsService {
281 newStatisticsService := &StatisticsService{} 336 newStatisticsService := &StatisticsService{}
282 return newStatisticsService 337 return newStatisticsService
@@ -6,10 +6,12 @@ import ( @@ -6,10 +6,12 @@ import (
6 ) 6 )
7 7
8 type CreateExchangeCashPersonCommand struct { 8 type CreateExchangeCashPersonCommand struct {
  9 + Uid int64 `json:"uid"` // 统一用户id
9 PersonName string `json:"personName,omitempty"` // 兑换现金人员名称 10 PersonName string `json:"personName,omitempty"` // 兑换现金人员名称
10 - PersonAccount string `json:"personAccount,omitempty"` // 手机账号  
11 - ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 参与的兑换活动id  
12 - ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币值 11 + Operator int64 `json:"operator"` // 操作人
  12 + PersonAccount string `json:"personAccount,omitempty"` // 手机账号
  13 + ExchangeCashActivityId int64 `json:"exchangeCashActivityId" valid:"Required"` // 参与的兑换活动id
  14 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币值
13 } 15 }
14 16
15 func (createExchangeCashPersonCommand *CreateExchangeCashPersonCommand) ValidateCommand() error { 17 func (createExchangeCashPersonCommand *CreateExchangeCashPersonCommand) ValidateCommand() error {
@@ -34,7 +34,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -34,7 +34,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
34 defer func() { 34 defer func() {
35 transactionContext.RollbackTransaction() 35 transactionContext.RollbackTransaction()
36 }() 36 }()
37 -  
38 var employeeDao *dao.EmployeeDao 37 var employeeDao *dao.EmployeeDao
39 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 38 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
40 "transactionContext": transactionContext, 39 "transactionContext": transactionContext,
@@ -43,7 +42,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -43,7 +42,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
43 } else { 42 } else {
44 employeeDao = value 43 employeeDao = value
45 } 44 }
46 -  
47 // 统计系统素币 45 // 统计系统素币
48 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId) 46 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
49 if err != nil { 47 if err != nil {
@@ -52,7 +50,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -52,7 +50,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
52 if systemSuMoneyStatistics == nil { 50 if systemSuMoneyStatistics == nil {
53 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 51 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
54 } 52 }
55 - 53 + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
  54 + systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
56 // 统计系统现金 55 // 统计系统现金
57 systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId) 56 systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
58 if err != nil { 57 if err != nil {
@@ -61,7 +60,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -61,7 +60,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
61 if systemCashStatistics == nil { 60 if systemCashStatistics == nil {
62 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 61 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
63 } 62 }
64 - 63 + systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
  64 + systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
65 var cashPoolRepository domain.CashPoolRepository 65 var cashPoolRepository domain.CashPoolRepository
66 if value, err := factory.CreateCashPoolRepository(map[string] interface{} { 66 if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
67 "transactionContext": transactionContext, 67 "transactionContext": transactionContext,
@@ -70,15 +70,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -70,15 +70,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
70 } else { 70 } else {
71 cashPoolRepository = value 71 cashPoolRepository = value
72 } 72 }
73 -  
74 - systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)  
75 - systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)  
76 - systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)  
77 - systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)  
78 -  
79 - // TODO 计算系统平均兑换汇率 73 + // 计算系统平均兑换汇率
80 rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率 74 rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
81 -  
82 // 新建现金池 75 // 新建现金池
83 newCashPool := &domain.CashPool{ 76 newCashPool := &domain.CashPool{
84 CompanyId: createCashPoolCommand.CompanyId, 77 CompanyId: createCashPoolCommand.CompanyId,
@@ -122,7 +115,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -122,7 +115,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
122 defer func() { 115 defer func() {
123 transactionContext.RollbackTransaction() 116 transactionContext.RollbackTransaction()
124 }() 117 }()
125 - 118 + // 统计系统素币
126 var employeeDao *dao.EmployeeDao 119 var employeeDao *dao.EmployeeDao
127 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 120 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
128 "transactionContext": transactionContext, 121 "transactionContext": transactionContext,
@@ -131,8 +124,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -131,8 +124,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
131 } else { 124 } else {
132 employeeDao = value 125 employeeDao = value
133 } 126 }
134 -  
135 - // 统计系统素币  
136 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(getCashPoolQuery.CompanyId) 127 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(getCashPoolQuery.CompanyId)
137 if err != nil { 128 if err != nil {
138 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 129 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -140,10 +131,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -140,10 +131,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
140 if systemSuMoneyStatistics == nil { 131 if systemSuMoneyStatistics == nil {
141 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 132 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
142 } 133 }
143 -  
144 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 134 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
145 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 135 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
146 -  
147 var cashPoolRepository domain.CashPoolRepository 136 var cashPoolRepository domain.CashPoolRepository
148 if value, err := factory.CreateCashPoolRepository(map[string] interface{} { 137 if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
149 "transactionContext": transactionContext, 138 "transactionContext": transactionContext,
@@ -158,7 +147,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC @@ -158,7 +147,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC
158 if err := transactionContext.CommitTransaction(); err != nil { 147 if err := transactionContext.CommitTransaction(); err != nil {
159 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 148 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
160 } 149 }
161 - // 初始状态下,现金池返回默认值  
162 if count == 0 { 150 if count == 0 {
163 return map[string] interface{} { 151 return map[string] interface{} {
164 "cashPoolId": 0, 152 "cashPoolId": 0,
@@ -192,12 +180,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -192,12 +180,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
192 defer func() { 180 defer func() {
193 transactionContext.RollbackTransaction() 181 transactionContext.RollbackTransaction()
194 }() 182 }()
195 -  
196 var timeNow = time.Now() 183 var timeNow = time.Now()
197 var deadline = createExchangeCashActivityCommand.Deadline 184 var deadline = createExchangeCashActivityCommand.Deadline
198 var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local) 185 var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
199 var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local) 186 var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
200 -  
201 newActivity := &domain.ExchangeCashActivity{ 187 newActivity := &domain.ExchangeCashActivity{
202 ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName, 188 ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
203 CompanyId: createExchangeCashActivityCommand.CompanyId, 189 CompanyId: createExchangeCashActivityCommand.CompanyId,
@@ -208,7 +194,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -208,7 +194,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
208 Rate: createExchangeCashActivityCommand.ExchangeRate, 194 Rate: createExchangeCashActivityCommand.ExchangeRate,
209 CreateTime: timeNow, 195 CreateTime: timeNow,
210 } 196 }
211 -  
212 var exchangeCashActivityRepository domain.ExchangeActivityRepository 197 var exchangeCashActivityRepository domain.ExchangeActivityRepository
213 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 198 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
214 "transactionContext": transactionContext, 199 "transactionContext": transactionContext,
@@ -217,7 +202,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -217,7 +202,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
217 } else { 202 } else {
218 exchangeCashActivityRepository = value 203 exchangeCashActivityRepository = value
219 } 204 }
220 -  
221 if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil { 205 if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil {
222 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 206 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
223 } else { 207 } else {
@@ -233,7 +217,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -233,7 +217,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
233 if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil { 217 if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
234 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 218 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
235 } 219 }
236 -  
237 transactionContext, err := factory.CreateTransactionContext(nil) 220 transactionContext, err := factory.CreateTransactionContext(nil)
238 if err != nil { 221 if err != nil {
239 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 222 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -244,7 +227,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -244,7 +227,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
244 defer func() { 227 defer func() {
245 transactionContext.RollbackTransaction() 228 transactionContext.RollbackTransaction()
246 }() 229 }()
247 -  
248 var exchangeActivityRepository domain.ExchangeActivityRepository 230 var exchangeActivityRepository domain.ExchangeActivityRepository
249 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 231 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
250 "transactionContext": transactionContext, 232 "transactionContext": transactionContext,
@@ -253,7 +235,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas @@ -253,7 +235,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
253 } else { 235 } else {
254 exchangeActivityRepository = value 236 exchangeActivityRepository = value
255 } 237 }
256 -  
257 if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil { 238 if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
258 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 239 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
259 } else { 240 } else {
@@ -360,7 +341,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -360,7 +341,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
360 transactionContext.RollbackTransaction() 341 transactionContext.RollbackTransaction()
361 }() 342 }()
362 343
363 - // TODO 更新汇率处理: 344 + // TODO 更新汇率判断
364 345
365 var exchangeCashActivityRepository domain.ExchangeActivityRepository 346 var exchangeCashActivityRepository domain.ExchangeActivityRepository
366 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 347 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
@@ -380,25 +361,20 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -380,25 +361,20 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
380 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 361 if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
381 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 362 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
382 } 363 }
383 - if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil { 364 + activityUpdated, err := exchangeCashActivityRepository.Save(activity)
  365 + if err != nil {
384 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 366 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
385 - } else {  
386 - // TODO 更新现金池已兑换素币、已兑换现金值、未兑换素币、未兑换现金值、平均汇率 367 + }
387 368
388 - //var cashPoolRepository domain.CashPoolRepository  
389 - //if value, err := factory.CreateCashPoolRepository(map[string]interface{}{  
390 - // "transactionContext": transactionContext,  
391 - //}); err != nil {  
392 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
393 - //} else {  
394 - // cashPoolRepository = value  
395 - //} 369 + // TODO 更新现金池
  370 + // 获取现金池
396 371
397 - if err := transactionContext.CommitTransaction(); err != nil {  
398 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
399 - }  
400 - return activityUpdated, nil 372 + // 更新现金池
  373 +
  374 + if err := transactionContext.CommitTransaction(); err != nil {
  375 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
401 } 376 }
  377 + return activityUpdated, nil
402 } 378 }
403 379
404 // 新增兑换素币清单 380 // 新增兑换素币清单
@@ -416,58 +392,121 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -416,58 +392,121 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
416 defer func() { 392 defer func() {
417 transactionContext.RollbackTransaction() 393 transactionContext.RollbackTransaction()
418 }() 394 }()
419 -  
420 - // TODO 获取兑换活动兑换汇率  
421 -  
422 - //var exchangeCashActivityRepository domain.ExchangeActivityRepository  
423 - //activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": createExchangeCashPersonCommand.ExchangeCashActivityId})  
424 - //if err != nil {  
425 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
426 - //}  
427 - //if activity == nil {  
428 - // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string("请设置汇率")))  
429 - //} else {  
430 - // fmt.Print(activity.Rate)  
431 - //}  
432 -  
433 - // TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”  
434 -  
435 - // TODO 新增兑换清单时,根据uid判断成员是否存在,判断素币值是否超过本人持有的素币  
436 -  
437 - // TODO 导入兑换清单时,时根据手机账号判断成员是否存在,判断素币是否超过本人持有的素币  
438 - 395 + // 获取兑换活动兑换汇率
  396 + var rate float64
  397 + var exchangeCashActivityRepository domain.ExchangeActivityRepository
  398 + activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
  399 + if err != nil {
  400 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  401 + }
  402 + if activity != nil {
  403 + rate = activity.Rate
  404 + }
  405 + // 根据uid/手机账号判断成员是否存在
  406 + var employeeRepository domain.EmployeeRepository
  407 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  408 + "transactionContext": transactionContext,
  409 + }); err != nil {
  410 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  411 + } else {
  412 + employeeRepository = value
  413 + }
  414 + employee, err := employeeRepository.FindOne(map[string]interface{}{
  415 + "uid": createExchangeCashPersonCommand.Uid,
  416 + "account": createExchangeCashPersonCommand.PersonAccount,
  417 + })
  418 + if err != nil {
  419 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  420 + }
  421 + if employee == nil {
  422 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
  423 + }
  424 + if employee.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
  425 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
  426 + }
  427 + // 新增兑换清单
  428 + var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
  429 + if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
  430 + "transactionContext": transactionContext,
  431 + }); err != nil {
  432 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  433 + } else {
  434 + exchangeCashPersonListRepository = value
  435 + }
439 newPerson := &domain.ExchangeCashPersonList{ 436 newPerson := &domain.ExchangeCashPersonList{
440 EmployeeInfo: &domain.EmployeeInfo{ 437 EmployeeInfo: &domain.EmployeeInfo{
441 - EmployeeName: createExchangeCashPersonCommand.PersonName,  
442 - EmployeeAccount: createExchangeCashPersonCommand.PersonAccount, 438 + Uid: employee.EmployeeInfo.Uid,
  439 + EmployeeName: employee.EmployeeInfo.EmployeeName,
  440 + EmployeeAccount: employee.EmployeeInfo.EmployeeAccount,
443 }, 441 },
444 ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId, 442 ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
445 ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney, 443 ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
446 - ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney, 444 + ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * rate,
447 } 445 }
448 -  
449 - var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository  
450 - if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 446 + person, err := exchangeCashPersonListRepository.Save(newPerson)
  447 + if err != nil {
  448 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  449 + }
  450 + // 生成素币流水,更新个人素币
  451 + var operationSuMoneyService service.OperationSuMoneyService
  452 + if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
451 "transactionContext": transactionContext, 453 "transactionContext": transactionContext,
452 }); err != nil { 454 }); err != nil {
453 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 455 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
454 } else { 456 } else {
455 - exchangeCashPersonListRepository = value 457 + operationSuMoneyService = value
  458 + }
  459 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
  460 + Uid: person.EmployeeInfo.Uid,
  461 + Operator: createExchangeCashPersonCommand.Operator,
  462 + SuMoney: person.ExchangedSuMoney,
  463 + OperationType: 3,
  464 + OperationDescription: "素币兑换现金",
  465 + }
  466 + task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
  467 + if err != nil {
  468 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  469 + }
  470 + if task == nil {
  471 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
456 } 472 }
457 - if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil { 473 + // 更新兑换活动
  474 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
  475 + "transactionContext": transactionContext,
  476 + }); err != nil {
458 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 477 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
459 } else { 478 } else {
460 - // TODO 更新个人素币 479 + exchangeCashActivityRepository = value
  480 + }
  481 + activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
  482 + if err != nil {
  483 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  484 + }
  485 + if activityFound == nil {
  486 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
  487 + }
  488 + createExchangeCashPersonCommand.ExchangedSuMoney += activityFound.ExchangedSuMoney
  489 + if err := activityFound.Update(tool_funs.SimpleStructToMap(createExchangeCashPersonCommand)); err != nil {
  490 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  491 + }
  492 + activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
  493 + if err != nil {
  494 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  495 + }
  496 + if activityUpdated == nil {
  497 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
  498 + }
461 499
462 - // TODO 更新活动数据 500 + // TODO 判断清单中现金总额超过现金池未兑换现金时创建失败,提示:“已超过投入现金池的未兑换现金”
463 501
464 - // TODO 更新现金池数据 502 + // TODO 更新现金池
  503 + // 获取现金池
  504 + // 更新现金池
465 505
466 - if err := transactionContext.CommitTransaction(); err != nil {  
467 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
468 - }  
469 - return person, nil 506 + if err := transactionContext.CommitTransaction(); err != nil {
  507 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
470 } 508 }
  509 + return person, nil
471 } 510 }
472 511
473 // 返回兑换素币清单 512 // 返回兑换素币清单
@@ -558,6 +597,27 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -558,6 +597,27 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
558 defer func() { 597 defer func() {
559 transactionContext.RollbackTransaction() 598 transactionContext.RollbackTransaction()
560 }() 599 }()
  600 + var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
  601 + if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
  602 + "transactionContext": transactionContext,
  603 + }); err != nil {
  604 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  605 + } else {
  606 + exchangeCashPersonListRepository = value
  607 + }
  608 + person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": removeExchangeCashPersonCommand.ListId})
  609 + if err != nil {
  610 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  611 + }
  612 + if person == nil {
  613 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
  614 + }
  615 + // 移除兑换素币清单
  616 + personDeleted, err := exchangeCashPersonListRepository.Remove(person)
  617 + if err != nil {
  618 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  619 + }
  620 + // 生成素币流水,更新个人素币
561 var operationSuMoneyService service.OperationSuMoneyService 621 var operationSuMoneyService service.OperationSuMoneyService
562 if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{ 622 if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
563 "transactionContext": transactionContext, 623 "transactionContext": transactionContext,
@@ -566,52 +626,62 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -566,52 +626,62 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
566 } else { 626 } else {
567 operationSuMoneyService = value 627 operationSuMoneyService = value
568 } 628 }
569 - var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository  
570 - if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 629 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
  630 + Uid: person.EmployeeInfo.Uid,
  631 + Operator: removeExchangeCashPersonCommand.Operator,
  632 + SuMoney: person.ExchangedSuMoney,
  633 + OperationType: 1,
  634 + OperationDescription: "素币兑换现金调整",
  635 + }
  636 + task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
  637 + if err != nil {
  638 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  639 + }
  640 + if task == nil {
  641 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
  642 + }
  643 + // 更新兑换活动
  644 + var exchangeCashActivityRepository domain.ExchangeActivityRepository
  645 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
571 "transactionContext": transactionContext, 646 "transactionContext": transactionContext,
572 }); err != nil { 647 }); err != nil {
573 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 648 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
574 } else { 649 } else {
575 - exchangeCashPersonListRepository = value 650 + exchangeCashActivityRepository = value
576 } 651 }
577 - person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": removeExchangeCashPersonCommand.ListId}) 652 + activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId})
578 if err != nil { 653 if err != nil {
579 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 654 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
580 } 655 }
581 - if person == nil {  
582 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId))) 656 + if activityFound == nil {
  657 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
  658 + }
  659 + updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
  660 + ExchangeCashActivityId: person.ExchangeCashActivityId,
  661 + ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney,
  662 + ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,
583 } 663 }
584 - if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil { 664 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
  665 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  666 + }
  667 + activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
  668 + if err != nil {
585 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 669 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
586 - } else {  
587 - // TODO 更新个人素币,个人素币值需要还原,理由:素币兑换现金调整  
588 - operationSuMoneyCommand := &command.OperationSuMoneyCommand{  
589 - Uid: person.EmployeeInfo.Uid,  
590 - Operator: removeExchangeCashPersonCommand.Operator,  
591 - SuMoney: 0,  
592 - OperationType: 5,  
593 - OperationDescription: "素币兑换现金调整",  
594 - }  
595 - task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)  
596 - if err != nil {  
597 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
598 - }  
599 - if task == nil {  
600 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))  
601 - } 670 + }
  671 + if activityUpdated == nil {
  672 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
  673 + }
602 674
603 - // TODO 更新兑换活动数据 675 + // TODO 更新现金池
604 676
605 - // TODO 更新现金池数据  
606 677
607 - if err := transactionContext.CommitTransaction(); err != nil {  
608 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
609 - }  
610 - return personDeleted, nil 678 + if err := transactionContext.CommitTransaction(); err != nil {
  679 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
611 } 680 }
  681 + return personDeleted, nil
612 } 682 }
613 683
614 -// 更新兑换现金人员 684 +// 更新兑换清单
615 func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) { 685 func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
616 if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil { 686 if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
617 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 687 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -626,6 +696,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -626,6 +696,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
626 defer func() { 696 defer func() {
627 transactionContext.RollbackTransaction() 697 transactionContext.RollbackTransaction()
628 }() 698 }()
  699 + // 更新兑换清单
629 var operationSuMoneyService service.OperationSuMoneyService 700 var operationSuMoneyService service.OperationSuMoneyService
630 if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{ 701 if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
631 "transactionContext": transactionContext, 702 "transactionContext": transactionContext,
@@ -634,7 +705,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -634,7 +705,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
634 } else { 705 } else {
635 operationSuMoneyService = value 706 operationSuMoneyService = value
636 } 707 }
637 -  
638 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 708 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
639 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 709 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
640 "transactionContext": transactionContext, 710 "transactionContext": transactionContext,
@@ -653,34 +723,38 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -653,34 +723,38 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
653 if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil { 723 if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
654 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 724 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
655 } 725 }
656 - if personUpdated, err := exchangeCashPersonListRepository.Save(person); err != nil { 726 + personUpdated, err := exchangeCashPersonListRepository.Save(person)
  727 + if err != nil {
657 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 728 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
658 - } else {  
659 - operationSuMoneyCommand := &command.OperationSuMoneyCommand{  
660 - Uid: person.EmployeeInfo.Uid,  
661 - Operator: updateExchangeCashPersonCommand.Operator,  
662 - SuMoney: updateExchangeCashPersonCommand.ExchangedSuMoney,  
663 - OperationType: 5,  
664 - OperationDescription: "参与兑换素币活动",  
665 - }  
666 - // TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称)  
667 - task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)  
668 - if err != nil {  
669 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
670 - }  
671 - if task == nil {  
672 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))  
673 - } 729 + }
674 730
675 - // TODO 更新兑换活动数据 731 + // TODO 更新兑换活动
676 732
677 - // TODO 更新现金池  
678 733
679 - if err := transactionContext.CommitTransaction(); err != nil {  
680 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
681 - }  
682 - return personUpdated, nil 734 + // TODO 判断现金池未兑换现金
  735 +
  736 +
  737 + // TODO 更新现金池
  738 +
  739 + // 生成素币兑换流水记录,更新员工素币
  740 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
  741 + Uid: person.EmployeeInfo.Uid,
  742 + Operator: updateExchangeCashPersonCommand.Operator,
  743 + SuMoney: updateExchangeCashPersonCommand.ExchangedSuMoney,
  744 + OperationType: 3,
  745 + OperationDescription: "参与兑换素币活动",
  746 + }
  747 + task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
  748 + if err != nil {
  749 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  750 + }
  751 + if task == nil {
  752 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
  753 + }
  754 + if err := transactionContext.CommitTransaction(); err != nil {
  755 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
683 } 756 }
  757 + return personUpdated, nil
684 } 758 }
685 759
686 func NewCashPoolService(options map[string]interface{}) *CashPoolService { 760 func NewCashPoolService(options map[string]interface{}) *CashPoolService {
@@ -41,8 +41,6 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand * @@ -41,8 +41,6 @@ func (suMoneyService *SuMoneyService) OperationSuMoney(operationSuMoneyCommand *
41 if task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription); err != nil { 41 if task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription); err != nil {
42 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 42 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
43 } else { 43 } else {
44 - // TODO 增加、扣除素币和个人贡献值关联,兑换物资不与贡献值关联  
45 -  
46 if err := transactionContext.CommitTransaction(); err != nil { 44 if err := transactionContext.CommitTransaction(); err != nil {
47 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 45 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
48 } 46 }
@@ -29,6 +29,8 @@ type CreateTaskCommand struct { @@ -29,6 +29,8 @@ type CreateTaskCommand struct {
29 TaskNature int `json:"taskNature,omitempty"` 29 TaskNature int `json:"taskNature,omitempty"`
30 // 奖励素币 30 // 奖励素币
31 SuMoney float64 `json:"suMoney,omitempty"` 31 SuMoney float64 `json:"suMoney,omitempty"`
  32 + // 奖励素币参考值范围(1000~3000)
  33 + ReferenceSuMoney string `json:"referenceSuMoney"`
32 // 验收标准 34 // 验收标准
33 AcceptanceStandard string `json:"acceptanceStandard,omitempty"` 35 AcceptanceStandard string `json:"acceptanceStandard,omitempty"`
34 // 任务描述 36 // 任务描述
@@ -325,6 +325,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac @@ -325,6 +325,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
325 acceptanceTaskService = value 325 acceptanceTaskService = value
326 acceptanceTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{}) 326 acceptanceTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
327 } 327 }
  328 +
328 if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls, acceptanceTaskCommand.ActualCompletionTime); err != nil { 329 if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls, acceptanceTaskCommand.ActualCompletionTime); err != nil {
329 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 330 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
330 } else { 331 } else {
@@ -774,12 +775,9 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu @@ -774,12 +775,9 @@ func (taskService *TaskService) GetRejectTaskRecord(getRejectTaskRecordQuery *qu
774 775
775 // 创建新任务 776 // 创建新任务
776 func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) { 777 func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) {
777 - // 校验创建任务命令  
778 if err := createTaskCommand.ValidateCommand(); err != nil { 778 if err := createTaskCommand.ValidateCommand(); err != nil {
779 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 779 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
780 } 780 }
781 -  
782 - // 新建事务  
783 transactionContext, err := factory.CreateTransactionContext(nil) 781 transactionContext, err := factory.CreateTransactionContext(nil)
784 if err != nil { 782 if err != nil {
785 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 783 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -790,8 +788,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -790,8 +788,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
790 defer func() { 788 defer func() {
791 transactionContext.RollbackTransaction() 789 transactionContext.RollbackTransaction()
792 }() 790 }()
793 -  
794 - // 新建任务数据访问对象  
795 var taskDao *dao.TaskDao 791 var taskDao *dao.TaskDao
796 if value, err := factory.CreateTaskDao(map[string]interface{}{ 792 if value, err := factory.CreateTaskDao(map[string]interface{}{
797 "transactionContext": transactionContext, 793 "transactionContext": transactionContext,
@@ -800,8 +796,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -800,8 +796,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
800 } else { 796 } else {
801 taskDao = value 797 taskDao = value
802 } 798 }
803 -  
804 - // 获取任务发布者信息  
805 var employeeRepository domain.EmployeeRepository 799 var employeeRepository domain.EmployeeRepository
806 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 800 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
807 "transactionContext": transactionContext, 801 "transactionContext": transactionContext,
@@ -810,7 +804,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -810,7 +804,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
810 } else { 804 } else {
811 employeeRepository = value 805 employeeRepository = value
812 } 806 }
813 -  
814 sponsor, err := employeeRepository.FindOne(map[string]interface{}{ 807 sponsor, err := employeeRepository.FindOne(map[string]interface{}{
815 "uid": createTaskCommand.Sponsor, 808 "uid": createTaskCommand.Sponsor,
816 }) 809 })
@@ -820,7 +813,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -820,7 +813,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
820 if sponsor == nil { 813 if sponsor == nil {
821 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者") 814 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的发布者")
822 } 815 }
823 -  
824 // 获取任务指派人 816 // 获取任务指派人
825 var assignedPerson *domain.EmployeeInfo 817 var assignedPerson *domain.EmployeeInfo
826 if createTaskCommand.AssignedPerson != 0 { 818 if createTaskCommand.AssignedPerson != 0 {
@@ -835,8 +827,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -835,8 +827,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
835 } 827 }
836 assignedPerson = employee.EmployeeInfo 828 assignedPerson = employee.EmployeeInfo
837 } 829 }
838 -  
839 - // 创建新任务  
840 newTask := &domain.Task{ 830 newTask := &domain.Task{
841 TaskStatus: domain.TASK_STATUS_UNRELEASED, 831 TaskStatus: domain.TASK_STATUS_UNRELEASED,
842 CompanyId: createTaskCommand.CompanyId, 832 CompanyId: createTaskCommand.CompanyId,
@@ -851,6 +841,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -851,6 +841,7 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
851 CustomerValues: createTaskCommand.CustomerValues, 841 CustomerValues: createTaskCommand.CustomerValues,
852 TaskNature: createTaskCommand.TaskNature, 842 TaskNature: createTaskCommand.TaskNature,
853 SuMoney: createTaskCommand.SuMoney, 843 SuMoney: createTaskCommand.SuMoney,
  844 + ReferenceSuMoney: createTaskCommand.ReferenceSuMoney, // 奖励素币范围
854 AcceptanceStandard: createTaskCommand.AcceptanceStandard, 845 AcceptanceStandard: createTaskCommand.AcceptanceStandard,
855 TaskDescription: createTaskCommand.TaskDescription, 846 TaskDescription: createTaskCommand.TaskDescription,
856 TaskPictureUrls: createTaskCommand.TaskPictureUrls, 847 TaskPictureUrls: createTaskCommand.TaskPictureUrls,
@@ -859,7 +850,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask @@ -859,7 +850,6 @@ func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTask
859 PlannedCompletionTime: createTaskCommand.PlannedCompletionTime, 850 PlannedCompletionTime: createTaskCommand.PlannedCompletionTime,
860 CreateTime: time.Now(), 851 CreateTime: time.Now(),
861 } 852 }
862 -  
863 var taskRepository domain.TaskRepository 853 var taskRepository domain.TaskRepository
864 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 854 if value, err := factory.CreateTaskRepository(map[string]interface{}{
865 "transactionContext": transactionContext, 855 "transactionContext": transactionContext,
@@ -922,21 +912,16 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -922,21 +912,16 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
922 if err := getTaskQuery.ValidateQuery(); err != nil { 912 if err := getTaskQuery.ValidateQuery(); err != nil {
923 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 913 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
924 } 914 }
925 -  
926 transactionContext, err := factory.CreateTransactionContext(nil) 915 transactionContext, err := factory.CreateTransactionContext(nil)
927 -  
928 if err != nil { 916 if err != nil {
929 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 917 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
930 } 918 }
931 -  
932 if err := transactionContext.StartTransaction(); err != nil { 919 if err := transactionContext.StartTransaction(); err != nil {
933 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 920 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
934 } 921 }
935 -  
936 defer func() { 922 defer func() {
937 transactionContext.RollbackTransaction() 923 transactionContext.RollbackTransaction()
938 }() 924 }()
939 -  
940 var taskRepository domain.TaskRepository 925 var taskRepository domain.TaskRepository
941 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 926 if value, err := factory.CreateTaskRepository(map[string]interface{}{
942 "transactionContext": transactionContext, 927 "transactionContext": transactionContext,
@@ -945,18 +930,14 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -945,18 +930,14 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
945 } else { 930 } else {
946 taskRepository = value 931 taskRepository = value
947 } 932 }
948 -  
949 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId}) 933 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId})
950 -  
951 if err != nil { 934 if err != nil {
952 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 935 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
953 } 936 }
954 -  
955 if task == nil { 937 if task == nil {
956 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskQuery.TaskId))) 938 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskQuery.TaskId)))
957 } else { 939 } else {
958 var projectBelongRepository domain.ProjectBelongRepository 940 var projectBelongRepository domain.ProjectBelongRepository
959 -  
960 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{ 941 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
961 "transactionContext": transactionContext, 942 "transactionContext": transactionContext,
962 }); err != nil { 943 }); err != nil {
@@ -964,9 +945,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -964,9 +945,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
964 } else { 945 } else {
965 projectBelongRepository = value 946 projectBelongRepository = value
966 } 947 }
967 -  
968 projectBelongMap := make(map[int]*domain.ProjectBelong) 948 projectBelongMap := make(map[int]*domain.ProjectBelong)
969 -  
970 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{ 949 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
971 "companyId": task.CompanyId, 950 "companyId": task.CompanyId,
972 }); err != nil { 951 }); err != nil {
@@ -976,9 +955,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -976,9 +955,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
976 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong 955 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
977 } 956 }
978 } 957 }
979 -  
980 var customerValueRepository domain.CustomerValueRepository 958 var customerValueRepository domain.CustomerValueRepository
981 -  
982 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{ 959 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
983 "transactionContext": transactionContext, 960 "transactionContext": transactionContext,
984 }); err != nil { 961 }); err != nil {
@@ -986,9 +963,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -986,9 +963,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
986 } else { 963 } else {
987 customerValueRepository = value 964 customerValueRepository = value
988 } 965 }
989 -  
990 customerValueMap := make(map[int]*domain.CustomerValue) 966 customerValueMap := make(map[int]*domain.CustomerValue)
991 -  
992 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{ 967 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
993 "companyId": task.CompanyId, 968 "companyId": task.CompanyId,
994 }); err != nil { 969 }); err != nil {
@@ -998,9 +973,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -998,9 +973,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
998 customerValueMap[customerValue.CustomerValueId] = customerValue 973 customerValueMap[customerValue.CustomerValueId] = customerValue
999 } 974 }
1000 } 975 }
1001 -  
1002 var taskNatureRepository domain.TaskNatureRepository 976 var taskNatureRepository domain.TaskNatureRepository
1003 -  
1004 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{ 977 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
1005 "transactionContext": transactionContext, 978 "transactionContext": transactionContext,
1006 }); err != nil { 979 }); err != nil {
@@ -1008,9 +981,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -1008,9 +981,7 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
1008 } else { 981 } else {
1009 taskNatureRepository = value 982 taskNatureRepository = value
1010 } 983 }
1011 -  
1012 taskNatureMap := make(map[int]*domain.TaskNature) 984 taskNatureMap := make(map[int]*domain.TaskNature)
1013 -  
1014 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{ 985 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
1015 "companyId": task.CompanyId, 986 "companyId": task.CompanyId,
1016 }); err != nil { 987 }); err != nil {
@@ -1020,16 +991,13 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -1020,16 +991,13 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
1020 taskNatureMap[taskNature.TaskNatureId] = taskNature 991 taskNatureMap[taskNature.TaskNatureId] = taskNature
1021 } 992 }
1022 } 993 }
1023 -  
1024 taskDto := &dto.TaskDto{} 994 taskDto := &dto.TaskDto{}
1025 -  
1026 if err := taskDto.LoadDto(task, projectBelongMap, customerValueMap, taskNatureMap); err != nil { 995 if err := taskDto.LoadDto(task, projectBelongMap, customerValueMap, taskNatureMap); err != nil {
1027 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 996 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1028 } 997 }
1029 if err := transactionContext.CommitTransaction(); err != nil { 998 if err := transactionContext.CommitTransaction(); err != nil {
1030 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 999 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1031 } 1000 }
1032 -  
1033 return taskDto, nil 1001 return taskDto, nil
1034 } 1002 }
1035 } 1003 }
@@ -1241,9 +1209,17 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in @@ -1241,9 +1209,17 @@ func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (in
1241 if err := transactionContext.CommitTransaction(); err != nil { 1209 if err := transactionContext.CommitTransaction(); err != nil {
1242 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1210 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1243 } 1211 }
  1212 + // 拼接奖励素币范围值
  1213 + var retTasks []*domain.Task
  1214 + for _, task := range tasks {
  1215 + if task.ReferenceSuMoney == "" {
  1216 + task.ReferenceSuMoney = "0~" + fmt.Sprintf("%.0f", task.SuMoney)
  1217 + }
  1218 + retTasks = append(retTasks, task)
  1219 + }
1244 return map[string]interface{}{ 1220 return map[string]interface{}{
1245 "count": count, 1221 "count": count,
1246 - "tasks": tasks, 1222 + "tasks": retTasks,
1247 }, nil 1223 }, nil
1248 } 1224 }
1249 } 1225 }
@@ -17,6 +17,7 @@ type CashPool struct { @@ -17,6 +17,7 @@ type CashPool struct {
17 17
18 type CashPoolRepository interface { 18 type CashPoolRepository interface {
19 Save(cashPool *CashPool) (*CashPool, error) 19 Save(cashPool *CashPool) (*CashPool, error)
  20 + FindOne(queryOptions map[string]interface{}) (*CashPool, error)
20 Find(queryOptions map[string]interface{}) (int64, []*CashPool, error) 21 Find(queryOptions map[string]interface{}) (int64, []*CashPool, error)
21 } 22 }
22 23
@@ -50,6 +50,8 @@ type Task struct { @@ -50,6 +50,8 @@ type Task struct {
50 TaskNature int `json:"taskNature"` 50 TaskNature int `json:"taskNature"`
51 // 奖励素币 51 // 奖励素币
52 SuMoney float64 `json:"suMoney"` 52 SuMoney float64 `json:"suMoney"`
  53 + // 奖励素币参考值
  54 + ReferenceSuMoney string `json:"referenceSuMoney"`
53 // 验收标准 55 // 验收标准
54 AcceptanceStandard string `json:"acceptanceStandard"` 56 AcceptanceStandard string `json:"acceptanceStandard"`
55 // 任务描述 57 // 任务描述
@@ -10,47 +10,71 @@ type CashPoolDao struct { @@ -10,47 +10,71 @@ type CashPoolDao struct {
10 transactionContext *pgTransaction.TransactionContext 10 transactionContext *pgTransaction.TransactionContext
11 } 11 }
12 12
13 -// 计算系统素币  
14 -func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( float64, float64, error) {  
15 - var systemUnExchangeSuMoney float64  
16 - var systemExchangedSuMoney float64 13 +// 计算系统已兑换素币、未兑换素币
  14 +//func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( map[string]interface{}, error) {
  15 +// var systemUnExchangeSuMoney float64
  16 +// var systemExchangedSuMoney float64
  17 +// tx := dao.transactionContext.PgTx
  18 +// employeeModel := new(models.Employee)
  19 +// if err := tx.Model(employeeModel).
  20 +// ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
  21 +// Where("employee.company_id = ?", companyId).
  22 +// Select(&systemUnExchangeSuMoney); err != nil {
  23 +// return nil, err
  24 +// }
  25 +// exchangeCashActivityModel := new(models.ExchangeCashActivity)
  26 +// if err := tx.Model(exchangeCashActivityModel).
  27 +// ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").
  28 +// Where("exchange_cash_activity.company_id = ?", companyId).
  29 +// Select(&systemExchangedSuMoney); err != nil {
  30 +// return nil, err
  31 +// }
  32 +// return map[string]interface{}{
  33 +// "systemUnExchangeSuMoney": systemUnExchangeSuMoney,
  34 +// "systemExchangedSuMoney": systemExchangedSuMoney,
  35 +// }, nil
  36 +//}
17 37
18 - tx := dao.transactionContext.PgTx  
19 -  
20 - employeeModel := new(models.Employee)  
21 - if err := tx.Model(employeeModel).  
22 - ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").  
23 - Where("employee.company_id = ?", companyId).  
24 - Select(&systemUnExchangeSuMoney); err != nil {  
25 - return 0, 0, err  
26 - }  
27 -  
28 - exchangeCashActivityModel := new(models.ExchangeCashActivity)  
29 - if err := tx.Model(exchangeCashActivityModel).  
30 - ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").  
31 - Where("exchange_cash_activity.company_id = ?", companyId).  
32 - Select(&systemExchangedSuMoney); err != nil {  
33 - return 0, 0, err  
34 - }  
35 -  
36 - return systemUnExchangeSuMoney, systemExchangedSuMoney, nil  
37 -}  
38 -  
39 -// 计算系统已兑换现金  
40 -func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (float64, error) {  
41 - var systemExchangedCash float64 // 系统已兑换现金 38 +// 计算系统已兑换现金、未兑换现金
  39 +//func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (map[string]interface{}, error) {
  40 +// var systemExchangedCash float64 // 系统已兑换现金
  41 +// var systemUnExchangeCash float64 // 系统未兑换现金
  42 +// tx := dao.transactionContext.PgTx
  43 +// exchangeCashActivityModel := new(models.ExchangeCashActivity)
  44 +// if err := tx.Model(exchangeCashActivityModel).
  45 +// ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").
  46 +// Where("exchange_cash_activity.company_id = ?", companyId).
  47 +// Select(&systemExchangedCash) ; err != nil {
  48 +// return nil, err
  49 +// }
  50 +// return map[string]interface{}{
  51 +// "systemExchangedCash": systemExchangedCash,
  52 +// "systemUnExchangeCash": systemUnExchangeCash,
  53 +// }, nil
  54 +//}
42 55
  56 +// 兑换兑换活动已兑换素币、已兑换现金
  57 +func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map[string]interface{}, error) {
  58 + var activityExchangedSuMoney float64
  59 + var activityExchangedCash float64
43 tx := dao.transactionContext.PgTx 60 tx := dao.transactionContext.PgTx
44 - exchangeCashActivityModel := new(models.ExchangeCashActivity)  
45 -  
46 - if err := tx.Model(exchangeCashActivityModel).  
47 - ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").  
48 - Where("exchange_cash_activity.company_id = ?", companyId).  
49 - Select(&systemExchangedCash) ; err != nil {  
50 - return 0, err 61 + exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
  62 + if err := tx.Model(exchangeCashPersonListModels).
  63 + ColumnExpr("sum(exchange_cash_person_lists.exchanged_su_money) AS activity_exchanged_su_money").
  64 + Where("exchange_cash_person_lists.activity_id = ?", activityId).
  65 + Select(&activityExchangedSuMoney); err !=nil {
  66 + return nil, err
51 } 67 }
52 -  
53 - return systemExchangedCash, nil 68 + if err := tx.Model(exchangeCashPersonListModels).
  69 + ColumnExpr("sum(exchange_cash_person_lists.exchanged_cash) AS activity_exchanged_cash").
  70 + Where("exchange_cash_person_lists.activity_id = ?", activityId).
  71 + Select(&activityExchangedCash); err !=nil {
  72 + return nil, err
  73 + }
  74 + return map[string]interface{}{
  75 + "activityExchangedSuMoney": activityExchangedSuMoney,
  76 + "activityExchangedCash": activityExchangedCash,
  77 + }, nil
54 } 78 }
55 79
56 func NewCashPoolDao(transactionContext *pgTransaction.TransactionContext) (*CashPoolDao, error) { 80 func NewCashPoolDao(transactionContext *pgTransaction.TransactionContext) (*CashPoolDao, error) {
@@ -114,22 +114,26 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ @@ -114,22 +114,26 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
114 }, nil 114 }, nil
115 } 115 }
116 116
117 -// 计算系统素币 117 +// 系统已兑换素币、未兑换素币
118 func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] interface{}, error) { 118 func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] interface{}, error) {
119 var systemUnExchangeSuMoney float64 119 var systemUnExchangeSuMoney float64
120 var systemExchangedSuMoney float64 120 var systemExchangedSuMoney float64
121 tx := dao.transactionContext.PgTx 121 tx := dao.transactionContext.PgTx
122 - suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)  
123 - if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").  
124 - ColumnExpr("sum(su_money_transaction_record.current_su_money) AS system_unExchange_su_money"). 122 + // 系统未兑换素币
  123 + employeeModel := new(models.Employee)
  124 + if err := tx.Model(employeeModel).
  125 + ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
125 Where("employee.company_id = ?", companyId). 126 Where("employee.company_id = ?", companyId).
126 - Where(`su_money_transaction_record.record_type = ?`, 5). 127 + Where("employee.status = ?", 1).
127 Select(&systemUnExchangeSuMoney); err != nil { 128 Select(&systemUnExchangeSuMoney); err != nil {
128 return nil, err 129 return nil, err
129 } 130 }
  131 + // 系统已兑换现金素币
  132 + suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
130 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint"). 133 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
131 ColumnExpr("sum(su_money_transaction_record.su_money) AS system_changed_su_money"). 134 ColumnExpr("sum(su_money_transaction_record.su_money) AS system_changed_su_money").
132 - Where("employee.company_id = ?", companyId). 135 + Where("e.company_id = ?", companyId).
  136 + Where("e.status = ?", 1).
133 Where(`su_money_transaction_record.record_type = ?`, 5). 137 Where(`su_money_transaction_record.record_type = ?`, 5).
134 Select(&systemExchangedSuMoney); err != nil { 138 Select(&systemExchangedSuMoney); err != nil {
135 return nil, err 139 return nil, err
@@ -140,38 +144,40 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int @@ -140,38 +144,40 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int
140 },nil 144 },nil
141 } 145 }
142 146
143 -// 计算系统现金 147 +// 计算系统已兑换现金、未兑换现金
144 func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interface{}, error) { 148 func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interface{}, error) {
  149 + tx := dao.transactionContext.PgTx
145 var ( 150 var (
146 systemUnExchangeCash float64 151 systemUnExchangeCash float64
147 systemExchangedCash float64 152 systemExchangedCash float64
148 ) 153 )
149 - tx := dao.transactionContext.PgTx 154 + // 系统已兑换现金
150 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 155 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
151 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint"). 156 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
152 ColumnExpr("sum(su_money_transaction_record.cash) AS system_exchanged_cash"). 157 ColumnExpr("sum(su_money_transaction_record.cash) AS system_exchanged_cash").
153 - Where("employee.company_id = ?", companyId). 158 + Where("e.company_id = ?", companyId).
  159 + //Where(`e.status = ?`, 1).
154 Where(`su_money_transaction_record.record_type = ?`, 5). 160 Where(`su_money_transaction_record.record_type = ?`, 5).
155 Select(&systemExchangedCash) ; err != nil { 161 Select(&systemExchangedCash) ; err != nil {
156 return nil, err 162 return nil, err
157 } 163 }
158 - 164 + // 系统未兑换现金
159 cashPool := new(models.CashPool) 165 cashPool := new(models.CashPool)
160 if err := tx.Model(cashPool). 166 if err := tx.Model(cashPool).
161 Column("un_exchange_cash"). 167 Column("un_exchange_cash").
162 - Where("cash_pool.company_id = ?", companyId).  
163 - Order("id DSC"). 168 + Where("cash_pools.company_id = ?", companyId).
  169 + Order("id DESC").
164 Limit(1). 170 Limit(1).
165 Select(&systemUnExchangeCash) ; err != nil { 171 Select(&systemUnExchangeCash) ; err != nil {
166 return nil, err 172 return nil, err
167 } 173 }
168 -  
169 return map[string] interface{} { 174 return map[string] interface{} {
170 "systemUnExchangeCash": systemUnExchangeCash, 175 "systemUnExchangeCash": systemUnExchangeCash,
171 "systemExchangedCash": systemExchangedCash, 176 "systemExchangedCash": systemExchangedCash,
172 }, nil 177 }, nil
173 } 178 }
174 179
  180 +// 个人素币事务统计
175 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) { 181 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
176 var incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加) 182 var incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
177 var expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金) 183 var expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金)
@@ -201,47 +207,89 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -201,47 +207,89 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
201 }, nil 207 }, nil
202 } 208 }
203 209
204 -func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int) (map[string]interface{}, error) { 210 +// 员工财富值统计
  211 +func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
205 tx := dao.transactionContext.PgTx 212 tx := dao.transactionContext.PgTx
206 - var res []struct { 213 + var ret []struct {
  214 + Uid int
  215 + EmployeeName string
207 EmployeesSuMoney float64 216 EmployeesSuMoney float64
208 - Employee domain.Employee 217 + //Employee domain.Employee
209 } 218 }
210 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 219 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
211 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint"). 220 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
212 - Column("su_money_transaction_record.employee, (su_money_transaction_record.employee->>'employeeName')::text,").  
213 - ColumnExpr("sum(su_money_transaction_record.current_su_money) AS employee_su_money"). 221 + Column("su_money_transaction_records.employee, (su_money_transaction_records.employee->>'employeeName')::text,").
  222 + ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid, su_money_transaction_records.employee->>'employeeName' AS employeeName, sum(su_money_transaction_records.su_money) AS employee_su_money").
214 Where(`e.company_id = ?`, companyId). 223 Where(`e.company_id = ?`, companyId).
215 Where(`e.status = ?`, 1). 224 Where(`e.status = ?`, 1).
216 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).  
217 - Group("su_money_transaction_record.employee"). 225 + Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
  226 + Where(`su_money_transaction_records.create_time > ?`, startTime).
  227 + Where(`su_money_transaction_records.create_time < ?`, endTime).
  228 + Group("su_money_transaction_records.employee").
218 Order("employee_su_money DESC"). 229 Order("employee_su_money DESC").
219 - Select(&res); err != nil { 230 + Select(&ret); err != nil {
220 return nil, err 231 return nil, err
221 } 232 }
222 return map[string]interface{}{ 233 return map[string]interface{}{
223 - "employeesSuMoney": res, 234 + "employeesSuMoney": ret,
224 }, nil 235 }, nil
225 } 236 }
226 237
227 -func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int) (map[string]interface{}, error) { 238 +// 员工贡献值统计
  239 +func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
228 tx := dao.transactionContext.PgTx 240 tx := dao.transactionContext.PgTx
229 - var ret []struct { 241 + var ret []struct { // 员工贡献值
  242 + Uid int
  243 + EmployeeName string
  244 + EmployeesContributions float64
  245 + //Employee domain.Employee
  246 + }
  247 + var retDecrease []struct { // 员工减少的贡献值
  248 + Uid int
  249 + EmployeeName string
230 EmployeesContributions float64 250 EmployeesContributions float64
231 - Employee domain.Employee 251 + //Employee domain.Employee
232 } 252 }
  253 + //var employeesContributionsIncrease []struct{} // 员工增加的贡献值列表
  254 + //var employeesContributionsDecrease []struct{} //
  255 + //var employeesContributions []struct{}
233 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 256 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
234 - if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").  
235 - Column("su_money_transaction_record.employee").  
236 - ColumnExpr("sum(s.current_su_money) AS employees_contributions"). 257 + // 增加的贡献值
  258 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
  259 + Column("su_money_transaction_records.employee").
  260 + ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid, su_money_transaction_records.employee->>'employeeName' AS employeeName, sum(su_money_transaction_records.su_money) AS employees_contributions_increase").
237 Where(`e.company_id = ?`, companyId). 261 Where(`e.company_id = ?`, companyId).
238 - Where(`su_money_transaction_record.record_type = ?`, 2). 262 + Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})).
239 Where(`e.status = ?`, 1). 263 Where(`e.status = ?`, 1).
240 - Group("su_money_transaction_record.employee"). 264 + Where(`su_money_transaction_records.create_time > ?`, startTime).
  265 + Where(`su_money_transaction_records.create_time < ?`, endTime).
  266 + Group("su_money_transaction_records.employee").
241 Order("employees_contributions DESC"). 267 Order("employees_contributions DESC").
242 Select(&ret); err != nil { 268 Select(&ret); err != nil {
243 return nil, err 269 return nil, err
244 } 270 }
  271 + // 减少的贡献值
  272 + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
  273 + Column("su_money_transaction_records.employee").
  274 + ColumnExpr("sum(su_money_transaction_records.su_money) AS employees_contributions_decrease").
  275 + Where(`e.company_id = ?`, companyId).
  276 + Where(`su_money_transaction_records.record_type = ?`, 4).
  277 + Where(`e.status = ?`, 1).
  278 + Where(`su_money_transaction_records.create_time > ?`, startTime).
  279 + Where(`su_money_transaction_records.create_time < ?`, endTime).
  280 + Group("su_money_transaction_records.employee").
  281 + Order("employees_contributions DESC").
  282 + Select(&retDecrease); err != nil {
  283 + return nil, err
  284 + }
  285 + // merge两个贡献值
  286 + for i := 0; i < len(ret); i++ {
  287 + for j := 0; j < len(retDecrease); j++ {
  288 + if ret[i].Uid == retDecrease[j].Uid {
  289 + ret[i].EmployeesContributions -= retDecrease[j].EmployeesContributions
  290 + }
  291 + }
  292 + }
245 return map[string]interface{}{ 293 return map[string]interface{}{
246 "employeesContributions": ret, 294 "employeesContributions": ret,
247 }, nil 295 }, nil
@@ -57,14 +57,18 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64, @@ -57,14 +57,18 @@ func (service *OperationSuMoneyService) Operation(uid int64, operatorUid int64,
57 } 57 }
58 var recordType int 58 var recordType int
59 var transferSuMoney float64 59 var transferSuMoney float64
60 - if operationType == 1 { 60 + if operationType == 1 { // 增加
61 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE 61 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE
62 transferSuMoney = suMoney 62 transferSuMoney = suMoney
63 } 63 }
64 - if operationType == 2 { 64 + if operationType == 2 { // 扣除
65 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT 65 recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT
66 transferSuMoney = 0 - suMoney 66 transferSuMoney = 0 - suMoney
67 } 67 }
  68 + if operationType == 3 { // 兑换现金
  69 + recordType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH
  70 + transferSuMoney = 0 - suMoney
  71 + }
68 suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{ 72 suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{
69 RecordType: recordType, 73 RecordType: recordType,
70 Employee: employee.EmployeeInfo, 74 Employee: employee.EmployeeInfo,
@@ -29,6 +29,8 @@ type Task struct { @@ -29,6 +29,8 @@ type Task struct {
29 TaskNature int 29 TaskNature int
30 // 奖励素币 30 // 奖励素币
31 SuMoney float64 31 SuMoney float64
  32 + // 奖励素币参考值范围值
  33 + ReferenceSuMoney string
32 // 验收标准 34 // 验收标准
33 AcceptanceStandard string 35 AcceptanceStandard string
34 // 任务描述 36 // 任务描述
@@ -71,6 +71,27 @@ func (repository *CashPoolRepository) Find(queryOptions map[string]interface{}) @@ -71,6 +71,27 @@ func (repository *CashPoolRepository) Find(queryOptions map[string]interface{})
71 } 71 }
72 } 72 }
73 73
  74 +func (repository *CashPoolRepository) FindOne(queryOptions map[string]interface{}) (*domain.CashPool, error) {
  75 + tx := repository.transactionContext.PgTx
  76 + cashPoolModel := new(models.CashPool)
  77 + query := tx.Model(cashPoolModel)
  78 + if cashPoolId, ok := queryOptions["cashPoolId"]; ok {
  79 + query = query.Where("cash_pool.id = ?", cashPoolId)
  80 + }
  81 + if err := query.First(); err != nil {
  82 + if err.Error() == "pg: no rows in result set" {
  83 + return nil, fmt.Errorf("没有此资源")
  84 + } else {
  85 + return nil, err
  86 + }
  87 + }
  88 + if cashPoolModel.Id == 0 {
  89 + return nil, nil
  90 + } else {
  91 + return repository.transformPgModelToDomainModel(cashPoolModel)
  92 + }
  93 +}
  94 +
74 func (repository *CashPoolRepository) transformPgModelToDomainModel(cashPoolModel *models.CashPool) (*domain.CashPool, error) { 95 func (repository *CashPoolRepository) transformPgModelToDomainModel(cashPoolModel *models.CashPool) (*domain.CashPool, error) {
75 return &domain.CashPool{ 96 return &domain.CashPool{
76 CashPoolId: cashPoolModel.Id, 97 CashPoolId: cashPoolModel.Id,
@@ -63,6 +63,9 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{ @@ -63,6 +63,9 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{
63 if uid, ok := queryOptions["uid"]; ok { 63 if uid, ok := queryOptions["uid"]; ok {
64 query = query.Where("employee.uid = ?", uid) 64 query = query.Where("employee.uid = ?", uid)
65 } 65 }
  66 + if account, ok := queryOptions["account"]; ok {
  67 + query = query.Where("employee.employee_account = ?", account)
  68 + }
66 if err := query.First(); err != nil { 69 if err := query.First(); err != nil {
67 if err.Error() == "pg: no rows in result set" { 70 if err.Error() == "pg: no rows in result set" {
68 return nil, fmt.Errorf("没有此员工") 71 return nil, fmt.Errorf("没有此员工")
@@ -73,10 +73,8 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri @@ -73,10 +73,8 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri
73 if uid, ok := queryOptions["uid"]; ok && (uid != int64(0)) { 73 if uid, ok := queryOptions["uid"]; ok && (uid != int64(0)) {
74 query = query.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid) 74 query = query.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid)
75 } 75 }
76 - // TODO 姓名模糊查询  
77 if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (employeeMatchName != "") { 76 if employeeMatchName, ok := queryOptions["employeeMatchName"]; ok && (employeeMatchName != "") {
78 - //query = query.Where(`su_money_transaction_record.employee @> 'employeeName' LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))  
79 - query = query.Where(`su_money_transaction_record.employee :json->> 'employeeName' LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string))) 77 + query = query.Where(`(su_money_transaction_record.employee->>'employeeName')::text LIKE ?`, fmt.Sprintf("%%%s%%", employeeMatchName.(string)))
80 } 78 }
81 if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) { 79 if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) {
82 query = query.Where(`su_money_transaction_record.record_type = ?`, recordType) 80 query = query.Where(`su_money_transaction_record.record_type = ?`, recordType)
@@ -102,7 +102,7 @@ func (controller *EmployeeController) ListEmployee() { @@ -102,7 +102,7 @@ func (controller *EmployeeController) ListEmployee() {
102 controller.ServeJSON() 102 controller.ServeJSON()
103 } 103 }
104 104
105 -// TODO 导出员工素币情况列表,选择导出(ids) 105 +// TODO 导出员工素币情况列表,选择导出(ids),增加导出失败信息
106 func (controller *EmployeeController) ExportSuMoney() { 106 func (controller *EmployeeController) ExportSuMoney() {
107 107
108 } 108 }
@@ -339,7 +339,7 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -339,7 +339,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
339 dataList := make([]interface{}, 0) 339 dataList := make([]interface{}, 0)
340 rows, _ := xlsx.GetRows("Sheet1") 340 rows, _ := xlsx.GetRows("Sheet1")
341 for i, row := range rows { 341 for i, row := range rows {
342 - if i > 0 { 342 + if i > 3 {
343 for _, _ = range row { 343 for _, _ = range row {
344 createExchangeCashPersonCommand.ExchangeCashActivityId = activityId 344 createExchangeCashPersonCommand.ExchangeCashActivityId = activityId
345 createExchangeCashPersonCommand.PersonName = row[0] 345 createExchangeCashPersonCommand.PersonName = row[0]
@@ -364,12 +364,12 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -364,12 +364,12 @@ func (controller *SuMoneyController) ImportExchangeList () {
364 controller.ServeJSON() 364 controller.ServeJSON()
365 } 365 }
366 366
367 -// TODO 导出素币兑换清单,选择导出(ids) 367 +// TODO 导出素币兑换清单,选择导出(ids),增加导出失败信息
368 func (controller *SuMoneyController) ExportExchangeList() { 368 func (controller *SuMoneyController) ExportExchangeList() {
369 369
370 } 370 }
371 371
372 -// TODO 导出素币流水记录,选择导出(ids) 372 +// TODO 导出素币流水记录,选择导出(ids),增加导出失败信息
373 func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() { 373 func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
374 374
375 } 375 }