作者 陈志颖

refactor:优化导入功能

@@ -548,3 +548,32 @@ @@ -548,3 +548,32 @@
548 BodyData: 548 BodyData:
549 2020/11/24 13:45:45.059 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/activity/exchange-list/import.1606196744625039000 BodyData:{"code":0,"data":{"fail":null,"successCount":1},"msg":"ok"} 549 2020/11/24 13:45:45.059 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/activity/exchange-list/import.1606196744625039000 BodyData:{"code":0,"data":{"fail":null,"successCount":1},"msg":"ok"}
550 2020/11/24 13:45:45.059 [D] [server.go:1925] | 127.0.0.1| 200 | 437.704111ms| match| POST  /cash-pool/activity/exchange-list/import r:/cash-pool/activity/exchange-list/import 550 2020/11/24 13:45:45.059 [D] [server.go:1925] | 127.0.0.1| 200 | 437.704111ms| match| POST  /cash-pool/activity/exchange-list/import r:/cash-pool/activity/exchange-list/import
  551 +2020/11/24 15:51:18.546 [I] [???:0] http server Running on http://:8082
  552 +2020/11/24 15:51:26.674 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606204286674056000
  553 + Auth=
  554 + BodyData:
  555 +2020/11/24 15:51:27.664 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/activity/exchange-list/import.1606204286674056000 BodyData:{"code":0,"data":{"fail":null,"successCount":1},"msg":"ok"}
  556 +2020/11/24 15:51:27.664 [D] [server.go:1925] | 127.0.0.1| 200 | 990.726762ms| match| POST  /cash-pool/activity/exchange-list/import r:/cash-pool/activity/exchange-list/import
  557 +2020/11/24 15:52:10.472 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606204330472439000
  558 + Auth=
  559 + BodyData:
  560 +2020/11/24 15:52:10.488 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/activity/exchange-list/import.1606204330472439000 BodyData:{"code":0,"data":{"fail":{"tableData":[["卞信华","18900000000","单元格包含空字符"]],"tableHeader":["员工姓名","手机号","已兑换素币","错误详情"]},"successCount":0},"msg":"ok"}
  561 +2020/11/24 15:52:10.488 [D] [server.go:1925] | 127.0.0.1| 200 | 16.812751ms| match| POST  /cash-pool/activity/exchange-list/import r:/cash-pool/activity/exchange-list/import
  562 +2020/11/24 15:56:05.844 [I] [???:0] http server Running on http://:8082
  563 +2020/11/24 15:57:07.287 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606204627287511000
  564 + Auth=
  565 + BodyData:
  566 +2020/11/24 15:57:07.586 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/activity/exchange-list/import.1606204627287511000 BodyData:{"code":0,"data":{"fail":null,"successCount":2},"msg":"ok"}
  567 +2020/11/24 15:57:07.586 [D] [server.go:1925] | 127.0.0.1| 200 | 301.568812ms| match| POST  /cash-pool/activity/exchange-list/import r:/cash-pool/activity/exchange-list/import
  568 +2020/11/24 16:00:00.327 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606204800327448000
  569 + Auth=
  570 + BodyData:
  571 +2020/11/24 16:04:40.206 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/activity/exchange-list/import.1606204800327448000 BodyData:{"code":0,"data":{"fail":null,"successCount":2},"msg":"ok"}
  572 +2020/11/24 16:04:40.206 [D] [server.go:1925] | 127.0.0.1| 200 |4m39.880470496s| match| POST  /cash-pool/activity/exchange-list/import r:/cash-pool/activity/exchange-list/import
  573 +2020/11/24 16:04:53.206 [I] [???:0] http server Running on http://:8082
  574 +2020/11/24 16:04:55.624 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606205095624342000
  575 + Auth=
  576 + BodyData:
  577 +2020/11/24 16:04:59.355 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/activity/exchange-list/import.1606205095624342000 BodyData:{"code":0,"data":{"fail":{"tableData":[["hello","13162672794",2,{"Code":501,"Message":"内部服务出错:没有此员工"}]],"tableHeader":["员工姓名","手机号","已兑换素币","错误详情"]},"successCount":1},"msg":"ok"}
  578 +2020/11/24 16:04:59.355 [D] [server.go:1925] | 127.0.0.1| 200 | 3.731193052s| match| POST  /cash-pool/activity/exchange-list/import r:/cash-pool/activity/exchange-list/import
  579 +2020/11/24 16:21:47.937 [I] [???:0] http server Running on http://:8082
