|
@@ -1233,6 +1233,9 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
throw new BusinessException("作业车辆不能为空");
|
|
|
}
|
|
|
Date now = new Date();
|
|
|
+ if (errorBusinessBO.getCreateTime() != null) {
|
|
|
+ now = errorBusinessBO.getCreateTime();
|
|
|
+ }
|
|
|
TbGoods tbGoods = tbGoodsService.getById(errorBusinessBO.getGoodsId());
|
|
|
TbBusiness tbBusiness = new TbBusiness();
|
|
|
String customerId = errorBusinessBO.getCustomerId();
|
|
@@ -1248,6 +1251,9 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
BigDecimal price = new BigDecimal("0");
|
|
|
List<TbBusinessItem> itemList = new ArrayList<>();
|
|
|
String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
|
|
|
+ if (StrUtil.isNotEmpty(errorBusinessBO.getNo())) {
|
|
|
+ no = errorBusinessBO.getNo();
|
|
|
+ }
|
|
|
int index = 1;
|
|
|
for (TbItem tbItem : tbItems) {
|
|
|
TbItem db = tbItemService.getById(tbItem.getId());
|
|
@@ -1274,8 +1280,8 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
tbBusiness.setCardSize(errorBusinessBO.getCarSize()).setNetWeight(errorBusinessBO.getNetWeight())
|
|
|
.setOperator(errorBusinessBO.getOperator()).setOperateTime(errorBusinessBO.getOperateTime())
|
|
|
.setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(errorBusinessBO.getGoodsId())
|
|
|
- .setSupplementReason(errorBusinessBO.getSupplementReason()).setSupplementTime(new Date())
|
|
|
- .setSupplementBy(errorBusinessBO.getSupplementBy()).setSupplement(1)
|
|
|
+ .setSupplementReason(errorBusinessBO.getSupplementReason()).setSupplementTime(now)
|
|
|
+ .setSupplementBy(errorBusinessBO.getSupplementBy()).setSupplement(1).setPayStatus(errorBusinessBO.getPayStatus())
|
|
|
.setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(errorBusinessBO.getCardNo());
|
|
|
tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
|
|
|
.setItemPrice(price).setTotalMoney(price).setOwner(errorBusinessBO.getOwner());
|
|
@@ -1367,132 +1373,12 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
if (cars.isEmpty()) {
|
|
|
throw new BusinessException("作业车辆不能为空");
|
|
|
}
|
|
|
-
|
|
|
- Date now = new Date();
|
|
|
- List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessId(id);
|
|
|
- List<String> businessCarIds = cars.stream().filter(tbBusinessCar -> StrUtil.isNotEmpty(tbBusinessCar.getId()))
|
|
|
- .map(TbBusinessCar::getId).collect(Collectors.toList());
|
|
|
- List<String> removeIds = relationBusinessCars.stream()
|
|
|
- .filter(relationBusinessCar -> !businessCarIds.contains(relationBusinessCar.getBusinessCarId()))
|
|
|
- .map(RelationBusinessCar::getId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (!removeIds.isEmpty()) {
|
|
|
- //删除多的关联
|
|
|
- relationBusinessCarService.removeByIds(removeIds);
|
|
|
- }
|
|
|
- TbGoods tbGoods = tbGoodsService.getById(errorBusinessBO.getGoodsId());
|
|
|
- Integer chinaCarPay = tbGoods.getChinaCarPay();
|
|
|
- Integer vietnamCarPay = tbGoods.getVietnamCarPay();
|
|
|
- String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
|
|
|
- List<TbBusinessItem> itemList = new ArrayList<>();
|
|
|
- boolean isPay = TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus();
|
|
|
- //如果业务单未支付,直接删除掉,重新添加
|
|
|
- if (TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() != dbBusiness.getPayStatus()) {
|
|
|
- tbBusinessItemService.removeByBusinessId(id);
|
|
|
- BigDecimal price = new BigDecimal("0");
|
|
|
- String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
|
|
|
- int index = 1;
|
|
|
- for (TbItem tbItem : tbItems) {
|
|
|
- TbItem db = tbItemService.getById(tbItem.getId());
|
|
|
- TbBusinessItem item = new TbBusinessItem();
|
|
|
- int num = tbItem.getNum();
|
|
|
- TbItemType tbItemType = tbItemTypeService.getById(tbItem.getTypeId());
|
|
|
- BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
|
|
|
- item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
|
|
|
- .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
|
|
|
- item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId()).setBusinessId(dbBusiness.getId())
|
|
|
- .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
|
|
|
- .setItemTypeId(tbItem.getTypeId()).setItemTypeName(tbItemType.getName()).setPayStatus(1)
|
|
|
- .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
|
|
|
- price = price.add(itemTotalPrice);
|
|
|
- itemList.add(item);
|
|
|
- index++;
|
|
|
- }
|
|
|
- dbBusiness.setItemPrice(price).setTotalMoney(price);
|
|
|
- tbBusinessItemService.saveBatch(itemList);
|
|
|
- }
|
|
|
- for (TbBusinessCar tbBusinessCar : cars) {
|
|
|
- String businessCarId = tbBusinessCar.getId();
|
|
|
- String carNo = tbBusinessCar.getCarNo();
|
|
|
- for (TbBusinessItem item : itemList) {
|
|
|
- checkOtherBusiness(item.getItemTypeId(), errorBusinessBO.getOperateTime(), dbBusiness.getId(), carNo);
|
|
|
- }
|
|
|
- String carType = tbBusinessCar.getCarType();
|
|
|
- //修改
|
|
|
- if (StrUtil.isNotEmpty(businessCarId)) {
|
|
|
- //原来已存在的
|
|
|
- TbBusinessCar dbBusinessCar = tbBusinessCarService.getById(businessCarId);
|
|
|
- //如果修改了车牌号
|
|
|
- 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();
|
|
|
- otherCar.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4))
|
|
|
- .setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
|
|
|
- .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
|
|
|
- .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType());
|
|
|
- if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
|
|
|
- otherCar.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
|
|
|
- }
|
|
|
- tbBusinessCarService.save(otherCar);
|
|
|
- } else {
|
|
|
- List<TbBusiness> tbBusinessList = this.findOtherBusinessByCarId(businessCarId);
|
|
|
- if (tbBusinessList.size() == 1 && dbBusinessCar.getRealInTime() == null) {
|
|
|
- tbBusinessCarService.removeById(businessCarId);
|
|
|
- }
|
|
|
- }
|
|
|
- RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
|
|
|
- relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(otherCar.getId());
|
|
|
- relationBusinessCarService.save(relationBusinessCar);
|
|
|
- } else {
|
|
|
- dbBusinessCar.setNetWeight(tbBusinessCar.getNetWeight()).setNetWeight(tbBusinessCar.getNetWeight())
|
|
|
- .setCarSize(tbBusinessCar.getCarSize()).setCarType(tbBusinessCar.getCarType());
|
|
|
- tbBusinessCarService.updateById(dbBusinessCar);
|
|
|
- }
|
|
|
- } else {
|
|
|
- TbBusinessCar checkCar = tbBusinessCarService.findTheLastRecord(carNo);
|
|
|
- if (checkCar == null ||
|
|
|
- (checkCar.getRealInTime() != null && checkCar.getRealOutTime() != null)) {
|
|
|
- checkCar = new TbBusinessCar();
|
|
|
- checkCar.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
|
|
|
- }
|
|
|
- checkCar.setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
|
|
|
- .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
|
|
|
- .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType());
|
|
|
- if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
|
|
|
- checkCar.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
|
|
|
- }
|
|
|
- tbBusinessCarService.saveOrUpdate(checkCar);
|
|
|
- RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
|
|
|
- relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(checkCar.getId());
|
|
|
- relationBusinessCarService.save(relationBusinessCar);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!StrUtil.equals(dbBusiness.getGoodsId(), errorBusinessBO.getGoodsId())) {
|
|
|
- dbBusiness.setGoodsId(errorBusinessBO.getGoodsId())
|
|
|
- .setGoodsName(tbGoods.getName()).setPayStep(tbGoods.getPayStep());
|
|
|
- }
|
|
|
- String declareNo = errorBusinessBO.getDeclareNo();
|
|
|
- if (!StrUtil.equals(declareNo, dbBusiness.getDeclareNo())) {
|
|
|
- tbDeclareService.rebackDeclareNo(dbBusiness.getDeclareNo());
|
|
|
- TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(declareNo);
|
|
|
- tbDeclare.setBusinessId(dbBusiness.getId());
|
|
|
- tbDeclareService.updateById(tbDeclare);
|
|
|
- }
|
|
|
- dbBusiness.setCardSize(errorBusinessBO.getCarSize()).setNetWeight(errorBusinessBO.getNetWeight())
|
|
|
- .setOperator(errorBusinessBO.getOperator()).setOperateTime(errorBusinessBO.getOperateTime())
|
|
|
- .setGoodsId(errorBusinessBO.getGoodsId()).setSupplementReason(errorBusinessBO.getSupplementReason())
|
|
|
- .setOwner(errorBusinessBO.getOwner()).setPayStatus(errorBusinessBO.getPayStatus())
|
|
|
- .setDeclareNo(declareNo).setCardNo(errorBusinessBO.getCardNo());
|
|
|
- dbBusiness.setChinaCarNo(errorBusinessBO.getChinaCarNo());
|
|
|
- if (isPay){
|
|
|
- dbBusiness.setPayTime(errorBusinessBO.getPayTime());
|
|
|
- }
|
|
|
- this.updateById(dbBusiness);
|
|
|
+ this.removeById(id);
|
|
|
+ tbBusinessItemService.removeByBusinessId(id);
|
|
|
+ tbBusinessCarService.removeByBusinessId(id);
|
|
|
+ relationBusinessCarService.removeByBusinessId(id);
|
|
|
+ errorBusinessBO.setNo(dbBusiness.getNo()).setCreateTime(dbBusiness.getCreateTime());
|
|
|
+ this.addErrorBusiness(errorBusinessBO, false);
|
|
|
}
|
|
|
|
|
|
}
|