|
@@ -131,46 +131,81 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
|
|
|
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);
|
|
|
+ qw.eq("car_no", carNo);
|
|
|
+ qw.eq("fee_type", feeType);
|
|
|
+ qw.eq("item_type_name", itemTypeName);
|
|
|
+ return getOne(qw);
|
|
|
+ }
|
|
|
|
|
|
- public void chargeParkFee(List<PriceBO> cars, String transactionId,String outTradeNo) {
|
|
|
- Date now = new Date();
|
|
|
- String nowStr = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
|
|
|
- String toDay = DateUtil.format(now, "yyyy-MM-dd");
|
|
|
+
|
|
|
+ public void chargeParkFee(List<PriceBO> cars, String transactionId) {
|
|
|
for (PriceBO bo1 : cars) {
|
|
|
if(bo1.getP().compareTo(BigDecimal.valueOf(0)) == 0){
|
|
|
continue;
|
|
|
}
|
|
|
TbBusinessCar car = tbBusinessCarService.getById(bo1.getId());
|
|
|
TbBusiness business = tbBusinessService.getById(car.getBusinessId());
|
|
|
- String carNo = car.getCarNo();
|
|
|
- TbFeeDetails parkFee = null;
|
|
|
-// if(business != null){
|
|
|
-// parkFee = getByBusinessIdAndCarNoAndFeeType(car.getBusinessId(), carNo, TbFeeDetails.fee.PARK_FEE.getCode());
|
|
|
-// } else {
|
|
|
-// parkFee = getByBusinessCarIdAndCarNoAndFeeType(car.getId(), carNo, TbFeeDetails.fee.PARK_FEE.getCode());
|
|
|
-// }
|
|
|
- if(parkFee == null){
|
|
|
- parkFee = new TbFeeDetails();
|
|
|
- parkFee.setTaxRate(partConfig.getTaxRate());
|
|
|
+ BigDecimal paidMoney = car.getMoney();
|
|
|
+
|
|
|
+ List<TbFeeDetails> oldFeeList = getByBusinessCarIdAndCarNoAndFeeType(car.getId(), car.getCarNo(), TbFeeDetails.fee.PARK_FEE.getCode());
|
|
|
+ TbFeeDetails nightParkFee = new TbFeeDetails();
|
|
|
+ TbFeeDetails dayParkFee = new TbFeeDetails();
|
|
|
+ String transactionIdStr = "";
|
|
|
+ for (TbFeeDetails oldFee : oldFeeList) {
|
|
|
+ if(!StrUtil.isEmpty(oldFee.getTransactionId())){
|
|
|
+ transactionIdStr = oldFee.getTransactionId();
|
|
|
+ }
|
|
|
+ if(StrUtil.equals(oldFee.getItemTypeName(), "白天停车")){
|
|
|
+ dayParkFee = oldFee;
|
|
|
+ }
|
|
|
+ if(StrUtil.equals(oldFee.getItemTypeName(), "夜间停车")){
|
|
|
+ nightParkFee = oldFee;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ transactionIdStr = transactionIdStr.equals("") ? transactionId : transactionIdStr + "," + transactionId;
|
|
|
+ BigDecimal baseNightPrice = partConfig.getBasePrice().add(partConfig.getExtraPrice());
|
|
|
+ BigDecimal[] qr = paidMoney.divideAndRemainder(baseNightPrice);//商和余数的数组,商为夜间停车次数,余数为白天停车费用。
|
|
|
+ BigDecimal nightFeeNum = qr[0];
|
|
|
+ if(nightFeeNum.compareTo(BigDecimal.valueOf(0)) > 0){
|
|
|
+ nightParkFee.setNum(nightFeeNum.intValue()).setItemTypeName("夜间停车")
|
|
|
+ .setUnitPrice(baseNightPrice).setItemPrice(baseNightPrice.multiply(nightFeeNum));
|
|
|
+ setFee(nightParkFee, car, business, transactionIdStr);
|
|
|
+ saveOrUpdate(nightParkFee);
|
|
|
+ if(qr[1].compareTo(BigDecimal.valueOf(0)) == 0 && dayParkFee.getId() != null){
|
|
|
+ delete(Long.valueOf(dayParkFee.getId()));
|
|
|
+ }
|
|
|
}
|
|
|
- BigDecimal taxPrice = bo1.getP().divide(BigDecimal.valueOf(1).add(parkFee.getTaxRate()),2, BigDecimal.ROUND_HALF_UP).multiply(parkFee.getTaxRate());
|
|
|
- BigDecimal noTaxPrice = bo1.getP().subtract(taxPrice);
|
|
|
- parkFee.setBusinessId(car.getBusinessId()).setBusinessCarId(car.getId())
|
|
|
- .setCarNo(car.getCarNo()).setOutTradeNo(outTradeNo)
|
|
|
- .setItemPrice(bo1.getP()).setUnitPrice(bo1.getP()).setNoTaxPrice(noTaxPrice).setTaxPrice(taxPrice)
|
|
|
- .setFeeType(TbFeeDetails.fee.PARK_FEE.getCode()).setItemTypeName("停车业务")
|
|
|
- .setPayDay(toDay).setPayType(3).setCreateTime(now)
|
|
|
- .setNum(1).setIsSettle(1).setPayMode(1).setPayTime(nowStr)
|
|
|
- .setTransactionId(transactionId)
|
|
|
- .setBusinessCarNo(car.getNo());
|
|
|
- if (business!=null){
|
|
|
- parkFee.setWeight(business.getNetWeight()).setBusinessNo(business.getNo());
|
|
|
+ if(qr[1].compareTo(BigDecimal.valueOf(0)) > 0){
|
|
|
+ dayParkFee.setNum(1).setItemTypeName("白天停车").setUnitPrice(qr[1]).setItemPrice(qr[1]);
|
|
|
+ setFee(dayParkFee, car, business, transactionIdStr);
|
|
|
+ saveOrUpdate(dayParkFee);
|
|
|
}
|
|
|
- saveOrUpdate(parkFee);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ private void setFee(TbFeeDetails parkFee, TbBusinessCar car, TbBusiness business, String transactionId){
|
|
|
+ Date now = new Date();
|
|
|
+ String nowStr = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
|
|
|
+ String toDay = DateUtil.format(now, "yyyy-MM-dd");
|
|
|
+ parkFee.setTaxRate(partConfig.getTaxRate());
|
|
|
+ BigDecimal taxPrice = parkFee.getItemPrice().divide(BigDecimal.valueOf(1).add(parkFee.getTaxRate()),2, BigDecimal.ROUND_HALF_UP).multiply(parkFee.getTaxRate());
|
|
|
+ BigDecimal noTaxPrice = parkFee.getItemPrice().subtract(taxPrice);
|
|
|
+ parkFee.setBusinessId(car.getBusinessId()).setBusinessCarId(car.getId())
|
|
|
+ .setCarNo(car.getCarNo())
|
|
|
+ .setNoTaxPrice(noTaxPrice).setTaxPrice(taxPrice)
|
|
|
+ .setFeeType(TbFeeDetails.fee.PARK_FEE.getCode())
|
|
|
+ .setPayDay(toDay).setPayType(3).setCreateTime(now)
|
|
|
+ .setIsSettle(1).setPayMode(1).setPayTime(nowStr)
|
|
|
+ .setTransactionId(transactionId)
|
|
|
+ .setBusinessCarNo(car.getNo());
|
|
|
+ if (business!=null){
|
|
|
+ parkFee.setWeight(business.getNetWeight()).setBusinessNo(business.getNo());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public String export(SoMap so) throws Exception{
|
|
|
Date now = new Date();
|