|
@@ -20,6 +20,7 @@ import com.pj.project.tb_deduction_bind.TbDeductionBindService;
|
|
|
import com.pj.project.tb_deduction_record.TbDeductionRecord;
|
|
|
import com.pj.project.tb_fee_details.TbFeeDetails;
|
|
|
import com.pj.project.tb_fee_details.TbFeeDetailsService;
|
|
|
+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.project.tb_invoice_order.TbInvoiceOrder;
|
|
@@ -27,6 +28,7 @@ import com.pj.project.tb_invoice_order.TbInvoiceOrderService;
|
|
|
import com.pj.project.tb_item.TbItem;
|
|
|
import com.pj.utils.AesUtil;
|
|
|
import com.pj.utils.cache.RedisUtil;
|
|
|
+import com.pj.utils.sg.AjaxError;
|
|
|
import com.pj.utils.sg.NbUtil;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -68,7 +70,8 @@ public class AutomaticPay {
|
|
|
@Resource
|
|
|
@Lazy
|
|
|
private TbDeductionBindService tbDeductionBindService;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private TbFeeStatisticsService tbFeeStatisticsService;
|
|
|
private Integer feeType;
|
|
|
|
|
|
|
|
@@ -191,7 +194,7 @@ public class AutomaticPay {
|
|
|
List<TbFeeDetails> tbFeeDetailsList = tbFeeDetailsService.autoChargeBusinessFee(
|
|
|
businessItems, null, null, now);
|
|
|
//生成扣费记录
|
|
|
- createTbDeductionRecord(tbFeeDetailsList, tbAccount, plate, bind.getCustomerName(), no);
|
|
|
+ createTbDeductionRecord(tbFeeDetailsList, tbAccount, plate, bind.getCustomerName(), no);
|
|
|
//生成开票信息
|
|
|
createTbInvoiceOrder(tbBusiness, cars, parkingMoneyBig, plate, bind.getCustomerId(), no, isOut);
|
|
|
if (isOut) {//离场缴费
|
|
@@ -312,7 +315,7 @@ public class AutomaticPay {
|
|
|
*/
|
|
|
public void createTbDeductionRecord(List<TbFeeDetails> tbFeeDetailsList, TbAccount tbAccount, String plate, String customerName, String no) {
|
|
|
String bindIdStr = deductionBindService.getBindId(plate);
|
|
|
- BigDecimal banlanc = new BigDecimal(AesUtil.decryptECB(tbAccount.getTotalMoney(),AesUtil.reverse(tbAccount.getAccSalt())));
|
|
|
+ BigDecimal banlanc = new BigDecimal(AesUtil.decryptECB(tbAccount.getTotalMoney(), AesUtil.reverse(tbAccount.getAccSalt())));
|
|
|
for (TbFeeDetails feeDetails : tbFeeDetailsList) {
|
|
|
TbDeductionRecord deductionRecord = BeanUtil.toBean(feeDetails, TbDeductionRecord.class);
|
|
|
BigDecimal itemPrice = feeDetails.getItemPrice();
|
|
@@ -328,7 +331,7 @@ public class AutomaticPay {
|
|
|
banlanc = banlanc.subtract(itemPrice);
|
|
|
deductionRecord.setTotalMoney(banlanc.toString());
|
|
|
deductionRecord.insert();
|
|
|
- feeDetails.setCarNo(plate);
|
|
|
+// feeDetails.setCarNo(plate);
|
|
|
feeDetails.setPreOrderNum(no);
|
|
|
feeDetails.setCustomerName(customerName);
|
|
|
tbFeeDetailsService.updateById(feeDetails);
|
|
@@ -580,4 +583,97 @@ public class AutomaticPay {
|
|
|
String key = "autoPay:" + businessId + plate;
|
|
|
return key;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付停车费
|
|
|
+ * @param tbBusinessCar
|
|
|
+ * @param partMoney
|
|
|
+ * @param now
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean payPartMoney(TbBusinessCar tbBusinessCar, double partMoney, Date now) {
|
|
|
+ String carNo = tbBusinessCar.getCarNo();
|
|
|
+ TbDeductionBind bind = tbDeductionBindService.getBindCarByPlate(carNo);
|
|
|
+ //未绑定
|
|
|
+ if (bind == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ TbAccount tbAccount = tbAccountService.getByCustomerId(bind.getCustomerId());
|
|
|
+ String key = AesUtil.reverse(tbAccount.getAccSalt());
|
|
|
+ BigDecimal balance = new BigDecimal(tbAccount.getTotalMoney());
|
|
|
+ //不足
|
|
|
+ if (balance.doubleValue() < partMoney) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ balance = balance.subtract(new BigDecimal(partMoney));
|
|
|
+ tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(), key));
|
|
|
+ tbAccountService.updateById(tbAccount);
|
|
|
+ tbBusinessCar.setMoney(new BigDecimal(partMoney)).setPayType(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType()).setPayTime(now);
|
|
|
+ List<PriceBO> priceBOList = new ArrayList<PriceBO>() {{
|
|
|
+ add(new PriceBO(tbBusinessCar.getId(), tbBusinessCar.getMoney()));
|
|
|
+ }};
|
|
|
+ String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
|
|
|
+ //车辆的扣费记录
|
|
|
+ List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(
|
|
|
+ priceBOList, null, null, now, TbBusiness.PayType.PER_PAY);
|
|
|
+ this.createTbDeductionRecord(parkFeeDetailsList, tbAccount, tbBusinessCar.getCarNo(), bind.getCustomerName(), no);
|
|
|
+ tbFeeStatisticsService.addOrUpdateStatistic(now);//更新当前日期的日统计
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付停车费和业务费
|
|
|
+ * @param businessList
|
|
|
+ * @param businessMoney
|
|
|
+ * @param tbBusinessCar
|
|
|
+ * @param chinaCarMoney
|
|
|
+ * @param yueCarMoney
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean payBusinessAndPartMoney(List<TbBusiness> businessList,
|
|
|
+ BigDecimal businessMoney,
|
|
|
+ TbBusinessCar tbBusinessCar,
|
|
|
+ BigDecimal chinaCarMoney,
|
|
|
+ BigDecimal yueCarMoney) {
|
|
|
+ Date now = new Date();
|
|
|
+ String carNo = tbBusinessCar.getCarNo();
|
|
|
+ TbDeductionBind bind = tbDeductionBindService.getBindCarByPlate(carNo);
|
|
|
+ //未绑定
|
|
|
+ if (bind == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ BigDecimal totalMoney = businessMoney.add(chinaCarMoney).add(yueCarMoney).add(chinaCarMoney);
|
|
|
+ TbAccount tbAccount = tbAccountService.getByCustomerId(bind.getCustomerId());
|
|
|
+ String key = AesUtil.reverse(tbAccount.getAccSalt());
|
|
|
+ BigDecimal balance = new BigDecimal(tbAccount.getTotalMoney());
|
|
|
+ //不足
|
|
|
+ if (balance.doubleValue() < totalMoney.doubleValue()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ balance = balance.subtract(totalMoney);
|
|
|
+ tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(), key));
|
|
|
+ tbAccountService.updateById(tbAccount);
|
|
|
+ businessList.forEach(tbBusiness -> {
|
|
|
+ tbBusiness.setPayStatus(TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode())
|
|
|
+ .setPayMoney(tbBusiness.getItemPrice()).setTotalMoney(tbBusiness.getItemPrice());
|
|
|
+ });
|
|
|
+ tbBusinessService.updateBatchById(businessList);
|
|
|
+ List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessIdList(businessList.stream().map(TbBusiness::getId).collect(Collectors.toList()));
|
|
|
+ tbBusinessItems.parallelStream().forEach(item -> item.setPayStatus(1).setPayTime(now));
|
|
|
+ tbBusinessItemService.updateBatchById(tbBusinessItems);
|
|
|
+ tbBusinessCar.setPay(1).setPayType(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType())
|
|
|
+ .setPayTime(now);
|
|
|
+ tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ List<PriceBO> priceBOList = new ArrayList<PriceBO>() {{
|
|
|
+ add(new PriceBO(tbBusinessCar.getId(), tbBusinessCar.getMoney()));
|
|
|
+ }};
|
|
|
+ String plate=tbBusinessCar.getCarNo();
|
|
|
+ String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
|
|
|
+ List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(priceBOList, null, null, now, TbBusiness.PayType.PER_PAY);
|
|
|
+ this.createTbDeductionRecord(parkFeeDetailsList, tbAccount, plate, bind.getCustomerName(), no);
|
|
|
+ List<TbFeeDetails> tbFeeDetails = tbFeeDetailsService.chargeBusinessFee(tbBusinessItems, null, null, now, TbBusiness.PayType.PER_PAY);
|
|
|
+ createTbDeductionRecord(tbFeeDetails, tbAccount, plate, bind.getCustomerName(), no);
|
|
|
+ tbFeeStatisticsService.addOrUpdateStatistic(now);//更新当前日期的日统计
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|