Merge branch 'cc_20260415_trans'

This commit is contained in:
suzhuhong
2026-04-20 16:43:02 +08:00
23 changed files with 702 additions and 17 deletions

View File

@@ -419,5 +419,11 @@ public class RedisConstant {
*/
public static final String XGJ_CALLBACK_SHOP = "xgj_callback_shop:{0}";
/**
* 预分账单 分账key
*/
public static final String PRE_ALLOCATION = "pre_allocation:{0}";
public static final String STORE_ID_MAPPING = "store_id_mapping";
}

View File

@@ -394,10 +394,12 @@ public enum ErrorCodeEnum {
TRADE_EXIST(1621006, "部分交易流水号已被使用,请检查!", null),
NOT_COMPLETE_TRANS_SHEET(1621007, "存在关联未分账完成的分账单,请完成之后再操作!", null),
PENDING_TRANS_AMOUNT(1621008, "分账金额不能大于待分账金额!", null),
TRANSFER_ERROR(1621009, "分账异常", null),
TRANSFER_ERROR(1621009, "分账异常{0}", null),
TRANSFER_ING(1621010, "分账中,请勿重复分账!", null),
WITHDRAW_APPLY_NOT_EXIST(1621011, "提现申请单不存在!", null),
WITHDRAW_ING(1621012, "提现中,请勿重复分账!", null),
WALLET_BALANCE_INSUFFICIENT(1621013, "钱包余额不足!", null),

View File

@@ -175,6 +175,7 @@ public enum ShopSubStageStatusEnum {
SHOP_SUB_STAGE_STATUS_283(ShopSubStageEnum.SHOP_STAGE_28, 2830, "审批拒绝", Boolean.FALSE),
SHOP_SUB_STAGE_STATUS_284(ShopSubStageEnum.SHOP_STAGE_28, 2840, "待缴费", Boolean.FALSE),
SHOP_SUB_STAGE_STATUS_284_5(ShopSubStageEnum.SHOP_STAGE_28, 2845, "对账中", Boolean.FALSE),
SHOP_SUB_STAGE_STATUS_284_7(ShopSubStageEnum.SHOP_STAGE_28, 2847, "其他费用待扣款", Boolean.FALSE),
SHOP_SUB_STAGE_STATUS_285(ShopSubStageEnum.SHOP_STAGE_28, 2850, "已完成", Boolean.TRUE),
SHOP_SUB_STAGE_STATUS_290(ShopSubStageEnum.SHOP_STAGE_29, 2900, "待通知发货", Boolean.FALSE),

View File

@@ -0,0 +1,240 @@
package com.cool.store.utils;
import java.math.BigDecimal;
/**
* @Auther zx_szh
* @Date 2026/4/16 10:03
* @Version 1.0
*/
public class BigDecimalUtils {
/**
* 比较两个BigDecimal是否相等忽略精度差异
*
* @param a 第一个值
* @param b 第二个值
* @return 如果相等返回true
*/
public static boolean equals(BigDecimal a, BigDecimal b) {
if (a == b) return true;
if (a == null || b == null) return false;
return a.compareTo(b) == 0;
}
/**
* 比较两个BigDecimal是否相等指定精度
*
* @param a 第一个值
* @param b 第二个值
* @param scale 保留小数位数
* @param roundingMode 舍入模式
* @return 如果相等返回true
*/
public static boolean equals(BigDecimal a, BigDecimal b, int scale, int roundingMode) {
if (a == b) return true;
if (a == null || b == null) return false;
return a.setScale(scale, roundingMode).compareTo(b.setScale(scale, roundingMode)) == 0;
}
/**
* 判断a是否大于b
*
* @param a 第一个值
* @param b 第二个值
* @return 如果a大于b返回true
*/
public static boolean greaterThan(BigDecimal a, BigDecimal b) {
if (a == null || b == null) return false;
return a.compareTo(b) > 0;
}
/**
* 判断a是否大于或等于b
*
* @param a 第一个值
* @param b 第二个值
* @return 如果a大于或等于b返回true
*/
public static boolean greaterThanOrEqual(BigDecimal a, BigDecimal b) {
if (a == null || b == null) return false;
return a.compareTo(b) >= 0;
}
/**
* 判断a是否小于b
*
* @param a 第一个值
* @param b 第二个值
* @return 如果a小于b返回true
*/
public static boolean lessThan(BigDecimal a, BigDecimal b) {
if (a == null || b == null) return false;
return a.compareTo(b) < 0;
}
/**
* 判断a是否小于或等于b
*
* @param a 第一个值
* @param b 第二个值
* @return 如果a小于或等于b返回true
*/
public static boolean lessThanOrEqual(BigDecimal a, BigDecimal b) {
if (a == null || b == null) return false;
return a.compareTo(b) <= 0;
}
/**
* 判断value是否在min和max之间包含边界
*
* @param value 要判断的值
* @param min 最小值
* @param max 最大值
* @return 如果在范围内返回true
*/
public static boolean between(BigDecimal value, BigDecimal min, BigDecimal max) {
if (value == null || min == null || max == null) return false;
return value.compareTo(min) >= 0 && value.compareTo(max) <= 0;
}
/**
* 判断value是否在min和max之间不包含边界
*
* @param value 要判断的值
* @param min 最小值
* @param max 最大值
* @return 如果在范围内返回true
*/
public static boolean betweenExclusive(BigDecimal value, BigDecimal min, BigDecimal max) {
if (value == null || min == null || max == null) return false;
return value.compareTo(min) > 0 && value.compareTo(max) < 0;
}
/**
* 判断value是否在min和max之间左闭右开
*
* @param value 要判断的值
* @param min 最小值(包含)
* @param max 最大值(不包含)
* @return 如果在范围内返回true
*/
public static boolean betweenLeftClosedRightOpen(BigDecimal value, BigDecimal min, BigDecimal max) {
if (value == null || min == null || max == null) return false;
return value.compareTo(min) >= 0 && value.compareTo(max) < 0;
}
/**
* 判断value是否在min和max之间左开右闭
*
* @param value 要判断的值
* @param min 最小值(不包含)
* @param max 最大值(包含)
* @return 如果在范围内返回true
*/
public static boolean betweenLeftOpenRightClosed(BigDecimal value, BigDecimal min, BigDecimal max) {
if (value == null || min == null || max == null) return false;
return value.compareTo(min) > 0 && value.compareTo(max) <= 0;
}
/**
* 判断value是否大于0
*
* @param value 要判断的值
* @return 如果大于0返回true
*/
public static boolean isPositive(BigDecimal value) {
return greaterThan(value, BigDecimal.ZERO);
}
/**
* 判断value是否大于或等于0
*
* @param value 要判断的值
* @return 如果大于或等于0返回true
*/
public static boolean isNonNegative(BigDecimal value) {
return greaterThanOrEqual(value, BigDecimal.ZERO);
}
/**
* 判断value是否小于0
*
* @param value 要判断的值
* @return 如果小于0返回true
*/
public static boolean isNegative(BigDecimal value) {
return lessThan(value, BigDecimal.ZERO);
}
/**
* 判断value是否小于或等于0
*
* @param value 要判断的值
* @return 如果小于或等于0返回true
*/
public static boolean isNonPositive(BigDecimal value) {
return lessThanOrEqual(value, BigDecimal.ZERO);
}
/**
* 判断value是否等于0
*
* @param value 要判断的值
* @return 如果等于0返回true
*/
public static boolean isZero(BigDecimal value) {
return equals(value, BigDecimal.ZERO);
}
/**
* 判断value是否非零
*
* @param value 要判断的值
* @return 如果不等于0返回true
*/
public static boolean isNotZero(BigDecimal value) {
return !isZero(value);
}
/**
* 判断两个BigDecimal中的较大值
*
* @param a 第一个值
* @param b 第二个值
* @return 较大值如果都为null返回null
*/
public static BigDecimal max(BigDecimal a, BigDecimal b) {
if (a == null) return b;
if (b == null) return a;
return a.compareTo(b) >= 0 ? a : b;
}
/**
* 判断两个BigDecimal中的较小值
*
* @param a 第一个值
* @param b 第二个值
* @return 较小值如果都为null返回null
*/
public static BigDecimal min(BigDecimal a, BigDecimal b) {
if (a == null) return b;
if (b == null) return a;
return a.compareTo(b) <= 0 ? a : b;
}
/**
* 安全比较处理null情况
*
* @param a 第一个值
* @param b 第二个值
* @return 比较结果a>b返回1a=b返回0a<b返回-1
*/
public static int safeCompare(BigDecimal a, BigDecimal b) {
if (a == null && b == null) return 0;
if (a == null) return -1;
if (b == null) return 1;
return a.compareTo(b);
}
}

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);
}
@@ -74,4 +78,21 @@ public class PreAllocationRecordDAO {
}
return preAllocationRecordMapper.deleteByIdsNotPaid(ids) > 0;
}
/**
* 软删除
*/
public boolean softDeleteById(Long id) {
return preAllocationRecordMapper.softDeleteById(id) > 0;
}
/**
* 批量软删除
*/
public boolean softDeleteByIds(List<Long> ids) {
if (ids == null || ids.isEmpty()) {
return false;
}
return preAllocationRecordMapper.softDeleteByIds(ids) > 0;
}
}

