Commit 49661095 by 程裕兵

feat:pay

parent a7e66a66
......@@ -110,6 +110,9 @@ public class StudioCashierRecordVO {
@ApiModelProperty("错误信息")
private String failMessage;
@ApiModelProperty("扩展信息")
private JSONObject extra;
@ApiModelProperty("交易发生时间")
private Date tradingTime;
......
......@@ -25,7 +25,7 @@ public class FitFinanceTaskController implements FitFinanceTaskApi {
@PostMapping(value = "/private/task/checkSettle")
@Override
public JsonResult<Void> checkSettle(@Valid @RequestBody CheckSettleRequest request) {
payService.checkSettle(request.getMerchantId(), request.getSettleDate());
// payService.checkSettle(request.getMerchantId(), request.getSettleDate());
return JsonResult.success();
}
}
/*
* Copyright © 2024 Hangzhou Jiejing Technology Co., Ltd. All rights reserved.
*
* The copyright of the company's program code belongs to Hangzhou Jiejing Technology Co., Ltd. No one can illegally copy it without the explicit permission of this website.
* Official website: www.xiaomai5.com
*
*
*
* Copyright © 2024 杭州杰竞科技有限公司 版权所有.
*
* 本公司程序代码的版权归杭州杰竞科技有限公司所有,未经本网站的明确许可,任何人不得非法复制。
* 官网: www.xiaomai5.com
*/
package com.jiejing.fitness.finance.repository.entity;
import com.jiejing.paycenter.common.enums.common.TransStateEnums;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* <p>
* 商户结算记录
* </p>
*
* @author chengyubing, created on 2024-04-18
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class MerchantSettleRecord implements Serializable {
private static final long serialVersionUID = -6318307599330382290L;
/**
* 备注: 主键 是否允许为null: NO
*/
@TableId(value = "id", type = IdType.ID_WORKER)
private Long id;
/**
* 备注: 商户ID 是否允许为null: YES
*/
private Long merchantId;
/**
* 备注: 商户号 是否允许为null: YES
*/
private String merchantNo;
/**
* 备注: 状态 是否允许为null: YES
*
* @see TransStateEnums
*/
private String transState;
/**
* 备注: 结算金额(元) 是否允许为null: YES
*/
private BigDecimal transAmount;
/**
* 备注: 结算银行卡号 是否允许为null: YES
*/
private String cardNo;
/**
* 备注: 结算银行 是否允许为null: YES
*/
private String bankName;
/**
* 备注: 失败原因 是否允许为null: YES
*/
private String failMsg;
/**
* 备注: 盐 是否允许为null: YES
*/
private String salt;
/**
* 备注: 结算日期 是否允许为null: YES
*/
private Date settleDate;
/**
* 备注: 创建时间 是否允许为null: YES
*/
private Date createTime;
/**
* 备注: 更新时间 是否允许为null: YES
*/
private Date updateTime;
public static final String ID = "id";
public static final String MERCHANT_ID = "merchant_id";
public static final String MERCHANT_NO = "merchant_no";
public static final String TRANS_STATE = "trans_state";
public static final String TRANS_AMOUNT = "trans_amount";
public static final String CARD_NO = "card_no";
public static final String BANK_NAME = "bank_name";
public static final String FAIL_MSG = "fail_msg";
public static final String SALT = "salt";
public static final String SETTLE_DATE = "settle_date";
public static final String CREATE_TIME = "create_time";
public static final String UPDATE_TIME = "update_time";
}
......@@ -187,6 +187,11 @@ public class StudioCashierRecord implements Serializable {
private String failMessage;
/**
* 扩展信息
*/
private String extra;
/**
* 备注: 交易发生时间 是否允许为null: YES
*/
private Date tradingTime;
......@@ -266,6 +271,8 @@ public class StudioCashierRecord implements Serializable {
public static final String FAIL_MESSAGE = "fail_message";
public static final String EXTRA = "extra";
public static final String TRADING_TIME = "trading_time";
public static final String SUCCESS_TIME = "success_time";
......
......@@ -48,6 +48,11 @@ public class StudioSettleRecord implements Serializable {
private Long id;
/**
* 备注: merchant_settle_record的ID 是否允许为null: YES
*/
private Long parentId;
/**
* 备注: 场馆ID 是否允许为null: YES
*/
private Long studioId;
......@@ -117,6 +122,8 @@ public class StudioSettleRecord implements Serializable {
public static final String ID = "id";
public static final String PARENT_ID = "parent_id";
public static final String STUDIO_ID = "studio_id";
public static final String STUDIO_NAME = "studio_name";
......
/*
* Copyright © 2024 Hangzhou Jiejing Technology Co., Ltd. All rights reserved.
*
* The copyright of the company's program code belongs to Hangzhou Jiejing Technology Co., Ltd. No one can illegally copy it without the explicit permission of this website.
* Official website: www.xiaomai5.com
*
*
*
* Copyright © 2024 杭州杰竞科技有限公司 版权所有.
*
* 本公司程序代码的版权归杭州杰竞科技有限公司所有,未经本网站的明确许可,任何人不得非法复制。
* 官网: www.xiaomai5.com
*/
package com.jiejing.fitness.finance.repository.mapper;
import com.jiejing.fitness.finance.repository.entity.MerchantSettleRecord;
import com.jiejing.mbp.inject.XBaseMapper;
/**
* <p>
* 商户结算记录 Mapper 接口
* </p>
*
* @author chengyubing, created on 2024-04-18
*/
public interface MerchantSettleRecordMapper extends XBaseMapper<MerchantSettleRecord> {
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright © 2024 Hangzhou Jiejing Technology Co., Ltd. All rights reserved.
~
~ The copyright of the company's program code belongs to Hangzhou Jiejing Technology Co., Ltd. No one can illegally copy it without the explicit permission of this website.
~ Official website: www.xiaomai5.com
~
~
~
~ Copyright © 2024 杭州杰竞科技有限公司 版权所有.
~
~ 本公司程序代码的版权归杭州杰竞科技有限公司所有,未经本网站的明确许可,任何人不得非法复制。
~ 官网: www.xiaomai5.com
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jiejing.fitness.finance.repository.mapper.MerchantSettleRecordMapper">
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, merchant_id, merchant_no, trans_state, trans_amount, card_no, bank_name, fail_msg, salt, settle_date, create_time, update_time
</sql>
</mapper>
......@@ -17,7 +17,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, trans_no, order_no, business_no, sub_order_no, order_type, trans_type, brand_id, studio_id, studio_name, merchant_id, merchant_no, channel_no, sub_channel, trans_amount, fee_rate, fee, actual_amount, trans_state, buyer_name, buyer_phone, goods, remark, exist_related_trans, related_trans_no, third_trans_no, fail_message, trading_time, success_time, in_time, create_time, update_time
id, trans_no, order_no, business_no, sub_order_no, order_type, trans_type, brand_id, studio_id, studio_name, merchant_id, merchant_no, channel_no, sub_channel, trans_amount, fee_rate, fee, actual_amount, trans_state, buyer_name, buyer_phone, goods, remark, exist_related_trans, related_trans_no, third_trans_no, fail_message, extra, trading_time, success_time, in_time, create_time, update_time
</sql>
<select id="sumRefundActualAmountByPayTransNo" resultType="java.math.BigDecimal">
......
......@@ -17,7 +17,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, studio_id, studio_name, merchant_id, merchant_no, trans_state, trans_amount, card_no, bank_name, fail_msg, salt, settle_date, create_time, update_time
id, parent_id, studio_id, studio_name, merchant_id, merchant_no, trans_state, trans_amount, card_no, bank_name, fail_msg, salt, settle_date, create_time, update_time
</sql>
</mapper>
/*
* Copyright © 2024 Hangzhou Jiejing Technology Co., Ltd. All rights reserved.
*
* The copyright of the company's program code belongs to Hangzhou Jiejing Technology Co., Ltd. No one can illegally copy it without the explicit permission of this website.
* Official website: www.xiaomai5.com
*
*
*
* Copyright © 2024 杭州杰竞科技有限公司 版权所有.
*
* 本公司程序代码的版权归杭州杰竞科技有限公司所有,未经本网站的明确许可,任何人不得非法复制。
* 官网: www.xiaomai5.com
*/
package com.jiejing.fitness.finance.repository.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.jiejing.fitness.finance.repository.entity.MerchantSettleRecord;
import com.jiejing.fitness.finance.repository.entity.StudioSettleRecord;
import com.jiejing.fitness.finance.repository.mapper.MerchantSettleRecordMapper;
import com.jiejing.mbp.MapperRepoService;
import com.jiejing.paycenter.common.enums.common.TransStateEnums;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service;
/**
* <p>
* 商户结算记录 服务实现类
* </p>
*
* @author chengyubing, created on 2024-04-18
*/
@Service
public class MerchantSettleRecordRpService extends
MapperRepoService<Long, MerchantSettleRecord, MerchantSettleRecordMapper> {
public List<MerchantSettleRecord> listInitAndProcessByMerchantIdAndBeforeOrEqualEndDate(Long merchantId,
Date endDate) {
QueryWrapper<MerchantSettleRecord> wrapper = new QueryWrapper<>();
wrapper.eq(MerchantSettleRecord.MERCHANT_ID, merchantId);
wrapper.le(MerchantSettleRecord.SETTLE_DATE, endDate);
wrapper.in(MerchantSettleRecord.TRANS_STATE, Lists.newArrayList(
TransStateEnums.INIT.getCode(), TransStateEnums.PROCESS.getCode()
));
wrapper.orderByAsc(MerchantSettleRecord.ID);
return Optional.ofNullable(this.baseMapper.selectList(wrapper)).orElse(new ArrayList<>(1));
}
public MerchantSettleRecord getByMerchantIdAndSettleDate(Long merchantId, Date settleDate) {
QueryWrapper<MerchantSettleRecord> wrapper = new QueryWrapper<>();
wrapper.eq(MerchantSettleRecord.MERCHANT_ID, merchantId);
wrapper.eq(MerchantSettleRecord.SETTLE_DATE, settleDate);
wrapper.orderByDesc(MerchantSettleRecord.ID);
List<MerchantSettleRecord> list = this.baseMapper.selectList(wrapper);
return Optional.ofNullable(list).orElse(new ArrayList<>()).stream().findFirst().orElse(null);
}
}
......@@ -149,7 +149,9 @@ public class StudioCashierRecordRpService extends
Integer current, Integer size) {
QueryWrapper<StudioCashierRecord> wrapper = new QueryWrapper<>();
wrapper.eq(StudioCashierRecord.MERCHANT_ID, merchantId);
wrapper.ge(StudioCashierRecord.SUCCESS_TIME, startTime);
if (null != startTime) {
wrapper.ge(StudioCashierRecord.SUCCESS_TIME, startTime);
}
wrapper.lt(StudioCashierRecord.SUCCESS_TIME, endTime);
return this.findByWrapperPage(wrapper, current, size);
}
......
......@@ -15,6 +15,7 @@
package com.jiejing.fitness.finance.repository.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.jiejing.common.utils.text.StringUtil;
import com.jiejing.fitness.finance.repository.entity.StudioSettleRecord;
import com.jiejing.fitness.finance.repository.mapper.StudioSettleRecordMapper;
......@@ -40,14 +41,14 @@ import org.springframework.stereotype.Service;
public class StudioSettleRecordRpService extends
MapperRepoService<Long, StudioSettleRecord, StudioSettleRecordMapper> {
public List<StudioSettleRecord> listByMerchantIdAndSettleDate(Long merchantId, Date settleDate) {
public StudioSettleRecord getByMerchantIdAndSettleDate(Long merchantId, Date settleDate) {
QueryWrapper<StudioSettleRecord> wrapper = new QueryWrapper<>();
wrapper.eq(StudioSettleRecord.MERCHANT_ID, merchantId);
wrapper.eq(StudioSettleRecord.SETTLE_DATE, settleDate);
// wrapper.eq(StudioSettleRecord.TRANS_STATE, TransStateEnums.SUCCESS.getCode());
wrapper.eq(StudioSettleRecord.TRANS_STATE, TransStateEnums.SUCCESS.getCode());
wrapper.orderByDesc(StudioSettleRecord.ID);
List<StudioSettleRecord> list = this.baseMapper.selectList(wrapper);
return Optional.ofNullable(list).orElse(new ArrayList<>());
return Optional.ofNullable(list).orElse(new ArrayList<>()).stream().findFirst().orElse(null);
}
public Page<StudioSettleRecord> page(PageStudioSettleQuery query) {
......@@ -73,4 +74,24 @@ public class StudioSettleRecordRpService extends
wrapper.orderByDesc(StudioSettleRecord.ID);
return findByWrapperPage(wrapper, query.getCurrent(), query.getSize());
}
public List<StudioSettleRecord> listInitAndProcessByMerchantIdAndBeforeOrEqualEndDate(Long merchantId,
Date endDate) {
QueryWrapper<StudioSettleRecord> wrapper = new QueryWrapper<>();
wrapper.eq(StudioSettleRecord.MERCHANT_ID, merchantId);
wrapper.le(StudioSettleRecord.SETTLE_DATE, endDate);
wrapper.in(StudioSettleRecord.TRANS_STATE, Lists.newArrayList(
TransStateEnums.INIT.getCode(), TransStateEnums.PROCESS.getCode()
));
wrapper.orderByAsc(StudioSettleRecord.ID);
return Optional.ofNullable(this.baseMapper.selectList(wrapper)).orElse(new ArrayList<>(1));
}
public void updateByParentId(StudioSettleRecord record) {
QueryWrapper<StudioSettleRecord> wrapper = new QueryWrapper<>();
wrapper.eq(StudioSettleRecord.PARENT_ID, record.getParentId());
this.baseMapper.update(record, wrapper);
}
}
\ No newline at end of file
......@@ -57,8 +57,9 @@ public class GeneratorServiceEntity {
// "brand_cashier_record"
// "bank",
// "branch_bank",
"studio_settle_record",
// "studio_check_settle_record"
// "studio_settle_record",
// "studio_check_settle_record",
"merchant_settle_record"
};
/**
......
......@@ -12,7 +12,9 @@ import com.jiejing.fitness.finance.api.cashier.vo.StudioSettleVO;
import com.jiejing.fitness.finance.repository.entity.StudioCashierRecord;
import com.jiejing.fitness.finance.repository.entity.StudioSettleRecord;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
/**
......@@ -22,7 +24,10 @@ import org.springframework.data.domain.Page;
public class CashierConvert {
public static StudioCashierRecordVO convertVO(StudioCashierRecord record) {
return JSON.parseObject(JSON.toJSONString(record), StudioCashierRecordVO.class);
StudioCashierRecordVO result = new StudioCashierRecordVO();
BeanUtils.copyProperties(record, result, "extra");
result.setExtra(JSON.parseObject(Optional.ofNullable(record.getExtra()).orElse("{}")));
return result;
}
public static List<StudioCashierRecordVO> convertList(List<StudioCashierRecord> list) {
......
......@@ -72,4 +72,12 @@ public interface PayService {
*/
void checkSettle(Long merchantId, Date settleDate);
/**
* 同步结算状态
*
* @param merchantId 商户ID
* @param settleDate 结算日
*/
void syncSettle(Long merchantId, Date settleDate);
}
......@@ -10,6 +10,7 @@ import com.jiejing.common.utils.crypt.AesUtil;
import com.jiejing.common.utils.text.StringUtil;
import com.jiejing.fitness.enums.finance.BrandCashierTransStateEnum;
import com.jiejing.fitness.enums.finance.BrandCashierTransTypeEnum;
import com.jiejing.fitness.finance.repository.entity.MerchantSettleRecord;
import com.jiejing.fitness.finance.repository.entity.PartyToMerchant;
import com.jiejing.fitness.finance.repository.entity.StudioCashierRecord;
import com.jiejing.fitness.finance.repository.entity.StudioCheckSettleRecord;
......@@ -99,6 +100,7 @@ public class PayConvert {
.goods(params.getGoods())
.remark(params.getRemark())
.existRelatedTrans(false)
.extra(JSON.toJSONString(params.getExtra()))
.tradingTime(new Date())
.createTime(new Date())
.updateTime(new Date())
......@@ -244,25 +246,23 @@ public class PayConvert {
.build();
}
public static List<StudioSettleRecord> convertSettle(StudioMerchantApply apply,
Map<Long, BigDecimal> studioTransAmountMap, SettleVO vo, Map<Long, StudioVO> studioMap) {
String salt = AesUtil.getSalt(8);
Date now = new Date();
public static List<StudioSettleRecord> convertStudioSettle(MerchantSettleRecord record,
Map<Long, BigDecimal> studioTransAmountMap, Map<Long, StudioVO> studioMap) {
return studioTransAmountMap.keySet().stream().map(studioId -> StudioSettleRecord.builder()
.id(IdWorker.getId())
.studioId(studioId)
.studioName(Optional.ofNullable(studioMap.get(studioId)).map(StudioVO::getName).orElse("-"))
.merchantId(apply.getMerchantId())
.merchantNo(apply.getMerchantNo())
.transState(vo.getTransState())
.merchantId(record.getMerchantId())
.merchantNo(record.getMerchantNo())
.transState(record.getTransState())
.transAmount(studioTransAmountMap.getOrDefault(studioId, BigDecimal.ZERO))
.settleDate(vo.getTransDate())
.cardNo(AesUtil.encrypt(salt, vo.getCardNo()))
.bankName(vo.getBankName())
.failMsg(vo.getFailMsg())
.salt(salt)
.createTime(now)
.updateTime(now)
.settleDate(record.getSettleDate())
.cardNo(record.getCardNo())
.bankName(record.getBankName())
.failMsg(record.getFailMsg())
.salt(record.getSalt())
.createTime(record.getCreateTime())
.updateTime(record.getUpdateTime())
.build()).collect(Collectors.toList());
}
......@@ -280,13 +280,6 @@ public class PayConvert {
.build();
}
public static StudioSettleRecord convertSettleToModify(SettleVO vo) {
return StudioSettleRecord.builder()
.transState(vo.getTransState())
.failMsg(vo.getFailMsg())
.updateTime(new Date()).build();
}
public static PayEvent convertEvent(PayRequest request, PayVO vo) {
return PayEvent.builder()
.id(Long.parseLong(request.getTransNo()))
......@@ -300,4 +293,39 @@ public class PayConvert {
.extra(request.getExtra())
.build();
}
public static MerchantSettleRecord convertMerchantSettle(StudioMerchantApply apply, SettleVO vo) {
String salt = AesUtil.getSalt(8);
Date now = new Date();
return MerchantSettleRecord.builder()
.id(IdWorker.getId())
.merchantId(apply.getMerchantId())
.merchantNo(apply.getMerchantNo())
.transState(vo.getTransState())
.transAmount(vo.getTransAmount())
.settleDate(vo.getTransDate())
.cardNo(AesUtil.encrypt(salt, vo.getCardNo()))
.bankName(vo.getBankName())
.failMsg(vo.getFailMsg())
.salt(salt)
.createTime(now)
.updateTime(now).build();
}
public static MerchantSettleRecord convertMerchantSettle(MerchantSettleRecord history, SettleVO vo) {
return MerchantSettleRecord.builder()
.id(history.getId())
.transState(vo.getTransState())
.failMsg(vo.getFailMsg())
.updateTime(new Date()).build();
}
public static StudioSettleRecord convertStudioSettle(MerchantSettleRecord history, SettleVO vo) {
return StudioSettleRecord.builder()
.parentId(history.getId())
.transState(vo.getTransState())
.failMsg(vo.getFailMsg())
.updateTime(new Date()).build();
}
}
......@@ -17,11 +17,13 @@ import com.jiejing.fitness.enums.auth.AuthDomainEnum;
import com.jiejing.fitness.enums.finance.BrandCashierTransStateEnum;
import com.jiejing.fitness.enums.tenant.TenantTypeEnum;
import com.jiejing.fitness.finance.repository.entity.GlobalConfig;
import com.jiejing.fitness.finance.repository.entity.MerchantSettleRecord;
import com.jiejing.fitness.finance.repository.entity.StudioCashierRecord;
import com.jiejing.fitness.finance.repository.entity.PartyToMerchant;
import com.jiejing.fitness.finance.repository.entity.StudioMerchantApply;
import com.jiejing.fitness.finance.repository.entity.StudioSettleRecord;
import com.jiejing.fitness.finance.repository.service.GlobalConfigRpService;
import com.jiejing.fitness.finance.repository.service.MerchantSettleRecordRpService;
import com.jiejing.fitness.finance.repository.service.StudioCashierRecordRpService;
import com.jiejing.fitness.finance.repository.service.PartyToMerchantRpService;
import com.jiejing.fitness.finance.repository.service.StudioCheckSettleRecordRpService;
......@@ -128,6 +130,9 @@ public class PayServiceImpl implements PayService {
@Resource
private PermissionRpcService permissionRpcService;
@Resource
private MerchantSettleRecordRpService merchantSettleRecordRpService;
@Resource(name = "financeThreadPool")
private Executor executor;
......@@ -265,17 +270,20 @@ public class PayServiceImpl implements PayService {
@Override
public void checkSettle(Long merchantId, Date settleDate) {
Date endDate = null == settleDate ? TimeUtil.local().startOfDay(new Date()) : settleDate;
Date startDate = TimeUtil.local().plus(endDate, -15, ChronoUnit.DAYS);
AtomicInteger failCount = new AtomicInteger(0);
this.pageAndConsumer(merchantId, 200, apply -> {
List<StudioSettleRecord> exist = studioSettleRecordRpService.listByMerchantIdAndSettleDate(
// 同步历史处理中的结算记录
Date startDate = this.syncHistorySettle(apply.getMerchantId(), endDate);
MerchantSettleRecord exist = merchantSettleRecordRpService.getByMerchantIdAndSettleDate(
apply.getMerchantId(), endDate);
if (CollectionUtil.isNotEmpty(exist) && exist.stream()
.anyMatch(e -> e.getTransState().equals(TransStateEnums.SUCCESS.getCode()))) {
if (null != exist) {
return;
}
SettleVO vo = payRpcService.syncSettle(apply.getMerchantId(), endDate);
// 对账
SettleVO vo = payRpcService.syncSettle(apply.getMerchantId(), endDate);
BigDecimal totalAmount = studioCashierRecordRpService.sumMerchantPaySuccess(apply.getMerchantId(),
startDate, endDate);
log.info("settle vo is {}, local total amount is {}", JSON.toJSONString(vo), totalAmount);
......@@ -291,13 +299,12 @@ public class PayServiceImpl implements PayService {
apply.getMerchantId(), startDate, endDate);
Map<Long, StudioVO> studioMap = studioRpcService.mapStudio(
Lists.newArrayList(studioTransAmountMap.keySet()));
if (CollectionUtil.isEmpty(exist)) {
transactionTemplate.executeWithoutResult(action -> {
MerchantSettleRecord record = PayConvert.convertMerchantSettle(apply, vo);
merchantSettleRecordRpService.insert(record);
studioSettleRecordRpService.insertAll(
PayConvert.convertSettle(apply, studioTransAmountMap, vo, studioMap));
} else {
List<Long> ids = exist.stream().map(StudioSettleRecord::getId).collect(toList());
studioSettleRecordRpService.updateByIds(PayConvert.convertSettleToModify(vo), ids);
}
PayConvert.convertStudioSettle(record, studioTransAmountMap, studioMap));
});
if (TransStateEnums.SUCCESS == TransStateEnums.getByCode(vo.getTransState())) {
// 结算成功,则更新收银流水状态为记录为入账成功
this.updatePayIn(apply.getMerchantId(), startDate, endDate);
......@@ -318,6 +325,53 @@ public class PayServiceImpl implements PayService {
}
@Override
public void syncSettle(Long merchantId, Date settleDate) {
Date endDate = null == settleDate ? TimeUtil.local().startOfDay(new Date()) : settleDate;
this.pageAndConsumer(merchantId, 200,
apply -> this.syncHistorySettle(apply.getMerchantId(), endDate));
}
private Date syncHistorySettle(Long merchantId, Date endDate) {
Date startDate = TimeUtil.local().plus(endDate, -15, ChronoUnit.DAYS);
List<MerchantSettleRecord> list = merchantSettleRecordRpService.listInitAndProcessByMerchantIdAndBeforeOrEqualEndDate(
merchantId, endDate);
if (CollectionUtil.isEmpty(list)) {
return startDate;
}
for (int i = 0; i < list.size(); i++) {
MerchantSettleRecord history = list.get(i);
SettleVO vo = payRpcService.syncSettle(merchantId, history.getSettleDate());
if (vo == null) {
if (i == 0) {
return TimeUtil.local().plus(history.getSettleDate(), -15, ChronoUnit.DAYS);
} else {
return list.get(i - 1).getSettleDate();
}
}
TransStateEnums state = TransStateEnums.getByCode(vo.getTransState());
if (TransStateEnums.INIT == state || TransStateEnums.PROCESS == state) {
if (i == 0) {
return TimeUtil.local().plus(history.getSettleDate(), -15, ChronoUnit.DAYS);
} else {
return list.get(i - 1).getSettleDate();
}
}
transactionTemplate.executeWithoutResult(action -> {
merchantSettleRecordRpService.updateById(PayConvert.convertMerchantSettle(history, vo));
studioSettleRecordRpService.updateByParentId(PayConvert.convertStudioSettle(history, vo));
});
if (TransStateEnums.SUCCESS == state) {
this.updatePayIn(merchantId, null, history.getSettleDate());
}
startDate = history.getSettleDate();
}
return startDate;
}
private void updatePayIn(Long merchantId, Date startTime, Date endTime) {
Integer current = 0;
Integer size = 500;
......@@ -335,7 +389,6 @@ public class PayServiceImpl implements PayService {
StudioCashierRecord.builder().transState(BrandCashierTransStateEnum.PAY_IN.getCode())
.inTime(endTime)
.updateTime(new Date()).build(), ids);
} finally {
current++;
}
......
......@@ -29,7 +29,7 @@ public class ResourceRpcService {
request.setAccessTypeEnum(AccessTypeEnum.PUBLIC);
request.setResourceIds(resourceIds);
request.setTenantId(partyId);
request.setExpire(TimeUnit.SECONDS.toMillis(60));
request.setExpire(TimeUnit.MINUTES.toMillis(10));
JsonResult<List<ResourceInfoVO>> result = resourceApi.getInfoByIds(request);
return Optional.ofNullable(result.getResult())
.map(list -> list.stream().collect(Collectors.toMap(ResourceInfoVO::getResourceId, e -> e)))
......@@ -41,7 +41,7 @@ public class ResourceRpcService {
request.setAccessTypeEnum(AccessTypeEnum.PUBLIC);
request.setResourceIds(resourceIds);
request.setTenantId(partyId);
request.setExpire(TimeUnit.SECONDS.toMillis(60));
request.setExpire(TimeUnit.MINUTES.toMillis(10));
JsonResult<List<ResourceInfoVO>> result = resourceApi.getInfoByIds(request);
return Optional.ofNullable(result.getResult())
.map(list -> list.stream().collect(Collectors.toMap(ResourceInfoVO::getResourceId, e -> e.getUrl())))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment