This commit is contained in:
skjia 2025-04-10 18:41:15 +08:00
commit 31ef454db0
1 changed files with 57 additions and 50 deletions

View File

@ -37,6 +37,7 @@ import org.springframework.stereotype.Service;
import com.bonus.canteen.core.account.mapper.AccWalletInfoMapper;
import com.bonus.canteen.core.account.domain.AccWalletInfo;
import com.bonus.canteen.core.account.service.IAccWalletInfoService;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@ -194,57 +195,63 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
// SecurityUtils.getUserId().toString(), DateUtils.toLocalDateTime(new Date()));
// }
@Transactional(rollbackFor = Exception.class)
public void acWalletBalanceOperation(WalletBalanceOperation operation) {
switch (WalletBalanceOperationEnum.getEnum(operation.getOperationType())) {
case ADD_BAL:
addAccWalletInfo(operation);
break;
case REDUCE_BAL:
reduceAccWalletInfo(operation);
break;
default:
throw new ServiceException("钱包操作类型错误");
}
List<AccWalletInfo> walletInfoList = selectAccWalletInfoByUserId(operation.getUserId());
BigDecimal accBalTotal = walletInfoList.stream().map(AccWalletInfo::getWalletBal)
.filter(ObjectUtil::isNotNull).reduce(BigDecimal.ZERO, BigDecimal::add);
AjaxResult userResult = remoteUserService.getInfo(operation.getUserId() , SecurityConstants.INNER);
SysUser sysUser = null;
if(Objects.nonNull(userResult)) {
sysUser = JSONObject.parseObject(JSON.toJSONString(userResult.get(AjaxResult.DATA_TAG)), SysUser.class);
}
long tradeId = Id.next();
LocalDateTime tradeTime = LocalDateTime.now();
AccTrade accTrade = new AccTrade();
accTrade.setTradeId(tradeId);
accTrade.setTradeTime(tradeTime);
accTrade.setTradeType(operation.getTradeType());
accTrade.setAmount(operation.getAmount());
accTrade.setActualAmount(operation.getAmount());
accTrade.setWalletBalTotal(accBalTotal);
accTrade.setAccAllBal(accBalTotal);
accTrade.setPayState(PayStateEnum.PAY_SUCC.getKey());
accTrade.setTradeState(AccTradeStateEnum.TAKE_EFFECT.getKey());
accTrade.setUserId(operation.getUserId());
accTrade.setPayChannel(operation.getPayChannel());
accTrade.setPayType(operation.getPayType());
accTrade.setCreateBy(SecurityUtils.getUsername());
if(Objects.nonNull(sysUser)) {
accTrade.setDeptId(sysUser.getDeptId());
}
this.accTradeService.insertAccTrade(accTrade);
try{
switch (WalletBalanceOperationEnum.getEnum(operation.getOperationType())) {
case ADD_BAL:
addAccWalletInfo(operation);
break;
case REDUCE_BAL:
reduceAccWalletInfo(operation);
break;
default:
throw new ServiceException("钱包操作类型错误");
}
List<AccWalletInfo> walletInfoList = selectAccWalletInfoByUserId(operation.getUserId());
BigDecimal accBalTotal = walletInfoList.stream().map(AccWalletInfo::getWalletBal)
.filter(ObjectUtil::isNotNull).reduce(BigDecimal.ZERO, BigDecimal::add);
AjaxResult userResult = remoteUserService.getInfo(operation.getUserId() , SecurityConstants.INNER);
SysUser sysUser = null;
if(Objects.nonNull(userResult)) {
sysUser = JSONObject.parseObject(JSON.toJSONString(userResult.get(AjaxResult.DATA_TAG)), SysUser.class);
}
long tradeId = Id.next();
LocalDateTime tradeTime = LocalDateTime.now();
AccTrade accTrade = new AccTrade();
accTrade.setTradeId(tradeId);
accTrade.setTradeTime(tradeTime);
accTrade.setTradeType(operation.getTradeType());
accTrade.setAmount(operation.getAmount());
accTrade.setActualAmount(operation.getAmount());
accTrade.setWalletBalTotal(accBalTotal);
accTrade.setAccAllBal(accBalTotal);
accTrade.setPayState(PayStateEnum.PAY_SUCC.getKey());
accTrade.setTradeState(AccTradeStateEnum.TAKE_EFFECT.getKey());
accTrade.setUserId(operation.getUserId());
accTrade.setPayChannel(operation.getPayChannel());
accTrade.setPayType(operation.getPayType());
accTrade.setCreateBy(SecurityUtils.getUsername());
if(Objects.nonNull(sysUser)) {
accTrade.setDeptId(sysUser.getDeptId());
}
this.accTradeService.insertAccTrade(accTrade);
AccTradeWalletDetail accTradeWalletDetail = new AccTradeWalletDetail();
accTradeWalletDetail.setTradeId(tradeId);
accTradeWalletDetail.setUserId(operation.getUserId());
accTradeWalletDetail.setTradeType(operation.getTradeType());
accTradeWalletDetail.setAmount(operation.getAmount());
BigDecimal walletBalByWalletId = walletInfoList.stream().filter((item) -> {
return item.getWalletId().equals(operation.getWalletId());
}).map(AccWalletInfo::getWalletBal).filter(ObjectUtil::isNotNull).reduce(BigDecimal.ZERO, BigDecimal::add);
accTradeWalletDetail.setWalletBal(walletBalByWalletId);
accTradeWalletDetail.setTradeTime(DateUtils.getNowDate());
accTradeWalletDetail.setCreateBy(SecurityUtils.getUsername());
this.accTradeWalletDetailService.insertAccTradeWalletDetail(accTradeWalletDetail);
AccTradeWalletDetail accTradeWalletDetail = new AccTradeWalletDetail();
accTradeWalletDetail.setTradeId(tradeId);
accTradeWalletDetail.setUserId(operation.getUserId());
accTradeWalletDetail.setTradeType(operation.getTradeType());
accTradeWalletDetail.setAmount(operation.getAmount());
BigDecimal walletBalByWalletId = walletInfoList.stream().filter((item) -> {
return item.getWalletId().equals(operation.getWalletId());
}).map(AccWalletInfo::getWalletBal).filter(ObjectUtil::isNotNull).reduce(BigDecimal.ZERO, BigDecimal::add);
accTradeWalletDetail.setWalletBal(walletBalByWalletId);
accTradeWalletDetail.setTradeTime(DateUtils.getNowDate());
accTradeWalletDetail.setCreateBy(SecurityUtils.getUsername());
this.accTradeWalletDetailService.insertAccTradeWalletDetail(accTradeWalletDetail);
}catch (Exception ex) {
log.error("修改钱包失败", ex);
throw new ServiceException("修改钱包失败");
}
}
}