Commit 3f4c105e by 程裕兵

feat:settle

parent 1be4c0ad
...@@ -40,14 +40,14 @@ import org.springframework.stereotype.Service; ...@@ -40,14 +40,14 @@ import org.springframework.stereotype.Service;
public class StudioSettleRecordRpService extends public class StudioSettleRecordRpService extends
MapperRepoService<Long, StudioSettleRecord, StudioSettleRecordMapper> { MapperRepoService<Long, StudioSettleRecord, StudioSettleRecordMapper> {
public StudioSettleRecord getByMerchantIdAndSettleDate(Long merchantId, Date settleDate) { public List<StudioSettleRecord> listByMerchantIdAndSettleDate(Long merchantId, Date settleDate) {
QueryWrapper<StudioSettleRecord> wrapper = new QueryWrapper<>(); QueryWrapper<StudioSettleRecord> wrapper = new QueryWrapper<>();
wrapper.eq(StudioSettleRecord.MERCHANT_ID, merchantId); wrapper.eq(StudioSettleRecord.MERCHANT_ID, merchantId);
wrapper.eq(StudioSettleRecord.SETTLE_DATE, settleDate); 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); wrapper.orderByDesc(StudioSettleRecord.ID);
List<StudioSettleRecord> list = this.baseMapper.selectList(wrapper); List<StudioSettleRecord> list = this.baseMapper.selectList(wrapper);
return Optional.ofNullable(list).orElse(new ArrayList<>()).stream().findFirst().orElse(null); return Optional.ofNullable(list).orElse(new ArrayList<>());
} }
public Page<StudioSettleRecord> page(PageStudioSettleQuery query) { public Page<StudioSettleRecord> page(PageStudioSettleQuery query) {
......
...@@ -272,4 +272,11 @@ public class PayConvert { ...@@ -272,4 +272,11 @@ public class PayConvert {
.updateTime(new Date()) .updateTime(new Date())
.build(); .build();
} }
public static StudioSettleRecord convertSettleToModify(SettleVO vo) {
return StudioSettleRecord.builder()
.transState(vo.getTransState())
.failMsg(vo.getFailMsg())
.updateTime(new Date()).build();
}
} }
...@@ -224,9 +224,10 @@ public class PayServiceImpl implements PayService { ...@@ -224,9 +224,10 @@ public class PayServiceImpl implements PayService {
Date startDate = TimeUtil.local().plus(endDate, -15, ChronoUnit.DAYS); Date startDate = TimeUtil.local().plus(endDate, -15, ChronoUnit.DAYS);
AtomicInteger failCount = new AtomicInteger(0); AtomicInteger failCount = new AtomicInteger(0);
this.pageAndConsumer(merchantId, 200, apply -> { this.pageAndConsumer(merchantId, 200, apply -> {
StudioSettleRecord exist = studioSettleRecordRpService.getByMerchantIdAndSettleDate( List<StudioSettleRecord> exist = studioSettleRecordRpService.listByMerchantIdAndSettleDate(
apply.getMerchantId(), endDate); apply.getMerchantId(), endDate);
if (exist != null) { if (CollectionUtil.isNotEmpty(exist) && exist.stream()
.anyMatch(e -> e.getTransState().equals(TransStateEnums.SUCCESS.getCode()))) {
return; return;
} }
SettleVO vo = payRpcService.syncSettle(apply.getMerchantId(), endDate); SettleVO vo = payRpcService.syncSettle(apply.getMerchantId(), endDate);
...@@ -246,8 +247,13 @@ public class PayServiceImpl implements PayService { ...@@ -246,8 +247,13 @@ public class PayServiceImpl implements PayService {
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(studioTransAmountMap.keySet()));
studioSettleRecordRpService.insertAll( if (CollectionUtil.isEmpty(exist)) {
PayConvert.convertSettle(apply, studioTransAmountMap, vo, studioMap)); 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);
}
if (TransStateEnums.SUCCESS == TransStateEnums.getByCode(vo.getTransState())) { if (TransStateEnums.SUCCESS == TransStateEnums.getByCode(vo.getTransState())) {
// 结算成功,则更新收银流水状态为记录为入账成功 // 结算成功,则更新收银流水状态为记录为入账成功
this.updatePayIn(apply.getMerchantId(), startDate, endDate); this.updatePayIn(apply.getMerchantId(), startDate, endDate);
......
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