feat:trans

This commit is contained in:
suzhuhong
2026-04-15 18:02:18 +08:00
parent 19bce915ac
commit fa83eeb484
5 changed files with 80 additions and 0 deletions

View File

@@ -418,4 +418,10 @@ public class RedisConstant {
* 新管家缴费回调完成 标识
*/
public static final String XGJ_CALLBACK_SHOP = "xgj_callback_shop:{0}";
/**
* 预分账单 分账key
*/
public static final String PRE_ALLOCATION = "pre_allocation:{0}";
}

View File

@@ -17,6 +17,10 @@ public class PreAllocationRecordDAO {
return preAllocationRecordMapper.insertSelective(record) > 0;
}
public boolean updateByPrimaryKeySelective(PreAllocationRecordDO record) {
return preAllocationRecordMapper.updateByPrimaryKeySelective(record) > 0;
}
public PreAllocationRecordDO getById(Long id) {
return preAllocationRecordMapper.getById(id);
}

View File

@@ -0,0 +1,25 @@
package com.cool.store.request.store;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @Auther zx_szh
* @Date 2026/4/15 17:47
* @Version 1.0
*/
@Data
public class TransRequest {
@ApiModelProperty("分账单ID")
@NotNull
private Long id;
@ApiModelProperty("备注")
@NotBlank(message = "备注不能为空")
private String remark;
}

View File

@@ -4,6 +4,7 @@ import com.cool.store.entity.order.PreAllocationRecordDO;
import com.cool.store.entity.order.StoreOrderDO;
import com.cool.store.request.store.PreAllocationQueryShopRequest;
import com.cool.store.request.store.PreAllocationSaveRequest;
import com.cool.store.request.store.TransRequest;
import com.cool.store.vo.order.PreAllocationRecordVO;
import com.github.pagehelper.PageInfo;
@@ -26,4 +27,6 @@ public interface PreAllocationRecordService {
Integer pushStandardStoreFee(StoreOrderDO storeOrderDO);
Boolean trans(TransRequest transRequest);
}

View File

@@ -2,6 +2,7 @@ package com.cool.store.service.store.impl;
import cn.hutool.core.collection.CollStreamUtil;
import com.alibaba.fastjson.JSONObject;
import com.cool.store.constants.RedisConstant;
import com.cool.store.dao.FranchiseFeeDAO;
import com.cool.store.dao.LineInfoDAO;
import com.cool.store.dao.ShopInfoDAO;
@@ -15,6 +16,7 @@ import com.cool.store.dao.wallet.WalletTradeDAO;
import com.cool.store.dto.fees.ExpenseTypeAmountDTO;
import com.cool.store.dto.fees.WalletAllocationDTO;
import com.cool.store.dto.wallet.AccountInfoDTO;
import com.cool.store.dto.wallet.AccountTransferDTO;
import com.cool.store.dto.wallet.BatchTransferDTO;
import com.cool.store.entity.FranchiseFeeDO;
import com.cool.store.entity.LineInfoDO;
@@ -39,9 +41,11 @@ import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.mapper.FranchiseFeeMapper;
import com.cool.store.request.store.PreAllocationSaveRequest;
import com.cool.store.request.store.TransRequest;
import com.cool.store.request.wallet.BatchTransferQueryRequest;
import com.cool.store.request.wallet.BatchTransferRequest;
import com.cool.store.request.wallet.OutStoreIdRequest;
import com.cool.store.request.wallet.TransferRequest;
import com.cool.store.request.xgj.PushFranchiseFeeRequest;
import com.cool.store.request.xgj.ReceiptRequest;
import com.cool.store.service.PushService;
@@ -56,6 +60,7 @@ import com.cool.store.utils.RedisUtil;
import com.cool.store.utils.StringUtil;
import com.cool.store.vo.order.MiniStoreOrderDetailVO;
import com.cool.store.vo.order.PreAllocationRecordVO;
import com.sun.xml.bind.v2.TODO;
import groovy.util.logging.Slf4j;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
@@ -64,6 +69,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
@@ -715,4 +721,40 @@ public class PreAllocationRecordServiceImpl implements PreAllocationRecordServic
pushService.pushFranchiseFeeToXGJ(feeRequest);
return franchiseFeeDO.getId().intValue();
}
@Override
public Boolean trans(TransRequest transRequest) {
String lockKey = MessageFormat.format(RedisConstant.PRE_ALLOCATION,transRequest.getId());
String uuid = UUID.randomUUID().toString();
if(!Boolean.TRUE.equals(redisUtil.tryLock(lockKey, uuid,10, TimeUnit.MINUTES))){
throw new ServiceException(ErrorCodeEnum.TRANSFER_ING);
}
PreAllocationRecordDO record = preAllocationRecordDAO.getById(transRequest.getId());
if (record==null){
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
}
ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(record.getShopId());
OutStoreIdRequest outStoreIdRequest = new OutStoreIdRequest();
outStoreIdRequest.setOutStoreId(shopInfo.getStoreId());
List<AccountInfoDTO> accountInfoList = walletApiService.getAccountInfo(outStoreIdRequest);
if (CollectionUtils.isEmpty(accountInfoList)){
throw new ServiceException(ErrorCodeEnum.NOT_EXIST_WANG_SHANG_ACCOUNT);
}
AccountTransferDTO accountTransferDTO ;
try {
AccountInfoDTO accountInfoDTO = accountInfoList.get(0);
accountTransferDTO = walletPayInfoService.accountPay(record.getExpenseType(), record.getPayAmount(),
record.getPayeeCode(), accountInfoDTO.getAccountNo(), record.getPayNo(), transRequest.getRemark());
}catch (Exception e){
//分账失败 释放锁
redisUtil.unlock(lockKey);
log.info("confirmSplitOrder:{}",e.getMessage());
//todo 改为明确的提示
throw new ServiceException(ErrorCodeEnum.TRANSFER_ERROR);
}
record.setAllocationStatus(AllocationPayStatusEnum.PAYING.getStatus());
//先改为分账中
preAllocationRecordDAO.updateByPrimaryKeySelective(record);
return null;
}
}