交易记录修改
This commit is contained in:
parent
1e2ad095b5
commit
03e2fe84c0
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,9 +263,52 @@ 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);
|
||||
walletInfoList = selectAccWalletInfoByUserId(operation.getUserId());
|
||||
AccTradeWalletDetail accTradeWalletDetail = new AccTradeWalletDetail();
|
||||
accTradeWalletDetail.setTradeId(tradeId);
|
||||
accTradeWalletDetail.setUserId(operation.getUserId());
|
||||
accTradeWalletDetail.setTradeType(operation.getTradeType());
|
||||
accTradeWalletDetail.setAmount(operation.getAmount());
|
||||
accTradeWalletDetail.setWalletId(operation.getWalletId());
|
||||
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);
|
||||
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("修改钱包失败");
|
||||
}
|
||||
}
|
||||
|
||||
private void addAccWalletInfo(WalletBalanceOperation operation) {
|
||||
accWalletInfoMapper.addAccWalletInfo(operation.getAmount(), operation.getUserId(), operation.getWalletId(),
|
||||
SecurityUtils.getUserId().toString(), DateUtils.toLocalDateTime(new Date()));
|
||||
}
|
||||
|
||||
private void reduceAccWalletInfo(WalletBalanceOperation operation) {
|
||||
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)) {
|
||||
|
|
@ -271,8 +324,8 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
|
|||
accTrade.setActualAmount(operation.getAmount());
|
||||
accTrade.setWalletBalTotal(accBalTotal);
|
||||
accTrade.setAccAllBal(accBalTotal);
|
||||
accTrade.setPayState(PayStateEnum.PAY_SUCC.getKey());
|
||||
accTrade.setTradeState(AccTradeStateEnum.TAKE_EFFECT.getKey());
|
||||
accTrade.setPayState(PayStateEnum.PAY_INPROCESS.getKey());
|
||||
accTrade.setTradeState(AccTradeStateEnum.CREATE.getKey());
|
||||
accTrade.setUserId(operation.getUserId());
|
||||
accTrade.setPayChannel(operation.getPayChannel());
|
||||
accTrade.setPayType(operation.getPayType());
|
||||
|
|
@ -284,33 +337,6 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
|
|||
accTrade.setOrderNo(operation.getOrderNo().toString());
|
||||
}
|
||||
this.accTradeService.insertAccTrade(accTrade);
|
||||
|
||||
AccTradeWalletDetail accTradeWalletDetail = new AccTradeWalletDetail();
|
||||
accTradeWalletDetail.setTradeId(tradeId);
|
||||
accTradeWalletDetail.setUserId(operation.getUserId());
|
||||
accTradeWalletDetail.setTradeType(operation.getTradeType());
|
||||
accTradeWalletDetail.setAmount(operation.getAmount());
|
||||
accTradeWalletDetail.setWalletId(operation.getWalletId());
|
||||
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("修改钱包失败");
|
||||
}
|
||||
}
|
||||
|
||||
private void addAccWalletInfo(WalletBalanceOperation operation) {
|
||||
accWalletInfoMapper.addAccWalletInfo(operation.getAmount(), operation.getUserId(), operation.getWalletId(),
|
||||
SecurityUtils.getUserId().toString(), DateUtils.toLocalDateTime(new Date()));
|
||||
}
|
||||
|
||||
private void reduceAccWalletInfo(WalletBalanceOperation operation) {
|
||||
accWalletInfoMapper.reduceAccWalletInfo(operation.getAmount(), operation.getUserId(), operation.getWalletId(),
|
||||
SecurityUtils.getUserId().toString(), DateUtils.toLocalDateTime(new Date()));
|
||||
return tradeId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue