|
|
|
|
@@ -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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|