|
@@ -13,9 +13,11 @@ import com.pj.constants.business.CarEnum;
|
|
|
import com.pj.constants.business.FeeTypeEnum;
|
|
|
import com.pj.constants.business.GoodsEnum;
|
|
|
import com.pj.constants.business.PayEnum;
|
|
|
+import com.pj.current.config.SystemObject;
|
|
|
import com.pj.project.sync.SyncService;
|
|
|
import com.pj.project.sync.request.item.IOrderItem;
|
|
|
import com.pj.project.sync.response.IOrderPriceRes;
|
|
|
+import com.pj.project.sync.response.item.OrderPriceResultItem;
|
|
|
import com.pj.project.sync.response.item.PriceDetailItem;
|
|
|
import com.pj.project.tb_business.TbBusiness;
|
|
|
import com.pj.project.tb_business.TbBusinessService;
|
|
@@ -23,6 +25,8 @@ import com.pj.project.tb_business_car.TbBusinessCar;
|
|
|
import com.pj.project.tb_business_car.TbBusinessCarService;
|
|
|
import com.pj.project.tb_business_item.TbBusinessItem;
|
|
|
import com.pj.project.tb_business_item.TbBusinessItemService;
|
|
|
+import com.pj.project.tb_costomer.TbCostomer;
|
|
|
+import com.pj.project.tb_costomer.TbCostomerService;
|
|
|
import com.pj.project.tb_deduction_bind.TbDeductionBind;
|
|
|
import com.pj.project.tb_deduction_bind.TbDeductionBindService;
|
|
|
import com.pj.project.tb_deduction_record.TbDeductionRecord;
|
|
@@ -33,6 +37,7 @@ import com.pj.project.tb_goods.TbGoods;
|
|
|
import com.pj.project.tb_goods.TbGoodsService;
|
|
|
import com.pj.project.tb_invoice_order.TbInvoiceOrder;
|
|
|
import com.pj.project.tb_invoice_order.TbInvoiceOrderService;
|
|
|
+import com.pj.project.tb_item.TbItemService;
|
|
|
import com.pj.utils.AesUtil;
|
|
|
import com.pj.utils.cache.RedisUtil;
|
|
|
import com.pj.utils.sg.NbUtil;
|
|
@@ -62,8 +67,7 @@ public class AutomaticPay {
|
|
|
TbBusinessCarService tbBusinessCarService;
|
|
|
@Resource
|
|
|
TbBusinessService tbBusinessService;
|
|
|
- @Resource
|
|
|
- TbDeductionBindService deductionBindService;
|
|
|
+
|
|
|
@Resource
|
|
|
TbBusinessItemService tbBusinessItemService;
|
|
|
@Resource
|
|
@@ -72,40 +76,21 @@ public class AutomaticPay {
|
|
|
TbAccountService tbAccountService;
|
|
|
@Resource
|
|
|
TbInvoiceOrderService invoiceOrderService;
|
|
|
- @Resource
|
|
|
- TbGoodsService tbGoodsService;
|
|
|
- @Resource
|
|
|
- @Lazy
|
|
|
- private TbDeductionBindService tbDeductionBindService;
|
|
|
+
|
|
|
@Resource
|
|
|
private TbFeeStatisticsService tbFeeStatisticsService;
|
|
|
|
|
|
@Resource
|
|
|
private SyncService syncService;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 异步解绑入口
|
|
|
- *
|
|
|
- * @param plate
|
|
|
- */
|
|
|
- @Async
|
|
|
- public void unbindRun(String plate) {
|
|
|
- if (isExistTask(null, plate)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- autoUnbindCarByPlate(plate);
|
|
|
- delRedisTask(null, plate);
|
|
|
-// TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(plate);
|
|
|
-// TbDeductionBind bind = tbDeductionBindService.findTheLastUnBindCar(plate);
|
|
|
- }
|
|
|
+ @Resource
|
|
|
+ private TbCostomerService tbCostomerService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 生成扣费记录
|
|
|
*/
|
|
|
public TbDeductionRecord createTbDeductionRecord(TbFeeDetails feeDetails, BigDecimal originalMoney, BigDecimal balance,
|
|
|
- String customerId,String customerName,String plate, String businessCarId, FeeTypeEnum feeTypeEnum) {
|
|
|
+ String customerId, String customerName, String plate, String businessCarId, FeeTypeEnum feeTypeEnum) {
|
|
|
TbDeductionRecord deductionRecord = BeanUtil.toBean(feeDetails, TbDeductionRecord.class);
|
|
|
BigDecimal itemPrice = feeDetails.getItemPrice();
|
|
|
String no = feeDetails.getBusinessNo();
|
|
@@ -115,7 +100,7 @@ public class AutomaticPay {
|
|
|
.setDeductMoney(itemPrice)
|
|
|
.setBusinessNo(no)
|
|
|
.setOriginalMoney(originalMoney).setBusinessId(feeDetails.getBusinessId())
|
|
|
- .setTotalMoney(balance).setBusinessCarId(businessCarId)
|
|
|
+ .setTotalMoney(originalMoney.subtract(itemPrice)).setBusinessCarId(businessCarId)
|
|
|
.setFeeDetailsId(feeDetails.getId()).setItemName(feeDetails.getItemName())
|
|
|
.setItemTypeId(feeDetails.getItemTypeId()).setItemTypeName(feeDetails.getItemTypeName())
|
|
|
.setReviewStatus(0).setFeeType(feeTypeEnum.getCode()).setFeeTypeName(feeTypeEnum.getDesc())
|
|
@@ -123,239 +108,12 @@ public class AutomaticPay {
|
|
|
.setFeeDetailsId(feeDetails.getId())
|
|
|
.setBusinessNo(feeDetails.getBusinessNo());
|
|
|
deductionRecord.insert();
|
|
|
- String preNo= DateUtil.format(new Date(),"yyyyMMddHHmm")+RandomUtil.randomString(5);
|
|
|
+ String preNo = DateUtil.format(new Date(), "yyyyMMddHHmm") + RandomUtil.randomString(5);
|
|
|
feeDetails.setPreOrderNum(preNo);
|
|
|
tbFeeDetailsService.updateById(feeDetails);
|
|
|
return deductionRecord;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 更新停车费状态
|
|
|
- */
|
|
|
- private void updateTbBusinessCar(TbBusinessCar car) {
|
|
|
- if (car == null) return;
|
|
|
- car.setPay(1).setPayTime(new Date()).setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType());
|
|
|
- car.updateById();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新停车费状态
|
|
|
- */
|
|
|
- private void updateTbBusinessCars(List<TbBusinessCar> cars) {
|
|
|
- if (cars == null) return;
|
|
|
- for (TbBusinessCar car : cars) {
|
|
|
- updateTbBusinessCar(car);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成开票订单信息
|
|
|
- *
|
|
|
- * @param tbBusiness
|
|
|
- */
|
|
|
- private void createTbInvoiceOrder(TbBusiness tbBusiness, List<TbBusinessCar> cars, BigDecimal parkingFee,
|
|
|
- String plate, String customerId, String no, boolean isOut) {
|
|
|
- TbInvoiceOrder invoiceOrder = new TbInvoiceOrder();
|
|
|
- List<String> businessNameList = new ArrayList<>();
|
|
|
- List<String> businessNoList = new ArrayList<>();
|
|
|
- List<String> carNos = new ArrayList<>();
|
|
|
- businessNoList.add(tbBusiness.getNo());
|
|
|
- carNos.add(plate);
|
|
|
- businessNameList.add(tbBusiness.getGoodsName());
|
|
|
- if (cars != null) {
|
|
|
- for (TbBusinessCar car : cars) {
|
|
|
- if (isOut) {
|
|
|
- if (CarEnum.PayTypeEnum.FEE_TYPE.getType().equals(car.getPayType())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (!businessNameList.contains("停车费")) {
|
|
|
- businessNameList.add("停车费");
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (NbUtil.isNull(car.getCarNo()) || !car.getCarNo().equals(plate)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!businessNoList.contains(car.getNo())) {
|
|
|
- businessNoList.add(car.getNo());
|
|
|
- }
|
|
|
- if (!carNos.contains(car.getCarNo())) {
|
|
|
- carNos.add(car.getCarNo());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- String businessNameStr = businessNameList.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
- String businessNoStr = businessNoList.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
- String carNoStr = carNos.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
- BigDecimal billMoney = tbBusiness.getItemPrice();
|
|
|
- if (parkingFee != null) {
|
|
|
- billMoney = parkingFee.add(billMoney);
|
|
|
- }
|
|
|
- invoiceOrder.setBusinessName(businessNameStr).setBusinessNo(businessNoStr).setCarNo(carNoStr)
|
|
|
- .setTransactionId(null).setBillMoney(billMoney).setBusinessId(tbBusiness.getId())
|
|
|
- .setStatus(0).setCreateTime(new Date()).setCustomerId(customerId).setPreOrderNum(no);
|
|
|
- invoiceOrderService.save(invoiceOrder);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 无业务车辆收停车费生成发票信息
|
|
|
- */
|
|
|
- private void createTbInvoiceOrderPark(TbBusinessCar car, String customerId, String no) {
|
|
|
- TbInvoiceOrder invoiceOrder = new TbInvoiceOrder();
|
|
|
-
|
|
|
- invoiceOrder.setBusinessName("停车费").setBusinessNo(car.getNo()).setCarNo(car.getCarNo())
|
|
|
- .setTransactionId(null).setBillMoney(car.getMoney()).setBusinessId(null)
|
|
|
- .setStatus(0).setCreateTime(new Date()).setCustomerId(customerId).setPreOrderNum(no);
|
|
|
- invoiceOrderService.save(invoiceOrder);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 补录进场解绑逻辑
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- private void autoUnbindCarByPlate(String plate) {
|
|
|
- if (NbUtil.isNull(plate)) return;
|
|
|
- TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(plate);
|
|
|
- //离场逻辑
|
|
|
- if (tbBusinessCar != null) {
|
|
|
- if (doUnbindCarByPlate(tbBusinessCar)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- //进场逻辑
|
|
|
- TbDeductionBind bind = deductionBindService.getOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
|
|
|
- TbDeductionBind::getBindCar, plate).isNull(TbDeductionBind::getUnbindTime));
|
|
|
- if (bind != null) {
|
|
|
- TbDeductionRecord record = new TbDeductionRecord();
|
|
|
- Integer count = record.selectCount(new LambdaQueryWrapper<TbDeductionRecord>().like(
|
|
|
- TbDeductionRecord::getDeductionBindId, bind.getId()));
|
|
|
- if (count > 0) {
|
|
|
- bind.setUpdateBy("预充值自动缴费解绑");
|
|
|
- bind.setUpdateTime(new Date());
|
|
|
- bind.setUnbindTime(new Date());
|
|
|
- bind.updateById();
|
|
|
- } else {
|
|
|
- Integer buCount = tbBusinessService.count(new LambdaQueryWrapper<TbBusiness>().ne(
|
|
|
- TbBusiness::getPayStatus, 1)
|
|
|
- .between(TbBusiness::getCreateTime, bind.getBindTime(), NbUtil.getNow()));
|
|
|
- if (buCount > 0) {
|
|
|
- bind.setUpdateBy("预充值自动缴费解绑");
|
|
|
- bind.setUpdateTime(new Date());
|
|
|
- bind.setUnbindTime(new Date());
|
|
|
- bind.updateById();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 补录出场解绑逻辑
|
|
|
- *
|
|
|
- * @param tbBusinessCar
|
|
|
- */
|
|
|
- private boolean doUnbindCarByPlate(TbBusinessCar tbBusinessCar) {
|
|
|
- if (tbBusinessCar == null || tbBusinessCar.getRealOutTime() == null) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- TbDeductionBind bind = deductionBindService.getOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
|
|
|
- TbDeductionBind::getBindCar, tbBusinessCar.getCarNo())
|
|
|
- .lt(TbDeductionBind::getBindTime, tbBusinessCar.getRealOutTime())
|
|
|
- .isNull(TbDeductionBind::getUnbindTime));
|
|
|
- if (bind == null) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- bind.setUpdateBy("预充值自动缴费解绑");
|
|
|
- bind.setUpdateTime(new Date());
|
|
|
- bind.setUnbindTime(new Date());
|
|
|
- bind.updateById();
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 缓存任务,如果存在任务不继续往下执行
|
|
|
- *
|
|
|
- * @param businessId
|
|
|
- * @param plate
|
|
|
- * @return
|
|
|
- */
|
|
|
- private boolean isExistTask(String businessId, String plate) {
|
|
|
- String key = getRedisKey(businessId, plate);
|
|
|
- if (NbUtil.isNullStr(RedisUtil.get(key))) {
|
|
|
- RedisUtil.setBySECONDS(key, key, 5);
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- private void delRedisTask(String businessId, String plate) {
|
|
|
- String key = getRedisKey(businessId, plate);
|
|
|
- RedisUtil.del(key);
|
|
|
- }
|
|
|
-
|
|
|
- private String getRedisKey(String businessId, String plate) {
|
|
|
- if (NbUtil.isNullStr(businessId)) {
|
|
|
- businessId = "100";
|
|
|
- }
|
|
|
- if (NbUtil.isNullStr(plate)) {
|
|
|
- plate = "100";
|
|
|
- }
|
|
|
- String key = "autoPay:" + businessId + plate;
|
|
|
- return key;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 预付款支付停车费
|
|
|
- *
|
|
|
- * @param tbBusinessCar
|
|
|
- * @param now
|
|
|
- * @return
|
|
|
- */
|
|
|
- public boolean payPartMoney(TbBusinessCar tbBusinessCar, IOrderPriceRes orderPriceRes, Date now) {
|
|
|
- String carNo = tbBusinessCar.getCarNo();
|
|
|
- TbDeductionBind bind = tbDeductionBindService.getBindCarByPlate(carNo);
|
|
|
- //未绑定
|
|
|
- if (bind == null) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- TbAccount tbAccount = tbAccountService.getAccountByCustomerId(bind.getCustomerId());
|
|
|
- BigDecimal balance = tbAccount.getTotalMoney();
|
|
|
- //不足
|
|
|
- BigDecimal partMoney = orderPriceRes.getTotalOrderPrice();
|
|
|
- if (balance.compareTo(partMoney) < 0) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- balance = balance.subtract(partMoney);
|
|
|
- //更新余额+累计扣款
|
|
|
- tbAccount.setTotalMoney(balance).setLastSumMoney(tbAccount.getLastSumMoney().add(partMoney));
|
|
|
- tbAccountService.updateById(tbAccount);
|
|
|
- tbBusinessCar.setMoney(partMoney).setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType()).setPayTime(now);
|
|
|
- //todo 自动扣款修改
|
|
|
- PriceBO priceBO = new PriceBO();
|
|
|
- priceBO.setId(tbBusinessCar.getId()).setHourDesc(orderPriceRes.getHourDesc()).setCarDesc(orderPriceRes.getCarDesc())
|
|
|
- .setCalculateId(orderPriceRes.getCalculateId()).setP(orderPriceRes.getTotalOrderPrice());
|
|
|
- List<PriceDetailItem> priceDetailItems = orderPriceRes.getFireResult().get(0).getPriceDetail();
|
|
|
- for (PriceDetailItem priceDetailItem : priceDetailItems) {
|
|
|
- String k = StrUtil.trim(priceDetailItem.getKey()).toLowerCase();
|
|
|
- String v = priceDetailItem.getValue();
|
|
|
- if (k.equals("standard")) {
|
|
|
- priceBO.setStandard(new BigDecimal(v));
|
|
|
- } else if (k.equals("extraPrice")) {
|
|
|
- priceBO.setExtraPrice(new BigDecimal(v));
|
|
|
- }
|
|
|
- }
|
|
|
- List<PriceBO> priceBOList = new ArrayList<PriceBO>() {{
|
|
|
- add(priceBO);
|
|
|
- }};
|
|
|
- String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
|
|
|
- //车辆的扣费记录
|
|
|
- List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(
|
|
|
- priceBOList, null, null, now, PayEnum.PayType.PER_PAY);
|
|
|
-
|
|
|
- tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
|
|
|
- return true;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 支付停车费和业务费
|
|
@@ -365,88 +123,108 @@ public class AutomaticPay {
|
|
|
*/
|
|
|
public boolean payBusinessAndPartMoney(List<TbBusiness> businessList,
|
|
|
TbBusinessCar tbBusinessCar,
|
|
|
- IOrderPriceRes partMoneyRes) {
|
|
|
+ IOrderPriceRes partMoneyRes, IOrderPriceRes businessRes) {
|
|
|
Date now = new Date();
|
|
|
- for (TbBusiness tbBusiness : businessList) {
|
|
|
- TbAccount tbAccount = tbAccountService.getAccountByCustomerId(tbBusiness.getCustomerId());
|
|
|
- BigDecimal balance = tbAccount.getTotalMoney();
|
|
|
- //停车费扣除
|
|
|
- BigDecimal partMoney = partMoneyRes.getTotalOrderPrice();
|
|
|
- if (partMoney.compareTo(balance) > 0) {
|
|
|
- return false;//不够交
|
|
|
+ String customerId = tbBusinessCar.getCustomerId();
|
|
|
+ if (StrUtil.isEmpty(customerId)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ TbAccount tbAccount = tbAccountService.getAccountByCustomerId(customerId);
|
|
|
+ //原金额
|
|
|
+ BigDecimal originalMoney = tbAccount.getTotalMoney();
|
|
|
+ //停车费扣除
|
|
|
+ BigDecimal partMoney = partMoneyRes.getTotalOrderPrice();
|
|
|
+ //业务费用
|
|
|
+ BigDecimal businessMoney = businessRes.getTotalOrderPrice();
|
|
|
+ //总费用
|
|
|
+ BigDecimal totalMoney = partMoney.add(businessMoney);
|
|
|
+ if (totalMoney.compareTo(originalMoney) > 0) {
|
|
|
+ return false;//不够交
|
|
|
+ }
|
|
|
+ BigDecimal balance = originalMoney.subtract(totalMoney);
|
|
|
+ tbAccount.setTotalMoney(balance);
|
|
|
+ TbCostomer tbCostomer = tbCostomerService.getById(customerId);
|
|
|
+ String customerName = tbCostomer.getName();
|
|
|
+ //需要交停车费且未交的话
|
|
|
+ if (tbBusinessCar.getPay() == 0 && partMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ String businessIds = businessList.stream().filter(tbBusiness -> tbBusiness.getGoodsName().contains("停车"))
|
|
|
+ .map(TbBusiness::getId).collect(Collectors.joining(","));
|
|
|
+ String uniqExpenseId = partMoneyRes.getUniqueExpenseId();
|
|
|
+ String calculateId = partMoneyRes.getCalculateId();
|
|
|
+ String carDesc = partMoneyRes.getCarDesc();
|
|
|
+ String hourDesc = partMoneyRes.getHourDesc();
|
|
|
+ List<PriceDetailItem> items = partMoneyRes.getFireResult().get(0).getPriceDetail();
|
|
|
+ if (partMoneyRes.getTotalOrderPrice().intValue() > 0) {
|
|
|
+ items = partMoneyRes.getFireResult().get(0).getPriceDetail();
|
|
|
}
|
|
|
- if (tbBusinessCar.getPay() == 0 && partMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- String uniqExpenseId = partMoneyRes.getUniqueExpenseId();
|
|
|
- String calculateId = partMoneyRes.getCalculateId();
|
|
|
- String carDesc = partMoneyRes.getCarDesc();
|
|
|
- String hourDesc = partMoneyRes.getHourDesc();
|
|
|
- List<PriceDetailItem> items = partMoneyRes.getFireResult().get(0).getPriceDetail();
|
|
|
- if (partMoneyRes.getTotalOrderPrice().intValue() > 0) {
|
|
|
- items = partMoneyRes.getFireResult().get(0).getPriceDetail();
|
|
|
- }
|
|
|
- PriceBO priceBO = new PriceBO();
|
|
|
- List<PriceBO> priceBOList = new ArrayList<>();
|
|
|
- priceBO.setId(tbBusinessCar.getId()).setP(partMoney).setCalculateId(calculateId)
|
|
|
- .setCarDesc(carDesc).setHourDesc(hourDesc).setBusinessId(tbBusiness.getId())
|
|
|
- .setUniqExpenseId(uniqExpenseId);
|
|
|
- priceBOList.add(priceBO);
|
|
|
- for (PriceDetailItem item : items) {
|
|
|
- if (item.getKey().toLowerCase().trim().equals("standard")) {
|
|
|
- priceBO.setStandard(new BigDecimal(item.getValue()));
|
|
|
- } else if (item.getKey().toLowerCase().trim().equals("extraPrice")) {
|
|
|
- priceBO.setStandard(new BigDecimal(item.getValue()));
|
|
|
- }
|
|
|
+ PriceBO priceBO = new PriceBO();
|
|
|
+ List<PriceBO> priceBOList = new ArrayList<>();
|
|
|
+ priceBO.setId(tbBusinessCar.getId()).setP(partMoney).setCalculateId(calculateId)
|
|
|
+ .setCarDesc(carDesc).setHourDesc(hourDesc).setBusinessId(businessIds)
|
|
|
+ .setUniqExpenseId(uniqExpenseId);
|
|
|
+ priceBOList.add(priceBO);
|
|
|
+ for (PriceDetailItem item : items) {
|
|
|
+ if (item.getKey().toLowerCase().trim().equals("standard")) {
|
|
|
+ priceBO.setStandard(new BigDecimal(item.getValue()));
|
|
|
+ } else if (item.getKey().trim().equals("extraPrice")) {
|
|
|
+ priceBO.setExtraPrice(new BigDecimal(item.getValue()));
|
|
|
}
|
|
|
- BigDecimal afterBalance = balance.subtract(partMoney);
|
|
|
- tbAccount.setTotalMoney(afterBalance);
|
|
|
- tbAccountService.updateById(tbAccount);
|
|
|
- String plate = tbBusinessCar.getCarNo();
|
|
|
- tbBusinessCar.setPay(1).setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType())
|
|
|
- .setPayTime(now).setMoney(partMoney);
|
|
|
- tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
- List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(priceBOList, null, null, now, PayEnum.PayType.PER_PAY);
|
|
|
- //停车费明细
|
|
|
- this.createTbDeductionRecord(parkFeeDetailsList.get(0), balance, afterBalance,
|
|
|
- tbBusiness.getCustomerId(),tbBusiness.getCustomerName(), plate, tbBusinessCar.getId(), FeeTypeEnum.PARK_FEE);
|
|
|
-
|
|
|
}
|
|
|
+ String plate = tbBusinessCar.getCarNo();
|
|
|
+ tbBusinessCar.setPay(1).setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType())
|
|
|
+ .setPayTime(now).setMoney(partMoney);
|
|
|
+ tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ TbBusiness tbBusiness = businessList.get(0);
|
|
|
+ String businessNo = tbBusiness.getNo();
|
|
|
+ List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(priceBOList, null, null, now, PayEnum.PayType.PER_PAY);
|
|
|
+ //停车费明细
|
|
|
+ for (TbFeeDetails tbFeeDetails : parkFeeDetailsList) {
|
|
|
+ tbFeeDetails.setBusinessNo(businessNo);
|
|
|
+ TbDeductionRecord record = this.createTbDeductionRecord(tbFeeDetails, originalMoney, BigDecimal.ZERO,
|
|
|
+ customerId, customerName, plate, tbBusinessCar.getId(), FeeTypeEnum.PARK_FEE);
|
|
|
+ invoiceOrderService.addInvoiceOrder("停车业务", businessNo, tbBusinessCar.getCarNo(), tbBusiness.getId(), tbBusinessCar.getCustomerId(), tbBusiness.getCustomerName(), tbBusiness.getCustomerName(), partMoney, tbFeeDetails, record);
|
|
|
+ originalMoney = originalMoney.subtract(tbFeeDetails.getItemPrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //业务费用
|
|
|
+ for (TbBusiness tbBusiness : businessList) {
|
|
|
List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(tbBusiness.getId());
|
|
|
items = items.stream().filter(item -> item.getPayStatus() == 0).collect(Collectors.toList());
|
|
|
for (TbBusinessItem item : items) {
|
|
|
if (item.getPayStatus() == 1) {//已支付的
|
|
|
continue;
|
|
|
}
|
|
|
- int feeType = item.getPayType();
|
|
|
- FeeTypeEnum feeTypeEnum = FeeTypeEnum.getEnum(feeType);
|
|
|
- List<IOrderItem> expenses = new ArrayList<>();
|
|
|
- tbBusinessItemService.buildExpenses(Collections.singletonList(item), expenses);
|
|
|
- IOrderPriceRes res = syncService.orderPriceCal(expenses);
|
|
|
- BigDecimal price = res.getTotalOrderPrice();
|
|
|
- if (balance.compareTo(price) < 0) {
|
|
|
- return false;
|
|
|
+ //支付金额累加
|
|
|
+ if (!StrUtil.equals(item.getItemAlias(), SystemObject.config.getPartItemAlias())) {
|
|
|
+ List<IOrderItem> orderItems = new ArrayList<>();
|
|
|
+ tbBusinessItemService.buildExpenses(Collections.singletonList(item), orderItems);
|
|
|
+ if (orderItems.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ IOrderPriceRes res = syncService.orderPriceCal(orderItems);
|
|
|
+ BigDecimal price = res.getTotalOrderPrice();
|
|
|
+ item.setTotal(price);
|
|
|
+ tbBusiness.setPayMoney(tbBusiness.getPayMoney().add(price));
|
|
|
+ int feeType = item.getPayType();
|
|
|
+ FeeTypeEnum feeTypeEnum = FeeTypeEnum.getEnum(feeType);
|
|
|
+ TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, tbBusiness.getCustomerName(), tbBusiness.getPickCustomerName(), feeTypeEnum);
|
|
|
+ TbDeductionRecord record = createTbDeductionRecord(details, originalMoney, BigDecimal.ZERO, customerId, tbBusiness.getCustomerName(),
|
|
|
+ tbBusinessCar.getCarNo(), tbBusinessCar.getId(), feeTypeEnum);
|
|
|
+ invoiceOrderService.addInvoiceOrder(tbBusiness.getGoodsName(), tbBusiness.getNo(), tbBusiness.getCarNoStr(), tbBusiness.getId(),
|
|
|
+ tbBusiness.getCustomerId(), tbBusiness.getCustomerName(), tbBusiness.getCustomerName(), res.getTotalOrderPrice(), details, record);
|
|
|
+ } else {
|
|
|
+ tbBusiness.setPayMoney(tbBusiness.getPayMoney().add(partMoney)).setItemPrice(BigDecimal.ZERO);
|
|
|
}
|
|
|
- item.setPayStatus(1).setPayTime(new Date());
|
|
|
+ item.setPayStatus(1).setPayTime(now);
|
|
|
tbBusinessItemService.updateById(item);
|
|
|
- String customerId = tbBusiness.getCustomerId();
|
|
|
- BigDecimal afterBalance = balance.subtract(price);
|
|
|
- tbAccount.setTotalMoney(afterBalance);
|
|
|
- tbAccountService.updateById(tbAccount);
|
|
|
- //支付金额累加
|
|
|
- tbBusiness.setPayMoney(tbBusiness.getPayMoney().add(price));
|
|
|
+ tbBusiness.setPayStatus(PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode()).setPayTime(now);
|
|
|
tbBusinessService.updateById(tbBusiness);
|
|
|
- TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, feeTypeEnum);
|
|
|
- createTbDeductionRecord(details, balance, afterBalance, customerId,tbBusiness.getCustomerName(),
|
|
|
- tbBusinessCar.getCarNo(), tbBusinessCar.getId(), feeTypeEnum);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (businessList.isEmpty()&&partMoneyRes.getTotalOrderPrice().compareTo(BigDecimal.ZERO)>0){
|
|
|
- //单独交停车费
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
//todo 构造统计数据
|
|
|
tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
|
|
|
+ //更新账户余额
|
|
|
+ tbAccountService.updateById(tbAccount);
|
|
|
return true;
|
|
|
}
|
|
|
}
|