|
@@ -1,16 +1,13 @@
|
|
|
package com.pj.project.tb_business;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.time.LocalTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
@@ -19,9 +16,7 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.IService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.pj.api.bo.OtherBusinessBO;
|
|
|
import com.pj.api.bo.OtherBusinessEditBO;
|
|
|
-import com.pj.api.open.ResultJson;
|
|
|
import com.pj.api.wx.bo.MsgDataBO;
|
|
|
import com.pj.api.wx.service.WxService;
|
|
|
import com.pj.constants.UserTypeEnum;
|
|
@@ -30,6 +25,11 @@ import com.pj.current.config.MyConfig;
|
|
|
import com.pj.current.config.PartConfig;
|
|
|
import com.pj.current.config.WxConfig;
|
|
|
import com.pj.current.satoken.StpUserUtil;
|
|
|
+import com.pj.project.relation_business_car.RelationBusinessCar;
|
|
|
+import com.pj.project.relation_business_car.RelationBusinessCarService;
|
|
|
+import com.pj.project.relation_goods_type.RelationGoodsTypeService;
|
|
|
+import com.pj.project.relation_type_item.RelationTypeItem;
|
|
|
+import com.pj.project.relation_type_item.RelationTypeItemService;
|
|
|
import com.pj.project.tb_business_car.TbBusinessCar;
|
|
|
import com.pj.project.tb_business_car.TbBusinessCarService;
|
|
|
import com.pj.project.tb_business_item.TbBusinessItem;
|
|
@@ -54,10 +54,7 @@ import com.pj.project.tb_item.TbItem;
|
|
|
import com.pj.project.tb_item.TbItemService;
|
|
|
import com.pj.project.tb_item_type.TbItemType;
|
|
|
import com.pj.project.tb_item_type.TbItemTypeService;
|
|
|
-import com.pj.project.tb_notices.TbNoticesMapper;
|
|
|
import com.pj.project.tb_notices.TbNoticesService;
|
|
|
-import com.pj.project.tb_pass_record.TbPassRecord;
|
|
|
-import com.pj.project.tb_pass_record.TbPassRecordService;
|
|
|
import com.pj.project.tb_sort_group.TbSortGroup;
|
|
|
import com.pj.project.tb_sort_group.TbSortGroupService;
|
|
|
import com.pj.project.tb_unit.TbUnit;
|
|
@@ -65,13 +62,8 @@ import com.pj.project.tb_unit.TbUnitService;
|
|
|
import com.pj.project4sp.admin.SpAdmin;
|
|
|
import com.pj.project4sp.admin.SpAdminService;
|
|
|
import com.pj.project4sp.global.BusinessException;
|
|
|
-import com.pj.project4sp.role.SpRoleUtil;
|
|
|
-import com.pj.project4sp.role4permission.SpRolePermissionService;
|
|
|
import com.pj.utils.so.SoMap;
|
|
|
-import org.aspectj.weaver.loadtime.Aj;
|
|
|
-import org.omg.CORBA.OBJ_ADAPTER;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -87,7 +79,7 @@ import javax.annotation.Resource;
|
|
|
* @author qzy
|
|
|
*/
|
|
|
@Service
|
|
|
-@Transactional
|
|
|
+@Transactional(rollbackFor = Exception.class)
|
|
|
public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness> implements IService<TbBusiness> {
|
|
|
|
|
|
/**
|
|
@@ -144,6 +136,12 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
private TbBusinessSortService tbBusinessSortService;
|
|
|
@Resource
|
|
|
private TbSortGroupService tbSortGroupService;
|
|
|
+ @Resource
|
|
|
+ private TbGoodsService tbGoodsService;
|
|
|
+ @Resource
|
|
|
+ private RelationTypeItemService relationTypeItemService;
|
|
|
+ @Resource
|
|
|
+ private RelationBusinessCarService relationBusinessCarService;
|
|
|
|
|
|
|
|
|
private final List<String> CAR_LIST = StrUtil.splitTrim("浙,粤,京,津,冀,晋,蒙,辽,黑,沪,吉,苏,皖,赣,鲁,豫,鄂,湘,桂,琼,渝,川,贵,云,藏, 陕, 甘, 青, 宁", ",");
|
|
@@ -326,7 +324,6 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
* 查集合 - 根据条件(参数为空时代表忽略指定条件)
|
|
|
*/
|
|
|
public List<TbBusiness> getList(SoMap so) {
|
|
|
-
|
|
|
return tbBusinessMapper.getList(so);
|
|
|
}
|
|
|
|
|
@@ -356,10 +353,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
.setConfirmInputTime(new Date())
|
|
|
.setConfirmInputBy(StpUserUtil.getAdmin().getName());
|
|
|
this.updateById(business);
|
|
|
- List<TbBusinessCar> cars = tbBusinessCarService.findByBusinessId(business.getId());
|
|
|
- if (TbBusiness.BusinessType.CAR_DISINCLE.getCode().equals(business.getBusinessType())) {
|
|
|
- cars = Collections.singletonList(tbBusinessCarService.getById(business.getBusinessCarId()));
|
|
|
- }
|
|
|
+ List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(business.getId());
|
|
|
String carNoStr = cars.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
|
|
|
storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认" + DateUtil.now() + "。");
|
|
|
List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
|
|
@@ -497,41 +491,37 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
}
|
|
|
|
|
|
|
|
|
- public Map<String, Object> getBusinessMoney(String carId, String state) {
|
|
|
+ public Map<String, Object> getBusinessMoney(String businessCarId, String state) {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- TbBusinessCar car = tbBusinessCarService.getById(carId);
|
|
|
- String businessId = car.getBusinessId();
|
|
|
- Integer businessType = car.getBusinessType();
|
|
|
- result.put("type", businessType);
|
|
|
- result.put("showPay", true);
|
|
|
+ List<TbBusiness> businessList = this.findOtherBusinessByCarId(businessCarId);
|
|
|
List<TbBusinessCar> cars = new ArrayList<>();
|
|
|
- List<TbBusinessItem> items = new ArrayList<>();
|
|
|
- cars.add(car);
|
|
|
- //其他业务
|
|
|
- String itemTypeId = "";
|
|
|
- if (TbBusiness.BusinessType.CAR_DISINCLE.getCode().equals(businessType)) {
|
|
|
- List<TbBusiness> businesses = this.findOtherBusinessByCarId(carId);
|
|
|
- businesses = businesses.stream()
|
|
|
- .filter(tbBusiness -> tbBusiness.getPayMoney().doubleValue() < tbBusiness.getTotalMoney().doubleValue()
|
|
|
- && ((TbItemType.PayStep.BEFORE_CONFIRM.getCode().equals(tbBusiness.getPayStep()) && tbBusiness.getAdminConfirmInput() >= 0)
|
|
|
- || (TbItemType.PayStep.AFTER_CONFIRM.getCode().equals(tbBusiness.getPayStep()) && tbBusiness.getAdminConfirmInput() == 1)
|
|
|
- )
|
|
|
- )
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<String> businessIdList = businesses.stream().map(TbBusiness::getId).collect(Collectors.toList());
|
|
|
- if (!businessIdList.isEmpty()) {
|
|
|
- itemTypeId = businesses.get(0).getItemTypeId();
|
|
|
- items = tbBusinessItemService.findByBusinessIdList(businessIdList);
|
|
|
- businessId = String.join(",", businessIdList);
|
|
|
- }
|
|
|
- } else if (TbBusiness.BusinessType.HOLD_CAR.getCode().equals(businessType)) {
|
|
|
- cars = tbBusinessCarService.findByBusinessId(businessId);
|
|
|
- TbBusiness tbBusiness = this.getById(businessId);
|
|
|
- if (tbBusiness.getPayStatus() != TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode()) {
|
|
|
- items = tbBusinessItemService.findByBusinessId(businessId);
|
|
|
- }
|
|
|
- }
|
|
|
- result.put("businessId", businessId);
|
|
|
+
|
|
|
+ //中国车是否需要支付
|
|
|
+ int vietnamCarPay = businessList.stream().anyMatch(tbBusiness -> {
|
|
|
+ TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
|
|
|
+ return tbGoods.getVietnamCarPay() == 1;
|
|
|
+ }) ? 1 : 0;
|
|
|
+ //越南车是否需要支付
|
|
|
+ int chinaCarPay = businessList.stream().anyMatch(tbBusiness -> {
|
|
|
+ TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
|
|
|
+ return tbGoods.getChinaCarPay() == 1;
|
|
|
+ }) ? 1 : 0;
|
|
|
+ //无业务的车辆
|
|
|
+ if (businessList.isEmpty()) {
|
|
|
+ vietnamCarPay = 1;
|
|
|
+ chinaCarPay = 1;
|
|
|
+ cars.add(tbBusinessCarService.getById(businessCarId));
|
|
|
+ }
|
|
|
+ businessList.forEach(tbBusiness -> {
|
|
|
+ List<TbBusinessCar> businessCars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
|
|
|
+ cars.addAll(businessCars);
|
|
|
+ });
|
|
|
+ List<String> businessIdList = businessList.stream().map(TbBusiness::getId).collect(Collectors.toList());
|
|
|
+ String businessIds = StrUtil.join(",", businessIdList);
|
|
|
+// result.put("type", businessType);
|
|
|
+ result.put("showPay", true);
|
|
|
+ result.put("businessId", businessIds);
|
|
|
+ List<TbBusinessItem> items = tbBusinessItemService.findByBusinessIdList(businessIdList);
|
|
|
Date now = new Date();
|
|
|
List<Map<String, Object>> carsList = new ArrayList<>();
|
|
|
for (TbBusinessCar tbBusinessCar : cars) {
|
|
@@ -544,7 +534,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
}
|
|
|
partMoney = this.calculationPartMoney(inTime, now);
|
|
|
}
|
|
|
- if (StrUtil.isNotEmpty(tbBusinessCar.getColor())) {
|
|
|
+ if (StrUtil.isNotEmpty(tbBusinessCar.getColor())) {//蓝色车辆免费
|
|
|
List<TbCarNoColor> freeList = tbCarNoColorService.getFreeColor();
|
|
|
List<String> colorList = freeList.stream().map(f -> f.getCarNoColor().substring(0, 1)).collect(Collectors.toList());
|
|
|
String color = tbBusinessCar.getColor().substring(0, 1);
|
|
@@ -552,8 +542,13 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
partMoney = new BigDecimal("0");
|
|
|
}
|
|
|
}
|
|
|
- //越南车牌,整车业务免停车费
|
|
|
- if (!CAR_LIST.contains(carNo) && TbBusiness.BusinessType.HOLD_CAR.getCode().equals(businessType)) {
|
|
|
+
|
|
|
+ //越南车牌,是否免费
|
|
|
+ if (!CAR_LIST.contains(carNo) && vietnamCarPay == 0) {
|
|
|
+ partMoney = new BigDecimal("0");
|
|
|
+ }
|
|
|
+ //中国车,是否免费
|
|
|
+ if (CAR_LIST.contains(carNo) && chinaCarPay == 0) {
|
|
|
partMoney = new BigDecimal("0");
|
|
|
}
|
|
|
Map<String, Object> carMap = new HashMap<>();
|
|
@@ -561,8 +556,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
carMap.put("id", tbBusinessCar.getId());
|
|
|
carMap.put("carNo", tbBusinessCar.getCarNo());
|
|
|
carMap.put("pay", tbBusinessCar.getPay());
|
|
|
- TbCar tbCar = tbCarService.findByCardNo(tbBusinessCar.getCarNo());
|
|
|
- if (tbCar != null && !TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
|
|
|
+ if (TbBusinessCar.PayTypeEnum.FEE_TYPE.getType().equals(tbBusinessCar.getPayType())) {
|
|
|
carMap.put("price", 0);
|
|
|
}
|
|
|
carsList.add(carMap);
|
|
@@ -579,32 +573,29 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
itemMap.put("price", itemPrice);
|
|
|
itemMap.put("pay", item.getPayStatus());
|
|
|
itemList.add(itemMap);
|
|
|
- }
|
|
|
- result.put("itemsPrice", itemsPrice);
|
|
|
- result.put("itemList", itemList);
|
|
|
- if (TbBusiness.BusinessType.CAR_DISINCLE.getCode().equals(businessType) && StrUtil.isNotEmpty(itemTypeId)) {
|
|
|
- TbBusinessSort tbBusinessSort = tbBusinessSortService.findByItemTypeId(itemTypeId);
|
|
|
- TbSortGroup sortGroup = tbSortGroupService.getById(tbBusinessSort.getGroupId());
|
|
|
- if (sortGroup.getCompletePay().equals(1) && sortGroup.getStatus().equals(1)) {
|
|
|
- List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sortGroup.getId());
|
|
|
- if (sorts.size() > items.size()) {
|
|
|
- result.put("showPay", false);
|
|
|
+ TbBusinessSort tbBusinessSort = tbBusinessSortService.findByItemTypeId(item.getItemTypeId());
|
|
|
+ if (tbBusinessSort != null) {
|
|
|
+ TbSortGroup sortGroup = tbSortGroupService.getById(tbBusinessSort.getGroupId());
|
|
|
+ if (sortGroup.getCompletePay().equals(1) && sortGroup.getStatus().equals(1)) {
|
|
|
+ List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sortGroup.getId());
|
|
|
+ if (sorts.size() > items.size()) {
|
|
|
+ result.put("showPay", false);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ result.put("itemsPrice", itemsPrice);
|
|
|
+ result.put("itemList", itemList);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public List<TbBusiness> findOtherBusinessByCarId(String businessCarId) {
|
|
|
- QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
|
|
|
- ew.eq("business_car_id", businessCarId);
|
|
|
- return list(ew);
|
|
|
+ return tbBusinessMapper.findOtherBusinessByCarId(businessCarId);
|
|
|
}
|
|
|
|
|
|
public void uploadReport(TbBusiness tbBusiness) {
|
|
|
this.updateById(tbBusiness);
|
|
|
- List<TbBusinessCar> cars = tbBusinessCarService.findByBusinessId(tbBusiness.getId());
|
|
|
+ List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
|
|
|
tbBusinessCarService.updateBatchById(cars);
|
|
|
}
|
|
|
|
|
@@ -613,31 +604,38 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
return tbBusinessMapper.getCarDisincleList(soMap);
|
|
|
}
|
|
|
|
|
|
- public OtherBusinessEditBO getOtherBusinessById(String id) {
|
|
|
+ public TbBusiness getOtherBusinessById(String id) {
|
|
|
TbBusiness tbBusiness = this.getById(id);
|
|
|
List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessId(id);
|
|
|
- TbBusinessCar car = tbBusinessCarService.getById(tbBusiness.getBusinessCarId());
|
|
|
- OtherBusinessEditBO otherBusinessBO = new OtherBusinessEditBO();
|
|
|
- otherBusinessBO.setId(tbBusiness.getId()).setOperator(tbBusiness.getOperator()).setOperateTime(tbBusiness.getOperateTime());
|
|
|
- otherBusinessBO.setCustomerId(tbBusiness.getCustomerId());
|
|
|
- otherBusinessBO.setCarNo(car.getCarNo()).setCarWeight(tbBusiness.getNetWeight())
|
|
|
- .setCarSize(tbBusiness.getCardSize()).setCarType(tbBusiness.getGoodsName())
|
|
|
- .setItemTypeId(tbBusiness.getItemTypeId());
|
|
|
- otherBusinessBO.setItems(tbBusinessItems);
|
|
|
- return otherBusinessBO;
|
|
|
+ tbBusiness.setItems(tbBusinessItems);
|
|
|
+ List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(id);
|
|
|
+ tbBusiness.setCars(cars);
|
|
|
+ return tbBusiness;
|
|
|
}
|
|
|
|
|
|
public void deleteOtherBusiness(String id) {
|
|
|
TbBusiness db = super.getById(id);
|
|
|
- TbBusinessCar tbBusinessCar = tbBusinessCarService.getById(db.getBusinessCarId());
|
|
|
- if (tbBusinessCar == null || tbBusinessCar.getRealInTime() == null) {
|
|
|
- List<TbBusiness> businesses = this.findOtherBusinessByCarId(db.getBusinessCarId());
|
|
|
- if (businesses.size() == 1) {
|
|
|
- tbBusinessCarService.removeById(db.getBusinessCarId());
|
|
|
- }
|
|
|
+ String declareNo = db.getDeclareNo();
|
|
|
+ if (StrUtil.isNotEmpty(declareNo)) {
|
|
|
+ tbDeclareService.rebackDeclareNo(declareNo);
|
|
|
}
|
|
|
this.removeById(id);
|
|
|
+ //删除响应业务项
|
|
|
tbBusinessItemService.removeByBusinessId(id);
|
|
|
+ //检查是否删除车辆
|
|
|
+ List<TbBusinessCar> tbBusinessCarList = tbBusinessCarService.findOtherBusinessCar(id);
|
|
|
+ tbBusinessCarList.forEach(tbBusinessCar -> {
|
|
|
+ //未入场
|
|
|
+ if (tbBusinessCar.getRealInTime() == null) {
|
|
|
+ List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessCarId(tbBusinessCar.getId());
|
|
|
+ //无关联业务==>删除
|
|
|
+ if (relationBusinessCars.size() == 1) {
|
|
|
+ tbBusinessCarService.removeById(tbBusinessCar.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //删除关系
|
|
|
+ relationBusinessCarService.removeByBusinessId(id);
|
|
|
}
|
|
|
|
|
|
public int checkCarBusinessType(String typeId, String carNo, String operateTime, int before) {
|
|
@@ -648,25 +646,29 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
return tbBusinessMapper.checkCarBusinessTypeByTime(typeId, carNo, timeStart, timeEnd, businessId);
|
|
|
}
|
|
|
|
|
|
- public void manualConfirmPay(String id, String inChannel, Date realInTime, String outChannel, Date realOutTime, String remark) {
|
|
|
+ public void manualConfirmPay(String id, List<TbBusinessCar> cars, String remark) {
|
|
|
TbBusiness db = this.getById(id);
|
|
|
if (db == null) {
|
|
|
throw new BusinessException("业务不存在");
|
|
|
}
|
|
|
- db.setPayStatus(3).setPayMoney(db.getItemPrice());
|
|
|
+ Date now = new Date();
|
|
|
+ db.setPayStatus(3).setPayMoney(db.getItemPrice()).setPayTime(now);
|
|
|
this.updateById(db);
|
|
|
- TbBusinessCar tbBusinessCar = tbBusinessCarService.getById(db.getBusinessCarId());
|
|
|
- if (realInTime != null && realOutTime != null) {
|
|
|
- BigDecimal price = calculationPartMoney(realInTime, realOutTime);
|
|
|
- tbBusinessCar.setMoney(price).setPay(1);
|
|
|
- }
|
|
|
- tbBusinessCar.setInChannel(inChannel)
|
|
|
- .setOutChannel(outChannel)
|
|
|
- .setRealOutTime(realOutTime)
|
|
|
- .setRealInTime(realInTime);
|
|
|
- tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ cars.forEach(tbBusinessCar -> {
|
|
|
+ Date realInTime = tbBusinessCar.getRealInTime();
|
|
|
+ Date realOutTime = tbBusinessCar.getRealOutTime();
|
|
|
+ if (realInTime != null && realOutTime != null) {
|
|
|
+ BigDecimal price = calculationPartMoney(realInTime, realOutTime);
|
|
|
+ tbBusinessCar.setMoney(price);
|
|
|
+ }
|
|
|
+ tbBusinessCar.setPay(1);
|
|
|
+ tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ });
|
|
|
List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
|
|
|
- items.forEach(tbBusinessItem -> tbBusinessItem.setPayStatus(1).setRemark(StrUtil.isEmpty(remark) ? "手动确认" : remark));
|
|
|
+ items.forEach(tbBusinessItem -> tbBusinessItem
|
|
|
+ .setPayStatus(1).setPayTime(now)
|
|
|
+ .setRemark(StrUtil.isEmpty(remark) ? "手动确认" : remark)
|
|
|
+ );
|
|
|
tbBusinessItemService.updateBatchById(items);
|
|
|
}
|
|
|
|
|
@@ -680,29 +682,269 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
tbBusinessMapper.unBindCar(id);
|
|
|
}
|
|
|
|
|
|
- public void bindCar(String id, String businessCarId) {
|
|
|
- TbBusiness db = this.getById(id);
|
|
|
- if (!TbBusiness.BusinessType.CAR_DISINCLE.getCode().equals(db.getBusinessType())) {
|
|
|
- throw new BusinessException("业务类型不正确");
|
|
|
- }
|
|
|
- TbBusinessCar tbBusinessCar = tbBusinessCarService.getById(businessCarId);
|
|
|
- if (tbBusinessCar == null) {
|
|
|
- throw new BusinessException("车辆记录不存在");
|
|
|
- }
|
|
|
- List<TbBusiness> list = this.findOtherBusinessByCarId(businessCarId);
|
|
|
- int count = (int) list.stream().filter(tbBusiness -> !tbBusiness.getId().equals(id) && tbBusiness.getItemTypeId().equals(db.getItemTypeId())).count();
|
|
|
- if (count>0){
|
|
|
- throw new BusinessException("同一车辆请勿绑定多个相同业务");
|
|
|
- }
|
|
|
- String carNo = tbBusinessCar.getCarNo();
|
|
|
- String carNoStr = StrUtil.sub(carNo, 0, 1);
|
|
|
- //中国车
|
|
|
- if (CAR_LIST.contains(carNoStr)) {
|
|
|
- db.setChinaCarNo(carNo);
|
|
|
- } else {
|
|
|
- db.setCardNo(carNo);
|
|
|
+
|
|
|
+ public void addOtherBusiness(OtherBusinessBO otherBusinessBO) {
|
|
|
+ List<TbItem> tbItems = otherBusinessBO.getItems();
|
|
|
+ if (tbItems.isEmpty()) {
|
|
|
+ throw new BusinessException("请选择明细");
|
|
|
}
|
|
|
- db.setBusinessCarId(businessCarId);
|
|
|
- this.updateById(db);
|
|
|
+ List<TbBusinessCar> cars = otherBusinessBO.getCars();
|
|
|
+ if (cars.isEmpty()) {
|
|
|
+ throw new BusinessException("作业车辆不能为空");
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
|
|
|
+ TbBusiness tbBusiness = new TbBusiness();
|
|
|
+ String customerId = otherBusinessBO.getCustomerId();
|
|
|
+ tbBusiness.setCreateBy(StpUserUtil.getAdmin().getName());
|
|
|
+ tbBusiness.setPayStep(tbGoods.getPayStep());
|
|
|
+ TbCostomer tbCostomer = tbCostomerService.getById(customerId);
|
|
|
+ if (tbCostomer != null) {
|
|
|
+ tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
|
|
|
+ }
|
|
|
+ BigDecimal price = new BigDecimal("0");
|
|
|
+ List<TbBusinessItem> itemList = new ArrayList<>();
|
|
|
+ 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();
|
|
|
+ String typeId = tbItem.getTypeId();
|
|
|
+ TbItemType tbItemType = tbItemTypeService.getById(typeId);
|
|
|
+ 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())
|
|
|
+ .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
|
|
|
+ .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
|
|
|
+ .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
|
|
|
+ price = price.add(itemTotalPrice);
|
|
|
+ itemList.add(item);
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ String declareNo = otherBusinessBO.getDeclareNo();
|
|
|
+ tbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
|
|
|
+ .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
|
|
|
+ .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(otherBusinessBO.getGoodsId())
|
|
|
+ .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
|
|
|
+ tbBusiness.setCreateTime(now).setBusinessType(TbBusiness.BusinessType.CAR_DISINCLE.getCode())
|
|
|
+ .setItemPrice(price).setTotalMoney(price);
|
|
|
+ tbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
|
|
|
+ this.save(tbBusiness);
|
|
|
+ Integer chinaCarPay = tbGoods.getChinaCarPay();
|
|
|
+ Integer vietnamCarPay = tbGoods.getVietnamCarPay();
|
|
|
+ String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
|
|
|
+ for (TbBusinessCar car : cars) {
|
|
|
+ String carNo = car.getCarNo().trim().toUpperCase();
|
|
|
+ String carPrefix = StrUtil.sub(carNo, 0, 1);
|
|
|
+ //最新一条记录
|
|
|
+ TbBusinessCar db = tbBusinessCarService.findTheLastRecord(carNo);
|
|
|
+ //不存在,或者已离场记录--->新建记录;
|
|
|
+ if (db == null || db.getRealInTime() != null && db.getRealOutTime() != null) {
|
|
|
+ db = new TbBusinessCar();
|
|
|
+ db.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
|
|
|
+ }
|
|
|
+ for (TbBusinessItem item : itemList) {
|
|
|
+ checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), tbBusiness.getId(), carNo);
|
|
|
+ }
|
|
|
+ if ((CAR_LIST.contains(carPrefix) && chinaCarPay == 1) || (!CAR_LIST.contains(carPrefix) && vietnamCarPay == 1)) {
|
|
|
+ db.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
|
|
|
+ }
|
|
|
+ db.setBusinessType(TbBusiness.BusinessType.CAR_DISINCLE.getCode());
|
|
|
+ TbCar tbCar = tbCarService.findByCardNo(carNo);
|
|
|
+ db.setCarNo(carNo).setBusinessType(TbBusiness.BusinessType.CAR_DISINCLE.getCode())
|
|
|
+ .setIsLock(0).setCarCompany(tbCar != null ? tbCar.getCustomerName() : "临时");
|
|
|
+ db.setCarSize(car.getCarSize())
|
|
|
+ .setTimeUpdate(now).setCarType(car.getCarType())
|
|
|
+ .setNetWeight(car.getNetWeight())
|
|
|
+ .setCustomerId(customerId)
|
|
|
+ .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
|
|
|
+ tbBusinessCarService.saveOrUpdate(db);
|
|
|
+ RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
|
|
|
+ relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(db.getId());
|
|
|
+ relationBusinessCarService.save(relationBusinessCar);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotEmpty(declareNo)) {
|
|
|
+ TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
|
|
|
+ declare.setBusinessId(tbBusiness.getId());
|
|
|
+ }
|
|
|
+ itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
|
|
|
+ tbBusinessItemService.saveBatch(itemList);
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public List<TbBusiness> getOtherBusiness(SoMap startPage) {
|
|
|
+ return tbBusinessMapper.getOtherBusiness(startPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void editOtherBusiness(OtherBusinessBO otherBusinessBO) {
|
|
|
+ String id = otherBusinessBO.getId();
|
|
|
+ TbBusiness dbBusiness = this.getById(id);
|
|
|
+ if (dbBusiness == null) {
|
|
|
+ throw new BusinessException("记录不存在");
|
|
|
+ }
|
|
|
+ List<TbItem> tbItems = otherBusinessBO.getItems();
|
|
|
+ if (tbItems.isEmpty()) {
|
|
|
+ throw new BusinessException("请选择明细");
|
|
|
+ }
|
|
|
+ List<TbBusinessCar> cars = otherBusinessBO.getCars();
|
|
|
+ if (cars.isEmpty()) {
|
|
|
+ throw new BusinessException("作业车辆不能为空");
|
|
|
+ }
|
|
|
+ tbBusinessItemService.removeByBusinessId(id);
|
|
|
+ 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(otherBusinessBO.getGoodsId());
|
|
|
+ Integer chinaCarPay = tbGoods.getChinaCarPay();
|
|
|
+ Integer vietnamCarPay = tbGoods.getVietnamCarPay();
|
|
|
+ String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
|
|
|
+ BigDecimal price = new BigDecimal("0");
|
|
|
+ List<TbBusinessItem> itemList = new ArrayList<>();
|
|
|
+ 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())
|
|
|
+ .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(), otherBusinessBO.getOperateTime(), dbBusiness.getId(), carNo);
|
|
|
+ }
|
|
|
+ String carPrefix = StrUtil.sub(carNo, 0, 1);
|
|
|
+ if (StrUtil.isNotEmpty(businessCarId)) {
|
|
|
+ TbBusinessCar dbBusinessCar = tbBusinessCarService.getById(businessCarId);
|
|
|
+ dbBusinessCar.setNetWeight(tbBusinessCar.getNetWeight()).setCarType(tbBusinessCar.getCarType())
|
|
|
+ .setCarSize(tbBusinessCar.getCarSize()).setCarNo(carNo);
|
|
|
+ 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);
|
|
|
+ if ((CAR_LIST.contains(carPrefix) && chinaCarPay == 1) || (!CAR_LIST.contains(carPrefix) && vietnamCarPay == 1)) {
|
|
|
+ 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(), otherBusinessBO.getGoodsId())) {
|
|
|
+ dbBusiness.setGoodsId(otherBusinessBO.getGoodsId())
|
|
|
+ .setGoodsName(tbGoods.getName()).setPayStep(tbGoods.getPayStep());
|
|
|
+ }
|
|
|
+ String declareNo = otherBusinessBO.getDeclareNo();
|
|
|
+ if (!StrUtil.equals(declareNo, dbBusiness.getDeclareNo())) {
|
|
|
+ tbDeclareService.rebackDeclareNo(dbBusiness.getDeclareNo());
|
|
|
+ }
|
|
|
+ dbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
|
|
|
+ .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
|
|
|
+ .setNo(no).setGoodsId(otherBusinessBO.getGoodsId())
|
|
|
+ .setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
|
|
|
+ dbBusiness.setBusinessType(TbBusiness.BusinessType.CAR_DISINCLE.getCode())
|
|
|
+ .setItemPrice(price).setTotalMoney(price);
|
|
|
+ dbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
|
|
|
+ this.updateById(dbBusiness);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void bindOtherBusinessCar(String businessId, List<String> businessCarIdList) {
|
|
|
+ TbBusiness tbBusiness = this.getById(businessId);
|
|
|
+ relationBusinessCarService.removeByBusinessId(businessId);
|
|
|
+ List<TbBusinessCar> carList = tbBusinessCarService.listByIds(businessCarIdList);
|
|
|
+ String chinaCarNo = carList.stream().filter(tbBusinessCar -> {
|
|
|
+ String carNo = tbBusinessCar.getCarNo();
|
|
|
+ String carStr = StrUtil.sub(carNo, 0, 1);
|
|
|
+ return CAR_LIST.contains(carStr);
|
|
|
+ }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
|
|
|
+ String yueCarNo = carList.stream().filter(tbBusinessCar -> {
|
|
|
+ String carNo = tbBusinessCar.getCarNo();
|
|
|
+ String carStr = StrUtil.sub(carNo, 0, 1);
|
|
|
+ return !CAR_LIST.contains(carStr);
|
|
|
+ }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
|
|
|
+ tbBusiness.setChinaCarNo(chinaCarNo);
|
|
|
+ tbBusiness.setCardNo(yueCarNo);
|
|
|
+ this.updateById(tbBusiness);
|
|
|
+ businessCarIdList.forEach(businessCarId -> {
|
|
|
+ RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
|
|
|
+ relationBusinessCar.setBusinessCarId(businessCarId).setBusinessId(businessId);
|
|
|
+ relationBusinessCarService.save(relationBusinessCar);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkOtherBusiness(String itemTypeId, String operateTimeStr, String businessId, String carNo) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ TbBusinessSort sort = tbBusinessSortService.findByItemTypeId(itemTypeId);
|
|
|
+ List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sort.getGroupId());
|
|
|
+ LocalDateTime operateTime = LocalDateTime.parse(operateTimeStr, formatter);
|
|
|
+ int i = 0;
|
|
|
+ for (TbBusinessSort tbBusinessSort : sorts) {
|
|
|
+ if (i == 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId) && sorts.size() > 1) {
|
|
|
+ TbBusinessSort afterItem = sorts.get(i + 1);
|
|
|
+ String typeId = afterItem.getTypeId();
|
|
|
+ Integer interval = afterItem.getIntervalTime();
|
|
|
+ LocalDateTime endTime = operateTime.plusMinutes(interval);
|
|
|
+ if (afterItem.getIntervalTime() > 0) {
|
|
|
+ int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 1);
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BusinessException("车辆:[" + carNo + "]" + tbBusinessSort.getTypeName() + "后" + afterItem.getIntervalTime() + "分钟才可以执行" + afterItem.getTypeName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (i > 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId)) {
|
|
|
+ TbBusinessSort beforeItem = sorts.get(i - 1);
|
|
|
+ String typeId = beforeItem.getTypeId();
|
|
|
+ Integer interval = tbBusinessSort.getIntervalTime();
|
|
|
+ LocalDateTime endTime = operateTime.minusMinutes(interval);
|
|
|
+ if (tbBusinessSort.getIntervalTime() > 0) {
|
|
|
+ int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 0);
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BusinessException("车辆:[" + carNo + "]" + beforeItem.getTypeName() + "后" + tbBusinessSort.getIntervalTime() + "分钟才可以执行" + tbBusinessSort.getTypeName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer singleIntervalTime = tbBusinessSort.getSingleIntervalTime();
|
|
|
+ String timeStart = operateTime.minusHours(singleIntervalTime).format(formatter);
|
|
|
+ String timeEnd = operateTime.plusHours(singleIntervalTime).format(formatter);
|
|
|
+ int count = this.checkCarBusinessType(itemTypeId, carNo, timeStart, timeEnd, businessId);
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BusinessException("车辆:[" + carNo + "]" + singleIntervalTime + "小时内已有相同作业");
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|