|
@@ -8,6 +8,7 @@ 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,6 +20,9 @@ import cn.hutool.log.StaticLog;
|
|
|
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.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.pj.api.wx.bo.MsgDataBO;
|
|
|
import com.pj.api.wx.service.WxService;
|
|
@@ -31,6 +35,7 @@ import com.pj.project.relation_business_car.RelationBusinessCar;
|
|
|
import com.pj.project.relation_business_car.RelationBusinessCarService;
|
|
|
import com.pj.project.relation_type_item.RelationTypeItemService;
|
|
|
|
|
|
+import com.pj.project.tb_account.TbAccount;
|
|
|
import com.pj.project.tb_business_car.TbBusinessCar;
|
|
|
import com.pj.project.tb_business_car.TbBusinessCarService;
|
|
|
import com.pj.project.tb_business_item.TbBusinessItem;
|
|
@@ -999,7 +1004,6 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 选择异常单发送
|
|
|
*
|
|
@@ -1036,29 +1040,30 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
|
|
|
/**
|
|
|
* 处理车辆支付
|
|
|
+ *
|
|
|
* @param tbBusinessCar
|
|
|
*/
|
|
|
private void handlerCarPay(TbBusinessCar tbBusinessCar) {
|
|
|
- String carNo = tbBusinessCar.getCarNo();
|
|
|
- String payType = tbBusinessCar.getPayType();
|
|
|
- Date payTime = tbBusinessCar.getPayTime();
|
|
|
- Date inTime = tbBusinessCar.getRealInTime();
|
|
|
- if (inTime == null) {
|
|
|
- throw new AjaxError(carNo + "入场时间不能为空");
|
|
|
- }
|
|
|
- Date outTime = tbBusinessCar.getRealOutTime();
|
|
|
- if (outTime == null) {
|
|
|
- throw new AjaxError(carNo + "离场时间不能为空");
|
|
|
- }
|
|
|
- if (payType.equals(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType())) {
|
|
|
- if (payTime == null) {
|
|
|
- throw new AjaxError(carNo + "支付时间不能为空");
|
|
|
- }
|
|
|
- outTime = payTime;
|
|
|
+ String carNo = tbBusinessCar.getCarNo();
|
|
|
+ String payType = tbBusinessCar.getPayType();
|
|
|
+ Date payTime = tbBusinessCar.getPayTime();
|
|
|
+ Date inTime = tbBusinessCar.getRealInTime();
|
|
|
+ if (inTime == null) {
|
|
|
+ throw new AjaxError(carNo + "入场时间不能为空");
|
|
|
+ }
|
|
|
+ Date outTime = tbBusinessCar.getRealOutTime();
|
|
|
+ if (outTime == null) {
|
|
|
+ throw new AjaxError(carNo + "离场时间不能为空");
|
|
|
+ }
|
|
|
+ if (payType.equals(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType())) {
|
|
|
+ if (payTime == null) {
|
|
|
+ throw new AjaxError(carNo + "支付时间不能为空");
|
|
|
}
|
|
|
- //计算停车费
|
|
|
- BigDecimal parkMoney = this.calculationPartMoney(inTime, outTime);
|
|
|
- tbBusinessCar.setMoney(parkMoney);
|
|
|
+ outTime = payTime;
|
|
|
+ }
|
|
|
+ //计算停车费
|
|
|
+ BigDecimal parkMoney = this.calculationPartMoney(inTime, outTime);
|
|
|
+ tbBusinessCar.setMoney(parkMoney);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1079,8 +1084,13 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
log.info("请求返回:{}", resp);
|
|
|
OAResultBO oaResultBO = JSONUtil.toBean(resp, OAResultBO.class);
|
|
|
if (oaResultBO.getSuccess() && oaResultBO.getCode() == 200) {
|
|
|
- tbBusiness.setSendOa(1).setSendTime(new Date()).setSendBy(sendBy)
|
|
|
- .setOaFdId(oaResultBO.getData().getFdId());
|
|
|
+ String fdId = oaResultBO.getData().getFdId();
|
|
|
+ if (StrUtil.isEmpty(fdId)) {
|
|
|
+ throw new BusinessException("流程发起失败");
|
|
|
+ }
|
|
|
+ tbBusiness.setSendOa(1).setOaResult(TbBusiness.OAResultEnum.JUDGE_ING.getCode()).setSendTime(new Date()).setSendBy(sendBy)
|
|
|
+ .setOaFdId(fdId);
|
|
|
+ this.updateById(tbBusiness);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1106,13 +1116,12 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
.setOperationalPerson(operator).setOperationalReason(reason)
|
|
|
.setDocSubject(project + "补单流程").setFdTemplateId(oaConfig.getTemplateId()).setDocCreator(JSONUtil.toJsonStr(docCreator));
|
|
|
//基础信息
|
|
|
- ParamsBO.DataBO.FormValuesBO formValuesBO = buildFormValues(tbBusiness);
|
|
|
+ JSONObject formValues = buildFormValues(tbBusiness);
|
|
|
//车辆信息
|
|
|
- ParamsBO.DataBO.FormValuesBO.VehicleInfoBO vehicleInfoBO = buildCarParams(tbBusinessCars);
|
|
|
- formValuesBO.setVehicleInfo(vehicleInfoBO);
|
|
|
- ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO specificBusinessItemsBO = buildItemPrams(items);
|
|
|
- formValuesBO.setSpecificBusinessItems(specificBusinessItemsBO);
|
|
|
- dataBO.setFormValues(formValuesBO);
|
|
|
+ buildCarParams(tbBusinessCars, formValues);
|
|
|
+ //业务项信息
|
|
|
+ buildItemPrams(items, formValues);
|
|
|
+ dataBO.setFormValues(formValues.toJSONString(0));
|
|
|
paramsBO.setData(dataBO);
|
|
|
return paramsBO;
|
|
|
}
|
|
@@ -1123,8 +1132,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
* @param items
|
|
|
* @return
|
|
|
*/
|
|
|
- private ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO buildItemPrams(List<TbBusinessItem> items) {
|
|
|
- ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO specificBusinessItemsBO = new ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO();
|
|
|
+ private void buildItemPrams(List<TbBusinessItem> items, JSONObject formValues) {
|
|
|
List<String> itemTypeNameList = new ArrayList<>();
|
|
|
List<String> itemNameList = new ArrayList<>();
|
|
|
List<String> itemPriceList = new ArrayList<>();
|
|
@@ -1133,6 +1141,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
List<String> payStatusList = new ArrayList<>();
|
|
|
List<String> payTimeList = new ArrayList<>();
|
|
|
List<String> remarkList = new ArrayList<>();
|
|
|
+ double total = items.stream().collect(Collectors.summarizingDouble(item -> item.getItemPrice().doubleValue())).getSum();
|
|
|
items.forEach(item -> {
|
|
|
itemTypeNameList.add(item.getItemTypeName());
|
|
|
itemNameList.add(item.getItemName());
|
|
@@ -1140,13 +1149,19 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
unitList.add(item.getUnit());
|
|
|
numList.add(item.getNum());
|
|
|
payStatusList.add(item.getPayStatus() == 1 ? "已支付" : "未支付");
|
|
|
- payTimeList.add(item.getPayTime()==null?"-":DateUtil.format(item.getPayTime(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ payTimeList.add(item.getPayTime() == null ? "" : DateUtil.format(item.getPayTime(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
remarkList.add(StrUtil.isEmpty(item.getRemark()) ? "-" : item.getRemark());
|
|
|
});
|
|
|
- specificBusinessItemsBO.setChargingItem(itemTypeNameList)
|
|
|
- .setChargeDetail(itemNameList).setUnitPrice(itemPriceList).setChargingStandard(unitList)
|
|
|
- .setQuantity(numList).setPayoutStatus(payStatusList).setPayTime(payTimeList).setNote(remarkList);
|
|
|
- return specificBusinessItemsBO;
|
|
|
+ formValues
|
|
|
+ .set("specificBusinessItems.chargingItem", itemTypeNameList)
|
|
|
+ .set("specificBusinessItems.chargeDetail", itemNameList)
|
|
|
+ .set("specificBusinessItems.unitPrice", itemPriceList)
|
|
|
+ .set("specificBusinessItems.chargingStandard", unitList)
|
|
|
+ .set("specificBusinessItems.quantity", numList)
|
|
|
+ .set("specificBusinessItems.payoutStatus", payStatusList)
|
|
|
+ .set("specificBusinessItems.payTime", payTimeList)
|
|
|
+ .set("specificBusinessItems.total", Collections.singleton(total))
|
|
|
+ .set("specificBusinessItems.note", remarkList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1155,15 +1170,15 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
* @param tbBusiness
|
|
|
* @return
|
|
|
*/
|
|
|
- private ParamsBO.DataBO.FormValuesBO buildFormValues(TbBusiness tbBusiness) {
|
|
|
+ private JSONObject buildFormValues(TbBusiness tbBusiness) {
|
|
|
ParamsBO.DataBO.FormValuesBO formValuesBO = new ParamsBO.DataBO.FormValuesBO();
|
|
|
String project = tbBusiness.getGoodsName();
|
|
|
- formValuesBO.setOperationalProject(project).setWorkingTime(tbBusiness.getOperateTime())
|
|
|
- .setOperatingOutlay(tbBusiness.getItemPrice()).setAmount(tbBusiness.getItemPrice())
|
|
|
- .setPaymentTime(tbBusiness.getPayTime()).setCargoOwner(tbBusiness.getOwner()).setOperationNo(tbBusiness.getNo())
|
|
|
- .setRecordingTime(tbBusiness.getCreateTime()).setRecorder(tbBusiness.getCreateBy())
|
|
|
+ formValuesBO.setOperationalProject(project).setWorkingTime(tbBusiness.getOperateTime()).setCustomerName(tbBusiness.getCustomerName())
|
|
|
+ .setOperatingOutlay(tbBusiness.getItemPrice().toString()).setAmount(tbBusiness.getItemPrice())
|
|
|
+ .setPaymentTime(tbBusiness.getPayTime() == null ? "" : DateUtil.format(tbBusiness.getPayTime(), "yyyy-MM-dd HH:mm:ss")).setCargoOwner(tbBusiness.getOwner()).setOperationNo(tbBusiness.getNo())
|
|
|
+ .setRecordingTime(DateUtil.format(tbBusiness.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setRecorder(tbBusiness.getCreateBy())
|
|
|
.setIsPay(TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == tbBusiness.getPayStatus() ? "已支付" : "未支付");
|
|
|
- return formValuesBO;
|
|
|
+ return JSONUtil.parseObj(formValuesBO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1172,8 +1187,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
* @param tbBusinessCars
|
|
|
* @return
|
|
|
*/
|
|
|
- private ParamsBO.DataBO.FormValuesBO.VehicleInfoBO buildCarParams(List<TbBusinessCar> tbBusinessCars) {
|
|
|
- ParamsBO.DataBO.FormValuesBO.VehicleInfoBO vehicleInfoBO = new ParamsBO.DataBO.FormValuesBO.VehicleInfoBO();
|
|
|
+ private void buildCarParams(List<TbBusinessCar> tbBusinessCars, JSONObject jsonObject) {
|
|
|
List<String> carNoList = new ArrayList<>();
|
|
|
List<String> typeList = new ArrayList<>();
|
|
|
List<String> loadList = new ArrayList<>();
|
|
@@ -1195,14 +1209,21 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
inList.add(tbBusinessCar.getRealInTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealInTime(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
outList.add(tbBusinessCar.getRealOutTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealOutTime(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
});
|
|
|
- vehicleInfoBO.setLicenseNo(carNoList).setType(typeList).setLoad(loadList).setSpecifications(unitsList)
|
|
|
- .setPaymentStatus(payStatusList).setVehicleState(carStatusList).setParkingFee(feeList)
|
|
|
- .setEntryTime(inList).setDepartureTime(outList);
|
|
|
- return vehicleInfoBO;
|
|
|
+ jsonObject
|
|
|
+ .set("vehicleInfo.licenseNo", carNoList)
|
|
|
+ .set("vehicleInfo.type", typeList)
|
|
|
+ .set("vehicleInfo.load", loadList)
|
|
|
+ .set("vehicleInfo.specifications", unitsList)
|
|
|
+ .set("vehicleInfo.paymentStatus", payStatusList)
|
|
|
+ .set("vehicleInfo.vehicleState", carStatusList)
|
|
|
+ .set("vehicleInfo.parkingFee", feeList)
|
|
|
+ .set("vehicleInfo.entryTime", inList)
|
|
|
+ .set("vehicleInfo.departureTime", outList);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//添加异常单
|
|
|
- public void addErrorBusiness(ErrorBusinessBO errorBusinessBO) {
|
|
|
+ public void addErrorBusiness(ErrorBusinessBO errorBusinessBO, boolean isAdmin) {
|
|
|
List<TbItem> tbItems = errorBusinessBO.getItems();
|
|
|
if (tbItems.isEmpty()) {
|
|
|
throw new BusinessException("请选择明细");
|
|
@@ -1215,14 +1236,14 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
TbGoods tbGoods = tbGoodsService.getById(errorBusinessBO.getGoodsId());
|
|
|
TbBusiness tbBusiness = new TbBusiness();
|
|
|
String customerId = errorBusinessBO.getCustomerId();
|
|
|
- tbBusiness.setCreateBy(StpUserUtil.getAdmin().getNickname());
|
|
|
- tbBusiness.setPayStep(tbGoods.getPayStep());
|
|
|
+ tbBusiness.setCreateBy(StpUserUtil.getAdmin().getNickname())
|
|
|
+ .setPayStep(tbGoods.getPayStep());
|
|
|
TbCostomer tbCostomer = tbCostomerService.getById(customerId);
|
|
|
if (tbCostomer != null) {
|
|
|
tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
|
|
|
}
|
|
|
- boolean businessIsPay=TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus();
|
|
|
- Date businessPayTime=errorBusinessBO.getPayTime();
|
|
|
+ boolean businessIsPay = TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus();
|
|
|
+ Date businessPayTime = errorBusinessBO.getPayTime();
|
|
|
|
|
|
BigDecimal price = new BigDecimal("0");
|
|
|
List<TbBusinessItem> itemList = new ArrayList<>();
|
|
@@ -1242,7 +1263,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
.setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
|
|
|
.setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
|
|
|
price = price.add(itemTotalPrice);
|
|
|
- if (businessIsPay){
|
|
|
+ if (businessIsPay) {
|
|
|
tbBusinessItem.setPayTime(businessPayTime)
|
|
|
.setPayStatus(1);
|
|
|
}
|
|
@@ -1254,7 +1275,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
.setOperator(errorBusinessBO.getOperator()).setOperateTime(errorBusinessBO.getOperateTime())
|
|
|
.setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(errorBusinessBO.getGoodsId())
|
|
|
.setSupplementReason(errorBusinessBO.getSupplementReason()).setSupplementTime(new Date())
|
|
|
- .setSupplementBy(errorBusinessBO.getSupplementBy())
|
|
|
+ .setSupplementBy(errorBusinessBO.getSupplementBy()).setSupplement(1)
|
|
|
.setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(errorBusinessBO.getCardNo());
|
|
|
tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
|
|
|
.setItemPrice(price).setTotalMoney(price).setOwner(errorBusinessBO.getOwner());
|
|
@@ -1273,7 +1294,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
if (StrUtil.isEmpty(carType)) {
|
|
|
throw new BusinessException(carNo + "类型不能为空");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
car.setCreateTime(now).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
|
|
|
if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0)
|
|
|
|| (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
|
|
@@ -1305,11 +1326,14 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
}
|
|
|
itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
|
|
|
tbBusinessItemService.saveBatch(itemList);
|
|
|
-
|
|
|
+ if (isAdmin) {
|
|
|
+ sendOA(tbBusiness, itemList, cars, errorBusinessBO.getSupplementBy());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 单独发起审批
|
|
|
+ *
|
|
|
* @param id
|
|
|
*/
|
|
|
public void applyOA(String id, String sendBy) {
|
|
@@ -1319,4 +1343,156 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
|
|
|
sendOA(tbBusiness, items, tbBusinessCars, sendBy);
|
|
|
this.updateById(tbBusiness);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑异常单
|
|
|
+ *
|
|
|
+ * @param errorBusinessBO
|
|
|
+ */
|
|
|
+ public void editErrorBusiness(ErrorBusinessBO errorBusinessBO) {
|
|
|
+ String id = errorBusinessBO.getId();
|
|
|
+ TbBusiness dbBusiness = this.getById(id);
|
|
|
+ if (dbBusiness == null) {
|
|
|
+ throw new BusinessException("记录不存在");
|
|
|
+ }
|
|
|
+ if (!(dbBusiness.getSendOa() == 0 || TbBusiness.OAResultEnum.NO_PASS.getCode().equals(dbBusiness.getOaResult()))) {
|
|
|
+ throw new BusinessException("业务单正在审核,无法修改");
|
|
|
+ }
|
|
|
+ List<TbItem> tbItems = errorBusinessBO.getItems();
|
|
|
+ if (tbItems.isEmpty()) {
|
|
|
+ throw new BusinessException("请选择收费明细");
|
|
|
+ }
|
|
|
+ List<TbBusinessCar> cars = errorBusinessBO.getCars();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|