diff --git a/coolstore-partner-common/src/main/java/com/cool/store/constants/RedisConstant.java b/coolstore-partner-common/src/main/java/com/cool/store/constants/RedisConstant.java index 737b900d9..5283ea669 100644 --- a/coolstore-partner-common/src/main/java/com/cool/store/constants/RedisConstant.java +++ b/coolstore-partner-common/src/main/java/com/cool/store/constants/RedisConstant.java @@ -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}"; } diff --git a/coolstore-partner-dao/src/main/java/com/cool/store/dao/order/PreAllocationRecordDAO.java b/coolstore-partner-dao/src/main/java/com/cool/store/dao/order/PreAllocationRecordDAO.java index d5e0d3130..da99a419d 100644 --- a/coolstore-partner-dao/src/main/java/com/cool/store/dao/order/PreAllocationRecordDAO.java +++ b/coolstore-partner-dao/src/main/java/com/cool/store/dao/order/PreAllocationRecordDAO.java @@ -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); } diff --git a/coolstore-partner-model/src/main/java/com/cool/store/request/store/TransRequest.java b/coolstore-partner-model/src/main/java/com/cool/store/request/store/TransRequest.java new file mode 100644 index 000000000..fc7ce6118 --- /dev/null +++ b/coolstore-partner-model/src/main/java/com/cool/store/request/store/TransRequest.java @@ -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; + +} diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/store/PreAllocationRecordService.java b/coolstore-partner-service/src/main/java/com/cool/store/service/store/PreAllocationRecordService.java index f204f05be..737d2595b 100644 --- a/coolstore-partner-service/src/main/java/com/cool/store/service/store/PreAllocationRecordService.java +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/store/PreAllocationRecordService.java @@ -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); + } diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/store/impl/PreAllocationRecordServiceImpl.java b/coolstore-partner-service/src/main/java/com/cool/store/service/store/impl/PreAllocationRecordServiceImpl.java index 8ab630222..27b6d92d8 100644 --- a/coolstore-partner-service/src/main/java/com/cool/store/service/store/impl/PreAllocationRecordServiceImpl.java +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/store/impl/PreAllocationRecordServiceImpl.java @@ -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 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; + } }