From 6722c529feac8cc177c53cd271d227cd053f2e99 Mon Sep 17 00:00:00 2001 From: linfso Date: Sun, 14 Jul 2024 21:04:16 +0800 Subject: [PATCH] md --- emis-biz-web/emis-biz-web.iml | 26 +- emis-biz-web/pom.xml | 1 - .../erp/emis/service/IEmisWaybillService.java | 10 +- .../service/impl/EmisWaybillServiceImpl.java | 441 ++++++++++++++++++ 4 files changed, 463 insertions(+), 15 deletions(-) diff --git a/emis-biz-web/emis-biz-web.iml b/emis-biz-web/emis-biz-web.iml index b5034d571..c5cd89ef1 100644 --- a/emis-biz-web/emis-biz-web.iml +++ b/emis-biz-web/emis-biz-web.iml @@ -61,11 +61,22 @@ + + + + + + + + + + + + - @@ -77,6 +88,7 @@ + @@ -85,14 +97,6 @@ - - - - - - - - @@ -102,7 +106,6 @@ - @@ -212,9 +215,6 @@ - - - diff --git a/emis-biz-web/pom.xml b/emis-biz-web/pom.xml index 54735f524..6e78e4828 100644 --- a/emis-biz-web/pom.xml +++ b/emis-biz-web/pom.xml @@ -35,7 +35,6 @@ com.xdadan emis-biz 1.0.2 - compile diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java index dc261ae2e..74013a9bf 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java @@ -92,8 +92,16 @@ public interface IEmisWaybillService public int realSubmitOrder(EmisWaybill emisWaybill) throws EmisBizError; + /** + * OMS下单 + * @param emisWaybill + * @return + * @throws EmisBizError + */ + public int realSubmitOrderByOms(EmisWaybill emisWaybill) throws EmisBizError; - /** + + /** * 更新 * @param oldEmisWaybill * @param emisWaybillSave diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java index c43497ee7..f10978c5d 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java @@ -580,6 +580,52 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb } + /** + * 下单接口Oms + * @param emisWaybillSave + * @return + */ + @Override + @Transactional + public int realSubmitOrderByOms(EmisWaybill emisWaybillSave) throws EmisBizError { + + boolean isNew = true; + EmisWaybill emisWaybillOld = null; + + if( !StringUtils.isEmpty(emisWaybillSave.getBillCode()) ){ + emisWaybillOld = this.selectEmisWaybillByBillCode(emisWaybillSave.getBillCode()); + if(emisWaybillOld!=null){ + isNew=false; + } + }else{ + if( !StringUtils.isEmpty(emisWaybillSave.getOrderSn()) ){ + emisWaybillOld = this.selectEmisWaybillByOrderSn(emisWaybillSave.getOrderSn()); + if(emisWaybillOld!=null){ + isNew=false; + } + } + } + + // 新开单 + if(isNew){ + addNewWaybillByOms(emisWaybillSave); + } + // 运单修改 + else{ +// // 检查是否已锁单 +// checkDBBillIsLock(emisWaybillOld); +// +// emisWaybillSave.setId(emisWaybillOld.getId()); +// // 把历史发货日期带过来用于重新计算预估到到时间 +// emisWaybillSave.setSendDate(emisWaybillOld.getSendDate()); +// +// reUpdateWayBill(emisWaybillOld,emisWaybillSave); + } + + return 1; + } + + /** @@ -658,6 +704,284 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb return emisWaybillMapper.assignTakeMan(emisWaybill); } + + /** + * 计算运单公共信息 OMS + * @param emisWaybillSave + * @param isNew + * @throws EmisBizError + */ + private void calcWayBillCommonInfoByOms(EmisWaybill emisWaybillSave,boolean isNew) throws EmisBizError { + + String orderSn = WaybillHelper.genOrderSn(); + emisWaybillSave.setBlGenSubbill("1"); + // 订单号 + if(isNew) { + emisWaybillSave.setOrderSn(orderSn); + } + + // 登记网点 + if(isNew) { + if(!StringUtils.isEmpty(emisWaybillSave.getSendSiteCode())) { + emisWaybillSave.setRegisterSiteCode(emisWaybillSave.getSendSiteCode()); + }else{ + // 没有寄件网点则登记网点放到总部 + emisWaybillSave.setRegisterSiteCode("88888"); + } + +// emisWaybillSave.setRegisterManCode(getCurrentUser().getEmpCode()); + emisWaybillSave.setRegisterDate(new Date()); + } + + if(isNew) { + emisWaybillSave.setDataFrom(WaybillHelper.getDataFrom()); + } + + if(emisWaybillSave.getFreight().floatValue()<=0.0f){ + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"运费必须大于0"); + } + + if( + emisWaybillSave.getTotalVolume().floatValue() <=0.0f + || emisWaybillSave.getBillWeight().floatValue() <=0.0f + ){ + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"体积,实重必须大于0"); + } + + if(StringUtils.isAnyEmpty( + emisWaybillSave.getPickupMethod(), + emisWaybillSave.getDispatchMethod(), + emisWaybillSave.getCustomsEclaration(), + emisWaybillSave.getCustomsClear() + ) + ){ + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"取件方式,派送方式,报关方式,清关方式必填"); + } + + // 默认按重量计费 + emisWaybillSave.setCalcFeeType("1"); +// if(StringUtils.isEmpty(emisWaybillSave.getCalcFeeType())){ +// throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"计费方式必填"); +// } + + + // 发件网点 + if(StringUtils.isEmpty(emisWaybillSave.getSendSiteCode())){ +// throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"寄件网点必填"); + emisWaybillSave.setSendSiteCode("88888"); + }else{ + // 寄件网点财务中心 + EmisSite sendSite = getSiteByCode(emisWaybillSave.getSendSiteCode()); + if(sendSite!=null) { + emisWaybillSave.setSendCenterCode(sendSite.getParentSiteCode()); + } + } + + if(StringUtils.isEmpty(emisWaybillSave.getPackType())){ + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"包装类型必填"); + } + + // 目的网点 + if(StringUtils.isEmpty(emisWaybillSave.getDispatchUnderlingSiteCode())){ +// throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"目的网点必填"); + } + + // 计算单据归属 + String customerCode = emisWaybillSave.getCustomerCode(); + String customerName = emisWaybillSave.getCustomerName(); + + // 订单运单初始状态 订单为已接单,运单未初始,待揽收 + emisWaybillSave.setOrderStatus("0"); + emisWaybillSave.setWaybillStatus("0"); + + // 计算三段码 目的网点2字码+目的地名称 + String destSite3Code = ""; + EmisSite destSite=getSiteByCode(emisWaybillSave.getDispatchUnderlingSiteCode()); + if(destSite!=null){ + destSite3Code=destSite.getSizeCode2(); + // 目的网点财务中心 + emisWaybillSave.setDestinationCenterCode(destSite.getParentSiteCode()); + } + + // 初始 派件网点=目的网点 + emisWaybillSave.setDispatchSiteCode(emisWaybillSave.getDispatchUnderlingSiteName()); + + // 目的地名称 + EmisDestination destination=getDestinationByCode(emisWaybillSave.getDestinationCode()); + String destName=""; + if(destination!=null){ + destName=destination.getDestName(); + } + String thirdCode="["+emisWaybillSave.getSendSiteName()+'-'+destName+"]["+destSite3Code+"]"; + emisWaybillSave.setThirdCode(thirdCode); + // 下单时间 + emisWaybillSave.setOrderDate(emisWaybillSave.getSendDate()); + + // 订单类型 0-客户下单 + emisWaybillSave.setOrderType("0"); + + // 寄件地址 + if(StringUtils.isAnyEmpty( + emisWaybillSave.getSendCountry(), + emisWaybillSave.getSendName(), + emisWaybillSave.getSendMobile(), + emisWaybillSave.getSendProvince(), + emisWaybillSave.getSendAddress() + ) + ){ + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"寄件人信息不完整,名称, 电话,国家,省份,地址必填"); + } + + EmisCustomerAddress sendAddress = new EmisCustomerAddress(); + sendAddress.setCountry(emisWaybillSave.getSendCountry()); + sendAddress.setName(emisWaybillSave.getSendName()); + sendAddress.setPhone(emisWaybillSave.getSendMobile()); + sendAddress.setProvince(emisWaybillSave.getSendProvince()); + sendAddress.setCity(emisWaybillSave.getSendCity()); + sendAddress.setCounty(emisWaybillSave.getSendCounty()); + sendAddress.setTown(emisWaybillSave.getSendTown()); +// recieveAddress.setEmail(emisWaybillSave); + sendAddress.setAddress(emisWaybillSave.getSendAddress()); + sendAddress.setCompany(emisWaybillSave.getSendCompany()); + + sendAddress.setUseSiteCode(emisWaybillSave.getSendSiteCode()); + sendAddress.setAddressType("1"); + + // 收件地址 + if(StringUtils.isAnyEmpty( + emisWaybillSave.getReceiveCountry(), + emisWaybillSave.getReceiveName(), + emisWaybillSave.getReceiveMobile(), + emisWaybillSave.getReceiveProvince(), + emisWaybillSave.getReceiveAddress() + ) + + ){ + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"收件人信息不完整,名称, 电话,国家,省份,地址必填"); + } + + EmisCustomerAddress recieveAddress = new EmisCustomerAddress(); + recieveAddress.setCountry(emisWaybillSave.getReceiveCountry()); + recieveAddress.setName(emisWaybillSave.getReceiveName()); + recieveAddress.setPhone(emisWaybillSave.getReceiveMobile()); + recieveAddress.setProvince(emisWaybillSave.getReceiveProvince()); + recieveAddress.setCity(emisWaybillSave.getReceiveCity()); + recieveAddress.setCounty(emisWaybillSave.getReceiveCounty()); + recieveAddress.setTown(emisWaybillSave.getReceiveTown()); +// recieveAddress.setEmail(emisWaybillSave); + recieveAddress.setAddress(emisWaybillSave.getReceiveAddress()); + recieveAddress.setCompany(emisWaybillSave.getReceiveCompany()); + recieveAddress.setUseSiteCode(emisWaybillSave.getSendSiteCode()); + recieveAddress.setAddressType("2"); + + if( emisWaybillSave.getPaymentType()==null) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"支付方式必填"); + } + + // 月结客户直接根据月结编号获取客户编码和名称 + if( + "2".equals(emisWaybillSave.getPaymentType()) + || "4".equals(emisWaybillSave.getPaymentType()) + || "5".equals(emisWaybillSave.getPaymentType()) + + ){ + EmisCustomerUser emisCustomerUser=getCustomerUserByMonthlyPayCode(emisWaybillSave.getCustNo()); + if(emisCustomerUser==null){ + throw new EmisBizError(EmisBizErrorType.FAIL,"月结客户不存在"); + } + emisWaybillSave.setSalesmen(emisCustomerUser.getSalesmen()); + emisWaybillSave.setPayee(emisCustomerUser.getPayee()); + } + // 到付 + else if( "3".equals(emisWaybillSave.getPaymentType()) ) { + + } + // 寄付和其他 + else{ + + } + + // 保存客户收件、寄件地址 + sendAddress.setCustomerCode(customerCode); + recieveAddress.setCustomerCode(customerCode); + createCustomerAddress(sendAddress); + createCustomerAddress(recieveAddress); + + emisWaybillSave.setCustomerCode(customerCode); + emisWaybillSave.setCustomerName(customerName); + + if( StringUtils.isAnyEmpty( + emisWaybillSave.getTransLineType(), + emisWaybillSave.getProductType() + ) + ) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"线路、产品必填"); + } + + // 获取泡重比 + EmisTransLine emisTransLine = getTransLineByCode(emisWaybillSave.getTransLineType()); + emisWaybillSave.setMeterType(emisTransLine.getMeterRate()); + + // 时效 + EmisTransProduct emisTransProduct = getTransProductByCode(emisWaybillSave.getProductType()); + emisWaybillSave.setTimeType(emisTransProduct.getAgingDesc()); + + if(emisWaybillSave.getSendDate()==null){ + emisWaybillSave.setSendDate(new Date()); + } + +// // 计算目的地 +// EmisDestination destination=calcDestSiteByBase(emisWaybillSave.getReceiveCountry(),emisWaybillSave.getTransLineType(), +// emisWaybillSave.getReceiveProvince(),emisWaybillSave.getReceiveCity(), +// emisWaybillSave.getReceiveCounty(), +// emisWaybillSave.getReceiveAddress()); +// if(destination==null){ +// throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "找不到目的地"); +// } +// +// emisWaybillSave.setDestinationCode(destination.getDestCode()); +// emisWaybillSave.setDispatchUnderlingSiteCode(destination.getSiteCode()); + + try { + // 计算体积重量 + calcVolumeWeight(emisWaybillSave); + // 计算结算重量 + calcSettledWeight(emisWaybillSave); + // 计算应收费 + calcWaybillFee(emisWaybillSave); + }catch (Exception ex){ + ex.printStackTrace(); + log.error("===OMS下单模式,计费错误:",ex.getMessage()); + } + + + if(isNew) { + if( emisWaybillSave.getSendDate()==null ){ + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1,"发件日期必填"); + } + } + // 开单当天不算时效 + Date estDate = getEstimateDate( + emisWaybillSave.getSendDate(),emisWaybillSave.getProductType(), + emisWaybillSave.getSendCountry(), + emisWaybillSave.getReceiveCountry(),0); + + // 预计到达时间 + log.info("预估到达时间==>"+ DateUtils.dateTime(estDate)); + emisWaybillSave.setEstimateDate(estDate); + + // 子单号 + if("1".equals(emisWaybillSave.getBlGenSubbill()) ){ + // 子单号拼接 + StringBuilder sb = new StringBuilder(); + for(int i=1;i<=emisWaybillSave.getParcelQty().intValue();i++){ + sb.append(emisWaybillSave.getBillCode()+ StringUtils.leftPad(String.valueOf(i),4,"0")+","); + } + emisWaybillSave.setBillCodeSub(sb.toString()); + } + + } + /** * 计算运单公共信息 * @param emisWaybillSave @@ -1097,6 +1421,123 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb } + /** + * Oms 新开单 + * @param emisWaybillSave + */ + private void addNewWaybillByOms(EmisWaybill emisWaybillSave) throws EmisBizError { + + // 子单号做扣减 +// if("1".equals(emisWaybillSave.getBlGenSubbill())) { +// int subBillCount = emisElectronicSitePagService.getTotalAvailablePagCount(emisWaybillSave.getSendSiteCode(), "T7080", "1002"); +// if(subBillCount<=0){ +// throw new EmisBizError(EmisBizErrorType.FAIL,"子单数量不足"); +// } +// } + + // 判断网点余额-运单金额 是否足够,如果不够则不允许下单 +// EmisSiteAccount emisSiteAccount=getSiteAccountBySiteCode(emisWaybillSave.getSendSiteCode()); +// if(emisSiteAccount==null){ +// throw new EmisBizError(EmisBizErrorType.FAIL,"网点结算账户不存在,请先开结算账户"); +// } +// +// BigDecimal curMoney=emisSiteAccount.getCurMoney(); +// BigDecimal closeMoney=emisSiteAccount.getCloseMoney(); +// +// BigDecimal newCurMoney=curMoney.subtract(emisWaybillSave.getFreight()); +// if(newCurMoney.compareTo(closeMoney)==-1){ +// throw new EmisBizError(EmisBizErrorType.FAIL,"网点余额不足,请充值"); +// } + + // 公共计算部分 + calcWayBillCommonInfoByOms(emisWaybillSave,true); + + //补齐数据 + emisWaybillMapper.insertEmisWaybill(emisWaybillSave); + + // 扣减子单 + emisElectronicSitePagService.realMatchSubBill(emisWaybillSave.getSendSiteCode(),"T7080",emisWaybillSave.getParcelQty()); + + // 产生主键插入其他数据 + // 插入费用 + List feeitemList=emisWaybillSave.getFeeitemList(); + if(!CollectionUtils.isEmpty(feeitemList)){ + for (EmisWaybillFeeitem feeItem:feeitemList) { + feeItem.setWaybillId(emisWaybillSave.getId()); + emisWaybillFeeitemMapper.insertEmisWaybillFeeitem(feeItem); + } + } + + // 插入商品信息 + if(!CollectionUtil.isEmpty(emisWaybillSave.getCargoList() )){ + List cargoList=emisWaybillSave.getCargoList(); + for (EmisWaybillCargo cargoItem:cargoList) { + cargoItem.setWaybillId(emisWaybillSave.getId()); + emisWaybillCargoMapper.insertEmisWaybillCargo(cargoItem); + } + } + + // 保存货物图片 + if(!StringUtils.isEmpty(emisWaybillSave.getGoodsPics())){ + if(CollectionUtil.isEmpty(emisWaybillSave.getAttachmentList() )){ + List attachmentList = new ArrayList(); + EmisWaybillAttachment goodsPicAttachment = new EmisWaybillAttachment(); + goodsPicAttachment.setAttachType(WaybillAttachType.GOODS_PIC.typeCode); + goodsPicAttachment.setBillCode(emisWaybillSave.getBillCode()); + goodsPicAttachment.setFileUrl(emisWaybillSave.getGoodsPics()); + attachmentList.add(goodsPicAttachment); + emisWaybillSave.setAttachmentList(attachmentList); + } + } + + // 插入附件信息 + if(!CollectionUtil.isEmpty(emisWaybillSave.getAttachmentList() )){ + // 商品附件图片插入到附件 + List attachmentList=emisWaybillSave.getAttachmentList(); + for (EmisWaybillAttachment attachmentItem:attachmentList) { + attachmentItem.setWaybillId(emisWaybillSave.getId()); + attachmentItem.setBillCode(emisWaybillSave.getBillCode()); + emisWaybillAttachmentMapper.insertEmisWaybillAttachment(attachmentItem); + } + } + + // 占用进仓单号 +// if(!StringUtils.isEmpty(emisWaybillSave.getWarehouseInNo())) { +// String warehouseInNo = WaybillHelper.formatQueryValue(emisWaybillSave.getWarehouseInNo()); +//// useWarehouseInNo(emisWaybillSave.getBillCode(),null,warehouseInNo); +// useWarehouseInNo(emisWaybillSave.getBillCode(),null,warehouseInNo); +// } + + // 插入揽收记录 +// ScanInfo scanInfo = new ScanInfo(); +// List> scanDataList = new ArrayList<>(); +// scanInfo.setOpType(2); +// scanInfo.setScanType(ScanType.GOT.opCode); +// +// String dispatchOrSendManCode=""; +// if("1".equals(emisWaybillSave.getPickupMethod())){ +// dispatchOrSendManCode=emisWaybillSave.getOperateEmployeeCode(); +// } +// else if("2".equals(emisWaybillSave.getPickupMethod())){ +// dispatchOrSendManCode=emisWaybillSave.getTakePieceEmployeeCode(); +// } +// +// Map scanDateItem = new HashMap<>(); +// scanDateItem.put("billCode",emisWaybillSave.getBillCode()); +// scanDateItem.put("dispatchOrSendManCode",dispatchOrSendManCode); +// scanDateItem.put("scanDate", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,emisWaybillSave.getSendDate())); +// scanDateItem.put("scanWeight", "0.0"); +// scanDataList.add(scanDateItem); +// scanInfo.setScanData(scanDataList); +// +// try { +// emisTmsScanRecordService.scan(scanInfo); +// } catch (Exception e) { +// e.printStackTrace(); +// } + } + + /** * 运单修改更新 * @param emisWaybillSave