View File

@@ -67,6 +67,17 @@ public class WalletTradeDAO {
return walletTradeMapper.getPayingOrderBatchCode(module, type);
}
/**
* 查询支付中的 单次支付的数据 非批量
* @param module
* @param type
* @return
*/
public List<WalletTradeDO> getPayingOrder(String module, Integer type) {
return walletTradeMapper.getPayingOrder(module, type);
}
public List<WalletTradeDO> transferTradeList(String module, Integer type) {
return walletTradeMapper.transferTradeList(module, type);
}

View File

@@ -33,4 +33,14 @@ public interface PreAllocationRecordMapper extends Mapper<PreAllocationRecordDO>
int deleteByIdsNotPaid(@Param("ids") List<Long> ids);
Integer updateByPayNoList(@Param("payNoList") List<String> payNoList, @Param("status") Integer status);
/**
* 软删除
*/
int softDeleteById(@Param("id") Long id);
/**
* 批量软删除
*/
int softDeleteByIds(@Param("ids") List<Long> ids);
}

View File

@@ -21,5 +21,7 @@ public interface WalletTradeMapper extends Mapper<WalletTradeDO> {
*/
List<String> getPayingOrderBatchCode(@Param("module") String module, @Param("type") Integer type);
List<WalletTradeDO> getPayingOrder(@Param("module") String module, @Param("type") Integer type);
List<WalletTradeDO> transferTradeList(@Param("module") String module, @Param("type") Integer type);
}

