交易记录修改

This commit is contained in:
gaowdong 2025-04-21 15:13:21 +08:00
parent 1e2ad095b5
commit 03e2fe84c0
3 changed files with 64 additions and 33 deletions

View File

@ -15,6 +15,8 @@ import com.bonus.common.houqin.utils.id.Id;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ -63,6 +65,7 @@ public class AccTradeServiceImpl implements IAccTradeService {
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public int insertAccTrade(AccTrade accTrade) {
accTrade.setCreateTime(DateUtils.getNowDate());
return accTradeMapper.insertAccTrade(accTrade);
@ -88,6 +91,7 @@ public class AccTradeServiceImpl implements IAccTradeService {
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public int updateAccTrade(AccTrade accTrade) {
accTrade.setUpdateTime(DateUtils.getNowDate());
try {

View File

@ -37,6 +37,7 @@ import com.bonus.common.houqin.utils.id.Id;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.system.api.RemoteUserService;
import com.bonus.system.api.domain.SysUser;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -242,7 +243,16 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
private void acWalletBalanceOperation(WalletBalanceOperation operation) {
Long tradeId = null;
try{
List<AccWalletInfo> walletInfoList = selectAccWalletInfoByUserId(operation.getUserId());
BigDecimal accBalTotal = walletInfoList.stream().map(AccWalletInfo::getWalletBal)
.filter(ObjectUtil::isNotNull).reduce(BigDecimal.ZERO, BigDecimal::add);
tradeId = insertAccTradeRecode(operation, accBalTotal);
if(WalletBalanceOperationEnum.getEnum(operation.getOperationType()) == null) {
throw new ServiceException("钱包操作类型不存在");
}
switch (WalletBalanceOperationEnum.getEnum(operation.getOperationType())) {
case ADD_BAL:
addAccWalletInfo(operation);
@ -253,38 +263,7 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
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());
}
if(Objects.nonNull(operation.getOrderNo())) {
accTrade.setOrderNo(operation.getOrderNo().toString());
}
this.accTradeService.insertAccTrade(accTrade);
walletInfoList = selectAccWalletInfoByUserId(operation.getUserId());
AccTradeWalletDetail accTradeWalletDetail = new AccTradeWalletDetail();
accTradeWalletDetail.setTradeId(tradeId);
accTradeWalletDetail.setUserId(operation.getUserId());
@ -298,7 +277,22 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
accTradeWalletDetail.setTradeTime(DateUtils.getNowDate());
accTradeWalletDetail.setCreateBy(SecurityUtils.getUsername());
this.accTradeWalletDetailService.insertAccTradeWalletDetail(accTradeWalletDetail);
AccTrade accTrade = new AccTrade();
accTrade.setTradeId(tradeId);
accTrade.setPayState(PayStateEnum.PAY_SUCC.getKey());
accTrade.setTradeState(AccTradeStateEnum.TAKE_EFFECT.getKey());
accTrade.setUpdateBy(SecurityUtils.getUsername());
this.accTradeService.updateAccTrade(accTrade);
}catch (Exception ex) {
if(Objects.nonNull(tradeId)) {
AccTrade accTrade = new AccTrade();
accTrade.setTradeId(tradeId);
accTrade.setPayState(PayStateEnum.PAY_FAIL.getKey());
accTrade.setTradeState(AccTradeStateEnum.CANCELED.getKey());
accTrade.setUpdateBy(SecurityUtils.getUsername());
accTrade.setFailReason(StringUtils.substring(ex.getMessage(), 0, 100));
this.accTradeService.updateAccTrade(accTrade);
}
log.error("修改钱包失败", ex);
throw new ServiceException("修改钱包失败");
}
@ -313,4 +307,36 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
accWalletInfoMapper.reduceAccWalletInfo(operation.getAmount(), operation.getUserId(), operation.getWalletId(),
SecurityUtils.getUserId().toString(), DateUtils.toLocalDateTime(new Date()));
}
private long insertAccTradeRecode(WalletBalanceOperation operation, BigDecimal accBalTotal) {
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_INPROCESS.getKey());
accTrade.setTradeState(AccTradeStateEnum.CREATE.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());
}
if(Objects.nonNull(operation.getOrderNo())) {
accTrade.setOrderNo(operation.getOrderNo().toString());
}
this.accTradeService.insertAccTrade(accTrade);
return tradeId;
}
}

View File

@ -284,7 +284,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
inner join acc_trade_wallet_detail atwd on
ate.trade_id = atwd.trade_id
where
ate.order_no = #{orderNo}
ate.pay_state = 3
and ate.order_no = #{orderNo}
and ate.trade_type = #{accTradeType}
</select>