|
@@ -62,6 +62,7 @@ import com.pj.project.tb_declare.TbDeclare;
|
|
|
import com.pj.project.tb_declare.TbDeclareService;
|
|
|
import com.pj.project.tb_deduction_bind.TbDeductionBind;
|
|
|
import com.pj.project.tb_deduction_bind.TbDeductionBindService;
|
|
|
+import com.pj.project.tb_deduction_record.TbDeductionRecord;
|
|
|
import com.pj.project.tb_driver.TbDriver;
|
|
|
import com.pj.project.tb_driver.TbDriverService;
|
|
|
import com.pj.project.tb_fee_details.TbFeeDetails;
|
|
@@ -69,6 +70,8 @@ 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;
|
|
|
+import com.pj.project.tb_invoice_order.TbInvoiceOrderService;
|
|
|
import com.pj.project.tb_item.TbItem;
|
|
|
import com.pj.project.tb_item.TbItemService;
|
|
|
import com.pj.project.tb_item_fac.TbItemFac;
|
|
@@ -90,6 +93,7 @@ import com.pj.utils.cache.RedisUtil;
|
|
|
import com.pj.utils.sg.AjaxJson;
|
|
|
import com.pj.utils.so.SoMap;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.aspectj.weaver.loadtime.Aj;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -177,7 +181,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
private TbFeeDetailsService tbFeeDetailsService;
|
|
|
|
|
|
@Resource
|
|
|
- private TbDeductionBindService tbDeductionBindService;
|
|
|
+ private TbInvoiceOrderService tbInvoiceOrderService;
|
|
|
@Resource
|
|
|
@Lazy
|
|
|
private TbFeeStatisticsService tbFeeStatisticsService;
|
|
@@ -455,14 +459,11 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
|
|
|
List<String> businessIdList = businessList.stream().map(TbBusiness::getId).collect(Collectors.toList());
|
|
|
String businessIds = StrUtil.join(",", businessIdList);
|
|
|
+ long judgeCount = businessList.stream().filter(tbBusiness -> tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()).count();
|
|
|
+ int size = businessList.size();
|
|
|
result.put("showPay", true);
|
|
|
result.put("businessId", businessIds);
|
|
|
- result.put("noJudgeCount", 0);
|
|
|
- if (CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType().equals(tbBusinessCar.getBusinessType())) {
|
|
|
- if (tbBusinessCar.getConfirmJudge() != CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
|
|
|
- result.put("noJudgeCount", 1);
|
|
|
- }
|
|
|
- }
|
|
|
+ result.put("noJudgeCount", judgeCount == size ? 0 : 1);
|
|
|
List<TbBusinessItem> items = tbBusinessItemService.findByBusinessIdList(businessIdList);
|
|
|
Date inTime = tbBusinessCar.getRealInTime();
|
|
|
int pay = tbBusinessCar.getPay();
|
|
@@ -781,10 +782,6 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
}
|
|
|
//最新一条记录
|
|
|
TbBusinessCar db = tbBusinessCarService.findTheLastRecord(carNo);
|
|
|
- //存在并且未离场+已审核
|
|
|
- if (db != null && db.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode() && db.getRealOutTime() == null) {
|
|
|
- throw new BusinessException("车辆【" + carNo + "】已审核,请驳回再录入业务");
|
|
|
- }
|
|
|
if (!tbGoods.getName().contains("整车")) {
|
|
|
//记录不存在或者已离场
|
|
|
if (db == null || db.getRealOutTime() != null) {
|
|
@@ -839,15 +836,18 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
String id = otherBusinessBO.getId();
|
|
|
TbBusiness dbBusiness = this.getById(id);
|
|
|
if (dbBusiness == null) {
|
|
|
- throw new BusinessException("记录不存在");
|
|
|
+ throw new AjaxError("记录不存在");
|
|
|
+ }
|
|
|
+ if (dbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
|
|
|
+ throw new AjaxError("业务已审核,请驳回后修改");
|
|
|
}
|
|
|
List<TbItem> tbItems = otherBusinessBO.getItems();
|
|
|
if (tbItems.isEmpty()) {
|
|
|
- throw new BusinessException("请选择收费明细");
|
|
|
+ throw new AjaxError("请选择收费明细");
|
|
|
}
|
|
|
List<TbBusinessCar> cars = otherBusinessBO.getCars();
|
|
|
if (cars.isEmpty()) {
|
|
|
- throw new BusinessException("作业车辆不能为空");
|
|
|
+ throw new AjaxError("作业车辆不能为空");
|
|
|
}
|
|
|
|
|
|
Date now = new Date();
|
|
@@ -914,16 +914,12 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
if (StrUtil.isNotEmpty(businessCarId)) {
|
|
|
//原来已存在的
|
|
|
TbBusinessCar dbBusinessCar = tbBusinessCarService.getById(businessCarId);
|
|
|
- if (dbBusinessCar.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
|
|
|
- throw new BusinessException("车辆【" + carNo + "】已审核,请驳回再录入业务");
|
|
|
- }
|
|
|
//如果修改了车牌号
|
|
|
String dbCarNo = dbBusinessCar.getCarNo();
|
|
|
if (!dbCarNo.equals(carNo)) {
|
|
|
//把关联删除掉,然后添加新的关联
|
|
|
relationBusinessCarService.removeByBusinessIdAndCarId(dbBusiness.getId(), businessCarId);
|
|
|
TbBusinessCar otherCar = tbBusinessCarService.findTheLastRecord(carNo);
|
|
|
-
|
|
|
if (otherCar == null ||//不存在或者已离场===>新建
|
|
|
(otherCar.getRealInTime() != null && otherCar.getRealOutTime() != null)) {
|
|
|
otherCar = new TbBusinessCar();
|
|
@@ -950,12 +946,6 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
}
|
|
|
} else {
|
|
|
TbBusinessCar checkCar = tbBusinessCarService.findTheLastRecord(carNo);
|
|
|
- //存在+审核+未离场的
|
|
|
- if (checkCar != null
|
|
|
- && checkCar.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()
|
|
|
- && checkCar.getRealOutTime() == null) {
|
|
|
- throw new BusinessException("车辆【" + carNo + "】已审核,请驳回再录入业务");
|
|
|
- }
|
|
|
//不存在或者已经离场的
|
|
|
if (checkCar == null ||
|
|
|
(checkCar.getRealInTime() != null && checkCar.getRealOutTime() != null)) {
|
|
@@ -978,14 +968,14 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
dbBusiness.setGoodsId(otherBusinessBO.getGoodsId())
|
|
|
.setGoodsName(tbGoods.getName()).setPayStep(tbGoods.getPayStep());
|
|
|
}
|
|
|
- String customerId=otherBusinessBO.getCustomerId();
|
|
|
- if (StrUtil.isNotEmpty(customerId)){
|
|
|
- TbCostomer tbCostomer=tbCostomerService.getById(customerId);
|
|
|
+ String customerId = otherBusinessBO.getCustomerId();
|
|
|
+ if (StrUtil.isNotEmpty(customerId)) {
|
|
|
+ TbCostomer tbCostomer = tbCostomerService.getById(customerId);
|
|
|
dbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
|
|
|
}
|
|
|
- String pickCustomerId=otherBusinessBO.getPickCustomerId();
|
|
|
- if (StrUtil.isNotEmpty(pickCustomerId)){
|
|
|
- TbCostomer tbCostomer=tbCostomerService.getById(pickCustomerId);
|
|
|
+ String pickCustomerId = otherBusinessBO.getPickCustomerId();
|
|
|
+ if (StrUtil.isNotEmpty(pickCustomerId)) {
|
|
|
+ TbCostomer tbCostomer = tbCostomerService.getById(pickCustomerId);
|
|
|
dbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(tbCostomer.getName());
|
|
|
}
|
|
|
|
|
@@ -1006,11 +996,10 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
|
|
|
public void bindOtherBusinessCar(String businessId, List<String> businessCarIdList) {
|
|
|
TbBusiness tbBusiness = this.getById(businessId);
|
|
|
- List<TbBusinessCar> list = tbBusinessCarService.findOtherBusinessCar(businessId);
|
|
|
- long count = list.stream().filter(tbBusinessCar -> tbBusinessCar.getConfirmJudge() == 1).count();
|
|
|
- if (count > 0) {
|
|
|
- throw new AjaxError("业务已审核,请先驳回审核");
|
|
|
+ if (tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
|
|
|
+ throw new AjaxError("业务已审核,请先驳回");
|
|
|
}
|
|
|
+ List<TbBusinessCar> list = tbBusinessCarService.findOtherBusinessCar(businessId);
|
|
|
list.stream().filter(tbBusinessCar -> !businessCarIdList.contains(tbBusinessCar.getId()) && tbBusinessCar.getRealInTime() == null)
|
|
|
.forEach(tbBusinessCar -> tbBusinessCarService.removeById(tbBusinessCar.getId()));
|
|
|
relationBusinessCarService.removeByBusinessId(businessId);
|
|
@@ -1538,6 +1527,9 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
public void addBusinessCar(TbBusinessCar tbBusinessCar) {
|
|
|
String businessId = tbBusinessCar.getBusinessId();
|
|
|
TbBusiness tbBusiness = this.getById(businessId);
|
|
|
+ if (tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
|
|
|
+ throw new AjaxError("业务已审核,不能绑定新车辆");
|
|
|
+ }
|
|
|
String carNo = tbBusinessCar.getCarNo().trim().toUpperCase();
|
|
|
TbBusinessCar lastRecord = tbBusinessCarService.findTheLastRecord(carNo);
|
|
|
String businessCarId;
|
|
@@ -1556,8 +1548,10 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
businessCarId = tbBusinessCar.getId();
|
|
|
} else {
|
|
|
businessCarId = lastRecord.getId();
|
|
|
- lastRecord.setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType()).setCustomerId(tbBusiness.getCustomerId())
|
|
|
- .setCarNo(carNo).setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode()).setPayUnloadMoney(0)
|
|
|
+ lastRecord.setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType())
|
|
|
+ .setCustomerId(tbBusiness.getCustomerId())
|
|
|
+ .setCarNo(carNo).setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode())
|
|
|
+ .setPayUnloadMoney(lastRecord.getPayUnloadMoney())
|
|
|
.setTimeUpdate(now)
|
|
|
.setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType());
|
|
|
tbBusinessCarService.updateById(lastRecord);
|
|
@@ -1586,4 +1580,122 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核通过
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ public void confirmJudgePass(String id) {
|
|
|
+ TbBusiness tbBusiness = this.getById(id);
|
|
|
+ if (tbBusiness == null) {
|
|
|
+ throw new AjaxError("业务不存在");
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ List<TbBusinessCar> tbBusinessCars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
|
|
|
+ //审核
|
|
|
+ List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessId(tbBusiness.getId());
|
|
|
+ String customerId = tbBusiness.getPickCustomerId();
|
|
|
+ TbAccount tbAccount = tbAccountService.getAccountByCustomerId(customerId);
|
|
|
+ for (TbBusinessCar tbBusinessCar : tbBusinessCars) {
|
|
|
+ for (TbBusinessItem item : tbBusinessItems) {
|
|
|
+ String itemName = item.getItemName();
|
|
|
+ // todo 扣除 人工、机械装卸车辆---->每辆车都要支付----->
|
|
|
+ if (SystemObject.config.getEveryCarPay().contains(itemName) && tbBusinessCar.getPayUnloadMoney() == 0) {
|
|
|
+ List<IOrderItem> expenses = new ArrayList<>();
|
|
|
+ IOrderItem orderItem = new IOrderItem();
|
|
|
+ orderItem.setExpenseNum(Integer.parseInt(item.getNum()))
|
|
|
+ .setUniqExpenseId(item.getItemCode());
|
|
|
+ expenses.add(orderItem);
|
|
|
+ IOrderPriceRes res = syncService.orderPriceCal(expenses);
|
|
|
+ BigDecimal price = res.getTotalOrderPrice();
|
|
|
+ BigDecimal balance = tbAccount.getTotalMoney();
|
|
|
+ if (price.compareTo(balance) > 0) {
|
|
|
+ throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());
|
|
|
+ } else {
|
|
|
+ tbBusinessCar.setPayUnloadMoney(1);
|
|
|
+ tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ item.setPayTime(now).setPayStatus(1).setPayType(PayEnum.PayType.PER_PAY.getCode())
|
|
|
+ .setPayTypeName(PayEnum.PayType.PER_PAY.getDesc());
|
|
|
+ tbBusinessItemService.updateById(item);
|
|
|
+ tbBusiness.setPayMoney(price.add(tbBusiness.getPayMoney()));
|
|
|
+ BigDecimal afterBalance = balance.subtract(price);
|
|
|
+ tbAccount.setTotalMoney(afterBalance);//增加累计扣款
|
|
|
+ tbAccountService.updateById(tbAccount);
|
|
|
+ TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, FeeTypeEnum.STEVEDORE_FEE);
|
|
|
+ tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
|
|
|
+ TbDeductionRecord record= automaticPay.createTbDeductionRecord(details, balance, afterBalance, tbBusiness.getPickCustomerId(), tbBusiness.getPickCustomerName(), tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.STEVEDORE_FEE);
|
|
|
+ addInvoiceOrder(tbBusiness, res.getTotalOrderPrice(),details,record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //其他费项 装卸业务管理费” 进行预存款扣除
|
|
|
+ for (TbBusinessItem item : tbBusinessItems) {
|
|
|
+ //业务类型是装卸业务管理费且未支付的进行扣款
|
|
|
+ if (item.getPayStatus() == 0 && SystemObject.config.getUnLoadItem().contains(item.getItemTypeName())) {
|
|
|
+ List<IOrderItem> expenses = new ArrayList<>();
|
|
|
+ IOrderItem orderItem = new IOrderItem();
|
|
|
+ orderItem.setExpenseNum(Integer.parseInt(item.getNum()))
|
|
|
+ .setUniqExpenseId(item.getItemCode());
|
|
|
+ expenses.add(orderItem);
|
|
|
+ IOrderPriceRes res = syncService.orderPriceCal(expenses);
|
|
|
+ BigDecimal price = res.getTotalOrderPrice();
|
|
|
+ BigDecimal balance = tbAccount.getTotalMoney();
|
|
|
+ if (price.compareTo(balance) > 0) {
|
|
|
+ throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());
|
|
|
+ } else {
|
|
|
+ BigDecimal afterBalance = balance.subtract(price);
|
|
|
+ tbAccount.setTotalMoney(afterBalance);//增加累计扣款
|
|
|
+ tbAccountService.updateById(tbAccount);
|
|
|
+ item.setPayTime(now).setPayStatus(1).setPayType(PayEnum.PayType.PER_PAY.getCode())
|
|
|
+ .setPayTypeName(PayEnum.PayType.PER_PAY.getDesc());
|
|
|
+ tbBusinessItemService.updateById(item);
|
|
|
+ tbBusiness.setPayMoney(price.add(tbBusiness.getPayMoney()));
|
|
|
+ //查找越南车--->统计以
|
|
|
+ TbBusinessCar tbBusinessCar = tbBusinessCars.stream().filter(car -> !CAR_LIST.contains(car.getCarNo().substring(0, 1)))
|
|
|
+ .findAny().orElse(tbBusinessCars.get(0));
|
|
|
+ TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, FeeTypeEnum.STEVEDORE_FEE);
|
|
|
+ tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
|
|
|
+ TbDeductionRecord record= automaticPay.createTbDeductionRecord(details, balance, afterBalance, tbBusiness.getPickCustomerId(), tbBusiness.getPickCustomerName(), tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.STEVEDORE_FEE);
|
|
|
+ addInvoiceOrder(tbBusiness, res.getTotalOrderPrice(),details,record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tbBusiness.setConfirmJudgeTime(now).setConfirmJudgeContent("审核通过")
|
|
|
+ .setConfirmJudge(CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode())
|
|
|
+ .setJudgeBy(StpUserUtil.getCreateBy()).setPayTime(now);
|
|
|
+ this.updateById(tbBusiness);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加开票订单
|
|
|
+ * @param tbBusiness
|
|
|
+ * @param billMoney
|
|
|
+ */
|
|
|
+ private void addInvoiceOrder(TbBusiness tbBusiness, BigDecimal billMoney,TbFeeDetails details,TbDeductionRecord record) {
|
|
|
+ TbInvoiceOrder t = new TbInvoiceOrder();
|
|
|
+ t.setBusinessName(tbBusiness.getGoodsName())
|
|
|
+ .setBusinessNo(tbBusiness.getNo())
|
|
|
+ .setCarNo(tbBusiness.getCarNoStr())
|
|
|
+ .setBusinessId(tbBusiness.getId())
|
|
|
+ .setCustomerId(tbBusiness.getCustomerId())
|
|
|
+ .setBillMoney(billMoney).setDetailId(details.getId())
|
|
|
+ .setPreOrderNum(details.getPreOrderNum())
|
|
|
+ .setDeductionRecordId(record.getId())
|
|
|
+ .setStatus(0).setCreateTime(new Date());
|
|
|
+ tbInvoiceOrderService.save(t);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核驳回
|
|
|
+ * @param id
|
|
|
+ * @param judgeContent
|
|
|
+ */
|
|
|
+ public void callback(String id, String judgeContent) {
|
|
|
+ TbBusiness db = this.getById(id);
|
|
|
+ db.setConfirmJudge(CarEnum.ConfirmJudgeEnum.CALL_BACK.getCode())
|
|
|
+ .setConfirmJudgeContent(judgeContent).setConfirmJudgeTime(new Date())
|
|
|
+ .setJudgeBy(StpUserUtil.getCreateBy());
|
|
|
+ this.updateById(db);
|
|
|
+ }
|
|
|
+}
|