Procházet zdrojové kódy

收费明细中的支付时间调整,停车费明细改为按日期拆分

lzm před 3 roky
rodič
revize
f655d74772

+ 5 - 3
sp-server/src/main/java/com/pj/api/wx/service/WxService.java

@@ -237,7 +237,6 @@ public class WxService {
         if (StrUtil.isNotEmpty(attachStr)) {
             Attach attach = JSONUtil.toBean(attachStr, Attach.class);
             List<PriceBO> cars = JSONUtil.toList(attach.getC(), PriceBO.class);
-            tbFeeStatisticsService.countParkFee(cars);//停车费统计
             for (PriceBO bo1 : cars) {
                 TbBusinessCar car = tbBusinessCarService.getById(bo1.getId());
                 BigDecimal price = bo1.getP();
@@ -248,7 +247,7 @@ public class WxService {
                 car.setPay(1).setMoney(car.getMoney().add(price)).setPayTime(payTime).setPayType(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType());
                 tbBusinessCarService.updateById(car);
             }
-            tbFeeDetailsService.chargeParkFee(cars, transactionId, outTradeNo);//添加cars的收费明细
+            tbFeeDetailsService.chargeParkFee(cars, transactionId, outTradeNo, payTime);//添加cars的收费明细
             String businessId = attach.getB();
             Date finalPayTime = payTime;
             if (StrUtil.isNotEmpty(businessId)) {
@@ -273,10 +272,13 @@ public class WxService {
                         }
                     });
                 }
-                tbFeeStatisticsService.countBusinessFee(items, transactionId, outTradeNo);//业务费统计
+                tbFeeDetailsService.chargeBusinessFee(items, transactionId, outTradeNo, payTime);//添加items的收费明细
+
+                items.forEach(tbBusinessItem -> tbBusinessItem.setPayStatus(1).setPayTime(now));
                 items.forEach(tbBusinessItem -> tbBusinessItem.setPayStatus(1).setPayTime(finalPayTime));
                 tbBusinessItemService.updateBatchById(items);
             }
