...
|
...
|
@@ -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
|
|
|
}
|
|
|
|
|
|
// 页面新增兑换素币清单
|
...
|
...
|
|