@@ -154,20 +154,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -154,20 +154,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
154 } 154 }
155 } 155 }
156 156
157 - // 更新现金池  
158 - //newCashPool := &domain.CashPool{  
159 - // CashPoolId: cashPools[0].CashPoolId,  
160 - // CompanyId: createCashPoolCommand.CompanyId,  
161 - // Cash: createCashPoolCommand.Cash,  
162 - // ExchangedCash: cashPools[0].ExchangedCash,  
163 - // UnExchangeCash: cashPools[0].UnExchangeCash + (createCashPoolCommand.Cash - cashPools[0].Cash),  
164 - // ExchangedSuMoney: systemExchangedSuMoney,  
165 - // UnExchangeSuMoney: systemUnExchangeSuMoney,  
166 - // Rate: newRate,  
167 - // LastRate: lastActivityRate,  
168 - // CreateTime: time.Now().Local(),  
169 - //}  
170 -  
171 // 更新现金池命令 157 // 更新现金池命令
172 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 158 updateCashPoolCommand := &command.UpdateCashPoolCommand{
173 CashPoolId: cashPools[0].CashPoolId, 159 CashPoolId: cashPools[0].CashPoolId,
@@ -1288,17 +1274,31 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1288,17 +1274,31 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1288 } 1274 }
1289 1275
1290 // 导入新增兑换素币清单 1276 // 导入新增兑换素币清单
1291 -func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {  
1292 - if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {  
1293 - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1277 +func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommands []*command.CreateExchangeCashPersonCommand, failureDataList []interface{}) ([]interface{}, error) {
  1278 + // 批量校验
  1279 + for _, createExchangeCashPersonCommand := range createExchangeCashPersonCommands {
  1280 + if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
  1281 + row := []interface{}{
  1282 + createExchangeCashPersonCommand.PersonName,
  1283 + createExchangeCashPersonCommand.PersonAccount,
  1284 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1285 + err.Error(),
  1286 + }
  1287 + failureDataList = append(failureDataList, row)
  1288 + continue
  1289 + }
  1290 + }
  1291 +
  1292 + if len(failureDataList) > 0 {
  1293 + return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, "校验失败")
1294 } 1294 }
1295 1295
1296 transactionContext, err := factory.CreateTransactionContext(nil) 1296 transactionContext, err := factory.CreateTransactionContext(nil)
1297 if err != nil { 1297 if err != nil {
1298 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1298 + return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1299 } 1299 }
1300 if err := transactionContext.StartTransaction(); err != nil { 1300 if err := transactionContext.StartTransaction(); err != nil {
1301 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1301 + return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1302 } 1302 }
1303 defer func() { 1303 defer func() {
1304 transactionContext.RollbackTransaction() 1304 transactionContext.RollbackTransaction()
@@ -1309,7 +1309,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1309,7 +1309,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1309 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ 1309 if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
1310 "transactionContext": transactionContext, 1310 "transactionContext": transactionContext,
1311 }); err != nil { 1311 }); err != nil {
1312 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1312 + return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1313 } else { 1313 } else {
1314 exchangeCashActivityRepository = value 1314 exchangeCashActivityRepository = value
1315 } 1315 }
@@ -1319,7 +1319,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1319,7 +1319,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1319 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 1319 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
1320 "transactionContext": transactionContext, 1320 "transactionContext": transactionContext,
1321 }); err != nil { 1321 }); err != nil {
1322 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1322 + return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1323 } else { 1323 } else {
1324 exchangeCashPersonListRepository = value 1324 exchangeCashPersonListRepository = value
1325 } 1325 }
@@ -1329,7 +1329,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1329,7 +1329,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1329 if value, err := factory.CreateCashPoolRepository(map[string] interface{} { 1329 if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
1330 "transactionContext": transactionContext, 1330 "transactionContext": transactionContext,
1331 }); err != nil { 1331 }); err != nil {
1332 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1332 + return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1333 } else { 1333 } else {
1334 cashPoolRepository = value 1334 cashPoolRepository = value
1335 } 1335 }
@@ -1339,7 +1339,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1339,7 +1339,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1339 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 1339 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
1340 "transactionContext": transactionContext, 1340 "transactionContext": transactionContext,
1341 }); err != nil { 1341 }); err != nil {
1342 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1342 + return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1343 } else { 1343 } else {
1344 employeeRepository = value 1344 employeeRepository = value
1345 } 1345 }
@@ -1349,7 +1349,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1349,7 +1349,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1349 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 1349 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
1350 "transactionContext": transactionContext, 1350 "transactionContext": transactionContext,
1351 }); err != nil { 1351 }); err != nil {
1352 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1352 + return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1353 } else { 1353 } else {
1354 employeeDao = value 1354 employeeDao = value
1355 } 1355 }
@@ -1359,248 +1359,579 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1359,248 +1359,579 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1359 if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{ 1359 if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
1360 "transactionContext": transactionContext, 1360 "transactionContext": transactionContext,
1361 }); err != nil { 1361 }); err != nil {
1362 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1362 + return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1363 } else { 1363 } else {
1364 operationSuMoneyService = value 1364 operationSuMoneyService = value
1365 } 1365 }
1366 1366
1367 - // 获取当前兑换清单兑换活动  
1368 - activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})  
1369 - if err != nil {  
1370 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1371 - }  
1372 - if activityFound == nil {  
1373 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR,"当前未创建任务兑换活动")  
1374 - } 1367 + // 循环添加
  1368 + for _, createExchangeCashPersonCommand := range createExchangeCashPersonCommands {
  1369 + // 获取当前兑换清单兑换活动
  1370 + activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
  1371 + if err != nil {
  1372 + row := []interface{}{
  1373 + createExchangeCashPersonCommand.PersonName,
  1374 + createExchangeCashPersonCommand.PersonAccount,
  1375 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1376 + err.Error(),
  1377 + }
  1378 + failureDataList = append(failureDataList, row)
  1379 + continue
  1380 + }
  1381 + if activityFound == nil {
  1382 + row := []interface{}{
  1383 + createExchangeCashPersonCommand.PersonName,
  1384 + createExchangeCashPersonCommand.PersonAccount,
  1385 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1386 + "当前未创建任务兑换活动",
  1387 + }
  1388 + failureDataList = append(failureDataList, row)
  1389 + continue
  1390 + }
1375 1391
1376 - // 获取当前公司现金池  
1377 - _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{  
1378 - "companyId": activityFound.CompanyId,  
1379 - })  
1380 - if err != nil {  
1381 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1382 - }  
1383 - if len(cashPoolsFound) == 0 {  
1384 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")  
1385 - } 1392 + // 获取当前公司现金池
  1393 + _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
  1394 + "companyId": activityFound.CompanyId,
  1395 + })
  1396 + if err != nil {
  1397 + row := []interface{}{
  1398 + createExchangeCashPersonCommand.PersonName,
  1399 + createExchangeCashPersonCommand.PersonAccount,
  1400 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1401 + err.Error(),
  1402 + }
  1403 + failureDataList = append(failureDataList, row)
  1404 + continue
  1405 + }
  1406 + if len(cashPoolsFound) == 0 {
  1407 + row := []interface{}{
  1408 + createExchangeCashPersonCommand.PersonName,
  1409 + createExchangeCashPersonCommand.PersonAccount,
  1410 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1411 + "当前现金池为空,请先投入现金",
  1412 + }
  1413 + failureDataList = append(failureDataList, row)
  1414 + continue
  1415 + }
1386 1416
1387 - // 获取员工查询条件  
1388 - getEmployee := map[string]interface{}{  
1389 - "account": createExchangeCashPersonCommand.PersonAccount,  
1390 - "companyId": activityFound.CompanyId,  
1391 - "status": 1,  
1392 - } 1417 + // 获取员工查询条件
  1418 + getEmployee := map[string]interface{}{
  1419 + "account": createExchangeCashPersonCommand.PersonAccount,
  1420 + "companyId": activityFound.CompanyId,
  1421 + }
1393 1422
1394 - // 判断当前员工是否有效  
1395 - employeeFound, err := employeeRepository.FindOne(getEmployee)  
1396 - if err != nil {  
1397 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1398 - }  
1399 - if employeeFound == nil {  
1400 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")  
1401 - } 1423 + // 判断当前员工是否有效
  1424 + employeeFound, err := employeeRepository.FindOne(getEmployee)
  1425 + if err != nil {
  1426 + row := []interface{}{
  1427 + createExchangeCashPersonCommand.PersonName,
  1428 + createExchangeCashPersonCommand.PersonAccount,
  1429 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1430 + err.Error(),
  1431 + }
  1432 + failureDataList = append(failureDataList, row)
  1433 + continue
  1434 + }
  1435 + if employeeFound == nil {
  1436 + row := []interface{}{
  1437 + createExchangeCashPersonCommand.PersonName,
  1438 + createExchangeCashPersonCommand.PersonAccount,
  1439 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1440 + "无效的导入员工",
  1441 + }
  1442 + failureDataList = append(failureDataList, row)
  1443 + continue
  1444 + }