+            tbFeeStatisticsService.addOrUpdateStatistic(payTime);//更新当前日期的日统计
             String a = attach.getA();
             if (StrUtil.isNotEmpty(a)) {//充值的======>
                 AccountChargeBO chargeBO = JSONUtil.toBean(a, AccountChargeBO.class);

+ 3 - 0
sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetailsMapper.java

@@ -5,6 +5,7 @@ import java.util.List;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.pj.project.tb_fee_details.statics.FeeTypeStatics;
+import com.pj.project.tb_fee_statistics.TbFeeStatistics;
 import org.apache.ibatis.annotations.Mapper;
 
 import com.pj.utils.so.*;
@@ -61,4 +62,6 @@ public interface TbFeeDetailsMapper extends BaseMapper<TbFeeDetails> {
 	List<FeeTypeStatics> itemTypeStatics(@Param("startDay") String startDay,@Param("endDay") String endDay);
 
     BigDecimal getTotalMoney(SoMap so);
+
+    List<TbFeeStatistics> getDayStatistics(@Param("toDay") String toDay);
 }

+ 7 - 0
sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetailsMapper.xml

@@ -142,5 +142,12 @@
         </where>
 	</select>
 
+    <select id="getDayStatistics" resultType="com.pj.project.tb_fee_statistics.TbFeeStatistics">
+		select  fee_type, sum(num) as num,sum(item_price) as tax_money, any_value(tax_rate) as tax_rate ,sum(tax_price) as taxes,sum(no_tax_price) as no_tax_money
+		from tb_fee_details
+		where DATE_FORMAT(pay_time, '%Y-%m-%d' ) = #{toDay}
+		group by fee_type
+	</select>
+
 
 </mapper>

+ 114 - 7
sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetailsService.java

@@ -21,6 +21,8 @@ import com.pj.api.wx.bo.PriceBO;
 import com.pj.current.config.MyConfig;
 import com.pj.current.config.PartConfig;
 import com.pj.current.satoken.StpUserUtil;
+import com.pj.project.relation_business_car.RelationBusinessCar;
+import com.pj.project.relation_business_car.RelationBusinessCarService;
 import com.pj.project.tb_business.TbBusiness;
 import com.pj.project.tb_business.TbBusinessService;
 import com.pj.project.tb_business_car.TbBusinessCar;
@@ -29,6 +31,8 @@ import com.pj.project.tb_business_item.TbBusinessItem;
 import com.pj.project.tb_fee_details.statics.FeeTypeStatics;
 import com.pj.project.tb_fee_statistics.TbFeeStatistics;
 import com.pj.project.tb_fee_statistics.TbFeeStatisticsService;
+import com.pj.project.tb_goods.TbGoods;
+import com.pj.project.tb_goods.TbGoodsService;
 import com.pj.project4sp.admin.SpAdmin;
 import com.pj.project4sp.global.BusinessException;
 import com.pj.project4sp.role.SpRole;
@@ -75,6 +79,10 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
     SpRoleMapper spRoleMapper;
     @Resource
     TbFeeStatisticsService tbFeeStatisticsService;
+    @Resource
+    private RelationBusinessCarService relationBusinessCarService;
+    @Resource
+    private TbGoodsService tbGoodsService;
 
     /**
      * 增
@@ -146,6 +154,15 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
         return list(qw);
     }
 
+    public List<TbFeeDetails> getByBusinessCarIdAndCarNoAndFeeTypeAndPayDay(String businessCarId, String carNo, Integer feeType, String payDay){
+        QueryWrapper<TbFeeDetails> qw = new QueryWrapper<>();
+        qw.eq("business_car_id", businessCarId);
+        qw.eq("car_no", carNo);
+        qw.eq("fee_type", feeType);
+        qw.eq("pay_day", payDay);
+        return list(qw);
+    }
+
     public TbFeeDetails findBuCarIdAndCarNoAndFeeTypeAndItemTypeName(String businessCarId, String carNo, Integer feeType, String itemTypeName){
         QueryWrapper<TbFeeDetails> qw = new QueryWrapper<>();
         qw.eq("business_car_id", businessCarId);
@@ -155,18 +172,29 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
         return getOne(qw);
     }
 
+    public List<TbFeeDetails> findByTransactionId(String transactionId){
+        QueryWrapper<TbFeeDetails> qw = new QueryWrapper<>();
+        qw.like("transaction_id", transactionId);
+        return list(qw);
+    }
 
-    public void chargeParkFee(List<PriceBO> cars, String transactionId, String outTradeNo) {
+
+    public void chargeParkFee(List<PriceBO> cars, String transactionId, String outTradeNo, Date now) {
         log.info("进入计算停车费:{}", JSONUtil.toJsonStr(cars));
+        List<TbFeeDetails> transList = this.findByTransactionId(transactionId);
+        if(transList.size() > 0){
+            log.error("========收费明细已生成==========:{}", transactionId);
+            return;
+        }
+        String payDay = DateUtil.format(now, "yyyy-MM-dd");
         for (PriceBO bo1 : cars) {
             if(bo1.getP().compareTo(BigDecimal.valueOf(0)) == 0){
                 continue;
             }
             TbBusinessCar car = tbBusinessCarService.getById(bo1.getId());
-
             BigDecimal paidMoney  = car.getMoney();
 
-            List<TbFeeDetails> oldFeeList = getByBusinessCarIdAndCarNoAndFeeType(car.getId(), car.getCarNo(), TbFeeDetails.fee.PARK_FEE.getCode());
+            List<TbFeeDetails> oldFeeList = getByBusinessCarIdAndCarNoAndFeeTypeAndPayDay(car.getId(), car.getCarNo(), TbFeeDetails.fee.PARK_FEE.getCode(), payDay);
             TbFeeDetails nightParkFee = new TbFeeDetails();
             TbFeeDetails dayParkFee = new TbFeeDetails();
             String transactionIdStr = "";
@@ -191,7 +219,7 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
             if(nightFeeNum.compareTo(BigDecimal.valueOf(0)) > 0){
                     nightParkFee.setNum(nightFeeNum.intValue()).setItemTypeName("夜间停车")
                             .setUnitPrice(baseNightPrice).setItemPrice(baseNightPrice.multiply(nightFeeNum));
-                    setFee(nightParkFee, car, transactionIdStr, outTradeNoStr);
+                    setFee(nightParkFee, car, transactionIdStr, outTradeNoStr, now);
                     saveOrUpdate(nightParkFee);
                     if(qr[1].compareTo(BigDecimal.valueOf(0)) == 0 && dayParkFee.getId() != null){
                         delete(Long.valueOf(dayParkFee.getId()));
@@ -199,15 +227,15 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
             }
             if(qr[1].compareTo(BigDecimal.valueOf(0)) > 0){
                 dayParkFee.setNum(1).setItemTypeName("白天停车").setUnitPrice(qr[1]).setItemPrice(qr[1]);
-                setFee(dayParkFee, car, transactionIdStr, outTradeNoStr);
+                setFee(dayParkFee, car, transactionIdStr, outTradeNoStr, now);
                 saveOrUpdate(dayParkFee);
             }
 
         }
     }
 
-    private void setFee(TbFeeDetails parkFee, TbBusinessCar car, String transactionId, String outTradeNo){
-        Date now = new Date();
+    private void setFee(TbFeeDetails parkFee, TbBusinessCar car, String transactionId, String outTradeNo, Date now){
+
         String nowStr = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
         String toDay = DateUtil.format(now, "yyyy-MM-dd");
         parkFee.setTaxRate(partConfig.getTaxRate());
@@ -224,6 +252,81 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
                 .setTransactionId(transactionId).setOutTradeNo(outTradeNo)
                 .setBusinessCarNo(car.getNo());
     }
+    public void chargeBusinessFee(List<TbBusinessItem> items, String transactionId, String outTradeNo, Date now) {
+        List<TbFeeDetails> transList = this.findByTransactionId(transactionId);
+        if(transList.size() > 0){
+            log.error("========收费明细已生成==========:{}", transactionId);
+            return;
+        }
+        String nowStr = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
+        String toDay = DateUtil.format(now, "yyyy-MM-dd");
+        for (TbBusinessItem item : items) {
+            Integer feeType = item.getPayType();
+            String itemType = item.getItemTypeName();
+            if (StrUtil.isNotEmpty(itemType)) {
+                if (itemType.contains("核酸")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.NUCLEIC_FEE.getCode();
+                } else if (itemType.contains("消毒") || itemType.contains("消杀")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.DISINFECT_FEE.getCode();
+                } else if (itemType.contains("装卸")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.STEVEDORE_FEE.getCode();
+                } else if (StrUtil.equals(itemType, "特殊车辆") || StrUtil.equals(itemType, "汽车吊")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.STEVEDORE_FEE.getCode();
+                } else if (itemType.contains("入场管理")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.MANAGE_FEE.getCode();
+                } else if (StrUtil.equals(itemType, "充电打冷")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.CHARGE_FEE.getCode();
+                }
+            }
+            Double taxRate = item.getTaxRate();
+            //添加此item的收费明细
+            TbBusiness business = tbBusinessService.getById(item.getBusinessId());
+            TbFeeDetails businessFeeDetail = new TbFeeDetails();
+            businessFeeDetail.setTaxRate(BigDecimal.valueOf(taxRate));
+            BigDecimal taxPrice = item.getTotal()
+                    .divide(BigDecimal.valueOf(1).add(businessFeeDetail.getTaxRate()), 2, BigDecimal.ROUND_HALF_UP)
+                    .multiply(businessFeeDetail.getTaxRate());
+            taxPrice = taxPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal noTaxPrice = item.getTotal().subtract(taxPrice);
+            noTaxPrice = noTaxPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
+
+            String carNo = business.getCardNo();
+            if (StrUtil.isEmpty(business.getCardNo())) {
+                carNo = business.getChinaCarNo();
+            }
+            TbGoods businessCfg = tbGoodsService.getById(business.getGoodsId());
+            if((TbGoods.LeaveEnum.BUSINESS_MONEY.getCode()==businessCfg.getChinaCarLeave() || TbGoods.LeaveEnum.APART_BUSINESS.getCode()==businessCfg.getChinaCarLeave())
+                    && TbGoods.LeaveEnum.BUSINESS_MONEY.getCode()!=businessCfg.getVietnamCarLeave() && TbGoods.LeaveEnum.APART_BUSINESS.getCode()!=businessCfg.getVietnamCarLeave()){
+                carNo = business.getChinaCarNo();
+            }
+            String businessCarIds = "";
+            String businessCarNos = "";
+            List<RelationBusinessCar> relation = relationBusinessCarService.findByBusinessId(item.getBusinessId());
+            for (RelationBusinessCar rela : relation) {
+                TbBusinessCar bt = tbBusinessCarService.getById(rela.getBusinessCarId());
+                if(StrUtil.contains(carNo, bt.getCarNo())){
+                    businessCarIds += bt.getId() + ",";
+                    businessCarNos += bt.getNo() + ",";
+                }
+            }
+            businessCarIds = StrUtil.sub(businessCarIds, 0, businessCarIds.length()-1);
+            businessCarNos = StrUtil.sub(businessCarNos, 0, businessCarNos.length()-1);
+            businessFeeDetail.setBusinessId(item.getBusinessId()).setBusinessNo(business.getNo())
+                    .setBusinessItemNo(item.getNo()).setBusinessCarId(businessCarIds).setBusinessCarNo(businessCarNos)
+                    .setCarNo(carNo)
+                    .setItemPrice(item.getTotal()).setUnitPrice(item.getItemPrice()).setNoTaxPrice(noTaxPrice).setTaxPrice(taxPrice)
+                    .setFeeType(feeType)
+                    .setItemTypeId(item.getItemTypeId()).setItemTypeName(item.getItemTypeName())
+                    .setItemId(item.getItemId()).setItemName(item.getItemName())
+                    .setPayDay(toDay).setPayType(3).setCreateTime(now)
+                    .setBusinessItemId(item.getId() + "")
+                    .setPickCustomerName(item.getPickCustomerName())
+                    .setIsSettle(1).setPayMode(1).setPayTime(nowStr).setWeight(business.getNetWeight())
+                    .setTransactionId(transactionId).setOutTradeNo(outTradeNo)
+                    .setNum(Integer.valueOf(item.getNum()));
+            this.saveOrUpdate(businessFeeDetail);
+        }
+    }
 
     public String export(SoMap so) throws Exception{
         Date now = new Date();
@@ -580,4 +683,8 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
         ew.eq("business_no",businessNo);
        return list(ew);
     }
+
+    public List<TbFeeStatistics> getDayStatistics(String toDay) {
+        return tbFeeDetailsMapper.getDayStatistics(toDay);
+    }
 }

+ 31 - 5
sp-server/src/main/java/com/pj/project/tb_fee_statistics/TbFeeStatisticsService.java

@@ -5,6 +5,7 @@ import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.*;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.date.Month;
 import cn.hutool.core.util.StrUtil;
@@ -129,8 +130,9 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
     }
 
 
-    public void countParkFee(List<PriceBO> cars) {
-        Date now = new Date();
+
+    public void countParkFee(List<PriceBO> cars, Date now) {
+
         String toDay = DateUtil.format(now, "yyyy-MM-dd");
         String thisYear = StrUtil.sub(toDay, 0, 4);
         String thisMonth = StrUtil.sub(toDay, 0, 7);
@@ -187,8 +189,8 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
     }
 
 
-    public void countBusinessFee(List<TbBusinessItem> items, String transactionId, String outTradeNo) {
-        Date now = new Date();
+    public void countBusinessFee(List<TbBusinessItem> items, String transactionId, String outTradeNo, Date now) {
+
         String nowStr = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
         String toDay = DateUtil.format(now, "yyyy-MM-dd");
         String thisYear = StrUtil.sub(toDay, 0, 4);
@@ -285,6 +287,30 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
         }
     }
 
+    /**
+     * 照搬收费明细到日统计
+     * */
+    public void  addOrUpdateStatistic(Date now){
+        String toDay = DateUtil.format(now, "yyyy-MM-dd");
+        String thisYear = StrUtil.sub(toDay, 0, 4);
+        String thisMonth = StrUtil.sub(toDay, 0, 7);
+        List<TbFeeStatistics> detailsStats = tbFeeDetailsService.getDayStatistics(toDay);
+        for (TbFeeStatistics stat : detailsStats) {
+            TbFeeStatistics statistics = this.getByDayAndFeeType(toDay, stat.getFeeType());
+            if (statistics == null) {
+                statistics = new TbFeeStatistics();
+            }
+            statistics.setFeeType(stat.getFeeType()).setDayTime(now)
+                    .setNum(stat.getNum()).setTaxMoney(stat.getTaxMoney()).setTaxRate(stat.getTaxRate())
+                    .setTaxes(stat.getTaxes()).setNoTaxMoney(stat.getNoTaxMoney())
+                    .setDay(toDay).setMonth(thisMonth).setYear(thisYear)
+                    .setPayType(3);
+            this.saveOrUpdate(statistics);
+        }
+
+
+    }
+
     public TbFeeStatistics updateParkNum(String day) {
         QueryWrapper<TbFeeDetails> qw = new QueryWrapper<>();
         qw.like("create_time", day);
@@ -392,7 +418,7 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
             String day = statistic.getDay();
             Integer feeType = statistic.getFeeType();
             QueryWrapper<TbFeeDetails> qw = new QueryWrapper<>();
-            qw.like("create_time", day).eq("fee_type", feeType);
+            qw.like("pay_time", day).eq("fee_type", feeType);
             List<TbFeeDetails> detailsList = tbFeeDetailsService.list(qw);
             BigDecimal totalPrice = new BigDecimal(0);
             BigDecimal totalTaxes = new BigDecimal(0);