View File

@@ -14,11 +14,17 @@
<result column="allocation_status" property="allocationStatus" jdbcType="INTEGER"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
<result column="remark" property="remark" jdbcType="VARCHAR"/>
<result column="deleted" property="deleted" jdbcType="TINYINT"/>
</resultMap>
<sql id="Base_Column_List">
id, order_id, shop_id, pay_no, expense_type, payee_name, payee_code,
pay_amount, allocation_status, create_time, update_time
pay_amount, allocation_status, create_time, update_time, remark, deleted
</sql>
<sql id="Not_Deleted_Condition">
deleted = 0
</sql>
<select id="getById" resultMap="BaseResultMap">
@@ -31,6 +37,7 @@
SELECT <include refid="Base_Column_List"/>
FROM zxjp_pre_allocation_record
WHERE order_id = #{orderId}
AND <include refid="Not_Deleted_Condition"/>
ORDER BY create_time DESC
</select>
@@ -38,6 +45,7 @@
SELECT <include refid="Base_Column_List"/>
FROM zxjp_pre_allocation_record
WHERE shop_id = #{shopId}
AND <include refid="Not_Deleted_Condition"/>
ORDER BY create_time DESC
</select>
@@ -45,14 +53,16 @@
SELECT <include refid="Base_Column_List"/>
FROM zxjp_pre_allocation_record
WHERE shop_id = #{shopId}
and expense_type = #{expenseType}
AND expense_type = #{expenseType}
ORDER BY create_time DESC
limit 1
</select>
<select id="queryPageByPayNo" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM zxjp_pre_allocation_record
WHERE pay_no = #{payNo}
AND <include refid="Not_Deleted_Condition"/>
ORDER BY create_time DESC
</select>
@@ -130,6 +140,23 @@
</foreach>
</delete>
<update id="softDeleteById">
UPDATE zxjp_pre_allocation_record
SET deleted = 1,
update_time = NOW()
WHERE id = #{id}
AND <include refid="Not_Deleted_Condition"/>
</update>
<update id="softDeleteByIds">
UPDATE zxjp_pre_allocation_record
SET deleted = 1,
update_time = NOW()
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND <include refid="Not_Deleted_Condition"/>
</update>
</mapper>

View File

@@ -72,6 +72,12 @@
GROUP BY batch_code
</select>
<select id="getPayingOrder" resultMap="BaseResultMap">
SELECT *
FROM zxjp_wallet_trade
WHERE pay_status = 3 AND module = #{module} AND type = #{type} AND batch_code IS NULL
</select>
<select id="transferTradeList" resultMap="BaseResultMap">
SELECT *
FROM zxjp_wallet_trade

View File

@@ -53,4 +53,10 @@ public class PreAllocationRecordDO implements Serializable {
@Column(name = "update_time")
private Date updateTime;
@Column(name = "remark")
private String remark;
@Column(name = "deleted")
private Integer deleted;
}

View File

@@ -41,7 +41,7 @@ public class WalletTradeDO {
private String tradeId;
/**
* 交易类型1转账
* 交易类型1转账 2-提现
*/
private Integer type;

View File

@@ -0,0 +1,42 @@
package com.cool.store.request.store;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/**
* 新增预分账记录请求
*/
@Data
public class PreAllocationAddRequest {
@NotNull(message = "订单ID不能为空")
@ApiModelProperty("订单ID")
private Long orderId;
@NotNull(message = "门店ID不能为空")
@ApiModelProperty("门店ID")
private Long shopId;
@NotBlank(message = "费用类型不能为空")
@ApiModelProperty("费用类型")
private String expenseType;
@ApiModelProperty("收款公司名称")
private String payeeName;
@ApiModelProperty("收款公司Code")
private String payeeCode;
@NotNull(message = "分账金额不能为空")
@DecimalMin(value = "0.01", message = "分账金额必须大于0")
@ApiModelProperty("分账金额")
private BigDecimal payAmount;
@ApiModelProperty("分账备注")
private String remark;
}

View File

@@ -0,0 +1,36 @@
package com.cool.store.request.store;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/**
* 编辑预分账记录请求
*/
@Data
public class PreAllocationEditRequest {
@NotNull(message = "记录ID不能为空")
@ApiModelProperty("记录ID")
private Long id;
@ApiModelProperty("费用类型")
private String expenseType;
@ApiModelProperty("收款公司名称")
private String payeeName;
@ApiModelProperty("收款公司Code")
private String payeeCode;
@ApiModelProperty("分账金额")
@DecimalMin(value = "0.01", message = "分账金额必须大于0")
private BigDecimal payAmount;
@ApiModelProperty("分账备注")
private String remark;
}

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

@@ -50,5 +50,7 @@ public class PreAllocationRecordVO {
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("分账备注")
private String remark;
}

View File

@@ -335,7 +335,7 @@ public class FranchiseFeeServiceImpl implements FranchiseFeeService {
stageList.add(SHOP_SUB_STAGE_STATUS_80);
}else {
//标准店
stageList.add(SHOP_SUB_STAGE_STATUS_285);
stageList.add(SHOP_SUB_STAGE_STATUS_284_7);
stageList.add(SHOP_SUB_STAGE_STATUS_80);
//查询可乐机缴费状态
PreAllocationRecordDO preAllocationRecordDO = preAllocationRecordDAO.queryPageByShopIdAndExpenseType(request.getShopId(), WalletFeeItemEnum.DEVICE_EARNEST_MONEY.getExpenseType());

View File

@@ -44,8 +44,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import static com.cool.store.enums.point.ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_285;
import static com.cool.store.enums.point.ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_80;
import static com.cool.store.enums.point.ShopSubStageStatusEnum.*;
/**
* @Author suzhuhong
@@ -127,7 +126,7 @@ public class OpenApiServiceImpl implements OpenApiService {
if (request.getClaimStatus() == 1 && preAllocationRecordDO!=null&&WalletFeeItemEnum.DEVICE_EARNEST_MONEY.getExpenseType().equals(preAllocationRecordDO.getExpenseType())){
String key = MessageFormat.format(RedisConstant.XGJ_CALLBACK_SHOP, preAllocationRecordDO.getShopId());
if (StringUtils.isNotEmpty(redisUtilPool.getString(key))){
shopStageInfoDAO.batchUpdateShopStageStatus(preAllocationRecordDO.getShopId(),Arrays.asList(SHOP_SUB_STAGE_STATUS_285,SHOP_SUB_STAGE_STATUS_80));
shopStageInfoDAO.batchUpdateShopStageStatus(preAllocationRecordDO.getShopId(),Arrays.asList(SHOP_SUB_STAGE_STATUS_284_7,SHOP_SUB_STAGE_STATUS_80));
}
}
return ApiResponse.success(Boolean.TRUE);

View File

@@ -252,7 +252,7 @@ public class SplitOrderServiceImpl implements SplitOrderService {
//分账失败 释放锁
redisUtil.unlock(lockKey);
log.info("confirmSplitOrder:{}",e.getMessage());
throw new ServiceException(ErrorCodeEnum.TRANSFER_ERROR);
throw new ServiceException(ErrorCodeEnum.ERROR_MESSAGE,e.getMessage());
}
existing.setConfirmer(userInfo.getUserId());
existing.setStatus(accountTransferDTO.getTradeStatus());

View File

@@ -2,8 +2,12 @@ package com.cool.store.service.store;
import com.cool.store.entity.order.PreAllocationRecordDO;
import com.cool.store.entity.order.StoreOrderDO;
import com.cool.store.entity.wallet.WalletTradeDO;
import com.cool.store.request.store.PreAllocationAddRequest;
import com.cool.store.request.store.PreAllocationEditRequest;
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 +30,35 @@ public interface PreAllocationRecordService {
Integer pushStandardStoreFee(StoreOrderDO storeOrderDO);
Boolean trans(TransRequest transRequest);
/**
* 分账状态刷新
* @param walletTradeDO
* @return
*/
Boolean transStatusRefresh(WalletTradeDO walletTradeDO);
/**
* 新增预分账记录
* @param request
* @return
*/
Boolean add(PreAllocationAddRequest request);
/**
* 编辑预分账记录
* @param request
* @return
*/
Boolean edit(PreAllocationEditRequest request);
/**
* 删除预分账记录(软删除)
* @param id
* @return
*/
Boolean delete(Long id);
}

View File

@@ -1,7 +1,9 @@
package com.cool.store.service.store.impl;
import cn.hutool.core.collection.CollStreamUtil;
import com.alibaba.excel.converters.bigdecimal.BigDecimalNumberConverter;
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,7 +17,9 @@ 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.dto.wallet.TradeRecordDTO;
import com.cool.store.entity.FranchiseFeeDO;
import com.cool.store.entity.LineInfoDO;
import com.cool.store.entity.ShopInfoDO;
@@ -36,12 +40,14 @@ import com.cool.store.enums.fees.WalletFeeItemEnum;
import com.cool.store.enums.order.StoreOrderStatusEnum;
import com.cool.store.enums.point.ShopSubStageEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.enums.wallet.TradeTypeEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.mapper.FranchiseFeeMapper;
import com.cool.store.request.store.PreAllocationAddRequest;
import com.cool.store.request.store.PreAllocationEditRequest;
import com.cool.store.request.store.PreAllocationSaveRequest;
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.store.TransRequest;
import com.cool.store.request.wallet.*;
import com.cool.store.request.xgj.PushFranchiseFeeRequest;
import com.cool.store.request.xgj.ReceiptRequest;
import com.cool.store.service.PushService;
@@ -50,12 +56,10 @@ import com.cool.store.service.fees.WalletPayInfoService;
import com.cool.store.service.order.MiniStoreOrderService;
import com.cool.store.service.store.PreAllocationRecordService;
import com.cool.store.service.wallet.WalletApiService;
import com.cool.store.utils.BeanUtil;
import com.cool.store.utils.GenerateNoUtil;
import com.cool.store.utils.RedisUtil;
import com.cool.store.utils.StringUtil;
import com.cool.store.utils.*;
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 +68,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;
@@ -71,7 +76,8 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.cool.store.enums.order.StoreOrderStatusEnum.PAY_FAIL;
import static com.cool.store.enums.wallet.WalletTradeModuleEnum.STANDARD_STORE;
import static com.cool.store.enums.point.ShopSubStageStatusEnum.*;
import static com.cool.store.enums.wallet.WalletTradeModuleEnum.*;
/**
* @Auther zx_szh
@@ -715,4 +721,157 @@ 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);
}
//校验金额
AccountInfoDTO accountInfoDTO = accountInfoList.get(0);
String totalAmount = accountInfoDTO.getTotalAmount();
Boolean amountSupport = BigDecimalUtils.greaterThanOrEqual(new BigDecimal(totalAmount), record.getPayAmount());
if (!amountSupport){
throw new ServiceException(ErrorCodeEnum.WALLET_BALANCE_INSUFFICIENT);
}
AccountTransferDTO accountTransferDTO ;
try {
accountTransferDTO = walletPayInfoService.accountPay(record.getExpenseType(), record.getPayAmount(),
record.getPayeeCode(), accountInfoDTO.getAccountNo(), record.getPayNo(), transRequest.getRemark());
}catch (Exception e){
//分账失败 释放锁
redisUtil.unlock(lockKey);
log.error("confirmSplitOrder:{}",e.getMessage());
throw new ServiceException(ErrorCodeEnum.ERROR_MESSAGE,e.getMessage());
}
record.setAllocationStatus(AllocationPayStatusEnum.PAYING.getStatus());
record.setRemark(transRequest.getRemark());
//先改为分账中
preAllocationRecordDAO.updateByPrimaryKeySelective(record);
WalletTradeDO walletTradeDO = new WalletTradeDO();
walletTradeDO.setPayStatus(accountTransferDTO.getTradeStatus());
walletTradeDO.setModule(TRANSFER.getModule());
walletTradeDO.setRemark(transRequest.getRemark());
walletTradeDO.setPayAmount(new BigDecimal(accountTransferDTO.getAmount()));
walletTradeDO.setPayTime(new Date());
walletTradeDO.setPayNo(record.getPayNo());
walletTradeDO.setTradeId(String.valueOf(accountTransferDTO.getTradeId()));
walletTradeDO.setType(TradeTypeEnum.ADD_BY_HAND.getStatus());
walletTradeDAO.insertSelective(walletTradeDO);
return null;
}
@Override
public Boolean transStatusRefresh(WalletTradeDO walletTradeDO) {
BillDetailRequest request = new BillDetailRequest();
request.setTradeId(Long.valueOf(walletTradeDO.getTradeId()));
TradeRecordDTO billDetail = walletApiService.getBillDetail(request);
walletTradeDO.setPayStatus(billDetail.getTradeStatus());
walletTradeDAO.updateByPrimaryKeySelective(walletTradeDO);
PreAllocationRecordDO preAllocationRecordDO = preAllocationRecordDAO.queryPageByPayNo(walletTradeDO.getPayNo());
preAllocationRecordDO.setAllocationStatus(billDetail.getTradeStatus());
preAllocationRecordDO.setUpdateTime(new Date());
preAllocationRecordDAO.updateByPrimaryKeySelective(preAllocationRecordDO);
if (AllocationPayStatusEnum.PAID.getStatus().equals(walletTradeDO.getPayStatus())) {
ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(preAllocationRecordDO.getShopId());
//订单状态更新
StoreOrderDO storeOrder = storeOrderDAO.getById(preAllocationRecordDO.getOrderId());
//部分支付
StoreOrderDO updateOrder = StoreOrderDO.builder()
.id(storeOrder.getId())
.status(StoreOrderStatusEnum.PART_OF_WAIT_PAY.getCode())
.updateTime(new Date())
.build();
//当前缴纳金额 = 本次缴纳前已缴纳金额+本次缴纳金额
BigDecimal currentAmount = new BigDecimal(billDetail.getAmount());
BigDecimal paidAmount = storeOrder.getPaidAmount().add(currentAmount);
BigDecimal unpaidAmount = storeOrder.getTotalAmount().subtract(paidAmount);
//支付成功 修改金额,支付中 回调的时候习惯
updateOrder.setPaidAmount(paidAmount);
updateOrder.setUnpaidAmount(unpaidAmount);
updateOrder.setPayTime(new Date());
if (BigDecimalUtils.equals(unpaidAmount,new BigDecimal(0))){
//剩余缴纳金额是0 缴费完成
updateOrder.setStatus( StoreOrderStatusEnum.PAID.getCode());
//阶段状态变为完成
shopStageInfoDAO.updateShopStageInfo(storeOrder.getShopId(), SHOP_SUB_STAGE_STATUS_285);
}
storeOrderDAO.updateSelective(updateOrder);
//清除缓存
String lockKey = MessageFormat.format(RedisConstant.PRE_ALLOCATION,preAllocationRecordDO.getId());
redisUtil.unlock(lockKey);
}
return Boolean.TRUE;
}
@Override
public Boolean add(PreAllocationAddRequest request) {
if (request == null) {
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
}
PreAllocationRecordDO record = PreAllocationRecordDO.builder()
.orderId(request.getOrderId())
.shopId(request.getShopId())
.expenseType(request.getExpenseType())
.payeeName(request.getPayeeName())
.payeeCode(request.getPayeeCode())
.payAmount(request.getPayAmount())
.payNo(GenerateNoUtil.generateMillsNoWithRandom())
.remark(request.getRemark())
.deleted(0)
.allocationStatus(AllocationPayStatusEnum.UNPAID.getStatus())
.createTime(new Date())
.updateTime(new Date())
.build();
return dao.insertSelective(record);
}
@Override
public Boolean edit(PreAllocationEditRequest request) {
if (request == null || request.getId() == null) {
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
}
PreAllocationRecordDO exist = dao.getById(request.getId());
if (exist == null) {
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
}
PreAllocationRecordDO record = PreAllocationRecordDO.builder()
.id(request.getId())
.expenseType(request.getExpenseType())
.payeeName(request.getPayeeName())
.payeeCode(request.getPayeeCode())
.payAmount(request.getPayAmount())
.remark(request.getRemark())
.updateTime(new Date())
.build();
return dao.updateByPrimaryKeySelective(record);
}
@Override
public Boolean delete(Long id) {
if (id == null) {
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
}
return dao.softDeleteById(id);
}
}

View File

@@ -1,7 +1,10 @@
package com.cool.store.controller.webb;
import com.cool.store.request.store.PreAllocationAddRequest;
import com.cool.store.request.store.PreAllocationEditRequest;
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.response.ResponseResult;
import com.cool.store.service.store.PreAllocationRecordService;
import com.cool.store.vo.order.PreAllocationRecordVO;
@@ -33,9 +36,34 @@ public class PreAllocationRecordController {
return ResponseResult.success(preAllocationRecordService.saveBatch(req));
}
@ApiOperation("单费用类型独立分账")
@PostMapping("/trans")
public ResponseResult<Boolean> queryByShop(@RequestBody @Valid TransRequest request ){
return ResponseResult.success(preAllocationRecordService.trans(request));
}
@ApiOperation("按门店查询预分账明细")
@GetMapping("/queryByShop")
public ResponseResult<List<PreAllocationRecordVO>> queryByShop(@RequestParam(value = "shopId" ,required = true) Long shopId){
return ResponseResult.success(preAllocationRecordService.queryByShop(shopId));
}
@ApiOperation("新增预分账记录")
@PostMapping("/add")
public ResponseResult<Boolean> add(@RequestBody @Valid PreAllocationAddRequest request){
return ResponseResult.success(preAllocationRecordService.add(request));
}
@ApiOperation("编辑预分账记录")
@PostMapping("/edit")
public ResponseResult<Boolean> edit(@RequestBody @Valid PreAllocationEditRequest request){
return ResponseResult.success(preAllocationRecordService.edit(request));
}
@ApiOperation("删除预分账记录")
@PostMapping("/delete")
public ResponseResult<Boolean> delete(@RequestParam(value = "id" ,required = true) Long id){
return ResponseResult.success(preAllocationRecordService.delete(id));
}
}

View File

@@ -676,6 +676,33 @@ public class XxlJobHandler {
pageNum++;
}
log.info("------end batchTransferStandardStore------");
//开始单个分账状态查询
transferStandardStore();
}
public void transferStandardStore() {
log.info("------start transferStandardStore------");
boolean hasNext = true;
int pageNum = 1;
int pageSize = CommonConstants.BATCH_SIZE;
while (hasNext) {
PageHelper.startPage(pageNum, pageSize);
List<WalletTradeDO> list = walletTradeDAO.getPayingOrder(WalletTradeModuleEnum.STANDARD_STORE.getModule(), 1);
hasNext = list.size() >= pageSize;
if (CollectionUtils.isEmpty(list)) {
break;
}
for (WalletTradeDO walletTradeDO : list) {
try {
preAllocationRecordService.transStatusRefresh(walletTradeDO);
} catch (Exception e) {
log.error("钱包单费用类型转账分账支付状态查询失败, walletTradeDO:{}", walletTradeDO, e);
}
}
pageNum++;
}
log.info("------end transferStandardStore------");
}
@XxlJob("transfer")