1402 1445
1403 - // 判断当前员工是否已经在素币兑换清单中  
1404 - _, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{  
1405 - "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,  
1406 - "exchangeCashActivityId": activityFound.ActivityId,  
1407 - "offset": 0,  
1408 - "limit": 1,  
1409 - })  
1410 - if err != nil {  
1411 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1412 - } 1446 + // 判断当前员工是否已经在素币兑换清单中
  1447 + _, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
  1448 + "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
  1449 + "exchangeCashActivityId": activityFound.ActivityId,
  1450 + "offset": 0,
  1451 + "limit": 1,
  1452 + })
  1453 + if err != nil {
  1454 + row := []interface{}{
  1455 + createExchangeCashPersonCommand.PersonName,
  1456 + createExchangeCashPersonCommand.PersonAccount,
  1457 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1458 + err.Error(),
  1459 + }
  1460 + failureDataList = append(failureDataList, row)
  1461 + continue
  1462 + }
1413 1463
1414 - // 判断该员工兑换的素币是否超过本人持有的素币  
1415 - if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {  
1416 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")  
1417 - } 1464 + // 判断该员工兑换的素币是否超过本人持有的素币
  1465 + if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
  1466 + row := []interface{}{
  1467 + createExchangeCashPersonCommand.PersonName,
  1468 + createExchangeCashPersonCommand.PersonAccount,
  1469 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1470 + "当前兑换素币超过本人持有的素币值",
  1471 + }
  1472 + failureDataList = append(failureDataList, row)
  1473 + continue
  1474 + }
1418 1475
1419 - if len(peopleFound) > 0 { // 当前导入员工在素币兑换清单中,判断追加素币兑换或撤回素币兑换  
1420 - // 获取当前员工已兑换素币  
1421 - personFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney 1476 + if len(peopleFound) > 0 { // 当前导入员工在素币兑换清单中,判断追加素币兑换或撤回素币兑换
  1477 + // 获取当前员工已兑换素币
  1478 + personFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney
1422 1479
1423 - // 获取当前兑换员工已兑换现金  
1424 - //personFoundExchangedCash := peopleFound[0].ExchangedCash 1480 + // 获取当前兑换员工已兑换现金
  1481 + //personFoundExchangedCash := peopleFound[0].ExchangedCash
1425 1482
1426 - if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于本人已兑换素币,撤回兑换素币  
1427 - // 素币减量  
1428 - suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney 1483 + if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于本人已兑换素币,撤回兑换素币
  1484 + // 素币减量
  1485 + suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney
1429 1486
1430 - // 现金减量  
1431 - cashDecrement := suMoneyDecrement * activityFound.Rate 1487 + // 现金减量
  1488 + cashDecrement := suMoneyDecrement * activityFound.Rate
1432 1489
1433 - // 更新兑换素币清单命令  
1434 - updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{  
1435 - ListId: peopleFound[0].ListId,  
1436 - ExchangedSuMoney: personFoundExchangedSuMoney - suMoneyDecrement,  
1437 - ExchangedCash: (personFoundExchangedSuMoney - suMoneyDecrement) * activityFound.Rate,  
1438 - Operator: createExchangeCashPersonCommand.Operator,  
1439 - } 1490 + // 更新兑换素币清单命令
  1491 + updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{
  1492 + ListId: peopleFound[0].ListId,
  1493 + ExchangedSuMoney: personFoundExchangedSuMoney - suMoneyDecrement,
  1494 + ExchangedCash: (personFoundExchangedSuMoney - suMoneyDecrement) * activityFound.Rate,
  1495 + Operator: createExchangeCashPersonCommand.Operator,
  1496 + }
1440 1497
1441 - // 更新兑换素币清单  
1442 - if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {  
1443 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
1444 - } 1498 + // 更新兑换素币清单
  1499 + if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
  1500 + row := []interface{}{
  1501 + createExchangeCashPersonCommand.PersonName,
  1502 + createExchangeCashPersonCommand.PersonAccount,
  1503 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1504 + err.Error(),
  1505 + }
  1506 + failureDataList = append(failureDataList, row)
  1507 + continue
  1508 + }
1445 1509
1446 - // 保存兑换素币清单更新  
1447 - personUpdated, err := exchangeCashPersonListRepository.Save(peopleFound[0])  
1448 - if err != nil {  
1449 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1450 - } 1510 + // 保存兑换素币清单更新
  1511 + personUpdated, err := exchangeCashPersonListRepository.Save(peopleFound[0])
  1512 + if err != nil {
  1513 + row := []interface{}{
  1514 + createExchangeCashPersonCommand.PersonName,
  1515 + createExchangeCashPersonCommand.PersonAccount,
  1516 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1517 + err.Error(),
  1518 + }
  1519 + failureDataList = append(failureDataList, row)
  1520 + continue
  1521 + }
1451 1522
1452 - // 更新素币兑换活动命令  
1453 - updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{  
1454 - ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId,  
1455 - ExchangedSuMoney: activityFound.ExchangedSuMoney - suMoneyDecrement,  
1456 - ExchangedCash: activityFound.ExchangedCash - cashDecrement,  
1457 - Deadline: activityFound.Deadline,  
1458 - CountDown: activityFound.CountDown,  
1459 - ExchangeRate: activityFound.Rate,  
1460 - } 1523 + // 更新素币兑换活动命令
  1524 + updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
  1525 + ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId,
  1526 + ExchangedSuMoney: activityFound.ExchangedSuMoney - suMoneyDecrement,
  1527 + ExchangedCash: activityFound.ExchangedCash - cashDecrement,
  1528 + Deadline: activityFound.Deadline,
  1529 + CountDown: activityFound.CountDown,
  1530 + ExchangeRate: activityFound.Rate,
  1531 + }
1461 1532
1462 - // 更新兑换活动  
1463 - if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {  
1464 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
1465 - } 1533 + // 更新兑换活动
  1534 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
  1535 + row := []interface{}{
  1536 + createExchangeCashPersonCommand.PersonName,
  1537 + createExchangeCashPersonCommand.PersonAccount,
  1538 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1539 + err.Error(),
  1540 + }
  1541 + failureDataList = append(failureDataList, row)
  1542 + continue
  1543 + }
1466 1544
1467 - // 保存兑换现金活动更新  
1468 - activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)  
1469 - if err != nil {  
1470 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1471 - }  
1472 - if activityUpdated == nil {  
1473 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))  
1474 - } 1545 + // 保存兑换现金活动更新
  1546 + activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
  1547 + if err != nil {
  1548 + row := []interface{}{
  1549 + createExchangeCashPersonCommand.PersonName,
  1550 + createExchangeCashPersonCommand.PersonAccount,
  1551 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1552 + err.Error(),
  1553 + }
  1554 + failureDataList = append(failureDataList, row)
  1555 + continue
  1556 + }
  1557 + if activityUpdated == nil {
  1558 + row := []interface{}{
  1559 + createExchangeCashPersonCommand.PersonName,
  1560 + createExchangeCashPersonCommand.PersonAccount,
  1561 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1562 + "兑换现金活动保存失败",
  1563 + }
  1564 + failureDataList = append(failureDataList, row)
  1565 + continue
  1566 + }
