123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- package com.qtzl.alterSales.manager.service;
-
- import cn.com.taiji.common.manager.net.http.ServiceHandleException;
- import cn.hutool.core.bean.BeanUtil;
- import com.alibaba.fastjson.JSON;
- import com.google.common.collect.Lists;
- import com.qtzl.alterSales.dao.entity.primary.AflApPayOrder;
- import com.qtzl.alterSales.dao.entity.primary.FssPaccountPay;
- import com.qtzl.alterSales.dao.entity.primary.WechatBillPayApply;
- import com.qtzl.alterSales.dao.entity.primary.WechatBillPaySuccess;
- import com.qtzl.alterSales.dao.entity.second.AflPaccountRefundCount;
- import com.qtzl.alterSales.dao.repo.jpa.primary.AflApPayOrderRepo;
- import com.qtzl.alterSales.dao.repo.jpa.primary.AflSupplementaryPayOrderRepo;
- import com.qtzl.alterSales.dao.repo.jpa.primary.FssPaccountPayRepo;
- import com.qtzl.alterSales.dao.repo.jpa.primary.FssPaccountRefundRepo;
- import com.qtzl.alterSales.dao.repo.jpa.primary.WechatBillPayApplyRepo;
- import com.qtzl.alterSales.dao.repo.jpa.primary.WechatBillPaySuccessRepo;
- import com.qtzl.alterSales.dao.repo.jpa.second.AflPaccountRefundCountRepo;
- import com.qtzl.alterSales.manager.enums.VehiclePlateColorEnum;
- import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
- import com.qtzl.alterSales.manager.model.protocol.sales.FssPaccountPayResultFindByPayIdResponse;
- import com.qtzl.alterSales.manager.vo.AflPaccountRefundCountFindVo;
- import com.qtzl.alterSales.manager.vo.VehicleAgreementNumBillsVo;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
-
- import javax.annotation.Resource;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
-
- /***
- * <p>
- * 选装-原始流水 service
- * </p>
- * @author hou yi
- * {@code @date} 2023/10/12 11:43
- **/
- @Service
- public class FssPaccountPayServiceImpl implements FssPaccountPayService {
-
- private static final Logger log = LoggerFactory.getLogger(FssPaccountPayServiceImpl.class);
-
- @Resource
- private FssPaccountPayRepo paccountPayRepo;
- @Resource
- private AflPaccountRefundCountRepo aflPaccountRefundCountRepo;
- @Resource
- private FssPaccountRefundRepo fssPaccountRefundRepo;
-
- @Resource
- private AflSupplementaryPayOrderRepo supplementaryPayOrderRepo;
- @Resource
- private WechatBillPayApplyRepo wechatBillPayApplyRepo;
-
- @Resource
- private WechatBillPaySuccessRepo successRepo;
- @Resource
- private AflApPayOrderRepo apPayOrderRepo;
-
-
- @Override
- public List<VehicleAgreementNumBillsVo> getAgreementBills(String plateNumber, Integer plateColor) throws ServiceHandleException {
- if (StringUtils.isEmpty(plateNumber) || null == plateColor) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请指定车牌号、车牌颜色");
- }
- List<FssPaccountPay> agreementBills = paccountPayRepo.findByVehicleId(plateNumber + "_" + plateColor);
- if (CollectionUtils.isEmpty(agreementBills)) {
- return Lists.newArrayList();
- }
- /* // 过滤掉已生成补缴单的流水
- final List<String> payIds = agreementBills.stream().map(FssPaccountPay::getPayId).toList();
- final List<AflSupplementaryPayOrder> orders = supplementaryPayOrderRepo.findAll((root, query, cb) -> query
- .where(
- root.<String>get("payId").in(payIds)
- ).getRestriction());
- if (!CollectionUtils.isEmpty(orders)) {
- final List<String> orderPayIds = orders.stream().map(AflSupplementaryPayOrder::getPayId).toList();
- agreementBills = agreementBills.stream().filter(vo -> !orderPayIds.contains(vo.getPayId())).toList();
- }*/
- return toVo(agreementBills);
- }
-
- @Override
- public List<VehicleAgreementNumBillsVo> findByPayId(List<String> payIds) {
- if (CollectionUtils.isEmpty(payIds)) {
- return Lists.newArrayList();
- }
- return toVo(paccountPayRepo.findByPayIdIn(payIds));
- }
-
- @Override
- public void count(int day) throws ServiceHandleException {
- // 获取当前日期前一天的日期
- LocalDate localDate = LocalDate.now().minusDays(day);//1代表提前多少天
- String yesterday = localDate.toString();
- System.out.println("当前导入记录日期=" + yesterday);
- Integer i = aflPaccountRefundCountRepo.findByToDay(yesterday.replaceAll("-", ""));
- if (i != null && i > 0) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当前n+" + day + "天记录已存在");
- }
- List<Map<String, Object>> countTotal = paccountPayRepo.findCountTotal(yesterday + " 00:00:00", yesterday + " " +
- "23:59:59");
- List<AflPaccountRefundCountFindVo> list = new ArrayList<AflPaccountRefundCountFindVo>();
- for (Map<String, Object> stringObjectMap : countTotal) {
- AflPaccountRefundCountFindVo aflPaccountRefundCountVo =
- JSON.parseObject(JSON.toJSONString(stringObjectMap), AflPaccountRefundCountFindVo.class);
- list.add(aflPaccountRefundCountVo);
- }
- if (list == null || list.size() < 1) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当前n+" + day + "天记录无数据");
- }
- log.info("本次处理数据:{}", JSON.toJSON(list));
- AflPaccountRefundCount bydAflPaccountRefundCount = null;
- for (AflPaccountRefundCountFindVo aflPaccountRefundCountVo : list) {
- AflPaccountRefundCount aflPaccountRefundCount = new AflPaccountRefundCount();
- Long refundMoney = fssPaccountRefundRepo.findByCountRefundMoney(aflPaccountRefundCountVo.getAgentId(),
- aflPaccountRefundCountVo.getAccountDate());
- BeanUtils.copyProperties(aflPaccountRefundCountVo, aflPaccountRefundCount);
- aflPaccountRefundCount.setRefundMoney(refundMoney);
- if (!StringUtils.isEmpty(aflPaccountRefundCountVo.getAccountDate())) {
- String accountDate = aflPaccountRefundCountVo.getAccountDate().replaceAll("-", "");
- Integer newAccountDate = Integer.parseInt(accountDate);
- aflPaccountRefundCount.setAccountDate(newAccountDate);
- }
- if ("52010188999".equals(aflPaccountRefundCount.getAgentId()) && aflPaccountRefundCount.getAccountDate() != null) {
- bydAflPaccountRefundCount = aflPaccountRefundCount;
- AflPaccountRefundCount bydNewAflPaccountRefundCount = aflPaccountRefundCountRepo.finByDateAndAgentId(
- "52010188930", aflPaccountRefundCount.getAccountDate());
- if (bydNewAflPaccountRefundCount != null) {
- if (bydAflPaccountRefundCount.getMoneyTotal() != null) {
- bydNewAflPaccountRefundCount.setMoneyTotal(bydNewAflPaccountRefundCount.getMoneyTotal() + bydAflPaccountRefundCount.getMoneyTotal());
- }
- if (bydAflPaccountRefundCount.getRefundMoney() != null) {
- bydNewAflPaccountRefundCount.setRefundMoney(bydNewAflPaccountRefundCount.getRefundMoney() + bydAflPaccountRefundCount.getRefundMoney());
- }
- if (bydAflPaccountRefundCount.getCollectMoney() != null) {
- bydNewAflPaccountRefundCount.setCollectMoney(bydNewAflPaccountRefundCount.getCollectMoney() + bydAflPaccountRefundCount.getCollectMoney());
- }
- if (bydAflPaccountRefundCount.getNumberTotal() != null) {
- bydNewAflPaccountRefundCount.setNumberTotal(bydNewAflPaccountRefundCount.getNumberTotal() + bydAflPaccountRefundCount.getNumberTotal());
- }
- aflPaccountRefundCountRepo.save(bydNewAflPaccountRefundCount);
- }
- continue;
- }
- if ("52010188930".equals(aflPaccountRefundCount.getAgentId()) && bydAflPaccountRefundCount != null) {
- if (bydAflPaccountRefundCount.getMoneyTotal() != null) {
- aflPaccountRefundCount.setMoneyTotal(aflPaccountRefundCount.getMoneyTotal() + bydAflPaccountRefundCount.getMoneyTotal());
- }
- if (bydAflPaccountRefundCount.getRefundMoney() != null) {
- aflPaccountRefundCount.setRefundMoney(aflPaccountRefundCount.getRefundMoney() + bydAflPaccountRefundCount.getRefundMoney());
- }
- if (bydAflPaccountRefundCount.getCollectMoney() != null) {
- aflPaccountRefundCount.setCollectMoney(aflPaccountRefundCount.getCollectMoney() + bydAflPaccountRefundCount.getCollectMoney());
- }
- if (bydAflPaccountRefundCount.getNumberTotal() != null) {
- aflPaccountRefundCount.setCollectMoney(aflPaccountRefundCount.getCollectMoney() + bydAflPaccountRefundCount.getCollectMoney());
- }
- }
- aflPaccountRefundCount.setId(UUID.randomUUID().toString().replace("-", ""));
- aflPaccountRefundCount.setUpdateTime(LocalDateTime.now());
- aflPaccountRefundCount.setInsertTime(LocalDateTime.now());
- aflPaccountRefundCountRepo.save(aflPaccountRefundCount);
- }
- }
-
-
- /**
- * 更新统计
- * @param day
- * @throws ServiceHandleException
- */
- @Override
- public void newCount(int day) throws ServiceHandleException {
- // 获取当前日期前一天的日期
- //1代表提前多少天
- LocalDate localDate = LocalDate.now().minusDays(day);
- String yesterday = localDate.toString();
- log.info("当前导入记录日期="+yesterday);
- List<Map<String, Object>> countTotal = paccountPayRepo.findCountTotal(yesterday+" 00:00:00",yesterday+" 23:59:59");
- List<AflPaccountRefundCountFindVo> list = new ArrayList<AflPaccountRefundCountFindVo>();
- for (Map<String, Object> stringObjectMap : countTotal) {
- AflPaccountRefundCountFindVo aflPaccountRefundCountVo = JSON.parseObject(JSON.toJSONString(stringObjectMap), AflPaccountRefundCountFindVo.class);
- list.add(aflPaccountRefundCountVo);
- }
- if (list==null||list.size()<1){
- log.error("当前n+"+day+"天记录无数据");
- return;
- // throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当前n+"+day+"天记录无数据");
- }
- log.info("本次处理数据:{}", JSON.toJSON(list));
- AflPaccountRefundCount bydAflPaccountRefundCount = null;
- for (AflPaccountRefundCountFindVo aflPaccountRefundCountVo : list) {
- Integer newAccountDate1 =null;
- if (!StringUtils.isEmpty(aflPaccountRefundCountVo.getAccountDate())){
- String accountDate=aflPaccountRefundCountVo.getAccountDate().replaceAll("-","");
- newAccountDate1 = Integer.parseInt(accountDate);
- }
- AflPaccountRefundCount aflPaccountRefundCount= null;
- if("52010188999".equals(aflPaccountRefundCountVo.getAgentId())&&newAccountDate1!=null){
- aflPaccountRefundCount= aflPaccountRefundCountRepo.finByDateAndAgentId("52010188930",newAccountDate1);
- }else {
- aflPaccountRefundCount= aflPaccountRefundCountRepo.finByDateAndAgentId(aflPaccountRefundCountVo.getAgentId(),newAccountDate1);
- }
- if (aflPaccountRefundCount==null){
- aflPaccountRefundCount = new AflPaccountRefundCount();
- }
- Long refundMoney = fssPaccountRefundRepo.findByCountRefundMoney(aflPaccountRefundCountVo.getAgentId(),aflPaccountRefundCountVo.getAccountDate());
-
- aflPaccountRefundCountVo.setId(aflPaccountRefundCount.getId());
- BeanUtils.copyProperties(aflPaccountRefundCountVo,aflPaccountRefundCount);
- aflPaccountRefundCount.setRefundMoney(refundMoney);
- if (!StringUtils.isEmpty(aflPaccountRefundCountVo.getAccountDate())){
- String accountDate=aflPaccountRefundCountVo.getAccountDate().replaceAll("-","");
- Integer newAccountDate = Integer.parseInt(accountDate);
- aflPaccountRefundCount.setAccountDate(newAccountDate);
- }
- if ("52010188999".equals(aflPaccountRefundCount.getAgentId())&&aflPaccountRefundCount.getAccountDate()!=null){
- bydAflPaccountRefundCount=aflPaccountRefundCount;
- AflPaccountRefundCount bydNewAflPaccountRefundCount= aflPaccountRefundCountRepo.finByDateAndAgentId("52010188930",aflPaccountRefundCount.getAccountDate());
- if (bydNewAflPaccountRefundCount!=null){
- if (bydAflPaccountRefundCount.getMoneyTotal()!=null){
- bydNewAflPaccountRefundCount.setMoneyTotal(bydNewAflPaccountRefundCount.getMoneyTotal()+bydAflPaccountRefundCount.getMoneyTotal());
- }
- if (bydAflPaccountRefundCount.getRefundMoney()!=null){
- bydNewAflPaccountRefundCount.setRefundMoney(bydNewAflPaccountRefundCount.getRefundMoney()+bydAflPaccountRefundCount.getRefundMoney());
- }
- if (bydAflPaccountRefundCount.getCollectMoney()!=null){
- bydNewAflPaccountRefundCount.setCollectMoney(bydNewAflPaccountRefundCount.getCollectMoney()+bydAflPaccountRefundCount.getCollectMoney());
- }
- if (bydAflPaccountRefundCount.getNumberTotal()!=null){
- bydNewAflPaccountRefundCount.setNumberTotal(bydNewAflPaccountRefundCount.getNumberTotal()+bydAflPaccountRefundCount.getNumberTotal());
- }
- aflPaccountRefundCountRepo.save(bydNewAflPaccountRefundCount);
- }
- continue;
- }
- if ("52010188930".equals(aflPaccountRefundCount.getAgentId())&&bydAflPaccountRefundCount!=null){
- if (bydAflPaccountRefundCount.getMoneyTotal()!=null){
- aflPaccountRefundCount.setMoneyTotal(aflPaccountRefundCount.getMoneyTotal()+bydAflPaccountRefundCount.getMoneyTotal());
- }
- if (bydAflPaccountRefundCount.getRefundMoney()!=null){
- aflPaccountRefundCount.setRefundMoney(aflPaccountRefundCount.getRefundMoney()+bydAflPaccountRefundCount.getRefundMoney());
- }
- if (bydAflPaccountRefundCount.getCollectMoney()!=null){
- aflPaccountRefundCount.setCollectMoney(aflPaccountRefundCount.getCollectMoney()+bydAflPaccountRefundCount.getCollectMoney());
- }
- if (bydAflPaccountRefundCount.getNumberTotal()!=null){
- aflPaccountRefundCount.setCollectMoney(aflPaccountRefundCount.getCollectMoney()+bydAflPaccountRefundCount.getCollectMoney());
- }
- }
- if (StringUtils.isEmpty(aflPaccountRefundCount.getId())){
- aflPaccountRefundCount.setId(UUID.randomUUID().toString().replace("-", ""));
- aflPaccountRefundCount.setInsertTime(LocalDateTime.now());
- }
- aflPaccountRefundCount.setUpdateTime(LocalDateTime.now());
-
- aflPaccountRefundCountRepo.save(aflPaccountRefundCount);
- }
- }
-
- private List<VehicleAgreementNumBillsVo> toVo(List<FssPaccountPay> payList) {
- if (CollectionUtils.isEmpty(payList)) {
- return Lists.newArrayList();
- }
- List<VehicleAgreementNumBillsVo> billsVos = Lists.newArrayList();
- VehicleAgreementNumBillsVo billsVo;
- for (FssPaccountPay bill : payList) {
- final LocalDateTime firstInsertTime = wechatBillPayApplyRepo.getFirstInsertTime(bill.getPayId());
- if (null == firstInsertTime) {
- // 过滤掉没有// 过滤掉没有轮扣过的流水
- continue;
- }
- billsVo = new VehicleAgreementNumBillsVo(bill.getPayId(), bill.getSceneTp(), bill.getReceiptAmt(),
- bill.getChargeTime());
- // 处理车牌号、车牌颜色
- if (!StringUtils.isEmpty(bill.getVehicleId()) && bill.getVehicleId().contains("_")) {
- final String[] vehicle = bill.getVehicleId().split("_");
- billsVo.setPlateNumber(vehicle[0]);
- billsVo.setPlateNumberColor(VehiclePlateColorEnum.find(Integer.parseInt(vehicle[1])).getColor());
- }
- // 处理出入口站名、停车场名称
- if (!StringUtils.isEmpty(bill.getTitle()) && null != bill.getSceneTp()) {
- final String[] titleSplit = bill.getTitle().split("[,,]");
- if (titleSplit.length != 5) {
- continue;
- }
- if (bill.getSceneTp().equals(2)) {
- // 停车场流水
- billsVo.setParkingLotName(titleSplit[3]);
- } else {
- // 非停车场流水的, 按照通行流水处理
- billsVo.setInboundName(titleSplit[2]);
- billsVo.setOutboundName(titleSplit[3]);
- }
- }
- billsVos.add(billsVo);
- }
- return billsVos;
- }
-
- @Override
- public FssPaccountPayResultFindByPayIdResponse findPaccountPayResultByPayId(String payId) throws ServiceHandleException {
- FssPaccountPay fssPaccountPay = paccountPayRepo.findByPayId(payId);
- if (fssPaccountPay == null) {
- throw UcServiceError.NOT_FOUND_DATA.toHandleException("未查询到数据");
- }
- FssPaccountPayResultFindByPayIdResponse response = new FssPaccountPayResultFindByPayIdResponse();
- BeanUtil.copyProperties(fssPaccountPay, response);
- response.setPayStatus(fssPaccountPay.getStatus());
- // 请款中的数据,查看是否存在扣款失败原因
- if (fssPaccountPay.getStatus().equals(2)) {
- final LocalDateTime firstInsertTime = wechatBillPayApplyRepo.getFirstInsertTime(payId);
- final WechatBillPayApply payApply = null == firstInsertTime ?
- null : wechatBillPayApplyRepo.findByPayIdAndInsertTime(payId, firstInsertTime);
- if (null != payApply) {
- response.setPayMsg(StringUtils.isEmpty(payApply.getErrCodeDes()) ? payApply.getResErrCodeDes() :
- payApply.getErrCodeDes());
- response.setWxOrderId(payApply.getOutTradeNo());
- }
- }
- //扣款成功,需返回微信支付订单号
- if (fssPaccountPay.getStatus().equals(1) && StringUtils.isNotBlank(fssPaccountPay.getWxOrderId())) {
- WechatBillPaySuccess paySuccess = successRepo.findByOutTradeNo(fssPaccountPay.getWxOrderId());
- if (null != paySuccess) {
- response.setTransactionId(paySuccess.getTransactionId());
- } else {
- AflApPayOrder aflApPayOrder = apPayOrderRepo.findByOrderNo(fssPaccountPay.getWxOrderId());
- if (null != aflApPayOrder) {
- response.setTransactionId(aflApPayOrder.getTransactionId());
- }
- }
- }
- return response;
- }
- }
|