Commit 0bcc5c10 by 程裕兵

feat:settle

parent e79ecfd9
package com.jiejing.fitness.finance.api.task;
import com.jiejing.common.model.JsonResult;
import com.jiejing.fitness.finance.api.task.request.CheckSettleRequest;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
/**
* @author chengyubing
* @since 2024/4/7 13:49
*/
@FeignClient(name = "FINANCE", url = "${rpc.url.fit-finance:http://app-fit-finance:7008}", fallbackFactory = FitFinanceTaskApiFallback.class)
public interface FitFinanceTaskApi {
String TAG = "【任务】任务调度";
@ApiOperation(value = "对账", tags = {TAG})
@PostMapping(value = "/private/task/checkSettle")
JsonResult<Void> checkSettle(CheckSettleRequest request);
}
package com.jiejing.fitness.finance.api.task;
import com.jiejing.common.model.JsonResult;
import com.jiejing.fitness.finance.api.task.request.CheckSettleRequest;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* @author chengyubing
* @since 2024/4/7 13:49
*/
@Component
public class FitFinanceTaskApiFallback implements FallbackFactory<FitFinanceTaskApi> {
@Override
public FitFinanceTaskApi create(Throwable throwable) {
return new FitFinanceTaskApi() {
@Override
public JsonResult<Void> checkSettle(CheckSettleRequest request) {
return JsonResult.rpcError();
}
};
}
}
package com.jiejing.fitness.finance.api.task.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author chengyubing
* @since 2024/4/7 14:43
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "对账请求")
public class CheckSettleRequest {
@ApiModelProperty(value = "商户ID")
private Long merchantId;
@ApiModelProperty(value = "结算日")
private Date settleDate;
}
package com.jiejing.fitness.finance.app.controller.task;
import com.jiejing.common.model.JsonResult;
import com.jiejing.fitness.finance.api.task.FitFinanceTaskApi;
import com.jiejing.fitness.finance.api.task.request.CheckSettleRequest;
import com.jiejing.fitness.finance.service.pay.PayService;
import feign.hystrix.FallbackFactory;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* @author chengyubing
* @since 2024/4/7 13:52
*/
@Component
public class FitFinanceTaskController implements FitFinanceTaskApi {
@Resource
private PayService payService;
@ApiOperation(value = "对账", tags = {TAG})
@PostMapping(value = "/private/task/checkSettle")
@Override
public JsonResult<Void> checkSettle(@Valid @RequestBody CheckSettleRequest request) {
payService.checkSettle(request.getMerchantId(), request.getSettleDate());
return JsonResult.success();
}
}
...@@ -135,7 +135,7 @@ public class StudioCashierRecord implements Serializable { ...@@ -135,7 +135,7 @@ public class StudioCashierRecord implements Serializable {
private BigDecimal actualAmount; private BigDecimal actualAmount;
/** /**
* 备注: 交易状态:0-支付初始态;1-支付中;2-支付失败;3-入账中(支付成功);4-入账成功;5-退款中;6-退款成功;7-退款失败 默认值: 1 是否允许为null: YES * 备注: 交易状态
* *
* @see BrandCashierTransStateEnum * @see BrandCashierTransStateEnum
*/ */
......
/*
* 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.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-07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class StudioCheckSettleRecord implements Serializable {
private static final long serialVersionUID = -3981429835869732959L;
/**
* 备注: 主键
* 是否允许为null: YES
*/
private Long id;
/**
* 备注: 商户ID
* 是否允许为null: YES
*/
private Long merchantId;
/**
* 备注: 商户号
* 是否允许为null: YES
*/
private String merchantNo;
/**
* 备注: 对账状态
* 是否允许为null: YES
*/
private String checkState;
/**
* 备注: 对账失败原因
* 是否允许为null: YES
*/
private String failMsg;
/**
* 备注: 对账日期
* 是否允许为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 CHECK_STATE = "check_state";
public static final String FAIL_MSG = "fail_msg";
public static final String SETTLE_DATE = "settle_date";
public static final String CREATE_TIME = "create_time";
public static final String UPDATE_TIME = "update_time";
}
...@@ -64,7 +64,7 @@ public class StudioSettleRecord implements Serializable { ...@@ -64,7 +64,7 @@ public class StudioSettleRecord implements Serializable {
* 备注: 商户号 * 备注: 商户号
* 是否允许为null: YES * 是否允许为null: YES
*/ */
private String mercahntNo; private String merchantNo;
/** /**
* 备注: 状态 * 备注: 状态
...@@ -109,7 +109,7 @@ public class StudioSettleRecord implements Serializable { ...@@ -109,7 +109,7 @@ public class StudioSettleRecord implements Serializable {
public static final String MERCHANT_ID = "merchant_id"; public static final String MERCHANT_ID = "merchant_id";
public static final String MERCAHNT_NO = "mercahnt_no"; public static final String MERCHANT_NO = "merchant_no";
public static final String TRANS_STATE = "trans_state"; public static final String TRANS_STATE = "trans_state";
......
...@@ -17,6 +17,7 @@ package com.jiejing.fitness.finance.repository.mapper; ...@@ -17,6 +17,7 @@ package com.jiejing.fitness.finance.repository.mapper;
import com.jiejing.fitness.finance.repository.entity.StudioCashierRecord; import com.jiejing.fitness.finance.repository.entity.StudioCashierRecord;
import com.jiejing.mbp.inject.XBaseMapper; import com.jiejing.mbp.inject.XBaseMapper;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
/** /**
...@@ -30,4 +31,7 @@ public interface StudioCashierRecordMapper extends XBaseMapper<StudioCashierReco ...@@ -30,4 +31,7 @@ public interface StudioCashierRecordMapper extends XBaseMapper<StudioCashierReco
BigDecimal sumRefundActualAmountByPayTransNo(@Param("payTransNo") String payTransNo); BigDecimal sumRefundActualAmountByPayTransNo(@Param("payTransNo") String payTransNo);
BigDecimal sumMerchantPaySuccess(@Param("merchantId") Long merchantId,
@Param("startTime") Date startTime, @Param("endTime") Date endTime);
} }
...@@ -27,4 +27,13 @@ ...@@ -27,4 +27,13 @@
and trans_state in ('REFUNDING', 'REFUND_SUCCESS') and trans_state in ('REFUNDING', 'REFUND_SUCCESS')
</select> </select>
<select id="sumMerchantPaySuccess" resultType="java.math.BigDecimal">
select sum(trans_amount)
from studio_cashier_record
where merchant_id = #{merchantId}
and trans_state in ('PAY_SUCCESS', 'PAY_IN')
and success_time >= #{startTime}
and success_time &lt; #{endTime}
</select>
</mapper> </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.mapper;
import com.jiejing.fitness.finance.repository.entity.StudioCheckSettleRecord;
import com.jiejing.mbp.inject.XBaseMapper;
/**
* <p>
* 场馆对账记录 Mapper 接口
* </p>
*
* @author chengyubing, created on 2024-04-07
*/
public interface StudioCheckSettleRecordMapper extends XBaseMapper<StudioCheckSettleRecord> {
}
<?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.StudioCheckSettleRecordMapper">
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, merchant_id, merchant_no, check_state, fail_msg, settle_date, create_time, update_time
</sql>
</mapper>
...@@ -16,6 +16,7 @@ package com.jiejing.fitness.finance.repository.mapper; ...@@ -16,6 +16,7 @@ package com.jiejing.fitness.finance.repository.mapper;
import com.jiejing.fitness.finance.repository.entity.StudioMerchantApply; import com.jiejing.fitness.finance.repository.entity.StudioMerchantApply;
import com.jiejing.mbp.inject.XBaseMapper; import com.jiejing.mbp.inject.XBaseMapper;
import java.util.List;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
/** /**
...@@ -31,4 +32,7 @@ public interface StudioMerchantApplyMapper extends XBaseMapper<StudioMerchantApp ...@@ -31,4 +32,7 @@ public interface StudioMerchantApplyMapper extends XBaseMapper<StudioMerchantApp
StudioMerchantApply getLatestOneSuccessByStudioId(@Param("studioId") Long studioId); StudioMerchantApply getLatestOneSuccessByStudioId(@Param("studioId") Long studioId);
List<StudioMerchantApply> listByMinId(@Param("minId") Long minId, @Param("merchantId") Long merchantId,
@Param("size") Integer size);
} }
...@@ -42,4 +42,18 @@ ...@@ -42,4 +42,18 @@
limit 1 limit 1
</select> </select>
<select id="listByMinId"
resultType="com.jiejing.fitness.finance.repository.entity.StudioMerchantApply">
select *
from studio_merchant_apply
where id > #{minId}
<if test="merchantId != null">
and merchant_id = #{merchantId}
</if>
and open_state = 'SUCCESS'
and apply_type in ('OPEN', 'RE_OPEN')
order by id asc
limit #{size}
</select>
</mapper> </mapper>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, studio_id, merchant_id, mercahnt_no, trans_state, trans_amount, card_no, settle_date, create_time, update_time id, studio_id, merchant_id, merchant_no, trans_state, trans_amount, card_no, settle_date, create_time, update_time
</sql> </sql>
</mapper> </mapper>
...@@ -21,6 +21,7 @@ import com.jiejing.fitness.finance.repository.mapper.StudioCashierRecordMapper; ...@@ -21,6 +21,7 @@ import com.jiejing.fitness.finance.repository.mapper.StudioCashierRecordMapper;
import com.jiejing.fitness.finance.repository.query.PageBrandCashierRecordQuery; import com.jiejing.fitness.finance.repository.query.PageBrandCashierRecordQuery;
import com.jiejing.mbp.MapperRepoService; import com.jiejing.mbp.MapperRepoService;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
import java.util.List; import java.util.List;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -99,4 +100,7 @@ public class StudioCashierRecordRpService extends ...@@ -99,4 +100,7 @@ public class StudioCashierRecordRpService extends
return this.baseMapper.selectList(wrapper); return this.baseMapper.selectList(wrapper);
} }
public BigDecimal sumMerchantPaySuccess(Long merchantId, Date startTime, Date endTime) {
return this.baseMapper.sumMerchantPaySuccess(merchantId, startTime, endTime);
}
} }
/*
* 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.jiejing.fitness.finance.repository.entity.StudioCheckSettleRecord;
import com.jiejing.fitness.finance.repository.mapper.StudioCheckSettleRecordMapper;
import com.jiejing.mbp.MapperRepoService;
import org.springframework.stereotype.Service;
/**
* <p>
* 场馆对账记录 服务实现类
* </p>
*
* @author chengyubing, created on 2024-04-07
*/
@Service
public class StudioCheckSettleRecordRpService extends MapperRepoService<Long, StudioCheckSettleRecord, StudioCheckSettleRecordMapper> {
}
...@@ -24,7 +24,9 @@ import com.jiejing.fitness.finance.repository.mapper.StudioMerchantApplyMapper; ...@@ -24,7 +24,9 @@ import com.jiejing.fitness.finance.repository.mapper.StudioMerchantApplyMapper;
import com.jiejing.fitness.finance.repository.query.PageStudioMerchantApplyQuery; import com.jiejing.fitness.finance.repository.query.PageStudioMerchantApplyQuery;
import com.jiejing.mbp.MapperRepoService; import com.jiejing.mbp.MapperRepoService;
import com.jiejing.paycenter.common.enums.common.OpenStateEnums; import com.jiejing.paycenter.common.enums.common.OpenStateEnums;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -35,6 +37,7 @@ import org.springframework.stereotype.Service; ...@@ -35,6 +37,7 @@ import org.springframework.stereotype.Service;
* *
* @author chengyubing, created on 2024-03-05 * @author chengyubing, created on 2024-03-05
*/ */
@Slf4j
@Service @Service
public class StudioMerchantApplyRpService extends public class StudioMerchantApplyRpService extends
MapperRepoService<Long, StudioMerchantApply, StudioMerchantApplyMapper> { MapperRepoService<Long, StudioMerchantApply, StudioMerchantApplyMapper> {
...@@ -102,4 +105,8 @@ public class StudioMerchantApplyRpService extends ...@@ -102,4 +105,8 @@ public class StudioMerchantApplyRpService extends
return Optional.ofNullable(count).orElse(0); return Optional.ofNullable(count).orElse(0);
} }
public List<StudioMerchantApply> listByMinId(Long minId, Long merchantId, Integer size) {
return this.baseMapper.listByMinId(minId, merchantId, size);
}
} }
...@@ -14,9 +14,15 @@ ...@@ -14,9 +14,15 @@
package com.jiejing.fitness.finance.repository.service; package com.jiejing.fitness.finance.repository.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiejing.fitness.finance.repository.entity.StudioSettleRecord; import com.jiejing.fitness.finance.repository.entity.StudioSettleRecord;
import com.jiejing.fitness.finance.repository.mapper.StudioSettleRecordMapper; import com.jiejing.fitness.finance.repository.mapper.StudioSettleRecordMapper;
import com.jiejing.mbp.MapperRepoService; 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; import org.springframework.stereotype.Service;
/** /**
...@@ -27,6 +33,16 @@ import org.springframework.stereotype.Service; ...@@ -27,6 +33,16 @@ import org.springframework.stereotype.Service;
* @author chengyubing, created on 2024-04-07 * @author chengyubing, created on 2024-04-07
*/ */
@Service @Service
public class StudioSettleRecordRpService extends MapperRepoService<Long, StudioSettleRecord, StudioSettleRecordMapper> { public class StudioSettleRecordRpService extends
MapperRepoService<Long, StudioSettleRecord, StudioSettleRecordMapper> {
} 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());
List<StudioSettleRecord> list = this.baseMapper.selectList(wrapper);
return Optional.ofNullable(list).orElse(new ArrayList<>()).stream().findFirst().orElse(null);
}
}
\ No newline at end of file
...@@ -57,7 +57,8 @@ public class GeneratorServiceEntity { ...@@ -57,7 +57,8 @@ public class GeneratorServiceEntity {
// "brand_cashier_record" // "brand_cashier_record"
// "bank", // "bank",
// "branch_bank", // "branch_bank",
"studio_settle_record" // "studio_settle_record",
"studio_check_settle_record"
}; };
/** /**
......
...@@ -9,7 +9,6 @@ import com.jiejing.fitness.finance.service.pay.PayService; ...@@ -9,7 +9,6 @@ import com.jiejing.fitness.finance.service.pay.PayService;
import com.jiejing.paycenter.common.event.MerchantEvent; import com.jiejing.paycenter.common.event.MerchantEvent;
import com.jiejing.paycenter.common.event.PayEvent; import com.jiejing.paycenter.common.event.PayEvent;
import com.jiejing.paycenter.common.event.RefundEvent; import com.jiejing.paycenter.common.event.RefundEvent;
import com.jiejing.paycenter.common.event.SettleEvent;
import com.xiaomai.event.annotation.EventHandler; import com.xiaomai.event.annotation.EventHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
...@@ -67,17 +66,6 @@ public class ListenerService { ...@@ -67,17 +66,6 @@ public class ListenerService {
} }
} }
@EventHandler(value = SettleEvent.class, binder = "biz-kafka", maxAttempts = MAX_RETRY)
public void refundEventCallback(SettleEvent event, @Header(DELIVERY_ATTEMPT) int retryNum) {
try {
log.info("start process settle event {}", JSON.toJSONString(event));
payService.settleCallback(event);
} catch (Exception e) {
log.info("process settle event fail {}", JSON.toJSONString(event), e);
}
}
@EventHandler(value = RefundEvent.class, binder = "biz-kafka", maxAttempts = MAX_RETRY) @EventHandler(value = RefundEvent.class, binder = "biz-kafka", maxAttempts = MAX_RETRY)
public void refundEventCallback(RefundEvent event, @Header(DELIVERY_ATTEMPT) int retryNum) { public void refundEventCallback(RefundEvent event, @Header(DELIVERY_ATTEMPT) int retryNum) {
try { try {
......
...@@ -2,11 +2,11 @@ package com.jiejing.fitness.finance.service.pay; ...@@ -2,11 +2,11 @@ package com.jiejing.fitness.finance.service.pay;
import com.jiejing.fitness.finance.service.pay.params.StudioMerchantPayParams; import com.jiejing.fitness.finance.service.pay.params.StudioMerchantPayParams;
import com.jiejing.fitness.finance.service.pay.params.BrandMerchantRefundParams; import com.jiejing.fitness.finance.service.pay.params.BrandMerchantRefundParams;
import com.jiejing.paycenter.common.event.SettleEvent;
import com.jiejing.paycenter.common.model.vo.PayVO; import com.jiejing.paycenter.common.model.vo.PayVO;
import com.jiejing.paycenter.api.pay.vo.RefundVO; import com.jiejing.paycenter.api.pay.vo.RefundVO;
import com.jiejing.paycenter.common.event.PayEvent; import com.jiejing.paycenter.common.event.PayEvent;
import com.jiejing.paycenter.common.event.RefundEvent; import com.jiejing.paycenter.common.event.RefundEvent;
import java.util.Date;
/** /**
* @author chengyubing * @author chengyubing
...@@ -45,10 +45,11 @@ public interface PayService { ...@@ -45,10 +45,11 @@ public interface PayService {
void refundCallback(RefundEvent event); void refundCallback(RefundEvent event);
/** /**
* 结算回调 * 对账
* *
* @param event 事件 * @param merchantId 商户ID
* @param settleDate 结算日
*/ */
void settleCallback(SettleEvent event); void checkSettle(Long merchantId, Date settleDate);
} }
package com.jiejing.fitness.finance.service.pay.impl; package com.jiejing.fitness.finance.service.pay.impl;
import com.jiejing.common.exception.BizException; import com.jiejing.common.exception.BizException;
import com.jiejing.common.utils.collection.CollectionUtil;
import com.jiejing.common.utils.time.TimeUtil;
import com.jiejing.fitness.enums.finance.BrandCashierTransStateEnum;
import com.jiejing.fitness.finance.repository.entity.StudioCashierRecord; import com.jiejing.fitness.finance.repository.entity.StudioCashierRecord;
import com.jiejing.fitness.finance.repository.entity.PartyToMerchant; 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.StudioCashierRecordRpService; import com.jiejing.fitness.finance.repository.service.StudioCashierRecordRpService;
import com.jiejing.fitness.finance.repository.service.PartyToMerchantRpService; import com.jiejing.fitness.finance.repository.service.PartyToMerchantRpService;
import com.jiejing.fitness.finance.repository.service.StudioMerchantApplyRpService;
import com.jiejing.fitness.finance.repository.service.StudioSettleRecordRpService;
import com.jiejing.fitness.finance.service.enums.FinanceErrorEnums; import com.jiejing.fitness.finance.service.enums.FinanceErrorEnums;
import com.jiejing.fitness.finance.service.pay.PayService; import com.jiejing.fitness.finance.service.pay.PayService;
import com.jiejing.fitness.finance.service.pay.convert.PayConvert; import com.jiejing.fitness.finance.service.pay.convert.PayConvert;
...@@ -13,7 +20,7 @@ import com.jiejing.fitness.finance.service.pay.params.StudioMerchantPayParams; ...@@ -13,7 +20,7 @@ import com.jiejing.fitness.finance.service.pay.params.StudioMerchantPayParams;
import com.jiejing.fitness.finance.service.rpc.MerchantRpcService; import com.jiejing.fitness.finance.service.rpc.MerchantRpcService;
import com.jiejing.fitness.finance.service.rpc.PayRpcService; import com.jiejing.fitness.finance.service.rpc.PayRpcService;
import com.jiejing.fitness.finance.service.rpc.StudioRpcService; import com.jiejing.fitness.finance.service.rpc.StudioRpcService;
import com.jiejing.paycenter.common.event.SettleEvent; import com.jiejing.paycenter.common.enums.common.TransStateEnums;
import com.jiejing.paycenter.common.model.vo.MerchantVO; import com.jiejing.paycenter.common.model.vo.MerchantVO;
import com.jiejing.paycenter.api.pay.request.PayRequest; import com.jiejing.paycenter.api.pay.request.PayRequest;
import com.jiejing.paycenter.api.pay.request.RefundPayRequest; import com.jiejing.paycenter.api.pay.request.RefundPayRequest;
...@@ -21,11 +28,17 @@ import com.jiejing.paycenter.common.model.vo.PayVO; ...@@ -21,11 +28,17 @@ import com.jiejing.paycenter.common.model.vo.PayVO;
import com.jiejing.paycenter.api.pay.vo.RefundVO; import com.jiejing.paycenter.api.pay.vo.RefundVO;
import com.jiejing.paycenter.common.event.PayEvent; import com.jiejing.paycenter.common.event.PayEvent;
import com.jiejing.paycenter.common.event.RefundEvent; import com.jiejing.paycenter.common.event.RefundEvent;
import com.jiejing.paycenter.common.model.vo.SettleVO;
import com.jiejing.studio.api.studio.vo.StudioVO; import com.jiejing.studio.api.studio.vo.StudioVO;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import java.util.function.Consumer;
import javax.annotation.Resource; import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
...@@ -54,6 +67,12 @@ public class PayServiceImpl implements PayService { ...@@ -54,6 +67,12 @@ public class PayServiceImpl implements PayService {
@Resource @Resource
private MerchantRpcService merchantRpcService; private MerchantRpcService merchantRpcService;
@Resource
private StudioSettleRecordRpService studioSettleRecordRpService;
@Resource
private StudioMerchantApplyRpService studioMerchantApplyRpService;
@Override @Override
public PayVO merchantPay(StudioMerchantPayParams params) { public PayVO merchantPay(StudioMerchantPayParams params) {
StudioVO studio = studioRpcService.getStudio(params.getStudioId()); StudioVO studio = studioRpcService.getStudio(params.getStudioId());
...@@ -115,10 +134,59 @@ public class PayServiceImpl implements PayService { ...@@ -115,10 +134,59 @@ public class PayServiceImpl implements PayService {
} }
@Override @Override
public void settleCallback(SettleEvent event) { public void checkSettle(Long merchantId, Date settleDate) {
// TODO Date endDate = null == settleDate ? TimeUtil.local().startOfDay(new Date()) : settleDate;
// 按照商户对总账 Date startDate = TimeUtil.local().plus(endDate, -15, ChronoUnit.DAYS);
// 按照场馆拆分结算记录 this.pageAndConsumer(merchantId, 200, apply -> {
StudioSettleRecord exist = studioSettleRecordRpService.getByMerchantIdAndSettleDate(
apply.getMerchantId(), endDate);
if (exist != null) {
return;
}
SettleVO vo = payRpcService.syncSettle(apply.getMerchantId(), endDate);
// TODO 对账
switch (TransStateEnums.getByCode(vo.getTransState())) {
case SUCCESS:
BigDecimal totalAmount = studioCashierRecordRpService.sumMerchantPaySuccess(apply.getMerchantId(),
startDate, endDate);
if (vo.getTransAmount().compareTo(totalAmount) != 0) {
}
break;
case FAIL:
break;
default:
break;
}
});
}
public void pageAndConsumer(Long merchantId, Integer batch, Consumer<StudioMerchantApply> consumer) {
Long minId = 0L;
log.info("consumer merchant apply start");
do {
List<StudioMerchantApply> list = studioMerchantApplyRpService.listByMinId(minId, merchantId, batch);
if (CollectionUtil.isEmpty(list)) {
break;
}
try {
list.forEach(apply -> {
try {
log.info("start consumer merchant apply {}, {}", apply.getMerchantId(), apply.getMerchantNo());
consumer.accept(apply);
log.info("end consumer merchant apply {}, {}", apply.getMerchantId(), apply.getMerchantNo());
} catch (Exception e) {
log.error("consumer apply fail apply {}, {}", apply.getMerchantId(), apply.getMerchantNo(), e);
}
});
} finally {
minId = list.get(list.size() - 1).getId();
}
} while (true);
log.info("consumer merchant apply finished");
} }
} }
...@@ -4,10 +4,13 @@ import com.jiejing.common.model.JsonResult; ...@@ -4,10 +4,13 @@ import com.jiejing.common.model.JsonResult;
import com.jiejing.paycenter.api.pay.PayApi; import com.jiejing.paycenter.api.pay.PayApi;
import com.jiejing.paycenter.api.pay.request.PayRequest; import com.jiejing.paycenter.api.pay.request.PayRequest;
import com.jiejing.paycenter.api.pay.request.RefundPayRequest; import com.jiejing.paycenter.api.pay.request.RefundPayRequest;
import com.jiejing.paycenter.api.pay.request.SyncSettleRequest;
import com.jiejing.paycenter.common.model.vo.PayVO; import com.jiejing.paycenter.common.model.vo.PayVO;
import com.jiejing.paycenter.api.pay.vo.RefundVO; import com.jiejing.paycenter.api.pay.vo.RefundVO;
import com.jiejing.paycenter.common.enums.common.TransStateEnums; import com.jiejing.paycenter.common.enums.common.TransStateEnums;
import com.jiejing.paycenter.common.enums.pay.PayStateEnums; import com.jiejing.paycenter.common.enums.pay.PayStateEnums;
import com.jiejing.paycenter.common.model.vo.SettleVO;
import java.util.Date;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -41,4 +44,12 @@ public class PayRpcService { ...@@ -41,4 +44,12 @@ public class PayRpcService {
} }
} }
public SettleVO syncSettle(Long merchantId, Date settleDate) {
JsonResult<SettleVO> result = payApi.syncSettle(SyncSettleRequest.builder()
.merchantId(merchantId)
.settleDate(settleDate)
.build());
result.assertSuccess();
return result.getResult();
}
} }
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