1475 1567
1476 - // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励 1568 + // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
1477 1569
1478 - // 个人素币操作命令  
1479 - operationSuMoneyCommand := &command.OperationSuMoneyCommand{  
1480 - Uid: employeeFound.EmployeeInfo.Uid,  
1481 - Operator: createExchangeCashPersonCommand.Operator,  
1482 - SuMoney: suMoneyDecrement,  
1483 - OperationType: 41,  
1484 - OperationDescription: activityFound.ExchangeActivityName + "调整",  
1485 - } 1570 + // 个人素币操作命令
  1571 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
  1572 + Uid: employeeFound.EmployeeInfo.Uid,
  1573 + Operator: createExchangeCashPersonCommand.Operator,
  1574 + SuMoney: suMoneyDecrement,
  1575 + OperationType: 41,
  1576 + OperationDescription: activityFound.ExchangeActivityName + "调整",
  1577 + }
1486 1578
1487 - // 操作个人素币,生成素币流水记录  
1488 - task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)  
1489 - if err != nil {  
1490 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1491 - }  
1492 - if task == nil {  
1493 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))  
1494 - } 1579 + // 操作个人素币,生成素币流水记录
  1580 + task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
  1581 + if err != nil {
  1582 + row := []interface{}{
  1583 + createExchangeCashPersonCommand.PersonName,
  1584 + createExchangeCashPersonCommand.PersonAccount,
  1585 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1586 + "操作个人素币失败",
  1587 + }
  1588 + failureDataList = append(failureDataList, row)
  1589 + continue
  1590 + }
  1591 + if task == nil {
  1592 + row := []interface{}{
  1593 + createExchangeCashPersonCommand.PersonName,
  1594 + createExchangeCashPersonCommand.PersonAccount,
  1595 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1596 + "操作个人素币失败",
  1597 + }
  1598 + failureDataList = append(failureDataList, row)
  1599 + continue
  1600 + }
1495 1601
1496 - // 判断兑换活动的现金是否超过现金池未兑换现金  
1497 - if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {  
1498 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")  
1499 - } 1602 + // 判断兑换活动的现金是否超过现金池未兑换现金
  1603 + if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
  1604 + row := []interface{}{
  1605 + createExchangeCashPersonCommand.PersonName,
  1606 + createExchangeCashPersonCommand.PersonAccount,
  1607 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1608 + "已超过现金池未兑换现金",
  1609 + }
  1610 + failureDataList = append(failureDataList, row)
  1611 + continue
  1612 + }
1500 1613
1501 - // 获取平台素币兑换情况  
1502 - systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)  
1503 - if err != nil {  
1504 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1505 - }  
1506 - if systemSuMoneyStatistics == nil {  
1507 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")  
1508 - }  
1509 - systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)  
1510 - systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 1614 + // 获取平台素币兑换情况
  1615 + systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
  1616 + if err != nil {
  1617 + row := []interface{}{
  1618 + createExchangeCashPersonCommand.PersonName,
  1619 + createExchangeCashPersonCommand.PersonAccount,
  1620 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1621 + err.Error(),
  1622 + }
  1623 + failureDataList = append(failureDataList, row)
  1624 + continue
  1625 + }
  1626 + if systemSuMoneyStatistics == nil {
  1627 + row := []interface{}{
  1628 + createExchangeCashPersonCommand.PersonName,
  1629 + createExchangeCashPersonCommand.PersonAccount,
  1630 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1631 + "无效的公司",
  1632 + }
  1633 + failureDataList = append(failureDataList, row)
  1634 + continue
  1635 + }
  1636 + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
  1637 + systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
  1638 +
  1639 + // 计算平均兑换汇率
  1640 + var newRate float64
  1641 + if systemExchangedSuMoney == 0 {
  1642 + newRate = 0
  1643 + } else {
  1644 + newRate = (cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney
  1645 + }
1511 1646
1512 - // 计算平均兑换汇率  
1513 - var newRate float64  
1514 - if systemExchangedSuMoney == 0 {  
1515 - newRate = 0  
1516 - } else {  
1517 - newRate = (cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney  
1518 - } 1647 + // 更新现金池命令
  1648 + updateCashPoolCommand := &command.UpdateCashPoolCommand{
  1649 + CashPoolId: cashPoolsFound[0].CashPoolId,
  1650 + Cash: cashPoolsFound[0].Cash,
  1651 + ExchangedCash: cashPoolsFound[0].ExchangedCash - cashDecrement,
  1652 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash + cashDecrement,
  1653 + ExchangedSuMoney: systemExchangedSuMoney,
  1654 + UnExchangeSuMoney: systemUnExchangeSuMoney,
  1655 + Rate: newRate,
  1656 + LastRate: cashPoolsFound[0].LastRate,
  1657 + }
1519 1658
1520 - // 更新现金池命令  
1521 - updateCashPoolCommand := &command.UpdateCashPoolCommand{  
1522 - CashPoolId: cashPoolsFound[0].CashPoolId,  
1523 - Cash: cashPoolsFound[0].Cash,  
1524 - ExchangedCash: cashPoolsFound[0].ExchangedCash - cashDecrement,  
1525 - UnExchangeCash: cashPoolsFound[0].UnExchangeCash + cashDecrement,  
1526 - ExchangedSuMoney: systemExchangedSuMoney,  
1527 - UnExchangeSuMoney: systemUnExchangeSuMoney,  
1528 - Rate: newRate,  
1529 - LastRate: cashPoolsFound[0].LastRate,  
1530 - } 1659 + // 更新现金池
  1660 + if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
  1661 + row := []interface{}{
  1662 + createExchangeCashPersonCommand.PersonName,
  1663 + createExchangeCashPersonCommand.PersonAccount,
  1664 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1665 + err.Error(),
  1666 + }
  1667 + failureDataList = append(failureDataList, row)
  1668 + continue
  1669 + }
1531 1670
1532 - // 更新现金池  
1533 - if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {  
1534 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
1535 - } 1671 + // 保存现金池更新
  1672 + cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
  1673 + if err != nil {
  1674 + row := []interface{}{
  1675 + createExchangeCashPersonCommand.PersonName,
  1676 + createExchangeCashPersonCommand.PersonAccount,
  1677 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1678 + "内部业务错误" + err.Error(),
  1679 + }
  1680 + failureDataList = append(failureDataList, row)
  1681 + continue
  1682 + }
  1683 + if cashPoolUpdated == nil {
  1684 + row := []interface{}{
  1685 + createExchangeCashPersonCommand.PersonName,
  1686 + createExchangeCashPersonCommand.PersonAccount,
  1687 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1688 + "内部业务错误" + err.Error(),
  1689 + }
  1690 + failureDataList = append(failureDataList, row)
  1691 + continue
  1692 + }
  1693 + } else { // 当前兑换素币大于等于已兑换素币,追加兑换素币
  1694 + // 素币增量
  1695 + suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney
  1696 +
  1697 + // 现金增量
  1698 + cashIncrement := suMoneyIncrement * activityFound.Rate
  1699 +
  1700 + // 更新兑换素币清单命令
  1701 + updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{
  1702 + ListId: peopleFound[0].ListId,
  1703 + ExchangedSuMoney: personFoundExchangedSuMoney + suMoneyIncrement,
  1704 + ExchangedCash: (personFoundExchangedSuMoney + suMoneyIncrement) * activityFound.Rate,
  1705 + Operator: createExchangeCashPersonCommand.Operator,
  1706 + }
1536 1707
1537 - // 保存现金池更新  
1538 - cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])  
1539 - if err != nil {  
1540 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1541 - }  
1542 - if cashPoolUpdated == nil {  
1543 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1544 - } 1708 + // 更新兑换素币清单
  1709 + if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
  1710 + row := []interface{}{
  1711 + createExchangeCashPersonCommand.PersonName,
  1712 + createExchangeCashPersonCommand.PersonAccount,
  1713 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1714 + "内部业务错误" + err.Error(),
  1715 + }
  1716 + failureDataList = append(failureDataList, row)
  1717 + continue
  1718 + }
1545 1719
1546 - if err := transactionContext.CommitTransaction(); err != nil {  
1547 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
1548 - }  
1549 - return personUpdated, nil  
1550 - } else if createExchangeCashPersonCommand.ExchangedSuMoney > personFoundExchangedSuMoney { // 当前兑换素币大于已兑换素币,追加兑换素币  
1551 - // 素币增量  
1552 - suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney  
1553 -  
1554 - // 现金增量  
1555 - cashIncrement := suMoneyIncrement * activityFound.Rate  
1556 -  
1557 - // 更新兑换素币清单命令  
1558 - updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{  
1559 - ListId: peopleFound[0].ListId,  
1560 - ExchangedSuMoney: personFoundExchangedSuMoney + suMoneyIncrement,  
1561 - ExchangedCash: (personFoundExchangedSuMoney + suMoneyIncrement) * activityFound.Rate,  
1562 - Operator: createExchangeCashPersonCommand.Operator,  
1563 - } 1720 + // 保存兑换素币清单更新
  1721 + personUpdated, err := exchangeCashPersonListRepository.Save(peopleFound[0])
  1722 + if err != nil {
  1723 + row := []interface{}{
  1724 + createExchangeCashPersonCommand.PersonName,
  1725 + createExchangeCashPersonCommand.PersonAccount,
  1726 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1727 + "内部业务错误" + err.Error(),
  1728 + }
  1729 + failureDataList = append(failureDataList, row)
  1730 + continue
  1731 + }
1564 1732
1565 - // 更新兑换素币清单  
1566 - if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {  
1567 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
1568 - } 1733 + // 更新素币兑换活动命令
  1734 + updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
  1735 + ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId,
  1736 + ExchangedSuMoney: activityFound.ExchangedSuMoney + suMoneyIncrement,
  1737 + ExchangedCash: activityFound.ExchangedCash + cashIncrement,
  1738 + Deadline: activityFound.Deadline,
  1739 + CountDown: activityFound.CountDown,
  1740 + ExchangeRate: activityFound.Rate,
  1741 + }
1569 1742
1570 - // 保存兑换素币清单更新  
1571 - personUpdated, err := exchangeCashPersonListRepository.Save(peopleFound[0])  
1572 - if err != nil {  
1573 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1574 - } 1743 + // 更新兑换活动
  1744 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
  1745 + row := []interface{}{
  1746 + createExchangeCashPersonCommand.PersonName,
  1747 + createExchangeCashPersonCommand.PersonAccount,
  1748 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1749 + "内部业务错误" + err.Error(),
  1750 + }
  1751 + failureDataList = append(failureDataList, row)
  1752 + continue
  1753 + }
1575 1754
1576 - // 更新素币兑换活动命令  
1577 - updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{  
1578 - ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId,  
1579 - ExchangedSuMoney: activityFound.ExchangedSuMoney + suMoneyIncrement,  
1580 - ExchangedCash: activityFound.ExchangedCash + cashIncrement,  
1581 - Deadline: activityFound.Deadline,  
1582 - CountDown: activityFound.CountDown,  
1583 - ExchangeRate: activityFound.Rate,  
1584 - } 1755 + // 保存兑换现金活动更新
  1756 + activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
  1757 + if err != nil {
  1758 + row := []interface{}{
  1759 + createExchangeCashPersonCommand.PersonName,
  1760 + createExchangeCashPersonCommand.PersonAccount,
  1761 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1762 + "内部业务错误" + err.Error(),
  1763 + }
  1764 + failureDataList = append(failureDataList, row)
  1765 + continue
  1766 + }
  1767 + if activityUpdated == nil {
  1768 + row := []interface{}{
  1769 + createExchangeCashPersonCommand.PersonName,
  1770 + createExchangeCashPersonCommand.PersonAccount,
  1771 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1772 + "内部业务错误",
  1773 + }
  1774 + failureDataList = append(failureDataList, row)
  1775 + continue
  1776 + }
1585 1777
1586 - // 更新兑换活动  
1587 - if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {  
1588 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 1778 + // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
  1779 +
  1780 + // 操作素币命令
  1781 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
  1782 + Uid: employeeFound.EmployeeInfo.Uid,
  1783 + Operator: createExchangeCashPersonCommand.Operator,
  1784 + SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
  1785 + OperationType: 4,
  1786 + OperationDescription: "参与" + activityFound.ExchangeActivityName,
  1787 + }
  1788 +
  1789 + // 操作素币,生成素币流水
  1790 + task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
  1791 + if err != nil {
  1792 + row := []interface{}{
  1793 + createExchangeCashPersonCommand.PersonName,
  1794 + createExchangeCashPersonCommand.PersonAccount,
  1795 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1796 + "内部业务错误" + err.Error(),
  1797 + }
  1798 + failureDataList = append(failureDataList, row)
  1799 + continue
  1800 + }
  1801 + if task == nil {
  1802 + row := []interface{}{
  1803 + createExchangeCashPersonCommand.PersonName,
  1804 + createExchangeCashPersonCommand.PersonAccount,
  1805 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1806 + "内部业务错误",
  1807 + }
  1808 + failureDataList = append(failureDataList, row)
  1809 + continue
  1810 + }
  1811 +
  1812 + // 判断兑换活动的现金是否超过现金池未兑换现金
  1813 + if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
  1814 + row := []interface{}{
  1815 + createExchangeCashPersonCommand.PersonName,
  1816 + createExchangeCashPersonCommand.PersonAccount,
  1817 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1818 + "已超过现金池未兑换现金",
  1819 + }
  1820 + failureDataList = append(failureDataList, row)
  1821 + continue
  1822 + }
  1823 +
  1824 + // 获取平台素币兑换情况
  1825 + systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
  1826 + if err != nil {
  1827 + row := []interface{}{
  1828 + createExchangeCashPersonCommand.PersonName,
  1829 + createExchangeCashPersonCommand.PersonAccount,
  1830 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1831 + "内部业务错误" + err.Error(),
  1832 + }
  1833 + failureDataList = append(failureDataList, row)
  1834 + continue
  1835 + }
  1836 + if systemSuMoneyStatistics == nil {
  1837 + row := []interface{}{
  1838 + createExchangeCashPersonCommand.PersonName,
  1839 + createExchangeCashPersonCommand.PersonAccount,
  1840 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1841 + "无效的公司员工",
  1842 + }
  1843 + failureDataList = append(failureDataList, row)
  1844 + continue
  1845 + }
  1846 + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
  1847 + systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
  1848 +
  1849 + // 计算平均兑换汇率
  1850 + var newRate float64
  1851 + if systemExchangedSuMoney == 0 {
  1852 + newRate = 0
  1853 + } else {
  1854 + newRate = (cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney
  1855 + }
  1856 +
  1857 + // 更新现金池命令
  1858 + updateCashPoolCommand := &command.UpdateCashPoolCommand{
  1859 + CashPoolId: cashPoolsFound[0].CashPoolId,
  1860 + Cash: cashPoolsFound[0].Cash,
  1861 + ExchangedCash: cashPoolsFound[0].ExchangedCash + cashIncrement,
  1862 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash - cashIncrement,
  1863 + ExchangedSuMoney: systemExchangedSuMoney,
  1864 + UnExchangeSuMoney: systemUnExchangeSuMoney,
  1865 + Rate: newRate,
  1866 + LastRate: cashPoolsFound[0].LastRate,
  1867 + }
  1868 +
  1869 + // 更新现金池
  1870 + if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
  1871 + row := []interface{}{
  1872 + createExchangeCashPersonCommand.PersonName,
  1873 + createExchangeCashPersonCommand.PersonAccount,
  1874 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1875 + "内部业务错误" + err.Error(),
  1876 + }
  1877 + failureDataList = append(failureDataList, row)
  1878 + continue
  1879 + }
  1880 +
  1881 + // 保存现金池更新
  1882 + cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
  1883 + if err != nil {
  1884 + row := []interface{}{
  1885 + createExchangeCashPersonCommand.PersonName,
  1886 + createExchangeCashPersonCommand.PersonAccount,
  1887 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1888 + "内务业务错误" + err.Error(),
  1889 + }
  1890 + failureDataList = append(failureDataList, row)
  1891 + continue
  1892 + }
  1893 + if cashPoolUpdated == nil {
  1894 + row := []interface{}{
  1895 + createExchangeCashPersonCommand.PersonName,
  1896 + createExchangeCashPersonCommand.PersonAccount,
  1897 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1898 + "内部业务错误" + err.Error(),
  1899 + }
  1900 + failureDataList = append(failureDataList, row)
  1901 + continue
  1902 + }
  1903 + }
  1904 + } else if len(peopleFound) == 0 { // 导入兑换素币清单员工不存在兑换素币清单中,新增兑换素币清单
  1905 + // 新增兑换素币清单命令
  1906 + newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
  1907 + newPerson := &domain.ExchangeCashPersonList{
  1908 + EmployeeInfo: &domain.EmployeeInfo{
  1909 + Uid: employeeFound.EmployeeInfo.Uid,
  1910 + EmployeeName: employeeFound.EmployeeInfo.EmployeeName,
  1911 + EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,
  1912 + },
  1913 + ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
  1914 + ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
  1915 + ExchangedCash: newPersonExchangedCash,
1589 } 1916 }
1590 1917
1591 - // 保存兑换现金活动更新  
1592 - activityUpdated, err := exchangeCashActivityRepository.Save(activityFound) 1918 + // 保存兑换素币清单
  1919 + personSaved, err := exchangeCashPersonListRepository.Save(newPerson)
1593 if err != nil { 1920 if err != nil {
1594 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1595 - }  
1596 - if activityUpdated == nil {  
1597 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId))) 1921 + row := []interface{}{
  1922 + createExchangeCashPersonCommand.PersonName,
  1923 + createExchangeCashPersonCommand.PersonAccount,
  1924 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1925 + "内务业务错误" + err.Error(),
  1926 + }
  1927 + failureDataList = append(failureDataList, row)
  1928 + continue
1598 } 1929 }
1599 1930
1600 // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励 1931 // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
1601 1932
1602 // 操作素币命令 1933 // 操作素币命令
1603 - operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 1934 + operationSuMoneyCommand := &command.OperationSuMoneyCommand{
1604 Uid: employeeFound.EmployeeInfo.Uid, 1935 Uid: employeeFound.EmployeeInfo.Uid,
1605 Operator: createExchangeCashPersonCommand.Operator, 1936 Operator: createExchangeCashPersonCommand.Operator,
1606 SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney, 1937 SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
@@ -1611,42 +1942,123 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1611,42 +1942,123 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1611 // 操作素币,生成素币流水 1942 // 操作素币,生成素币流水
1612 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription) 1943 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
1613 if err != nil { 1944 if err != nil {
1614 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1945 + row := []interface{}{
  1946 + createExchangeCashPersonCommand.PersonName,
  1947 + createExchangeCashPersonCommand.PersonAccount,
  1948 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1949 + "内部业务错误" + err.Error(),
  1950 + }
  1951 + failureDataList = append(failureDataList, row)
  1952 + continue
1615 } 1953 }
1616 if task == nil { 1954 if task == nil {
1617 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) 1955 + row := []interface{}{
  1956 + createExchangeCashPersonCommand.PersonName,
  1957 + createExchangeCashPersonCommand.PersonAccount,
  1958 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1959 + "内部业务错误",
  1960 + }
  1961 + failureDataList = append(failureDataList, row)
  1962 + continue
  1963 + }
  1964 +
  1965 + // 更新兑换活动命令
  1966 + updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
  1967 + ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
  1968 + ExchangeActivityName: activityFound.ExchangeActivityName,
  1969 + ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
  1970 + ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
  1971 + Deadline: activityFound.Deadline,
  1972 + CountDown: activityFound.CountDown,
  1973 + ExchangeRate: activityFound.Rate,
  1974 + }
  1975 +
  1976 + // 更新兑换活动
  1977 + if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
  1978 + row := []interface{}{
  1979 + createExchangeCashPersonCommand.PersonName,
  1980 + createExchangeCashPersonCommand.PersonAccount,
  1981 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1982 + "当前兑换素币超过本人持有的素币值",
  1983 + }
  1984 + failureDataList = append(failureDataList, row)
  1985 + continue
  1986 + }
  1987 +
  1988 + // 保存兑换现金活动更新
  1989 + activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
  1990 + if err != nil {
  1991 + row := []interface{}{
  1992 + createExchangeCashPersonCommand.PersonName,
  1993 + createExchangeCashPersonCommand.PersonAccount,
  1994 + createExchangeCashPersonCommand.ExchangedSuMoney,
  1995 + "内部业务错误" + err.Error(),
  1996 + }
  1997 + failureDataList = append(failureDataList, row)
  1998 + continue
  1999 + }
  2000 + if activityUpdated == nil {
  2001 + row := []interface{}{
  2002 + createExchangeCashPersonCommand.PersonName,
  2003 + createExchangeCashPersonCommand.PersonAccount,
  2004 + createExchangeCashPersonCommand.ExchangedSuMoney,
  2005 + "内部业务错误",
  2006 + }
  2007 + failureDataList = append(failureDataList, row)
  2008 + continue
1618 } 2009 }
1619 2010
1620 // 判断兑换活动的现金是否超过现金池未兑换现金 2011 // 判断兑换活动的现金是否超过现金池未兑换现金
1621 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash { 2012 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
1622 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金") 2013 + row := []interface{}{
  2014 + createExchangeCashPersonCommand.PersonName,
  2015 + createExchangeCashPersonCommand.PersonAccount,
  2016 + createExchangeCashPersonCommand.ExchangedSuMoney,
  2017 + "已超过现金池未兑换现金",
  2018 + }
  2019 + failureDataList = append(failureDataList, row)
  2020 + continue
