作者 陈志颖

refactor:优化导入功能

... ... @@ -548,3 +548,32 @@
BodyData:
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"}
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
2020/11/24 15:51:18.546 [I] [???:0] http server Running on http://:8082
2020/11/24 15:51:26.674 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606204286674056000
Auth=
BodyData:
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"}
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
2020/11/24 15:52:10.472 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606204330472439000
Auth=
BodyData:
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"}
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
2020/11/24 15:56:05.844 [I] [???:0] http server Running on http://:8082
2020/11/24 15:57:07.287 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606204627287511000
Auth=
BodyData:
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"}
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
2020/11/24 16:00:00.327 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606204800327448000
Auth=
BodyData:
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"}
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
2020/11/24 16:04:53.206 [I] [???:0] http server Running on http://:8082
2020/11/24 16:04:55.624 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./cash-pool/activity/exchange-list/import.1606205095624342000
Auth=
BodyData:
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"}
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
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
}
}
// 更新现金池
//newCashPool := &domain.CashPool{
// CashPoolId: cashPools[0].CashPoolId,
// CompanyId: createCashPoolCommand.CompanyId,
// Cash: createCashPoolCommand.Cash,
// ExchangedCash: cashPools[0].ExchangedCash,
// UnExchangeCash: cashPools[0].UnExchangeCash + (createCashPoolCommand.Cash - cashPools[0].Cash),
// ExchangedSuMoney: systemExchangedSuMoney,
// UnExchangeSuMoney: systemUnExchangeSuMoney,
// Rate: newRate,
// LastRate: lastActivityRate,
// CreateTime: time.Now().Local(),
//}
// 更新现金池命令
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPools[0].CashPoolId,
... ... @@ -1288,17 +1274,31 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
}
// 导入新增兑换素币清单
func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommands []*command.CreateExchangeCashPersonCommand, failureDataList []interface{}) ([]interface{}, error) {
// 批量校验
for _, createExchangeCashPersonCommand := range createExchangeCashPersonCommands {
if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
}
if len(failureDataList) > 0 {
return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, "校验失败")
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
... ... @@ -1309,7 +1309,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashActivityRepository = value
}
... ... @@ -1319,7 +1319,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeCashPersonListRepository = value
}
... ... @@ -1329,7 +1329,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cashPoolRepository = value
}
... ... @@ -1339,7 +1339,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeRepository = value
}
... ... @@ -1349,7 +1349,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return []interface{}{}, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
employeeDao = value
}
... ... @@ -1359,18 +1359,34 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operationSuMoneyService = value
}
// 循环添加
for _, createExchangeCashPersonCommand := range createExchangeCashPersonCommands {
// 获取当前兑换清单兑换活动
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if activityFound == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR,"当前未创建任务兑换活动")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"当前未创建任务兑换活动",
}
failureDataList = append(failureDataList, row)
continue
}
// 获取当前公司现金池
... ... @@ -1378,26 +1394,53 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
"companyId": activityFound.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if len(cashPoolsFound) == 0 {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"当前现金池为空,请先投入现金",
}
failureDataList = append(failureDataList, row)
continue
}
// 获取员工查询条件
getEmployee := map[string]interface{}{
"account": createExchangeCashPersonCommand.PersonAccount,
"companyId": activityFound.CompanyId,
"status": 1,
}
// 判断当前员工是否有效
employeeFound, err := employeeRepository.FindOne(getEmployee)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if employeeFound == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"无效的导入员工",
}
failureDataList = append(failureDataList, row)
continue
}
// 判断当前员工是否已经在素币兑换清单中
... ... @@ -1408,12 +1451,26 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 判断该员工兑换的素币是否超过本人持有的素币
if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"当前兑换素币超过本人持有的素币值",
}
failureDataList = append(failureDataList, row)
continue
}
if len(peopleFound) > 0 { // 当前导入员工在素币兑换清单中,判断追加素币兑换或撤回素币兑换
... ... @@ -1440,13 +1497,27 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 更新兑换素币清单
if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 保存兑换素币清单更新
personUpdated, err := exchangeCashPersonListRepository.Save(peopleFound[0])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 更新素币兑换活动命令
... ... @@ -1461,16 +1532,37 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 更新兑换活动
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 保存兑换现金活动更新
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if activityUpdated == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"兑换现金活动保存失败",
}
failureDataList = append(failureDataList, row)
continue
}
// 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
... ... @@ -1487,24 +1579,59 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 操作个人素币,生成素币流水记录
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"操作个人素币失败",
}
failureDataList = append(failureDataList, row)
continue
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"操作个人素币失败",
}
failureDataList = append(failureDataList, row)
continue
}
// 判断兑换活动的现金是否超过现金池未兑换现金
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"已超过现金池未兑换现金",
}
failureDataList = append(failureDataList, row)
continue
}
// 获取平台素币兑换情况
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"无效的公司",
}
failureDataList = append(failureDataList, row)
continue
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
... ... @@ -1531,23 +1658,39 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 更新现金池
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 保存现金池更新
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if cashPoolUpdated == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
failureDataList = append(failureDataList, row)
continue
}
return personUpdated, nil
} else if createExchangeCashPersonCommand.ExchangedSuMoney > personFoundExchangedSuMoney { // 当前兑换素币大于已兑换素币,追加兑换素币
} else { // 当前兑换素币大于等于已兑换素币,追加兑换素币
// 素币增量
suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney
... ... @@ -1564,13 +1707,27 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 更新兑换素币清单
if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 保存兑换素币清单更新
personUpdated, err := exchangeCashPersonListRepository.Save(peopleFound[0])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 更新素币兑换活动命令
... ... @@ -1585,16 +1742,37 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 更新兑换活动
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 保存兑换现金活动更新
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if activityUpdated == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误",
}
failureDataList = append(failureDataList, row)
continue
}
// 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
... ... @@ -1611,24 +1789,59 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 操作素币,生成素币流水
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误",
}
failureDataList = append(failureDataList, row)
continue
}
// 判断兑换活动的现金是否超过现金池未兑换现金
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"已超过现金池未兑换现金",
}
failureDataList = append(failureDataList, row)
continue
}
// 获取平台素币兑换情况
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"无效的公司员工",
}
failureDataList = append(failureDataList, row)
continue
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
... ... @@ -1655,27 +1868,38 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 更新现金池
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 保存现金池更新
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内务业务错误" + err.Error(),
}
if cashPoolUpdated == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
failureDataList = append(failureDataList, row)
continue
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
if cashPoolUpdated == nil {
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
return personUpdated, nil
} else { // 当前导入兑换素币清单素币等于本人已兑换素币
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
failureDataList = append(failureDataList, row)
continue
}
return nil, nil
}
} else if len(peopleFound) == 0 { // 导入兑换素币清单员工不存在兑换素币清单中,新增兑换素币清单
// 新增兑换素币清单命令
... ... @@ -1694,7 +1918,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 保存兑换素币清单
personSaved, err := exchangeCashPersonListRepository.Save(newPerson)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内务业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
... ... @@ -1711,10 +1942,24 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 操作素币,生成素币流水
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误",
}
failureDataList = append(failureDataList, row)
continue
}
// 更新兑换活动命令
... ... @@ -1730,30 +1975,72 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 更新兑换活动
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"当前兑换素币超过本人持有的素币值",
}
failureDataList = append(failureDataList, row)
continue
}
// 保存兑换现金活动更新
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if activityUpdated == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误",
}
failureDataList = append(failureDataList, row)
continue
}
// 判断兑换活动的现金是否超过现金池未兑换现金
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"已超过现金池未兑换现金",
}
failureDataList = append(failureDataList, row)
continue
}
// 获取平台素币兑换情况
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"无效的公司员工",
}
failureDataList = append(failureDataList, row)
continue
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
... ... @@ -1780,28 +2067,57 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
// 更新现金池
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
// 保存现金池更新
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
failureDataList = append(failureDataList, row)
continue
}
if cashPoolUpdated == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"内部业务错误" + err.Error(),
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
failureDataList = append(failureDataList, row)
continue
}
return personSaved, nil
} else { // 未知情况
row := []interface{}{
createExchangeCashPersonCommand.PersonName,
createExchangeCashPersonCommand.PersonAccount,
createExchangeCashPersonCommand.ExchangedSuMoney,
"未知错误",
}
failureDataList = append(failureDataList, row)
continue
}
}
if len(failureDataList) == 0 {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return failureDataList, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return failureDataList, nil
}
return failureDataList, nil
}
// 页面新增兑换素币清单
... ...
... ... @@ -460,7 +460,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
if i > 2 {
if len(row) != 3 {
for j, cell := range row {
if cell == "" {
if cell == " " {
utils_tool.InsertSlice(j, row, newstr)
}
}
... ... @@ -490,6 +490,8 @@ func (controller *SuMoneyController) ImportExchangeList () {
// 新增成功计数
var successDataCount int64
var createExchangeCashPersonCommands []*command.CreateExchangeCashPersonCommand
for i, row := range rows {
if i > 2 && len(row) > 1 {
// 创建兑换清单命令
... ... @@ -500,18 +502,22 @@ func (controller *SuMoneyController) ImportExchangeList () {
createExchangeCashPersonCommand.PersonAccount = row[1]
r2, _ := strconv.ParseFloat(row[2], 64)
createExchangeCashPersonCommand.ExchangedSuMoney = r2
createExchangeCashPersonCommands = append(createExchangeCashPersonCommands, createExchangeCashPersonCommand)
}
}
// 创建兑换素币清单
_, err := cashPoolService.ImportCreateExchangeCashPerson(createExchangeCashPersonCommand)
failureDataList, err = cashPoolService.ImportCreateExchangeCashPerson(createExchangeCashPersonCommands, failureDataList)
if err != nil { // 导入失败处理
rows[i] = append(rows[i], err.Error())
failureDataList = append(failureDataList, rows[i]) // 导入失败的记录
} else { // 导入成功处理
successDataCount += 1
}
}
response = utils.ResponseError(controller.Ctx, err)
controller.Data["json"] = response
controller.ServeJSON()
return
} else {
successDataCount = int64(len(rows) - 3 - len(failureDataList))
}
// 导入失败返回
ret = map[string]interface{}{
"successCount": successDataCount,
"fail": map[string]interface{}{
... ... @@ -520,6 +526,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
},
}
// 导入成功返回
if successDataCount == int64(len(rows) - 3) {
ret = map[string]interface{}{
"successCount": successDataCount,
... ...