Commit 0ddceb8c by 程裕兵

feat:change module

parent 6a25cea4
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>fit-finance</artifactId> <artifactId>fit-finance</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>api</artifactId> <artifactId>finance-api</artifactId>
<name>api</name> <name>finance-api</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
<dependency> <dependency>
<groupId>com.jiejing.paycenter</groupId> <groupId>com.jiejing.paycenter</groupId>
<artifactId>paycenter-api</artifactId> <artifactId>paycenter-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>fit-finance</artifactId> <artifactId>fit-finance</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>api</artifactId> <artifactId>finance-api</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>service</artifactId> <artifactId>service</artifactId>
</dependency> </dependency>
<dependency> <dependency>
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>fit-finance</artifactId> <artifactId>fit-finance</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
...@@ -34,17 +34,17 @@ ...@@ -34,17 +34,17 @@
<dependencies> <dependencies>
<!-- ======================= fit-finance start ======================= --> <!-- ======================= fit-finance start ======================= -->
<dependency> <dependency>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>api</artifactId> <artifactId>finance-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>repository</artifactId> <artifactId>repository</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>service</artifactId> <artifactId>service</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>fit-finance</artifactId> <artifactId>fit-finance</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>api</artifactId> <artifactId>finance-api</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
......
...@@ -38,9 +38,14 @@ public interface StudioCashierRecordMapper extends XBaseMapper<StudioCashierReco ...@@ -38,9 +38,14 @@ public interface StudioCashierRecordMapper extends XBaseMapper<StudioCashierReco
BigDecimal sumMerchantPaySuccess(@Param("merchantId") Long merchantId, BigDecimal sumMerchantPaySuccess(@Param("merchantId") Long merchantId,
@Param("startTime") Date startTime, @Param("endTime") Date endTime); @Param("startTime") Date startTime, @Param("endTime") Date endTime);
BigDecimal sumMerchantRefundSuccess(@Param("merchantId") Long merchantId,
@Param("startTime") Date startTime, @Param("endTime") Date endTime);
List<StudioCashierRecord> sumMerchantPaySuccessGroupByStudioId(@Param("merchantId") Long merchantId, List<StudioCashierRecord> sumMerchantPaySuccessGroupByStudioId(@Param("merchantId") Long merchantId,
@Param("startTime") Date startTime, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
@Param("endTime") Date endTime);
List<StudioCashierRecord> sumMerchantRefundSuccessGroupByStudioId(@Param("merchantId") Long merchantId,
@Param("startTime") Date startTime, @Param("endTime") Date endTime);
StudioCashierStatisticVO statistic(@Param("query") PageBrandCashierRecordQuery query); StudioCashierStatisticVO statistic(@Param("query") PageBrandCashierRecordQuery query);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
select sum(actual_amount) select sum(actual_amount)
from studio_cashier_record from studio_cashier_record
where related_trans_no = #{payTransNo} where related_trans_no = #{payTransNo}
and trans_type = 'REFUND'
and trans_state in ('REFUNDING', 'REFUND_SUCCESS') and trans_state in ('REFUNDING', 'REFUND_SUCCESS')
</select> </select>
...@@ -32,6 +33,17 @@ ...@@ -32,6 +33,17 @@
from studio_cashier_record from studio_cashier_record
where merchant_id = #{merchantId} where merchant_id = #{merchantId}
and trans_state = 'PAY_SUCCESS' and trans_state = 'PAY_SUCCESS'
and trans_type = 'PAY'
and success_time >= #{startTime}
and success_time &lt; #{endTime}
</select>
<select id="sumMerchantRefundSuccess" resultType="java.math.BigDecimal">
select sum(actual_amount)
from studio_cashier_record
where merchant_id = #{merchantId}
and trans_type = 'REFUND'
and trans_state = 'REFUND_SUCCESS'
and success_time >= #{startTime} and success_time >= #{startTime}
and success_time &lt; #{endTime} and success_time &lt; #{endTime}
</select> </select>
...@@ -41,12 +53,25 @@ ...@@ -41,12 +53,25 @@
select studio_id, sum(actual_amount) as actual_amount select studio_id, sum(actual_amount) as actual_amount
from studio_cashier_record from studio_cashier_record
where merchant_id = #{merchantId} where merchant_id = #{merchantId}
and trans_type = 'PAY'
and trans_state = 'PAY_SUCCESS' and trans_state = 'PAY_SUCCESS'
and success_time >= #{startTime} and success_time >= #{startTime}
and success_time &lt; #{endTime} and success_time &lt; #{endTime}
group by studio_id group by studio_id
</select> </select>
<select id="sumMerchantRefundSuccessGroupByStudioId"
resultType="com.jiejing.fitness.finance.repository.entity.StudioCashierRecord">
select studio_id, sum(actual_amount) as actual_amount
from studio_cashier_record
where merchant_id = #{merchantId}
and trans_type = 'REFUND'
and trans_state = 'REFUND_SUCCESS'
and success_time >= #{startTime}
and success_time &lt; #{endTime}
group by studio_id
</select>
<select id="statistic" resultType="com.jiejing.fitness.finance.api.cashier.vo.StudioCashierStatisticVO"> <select id="statistic" resultType="com.jiejing.fitness.finance.api.cashier.vo.StudioCashierStatisticVO">
select sum(trans_amount) as total_trans_amount, sum(actual_amount) as total_actual_amount, select sum(trans_amount) as total_trans_amount, sum(actual_amount) as total_actual_amount,
sum(fee) as total_fee, count(id) as total sum(fee) as total_fee, count(id) as total
...@@ -61,6 +86,9 @@ ...@@ -61,6 +86,9 @@
<if test="query.orderNo != null and query.orderNo != ''"> <if test="query.orderNo != null and query.orderNo != ''">
and order_no = #{query.orderNo} and order_no = #{query.orderNo}
</if> </if>
<if test="query.businessNo != null and query.businessNo != ''">
and business_no = #{query.businessNo}
</if>
<if test="query.transNo != null and query.transNo != ''"> <if test="query.transNo != null and query.transNo != ''">
and trans_no = #{query.transNo} and trans_no = #{query.transNo}
</if> </if>
...@@ -71,7 +99,7 @@ ...@@ -71,7 +99,7 @@
and trans_state = #{query.transState} and trans_state = #{query.transState}
</if> </if>
<if test="query.transState == null or query.transState == ''"> <if test="query.transState == null or query.transState == ''">
and trans_state in ('PAY_SUCCESS', 'PAY_IN') and trans_state in ('PAY_SUCCESS', 'PAY_IN', 'REFUNDING', 'REFUND_SUCCESS', 'REFUND_FAIL')
</if> </if>
<if test="query.orderType != null and query.orderType != ''"> <if test="query.orderType != null and query.orderType != ''">
and order_type = #{query.orderType} and order_type = #{query.orderType}
......
...@@ -136,6 +136,11 @@ public class StudioCashierRecordRpService extends ...@@ -136,6 +136,11 @@ public class StudioCashierRecordRpService extends
.orElse(BigDecimal.ZERO); .orElse(BigDecimal.ZERO);
} }
public BigDecimal sumMerchantRefundSuccess(Long merchantId, Date startTime, Date endTime) {
return Optional.ofNullable(this.baseMapper.sumMerchantRefundSuccess(merchantId, startTime, endTime))
.orElse(BigDecimal.ZERO);
}
public Map<Long, BigDecimal> sumMerchantPaySuccessGroupByStudioId(Long merchantId, public Map<Long, BigDecimal> sumMerchantPaySuccessGroupByStudioId(Long merchantId,
Date startTime, Date endTime) { Date startTime, Date endTime) {
return Optional.ofNullable( return Optional.ofNullable(
...@@ -145,6 +150,15 @@ public class StudioCashierRecordRpService extends ...@@ -145,6 +150,15 @@ public class StudioCashierRecordRpService extends
.collect(Collectors.toMap(StudioCashierRecord::getStudioId, StudioCashierRecord::getActualAmount)); .collect(Collectors.toMap(StudioCashierRecord::getStudioId, StudioCashierRecord::getActualAmount));
} }
public Map<Long, BigDecimal> sumMerchantRefundSuccessGroupByStudioId(Long merchantId,
Date startTime, Date endTime) {
return Optional.ofNullable(
this.baseMapper.sumMerchantRefundSuccessGroupByStudioId(merchantId, startTime, endTime))
.orElse(new ArrayList<>(1))
.stream()
.collect(Collectors.toMap(StudioCashierRecord::getStudioId, StudioCashierRecord::getActualAmount));
}
public Page<StudioCashierRecord> pageMerchantPaySuccess(Long merchantId, Date startTime, Date endTime, public Page<StudioCashierRecord> pageMerchantPaySuccess(Long merchantId, Date startTime, Date endTime,
Integer current, Integer size) { Integer current, Integer size) {
QueryWrapper<StudioCashierRecord> wrapper = new QueryWrapper<>(); QueryWrapper<StudioCashierRecord> wrapper = new QueryWrapper<>();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>fit-finance</artifactId> <artifactId>fit-finance</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.jiejing.fitness.finance</groupId> <groupId>com.jiejing.fitness</groupId>
<artifactId>repository</artifactId> <artifactId>repository</artifactId>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -246,8 +246,12 @@ public class PayConvert { ...@@ -246,8 +246,12 @@ public class PayConvert {
} }
public static List<StudioSettleRecord> convertStudioSettle(MerchantSettleRecord record, public static List<StudioSettleRecord> convertStudioSettle(MerchantSettleRecord record,
Map<Long, BigDecimal> studioTransAmountMap, Map<Long, StudioVO> studioMap) { Map<Long, BigDecimal> studioPayAmountMap, Map<Long, BigDecimal> studioRefundAmountMap,
return studioTransAmountMap.keySet().stream().map(studioId -> StudioSettleRecord.builder() Map<Long, StudioVO> studioMap) {
// A场馆支付了100,B场馆支付了0,B场馆发起退款-》成功。结算记录-》
// A场馆支付了0,B场馆支付了0,B场馆发起退款-》失败
// A场馆支付了100,B场馆支付了0,B场馆发起退款-》成功,A场馆发起退款100-》失败
return studioPayAmountMap.keySet().stream().map(studioId -> StudioSettleRecord.builder()
.id(IdWorker.getId()) .id(IdWorker.getId())
.parentId(record.getId()) .parentId(record.getId())
.studioId(studioId) .studioId(studioId)
...@@ -255,7 +259,8 @@ public class PayConvert { ...@@ -255,7 +259,8 @@ public class PayConvert {
.merchantId(record.getMerchantId()) .merchantId(record.getMerchantId())
.merchantNo(record.getMerchantNo()) .merchantNo(record.getMerchantNo())
.transState(record.getTransState()) .transState(record.getTransState())
.transAmount(studioTransAmountMap.getOrDefault(studioId, BigDecimal.ZERO)) .transAmount(MoneyUtil.subtract(studioPayAmountMap.getOrDefault(studioId, BigDecimal.ZERO),
studioRefundAmountMap.getOrDefault(studioId, BigDecimal.ZERO)))
.settleDate(record.getSettleDate()) .settleDate(record.getSettleDate())
.cardNo(record.getCardNo()) .cardNo(record.getCardNo())
.bankName(record.getBankName()) .bankName(record.getBankName())
......
...@@ -304,9 +304,14 @@ public class PayServiceImpl implements PayService { ...@@ -304,9 +304,14 @@ public class PayServiceImpl implements PayService {
// 对账 // 对账
SettleVO vo = payRpcService.syncSettle(apply.getMerchantId(), endDate); SettleVO vo = payRpcService.syncSettle(apply.getMerchantId(), endDate);
BigDecimal totalAmount = studioCashierRecordRpService.sumMerchantPaySuccess(apply.getMerchantId(),
BigDecimal totalPayAmount = studioCashierRecordRpService.sumMerchantPaySuccess(apply.getMerchantId(),
startDate, endDate); startDate, endDate);
log.info("settle vo is {}, local total amount is {}", JSON.toJSONString(vo), totalAmount); BigDecimal totalRefundAmount = studioCashierRecordRpService.sumMerchantRefundSuccess(apply.getMerchantId(), startDate, endDate);
// 没有钱包,退款金额只能从入账中扣,因此收款的钱必须大于等于退款的钱
BigDecimal totalAmount = MoneyUtil.subtract(totalPayAmount, totalRefundAmount);
log.info("settle vo is {}, local total amount is {}, total pay amount is {}, total refund amount is {}",
JSON.toJSONString(vo), totalAmount, totalPayAmount, totalRefundAmount);
if (BigDecimal.ZERO.compareTo(vo.getTransAmount()) == 0 if (BigDecimal.ZERO.compareTo(vo.getTransAmount()) == 0
&& BigDecimal.ZERO.compareTo(totalAmount) == 0) { && BigDecimal.ZERO.compareTo(totalAmount) == 0) {
// 没有交易 // 没有交易
...@@ -315,15 +320,18 @@ public class PayServiceImpl implements PayService { ...@@ -315,15 +320,18 @@ public class PayServiceImpl implements PayService {
if (vo.getTransAmount().compareTo(totalAmount) == 0) { if (vo.getTransAmount().compareTo(totalAmount) == 0) {
// 对账成功 // 对账成功
Map<Long, BigDecimal> studioTransAmountMap = studioCashierRecordRpService.sumMerchantPaySuccessGroupByStudioId( Map<Long, BigDecimal> studioPayAmountMap = studioCashierRecordRpService.sumMerchantPaySuccessGroupByStudioId(
apply.getMerchantId(), startDate, endDate);
Map<Long, BigDecimal> studioRefundAmountMap = studioCashierRecordRpService.sumMerchantRefundSuccessGroupByStudioId(
apply.getMerchantId(), startDate, endDate); apply.getMerchantId(), startDate, endDate);
Map<Long, StudioVO> studioMap = studioRpcService.mapStudio( Map<Long, StudioVO> studioMap = studioRpcService.mapStudio(
Lists.newArrayList(studioTransAmountMap.keySet())); Lists.newArrayList(studioPayAmountMap.keySet()));
transactionTemplate.executeWithoutResult(action -> { transactionTemplate.executeWithoutResult(action -> {
MerchantSettleRecord record = PayConvert.convertMerchantSettle(apply, vo); MerchantSettleRecord record = PayConvert.convertMerchantSettle(apply, vo);
merchantSettleRecordRpService.insert(record); merchantSettleRecordRpService.insert(record);
studioSettleRecordRpService.insertAll( studioSettleRecordRpService.insertAll(
PayConvert.convertStudioSettle(record, studioTransAmountMap, studioMap)); PayConvert.convertStudioSettle(record, studioPayAmountMap, studioRefundAmountMap, studioMap));
}); });
if (TransStateEnums.SUCCESS == TransStateEnums.getByCode(vo.getTransState())) { if (TransStateEnums.SUCCESS == TransStateEnums.getByCode(vo.getTransState())) {
// 结算成功,则更新收银流水状态为记录为入账成功 // 结算成功,则更新收银流水状态为记录为入账成功
......
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