1623 } 2021 }
1624 2022
1625 // 获取平台素币兑换情况 2023 // 获取平台素币兑换情况
1626 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId) 2024 systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
1627 if err != nil { 2025 if err != nil {
1628 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 2026 + row := []interface{}{
  2027 + createExchangeCashPersonCommand.PersonName,
  2028 + createExchangeCashPersonCommand.PersonAccount,
  2029 + createExchangeCashPersonCommand.ExchangedSuMoney,
  2030 + "内部业务错误" + err.Error(),
  2031 + }
  2032 + failureDataList = append(failureDataList, row)
  2033 + continue
1629 } 2034 }
1630 if systemSuMoneyStatistics == nil { 2035 if systemSuMoneyStatistics == nil {
1631 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 2036 + row := []interface{}{
  2037 + createExchangeCashPersonCommand.PersonName,
  2038 + createExchangeCashPersonCommand.PersonAccount,
  2039 + createExchangeCashPersonCommand.ExchangedSuMoney,
  2040 + "无效的公司员工",
  2041 + }
  2042 + failureDataList = append(failureDataList, row)
  2043 + continue
1632 } 2044 }
1633 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 2045 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
1634 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 2046 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
1635 2047
1636 - // 计算平均兑换汇率 2048 + // 重新计算现金池平均兑换汇率
1637 var newRate float64 2049 var newRate float64
1638 if systemExchangedSuMoney == 0 { 2050 if systemExchangedSuMoney == 0 {
1639 newRate = 0 2051 newRate = 0
1640 } else { 2052 } else {
1641 - newRate = (cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney 2053 + newRate = (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
1642 } 2054 }
1643 2055
1644 // 更新现金池命令 2056 // 更新现金池命令
1645 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 2057 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1646 CashPoolId: cashPoolsFound[0].CashPoolId, 2058 CashPoolId: cashPoolsFound[0].CashPoolId,
1647 Cash: cashPoolsFound[0].Cash, 2059 Cash: cashPoolsFound[0].Cash,
1648 - ExchangedCash: cashPoolsFound[0].ExchangedCash + cashIncrement,  
1649 - UnExchangeCash: cashPoolsFound[0].UnExchangeCash - cashIncrement, 2060 + ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
  2061 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
1650 ExchangedSuMoney: systemExchangedSuMoney, 2062 ExchangedSuMoney: systemExchangedSuMoney,
1651 UnExchangeSuMoney: systemUnExchangeSuMoney, 2063 UnExchangeSuMoney: systemUnExchangeSuMoney,
1652 Rate: newRate, 2064 Rate: newRate,
@@ -1655,153 +2067,57 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1655,153 +2067,57 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1655 2067
1656 // 更新现金池 2068 // 更新现金池
1657 if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { 2069 if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
1658 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 2070 + row := []interface{}{
  2071 + createExchangeCashPersonCommand.PersonName,
  2072 + createExchangeCashPersonCommand.PersonAccount,
  2073 + createExchangeCashPersonCommand.ExchangedSuMoney,
  2074 + "内部业务错误" + err.Error(),
  2075 + }
  2076 + failureDataList = append(failureDataList, row)
  2077 + continue
1659 } 2078 }
1660 2079
1661 // 保存现金池更新 2080 // 保存现金池更新
1662 cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0]) 2081 cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
1663 if err != nil { 2082 if err != nil {
1664 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 2083 + row := []interface{}{
  2084 + createExchangeCashPersonCommand.PersonName,
  2085 + createExchangeCashPersonCommand.PersonAccount,
  2086 + createExchangeCashPersonCommand.ExchangedSuMoney,
  2087 + "内部业务错误" + err.Error(),
  2088 + }
  2089 + failureDataList = append(failureDataList, row)
  2090 + continue
1665 } 2091 }
1666 if cashPoolUpdated == nil { 2092 if cashPoolUpdated == nil {
1667 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1668 - }  
1669 -  
1670 - if err := transactionContext.CommitTransaction(); err != nil {  
1671 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 2093 + row := []interface{}{
  2094 + createExchangeCashPersonCommand.PersonName,
  2095 + createExchangeCashPersonCommand.PersonAccount,
  2096 + createExchangeCashPersonCommand.ExchangedSuMoney,
  2097 + "内部业务错误" + err.Error(),
  2098 + }
  2099 + failureDataList = append(failureDataList, row)
  2100 + continue
1672 } 2101 }
1673 - return personUpdated, nil  
1674 - } else { // 当前导入兑换素币清单素币等于本人已兑换素币  
1675 - if err := transactionContext.CommitTransaction(); err != nil {  
1676 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 2102 + } else { // 未知情况
  2103 + row := []interface{}{
  2104 + createExchangeCashPersonCommand.PersonName,
  2105 + createExchangeCashPersonCommand.PersonAccount,
  2106 + createExchangeCashPersonCommand.ExchangedSuMoney,
  2107 + "未知错误",
1677 } 2108 }
1678 - return nil, nil  
1679 - }  
1680 - } else if len(peopleFound) == 0 { // 导入兑换素币清单员工不存在兑换素币清单中,新增兑换素币清单  
1681 - // 新增兑换素币清单命令  
1682 - newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)  
1683 - newPerson := &domain.ExchangeCashPersonList{  
1684 - EmployeeInfo: &domain.EmployeeInfo{  
1685 - Uid: employeeFound.EmployeeInfo.Uid,  
1686 - EmployeeName: employeeFound.EmployeeInfo.EmployeeName,  
1687 - EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,  
1688 - },  
1689 - ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,  
1690 - ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,  
1691 - ExchangedCash: newPersonExchangedCash,  
1692 - }  
1693 -  
1694 - // 保存兑换素币清单  
1695 - personSaved, err := exchangeCashPersonListRepository.Save(newPerson)  
1696 - if err != nil {  
1697 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1698 - }  
1699 -  
1700 - // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励  
1701 -  
1702 - // 操作素币命令  
1703 - operationSuMoneyCommand := &command.OperationSuMoneyCommand{  
1704 - Uid: employeeFound.EmployeeInfo.Uid,  
1705 - Operator: createExchangeCashPersonCommand.Operator,  
1706 - SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,  
1707 - OperationType: 4,  
1708 - OperationDescription: "参与" + activityFound.ExchangeActivityName,  
1709 - }  
1710 -  
1711 - // 操作素币,生成素币流水  
1712 - task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)  
1713 - if err != nil {  
1714 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1715 - }  
1716 - if task == nil {  
1717 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))  
1718 - }  
1719 -  
1720 - // 更新兑换活动命令  
1721 - updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{  
1722 - ExchangeCashActivityId: personSaved.ExchangeCashActivityId,  
1723 - ExchangeActivityName: activityFound.ExchangeActivityName,  
1724 - ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,  
1725 - ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,  
1726 - Deadline: activityFound.Deadline,  
1727 - CountDown: activityFound.CountDown,  
1728 - ExchangeRate: activityFound.Rate,  
1729 - }  
1730 -  
1731 - // 更新兑换活动  
1732 - if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {  
1733 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
1734 - }  
1735 -  
1736 - // 保存兑换现金活动更新  
1737 - activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)  
1738 - if err != nil {  
1739 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1740 - }  
1741 - if activityUpdated == nil {  
1742 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))  
1743 - }  
1744 -  
1745 - // 判断兑换活动的现金是否超过现金池未兑换现金  
1746 - if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {  
1747 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")  
1748 - }  
1749 -  
1750 - // 获取平台素币兑换情况  
1751 - systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)  
1752 - if err != nil {  
1753 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1754 - }  
1755 - if systemSuMoneyStatistics == nil {  
1756 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")  
1757 - }  
1758 - systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)  
1759 - systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)  
1760 -  
1761 - // 重新计算现金池平均兑换汇率  
1762 - var newRate float64  
1763 - if systemExchangedSuMoney == 0 {  
1764 - newRate = 0  
1765 - } else {  
1766 - newRate = (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney  
1767 - }  
1768 -  
1769 - // 更新现金池命令  
1770 - updateCashPoolCommand := &command.UpdateCashPoolCommand{  
1771 - CashPoolId: cashPoolsFound[0].CashPoolId,  
1772 - Cash: cashPoolsFound[0].Cash,  
1773 - ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,  
1774 - UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,  
1775 - ExchangedSuMoney: systemExchangedSuMoney,  
1776 - UnExchangeSuMoney: systemUnExchangeSuMoney,  
1777 - Rate: newRate,  
1778 - LastRate: cashPoolsFound[0].LastRate,  
1779 - }  
1780 -  
1781 - // 更新现金池  
1782 - if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {  
1783 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
1784 - }  
1785 -  
1786 - // 保存现金池更新  
1787 - cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])  
1788 - if err != nil {  
1789 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1790 - }  
1791 - if cashPoolUpdated == nil {  
1792 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 2109 + failureDataList = append(failureDataList, row)
  2110 + continue
1793 } 2111 }
  2112 + }
1794 2113
  2114 + if len(failureDataList) == 0 {
1795 if err := transactionContext.CommitTransaction(); err != nil { 2115 if err := transactionContext.CommitTransaction(); err != nil {
1796 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
1797 - }  
1798 - return personSaved, nil  
1799 - } else { // 未知情况  
1800 - if err := transactionContext.CommitTransaction(); err != nil {  
1801 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 2116 + return failureDataList, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1802 } 2117 }
1803 - return nil, nil 2118 + return failureDataList, nil
1804 } 2119 }
  2120 + return failureDataList, nil
1805 } 2121 }
1806 2122
1807 // 页面新增兑换素币清单 2123 // 页面新增兑换素币清单
@@ -460,7 +460,7 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -460,7 +460,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
460 if i > 2 { 460 if i > 2 {
461 if len(row) != 3 { 461 if len(row) != 3 {
462 for j, cell := range row { 462 for j, cell := range row {
463 - if cell == "" { 463 + if cell == " " {
464 utils_tool.InsertSlice(j, row, newstr) 464 utils_tool.InsertSlice(j, row, newstr)
465 } 465 }
466 } 466 }
@@ -490,6 +490,8 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -490,6 +490,8 @@ func (controller *SuMoneyController) ImportExchangeList () {
490 // 新增成功计数 490 // 新增成功计数
491 var successDataCount int64 491 var successDataCount int64
492 492
  493 + var createExchangeCashPersonCommands []*command.CreateExchangeCashPersonCommand
  494 +
493 for i, row := range rows { 495 for i, row := range rows {
494 if i > 2 && len(row) > 1 { 496 if i > 2 && len(row) > 1 {
495 // 创建兑换清单命令 497 // 创建兑换清单命令
@@ -500,18 +502,22 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -500,18 +502,22 @@ func (controller *SuMoneyController) ImportExchangeList () {
500 createExchangeCashPersonCommand.PersonAccount = row[1] 502 createExchangeCashPersonCommand.PersonAccount = row[1]
501 r2, _ := strconv.ParseFloat(row[2], 64) 503 r2, _ := strconv.ParseFloat(row[2], 64)
502 createExchangeCashPersonCommand.ExchangedSuMoney = r2 504 createExchangeCashPersonCommand.ExchangedSuMoney = r2
503 -  
504 - // 创建兑换素币清单  
505 - _, err := cashPoolService.ImportCreateExchangeCashPerson(createExchangeCashPersonCommand)  
506 - if err != nil { // 导入失败处理  
507 - rows[i] = append(rows[i], err.Error())  
508 - failureDataList = append(failureDataList, rows[i]) // 导入失败的记录  
509 - } else { // 导入成功处理  
510 - successDataCount += 1  
511 - } 505 + createExchangeCashPersonCommands = append(createExchangeCashPersonCommands, createExchangeCashPersonCommand)
512 } 506 }
513 } 507 }
514 508
  509 + // 创建兑换素币清单
  510 + failureDataList, err = cashPoolService.ImportCreateExchangeCashPerson(createExchangeCashPersonCommands, failureDataList)
  511 + if err != nil { // 导入失败处理
  512 + response = utils.ResponseError(controller.Ctx, err)
  513 + controller.Data["json"] = response
  514 + controller.ServeJSON()
  515 + return
  516 + } else {
  517 + successDataCount = int64(len(rows) - 3 - len(failureDataList))
  518 + }
  519 +
  520 + // 导入失败返回
515 ret = map[string]interface{}{ 521 ret = map[string]interface{}{
516 "successCount": successDataCount, 522 "successCount": successDataCount,
517 "fail": map[string]interface{}{ 523 "fail": map[string]interface{}{
@@ -520,6 +526,7 @@ func (controller *SuMoneyController) ImportExchangeList () { @@ -520,6 +526,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
520 }, 526 },
521 } 527 }
522 528
  529 + // 导入成功返回
523 if successDataCount == int64(len(rows) - 3) { 530 if successDataCount == int64(len(rows) - 3) {
524 ret = map[string]interface{}{ 531 ret = map[string]interface{}{
525 "successCount": successDataCount, 532 "successCount": successDataCount,