From 8224648b197a638a6c9d0b40dab0b4f26e9c867a Mon Sep 17 00:00:00 2001 From: FOAM <491460741@qq.com> Date: Thu, 10 Oct 2024 17:55:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8E=E6=81=92=E6=9C=AC=E7=94=B0=E8=B4=B9?= =?UTF-8?q?=E7=94=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/pojo/DefaultOrderManager.java | 12747 +++++++++------- 1 file changed, 7140 insertions(+), 5607 deletions(-) diff --git a/src/main/java/com/dev/stms/server/service/order/pojo/DefaultOrderManager.java b/src/main/java/com/dev/stms/server/service/order/pojo/DefaultOrderManager.java index 283884a..8337c4c 100644 --- a/src/main/java/com/dev/stms/server/service/order/pojo/DefaultOrderManager.java +++ b/src/main/java/com/dev/stms/server/service/order/pojo/DefaultOrderManager.java @@ -151,10 +151,11 @@ import jxl.NumberCell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; + /** * @author dev */ -@SuppressWarnings("unchecked") +@SuppressWarnings("unchecked") public class DefaultOrderManager extends DefaultBaseManager implements OrderManager { @@ -169,75 +170,82 @@ public class DefaultOrderManager extends DefaultBaseManager implements protected final ILegMonitorService legMonitorService; protected final TmsOperationHisManager operationHisManager; - + protected final FeeManager feeManager; protected final BaseCheckQueryManager baseCheckQueryManager; protected final ImageFileManager imageFileManager; - + protected final ShipmentManager shipmentManager; + public DefaultOrderManager(BeanPropertyUtils beanPropertyUtils, InterfaceLogManager interfaceLogManager, BussinessCodeManager codeManager, IMessageService messageService, ILegMonitorService legMonitorService, - TmsOperationHisManager operationHisManager,FeeManager feeManager, - BaseCheckQueryManager baseCheckQueryManager,ImageFileManager imageFileManager, - ShipmentManager shipmentManager) { + TmsOperationHisManager operationHisManager, FeeManager feeManager, + BaseCheckQueryManager baseCheckQueryManager, + ImageFileManager imageFileManager, ShipmentManager shipmentManager) { this.beanPropertyUtils = beanPropertyUtils; this.interfaceLogManager = interfaceLogManager; this.codeManager = codeManager; this.messageService = messageService; this.legMonitorService = legMonitorService; this.operationHisManager = operationHisManager; - this.feeManager=feeManager; - this.baseCheckQueryManager=baseCheckQueryManager; - this.imageFileManager=imageFileManager; - this.shipmentManager=shipmentManager; + this.feeManager = feeManager; + this.baseCheckQueryManager = baseCheckQueryManager; + this.imageFileManager = imageFileManager; + this.shipmentManager = shipmentManager; } - public void saveOrderSupply(Order order){ + + public void saveOrderSupply(Order order) { commonDao.store(order); } - - public void modifySaveOrder(Order order,File file, - String imageType, String objectType){ -// Order o=commonDao.load(Order.class, order.getId()); -// o.setExtends1(order.getExtends1()); -// o.setExtends2(order.getExtends2()); -// o.setExtends3(order.getExtends3()); -// o.setExtends4(order.getExtends4()); -// if(order.getUnit().equals(MeasureUnit.VEHICLETYPE)){ -// if(order.getExtends1()==null){ -// throw new BusinessException("计费车型1不能为空"); -// } -// } -// if(order.getExtends1()==null && order.getVehicleNumber1()!=null){ -// throw new BusinessException("计费车型1为空,车次数1不能有值"); -// } -// if(order.getExtends2()==null && order.getVehicleNumber2()!=null){ -// throw new BusinessException("计费车型2为空,车次数2不能有值"); -// } -// if(order.getExtends3()==null && order.getVehicleNumber3()!=null){ -// throw new BusinessException("计费车型3为空,车次数3不能有值"); -// } -// if(order.getExtends4()==null && order.getVehicleNumber4()!=null){ -// throw new BusinessException("计费车型4为空,车次数4不能有值"); -// } - if(order.getStatus().equals("SIGNED")){ + + public void modifySaveOrder(Order order, File file, String imageType, + String objectType) { + // Order o=commonDao.load(Order.class, order.getId()); + // o.setExtends1(order.getExtends1()); + // o.setExtends2(order.getExtends2()); + // o.setExtends3(order.getExtends3()); + // o.setExtends4(order.getExtends4()); + // if(order.getUnit().equals(MeasureUnit.VEHICLETYPE)){ + // if(order.getExtends1()==null){ + // throw new BusinessException("计费车型1不能为空"); + // } + // } + // if(order.getExtends1()==null && order.getVehicleNumber1()!=null){ + // throw new BusinessException("计费车型1为空,车次数1不能有值"); + // } + // if(order.getExtends2()==null && order.getVehicleNumber2()!=null){ + // throw new BusinessException("计费车型2为空,车次数2不能有值"); + // } + // if(order.getExtends3()==null && order.getVehicleNumber3()!=null){ + // throw new BusinessException("计费车型3为空,车次数3不能有值"); + // } + // if(order.getExtends4()==null && order.getVehicleNumber4()!=null){ + // throw new BusinessException("计费车型4为空,车次数4不能有值"); + // } + if (order.getStatus().equals("SIGNED")) { throw new BusinessException("订单已回单!"); } commonDao.store(order); - if(null!=file){ - imageFileManager.importImageZip(order.getId(),file,imageType,objectType); + if (null != file) { + imageFileManager.importImageZip(order.getId(), file, imageType, + objectType); } - modifySignOrderDetail(order.getId(),order.getSignTime(),order.getSignNote()); - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "回单管理-回单签收管理", "回单签收",OperationHisUtil.operationHisStatus("ARRIVED"), - OperationHisUtil.operationHisStatus("SIGNED"),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription(), "TMS"); + modifySignOrderDetail(order.getId(), order.getSignTime(), + order.getSignNote()); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "回单管理-回单签收管理", "回单签收", + OperationHisUtil.operationHisStatus("ARRIVED"), + OperationHisUtil.operationHisStatus("SIGNED"), + order.getQuantity(), order.getWeight(), order.getVolume(), 0, + order.getDescription(), "TMS"); } - - public void importImageZip(File file){ - Long id=null; - String imageType="HD"; - String objectType="ORDER"; + + public void importImageZip(File file) { + Long id = null; + String imageType = "HD"; + String objectType = "ORDER"; if (file != null) { String filename = file.getName(); int index = filename.lastIndexOf("-"); @@ -250,38 +258,48 @@ public class DefaultOrderManager extends DefaultBaseManager implements for (int i = 0; i < list.size(); i++) { String fname = (String) list.get(i); File f = new File(fname); - String fn=f.getName(); - String caselsh = fn.substring(0,fn.lastIndexOf(".")); -// caselsh = filename.substring(0,caselsh.lastIndexOf("_")); - String [] strArr= caselsh.split("_"); - caselsh=strArr[0]; - String str=""; - int length=caselsh.length(); - if(length>9) { - str=caselsh.substring(length-9,length); - }else { - str=caselsh; + String fn = f.getName(); + String caselsh = fn.substring(0, fn.lastIndexOf(".")); + // caselsh = + // filename.substring(0,caselsh.lastIndexOf("_")); + String[] strArr = caselsh.split("_"); + caselsh = strArr[0]; + String str = ""; + int length = caselsh.length(); + if (length > 9) { + str = caselsh.substring(length - 9, length); + } else { + str = caselsh; } - String sql=" from Order o where (o.relateBill3 like '%"+str+"' or o.customerOrderNO='"+caselsh+"' or o.relateBill2='"+caselsh+"') " - + "and o.contractor.id="+PlatFormHolder.getPlatForm().getId(); - List orders=commonDao.findByQuery(sql); - if(orders.size()>0){ - id=orders.get(0).getId(); - Order o=commonDao.load(Order.class, id); - if(o.getStatus().equals("ARRIVED")){ - modifySignOrderDetail(o.getId(),o.getArriveTime(),""); + String sql = " from Order o where (o.relateBill3 like '%" + + str + + "' or o.customerOrderNO='" + + caselsh + + "' or o.relateBill2='" + + caselsh + + "') " + + "and o.contractor.id=" + + PlatFormHolder.getPlatForm().getId(); + List orders = commonDao.findByQuery(sql); + if (orders.size() > 0) { + id = orders.get(0).getId(); + Order o = commonDao.load(Order.class, id); + if (o.getStatus().equals("ARRIVED")) { + modifySignOrderDetail(o.getId(), + o.getArriveTime(), ""); } } File newFile = new File(fname + "-" + RandomStringUtils.randomAlphanumeric(6)); f.renameTo(newFile); - imageFileManager.importImageFile(id, newFile, imageType, objectType); + imageFileManager.importImageFile(id, newFile, + imageType, objectType); newFile.delete(); } } else { throw new BusinessException("zip.empty"); } - + } else { throw new BusinessException("only.zip.or.pic"); } @@ -289,34 +307,34 @@ public class DefaultOrderManager extends DefaultBaseManager implements throw new BusinessException("file.empty.or.too.big"); } LocalizedMessage.addLocalizedMessage("上传成功"); - - + } - - - public void modifySaveOrder(Long id, File file1, - File file2,File file3,File file4,File file5,File file6,File file7, - File file8,File file9,File file10,String imageType,String objectType){ - -// System.out.println(file1.getName()); -// URLDecoder.decode(file1.getName()); - Order o=commonDao.load(Order.class, id); - if(o.getStatus().equals("ARRIVED")){ - modifySignOrderDetail(o.getId(),o.getArriveTime(),""); + + public void modifySaveOrder(Long id, File file1, File file2, File file3, + File file4, File file5, File file6, File file7, File file8, + File file9, File file10, String imageType, String objectType) { + + // System.out.println(file1.getName()); + // URLDecoder.decode(file1.getName()); + Order o = commonDao.load(Order.class, id); + if (o.getStatus().equals("ARRIVED")) { + modifySignOrderDetail(o.getId(), o.getArriveTime(), ""); } - imageFileManager.importImageZip(o.getId(),file1,file2,file3,file4,file5,file6,file7,file8,file9,file10,imageType,objectType); - + imageFileManager.importImageZip(o.getId(), file1, file2, file3, file4, + file5, file6, file7, file8, file9, file10, imageType, + objectType); + } - - - public void foreSigneOrder(Order order,File file, - String imageType, String objectType){ - if(order.getStatus().equals("SIGNED")){ + + public void foreSigneOrder(Order order, File file, String imageType, + String objectType) { + if (order.getStatus().equals("SIGNED")) { throw new BusinessException("订单已回单!"); } commonDao.store(order); - if(null!=file){ - imageFileManager.importImageZip(order.getId(),file,imageType,objectType); + if (null != file) { + imageFileManager.importImageZip(order.getId(), file, imageType, + objectType); } Set orderDetails = order.getDetails(); double signQuantity = 0; @@ -333,11 +351,12 @@ public class DefaultOrderManager extends DefaultBaseManager implements order.setDeltaQuantity(deltaQuantity); order.setSignBy(UserHolder.getUser().getName()); order.setStatus(OrderStatus.SIGNED); - for(Legs l:order.getOrderLegs()){ - if(l.getArriveTime()==null){ - if(l.getShipment()!=null&&l.getShipment().getArriveTime()!=null){ + for (Legs l : order.getOrderLegs()) { + if (l.getArriveTime() == null) { + if (l.getShipment() != null + && l.getShipment().getArriveTime() != null) { l.setArriveTime(l.getShipment().getArriveTime()); - }else{ + } else { l.setArriveTime(order.getSignTime()); } l.setStatus(LegsStatus.ARRIVED); @@ -345,160 +364,183 @@ public class DefaultOrderManager extends DefaultBaseManager implements this.commonDao.store(l); } } - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-回单", "强制回单签收",OperationHisUtil.operationHisStatus("ARRIVED"), - OperationHisUtil.operationHisStatus("SIGNED"),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription(), "TMS"); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "订单管理-回单", "强制回单签收", + OperationHisUtil.operationHisStatus("ARRIVED"), + OperationHisUtil.operationHisStatus("SIGNED"), + order.getQuantity(), order.getWeight(), order.getVolume(), 0, + order.getDescription(), "TMS"); } - - - + /** * * @date: 2008-5-23 下午05:08:58 * @description: 编辑订单,对订单新增,修改功能增加条件约束 * */ - public void storeOrder(Order vOrder,String consignorName) { - if(vOrder.isNew()){ + public void storeOrder(Order vOrder, String consignorName) { + if (vOrder.isNew()) { vOrder.setSingleIdentity(true); vOrder.setStatus(OrderStatus.INPUT); - }else{ - if(!vOrder.getStatus().equals(OrderStatus.INPUT)){ + } else { + if (!vOrder.getStatus().equals(OrderStatus.INPUT)) { throw new BusinessException("状态不正确"); } } - storeTransOrder(vOrder,consignorName); + storeTransOrder(vOrder, consignorName); } - public void checkOrderInputInfo(Order order){ - if(CheckUtils.isTrimEmpty(order.getUnit())){ + + public void checkOrderInputInfo(Order order) { + if (CheckUtils.isTrimEmpty(order.getUnit())) { throw new BusinessException("计量单位必填"); - }else if(CheckUtils.isTrimEmpty(order.getSuperviseType())){ - //throw new BusinessException("货物类型必填"); - }else if(CheckUtils.isTrimEmpty(order.getPaymentMethod())){ + } else if (CheckUtils.isTrimEmpty(order.getSuperviseType())) { + // throw new BusinessException("货物类型必填"); + } else if (CheckUtils.isTrimEmpty(order.getPaymentMethod())) { throw new BusinessException("付款方式必填"); } - int jzt=0; - if(order.getQuantity()>0){ - jzt=jzt+1; + int jzt = 0; + if (order.getQuantity() > 0) { + jzt = jzt + 1; } - if(order.getWeight()>0){ - jzt=jzt+1; + if (order.getWeight() > 0) { + jzt = jzt + 1; } - if(order.getVolume()>0){ - jzt=jzt+1; + if (order.getVolume() > 0) { + jzt = jzt + 1; } -// if(jzt<2){ -// throw new BusinessException("件重体其中两项必须大于0"); -// } - Organization org=order.getConsignor(); - if(org.getIsJK()!=null && org.getIsJK()==true && order.getPredictFee()==0){ - throw new BusinessException(org.getShortName()+"客户必须填写货值!"); + // if(jzt<2){ + // throw new BusinessException("件重体其中两项必须大于0"); + // } + Organization org = order.getConsignor(); + if (org.getIsJK() != null && org.getIsJK() == true + && order.getPredictFee() == 0) { + throw new BusinessException(org.getShortName() + "客户必须填写货值!"); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); - String re_StrTime = null; - if(order.getPlanArriveTime()!=null){ + String re_StrTime = null; + if (order.getPlanArriveTime() != null) { re_StrTime = sdf1.format(order.getPlanArriveTime()); } - if(order.getDeclare()!=null && !"".equals(order.getDeclare()) && re_StrTime!=null){ - re_StrTime=re_StrTime+" "+order.getDeclare(); + if (order.getDeclare() != null && !"".equals(order.getDeclare()) + && re_StrTime != null) { + re_StrTime = re_StrTime + " " + order.getDeclare(); try { - Date d=sdf.parse(re_StrTime); - order.setPlanArriveTime(d); - } catch (ParseException e) { - // TODO Auto-generated catch block + Date d = sdf.parse(re_StrTime); + order.setPlanArriveTime(d); + } catch (ParseException e) { + // TODO Auto-generated catch block throw new BusinessException("计划到达时间格式不对!"); - } + } } - if(order.getPlanLeaveTime()!=null){ - if(order.getOrderDate().after(order.getPlanLeaveTime())){ + if (order.getPlanLeaveTime() != null) { + if (order.getOrderDate().after(order.getPlanLeaveTime())) { throw new BusinessException("计划出发时间必须大于开单时间!"); } } - if(order.getPlanArriveTime()!=null && order.getPlanLeaveTime()!=null){ - if(order.getPlanLeaveTime().after(order.getPlanArriveTime())){ + if (order.getPlanArriveTime() != null + && order.getPlanLeaveTime() != null) { + if (order.getPlanLeaveTime().after(order.getPlanArriveTime())) { throw new BusinessException("计划到达时间必须大于计划出发时间!"); } } } - public void storeTransOrder(Order order,String consignorName) { - this.storeTransOrderSB(order, Boolean.FALSE,null,null,null); + + public void storeTransOrder(Order order, String consignorName) { + this.storeTransOrderSB(order, Boolean.FALSE, null, null, null); } - public void storeTransOrderSB(Order order,Boolean equipment,Long platFormId,Long userId,String userName) { -// if(CheckUtils.isTrimEmpty(order.getUnitOne())){ -// throw new BusinessException("单位必填"); -// }else -// String hql="select id from Order o where o.relateBill2='"+order.getRelateBill2()+"'"; -// List os=new ArrayList(); -// String hql1="select id from Order o where o.department.id=1004 and o.relateBill1='"+order.getRelateBill1()+"'"; -// List orb=new ArrayList(); - //判断 计划出发时间如果有值的话必须大于等于开单日期。计划到达时间也必须大于等于计划出发时间 - if(!equipment){ + + public void storeTransOrderSB(Order order, Boolean equipment, + Long platFormId, Long userId, String userName) { + // if(CheckUtils.isTrimEmpty(order.getUnitOne())){ + // throw new BusinessException("单位必填"); + // }else + // String + // hql="select id from Order o where o.relateBill2='"+order.getRelateBill2()+"'"; + // List os=new ArrayList(); + // String + // hql1="select id from Order o where o.department.id=1004 and o.relateBill1='"+order.getRelateBill1()+"'"; + // List orb=new ArrayList(); + // 判断 计划出发时间如果有值的话必须大于等于开单日期。计划到达时间也必须大于等于计划出发时间 + if (!equipment) { checkOrderInputInfo(order); } if (order.isNew()) { - if(order.getCode().isEmpty()){ + if (order.getCode().isEmpty()) { order.setCode(codeManager.generateItemCode()); } - if(!order.isSingleIdentity()){ + if (!order.isSingleIdentity()) { order.setStatus(OrderStatus.AVAILABLE); } -// if (retrieveOrder(order)) { -// throw new BusinessException("tms.code.exist"); -// } - + // if (retrieveOrder(order)) { + // throw new BusinessException("tms.code.exist"); + // } + order.setOperatorDate(new Date()); order.setCreateTime(new Date()); order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); order.setContractor(PlatFormHolder.getPlatForm()); order.setOtherStatus(FeeStatus.OPEN); } - if(order.getFromCityCountiy()==null){ - if(order.getFromLocation()!=null){ - TransLocation fromL=this.commonDao.get(TransLocation.class, order.getFromLocation().getId()); + if (order.getFromCityCountiy() == null) { + if (order.getFromLocation() != null) { + TransLocation fromL = this.commonDao.get(TransLocation.class, + order.getFromLocation().getId()); order.setFromCityCountiy(fromL.getCity()); } } order.setFromCity(order.getFromCityCountiy()); order.setToCity(order.getToCityCountiy()); order.setInvName(order.getInvName()); -// City fromCity=order.getFromCityCountiy(); -// TransLocation fromLocation=baseCheckQueryManager.getTransLocation(order.getContractor(),Boolean.TRUE,CheckUtils.extractChar(order.getFromName()), fromCity,CheckUtils.extractChar(order.getFromContact().getAddress()), -// CheckUtils.extractChar(order.getFromContact().getPhone()), CheckUtils.extractChar(order.getFromContact().getLinkman()), order.getDescription1()); -// order.setFromLocation(fromLocation); -// order.setFromContact(fromLocation.getContact()); -// order.setFromName(fromLocation.getName()); -// order.setFromLocation(fromLocation); -// if(order.getToCityCountiy()==null){ -// if(order.getToLocation()!=null){ -// TransLocation toL=this.commonDao.get(TransLocation.class, order.getToLocation().getId()); -// order.setToCityCountiy(toL.getCity()); -// } -// } -// City toCity=order.getToCityCountiy(); -// TransLocation toLocation=baseCheckQueryManager.getTransLocation(order.getContractor(),Boolean.FALSE,CheckUtils.extractChar(order.getToName()), toCity,CheckUtils.extractChar(order.getToContact().getAddress()), -// CheckUtils.extractChar(order.getToContact().getPhone()), CheckUtils.extractChar(order.getToContact().getLinkman()), order.getDescription2()); -// order.setToLocation(toLocation); -// order.setToContact(toLocation.getContact()); -// order.setToName(toLocation.getName()); -// if(toLocation==null){ -// if(toCity!=null){ -// List t2s=this.commonDao.findByQuery("from TransLocation t where t.sourceId="+toCity.getId()); -// if(t2s.size()>0){ -// order.setToLocation(t2s.get(0)); -// } -// } -// } + // City fromCity=order.getFromCityCountiy(); + // TransLocation + // fromLocation=baseCheckQueryManager.getTransLocation(order.getContractor(),Boolean.TRUE,CheckUtils.extractChar(order.getFromName()), + // fromCity,CheckUtils.extractChar(order.getFromContact().getAddress()), + // CheckUtils.extractChar(order.getFromContact().getPhone()), + // CheckUtils.extractChar(order.getFromContact().getLinkman()), + // order.getDescription1()); + // order.setFromLocation(fromLocation); + // order.setFromContact(fromLocation.getContact()); + // order.setFromName(fromLocation.getName()); + // order.setFromLocation(fromLocation); + // if(order.getToCityCountiy()==null){ + // if(order.getToLocation()!=null){ + // TransLocation toL=this.commonDao.get(TransLocation.class, + // order.getToLocation().getId()); + // order.setToCityCountiy(toL.getCity()); + // } + // } + // City toCity=order.getToCityCountiy(); + // TransLocation + // toLocation=baseCheckQueryManager.getTransLocation(order.getContractor(),Boolean.FALSE,CheckUtils.extractChar(order.getToName()), + // toCity,CheckUtils.extractChar(order.getToContact().getAddress()), + // CheckUtils.extractChar(order.getToContact().getPhone()), + // CheckUtils.extractChar(order.getToContact().getLinkman()), + // order.getDescription2()); + // order.setToLocation(toLocation); + // order.setToContact(toLocation.getContact()); + // order.setToName(toLocation.getName()); + // if(toLocation==null){ + // if(toCity!=null){ + // List + // t2s=this.commonDao.findByQuery("from TransLocation t where t.sourceId="+toCity.getId()); + // if(t2s.size()>0){ + // order.setToLocation(t2s.get(0)); + // } + // } + // } if (StringUtils.isEmpty(order.getGroupNo())) { order.setGroupNo(codeManager.generateGroupNo()); } - if(order.getRelateBill3()==null||order.getRelateBill3().equals("")){ - order.setRelateBill3(codeManager.generateLegsCode(PlatFormHolder.getPlatForm().getCode())); + if (order.getRelateBill3() == null || order.getRelateBill3().equals("")) { + order.setRelateBill3(codeManager.generateLegsCode(PlatFormHolder + .getPlatForm().getCode())); } if (order.isNew()) { - List legs=this.commonDao.findByQuery("from Legs l where l.order.id=:orderId", - new String[]{"orderId"},new Object[]{order.getId()}); - for(Legs leg:legs){ + List legs = this.commonDao.findByQuery( + "from Legs l where l.order.id=:orderId", + new String[] { "orderId" }, new Object[] { order.getId() }); + for (Legs leg : legs) { leg.setToCode(order.getToCode()); leg.setFromCode(order.getFromCode()); leg.setFromLocation(order.getFromLocation()); @@ -509,73 +551,92 @@ public class DefaultOrderManager extends DefaultBaseManager implements leg.setToName(order.getToName()); this.commonDao.store(leg); } - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-订单维护", "新建",OperationHisUtil.operationHisStatus("INPUT"), - OperationHisUtil.operationHisStatus("INPUT"),order.getQuantity(), order.getWeight(),order.getVolume(), 0, order.getDescription(), "TMS"); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "订单管理-订单维护", "新建", + OperationHisUtil.operationHisStatus("INPUT"), + OperationHisUtil.operationHisStatus("INPUT"), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, order.getDescription(), "TMS"); } else { - if(!equipment){ - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-订单维护", "修改", - OperationHisUtil.operationHisStatus(order.getStatus()),OperationHisUtil.operationHisStatus(order.getStatus()), - order.getQuantity(), order.getWeight(), order.getVolume(),0, order.getDescription(), "TMS"); - }else{ - operationHisManager.saveOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-订单维护", "APP新建", - OperationHisUtil.operationHisStatus(order.getStatus()),OperationHisUtil.operationHisStatus(order.getStatus()), - order.getQuantity(), order.getWeight(), order.getVolume(),0, order.getDescription(), "TMS", Boolean.TRUE,platFormId, userId, userName); + if (!equipment) { + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "订单管理-订单维护", "修改", + OperationHisUtil.operationHisStatus(order.getStatus()), + OperationHisUtil.operationHisStatus(order.getStatus()), + order.getQuantity(), order.getWeight(), + order.getVolume(), 0, order.getDescription(), "TMS"); + } else { + operationHisManager.saveOperationHis(order.getId(), + order.getRelateBill3(), null, null, "订单管理-订单维护", + "APP新建", + OperationHisUtil.operationHisStatus(order.getStatus()), + OperationHisUtil.operationHisStatus(order.getStatus()), + order.getQuantity(), order.getWeight(), + order.getVolume(), 0, order.getDescription(), "TMS", + Boolean.TRUE, platFormId, userId, userName); } } - if(!CheckUtils.isTrimEmpty(order.getPaymentMethod())&&!order.getPaymentMethod().equals(SysCodeValue.DF_FK)&&!order.getPaymentMethod().equals(SysCodeValue.XF_FK)){ + if (!CheckUtils.isTrimEmpty(order.getPaymentMethod()) + && !order.getPaymentMethod().equals(SysCodeValue.DF_FK) + && !order.getPaymentMethod().equals(SysCodeValue.XF_FK)) { order.setCash(0); } - if(order.getStatus().equals("TRANS_AVAILABLE")){ - String unt=order.getUnit(); - double quantityTwo=order.getQuantityTwo(); - double weightTwo=order.getWeightTwo(); - double volumeTwo=order.getVolumeTwo(); - order=commonDao.load(Order.class, order.getId()); + if (order.getStatus().equals("TRANS_AVAILABLE")) { + String unt = order.getUnit(); + double quantityTwo = order.getQuantityTwo(); + double weightTwo = order.getWeightTwo(); + double volumeTwo = order.getVolumeTwo(); + order = commonDao.load(Order.class, order.getId()); order.setQuantityTwo(quantityTwo); order.setWeightTwo(weightTwo); order.setVolumeTwo(volumeTwo); order.setUnit(unt); } - + this.commonDao.store(order); this.orderPrescription(order); - if(equipment){ - List ids=new ArrayList(); + if (equipment) { + List ids = new ArrayList(); ids.add(order.getId()); - availableTransOrderSB(ids, equipment,userName); + availableTransOrderSB(ids, equipment, userName); } } + public void storeTransOrderTwo(Order order) { - if(!"".equals(order.getBillCode()) && null!=order.getBillCode()){ + if (!"".equals(order.getBillCode()) && null != order.getBillCode()) { throw new BusinessException("已对账!不能修改。"); } checkOrderInputInfo(order); - if(order.getFromCity()==null){ + if (order.getFromCity() == null) { order.setFromCity(order.getFromCityCountiy()); order.setToCity(order.getToCityCountiy()); } if (!order.isNew()) { - List legs=this.commonDao.findByQuery("from Legs l where l.order.id=:orderId ", - new String[]{"orderId"},new Object[]{order.getId()}); - int i=0; - double quantity=0; - double weight=0; - double Volume=0; - String superviseType=""; - String shipmentMethod=""; - String address=""; - Long consignorId=null; - List objs= commonDao.findByQuery("select o.consignor.id,o.quantity,o.weight,o.volume from Order o where o.id=:id ", - new String[] { "id" },new Object[] { order.getId() }); - if(objs.size()>0){ - Object[] obj=objs.get(0); - consignorId=Long.parseLong(obj[0].toString()); - quantity=(Double)obj[1]; - weight=(Double)obj[2]; - Volume=(Double)obj[3]; + List legs = this.commonDao.findByQuery( + "from Legs l where l.order.id=:orderId ", + new String[] { "orderId" }, new Object[] { order.getId() }); + int i = 0; + double quantity = 0; + double weight = 0; + double Volume = 0; + String superviseType = ""; + String shipmentMethod = ""; + String address = ""; + Long consignorId = null; + List objs = commonDao + .findByQuery( + "select o.consignor.id,o.quantity,o.weight,o.volume from Order o where o.id=:id ", + new String[] { "id" }, + new Object[] { order.getId() }); + if (objs.size() > 0) { + Object[] obj = objs.get(0); + consignorId = Long.parseLong(obj[0].toString()); + quantity = (Double) obj[1]; + weight = (Double) obj[2]; + Volume = (Double) obj[3]; } this.commonDao.store(order); - for(Legs leg:legs){ + for (Legs leg : legs) { i++; leg.setFromLocation(order.getFromLocation()); leg.setFromContact(order.getFromContact()); @@ -585,60 +646,80 @@ public class DefaultOrderManager extends DefaultBaseManager implements leg.setToName(order.getToName()); leg.setConsignor(order.getConsignor()); leg.setWeight(order.getWeight()); - //如果重量为0,则断定为泡货,泡货的话需要则算重量比,1:3 - if(order.getWeight()<=0){ - leg.setShareWeight(DoubleUtils.format3Fraction(order.getVolume()/(order.getFeeRate()*0.001))); - }else{ + // 如果重量为0,则断定为泡货,泡货的话需要则算重量比,1:3 + if (order.getWeight() <= 0) { + leg.setShareWeight(DoubleUtils.format3Fraction(order + .getVolume() / (order.getFeeRate() * 0.001))); + } else { leg.setShareWeight(order.getWeight()); } leg.setVolume(order.getVolume()); leg.setQuantity(order.getQuantity()); this.commonDao.store(leg); - Shipment s=leg.getShipment(); - if(s!=null) { - List ss= commonDao.findByQuery("select sum(o.quantity),sum(o.weight),sum(o.volume) from Legs o where o.shipment.id=:id ", - new String[] { "id" },new Object[] { s.getId() }); - if(ss.size()>0){ - Object[] obj=ss.get(0); - s.setQuantity((Double)obj[0]); - s.setWeight((Double)obj[1]); - s.setVolume((Double)obj[2]); - s.setQuantityFee(s.getQuantity()); - s.setWeightFee(s.getWeight()); - s.setVolumeFee(s.getVolume()); - this.commonDao.store(s); + Shipment s = leg.getShipment(); + if (s != null) { + List ss = commonDao + .findByQuery( + "select sum(o.quantity),sum(o.weight),sum(o.volume) from Legs o where o.shipment.id=:id ", + new String[] { "id" }, + new Object[] { s.getId() }); + if (ss.size() > 0) { + Object[] obj = ss.get(0); + s.setQuantity((Double) obj[0]); + s.setWeight((Double) obj[1]); + s.setVolume((Double) obj[2]); + s.setQuantityFee(s.getQuantity()); + s.setWeightFee(s.getWeight()); + s.setVolumeFee(s.getVolume()); + this.commonDao.store(s); + } } } - } -// if(order.getFromLocation()!=null){ -// TransLocation fromLocation=this.commonDao.get(TransLocation.class, order.getFromLocation().getId()); -// fromLocation.setName(order.getFromName()); -// fromLocation.setContact(order.getFromContact()); -// fromLocation.setPlatForm(order.getContractor()); -// commonDao.store(fromLocation); -// } -// if(order.getToLocation()!=null){ -// TransLocation toLocation=this.commonDao.get(TransLocation.class, order.getToLocation().getId()); -// toLocation.setName(order.getToName()); -// toLocation.setContact(order.getToContact()); -// toLocation.setPlatForm(order.getContractor()); -// commonDao.store(toLocation); -// } - - String remark=""; - if(!consignorId.equals(order.getConsignor().getId())||quantity-order.getQuantity()!=0 || weight-order.getWeight()!=0 || Volume-order.getVolume()!=0){ - remark="原客户Id"+consignorId+";原数量"+quantity+";原重量"+weight+";原体积"+Volume+";" - + "现客户Id"+order.getConsignor().getId()+";现数量"+order.getQuantity()+";现重量"+order.getWeight()+";现体积"+order.getVolume(); - //运输费查询 - if(!consignorId.equals(order.getConsignor().getId())){ - List ids = commonDao.findByQuery("select f.id from Fee f where f.billId=:id and f.billObject='ORDER' ", - new String[] { "id"},new Object[] {order.getId() }); + // if(order.getFromLocation()!=null){ + // TransLocation + // fromLocation=this.commonDao.get(TransLocation.class, + // order.getFromLocation().getId()); + // fromLocation.setName(order.getFromName()); + // fromLocation.setContact(order.getFromContact()); + // fromLocation.setPlatForm(order.getContractor()); + // commonDao.store(fromLocation); + // } + // if(order.getToLocation()!=null){ + // TransLocation toLocation=this.commonDao.get(TransLocation.class, + // order.getToLocation().getId()); + // toLocation.setName(order.getToName()); + // toLocation.setContact(order.getToContact()); + // toLocation.setPlatForm(order.getContractor()); + // commonDao.store(toLocation); + // } + + String remark = ""; + if (!consignorId.equals(order.getConsignor().getId()) + || quantity - order.getQuantity() != 0 + || weight - order.getWeight() != 0 + || Volume - order.getVolume() != 0) { + remark = "原客户Id" + consignorId + ";原数量" + quantity + ";原重量" + + weight + ";原体积" + Volume + ";" + "现客户Id" + + order.getConsignor().getId() + ";现数量" + + order.getQuantity() + ";现重量" + order.getWeight() + + ";现体积" + order.getVolume(); + // 运输费查询 + if (!consignorId.equals(order.getConsignor().getId())) { + List ids = commonDao + .findByQuery( + "select f.id from Fee f where f.billId=:id and f.billObject='ORDER' ", + new String[] { "id" }, + new Object[] { order.getId() }); feeManager.deleteFee(ids); - }else{ - List fees = commonDao.findByQuery("from Fee f where f.billId=:id and f.billObject='ORDER' and f.feeName.id=:feeNameid ", - new String[] { "id","feeNameid" },new Object[] { order.getId(),1008L }); - for(Fee f:fees){ - order.setReceivefee(order.getReceivefee()-f.getTotalFee()); + } else { + List fees = commonDao + .findByQuery( + "from Fee f where f.billId=:id and f.billObject='ORDER' and f.feeName.id=:feeNameid ", + new String[] { "id", "feeNameid" }, + new Object[] { order.getId(), 1008L }); + for (Fee f : fees) { + order.setReceivefee(order.getReceivefee() + - f.getTotalFee()); f.setPrice(0); f.setQuantity(1); f.setTotalFee(0); @@ -656,36 +737,43 @@ public class DefaultOrderManager extends DefaultBaseManager implements order.setFee7(0); order.setFee8(0); } - }else{ - if(order.getCash()>0){ - if(order.getPaymentMethod().equals(SysCodeValue.DF_FK)){ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, "现付", "运输费", 0d); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, "到付", "运输费", order.getCash()); - }else if(order.getPaymentMethod().equals(SysCodeValue.XF_FK)){ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, "现付", "运输费", order.getCash()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, "到付", "运输费", 0d); - }else{ + } else { + if (order.getCash() > 0) { + if (order.getPaymentMethod().equals(SysCodeValue.DF_FK)) { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, "现付", "运输费", 0d); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, "到付", "运输费", + order.getCash()); + } else if (order.getPaymentMethod().equals( + SysCodeValue.XF_FK)) { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, "现付", "运输费", + order.getCash()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, "到付", "运输费", 0d); + } else { order.setCash(0); order.setFee6(0); order.setFee7(0); } - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); } - remark=order.getDescription(); + remark = order.getDescription(); } commonDao.store(order); this.orderPrescription(order); - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-费用维护", "特殊修改", - OperationHisUtil.operationHisStatus(order.getStatus()),OperationHisUtil.operationHisStatus(order.getStatus()), - order.getQuantity(), order.getWeight(), order.getVolume(),0, remark, "TMS"); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "订单管理-费用维护", "特殊修改", + OperationHisUtil.operationHisStatus(order.getStatus()), + OperationHisUtil.operationHisStatus(order.getStatus()), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, remark, "TMS"); } - - } - - - - + } + private void processOrder(Order order) { // 初始化FromLocation,ToLocation用于判断是否为配送运输类型订单,市内/市外 TransLocation fromLocation = load(TransLocation.class, order @@ -694,35 +782,39 @@ public class DefaultOrderManager extends DefaultBaseManager implements .getToLocation().getId()); order.setFromLocation(fromLocation); order.setToLocation(toLocation); -// if (toLocation.getCity().getCode() -// .equals(fromLocation.getCity().getCode())) { -// order.setBusinessType(BusinessType.IN); -// } else { -// order.setBusinessType(BusinessType.OUT); -// } - + // if (toLocation.getCity().getCode() + // .equals(fromLocation.getCity().getCode())) { + // order.setBusinessType(BusinessType.IN); + // } else { + // order.setBusinessType(BusinessType.OUT); + // } + if (order.getOrderType().getIsTransport()) { order.setSelfDelivery(false); } order.setSignNo(order.getCode()); order.setBussinessMode(order.getOrderType().getType()); } - public void storeShipOrder(Order order){ + + public void storeShipOrder(Order order) { commonDao.store(order); - List legs=this.commonDao.findByQuery("from Legs l where l.order.id=:orderId", - new String[]{"orderId"},new Object[]{order.getId()}); - if(legs.size()>0){ - //判断leg的状态,如果已调度,则不允许更改 - }else{ - order.setRelateBill3(codeManager.generateLegsCode(order.getDepartment().getCode())); + List legs = this.commonDao.findByQuery( + "from Legs l where l.order.id=:orderId", + new String[] { "orderId" }, new Object[] { order.getId() }); + if (legs.size() > 0) { + // 判断leg的状态,如果已调度,则不允许更改 + } else { + order.setRelateBill3(codeManager.generateLegsCode(order + .getDepartment().getCode())); publishEdiServerAvailableOrder(order); -// for(Legs l : order.getOrderLegs() ){ -// l.setLegNo(codeManager.generateLegsCode()); -// commonDao.store(l); -// } + // for(Legs l : order.getOrderLegs() ){ + // l.setLegNo(codeManager.generateLegsCode()); + // commonDao.store(l); + // } } - + } + /** * * @date: 2008-5-23 下午04:35:42 @@ -824,7 +916,7 @@ public class DefaultOrderManager extends DefaultBaseManager implements if ((OrderStatus.INPUT.equals(order.getStatus()) || OrderStatus.UNCHECK.equals(order.getStatus()) || OrderStatus.FAILED.equals(order.getStatus()) || OrderStatus.LOCKED - .equals(order.getStatus()))) { + .equals(order.getStatus()))) { order.setExecutePlan(load(ExecutePlan.class, executePlanId)); if (OrderStatus.AVAILABLE.equals(order.getStatus())) changTransPlan(order); @@ -914,10 +1006,13 @@ public class DefaultOrderManager extends DefaultBaseManager implements public void availableOrder(List ids) { for (Order order : loadAllOrder(ids)) { availableOrder(order); - //saveFee(order); - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-订单维护", "生效", - OperationHisUtil.operationHisStatus("INPUT"),OperationHisUtil.operationHisStatus("AVAILABLE"), - order.getQuantity(), order.getWeight(), order.getVolume(),0, order.getDescription(), "TMS"); + // saveFee(order); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "订单管理-订单维护", "生效", + OperationHisUtil.operationHisStatus("INPUT"), + OperationHisUtil.operationHisStatus("AVAILABLE"), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, order.getDescription(), "TMS"); } } @@ -935,80 +1030,106 @@ public class DefaultOrderManager extends DefaultBaseManager implements order.setActiveTime(new Date()); setUpdateInfo(order); commonDao.store(order); - //publishEdiServerAvailableOrder(order); + // publishEdiServerAvailableOrder(order); } else { throw new BusinessException("order.status.error"); } } + public void availableTransOrder(List ids) { -// String hql="from Order o where o.consignor.code='YK' and to_char(o.planFromDate,'yyyy-mm-dd')<='2019-11-21'" -// + " and to_char(o.planFromDate,'yyyy-mm-dd')>='2019-11-01' and status!='INPUT'" -// + " and status!='AVAILABLE'"; -// //hql+= " and receivefee>0"; -//// hql+=" and o.predictFee>0"; -// List os=this.commonDao.findByQuery(hql); -// int i=0; -// System.out.println(os.size()+"==="+new Date()); -// for(Order order:os){ -// System.out.println(i++); -// deleteOpFee(order); -// createCusFee(order); -//// order.setFee1(0); -//// order.setFee2(0); -//// order.setFee3(0); -//// order.setFee4(0); -//// order.setFee5(0); -//// order.setFee6(0); -//// order.setFee7(0); -//// order.setFee8(0); -//// order.setFee9(0); -//// order.setFee10(0); -//// feeManager.saveOrderInputFee(order); -// feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); -// } -// System.out.println("end==="+new Date()); - availableTransOrderSB(ids, Boolean.FALSE,UserHolder.getUser().getName()); + // String + // hql="from Order o where o.consignor.code='YK' and to_char(o.planFromDate,'yyyy-mm-dd')<='2019-11-21'" + // + + // " and to_char(o.planFromDate,'yyyy-mm-dd')>='2019-11-01' and status!='INPUT'" + // + " and status!='AVAILABLE'"; + // //hql+= " and receivefee>0"; + // // hql+=" and o.predictFee>0"; + // List os=this.commonDao.findByQuery(hql); + // int i=0; + // System.out.println(os.size()+"==="+new Date()); + // for(Order order:os){ + // System.out.println(i++); + // deleteOpFee(order); + // createCusFee(order); + // // order.setFee1(0); + // // order.setFee2(0); + // // order.setFee3(0); + // // order.setFee4(0); + // // order.setFee5(0); + // // order.setFee6(0); + // // order.setFee7(0); + // // order.setFee8(0); + // // order.setFee9(0); + // // order.setFee10(0); + // // feeManager.saveOrderInputFee(order); + // feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + // Boolean.TRUE); + // } + // System.out.println("end==="+new Date()); + availableTransOrderSB(ids, Boolean.FALSE, UserHolder.getUser() + .getName()); } - public void availableTransOrderSB(List ids,Boolean equipment,String userName) { + + public void availableTransOrderSB(List ids, Boolean equipment, + String userName) { Long startTime = System.currentTimeMillis(); - for (Long id:ids) { - Order order=commonDao.get(Order.class, id); - if(order.getStatus().equals("INPUT")||order.getStatus().equals("CHECKED")||order.getStatus().equals("AVAILABLE")){ + for (Long id : ids) { + Order order = commonDao.get(Order.class, id); + if (order.getStatus().equals("INPUT") + || order.getStatus().equals("CHECKED") + || order.getStatus().equals("AVAILABLE")) { getVehicleCountNum(id); order.setStatus(OrderStatus.TRANS_AVAILABLE); - order.setFeeTime(new Date());//计费时间 - order.setActiveTime(new Date());//生效时间 - if(order.getQuantity()==0){ + order.setFeeTime(new Date());// 计费时间 + order.setActiveTime(new Date());// 生效时间 + if (order.getQuantity() == 0) { order.setQuantity(order.getQuantityTwo()); - order.setWeight(DoubleUtils.formatByPrecision(order.getWeightTwo(),5)); - order.setVolume(DoubleUtils.formatByPrecision(order.getVolumeTwo(),7)); + order.setWeight(DoubleUtils.formatByPrecision( + order.getWeightTwo(), 5)); + order.setVolume(DoubleUtils.formatByPrecision( + order.getVolumeTwo(), 7)); } orderPrescription(order); publishEdiServerAvailableOrder(order); - if(order.getCash()>0){ - FeeType ft=getFeeType(SysCodeValue.YS_FYKM); - feeManager.createFee(id, BillObjectType.ORDER, ft,"CASH",0,userName); + if (order.getCash() > 0) { + FeeType ft = getFeeType(SysCodeValue.YS_FYKM); + feeManager.createFee(id, BillObjectType.ORDER, ft, "CASH", + 0, userName); } - if(order.getFee11()>0){ - feeManager.saveInputFee(id, BillObjectType.ORDER, null,"代收运费", order.getFee11()); + if (order.getFee11() > 0) { + feeManager.saveInputFee(id, BillObjectType.ORDER, null, + "代收运费", order.getFee11()); } createCusFee(order); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - if(!equipment){ - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-订单维护", "生效", - OperationHisUtil.operationHisStatus("INPUT"),OperationHisUtil.operationHisStatus("AVAILABLE"), - order.getQuantity(), order.getWeight(), order.getVolume(),0, order.getDescription(), "TMS"); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + if (!equipment) { + operationHisManager + .storeOperationHis(order.getId(), order + .getRelateBill3(), null, null, "订单管理-订单维护", + "生效", OperationHisUtil + .operationHisStatus("INPUT"), + OperationHisUtil + .operationHisStatus("AVAILABLE"), + order.getQuantity(), order.getWeight(), + order.getVolume(), 0, order + .getDescription(), "TMS"); } - if(order.getContractor().isBeSale()){ - List legs=this.commonDao.findByQuery("from Legs l where l.order.id=:orderId", - new String[]{"orderId"},new Object[]{order.getId()}); - if(legs.size()>0){ - List ss=this.commonDao.findByQuery("from Separate s where s.order.id="+order.getId()); - for(int i=ss.size();i<(int)order.getQuantity();i++){ + if (order.getContractor().isBeSale()) { + List legs = this.commonDao.findByQuery( + "from Legs l where l.order.id=:orderId", + new String[] { "orderId" }, + new Object[] { order.getId() }); + if (legs.size() > 0) { + List ss = this.commonDao + .findByQuery("from Separate s where s.order.id=" + + order.getId()); + for (int i = ss.size(); i < (int) order.getQuantity(); i++) { Separate separate = new Separate(); - separate.setBoxNumber(i+1);//箱序号 + separate.setBoxNumber(i + 1);// 箱序号 separate.setSeparateQty(1); - separate.setContainerNo(order.getRelateBill3()+"_"+(i+1));//分单号 + separate.setContainerNo(order.getRelateBill3() + + "_" + (i + 1));// 分单号 separate.setOperator(UserHolder.getUser().getName()); separate.setOperatorDate(new Date()); separate.setOrder(order); @@ -1023,880 +1144,1086 @@ public class DefaultOrderManager extends DefaultBaseManager implements Long tempTime = (endTime - startTime); System.out.println(tempTime); } - public void refreshOrderFee(List ids){ -// List ls=this.commonDao.findByQuery("from Legs s where 1=1 " -// + "and to_char(s.order.planFromDate,'yyyy-mm-dd')>='2020-09-01' and to_char(s.order.planFromDate,'yyyy-mm-dd')<='2020-09-30' " -// + "and s.shipment.id is not null " -// + "and s.order.consignor.id in (3776,3216,4811) " -// + "and s.shipment.carrier.id not in (3176,3177) " -// ); -// for(Legs l:ls){ -// Shipment s=l.getShipment(); -// if(s.getPayfee()==0){ -// l.setPayfee(0); -// this.commonDao.store(l); -// } -// Order order=l.getOrder(); -// double payfee=(Double)commonDao.findByQuery("select nvl(sum(payfee+otherFee+supplierFee+expense),0) from Legs l where l.order.id=:orderId", -// new String[]{"orderId"},new Object[]{order.getId()}).get(0); -// order.setPayfee(DoubleUtils.format3Fraction(DoubleUtils.format3Fraction(payfee))); -// this.commonDao.store(order); -// } -// List os=this.commonDao.findByQuery("from Order o where 1=1 " -// + "and to_char(o.planFromDate,'yyyy-mm-dd')>='2020-10-01' and to_char(o.planFromDate,'yyyy-mm-dd')<='2020-12-20' " -// + "and o.consignor.code='GQCQ' and volumeThree<30" -// ); -// int i=0; -// for(Order order:os){ -// System.out.println(os.size()+"==="+i); -// deleteOpFee(order); -// createCusFee(order); -// feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); -// i++; -// } - - for(Long id:ids){ - Order order=commonDao.load(Order.class, id); - Boolean temp=Boolean.TRUE; - if(order.getConsignor().getCode().equals("DKN")){ - City toC=order.getToCity(); - if(toC!=null){ - String name=toC.getName(); - if(name.equals("长沙市")||name.equals("萍乡市")||name.equals("株洲市")||name.equals("湘潭市")||name.equals("常德市")||name.equals("衡阳市")){ - temp=Boolean.FALSE; - //湖南省内,按照车型计算费用 + + public void refreshOrderFee(List ids) { + // List ls=this.commonDao.findByQuery("from Legs s where 1=1 " + // + + // "and to_char(s.order.planFromDate,'yyyy-mm-dd')>='2020-09-01' and to_char(s.order.planFromDate,'yyyy-mm-dd')<='2020-09-30' " + // + "and s.shipment.id is not null " + // + "and s.order.consignor.id in (3776,3216,4811) " + // + "and s.shipment.carrier.id not in (3176,3177) " + // ); + // for(Legs l:ls){ + // Shipment s=l.getShipment(); + // if(s.getPayfee()==0){ + // l.setPayfee(0); + // this.commonDao.store(l); + // } + // Order order=l.getOrder(); + // double + // payfee=(Double)commonDao.findByQuery("select nvl(sum(payfee+otherFee+supplierFee+expense),0) from Legs l where l.order.id=:orderId", + // new String[]{"orderId"},new Object[]{order.getId()}).get(0); + // order.setPayfee(DoubleUtils.format3Fraction(DoubleUtils.format3Fraction(payfee))); + // this.commonDao.store(order); + // } + // List os=this.commonDao.findByQuery("from Order o where 1=1 " + // + + // "and to_char(o.planFromDate,'yyyy-mm-dd')>='2020-10-01' and to_char(o.planFromDate,'yyyy-mm-dd')<='2020-12-20' " + // + "and o.consignor.code='GQCQ' and volumeThree<30" + // ); + // int i=0; + // for(Order order:os){ + // System.out.println(os.size()+"==="+i); + // deleteOpFee(order); + // createCusFee(order); + // feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + // Boolean.TRUE); + // i++; + // } + + for (Long id : ids) { + Order order = commonDao.load(Order.class, id); + Boolean temp = Boolean.TRUE; + if (order.getConsignor().getCode().equals("DKN")) { + City toC = order.getToCity(); + if (toC != null) { + String name = toC.getName(); + if (name.equals("长沙市") || name.equals("萍乡市") + || name.equals("株洲市") || name.equals("湘潭市") + || name.equals("常德市") || name.equals("衡阳市")) { + temp = Boolean.FALSE; + // 湖南省内,按照车型计算费用 } } } - if(temp){ - -// SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); -// List os=commonDao.findByQuery("from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')>=:planFromDate and o.predictFee>0 ", -// new String[] { "id","planFromDate"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate())}); -// for(Order o:os){ -// deleteOpFee(o); -// createCusFee(o); -// feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); -// } + if (temp) { + + // SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); + // List + // os=commonDao.findByQuery("from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')>=:planFromDate and o.predictFee>0 ", + // new String[] { "id","planFromDate"},new Object[] + // {order.getConsignor().getId(),sdf.format(order.getPlanFromDate())}); + // for(Order o:os){ + // deleteOpFee(o); + // createCusFee(o); + // feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, + // Boolean.TRUE); + // } deleteOpFee(order); createCusFee(order); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); } } } - - public void refreshShipmentFee(List ids){ - for(Long id:ids){ - Shipment s=commonDao.load(Shipment.class, id); -// if(s.getPayfee()>0||s.getOtherFee()>0){ -// return; -// } - List fees = this.commonDao.findByQuery( - "from Fee f where f.billId=:feeId and f.billCode=:billCode and f.operator='system' ", - new String[] { "feeId", "billCode" }, - new Object[] { s.getId(), s.getCode()}); + + public void refreshShipmentFee(List ids) { + for (Long id : ids) { + Shipment s = commonDao.load(Shipment.class, id); + // if(s.getPayfee()>0||s.getOtherFee()>0){ + // return; + // } + List fees = this.commonDao + .findByQuery( + "from Fee f where f.billId=:feeId and f.billCode=:billCode and f.operator='system' ", + new String[] { "feeId", "billCode" }, new Object[] { + s.getId(), s.getCode() }); for (Fee fee : fees) { - if(fee.getBillFee()!=null){ - throw new BusinessException(s.getCode()+"费用已对帐,不能取消回单"); + if (fee.getBillFee() != null) { + throw new BusinessException(s.getCode() + "费用已对帐,不能取消回单"); } this.commonDao.delete(fee); } - List f2s = this.commonDao.findByQuery( - "from Fee f where f.billId in (select id from Legs l where l.shipment.id=:sId) and f.billObject='LEGS' and f.operator='system' ", - new String[] { "sId" }, - new Object[] { s.getId()}); + List f2s = this.commonDao + .findByQuery( + "from Fee f where f.billId in (select id from Legs l where l.shipment.id=:sId) and f.billObject='LEGS' and f.operator='system' ", + new String[] { "sId" }, new Object[] { s.getId() }); for (Fee fee : f2s) { - if(fee.getBillFee()!=null){ - throw new BusinessException(s.getCode()+"费用已对帐,不能取消回单"); + if (fee.getBillFee() != null) { + throw new BusinessException(s.getCode() + "费用已对帐,不能取消回单"); } this.commonDao.delete(fee); } createCarrierFee(s); - //如果该调度单为DKN湖南客户,则直接刷新应收 - List ls=this.commonDao.findByQuery("from Legs l where l.shipment.id="+s.getId()+" and l.order.consignor.code='DKN'" - + " and l.order.toCity.name in ('长沙市','常德市','湘潭市','株洲市','萍乡市','衡阳市') " - + " and l.order.toName in ('梅溪湖','芙蓉北','芙蓉南','湘江路','秋收广场','红旗广场','岳塘店','柳叶店','衡州大道') " - + " and l.shipment.vehicleType.name in ('17米5半挂','19米半挂','9米6厢式货车','7米6厢式货车')"); - if(ls.size()>0){ - VehicleType vt=s.getVehicleType(); - double price=0; - if(vt.getName().equals("17米5半挂")||vt.getName().equals("19米半挂")){ - price=4300; - }else if(vt.getName().equals("9米6厢式货车")){ - price=3000; - }else if(vt.getName().equals("7米6厢式货车")){ - price=2800; + // 如果该调度单为DKN湖南客户,则直接刷新应收 + List ls = this.commonDao + .findByQuery("from Legs l where l.shipment.id=" + + s.getId() + + " and l.order.consignor.code='DKN'" + + " and l.order.toCity.name in ('长沙市','常德市','湘潭市','株洲市','萍乡市','衡阳市') " + + " and l.order.toName in ('梅溪湖','芙蓉北','芙蓉南','湘江路','秋收广场','红旗广场','岳塘店','柳叶店','衡州大道') " + + " and l.shipment.vehicleType.name in ('17米5半挂','19米半挂','9米6厢式货车','7米6厢式货车')"); + if (ls.size() > 0) { + VehicleType vt = s.getVehicleType(); + double price = 0; + if (vt.getName().equals("17米5半挂") + || vt.getName().equals("19米半挂")) { + price = 4300; + } else if (vt.getName().equals("9米6厢式货车")) { + price = 3000; + } else if (vt.getName().equals("7米6厢式货车")) { + price = 2800; } - //需要计算整车价格,和每个门店的送货费 - Boolean ysf=Boolean.FALSE; - FeeType ft=getFeeType("运输费"); - for(Legs l:ls){ - Order o=l.getOrder(); - List fs=isOpFee(o, ft); - if(fs.size()>0){ - //如果有运费,看看是否正确,修改金额 - if(ysf){ + // 需要计算整车价格,和每个门店的送货费 + Boolean ysf = Boolean.FALSE; + FeeType ft = getFeeType("运输费"); + for (Legs l : ls) { + Order o = l.getOrder(); + List fs = isOpFee(o, ft); + if (fs.size() > 0) { + // 如果有运费,看看是否正确,修改金额 + if (ysf) { deleteFees(fs); - }else{ + } else { deleteFees(fs); - createFeeInfo(o.getRelateBill3(), o.getId(), BillObjectType.ORDER, o.getCarrier(), ft, - 1, price, 1*price, FeePayReceive.RECEIVE, MeasureUnit.TICKET, o.getContractor()); + createFeeInfo(o.getRelateBill3(), o.getId(), + BillObjectType.ORDER, o.getCarrier(), ft, + 1, price, 1 * price, FeePayReceive.RECEIVE, + MeasureUnit.TICKET, o.getContractor()); } - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - ysf=Boolean.TRUE; + feeManager.refreshBillFee(o.getId(), + BillObjectType.ORDER, Boolean.TRUE); + ysf = Boolean.TRUE; } } - if(!ysf){ - //如果没有运输费,随便创建即可。 - Order o=ls.get(0).getOrder(); - createFeeInfo(o.getRelateBill3(), o.getId(), BillObjectType.ORDER, o.getCarrier(), ft, - 1, price, 1*price, FeePayReceive.RECEIVE, MeasureUnit.TICKET, o.getContractor()); - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); + if (!ysf) { + // 如果没有运输费,随便创建即可。 + Order o = ls.get(0).getOrder(); + createFeeInfo(o.getRelateBill3(), o.getId(), + BillObjectType.ORDER, o.getCarrier(), ft, 1, price, + 1 * price, FeePayReceive.RECEIVE, + MeasureUnit.TICKET, o.getContractor()); + feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, + Boolean.TRUE); } - List mans=this.commonDao.findByQuery("select l.order.toName from Legs l where l.shipment.id="+s.getId() - + " and l.order.toCity.name in ('长沙市','常德市','湘潭市','株洲市','萍乡市','衡阳市') " - + " and l.order.toName in ('梅溪湖','芙蓉北','芙蓉南','湘江路','秋收广场','红旗广场','岳塘店','柳叶店','衡州大道') " - + " and l.order.toName is not null group by l.order.toName"); - FeeType ft2=getFeeType("送货费"); - for(String man:mans){ - Boolean shf=Boolean.FALSE; - double price2=0; - if(man.equals("梅溪湖")||man.equals("芙蓉北")||man.equals("芙蓉南")||man.equals("湘江路")){ - price2=340; - }else if(man.equals("秋收广场")||man.equals("岳塘店")||man.equals("红旗广场")){ - price2=540; - }else if(man.equals("柳叶店")||man.equals("衡州大道")){ - price2=880; + List mans = this.commonDao + .findByQuery("select l.order.toName from Legs l where l.shipment.id=" + + s.getId() + + " and l.order.toCity.name in ('长沙市','常德市','湘潭市','株洲市','萍乡市','衡阳市') " + + " and l.order.toName in ('梅溪湖','芙蓉北','芙蓉南','湘江路','秋收广场','红旗广场','岳塘店','柳叶店','衡州大道') " + + " and l.order.toName is not null group by l.order.toName"); + FeeType ft2 = getFeeType("送货费"); + for (String man : mans) { + Boolean shf = Boolean.FALSE; + double price2 = 0; + if (man.equals("梅溪湖") || man.equals("芙蓉北") + || man.equals("芙蓉南") || man.equals("湘江路")) { + price2 = 340; + } else if (man.equals("秋收广场") || man.equals("岳塘店") + || man.equals("红旗广场")) { + price2 = 540; + } else if (man.equals("柳叶店") || man.equals("衡州大道")) { + price2 = 880; } - List ls2=this.commonDao.findByQuery("from Legs l where l.shipment.id="+s.getId()+" and l.order.toName='"+man+"'"); - for(Legs l:ls2){ - Order o=l.getOrder(); - List fs=isOpFee(o, ft2); - if(fs.size()>0){ - //如果有送货费,看看是否正确,修改金额 - if(shf){ + List ls2 = this.commonDao + .findByQuery("from Legs l where l.shipment.id=" + + s.getId() + " and l.order.toName='" + man + + "'"); + for (Legs l : ls2) { + Order o = l.getOrder(); + List fs = isOpFee(o, ft2); + if (fs.size() > 0) { + // 如果有送货费,看看是否正确,修改金额 + if (shf) { deleteFees(fs); - }else{ + } else { deleteFees(fs); - createFeeInfo(o.getRelateBill3(), o.getId(), BillObjectType.ORDER, o.getCarrier(), ft2, - 1, price2, 1*price2, FeePayReceive.RECEIVE, MeasureUnit.TICKET, o.getContractor()); + createFeeInfo(o.getRelateBill3(), o.getId(), + BillObjectType.ORDER, o.getCarrier(), + ft2, 1, price2, 1 * price2, + FeePayReceive.RECEIVE, + MeasureUnit.TICKET, o.getContractor()); } - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - shf=Boolean.TRUE; + feeManager.refreshBillFee(o.getId(), + BillObjectType.ORDER, Boolean.TRUE); + shf = Boolean.TRUE; } } - if(!shf){ - //如果没有送货费,随便创建即可。 - Order o=ls2.get(0).getOrder(); - createFeeInfo(o.getRelateBill3(), o.getId(), BillObjectType.ORDER, o.getCarrier(), ft2, - 1, price2, 1*price2, FeePayReceive.RECEIVE, MeasureUnit.TICKET, o.getContractor()); - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); + if (!shf) { + // 如果没有送货费,随便创建即可。 + Order o = ls2.get(0).getOrder(); + createFeeInfo(o.getRelateBill3(), o.getId(), + BillObjectType.ORDER, o.getCarrier(), ft2, 1, + price2, 1 * price2, FeePayReceive.RECEIVE, + MeasureUnit.TICKET, o.getContractor()); + feeManager.refreshBillFee(o.getId(), + BillObjectType.ORDER, Boolean.TRUE); } } } - + } } - - public void createCusFee(Order order){ - String cusCode=order.getConsignor().getCode(); - if(cusCode.equals("DJKT")){ - List vs=this.commonDao.findByQuery("from LfItemView o where o.oh_id="+order.getId()); - if(vs.size()>0){ - int bz=order.getGroupIndex(); - //链风材料,走其他的运算逻辑 - List ods=this.commonDao.findByQuery("from OrderDetail od where od.order.id="+order.getId()); - double vt=0; - double price=0; - double shf=0; - for(OrderDetail od:ods){ - LfItemView v=this.get(LfItemView.class, od.getId()); + + public void createCusFee(Order order) { + String cusCode = order.getConsignor().getCode(); + if (cusCode.equals("DJKT")) { + List vs = this.commonDao + .findByQuery("from LfItemView o where o.oh_id=" + + order.getId()); + if (vs.size() > 0) { + int bz = order.getGroupIndex(); + // 链风材料,走其他的运算逻辑 + List ods = this.commonDao + .findByQuery("from OrderDetail od where od.order.id=" + + order.getId()); + double vt = 0; + double price = 0; + double shf = 0; + for (OrderDetail od : ods) { + LfItemView v = this.get(LfItemView.class, od.getId()); System.out.println(od.getId()); - Item item=od.getItem(); - if(item==null){ - List items= this.commonDao.findByQuery("from Item i where i.code=:code ", - new String[]{"code"},new Object[]{od.getMaterielCode()}); - if(items.size()>0){ - item=items.get(0); + Item item = od.getItem(); + if (item == null) { + List items = this.commonDao.findByQuery( + "from Item i where i.code=:code ", + new String[] { "code" }, + new Object[] { od.getMaterielCode() }); + if (items.size() > 0) { + item = items.get(0); od.setItem(item); } - System.out.println(od.getId()+"=="+item.getCode()); + System.out.println(od.getId() + "==" + item.getCode()); System.out.println(item.getMinPackageUnit()); } - PackageUnit unit=item.getMinPackageUnit(); - if(v!=null){ - shf=v.getShf(); - od.setVolume2(DoubleUtils.format4Fraction(v.getLength()*v.getWidth()*v.getHeight()/1000000)); - od.setVolume(od.getVolume2()*v.getQuantity()); - if(bz==1){ - price=v.getPrice1(); - }else{ - price=v.getPrice2(); + PackageUnit unit = item.getMinPackageUnit(); + if (v != null) { + shf = v.getShf(); + od.setVolume2(DoubleUtils.format4Fraction(v.getLength() + * v.getWidth() * v.getHeight() / 1000000)); + od.setVolume(od.getVolume2() * v.getQuantity()); + if (bz == 1) { + price = v.getPrice1(); + } else { + price = v.getPrice2(); } od.setReceivedQuantity(price); - }else{ + } else { od.setReceivedQuantity(item.getPrice()); - od.setVolume2(DoubleUtils.format4Fraction(unit.getLength()*unit.getWidth()*unit.getHeight())); - od.setVolume(od.getVolume2()*od.getQuantity()); + od.setVolume2(DoubleUtils.format4Fraction(unit + .getLength() + * unit.getWidth() + * unit.getHeight())); + od.setVolume(od.getVolume2() * od.getQuantity()); } - od.setVolume2(DoubleUtils.format4Fraction(unit.getLength()*unit.getWidth()*unit.getHeight())); - od.setVolume(od.getVolume2()*od.getQuantity()); + od.setVolume2(DoubleUtils.format4Fraction(unit.getLength() + * unit.getWidth() * unit.getHeight())); + od.setVolume(od.getVolume2() * od.getQuantity()); od.setWeight2(DoubleUtils.format4Fraction(unit.getWeight())); - od.setJfWeight(DoubleUtils.format2Fraction(unit.getWeight()*od.getQuantity())); - vt+=od.getVolume(); + od.setJfWeight(DoubleUtils.format2Fraction(unit.getWeight() + * od.getQuantity())); + vt += od.getVolume(); } order.setVolume(vt); order.setWeightThree(DoubleUtils.format2Fraction(vt)); order.setFreight(price); this.commonDao.store(order); // - FeeType ft=getFeeType("送货费"); - Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, - 1, shf, shf, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - fee.setDescription("链风送货费"+shf); + FeeType ft = getFeeType("送货费"); + Fee fee = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), ft, 1, shf, shf, + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); + fee.setDescription("链风送货费" + shf); this.commonDao.store(fee); - FeeType ft2=getFeeType("运输费"); - double jfv=order.getVolume()<1?1:order.getVolume(); - Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft2, - jfv, price, price*jfv, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - fee2.setDescription("链风送货费"+price*jfv); - if(order.getVolume()<1){ - fee2.setDescription("不足1立方按照1立方链风送货费"+price*jfv); + FeeType ft2 = getFeeType("运输费"); + double jfv = order.getVolume() < 1 ? 1 : order.getVolume(); + Fee fee2 = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), ft2, jfv, price, price * jfv, + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); + fee2.setDescription("链风送货费" + price * jfv); + if (order.getVolume() < 1) { + fee2.setDescription("不足1立方按照1立方链风送货费" + price * jfv); } this.commonDao.store(fee2); - }else{ + } else { this.createSpecialFee(order); - if(!order.getSelfDelivery()){ + if (!order.getSelfDelivery()) { this.createDJFee(order); } } - }else if(cusCode.equals("XGGL")){ + } else if (cusCode.equals("XGGL")) { order.setWeightThree(order.getWeight()); this.createGLFee(order); - if(order.isUpside()){ - FeeType ft=getFeeType("加急费"); - Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, - 1, 500, 500, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); + if (order.isUpside()) { + FeeType ft = getFeeType("加急费"); + Fee fee = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), ft, 1, 500, 500, + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); fee.setDescription("加急收取费用500"); this.commonDao.store(fee); } - if(order.getShipmentMethod().equals(ShipmentMethod.TRUCK)&&order.getQuantity()>10&&order.getToName()!=null&&!order.getToName().equals("")){ - String toName=order.getToName(); - double qms=0d;//起码数 - if(order.getToName().indexOf("比亚迪")>=0){ - qms=20; - }else if(toName.indexOf("史密斯")>=0||toName.indexOf("苏泊尔")>=0||toName.indexOf("松芝")>=0||toName.indexOf("中广电器")>=0){ - qms=30; - }else if(toName.indexOf("三电")>=0||toName.indexOf("奥克斯")>=0||toName.indexOf("TCL")>=0){ - qms=21; - }else if(order.getToName().indexOf("柳州五菱")>=0){ - qms=16; - }else if(order.getToName().indexOf("法雷奥")>=0){ - qms=15; + if (order.getShipmentMethod().equals(ShipmentMethod.TRUCK) + && order.getQuantity() > 10 && order.getToName() != null + && !order.getToName().equals("")) { + String toName = order.getToName(); + double qms = 0d;// 起码数 + if (order.getToName().indexOf("比亚迪") >= 0) { + qms = 20; + } else if (toName.indexOf("史密斯") >= 0 + || toName.indexOf("苏泊尔") >= 0 + || toName.indexOf("松芝") >= 0 + || toName.indexOf("中广电器") >= 0) { + qms = 30; + } else if (toName.indexOf("三电") >= 0 + || toName.indexOf("奥克斯") >= 0 + || toName.indexOf("TCL") >= 0) { + qms = 21; + } else if (order.getToName().indexOf("柳州五菱") >= 0) { + qms = 16; + } else if (order.getToName().indexOf("法雷奥") >= 0) { + qms = 15; } - //托盘费=码托数*35.0+护脚=1.2*8*7.0 - if(qms>0){ - double price=35; - double tps=Math.ceil(order.getQuantity()/qms);//托盘数 - FeeType ft=getFeeType("托盘费"); - Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, - tps, (price+1.2*8), tps*(price+1.2*8), FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - fee.setDescription("托盘费="+tps+"*"+price+";护脚=1.2*8*"+tps); + // 托盘费=码托数*35.0+护脚=1.2*8*7.0 + if (qms > 0) { + double price = 35; + double tps = Math.ceil(order.getQuantity() / qms);// 托盘数 + FeeType ft = getFeeType("托盘费"); + Fee fee = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), ft, tps, (price + 1.2 * 8), + tps * (price + 1.2 * 8), FeePayReceive.RECEIVE, + MeasureUnit.TICKET, order.getContractor()); + fee.setDescription("托盘费=" + tps + "*" + price + + ";护脚=1.2*8*" + tps); this.commonDao.store(fee); } } - }else if(cusCode.equals("YQDZ")){//一汽大众 + } else if (cusCode.equals("YQDZ")) {// 一汽大众 order.setWeightThree(order.getWeight()); this.createDZFee(order); - }else if(cusCode.equals("DZYD")){ + } else if (cusCode.equals("DZYD")) { order.setWeightThree(order.getWeight()); this.createDZYDFee(order); - }else if(cusCode.equals("YK")){ + } else if (cusCode.equals("YK")) { order.setWeightThree(order.getWeight()); this.createQKCusFee(order); - }else if(cusCode.equals("LF")){ + } else if (cusCode.equals("LF")) { order.setWeightThree(order.getWeight()); this.createQKCusFee(order); - this.createQTCusFee(order,Boolean.TRUE,Boolean.FALSE); - }else if(order.getConsignor().getCode().equals("ZQMS")){ -// order.setWeightThree(order.getWeight()); -// this.createZQMSCusFee(order); + this.createQTCusFee(order, Boolean.TRUE, Boolean.FALSE); + } else if (order.getConsignor().getCode().equals("ZQMS")) { + // order.setWeightThree(order.getWeight()); + // this.createZQMSCusFee(order); this.createNewZQMSFee(order); - }else if(order.getConsignor().getCode().equals("YYK")){ + } else if (order.getConsignor().getCode().equals("YYK")) { this.createYYKFee(order); - }else if(order.getConsignor().getCode().equals("GQFT")||order.getConsignor().getCode().equals("GQBT")){ + } else if (order.getConsignor().getCode().equals("GQFT") + || order.getConsignor().getCode().equals("GQBT")) { this.createFTAndBTFee(order); - }else if(order.getConsignor().getCode().equals("JZST")){ + } else if (order.getConsignor().getCode().equals("JZST")) { this.createJZSTFee(order); - }else if(cusCode.equals("GQCQ")){ + } else if (cusCode.equals("GQCQ")) { this.createGQCQFee(order); - }else if(cusCode.equals("YDSPFJ")){ + } else if (cusCode.equals("YDSPFJ")) { this.createYDSPFJFee(order); - }else if(cusCode.equals("YXZC")){ + } else if (cusCode.equals("YXZC")) { this.createYXZCFee(order); - }else if(cusCode.equals("YQFT")){ + } else if (cusCode.equals("YQFT")) { this.createYQFTFee(order); - }else if(cusCode.equals("YCCQ")){ + } else if (cusCode.equals("YCCQ")) { this.createYCCQFee(order); - }else if(cusCode.equals("GZHH-BT")){ + } else if (cusCode.equals("GZHH-BT")) {// 华恒本田 this.createGZHHBTFee(order); - }else if(cusCode.equals("hlyjxcq")){ + } else if (cusCode.equals("hlyjxcq")) { this.createhlyjxcqFee(order); - }else if(cusCode.equals("hhFT")){ + } else if (cusCode.equals("hhFT")) { this.createhhFTFee(order); - }else if(cusCode.equals("HH-GZCQ")||cusCode.equals("MJ-GZCQ")){ + } else if (cusCode.equals("HH-GZCQ") || cusCode.equals("MJ-GZCQ")) { this.createHHGZCQFee(order); - }else if(cusCode.equals("LP")){ + } else if (cusCode.equals("LP")) { this.createLPFee(order); - }else if(cusCode.equals("HHBTZC")){ + } else if (cusCode.equals("HHBTZC")) { this.createHHBTZCFee(order); - }else if(cusCode.equals("hlyft")){ + } else if (cusCode.equals("hlyft")) { this.createhlyftFee(order); - }else if(cusCode.equals("HHFKSL")){ - //this.createHHFKSLFee(order); - }else if(cusCode.equals("ZYJL")){ + } else if (cusCode.equals("HHFKSL")) { + // this.createHHFKSLFee(order); + } else if (cusCode.equals("ZYJL")) { this.createZYJLFee(order); - }else if(cusCode.equals("WHSL")){ + } else if (cusCode.equals("WHSL")) { this.createWHSLFee(order); - }else if(cusCode.equals("WL")){ + } else if (cusCode.equals("WL")) { this.createWLFee(order); - }else{ - //ZY,FT,DKN,JL,GQCQ + } else { + // ZY,FT,DKN,JL,GQCQ order.setWeightThree(order.getWeight()); - if(cusCode.equals("JL")|| cusCode.equals("lk")){ -// this.createQTCusFee(order,Boolean.FALSE,Boolean.FALSE); + if (cusCode.equals("JL") || cusCode.equals("lk")) { + // this.createQTCusFee(order,Boolean.FALSE,Boolean.FALSE); this.createJLandLKCusFee(order); - }else{ - this.createQTCusFee(order,Boolean.TRUE,Boolean.FALSE); + } else { + this.createQTCusFee(order, Boolean.TRUE, Boolean.FALSE); } - + } } - - public void createCarrierFee(Shipment s){ - List cus_nos=this.commonDao.findByQuery("select distinct(l.order.consignor.code) " - + " from Legs l where l.shipment.id="+s.getId()); -// List objs=this.commonDao.findByQuery("select sum(l.quantity),sum(l.weight),sum(l.volume)," -// + "max(l.order.fromCityCountiy.id), max(l.order.toCityCountiy.id)," -// + "max(l.order.toContact.linkman),max(l.order.toName),max(l.order.toCityCountiy.zone.id), max(to_char(l.order.planFromDate,'yyyy-mm-dd')) " -// + " from Legs l where l.shipment.id="+s.getId()); - if(cus_nos.size()>1){ + + public void createCarrierFee(Shipment s) { + List cus_nos = this.commonDao + .findByQuery("select distinct(l.order.consignor.code) " + + " from Legs l where l.shipment.id=" + s.getId()); + // List + // objs=this.commonDao.findByQuery("select sum(l.quantity),sum(l.weight),sum(l.volume)," + // + "max(l.order.fromCityCountiy.id), max(l.order.toCityCountiy.id)," + // + + // "max(l.order.toContact.linkman),max(l.order.toName),max(l.order.toCityCountiy.zone.id), max(to_char(l.order.planFromDate,'yyyy-mm-dd')) " + // + " from Legs l where l.shipment.id="+s.getId()); + if (cus_nos.size() > 1) { this.createShipmentFee(s); - feeManager.refreshBillFee(s.getId(), BillObjectType.SHIPMENT, Boolean.TRUE); - }else{ - String cus_no=cus_nos.get(0).toString(); - List ls=this.commonDao.findByQuery("from Legs l where l.shipment.id="+s.getId()); - if(ls.size()<=0){ + feeManager.refreshBillFee(s.getId(), BillObjectType.SHIPMENT, + Boolean.TRUE); + } else { + String cus_no = cus_nos.get(0).toString(); + List ls = this.commonDao + .findByQuery("from Legs l where l.shipment.id=" + s.getId()); + if (ls.size() <= 0) { return; } - if(cus_no.equals("JL")){ - List objs=this.commonDao.findByQuery("select sum(l.quantity),sum(l.weight),sum(l.volume)," + if (cus_no.equals("JL")) { + List objs = this.commonDao + .findByQuery("select sum(l.quantity),sum(l.weight),sum(l.volume)," + + "max(l.order.fromCityCountiy.id), max(l.order.toCityCountiy.id)," + + "max(l.order.toContact.linkman),max(l.order.toName),max(l.order.toCityCountiy.zone.id), max(to_char(l.order.planFromDate,'yyyy-mm-dd')) " + + " from Legs l where l.shipment.id=" + + s.getId()); + if (objs.size() > 0) { + Object[] obj = objs.get(0); + double qty = Double.parseDouble(obj[0].toString()); + double weight = Double.parseDouble(obj[1].toString()); + double volume = Double.parseDouble(obj[2].toString()); + Long fId = Long.parseLong(obj[3] == null ? "0" : obj[3] + .toString()); + Long tId = Long.parseLong(obj[4] == null ? "0" : obj[4] + .toString()); + String linkman = obj[5] == null ? "" : obj[5].toString(); + String toName = obj[6] == null ? "" : obj[6].toString(); + Long tZoneId = Long.parseLong(obj[7] == null ? "0" : obj[7] + .toString()); + String planFromDate = obj[8] == null ? "" : obj[8] + .toString(); + this.createLegsFee(ls.get(0), qty, weight, volume, fId, + tId, linkman, toName, tZoneId, planFromDate); + feeManager.refreshBillFee(ls.get(0).getId(), + BillObjectType.LEGS, Boolean.TRUE); + } + } else if (cus_no.equals("XGGL") || cus_no.equals("XGGLLS")) { + for (Legs l : ls) { + Order o = l.getOrder(); + Long fId = o.getFromCityCountiy() == null ? 0l : o + .getFromCityCountiy().getId(); + Long tId = o.getToCityCountiy() == null ? 0l : o + .getToCityCountiy().getId(); + String linkman = o.getToContact() == null ? "" : o + .getToContact().getLinkman(); + String toName = o.getToName(); + Long tZoneId = o.getToCityCountiy() == null ? 0l : o + .getToCityCountiy().getZone().getId(); + String planFromDate = DateUtil.formatDateYMDToStr(o + .getPlanFromDate()); + this.createLegsFee(ls.get(0), o.getQuantity(), + o.getWeight(), o.getVolume(), fId, tId, linkman, + toName, tZoneId, planFromDate); + feeManager.refreshBillFee(l.getId(), BillObjectType.LEGS, + Boolean.TRUE); + } + double payfee = (Double) commonDao + .findByQuery( + "select nvl(sum(otherFee),0) from Legs l where l.shipment.id=:shipmentId", + new String[] { "shipmentId" }, + new Object[] { s.getId() }).get(0); + s.setOtherFee(DoubleUtils.format3Fraction(DoubleUtils + .format3Fraction(payfee))); + this.commonDao.store(s); + } else { + this.createShipmentFee(s); + feeManager.refreshBillFee(s.getId(), BillObjectType.SHIPMENT, + Boolean.TRUE); + } + // feeManager.refreshBillFee(s.getId(), BillObjectType.LEGS, + // Boolean.TRUE); + } + + } + + public void createShipmentFee(Shipment s) { + List objs = this.commonDao + .findByQuery("select sum(l.quantity),sum(l.weight),sum(l.volume)," + "max(l.order.fromCityCountiy.id), max(l.order.toCityCountiy.id)," + "max(l.order.toContact.linkman),max(l.order.toName),max(l.order.toCityCountiy.zone.id), max(to_char(l.order.planFromDate,'yyyy-mm-dd')) " - + " from Legs l where l.shipment.id="+s.getId()); - if(objs.size()>0){ - Object[] obj=objs.get(0); - double qty=Double.parseDouble(obj[0].toString()); - double weight=Double.parseDouble(obj[1].toString()); - double volume=Double.parseDouble(obj[2].toString()); - Long fId=Long.parseLong(obj[3]==null?"0":obj[3].toString()); - Long tId=Long.parseLong(obj[4]==null?"0":obj[4].toString()); - String linkman=obj[5]==null?"":obj[5].toString(); - String toName=obj[6]==null?"":obj[6].toString(); - Long tZoneId=Long.parseLong(obj[7]==null?"0":obj[7].toString()); - String planFromDate=obj[8]==null?"":obj[8].toString(); - this.createLegsFee(ls.get(0), qty, weight, volume, fId, tId, linkman, toName, tZoneId, planFromDate); - feeManager.refreshBillFee(ls.get(0).getId(), BillObjectType.LEGS, Boolean.TRUE); - } - }else if(cus_no.equals("XGGL")||cus_no.equals("XGGLLS")){ - for(Legs l:ls){ - Order o=l.getOrder(); - Long fId=o.getFromCityCountiy()==null?0l:o.getFromCityCountiy().getId(); - Long tId=o.getToCityCountiy()==null?0l:o.getToCityCountiy().getId(); - String linkman=o.getToContact()==null?"":o.getToContact().getLinkman(); - String toName=o.getToName(); - Long tZoneId=o.getToCityCountiy()==null?0l:o.getToCityCountiy().getZone().getId(); - String planFromDate=DateUtil.formatDateYMDToStr(o.getPlanFromDate()); - this.createLegsFee(ls.get(0), o.getQuantity(), o.getWeight(), o.getVolume(), fId, tId,linkman, toName, tZoneId, planFromDate); - feeManager.refreshBillFee(l.getId(), BillObjectType.LEGS, Boolean.TRUE); - } - double payfee=(Double)commonDao.findByQuery("select nvl(sum(otherFee),0) from Legs l where l.shipment.id=:shipmentId", - new String[]{"shipmentId"},new Object[]{s.getId()}).get(0); - s.setOtherFee(DoubleUtils.format3Fraction( DoubleUtils.format3Fraction(payfee))); - this.commonDao.store(s); - }else{ - this.createShipmentFee(s); - feeManager.refreshBillFee(s.getId(), BillObjectType.SHIPMENT, Boolean.TRUE); - } - //feeManager.refreshBillFee(s.getId(), BillObjectType.LEGS, Boolean.TRUE); - } - - } - public void createShipmentFee(Shipment s){ - List objs=this.commonDao.findByQuery("select sum(l.quantity),sum(l.weight),sum(l.volume)," - + "max(l.order.fromCityCountiy.id), max(l.order.toCityCountiy.id)," - + "max(l.order.toContact.linkman),max(l.order.toName),max(l.order.toCityCountiy.zone.id), max(to_char(l.order.planFromDate,'yyyy-mm-dd')) " - + " from Legs l where l.shipment.id="+s.getId()); - if(objs.size()>0){ - Object[] obj=objs.get(0); - double qty=Double.parseDouble(obj[0].toString()); - double weight=Double.parseDouble(obj[1].toString()); - double volume=Double.parseDouble(obj[2].toString()); - Long fId=Long.parseLong(obj[3]==null?"0":obj[3].toString()); - Long tId=Long.parseLong(obj[4]==null?"0":obj[4].toString()); - String linkman=obj[5]==null?"":obj[5].toString(); - String toName=obj[6]==null?"":obj[6].toString(); - Long tZoneId=Long.parseLong(obj[7]==null?"0":obj[7].toString()); - String planFromDate=obj[8]==null?"":obj[8].toString(); - Long carrierId=s.getCarrier().getId(); - if(s.getCarrier().getName().indexOf("跨越")>=0){ - String hql="from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id=:tid "; - List crs=commonDao.findByQuery(hql,new String[]{"balanceId","tid"},new Object[]{carrierId,tId}); - if(crs.size()<=0){//按省份 - hql="from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id is null and " + + " from Legs l where l.shipment.id=" + s.getId()); + if (objs.size() > 0) { + Object[] obj = objs.get(0); + double qty = Double.parseDouble(obj[0].toString()); + double weight = Double.parseDouble(obj[1].toString()); + double volume = Double.parseDouble(obj[2].toString()); + Long fId = Long.parseLong(obj[3] == null ? "0" : obj[3].toString()); + Long tId = Long.parseLong(obj[4] == null ? "0" : obj[4].toString()); + String linkman = obj[5] == null ? "" : obj[5].toString(); + String toName = obj[6] == null ? "" : obj[6].toString(); + Long tZoneId = Long.parseLong(obj[7] == null ? "0" : obj[7] + .toString()); + String planFromDate = obj[8] == null ? "" : obj[8].toString(); + Long carrierId = s.getCarrier().getId(); + if (s.getCarrier().getName().indexOf("跨越") >= 0) { + String hql = "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id=:tid "; + List crs = commonDao.findByQuery(hql, + new String[] { "balanceId", "tid" }, new Object[] { + carrierId, tId }); + if (crs.size() <= 0) {// 按省份 + hql = "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id is null and " + " c.routeFee.toZone.id=:tZoneId "; - crs=commonDao.findByQuery(hql,new String[]{"balanceId","tZoneId"},new Object[]{carrierId,tZoneId}); + crs = commonDao.findByQuery(hql, new String[] { + "balanceId", "tZoneId" }, new Object[] { carrierId, + tZoneId }); } - if(crs.size()>0){ - ContractRate cr=crs.get(0); - double rate=cr.getContract().getRate(); - double price=0; - qty=weight; - String remark=""; - if(cr.getModels()>0&&qty 0) { + ContractRate cr = crs.get(0); + double rate = cr.getContract().getRate(); + double price = 0; + qty = weight; + String remark = ""; + if (cr.getModels() > 0 && qty < cr.getModels()) { + qty = cr.getModels(); + remark = weight + "小于最低起算,按最低" + qty + "计算"; } - if(cr.getVehiclePrice()>0){//如果首重大于0 - qty=qty-1; + if (cr.getVehiclePrice() > 0) {// 如果首重大于0 + qty = qty - 1; } - if(cr.getFromRange1()==null){ - price=DoubleUtils.format3Fraction(cr.getPrice1()); - }else if(cr.getFromRange1()!=null&&qty>=cr.getFromRange1() &&(cr.getToRange1()==null||qty<=cr.getToRange1())){ - price=DoubleUtils.format3Fraction(cr.getPrice1()); - }else if(cr.getFromRange2()!=null&&qty>=cr.getFromRange2()&&(cr.getToRange2()==null||qty<=cr.getToRange2())){ - price=DoubleUtils.format3Fraction(cr.getPrice2()); - }else if(cr.getFromRange3()!=null&&qty>=cr.getFromRange3()&&(cr.getToRange3()==null||qty<=cr.getToRange3())){ - price=DoubleUtils.format3Fraction(cr.getPrice3()); - }else if(cr.getFromRange4()!=null&&qty>=cr.getFromRange4()&&(cr.getToRange4()==null||qty<=cr.getToRange4())){ - price=DoubleUtils.format3Fraction(cr.getPrice4()); - }else if(cr.getFromRange5()!=null&&qty>=cr.getFromRange5()&&(cr.getToRange5()==null||qty<=cr.getToRange5())){ - price=DoubleUtils.format3Fraction(cr.getPrice5()); - }else if(cr.getFromRange6()!=null&&qty>=cr.getFromRange6()&&(cr.getToRange6()==null||qty<=cr.getToRange6())){ - price=DoubleUtils.format3Fraction(cr.getPrice6()); - }else if(cr.getFromRange7()!=null&&qty>=cr.getFromRange7()&&(cr.getToRange7()==null||qty<=cr.getToRange7())){ - price=DoubleUtils.format3Fraction(cr.getPrice7()); - }else if(cr.getFromRange8()!=null&&qty>=cr.getFromRange8()&&(cr.getToRange8()==null||qty<=cr.getToRange8())){ - price=DoubleUtils.format3Fraction(cr.getPrice8()); - }else if(cr.getFromRange9()!=null&&qty>=cr.getFromRange9()){ - price=DoubleUtils.format3Fraction(cr.getPrice9()); + if (cr.getFromRange1() == null) { + price = DoubleUtils.format3Fraction(cr.getPrice1()); + } else if (cr.getFromRange1() != null + && qty >= cr.getFromRange1() + && (cr.getToRange1() == null || qty <= cr + .getToRange1())) { + price = DoubleUtils.format3Fraction(cr.getPrice1()); + } else if (cr.getFromRange2() != null + && qty >= cr.getFromRange2() + && (cr.getToRange2() == null || qty <= cr + .getToRange2())) { + price = DoubleUtils.format3Fraction(cr.getPrice2()); + } else if (cr.getFromRange3() != null + && qty >= cr.getFromRange3() + && (cr.getToRange3() == null || qty <= cr + .getToRange3())) { + price = DoubleUtils.format3Fraction(cr.getPrice3()); + } else if (cr.getFromRange4() != null + && qty >= cr.getFromRange4() + && (cr.getToRange4() == null || qty <= cr + .getToRange4())) { + price = DoubleUtils.format3Fraction(cr.getPrice4()); + } else if (cr.getFromRange5() != null + && qty >= cr.getFromRange5() + && (cr.getToRange5() == null || qty <= cr + .getToRange5())) { + price = DoubleUtils.format3Fraction(cr.getPrice5()); + } else if (cr.getFromRange6() != null + && qty >= cr.getFromRange6() + && (cr.getToRange6() == null || qty <= cr + .getToRange6())) { + price = DoubleUtils.format3Fraction(cr.getPrice6()); + } else if (cr.getFromRange7() != null + && qty >= cr.getFromRange7() + && (cr.getToRange7() == null || qty <= cr + .getToRange7())) { + price = DoubleUtils.format3Fraction(cr.getPrice7()); + } else if (cr.getFromRange8() != null + && qty >= cr.getFromRange8() + && (cr.getToRange8() == null || qty <= cr + .getToRange8())) { + price = DoubleUtils.format3Fraction(cr.getPrice8()); + } else if (cr.getFromRange9() != null + && qty >= cr.getFromRange9()) { + price = DoubleUtils.format3Fraction(cr.getPrice9()); } - if(cr.getVehiclePrice()>0){//如果首重大于0 - remark+="首重"+cr.getVehiclePrice()+";"+price+"*"+qty; + if (cr.getVehiclePrice() > 0) {// 如果首重大于0 + remark += "首重" + cr.getVehiclePrice() + ";" + price + + "*" + qty; } - Double totalFee=price*qty+cr.getVehiclePrice(); - FeeType ft=getFeeType("运输费"); - Fee f=createFeeInfo(s.getCode(), s.getId(), BillObjectType.SHIPMENT, s.getCarrier(), ft, qty,price, - totalFee*rate, FeePayReceive.PAY, cr.getUnit(), s.getPlatForm()); - f.setDescription("运输费="+price+"*"+qty); - if(cr.getVehiclePrice()>0){ - f.setDescription("首重"+cr.getVehiclePrice()+";"+"运输费="+price+"*"+weight); + Double totalFee = price * qty + cr.getVehiclePrice(); + FeeType ft = getFeeType("运输费"); + Fee f = createFeeInfo(s.getCode(), s.getId(), + BillObjectType.SHIPMENT, s.getCarrier(), ft, qty, + price, totalFee * rate, FeePayReceive.PAY, + cr.getUnit(), s.getPlatForm()); + f.setDescription("运输费=" + price + "*" + qty); + if (cr.getVehiclePrice() > 0) { + f.setDescription("首重" + cr.getVehiclePrice() + ";" + + "运输费=" + price + "*" + weight); } f.setRemark(remark); - if(cr.getMinPrice()!=null&&f.getTotalFee()0){ - hql+=" and c.unit='WEIGHT'"; - }else{ - hql+=" and c.unit='QUANTITY'"; + } else { + String hql = "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id=:tid "; + if (s.getCarrier().getName().equals("胜速物流")) { + if (qty > 0) { + hql += " and c.unit='WEIGHT'"; + } else { + hql += " and c.unit='QUANTITY'"; } } - String hql2=hql+" and c.superviseType='"+linkman+"'"; - List crs=new ArrayList(); - crs=commonDao.findByQuery(hql2, - new String[]{"balanceId","tid"}, - new Object[]{s.getCarrier().getId(),tId}); - if(crs.size()<=0){ - crs=commonDao.findByQuery(hql, - new String[]{"balanceId","tid"}, - new Object[]{s.getCarrier().getId(),tId}); + String hql2 = hql + " and c.superviseType='" + linkman + "'"; + List crs = new ArrayList(); + crs = commonDao.findByQuery(hql2, new String[] { "balanceId", + "tid" }, new Object[] { s.getCarrier().getId(), tId }); + if (crs.size() <= 0) { + crs = commonDao.findByQuery(hql, new String[] { + "balanceId", "tid" }, new Object[] { + s.getCarrier().getId(), tId }); } - if(crs.size()>0){ - ContractRate cr=crs.get(0); - double rate=cr.getContract().getRate(); - if(cr.getVehiclePrice()>0){ - double quantity=0; - if(cr.getUnit().equals( MeasureUnit.VOLUME)){ - quantity=volume; - }else if(cr.getUnit().equals( MeasureUnit.WEIGHT)){ - quantity=weight/1000; - //quantity=weight; - }else if(cr.getUnit().equals( MeasureUnit.QUANTITY)){ - quantity=qty; - }else if(cr.getUnit().equals( MeasureUnit.TICKET)){ - quantity=1; + if (crs.size() > 0) { + ContractRate cr = crs.get(0); + double rate = cr.getContract().getRate(); + if (cr.getVehiclePrice() > 0) { + double quantity = 0; + if (cr.getUnit().equals(MeasureUnit.VOLUME)) { + quantity = volume; + } else if (cr.getUnit().equals(MeasureUnit.WEIGHT)) { + quantity = weight / 1000; + // quantity=weight; + } else if (cr.getUnit().equals(MeasureUnit.QUANTITY)) { + quantity = qty; + } else if (cr.getUnit().equals(MeasureUnit.TICKET)) { + quantity = 1; } - double price=cr.getVehiclePrice(); - double totalFee=cr.getVehiclePrice()*quantity; - if(s.getCarrier().getName().equals("零贰贰")){ -// if(toName.equals("苏国强")||toName.equals("隗红爱")){ -// if(quantity>11&&quantity<=29){ -// price=10; -// }else{ -// totalFee=110; -// } -// }else if(toName.equals("张仲立")){ -// if(quantity>11&&quantity<=14){ -// price=10; -// }else{ -// totalFee=110; -// } -// } - if(toName.equals("张仲立")){ - //数量不足一立方按照一立方算,数量小于11箱按照10一箱算 - if(qty>11&&qty<=14){ - totalFee=110; - }else if (qty<=11){ - price=10; - totalFee=price*qty; + double price = cr.getVehiclePrice(); + double totalFee = cr.getVehiclePrice() * quantity; + if (s.getCarrier().getName().equals("零贰贰")) { + // if(toName.equals("苏国强")||toName.equals("隗红爱")){ + // if(quantity>11&&quantity<=29){ + // price=10; + // }else{ + // totalFee=110; + // } + // }else if(toName.equals("张仲立")){ + // if(quantity>11&&quantity<=14){ + // price=10; + // }else{ + // totalFee=110; + // } + // } + if (toName.equals("张仲立")) { + // 数量不足一立方按照一立方算,数量小于11箱按照10一箱算 + if (qty > 11 && qty <= 14) { + totalFee = 110; + } else if (qty <= 11) { + price = 10; + totalFee = price * qty; } - }else{ - if(qty>11&&qty<=29){ - totalFee=110; - }else if (qty<=11){ - price=10; - totalFee=price*qty; + } else { + if (qty > 11 && qty <= 29) { + totalFee = 110; + } else if (qty <= 11) { + price = 10; + totalFee = price * qty; } } - + } - FeeType ft=getFeeType("运输费"); - Fee f=createFeeInfo(s.getCode(), s.getId(), BillObjectType.SHIPMENT, s.getCarrier(), ft, quantity, price, - totalFee*rate, FeePayReceive.PAY, cr.getUnit(), s.getPlatForm()); - f.setDescription("运输费="+price+"*"+quantity); - if(cr.getMinPrice()!=null&&f.getTotalFee()0){ - //如果当天该收货人已收取费用,则不重复收取 - List sids=this.commonDao.findByQuery("select l.shipment.id from Legs l where l.order.toContact.linkman='"+linkman - +"' and to_char(l.order.planFromDate,'yyyy-mm-dd')='"+planFromDate+"' and l.shipment.id is not null"); - FeeType ft=getFeeType("送货费"); - Boolean temp=Boolean.TRUE; - for(Long id:sids){ - List fs=this.commonDao.findByQuery("from Fee f where f.billId="+id+" and f.billObject='SHIPMENT' and f.feeName.id="+ft.getId()); - if(fs.size()>0){ - temp=Boolean.FALSE; + if (cr.getDeliveryFee() != null && cr.getDeliveryFee() > 0) { + // 如果当天该收货人已收取费用,则不重复收取 + List sids = this.commonDao + .findByQuery("select l.shipment.id from Legs l where l.order.toContact.linkman='" + + linkman + + "' and to_char(l.order.planFromDate,'yyyy-mm-dd')='" + + planFromDate + + "' and l.shipment.id is not null"); + FeeType ft = getFeeType("送货费"); + Boolean temp = Boolean.TRUE; + for (Long id : sids) { + List fs = this.commonDao + .findByQuery("from Fee f where f.billId=" + + id + + " and f.billObject='SHIPMENT' and f.feeName.id=" + + ft.getId()); + if (fs.size() > 0) { + temp = Boolean.FALSE; return; } } - //孝感高理-跨越-收货人-朱魁则送货费=150 - if(linkman.equals("朱魁")){ - shf=150; + // 孝感高理-跨越-收货人-朱魁则送货费=150 + if (linkman.equals("朱魁")) { + shf = 150; } - if(temp){ - createFeeInfo(s.getCode(), s.getId(), BillObjectType.SHIPMENT, s.getCarrier(), ft, 1,shf, - shf*rate, FeePayReceive.PAY, MeasureUnit.TICKET, s.getPlatForm()); + if (temp) { + createFeeInfo(s.getCode(), s.getId(), + BillObjectType.SHIPMENT, s.getCarrier(), + ft, 1, shf, shf * rate, FeePayReceive.PAY, + MeasureUnit.TICKET, s.getPlatForm()); } } - - if(cr.getCarryFee()!=null&&cr.getCarryFee()>0){ - FeeType ft=getFeeType("卸货费"); - createFeeInfo(s.getCode(), s.getId(), BillObjectType.SHIPMENT, s.getCarrier(), ft, 1,cr.getCarryFee(), - cr.getCarryFee()*qty*rate, FeePayReceive.PAY, MeasureUnit.QUANTITY, s.getPlatForm()); + + if (cr.getCarryFee() != null && cr.getCarryFee() > 0) { + FeeType ft = getFeeType("卸货费"); + createFeeInfo(s.getCode(), s.getId(), + BillObjectType.SHIPMENT, s.getCarrier(), ft, 1, + cr.getCarryFee(), + cr.getCarryFee() * qty * rate, + FeePayReceive.PAY, MeasureUnit.QUANTITY, + s.getPlatForm()); } } } } } - - public void createLegsFee(Legs l,double qty,double weight,double volume,Long fId,Long tId,String linkman,String toName,Long tZoneId,String planFromDate){ - Organization carrier=l.getShipment().getCarrier(); - Long carrierId=carrier.getId(); - if(carrier.getName().indexOf("跨越")>=0){ - String hql="from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id=:tid "; - List crs=commonDao.findByQuery(hql,new String[]{"balanceId","tid"},new Object[]{carrierId,tId}); - if(crs.size()<=0){//按省份 - hql="from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id is null and " + + public void createLegsFee(Legs l, double qty, double weight, double volume, + Long fId, Long tId, String linkman, String toName, Long tZoneId, + String planFromDate) { + Organization carrier = l.getShipment().getCarrier(); + Long carrierId = carrier.getId(); + if (carrier.getName().indexOf("跨越") >= 0) { + String hql = "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id=:tid "; + List crs = commonDao.findByQuery(hql, new String[] { + "balanceId", "tid" }, new Object[] { carrierId, tId }); + if (crs.size() <= 0) {// 按省份 + hql = "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id is null and " + " c.routeFee.toZone.id=:tZoneId "; - crs=commonDao.findByQuery(hql,new String[]{"balanceId","tZoneId"},new Object[]{carrierId,tZoneId}); + crs = commonDao.findByQuery(hql, new String[] { "balanceId", + "tZoneId" }, new Object[] { carrierId, tZoneId }); } - if(crs.size()>0){ - ContractRate cr=crs.get(0); - double rate=cr.getContract().getRate(); - double price=0; - qty=weight; - String remark=""; - if(cr.getModels()>0&&qty 0) { + ContractRate cr = crs.get(0); + double rate = cr.getContract().getRate(); + double price = 0; + qty = weight; + String remark = ""; + if (cr.getModels() > 0 && qty < cr.getModels()) { + qty = cr.getModels(); + remark = weight + "小于最低起算,按最低" + qty + "计算"; } - if(cr.getVehiclePrice()>0){//如果首重大于0 - qty=qty-1; + if (cr.getVehiclePrice() > 0) {// 如果首重大于0 + qty = qty - 1; } - if(cr.getFromRange1()==null){ - price=DoubleUtils.format3Fraction(cr.getPrice1()); - }else if(cr.getFromRange1()!=null&&qty>=cr.getFromRange1() &&(cr.getToRange1()==null||qty<=cr.getToRange1())){ - price=DoubleUtils.format3Fraction(cr.getPrice1()); - }else if(cr.getFromRange2()!=null&&qty>=cr.getFromRange2()&&(cr.getToRange2()==null||qty<=cr.getToRange2())){ - price=DoubleUtils.format3Fraction(cr.getPrice2()); - }else if(cr.getFromRange3()!=null&&qty>=cr.getFromRange3()&&(cr.getToRange3()==null||qty<=cr.getToRange3())){ - price=DoubleUtils.format3Fraction(cr.getPrice3()); - }else if(cr.getFromRange4()!=null&&qty>=cr.getFromRange4()&&(cr.getToRange4()==null||qty<=cr.getToRange4())){ - price=DoubleUtils.format3Fraction(cr.getPrice4()); - }else if(cr.getFromRange5()!=null&&qty>=cr.getFromRange5()&&(cr.getToRange5()==null||qty<=cr.getToRange5())){ - price=DoubleUtils.format3Fraction(cr.getPrice5()); - }else if(cr.getFromRange6()!=null&&qty>=cr.getFromRange6()&&(cr.getToRange6()==null||qty<=cr.getToRange6())){ - price=DoubleUtils.format3Fraction(cr.getPrice6()); - }else if(cr.getFromRange7()!=null&&qty>=cr.getFromRange7()&&(cr.getToRange7()==null||qty<=cr.getToRange7())){ - price=DoubleUtils.format3Fraction(cr.getPrice7()); - }else if(cr.getFromRange8()!=null&&qty>=cr.getFromRange8()&&(cr.getToRange8()==null||qty<=cr.getToRange8())){ - price=DoubleUtils.format3Fraction(cr.getPrice8()); - }else if(cr.getFromRange9()!=null&&qty>=cr.getFromRange9()){ - price=DoubleUtils.format3Fraction(cr.getPrice9()); + if (cr.getFromRange1() == null) { + price = DoubleUtils.format3Fraction(cr.getPrice1()); + } else if (cr.getFromRange1() != null + && qty >= cr.getFromRange1() + && (cr.getToRange1() == null || qty <= cr.getToRange1())) { + price = DoubleUtils.format3Fraction(cr.getPrice1()); + } else if (cr.getFromRange2() != null + && qty >= cr.getFromRange2() + && (cr.getToRange2() == null || qty <= cr.getToRange2())) { + price = DoubleUtils.format3Fraction(cr.getPrice2()); + } else if (cr.getFromRange3() != null + && qty >= cr.getFromRange3() + && (cr.getToRange3() == null || qty <= cr.getToRange3())) { + price = DoubleUtils.format3Fraction(cr.getPrice3()); + } else if (cr.getFromRange4() != null + && qty >= cr.getFromRange4() + && (cr.getToRange4() == null || qty <= cr.getToRange4())) { + price = DoubleUtils.format3Fraction(cr.getPrice4()); + } else if (cr.getFromRange5() != null + && qty >= cr.getFromRange5() + && (cr.getToRange5() == null || qty <= cr.getToRange5())) { + price = DoubleUtils.format3Fraction(cr.getPrice5()); + } else if (cr.getFromRange6() != null + && qty >= cr.getFromRange6() + && (cr.getToRange6() == null || qty <= cr.getToRange6())) { + price = DoubleUtils.format3Fraction(cr.getPrice6()); + } else if (cr.getFromRange7() != null + && qty >= cr.getFromRange7() + && (cr.getToRange7() == null || qty <= cr.getToRange7())) { + price = DoubleUtils.format3Fraction(cr.getPrice7()); + } else if (cr.getFromRange8() != null + && qty >= cr.getFromRange8() + && (cr.getToRange8() == null || qty <= cr.getToRange8())) { + price = DoubleUtils.format3Fraction(cr.getPrice8()); + } else if (cr.getFromRange9() != null + && qty >= cr.getFromRange9()) { + price = DoubleUtils.format3Fraction(cr.getPrice9()); } - if(cr.getVehiclePrice()>0){//如果首重大于0 - remark+="首重"+cr.getVehiclePrice()+";"+price+"*"+qty; + if (cr.getVehiclePrice() > 0) {// 如果首重大于0 + remark += "首重" + cr.getVehiclePrice() + ";" + price + "*" + + qty; } - Double totalFee=price*qty+cr.getVehiclePrice(); - FeeType ft=getFeeType("运输费"); - Fee f=createFeeInfo(l.getOrder().getRelateBill3(), l.getId(), BillObjectType.LEGS, carrier, ft, qty,price, - totalFee*rate, FeePayReceive.PAY, cr.getUnit(), l.getExecuter()); - f.setDescription("运输费="+price+"*"+qty); - if(cr.getVehiclePrice()>0){ - f.setDescription("首重"+cr.getVehiclePrice()+";"+"运输费="+price+"*"+weight); + Double totalFee = price * qty + cr.getVehiclePrice(); + FeeType ft = getFeeType("运输费"); + Fee f = createFeeInfo(l.getOrder().getRelateBill3(), l.getId(), + BillObjectType.LEGS, carrier, ft, qty, price, totalFee + * rate, FeePayReceive.PAY, cr.getUnit(), + l.getExecuter()); + f.setDescription("运输费=" + price + "*" + qty); + if (cr.getVehiclePrice() > 0) { + f.setDescription("首重" + cr.getVehiclePrice() + ";" + "运输费=" + + price + "*" + weight); } f.setRemark(remark); - if(cr.getMinPrice()!=null&&f.getTotalFee()0){ - hql+=" and c.unit='WEIGHT'"; - }else{ - hql+=" and c.unit='QUANTITY'"; - } - } - String hql2=hql+" and c.superviseType='"+linkman+"'"; - List crs=new ArrayList(); - crs=commonDao.findByQuery(hql2, - new String[]{"balanceId","tid"}, - new Object[]{carrier.getId(),tId}); - if(crs.size()<=0){ - crs=commonDao.findByQuery(hql, - new String[]{"balanceId","tid"}, - new Object[]{carrier.getId(),tId}); - } - if(crs.size()>0){ - ContractRate cr=crs.get(0); - double rate=cr.getContract().getRate(); - if(cr.getVehiclePrice()>0){ - double quantity=0; - if(cr.getUnit().equals( MeasureUnit.VOLUME)){ - quantity=volume; - }else if(cr.getUnit().equals( MeasureUnit.WEIGHT)){ - quantity=weight/1000; - //quantity=weight; - }else if(cr.getUnit().equals( MeasureUnit.QUANTITY)){ - quantity=qty; - }else if(cr.getUnit().equals( MeasureUnit.TICKET)){ - quantity=1; - } - double price=cr.getVehiclePrice(); - double totalFee=cr.getVehiclePrice()*quantity; - if(carrier.getName().equals("零贰贰")){ - if(toName.equals("张仲立")){ - //数量不足一立方按照一立方算,数量小于11箱按照10*数量算 - if(qty>11&&qty<=14){ - totalFee=110; - }else if (qty<=11){ - price=10; - totalFee=price*qty; - } - }else{ - if(qty>11&&qty<=29){ - totalFee=110; - }else if (qty<=11){ - price=10; - totalFee=price*qty; - } - } - - } - FeeType ft=getFeeType("运输费"); - Fee f=createFeeInfo(l.getOrder().getRelateBill3(), l.getId(), BillObjectType.LEGS, carrier, ft, quantity, price, - totalFee*rate, FeePayReceive.PAY, cr.getUnit(), l.getExecuter()); - f.setDescription("运输费="+price+"*"+quantity+"*"+rate); - if(cr.getMinPrice()!=null&&f.getTotalFee()0){ - //如果当天该收货人已收取费用,则不重复收取 - List sids=this.commonDao.findByQuery("select l.id from Legs l where l.order.toContact.linkman='"+linkman - +"' and to_char(l.order.planFromDate,'yyyy-mm-dd')='"+planFromDate+"' and l.shipment.id is not null"); - FeeType ft=getFeeType("送货费"); - Boolean temp=Boolean.TRUE; - for(Long id:sids){ - List fs=this.commonDao.findByQuery("from Fee f where f.billId="+id+" and f.billObject='LEGS' and f.feeName.id="+ft.getId()); - if(fs.size()>0){ - temp=Boolean.FALSE; - return; - } - } - //孝感高理-跨越-收货人-朱魁则送货费=150 - if(linkman.equals("朱魁")){ - shf=150; - } - if(temp){ - createFeeInfo(l.getOrder().getRelateBill3(), l.getId(), BillObjectType.LEGS, carrier, ft, 1,shf, - shf*rate, FeePayReceive.PAY, MeasureUnit.TICKET, l.getExecuter()); - } - } - - if(cr.getCarryFee()!=null&&cr.getCarryFee()>0){ - FeeType ft=getFeeType("卸货费"); - createFeeInfo(l.getOrder().getRelateBill3(), l.getId(), BillObjectType.LEGS, carrier, ft, 1,cr.getCarryFee(), - cr.getCarryFee()*qty*rate, FeePayReceive.PAY, MeasureUnit.QUANTITY,l.getExecuter()); - } + } else { + String hql = "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id=:tid "; + if (carrier.getName().equals("胜速物流")) { + if (qty > 0) { + hql += " and c.unit='WEIGHT'"; + } else { + hql += " and c.unit='QUANTITY'"; + } + } + String hql2 = hql + " and c.superviseType='" + linkman + "'"; + List crs = new ArrayList(); + crs = commonDao.findByQuery(hql2, + new String[] { "balanceId", "tid" }, + new Object[] { carrier.getId(), tId }); + if (crs.size() <= 0) { + crs = commonDao.findByQuery(hql, new String[] { "balanceId", + "tid" }, new Object[] { carrier.getId(), tId }); + } + if (crs.size() > 0) { + ContractRate cr = crs.get(0); + double rate = cr.getContract().getRate(); + if (cr.getVehiclePrice() > 0) { + double quantity = 0; + if (cr.getUnit().equals(MeasureUnit.VOLUME)) { + quantity = volume; + } else if (cr.getUnit().equals(MeasureUnit.WEIGHT)) { + quantity = weight / 1000; + // quantity=weight; + } else if (cr.getUnit().equals(MeasureUnit.QUANTITY)) { + quantity = qty; + } else if (cr.getUnit().equals(MeasureUnit.TICKET)) { + quantity = 1; + } + double price = cr.getVehiclePrice(); + double totalFee = cr.getVehiclePrice() * quantity; + if (carrier.getName().equals("零贰贰")) { + if (toName.equals("张仲立")) { + // 数量不足一立方按照一立方算,数量小于11箱按照10*数量算 + if (qty > 11 && qty <= 14) { + totalFee = 110; + } else if (qty <= 11) { + price = 10; + totalFee = price * qty; + } + } else { + if (qty > 11 && qty <= 29) { + totalFee = 110; + } else if (qty <= 11) { + price = 10; + totalFee = price * qty; + } + } + + } + FeeType ft = getFeeType("运输费"); + Fee f = createFeeInfo(l.getOrder().getRelateBill3(), + l.getId(), BillObjectType.LEGS, carrier, ft, + quantity, price, totalFee * rate, + FeePayReceive.PAY, cr.getUnit(), l.getExecuter()); + f.setDescription("运输费=" + price + "*" + quantity + "*" + + rate); + if (cr.getMinPrice() != null + && f.getTotalFee() < cr.getMinPrice()) { + totalFee = cr.getMinPrice(); + price = totalFee; + qty = 1; + f.setUnit(MeasureUnit.TICKET); + f.setTotalFee(totalFee * rate); + f.setPrice(price); + f.setQuantity(qty); + f.setRemark(f.getRemark() + "不足最低价,按最低价算" + + cr.getMinPrice()); + } + this.commonDao.store(f); + } + double shf = cr.getDeliveryFee() == null ? 0 : cr + .getDeliveryFee(); + if (toName.equals("青岛三电")) { + shf = 150; + } + if (toName.equals("青岛进仓")) { + shf = 400; + } + if (toName.equals("青岛海信")) { + shf = 350; + } + if (cr.getDeliveryFee() != null && cr.getDeliveryFee() > 0) { + // 如果当天该收货人已收取费用,则不重复收取 + List sids = this.commonDao + .findByQuery("select l.id from Legs l where l.order.toContact.linkman='" + + linkman + + "' and to_char(l.order.planFromDate,'yyyy-mm-dd')='" + + planFromDate + + "' and l.shipment.id is not null"); + FeeType ft = getFeeType("送货费"); + Boolean temp = Boolean.TRUE; + for (Long id : sids) { + List fs = this.commonDao + .findByQuery("from Fee f where f.billId=" + + id + + " and f.billObject='LEGS' and f.feeName.id=" + + ft.getId()); + if (fs.size() > 0) { + temp = Boolean.FALSE; + return; + } + } + // 孝感高理-跨越-收货人-朱魁则送货费=150 + if (linkman.equals("朱魁")) { + shf = 150; + } + if (temp) { + createFeeInfo(l.getOrder().getRelateBill3(), l.getId(), + BillObjectType.LEGS, carrier, ft, 1, shf, shf + * rate, FeePayReceive.PAY, + MeasureUnit.TICKET, l.getExecuter()); + } + } + + if (cr.getCarryFee() != null && cr.getCarryFee() > 0) { + FeeType ft = getFeeType("卸货费"); + createFeeInfo(l.getOrder().getRelateBill3(), l.getId(), + BillObjectType.LEGS, carrier, ft, 1, + cr.getCarryFee(), cr.getCarryFee() * qty * rate, + FeePayReceive.PAY, MeasureUnit.QUANTITY, + l.getExecuter()); } } - } - public void unRefreshOrderFee(List ids){ - for(Long id:ids){ - Order o=commonDao.load(Order.class, id); - deleteOpFee(o); - feeManager.refreshBillFee(id, BillObjectType.ORDER, Boolean.TRUE); } } - public void availableAndPrintOrder(List ids,Long userId) { + + public void unRefreshOrderFee(List ids) { + for (Long id : ids) { + Order o = commonDao.load(Order.class, id); + deleteOpFee(o); + feeManager.refreshBillFee(id, BillObjectType.ORDER, Boolean.TRUE); + } + } + + public void availableAndPrintOrder(List ids, Long userId) { this.availableTransOrder(ids); } public void deleteOpFee(Order order) { - List fees = this.commonDao.findByQuery( - "from Fee f where f.billId=:feeId and f.billCode=:billCode and (f.operator='system' or f.divideWaybill=:divideWaybill)", - new String[] { "feeId", "billCode","divideWaybill" }, - new Object[] { order.getId(), order.getRelateBill3(),order.getPaymentMethod()}); + List fees = this.commonDao + .findByQuery( + "from Fee f where f.billId=:feeId and f.billCode=:billCode and (f.operator='system' or f.divideWaybill=:divideWaybill)", + new String[] { "feeId", "billCode", "divideWaybill" }, + new Object[] { order.getId(), order.getRelateBill3(), + order.getPaymentMethod() }); for (Fee fee : fees) { - if(fee.getBillFee()!=null){ - throw new BusinessException(order.getRelateBill3()+"费用已对帐,不能取消回单"); - } - this.commonDao.delete(fee); - } - } - public List isOpFee(Order order,FeeType ft) { - String hql="from Fee f where f.billId="+ order.getId()+" and f.billCode='"+order.getRelateBill3()+"'"; - if(ft!=null){ - hql+=" and f.feeName.id="+ft.getId(); - } - List fees = this.commonDao.findByQuery(hql); - return fees; - } - - public void deleteFees(List fees) { - for (Fee fee : fees) { - if(fee.getBillFee()!=null){ - throw new BusinessException(fee.getBillCode()+"费用已对帐,不能取消回单"); + if (fee.getBillFee() != null) { + throw new BusinessException(order.getRelateBill3() + + "费用已对帐,不能取消回单"); } this.commonDao.delete(fee); } } -// public void saveFee(Order order) { -// List ofts = this.commonDao.findByQuery( -// "from OrderFeeType f where f.orderType.id=:otId", -// new String[] { "otId" }, new Object[] { order.getOrderType() -// .getId() }); -// for (OrderFeeType oft : ofts) { -// Fee fee=new Fee(); -// fee.setBillId(order.getId()); -// fee.setBillCode(order.getCode()); -// fee.setGeneralDepartment(order.getDepartment()); -// fee.setAccount(order.getConsignor()); -// fee.setUnit(MeasureUnit.TICKET); -// fee.setBillObject(BillObjectType.ORDER); -// fee.setStatus(FeeStatus.OPEN); -// fee.setOperator("system"); -// fee.setOperatorDate(new Date()); -// fee.setFeeDate(new Date()); -// fee.setPayOrReceive(oft.getPayOrReceive()); -// fee.setFeeName(oft.getFeeType()); -// fee.setPrice(oft.getPrice()); -// fee.setQuantity(1); -// fee.setTotalFee(DoubleUtils.format4Fraction(oft.getPrice())); -// fee.setTax(fee.getFeeName().getTaxRate()); -// fee.setNoTaxFee(fee.getTotalFee()/(1+fee.getTax()/100)); -// fee.setTaxFee(DoubleUtils.format2Fraction(fee.getTax() * fee.getNoTaxFee() / 100)); -// fee.setOrderId(order.getId()); -// commonDao.store(fee); -// } -// // .订单生效时,根据订单所属单据类型下关联的费用项自动生成费用。费用金额为0 -// // ,单价为0,数量为0,结算对象为订单所属客户,单据序号为订单ID,单据号为订单号, -// // 单据对象为枚举,取值订单。总控部门为单头上的总控部门,费用名称为单据类型下的费用名称, -// // 状态打开,费用日期当前日期,操作人当前用户,操作时间当前时间。 -// } + public List isOpFee(Order order, FeeType ft) { + String hql = "from Fee f where f.billId=" + order.getId() + + " and f.billCode='" + order.getRelateBill3() + "'"; + if (ft != null) { + hql += " and f.feeName.id=" + ft.getId(); + } + List fees = this.commonDao.findByQuery(hql); + return fees; + } + + public void deleteFees(List fees) { + for (Fee fee : fees) { + if (fee.getBillFee() != null) { + throw new BusinessException(fee.getBillCode() + "费用已对帐,不能取消回单"); + } + this.commonDao.delete(fee); + } + } + + // public void saveFee(Order order) { + // List ofts = this.commonDao.findByQuery( + // "from OrderFeeType f where f.orderType.id=:otId", + // new String[] { "otId" }, new Object[] { order.getOrderType() + // .getId() }); + // for (OrderFeeType oft : ofts) { + // Fee fee=new Fee(); + // fee.setBillId(order.getId()); + // fee.setBillCode(order.getCode()); + // fee.setGeneralDepartment(order.getDepartment()); + // fee.setAccount(order.getConsignor()); + // fee.setUnit(MeasureUnit.TICKET); + // fee.setBillObject(BillObjectType.ORDER); + // fee.setStatus(FeeStatus.OPEN); + // fee.setOperator("system"); + // fee.setOperatorDate(new Date()); + // fee.setFeeDate(new Date()); + // fee.setPayOrReceive(oft.getPayOrReceive()); + // fee.setFeeName(oft.getFeeType()); + // fee.setPrice(oft.getPrice()); + // fee.setQuantity(1); + // fee.setTotalFee(DoubleUtils.format4Fraction(oft.getPrice())); + // fee.setTax(fee.getFeeName().getTaxRate()); + // fee.setNoTaxFee(fee.getTotalFee()/(1+fee.getTax()/100)); + // fee.setTaxFee(DoubleUtils.format2Fraction(fee.getTax() * + // fee.getNoTaxFee() / 100)); + // fee.setOrderId(order.getId()); + // commonDao.store(fee); + // } + // // .订单生效时,根据订单所属单据类型下关联的费用项自动生成费用。费用金额为0 + // // ,单价为0,数量为0,结算对象为订单所属客户,单据序号为订单ID,单据号为订单号, + // // 单据对象为枚举,取值订单。总控部门为单头上的总控部门,费用名称为单据类型下的费用名称, + // // 状态打开,费用日期当前日期,操作人当前用户,操作时间当前时间。 + // } @SuppressWarnings("unchecked") private void setExecutePlan(Order order) { @@ -1958,20 +2285,21 @@ public class DefaultOrderManager extends DefaultBaseManager implements */ private void publishEdiServerAvailableOrder(Order order) { String type = ""; -// if (order.getOrderType().getIsInStorage()) { -// // 收货订单发送ASN消息 -// type = InterfaceLogConstant.AVAILABLE_ORDER_PO; -// } else if (order.getOrderType().getIsOutStorage() -// || order.getOrderType().isTransport()) { -// // 发货订单发送SHIPPINGORDER消息 -// type = InterfaceLogConstant.AVAILABLE_ORDER_SO; -// } -// if (order.getOrderType().isTransport()) { - // 发货订单发送SHIPPINGORDER消息 - type = InterfaceLogConstant.AVAILABLE_ORDER_SO; -// } -// messageService.publishMessageRecord(new MessageRecord(type,order.getId())); - TmsTask t=(TmsTask) EntityFactory.getEntity(TmsTask.class); + // if (order.getOrderType().getIsInStorage()) { + // // 收货订单发送ASN消息 + // type = InterfaceLogConstant.AVAILABLE_ORDER_PO; + // } else if (order.getOrderType().getIsOutStorage() + // || order.getOrderType().isTransport()) { + // // 发货订单发送SHIPPINGORDER消息 + // type = InterfaceLogConstant.AVAILABLE_ORDER_SO; + // } + // if (order.getOrderType().isTransport()) { + // 发货订单发送SHIPPINGORDER消息 + type = InterfaceLogConstant.AVAILABLE_ORDER_SO; + // } + // messageService.publishMessageRecord(new + // MessageRecord(type,order.getId())); + TmsTask t = (TmsTask) EntityFactory.getEntity(TmsTask.class); t.setMessageId(order.getId()); t.setMessageType(type); t.setType(InterfaceLogConstant.SO_RECIVED); @@ -1979,7 +2307,8 @@ public class DefaultOrderManager extends DefaultBaseManager implements t.setStatus(TmsTask.STAT_FINISH); this.commonDao.store(t); legMonitorService.expandLegsAndMonitorByExecutePlan(order); - //legMonitorService.manualSetMonitorRecordTime(order, ExecutePlanTaskName.ORDER_PROCESSING, order.getActiveTime()); + // legMonitorService.manualSetMonitorRecordTime(order, + // ExecutePlanTaskName.ORDER_PROCESSING, order.getActiveTime()); } /** @@ -1989,11 +2318,13 @@ public class DefaultOrderManager extends DefaultBaseManager implements * */ public void unAvailableOrder(List ids) { - unAvailableOrderSB(ids,Boolean.FALSE,null,null,null); + unAvailableOrderSB(ids, Boolean.FALSE, null, null, null); } - public void unAvailableOrderSB(List ids,Boolean equipment,Long platFormId,Long userId,String userName) { + + public void unAvailableOrderSB(List ids, Boolean equipment, + Long platFormId, Long userId, String userName) { for (Order order : loadAllOrder(ids)) { - if (OrderStatus.TRANS_AVAILABLE.equals(order.getStatus())){ + if (OrderStatus.TRANS_AVAILABLE.equals(order.getStatus())) { // 失效订单直接返回录入中状态,待录入确认后重新包装和审核库存 deleteOpFee(order); order.setStatus(OrderStatus.AVAILABLE); @@ -2006,41 +2337,55 @@ public class DefaultOrderManager extends DefaultBaseManager implements legs.addAll(order.getOrderLegs()); for (Legs leg : legs) { if (leg.getTempShipment() != null) { - TempShipment tempShip = load(TempShipment.class,leg.getTempShipment().getId()); + TempShipment tempShip = load(TempShipment.class, leg + .getTempShipment().getId()); tempShip.removeLegs(leg); commonDao.store(tempShip); } } - List fs=commonDao.findByQuery("from Fee f where f.beShare=1 and f.billObject='ORDER' and f.billId="+order.getId()+" and f.operator='system'"); - for(Fee f:fs){ + List fs = commonDao + .findByQuery("from Fee f where f.beShare=1 and f.billObject='ORDER' and f.billId=" + + order.getId() + " and f.operator='system'"); + for (Fee f : fs) { this.commonDao.delete(f); } - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); order.removeAllOrderLegs(legs); setUpdateInfo(order); // 向EDI-Server接口,发送订单失效消息;..... - messageService.publishMessageRecord(new MessageRecord(InterfaceLogConstant.ORDER_INVALID, order.getId())); - - //失效删除分单信息 - List Separates=this.commonDao.findByQuery("from Separate s where s.order.id=:id", - new String[]{"id"},new Object[]{order.getId()}); - if(Separates.size()>0){ - for(Separate s: Separates){ + messageService.publishMessageRecord(new MessageRecord( + InterfaceLogConstant.ORDER_INVALID, order.getId())); + + // 失效删除分单信息 + List Separates = this.commonDao.findByQuery( + "from Separate s where s.order.id=:id", + new String[] { "id" }, new Object[] { order.getId() }); + if (Separates.size() > 0) { + for (Separate s : Separates) { commonDao.delete(s); } } - - }else { + + } else { throw new BusinessException("order.status.error"); } - if(!equipment){ - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-订单维护", "失效", - OperationHisUtil.operationHisStatus("AVAILABLE"),OperationHisUtil.operationHisStatus("INPUT"), - order.getQuantity(), order.getWeight(), order.getVolume(),0, order.getDescription(), "TMS"); - }else{ - operationHisManager.saveOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-订单维护", "APP失效", - OperationHisUtil.operationHisStatus(order.getStatus()),OperationHisUtil.operationHisStatus(order.getStatus()), - order.getQuantity(), order.getWeight(), order.getVolume(),0, order.getDescription(), "TMS", Boolean.TRUE,platFormId, userId, userName); + if (!equipment) { + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "订单管理-订单维护", "失效", + OperationHisUtil.operationHisStatus("AVAILABLE"), + OperationHisUtil.operationHisStatus("INPUT"), + order.getQuantity(), order.getWeight(), + order.getVolume(), 0, order.getDescription(), "TMS"); + } else { + operationHisManager.saveOperationHis(order.getId(), + order.getRelateBill3(), null, null, "订单管理-订单维护", + "APP失效", + OperationHisUtil.operationHisStatus(order.getStatus()), + OperationHisUtil.operationHisStatus(order.getStatus()), + order.getQuantity(), order.getWeight(), + order.getVolume(), 0, order.getDescription(), "TMS", + Boolean.TRUE, platFormId, userId, userName); } } @@ -2083,12 +2428,25 @@ public class DefaultOrderManager extends DefaultBaseManager implements public void cancelOrder(List ids) { for (Order order : loadAllOrder(ids)) { // 条件约束订单状态为 '未生效' - if (order.getStatus().equals(OrderStatus.INPUT)||order.getStatus().equals(OrderStatus.AVAILABLE)) { + if (order.getStatus().equals(OrderStatus.INPUT) + || order.getStatus().equals(OrderStatus.AVAILABLE)) { order.setStatus(OrderStatus.CANCEL); setUpdateInfo(order); - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理-订单管理", "取消", - OperationHisUtil.operationHisStatus(OrderStatus.AVAILABLE),OperationHisUtil.operationHisStatus(OrderStatus.CANCEL), - order.getQuantity(),order.getWeight(),order.getVolume(),0, order.getDescription(), "TMS"); + operationHisManager + .storeOperationHis( + order.getId(), + order.getRelateBill3(), + null, + null, + "订单管理-订单管理", + "取消", + OperationHisUtil + .operationHisStatus(OrderStatus.AVAILABLE), + OperationHisUtil + .operationHisStatus(OrderStatus.CANCEL), + order.getQuantity(), order.getWeight(), order + .getVolume(), 0, + order.getDescription(), "TMS"); } else { throw new BusinessException("order.status.error"); } @@ -2097,53 +2455,67 @@ public class DefaultOrderManager extends DefaultBaseManager implements public void forceCancelOrder(List ids) { for (Long id : ids) { - Order o=this.commonDao.get(Order.class, id); - String des=""; - String oldStatus=o.getStatus(); - List separates=this.commonDao.findByQuery("from Separate l where l.order.id=:orderId",new String[]{"orderId"},new Object[]{o.getId()}); - for(Separate s:separates){ + Order o = this.commonDao.get(Order.class, id); + String des = ""; + String oldStatus = o.getStatus(); + List separates = this.commonDao.findByQuery( + "from Separate l where l.order.id=:orderId", + new String[] { "orderId" }, new Object[] { o.getId() }); + for (Separate s : separates) { commonDao.delete(s); } - List legs=this.commonDao.findByQuery("from Legs l where l.order.id=:orderId",new String[]{"orderId"},new Object[]{o.getId()}); - for(Legs l:legs){ - //删除leg下的费用 - Shipment s=l.getShipment(); - if(s!=null){ + List legs = this.commonDao.findByQuery( + "from Legs l where l.order.id=:orderId", + new String[] { "orderId" }, new Object[] { o.getId() }); + for (Legs l : legs) { + // 删除leg下的费用 + Shipment s = l.getShipment(); + if (s != null) { s.removeLegs(l); } - List feeIds=this.commonDao.findByQuery("select id from Fee f where f.billId=:billId and f.billObject=:billType", - new String[]{"billId","billType"},new Object[]{l.getId(),BillObjectType.LEGS}); - des+="删除"+l.getEcNo()+"及费用;状态为"+l.getDispatchNode()+"-"+l.getStatus()+";"; + List feeIds = this.commonDao + .findByQuery( + "select id from Fee f where f.billId=:billId and f.billObject=:billType", + new String[] { "billId", "billType" }, + new Object[] { l.getId(), BillObjectType.LEGS }); + des += "删除" + l.getEcNo() + "及费用;状态为" + l.getDispatchNode() + + "-" + l.getStatus() + ";"; feeManager.deleteFee(feeIds); - List sites=this.commonDao.findByQuery("from CollectionSite s where s.order.id=:orderId", - new String[]{"orderId"},new Object[]{o.getId()}); - if(sites.size()>0){ + List sites = this.commonDao.findByQuery( + "from CollectionSite s where s.order.id=:orderId", + new String[] { "orderId" }, new Object[] { o.getId() }); + if (sites.size() > 0) { this.commonDao.deleteAll(sites); } - List srs=this.commonDao.findByQuery("from StarRating s where s.order.id=:orderId", - new String[]{"orderId"},new Object[]{l.getId()}); - if(srs.size()>0){ + List srs = this.commonDao.findByQuery( + "from StarRating s where s.order.id=:orderId", + new String[] { "orderId" }, new Object[] { l.getId() }); + if (srs.size() > 0) { this.commonDao.deleteAll(srs); } this.commonDao.delete(l); - if(s!=null){ + if (s != null) { feeManager.shareShipmentFee(s.getId()); - des+="从"+s.getCode()+"中强制移除,成本"+s.getPayfee()+"重新均摊;"; - //如果调度单无明细,费用应该为0 + des += "从" + s.getCode() + "中强制移除,成本" + s.getPayfee() + + "重新均摊;"; + // 如果调度单无明细,费用应该为0 } - + } o.setLeaveTime(null); o.setArriveTime(null); o.setSignTime(null); o.setStatus(OrderStatus.AVAILABLE); this.commonDao.store(o); - operationHisManager.storeOperationHis(o.getId(),o.getRelateBill3(), null, null, "订单管理-客户费用审核", "强制失效", - OperationHisUtil.operationHisStatus(oldStatus),OperationHisUtil.operationHisStatus(o.getStatus()), - o.getQuantity(),o.getWeight(),o.getVolume(),0, des, "TMS"); + operationHisManager.storeOperationHis(o.getId(), + o.getRelateBill3(), null, null, "订单管理-客户费用审核", "强制失效", + OperationHisUtil.operationHisStatus(oldStatus), + OperationHisUtil.operationHisStatus(o.getStatus()), + o.getQuantity(), o.getWeight(), o.getVolume(), 0, des, + "TMS"); } } - + protected Date formatDate(String str) { return DateUtil.formatDateYMD_HM(DateUtil.getDate() + " " + str); } @@ -2275,7 +2647,8 @@ public class DefaultOrderManager extends DefaultBaseManager implements Order order = load(Order.class, id); if (OrderStatus.SIGNED.equals(order.getStatus()) && order.isSignException()) { - Order recedeOrder = (Order) EntityFactory.getEntity(Order.class); + Order recedeOrder = (Order) EntityFactory + .getEntity(Order.class); if (order.notEmptyDetails()) { for (OrderDetail od : order.getDetails()) { @@ -2341,7 +2714,8 @@ public class DefaultOrderManager extends DefaultBaseManager implements public void signImageStore(Map map) { Order signOrder = retrieveSignOrder(map); if (null != signOrder) { - SignFile signFile = (SignFile) EntityFactory.getEntity(SignFile.class); + SignFile signFile = (SignFile) EntityFactory + .getEntity(SignFile.class); signFile.setFileName(map.get("currentImageName").toString()); signFile.setImageType(map.get("signFile.imageType").toString()); signFile.processFileUrl(map.get("imageTarget").toString()); @@ -2431,9 +2805,13 @@ public class DefaultOrderManager extends DefaultBaseManager implements order.setImageStatus(Boolean.TRUE);// 重置图片上传状态 order.addFiles(signFile);// 创建和附件的关联 setUpdateInfo(order);// 更新回单日志 - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), signFile.getId(), null, "运输订单-回单管理", "影像归档",OperationHisUtil.operationHisStatus("SIGNED"), - OperationHisUtil.operationHisStatus("SIGNED"),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription(), "TMS"); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), signFile.getId(), null, + "运输订单-回单管理", "影像归档", + OperationHisUtil.operationHisStatus("SIGNED"), + OperationHisUtil.operationHisStatus("SIGNED"), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, order.getDescription(), "TMS"); } else { throw new BusinessException( "file.not.exist.or.file.length.bigger.than.2M"); @@ -2561,9 +2939,6 @@ public class DefaultOrderManager extends DefaultBaseManager implements } } - - - /** * 回单登记:签收确认 * @@ -2592,7 +2967,7 @@ public class DefaultOrderManager extends DefaultBaseManager implements order.setDeltaQuantity(deltaQuantity); order.setSignTime(signDate); order.setSignNote(signNote); - + order.setStatus(OrderStatus.SIGNED); getVehicleCountNum(orderId); /** @@ -2600,27 +2975,32 @@ public class DefaultOrderManager extends DefaultBaseManager implements */ setUpdateInfo(order); checkOrderLegsStatus(order); - //updateOrderStatus(order); - if(order.getStatus().equals(OrderStatus.SIGNED)){ + // updateOrderStatus(order); + if (order.getStatus().equals(OrderStatus.SIGNED)) { order.setSignException(order.recedeException()); - if(order.getFeeCode()!=null&&!order.getFeeCode().equals("")){ - String feeCode=order.getFeeCode(); - List fcodes=this.commonDao.findByQuery("select o.id from Order o where o.relateBill3=:code",new String[]{"code"},new Object[]{feeCode}); - if(fcodes.size()<=0){ - throw new BusinessException("找不到该计费单号"+feeCode+"请重新输入"); + if (order.getFeeCode() != null && !order.getFeeCode().equals("")) { + String feeCode = order.getFeeCode(); + List fcodes = this.commonDao.findByQuery( + "select o.id from Order o where o.relateBill3=:code", + new String[] { "code" }, new Object[] { feeCode }); + if (fcodes.size() <= 0) { + throw new BusinessException("找不到该计费单号" + feeCode + "请重新输入"); } - String remark="该费用合并计算在"+order.getFeeCode()+"单号上"; -// feeManager.createContractOrderFee(order,remark); - }else{ - if(order.getConsignor().getFeeUnit()==null||order.getConsignor().getFeeUnit().equals("")||!order.getConsignor().getFeeUnit().equals("DAY_SHIPMEN")){ -// contractFee(order.getId()); + String remark = "该费用合并计算在" + order.getFeeCode() + "单号上"; + // feeManager.createContractOrderFee(order,remark); + } else { + if (order.getConsignor().getFeeUnit() == null + || order.getConsignor().getFeeUnit().equals("") + || !order.getConsignor().getFeeUnit() + .equals("DAY_SHIPMEN")) { + // contractFee(order.getId()); } } - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER,Boolean.TRUE); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); } } - - + @SuppressWarnings("unchecked") public void saveSignOrder(Map map) { Set> itor = map.entrySet(); @@ -2643,9 +3023,10 @@ public class DefaultOrderManager extends DefaultBaseManager implements /** * 整单签收 + * * @author dev */ - public void confirmSignOrder(List ids,Date signTime,Date feeTime) { + public void confirmSignOrder(List ids, Date signTime, Date feeTime) { for (Long id : ids) { Order order = this.get(Order.class, id); if (OrderStatus.SIGNED != order.getStatus()) { @@ -2656,7 +3037,10 @@ public class DefaultOrderManager extends DefaultBaseManager implements orderDetail.setShipedQuantity(orderDetail .getQuantity()); } - orderDetail.signQuantity(orderDetail.getShipedQuantity()- orderDetail.getSignQuantity()- orderDetail.getBadQuantity(), 0); + orderDetail.signQuantity( + orderDetail.getShipedQuantity() + - orderDetail.getSignQuantity() + - orderDetail.getBadQuantity(), 0); } } else { /** @@ -2671,84 +3055,97 @@ public class DefaultOrderManager extends DefaultBaseManager implements } else { throw new BusinessException("order.status.error"); } -// if(order.getUnit().equals(MeasureUnit.VEHICLETYPE)){ -// if(order.getExtends1()==null){ -// throw new BusinessException("计费车型1不能为空"); -// } -// } -// if(order.getExtends1()==null && order.getVehicleNumber1()!=null){ -// throw new BusinessException("计费车型1为空,车次数1不能有值"); -// } -// if(order.getExtends2()==null && order.getVehicleNumber2()!=null){ -// throw new BusinessException("计费车型2为空,车次数2不能有值"); -// } -// if(order.getExtends3()==null && order.getVehicleNumber3()!=null){ -// throw new BusinessException("计费车型3为空,车次数3不能有值"); -// } -// if(order.getExtends4()==null && order.getVehicleNumber4()!=null){ -// throw new BusinessException("计费车型4为空,车次数4不能有值"); -// } + // if(order.getUnit().equals(MeasureUnit.VEHICLETYPE)){ + // if(order.getExtends1()==null){ + // throw new BusinessException("计费车型1不能为空"); + // } + // } + // if(order.getExtends1()==null && order.getVehicleNumber1()!=null){ + // throw new BusinessException("计费车型1为空,车次数1不能有值"); + // } + // if(order.getExtends2()==null && order.getVehicleNumber2()!=null){ + // throw new BusinessException("计费车型2为空,车次数2不能有值"); + // } + // if(order.getExtends3()==null && order.getVehicleNumber3()!=null){ + // throw new BusinessException("计费车型3为空,车次数3不能有值"); + // } + // if(order.getExtends4()==null && order.getVehicleNumber4()!=null){ + // throw new BusinessException("计费车型4为空,车次数4不能有值"); + // } updateOrderStatus(order); - if(order.getStatus().equals(OrderStatus.SIGNED)){ - if(order.getConsignor().getFeeUnit()==null||order.getConsignor().getFeeUnit().equals("")||!order.getConsignor().getFeeUnit().equals("DAY_SHIPMEN")){ -// contractFee(id); + if (order.getStatus().equals(OrderStatus.SIGNED)) { + if (order.getConsignor().getFeeUnit() == null + || order.getConsignor().getFeeUnit().equals("") + || !order.getConsignor().getFeeUnit() + .equals("DAY_SHIPMEN")) { + // contractFee(id); } getVehicleCountNum(id); -// feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER,Boolean.TRUE); + // feeManager.refreshBillFee(order.getId(), + // BillObjectType.ORDER,Boolean.TRUE); } -// contractCZFee(id); - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "回单管理-批量回单签收", "批量回单签收",OperationHisUtil.operationHisStatus("ARRIVED"), - OperationHisUtil.operationHisStatus("SIGNED"),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription(), "TMS"); + // contractCZFee(id); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "回单管理-批量回单签收", + "批量回单签收", OperationHisUtil.operationHisStatus("ARRIVED"), + OperationHisUtil.operationHisStatus("SIGNED"), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, order.getDescription(), "TMS"); } } + /** * 判断是部门回单还是全部回单完成 + * * @param order */ private void updateOrderStatus(Order order) { - String hql="from Legs l where l.order="+order.getId(); - List lsgs=commonDao.findByQuery(hql); - if(lsgs.size()>0){ - int i=0,j=0; - for(Legs l: lsgs){ - if(OrderStatus.SIGNED.equals(l.getStatus())){ - i+=1; - }else{ - j+=1; + String hql = "from Legs l where l.order=" + order.getId(); + List lsgs = commonDao.findByQuery(hql); + if (lsgs.size() > 0) { + int i = 0, j = 0; + for (Legs l : lsgs) { + if (OrderStatus.SIGNED.equals(l.getStatus())) { + i += 1; + } else { + j += 1; } } - if(i>0 && j>0){ + if (i > 0 && j > 0) { order.setStatus(OrderStatus.PART_SIGNED); } } commonDao.store(order); - - + } - - + /** * 检查下面的运单是否都已运抵,全部运抵才可回单签收 + * * @param order */ private void checkOrderLegsStatus(Order order) { for (Legs olegs : order.getOrderLegs()) { -// if(olegs.getArriveTime()==null){ -// //if(!olegs.getStatus().equals(LegsStatus.ARRIVED) && !olegs.getStatus().equals(LegsStatus.HW_ARRIVED) && !olegs.getStatus().equals(LegsStatus.GYS_ARRIVED) && !olegs.getStatus().equals(LegsStatus.SH_ARRIVED)){ -// throw new BusinessException(olegs.getEcNo()+"有未运抵的运单,不能回单确认!"); -// } + // if(olegs.getArriveTime()==null){ + // //if(!olegs.getStatus().equals(LegsStatus.ARRIVED) && + // !olegs.getStatus().equals(LegsStatus.HW_ARRIVED) && + // !olegs.getStatus().equals(LegsStatus.GYS_ARRIVED) && + // !olegs.getStatus().equals(LegsStatus.SH_ARRIVED)){ + // throw new BusinessException(olegs.getEcNo()+"有未运抵的运单,不能回单确认!"); + // } } } public void canelConfirmSignOrder(List ids) { for (Long id : ids) { Order order = this.get(Order.class, id); -// if(!order.getOtherStatus().equals("OPEN")&&!order.getOtherStatus().equals(FeeStatus.SUBMIT_CHECK)){ -// throw new BusinessException(order.getRelateBill3()+"委外费用已审核,请先退回相关操作"); -// } - if(!order.getCostStatus().equals("OPEN")){ - throw new BusinessException(order.getRelateBill3()+"营业额费用已审核,请先退回相关操作"); + // if(!order.getOtherStatus().equals("OPEN")&&!order.getOtherStatus().equals(FeeStatus.SUBMIT_CHECK)){ + // throw new + // BusinessException(order.getRelateBill3()+"委外费用已审核,请先退回相关操作"); + // } + if (!order.getCostStatus().equals("OPEN")) { + throw new BusinessException(order.getRelateBill3() + + "营业额费用已审核,请先退回相关操作"); } if (OrderStatus.SIGNED.equals(order.getStatus())) { order.setSignTime(null); @@ -2771,21 +3168,24 @@ public class DefaultOrderManager extends DefaultBaseManager implements + detail.getId() + " order by log.id"); commonDao.deleteAll(orderSignLogs); } -// order.setReceivefee(0); -// order.setProfit(order.getReceivefee()-order.getPayfee()+order.getOtherFee()); -// for(Legs leg:order.getOrderLegs()){ -// leg.setTurnover(0); -// leg.setProfit(leg.getTurnover()-leg.getOtherFee()-leg.getPayfee()); -// this.commonDao.store(leg); -// } + // order.setReceivefee(0); + // order.setProfit(order.getReceivefee()-order.getPayfee()+order.getOtherFee()); + // for(Legs leg:order.getOrderLegs()){ + // leg.setTurnover(0); + // leg.setProfit(leg.getTurnover()-leg.getOtherFee()-leg.getPayfee()); + // this.commonDao.store(leg); + // } commonDao.store(order); -// deleteOpFee(order); + // deleteOpFee(order); } else { throw new BusinessException("order.status.error"); } - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "回单管理-取消签收", "取消签收",OperationHisUtil.operationHisStatus("SIGNED"), - OperationHisUtil.operationHisStatus("ARRIVED"),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription(), "TMS"); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "回单管理-取消签收", "取消签收", + OperationHisUtil.operationHisStatus("SIGNED"), + OperationHisUtil.operationHisStatus("ARRIVED"), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, order.getDescription(), "TMS"); } } @@ -2879,26 +3279,37 @@ public class DefaultOrderManager extends DefaultBaseManager implements public void removeOrders(List ids) { for (Long id : ids) { Order order = this.load(Order.class, id); - if(order.getStatus().equals(OrderStatus.AVAILABLE)||order.getStatus().equals(OrderStatus.CANCEL)){ - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "运输订单管理-运输订单维护", "删除",OperationHisUtil.operationHisStatus("INPUT"), - OperationHisUtil.operationHisStatus("AVAILABLE"),order.getQuantity(), order.getWeight(), + if (order.getStatus().equals(OrderStatus.AVAILABLE) + || order.getStatus().equals(OrderStatus.CANCEL)) { + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "运输订单管理-运输订单维护", + "删除", OperationHisUtil.operationHisStatus("INPUT"), + OperationHisUtil.operationHisStatus("AVAILABLE"), + order.getQuantity(), order.getWeight(), order.getVolume(), 0, order.getDescription(), "TMS"); - List ps=this.commonDao.findByQuery("from PackDetail d where d.order.id="+order.getId()); - if(ps.size()>0){ + List ps = this.commonDao + .findByQuery("from PackDetail d where d.order.id=" + + order.getId()); + if (ps.size() > 0) { this.commonDao.deleteAll(ps); } - List ds=this.commonDao.findByQuery("from OrderDetail d where d.order.id="+order.getId()); - if(ds.size()>0){ + List ds = this.commonDao + .findByQuery("from OrderDetail d where d.order.id=" + + order.getId()); + if (ds.size() > 0) { this.commonDao.deleteAll(ds); } this.commonDao.delete(order); - }else{ - throw new BusinessException(order.getRelateBill3()+"状态错误"); + } else { + throw new BusinessException(order.getRelateBill3() + "状态错误"); } - - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "运输订单管理-运输订单维护", "删除",OperationHisUtil.operationHisStatus("INPUT"), - OperationHisUtil.operationHisStatus("AVAILABLE"),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription(), "TMS"); + + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "运输订单管理-运输订单维护", "删除", + OperationHisUtil.operationHisStatus("INPUT"), + OperationHisUtil.operationHisStatus("AVAILABLE"), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, order.getDescription(), "TMS"); } } @@ -2976,7 +3387,7 @@ public class DefaultOrderManager extends DefaultBaseManager implements if (!(order.getStatus().equals(OrderStatus.INPUT) || order.getStatus().equals(OrderStatus.UNCHECK) || order.getStatus().equals(OrderStatus.CHECKING) || order - .isSplited() == false)) { + .isSplited() == false)) { throw new BusinessException("this.is.order.status.error", new String[] { order.getStatus(), order.getCode() }); } @@ -3017,23 +3428,27 @@ public class DefaultOrderManager extends DefaultBaseManager implements "splitQuantity.bigger.than.detailQuantity", new String[] { od.getLineNo().toString() }); } - od.setWeight(od.getWeight()/od.getQuantity()*(od.getQuantity()-splitQuantity)); - od.setVolume(od.getVolume()/od.getQuantity()*(od.getQuantity()-splitQuantity)); - od.setQuantity(od.getQuantity()-splitQuantity); + od.setWeight(od.getWeight() / od.getQuantity() + * (od.getQuantity() - splitQuantity)); + od.setVolume(od.getVolume() / od.getQuantity() + * (od.getQuantity() - splitQuantity)); + od.setQuantity(od.getQuantity() - splitQuantity); oDetail.setQuantity(splitQuantity); - oDetail.setWeight(od.getWeight()/od.getQuantity() * splitQuantity); - oDetail.setVolume(od.getVolume()/od.getQuantity() * splitQuantity); + oDetail.setWeight(od.getWeight() / od.getQuantity() + * splitQuantity); + oDetail.setVolume(od.getVolume() / od.getQuantity() + * splitQuantity); quantity += splitQuantity; - weight += od.getWeight()/od.getQuantity() * splitQuantity; - volume += od.getVolume()/od.getQuantity() * splitQuantity; + weight += od.getWeight() / od.getQuantity() * splitQuantity; + volume += od.getVolume() / od.getQuantity() * splitQuantity; newOrder.addDetail(oDetail); od.setSplitQuantity(od.getSplitQuantity() + splitQuantity); } } } newOrder.setQuantity(quantity); - newOrder.setWeight(DoubleUtils.formatByPrecision(weight,5)); - newOrder.setVolume(DoubleUtils.formatByPrecision(volume,5)); + newOrder.setWeight(DoubleUtils.formatByPrecision(weight, 5)); + newOrder.setVolume(DoubleUtils.formatByPrecision(volume, 5)); newOrder.setCode(getAvailableCode(order)); // 为拆分分配code newOrder.setRelateBill3(order.getCode()); newOrder.setSplited(false); @@ -3042,9 +3457,11 @@ public class DefaultOrderManager extends DefaultBaseManager implements List ids = new ArrayList(); ids.add(newOrder.getId()); enterCheck(ids); - order.setQuantity(order.getQuantity()-quantity); - order.setWeight(DoubleUtils.formatByPrecision(order.getWeight()-weight,5)); - order.setVolume(DoubleUtils.formatByPrecision(order.getVolume()-volume,7)); + order.setQuantity(order.getQuantity() - quantity); + order.setWeight(DoubleUtils.formatByPrecision(order.getWeight() + - weight, 5)); + order.setVolume(DoubleUtils.formatByPrecision(order.getVolume() + - volume, 7)); order.setSplited(true); store(order); } @@ -3123,13 +3540,16 @@ public class DefaultOrderManager extends DefaultBaseManager implements od.setSplitQuantity(od.getSplitQuantity() - orderDetail.getQuantity()); - od.setQuantity(od.getQuantity()+orderDetail.getQuantity()); - od.setWeight(od.getWeight()+orderDetail.getWeight()); - od.setVolume(od.getVolume()+orderDetail.getVolume()); - quantity+=orderDetail.getQuantity(); - weight+=orderDetail.getWeight(); - volume+=orderDetail.getVolume(); - + od.setQuantity(od.getQuantity() + + orderDetail.getQuantity()); + od.setWeight(od.getWeight() + + orderDetail.getWeight()); + od.setVolume(od.getVolume() + + orderDetail.getVolume()); + quantity += orderDetail.getQuantity(); + weight += orderDetail.getWeight(); + volume += orderDetail.getVolume(); + } } @@ -3142,9 +3562,11 @@ public class DefaultOrderManager extends DefaultBaseManager implements } if (parentOrder.getSplitQuantity() == 0) { parentOrder.setSplited(false); - parentOrder.setQuantity(quantity+parentOrder.getQuantity()); - parentOrder.setWeight(DoubleUtils.formatByPrecision(weight+parentOrder.getWeight(),5)); - parentOrder.setVolume(DoubleUtils.formatByPrecision(volume+parentOrder.getVolume(),7)); + parentOrder.setQuantity(quantity + parentOrder.getQuantity()); + parentOrder.setWeight(DoubleUtils.formatByPrecision(weight + + parentOrder.getWeight(), 5)); + parentOrder.setVolume(DoubleUtils.formatByPrecision(volume + + parentOrder.getVolume(), 7)); parentOrder.setStatus(OrderStatus.INPUT); } this.store(parentOrder); @@ -3219,7 +3641,8 @@ public class DefaultOrderManager extends DefaultBaseManager implements } } if (newPackage == null) { - newPackage = (OrderPackage) EntityFactory.getEntity(OrderPackage.class); + newPackage = (OrderPackage) EntityFactory + .getEntity(OrderPackage.class); String currentLineNo = ObjectUtils .toString( @@ -3301,7 +3724,8 @@ public class DefaultOrderManager extends DefaultBaseManager implements } } if (newPackage == null) { - newPackage = (OrderPackage) EntityFactory.getEntity(OrderPackage.class); // 添加重包装的package + newPackage = (OrderPackage) EntityFactory + .getEntity(OrderPackage.class); // 添加重包装的package newOpp.setOrderPackage(newPackage); } // 生成对应的OrderPackageProduct @@ -3435,7 +3859,8 @@ public class DefaultOrderManager extends DefaultBaseManager implements } // 将页面传入的数据创建一个包装 // packWeight+=weight; - LegPackage orPackage = (LegPackage) EntityFactory.getEntity(LegPackage.class); // 添加重包装的package + LegPackage orPackage = (LegPackage) EntityFactory + .getEntity(LegPackage.class); // 添加重包装的package orPackage.setPackageDesc(ProductPackageUnit.CASE); orPackage.setVolume(packVolume); orPackage.setWeight(packWeight); @@ -3649,55 +4074,54 @@ public class DefaultOrderManager extends DefaultBaseManager implements CaseModel casemodel = this.load(CaseModel.class, caseid); return casemodel.getWeight(); } - + public String plannedarrivaltime(Map map) { - SimpleDateFormat sdf=new SimpleDateFormat("hh:mm"); + SimpleDateFormat sdf = new SimpleDateFormat("hh:mm"); Long orderid = (Long) map.get("orders.id"); - Order order=this.load(Order.class, orderid); - String fromCity=order.getFromCityCountiy().getName(); - String toCity=order.getToCityCountiy().getName(); - String siteName=fromCity+"-"+toCity; - RouteFee routeFee=null; - Date orderdate=order.getOrderDate();//获取下单时间 - Long time= orderdate.getTime();//获取时间毫秒数 - List routeFees=commonDao.findByQuery(" from RouteFee r where r.name=:name ", - new String[] { "name"},new Object[] {siteName}); - if(routeFees.size()>0) { - routeFee=routeFees.get(0); - if(order.getShipmentMethod().equals("TRUCK")) { - time+=(int)routeFee.getTransportationAging()*1000*60;//普运 - return sdf.format( time); - }else if(order.getShipmentMethod().equals("RAILWAY")) { - time+=(int)routeFee.getTransportationAging2()*1000*60;//快运 + Order order = this.load(Order.class, orderid); + String fromCity = order.getFromCityCountiy().getName(); + String toCity = order.getToCityCountiy().getName(); + String siteName = fromCity + "-" + toCity; + RouteFee routeFee = null; + Date orderdate = order.getOrderDate();// 获取下单时间 + Long time = orderdate.getTime();// 获取时间毫秒数 + List routeFees = commonDao.findByQuery( + " from RouteFee r where r.name=:name ", + new String[] { "name" }, new Object[] { siteName }); + if (routeFees.size() > 0) { + routeFee = routeFees.get(0); + if (order.getShipmentMethod().equals("TRUCK")) { + time += (int) routeFee.getTransportationAging() * 1000 * 60;// 普运 return sdf.format(time); - }else if(order.getShipmentMethod().equals("SPECIAL_CAR")) { - time+=(int)routeFee.getTransportationAging3()*1000*60;//专车 + } else if (order.getShipmentMethod().equals("RAILWAY")) { + time += (int) routeFee.getTransportationAging2() * 1000 * 60;// 快运 return sdf.format(time); - }else if(order.getShipmentMethod().equals("ZERO_SINGLE")) { - time+=(int)routeFee.getTransportationAging4()*1000*60;//快递 + } else if (order.getShipmentMethod().equals("SPECIAL_CAR")) { + time += (int) routeFee.getTransportationAging3() * 1000 * 60;// 专车 return sdf.format(time); - }else if(order.getShipmentMethod().equals("AIR")) { - time+=(int)routeFee.getTransportationAging5()*1000*60;//空运 + } else if (order.getShipmentMethod().equals("ZERO_SINGLE")) { + time += (int) routeFee.getTransportationAging4() * 1000 * 60;// 快递 return sdf.format(time); - }else if(order.getShipmentMethod().equals("URGENT")) { - time+=(int)routeFee.getTransportationAging6()*1000*60;//加急 + } else if (order.getShipmentMethod().equals("AIR")) { + time += (int) routeFee.getTransportationAging5() * 1000 * 60;// 空运 return sdf.format(time); - }else if(order.getShipmentMethod().equals("AIR_URGENT")) { - time+=(int)routeFee.getTransportationAging7()*1000*60;//空运加急 + } else if (order.getShipmentMethod().equals("URGENT")) { + time += (int) routeFee.getTransportationAging6() * 1000 * 60;// 加急 return sdf.format(time); - }else if(order.getShipmentMethod().equals("HIGHWAY")){ - time+=(int)routeFee.getTransportationAging8()*1000*60;//高铁 + } else if (order.getShipmentMethod().equals("AIR_URGENT")) { + time += (int) routeFee.getTransportationAging7() * 1000 * 60;// 空运加急 + return sdf.format(time); + } else if (order.getShipmentMethod().equals("HIGHWAY")) { + time += (int) routeFee.getTransportationAging8() * 1000 * 60;// 高铁 return sdf.format(time); } - - }else { + + } else { return ""; } - + return sdf.format(time); } - - public void fee(Long id, Long feeTypeId, double moneyFeeamount, String remark) { @@ -3987,203 +4411,232 @@ public class DefaultOrderManager extends DefaultBaseManager implements } - private String checkContract(Contract c,Date computeDate){ - String description=""; + private String checkContract(Contract c, Date computeDate) { + String description = ""; Date contractDateStart = c.getContractDateStart(); Date contractDateEnd = c.getContractDateEnd(); - if(contractDateEnd==null){ - description+="合同未设置有效期;"; - }else{ - if(computeDate.getTime() > contractDateEnd.getTime()){ - description+="合同已到期;"; + if (contractDateEnd == null) { + description += "合同未设置有效期;"; + } else { + if (computeDate.getTime() > contractDateEnd.getTime()) { + description += "合同已到期;"; } } - if(c.getStatus().equals(ContractStatus.OPEN)){ - description+="合同为打开状态,需区域审核;"; - }else if(c.getStatus().equals(ContractStatus.PART_CEHCK)){ - description+="合同为区域审核状态,需总部审核;"; + if (c.getStatus().equals(ContractStatus.OPEN)) { + description += "合同为打开状态,需区域审核;"; + } else if (c.getStatus().equals(ContractStatus.PART_CEHCK)) { + description += "合同为区域审核状态,需总部审核;"; } return description; } - private int getVehicleCountNum(Long id){ + + private int getVehicleCountNum(Long id) { Order o = commonDao.load(Order.class, id); - int vehicleCountNum=0; - if(o.getExtends1()!=null){ - int vehicleNumber1=o.getVehicleNumber1()==null?1:o.getVehicleNumber1(); + int vehicleCountNum = 0; + if (o.getExtends1() != null) { + int vehicleNumber1 = o.getVehicleNumber1() == null ? 1 : o + .getVehicleNumber1(); o.setVehicleNumber1(vehicleNumber1); - vehicleCountNum+=vehicleNumber1; + vehicleCountNum += vehicleNumber1; } - if(o.getExtends2()!=null){ - int vehicleNumber2=o.getVehicleNumber2()==null?1:o.getVehicleNumber2(); + if (o.getExtends2() != null) { + int vehicleNumber2 = o.getVehicleNumber2() == null ? 1 : o + .getVehicleNumber2(); o.setVehicleNumber2(vehicleNumber2); - vehicleCountNum+=vehicleNumber2; + vehicleCountNum += vehicleNumber2; } - if(o.getExtends3()!=null){ - int vehicleNumber3=o.getVehicleNumber3()==null?1:o.getVehicleNumber3(); + if (o.getExtends3() != null) { + int vehicleNumber3 = o.getVehicleNumber3() == null ? 1 : o + .getVehicleNumber3(); o.setVehicleNumber3(vehicleNumber3); - vehicleCountNum+=vehicleNumber3; + vehicleCountNum += vehicleNumber3; } - if(o.getExtends4()!=null){ - int vehicleNumber4=o.getVehicleNumber4()==null?1:o.getVehicleNumber4(); + if (o.getExtends4() != null) { + int vehicleNumber4 = o.getVehicleNumber4() == null ? 1 : o + .getVehicleNumber4(); o.setVehicleNumber4(vehicleNumber4); - vehicleCountNum+=vehicleNumber4; + vehicleCountNum += vehicleNumber4; } o.setVehicleCountNum(vehicleCountNum); this.commonDao.store(o); return vehicleCountNum; - + } + private double contractFee(Long id) { Order o = commonDao.load(Order.class, id); - Date computeDate = o.getOrderDate()==null?new Date():o.getOrderDate(); - List contracts = commonDao.findByQuery("from Contract c where c.balance.id=:id and c.platForm.id=:pid and disabled=0 ", - new String[] { "id","pid" },new Object[] { o.getConsignor().getId(),PlatFormHolder.getPlatForm().getId() }); - double receivefee=0; - Boolean temp=Boolean.FALSE; + Date computeDate = o.getOrderDate() == null ? new Date() : o + .getOrderDate(); + List contracts = commonDao + .findByQuery( + "from Contract c where c.balance.id=:id and c.platForm.id=:pid and disabled=0 ", + new String[] { "id", "pid" }, new Object[] { + o.getConsignor().getId(), + PlatFormHolder.getPlatForm().getId() }); + double receivefee = 0; + Boolean temp = Boolean.FALSE; if (contracts.size() >= 1) { for (Contract c : contracts) { - double totalFee=0; - String remark=checkContract(c,computeDate); - if(o.getUnit().equals(MeasureUnit.VEHICLETYPE)){ - List rates=null; - ContractRate rateFee=null; - String rateId=""; - rates=getContractRate(o, c, MeasureUnit.VEHICLETYPE); - if(rates.size()>1){ - remark+=o.getExtends1().getCode()+"线路多条相同费率;"; + double totalFee = 0; + String remark = checkContract(c, computeDate); + if (o.getUnit().equals(MeasureUnit.VEHICLETYPE)) { + List rates = null; + ContractRate rateFee = null; + String rateId = ""; + rates = getContractRate(o, c, MeasureUnit.VEHICLETYPE); + if (rates.size() > 1) { + remark += o.getExtends1().getCode() + "线路多条相同费率;"; } - for(ContractRate rate :rates){ - rateFee=rate; - if(o.getExtends1()!=null){ - double price=getZCContractRatePrice(rate,o.getExtends1()); - rateId+=rate.getId()+":"+price+";"; - double feeAmount=price*(o.getVehicleNumber1()==null?1:o.getVehicleNumber1()); - totalFee+=feeAmount; + for (ContractRate rate : rates) { + rateFee = rate; + if (o.getExtends1() != null) { + double price = getZCContractRatePrice(rate, + o.getExtends1()); + rateId += rate.getId() + ":" + price + ";"; + double feeAmount = price + * (o.getVehicleNumber1() == null ? 1 : o + .getVehicleNumber1()); + totalFee += feeAmount; } - if(o.getExtends2()!=null){ - double price=getZCContractRatePrice(rate,o.getExtends2()); - rateId+=rate.getId()+":"+price+";"; - double feeAmount=price*(o.getVehicleNumber2()==null?1:o.getVehicleNumber2()); - totalFee+=feeAmount; + if (o.getExtends2() != null) { + double price = getZCContractRatePrice(rate, + o.getExtends2()); + rateId += rate.getId() + ":" + price + ";"; + double feeAmount = price + * (o.getVehicleNumber2() == null ? 1 : o + .getVehicleNumber2()); + totalFee += feeAmount; } } - if(rateFee!=null){ - temp=Boolean.TRUE; - Fee fee=createContractFee(o, rateFee, totalFee,1,totalFee,PriceUnit.TICKET); + if (rateFee != null) { + temp = Boolean.TRUE; + Fee fee = createContractFee(o, rateFee, totalFee, 1, + totalFee, PriceUnit.TICKET); fee.setRateId(rateId); - if(remark!=null&&!remark.equals("")){ - fee.setRemark(c.getCode()+remark); + if (remark != null && !remark.equals("")) { + fee.setRemark(c.getCode() + remark); } - if(o.isBeReturn()){ - fee.setRemark(fee.getRemark()+"(返货)"); + if (o.isBeReturn()) { + fee.setRemark(fee.getRemark() + "(返货)"); } - fee.setRemark(fee.getTotalFee()+fee.getRemark()==null?"":fee.getRemark()); + fee.setRemark(fee.getTotalFee() + fee.getRemark() == null ? "" + : fee.getRemark()); this.commonDao.store(fee); } - receivefee+=totalFee; - }else{ - List rates=getContractRate(o, c); - for(ContractRate rate :rates){ - //查找区间费率 - double quantity=0; + receivefee += totalFee; + } else { + List rates = getContractRate(o, c); + for (ContractRate rate : rates) { + // 查找区间费率 + double quantity = 0; if (MeasureUnit.QUANTITY.equals(o.getUnit())) { - quantity=o.getQuantity(); - }else if (MeasureUnit.WEIGHT.equals(o.getUnit())) { - quantity=o.getWeight(); - }else if (MeasureUnit.TICKET.equals(o.getUnit()) || MeasureUnit.CHARTERED.equals(o.getUnit())) { - quantity=1.0; - }else if (MeasureUnit.TRAIN.equals(o.getUnit()) ) { - quantity=o.getVehicleNumber1()==null?0:o.getVehicleNumber1(); - }else if (MeasureUnit.VOLUME.equals(o.getUnit())) { - quantity=o.getVolume(); + quantity = o.getQuantity(); + } else if (MeasureUnit.WEIGHT.equals(o.getUnit())) { + quantity = o.getWeight(); + } else if (MeasureUnit.TICKET.equals(o.getUnit()) + || MeasureUnit.CHARTERED.equals(o.getUnit())) { + quantity = 1.0; + } else if (MeasureUnit.TRAIN.equals(o.getUnit())) { + quantity = o.getVehicleNumber1() == null ? 0 : o + .getVehicleNumber1(); + } else if (MeasureUnit.VOLUME.equals(o.getUnit())) { + quantity = o.getVolume(); } - Double price=0d; - Map map=getContractRatePrice(rate,quantity); - price=(Double)map.get("price"); -// if(o.isBeReturn()){ -// price=DoubleUtils.format3Fraction(price*rate.getVent()/100); -// } -// if(null==price){ -// price=0d; -// } - totalFee=(Double)map.get("totalFee"); - String priceUnit=(String)map.get("priceUnit"); - temp=Boolean.TRUE; - Fee fee=createContractFee(o, rate, price, quantity,totalFee,priceUnit); - if(remark!=null&&!remark.equals("")){ - fee.setRemark(c.getCode()+remark); + Double price = 0d; + Map map = getContractRatePrice(rate, quantity); + price = (Double) map.get("price"); + // if(o.isBeReturn()){ + // price=DoubleUtils.format3Fraction(price*rate.getVent()/100); + // } + // if(null==price){ + // price=0d; + // } + totalFee = (Double) map.get("totalFee"); + String priceUnit = (String) map.get("priceUnit"); + temp = Boolean.TRUE; + Fee fee = createContractFee(o, rate, price, quantity, + totalFee, priceUnit); + if (remark != null && !remark.equals("")) { + fee.setRemark(c.getCode() + remark); } - if(o.isBeReturn()){ - fee.setRemark(fee.getRemark()+"(返货)"); + if (o.isBeReturn()) { + fee.setRemark(fee.getRemark() + "(返货)"); } - fee.setRemark(fee.getTotalFee()+fee.getRemark()==null?"":fee.getRemark()); + fee.setRemark(fee.getTotalFee() + fee.getRemark() == null ? "" + : fee.getRemark()); this.commonDao.store(fee); - receivefee+=totalFee; + receivefee += totalFee; } } } - //如果没有生成费用,则自动创建一条为0的费用 - if(!temp){ - feeManager.createContractOrderFee(o, contracts.get(0).getCode()+"找不到对应零担合同费率"); - } - }else{ - feeManager.createContractOrderFee(o, "找不到对应的有效合同"); - operationHisManager.storeOperationHis(o.getId(),o.getRelateBill3(), null, o.getRelateBill3(), o.getConsignor().getCode()+"该客户没有签署对应合同", null,null,null,0,0,0,0, o.getRelateBill3(), "TMS"); + // 如果没有生成费用,则自动创建一条为0的费用 + if (!temp) { + feeManager.createContractOrderFee(o, contracts.get(0).getCode() + + "找不到对应零担合同费率"); + } + } else { + feeManager.createContractOrderFee(o, "找不到对应的有效合同"); + operationHisManager.storeOperationHis(o.getId(), + o.getRelateBill3(), null, o.getRelateBill3(), o + .getConsignor().getCode() + "该客户没有签署对应合同", null, + null, null, 0, 0, 0, 0, o.getRelateBill3(), "TMS"); } -// if(MeasureUnit.WEIGHT.equals(o.getUnit())&&!o.isBeReturn()){ -// if(receivefee<3000){ -// feeManager.createFee(o.getId(), BillObjectType.ORDER, getFeeType(SysCodeValue.SH_FYKM),"THF",100); -// } -// } + // if(MeasureUnit.WEIGHT.equals(o.getUnit())&&!o.isBeReturn()){ + // if(receivefee<3000){ + // feeManager.createFee(o.getId(), BillObjectType.ORDER, + // getFeeType(SysCodeValue.SH_FYKM),"THF",100); + // } + // } return receivefee; } - - public void autoComputeFee(List rateIds,Long billId){ - double qty=0; - double weight=0; - double volume=0; - String billCode=""; + + public void autoComputeFee(List rateIds, Long billId) { + double qty = 0; + double weight = 0; + double volume = 0; + String billCode = ""; Order asn = this.commonDao.load(Order.class, billId); - qty=asn.getQuantity(); - weight=asn.getWeight(); - volume=asn.getVolume(); - billCode=asn.getCode(); - for(Long rateId:rateIds){ - ContractRate rate=this.commonDao.get(ContractRate.class, rateId); - double quantity=0; - if(rate.getUnit().equals(MeasureUnit.WEIGHT)){ - quantity=weight; - }else if(rate.getUnit().equals(MeasureUnit.VOLUME)){ - quantity=volume; - }else if(rate.getUnit().equals(MeasureUnit.WEIGHT_VOLUME)){ - quantity=weight > volume ? weight : volume; - }else if(rate.getUnit().equals(MeasureUnit.TICKET)){ - quantity=1; - }else if(rate.getUnit().equals(MeasureUnit.QUANTITY)){ - quantity=qty; + qty = asn.getQuantity(); + weight = asn.getWeight(); + volume = asn.getVolume(); + billCode = asn.getCode(); + for (Long rateId : rateIds) { + ContractRate rate = this.commonDao.get(ContractRate.class, rateId); + double quantity = 0; + if (rate.getUnit().equals(MeasureUnit.WEIGHT)) { + quantity = weight; + } else if (rate.getUnit().equals(MeasureUnit.VOLUME)) { + quantity = volume; + } else if (rate.getUnit().equals(MeasureUnit.WEIGHT_VOLUME)) { + quantity = weight > volume ? weight : volume; + } else if (rate.getUnit().equals(MeasureUnit.TICKET)) { + quantity = 1; + } else if (rate.getUnit().equals(MeasureUnit.QUANTITY)) { + quantity = qty; } - if(quantity getContractRate(Order order,Contract contract,String unit){ - List rates = commonDao.findByQuery("from ContractRate c where c.contract.id=:id and unit=:unit and superviseType=:superviseType and c.routeFee.id=:rfId ", - new String[] { "id","unit","superviseType","rfId" }, - new Object[] { contract.getId(),unit,order.getSuperviseType(),order.getRouteFee().getId()}); - if (rates.size()<=0) { - operationHisManager.storeOperationHis(contract.getId(),contract.getCode(), null, null, order.getRelateBill3()+"没有找到符合条件的整车合同费率", null,null,null,0,0,0,0, order.getCode(), "TMS"); + + // 查找符合条件的整车合同费率 + public List getContractRate(Order order, Contract contract, + String unit) { + List rates = commonDao + .findByQuery( + "from ContractRate c where c.contract.id=:id and unit=:unit and superviseType=:superviseType and c.routeFee.id=:rfId ", + new String[] { "id", "unit", "superviseType", "rfId" }, + new Object[] { contract.getId(), unit, + order.getSuperviseType(), + order.getRouteFee().getId() }); + if (rates.size() <= 0) { + operationHisManager.storeOperationHis(contract.getId(), + contract.getCode(), null, null, order.getRelateBill3() + + "没有找到符合条件的整车合同费率", null, null, null, 0, 0, 0, 0, + order.getCode(), "TMS"); } return rates; } - //查找符合条件的零担合同费率 - public List getContractRate(Order order,Contract contract){ - List rates = commonDao.findByQuery("from ContractRate c where c.contract.id=:id and unit in (:unit1,:unit2) and c.routeFee.id=:rfId and superviseType=:superviseType ", - new String[] { "id","unit1","unit2","rfId","superviseType" }, - new Object[] { contract.getId(),order.getUnit(),order.getUnit()==MeasureUnit.WEIGHT?MeasureUnit.WEIGHT_TON:order.getUnit(),order.getRouteFee().getId(),order.getSuperviseType()}); - if (rates.size()<=0) { - operationHisManager.storeOperationHis(contract.getId(),contract.getCode(), null, null, order.getRelateBill3()+"没有找到符合条件的整车合同费率", null,null,null,0,0,0,0, order.getCode(), "TMS"); + + // 查找符合条件的零担合同费率 + public List getContractRate(Order order, Contract contract) { + List rates = commonDao + .findByQuery( + "from ContractRate c where c.contract.id=:id and unit in (:unit1,:unit2) and c.routeFee.id=:rfId and superviseType=:superviseType ", + new String[] { "id", "unit1", "unit2", "rfId", + "superviseType" }, + new Object[] { + contract.getId(), + order.getUnit(), + order.getUnit() == MeasureUnit.WEIGHT ? MeasureUnit.WEIGHT_TON + : order.getUnit(), + order.getRouteFee().getId(), + order.getSuperviseType() }); + if (rates.size() <= 0) { + operationHisManager.storeOperationHis(contract.getId(), + contract.getCode(), null, null, order.getRelateBill3() + + "没有找到符合条件的整车合同费率", null, null, null, 0, 0, 0, 0, + order.getCode(), "TMS"); } return rates; } - public Double getZCContractRatePrice(ContractRate rate ,VehicleType vt){ - Double price=null; - if(rate.getVehicleType1()!=null&&vt.getId().equals(rate.getVehicleType1().getId())){ - price=rate.getVehiclePrice1()==null?0:rate.getVehiclePrice1(); - }else if(rate.getVehicleType2()!=null&&vt.getId().equals(rate.getVehicleType2().getId())){ - price=rate.getVehiclePrice2()==null?0:rate.getVehiclePrice2(); - }else if(rate.getVehicleType3()!=null&&vt.getId().equals(rate.getVehicleType3().getId())){ - price=rate.getVehiclePrice3()==null?0:rate.getVehiclePrice3(); - }else if(rate.getVehicleType4()!=null&&vt.getId().equals(rate.getVehicleType4().getId())){ - price=rate.getVehiclePrice4()==null?0:rate.getVehiclePrice4(); - }else if(rate.getVehicleType5()!=null&&vt.getId().equals(rate.getVehicleType5().getId())){ - price=rate.getVehiclePrice5()==null?0:rate.getVehiclePrice5(); - }else if(rate.getVehicleType6()!=null&&vt.getId().equals(rate.getVehicleType6().getId())){ - price=rate.getVehiclePrice6()==null?0:rate.getVehiclePrice6(); - }else if(rate.getVehicleType7()!=null&&vt.getId().equals(rate.getVehicleType7().getId())){ - price=rate.getVehiclePrice7()==null?0:rate.getVehiclePrice7(); - }else if(rate.getVehicleType8()!=null&&vt.getId().equals(rate.getVehicleType8().getId())){ - price=rate.getVehiclePrice8()==null?0:rate.getVehiclePrice8(); - }else if(rate.getVehicleType9()!=null&&vt.getId().equals(rate.getVehicleType9().getId())){ - price=rate.getVehiclePrice9()==null?0:rate.getVehiclePrice9(); - }else if(rate.getVehicleType10()!=null&&vt.getId().equals(rate.getVehicleType10().getId())){ - price=rate.getVehiclePrice10()==null?0:rate.getVehiclePrice10(); + + public Double getZCContractRatePrice(ContractRate rate, VehicleType vt) { + Double price = null; + if (rate.getVehicleType1() != null + && vt.getId().equals(rate.getVehicleType1().getId())) { + price = rate.getVehiclePrice1() == null ? 0 : rate + .getVehiclePrice1(); + } else if (rate.getVehicleType2() != null + && vt.getId().equals(rate.getVehicleType2().getId())) { + price = rate.getVehiclePrice2() == null ? 0 : rate + .getVehiclePrice2(); + } else if (rate.getVehicleType3() != null + && vt.getId().equals(rate.getVehicleType3().getId())) { + price = rate.getVehiclePrice3() == null ? 0 : rate + .getVehiclePrice3(); + } else if (rate.getVehicleType4() != null + && vt.getId().equals(rate.getVehicleType4().getId())) { + price = rate.getVehiclePrice4() == null ? 0 : rate + .getVehiclePrice4(); + } else if (rate.getVehicleType5() != null + && vt.getId().equals(rate.getVehicleType5().getId())) { + price = rate.getVehiclePrice5() == null ? 0 : rate + .getVehiclePrice5(); + } else if (rate.getVehicleType6() != null + && vt.getId().equals(rate.getVehicleType6().getId())) { + price = rate.getVehiclePrice6() == null ? 0 : rate + .getVehiclePrice6(); + } else if (rate.getVehicleType7() != null + && vt.getId().equals(rate.getVehicleType7().getId())) { + price = rate.getVehiclePrice7() == null ? 0 : rate + .getVehiclePrice7(); + } else if (rate.getVehicleType8() != null + && vt.getId().equals(rate.getVehicleType8().getId())) { + price = rate.getVehiclePrice8() == null ? 0 : rate + .getVehiclePrice8(); + } else if (rate.getVehicleType9() != null + && vt.getId().equals(rate.getVehicleType9().getId())) { + price = rate.getVehiclePrice9() == null ? 0 : rate + .getVehiclePrice9(); + } else if (rate.getVehicleType10() != null + && vt.getId().equals(rate.getVehicleType10().getId())) { + price = rate.getVehiclePrice10() == null ? 0 : rate + .getVehiclePrice10(); } return price; } - public Map getContractRatePrice(ContractRate rate ,double quantity){ - Map map=new HashMap(); - if(rate.getUnit().equals(MeasureUnit.WEIGHT_TON)){ - quantity=quantity/1000; + + public Map getContractRatePrice(ContractRate rate, double quantity) { + Map map = new HashMap(); + if (rate.getUnit().equals(MeasureUnit.WEIGHT_TON)) { + quantity = quantity / 1000; } - Double fromRange1=rate.getFromRange1()==null?0:rate.getFromRange1(); - Double toRange1=rate.getToRange1()==null?99999:rate.getToRange1(); - Double fromRange2=rate.getFromRange2(); - Double toRange2=rate.getToRange2()==null?99999:rate.getToRange2(); - Double fromRange3=rate.getFromRange3(); - Double toRange3=rate.getToRange3()==null?99999:rate.getToRange3(); - Double fromRange4=rate.getFromRange4(); - Double toRange4=rate.getToRange4()==null?99999:rate.getToRange4(); - Double fromRange5=rate.getFromRange5(); - Double toRange5=rate.getToRange5()==null?99999:rate.getToRange5(); - Double fromRange6=rate.getFromRange6(); - Double toRange6=rate.getToRange6()==null?99999:rate.getToRange6(); - Double fromRange7=rate.getFromRange7(); - Double toRange7=rate.getToRange7()==null?99999:rate.getToRange7(); - Double fromRange8=rate.getFromRange8(); - Double toRange8=rate.getToRange8()==null?99999:rate.getToRange8(); - Double fromRange9=rate.getFromRange9(); - Double toRange9=rate.getToRange9()==null?99999:rate.getToRange9(); - Double fromRange10=rate.getFromRange10(); - Double toRange10=rate.getToRange10()==null?99999:rate.getToRange10(); - Double price=null; - String unit=null; - Double totalFee=0.0; - double fromRange=0; - double minPrice=rate.getMinPrice()==null?0:rate.getMinPrice(); + Double fromRange1 = rate.getFromRange1() == null ? 0 : rate + .getFromRange1(); + Double toRange1 = rate.getToRange1() == null ? 99999 : rate + .getToRange1(); + Double fromRange2 = rate.getFromRange2(); + Double toRange2 = rate.getToRange2() == null ? 99999 : rate + .getToRange2(); + Double fromRange3 = rate.getFromRange3(); + Double toRange3 = rate.getToRange3() == null ? 99999 : rate + .getToRange3(); + Double fromRange4 = rate.getFromRange4(); + Double toRange4 = rate.getToRange4() == null ? 99999 : rate + .getToRange4(); + Double fromRange5 = rate.getFromRange5(); + Double toRange5 = rate.getToRange5() == null ? 99999 : rate + .getToRange5(); + Double fromRange6 = rate.getFromRange6(); + Double toRange6 = rate.getToRange6() == null ? 99999 : rate + .getToRange6(); + Double fromRange7 = rate.getFromRange7(); + Double toRange7 = rate.getToRange7() == null ? 99999 : rate + .getToRange7(); + Double fromRange8 = rate.getFromRange8(); + Double toRange8 = rate.getToRange8() == null ? 99999 : rate + .getToRange8(); + Double fromRange9 = rate.getFromRange9(); + Double toRange9 = rate.getToRange9() == null ? 99999 : rate + .getToRange9(); + Double fromRange10 = rate.getFromRange10(); + Double toRange10 = rate.getToRange10() == null ? 99999 : rate + .getToRange10(); + Double price = null; + String unit = null; + Double totalFee = 0.0; + double fromRange = 0; + double minPrice = rate.getMinPrice() == null ? 0 : rate.getMinPrice(); if (fromRange1 == 0.0) { - unit=rate.getPriceUnit1(); - price=rate.getVehiclePrice(); - fromRange=fromRange1; + unit = rate.getPriceUnit1(); + price = rate.getVehiclePrice(); + fromRange = fromRange1; } - if (fromRange1 minPrice){ - minPrice=rate.getVehiclePrice(); + } else if (unit.equals(PriceUnit.EXCEED_PRICE)) { + quantity = quantity - fromRange; + if (rate.getVehiclePrice() > minPrice) { + minPrice = rate.getVehiclePrice(); } - totalFee=price*quantity+minPrice; - quantity=1; - price=totalFee; + totalFee = price * quantity + minPrice; + quantity = 1; + price = totalFee; } - }else{ - totalFee=price*quantity; - if(totalFee params=this.commonDao.findByQuery("from GlobalParam g where g.paramId=:paramId",new String[]{"paramId"},new Object[]{"reportPrintURL"}); - if(params.size()>0){ - GlobalParam param=params.get(0); + List params = this.commonDao.findByQuery( + "from GlobalParam g where g.paramId=:paramId", + new String[] { "paramId" }, new Object[] { "reportPrintURL" }); + if (params.size() > 0) { + GlobalParam param = params.get(0); return param.getValue(); } return null; - + } + /** * 成本费用审核 + * * @param ids */ - public void costStatusCheck(List ids){ - for(Long id : ids){ - Order order =commonDao.load(Order.class, id); - String sql="from Legs l where l.order.id="+order.getId(); - List legs=commonDao.findByQuery(sql); - if(legs.size()>0){ - for(Legs l: legs){ - l.setCostStatus(FeeStatus.CHECK); - commonDao.store(l); - } + public void costStatusCheck(List ids) { + for (Long id : ids) { + Order order = commonDao.load(Order.class, id); + String sql = "from Legs l where l.order.id=" + order.getId(); + List legs = commonDao.findByQuery(sql); + if (legs.size() > 0) { + for (Legs l : legs) { + l.setCostStatus(FeeStatus.CHECK); + commonDao.store(l); + } } order.setCostStatus(FeeStatus.CHECK); commonDao.store(order); } } + /** * 其他费用审核 + * * @param ids */ - public void otherStatusCheck(List ids){ - for(Long id : ids){ - Order order =commonDao.load(Order.class, id); - String sql="from Legs l where l.order.id="+order.getId(); - String sql1="From Fee f where f.billObject='ORDER' and f.billId="+id; - List f1=commonDao.findByQuery(sql1); - for(Fee f : f1){ + public void otherStatusCheck(List ids) { + for (Long id : ids) { + Order order = commonDao.load(Order.class, id); + String sql = "from Legs l where l.order.id=" + order.getId(); + String sql1 = "From Fee f where f.billObject='ORDER' and f.billId=" + + id; + List f1 = commonDao.findByQuery(sql1); + for (Fee f : f1) { f.setCheckFee(FeeStatus.CHECK); commonDao.store(f); } - List legs=commonDao.findByQuery(sql); - if(legs.size()>0){ - for(Legs l: legs){ - l.setOtherStatus(FeeStatus.CHECK); - commonDao.store(l); - - String sql2="From Fee f where f.billObject='LEGS' and f.billId="+l.getId(); - List f2=commonDao.findByQuery(sql2); - for(Fee f : f2){ + List legs = commonDao.findByQuery(sql); + if (legs.size() > 0) { + for (Legs l : legs) { + l.setOtherStatus(FeeStatus.CHECK); + commonDao.store(l); + + String sql2 = "From Fee f where f.billObject='LEGS' and f.billId=" + + l.getId(); + List f2 = commonDao.findByQuery(sql2); + for (Fee f : f2) { f.setCheckFee(FeeStatus.CHECK); commonDao.store(f); } - } + } } order.setOtherStatus(FeeStatus.CHECK); commonDao.store(order); - } + } } - - public void cancelOrderFeeCheck(List ids){ - for(Long id:ids){ - Order order =commonDao.load(Order.class, id); - List fees=commonDao.findByQuery("from Fee fee where fee.billObject='ORDER' and fee.billId=:id",new String []{"id"},new Object[]{id}); - for(Fee fee:fees){ + + public void cancelOrderFeeCheck(List ids) { + for (Long id : ids) { + Order order = commonDao.load(Order.class, id); + List fees = commonDao + .findByQuery( + "from Fee fee where fee.billObject='ORDER' and fee.billId=:id", + new String[] { "id" }, new Object[] { id }); + for (Fee fee : fees) { fee.setStatus(FeeStatus.OPEN); fee.setOperator("system"); fee.setOperatorDate(fee.getFeeDate()); @@ -4463,253 +4992,327 @@ public class DefaultOrderManager extends DefaultBaseManager implements this.commonDao.store(order); } } - - public void feeCheck(List ids){ - for(Long id:ids){ - Fee fee =commonDao.load(Fee.class, id); - fee.setStatus(FeeStatus.CHECK); - fee.setOperator(UserHolder.getUser().getName()); - fee.setOperatorDate(new Date()); - this.store(fee); + + public void feeCheck(List ids) { + for (Long id : ids) { + Fee fee = commonDao.load(Fee.class, id); + fee.setStatus(FeeStatus.CHECK); + fee.setOperator(UserHolder.getUser().getName()); + fee.setOperatorDate(new Date()); + this.store(fee); } } - - public void cancelFeeCheck(List ids){ - for(Long id:ids){ - Fee fee =commonDao.load(Fee.class, id); - fee.setStatus(FeeStatus.OPEN); - fee.setOperator("system"); - fee.setOperatorDate(fee.getFeeDate()); - this.store(fee); + + public void cancelFeeCheck(List ids) { + for (Long id : ids) { + Fee fee = commonDao.load(Fee.class, id); + fee.setStatus(FeeStatus.OPEN); + fee.setOperator("system"); + fee.setOperatorDate(fee.getFeeDate()); + this.store(fee); } } - public void modifyOrderTurnover(Long orderID,Map map){ + + public void modifyOrderTurnover(Long orderID, Map map) { Set> itor = map.entrySet(); - Order order=this.commonDao.get(Order.class, orderID); + Order order = this.commonDao.get(Order.class, orderID); for (Map.Entry me : itor) { - Legs legs=commonDao.load(Legs.class, me.getKey()); - double oldTurnover=legs.getTurnover(); - Double turnover = Double.parseDouble(me.getValue().get(0).toString()); + Legs legs = commonDao.load(Legs.class, me.getKey()); + double oldTurnover = legs.getTurnover(); + Double turnover = Double.parseDouble(me.getValue().get(0) + .toString()); legs.setTurnover(turnover); - legs.setProfit(legs.getTurnover()-legs.getPayfee()-legs.getOtherFee()); + legs.setProfit(legs.getTurnover() - legs.getPayfee() + - legs.getOtherFee()); this.commonDao.store(legs); - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "回单管理-调整营业额", "调整营业额",OperationHisUtil.operationHisStatus(FeeStatus.OPEN), - OperationHisUtil.operationHisStatus(FeeStatus.CHECK),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription()+"营业额"+oldTurnover+"变为"+turnover, "TMS"); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "回单管理-调整营业额", "调整营业额", + OperationHisUtil.operationHisStatus(FeeStatus.OPEN), + OperationHisUtil.operationHisStatus(FeeStatus.CHECK), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, order.getDescription() + "营业额" + oldTurnover + "变为" + + turnover, "TMS"); } - double turnover1=(Double)commonDao.findByQuery("select nvl(sum(turnover),0) from Legs l where l.order.id=:orderId", - new String[]{"orderId"},new Object[]{orderID}).get(0); - if(-0.5>(turnover1-order.getReceivefee())||(turnover1-order.getReceivefee())>0.5){ - throw new BusinessException(order.getRelateBill3()+"对应营业额均摊金额不等于订单营业额,请重新确认"); - } - } - public void orderFeeCheck(List ids){ - for(Long id:ids){ - Order order =commonDao.load(Order.class, id); -// if(order.getStatus().equals(OrderStatus.SIGNED)){ -// List fees=commonDao.findByQuery("from Fee fee where fee.billObject='ORDER' and fee.billId=:id and fee.type is null ",new String []{"id"},new Object[]{id}); -// double turnover=(Double)commonDao.findByQuery("select nvl(sum(turnover),0) from Legs l where l.order.id=:orderId", -// new String[]{"orderId"},new Object[]{id}).get(0); -// if(-0.5>(turnover-order.getReceivefee())||(turnover-order.getReceivefee())>0.5){ -// throw new BusinessException(order.getRelateBill3()+"对应营业额均摊金额不等于订单营业额,请重新确认"); -// } -// for(Fee fee:fees){ -// fee.setStatus(FeeStatus.CHECK); -//// if((fee.getFeeName().getName().equals("压车费") && order.isGuard()) || -//// (fee.getFeeName().getName().equals("待时费") && order.isWaitTime()) || -//// (fee.getFeeName().getName().equals("其他费") && order.isOther()) || -//// (fee.getFeeName().getName().equals("查检费") && order.isCheck()) -//// && fee.getTotalFee()<=0){ -//// throw new BusinessException("有特殊费用需提交该费用"); -//// } -// this.commonDao.store(fee); -// } - order.setCostStatus(FeeStatus.CHECK); - this.commonDao.store(order); - //当订单所属调度单所有营业额审核状态为已审核时,调度单对应的营业额审核状态为已审核 -// for(Legs leg:order.getOrderLegs()){ -// Shipment s=leg.getShipment(); -// if(s!=null){ -// List ls=this.commonDao.findByQuery("from Legs l where l.shipment.id=:shipmentId and l.order.costStatus!='CHECK'", -// new String[]{"shipmentId"},new Object[]{s.getId()}); -// if(ls.size()==0){ -// s.setTurnoverStatus(FeeStatus.CHECK); -// this.commonDao.store(s); -// } -// -// } -// } - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "回单管理-费用审核", "费用审核",OperationHisUtil.operationHisStatus(FeeStatus.OPEN), - OperationHisUtil.operationHisStatus(FeeStatus.CHECK),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription()+"营业额"+order.getReceivefee(), "TMS"); -// }else{ -// throw new BusinessException(order.getRelateBill3()+"该单据未回单,不能费用审核"); -// } + double turnover1 = (Double) commonDao + .findByQuery( + "select nvl(sum(turnover),0) from Legs l where l.order.id=:orderId", + new String[] { "orderId" }, new Object[] { orderID }) + .get(0); + if (-0.5 > (turnover1 - order.getReceivefee()) + || (turnover1 - order.getReceivefee()) > 0.5) { + throw new BusinessException(order.getRelateBill3() + + "对应营业额均摊金额不等于订单营业额,请重新确认"); } } - - public void orderFeeCancelCheck(List ids){ - for(Long id:ids){ - Order order =commonDao.load(Order.class, id); -// List fees=commonDao.findByQuery("from Fee fee where fee.billObject='ORDER' and fee.billId=:id and fee.type is null ",new String []{"id"},new Object[]{id}); -// for(Fee fee:fees){ -// if(fee.getBillFee()!=null){ -// throw new BusinessException(order.getRelateBill3()+"费用已对帐,不能取消审核"); -// } -// } - if(order.getOtherStatus().equals(FeeStatus.CHECK)){ - throw new BusinessException(order.getRelateBill3()+"成本营业额已审核,请先退回"); + + public void orderFeeCheck(List ids) { + for (Long id : ids) { + Order order = commonDao.load(Order.class, id); + // if(order.getStatus().equals(OrderStatus.SIGNED)){ + // List + // fees=commonDao.findByQuery("from Fee fee where fee.billObject='ORDER' and fee.billId=:id and fee.type is null ",new + // String []{"id"},new Object[]{id}); + // double + // turnover=(Double)commonDao.findByQuery("select nvl(sum(turnover),0) from Legs l where l.order.id=:orderId", + // new String[]{"orderId"},new Object[]{id}).get(0); + // if(-0.5>(turnover-order.getReceivefee())||(turnover-order.getReceivefee())>0.5){ + // throw new + // BusinessException(order.getRelateBill3()+"对应营业额均摊金额不等于订单营业额,请重新确认"); + // } + // for(Fee fee:fees){ + // fee.setStatus(FeeStatus.CHECK); + // // if((fee.getFeeName().getName().equals("压车费") && + // order.isGuard()) || + // // (fee.getFeeName().getName().equals("待时费") && + // order.isWaitTime()) || + // // (fee.getFeeName().getName().equals("其他费") && order.isOther()) + // || + // // (fee.getFeeName().getName().equals("查检费") && order.isCheck()) + // // && fee.getTotalFee()<=0){ + // // throw new BusinessException("有特殊费用需提交该费用"); + // // } + // this.commonDao.store(fee); + // } + order.setCostStatus(FeeStatus.CHECK); + this.commonDao.store(order); + // 当订单所属调度单所有营业额审核状态为已审核时,调度单对应的营业额审核状态为已审核 + // for(Legs leg:order.getOrderLegs()){ + // Shipment s=leg.getShipment(); + // if(s!=null){ + // List + // ls=this.commonDao.findByQuery("from Legs l where l.shipment.id=:shipmentId and l.order.costStatus!='CHECK'", + // new String[]{"shipmentId"},new Object[]{s.getId()}); + // if(ls.size()==0){ + // s.setTurnoverStatus(FeeStatus.CHECK); + // this.commonDao.store(s); + // } + // + // } + // } + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "回单管理-费用审核", "费用审核", + OperationHisUtil.operationHisStatus(FeeStatus.OPEN), + OperationHisUtil.operationHisStatus(FeeStatus.CHECK), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, order.getDescription() + "营业额" + order.getReceivefee(), + "TMS"); + // }else{ + // throw new + // BusinessException(order.getRelateBill3()+"该单据未回单,不能费用审核"); + // } + } + } + + public void orderFeeCancelCheck(List ids) { + for (Long id : ids) { + Order order = commonDao.load(Order.class, id); + // List + // fees=commonDao.findByQuery("from Fee fee where fee.billObject='ORDER' and fee.billId=:id and fee.type is null ",new + // String []{"id"},new Object[]{id}); + // for(Fee fee:fees){ + // if(fee.getBillFee()!=null){ + // throw new + // BusinessException(order.getRelateBill3()+"费用已对帐,不能取消审核"); + // } + // } + if (order.getOtherStatus().equals(FeeStatus.CHECK)) { + throw new BusinessException(order.getRelateBill3() + + "成本营业额已审核,请先退回"); } order.setCostStatus(FeeStatus.OPEN); this.commonDao.store(order); -// for(Legs leg:order.getOrderLegs()){ -// Shipment s=leg.getShipment(); -// if(s!=null){ -// s.setTurnoverStatus(FeeStatus.OPEN); -// this.commonDao.store(s); -// -// } -// } - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "回单管理-费用取消审核", "费用取消审核",OperationHisUtil.operationHisStatus(FeeStatus.OPEN), - OperationHisUtil.operationHisStatus(FeeStatus.CHECK),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription()+"营业额"+order.getReceivefee(), "TMS"); + // for(Legs leg:order.getOrderLegs()){ + // Shipment s=leg.getShipment(); + // if(s!=null){ + // s.setTurnoverStatus(FeeStatus.OPEN); + // this.commonDao.store(s); + // + // } + // } + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "回单管理-费用取消审核", + "费用取消审核", + OperationHisUtil.operationHisStatus(FeeStatus.OPEN), + OperationHisUtil.operationHisStatus(FeeStatus.CHECK), + order.getQuantity(), order.getWeight(), order.getVolume(), + 0, order.getDescription() + "营业额" + order.getReceivefee(), + "TMS"); } } - public void orderFeeSubmit(Long orderID,String remark){ - Order order =commonDao.load(Order.class,orderID); + + public void orderFeeSubmit(Long orderID, String remark) { + Order order = commonDao.load(Order.class, orderID); order.setRemark(remark); - String hql=" from Fee f where f.billId=" +orderID+" and f.billObject='ORDER'"; - List fees=commonDao.findByQuery(hql); - for(Fee fee: fees){ - //List FeeTypes=commonDao.findByQuery("from FeeType feeType where feeType.id=:id",new String []{"id"},new Object[]{fee.getFeeName().getId()}); - if((fee.getFeeName().getName().equals("压车费") && order.isGuard()) || - (fee.getFeeName().getName().equals("待时费") && order.isWaitTime()) || - (fee.getFeeName().getName().equals("其他费") && order.isOther()) || - (fee.getFeeName().getName().equals("查检费") && order.isCheck()) - && fee.getTotalFee()>0){ - throw new BusinessException("不用提交该费用"); - } + String hql = " from Fee f where f.billId=" + orderID + + " and f.billObject='ORDER'"; + List fees = commonDao.findByQuery(hql); + for (Fee fee : fees) { + // List + // FeeTypes=commonDao.findByQuery("from FeeType feeType where feeType.id=:id",new + // String []{"id"},new Object[]{fee.getFeeName().getId()}); + if ((fee.getFeeName().getName().equals("压车费") && order.isGuard()) + || (fee.getFeeName().getName().equals("待时费") && order + .isWaitTime()) + || (fee.getFeeName().getName().equals("其他费") && order + .isOther()) + || (fee.getFeeName().getName().equals("查检费") && order + .isCheck()) && fee.getTotalFee() > 0) { + throw new BusinessException("不用提交该费用"); } + } commonDao.store(order); - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "回单管理-提交", "提交",OperationHisUtil.operationHisStatus(FeeStatus.OPEN), - OperationHisUtil.operationHisStatus(FeeStatus.SUBMIT),order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription()+"营业额"+order.getReceivefee(), "TMS"); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "回单管理-提交", "提交", + OperationHisUtil.operationHisStatus(FeeStatus.OPEN), + OperationHisUtil.operationHisStatus(FeeStatus.SUBMIT), + order.getQuantity(), order.getWeight(), order.getVolume(), 0, + order.getDescription() + "营业额" + order.getReceivefee(), "TMS"); } - public void feeTime(List orderID,Date feeTime){ - for(Long id:orderID){ - Order order =commonDao.load(Order.class,id); + + public void feeTime(List orderID, Date feeTime) { + for (Long id : orderID) { + Order order = commonDao.load(Order.class, id); order.setNodeFeeDate(feeTime); commonDao.store(order); - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "回单管理-设置费用时间", "设置费用时间","", - "",order.getQuantity(), order.getWeight(), - order.getVolume(), 0, order.getDescription()+"营业额"+order.getReceivefee(), "TMS"); + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "回单管理-设置费用时间", + "设置费用时间", "", "", order.getQuantity(), order.getWeight(), + order.getVolume(), 0, order.getDescription() + "营业额" + + order.getReceivefee(), "TMS"); } } - - - public OperationHis storeOperationHis(Long sourceId, String sourceNo, Long detailId, String detailNo, String sourceType, String actionName, String fromStatus, String toStatus, double quantity, double weight, double netWeight, double volume, String remark, String extendStr1,Long warehouseId,Long userId) { - OperationHis his = (OperationHis)EntityFactory.getEntity(OperationHis.class); - his.setSourceId(sourceId); - his.setSourceNo(sourceNo); - his.setDetailId(detailId); - his.setDetailNo(detailNo); - his.setSourceType(sourceType); - his.setActionName(actionName); - his.setFromStatus(fromStatus); - his.setToStatus(toStatus); - his.setQuantity(quantity); - his.setWeight(weight); - his.setExtendN1(netWeight); - his.setExtendStr1(extendStr1); - his.setVolume(volume); - his.setRemark(remark); - his.setWarehouseId(warehouseId); - his.setExtendStr1(extendStr1); - User user = commonDao.get(User.class, userId); - his.setSourceId(sourceId); - if(user!=null){ - his.setUserID(user.getId()); - his.setUserName(user.getLoginName()); - } - his.setUpdateTime(new Date()); - this.commonDao.store(his); - return his; - } - - @Override - @Transactional - public void commitPaperSignOrder(List ids, Date paperSignDate ) { - // TODO Auto-generated method stub - for(Long id : ids){ - Order order = this.get(Order.class, id); - order.setPaperSignDate(paperSignDate); - order.setWhetherSign(true); - commonDao.store(order); - } - + + public OperationHis storeOperationHis(Long sourceId, String sourceNo, + Long detailId, String detailNo, String sourceType, + String actionName, String fromStatus, String toStatus, + double quantity, double weight, double netWeight, double volume, + String remark, String extendStr1, Long warehouseId, Long userId) { + OperationHis his = (OperationHis) EntityFactory + .getEntity(OperationHis.class); + his.setSourceId(sourceId); + his.setSourceNo(sourceNo); + his.setDetailId(detailId); + his.setDetailNo(detailNo); + his.setSourceType(sourceType); + his.setActionName(actionName); + his.setFromStatus(fromStatus); + his.setToStatus(toStatus); + his.setQuantity(quantity); + his.setWeight(weight); + his.setExtendN1(netWeight); + his.setExtendStr1(extendStr1); + his.setVolume(volume); + his.setRemark(remark); + his.setWarehouseId(warehouseId); + his.setExtendStr1(extendStr1); + User user = commonDao.get(User.class, userId); + his.setSourceId(sourceId); + if (user != null) { + his.setUserID(user.getId()); + his.setUserName(user.getLoginName()); + } + his.setUpdateTime(new Date()); + this.commonDao.store(his); + return his; } + @Override @Transactional - public - void modifyAvgTrimCost(Long shipmentID, Map map) { + public void commitPaperSignOrder(List ids, Date paperSignDate) { + // TODO Auto-generated method stub + for (Long id : ids) { + Order order = this.get(Order.class, id); + order.setPaperSignDate(paperSignDate); + order.setWhetherSign(true); + commonDao.store(order); + } + + } + + @Override + @Transactional + public void modifyAvgTrimCost(Long shipmentID, Map map) { // TODO Auto-generated method stub Set> itor = map.entrySet(); - Shipment shipment=commonDao.load(Shipment.class, shipmentID); - double sum=0; + Shipment shipment = commonDao.load(Shipment.class, shipmentID); + double sum = 0; for (Map.Entry me : itor) { - Legs legs=commonDao.load(Legs.class, me.getKey()); - double oldPayfee=legs.getPayfee(); - Double payfee=Double.parseDouble(me.getValue().get(1).toString()); + Legs legs = commonDao.load(Legs.class, me.getKey()); + double oldPayfee = legs.getPayfee(); + Double payfee = Double.parseDouble(me.getValue().get(1).toString()); legs.setPayfee(payfee); - sum=sum+payfee; - legs.setProfit(legs.getTurnover()-legs.getPayfee()-legs.getOtherFee()); + sum = sum + payfee; + legs.setProfit(legs.getTurnover() - legs.getPayfee() + - legs.getOtherFee()); this.commonDao.store(legs); - operationHisManager.storeOperationHis(legs.getId(),legs.getEcNo(), null, null, "应付费用提交-调整成本", "调整成本",OperationHisUtil.operationHisStatus(FeeStatus.OPEN), - OperationHisUtil.operationHisStatus(FeeStatus.CHECK),legs.getQuantity(), legs.getWeight(), - legs.getVolume(), 0, legs.getDescription()+"成本"+oldPayfee+"变为"+payfee, "TMS"); + operationHisManager.storeOperationHis(legs.getId(), legs.getEcNo(), + null, null, "应付费用提交-调整成本", "调整成本", + OperationHisUtil.operationHisStatus(FeeStatus.OPEN), + OperationHisUtil.operationHisStatus(FeeStatus.CHECK), + legs.getQuantity(), legs.getWeight(), legs.getVolume(), 0, + legs.getDescription() + "成本" + oldPayfee + "变为" + payfee, + "TMS"); } - double pay=shipment.getPayfee(); - pay=Math.floor(pay*10); - sum=Math.floor(sum*10); - if(pay!=sum){ + double pay = shipment.getPayfee(); + pay = Math.floor(pay * 10); + sum = Math.floor(sum * 10); + if (pay != sum) { throw new BusinessException("调整后金额不等于总金额,请重新调整!"); } } - + private double contractCZFee(Long id) { - List fns=this.commonDao.findByQuery("from FeeType ft where ft.name=:name and ft.platForm.id=:platFormId", - new String[]{"name","platFormId"},new Object[]{"场站费",PlatFormHolder.getPlatForm().getId()}); - FeeType ft=null; - if(fns.size()>0){ + List fns = this.commonDao + .findByQuery( + "from FeeType ft where ft.name=:name and ft.platForm.id=:platFormId", + new String[] { "name", "platFormId" }, new Object[] { + "场站费", PlatFormHolder.getPlatForm().getId() }); + FeeType ft = null; + if (fns.size() > 0) { Order o = commonDao.load(Order.class, id); - List contracts = commonDao.findByQuery("from Contract c where c.balance.id=:id and c.platForm.id=:pid and disabled=0", - new String[] { "id","pid" },new Object[] { o.getConsignor().getId(),PlatFormHolder.getPlatForm().getId() }); - double receivefee=0; - Boolean temp=Boolean.FALSE; - ft=fns.get(0); + List contracts = commonDao + .findByQuery( + "from Contract c where c.balance.id=:id and c.platForm.id=:pid and disabled=0", + new String[] { "id", "pid" }, new Object[] { + o.getConsignor().getId(), + PlatFormHolder.getPlatForm().getId() }); + double receivefee = 0; + Boolean temp = Boolean.FALSE; + ft = fns.get(0); if (contracts.size() >= 1) { for (Contract c : contracts) { - List prices = commonDao.findByQuery("from ContractPrice c where c.contract.id=:id and c.routeFee.id=:rfId", - new String[] { "id","rfId" },new Object[] { c.getId(),o.getRouteFee().getId()}); - for(ContractPrice p:prices){ - if(p.getDepotNumber()>0){ - List depotNumbers=commonDao.findByQuery("select b.freightStstion from BranchOrder b where b.order.id=:orderId and b.freightStstion is not null group by b.freightStstion ", - new String[]{"orderId"},new Object[]{o.getId()}); - if(depotNumbers.size()-p.getDepotNumber()!=0){ + List prices = commonDao + .findByQuery( + "from ContractPrice c where c.contract.id=:id and c.routeFee.id=:rfId", + new String[] { "id", "rfId" }, + new Object[] { c.getId(), + o.getRouteFee().getId() }); + for (ContractPrice p : prices) { + if (p.getDepotNumber() > 0) { + List depotNumbers = commonDao + .findByQuery( + "select b.freightStstion from BranchOrder b where b.order.id=:orderId and b.freightStstion is not null group by b.freightStstion ", + new String[] { "orderId" }, + new Object[] { o.getId() }); + if (depotNumbers.size() - p.getDepotNumber() != 0) { continue; } - }else{ - if(p.getTransferPoint()!=null&&!p.getTransferPoint().equals("")){ - if(!p.getTransferPoint().equals(o.getTransforPoint())){ + } else { + if (p.getTransferPoint() != null + && !p.getTransferPoint().equals("")) { + if (!p.getTransferPoint().equals( + o.getTransforPoint())) { continue; } } } - if(p.getCash()>0){ - createContractPriceFee(o,p,p.getCash(),ft,ReimbursemengtMode.CASH); + if (p.getCash() > 0) { + createContractPriceFee(o, p, p.getCash(), ft, + ReimbursemengtMode.CASH); } - if(p.getCheque()>0){ - createContractPriceFee(o,p,p.getCheque(),ft,ReimbursemengtMode.CHECK); + if (p.getCheque() > 0) { + createContractPriceFee(o, p, p.getCheque(), ft, + ReimbursemengtMode.CHECK); } } } @@ -4717,8 +5320,9 @@ public class DefaultOrderManager extends DefaultBaseManager implements } return 0; } - - public Fee createContractPriceFee(Order o,ContractPrice rate,double price,FeeType ft,String reimbursemengtMode){ + + public Fee createContractPriceFee(Order o, ContractPrice rate, + double price, FeeType ft, String reimbursemengtMode) { Fee fee = (Fee) EntityFactory.getEntity(Fee.class); fee.setBillCode(o.getRelateBill3()); fee.setBillId(o.getId()); @@ -4729,17 +5333,17 @@ public class DefaultOrderManager extends DefaultBaseManager implements fee.setQuantity(1); fee.setUnit(MeasureUnit.TICKET); fee.setPrice(price); - fee.setTotalFee(DoubleUtils.format4Fraction( price)); + fee.setTotalFee(DoubleUtils.format4Fraction(price)); fee.setStatus(FeeStatus.CHECK); fee.setTax(ft.getTaxRate()); - fee.setNoTaxFee(fee.getTotalFee()/(1+fee.getTax()/100)); - fee.setTaxFee(fee.getNoTaxFee()*fee.getTax()/100); + fee.setNoTaxFee(fee.getTotalFee() / (1 + fee.getTax() / 100)); + fee.setTaxFee(fee.getNoTaxFee() * fee.getTax() / 100); fee.setFeeDate(new Date()); fee.setOperator("system"); fee.setOperatorDate(new Date()); fee.setPayOrReceive(FeePayReceive.RECEIVE); fee.setPlatForm(o.getContractor()); - fee.setRateId(rate.getId()+":"+price); + fee.setRateId(rate.getId() + ":" + price); fee.setBeShare(Boolean.FALSE); fee.setType("IN"); fee.setOrderId(o.getId()); @@ -4747,225 +5351,242 @@ public class DefaultOrderManager extends DefaultBaseManager implements commonDao.store(fee); return fee; } - + public void storeShipmentOrder(ShipmentOrder shimpmentOrder) { - if(shimpmentOrder.isNew()){ - Department department=getDepartment("JH"); - if(department==null){ + if (shimpmentOrder.isNew()) { + Department department = getDepartment("JH"); + if (department == null) { throw new BusinessException("请维护代码为JH的集卡车队总控部门"); } shimpmentOrder.setDepartment(department); - shimpmentOrder.setShipmentCode(codeManager.generateDpCode(department.getCode(),4)); + shimpmentOrder.setShipmentCode(codeManager.generateDpCode( + department.getCode(), 4)); shimpmentOrder.setOperatorName(UserHolder.getUser().getName()); shimpmentOrder.setOperatorDate(new Date()); shimpmentOrder.setOrganizationName(PlatFormHolder.getPlatForm()); } this.commonDao.store(shimpmentOrder); } - - public Department getDepartment(String code){ - List departments=this.commonDao.findByQuery(" from Department d where d.code=:code", new String[]{"code"},new Object[]{code}); - if(departments.size()>0){ + + public Department getDepartment(String code) { + List departments = this.commonDao.findByQuery( + " from Department d where d.code=:code", + new String[] { "code" }, new Object[] { code }); + if (departments.size() > 0) { return departments.get(0); - }else{ + } else { return null; } } - - public void storeForeignTradeHis(ForeignTradeHis foreignTradeHis){ + + public void storeForeignTradeHis(ForeignTradeHis foreignTradeHis) { foreignTradeHis.setOperatorName(UserHolder.getUser().getName()); foreignTradeHis.setOperatorTime(new Date()); foreignTradeHis.setContractor(PlatFormHolder.getPlatForm()); this.store(foreignTradeHis); } - - public void removeForeignTradeHis(List ids){ - for(Long id:ids){ - ForeignTradeHis fth=commonDao.load(ForeignTradeHis.class, id); + + public void removeForeignTradeHis(List ids) { + for (Long id : ids) { + ForeignTradeHis fth = commonDao.load(ForeignTradeHis.class, id); this.delete(fth); } - + } - - + @Transactional - public void importForeignTradeHis(File file){ - - //合同编号,客户名称,总运单号,分运单号,出库单号,报关单号,产品名称,币值,货值,接单时间 + public void importForeignTradeHis(File file) { + + // 合同编号,客户名称,总运单号,分运单号,出库单号,报关单号,产品名称,币值,货值,接单时间 try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); - for (int i = 1; i fths= this.commonDao.findByQuery("from ForeignTradeHis fth where fth.contractCode=:code", -// new String[]{"code"},new Object[]{contractCode}); -// if(fths.size()>0){ -// fth=fths.get(0); -// }else{ - fth.setContractCode(contractCode); - fth.setConsignorName(consignorName); - fth.setRelateBill1(relateBill1); - fth.setRelateBill2(relateBill2); - fth.setCustomsCode(customsCode); - fth.setPickticketCode(pickticketCode); - fth.setItemName(itemName); - fth.setCurrencyValue(currencyValue); - fth.setItemValue(itemValue); - if(orderDate!=null && !orderDate.equals("")){ - fth.setOrderDate(sdf.parse(orderDate)); - } - fth.setContractor(PlatFormHolder.getPlatForm()); - fth.setOperatorName(UserHolder.getUser().getName()); - fth.setOperatorTime(new Date()); - this.commonDao.store(fth); - System.out.println(i); -// } - - } - - + Sheet sheet = workbook.getSheet(0);// 得到excel第一页的内容 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); + for (int i = 1; i < sheet.getRows(); i++) { + String contractCode = sheet.getCell(0, i).getContents(); + String consignorName = sheet.getCell(1, i).getContents(); + String relateBill1 = sheet.getCell(2, i).getContents(); + String relateBill2 = sheet.getCell(3, i).getContents(); + String pickticketCode = sheet.getCell(4, i).getContents(); + String customsCode = sheet.getCell(5, i).getContents(); + String itemName = sheet.getCell(6, i).getContents(); + String currencyValue = sheet.getCell(7, i).getContents(); + String itemValue = sheet.getCell(8, i).getContents(); + String orderDate = sheet.getCell(9, i).getContents(); + ForeignTradeHis fth = new ForeignTradeHis(); + // List fths= + // this.commonDao.findByQuery("from ForeignTradeHis fth where fth.contractCode=:code", + // new String[]{"code"},new Object[]{contractCode}); + // if(fths.size()>0){ + // fth=fths.get(0); + // }else{ + fth.setContractCode(contractCode); + fth.setConsignorName(consignorName); + fth.setRelateBill1(relateBill1); + fth.setRelateBill2(relateBill2); + fth.setCustomsCode(customsCode); + fth.setPickticketCode(pickticketCode); + fth.setItemName(itemName); + fth.setCurrencyValue(currencyValue); + fth.setItemValue(itemValue); + if (orderDate != null && !orderDate.equals("")) { + fth.setOrderDate(sdf.parse(orderDate)); + } + fth.setContractor(PlatFormHolder.getPlatForm()); + fth.setOperatorName(UserHolder.getUser().getName()); + fth.setOperatorTime(new Date()); + this.commonDao.store(fth); + System.out.println(i); + // } + + } + } catch (Exception e) { e.printStackTrace(); } } - public FeeType getFeeType(String name){ - List fts=this.commonDao.findByQuery("from FeeType ft where ft.name=:name", - new String[]{"name"},new Object[]{name}); - if(fts.size()>0){ + public FeeType getFeeType(String name) { + List fts = this.commonDao.findByQuery( + "from FeeType ft where ft.name=:name", new String[] { "name" }, + new Object[] { name }); + if (fts.size() > 0) { return fts.get(0); - }else{ - throw new BusinessException("当前区域未维护"+name+"的费用科目项"); + } else { + throw new BusinessException("当前区域未维护" + name + "的费用科目项"); } } - + @SuppressWarnings("unchecked") public Date getCurrierTime(Map map) { Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - Date zero = calendar.getTime(); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + Date zero = calendar.getTime(); return zero; } - + public Date getClientTime(Map map) { - return DateUtil.addDayToDate(new Date(), -30); + return DateUtil.addDayToDate(new Date(), -30); } + public Date getClientNull(Map map) { - return DateUtil.formatStrToDateYMD("2017-01-01"); + return DateUtil.formatStrToDateYMD("2017-01-01"); } - public void setMailTime(List ids,Date mailTime){ - for(Long id: ids){ - Order o=commonDao.load(Order.class, id); + + public void setMailTime(List ids, Date mailTime) { + for (Long id : ids) { + Order o = commonDao.load(Order.class, id); o.setMailTime(mailTime); commonDao.store(o); } } - - //添加订单明细维护 + + // 添加订单明细维护 @Override - public void addOrderDetail(Long id,Long lid, OrderDetail orderDetail) { - if(id!=0) { - Order orders = commonDao.load(Order.class, id); - if (orderDetail.isNew()) { - orders.addOrderDetail(orderDetail); - } - orderDetail.setWeight(orderDetail.getQuantity()*orderDetail.getWeight()); - orderDetail.setVolume(orderDetail.getQuantity()*orderDetail.getVolume()); - commonDao.store(orderDetail); - refreshQuantity(id); - }else { - Order order = commonDao.load(Order.class, lid); - if (orderDetail.isNew()) { - order.addOrderDetail(orderDetail); - - } - commonDao.store(orderDetail); + public void addOrderDetail(Long id, Long lid, OrderDetail orderDetail) { + if (id != 0) { + Order orders = commonDao.load(Order.class, id); + if (orderDetail.isNew()) { + orders.addOrderDetail(orderDetail); + } + orderDetail.setWeight(orderDetail.getQuantity() + * orderDetail.getWeight()); + orderDetail.setVolume(orderDetail.getQuantity() + * orderDetail.getVolume()); + commonDao.store(orderDetail); + refreshQuantity(id); + } else { + Order order = commonDao.load(Order.class, lid); + if (orderDetail.isNew()) { + order.addOrderDetail(orderDetail); + + } + commonDao.store(orderDetail); } } - - //删除订单明细维护 + + // 删除订单明细维护 @Override public void deleteOrderDetail(List ids) { - Long orderId=null; + Long orderId = null; for (Long id : ids) { - OrderDetail s=commonDao.load(OrderDetail.class,id ); - orderId=s.getOrder().getId(); - commonDao.delete(s); + OrderDetail s = commonDao.load(OrderDetail.class, id); + orderId = s.getOrder().getId(); + commonDao.delete(s); } - if(orderId!=null){ - refreshQuantity(orderId); + if (orderId != null) { + refreshQuantity(orderId); } - + } - - //刷新数量,体重,体积 + + // 刷新数量,体重,体积 public void refreshQuantity(Long id) { - Order orders = commonDao.load(Order.class, id); - List objs = commonDao.findByQuery("select nvl(sum(o.quantity),0),nvl(sum(o.weight),0),nvl(sum(o.volume),0) from OrderDetail o where o.order.id=:id ", - new String[] { "id"},new Object[] {id}); - if(objs.size()>0){ - Object[] obj=objs.get(0); - orders.setQuantity((Double)obj[0]); - orders.setWeight(DoubleUtils.formatByPrecision((Double)obj[1],5)); - orders.setVolume(DoubleUtils.formatByPrecision((Double)obj[2],7)); + Order orders = commonDao.load(Order.class, id); + List objs = commonDao + .findByQuery( + "select nvl(sum(o.quantity),0),nvl(sum(o.weight),0),nvl(sum(o.volume),0) from OrderDetail o where o.order.id=:id ", + new String[] { "id" }, new Object[] { id }); + if (objs.size() > 0) { + Object[] obj = objs.get(0); + orders.setQuantity((Double) obj[0]); + orders.setWeight(DoubleUtils.formatByPrecision((Double) obj[1], 5)); + orders.setVolume(DoubleUtils.formatByPrecision((Double) obj[2], 7)); } refPackOrder(orders); } - - public void importUpdateOrder(File file){ + + public void importUpdateOrder(File file) { try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); - for (int i = 1; i os=this.commonDao.findByQuery("from Order o where o.customerOrderNO='"+code+"'"); -// List os=this.commonDao.findByQuery("from Order o where o.relateBill1 like '%"+code+"' and o.consignor.id=4254"); - if(os.size()>0){ - Order o=os.get(0); - o.setQuantity(DoubleUtils.formatByPrecision(qty.getValue(),7)); - o.setWeight(DoubleUtils.formatByPrecision(weight.getValue(),7)); - o.setVolume(DoubleUtils.formatByPrecision(v.getValue(),7)); + // j=7; + NumberCell qty = (NumberCell) sheet.getCell(j++, i); + NumberCell weight = (NumberCell) sheet.getCell(j++, i); + NumberCell v = (NumberCell) sheet.getCell(j++, i); + // String predictFee=sheet.getCell(j++,i).getContents(); + // code=code.substring(3,code.length()); + List os = this.commonDao + .findByQuery("from Order o where o.customerOrderNO='" + + code + "'"); + // List + // os=this.commonDao.findByQuery("from Order o where o.relateBill1 like '%"+code+"' and o.consignor.id=4254"); + if (os.size() > 0) { + Order o = os.get(0); + o.setQuantity(DoubleUtils.formatByPrecision(qty.getValue(), + 7)); + o.setWeight(DoubleUtils.formatByPrecision( + weight.getValue(), 7)); + o.setVolume(DoubleUtils.formatByPrecision(v.getValue(), 7)); this.commonDao.store(o); - List ls=this.commonDao.findByQuery("from Legs l where l.order.id="+o.getId()); - for(Legs l:ls){ + List ls = this.commonDao + .findByQuery("from Legs l where l.order.id=" + + o.getId()); + for (Legs l : ls) { l.setQuantity(o.getQuantity()); l.setWeight(o.getWeight()); l.setVolume(o.getVolume()); this.commonDao.store(l); } -// deleteOpFee(o); -// createCusFee(o); -// feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - }else{ - System.out.println(i+"==="+code+"不存在"); -// throw new BusinessException(i+"==="+code+"不存在"); + // deleteOpFee(o); + // createCusFee(o); + // feeManager.refreshBillFee(o.getId(), + // BillObjectType.ORDER, Boolean.TRUE); + } else { + System.out.println(i + "===" + code + "不存在"); + // throw new BusinessException(i+"==="+code+"不存在"); } - } + } } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -4974,314 +5595,377 @@ public class DefaultOrderManager extends DefaultBaseManager implements e.printStackTrace(); } } - public void importOrderDetail(File file){ + + public void importOrderDetail(File file) { try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf2=new SimpleDateFormat("yyyy/MM/dd HH:mm"); - SimpleDateFormat sdf1=new SimpleDateFormat("yyyy/MM/dd HH:mm"); - Organization plat=PlatFormHolder.getPlatForm(); - Boolean isJJ=Boolean.FALSE; - if(plat.getName().equals("大金旧件")){ - isJJ=Boolean.TRUE; + Sheet sheet = workbook.getSheet(0);// 得到excel第一页的内容 + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd HH:mm"); + SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd HH:mm"); + Organization plat = PlatFormHolder.getPlatForm(); + Boolean isJJ = Boolean.FALSE; + if (plat.getName().equals("大金旧件")) { + isJJ = Boolean.TRUE; } - for (int i = 1; i cuss= this.commonDao.findByQuery("from Organization o where o.shortName=:name ", - new String[]{"name"},new Object[]{consignorName}); - Organization cus=null; - if(cuss.size()>0){ - cus=cuss.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行+"+(j+1)+"列,客户不存在!"); - } - if(cus.getShortName().equals("武汉大金")||cus.getShortName().equals("上海大金")||cus.getShortName().equals("南昌大金")) { - if(wlmc!=null&&!wlmc.equals("")){ - wlmc=wlmc.trim(); - } - if(wldm!=null&&!wldm.equals("")){ - wldm=wldm.trim(); - } - List Items= this.commonDao.findByQuery("from Item i where i.code=:code ", - new String[]{"code"},new Object[]{wldm}); - if(Items.size()>0) { - item=Items.get(0); - List PackageUnits= this.commonDao.findByQuery("from PackageUnit p where p.item.id=:id ", - new String[]{"id"},new Object[]{item.getId()}); - if(PackageUnits.size()>0) { - packageUnit =PackageUnits.get(0); - } - }else { - throw new BusinessException("第"+(i+1)+"行+"+(j+1)+"列,"+wldm+" 货品不存在"); - } - } - City fromCity=new City(); - if(zhqy!=null&&!zhqy.equals("")){ - List fcs= this.commonDao.findByQuery("from City c where c.name=:name", - new String[]{"name"},new Object[]{zhqy}); - if(fcs.size()>0){ - fromCity=fcs.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行+"+(j+1)+"列,出发城市"+zhqy+"没找到"); - } - }else{ - throw new BusinessException("第"+(i+1)+"行+"+(j+1)+"列,出发城市不能为空!"); - } - City toCity=new City(); - if(!shqy.equals("")&&shqy!=null){ - shqy=shqy.trim(); - List tcs= this.commonDao.findByQuery("from City c where c.name=:name", - new String[]{"name"},new Object[]{shqy}); - if(tcs.size()>0){ - toCity=tcs.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行+"+(j+1)+"列,目标城市"+shqy+"没找到"); - } - }else{ - throw new BusinessException("第"+(i+1)+"行+"+(j+1)+"列,目标城市不能为空!"); - } - Double quantity=0D; - if(hjdpsl!=null && !hjdpsl.equals("")){ - System.out.println(wlmc+"==="+(i+1)); - String regEx="\\D"; - Pattern p=Pattern.compile(regEx); - Matcher m=p.matcher(hjdpsl); - String result=m.replaceAll("").trim(); - Character ch=result.charAt(0); - int index=hjdpsl.indexOf(ch); - String qty= hjdpsl.substring(index,hjdpsl.length()); - try { - quantity=Double.parseDouble(qty); - } catch (Exception e) { - throw new BusinessException("第"+(i+1)+"行+"+(j+1)+"列,数量格式有误!"); + String relateBill1 = sheet.getCell(j++, i).getContents(); + String description3 = ""; + String orderJG = ""; + String thdz = ""; + String cellDate = ""; + Date orderDate = null; + if (!isJJ) { + // 货主名称 货主单号 物流单号 接单机构 接单时间 运输方式 货主指示人 装货区域 收货区域 收货地址 目的标志 + // 收货联系人 收货电话 + // 物料名称 合计单品数量 物料规格 物料代码 受注编号 保险金额 + description3 = sheet.getCell(j++, i).getContents(); + orderJG = sheet.getCell(j++, i).getContents(); + if (sheet.getColumns() < 19) { + throw new BusinessException("模版列数不正确,应为19列S"); } - - } - Order order=new Order(); - List fths=null; - if(!isJJ){ - fths= this.commonDao.findByQuery("from Order o where to_char(o.orderDate,'yyyy-MM-dd')=:orderDate and o.toCityCountiy.id=:toCityId " - + " and o.toContact.linkman=:linkman and o.status=:status and o.shipmentMethod=:shipmentMethod and o.contractor.id=:contractor_id and o.toContact.address=:address and o.toName=:toName", - new String[]{"orderDate","toCityId","linkman","status","shipmentMethod","contractor_id","address","toName"},new Object[]{DateUtil.formatDateYMDToStr(orderDate),toCity.getId(),toLinkman,OrderStatus.AVAILABLE,ysfs,PlatFormHolder.getPlatForm().getId(),shdz,toName}); - - }else{ - fths= this.commonDao.findByQuery("from Order o where to_char(o.orderDate,'yyyy-MM-dd')=:orderDate and o.toCityCountiy.id=:toCityId " - + " and o.toContact.linkman=:linkman and o.status=:status and o.fromContact.address=:thdz and o.contractor.id=:contractor_id", - new String[]{"orderDate","toCityId","linkman","status","thdz","contractor_id"},new Object[]{DateUtil.formatDateYMDToStr(orderDate),toCity.getId(),toLinkman,OrderStatus.AVAILABLE,thdz,PlatFormHolder.getPlatForm().getId()}); - - } - if(fths.size()>0){ - order=fths.get(0); - }else{ - order.setShipmentMethod(ysfs); - order.setConsignor(cus); - if(orderJG!=null && !orderJG.equals("")){ - List ts=this.commonDao.findByQuery("from TransLocation l where l.name=:name ", - new String[]{"name"},new Object[]{orderJG}); - if(ts.size()>0){ - TransLocation l=new TransLocation(); - l=ts.get(0); - order.setFromLocation(l); - order.setFromCode(l.getCode()); - order.setFromName(l.getName()); - order.setFromContact(l.getContact()); - } - } - if(thdz!=null&&!thdz.equals("")){ - Contact ct=order.getFromContact(); - if(ct==null){ - ct=new Contact(); - } - ct.setAddress(thdz); - order.setFromContact(ct); - } - order.setRelateBill1(relateBill1); - order.setDescription3(description3); - order.setDescription4(orderJG); - order.setOrderDate(orderDate); - order.setPlanFromDate(orderDate); - order.setFromCity(fromCity); - order.setFromCityCountiy(fromCity); - List toLs=this.commonDao.findByQuery("from TransLocation l where l.contact.linkman=:linkman", - new String[]{"linkman"},new Object[]{toLinkman}); - if(toLs.size()>0){ - TransLocation toL=toLs.get(0); - order.setToLocation(toL); - order.setCargoType(toL.getWorkphone()); - } - order.setToCity(toCity); - if(shqy.equals("")||shqy==null){ - order.setToCity(fromCity); - }else{ - order.setToCity(toCity); - - } - if(!isJJ){ - order.setCustomerOrderNO(szbh); - } - order.setToCityCountiy(toCity); - order.setToName(toName); - Contact toContact=new Contact(); - toContact.setAddress(shdz); - toContact.setLinkman(toLinkman); - toContact.setPhone(toPhone); - order.setToContact(toContact); - order.setCode(codeManager.generateItemCode()); - order.setStatus(OrderStatus.AVAILABLE); - order.setGroupNo(codeManager.generateGroupNo()); - order.setRelateBill3(codeManager.generateLegsCode(PlatFormHolder.getPlatForm().getCode())); - order.setCash(0); - order.setOperatorDate(new Date()); - order.setCreateTime(new Date()); - order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); - order.setContractor(PlatFormHolder.getPlatForm()); - order.setOtherStatus(FeeStatus.OPEN); - order.setUnit("件"); - order.setSuperviseType(SuperviseType.UNSUPERVISE); - order.setPaymentMethod("月付"); - order.setUnit(MeasureUnit.TON_CUBIC);//默认计量单位 - order.setDeliveryMode("送货上门"); - int groupIndex=1; - try { - groupIndex=Integer.parseInt(mdbz); + } else { + if (sheet.getColumns() < 17) { + throw new BusinessException("模版列数不正确,应为17列Q"); + } + // 货主名称 货主单号 提货单位 提货地址 接单时间 运输方式 货主指示人 装货区域 收货区域 收货地址 收货联系人 + // 收货电话 + // 物料代码 物料名称 机型 机号 合计单品数量 + orderJG = sheet.getCell(j++, i).getContents(); + thdz = sheet.getCell(j++, i).getContents(); + } + if (sheet.getCell(4, i).getType() == CellType.DATE) { + DateCell dc = (DateCell) sheet.getCell(j++, i); + TimeZone zone = TimeZone.getTimeZone("GMT"); + sdf2.setTimeZone(zone); + try { + orderDate = sdf1.parse(sdf2.format(dc.getDate())); + } catch (ParseException e1) { + throw new BusinessException("第" + (i + 1) + "行,日期格式错误!"); + } + } else { + throw new BusinessException("第" + (i + 1) + "行,日期格式错误!"); + } + + String ysfs = sheet.getCell(j++, i).getContents(); + String toName = sheet.getCell(j++, i).getContents(); + String zhqy = sheet.getCell(j++, i).getContents();// 装货区域 + String shqy = sheet.getCell(j++, i).getContents();// 收货区域 + String shdz = sheet.getCell(j++, i).getContents();// 收货地址 + String mdbz = sheet.getCell(j++, i).getContents();// 目的标志 + String toLinkman = sheet.getCell(j++, i).getContents();// 收货联系人 + String toPhone = sheet.getCell(j++, i).getContents();// 收货电话 + String wlmc = ""; + String wldm = ""; + String hjdpsl = ""; + String wlgg = ""; + String szbh = ""; + if (!isJJ) { + wlmc = sheet.getCell(j++, i).getContents();// 物料名称 + hjdpsl = sheet.getCell(j++, i).getContents();// 合计单品数量 + wlgg = sheet.getCell(j++, i).getContents();// 部品编号 + wldm = sheet.getCell(j++, i).getContents(); + szbh = sheet.getCell(j++, i).getContents();// 受注编号 + } else { + wldm = sheet.getCell(j++, i).getContents(); + wlmc = sheet.getCell(j++, i).getContents(); + wlgg = sheet.getCell(j++, i).getContents(); + szbh = sheet.getCell(j++, i).getContents(); + hjdpsl = sheet.getCell(j++, i).getContents(); + } + Item item = null; + PackageUnit packageUnit = null; + if (ysfs.equals("普运") || ysfs.equals("汽运")) { + ysfs = "TRUCK"; + } else if (ysfs.equals("空运")) { + ysfs = "AIR"; + } else if (ysfs.equals("快运")) { + ysfs = "RAILWAY"; + } else if (ysfs.equals("快递")) { + ysfs = "ZERO_SINGLE"; + } else if (ysfs.equals("加急")) { + ysfs = "URGENT"; + } else { + ysfs = "TRUCK"; + } + + if (ysfs == null || ysfs.equals("")) { + throw new BusinessException("第" + (i + 1) + "行+" + (j + 1) + + "列,运输方式不能为空!"); + } + if (toName == null || toName.equals("")) { + throw new BusinessException("第" + (i + 1) + "行+" + (j + 1) + + "列,货主指示人不能为空!"); + } + if (toLinkman == null || toLinkman.equals("")) { + throw new BusinessException("第" + (i + 1) + "行+" + (j + 1) + + "列,收货联系人不能为空!"); + } else { + toLinkman = toLinkman.trim(); + } + if (zhqy == null || zhqy.equals("")) { + throw new BusinessException("第" + (i + 1) + "行+" + (j + 1) + + "列,装货区域不能为空!"); + } else { + zhqy = zhqy.trim(); + } + List cuss = this.commonDao + .findByQuery( + "from Organization o where o.shortName=:name ", + new String[] { "name" }, + new Object[] { consignorName }); + Organization cus = null; + if (cuss.size() > 0) { + cus = cuss.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行+" + (j + 1) + + "列,客户不存在!"); + } + if (cus.getShortName().equals("武汉大金") + || cus.getShortName().equals("上海大金") + || cus.getShortName().equals("南昌大金")) { + if (wlmc != null && !wlmc.equals("")) { + wlmc = wlmc.trim(); + } + if (wldm != null && !wldm.equals("")) { + wldm = wldm.trim(); + } + List Items = this.commonDao.findByQuery( + "from Item i where i.code=:code ", + new String[] { "code" }, new Object[] { wldm }); + if (Items.size() > 0) { + item = Items.get(0); + List PackageUnits = this.commonDao + .findByQuery( + "from PackageUnit p where p.item.id=:id ", + new String[] { "id" }, + new Object[] { item.getId() }); + if (PackageUnits.size() > 0) { + packageUnit = PackageUnits.get(0); + } + } else { + throw new BusinessException("第" + (i + 1) + "行+" + + (j + 1) + "列," + wldm + " 货品不存在"); + } + } + City fromCity = new City(); + if (zhqy != null && !zhqy.equals("")) { + List fcs = this.commonDao.findByQuery( + "from City c where c.name=:name", + new String[] { "name" }, new Object[] { zhqy }); + if (fcs.size() > 0) { + fromCity = fcs.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行+" + + (j + 1) + "列,出发城市" + zhqy + "没找到"); + } + } else { + throw new BusinessException("第" + (i + 1) + "行+" + (j + 1) + + "列,出发城市不能为空!"); + } + City toCity = new City(); + if (!shqy.equals("") && shqy != null) { + shqy = shqy.trim(); + List tcs = this.commonDao.findByQuery( + "from City c where c.name=:name", + new String[] { "name" }, new Object[] { shqy }); + if (tcs.size() > 0) { + toCity = tcs.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行+" + + (j + 1) + "列,目标城市" + shqy + "没找到"); + } + } else { + throw new BusinessException("第" + (i + 1) + "行+" + (j + 1) + + "列,目标城市不能为空!"); + } + Double quantity = 0D; + if (hjdpsl != null && !hjdpsl.equals("")) { + System.out.println(wlmc + "===" + (i + 1)); + String regEx = "\\D"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(hjdpsl); + String result = m.replaceAll("").trim(); + Character ch = result.charAt(0); + int index = hjdpsl.indexOf(ch); + String qty = hjdpsl.substring(index, hjdpsl.length()); + try { + quantity = Double.parseDouble(qty); + } catch (Exception e) { + throw new BusinessException("第" + (i + 1) + "行+" + + (j + 1) + "列,数量格式有误!"); + } + + } + Order order = new Order(); + List fths = null; + if (!isJJ) { + fths = this.commonDao + .findByQuery( + "from Order o where to_char(o.orderDate,'yyyy-MM-dd')=:orderDate and o.toCityCountiy.id=:toCityId " + + " and o.toContact.linkman=:linkman and o.status=:status and o.shipmentMethod=:shipmentMethod and o.contractor.id=:contractor_id and o.toContact.address=:address and o.toName=:toName", + new String[] { "orderDate", "toCityId", + "linkman", "status", + "shipmentMethod", "contractor_id", + "address", "toName" }, + new Object[] { + DateUtil.formatDateYMDToStr(orderDate), + toCity.getId(), + toLinkman, + OrderStatus.AVAILABLE, + ysfs, + PlatFormHolder.getPlatForm() + .getId(), shdz, toName }); + + } else { + fths = this.commonDao + .findByQuery( + "from Order o where to_char(o.orderDate,'yyyy-MM-dd')=:orderDate and o.toCityCountiy.id=:toCityId " + + " and o.toContact.linkman=:linkman and o.status=:status and o.fromContact.address=:thdz and o.contractor.id=:contractor_id", + new String[] { "orderDate", "toCityId", + "linkman", "status", "thdz", + "contractor_id" }, + new Object[] { + DateUtil.formatDateYMDToStr(orderDate), + toCity.getId(), + toLinkman, + OrderStatus.AVAILABLE, + thdz, + PlatFormHolder.getPlatForm() + .getId() }); + + } + if (fths.size() > 0) { + order = fths.get(0); + } else { + order.setShipmentMethod(ysfs); + order.setConsignor(cus); + if (orderJG != null && !orderJG.equals("")) { + List ts = this.commonDao.findByQuery( + "from TransLocation l where l.name=:name ", + new String[] { "name" }, + new Object[] { orderJG }); + if (ts.size() > 0) { + TransLocation l = new TransLocation(); + l = ts.get(0); + order.setFromLocation(l); + order.setFromCode(l.getCode()); + order.setFromName(l.getName()); + order.setFromContact(l.getContact()); + } + } + if (thdz != null && !thdz.equals("")) { + Contact ct = order.getFromContact(); + if (ct == null) { + ct = new Contact(); + } + ct.setAddress(thdz); + order.setFromContact(ct); + } + order.setRelateBill1(relateBill1); + order.setDescription3(description3); + order.setDescription4(orderJG); + order.setOrderDate(orderDate); + order.setPlanFromDate(orderDate); + order.setFromCity(fromCity); + order.setFromCityCountiy(fromCity); + List toLs = this.commonDao + .findByQuery( + "from TransLocation l where l.contact.linkman=:linkman", + new String[] { "linkman" }, + new Object[] { toLinkman }); + if (toLs.size() > 0) { + TransLocation toL = toLs.get(0); + order.setToLocation(toL); + order.setCargoType(toL.getWorkphone()); + } + order.setToCity(toCity); + if (shqy.equals("") || shqy == null) { + order.setToCity(fromCity); + } else { + order.setToCity(toCity); + + } + if (!isJJ) { + order.setCustomerOrderNO(szbh); + } + order.setToCityCountiy(toCity); + order.setToName(toName); + Contact toContact = new Contact(); + toContact.setAddress(shdz); + toContact.setLinkman(toLinkman); + toContact.setPhone(toPhone); + order.setToContact(toContact); + order.setCode(codeManager.generateItemCode()); + order.setStatus(OrderStatus.AVAILABLE); + order.setGroupNo(codeManager.generateGroupNo()); + order.setRelateBill3(codeManager + .generateLegsCode(PlatFormHolder.getPlatForm() + .getCode())); + order.setCash(0); + order.setOperatorDate(new Date()); + order.setCreateTime(new Date()); + order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); + order.setContractor(PlatFormHolder.getPlatForm()); + order.setOtherStatus(FeeStatus.OPEN); + order.setUnit("件"); + order.setSuperviseType(SuperviseType.UNSUPERVISE); + order.setPaymentMethod("月付"); + order.setUnit(MeasureUnit.TON_CUBIC);// 默认计量单位 + order.setDeliveryMode("送货上门"); + int groupIndex = 1; + try { + groupIndex = Integer.parseInt(mdbz); } catch (Exception e) { // TODO: handle exception } - order.setGroupIndex(groupIndex); - this.commonDao.store(order); - } - OrderDetail orderDetail=new OrderDetail(); - orderDetail.setItem(item); - String hql="from OrderDetail d where 1=1 and d.order.id="+order.getId(); - if(szbh!=null&&!szbh.equals("")){ - hql+=" and d.annotationCode='"+szbh+"'"; - } - if(wldm!=null&&!wldm.equals("")){ - hql+=" and d.materielCode='"+wldm+"'"; - } - List orderDetails= this.commonDao.findByQuery(hql); - if(orderDetails.size()>0){ - orderDetail=orderDetails.get(0); - } else{ - orderDetail.setOrder(order); - orderDetail.setAnnotationCode(szbh); - orderDetail.setSerial(wlmc); - orderDetail.setQuantity(quantity); - orderDetail.setFeeDetail(wlgg); - orderDetail.setMaterielCode(wldm); - if(packageUnit!=null){ - if(packageUnit.getWeight()>packageUnit.getArea()){ - orderDetail.setWeight(packageUnit.getWeight()*quantity); - }else{ - orderDetail.setWeight(packageUnit.getArea()*quantity); - } - orderDetail.setVolume(packageUnit.getVolume()*quantity); - } - - orderDetail.setConsignorName(relateBill1); - commonDao.store(orderDetail); - } - refreshQuantity(order.getId()); - System.out.println(i); - } + order.setGroupIndex(groupIndex); + this.commonDao.store(order); + } + OrderDetail orderDetail = new OrderDetail(); + orderDetail.setItem(item); + String hql = "from OrderDetail d where 1=1 and d.order.id=" + + order.getId(); + if (szbh != null && !szbh.equals("")) { + hql += " and d.annotationCode='" + szbh + "'"; + } + if (wldm != null && !wldm.equals("")) { + hql += " and d.materielCode='" + wldm + "'"; + } + List orderDetails = this.commonDao + .findByQuery(hql); + if (orderDetails.size() > 0) { + orderDetail = orderDetails.get(0); + } else { + orderDetail.setOrder(order); + orderDetail.setAnnotationCode(szbh); + orderDetail.setSerial(wlmc); + orderDetail.setQuantity(quantity); + orderDetail.setFeeDetail(wlgg); + orderDetail.setMaterielCode(wldm); + if (packageUnit != null) { + if (packageUnit.getWeight() > packageUnit.getArea()) { + orderDetail.setWeight(packageUnit.getWeight() + * quantity); + } else { + orderDetail.setWeight(packageUnit.getArea() + * quantity); + } + orderDetail.setVolume(packageUnit.getVolume() + * quantity); + } + + orderDetail.setConsignorName(relateBill1); + commonDao.store(orderDetail); + } + refreshQuantity(order.getId()); + System.out.println(i); + } } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -5290,227 +5974,253 @@ public class DefaultOrderManager extends DefaultBaseManager implements e.printStackTrace(); } } - - Date convertDate(CellType type,Cell cell,int i){ - Date orderDate=null; - if(type==CellType.DATE){ - DateCell dc=(DateCell)cell;//接单时间 - orderDate = dc.getDate(); - if(orderDate!=null){ - Calendar curr = Calendar.getInstance(); - curr.setTime(orderDate); - int y=curr.get(Calendar.YEAR); - if(y<1000){ - curr.set(Calendar.YEAR,curr.get(Calendar.YEAR)+2000); - orderDate=curr.getTime(); - } - } - }else{ - String dateCell=cell.getContents(); - if(dateCell==null||dateCell.equals("")){ - throw new BusinessException("第"+(i+1)+"行,接单时间不存在!"); - } - orderDate=DateUtil.getDateFormat2(dateCell); - } - return orderDate; + + Date convertDate(CellType type, Cell cell, int i) { + Date orderDate = null; + if (type == CellType.DATE) { + DateCell dc = (DateCell) cell;// 接单时间 + orderDate = dc.getDate(); + if (orderDate != null) { + Calendar curr = Calendar.getInstance(); + curr.setTime(orderDate); + int y = curr.get(Calendar.YEAR); + if (y < 1000) { + curr.set(Calendar.YEAR, curr.get(Calendar.YEAR) + 2000); + orderDate = curr.getTime(); + } + } + } else { + String dateCell = cell.getContents(); + if (dateCell == null || dateCell.equals("")) { + throw new BusinessException("第" + (i + 1) + "行,接单时间不存在!"); + } + orderDate = DateUtil.getDateFormat2(dateCell); + } + return orderDate; } - //高理订单导入 - public void importGaoLiOrderDetail(File file){ - + + // 高理订单导入 + public void importGaoLiOrderDetail(File file) { + try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - //操作状态 订单状态 货主名称 货主单号 物流单号 订单类型 接单机构 接单时间 货主指示人 备注 结算方式 发运日期 签收日期 签收人 - //装货区域 收货区域 收货地址 收货联系人 收货电话 物料名称 合计单品数量 货物名称 货主部门 波次单号 物料规格 物料代码 生产日期 - //失效日期 批号 服务号 序列号 货主部门 主运单号 受注编号 承运商 压缩机序号 - //提货日期 客户订单号 出发地 目的地 运输方式 事业部 收货人 收货单位 收货电话 收货地址 实际承运商 送货方式 件数 重量 签收日期 签收人 失效正常 原因 承运单号 - for (int i = 1; i organizations= this.commonDao.findByQuery("from Organization o where o.shortName=:name ", - new String[]{"name"},new Object[]{"高理"}); - Organization org=null; - if(organizations.size()>0){ - org=organizations.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,客户不存在!"); - } - List os = commonDao.findByQuery(" from Order o where o.consignor.id=:consignorId and o.customerOrderNO=:customerOrderNO ", - new String[] { "consignorId","customerOrderNO"},new Object[] {org.getId(),customerOrderNO}); - if(customerOrderNO!=null&&os.size()>0&&!customerOrderNO.equals("")){ - throw new BusinessException("第"+(i+1)+"行,客户订单号"+customerOrderNO+"已存在"); - } - City fromCity=new City(); - if(zhqy!=null&&!zhqy.equals("")){ - List fcs= this.commonDao.findByQuery("from City c where c.name like '%" + zhqy + "%'", - new String[]{},new Object[]{}); - if(fcs.size()>0){ - fromCity=fcs.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,出发城市"+zhqy+"没找到"); - } - }else{ - throw new BusinessException("第"+(i+1)+"行,出发城市不能为空!"); - } - City toCity=new City(); - if(!shqy.equals("")&&shqy!=null){ - shqy=shqy.trim(); - List tcs= this.commonDao.findByQuery("from City c where c.name like '%" + shqy + "%'", - new String[]{},new Object[]{}); - if(tcs.size()>0){ - toCity=tcs.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,目标城市"+shqy+"没找到"); - } - } - //承运商 - Organization carrier=null; - if(!cys.equals("")&&cys!=null){ - cys=cys.trim(); - List carriers= this.commonDao.findByQuery("from Organization org where org.bePlatForm=false and org.beCustomer=false and org.shortName like '%" + cys + "%'", - new String[]{},new Object[]{}); - if(carriers.size()>0){ - carrier=carriers.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,承运商"+cys+"没找到"); - } - } - Date thsj=sdf.parse(thrq); - if(thsj!=null){ - Calendar curr = Calendar.getInstance(); - curr.setTime(thsj); - int y=curr.get(Calendar.YEAR); - if(y<1000){ - curr.set(Calendar.YEAR,curr.get(Calendar.YEAR)+2000); - thsj=curr.getTime(); - } - } - Order order=new Order(); - System.out.println(thsj); - order.setPlanFromDate(thsj);//提货日期 - order.setConsignor(org);//客户 - order.setOrderDate(new Date());//开单时间 - order.setCarrier(carrier);//承运商 - order.setCustomerOrderNO(customerOrderNO);//客户订单号 - order.setShipmentMethod(ysfs);//运输方式 - order.setFromCity(fromCity); - order.setFromCityCountiy(fromCity); - List toLs=this.commonDao.findByQuery("from TransLocation l where l.contact.linkman=:linkman", - new String[]{"linkman"},new Object[]{toLinkman}); - if(toLs.size()>0){ - TransLocation toL=toLs.get(0); - order.setToLocation(toL); - order.setCargoType(toL.getWorkphone()); - } - order.setToCity(toCity); - if(shqy.equals("")||shqy==null){ - order.setToCity(fromCity); - }else{ - order.setToCity(toCity); - - } - order.setToCityCountiy(toCity); - Contact toContact=new Contact(); - toContact.setAddress(shdz);//收货地址 - toContact.setLinkman(toLinkman);//联系人 - toContact.setPhone(toPhone);//电话 - order.setToContact(toContact); - order.setCode(codeManager.generateItemCode()); - order.setStatus(OrderStatus.SIGNED); - order.setGroupNo(codeManager.generateGroupNo()); - order.setRelateBill3(codeManager.generateLegsCode(PlatFormHolder.getPlatForm().getCode())); - order.setCash(0); - order.setOperatorDate(new Date()); - order.setCreateTime(new Date()); - order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); - order.setContractor(PlatFormHolder.getPlatForm()); - order.setOtherStatus(FeeStatus.OPEN); - order.setUnit("件"); - order.setSuperviseType(SuperviseType.UNSUPERVISE); - order.setPaymentMethod("月付"); - order.setUnit(MeasureUnit.WEIGHT);//默认计量单位 - if(shfs.equals("到门")) { - shfs="送货上门"; - }else if(shfs.equals("自提")) { - shfs="客户自提"; - } - order.setDeliveryMode(shfs);//送货方式 - order.setSignBy(qspeople);//签收人 - Date qs=sdf.parse(qsrq); - Calendar curr1 = Calendar.getInstance(); - curr1.setTime(qs); - int t=curr1.get(Calendar.YEAR); - if(t<1000){ - curr1.set(Calendar.YEAR,curr1.get(Calendar.YEAR)+2000); - qs=curr1.getTime(); - } - order.setSignTime(qs);//签收日期 - this.commonDao.store(order); - orderPrescription(order);//时效 - - OrderDetail orderDetail=new OrderDetail(); - String hql="from OrderDetail d where 1=1 and d.order.id="+order.getId(); - List orderDetails= this.commonDao.findByQuery(hql); - if(orderDetails.size()>0){ - orderDetail=orderDetails.get(0); - } else{ - orderDetail.setOrder(order); - orderDetail.setBusinessDepartment(bm);//部门 - - orderDetail.setQuantity(Double.parseDouble(quantity)); - orderDetail.setWeight(Double.parseDouble(weight)); - commonDao.store(orderDetail); - } - refreshQuantity(order.getId()); - System.out.println(i); - } + Sheet sheet = workbook.getSheet(0);// 得到excel第一页的内容 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + // 操作状态 订单状态 货主名称 货主单号 物流单号 订单类型 接单机构 接单时间 货主指示人 备注 结算方式 发运日期 签收日期 + // 签收人 + // 装货区域 收货区域 收货地址 收货联系人 收货电话 物料名称 合计单品数量 货物名称 货主部门 波次单号 物料规格 物料代码 + // 生产日期 + // 失效日期 批号 服务号 序列号 货主部门 主运单号 受注编号 承运商 压缩机序号 + // 提货日期 客户订单号 出发地 目的地 运输方式 事业部 收货人 收货单位 收货电话 收货地址 实际承运商 送货方式 件数 重量 + // 签收日期 签收人 失效正常 原因 承运单号 + for (int i = 1; i < sheet.getRows(); i++) { + String thrq = sheet.getCell(0, i).getContents();// 提货日期 + String customerOrderNO = sheet.getCell(1, i).getContents();// 客户订单号 + String zhqy = sheet.getCell(2, i).getContents();// 装货区域-出发地 + String shqy = sheet.getCell(3, i).getContents();// 收货区域-目的地 + String ysfs = sheet.getCell(4, i).getContents();// 运输方式 + if (ysfs == null || ysfs.equals("")) { + throw new BusinessException("第" + (i + 1) + "行,运输方式不能为空!"); + } + // String bz=sheet.getCell(9,i).getContents();//备注 + String bm = sheet.getCell(5, i).getContents();// 部门 + String toLinkman = sheet.getCell(6, i).getContents();// 收货联系人 + String toLocation = sheet.getCell(7, i).getContents(); // 收货单位 + String toPhone = sheet.getCell(8, i).getContents();// 收货电话 + String shdz = sheet.getCell(9, i).getContents();// 收货地址 + String cys = sheet.getCell(10, i).getContents();// 承运商 + String shfs = sheet.getCell(11, i).getContents();// 送货方式-交付方式 + String quantity = sheet.getCell(12, i).getContents();// 件数 + String weight = sheet.getCell(13, i).getContents();// 重量 + String qsrq = sheet.getCell(14, i).getContents();// 签收日期 + String qspeople = sheet.getCell(15, i).getContents();// 签收人 + String sxzc = sheet.getCell(16, i).getContents();// 时效正常 + String reson = sheet.getCell(17, i).getContents();// 原因 + String cydh = sheet.getCell(18, i).getContents();// 承运单号 + Item item = null; + PackageUnit packageUnit = null; + if (ysfs.equals("普运") || ysfs.equals("汽运") || ysfs.equals("公路") + || ysfs.equals("跨越")) { + ysfs = "TRUCK"; + } else if (ysfs.equals("空运") || ysfs.equals("航空")) { + ysfs = "AIR"; + } else if (ysfs.equals("快运")) { + ysfs = "RAILWAY"; + } else if (ysfs.equals("快递")) { + ysfs = "ZERO_SINGLE"; + } else if (ysfs.equals("加急")) { + ysfs = "URGENT"; + } else if (ysfs.equals("专车")) { + ysfs = "SPECIAL_CAR"; + } else { + ysfs = "TRUCK"; + } + + if (zhqy == null || zhqy.equals("")) { + throw new BusinessException("第" + (i + 1) + "行,装货区域不能为空!"); + } else { + zhqy = zhqy.trim(); + } + + // 客户 + List organizations = this.commonDao.findByQuery( + "from Organization o where o.shortName=:name ", + new String[] { "name" }, new Object[] { "高理" }); + Organization org = null; + if (organizations.size() > 0) { + org = organizations.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行,客户不存在!"); + } + List os = commonDao + .findByQuery( + " from Order o where o.consignor.id=:consignorId and o.customerOrderNO=:customerOrderNO ", + new String[] { "consignorId", "customerOrderNO" }, + new Object[] { org.getId(), customerOrderNO }); + if (customerOrderNO != null && os.size() > 0 + && !customerOrderNO.equals("")) { + throw new BusinessException("第" + (i + 1) + "行,客户订单号" + + customerOrderNO + "已存在"); + } + City fromCity = new City(); + if (zhqy != null && !zhqy.equals("")) { + List fcs = this.commonDao.findByQuery( + "from City c where c.name like '%" + zhqy + + "%'", new String[] {}, new Object[] {}); + if (fcs.size() > 0) { + fromCity = fcs.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行,出发城市" + + zhqy + "没找到"); + } + } else { + throw new BusinessException("第" + (i + 1) + "行,出发城市不能为空!"); + } + City toCity = new City(); + if (!shqy.equals("") && shqy != null) { + shqy = shqy.trim(); + List tcs = this.commonDao.findByQuery( + "from City c where c.name like '%" + shqy + + "%'", new String[] {}, new Object[] {}); + if (tcs.size() > 0) { + toCity = tcs.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行,目标城市" + + shqy + "没找到"); + } + } + // 承运商 + Organization carrier = null; + if (!cys.equals("") && cys != null) { + cys = cys.trim(); + List carriers = this.commonDao + .findByQuery( + "from Organization org where org.bePlatForm=false and org.beCustomer=false and org.shortName like '%" + + cys + "%'", new String[] {}, + new Object[] {}); + if (carriers.size() > 0) { + carrier = carriers.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行,承运商" + + cys + "没找到"); + } + } + Date thsj = sdf.parse(thrq); + if (thsj != null) { + Calendar curr = Calendar.getInstance(); + curr.setTime(thsj); + int y = curr.get(Calendar.YEAR); + if (y < 1000) { + curr.set(Calendar.YEAR, curr.get(Calendar.YEAR) + 2000); + thsj = curr.getTime(); + } + } + Order order = new Order(); + System.out.println(thsj); + order.setPlanFromDate(thsj);// 提货日期 + order.setConsignor(org);// 客户 + order.setOrderDate(new Date());// 开单时间 + order.setCarrier(carrier);// 承运商 + order.setCustomerOrderNO(customerOrderNO);// 客户订单号 + order.setShipmentMethod(ysfs);// 运输方式 + order.setFromCity(fromCity); + order.setFromCityCountiy(fromCity); + List toLs = this.commonDao + .findByQuery( + "from TransLocation l where l.contact.linkman=:linkman", + new String[] { "linkman" }, + new Object[] { toLinkman }); + if (toLs.size() > 0) { + TransLocation toL = toLs.get(0); + order.setToLocation(toL); + order.setCargoType(toL.getWorkphone()); + } + order.setToCity(toCity); + if (shqy.equals("") || shqy == null) { + order.setToCity(fromCity); + } else { + order.setToCity(toCity); + + } + order.setToCityCountiy(toCity); + Contact toContact = new Contact(); + toContact.setAddress(shdz);// 收货地址 + toContact.setLinkman(toLinkman);// 联系人 + toContact.setPhone(toPhone);// 电话 + order.setToContact(toContact); + order.setCode(codeManager.generateItemCode()); + order.setStatus(OrderStatus.SIGNED); + order.setGroupNo(codeManager.generateGroupNo()); + order.setRelateBill3(codeManager + .generateLegsCode(PlatFormHolder.getPlatForm() + .getCode())); + order.setCash(0); + order.setOperatorDate(new Date()); + order.setCreateTime(new Date()); + order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); + order.setContractor(PlatFormHolder.getPlatForm()); + order.setOtherStatus(FeeStatus.OPEN); + order.setUnit("件"); + order.setSuperviseType(SuperviseType.UNSUPERVISE); + order.setPaymentMethod("月付"); + order.setUnit(MeasureUnit.WEIGHT);// 默认计量单位 + if (shfs.equals("到门")) { + shfs = "送货上门"; + } else if (shfs.equals("自提")) { + shfs = "客户自提"; + } + order.setDeliveryMode(shfs);// 送货方式 + order.setSignBy(qspeople);// 签收人 + Date qs = sdf.parse(qsrq); + Calendar curr1 = Calendar.getInstance(); + curr1.setTime(qs); + int t = curr1.get(Calendar.YEAR); + if (t < 1000) { + curr1.set(Calendar.YEAR, curr1.get(Calendar.YEAR) + 2000); + qs = curr1.getTime(); + } + order.setSignTime(qs);// 签收日期 + this.commonDao.store(order); + orderPrescription(order);// 时效 + + OrderDetail orderDetail = new OrderDetail(); + String hql = "from OrderDetail d where 1=1 and d.order.id=" + + order.getId(); + List orderDetails = this.commonDao + .findByQuery(hql); + if (orderDetails.size() > 0) { + orderDetail = orderDetails.get(0); + } else { + orderDetail.setOrder(order); + orderDetail.setBusinessDepartment(bm);// 部门 + + orderDetail.setQuantity(Double.parseDouble(quantity)); + orderDetail.setWeight(Double.parseDouble(weight)); + commonDao.store(orderDetail); + } + refreshQuantity(order.getId()); + System.out.println(i); + } } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -5523,66 +6233,77 @@ public class DefaultOrderManager extends DefaultBaseManager implements } } - @Override//通用订单导入模版 + @Override + // 通用订单导入模版 public void importCurrencyOrder1(File file) { try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); - //操作状态 订单状态 货主名称 货主单号 物流单号 订单类型 接单机构 接单时间 货主指示人 备注 结算方式 发运日期 签收日期 签收人 - //装货区域 收货区域 收货地址 收货联系人 收货电话 物料名称 合计单品数量 货物名称 货主部门 波次单号 物料规格 物料代码 生产日期 - //失效日期 批号 服务号 序列号 货主部门 主运单号 受注编号 承运商 压缩机序号 - //提货日期 客户订单号 出发地 目的地 运输方式 事业部 收货人 收货单位 收货电话 收货地址 实际承运商 送货方式 件数 重量 签收日期 签收人 失效正常 原因 承运单号 - //客户 提货日期 客户订单号 托运单号(提货单号) 提货单位 起运地址(提货地址) 起运城市(开始城市) 运输方式 收货单位 收货人 收货城市 收货地址 件数 重量 体积 备注1 备注2 - for (int i = 1; i organizations= this.commonDao.findByQuery("from Organization o where o.name=:name ", - new String[]{"name"},new Object[]{kh}); - Organization org=null; - if(organizations.size()>0){ - org=organizations.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,客户不存在!"); - } - List os = commonDao.findByQuery(" from Order o where o.consignor.id=:consignorId and o.customerOrderNO=:customerOrderNO ", - new String[] { "consignorId","customerOrderNO"},new Object[] {org.getId(),customerOrderNO}); - - Order order=new Order(); - if(os.size()>0) { - order=os.get(0); - if(order.getVolume()==0) { -// order.setVolume(Double.parseDouble(volume)); -// this.commonDao.store(order); -// System.out.println("为0的序号:"+customerOrderNO+i); - } - } - System.out.println(i+"======"+customerOrderNO+"===体积="+volume); - } + Sheet sheet = workbook.getSheet(0);// 得到excel第一页的内容 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); + // 操作状态 订单状态 货主名称 货主单号 物流单号 订单类型 接单机构 接单时间 货主指示人 备注 结算方式 发运日期 签收日期 + // 签收人 + // 装货区域 收货区域 收货地址 收货联系人 收货电话 物料名称 合计单品数量 货物名称 货主部门 波次单号 物料规格 物料代码 + // 生产日期 + // 失效日期 批号 服务号 序列号 货主部门 主运单号 受注编号 承运商 压缩机序号 + // 提货日期 客户订单号 出发地 目的地 运输方式 事业部 收货人 收货单位 收货电话 收货地址 实际承运商 送货方式 件数 重量 + // 签收日期 签收人 失效正常 原因 承运单号 + // 客户 提货日期 客户订单号 托运单号(提货单号) 提货单位 起运地址(提货地址) 起运城市(开始城市) 运输方式 收货单位 收货人 + // 收货城市 收货地址 件数 重量 体积 备注1 备注2 + for (int i = 1; i < sheet.getRows(); i++) { + Date thrq = null; + Contact toContacts = new Contact(); + String lxr = null;// 联系人 + String phone = null;// 电话 + String kh = sheet.getCell(0, i).getContents();// 客户 + String pp = sheet.getCell(1, i).getContents();// 品牌 + String thDate = sheet.getCell(2, i).getContents();// 开单日期 + + String customerOrderNO = sheet.getCell(3, i).getContents();// 客户订单号 + String tydh = sheet.getCell(4, i).getContents();// 托运单号 + String thdw = sheet.getCell(5, i).getContents();// 提货单位 + String thdz = sheet.getCell(6, i).getContents();// 提货地址 + String zhqy = sheet.getCell(7, i).getContents();// 装货区域-出发地 + String ysfs = sheet.getCell(8, i).getContents();// 运输方式 + String shdw = sheet.getCell(9, i).getContents();// 收货单位 + String toLinkman = sheet.getCell(10, i).getContents();// 收货人 + String lxfs = sheet.getCell(11, i).getContents();// 收货人联系方式 + String shqy = sheet.getCell(12, i).getContents();// 收货城市-目的地 + String shdz = sheet.getCell(13, i).getContents();// 收货地址 + String quantity = sheet.getCell(14, i).getContents();// 件数 + String weight = sheet.getCell(15, i).getContents();// 重量 + String volume = sheet.getCell(16, i).getContents();// 体积 + String hz = sheet.getCell(17, i).getContents().equals("") ? "0" + : sheet.getCell(17, i).getContents();// 货值 + String bz1 = sheet.getCell(18, i).getContents();// 备注1 + String bz2 = sheet.getCell(19, i).getContents();// 备注2 + // 客户 + List organizations = this.commonDao.findByQuery( + "from Organization o where o.name=:name ", + new String[] { "name" }, new Object[] { kh }); + Organization org = null; + if (organizations.size() > 0) { + org = organizations.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行,客户不存在!"); + } + List os = commonDao + .findByQuery( + " from Order o where o.consignor.id=:consignorId and o.customerOrderNO=:customerOrderNO ", + new String[] { "consignorId", "customerOrderNO" }, + new Object[] { org.getId(), customerOrderNO }); + + Order order = new Order(); + if (os.size() > 0) { + order = os.get(0); + if (order.getVolume() == 0) { + // order.setVolume(Double.parseDouble(volume)); + // this.commonDao.store(order); + // System.out.println("为0的序号:"+customerOrderNO+i); + } + } + System.out.println(i + "======" + customerOrderNO + "===体积=" + + volume); + } } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -5591,316 +6312,349 @@ public class DefaultOrderManager extends DefaultBaseManager implements e.printStackTrace(); } } - @Override//通用订单导入模版 - public void importCurrencyOrder(File file,double v) { + + @Override + // 通用订单导入模版 + public void importCurrencyOrder(File file, double v) { try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf2=new SimpleDateFormat("yyyy/MM/dd HH:mm"); - SimpleDateFormat sdf1=new SimpleDateFormat("yyyy/MM/dd HH:mm"); - //客户 提货日期 客户订单号 托运单号(提货单号) 提货单位 起运地址(提货地址) 起运城市(开始城市) 运输方式 收货单位 收货人 收货城市 收货地址 件数 重量 体积 备注1 备注2 - for (int i = 1; i organizations= this.commonDao.findByQuery("from Organization o where o.name=:name ", - new String[]{"name"},new Object[]{kh}); - Organization org=null; - if(organizations.size()>0){ - org=organizations.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,客户不存在!"); - } - List os = commonDao.findByQuery(" from Order o where o.consignor.id=:consignorId and o.customerOrderNO=:customerOrderNO ", - new String[] { "consignorId","customerOrderNO"},new Object[] {org.getId(),customerOrderNO}); - if(customerOrderNO!=null&&os.size()>0&&!customerOrderNO.equals("")){ - throw new BusinessException("第"+(i+1)+"行,客户订单号"+customerOrderNO+"已存在"); - } - //起运城市 - City fromCity=null; - if(zhqy!=null&&!zhqy.equals("")){ - List fcs= this.commonDao.findByQuery("from City c where c.name like '"+zhqy+"%'"); - if(fcs.size()>0){ - fromCity=fcs.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,起运城市"+zhqy+"没找到"); - } - }else{ - throw new BusinessException("第"+(i+1)+"行,起运城市不能为空!"); - } - //收货城市 - City toCity=null; - if(!shqy.equals("")&&shqy!=null){ - shqy=shqy.trim(); - List tcs= this.commonDao.findByQuery("from City c where c.name like '"+shqy+"%'"); - if(tcs.size()>0){ - toCity=tcs.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,收货城市"+shqy+"没找到"); - } - } - /*//承运商 - Organization carrier=null; - if(!cys.equals("")&&cys!=null){ - cys=cys.trim(); - List carriers= this.commonDao.findByQuery("from Organization org where org.bePlatForm=false and org.beCustomer=false and org.shortName like '%" + cys + "%'", - new String[]{},new Object[]{}); - if(carriers.size()>0){ - carrier=carriers.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,承运商"+cys+"没找到"); - } - }*/ - - Order order=new Order(); - - //提货单位 - if(thdw==null || thdw.equals("")) { - order.setFromLocation(null); - }else { - List fromLocations=this.commonDao.findByQuery("from TransLocation l where l.name=:name", - new String[]{"name"},new Object[]{thdw}); - if(fromLocations.size()>0){ - TransLocation fromLocation=fromLocations.get(0); - fromContact=fromLocation.getContact(); - if(fromContact!=null){ - order.setFromContact(fromContact); - order.getFromContact().setLinkman(fromContact.getLinkman()); - order.getFromContact().setPhone(fromContact.getPhone()); - order.getFromContact().setAddress(fromContact.getAddress()); - } - order.setFromCityCountiy(fromLocation.getCity()); - order.setFromLocation(fromLocation); - order.setFromName(fromLocation.getName());//提货单位 - order.setCargoType(fromLocation.getWorkphone());//办事处手机号 - - }else { - Contact fromContacts=new Contact(); - fromContacts.setAddress(thdz);//提货地址 - order.setFromContact(fromContacts); - order.setFromName(thdw);//提货单位 - } - } - order.setVolumeThree(v); - if(shdw==null ||shdw.equals("")) { - order.setToLocation(null); - }else { - List toLocations=this.commonDao.findByQuery("from TransLocation l where l.name=:name", - new String[]{"name"},new Object[]{shdw}); - if(toLocations.size()>0){ - TransLocation toLocation=toLocations.get(0); - toContact=toLocation.getContact(); - if(toContact!=null){ - order.setToContact(toContact); - order.getToContact().setLinkman(toContact.getLinkman()); - order.getToContact().setPhone(toContact.getPhone()); - order.getToContact().setAddress(toContact.getAddress()); - } - order.setToCityCountiy(toLocation.getCity()); - order.setToLocation(toLocation); - order.setToName(toLocation.getName());//收货单位 - }else { - order.setToName(shdw);//收货单位 -// toContacts=new Contact(); - toContacts.setAddress(shdz);//收货地址 - toContacts.setLinkman(toLinkman); - toContacts.setPhone(lxfs);//联系方式 - order.setToContact(toContacts); - - } - - } - - if(toLinkman==null || toLinkman.equals("")){ - - - }else{ - String [] strs = toLinkman.split("[/]");//杜鹏 /17600504443 - boolean status = toLinkman.contains("/"); - if(status){ - lxr=strs[0];//联系人 - phone=strs[1];//电话 - toContacts.setLinkman(lxr+"/"+phone);//收货人 - toContacts.setPhone(lxfs);//电话 - }else{ - toContacts.setLinkman(toLinkman); - } - - //order.getToContact().setLinkman(toContact.getLinkman()); - } - - order.setToCity(toCity); - if(shqy.equals("")||shqy==null){ - order.setToCity(fromCity); - }else{ - order.setToCity(toCity); - - } - - //计费车型 - VehicleType vehicleType=null; - List VehicleTypes = commonDao.findByQuery(" from VehicleType d where 1=1 and d.name=:name and d.disabled=0 and d.beContractVehicle=1 ", - new String[] { "name"},new Object[] {jfcx.trim()}); - if(VehicleTypes.size()>0){ - vehicleType=VehicleTypes.get(0); - order.setExtends1(vehicleType); - } - - order.setConsignor(org);//客户 - order.setInvName(pp);//品牌 - order.setPlanFromDate(thrq);//提货日期 - order.setCustomerOrderNO(customerOrderNO);//客户订单号 - order.setRelateBill1(tydh);//托运单号 - order.setOrderDate(thrq);//开单时间 - order.setShipmentMethod(ysfs);//运输方式 - order.setFromCity(fromCity); - order.setFromCityCountiy(fromCity); - order.setToCityCountiy(toCity); - if(quantity==null || quantity.equals("")) { - order.setQuantity(0); - }else{ - try { - order.setQuantity(Double.parseDouble(quantity));//数量 + try { + NumberCell weightCell = (NumberCell) sheet.getCell(18, i); + weight = weightCell.getValue(); + } catch (Exception e) { + throw new BusinessException("第" + (i + 1) + "行,重量格式错误!"); + } + double volume = 0; + try { + NumberCell volumeCell = (NumberCell) sheet.getCell(19, i); + volume = volumeCell.getValue(); + } catch (Exception e) { + throw new BusinessException("第" + (i + 1) + "行,体积格式错误!"); + } + String hz = sheet.getCell(20, i).getContents().equals("") ? "0" + : sheet.getCell(20, i).getContents();// 货值 + String bz1 = sheet.getCell(21, i).getContents();// 备注1 + String bz2 = sheet.getCell(22, i).getContents();// 备注2 + String jfcx = sheet.getCell(23, i).getContents();// 计费车型 + if (kh.equals("宇鑫专车")) { + jfcx = sheet.getCell(23, i).getContents();// 计费车型 + } + if (ysfs == null || ysfs.equals("")) { + throw new BusinessException("第" + (i + 1) + "行,运输方式不能为空!"); + } + + Contact toContact = null; + Contact fromContact = null; + Item item = null; + PackageUnit packageUnit = null; + if (ysfs.equals("普运") || ysfs.equals("汽运")) { + ysfs = "TRUCK"; + } else if (ysfs.equals("空运")) { + ysfs = "AIR"; + } else if (ysfs.equals("快运")) { + ysfs = "RAILWAY"; + } else if (ysfs.equals("快递")) { + ysfs = "ZERO_SINGLE"; + } else if (ysfs.equals("加急")) { + ysfs = "URGENT"; + } else if (ysfs.equals("专车")) { + ysfs = "SPECIAL_CAR"; + } else if (ysfs.equals("空运加急")) { + ysfs = "AIR_URGENT"; + } else if (ysfs.equals("高铁")) { + ysfs = "HIGHWAY"; + } else if (ysfs.equals("夜配")) { + ysfs = "NIGHT_MATH"; + } else { + ysfs = "TRUCK"; + } + + if (zhqy == null || zhqy.equals("")) { + throw new BusinessException("第" + (i + 1) + "行,起运城市不能为空!"); + } else { + zhqy = zhqy.trim(); + } + // 客户 + List organizations = this.commonDao.findByQuery( + "from Organization o where o.name=:name ", + new String[] { "name" }, new Object[] { kh }); + Organization org = null; + if (organizations.size() > 0) { + org = organizations.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行,客户不存在!"); + } + List os = commonDao + .findByQuery( + " from Order o where o.consignor.id=:consignorId and o.customerOrderNO=:customerOrderNO ", + new String[] { "consignorId", "customerOrderNO" }, + new Object[] { org.getId(), customerOrderNO }); + if (customerOrderNO != null && os.size() > 0 + && !customerOrderNO.equals("")) { + throw new BusinessException("第" + (i + 1) + "行,客户订单号" + + customerOrderNO + "已存在"); + } + // 起运城市 + City fromCity = null; + if (zhqy != null && !zhqy.equals("")) { + List fcs = this.commonDao + .findByQuery("from City c where c.name like '" + + zhqy + "%'"); + if (fcs.size() > 0) { + fromCity = fcs.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行,起运城市" + + zhqy + "没找到"); + } + } else { + throw new BusinessException("第" + (i + 1) + "行,起运城市不能为空!"); + } + // 收货城市 + City toCity = null; + if (!shqy.equals("") && shqy != null) { + shqy = shqy.trim(); + List tcs = this.commonDao + .findByQuery("from City c where c.name like '" + + shqy + "%'"); + if (tcs.size() > 0) { + toCity = tcs.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行,收货城市" + + shqy + "没找到"); + } + } + /* + * //承运商 Organization carrier=null; + * if(!cys.equals("")&&cys!=null){ cys=cys.trim(); + * List carriers= this.commonDao.findByQuery( + * "from Organization org where org.bePlatForm=false and org.beCustomer=false and org.shortName like '%" + * + cys + "%'", new String[]{},new Object[]{}); + * if(carriers.size()>0){ carrier=carriers.get(0); }else{ throw + * new BusinessException("第"+(i+1)+"行,承运商"+cys+"没找到"); } } + */ + + Order order = new Order(); + + // 提货单位 + if (thdw == null || thdw.equals("")) { + order.setFromLocation(null); + } else { + List fromLocations = this.commonDao + .findByQuery( + "from TransLocation l where l.name=:name", + new String[] { "name" }, + new Object[] { thdw }); + if (fromLocations.size() > 0) { + TransLocation fromLocation = fromLocations.get(0); + fromContact = fromLocation.getContact(); + if (fromContact != null) { + order.setFromContact(fromContact); + order.getFromContact().setLinkman( + fromContact.getLinkman()); + order.getFromContact().setPhone( + fromContact.getPhone()); + order.getFromContact().setAddress( + fromContact.getAddress()); + } + order.setFromCityCountiy(fromLocation.getCity()); + order.setFromLocation(fromLocation); + order.setFromName(fromLocation.getName());// 提货单位 + order.setCargoType(fromLocation.getWorkphone());// 办事处手机号 + + } else { + Contact fromContacts = new Contact(); + fromContacts.setAddress(thdz);// 提货地址 + order.setFromContact(fromContacts); + order.setFromName(thdw);// 提货单位 + } + } + order.setVolumeThree(v); + if (shdw == null || shdw.equals("")) { + order.setToLocation(null); + } else { + List toLocations = this.commonDao + .findByQuery( + "from TransLocation l where l.name=:name", + new String[] { "name" }, + new Object[] { shdw }); + if (toLocations.size() > 0) { + TransLocation toLocation = toLocations.get(0); + toContact = toLocation.getContact(); + if (toContact != null) { + order.setToContact(toContact); + order.getToContact().setLinkman( + toContact.getLinkman()); + order.getToContact().setPhone(toContact.getPhone()); + order.getToContact().setAddress( + toContact.getAddress()); + } + order.setToCityCountiy(toLocation.getCity()); + order.setToLocation(toLocation); + order.setToName(toLocation.getName());// 收货单位 + } else { + order.setToName(shdw);// 收货单位 + // toContacts=new Contact(); + toContacts.setAddress(shdz);// 收货地址 + toContacts.setLinkman(toLinkman); + toContacts.setPhone(lxfs);// 联系方式 + order.setToContact(toContacts); + + } + + } + + if (toLinkman == null || toLinkman.equals("")) { + + } else { + String[] strs = toLinkman.split("[/]");// 杜鹏 /17600504443 + boolean status = toLinkman.contains("/"); + if (status) { + lxr = strs[0];// 联系人 + phone = strs[1];// 电话 + toContacts.setLinkman(lxr + "/" + phone);// 收货人 + toContacts.setPhone(lxfs);// 电话 + } else { + toContacts.setLinkman(toLinkman); + } + + // order.getToContact().setLinkman(toContact.getLinkman()); + } + + order.setToCity(toCity); + if (shqy.equals("") || shqy == null) { + order.setToCity(fromCity); + } else { + order.setToCity(toCity); + + } + + // 计费车型 + VehicleType vehicleType = null; + List VehicleTypes = commonDao + .findByQuery( + " from VehicleType d where 1=1 and d.name=:name and d.disabled=0 and d.beContractVehicle=1 ", + new String[] { "name" }, + new Object[] { jfcx.trim() }); + if (VehicleTypes.size() > 0) { + vehicleType = VehicleTypes.get(0); + order.setExtends1(vehicleType); + } + + order.setConsignor(org);// 客户 + order.setInvName(pp);// 品牌 + order.setPlanFromDate(thrq);// 提货日期 + order.setCustomerOrderNO(customerOrderNO);// 客户订单号 + order.setRelateBill1(tydh);// 托运单号 + order.setOrderDate(thrq);// 开单时间 + order.setShipmentMethod(ysfs);// 运输方式 + order.setFromCity(fromCity); + order.setFromCityCountiy(fromCity); + order.setToCityCountiy(toCity); + if (quantity == null || quantity.equals("")) { + order.setQuantity(0); + } else { + try { + order.setQuantity(Double.parseDouble(quantity));// 数量 } catch (Exception e) { - throw new BusinessException("第"+(i+1)+"行,数量类型错误!"); + throw new BusinessException("第" + (i + 1) + "行,数量类型错误!"); } - - } - order.setWeight(DoubleUtils.formatByPrecision(weight,5));//重量 - order.setVolume(DoubleUtils.formatByPrecision(volume,7));//数量 - //判断订单编号是否重复 - String ddbh=""; - while(true){ - ddbh=codeManager.generateLegsCode(PlatFormHolder.getPlatForm().getCode()); - List Orders= this.commonDao.findByQuery("from Order o where o.relateBill3='"+ddbh+"'"); - if(Orders.size()<=0){ - break; - } - } -// if(Orders.size()>0){ -// throw new BusinessException("第"+(i+1)+"行,订单编号已重复,请重新导入!"); -// }else{ -// order.setRelateBill3(ddbh); -// } - order.setRelateBill3(ddbh); - try { - order.setPredictFee(DoubleUtils.formatByPrecision(Double.parseDouble(hz),5)); - } catch (Exception e) { - throw new BusinessException("第"+(i+1)+"行,货值类型错误!"); + } - order.setCode(codeManager.generateItemCode()); - order.setStatus(OrderStatus.AVAILABLE);//录入中 - order.setGroupNo(codeManager.generateGroupNo()); - order.setCash(0); - order.setOperatorDate(new Date()); - order.setCreateTime(new Date()); - order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); - order.setContractor(PlatFormHolder.getPlatForm()); - order.setOtherStatus(FeeStatus.OPEN); - order.setUnit("件");//单位 - order.setSuperviseType(SuperviseType.UNSUPERVISE); - order.setPaymentMethod("月付"); - order.setUnit(MeasureUnit.TON_CUBIC);//默认计量单位 - order.setDeliveryMode("送货上门");//送货方式 - order.setDescription(bz1);//提货要求 - order.setDescription1(bz2);//送货要求和备注 - order.setOilsQty(Double.parseDouble(oilsQty)); - order.setTyreQty(Double.parseDouble(tyreQty)); - order.setYhpQty(Double.parseDouble(yhpQty)); - this.commonDao.store(order); - //orderPrescription(order);//时效 - //refreshQuantity(order.getId()); - System.out.println(i); - } + order.setWeight(DoubleUtils.formatByPrecision(weight, 5));// 重量 + order.setVolume(DoubleUtils.formatByPrecision(volume, 7));// 数量 + // 判断订单编号是否重复 + String ddbh = ""; + while (true) { + ddbh = codeManager.generateLegsCode(PlatFormHolder + .getPlatForm().getCode()); + List Orders = this.commonDao + .findByQuery("from Order o where o.relateBill3='" + + ddbh + "'"); + if (Orders.size() <= 0) { + break; + } + } + // if(Orders.size()>0){ + // throw new BusinessException("第"+(i+1)+"行,订单编号已重复,请重新导入!"); + // }else{ + // order.setRelateBill3(ddbh); + // } + order.setRelateBill3(ddbh); + try { + order.setPredictFee(DoubleUtils.formatByPrecision( + Double.parseDouble(hz), 5)); + } catch (Exception e) { + throw new BusinessException("第" + (i + 1) + "行,货值类型错误!"); + } + order.setCode(codeManager.generateItemCode()); + order.setStatus(OrderStatus.AVAILABLE);// 录入中 + order.setGroupNo(codeManager.generateGroupNo()); + order.setCash(0); + order.setOperatorDate(new Date()); + order.setCreateTime(new Date()); + order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); + order.setContractor(PlatFormHolder.getPlatForm()); + order.setOtherStatus(FeeStatus.OPEN); + order.setUnit("件");// 单位 + order.setSuperviseType(SuperviseType.UNSUPERVISE); + order.setPaymentMethod("月付"); + order.setUnit(MeasureUnit.TON_CUBIC);// 默认计量单位 + order.setDeliveryMode("送货上门");// 送货方式 + order.setDescription(bz1);// 提货要求 + order.setDescription1(bz2);// 送货要求和备注 + order.setOilsQty(Double.parseDouble(oilsQty)); + order.setTyreQty(Double.parseDouble(tyreQty)); + order.setYhpQty(Double.parseDouble(yhpQty)); + this.commonDao.store(order); + // orderPrescription(order);//时效 + // refreshQuantity(order.getId()); + System.out.println(i); + } } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -5909,14 +6663,13 @@ public class DefaultOrderManager extends DefaultBaseManager implements e.printStackTrace(); } } - - - public void addPack( Pack pack){ - /*Order order =commonDao.load(Order.class, orderID); - if(pack.isNew()){ - pack.setOrder(order); - }*/ - if(pack.isNew()){ + + public void addPack(Pack pack) { + /* + * Order order =commonDao.load(Order.class, orderID); if(pack.isNew()){ + * pack.setOrder(order); } + */ + if (pack.isNew()) { pack.setBoxbarCode(codeManager.packCode("")); UserLoginLog u = new UserLoginLog(); pack.setCreatPeople(UserHolder.getUser().getName()); @@ -5924,38 +6677,46 @@ public class DefaultOrderManager extends DefaultBaseManager implements pack.setPlatform(PlatFormHolder.getPlatForm()); } commonDao.store(pack); - operationHisManager.storeOperationHis(pack.getId(),pack.getCode(), null, null, "打包管理", "添加",null,null,pack.getQuantity(),pack.getWeight(),pack.getVolume(),0, null, "TMS"); - List packDetails = commonDao.findByQuery(" from PackDetail pd where pd.pack.id=:id ", - new String[] { "id"},new Object[] { pack.getId()}); - for(PackDetail pd:packDetails){ - refPackOrder(pd.getOrder());//刷新订单箱数 + operationHisManager.storeOperationHis(pack.getId(), pack.getCode(), + null, null, "打包管理", "添加", null, null, pack.getQuantity(), + pack.getWeight(), pack.getVolume(), 0, null, "TMS"); + List packDetails = commonDao.findByQuery( + " from PackDetail pd where pd.pack.id=:id ", + new String[] { "id" }, new Object[] { pack.getId() }); + for (PackDetail pd : packDetails) { + refPackOrder(pd.getOrder());// 刷新订单箱数 } - refPack(pack);//刷打包数量 - /* refOrder(order);*/ - + refPack(pack);// 刷打包数量 + /* refOrder(order); */ + } - public void deletePackDetail(Long packid, List ids){ - Pack p=commonDao.load(Pack.class, packid); - for(Long id:ids){ - PackDetail pd=commonDao.load(PackDetail.class, id); - Order o=pd.getOrder(); - OrderDetail od=pd.getOrderDetail(); - od.setPackQuantity(od.getPackQuantity()-pd.getPackQuantity()); - operationHisManager.storeOperationHis(packid,p.getBoxbarCode(), id, od.getMaterielCode(), "打包管理", "移除打包记录",null,null,od.getQuantity(),0,0,0, null, "TMS"); + + public void deletePackDetail(Long packid, List ids) { + Pack p = commonDao.load(Pack.class, packid); + for (Long id : ids) { + PackDetail pd = commonDao.load(PackDetail.class, id); + Order o = pd.getOrder(); + OrderDetail od = pd.getOrderDetail(); + od.setPackQuantity(od.getPackQuantity() - pd.getPackQuantity()); + operationHisManager.storeOperationHis(packid, p.getBoxbarCode(), + id, od.getMaterielCode(), "打包管理", "移除打包记录", null, null, + od.getQuantity(), 0, 0, 0, null, "TMS"); commonDao.delete(pd); - refPackOrder(o);//刷新订单箱数 + refPackOrder(o);// 刷新订单箱数 } refPack(p); } - public void addPackDetail(Long packid, Map map){ - Pack p=commonDao.load(Pack.class, packid); + + public void addPackDetail(Long packid, Map map) { + Pack p = commonDao.load(Pack.class, packid); Set> itor = map.entrySet(); for (Map.Entry me : itor) { - OrderDetail od=commonDao.load(OrderDetail.class, me.getKey()); - Double importance = Double.parseDouble(me.getValue().get(0).toString()); - od.setPackQuantity(od.getPackQuantity()+importance); + OrderDetail od = commonDao.load(OrderDetail.class, me.getKey()); + Double importance = Double.parseDouble(me.getValue().get(0) + .toString()); + od.setPackQuantity(od.getPackQuantity() + importance); this.commonDao.store(od); - PackDetail pd=new PackDetail(); + PackDetail pd = new PackDetail(); pd.setOrderDetail(od); pd.setPackQuantity(importance); pd.setQuantity(od.getQuantity()); @@ -5965,32 +6726,44 @@ public class DefaultOrderManager extends DefaultBaseManager implements pd.setCreationTime(new Date()); p.setDescription(od.getOrder().getRelateBill3()); commonDao.store(pd); - refPackOrder(od.getOrder());//刷新订单箱数 - refPack(p);//刷打包数量 - operationHisManager.storeOperationHis(od.getId(),od.getLot(), null, null, "打包数量为"+importance, "添加订单明细",null,null,od.getQuantity(),0,0,0, null, "TMS"); + refPackOrder(od.getOrder());// 刷新订单箱数 + refPack(p);// 刷打包数量 + operationHisManager.storeOperationHis(od.getId(), od.getLot(), + null, null, "打包数量为" + importance, "添加订单明细", null, null, + od.getQuantity(), 0, 0, 0, null, "TMS"); } } -//刷新打包数量 - public void refPack(Pack p){ - Double qty= (Double) commonDao.findByQuery("select nvl(sum(pd.packQuantity),0) from PackDetail pd where pd.pack.id=:id ", - new String[] { "id"},new Object[] { p.getId()}).get(0); + + // 刷新打包数量 + public void refPack(Pack p) { + Double qty = (Double) commonDao + .findByQuery( + "select nvl(sum(pd.packQuantity),0) from PackDetail pd where pd.pack.id=:id ", + new String[] { "id" }, new Object[] { p.getId() }).get( + 0); p.setQuantity(qty); commonDao.store(p); - + } - - public void refPackOrder(Order order){ - List objs = commonDao.findByQuery("select nvl(count(p.id),0),nvl(sum(p.weight),0),nvl(sum(p.volume),0) from Pack p where p.id in (select pd.pack.id from PackDetail pd where pd.order.id=:orderId)", - new String[] { "orderId"},new Object[] { order.getId()}); - if(objs.size()>0){ - Object[] obj=objs.get(0); - Double qty=(Double) commonDao.findByQuery("select nvl(sum(d.quantity-d.packQuantity),0) from OrderDetail d where d.order.id=:orderId", - new String[] { "orderId"},new Object[] {order.getId()}).get(0); - order.setQuantityTwo(Double.parseDouble(obj[0].toString())+qty); - order.setWeightTwo((Double)obj[1]); - order.setVolumeTwo((Double)obj[2]); + + public void refPackOrder(Order order) { + List objs = commonDao + .findByQuery( + "select nvl(count(p.id),0),nvl(sum(p.weight),0),nvl(sum(p.volume),0) from Pack p where p.id in (select pd.pack.id from PackDetail pd where pd.order.id=:orderId)", + new String[] { "orderId" }, + new Object[] { order.getId() }); + if (objs.size() > 0) { + Object[] obj = objs.get(0); + Double qty = (Double) commonDao + .findByQuery( + "select nvl(sum(d.quantity-d.packQuantity),0) from OrderDetail d where d.order.id=:orderId", + new String[] { "orderId" }, + new Object[] { order.getId() }).get(0); + order.setQuantityTwo(Double.parseDouble(obj[0].toString()) + qty); + order.setWeightTwo((Double) obj[1]); + order.setVolumeTwo((Double) obj[2]); order.setContainerBill(Boolean.TRUE); - }else{ + } else { order.setQuantityTwo(order.getQuantity()); order.setWeightTwo(order.getWeight()); order.setVolumeTwo(order.getVolume()); @@ -5998,94 +6771,107 @@ public class DefaultOrderManager extends DefaultBaseManager implements } commonDao.store(order); } - public void deletePack(List ids){ - /*Order order =commonDao.load(Order.class, orderID);*/ - for(Long id:ids){ - Pack pack=commonDao.load(Pack.class, id); - List pds = commonDao.findByQuery(" from PackDetail pd where pd.pack.id=:packid ", - new String[] { "packid"},new Object[] { pack.getId()}); - for(PackDetail pd:pds){ - Order o=pd.getOrder(); - OrderDetail od=pd.getOrderDetail(); - od.setPackQuantity(od.getPackQuantity()-pd.getPackQuantity()); - commonDao.delete(pd); - refPackOrder(od.getOrder());//刷新订单箱数 - } - commonDao.delete(pack); - operationHisManager.storeOperationHis(pack.getId(),pack.getBoxbarCode(), null, null, "打包管理", "删除",null,null,pack.getQuantity(),pack.getWeight(),pack.getVolume(),0, null, "TMS"); + + public void deletePack(List ids) { + /* Order order =commonDao.load(Order.class, orderID); */ + for (Long id : ids) { + Pack pack = commonDao.load(Pack.class, id); + List pds = commonDao.findByQuery( + " from PackDetail pd where pd.pack.id=:packid ", + new String[] { "packid" }, new Object[] { pack.getId() }); + for (PackDetail pd : pds) { + Order o = pd.getOrder(); + OrderDetail od = pd.getOrderDetail(); + od.setPackQuantity(od.getPackQuantity() - pd.getPackQuantity()); + commonDao.delete(pd); + refPackOrder(od.getOrder());// 刷新订单箱数 } - /*refOrder(order);*/ + commonDao.delete(pack); + operationHisManager.storeOperationHis(pack.getId(), + pack.getBoxbarCode(), null, null, "打包管理", "删除", null, null, + pack.getQuantity(), pack.getWeight(), pack.getVolume(), 0, + null, "TMS"); + } + /* refOrder(order); */ } - - public void orderPrescription(Order order){ - if( order.getConsignor()!=null&&order.getFromCity()!=null&&order.getToCity()!=null){ - String hql="from RouteFee r where r.customer.id="+order.getConsignor().getId() - +" and r.fromCity.id="+order.getFromCity().getId() - +" and r.toCity.id="+order.getToCity().getId(); - String method=order.getShipmentMethod(); - double sx=24; - List objs = commonDao.findByQuery(hql); - //DateUtil.addDayToDate(DateUtil.getFirstHourOFDay(order.getPlanFromDate()),1); - if(objs.size()>0){ - if(objs.size()>1){ - objs = commonDao.findByQuery(hql+" and r.projectName='"+order.getToName()+"'"); + + public void orderPrescription(Order order) { + if (order.getConsignor() != null && order.getFromCity() != null + && order.getToCity() != null) { + String hql = "from RouteFee r where r.customer.id=" + + order.getConsignor().getId() + " and r.fromCity.id=" + + order.getFromCity().getId() + " and r.toCity.id=" + + order.getToCity().getId(); + String method = order.getShipmentMethod(); + double sx = 24; + List objs = commonDao.findByQuery(hql); + // DateUtil.addDayToDate(DateUtil.getFirstHourOFDay(order.getPlanFromDate()),1); + if (objs.size() > 0) { + if (objs.size() > 1) { + objs = commonDao.findByQuery(hql + " and r.projectName='" + + order.getToName() + "'"); } - if(objs.size()>0){ - RouteFee r=objs.get(0); - if(method.equals(ShipmentMethod.TRUCK)||method.equals(ShipmentMethod.TRUCK_DF)){ - sx=r.getTransportationAging(); + if (objs.size() > 0) { + RouteFee r = objs.get(0); + if (method.equals(ShipmentMethod.TRUCK) + || method.equals(ShipmentMethod.TRUCK_DF)) { + sx = r.getTransportationAging(); } order.setRouteFee(r); - if(sx>0){ + if (sx > 0) { Calendar calendar2 = Calendar.getInstance(); - if(r.isBeCreate()){ + if (r.isBeCreate()) { calendar2.setTime(order.getCreateTime()); - }else{ + } else { calendar2.setTime(order.getPlanFromDate()); - sx=sx+24; + sx = sx + 24; } - Date d=calendar2.getTime(); - order.setPlanArriveTime(DateUtil.addHourToDate(d, sx)); + Date d = calendar2.getTime(); + order.setPlanArriveTime(DateUtil.addHourToDate(d, sx)); } order.setExpectLicense(String.valueOf(sx)); commonDao.store(order); } - }else{ + } else { return; } - + } } - - //客戶自提 + + // 客戶自提 @Override public void customerSelf(List ids) { for (Long id : ids) { Order order = this.load(Order.class, id); - order.setStatus(OrderStatus.ARRIVED);//已到货 - - order.setArriveTime(new Date());//写入运抵时间 + order.setStatus(OrderStatus.ARRIVED);// 已到货 + + order.setArriveTime(new Date());// 写入运抵时间 order.setSelfDelivery(true);// 是提货 - operationHisManager.storeOperationHis(order.getId(),order.getRelateBill3(), null, null, "订单管理", "客户自提",null,null,order.getQuantity(),order.getWeight(),order.getVolume(),0, null, "TMS"); - + operationHisManager.storeOperationHis(order.getId(), + order.getRelateBill3(), null, null, "订单管理", "客户自提", null, + null, order.getQuantity(), order.getWeight(), + order.getVolume(), 0, null, "TMS"); + } - + } + @Override public void odpack(Pack pack, List ids, Map map) { - if(pack.isNew()){ + if (pack.isNew()) { pack.setBoxbarCode(codeManager.packCode("")); UserLoginLog u = new UserLoginLog(); pack.setCreatPeople(UserHolder.getUser().getName()); pack.setCreatTime(new Date()); } commonDao.store(pack); - - Pack p=commonDao.load(Pack.class, pack.getId()); + + Pack p = commonDao.load(Pack.class, pack.getId()); Set> itor = map.entrySet(); for (Map.Entry me : itor) { - OrderDetail od=commonDao.load(OrderDetail.class, me.getKey()); - PackDetail pd=new PackDetail(); + OrderDetail od = commonDao.load(OrderDetail.class, me.getKey()); + PackDetail pd = new PackDetail(); pd.setOrderDetail(od); pd.setQuantity(od.getQuantity()); pd.setPack(p); @@ -6093,316 +6879,368 @@ public class DefaultOrderManager extends DefaultBaseManager implements pd.setCreationPeople(UserHolder.getUser().getName()); pd.setCreationTime(new Date()); p.setDescription(od.getOrder().getRelateBill3()); - commonDao.store (pd); + commonDao.store(pd); } } - - //刷新高理订单的 重量 体积 数量 + + // 刷新高理订单的 重量 体积 数量 public void Refresh(Long id) { Order orders = commonDao.load(Order.class, id); - List orderDetails = commonDao.findByQuery("select nvl(sum(o.quantity),0),nvl(sum(o.weight),0),nvl(sum(o.volume),0) from OrderDetail o where o.order.id=:id ", - new String[] { "id"},new Object[] {id}); - if(orderDetails.size()>0){ - Object[] obj=orderDetails.get(0); - orders.setQuantity((Double)obj[0]); - orders.setWeight((Double)obj[1]); - orders.setVolume(DoubleUtils.formatByPrecision((Double)obj[2],7)); - } + List orderDetails = commonDao + .findByQuery( + "select nvl(sum(o.quantity),0),nvl(sum(o.weight),0),nvl(sum(o.volume),0) from OrderDetail o where o.order.id=:id ", + new String[] { "id" }, new Object[] { id }); + if (orderDetails.size() > 0) { + Object[] obj = orderDetails.get(0); + orders.setQuantity((Double) obj[0]); + orders.setWeight((Double) obj[1]); + orders.setVolume(DoubleUtils.formatByPrecision((Double) obj[2], 7)); + } commonDao.store(orders); } - + @Override - public void addOrderGaoliDetail(Long id,OrderDetail orderDetail) { - Order orders = commonDao.load(Order.class, id); - if (orderDetail.isNew()) { - orders.addOrderDetail(orderDetail); - } - if(orders.getToContact()!=null){ - TransLocation transLocation=null; - List TransLocations = commonDao.findByQuery(" from TransLocation t where t.name=:name ", - new String[] { "name"},new Object[] {orders.getToContact().getLinkman()}); - if(TransLocations.size()>0){ - transLocation=TransLocations.get(0); - if(orderDetail.getBusinessDepartment().equals("NTC")){ - orderDetail.setVolume(orderDetail.getQuantity()*transLocation.getLongitude()); - }else if(orderDetail.getBusinessDepartment().equals("PTC")){ - orderDetail.setVolume(orderDetail.getQuantity()*transLocation.getLatitude()); - } - } - } - commonDao.store(orderDetail); - Refresh(id); + public void addOrderGaoliDetail(Long id, OrderDetail orderDetail) { + Order orders = commonDao.load(Order.class, id); + if (orderDetail.isNew()) { + orders.addOrderDetail(orderDetail); + } + if (orders.getToContact() != null) { + TransLocation transLocation = null; + List TransLocations = commonDao.findByQuery( + " from TransLocation t where t.name=:name ", + new String[] { "name" }, new Object[] { orders + .getToContact().getLinkman() }); + if (TransLocations.size() > 0) { + transLocation = TransLocations.get(0); + if (orderDetail.getBusinessDepartment().equals("NTC")) { + orderDetail.setVolume(orderDetail.getQuantity() + * transLocation.getLongitude()); + } else if (orderDetail.getBusinessDepartment().equals("PTC")) { + orderDetail.setVolume(orderDetail.getQuantity() + * transLocation.getLatitude()); + } + } + } + commonDao.store(orderDetail); + Refresh(id); } + @Override public void deleteOrderGaoliDetail(List ids) { - Long orderId=null; + Long orderId = null; for (Long id : ids) { - OrderDetail s=commonDao.load(OrderDetail.class,id ); - orderId=s.getOrder().getId(); - commonDao.delete(s); + OrderDetail s = commonDao.load(OrderDetail.class, id); + orderId = s.getOrder().getId(); + commonDao.delete(s); } - if(orderId!=null){ - Refresh(orderId); + if (orderId != null) { + Refresh(orderId); } - + } + @Override public void Remarksregistration(String description, List ids) { - for(Long id : ids) { - Order order=this.load(Order.class, id); + for (Long id : ids) { + Order order = this.load(Order.class, id); order.setDescription5(description); commonDao.store(order); } - + } - - @Override//大众订单导入 + + @Override + // 大众订单导入 public void importPublicOrder(File file) { try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf2=new SimpleDateFormat("yyyy/MM/dd HH:mm"); - SimpleDateFormat sdf1=new SimpleDateFormat("yyyy/MM/dd HH:mm"); - //货主名称 物流单号 发货地址 销售清单号 货物价值 接单时间 - //打包件 打包体 打包重 运输方式 客户代码 装货区域 收货区域 - //收货地址 收货联系 收货电话 物料名称 波次 波次代码 - for (int i = 1; i organizations= this.commonDao.findByQuery("from Organization o where o.shortName=:name or o.code=:code", - new String[]{"name","code"},new Object[]{consignorName,consignorName}); - Organization org=new Organization(); - if(organizations.size()>0){ - org=organizations.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,客户不存在!"); - } - List os = commonDao.findByQuery(" from Order o where o.consignor.id=:consignorId and o.customerOrderNO like:customerOrderNO ", - new String[] { "consignorId","customerOrderNO"},new Object[] {org.getId(),xsqdh}); - if(xsqdh!=null&&os.size()>0&&!xsqdh.equals("")){ - throw new BusinessException("第"+(i+1)+"行,客户订单号"+xsqdh+"已存在"); - } - System.out.println(i+1+"==="+description3+"=="+shdws); - Order order=null; -// List os2 = commonDao.findByQuery(" from Order o where o.consignor.id=:consignorId and o.description3=:description3 and o.toName=:toName and o.status=:status", -// new String[] { "consignorId","description3","toName","status"},new Object[] {org.getId(),description3,shdws,OrderStatus.AVAILABLE}); - List os2 = commonDao.findByQuery(" from Order o where o.consignor.id=:consignorId and o.toCode=:toCode and o.relateBill2=:relateBill2 and o.status=:status", - new String[] { "consignorId","toCode","relateBill2","status"},new Object[] {org.getId(),khdm,description3,OrderStatus.AVAILABLE}); - - if(os2.size()>0){ - order=os2.get(0); - order.setCustomerOrderNO(order.getCustomerOrderNO()+","+xsqdh); - order.setPredictFee(DoubleUtils.formatByPrecision((predictFee+order.getPredictFee()),5)); - order.setQuantity(DoubleUtils.format2Fraction(qty+order.getQuantity())); - order.setQuantityTwo(DoubleUtils.format2Fraction(qty+order.getQuantityTwo()));//打包件数 - order.setWeight(DoubleUtils.formatByPrecision((weight+order.getWeight()),5)); - order.setWeightTwo(DoubleUtils.formatByPrecision((weight+order.getWeightTwo()),5));//打包重量 - order.setVolume(DoubleUtils.formatByPrecision((volume+order.getVolume()),7)); - order.setVolumeTwo(DoubleUtils.formatByPrecision((volume+order.getVolumeTwo()),5));//打包体积 + } + if (dbtj != null && !dbtj.equals("")) { + try { + volume = Double.valueOf(dbtj); + } catch (Exception e) { + throw new BusinessException("第" + (i + 1) + + "行,打包体积格式有误!"); + } + } + + String khdm = sheet.getCell(10, i).getContents();// 客户代码 + String shdws = sheet.getCell(11, i).getContents();// 收货单位 + String zhqy = sheet.getCell(12, i).getContents();// 装货区域 + String shqy = sheet.getCell(13, i).getContents();// 收货区域 + String shdz = sheet.getCell(14, i).getContents();// 收货地址 + String toLinkman = sheet.getCell(15, i).getContents();// 收货联系人 + String toPhone = sheet.getCell(16, i).getContents();// 收货电话 + String wlmc = sheet.getCell(17, i).getContents();// 物料名称 + String bc = sheet.getCell(18, i).getContents();// 波次 + String bcdm = sheet.getCell(19, i).getContents();// 波次代码 + if (consignorName == null || consignorName.equals("")) { + return; + } + List organizations = this.commonDao + .findByQuery( + "from Organization o where o.shortName=:name or o.code=:code", + new String[] { "name", "code" }, new Object[] { + consignorName, consignorName }); + Organization org = new Organization(); + if (organizations.size() > 0) { + org = organizations.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行,客户不存在!"); + } + List os = commonDao + .findByQuery( + " from Order o where o.consignor.id=:consignorId and o.customerOrderNO like:customerOrderNO ", + new String[] { "consignorId", "customerOrderNO" }, + new Object[] { org.getId(), xsqdh }); + if (xsqdh != null && os.size() > 0 && !xsqdh.equals("")) { + throw new BusinessException("第" + (i + 1) + "行,客户订单号" + + xsqdh + "已存在"); + } + System.out.println(i + 1 + "===" + description3 + "==" + shdws); + Order order = null; + // List os2 = + // commonDao.findByQuery(" from Order o where o.consignor.id=:consignorId and o.description3=:description3 and o.toName=:toName and o.status=:status", + // new String[] { + // "consignorId","description3","toName","status"},new Object[] + // {org.getId(),description3,shdws,OrderStatus.AVAILABLE}); + List os2 = commonDao + .findByQuery( + " from Order o where o.consignor.id=:consignorId and o.toCode=:toCode and o.relateBill2=:relateBill2 and o.status=:status", + new String[] { "consignorId", "toCode", + "relateBill2", "status" }, + new Object[] { org.getId(), khdm, description3, + OrderStatus.AVAILABLE }); + + if (os2.size() > 0) { + order = os2.get(0); + order.setCustomerOrderNO(order.getCustomerOrderNO() + "," + + xsqdh); + order.setPredictFee(DoubleUtils.formatByPrecision( + (predictFee + order.getPredictFee()), 5)); + order.setQuantity(DoubleUtils.format2Fraction(qty + + order.getQuantity())); + order.setQuantityTwo(DoubleUtils.format2Fraction(qty + + order.getQuantityTwo()));// 打包件数 + order.setWeight(DoubleUtils.formatByPrecision( + (weight + order.getWeight()), 5)); + order.setWeightTwo(DoubleUtils.formatByPrecision( + (weight + order.getWeightTwo()), 5));// 打包重量 + order.setVolume(DoubleUtils.formatByPrecision( + (volume + order.getVolume()), 7)); + order.setVolumeTwo(DoubleUtils.formatByPrecision( + (volume + order.getVolumeTwo()), 5));// 打包体积 this.commonDao.store(order); - }else{ - if(zhqy==null || zhqy.equals("")){ - throw new BusinessException("第"+(i+1)+"行,装货区域不能为空!"); - }else{ - zhqy=zhqy.trim(); - } - if(ysfs==null || ysfs.equals("")){ - throw new BusinessException("第"+(i+1)+"行,运输方式不能为空!"); - } - if(ysfs.equals("普运")||ysfs.equals("汽运")) { - ysfs="TRUCK"; - }else if(ysfs.equals("空运")) { - ysfs="AIR"; - }else if(ysfs.equals("快运")) { - ysfs="RAILWAY"; - }else if(ysfs.equals("快递")) { - ysfs="ZERO_SINGLE"; - }else if(ysfs.equals("加急")) { - ysfs="URGENT"; - }else{ - ysfs="TRUCK"; - } - City fromCity=new City(); - if(zhqy!=null&&!zhqy.equals("")){ - List fcs= this.commonDao.findByQuery("from City c where c.name = '"+zhqy+"'"); - - if(fcs.size()>0){ - fromCity=fcs.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,出发城市"+zhqy+"没找到"); - } - }else{ - throw new BusinessException("第"+(i+1)+"行,出发城市不能为空!"); - } - City toCity=new City(); - if(shqy.equals("")&&shqy==null) { - return ; - } - if(!shqy.equals("")&&shqy!=null){ - shqy=shqy.trim(); - List tcs= this.commonDao.findByQuery("from City c where c.name = '"+shqy+"'"); - if(tcs.size()>0){ - toCity=tcs.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,目标城市"+shqy+"没找到"); - } - } - order = new Order(); - order.setShipmentMethod(ysfs); - order.setConsignor(org); - order.setDescription3(description3); - order.setOrderDate(thrq); - order.setPlanFromDate(thrq); - order.setFromCity(fromCity); - order.setFromCityCountiy(fromCity); - List toLs=this.commonDao.findByQuery("from TransLocation l where l.code=:linkman ", - new String[]{"linkman"},new Object[]{khdm}); - if(toLs.size()>0){ - TransLocation toL=toLs.get(0); - order.setToLocation(toL); - order.setToCode(toL.getCode()); - if(shdws!=null&&!shdws.equals("")){ - order.setToName(toL.getName()); - } - order.setCargoType(toL.getWorkphone()); - }else{ - order.setToCode(khdm); - order.setToName(shdws); - } - order.setToCity(toCity); - if(shqy.equals("")||shqy==null){ - order.setToCity(fromCity); - order.setToCityCountiy(null); - }else{ - order.setToCity(toCity); - order.setToCityCountiy(toCity); - } - Contact toContact=new Contact(); - toContact.setAddress(shdz); - toContact.setLinkman(toLinkman); - toContact.setPhone(toPhone); - if(org.getContact()!=null&&shdz.equals("")&&toLinkman.equals("")&&toPhone.equals("")){ - toContact=org.getContact(); - } - Contact fromContact=new Contact(); - fromContact.setAddress(thdz); - order.setFromContact(fromContact); - order.setToContact(toContact); - order.setCode(codeManager.generateItemCode()); - order.setStatus(OrderStatus.AVAILABLE); - order.setGroupNo(codeManager.generateGroupNo()); - order.setRelateBill3(codeManager.generateLegsCode(PlatFormHolder.getPlatForm().getCode())); - order.setCash(0); - order.setOperatorDate(new Date()); - order.setCreateTime(new Date()); - order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); - order.setContractor(PlatFormHolder.getPlatForm()); - order.setOtherStatus(FeeStatus.OPEN); - order.setUnit("件"); - order.setSuperviseType(SuperviseType.UNSUPERVISE); - order.setPaymentMethod("月付"); - order.setDeliveryMode("送货上门"); - order.setCustomerOrderNO(xsqdh);//销售清单号 - order.setRelateBill2(description3);//波次代码 - order.setPredictRemark(bc);//波次 - order.setPredictFee(DoubleUtils.formatByPrecision(predictFee,5)); - order.setUnit(MeasureUnit.TON_CUBIC);//默认计量单位 - order.setItemName(wlmc);//物料名称 + } else { + if (zhqy == null || zhqy.equals("")) { + throw new BusinessException("第" + (i + 1) + + "行,装货区域不能为空!"); + } else { + zhqy = zhqy.trim(); + } + if (ysfs == null || ysfs.equals("")) { + throw new BusinessException("第" + (i + 1) + + "行,运输方式不能为空!"); + } + if (ysfs.equals("普运") || ysfs.equals("汽运")) { + ysfs = "TRUCK"; + } else if (ysfs.equals("空运")) { + ysfs = "AIR"; + } else if (ysfs.equals("快运")) { + ysfs = "RAILWAY"; + } else if (ysfs.equals("快递")) { + ysfs = "ZERO_SINGLE"; + } else if (ysfs.equals("加急")) { + ysfs = "URGENT"; + } else { + ysfs = "TRUCK"; + } + City fromCity = new City(); + if (zhqy != null && !zhqy.equals("")) { + List fcs = this.commonDao + .findByQuery("from City c where c.name = '" + + zhqy + "'"); + + if (fcs.size() > 0) { + fromCity = fcs.get(0); + } else { + throw new BusinessException("第" + (i + 1) + + "行,出发城市" + zhqy + "没找到"); + } + } else { + throw new BusinessException("第" + (i + 1) + + "行,出发城市不能为空!"); + } + City toCity = new City(); + if (shqy.equals("") && shqy == null) { + return; + } + if (!shqy.equals("") && shqy != null) { + shqy = shqy.trim(); + List tcs = this.commonDao + .findByQuery("from City c where c.name = '" + + shqy + "'"); + if (tcs.size() > 0) { + toCity = tcs.get(0); + } else { + throw new BusinessException("第" + (i + 1) + + "行,目标城市" + shqy + "没找到"); + } + } + order = new Order(); + order.setShipmentMethod(ysfs); + order.setConsignor(org); + order.setDescription3(description3); + order.setOrderDate(thrq); + order.setPlanFromDate(thrq); + order.setFromCity(fromCity); + order.setFromCityCountiy(fromCity); + List toLs = this.commonDao.findByQuery( + "from TransLocation l where l.code=:linkman ", + new String[] { "linkman" }, new Object[] { khdm }); + if (toLs.size() > 0) { + TransLocation toL = toLs.get(0); + order.setToLocation(toL); + order.setToCode(toL.getCode()); + if (shdws != null && !shdws.equals("")) { + order.setToName(toL.getName()); + } + order.setCargoType(toL.getWorkphone()); + } else { + order.setToCode(khdm); + order.setToName(shdws); + } + order.setToCity(toCity); + if (shqy.equals("") || shqy == null) { + order.setToCity(fromCity); + order.setToCityCountiy(null); + } else { + order.setToCity(toCity); + order.setToCityCountiy(toCity); + } + Contact toContact = new Contact(); + toContact.setAddress(shdz); + toContact.setLinkman(toLinkman); + toContact.setPhone(toPhone); + if (org.getContact() != null && shdz.equals("") + && toLinkman.equals("") && toPhone.equals("")) { + toContact = org.getContact(); + } + Contact fromContact = new Contact(); + fromContact.setAddress(thdz); + order.setFromContact(fromContact); + order.setToContact(toContact); + order.setCode(codeManager.generateItemCode()); + order.setStatus(OrderStatus.AVAILABLE); + order.setGroupNo(codeManager.generateGroupNo()); + order.setRelateBill3(codeManager + .generateLegsCode(PlatFormHolder.getPlatForm() + .getCode())); + order.setCash(0); + order.setOperatorDate(new Date()); + order.setCreateTime(new Date()); + order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); + order.setContractor(PlatFormHolder.getPlatForm()); + order.setOtherStatus(FeeStatus.OPEN); + order.setUnit("件"); + order.setSuperviseType(SuperviseType.UNSUPERVISE); + order.setPaymentMethod("月付"); + order.setDeliveryMode("送货上门"); + order.setCustomerOrderNO(xsqdh);// 销售清单号 + order.setRelateBill2(description3);// 波次代码 + order.setPredictRemark(bc);// 波次 + order.setPredictFee(DoubleUtils.formatByPrecision( + predictFee, 5)); + order.setUnit(MeasureUnit.TON_CUBIC);// 默认计量单位 + order.setItemName(wlmc);// 物料名称 order.setQuantity(qty); - order.setQuantityTwo(qty);//打包件数 - order.setWeight(DoubleUtils.formatByPrecision(weight,5)); - order.setWeightTwo(DoubleUtils.formatByPrecision(weight,5));//打包重量 - order.setVolume(DoubleUtils.formatByPrecision(volume,7)); - order.setVolumeTwo(DoubleUtils.formatByPrecision(volume,7));//打包体积 - commonDao.store(order); - System.out.println(i+1+"==="+order.getDescription3()+"=="+order.getToName()+"===="+order.getStatus()); - } - OrderDetail orderDetail=null; - String hql="from OrderDetail d where 1=1 and d.order.id="+order.getId(); - if(xsqdh!=null&&!xsqdh.equals("")){ - hql+=" and d.salesList='"+xsqdh+"'"; - } - List orderDetails= this.commonDao.findByQuery(hql); - if(orderDetails.size()>0){ - orderDetail=orderDetails.get(0); - orderDetail.setSalesList(xsqdh); - orderDetail.setSplitQuantity(predictFee); - commonDao.store(orderDetail); - } else{ - orderDetail=new OrderDetail(); - orderDetail.setOrder(order); - orderDetail.setSalesList(xsqdh); - orderDetail.setSplitQuantity(predictFee); - commonDao.store(orderDetail); - } - //orderPrescription(order);//时效 - //refreshQuantity(order.getId()); - System.out.println(i); - } - - + order.setQuantityTwo(qty);// 打包件数 + order.setWeight(DoubleUtils.formatByPrecision(weight, 5)); + order.setWeightTwo(DoubleUtils.formatByPrecision(weight, 5));// 打包重量 + order.setVolume(DoubleUtils.formatByPrecision(volume, 7)); + order.setVolumeTwo(DoubleUtils.formatByPrecision(volume, 7));// 打包体积 + commonDao.store(order); + System.out.println(i + 1 + "===" + order.getDescription3() + + "==" + order.getToName() + "====" + + order.getStatus()); + } + OrderDetail orderDetail = null; + String hql = "from OrderDetail d where 1=1 and d.order.id=" + + order.getId(); + if (xsqdh != null && !xsqdh.equals("")) { + hql += " and d.salesList='" + xsqdh + "'"; + } + List orderDetails = this.commonDao + .findByQuery(hql); + if (orderDetails.size() > 0) { + orderDetail = orderDetails.get(0); + orderDetail.setSalesList(xsqdh); + orderDetail.setSplitQuantity(predictFee); + commonDao.store(orderDetail); + } else { + orderDetail = new OrderDetail(); + orderDetail.setOrder(order); + orderDetail.setSalesList(xsqdh); + orderDetail.setSplitQuantity(predictFee); + commonDao.store(orderDetail); + } + // orderPrescription(order);//时效 + // refreshQuantity(order.getId()); + System.out.println(i); + } + } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -6410,2098 +7248,2693 @@ public class DefaultOrderManager extends DefaultBaseManager implements // TODO Auto-generated catch block e.printStackTrace(); } - + } - void createSpecialFee(Order order){ - String shipmentMethod=order.getShipmentMethod()==null?"":order.getShipmentMethod(); - Boolean DJJJ=order.getContractor().getName().equals("大金旧件")?Boolean.TRUE:Boolean.FALSE; - List ods=this.commonDao.findByQuery("from OrderDetail od where od.order.id="+order.getId()); - double hjw=0; - double bxf=0; - double ggxs=1;//规格系数 - double wwxs=1;//重量系数 - double mxsl=0;//明细数量=明细数量除以规格系数 - double bzf=0;//包装费根据明细计算,某些货物不收取包装费 - double volumeT=0; - if(order.getConsignor().getCode().equals("DJKT")){ - for(OrderDetail od:ods){ - Item item=od.getItem(); - if(item==null||!item.getCode().equals(od.getMaterielCode())){ - List items= this.commonDao.findByQuery("from Item i where i.code=:code ", - new String[]{"code"},new Object[]{od.getMaterielCode()}); - if(items.size()>0){ - item=items.get(0); + void createSpecialFee(Order order) { + String shipmentMethod = order.getShipmentMethod() == null ? "" : order + .getShipmentMethod(); + Boolean DJJJ = order.getContractor().getName().equals("大金旧件") ? Boolean.TRUE + : Boolean.FALSE; + List ods = this.commonDao + .findByQuery("from OrderDetail od where od.order.id=" + + order.getId()); + double hjw = 0; + double bxf = 0; + double ggxs = 1;// 规格系数 + double wwxs = 1;// 重量系数 + double mxsl = 0;// 明细数量=明细数量除以规格系数 + double bzf = 0;// 包装费根据明细计算,某些货物不收取包装费 + double volumeT = 0; + if (order.getConsignor().getCode().equals("DJKT")) { + for (OrderDetail od : ods) { + Item item = od.getItem(); + if (item == null + || !item.getCode().equals(od.getMaterielCode())) { + List items = this.commonDao.findByQuery( + "from Item i where i.code=:code ", + new String[] { "code" }, + new Object[] { od.getMaterielCode() }); + if (items.size() > 0) { + item = items.get(0); od.setItem(item); } } - if(item!=null){ + if (item != null) { od.setReceivedQuantity(item.getPrice()); - PackageUnit unit=item.getMinPackageUnit(); + PackageUnit unit = item.getMinPackageUnit(); od.setWeight2(DoubleUtils.format4Fraction(unit.getWeight())); - double weight=unit.getWeight(); - double volume=unit.getLength()*unit.getWidth()*unit.getHeight(); -// od.setWeight2(DoubleUtils.format2Fraction(unit.getWeight()>unit.getArea()?unit.getWeight():unit.getArea())); - od.setVolume2(DoubleUtils.format4Fraction(unit.getLength()*unit.getWidth()*unit.getHeight())); -// if(volume==0&&unit.getVolume()>0){ -// od.setVolume2(volume); -// } - od.setVolume(volume*od.getQuantity()); - volumeT+=od.getVolume(); - wwxs=item.getRatio(); - ggxs=item.getSpecsRatio()==0?1:item.getSpecsRatio(); - double jfv=volume/3000; - if(order.getShipmentMethod()!=null&&!order.getShipmentMethod().equals("") - &&(order.getShipmentMethod().equals(ShipmentMethod.ZERO_SINGLE)||order.getShipmentMethod().equals(ShipmentMethod.KD_DF))){ - jfv=volume/6000; + double weight = unit.getWeight(); + double volume = unit.getLength() * unit.getWidth() + * unit.getHeight(); + // od.setWeight2(DoubleUtils.format2Fraction(unit.getWeight()>unit.getArea()?unit.getWeight():unit.getArea())); + od.setVolume2(DoubleUtils.format4Fraction(unit.getLength() + * unit.getWidth() * unit.getHeight())); + // if(volume==0&&unit.getVolume()>0){ + // od.setVolume2(volume); + // } + od.setVolume(volume * od.getQuantity()); + volumeT += od.getVolume(); + wwxs = item.getRatio(); + ggxs = item.getSpecsRatio() == 0 ? 1 : item.getSpecsRatio(); + double jfv = volume / 3000; + if (order.getShipmentMethod() != null + && !order.getShipmentMethod().equals("") + && (order.getShipmentMethod().equals( + ShipmentMethod.ZERO_SINGLE) || order + .getShipmentMethod().equals( + ShipmentMethod.KD_DF))) { + jfv = volume / 6000; } - //如果是重货,则直接重量*3 - if(!shipmentMethod.equals(ShipmentMethod.ZERO_SINGLE)&&!shipmentMethod.equals(ShipmentMethod.KD_DF)&&item.isBeMarkWeight()){ - od.setJfWeight(DoubleUtils.format2Fraction(weight*3*od.getQuantity())); - }else{ - od.setJfWeight(DoubleUtils.format2Fraction((weight>jfv?weight:jfv)*od.getQuantity()*wwxs/ggxs)); + // 如果是重货,则直接重量*3 + if (!shipmentMethod.equals(ShipmentMethod.ZERO_SINGLE) + && !shipmentMethod.equals(ShipmentMethod.KD_DF) + && item.isBeMarkWeight()) { + od.setJfWeight(DoubleUtils.format2Fraction(weight * 3 + * od.getQuantity())); + } else { + od.setJfWeight(DoubleUtils + .format2Fraction((weight > jfv ? weight : jfv) + * od.getQuantity() * wwxs / ggxs)); } - //大金旧件计算形式不同,无保险费和包装费 - if(DJJJ ){ - - }else{ - //专车不收取保险费 - if(order.getSelfDelivery()||shipmentMethod.equals(ShipmentMethod.SPECIAL_CAR)){ + // 大金旧件计算形式不同,无保险费和包装费 + if (DJJJ) { + + } else { + // 专车不收取保险费 + if (order.getSelfDelivery() + || shipmentMethod + .equals(ShipmentMethod.SPECIAL_CAR)) { od.setFee1(0d); od.setFeeDes1("不收取保险费"); od.setFee2(0d); od.setFeeDes1("不收取包装费"); - }else{ - if(shipmentMethod.equals(ShipmentMethod.NIGHT_MATH)){//||!item.isBeWeight()){ + } else { + if (shipmentMethod + .equals(ShipmentMethod.NIGHT_MATH)) {// ||!item.isBeWeight()){ od.setFee2(0); od.setFeeDes1("不收取包装费"); - }else{ - od.setFee2(DoubleUtils.format2Fraction(od.getJfWeight()*0.6)); - od.setFeeDes1(od.getJfWeight()+"*"+"0.6"); + } else { + od.setFee2(DoubleUtils.format2Fraction(od + .getJfWeight() * 0.6)); + od.setFeeDes1(od.getJfWeight() + "*" + "0.6"); } - od.setFee1(DoubleUtils.format2Fraction(item.getPrice()*od.getQuantity()*0.005)); - od.setFeeDes1(od.getQuantity()+"*"+item.getPrice()); + od.setFee1(DoubleUtils.format2Fraction(item + .getPrice() * od.getQuantity() * 0.005)); + od.setFeeDes1(od.getQuantity() + "*" + + item.getPrice()); } } } - hjw+=od.getJfWeight(); - bxf+=od.getFee1(); - mxsl+=od.getQuantity()/ggxs; - bzf+=od.getFee2(); - //服务费=明细数量*单价/ggxs - //包装费算在明细上=明细重量*单价,be_weight为是才需要收费,单价固定 - //保险费=计费重量*保险金额的百分比 + hjw += od.getJfWeight(); + bxf += od.getFee1(); + mxsl += od.getQuantity() / ggxs; + bzf += od.getFee2(); + // 服务费=明细数量*单价/ggxs + // 包装费算在明细上=明细重量*单价,be_weight为是才需要收费,单价固定 + // 保险费=计费重量*保险金额的百分比 } order.setVolume(volumeT); order.setWeightThree(DoubleUtils.format2Fraction(hjw)); - }else{ + } else { order.setWeightThree(DoubleUtils.format2Fraction(order.getWeight())); } - String hql="from SpecialFee s where s.contract.balance.id=:balanceId and s.feeType.name!='包装费' and s.contract.platForm.id=:platFormId"; - //费用包含:运费、保险费、包装费、送货费、服务费 - //夜配只收服务费,运输费,保险费,不收(包装费) - //专车收运输费,服务费,不收保险费、包装费、送货费 - //自提只收取服务费,不收运费和其他费用和保险费 - //快递到付和快递不收送货费。 - if(DJJJ){ - if(order.getShipmentMethod().equals(ShipmentMethod.ZERO_SINGLE)||order.getShipmentMethod().equals(ShipmentMethod.SPECIAL_CAR)){ - hql+=" and s.feeType.name ='服务费'"; + String hql = "from SpecialFee s where s.contract.balance.id=:balanceId and s.feeType.name!='包装费' and s.contract.platForm.id=:platFormId"; + // 费用包含:运费、保险费、包装费、送货费、服务费 + // 夜配只收服务费,运输费,保险费,不收(包装费) + // 专车收运输费,服务费,不收保险费、包装费、送货费 + // 自提只收取服务费,不收运费和其他费用和保险费 + // 快递到付和快递不收送货费。 + if (DJJJ) { + if (order.getShipmentMethod().equals(ShipmentMethod.ZERO_SINGLE) + || order.getShipmentMethod().equals( + ShipmentMethod.SPECIAL_CAR)) { + hql += " and s.feeType.name ='服务费'"; } - //收货人为武汉圣达、成都圣达,无送货费 - //收货人不为武汉圣达、成都圣达,无服务费 - if(order.getToName()!=null&&(order.getToName().equals("武汉圣达")||order.getToName().equals("成都圣达"))){ - hql+=" and s.feeType.name !='送货费'"; - }else{ - hql+=" and s.feeType.name !='服务费'"; + // 收货人为武汉圣达、成都圣达,无送货费 + // 收货人不为武汉圣达、成都圣达,无服务费 + if (order.getToName() != null + && (order.getToName().equals("武汉圣达") || order.getToName() + .equals("成都圣达"))) { + hql += " and s.feeType.name !='送货费'"; + } else { + hql += " and s.feeType.name !='服务费'"; } - }else { - if(order.getSelfDelivery()){ - hql+=" and s.feeType.name ='服务费'"; - }else if(order.getShipmentMethod().equals(ShipmentMethod.NIGHT_MATH)||order.getShipmentMethod().equals(ShipmentMethod.SPECIAL_CAR)){ - hql+=" and s.feeType.name ='服务费'"; - }else if(order.getShipmentMethod().equals(ShipmentMethod.KD_DF)||order.getShipmentMethod().equals(ShipmentMethod.TRUCK_DF)||order.getShipmentMethod().equals(ShipmentMethod.ZERO_SINGLE)){ - hql+=" and s.feeType.name !='送货费'"; + } else { + if (order.getSelfDelivery()) { + hql += " and s.feeType.name ='服务费'"; + } else if (order.getShipmentMethod().equals( + ShipmentMethod.NIGHT_MATH) + || order.getShipmentMethod().equals( + ShipmentMethod.SPECIAL_CAR)) { + hql += " and s.feeType.name ='服务费'"; + } else if (order.getShipmentMethod().equals(ShipmentMethod.KD_DF) + || order.getShipmentMethod() + .equals(ShipmentMethod.TRUCK_DF) + || order.getShipmentMethod().equals( + ShipmentMethod.ZERO_SINGLE)) { + hql += " and s.feeType.name !='送货费'"; } } - //大金客户都取 武汉圣达的大金费用,大金旧件取其他的合同数据 - Long platFormId=new Long("1"); - if(DJJJ){ - platFormId=new Long("3574"); + // 大金客户都取 武汉圣达的大金费用,大金旧件取其他的合同数据 + Long platFormId = new Long("1"); + if (DJJJ) { + platFormId = new Long("3574"); } - List sfs=commonDao.findByQuery(hql, - new String[]{"balanceId","platFormId"},new Object[]{order.getConsignor().getId(),platFormId}); - for(SpecialFee sf:sfs){ - double totalFee=0; - double qty=0; - if(sf.getUnit().equals(MeasureUnit.WEIGHT)){ - qty=order.getWeightThree(); - }else if (sf.getUnit().equals(MeasureUnit.QUANTITY)){ - qty=mxsl;//order.getQuantity(); + List sfs = commonDao.findByQuery(hql, new String[] { + "balanceId", "platFormId" }, new Object[] { + order.getConsignor().getId(), platFormId }); + for (SpecialFee sf : sfs) { + double totalFee = 0; + double qty = 0; + if (sf.getUnit().equals(MeasureUnit.WEIGHT)) { + qty = order.getWeightThree(); + } else if (sf.getUnit().equals(MeasureUnit.QUANTITY)) { + qty = mxsl;// order.getQuantity(); } - totalFee=qty*sf.getPrice(); - Boolean temp=Boolean.FALSE; - if(totalFee=sf.getMinPrice()?totalFee:sf.getMinPrice(); - Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), sf.getFeeType(), - qty, sf.getPrice(), totalFee, FeePayReceive.RECEIVE, sf.getUnit(), order.getContractor()); - fee.setRemark(fee.getPrice()+"*"+fee.getQuantity()); - if(temp){ - fee.setRemark(fee.getRemark()+"不足最低价,按最低价算"+sf.getMinPrice()); + totalFee = totalFee >= sf.getMinPrice() ? totalFee : sf + .getMinPrice(); + Fee fee = this.createFeeInfo(order.getRelateBill3(), order.getId(), + BillObjectType.ORDER, order.getConsignor(), + sf.getFeeType(), qty, sf.getPrice(), totalFee, + FeePayReceive.RECEIVE, sf.getUnit(), order.getContractor()); + fee.setRemark(fee.getPrice() + "*" + fee.getQuantity()); + if (temp) { + fee.setRemark(fee.getRemark() + "不足最低价,按最低价算" + + sf.getMinPrice()); } this.commonDao.store(fee); } - if(bxf>0){ - List fts = commonDao.findByQuery("from FeeType ft where ft.name=:name", - new String[]{"name"},new Object[]{"保险费"}); - if(fts.size()>0){ - Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), fts.get(0), - 1, bxf, bxf, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - }else{ + if (bxf > 0) { + List fts = commonDao.findByQuery( + "from FeeType ft where ft.name=:name", + new String[] { "name" }, new Object[] { "保险费" }); + if (fts.size() > 0) { + Fee fee = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), fts.get(0), 1, bxf, bxf, + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); + } else { throw new BusinessException("请维护费用科目项‘保险费’"); } } - if(bzf>0){ - List fts = commonDao.findByQuery("from FeeType ft where ft.name=:name ", - new String[]{"name"},new Object[]{"包装费",order.getContractor().getId()}); - if(fts.size()>0){ - Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), fts.get(0), - 1, bzf, bzf, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - }else{ + if (bzf > 0) { + List fts = commonDao.findByQuery( + "from FeeType ft where ft.name=:name ", + new String[] { "name" }, new Object[] { "包装费", + order.getContractor().getId() }); + if (fts.size() > 0) { + Fee fee = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), fts.get(0), 1, bzf, bzf, + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); + } else { throw new BusinessException("请维护费用科目项‘包装费’"); } } } - - List getContract(Long balanceId,Long platId){ - List cs = commonDao.findByQuery("from Contract c where c.balance.id=:balanceId and c.platForm.id=:platFormId", - new String[]{"balanceId","platFormId"},new Object[]{balanceId,platId}); + + List getContract(Long balanceId, Long platId) { + List cs = commonDao + .findByQuery( + "from Contract c where c.balance.id=:balanceId and c.platForm.id=:platFormId", + new String[] { "balanceId", "platFormId" }, + new Object[] { balanceId, platId }); return cs; } - - void createDJFee(Order order){ - String shipmentMethod=order.getShipmentMethod()==null?"":order.getShipmentMethod(); - if(order.getWeightThree()>0||shipmentMethod.equals(ShipmentMethod.SPECIAL_CAR)||shipmentMethod.equals(ShipmentMethod.NIGHT_MATH)){ - - if(shipmentMethod.equals(ShipmentMethod.KD_DF)||shipmentMethod.equals(ShipmentMethod.TRUCK_DF)){ + + void createDJFee(Order order) { + String shipmentMethod = order.getShipmentMethod() == null ? "" : order + .getShipmentMethod(); + if (order.getWeightThree() > 0 + || shipmentMethod.equals(ShipmentMethod.SPECIAL_CAR) + || shipmentMethod.equals(ShipmentMethod.NIGHT_MATH)) { + + if (shipmentMethod.equals(ShipmentMethod.KD_DF) + || shipmentMethod.equals(ShipmentMethod.TRUCK_DF)) { return; } - double qty=order.getWeightThree(); - String unit=MeasureUnit.WEIGHT; - if(shipmentMethod.equals(ShipmentMethod.SPECIAL_CAR)||shipmentMethod.equals(ShipmentMethod.NIGHT_MATH)){ - qty=1; - unit=MeasureUnit.TICKET; + double qty = order.getWeightThree(); + String unit = MeasureUnit.WEIGHT; + if (shipmentMethod.equals(ShipmentMethod.SPECIAL_CAR) + || shipmentMethod.equals(ShipmentMethod.NIGHT_MATH)) { + qty = 1; + unit = MeasureUnit.TICKET; } -// if(shipmentMethod.equals(ShipmentMethod.TRUCK_DF)){ -// shipmentMethod=ShipmentMethod.TRUCK; -// } - createContractFee(order, order.getFromCity().getId(),order.getToCity().getId(),shipmentMethod,unit,"1",qty); - }else{ - List fts = commonDao.findByQuery("from FeeType ft where ft.name=:name and ft.platForm.id=:platFormId", - new String[]{"name","platFormId"},new Object[]{"运输费",order.getContractor().getId()}); - if(fts.size()>0){ - Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), fts.get(0), - 1, 0, 0, FeePayReceive.RECEIVE, MeasureUnit.WEIGHT, order.getContractor()); - fee.setDescription(fee.getDescription() +"无此线路"); - commonDao.store(fee); + // if(shipmentMethod.equals(ShipmentMethod.TRUCK_DF)){ + // shipmentMethod=ShipmentMethod.TRUCK; + // } + createContractFee(order, order.getFromCity().getId(), order + .getToCity().getId(), shipmentMethod, unit, "1", qty); + } else { + List fts = commonDao + .findByQuery( + "from FeeType ft where ft.name=:name and ft.platForm.id=:platFormId", + new String[] { "name", "platFormId" }, + new Object[] { "运输费", order.getContractor().getId() }); + if (fts.size() > 0) { + Fee fee = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), fts.get(0), 1, 0, 0, + FeePayReceive.RECEIVE, MeasureUnit.WEIGHT, + order.getContractor()); + fee.setDescription(fee.getDescription() + "无此线路"); + commonDao.store(fee); } - order.setDescription(order.getDescription() +"无此线路"); + order.setDescription(order.getDescription() + "无此线路"); } } - - //鹰空、利丰客户费用 -void createQKCusFee(Order order){ - List crs = null; - String shipmentMethod=order.getShipmentMethod()==null?"":order.getShipmentMethod(); - if(order.getFromCityCountiy()==null||order.getToCityCountiy()==null){ - return; - } - crs=commonDao.findByQuery("from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.transfer=0 and c.routeFee.fromCity.id=:fid and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode ", - new String[]{"balanceId","fid","tid","transportMode"},new Object[]{order.getConsignor().getId(),order.getFromCityCountiy().getId(),order.getToCityCountiy().getId(),shipmentMethod}); - for(ContractRate cr:crs){ - double pricew=DoubleUtils.format3Fraction(cr.getPrice1()==null?0:cr.getPrice1()); - double pricev=DoubleUtils.format3Fraction(cr.getPricet1()==null?0:cr.getPricet1()); - double ljdj=0; - double weight=order.getWeight(); - double volume=order.getVolume(); - Boolean temp=Boolean.FALSE; - if(weight>(cr.getFromRange1()==null?0:cr.getFromRange1()) &&(cr.getToRange1()==null||weight<=cr.getToRange1())){ - pricew=DoubleUtils.format3Fraction(cr.getPrice1()==null?0:cr.getPrice1()); + + // 鹰空、利丰客户费用 + void createQKCusFee(Order order) { + List crs = null; + String shipmentMethod = order.getShipmentMethod() == null ? "" : order + .getShipmentMethod(); + if (order.getFromCityCountiy() == null + || order.getToCityCountiy() == null) { + return; } - if(cr.getFromRange2()!=null&&weight>=cr.getFromRange2()){ - pricew=DoubleUtils.format3Fraction(cr.getPrice2()==null?0:cr.getPrice2()); - temp=Boolean.TRUE; - } - if(volume>(cr.getFromRange1()==null?0:cr.getFromRange1())/300 &&(cr.getToRange1()==null||volume<=cr.getToRange1()/300)){ - pricev=DoubleUtils.format3Fraction(cr.getPricet1()==null?0:cr.getPricet1()); - } - if(cr.getFromRange2()!=null&&volume>=cr.getFromRange2()/300){ - pricev=DoubleUtils.format3Fraction(cr.getPricet2()==null?0:cr.getPricet2()); - temp=Boolean.TRUE; - } - double tw=pricew*weight; - double tv=pricev*volume; - double qty=0; - double price=0; - String remark=""; - String unit=MeasureUnit.WEIGHT; - if(tw>tv){ - qty=weight; - price=pricew; - remark=pricew+"*"+weight+"大于"+pricev+"*"+volume+"按重量计算"; - }else{ - unit=MeasureUnit.VOLUME; - qty=volume; - price=pricev; - remark=pricew+"*"+weight+"小于"+pricev+"*"+volume+"按体积计算"; - } - //order.setFreight(price); - Double totalFee=price*qty; - if(cr.getFeeType().getName().equals("运输费")){ - order.setFreight(price); - } - Fee fee=null; - fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), cr.getFeeType(), - qty, price, totalFee, FeePayReceive.RECEIVE, unit, order.getContractor()); - fee.setRemark(remark); - if(cr.getMinPrice()!=null&&fee.getTotalFee()0&&fee.getTotalFee()>cr.getMaxPrice1()){ - totalFee=cr.getMaxPrice1(); - price=totalFee; - qty=1; - fee.setUnit(MeasureUnit.TICKET); - fee.setTotalFee(totalFee); - fee.setPrice(price); - fee.setQuantity(qty); - fee.setRemark(fee.getRemark()+"大于阶段1最高价,按最高价算"+cr.getMaxPrice1()); + crs = commonDao + .findByQuery( + "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.transfer=0 and c.routeFee.fromCity.id=:fid and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode ", + new String[] { "balanceId", "fid", "tid", + "transportMode" }, new Object[] { + order.getConsignor().getId(), + order.getFromCityCountiy().getId(), + order.getToCityCountiy().getId(), + shipmentMethod }); + for (ContractRate cr : crs) { + double pricew = DoubleUtils + .format3Fraction(cr.getPrice1() == null ? 0 : cr + .getPrice1()); + double pricev = DoubleUtils + .format3Fraction(cr.getPricet1() == null ? 0 : cr + .getPricet1()); + double ljdj = 0; + double weight = order.getWeight(); + double volume = order.getVolume(); + Boolean temp = Boolean.FALSE; + if (weight > (cr.getFromRange1() == null ? 0 : cr.getFromRange1()) + && (cr.getToRange1() == null || weight <= cr.getToRange1())) { + pricew = DoubleUtils.format3Fraction(cr.getPrice1() == null ? 0 + : cr.getPrice1()); } - }else{ - if(cr.getMaxPrice2()!=null&&cr.getMaxPrice2()>0&&fee.getTotalFee()>cr.getMaxPrice2()){ - totalFee=cr.getMaxPrice2(); - price=totalFee; - qty=1; - fee.setUnit(MeasureUnit.TICKET); - fee.setTotalFee(totalFee); - fee.setPrice(price); - fee.setQuantity(qty); - fee.setRemark(fee.getRemark()+"大于阶段2最高价,按最高价算"+cr.getMaxPrice2()); + if (cr.getFromRange2() != null && weight >= cr.getFromRange2()) { + pricew = DoubleUtils.format3Fraction(cr.getPrice2() == null ? 0 + : cr.getPrice2()); + temp = Boolean.TRUE; } - } - this.commonDao.store(fee); - } - } - - //重庆民生 - void createZQMSCusFee(Order order){ - List crs = null; - String shipmentMethod=order.getShipmentMethod()==null?"":order.getShipmentMethod(); - String hql="from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.fromCity.id=:fid and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode "; - if(order.getConsignor().getCode().equals("LF")){ - hql+=" and c.routeFee.transfer=1"; - shipmentMethod=ShipmentMethod.TRUCK; - } - crs=commonDao.findByQuery(hql,new String[]{"balanceId","fid","tid","transportMode"},new Object[]{order.getConsignor().getId(),order.getFromCityCountiy().getId(),order.getToCityCountiy().getId(),shipmentMethod}); - for(ContractRate cr:crs){ - double price=DoubleUtils.format3Fraction(cr.getPrice1()); - double ljdj=0; - double qty=1; - if(cr.getUnit().equals(MeasureUnit.WEIGHT)){ - qty=order.getWeight(); - }else if(cr.getUnit().equals(MeasureUnit.VOLUME)){ - qty=order.getVolume(); - }else if(cr.getUnit().equals(MeasureUnit.QUANTITY)){ - qty=order.getQuantity(); - } - if(cr.getFromRange1()!=null&&qty>cr.getFromRange1() &&(cr.getToRange1()==null||qty<=cr.getToRange1())){ - price=DoubleUtils.format3Fraction(cr.getPrice1()); - } - if(cr.getFromRange2()!=null&&(cr.getToRange2()==null||qty>=cr.getFromRange2())){ - price=DoubleUtils.format3Fraction(cr.getPrice2()); - ljdj=DoubleUtils.format3Fraction(cr.getPrice2()); - } - if(cr.getFeeType().getName().equals("运输费")){ - order.setFreight(price); - } - Double totalFee=price*qty; - String remark=price+"*"+qty; - Fee fee=null; - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( - "yyyy-MM-dd"); - List Fees=null; - Fees = commonDao.findByQuery(" from Fee f where f.billId in (select o.id from Order o where o.consignor.id=:id and o.toName=:toName and to_char(o.planFromDate,'yyyy-MM-dd')='"+sdf.format(order.getPlanFromDate())+"' ) and f.billObject='ORDER' and f.feeName.name='送货费' ", - new String[] { "id","toName"},new Object[] {order.getConsignor().getId(),order.getToName()}); - if(Fees.size()<=0){ - if(cr.getFeeType().getName().equals("送货费")){ - this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), cr.getFeeType(), - qty, price, totalFee, FeePayReceive.RECEIVE, cr.getUnit(), order.getContractor()); - }else if(cr.getFeeType().getName().equals("运输费")){ - this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), cr.getFeeType(), - qty, price, totalFee, FeePayReceive.RECEIVE, cr.getUnit(), order.getContractor()); + if (volume > (cr.getFromRange1() == null ? 0 : cr.getFromRange1()) / 300 + && (cr.getToRange1() == null || volume <= cr.getToRange1() / 300)) { + pricev = DoubleUtils + .format3Fraction(cr.getPricet1() == null ? 0 : cr + .getPricet1()); } - }else{ - if(cr.getFeeType().getName().equals("运输费")){ - this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), cr.getFeeType(), - qty, price, totalFee, FeePayReceive.RECEIVE, cr.getUnit(), order.getContractor()); + if (cr.getFromRange2() != null + && volume >= cr.getFromRange2() / 300) { + pricev = DoubleUtils + .format3Fraction(cr.getPricet2() == null ? 0 : cr + .getPricet2()); + temp = Boolean.TRUE; } - } - - } -} - //重庆民生 - void createNewZQMSFee(Order order){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - String lineName=""; - Contract c=null; - double count=0; - double price=0; - double shf=0; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - List Contracts = commonDao.findByQuery(" from Contract c where c.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - c=Contracts.get(0); - ContractRate cr=null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] { "id","name"},new Object[] {c.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - price=cr.getPrice1();//中转单价 - cr.getDeliveryFee();//送货费; - //门店条数 - count= (Double) commonDao.findByQuery("select sum(o.quantity) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", - new String[] { "id","planFromDate","toName"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}).get(0); - //shf=count*price+cr.getDeliveryFee(); - Order o=null; - List Orders = commonDao.findByQuery(" from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", - new String[] { "id","planFromDate","toName"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}); - if(Orders.size()>0){ - if(Orders.size()==1){ - o=Orders.get(0); - double ysf=o.getQuantity()*price; - shf=60; - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", ysf); - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "送货费", shf); - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - }else{ - for(Order oo:Orders){ - shf=60/count*oo.getQuantity(); - double ysf=oo.getQuantity()*price; - feeManager.saveInputFee(oo.getId(), BillObjectType.ORDER, null, "运输费", ysf); - feeManager.saveInputFee(oo.getId(), BillObjectType.ORDER, null, "送货费", shf); - feeManager.refreshBillFee(oo.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - } - - } - } - }else{ - throw new BusinessException("合同不存在!"); + double tw = pricew * weight; + double tv = pricev * volume; + double qty = 0; + double price = 0; + String remark = ""; + String unit = MeasureUnit.WEIGHT; + if (tw > tv) { + qty = weight; + price = pricew; + remark = pricew + "*" + weight + "大于" + pricev + "*" + volume + + "按重量计算"; + } else { + unit = MeasureUnit.VOLUME; + qty = volume; + price = pricev; + remark = pricew + "*" + weight + "小于" + pricev + "*" + volume + + "按体积计算"; } - }else{ - throw new BusinessException("提货区域或收货区域不存在!"); - } - - } - - //其他客户费用,利丰中转 - void createQTCusFee(Order order,Boolean is_city,Boolean from_city){ - List crs = new ArrayList(); - String shipmentMethod=order.getShipmentMethod()==null?"":order.getShipmentMethod(); - String xm=order.getToName(); - String planFromDate=DateUtil.formatDateYMDToStr(order.getPlanFromDate()); - String hql="from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode "; - String hqlxm=hql; - String linkman=order.getToContact()==null?"":order.getToContact().getLinkman(); - String cuscode=order.getConsignor().getCode(); - if(order.getConsignor().getCode().equals("LF")){ - hql+=" and c.routeFee.transfer=1"; - shipmentMethod=ShipmentMethod.TRUCK; - } - Long fid=order.getFromCityCountiy().getId(); - if(from_city){ - hql+=" and c.routeFee.fromCity.id="+fid; - hqlxm+=" and c.routeFee.fromCity.id="+fid; - } - if(is_city){ - if(order.getFromName()!=null){ - hqlxm+=" and c.superviseType='"+xm+"'"; - crs=commonDao.findByQuery(hqlxm,new String[]{"balanceId","tid","transportMode"},new Object[]{order.getConsignor().getId(),order.getToCityCountiy().getId(),shipmentMethod}); - }//福特的所有合同均按照收货单位来 - if(crs!=null&&crs.size()<=0&&!order.getConsignor().getCode().equals("FT")){ - crs=commonDao.findByQuery(hql,new String[]{"balanceId","tid","transportMode"},new Object[]{order.getConsignor().getId(),order.getToCityCountiy().getId(),shipmentMethod}); - } - }else{//按照省份找目的费率 - Long toId=null; - if(order.getToCityCountiy().getName().equals("武汉市")){ - toId=new Long(1050); - }else{ - toId=order.getToCityCountiy().getZone().getId(); - } - hql="from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toZone.id=:tid "; - crs=commonDao.findByQuery(hql,new String[]{"balanceId","tid"},new Object[]{order.getConsignor().getId(),toId}); - } - - for(ContractRate cr:crs){ - double price=DoubleUtils.format3Fraction(cr.getPrice1()); - double ljdj=0; - double qty=1; - if(cr.getUnit().equals(MeasureUnit.WEIGHT)){ - qty=order.getWeight(); - }else if(cr.getUnit().equals(MeasureUnit.VOLUME)){ - qty=order.getVolume(); -// if(cuscode.equals("GQCQ")){ -// qty=order.getVolumeThree(); -// } - }else if(cr.getUnit().equals(MeasureUnit.QUANTITY)){ - qty=order.getQuantity(); - } - if(cr.getFromRange1()!=null&&qty>cr.getFromRange1() &&(cr.getToRange1()==null||qty=cr.getFromRange2()&&(cr.getToRange2()==null||qty=1){ -// //大于1不管 -// }else{ -// jl_volume=(Double)this.commonDao.findByQuery("select sum(o.volume) from Order o where to_char(o.planFromDate,'yyyy-mm-dd')='"+planFromDate -// +"' and o.toName='"+to_name+"'").get(0); -// if(jl_volume<1){ -// qty=jl_volume; -// //如果当天该收货人已收取费用,则不重复收取 -// List sids=null; -// sids=this.commonDao.findByQuery("select o.id from Order o where o.toName='"+to_name -// +"' and to_char(o.planFromDate,'yyyy-mm-dd')='"+planFromDate+"'"); -// Boolean temp=Boolean.TRUE; -// for(Long id:sids){ -// List fs=this.commonDao.findByQuery("from Fee f where f.billId="+id+" and f.billObject='ORDER' and f.feeName.id="+ cr.getFeeType().getId() +" and f.operator='system'"); -// if(fs.size()>0){ -// temp=Boolean.FALSE; -// return; -// } -// } -// } -// } -// if(qty0){ - //如果当天该收货人已收取费用,则不重复收取 - List sids=null; - if(cuscode.equals("ZY")){ - sids=this.commonDao.findByQuery("select o.id from Order o where o.toContact.linkman='"+linkman - +"' and to_char(o.planFromDate,'yyyy-mm-dd')='"+planFromDate+"'"); - }else{ - sids=this.commonDao.findByQuery("select o.id from Order o where o.toName='"+xm - +"' and to_char(o.planFromDate,'yyyy-mm-dd')='"+planFromDate+"'"); + if (!temp) { + if (cr.getMaxPrice1() != null && cr.getMaxPrice1() > 0 + && fee.getTotalFee() > cr.getMaxPrice1()) { + totalFee = cr.getMaxPrice1(); + price = totalFee; + qty = 1; + fee.setUnit(MeasureUnit.TICKET); + fee.setTotalFee(totalFee); + fee.setPrice(price); + fee.setQuantity(qty); + fee.setRemark(fee.getRemark() + "大于阶段1最高价,按最高价算" + + cr.getMaxPrice1()); } - Boolean deleteFee=Boolean.FALSE; - if(order.getConsignor().getCode().equals("ZY")){ - //当客户为中邮时,大于5立方不收送货费 - double volume=(Double)this.commonDao.findByQuery("select sum(o.volume) from Order o where to_char(o.planFromDate,'yyyy-mm-dd')='"+planFromDate - +"' and o.toContact.linkman='"+linkman+"'").get(0); - if(volume>=5){ - deleteFee=Boolean.TRUE; + } else { + if (cr.getMaxPrice2() != null && cr.getMaxPrice2() > 0 + && fee.getTotalFee() > cr.getMaxPrice2()) { + totalFee = cr.getMaxPrice2(); + price = totalFee; + qty = 1; + fee.setUnit(MeasureUnit.TICKET); + fee.setTotalFee(totalFee); + fee.setPrice(price); + fee.setQuantity(qty); + fee.setRemark(fee.getRemark() + "大于阶段2最高价,按最高价算" + + cr.getMaxPrice2()); + } + } + this.commonDao.store(fee); + } + } + + // 重庆民生 + void createZQMSCusFee(Order order) { + List crs = null; + String shipmentMethod = order.getShipmentMethod() == null ? "" : order + .getShipmentMethod(); + String hql = "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.fromCity.id=:fid and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode "; + if (order.getConsignor().getCode().equals("LF")) { + hql += " and c.routeFee.transfer=1"; + shipmentMethod = ShipmentMethod.TRUCK; + } + crs = commonDao.findByQuery(hql, new String[] { "balanceId", "fid", + "tid", "transportMode" }, new Object[] { + order.getConsignor().getId(), + order.getFromCityCountiy().getId(), + order.getToCityCountiy().getId(), shipmentMethod }); + for (ContractRate cr : crs) { + double price = DoubleUtils.format3Fraction(cr.getPrice1()); + double ljdj = 0; + double qty = 1; + if (cr.getUnit().equals(MeasureUnit.WEIGHT)) { + qty = order.getWeight(); + } else if (cr.getUnit().equals(MeasureUnit.VOLUME)) { + qty = order.getVolume(); + } else if (cr.getUnit().equals(MeasureUnit.QUANTITY)) { + qty = order.getQuantity(); + } + if (cr.getFromRange1() != null && qty > cr.getFromRange1() + && (cr.getToRange1() == null || qty <= cr.getToRange1())) { + price = DoubleUtils.format3Fraction(cr.getPrice1()); + } + if (cr.getFromRange2() != null + && (cr.getToRange2() == null || qty >= cr.getFromRange2())) { + price = DoubleUtils.format3Fraction(cr.getPrice2()); + ljdj = DoubleUtils.format3Fraction(cr.getPrice2()); + } + if (cr.getFeeType().getName().equals("运输费")) { + order.setFreight(price); + } + Double totalFee = price * qty; + String remark = price + "*" + qty; + Fee fee = null; + java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( + "yyyy-MM-dd"); + List Fees = null; + Fees = commonDao + .findByQuery( + " from Fee f where f.billId in (select o.id from Order o where o.consignor.id=:id and o.toName=:toName and to_char(o.planFromDate,'yyyy-MM-dd')='" + + sdf.format(order.getPlanFromDate()) + + "' ) and f.billObject='ORDER' and f.feeName.name='送货费' ", + new String[] { "id", "toName" }, + new Object[] { order.getConsignor().getId(), + order.getToName() }); + if (Fees.size() <= 0) { + if (cr.getFeeType().getName().equals("送货费")) { + this.createFeeInfo(order.getRelateBill3(), order.getId(), + BillObjectType.ORDER, order.getConsignor(), + cr.getFeeType(), qty, price, totalFee, + FeePayReceive.RECEIVE, cr.getUnit(), + order.getContractor()); + } else if (cr.getFeeType().getName().equals("运输费")) { + this.createFeeInfo(order.getRelateBill3(), order.getId(), + BillObjectType.ORDER, order.getConsignor(), + cr.getFeeType(), qty, price, totalFee, + FeePayReceive.RECEIVE, cr.getUnit(), + order.getContractor()); + } + } else { + if (cr.getFeeType().getName().equals("运输费")) { + this.createFeeInfo(order.getRelateBill3(), order.getId(), + BillObjectType.ORDER, order.getConsignor(), + cr.getFeeType(), qty, price, totalFee, + FeePayReceive.RECEIVE, cr.getUnit(), + order.getContractor()); + } + } + + } + } + + // 重庆民生 + void createNewZQMSFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String lineName = ""; + Contract c = null; + double count = 0; + double price = 0; + double shf = 0; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + List Contracts = commonDao.findByQuery( + " from Contract c where c.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + c = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { c.getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + price = cr.getPrice1();// 中转单价 + cr.getDeliveryFee();// 送货费; + // 门店条数 + count = (Double) commonDao + .findByQuery( + "select sum(o.quantity) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", + new String[] { "id", "planFromDate", + "toName" }, + new Object[] { + order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }).get(0); + // shf=count*price+cr.getDeliveryFee(); + Order o = null; + List Orders = commonDao + .findByQuery( + " from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", + new String[] { "id", "planFromDate", + "toName" }, + new Object[] { + order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }); + if (Orders.size() > 0) { + if (Orders.size() == 1) { + o = Orders.get(0); + double ysf = o.getQuantity() * price; + shf = 60; + feeManager.saveInputFee(o.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + feeManager.saveInputFee(o.getId(), + BillObjectType.ORDER, null, "送货费", shf); + feeManager.refreshBillFee(o.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } else { + for (Order oo : Orders) { + shf = 60 / count * oo.getQuantity(); + double ysf = oo.getQuantity() * price; + feeManager.saveInputFee(oo.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + feeManager.saveInputFee(oo.getId(), + BillObjectType.ORDER, null, "送货费", shf); + feeManager.refreshBillFee(oo.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } + } + } } - FeeType ft=getFeeType("送货费"); - double shf=cr.getDeliveryFee(); - Boolean temp=Boolean.TRUE; - for(Long id:sids){ - List fs=this.commonDao.findByQuery("from Fee f where f.billId="+id+" and f.billObject='ORDER' and f.feeName.id="+ft.getId() +" and f.operator='system'"); - if(fs.size()>0){ - temp=Boolean.FALSE; - if(deleteFee){ - for(Fee f:fs){ + } else { + throw new BusinessException("合同不存在!"); + } + } else { + throw new BusinessException("提货区域或收货区域不存在!"); + } + + } + + // 其他客户费用,利丰中转 + void createQTCusFee(Order order, Boolean is_city, Boolean from_city) { + List crs = new ArrayList(); + String shipmentMethod = order.getShipmentMethod() == null ? "" : order + .getShipmentMethod(); + String xm = order.getToName(); + String planFromDate = DateUtil.formatDateYMDToStr(order + .getPlanFromDate()); + String hql = "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode "; + String hqlxm = hql; + String linkman = order.getToContact() == null ? "" : order + .getToContact().getLinkman(); + String cuscode = order.getConsignor().getCode(); + if (order.getConsignor().getCode().equals("LF")) { + hql += " and c.routeFee.transfer=1"; + shipmentMethod = ShipmentMethod.TRUCK; + } + Long fid = order.getFromCityCountiy().getId(); + if (from_city) { + hql += " and c.routeFee.fromCity.id=" + fid; + hqlxm += " and c.routeFee.fromCity.id=" + fid; + } + if (is_city) { + if (order.getFromName() != null) { + hqlxm += " and c.superviseType='" + xm + "'"; + crs = commonDao.findByQuery(hqlxm, new String[] { "balanceId", + "tid", "transportMode" }, new Object[] { + order.getConsignor().getId(), + order.getToCityCountiy().getId(), shipmentMethod }); + }// 福特的所有合同均按照收货单位来 + if (crs != null && crs.size() <= 0 + && !order.getConsignor().getCode().equals("FT")) { + crs = commonDao.findByQuery(hql, new String[] { "balanceId", + "tid", "transportMode" }, new Object[] { + order.getConsignor().getId(), + order.getToCityCountiy().getId(), shipmentMethod }); + } + } else {// 按照省份找目的费率 + Long toId = null; + if (order.getToCityCountiy().getName().equals("武汉市")) { + toId = new Long(1050); + } else { + toId = order.getToCityCountiy().getZone().getId(); + } + hql = "from ContractRate c where c.contract.balance.id=:balanceId and c.routeFee.toZone.id=:tid "; + crs = commonDao.findByQuery(hql, + new String[] { "balanceId", "tid" }, new Object[] { + order.getConsignor().getId(), toId }); + } + + for (ContractRate cr : crs) { + double price = DoubleUtils.format3Fraction(cr.getPrice1()); + double ljdj = 0; + double qty = 1; + if (cr.getUnit().equals(MeasureUnit.WEIGHT)) { + qty = order.getWeight(); + } else if (cr.getUnit().equals(MeasureUnit.VOLUME)) { + qty = order.getVolume(); + // if(cuscode.equals("GQCQ")){ + // qty=order.getVolumeThree(); + // } + } else if (cr.getUnit().equals(MeasureUnit.QUANTITY)) { + qty = order.getQuantity(); + } + if (cr.getFromRange1() != null && qty > cr.getFromRange1() + && (cr.getToRange1() == null || qty < cr.getToRange1())) { + price = DoubleUtils.format3Fraction(cr.getPrice1()); + } + if (cr.getFromRange2() != null && qty >= cr.getFromRange2() + && (cr.getToRange2() == null || qty < cr.getToRange2())) { + price = DoubleUtils.format3Fraction(cr.getPrice2()); + ljdj = DoubleUtils.format3Fraction(cr.getPrice2()); + } + if (cr.getFeeType().getName().equals("运输费")) { + order.setFreight(price); + } + double rate = DoubleUtils.format2Fraction(cr.getContract() + .getRate()); + if (rate == 0) { + rate = 1; + } + String remark = ""; + double jl_volume = order.getVolume(); + // 运输费,如果客户=JL吉利,判断当天收货人汇总体积是否超过1,超过则按照体积*单价,不超过则不足一立方按一立方 + if (cuscode.equals("JL")) { + // String to_name=order.getToName()==null?"":order.getToName(); + // if(order.getVolume()>=1){ + // //大于1不管 + // }else{ + // jl_volume=(Double)this.commonDao.findByQuery("select sum(o.volume) from Order o where to_char(o.planFromDate,'yyyy-mm-dd')='"+planFromDate + // +"' and o.toName='"+to_name+"'").get(0); + // if(jl_volume<1){ + // qty=jl_volume; + // //如果当天该收货人已收取费用,则不重复收取 + // List sids=null; + // sids=this.commonDao.findByQuery("select o.id from Order o where o.toName='"+to_name + // +"' and to_char(o.planFromDate,'yyyy-mm-dd')='"+planFromDate+"'"); + // Boolean temp=Boolean.TRUE; + // for(Long id:sids){ + // List + // fs=this.commonDao.findByQuery("from Fee f where f.billId="+id+" and f.billObject='ORDER' and f.feeName.id="+ + // cr.getFeeType().getId() +" and f.operator='system'"); + // if(fs.size()>0){ + // temp=Boolean.FALSE; + // return; + // } + // } + // } + // } + // if(qty 0) { + // 如果当天该收货人已收取费用,则不重复收取 + List sids = null; + if (cuscode.equals("ZY")) { + sids = this.commonDao + .findByQuery("select o.id from Order o where o.toContact.linkman='" + + linkman + + "' and to_char(o.planFromDate,'yyyy-mm-dd')='" + + planFromDate + "'"); + } else { + sids = this.commonDao + .findByQuery("select o.id from Order o where o.toName='" + + xm + + "' and to_char(o.planFromDate,'yyyy-mm-dd')='" + + planFromDate + "'"); + } + Boolean deleteFee = Boolean.FALSE; + if (order.getConsignor().getCode().equals("ZY")) { + // 当客户为中邮时,大于5立方不收送货费 + double volume = (Double) this.commonDao + .findByQuery( + "select sum(o.volume) from Order o where to_char(o.planFromDate,'yyyy-mm-dd')='" + + planFromDate + + "' and o.toContact.linkman='" + + linkman + "'").get(0); + if (volume >= 5) { + deleteFee = Boolean.TRUE; + } + } + FeeType ft = getFeeType("送货费"); + double shf = cr.getDeliveryFee(); + Boolean temp = Boolean.TRUE; + for (Long id : sids) { + List fs = this.commonDao + .findByQuery("from Fee f where f.billId=" + + id + + " and f.billObject='ORDER' and f.feeName.id=" + + ft.getId() + " and f.operator='system'"); + if (fs.size() > 0) { + temp = Boolean.FALSE; + if (deleteFee) { + for (Fee f : fs) { this.commonDao.delete(f); } } return; } } - if(temp&&!deleteFee){ - Fee f=createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, 1,shf, - shf*rate, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - f.setRemark(shf+"*"+rate); + if (temp && !deleteFee) { + Fee f = createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), ft, 1, shf, shf * rate, + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); + f.setRemark(shf + "*" + rate); this.commonDao.store(f); } - this.commonDao.store(fee); - } - } - } - - //吉利and领克 - void createJLandLKCusFee(Order o){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - String lineName=""; - double price=0;//单价 - double volume=0;//体积 - if(o.getToCityCountiy()!=null){ - if(o.getToCityCountiy().getZone()!=null){ - Zone zone=commonDao.load(Zone.class, 1050L); - lineName=zone.getName()+"-"+o.getToCityCountiy().getZone().getName(); - }else{ - throw new BusinessException("收货省份不存在!"); - } - }else{ - throw new BusinessException("收货区域不存在!"); - } - //合同是否存在 - ContractRate cr=null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.balance.id=:balanceId and cr.routeFee.name=:name ", - new String[] { "balanceId","name"},new Object[] {o.getConsignor().getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - price=cr.getPrice1(); - //总立方 - volume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.toCityCountiy.zone.name=:name ", - new String[] { "id","planFromDate","toName","name"},new Object[] {o.getConsignor().getId(),sdf.format(o.getPlanFromDate()),o.getToName(),o.getToCityCountiy().getZone().getName()}).get(0); - - List Orders = commonDao.findByQuery(" from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.toCityCountiy.zone.name=:name ", - new String[] { "id","planFromDate","toName","name"},new Object[] {o.getConsignor().getId(),sdf.format(o.getPlanFromDate()),o.getToName(),o.getToCityCountiy().getZone().getName()}); - if(volume>1){ - if(Orders.size()>0){ - for(Order order:Orders){ - //武汉市内 - if(order.getToCityCountiy().getName().equals("武汉市")){ - price=44.1; - double zj=price*volume; - this.createFee(zj, volume, order); - }else if(order.getToCityCountiy().getName().equals("九江市")){ - price=132.3; - double zj=price*volume; - this.createFee(zj, volume, order); - }else if(order.getToCityCountiy().getName().equals("岳阳市")){ - price=127.4; - double zj=price*volume; - this.createFee(zj, volume, order); - }else{ - double zj=price*volume; - this.createFee(zj, volume, order); - } - - } - } - }else{ - if(Orders.size()>0){ - if(Orders.size()==1){ - Order order=Orders.get(0); - if(order.getToCityCountiy().getName().equals("武汉市")){ - double ysf=44.1; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else if(order.getToCityCountiy().getName().equals("九江市")){ - double ysf=132.3; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else if(order.getToCityCountiy().getName().equals("岳阳市")){ - double ysf=127.4; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - double ysf=price; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - } - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - }else{ - for(Order order:Orders){ - if(order.getToCityCountiy().getName().equals("武汉市")){ - double zj=44.1; - createFee(zj, volume, order); - }else if(order.getToCityCountiy().getName().equals("九江市")){ - double zj=132.3; - createFee(zj, volume, order); - }else if(order.getToCityCountiy().getName().equals("岳阳市")){ - double zj=127.4; - createFee(zj, volume, order); - }else{ - double ysf=(price/volume)*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - } - } - - } - } - }else{ - throw new BusinessException("合同费率不存在!"); - } - - } - - //九州顺天 - /** - * 目的地-吉安 1方一下max(件数*10元/件,体积*100元/方)最高100,1方以上100元/方 送货费80元/票 - * 返回服务 没有送货费,100元/方 - * @param o - */ - void createJZSTFee(Order order){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - double price=0; - double volume=0; - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ - throw new BusinessException("城市信息为空!"); - } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - //返回服务不生成送货费 - if(!order.getToCityCountiy().getName().equals("武汉市")){ - //送货费=80 - price=80; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费", price); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - List Orders = commonDao.findByQuery(" from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", - new String[] { "id","planFromDate"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate())}); - if(Orders.size()>0){ - for(Order o:Orders){ - if(order.getToCityCountiy().getName().equals("武汉市")){ - //返货服务=100/立方 - double ysf=100*o.getVolume(); - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - if(o.getVolume()>1){ - //大于1立方,每立方100 - double ysf=100*o.getVolume(); - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - double js=o.getQuantity()*10;//件数 - double lf=o.getVolume()*100;//方 - if(js>lf){ - price=js; - if(price>100){ - price=100; - } - }else{ - price=lf; - if(price>100){ - price=100; - } - } - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", price); - } - - } - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - } - }else{ - throw new BusinessException("合同费率不存在,请维护合同费率!"); - } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - - } - - //广汽传祺 - void createGQCQFee(Order order){ - /*SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - double price=0; - double zvolume=0;//总体积 - double fvolume=0;//分摊体积 - double volume=0;//单票体积 - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ - throw new BusinessException("城市信息为空!"); - } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - //总体积 - zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName not in ('三环','盖瑞特') ", - new String[] { "id","planFromDate"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate())}).get(0); - if(zvolume<30){ - price=cr.getPrice1(); - }else{ - price=cr.getPrice2(); - } - //分摊体积-同一家店的体积 - fvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.toCityCountiy.name=:name and o.toName not in ('三环','盖瑞特') ", - new String[] { "id","planFromDate","toName","name"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName(),order.getToCityCountiy().getName()}).get(0); - - List Orders = commonDao.findByQuery(" from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.toCityCountiy.name=:name ", - new String[] { "id","planFromDate","toName","name"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName(),order.getToCityCountiy().getName()}); - if(Orders.size()>0){ - for(Order o:Orders){ - if(o.getToName().equals("三环")){ - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "送货费", 150d); - }else if(o.getToName().equals("盖瑞特")){ - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "送货费", 480d); - }else{ - //单票体积小于2方+30送货费 - double shf=0; - if(o.getVolume()<2){ - shf=30; - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "送货费", shf); - } - //最小计费体积: 单票不足0.1方按0.1方计算,单票体积<2方+30送货费。 - if(fvolume<0.1){ - fvolume=0.1; - double ysf=price*fvolume; - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - //运输费=单价*体积+送货费 - double ysf=price*fvolume; - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", ysf); - } - } - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - } - }else{ - throw new BusinessException("合同费率不存在,请维护合同费率!"); - } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - }*/ - - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - double price=0; - double zvolume=0;//总体积 - double volume=0;//单票体积 - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ - throw new BusinessException("城市信息为空!"); - } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - //总体积 - zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", - new String[] { "id","planFromDate","toName"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}).get(0); - if(zvolume<30){ - price=cr.getPrice2(); - }else{ - price=cr.getPrice1(); - } - - - //单票体积小于2方+30送货费 - if(zvolume<2){ - double shf=30/zvolume*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费", shf); - System.out.println("送货费"); - } - - //最小计费体积: 单票不足0.1方按0.1方计算 - if(zvolume<0.1){ - double ysf=price*0.1; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - //运输费=单价*体积 - double ysf=price*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - } - }else{ - throw new BusinessException("合同费率不存在,请维护合同费率!"); - } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - - } - - void createHHGZCQFee(Order order){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - double price=0; - double zvolume=0;//总体积 - double volume=0;//单票体积 - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ - throw new BusinessException("城市信息为空!"); - } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - //总体积 - zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", - new String[] { "id","planFromDate","toName"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}).get(0); - if(zvolume<30){ - price=cr.getPrice2(); - }else{ - price=cr.getPrice1(); - } - - - //单票体积小于2方+30送货费 - if(zvolume<2){ - double shf=30/zvolume*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费", shf); - System.out.println("送货费"); - } - - //最小计费体积: 单票不足0.1方按0.1方计算 - if(zvolume<0.1){ - double ysf=price*0.1; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - //运输费=单价*体积 - double ysf=price*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - } - }else{ - throw new BusinessException("合同费率不存在,请维护合同费率!"); - } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - - } - - void createLPFee(Order order){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ - throw new BusinessException("城市信息为空!"); - } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - double ysf=order.getVolume()*cr.getPrice2(); - if(ysf<100){ - ysf=100; - } - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - throw new BusinessException("合同费率不存在,请维护合同费率!"); - } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - - } - - /** - * 韵达返货 - * 湖北每票=50+63*方数 - * 湖南每票=50+70*方数 - * 江西每票=50+80*方数 - */ - public void createYDSPFJFee(Order order){ - double money=0;//费用 - if(order.getToCityCountiy()!=null){ - if(order.getToCityCountiy().getZone()!=null){ - if(PlatFormHolder.getPlatForm().getName().equals("武汉圣达")){ - if(order.getToCityCountiy().getName().equals("岳阳")||order.getToCityCountiy().getName().equals("岳阳市")){ - money=50+(70*order.getVolume()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", money); - }else if(order.getToCityCountiy().getName().equals("九江")||order.getToCityCountiy().getName().equals("九江市")){ - money=50+(80*order.getVolume()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", money); - }else{ - money=50+(63*order.getVolume()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", money); - } - }else if(PlatFormHolder.getPlatForm().getName().equals("长沙圣达")){ - if(order.getToCityCountiy().getName().equals("岳阳")||order.getToCityCountiy().getName().equals("岳阳市")){ - money=50+(70*order.getVolume()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", money); - }else if(order.getToCityCountiy().getName().equals("九江")||order.getToCityCountiy().getName().equals("九江市")){ - money=50+(80*order.getVolume()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", money); - }else{ - money=50+(70*order.getVolume()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", money); - } - - }else if(PlatFormHolder.getPlatForm().getName().equals("南昌圣达")){ - if(order.getToCityCountiy().getName().equals("岳阳")||order.getToCityCountiy().getName().equals("岳阳市")){ - money=50+(70*order.getVolume()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", money); - }else if(order.getToCityCountiy().getName().equals("九江")||order.getToCityCountiy().getName().equals("九江市")){ - money=50+(80*order.getVolume()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", money); - }else{ - money=50+(80*order.getVolume()); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", money); - } - } - } - - } - } - - public void createYXZCFee(Order order){ - String VehicleType=""; - if(order.getExtends1()!=null){ - VehicleType=order.getExtends1().getName(); - if(VehicleType.trim().equals("9.6")){ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", 1600d); - }else if(VehicleType.trim().equals("16.5")){ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", 2000d); - } - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - - } - - void createYQFTFee(Order order){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - if(order.getToCityCountiy().getName().equals("九江市")){ - Long piao= (Long) commonDao.findByQuery("select count(o.id) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toCityCountiy.name='九江市' ", - new String[] { "id","planFromDate"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}).get(0); - double ysf=1500/piao; - List Orders = commonDao.findByQuery(" from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toCityCountiy.name='九江市' ", - new String[] { "id","planFromDate"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate())}); - if(Orders.size()>0){ - for(Order o:Orders){ - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", ysf); - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - } - }else{ - Long piao= (Long) commonDao.findByQuery("select count(o.id) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toCityCountiy.name!='九江市' ", - new String[] { "id","planFromDate"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}).get(0); - double ysf=900/piao; - List Orders = commonDao.findByQuery(" from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toCityCountiy.name!='九江市' ", - new String[] { "id","planFromDate"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate())}); - if(Orders.size()>0){ - for(Order o:Orders){ - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", ysf); - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - } - } - } - - void createYCCQFee(Order order){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - double price=0; - double zvolume=0;//总体积 - double volume=0;//单票体积 - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ - throw new BusinessException("城市信息为空!"); - } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - //总体积 - zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", - new String[] { "id","planFromDate","toName"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}).get(0); - if(zvolume<30){ - price=cr.getPrice2(); - }else{ - price=cr.getPrice1(); - } - - - //单票体积小于2方+30送货费 - if(zvolume<2){ - double shf=30/zvolume*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费", shf); - System.out.println("送货费"); - } - - //最小计费体积: 单票不足0.1方按0.1方计算 - if(zvolume<0.1){ - double ysf=price*0.1; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - //运输费=单价*体积 - double ysf=price*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - } - }else{ - throw new BusinessException("合同费率不存在,请维护合同费率!"); - } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - } - - void createGZHHBTFee(Order order){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - double price=0; - double zvolume=0;//总体积 - double volume=0;//单票体积 - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ - throw new BusinessException("城市信息为空!"); - } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - price=cr.getPrice1();//零单价 - - if(order.getVolume()<3){ - double fwf=30; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "服务费", fwf); - } - double ldf=0; - if(order.getVolume()<0.5){ - ldf=price*0.5; - }else{ - ldf=price*order.getVolume(); - } - //运输费=零单费+油品+轮胎+养护品; - double ysf=(ldf)+(order.getOilsQty()*6.3)+(order.getTyreQty()*9)+(order.getYhpQty()*4.5); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - throw new BusinessException("合同费率不存在,请维护合同费率!"); - } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - } - - void createhlyjxcqFee(Order order){ - - if (order.getFromCityCountiy() == null || order.getToCityCountiy() == null) { - throw new BusinessException("城市信息为空!"); - } - - String lineName = order.getFromCityCountiy().getName() + "-" + order.getToCityCountiy().getName(); - - - List contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - - Contract con = (contracts != null && !contracts.isEmpty()) ? contracts.get(0) : null; - - if (con != null) { - List contractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - - ContractRate cr = (contractRates != null && !contractRates.isEmpty()) ? contractRates.get(0) : null; - - if(cr!=null){ - double price = cr.getPrice1(); // 单价 - double volume = Math.max(order.getVolume(), 0.1); - double ysf = volume * price; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - - String province = order.getToCityCountiy().getZone().getName();//省 - double additionalFee = 0; - - if ("江西省".equals(province) && order.getVolume() < 2) { - additionalFee = 20; - } else if ("襄阳市".equals(order.getToCityCountiy().getName()) && order.getVolume() < 2) { - additionalFee = 30; - } - - if (additionalFee > 0) { - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费", additionalFee); - } - } - } - - - /*if(province.equals("江西省")){ - if(order.getVolume()<=0.5){ - double ysf=0.5*155; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else if(order.getVolume()>0.5&&order.getVolume()<=1){ - double ysf=1*155; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - double ysf=order.getVolume()*155; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - } - }else if(order.getToCityCountiy().getName().equals("九江")){ - if(order.getVolume()<=0.5){ - double ysf=0.5*155; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else if(order.getVolume()>0.5&&order.getVolume()<=1){ - double ysf=1*155; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - double ysf=order.getVolume()*155; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - } - }else{ - double ysf=order.getVolume()*55; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - - } */ - - } - - void createhhFTFee(Order order){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - String province=""; - if(order.getExtends1()!=null){ - - }else{ - throw new BusinessException("计费车型不能为空,请维护!"); - } - - //总体积 - double zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.extends1.id=:extends1Id ", - new String[] { "id","planFromDate","extends1Id"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getExtends1().getId()}).get(0); - - double price=Double.parseDouble(order.getExtends1().getDescription());//车型价格 - - double ysf=price/zvolume*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - } - - public void createFee(double zj,double volume,Order order){ - double ysf=(zj/volume)*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - - void createContractFee(Order order,Long fid,Long tid,String shipmentMethod,String unit,String is_city,double qty){ -// for(Contract c:getContract(order.getConsignor().getId(),order.getContractor().getId())){ - List crs = null; - Boolean DJJJ=order.getContractor().getName().equals("大金旧件")?Boolean.TRUE:Boolean.FALSE; - Long platFormId=new Long("1"); - if(DJJJ){ - platFormId=new Long("3574"); - } - if(is_city.equals("1")){ - crs=commonDao.findByQuery("from ContractRate c where c.contract.platForm.id=:platFormId and c.contract.balance.id=:balanceId and c.routeFee.fromCity.id=:fid and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode and c.unit=:unit ", - new String[]{"platFormId","balanceId","fid","tid","transportMode","unit"},new Object[]{platFormId,order.getConsignor().getId(),fid,tid,shipmentMethod,unit}); - }else if(is_city.equals("2")){ - crs=commonDao.findByQuery("from ContractRate c where c.contract.platForm.id=:platFormId and c.contract.balance.id=:balanceId and c.routeFee.fromZone.id=:fid and c.routeFee.toZone.id=:tid and c.transportMode=:transportMode and c.unit=:unit ", - new String[]{"platFormId","balanceId","fid","tid","transportMode","unit"},new Object[]{platFormId,order.getConsignor().getId(),fid,tid,shipmentMethod,unit}); - }else if(is_city.equals("3")){ - crs=commonDao.findByQuery("from ContractRate c where c.contract.platForm.id=:platFormId and c.contract.balance.id=:balanceId and c.routeFee.fromZone.id=:fid and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode and c.unit=:unit ", - new String[]{"platFormId","balanceId","fid","tid","transportMode","unit"},new Object[]{platFormId,order.getConsignor().getId(),fid,tid,shipmentMethod,unit}); - } - Boolean kd=Boolean.FALSE; - if(shipmentMethod.equals(ShipmentMethod.ZERO_SINGLE)){ - kd=Boolean.TRUE; - } - for(ContractRate cr:crs){ - double price=0; - double ljdj=0;//快递的累计单价 - //double qty=order.getWeightThree(); - String remark=""; - if(kd){ - if(qty>cr.getFromRange1() &&qty<=cr.getToRange1()){ - price=DoubleUtils.format3Fraction(cr.getPrice1()); - } - if(qty>=cr.getFromRange2()){ - price=DoubleUtils.format3Fraction(cr.getPrice2()); - ljdj=DoubleUtils.format3Fraction(cr.getPrice2()); - } - }else{ - if(order.getConsignor().getCode().equals("XGGL")&&cr.getVehiclePrice()>0){ - qty=qty-1; - } - if(cr.getFromRange1()==null){ - price=DoubleUtils.format3Fraction(cr.getPrice1()); - }else if(cr.getFromRange1()!=null&&qty>=cr.getFromRange1() &&(cr.getToRange1()==null||qty<=cr.getToRange1())){ - price=DoubleUtils.format3Fraction(cr.getPrice1()); - }else if(cr.getFromRange2()!=null&&qty>=cr.getFromRange2()&&(cr.getToRange2()==null||qty<=cr.getToRange2())){ - price=DoubleUtils.format3Fraction(cr.getPrice2()); - ljdj=DoubleUtils.format3Fraction(cr.getPrice2()); - }else if(cr.getFromRange3()!=null&&qty>=cr.getFromRange3()&&(cr.getToRange3()==null||qty<=cr.getToRange3())){ - price=DoubleUtils.format3Fraction(cr.getPrice3()); - ljdj=DoubleUtils.format3Fraction(cr.getPrice3()); - }else if(cr.getFromRange4()!=null&&qty>=cr.getFromRange4()&&(cr.getToRange4()==null||qty<=cr.getToRange4())){ - price=DoubleUtils.format3Fraction(cr.getPrice4()); - ljdj=DoubleUtils.format3Fraction(cr.getPrice4()); - }else if(cr.getFromRange5()!=null&&qty>=cr.getFromRange5()&&(cr.getToRange5()==null||qty<=cr.getToRange5())){ - price=DoubleUtils.format3Fraction(cr.getPrice5()); - ljdj=DoubleUtils.format3Fraction(cr.getPrice5()); - }else if(cr.getFromRange6()!=null&&qty>=cr.getFromRange6()&&(cr.getToRange6()==null||qty<=cr.getToRange6())){ - price=DoubleUtils.format3Fraction(cr.getPrice6()); - ljdj=DoubleUtils.format3Fraction(cr.getPrice6()); - }else if(cr.getFromRange7()!=null&&qty>=cr.getFromRange7()){ - price=DoubleUtils.format3Fraction(cr.getPrice7()); - ljdj=DoubleUtils.format3Fraction(cr.getPrice7()); - } - if(order.getConsignor().getCode().equals("XGGL")&&cr.getVehiclePrice()>0){ - qty=qty-1; - remark="首重"+cr.getVehiclePrice()+";"+price+"*"+qty; - }else{ - remark=price+"*"+qty; - } - } - if(shipmentMethod.equals(ShipmentMethod.NIGHT_MATH)||shipmentMethod.equals(ShipmentMethod.SPECIAL_CAR)){ - order.setFreight(0); - }else{ - order.setFreight(price); - } - Double totalFee=price*qty; - Fee fee=null; - //快递算法,起步价+累计金额 - if(ljdj>0&&kd){ - totalFee=price*(qty-1); - qty=qty-1; - } - fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), cr.getFeeType(), - qty, price, totalFee, FeePayReceive.RECEIVE, cr.getUnit(), order.getContractor()); - if(order.getConsignor().getCode().equals("XGGL")){ - if(cr.getVehiclePrice()>0){//如果首重大于0 - fee.setTotalFee(DoubleUtils.format2Fraction(fee.getTotalFee()+cr.getVehiclePrice())); - } - } - if(kd){ - order.setIncome(cr.getPrice2()); - order.setFreight(cr.getPrice1()); - fee.setRemark("起步价"+cr.getPrice1()); - if(ljdj>0){ - fee.setRemark(fee.getRemark()+"+续重"+cr.getPrice2()+"*"+qty); - fee.setInvQty(cr.getPrice1()); - fee.setTotalFee(fee.getTotalFee()+cr.getPrice1()); - } - }else{ - fee.setRemark(remark); - } - if(kd){ - fee.setInvWeight(5); - fee.setTotalFee(fee.getTotalFee()+fee.getInvWeight()); - fee.setRemark(fee.getRemark()+"+5元回单费用"); - } - if(cr.getMinPrice()!=null&&fee.getTotalFee()0 && order.getConsignor().getCode().equals("XGGL")){ - String method=order.getShipmentMethod()==null?"":order.getShipmentMethod(); - if(method.equals(ShipmentMethod.ZERO_SINGLE)){ - List sfs=commonDao.findByQuery(" from SpecialFee sf where sf.contract.balance.id=:balanceId", - new String[]{"balanceId"},new Object[]{order.getConsignor().getId()}); - for(SpecialFee sf:sfs){ - double totalFee=0; - double qty=0; - if(sf.getUnit().equals(MeasureUnit.WEIGHT)){ - qty=order.getWeightThree(); + + // 吉利and领克 + void createJLandLKCusFee(Order o) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String lineName = ""; + double price = 0;// 单价 + double volume = 0;// 体积 + if (o.getToCityCountiy() != null) { + if (o.getToCityCountiy().getZone() != null) { + Zone zone = commonDao.load(Zone.class, 1050L); + lineName = zone.getName() + "-" + + o.getToCityCountiy().getZone().getName(); + } else { + throw new BusinessException("收货省份不存在!"); + } + } else { + throw new BusinessException("收货区域不存在!"); + } + // 合同是否存在 + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.balance.id=:balanceId and cr.routeFee.name=:name ", + new String[] { "balanceId", "name" }, new Object[] { + o.getConsignor().getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + price = cr.getPrice1(); + // 总立方 + volume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.toCityCountiy.zone.name=:name ", + new String[] { "id", "planFromDate", "toName", + "name" }, + new Object[] { o.getConsignor().getId(), + sdf.format(o.getPlanFromDate()), + o.getToName(), + o.getToCityCountiy().getZone().getName() }) + .get(0); + + List Orders = commonDao + .findByQuery( + " from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.toCityCountiy.zone.name=:name ", + new String[] { "id", "planFromDate", "toName", + "name" }, + new Object[] { o.getConsignor().getId(), + sdf.format(o.getPlanFromDate()), + o.getToName(), + o.getToCityCountiy().getZone().getName() }); + if (volume > 1) { + if (Orders.size() > 0) { + for (Order order : Orders) { + // 武汉市内 + if (order.getToCityCountiy().getName().equals("武汉市")) { + price = 44.1; + double zj = price * volume; + this.createFee(zj, volume, order); + } else if (order.getToCityCountiy().getName() + .equals("九江市")) { + price = 132.3; + double zj = price * volume; + this.createFee(zj, volume, order); + } else if (order.getToCityCountiy().getName() + .equals("岳阳市")) { + price = 127.4; + double zj = price * volume; + this.createFee(zj, volume, order); + } else { + double zj = price * volume; + this.createFee(zj, volume, order); + } + } - totalFee=qty*sf.getPrice(); - Boolean temp=Boolean.FALSE; - if(totalFee 0) { + if (Orders.size() == 1) { + Order order = Orders.get(0); + if (order.getToCityCountiy().getName().equals("武汉市")) { + double ysf = 44.1; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } else if (order.getToCityCountiy().getName() + .equals("九江市")) { + double ysf = 132.3; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } else if (order.getToCityCountiy().getName() + .equals("岳阳市")) { + double ysf = 127.4; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } else { + double ysf = price; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } else { + for (Order order : Orders) { + if (order.getToCityCountiy().getName() + .equals("武汉市")) { + double zj = 44.1; + createFee(zj, volume, order); + } else if (order.getToCityCountiy().getName() + .equals("九江市")) { + double zj = 132.3; + createFee(zj, volume, order); + } else if (order.getToCityCountiy().getName() + .equals("岳阳市")) { + double zj = 127.4; + createFee(zj, volume, order); + } else { + double ysf = (price / volume) + * order.getVolume(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } + } } - totalFee=totalFee>=sf.getMinPrice()?totalFee:sf.getMinPrice(); + + } + } + } else { + throw new BusinessException("合同费率不存在!"); + } + + } + + // 九州顺天 + /** + * 目的地-吉安 1方一下max(件数*10元/件,体积*100元/方)最高100,1方以上100元/方 送货费80元/票 返回服务 + * 没有送货费,100元/方 + * + * @param o + */ + void createJZSTFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + double price = 0; + double volume = 0; + String lineName = ""; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + } else { + throw new BusinessException("城市信息为空!"); + } + Contract con = null; + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + // 返回服务不生成送货费 + if (!order.getToCityCountiy().getName().equals("武汉市")) { + // 送货费=80 + price = 80; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", price); + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } + List Orders = commonDao + .findByQuery( + " from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", + new String[] { "id", "planFromDate" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()) }); + if (Orders.size() > 0) { + for (Order o : Orders) { + if (order.getToCityCountiy().getName().equals("武汉市")) { + // 返货服务=100/立方 + double ysf = 100 * o.getVolume(); + feeManager.saveInputFee(o.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } else { + if (o.getVolume() > 1) { + // 大于1立方,每立方100 + double ysf = 100 * o.getVolume(); + feeManager.saveInputFee(o.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } else { + double js = o.getQuantity() * 10;// 件数 + double lf = o.getVolume() * 100;// 方 + if (js > lf) { + price = js; + if (price > 100) { + price = 100; + } + } else { + price = lf; + if (price > 100) { + price = 100; + } + } + feeManager.saveInputFee(o.getId(), + BillObjectType.ORDER, null, "运输费", + price); + } + + } + feeManager.refreshBillFee(o.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } + } + } else { + throw new BusinessException("合同费率不存在,请维护合同费率!"); + } + } else { + throw new BusinessException("客户合同不存在,请维护客户合同!"); + } + + } + + // 广汽传祺 + void createGQCQFee(Order order) { + /* + * SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); double + * price=0; double zvolume=0;//总体积 double fvolume=0;//分摊体积 double + * volume=0;//单票体积 String lineName=""; + * if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ + * lineName + * =order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy + * ().getName(); }else{ throw new BusinessException("城市信息为空!"); } + * Contract con=null; List Contracts = + * commonDao.findByQuery(" from Contract co where co.balance.id=:id ", + * new String[] { "id"},new Object[] {order.getConsignor().getId()}); + * if(Contracts.size()>0){ con=Contracts.get(0); ContractRate cr =null; + * List ContractRates = commonDao.findByQuery( + * " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name " + * , new String[] {"id", "name"},new Object[] {con.getId(),lineName}); + * if(ContractRates.size()>0){ cr=ContractRates.get(0); //总体积 zvolume= + * (Double) commonDao.findByQuery( + * "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName not in ('三环','盖瑞特') " + * , new String[] { "id","planFromDate"},new Object[] + * {order.getConsignor + * ().getId(),sdf.format(order.getPlanFromDate())}).get(0); + * if(zvolume<30){ price=cr.getPrice1(); }else{ price=cr.getPrice2(); } + * //分摊体积-同一家店的体积 fvolume= (Double) commonDao.findByQuery( + * "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.toCityCountiy.name=:name and o.toName not in ('三环','盖瑞特') " + * , new String[] { "id","planFromDate","toName","name"},new Object[] + * {order + * .getConsignor().getId(),sdf.format(order.getPlanFromDate()),order + * .getToName(),order.getToCityCountiy().getName()}).get(0); + * + * List Orders = commonDao.findByQuery( + * " from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.toCityCountiy.name=:name " + * , new String[] { "id","planFromDate","toName","name"},new Object[] + * {order + * .getConsignor().getId(),sdf.format(order.getPlanFromDate()),order + * .getToName(),order.getToCityCountiy().getName()}); + * if(Orders.size()>0){ for(Order o:Orders){ + * if(o.getToName().equals("三环")){ feeManager.saveInputFee(o.getId(), + * BillObjectType.ORDER, null, "送货费", 150d); }else + * if(o.getToName().equals("盖瑞特")){ feeManager.saveInputFee(o.getId(), + * BillObjectType.ORDER, null, "送货费", 480d); }else{ //单票体积小于2方+30送货费 + * double shf=0; if(o.getVolume()<2){ shf=30; + * feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "送货费", + * shf); } //最小计费体积: 单票不足0.1方按0.1方计算,单票体积<2方+30送货费。 if(fvolume<0.1){ + * fvolume=0.1; double ysf=price*fvolume; + * feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", + * ysf); }else{ //运输费=单价*体积+送货费 double ysf=price*fvolume; + * feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", + * ysf); } } feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, + * Boolean.TRUE); } } }else{ throw new + * BusinessException("合同费率不存在,请维护合同费率!"); } }else{ throw new + * BusinessException("客户合同不存在,请维护客户合同!"); } + */ + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + double price = 0; + double zvolume = 0;// 总体积 + double volume = 0;// 单票体积 + String lineName = ""; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + } else { + throw new BusinessException("城市信息为空!"); + } + Contract con = null; + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + // 总体积 + zvolume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", + new String[] { "id", "planFromDate", "toName" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }).get(0); + if (zvolume < 30) { + price = cr.getPrice2(); + } else { + price = cr.getPrice1(); + } + + // 单票体积小于2方+30送货费 + if (zvolume < 2) { + double shf = 30 / zvolume * order.getVolume(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", shf); + System.out.println("送货费"); + } + + // 最小计费体积: 单票不足0.1方按0.1方计算 + if (zvolume < 0.1) { + double ysf = price * 0.1; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } else { + // 运输费=单价*体积 + double ysf = price * order.getVolume(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } + } else { + throw new BusinessException("合同费率不存在,请维护合同费率!"); + } + } else { + throw new BusinessException("客户合同不存在,请维护客户合同!"); + } + + } + + void createHHGZCQFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + double price = 0; + double zvolume = 0;// 总体积 + double volume = 0;// 单票体积 + String lineName = ""; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + } else { + throw new BusinessException("城市信息为空!"); + } + Contract con = null; + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + // 总体积 + zvolume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", + new String[] { "id", "planFromDate", "toName" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }).get(0); + if (zvolume < 30) { + price = cr.getPrice2(); + } else { + price = cr.getPrice1(); + } + + // 单票体积小于2方+30送货费 + if (zvolume < 2) { + double shf = 30 / zvolume * order.getVolume(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", shf); + System.out.println("送货费"); + } + + // 最小计费体积: 单票不足0.1方按0.1方计算 + if (zvolume < 0.1) { + double ysf = price * 0.1; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } else { + // 运输费=单价*体积 + double ysf = price * order.getVolume(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } + } else { + throw new BusinessException("合同费率不存在,请维护合同费率!"); + } + } else { + throw new BusinessException("客户合同不存在,请维护客户合同!"); + } + + } + + void createLPFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String lineName = ""; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + } else { + throw new BusinessException("城市信息为空!"); + } + Contract con = null; + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + double ysf = order.getVolume() * cr.getPrice2(); + if (ysf < 100) { + ysf = 100; + } + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, + null, "运输费", ysf); + } else { + throw new BusinessException("合同费率不存在,请维护合同费率!"); + } + } else { + throw new BusinessException("客户合同不存在,请维护客户合同!"); + } + + } + + /** + * 韵达返货 湖北每票=50+63*方数 湖南每票=50+70*方数 江西每票=50+80*方数 + */ + public void createYDSPFJFee(Order order) { + double money = 0;// 费用 + if (order.getToCityCountiy() != null) { + if (order.getToCityCountiy().getZone() != null) { + if (PlatFormHolder.getPlatForm().getName().equals("武汉圣达")) { + if (order.getToCityCountiy().getName().equals("岳阳") + || order.getToCityCountiy().getName().equals("岳阳市")) { + money = 50 + (70 * order.getVolume()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", money); + } else if (order.getToCityCountiy().getName().equals("九江") + || order.getToCityCountiy().getName().equals("九江市")) { + money = 50 + (80 * order.getVolume()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", money); + } else { + money = 50 + (63 * order.getVolume()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", money); + } + } else if (PlatFormHolder.getPlatForm().getName() + .equals("长沙圣达")) { + if (order.getToCityCountiy().getName().equals("岳阳") + || order.getToCityCountiy().getName().equals("岳阳市")) { + money = 50 + (70 * order.getVolume()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", money); + } else if (order.getToCityCountiy().getName().equals("九江") + || order.getToCityCountiy().getName().equals("九江市")) { + money = 50 + (80 * order.getVolume()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", money); + } else { + money = 50 + (70 * order.getVolume()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", money); + } + + } else if (PlatFormHolder.getPlatForm().getName() + .equals("南昌圣达")) { + if (order.getToCityCountiy().getName().equals("岳阳") + || order.getToCityCountiy().getName().equals("岳阳市")) { + money = 50 + (70 * order.getVolume()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", money); + } else if (order.getToCityCountiy().getName().equals("九江") + || order.getToCityCountiy().getName().equals("九江市")) { + money = 50 + (80 * order.getVolume()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", money); + } else { + money = 50 + (80 * order.getVolume()); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", money); + } + } + } + + } + } + + public void createYXZCFee(Order order) { + String VehicleType = ""; + if (order.getExtends1() != null) { + VehicleType = order.getExtends1().getName(); + if (VehicleType.trim().equals("9.6")) { + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, + null, "运输费", 1600d); + } else if (VehicleType.trim().equals("16.5")) { + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, + null, "运输费", 2000d); + } + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + } + + } + + void createYQFTFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + if (order.getToCityCountiy().getName().equals("九江市")) { + Long piao = (Long) commonDao + .findByQuery( + "select count(o.id) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toCityCountiy.name='九江市' ", + new String[] { "id", "planFromDate" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }).get(0); + double ysf = 1500 / piao; + List Orders = commonDao + .findByQuery( + " from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toCityCountiy.name='九江市' ", + new String[] { "id", "planFromDate" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()) }); + if (Orders.size() > 0) { + for (Order o : Orders) { + feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, + null, "运输费", ysf); + feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, + Boolean.TRUE); + } + } + } else { + Long piao = (Long) commonDao + .findByQuery( + "select count(o.id) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toCityCountiy.name!='九江市' ", + new String[] { "id", "planFromDate" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }).get(0); + double ysf = 900 / piao; + List Orders = commonDao + .findByQuery( + " from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toCityCountiy.name!='九江市' ", + new String[] { "id", "planFromDate" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()) }); + if (Orders.size() > 0) { + for (Order o : Orders) { + feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, + null, "运输费", ysf); + feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, + Boolean.TRUE); + } + } + } + } + + void createYCCQFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + double price = 0; + double zvolume = 0;// 总体积 + double volume = 0;// 单票体积 + String lineName = ""; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + } else { + throw new BusinessException("城市信息为空!"); + } + Contract con = null; + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + // 总体积 + zvolume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", + new String[] { "id", "planFromDate", "toName" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }).get(0); + if (zvolume < 30) { + price = cr.getPrice2(); + } else { + price = cr.getPrice1(); + } + + // 单票体积小于2方+30送货费 + if (zvolume < 2) { + double shf = 30 / zvolume * order.getVolume(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", shf); + System.out.println("送货费"); + } + + // 最小计费体积: 单票不足0.1方按0.1方计算 + if (zvolume < 0.1) { + double ysf = price * 0.1; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } else { + // 运输费=单价*体积 + double ysf = price * order.getVolume(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } + } else { + throw new BusinessException("合同费率不存在,请维护合同费率!"); + } + } else { + throw new BusinessException("客户合同不存在,请维护客户合同!"); + } + + } + + void createGZHHBTFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + double price = 0; + double zvolume = 0;// 总体积 + double volume = order.getVolume();// 单票体积 + String lineName = ""; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + } else { + throw new BusinessException("城市信息为空!"); + } + Contract con = null; + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + price = cr.getPrice1();// 零单价 + + if (order.getVolume() < 3) {// 体积小于3立方收取服务费 + double fwf = 27; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "服务费", fwf); + } + double ldf = 0; + if (order.getVolume() < 0.5) { + ldf = price * 0.5; + } + ldf = price * volume; + // 根据目标省份不同,油品、轮胎、养护单价不一致 + String sf = order.getToCityCountiy().getZone().getName(); + double yp_price = 0; + double lt_price = 0; + double yh_price = 0; + if (sf.equals("湖北省")) { + yp_price = 5.67; + lt_price = 8.1; + yh_price = 4.05; + } else if (sf.equals("江西省")) { + yp_price = 5.91; + lt_price = 8.44; + yh_price = 4.22; + } + // 运输费=零单费+油品+轮胎+养护品;t + double ysf = (ldf) + (order.getOilsQty() * yp_price) + + (order.getTyreQty() * lt_price) + + (order.getYhpQty() * yh_price); + // feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, + // null, "运输费", ysf); + Fee fee = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), cr.getFeeType(), volume, price, + ysf, FeePayReceive.RECEIVE, cr.getUnit(), + order.getContractor()); + fee.setRemark("运输费:" + price + "*" + volume + ";油品费:" + + yp_price + "*" + order.getOilsQty() + "轮胎费:" + + lt_price + "*" + order.getTyreQty() + "养护费:" + + yh_price + "*" + order.getYhpQty()); + this.commonDao.store(fee); + } else { + throw new BusinessException("合同费率不存在,请维护合同费率!"); + } + } else { + throw new BusinessException("客户合同不存在,请维护客户合同!"); + } + + } + + void createhlyjxcqFee(Order order) { + + if (order.getFromCityCountiy() == null + || order.getToCityCountiy() == null) { + throw new BusinessException("城市信息为空!"); + } + + String lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + + List contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + + Contract con = (contracts != null && !contracts.isEmpty()) ? contracts + .get(0) : null; + + if (con != null) { + List contractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + + ContractRate cr = (contractRates != null && !contractRates + .isEmpty()) ? contractRates.get(0) : null; + + if (cr != null) { + double price = cr.getPrice1(); // 单价 + double volume = Math.max(order.getVolume(), 0.1); + double ysf = volume * price; + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, + null, "运输费", ysf); + + String province = order.getToCityCountiy().getZone().getName();// 省 + double additionalFee = 0; + + if ("江西省".equals(province) && order.getVolume() < 2) { + additionalFee = 20; + } else if ("襄阳市".equals(order.getToCityCountiy().getName()) + && order.getVolume() < 2) { + additionalFee = 30; + } + + if (additionalFee > 0) { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", additionalFee); + } + } + } + + /* + * if(province.equals("江西省")){ if(order.getVolume()<=0.5){ double + * ysf=0.5*155; feeManager.saveInputFee(order.getId(), + * BillObjectType.ORDER, null, "运输费", ysf); }else + * if(order.getVolume()>0.5&&order.getVolume()<=1){ double ysf=1*155; + * feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, + * "运输费", ysf); }else{ double ysf=order.getVolume()*155; + * feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, + * "运输费", ysf); } }else + * if(order.getToCityCountiy().getName().equals("九江")){ + * if(order.getVolume()<=0.5){ double ysf=0.5*155; + * feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, + * "运输费", ysf); }else if(order.getVolume()>0.5&&order.getVolume()<=1){ + * double ysf=1*155; feeManager.saveInputFee(order.getId(), + * BillObjectType.ORDER, null, "运输费", ysf); }else{ double + * ysf=order.getVolume()*155; feeManager.saveInputFee(order.getId(), + * BillObjectType.ORDER, null, "运输费", ysf); } }else{ double + * ysf=order.getVolume()*55; feeManager.saveInputFee(order.getId(), + * BillObjectType.ORDER, null, "运输费", ysf); + * + * } + */ + + } + + void createhhFTFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String province = ""; + if (order.getExtends1() != null) { + + } else { + throw new BusinessException("计费车型不能为空,请维护!"); + } + + // 总体积 + double zvolume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.extends1.id=:extends1Id ", + new String[] { "id", "planFromDate", "extends1Id" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getExtends1().getId() }).get(0); + + double price = Double.parseDouble(order.getExtends1().getDescription());// 车型价格 + + double ysf = price / zvolume * order.getVolume(); + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, + "运输费", ysf); + } + + public void createFee(double zj, double volume, Order order) { + double ysf = (zj / volume) * order.getVolume(); + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, + "运输费", ysf); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + } + + void createContractFee(Order order, Long fid, Long tid, + String shipmentMethod, String unit, String is_city, double qty) { + // for(Contract + // c:getContract(order.getConsignor().getId(),order.getContractor().getId())){ + List crs = null; + Boolean DJJJ = order.getContractor().getName().equals("大金旧件") ? Boolean.TRUE + : Boolean.FALSE; + Long platFormId = new Long("1"); + if (DJJJ) { + platFormId = new Long("3574"); + } + if (is_city.equals("1")) { + crs = commonDao + .findByQuery( + "from ContractRate c where c.contract.platForm.id=:platFormId and c.contract.balance.id=:balanceId and c.routeFee.fromCity.id=:fid and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode and c.unit=:unit ", + new String[] { "platFormId", "balanceId", "fid", + "tid", "transportMode", "unit" }, + new Object[] { platFormId, + order.getConsignor().getId(), fid, tid, + shipmentMethod, unit }); + } else if (is_city.equals("2")) { + crs = commonDao + .findByQuery( + "from ContractRate c where c.contract.platForm.id=:platFormId and c.contract.balance.id=:balanceId and c.routeFee.fromZone.id=:fid and c.routeFee.toZone.id=:tid and c.transportMode=:transportMode and c.unit=:unit ", + new String[] { "platFormId", "balanceId", "fid", + "tid", "transportMode", "unit" }, + new Object[] { platFormId, + order.getConsignor().getId(), fid, tid, + shipmentMethod, unit }); + } else if (is_city.equals("3")) { + crs = commonDao + .findByQuery( + "from ContractRate c where c.contract.platForm.id=:platFormId and c.contract.balance.id=:balanceId and c.routeFee.fromZone.id=:fid and c.routeFee.toCity.id=:tid and c.transportMode=:transportMode and c.unit=:unit ", + new String[] { "platFormId", "balanceId", "fid", + "tid", "transportMode", "unit" }, + new Object[] { platFormId, + order.getConsignor().getId(), fid, tid, + shipmentMethod, unit }); + } + Boolean kd = Boolean.FALSE; + if (shipmentMethod.equals(ShipmentMethod.ZERO_SINGLE)) { + kd = Boolean.TRUE; + } + for (ContractRate cr : crs) { + double price = 0; + double ljdj = 0;// 快递的累计单价 + // double qty=order.getWeightThree(); + String remark = ""; + if (kd) { + if (qty > cr.getFromRange1() && qty <= cr.getToRange1()) { + price = DoubleUtils.format3Fraction(cr.getPrice1()); + } + if (qty >= cr.getFromRange2()) { + price = DoubleUtils.format3Fraction(cr.getPrice2()); + ljdj = DoubleUtils.format3Fraction(cr.getPrice2()); + } + } else { + if (order.getConsignor().getCode().equals("XGGL") + && cr.getVehiclePrice() > 0) { + qty = qty - 1; + } + if (cr.getFromRange1() == null) { + price = DoubleUtils.format3Fraction(cr.getPrice1()); + } else if (cr.getFromRange1() != null + && qty >= cr.getFromRange1() + && (cr.getToRange1() == null || qty <= cr.getToRange1())) { + price = DoubleUtils.format3Fraction(cr.getPrice1()); + } else if (cr.getFromRange2() != null + && qty >= cr.getFromRange2() + && (cr.getToRange2() == null || qty <= cr.getToRange2())) { + price = DoubleUtils.format3Fraction(cr.getPrice2()); + ljdj = DoubleUtils.format3Fraction(cr.getPrice2()); + } else if (cr.getFromRange3() != null + && qty >= cr.getFromRange3() + && (cr.getToRange3() == null || qty <= cr.getToRange3())) { + price = DoubleUtils.format3Fraction(cr.getPrice3()); + ljdj = DoubleUtils.format3Fraction(cr.getPrice3()); + } else if (cr.getFromRange4() != null + && qty >= cr.getFromRange4() + && (cr.getToRange4() == null || qty <= cr.getToRange4())) { + price = DoubleUtils.format3Fraction(cr.getPrice4()); + ljdj = DoubleUtils.format3Fraction(cr.getPrice4()); + } else if (cr.getFromRange5() != null + && qty >= cr.getFromRange5() + && (cr.getToRange5() == null || qty <= cr.getToRange5())) { + price = DoubleUtils.format3Fraction(cr.getPrice5()); + ljdj = DoubleUtils.format3Fraction(cr.getPrice5()); + } else if (cr.getFromRange6() != null + && qty >= cr.getFromRange6() + && (cr.getToRange6() == null || qty <= cr.getToRange6())) { + price = DoubleUtils.format3Fraction(cr.getPrice6()); + ljdj = DoubleUtils.format3Fraction(cr.getPrice6()); + } else if (cr.getFromRange7() != null + && qty >= cr.getFromRange7()) { + price = DoubleUtils.format3Fraction(cr.getPrice7()); + ljdj = DoubleUtils.format3Fraction(cr.getPrice7()); + } + if (order.getConsignor().getCode().equals("XGGL") + && cr.getVehiclePrice() > 0) { + qty = qty - 1; + remark = "首重" + cr.getVehiclePrice() + ";" + price + "*" + + qty; + } else { + remark = price + "*" + qty; + } + } + if (shipmentMethod.equals(ShipmentMethod.NIGHT_MATH) + || shipmentMethod.equals(ShipmentMethod.SPECIAL_CAR)) { + order.setFreight(0); + } else { + order.setFreight(price); + } + Double totalFee = price * qty; + Fee fee = null; + // 快递算法,起步价+累计金额 + if (ljdj > 0 && kd) { + totalFee = price * (qty - 1); + qty = qty - 1; + } + fee = this.createFeeInfo(order.getRelateBill3(), order.getId(), + BillObjectType.ORDER, order.getConsignor(), + cr.getFeeType(), qty, price, totalFee, + FeePayReceive.RECEIVE, cr.getUnit(), order.getContractor()); + if (order.getConsignor().getCode().equals("XGGL")) { + if (cr.getVehiclePrice() > 0) {// 如果首重大于0 + fee.setTotalFee(DoubleUtils.format2Fraction(fee + .getTotalFee() + cr.getVehiclePrice())); + } + } + if (kd) { + order.setIncome(cr.getPrice2()); + order.setFreight(cr.getPrice1()); + fee.setRemark("起步价" + cr.getPrice1()); + if (ljdj > 0) { + fee.setRemark(fee.getRemark() + "+续重" + cr.getPrice2() + + "*" + qty); + fee.setInvQty(cr.getPrice1()); + fee.setTotalFee(fee.getTotalFee() + cr.getPrice1()); + } + } else { + fee.setRemark(remark); + } + if (kd) { + fee.setInvWeight(5); + fee.setTotalFee(fee.getTotalFee() + fee.getInvWeight()); + fee.setRemark(fee.getRemark() + "+5元回单费用"); + } + if (cr.getMinPrice() != null + && fee.getTotalFee() < cr.getMinPrice()) { + totalFee = cr.getMinPrice(); + price = totalFee; + qty = 1; + fee.setUnit(MeasureUnit.TICKET); + fee.setTotalFee(totalFee); + fee.setPrice(price); + fee.setQuantity(qty); + fee.setRemark(fee.getRemark() + "不足最低价,按最低价算" + + cr.getMinPrice()); + } + this.commonDao.store(fee); + } + // } + + } + + void createGLFee(Order order) { + if (order.getWeight() > 0 + && order.getConsignor().getCode().equals("XGGL")) { + String method = order.getShipmentMethod() == null ? "" : order + .getShipmentMethod(); + if (method.equals(ShipmentMethod.ZERO_SINGLE)) { + List sfs = commonDao + .findByQuery( + " from SpecialFee sf where sf.contract.balance.id=:balanceId", + new String[] { "balanceId" }, + new Object[] { order.getConsignor().getId() }); + for (SpecialFee sf : sfs) { + double totalFee = 0; + double qty = 0; + if (sf.getUnit().equals(MeasureUnit.WEIGHT)) { + qty = order.getWeightThree(); + } + totalFee = qty * sf.getPrice(); + Boolean temp = Boolean.FALSE; + if (totalFee < sf.getMinPrice()) { + temp = Boolean.TRUE; + } + totalFee = totalFee >= sf.getMinPrice() ? totalFee : sf + .getMinPrice(); order.setFreight(sf.getPrice()); this.commonDao.store(order); - Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), sf.getFeeType(), - qty, sf.getPrice(), totalFee, FeePayReceive.RECEIVE, sf.getUnit(), order.getContractor()); - fee.setRemark(fee.getPrice()+"*"+fee.getQuantity()); - if(temp){ - fee.setRemark(fee.getRemark()+"不足最低价,按最低价算"+sf.getMinPrice()); + Fee fee = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), sf.getFeeType(), qty, + sf.getPrice(), totalFee, FeePayReceive.RECEIVE, + sf.getUnit(), order.getContractor()); + fee.setRemark(fee.getPrice() + "*" + fee.getQuantity()); + if (temp) { + fee.setRemark(fee.getRemark() + "不足最低价,按最低价算" + + sf.getMinPrice()); } this.commonDao.store(fee); } - }else{ - if(order.getFromCity()!=null&&order.getToCity()!=null) { - createContractFee(order, order.getFromCity().getId(),order.getToCity().getId(),method,MeasureUnit.WEIGHT,"1",order.getWeight()); - }else { + } else { + if (order.getFromCity() != null && order.getToCity() != null) { + createContractFee(order, order.getFromCity().getId(), order + .getToCity().getId(), method, MeasureUnit.WEIGHT, + "1", order.getWeight()); + } else { throw new BusinessException("提货区域和收获区域不能为空"); } - } - } - } - - void createDZFee(Order order){ - if(order.getPredictFee()>0&&order.getToCityCountiy()!=null){ - String zoneName=order.getToCityCountiy().getZone().getName(); - double xs=0; - if(zoneName.equals("湖南省")){ - xs=1.38; - }else if(zoneName.equals("湖北省")||zoneName.equals("江西省")){ - xs=1.13; } - //大众的运费=货值/1.13*1.65%(系数) -// 大众的保险费=货值*0.0015 - FeeType ft=getFeeType("运输费"); - Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, - xs/1.13/100, order.getPredictFee(), xs*order.getPredictFee()/1.13/100, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - fee2.setDescription(order.getPredictFee()+"货值/1.13*"+xs+"%"); - this.commonDao.store(fee2); - order.setFreight(order.getPredictFee()); - this.commonDao.store(order); } -// if(!order.getToCityCountiy().getName().equals("武汉市")){ -// //大众的运费=货值/1.13*1.65%(系数) -//// 大众的保险费=货值*0.0015 -//// FeeType ft=getFeeType("保险费"); -//// Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, -//// 1.5/1000, order.getPredictFee(), 1.5*order.getPredictFee()/1000, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); -// FeeType ft=getFeeType("运输费"); -// Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, -// 1.65/1.13/100, order.getPredictFee(), 1.65*order.getPredictFee()/1.13/100, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); -// fee2.setDescription(order.getPredictFee()+"货值/1.13*1.65%"); -// this.commonDao.store(fee2); -// order.setFreight(order.getPredictFee()); -// this.commonDao.store(order); -// }else{ -// //武汉市内运费=货值 -//// FeeType ft=getFeeType("运输费"); -//// Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, -//// 1, order.getPredictFee(), order.getPredictFee(), FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); -//// fee2.setDescription(order.getPredictFee()+"货值"); -//// this.commonDao.store(fee2); -// order.setFreight(order.getPredictFee()); -// this.commonDao.store(order); -// } -// } - } - - public void createDZFee(Date date1,Date date2,double xs){ - List os=this.commonDao.findByQuery("from Order o where o.consignor.id=3175 " - + "and to_char(o.planFromDate,'yyyy-mm-dd')>='"+DateUtil.formatDateYMDToStr(date1)+"'" - + "and to_char(o.planFromDate,'yyyy-mm-dd')<='"+DateUtil.formatDateYMDToStr(date2)+"'" - + " and o.status!='CANCEL'"); - FeeType ft=getFeeType("运输费"); - int i=0; - for(Order order:os){ - System.out.println(i+++"===="+new Date()); - if(order.getPredictFee()>0&&order.getToCityCountiy()!=null){ - List fees = this.commonDao.findByQuery( - "from Fee f where f.billId=:feeId and f.billCode=:billCode and (f.operator='system')", - new String[] { "feeId", "billCode" }, - new Object[] { order.getId(), order.getRelateBill3()}); + + void createDZFee(Order order) { + if (order.getPredictFee() > 0 && order.getToCityCountiy() != null) { + String zoneName = order.getToCityCountiy().getZone().getName(); + double xs = 0; + if (zoneName.equals("湖南省")) { + xs = 1.38; + } else if (zoneName.equals("湖北省") || zoneName.equals("江西省")) { + xs = 1.13; + } + // 大众的运费=货值/1.13*1.65%(系数) + // 大众的保险费=货值*0.0015 + FeeType ft = getFeeType("运输费"); + Fee fee2 = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, order.getConsignor(), + ft, xs / 1.13 / 100, order.getPredictFee(), + xs * order.getPredictFee() / 1.13 / 100, + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); + fee2.setDescription(order.getPredictFee() + "货值/1.13*" + xs + "%"); + this.commonDao.store(fee2); + order.setFreight(order.getPredictFee()); + this.commonDao.store(order); + } + // if(!order.getToCityCountiy().getName().equals("武汉市")){ + // //大众的运费=货值/1.13*1.65%(系数) + // // 大众的保险费=货值*0.0015 + // // FeeType ft=getFeeType("保险费"); + // // Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), + // BillObjectType.ORDER, order.getConsignor(), ft, + // // 1.5/1000, order.getPredictFee(), 1.5*order.getPredictFee()/1000, + // FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); + // FeeType ft=getFeeType("运输费"); + // Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), + // BillObjectType.ORDER, order.getConsignor(), ft, + // 1.65/1.13/100, order.getPredictFee(), + // 1.65*order.getPredictFee()/1.13/100, FeePayReceive.RECEIVE, + // MeasureUnit.TICKET, order.getContractor()); + // fee2.setDescription(order.getPredictFee()+"货值/1.13*1.65%"); + // this.commonDao.store(fee2); + // order.setFreight(order.getPredictFee()); + // this.commonDao.store(order); + // }else{ + // //武汉市内运费=货值 + // // FeeType ft=getFeeType("运输费"); + // // Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), + // BillObjectType.ORDER, order.getConsignor(), ft, + // // 1, order.getPredictFee(), order.getPredictFee(), + // FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); + // // fee2.setDescription(order.getPredictFee()+"货值"); + // // this.commonDao.store(fee2); + // order.setFreight(order.getPredictFee()); + // this.commonDao.store(order); + // } + // } + + } + + public void createDZFee(Date date1, Date date2, double xs) { + List os = this.commonDao + .findByQuery("from Order o where o.consignor.id=3175 " + + "and to_char(o.planFromDate,'yyyy-mm-dd')>='" + + DateUtil.formatDateYMDToStr(date1) + "'" + + "and to_char(o.planFromDate,'yyyy-mm-dd')<='" + + DateUtil.formatDateYMDToStr(date2) + "'" + + " and o.status!='CANCEL'"); + FeeType ft = getFeeType("运输费"); + int i = 0; + for (Order order : os) { + System.out.println(i++ + "====" + new Date()); + if (order.getPredictFee() > 0 && order.getToCityCountiy() != null) { + List fees = this.commonDao + .findByQuery( + "from Fee f where f.billId=:feeId and f.billCode=:billCode and (f.operator='system')", + new String[] { "feeId", "billCode" }, + new Object[] { order.getId(), + order.getRelateBill3() }); for (Fee fee : fees) { - if(!fee.getFeeName().getId().equals(ft.getId())){ + if (!fee.getFeeName().getId().equals(ft.getId())) { this.commonDao.delete(fee); - }else{ - if(fee.getBillFee()!=null){ - throw new BusinessException(order.getRelateBill3()+"费用已对帐,不能取消回单"); + } else { + if (fee.getBillFee() != null) { + throw new BusinessException(order.getRelateBill3() + + "费用已对帐,不能取消回单"); } - if(!order.getToCityCountiy().getName().equals("武汉市")){ + if (!order.getToCityCountiy().getName().equals("武汉市")) { fee.setInvQty(xs); - fee.setQuantity(xs/1.13/100); + fee.setQuantity(xs / 1.13 / 100); fee.setPrice(order.getPredictFee()); - fee.setTotalFee(xs*order.getPredictFee()/1.13/100); - fee.setDescription(order.getPredictFee()+"货值/1.13*"+xs+"%"); + fee.setTotalFee(xs * order.getPredictFee() / 1.13 + / 100); + fee.setDescription(order.getPredictFee() + + "货值/1.13*" + xs + "%"); this.commonDao.store(fee); order.setFreight(order.getPredictFee()); this.commonDao.store(order); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - }else{ - if(fee.getTotalFee()-order.getPredictFee()==0){ + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } else { + if (fee.getTotalFee() - order.getPredictFee() == 0) { continue; } fee.setInvQty(xs); fee.setQuantity(1); fee.setPrice(order.getPredictFee()); fee.setTotalFee(order.getPredictFee()); - fee.setDescription(order.getPredictFee()+"货值"); + fee.setDescription(order.getPredictFee() + "货值"); this.commonDao.store(fee); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } order.setFreight(order.getPredictFee()); this.commonDao.store(order); } } - if(fees.size()<=0){ - if(!order.getToCityCountiy().getName().equals("武汉市")){ - Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, - xs/1.13/100, order.getPredictFee(), xs*order.getPredictFee()/1.13/100, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - fee2.setDescription(order.getPredictFee()+"货值/1.13*"+xs+"%"); + if (fees.size() <= 0) { + if (!order.getToCityCountiy().getName().equals("武汉市")) { + Fee fee2 = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), ft, xs / 1.13 / 100, + order.getPredictFee(), + xs * order.getPredictFee() / 1.13 / 100, + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); + fee2.setDescription(order.getPredictFee() + "货值/1.13*" + + xs + "%"); + this.commonDao.store(fee2); + order.setFreight(order.getPredictFee()); + this.commonDao.store(order); + } else {// 武汉市内运费=货值 + Fee fee2 = this.createFeeInfo(order.getRelateBill3(), + order.getId(), BillObjectType.ORDER, + order.getConsignor(), ft, 1, + order.getPredictFee(), order.getPredictFee(), + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); + fee2.setDescription(order.getPredictFee() + "货值"); this.commonDao.store(fee2); order.setFreight(order.getPredictFee()); this.commonDao.store(order); - }else{//武汉市内运费=货值 - Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, - 1, order.getPredictFee(), order.getPredictFee(), FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - fee2.setDescription(order.getPredictFee()+"货值"); - this.commonDao.store(fee2); - order.setFreight(order.getPredictFee()); - this.commonDao.store(order); } - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - } + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } } } - -// if(order.getPredictFee()>0&&order.getToCityCountiy()!=null){ -// if(!order.getToCityCountiy().getName().equals("武汉市")){ -// Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, -// xs/1.13/100, order.getPredictFee(), xs*order.getPredictFee()/1.13/100, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); -// fee2.setDescription(order.getPredictFee()+"货值/1.13*"+xs+"%"); -// this.commonDao.store(fee2); -// order.setFreight(order.getPredictFee()); -// this.commonDao.store(order); -// }else{//武汉市内运费=货值 -// Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, -// 1, order.getPredictFee(), order.getPredictFee(), FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); -// fee2.setDescription(order.getPredictFee()+"货值"); -// this.commonDao.store(fee2); -// order.setFreight(order.getPredictFee()); -// this.commonDao.store(order); -// } -// } -// feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); -// } + + // if(order.getPredictFee()>0&&order.getToCityCountiy()!=null){ + // if(!order.getToCityCountiy().getName().equals("武汉市")){ + // Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), + // BillObjectType.ORDER, order.getConsignor(), ft, + // xs/1.13/100, order.getPredictFee(), + // xs*order.getPredictFee()/1.13/100, FeePayReceive.RECEIVE, + // MeasureUnit.TICKET, order.getContractor()); + // fee2.setDescription(order.getPredictFee()+"货值/1.13*"+xs+"%"); + // this.commonDao.store(fee2); + // order.setFreight(order.getPredictFee()); + // this.commonDao.store(order); + // }else{//武汉市内运费=货值 + // Fee fee2=this.createFeeInfo(order.getRelateBill3(), order.getId(), + // BillObjectType.ORDER, order.getConsignor(), ft, + // 1, order.getPredictFee(), order.getPredictFee(), + // FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); + // fee2.setDescription(order.getPredictFee()+"货值"); + // this.commonDao.store(fee2); + // order.setFreight(order.getPredictFee()); + // this.commonDao.store(order); + // } + // } + // feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + // Boolean.TRUE); + // } } - - //优衣库 - void createYYKFee(Order order){ - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - double price=0; - double volume=0; - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ + + // 优衣库 + void createYYKFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + double price = 0; + double volume = 0; + String lineName = ""; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + } else { throw new BusinessException("城市信息为空!"); } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - - List Orders = commonDao.findByQuery(" from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", - new String[] { "id","planFromDate"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate())}); - - //门店订单数量 - List mdOrders = commonDao.findByQuery(" from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", - new String[] { "id","planFromDate","toName"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}); - - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - if(order.getToCityCountiy().getName().equals("武汉市")){ - //返货 - //送货费=件数*0.082*单价+提货费 - if(Orders.size()>0){ - for(Order o:Orders){ - price=o.getQuantity()*0.082*cr.getPrice1()+cr.getDeliveryFee(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费", price); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); + Contract con = null; + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + + List Orders = commonDao + .findByQuery( + " from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", + new String[] { "id", "planFromDate" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()) }); + + // 门店订单数量 + List mdOrders = commonDao + .findByQuery( + " from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", + new String[] { "id", "planFromDate", "toName" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }); + + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + if (order.getToCityCountiy().getName().equals("武汉市")) { + // 返货 + // 送货费=件数*0.082*单价+提货费 + if (Orders.size() > 0) { + for (Order o : Orders) { + price = o.getQuantity() * 0.082 * cr.getPrice1() + + cr.getDeliveryFee(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", price); + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); } } - if(mdOrders.size()>0){ - for(Order o:mdOrders){ - price=30/mdOrders.size(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "提货费", price); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); + if (mdOrders.size() > 0) { + for (Order o : mdOrders) { + price = 30 / mdOrders.size(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "提货费", price); + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); } } - - - }else{ - //送货费=单价*体积+送货费 - price=cr.getPrice1()*order.getVolume()+cr.getDeliveryFee(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费", price); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); -// feeManager.createContractFee(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order, cr, price, 1, FeePayReceive.RECEIVE, false, shf); - volume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", - new String[] { "id","planFromDate"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate())}).get(0); - if(volume<=20){ - if(Orders.size()>0){ - for(Order o:Orders){ - double thff=200d/volume*o.getVolume(); + + } else { + // 送货费=单价*体积+送货费 + price = cr.getPrice1() * order.getVolume() + + cr.getDeliveryFee(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", price); + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); + // feeManager.createContractFee(order.getRelateBill3(), + // order.getId(), BillObjectType.ORDER, order, cr, price, 1, + // FeePayReceive.RECEIVE, false, shf); + volume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", + new String[] { "id", "planFromDate" }, + new Object[] { + order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()) }) + .get(0); + if (volume <= 20) { + if (Orders.size() > 0) { + for (Order o : Orders) { + double thff = 200d / volume * o.getVolume(); System.out.println(thff); -// feeManager.createContractFee(o.getRelateBill3(), o.getId(), BillObjectType.ORDER, o, cr, thff, 1, FeePayReceive.RECEIVE, false, thf); - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "提货费", thff); - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); + // feeManager.createContractFee(o.getRelateBill3(), + // o.getId(), BillObjectType.ORDER, o, cr, thff, + // 1, FeePayReceive.RECEIVE, false, thf); + feeManager + .saveInputFee(o.getId(), + BillObjectType.ORDER, null, + "提货费", thff); + feeManager.refreshBillFee(o.getId(), + BillObjectType.ORDER, Boolean.TRUE); } } } } - - }else{ + + } else { throw new BusinessException("合同费率不存在,请维护合同费率!"); } - }else{ + } else { throw new BusinessException("客户合同不存在,请维护客户合同!"); } - + } - - //广汽丰田and广汽本田 - void createFTAndBTFee(Order order){ - Date date=new Date(); - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - double price=0; - double volume=0;//总方数 - String billObject=BillObjectType.ORDER; - volume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id in(5254,5253) and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", - new String[] { "planFromDate"},new Object[] {sdf.format(order.getPlanFromDate())}).get(0); - List Orders = commonDao.findByQuery(" from Order o where o.consignor.id in(5254,5253) and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", - new String[] { "planFromDate"},new Object[] {sdf.format(order.getPlanFromDate())}); - if(Orders.size()>0){ - for(Order o:Orders){ - if(volume<15){ - price=1100/volume*o.getVolume(); - feeManager.saveInputFee(o.getId(), billObject, null, "运输费",price); - feeManager.refreshBillFee(o.getId(), billObject, Boolean.TRUE); - }else{ - price=100*o.getVolume(); - feeManager.saveInputFee(o.getId(), billObject, null, "运输费",price); - feeManager.refreshBillFee(o.getId(), billObject, Boolean.TRUE); + + // 广汽丰田and广汽本田 + void createFTAndBTFee(Order order) { + Date date = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + double price = 0; + double volume = 0;// 总方数 + String billObject = BillObjectType.ORDER; + volume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id in(5254,5253) and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", + new String[] { "planFromDate" }, + new Object[] { sdf.format(order.getPlanFromDate()) }) + .get(0); + List Orders = commonDao + .findByQuery( + " from Order o where o.consignor.id in(5254,5253) and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate ", + new String[] { "planFromDate" }, + new Object[] { sdf.format(order.getPlanFromDate()) }); + if (Orders.size() > 0) { + for (Order o : Orders) { + if (volume < 15) { + price = 1100 / volume * o.getVolume(); + feeManager.saveInputFee(o.getId(), billObject, null, "运输费", + price); + feeManager.refreshBillFee(o.getId(), billObject, + Boolean.TRUE); + } else { + price = 100 * o.getVolume(); + feeManager.saveInputFee(o.getId(), billObject, null, "运输费", + price); + feeManager.refreshBillFee(o.getId(), billObject, + Boolean.TRUE); } } } } - - void createDZYDFee(Order order){ - if(order.getPredictFee()>0){ - //大众韵达的运费=货值*2.4% - FeeType ft=getFeeType("运输费"); - Fee fee=this.createFeeInfo(order.getRelateBill3(), order.getId(), BillObjectType.ORDER, order.getConsignor(), ft, - 2.4/100, order.getPredictFee(), 2.4*order.getPredictFee()/100, FeePayReceive.RECEIVE, MeasureUnit.TICKET, order.getContractor()); - fee.setDescription(order.getPredictFee()+"货值*2.4%"); + + void createDZYDFee(Order order) { + if (order.getPredictFee() > 0) { + // 大众韵达的运费=货值*2.4% + FeeType ft = getFeeType("运输费"); + Fee fee = this.createFeeInfo(order.getRelateBill3(), order.getId(), + BillObjectType.ORDER, order.getConsignor(), ft, 2.4 / 100, + order.getPredictFee(), 2.4 * order.getPredictFee() / 100, + FeePayReceive.RECEIVE, MeasureUnit.TICKET, + order.getContractor()); + fee.setDescription(order.getPredictFee() + "货值*2.4%"); this.commonDao.store(fee); order.setFreight(order.getPredictFee()); this.commonDao.store(order); } - + } - void createZYFee(Order order){ - double qty=order.getVolume(); - String unit= MeasureUnit.VOLUME; - Long fId=null; - Long tId=null; - if(order.getFromCity().getName().equals("武汉市")){ - fId=new Long(1050); - }else{ - fId=order.getFromCity().getZone().getId(); + + void createZYFee(Order order) { + double qty = order.getVolume(); + String unit = MeasureUnit.VOLUME; + Long fId = null; + Long tId = null; + if (order.getFromCity().getName().equals("武汉市")) { + fId = new Long(1050); + } else { + fId = order.getFromCity().getZone().getId(); } - if(order.getToCity()!=null){ - tId=order.getToCity().getId(); - }else{ - tId=order.getToCity().getZone().getId(); + if (order.getToCity() != null) { + tId = order.getToCity().getId(); + } else { + tId = order.getToCity().getZone().getId(); } - createContractFee(order, fId, tId, order.getShipmentMethod(),unit, "3",qty); - + createContractFee(order, fId, tId, order.getShipmentMethod(), unit, + "3", qty); + } - void createJLFee(Order order){ - double qty=order.getVolume(); - String unit= MeasureUnit.VOLUME; - if(order.getUnit()!=null&&order.getUnit().equals(MeasureUnit.WEIGHT)){ - qty=order.getWeight(); - unit= MeasureUnit.WEIGHT; + + void createJLFee(Order order) { + double qty = order.getVolume(); + String unit = MeasureUnit.VOLUME; + if (order.getUnit() != null + && order.getUnit().equals(MeasureUnit.WEIGHT)) { + qty = order.getWeight(); + unit = MeasureUnit.WEIGHT; } - if(qty<=0){ + if (qty <= 0) { return; } - if(qty<1){ - qty=1; + if (qty < 1) { + qty = 1; } - Long fId=null; - Long tId=null; - if(order.getFromCity().getName().equals("武汉市")){ - fId=new Long(1050); - }else{ - fId=order.getFromCity().getZone().getId(); + Long fId = null; + Long tId = null; + if (order.getFromCity().getName().equals("武汉市")) { + fId = new Long(1050); + } else { + fId = order.getFromCity().getZone().getId(); } - if(order.getToCity().getName().equals("武汉市")){ - tId=new Long(1050); - }else{ - tId=order.getToCity().getZone().getId(); + if (order.getToCity().getName().equals("武汉市")) { + tId = new Long(1050); + } else { + tId = order.getToCity().getZone().getId(); } - -// if(order.getFromCity().getId().equals(order.getToCity().getId())){ -// fId=order.getFromCity().getId(); -// tId=order.getToCity().getId(); -// }else{ -// fId=order.getFromCity().getZone().getId(); -// tId=order.getToCity().getZone().getId(); -// } + + // if(order.getFromCity().getId().equals(order.getToCity().getId())){ + // fId=order.getFromCity().getId(); + // tId=order.getToCity().getId(); + // }else{ + // fId=order.getFromCity().getZone().getId(); + // tId=order.getToCity().getZone().getId(); + // } SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd"); - List orderIDs=commonDao.findByQuery(" select id from Order o where o.consignor.code='JL' AND to_char(o.planFromDate,'yyyy-mm-dd')='"+sdf2.format(order.getPlanFromDate())+"' and o.toName='"+order.getToName()+"'"); - List orders=commonDao.findByQuery(" select nvl(sum(o.volume),0) from Order o where o.consignor.code='JL' AND to_char(o.planFromDate,'yyyy-mm-dd')='"+sdf2.format(order.getPlanFromDate())+"' and o.toName='"+order.getToName()+"'"); + List orderIDs = commonDao + .findByQuery(" select id from Order o where o.consignor.code='JL' AND to_char(o.planFromDate,'yyyy-mm-dd')='" + + sdf2.format(order.getPlanFromDate()) + + "' and o.toName='" + order.getToName() + "'"); + List orders = commonDao + .findByQuery(" select nvl(sum(o.volume),0) from Order o where o.consignor.code='JL' AND to_char(o.planFromDate,'yyyy-mm-dd')='" + + sdf2.format(order.getPlanFromDate()) + + "' and o.toName='" + order.getToName() + "'"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < orderIDs.size(); i++) { - if (i == orderIDs.size() - 1) { - sb.append(orderIDs.get(i)); - } else { - sb.append(orderIDs.get(i)); - sb.append(","); - } - } - String hql=" from Fee f where f.account.code='JL' AND f.billId in ("+sb.toString()+") and f.billObject='ORDER' and f.feeName.code='运输费' "; - List fees=commonDao.findByQuery(hql); - - if(fees.size()==0) { - if(orders.get(0)>0) { - qty=orders.get(0); + if (i == orderIDs.size() - 1) { + sb.append(orderIDs.get(i)); + } else { + sb.append(orderIDs.get(i)); + sb.append(","); } - createContractFee(order, fId, tId, order.getShipmentMethod(),unit, "2",qty); + } + String hql = " from Fee f where f.account.code='JL' AND f.billId in (" + + sb.toString() + + ") and f.billObject='ORDER' and f.feeName.code='运输费' "; + List fees = commonDao.findByQuery(hql); + + if (fees.size() == 0) { + if (orders.get(0) > 0) { + qty = orders.get(0); + } + createContractFee(order, fId, tId, order.getShipmentMethod(), unit, + "2", qty); } } - - void createHHFKSLFee(Order order){ - - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); - double price=0; - double zvolume=0;//总体积 - double volume=0;//单票体积 - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ - throw new BusinessException("城市信息为空!"); - } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - //总体积 - zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", - new String[] { "id","planFromDate","toName"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}).get(0); - if(zvolume<30){ - price=cr.getPrice1(); - }else{ - price=cr.getPrice2(); - } - - //最小计费体积: 单票不足0.1方按0.1方计算 - if(zvolume<0.3){ - double ysf=price*0.1; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - }else{ - //运输费=单价*体积 - double ysf=price*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", ysf); - } - }else{ - throw new BusinessException("合同费率不存在,请维护合同费率!"); - } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - - } - - void createhlyftFee(Order order){ - String lineName=""; - if(order.getFromCityCountiy()!=null&&order.getToCityCountiy()!=null){ - lineName=order.getFromCityCountiy().getName()+"-"+order.getToCityCountiy().getName(); - }else{ - throw new BusinessException("城市信息为空!"); - } - Contract con=null; - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - ContractRate cr =null; - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", - new String[] {"id", "name"},new Object[] {con.getId(),lineName}); - if(ContractRates.size()>0){ - cr=ContractRates.get(0); - double price=cr.getPrice1();//零单价 - double ysf=order.getQuantity()*price; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费",ysf); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - }else{ - throw new BusinessException(lineName+"线路合同费率不存在,请维护合同费率!"); - } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - - } - - void createHHBTZCFee(Order order){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - if(order.getExtends1()==null){ - throw new BusinessException(order.getConsignor().getName()+"订单需要选择计费车型!"); + + void createHHFKSLFee(Order order) { + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + double price = 0; + double zvolume = 0;// 总体积 + double volume = 0;// 单票体积 + String lineName = ""; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + } else { + throw new BusinessException("城市信息为空!"); } - - - double zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.extends1.id=:extends1Id ", - new String[] { "id","planFromDate","extends1Id"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getExtends1().getId()}).get(0); - - double price=Double.parseDouble(order.getExtends1().getDescription());//车型价格 - - double ysf=price/zvolume*order.getVolume(); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费",ysf); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); + Contract con = null; + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + // 总体积 + zvolume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", + new String[] { "id", "planFromDate", "toName" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }).get(0); + if (zvolume < 30) { + price = cr.getPrice1(); + } else { + price = cr.getPrice2(); + } + + // 最小计费体积: 单票不足0.1方按0.1方计算 + if (zvolume < 0.3) { + double ysf = price * 0.1; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } else { + // 运输费=单价*体积 + double ysf = price * order.getVolume(); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", ysf); + } + } else { + throw new BusinessException("合同费率不存在,请维护合同费率!"); + } + } else { + throw new BusinessException("客户合同不存在,请维护客户合同!"); + } + } - - void createZYJLFee(Order order){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - String lineName=""; - if(order.getToName()==null){ - return; - } - Contract con=null; + + void createhlyftFee(Order order) { + String lineName = ""; + if (order.getFromCityCountiy() != null + && order.getToCityCountiy() != null) { + lineName = order.getFromCityCountiy().getName() + "-" + + order.getToCityCountiy().getName(); + } else { + throw new BusinessException("城市信息为空!"); + } + Contract con = null; + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + ContractRate cr = null; + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.name=:name ", + new String[] { "id", "name" }, + new Object[] { con.getId(), lineName }); + if (ContractRates.size() > 0) { + cr = ContractRates.get(0); + double price = cr.getPrice1();// 零单价 + double ysf = order.getQuantity() * price; + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, + null, "运输费", ysf); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + } else { + throw new BusinessException(lineName + "线路合同费率不存在,请维护合同费率!"); + } + } else { + throw new BusinessException("客户合同不存在,请维护客户合同!"); + } + + } + + void createHHBTZCFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + if (order.getExtends1() == null) { + throw new BusinessException(order.getConsignor().getName() + + "订单需要选择计费车型!"); + } + + double zvolume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.extends1.id=:extends1Id ", + new String[] { "id", "planFromDate", "extends1Id" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getExtends1().getId() }).get(0); + + double price = Double.parseDouble(order.getExtends1().getDescription());// 车型价格 + + double ysf = price / zvolume * order.getVolume(); + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, + "运输费", ysf); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + } + + void createZYJLFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String lineName = ""; + if (order.getToName() == null) { + return; + } + Contract con = null; System.out.println(order.getRelateBill3()); - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.size()>0){ - con=Contracts.get(0); - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.fromCity.id=:fromCityId and cr.routeFee.toCity.id=:toCityId", - new String[] {"id", "fromCityId","toCityId"},new Object[] {con.getId(),order.getFromCityCountiy().getId(),order.getToCityCountiy().getId()}); - if(ContractRates.size()>0){ - ContractRate cr =ContractRates.get(0); - double price=cr.getVehiclePrice(); - double volume=order.getVolume(); - double zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", - new String[] { "id","planFromDate","toName"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}).get(0); - double totalFee=DoubleUtils.format3Fraction(price*volume); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费",totalFee); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - if(zvolume<1){ - //当日单门店合计方数不足1个方+50元送货费(长沙、南昌除外) - if(order.getToCityCountiy().getName().equals("长沙市") || order.getToCityCountiy().getName().equals("南昌市")){ + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.size() > 0) { + con = Contracts.get(0); + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.fromCity.id=:fromCityId and cr.routeFee.toCity.id=:toCityId", + new String[] { "id", "fromCityId", "toCityId" }, + new Object[] { con.getId(), + order.getFromCityCountiy().getId(), + order.getToCityCountiy().getId() }); + if (ContractRates.size() > 0) { + ContractRate cr = ContractRates.get(0); + double price = cr.getVehiclePrice(); + double volume = order.getVolume(); + double zvolume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", + new String[] { "id", "planFromDate", "toName" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }).get(0); + double totalFee = DoubleUtils.format3Fraction(price * volume); + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, + null, "运输费", totalFee); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + if (zvolume < 1) { + // 当日单门店合计方数不足1个方+50元送货费(长沙、南昌除外) + if (order.getToCityCountiy().getName().equals("长沙市") + || order.getToCityCountiy().getName().equals("南昌市")) { System.out.println("长沙、南昌 不收送货费!"); - double shf=0; - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费",shf); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - }else{ - double shf=DoubleUtils.format3Fraction(50/zvolume*volume); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费",shf); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); + double shf = 0; + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", shf); + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } else { + double shf = DoubleUtils.format3Fraction(50 / zvolume + * volume); + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", shf); + feeManager.refreshBillFee(order.getId(), + BillObjectType.ORDER, Boolean.TRUE); } - + } - - - /*List fs1=this.commonDao.findByQuery("from Fee f where f.billId="+order.getId()+" and f.billObject='ORDER' and f.feeName.name='运输费' and f.operator='system'"); - if(fs1.size()>0){ - for(Fee f:fs1){ - if(f.getTotalFee()-totalFee!=0){ - f.setTotalFee(totalFee); - f.setDescription(des); - f.setBeShare(Boolean.FALSE); - this.commonDao.store(f); - System.out.println(order.getRelateBill3()+"=update=="+f.getId()+"==1="+f.getTotalFee()); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - } - }else{ - Fee f=this.createContractFee(order, cr, price, volume, totalFee, null); - f.setDescription(des); - f.setBeShare(Boolean.TRUE); - this.commonDao.store(f); - System.out.println(order.getRelateBill3()+"=new=="+f.getId()+"==2="+f.getTotalFee()); - } - //查找是否存在分摊费用 - List orders=commonDao.findByQuery("from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.volume<2 and o.id!=:dqId", - new String[] { "id","planFromDate","toName","dqId"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName(),order.getId()}); - if(zvolume>=2){ - for(Order o:orders){//重新计算费用 - double volume2=o.getVolume(); - double totalFee2=price*volume2; - des="订单体积"+volume+"门店当日总体积"+zvolume+";"+price+"*"+volume2+"="+totalFee2; - List fs2=this.commonDao.findByQuery("from Fee f where f.billId="+o.getId()+" and f.billObject='ORDER' and f.feeName.name='运输费' and f.operator='system'"); - if(fs2.size()>0){ - for(Fee f:fs2){ - if(f.getTotalFee()-totalFee2!=0){ - f.setTotalFee(totalFee2); - f.setDescription(des); - f.setBeShare(Boolean.FALSE); - this.commonDao.store(f); - System.out.println(o.getRelateBill3()+"=update=="+f.getId()+"==3="+f.getTotalFee()); - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - } - }else{ - Fee f=this.createContractFee(o, cr, price, volume, totalFee, null); - f.setDescription(des); - f.setBeShare(Boolean.TRUE); - this.commonDao.store(f); - System.out.println(o.getRelateBill3()+"==new="+f.getId()+"==4="+f.getTotalFee()); - } - } - }else{ - //总体积是否发生变化导致需要重新计算 - for(Order o:orders){//重新计算费用 - volume=o.getVolume(); - double ytotalFee=price*2;//门店当天总体积不足2按照2算并分摊 - //分摊出来 - totalFee= DoubleUtils.format4Fraction(ytotalFee*volume/zvolume); - des="订单体积"+volume+"门店当日总体积"+zvolume+"不足2,按照2算"+price+"*2"+"="+ytotalFee+"分摊:"+ytotalFee+"*"+volume+"/"+zvolume+"="+totalFee; - List fs=this.commonDao.findByQuery("from Fee f where f.billId="+o.getId()+" and f.billObject='ORDER' and f.feeName.name='运输费' and f.operator='system'"); - if(fs.size()>0){ - for(Fee f:fs){ - if(f.getTotalFee()-ytotalFee!=0){ - f.setTotalFee(totalFee); - f.setDescription(des); - this.commonDao.store(f); - System.out.println(o.getId()+"==update="+f.getId()+"==5="+f.getTotalFee()); - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - } - }else{ - Fee f=this.createContractFee(o, cr, price, volume, totalFee, null); - f.setDescription(des); - f.setBeShare(Boolean.TRUE); - this.commonDao.store(f); - System.out.println(o.getRelateBill3()+"=new=="+f.getId()+"==6="+f.getTotalFee()); - } - } - }*/ - - - }else{ + + /* + * List + * fs1=this.commonDao.findByQuery("from Fee f where f.billId=" + * +order.getId()+ + * " and f.billObject='ORDER' and f.feeName.name='运输费' and f.operator='system'" + * ); if(fs1.size()>0){ for(Fee f:fs1){ + * if(f.getTotalFee()-totalFee!=0){ f.setTotalFee(totalFee); + * f.setDescription(des); f.setBeShare(Boolean.FALSE); + * this.commonDao.store(f); + * System.out.println(order.getRelateBill3 + * ()+"=update=="+f.getId()+"==1="+f.getTotalFee()); + * feeManager.refreshBillFee(order.getId(), + * BillObjectType.ORDER, Boolean.TRUE); } } }else{ Fee + * f=this.createContractFee(order, cr, price, volume, totalFee, + * null); f.setDescription(des); f.setBeShare(Boolean.TRUE); + * this.commonDao.store(f); + * System.out.println(order.getRelateBill3 + * ()+"=new=="+f.getId()+"==2="+f.getTotalFee()); } //查找是否存在分摊费用 + * List orders=commonDao.findByQuery( + * "from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName and o.volume<2 and o.id!=:dqId" + * , new String[] { "id","planFromDate","toName","dqId"},new + * Object[] + * {order.getConsignor().getId(),sdf.format(order.getPlanFromDate + * ()),order.getToName(),order.getId()}); if(zvolume>=2){ + * for(Order o:orders){//重新计算费用 double volume2=o.getVolume(); + * double totalFee2=price*volume2; + * des="订单体积"+volume+"门店当日总体积"+zvolume + * +";"+price+"*"+volume2+"="+totalFee2; List + * fs2=this.commonDao + * .findByQuery("from Fee f where f.billId="+o.getId()+ + * " and f.billObject='ORDER' and f.feeName.name='运输费' and f.operator='system'" + * ); if(fs2.size()>0){ for(Fee f:fs2){ + * if(f.getTotalFee()-totalFee2!=0){ f.setTotalFee(totalFee2); + * f.setDescription(des); f.setBeShare(Boolean.FALSE); + * this.commonDao.store(f); + * System.out.println(o.getRelateBill3() + * +"=update=="+f.getId()+"==3="+f.getTotalFee()); + * feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, + * Boolean.TRUE); } } }else{ Fee f=this.createContractFee(o, cr, + * price, volume, totalFee, null); f.setDescription(des); + * f.setBeShare(Boolean.TRUE); this.commonDao.store(f); + * System.out + * .println(o.getRelateBill3()+"==new="+f.getId()+"==4=" + * +f.getTotalFee()); } } }else{ //总体积是否发生变化导致需要重新计算 for(Order + * o:orders){//重新计算费用 volume=o.getVolume(); double + * ytotalFee=price*2;//门店当天总体积不足2按照2算并分摊 //分摊出来 totalFee= + * DoubleUtils.format4Fraction(ytotalFee*volume/zvolume); + * des="订单体积" + * +volume+"门店当日总体积"+zvolume+"不足2,按照2算"+price+"*2"+"="+ + * ytotalFee+ + * "分摊:"+ytotalFee+"*"+volume+"/"+zvolume+"="+totalFee; + * List + * fs=this.commonDao.findByQuery("from Fee f where f.billId=" + * +o.getId()+ + * " and f.billObject='ORDER' and f.feeName.name='运输费' and f.operator='system'" + * ); if(fs.size()>0){ for(Fee f:fs){ + * if(f.getTotalFee()-ytotalFee!=0){ f.setTotalFee(totalFee); + * f.setDescription(des); this.commonDao.store(f); + * System.out.println + * (o.getId()+"==update="+f.getId()+"==5="+f.getTotalFee()); + * feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, + * Boolean.TRUE); } } }else{ Fee f=this.createContractFee(o, cr, + * price, volume, totalFee, null); f.setDescription(des); + * f.setBeShare(Boolean.TRUE); this.commonDao.store(f); + * System.out + * .println(o.getRelateBill3()+"=new=="+f.getId()+"==6=" + * +f.getTotalFee()); } } } + */ + + } else { return; } - }else{ - throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - } - - void createWHSLFee(Order order){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - if(StringUtils.isEmpty(order.getToName())){ - return; - } - - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.isEmpty()){ + } else { throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - Contract con=Contracts.get(0); - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.fromCity.id=:fromCityId and cr.routeFee.toCity.id=:toCityId", - new String[] {"id", "fromCityId","toCityId"},new Object[] {con.getId(),order.getFromCityCountiy().getId(),order.getToCityCountiy().getId()}); - if(ContractRates.isEmpty()){ - return; - } - - ContractRate cr =ContractRates.get(0); - double price=cr.getVehiclePrice();//价格 - double volume=order.getVolume();//单票体积 - double shfPrice=cr.getDeliveryFee();//总送货费 - - //总体积 - double zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", - new String[] { "id","planFromDate","toName"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),order.getToName()}).get(0); - - double zysf=price*zvolume; - //运输费分摊到每票;送货费分摊到每票 - double ysf=DoubleUtils.format2Fraction(zysf/zvolume*volume); - double shf=DoubleUtils.format2Fraction(shfPrice/zvolume*volume); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费",ysf); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费",shf); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - + } } - - void createWLFee(Order order){//五菱费用 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - if(StringUtils.isEmpty(order.getToName())){ + + void createWHSLFee(Order order) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + if (StringUtils.isEmpty(order.getToName())) { return; - } - String to_address=""; - if(order.getToContact()!=null){ - to_address=order.getToContact().getAddress(); - } - - List Contracts = commonDao.findByQuery(" from Contract co where co.balance.id=:id ", - new String[] { "id"},new Object[] {order.getConsignor().getId()}); - if(Contracts.isEmpty()){ + } + + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.isEmpty()) { throw new BusinessException("客户合同不存在,请维护客户合同!"); - } - - Contract con=Contracts.get(0); - List ContractRates = commonDao.findByQuery(" from ContractRate cr where cr.contract.id=:id and cr.routeFee.fromCity.id=:fromCityId and cr.routeFee.toCity.id=:toCityId", - new String[] {"id", "fromCityId","toCityId"},new Object[] {con.getId(),order.getFromCityCountiy().getId(),order.getToCityCountiy().getId()}); - if(ContractRates.isEmpty()){ - return; - } - - ContractRate cr =ContractRates.get(0); - double price=cr.getVehiclePrice();//价格 - double volume=order.getVolume();//单票体积 - - //总体积 - double zvolume= (Double) commonDao.findByQuery("select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toContact.address=:address ", - new String[] { "id","planFromDate","address"},new Object[] {order.getConsignor().getId(),sdf.format(order.getPlanFromDate()),to_address}).get(0); - if(zvolume>=0.5){//最小计费体积:最小计费体积0.5m³,不足0.5m³按0.5m³算 - double ysf=price*volume; - Fee f=this.createContractFee(order, cr, price, volume, ysf, null); - f.setDescription(price+"*"+volume); - this.commonDao.store(f); - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费",ysf); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - }else{ - double zysf=price*0.5*volume/zvolume; - //运输费分摊到每票;送货费分摊到每票 - double ysf=DoubleUtils.format2Fraction(price*0.5*volume/zvolume); - Fee f=this.createContractFee(order, cr, price, volume, ysf, null); - f.setDescription("不足0.5立方"+price+"*0.5*"+volume+"/"+zvolume); - f.setBeShare(Boolean.TRUE); - this.commonDao.store(f); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - - + } + + Contract con = Contracts.get(0); + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.fromCity.id=:fromCityId and cr.routeFee.toCity.id=:toCityId", + new String[] { "id", "fromCityId", "toCityId" }, + new Object[] { con.getId(), + order.getFromCityCountiy().getId(), + order.getToCityCountiy().getId() }); + if (ContractRates.isEmpty()) { + return; + } + + ContractRate cr = ContractRates.get(0); + double price = cr.getVehiclePrice();// 价格 + double volume = order.getVolume();// 单票体积 + double shfPrice = cr.getDeliveryFee();// 总送货费 + + // 总体积 + double zvolume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toName=:toName ", + new String[] { "id", "planFromDate", "toName" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), + order.getToName() }).get(0); + + double zysf = price * zvolume; + // 运输费分摊到每票;送货费分摊到每票 + double ysf = DoubleUtils.format2Fraction(zysf / zvolume * volume); + double shf = DoubleUtils.format2Fraction(shfPrice / zvolume * volume); + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, + "运输费", ysf); + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, + "送货费", shf); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + } - public void detailArriveConfirm(List legsIds, Date arriveTime,Long platFormId){ + + void createWLFee(Order order) {// 五菱费用 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + if (StringUtils.isEmpty(order.getToName())) { + return; + } + String to_address = ""; + if (order.getToContact() != null) { + to_address = order.getToContact().getAddress(); + } + + List Contracts = commonDao.findByQuery( + " from Contract co where co.balance.id=:id ", + new String[] { "id" }, new Object[] { order.getConsignor() + .getId() }); + if (Contracts.isEmpty()) { + throw new BusinessException("客户合同不存在,请维护客户合同!"); + } + + Contract con = Contracts.get(0); + List ContractRates = commonDao + .findByQuery( + " from ContractRate cr where cr.contract.id=:id and cr.routeFee.fromCity.id=:fromCityId and cr.routeFee.toCity.id=:toCityId", + new String[] { "id", "fromCityId", "toCityId" }, + new Object[] { con.getId(), + order.getFromCityCountiy().getId(), + order.getToCityCountiy().getId() }); + if (ContractRates.isEmpty()) { + return; + } + + ContractRate cr = ContractRates.get(0); + double price = cr.getVehiclePrice();// 价格 + double volume = order.getVolume();// 单票体积 + + // 总体积 + double zvolume = (Double) commonDao + .findByQuery( + "select nvl(sum(o.volume),0) from Order o where o.consignor.id=:id and to_char(o.planFromDate,'yyyy-MM-dd')=:planFromDate and o.toContact.address=:address ", + new String[] { "id", "planFromDate", "address" }, + new Object[] { order.getConsignor().getId(), + sdf.format(order.getPlanFromDate()), to_address }) + .get(0); + if (zvolume >= 0.5) {// 最小计费体积:最小计费体积0.5m³,不足0.5m³按0.5m³算 + double ysf = price * volume; + Fee f = this.createContractFee(order, cr, price, volume, ysf, null); + f.setDescription(price + "*" + volume); + this.commonDao.store(f); + feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, + "运输费", ysf); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + } else { + double zysf = price * 0.5 * volume / zvolume; + // 运输费分摊到每票;送货费分摊到每票 + double ysf = DoubleUtils.format2Fraction(price * 0.5 * volume + / zvolume); + Fee f = this.createContractFee(order, cr, price, volume, ysf, null); + f.setDescription("不足0.5立方" + price + "*0.5*" + volume + "/" + + zvolume); + f.setBeShare(Boolean.TRUE); + this.commonDao.store(f); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + } + + } + + public void detailArriveConfirm(List legsIds, Date arriveTime, + Long platFormId) { shipmentManager.detailArriveConfirm(legsIds, arriveTime, platFormId); - List list=new ArrayList(); - for(Long id:legsIds){ - Legs l=commonDao.load(Legs.class, id); - Shipment s=commonDao.load(Shipment.class, l.getShipment().getId()); - if(s.getStatus().equals("ARRIVE")){ + List list = new ArrayList(); + for (Long id : legsIds) { + Legs l = commonDao.load(Legs.class, id); + Shipment s = commonDao + .load(Shipment.class, l.getShipment().getId()); + if (s.getStatus().equals("ARRIVE")) { list.add(l.getShipment().getId()); } } - if(list.size()>0){ + if (list.size() > 0) { refreshShipmentFee(list); } } - + @Transactional - public void wholeArriveComfirm(Long shipmentId, Date arriveTime){ - shipmentManager.wholeArriveComfirm(shipmentId, arriveTime,Boolean.FALSE); - List list=new ArrayList(); - if(shipmentId>0){ + public void wholeArriveComfirm(Long shipmentId, Date arriveTime) { + shipmentManager.wholeArriveComfirm(shipmentId, arriveTime, + Boolean.FALSE); + List list = new ArrayList(); + if (shipmentId > 0) { list.add(shipmentId); refreshShipmentFee(list); } } - //订单运抵加费用计算 - public void detailSignImage(List legsIds, Date arriveTime,String imageType,String objectType,File signImage,String signBy,String description,String sjStar,String ddStar,String carryMode,Long unloadLocationId,String unloadAddress,Long unOrgId){ - shipmentManager.detailSignImage(legsIds, arriveTime, imageType, objectType, signImage, signBy, description, sjStar, ddStar, carryMode, unloadLocationId, unloadAddress, unOrgId); - List list=new ArrayList(); - for(Long id:legsIds){ - Legs l=commonDao.load(Legs.class, id); - Shipment s=commonDao.load(Shipment.class, l.getShipment().getId()); - if(s.getStatus().equals("ARRIVE")){ + + // 订单运抵加费用计算 + public void detailSignImage(List legsIds, Date arriveTime, + String imageType, String objectType, File signImage, String signBy, + String description, String sjStar, String ddStar, String carryMode, + Long unloadLocationId, String unloadAddress, Long unOrgId) { + shipmentManager.detailSignImage(legsIds, arriveTime, imageType, + objectType, signImage, signBy, description, sjStar, ddStar, + carryMode, unloadLocationId, unloadAddress, unOrgId); + List list = new ArrayList(); + for (Long id : legsIds) { + Legs l = commonDao.load(Legs.class, id); + Shipment s = commonDao + .load(Shipment.class, l.getShipment().getId()); + if (s.getStatus().equals("ARRIVE")) { list.add(l.getShipment().getId()); } } - if(list.size()>0){ + if (list.size() > 0) { refreshShipmentFee(list); } - + } - - public Fee createFeeInfo(String billCode,Long billId,String billObject,Organization account, - FeeType ft,double qty,double price,double totalFee,String payOrReceive,String unit,Organization pt){ - Fee fee=(Fee) EntityFactory.getEntity(Fee.class); + + public Fee createFeeInfo(String billCode, Long billId, String billObject, + Organization account, FeeType ft, double qty, double price, + double totalFee, String payOrReceive, String unit, Organization pt) { + Fee fee = (Fee) EntityFactory.getEntity(Fee.class); fee.setBillCode(billCode); fee.setBillId(billId); fee.setBillObject(billObject); @@ -8511,8 +9944,10 @@ void createQKCusFee(Order order){ fee.setPrice(DoubleUtils.format3Fraction(price)); fee.setTotalFee(DoubleUtils.format2Fraction(totalFee)); fee.setStatus(FeeStatus.CHECK); - fee.setNoTaxFee(DoubleUtils.format2Fraction(fee.getTotalFee()/(1+fee.getTax()/100))); - fee.setTaxFee(DoubleUtils.format2Fraction(fee.getNoTaxFee()*fee.getTax()/100)); + fee.setNoTaxFee(DoubleUtils.format2Fraction(fee.getTotalFee() + / (1 + fee.getTax() / 100))); + fee.setTaxFee(DoubleUtils.format2Fraction(fee.getNoTaxFee() + * fee.getTax() / 100)); fee.setFeeDate(new Date()); fee.setOperator("system"); fee.setOperatorDate(new Date()); @@ -8524,38 +9959,43 @@ void createQKCusFee(Order order){ this.commonDao.store(fee); return fee; } - public void importPlanOrderTime(File file){ + + public void importPlanOrderTime(File file) { try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); - //订单号 - for (int i = 1; i Orders= this.commonDao.findByQuery("from Order o where o.relateBill3='"+kh+"'"); - if(Orders.size()>0){ - order=Orders.get(0); - order.setPlanFromDate(thrq); - this.commonDao.store(order); - // throw new BusinessException("第"+(i+1)+"行,订单编号已重复,请重新导入!"); - } - System.out.println(i); - } + Sheet sheet = workbook.getSheet(0);// 得到excel第一页的内容 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); + // 订单号 + for (int i = 1; i < sheet.getRows(); i++) { + Date thrq = null; + String kh = sheet.getCell(0, i).getContents();// 订单号 + String thDate = sheet.getCell(1, i).getContents();// 计划提货时间 + thrq = DateUtil.getDateFormat2(thDate); + if (thrq != null) { + Calendar curr = Calendar.getInstance(); + curr.setTime(thrq); + int y = curr.get(Calendar.YEAR); + if (y < 1000) { + curr.set(Calendar.YEAR, curr.get(Calendar.YEAR) + 2000); + thrq = curr.getTime(); + } + } + Order order = new Order(); + // 判断订单编号是否重复 + // String + // ddbh=codeManager.generateLegsCode(PlatFormHolder.getPlatForm().getCode()); + List Orders = this.commonDao + .findByQuery("from Order o where o.relateBill3='" + + kh + "'"); + if (Orders.size() > 0) { + order = Orders.get(0); + order.setPlanFromDate(thrq); + this.commonDao.store(order); + // throw new + // BusinessException("第"+(i+1)+"行,订单编号已重复,请重新导入!"); + } + System.out.println(i); + } } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -8563,183 +10003,216 @@ void createQKCusFee(Order order){ // TODO Auto-generated catch block e.printStackTrace(); } - + } - public void importLegsFee(File file){ - String meg=""; + + public void importLegsFee(File file) { + String meg = ""; try { - Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); - //订单号 - for (int i = 1; i ts=this.commonDao.findByQuery("from Shipment s where s.code='"+dh+"'"); - for(Shipment s:ts){ - Long s_id=s.getId(); - int j=3; - String feeName1=sheet.getCell(j++,i).getContents(); - if(feeName1!=null&&!feeName1.equals("")){ - String fee1=sheet.getCell(j++,i).getContents(); - try { - feeManager.saveInputFee(s_id, BillObjectType.SHIPMENT, null, feeName1, Double.parseDouble(fee1)); - } catch (Exception e) { - throw new BusinessException("第"+(i+1)+"行数据有误"); + Workbook workbook = Workbook.getWorkbook(file); + Sheet sheet = workbook.getSheet(0);// 得到excel第一页的内容 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); + // 订单号 + for (int i = 1; i < sheet.getRows(); i++) { + String dh = sheet.getCell(0, i).getContents(); + if (dh == null || dh.equals("")) { + return; + } + List ts = this.commonDao + .findByQuery("from Shipment s where s.code='" + dh + + "'"); + for (Shipment s : ts) { + Long s_id = s.getId(); + int j = 3; + String feeName1 = sheet.getCell(j++, i).getContents(); + if (feeName1 != null && !feeName1.equals("")) { + String fee1 = sheet.getCell(j++, i).getContents(); + try { + feeManager.saveInputFee(s_id, + BillObjectType.SHIPMENT, null, feeName1, + Double.parseDouble(fee1)); + } catch (Exception e) { + throw new BusinessException("第" + (i + 1) + "行数据有误"); + } + } - - } - String feeName2=sheet.getCell(j++,i).getContents(); - if(feeName2!=null&&!feeName2.equals("")){ - String fee2=sheet.getCell(j++,i).getContents(); - try { - feeManager.saveInputFee(s_id, BillObjectType.SHIPMENT, null, feeName2, Double.parseDouble(fee2)); - } catch (Exception e) { - throw new BusinessException("第"+(i+1)+"行数据有误"); + String feeName2 = sheet.getCell(j++, i).getContents(); + if (feeName2 != null && !feeName2.equals("")) { + String fee2 = sheet.getCell(j++, i).getContents(); + try { + feeManager.saveInputFee(s_id, + BillObjectType.SHIPMENT, null, feeName2, + Double.parseDouble(fee2)); + } catch (Exception e) { + throw new BusinessException("第" + (i + 1) + "行数据有误"); + } } - } - String feeName3=sheet.getCell(j++,i).getContents(); - if(feeName3!=null&&!feeName3.equals("")){ - String fee3=sheet.getCell(j++,i).getContents(); - try { - feeManager.saveInputFee(s_id, BillObjectType.SHIPMENT, null, feeName3, Double.parseDouble(fee3)); - } catch (Exception e) { - throw new BusinessException("第"+(i+1)+"行数据有误"); + String feeName3 = sheet.getCell(j++, i).getContents(); + if (feeName3 != null && !feeName3.equals("")) { + String fee3 = sheet.getCell(j++, i).getContents(); + try { + feeManager.saveInputFee(s_id, + BillObjectType.SHIPMENT, null, feeName3, + Double.parseDouble(fee3)); + } catch (Exception e) { + throw new BusinessException("第" + (i + 1) + "行数据有误"); + } + } - - } - String feeName4=sheet.getCell(j++,i).getContents(); - if(feeName4!=null&&!feeName4.equals("")){ - String fee4=sheet.getCell(j++,i).getContents(); - try { - feeManager.saveInputFee(s_id, BillObjectType.SHIPMENT, null, feeName4, Double.parseDouble(fee4)); - } catch (Exception e) { - throw new BusinessException("第"+(i+1)+"行数据有误"); + String feeName4 = sheet.getCell(j++, i).getContents(); + if (feeName4 != null && !feeName4.equals("")) { + String fee4 = sheet.getCell(j++, i).getContents(); + try { + feeManager.saveInputFee(s_id, + BillObjectType.SHIPMENT, null, feeName4, + Double.parseDouble(fee4)); + } catch (Exception e) { + throw new BusinessException("第" + (i + 1) + "行数据有误"); + } } - } - feeManager.refreshBillFee(s.getId(), BillObjectType.SHIPMENT, Boolean.TRUE); - } - } - } catch (BiffException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - }finally{ - meg+="导入失败"; - System.out.println(meg); - } - - - } - public Legs getLegs(String kh,String cys){ - List ls= this.commonDao.findByQuery("from Legs o where o.order.customerOrderNO='"+kh+"' and o.shipment.carrier.name like '%"+cys+"%'"); - if(ls.size()>0){ - return ls.get(0); - }else{ - throw new BusinessException("当前区域未维护"+kh+"的承运商:"+cys+"无找到"); + feeManager.refreshBillFee(s.getId(), + BillObjectType.SHIPMENT, Boolean.TRUE); + } + } + } catch (BiffException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + meg += "导入失败"; + System.out.println(meg); } - + } - public Shipment getShipment(String kh,String cys){ - List ls= this.commonDao.findByQuery("from Shipment s where s.code='"+kh+"' and s.carrier.name like '%"+cys+"%'"); - if(ls.size()>0){ + + public Legs getLegs(String kh, String cys) { + List ls = this.commonDao + .findByQuery("from Legs o where o.order.customerOrderNO='" + + kh + "' and o.shipment.carrier.name like '%" + cys + + "%'"); + if (ls.size() > 0) { return ls.get(0); - }else{ - throw new BusinessException("这个调度单号"+kh+",承运商为:"+cys+"无找到"); + } else { + throw new BusinessException("当前区域未维护" + kh + "的承运商:" + cys + "无找到"); } - + } - public Fee getShipmentFee(Long kh,Long feeName){ - List ls= this.commonDao.findByQuery("from Fee o where o.billId="+kh+" and o.billObject ='SHIPMENT' AND o.feeName.id="+feeName); - if(ls.size()>0){ + + public Shipment getShipment(String kh, String cys) { + List ls = this.commonDao + .findByQuery("from Shipment s where s.code='" + kh + + "' and s.carrier.name like '%" + cys + "%'"); + if (ls.size() > 0) { return ls.get(0); - }else{ + } else { + throw new BusinessException("这个调度单号" + kh + ",承运商为:" + cys + "无找到"); + } + + } + + public Fee getShipmentFee(Long kh, Long feeName) { + List ls = this.commonDao + .findByQuery("from Fee o where o.billId=" + kh + + " and o.billObject ='SHIPMENT' AND o.feeName.id=" + + feeName); + if (ls.size() > 0) { + return ls.get(0); + } else { return null; } - + } - public Fee getLegsFee(Long kh,Long feeName){ - List ls= this.commonDao.findByQuery("from Fee o where o.billId="+kh+" and o.billObject ='LEGS' AND o.feeName.id="+feeName); - if(ls.size()>0){ + + public Fee getLegsFee(Long kh, Long feeName) { + List ls = this.commonDao + .findByQuery("from Fee o where o.billId=" + kh + + " and o.billObject ='LEGS' AND o.feeName.id=" + + feeName); + if (ls.size() > 0) { return ls.get(0); - }else{ + } else { return null; } - + } - public Fee saveLegsFee(Long l ,String feeName,double je,String type,Organization o){ - Fee fee=null; - FeeType ft=getFeeType(feeName); - fee=getShipmentFee(l,ft.getId()); - if(fee==null){ - fee=(Fee) EntityFactory.getEntity(Fee.class); - fee.setAccount(o); - fee.setFeeName(ft); - fee.setQuantity(1); - fee.setPrice(je); - fee.setUnit("TICKET"); - fee.setFeeDate(new Date()); - fee.setOperator(UserHolder.getUser().getName()); - fee.setOperatorDate(new Date()); - fee.setPayOrReceive("PAY"); - fee.setRemark("DR"); - feeManager.saveFee(fee, l, type); + + public Fee saveLegsFee(Long l, String feeName, double je, String type, + Organization o) { + Fee fee = null; + FeeType ft = getFeeType(feeName); + fee = getShipmentFee(l, ft.getId()); + if (fee == null) { + fee = (Fee) EntityFactory.getEntity(Fee.class); + fee.setAccount(o); + fee.setFeeName(ft); + fee.setQuantity(1); + fee.setPrice(je); + fee.setUnit("TICKET"); + fee.setFeeDate(new Date()); + fee.setOperator(UserHolder.getUser().getName()); + fee.setOperatorDate(new Date()); + fee.setPayOrReceive("PAY"); + fee.setRemark("DR"); + feeManager.saveFee(fee, l, type); } return fee; } + @Override - public void batchArrive(List shipemntId,Date arriveTime) { - for(Long id:shipemntId){ - wholeArriveComfirm(id,arriveTime); + public void batchArrive(List shipemntId, Date arriveTime) { + for (Long id : shipemntId) { + wholeArriveComfirm(id, arriveTime); } - } - - + } + @Override public void importBatchArrive(File file) { try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - for (int i = 1; i ss=this.commonDao.findByQuery("from Shipment s where s.code='"+code+"' "); - if(ss.size()<=0){ - throw new BusinessException("第"+(i+1)+"行,调度单号"+code+"有误!"); + List ss = this.commonDao + .findByQuery("from Shipment s where s.code='" + code + + "' "); + if (ss.size() <= 0) { + throw new BusinessException("第" + (i + 1) + "行,调度单号" + code + + "有误!"); } -// String date=sheet.getCell(1,i).getContents(); - if (sheet.getCell(1,i).getType() == CellType.DATE) { - DateCell dc = (DateCell)sheet.getCell(1,i); - Date date = dc.getDate(); -// long time = (orderDate.getTime() / 1000) - 60 * 60 * 8;//格林乔治 东八区 -// orderDate.setTime(time * 1000); - TimeZone zone = TimeZone.getTimeZone("GMT"); - sdf1.setTimeZone(zone); - try { - Shipment s=ss.get(0); - date=sdf2.parse(sdf1.format(date)); - s.setSecondDriverPhone("Excel导入运抵"); - System.out.println(date+"=="+code+"===="); - this.commonDao.store(s); - } catch (ParseException e1) { - throw new BusinessException("第"+(i+1)+"行,日期格式错误!"); - } - shipmentManager.wholeArriveComfirm(ss.get(0).getId(), date, Boolean.FALSE); - } else{ - throw new BusinessException("第"+(i+1)+"行,日期格式错误!"); - } - - } - + // String date=sheet.getCell(1,i).getContents(); + if (sheet.getCell(1, i).getType() == CellType.DATE) { + DateCell dc = (DateCell) sheet.getCell(1, i); + Date date = dc.getDate(); + // long time = (orderDate.getTime() / 1000) - 60 * 60 * + // 8;//格林乔治 东八区 + // orderDate.setTime(time * 1000); + TimeZone zone = TimeZone.getTimeZone("GMT"); + sdf1.setTimeZone(zone); + try { + Shipment s = ss.get(0); + date = sdf2.parse(sdf1.format(date)); + s.setSecondDriverPhone("Excel导入运抵"); + System.out.println(date + "==" + code + "===="); + this.commonDao.store(s); + } catch (ParseException e1) { + throw new BusinessException("第" + (i + 1) + "行,日期格式错误!"); + } + shipmentManager.wholeArriveComfirm(ss.get(0).getId(), date, + Boolean.FALSE); + } else { + throw new BusinessException("第" + (i + 1) + "行,日期格式错误!"); + } + + } + } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -8747,26 +10220,29 @@ void createQKCusFee(Order order){ // TODO Auto-generated catch block e.printStackTrace(); } -// for(Long id:shipemntId){ -// wholeArriveComfirm(id,arriveTime); -// } - } - - public void check_order(Order order,Long platFormId,Long userId,String userName,Long license_id) { + // for(Long id:shipemntId){ + // wholeArriveComfirm(id,arriveTime); + // } + } + + public void check_order(Order order, Long platFormId, Long userId, + String userName, Long license_id) { order.setStatus(OrderStatus.TRANS_AVAILABLE); - if(order.getFromCityCountiy()==null){ - if(order.getFromLocation()!=null){ - TransLocation fromL=this.commonDao.get(TransLocation.class, order.getFromLocation().getId()); + if (order.getFromCityCountiy() == null) { + if (order.getFromLocation() != null) { + TransLocation fromL = this.commonDao.get(TransLocation.class, + order.getFromLocation().getId()); order.setFromCityCountiy(fromL.getCity()); } } - if(order.getToCityCountiy()==null){ - if(order.getToLocation()!=null){ - TransLocation toL=this.commonDao.get(TransLocation.class, order.getToLocation().getId()); + if (order.getToCityCountiy() == null) { + if (order.getToLocation() != null) { + TransLocation toL = this.commonDao.get(TransLocation.class, + order.getToLocation().getId()); order.setToCityCountiy(toL.getCity()); - if(toL.getName()==null){ + if (toL.getName() == null) { order.setToName("收货"); - }else{ + } else { order.setToName(toL.getName()); } } @@ -8775,334 +10251,391 @@ void createQKCusFee(Order order){ order.setToCity(order.getToCityCountiy()); this.commonDao.store(order); this.orderPrescription(order); - order.setFeeTime(new Date());//计费时间 - order.setActiveTime(new Date());//生效时间 + order.setFeeTime(new Date());// 计费时间 + order.setActiveTime(new Date());// 生效时间 order.setQuantityTwo(order.getQuantity()); order.setWeightTwo(order.getWeight()); order.setVolumeTwo(order.getVolume()); - List legs=this.commonDao.findByQuery("from Legs l where l.order.id=:orderId", - new String[]{"orderId"},new Object[]{order.getId()}); - if(legs.size()<=0){ + List legs = this.commonDao.findByQuery( + "from Legs l where l.order.id=:orderId", + new String[] { "orderId" }, new Object[] { order.getId() }); + if (legs.size() <= 0) { publishEdiServerAvailableOrder(order); } createCusFee(order); - feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, Boolean.TRUE); - List legs2=this.commonDao.findByQuery("from Legs l where l.order.id=:orderId", - new String[]{"orderId"},new Object[]{order.getId()}); - if(legs2.size()>0&&license_id!=null){ - shipmentManager.createShipment_demo(legs2.get(0).getId(), license_id, userId, userName); + feeManager.refreshBillFee(order.getId(), BillObjectType.ORDER, + Boolean.TRUE); + List legs2 = this.commonDao.findByQuery( + "from Legs l where l.order.id=:orderId", + new String[] { "orderId" }, new Object[] { order.getId() }); + if (legs2.size() > 0 && license_id != null) { + shipmentManager.createShipment_demo(legs2.get(0).getId(), + license_id, userId, userName); } - + } - - public void cretate_shipment(String ids,Long platFormId,Long userId,String userName,Long carrier_id,Long license_id,Long driver_id,String driver_tel,String ps_node){ - String[] id=ids.split(","); - List legIds=new ArrayList(); - for(int i=0;i legIds = new ArrayList(); + for (int i = 0; i < id.length; i++) { legIds.add(Long.parseLong(id[i].toString())); } - shipmentManager.createShipment_demo(legIds,carrier_id,license_id,driver_id,driver_tel,ps_node); + shipmentManager.createShipment_demo(legIds, carrier_id, license_id, + driver_id, driver_tel, ps_node); } + public void importCurrencyOrderFee(File file) { - String meg=""; - try { + String meg = ""; + try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); - //订单号 - for (int i = 1; i ts=this.commonDao.findByQuery(" from Order o where o.customerOrderNO='"+dh+"'"); - if(ts.size()>0) { - for(Order o:ts){ - double f1=0; - double f2=0; - if(fee!=null&&!fee.equals("")) { - f1=Double.parseDouble(fee); - } - if(fee1!=null&&!fee1.equals("")) { - f2=Double.parseDouble(fee1); - } - if(f1>0) { - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "运输费", f1); - } - if(f2>0) { - feeManager.saveInputFee(o.getId(), BillObjectType.ORDER, null, "其他费", f2); - } - feeManager.refreshBillFee(o.getId(), BillObjectType.ORDER, Boolean.TRUE); - } - }else { - meg+=dh; - } - System.out.println(i); - } - System.out.println("不存在的客户订单号---"+meg); + Sheet sheet = workbook.getSheet(0);// 得到excel第一页的内容 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); + // 订单号 + for (int i = 1; i < sheet.getRows(); i++) { + String dh = sheet.getCell(1, i).getContents(); + String fee = sheet.getCell(11, i).getContents(); + String fee1 = sheet.getCell(12, i).getContents(); + + List ts = this.commonDao + .findByQuery(" from Order o where o.customerOrderNO='" + + dh + "'"); + if (ts.size() > 0) { + for (Order o : ts) { + double f1 = 0; + double f2 = 0; + if (fee != null && !fee.equals("")) { + f1 = Double.parseDouble(fee); + } + if (fee1 != null && !fee1.equals("")) { + f2 = Double.parseDouble(fee1); + } + if (f1 > 0) { + feeManager.saveInputFee(o.getId(), + BillObjectType.ORDER, null, "运输费", f1); + } + if (f2 > 0) { + feeManager.saveInputFee(o.getId(), + BillObjectType.ORDER, null, "其他费", f2); + } + feeManager.refreshBillFee(o.getId(), + BillObjectType.ORDER, Boolean.TRUE); + } + } else { + meg += dh; + } + System.out.println(i); + } + System.out.println("不存在的客户订单号---" + meg); } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); - }finally{ - meg+="导入失败"; + } finally { + meg += "导入失败"; System.out.println(meg); } - + } - - public void updateMethod(List ids, String shipmentMethod){ - for(Long id:ids){ - Order o=this.commonDao.get(Order.class, id); + + public void updateMethod(List ids, String shipmentMethod) { + for (Long id : ids) { + Order o = this.commonDao.get(Order.class, id); o.setShipmentMethod(shipmentMethod); this.commonDao.store(o); - List fos=new ArrayList() ; - if(!o.getStatus().equals(OrderStatus.TRANS_AVAILABLE)){ + List fos = new ArrayList(); + if (!o.getStatus().equals(OrderStatus.TRANS_AVAILABLE)) { fos.add(id); this.refreshOrderFee(fos); } } } - - public void updateIndex(List ids, int groupIndex){ - for(Long id:ids){ - Order o=this.commonDao.get(Order.class, id); + + public void updateIndex(List ids, int groupIndex) { + for (Long id : ids) { + Order o = this.commonDao.get(Order.class, id); o.setGroupIndex(groupIndex); this.commonDao.store(o); } } - + @Override public void importOrderFee(File file) { try { Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - for (int i = 1; i Orders = commonDao.findByQuery(" from Order o where o.relateBill3=:relateBill3 ", - new String[] { "relateBill3"},new Object[] {relateBill3}); - if(Orders.size()>0){ - Order order=Orders.get(0); - - if(Double.parseDouble(bzf)<=0){ - long id=getFeeId(order.getId(), "包装费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); - order.setFee9(Double.parseDouble(bzf)); + Sheet sheet = workbook.getSheet(0);// 得到excel第一页的内容 + for (int i = 1; i < sheet.getRows(); i++) { + + String relateBill3 = sheet.getCell(0, i).getContents();// 订单号 + String bzf = sheet.getCell(2, i).getContents().equals("") ? "0" + : sheet.getCell(2, i).getContents();// 包装费 + String thf = sheet.getCell(3, i).getContents().equals("") ? "0" + : sheet.getCell(3, i).getContents();// 提货费 + String ysf = sheet.getCell(4, i).getContents().equals("") ? "0" + : sheet.getCell(4, i).getContents();// 运输费 + String shf = sheet.getCell(5, i).getContents().equals("") ? "0" + : sheet.getCell(5, i).getContents();// 送货费 + String qtf = sheet.getCell(6, i).getContents().equals("") ? "0" + : sheet.getCell(6, i).getContents();// 其他费 + String jjf = sheet.getCell(7, i).getContents().equals("") ? "0" + : sheet.getCell(7, i).getContents();// 加急费 + String bxf = sheet.getCell(8, i).getContents().equals("") ? "0" + : sheet.getCell(8, i).getContents();// 保险费 + String fwf = sheet.getCell(9, i).getContents().equals("") ? "0" + : sheet.getCell(9, i).getContents();// 服务费 + String dsyf = sheet.getCell(10, i).getContents().equals("") ? "0" + : sheet.getCell(10, i).getContents();// 代收运费 + String tpf = sheet.getCell(11, i).getContents().equals("") ? "0" + : sheet.getCell(11, i).getContents();// 托盘费 + String receivefee = sheet.getCell(12, i).getContents() + .equals("") ? "0" : sheet.getCell(12, i).getContents();// 合计费用 + if (relateBill3 == null || relateBill3.length() <= 0) { + return; + } + List Orders = commonDao.findByQuery( + " from Order o where o.relateBill3=:relateBill3 ", + new String[] { "relateBill3" }, + new Object[] { relateBill3 }); + if (Orders.size() > 0) { + Order order = Orders.get(0); + + if (Double.parseDouble(bzf) <= 0) { + long id = getFeeId(order.getId(), "包装费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); + order.setFee9(Double.parseDouble(bzf)); } - } - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "包装费", Double.parseDouble(bzf)); - order.setFee9(Double.parseDouble(bzf)); - } - - if(Double.parseDouble(thf)<=0){ - long id=getFeeId(order.getId(), "提货费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); - order.setFee2(Double.parseDouble(thf)); + } + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "包装费", + Double.parseDouble(bzf)); + order.setFee9(Double.parseDouble(bzf)); + } + + if (Double.parseDouble(thf) <= 0) { + long id = getFeeId(order.getId(), "提货费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); + order.setFee2(Double.parseDouble(thf)); } - } - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "提货费", Double.parseDouble(thf)); - order.setFee2(Double.parseDouble(thf)); - } - - if(Double.parseDouble(ysf)<=0){ - long id=getFeeId(order.getId(), "运输费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); - order.setFee1(Double.parseDouble(ysf)); + } + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "提货费", + Double.parseDouble(thf)); + order.setFee2(Double.parseDouble(thf)); + } + + if (Double.parseDouble(ysf) <= 0) { + long id = getFeeId(order.getId(), "运输费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); + order.setFee1(Double.parseDouble(ysf)); } - } - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "运输费", Double.parseDouble(ysf)); - order.setFee1(Double.parseDouble(ysf)); - } - - if(Double.parseDouble(shf)<=0){ - long id=getFeeId(order.getId(), "送货费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); - order.setFee3(Double.parseDouble(shf)); + } + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "运输费", + Double.parseDouble(ysf)); + order.setFee1(Double.parseDouble(ysf)); + } + + if (Double.parseDouble(shf) <= 0) { + long id = getFeeId(order.getId(), "送货费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); + order.setFee3(Double.parseDouble(shf)); } - } - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "送货费", Double.parseDouble(shf)); - order.setFee3(Double.parseDouble(shf)); - } - - if(Double.parseDouble(qtf)<=0){ - long id=getFeeId(order.getId(), "其他费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); - order.setFee8(Double.parseDouble(qtf)); + } + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "送货费", + Double.parseDouble(shf)); + order.setFee3(Double.parseDouble(shf)); + } + + if (Double.parseDouble(qtf) <= 0) { + long id = getFeeId(order.getId(), "其他费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); + order.setFee8(Double.parseDouble(qtf)); } - } - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "其他费", Double.parseDouble(qtf)); - order.setFee8(Double.parseDouble(qtf)); - } - - if(Double.parseDouble(jjf)<=0){ - long id=getFeeId(order.getId(), "加急费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); - order.setFee5(Double.parseDouble(jjf)); + } + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "其他费", + Double.parseDouble(qtf)); + order.setFee8(Double.parseDouble(qtf)); + } + + if (Double.parseDouble(jjf) <= 0) { + long id = getFeeId(order.getId(), "加急费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); + order.setFee5(Double.parseDouble(jjf)); } - } - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "加急费", Double.parseDouble(jjf)); - order.setFee5(Double.parseDouble(jjf)); - } - - - if(Double.parseDouble(bxf)<=0){ - long id=getFeeId(order.getId(), "保险费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); - order.setFee4(Double.parseDouble(bxf)); + } + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "加急费", + Double.parseDouble(jjf)); + order.setFee5(Double.parseDouble(jjf)); + } + + if (Double.parseDouble(bxf) <= 0) { + long id = getFeeId(order.getId(), "保险费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); + order.setFee4(Double.parseDouble(bxf)); } - } - - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "保险费", Double.parseDouble(bxf)); - order.setFee4(Double.parseDouble(bxf)); - } - - if(Double.parseDouble(fwf)<=0){ - long id=getFeeId(order.getId(), "服务费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); - order.setFee6(Double.parseDouble(fwf)); + } + + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "保险费", + Double.parseDouble(bxf)); + order.setFee4(Double.parseDouble(bxf)); + } + + if (Double.parseDouble(fwf) <= 0) { + long id = getFeeId(order.getId(), "服务费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); + order.setFee6(Double.parseDouble(fwf)); } - } - - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "服务费", Double.parseDouble(fwf)); - order.setFee6(Double.parseDouble(fwf)); - } - - if(Double.parseDouble(dsyf)<=0){ - long id=getFeeId(order.getId(), "代收运费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); - order.setFee11(Double.parseDouble(dsyf)); + } + + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "服务费", + Double.parseDouble(fwf)); + order.setFee6(Double.parseDouble(fwf)); + } + + if (Double.parseDouble(dsyf) <= 0) { + long id = getFeeId(order.getId(), "代收运费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); + order.setFee11(Double.parseDouble(dsyf)); } - } - - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "代收运费", Double.parseDouble(dsyf)); - order.setFee11(Double.parseDouble(dsyf)); - } - - if(Double.parseDouble(tpf)<=0){ - long id=getFeeId(order.getId(), "托盘费"); - if(id>0){ - List ids=new ArrayList(); - ids.add(id); - Fee fee=this.load(Fee.class, id); - if(fee.getReimbursemengt()==null&&fee.getBillFee()==null){ - feeManager.deleteFee(ids); + } + + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "代收运费", + Double.parseDouble(dsyf)); + order.setFee11(Double.parseDouble(dsyf)); + } + + if (Double.parseDouble(tpf) <= 0) { + long id = getFeeId(order.getId(), "托盘费"); + if (id > 0) { + List ids = new ArrayList(); + ids.add(id); + Fee fee = this.load(Fee.class, id); + if (fee.getReimbursemengt() == null + && fee.getBillFee() == null) { + feeManager.deleteFee(ids); } - } - - }else{ - feeManager.saveInputFee(order.getId(), BillObjectType.ORDER, null, "托盘费", Double.parseDouble(tpf)); - } - - - order.setReceivefee(Double.parseDouble(receivefee)); - commonDao.store(order); - }else{ - throw new BusinessException("第"+(i+1)+"行,"+relateBill3+"单号不存在!"); - } - System.out.println("收入费用导入第"+(i+1)+"行"); - } + } + + } else { + feeManager.saveInputFee(order.getId(), + BillObjectType.ORDER, null, "托盘费", + Double.parseDouble(tpf)); + } + + order.setReceivefee(Double.parseDouble(receivefee)); + commonDao.store(order); + } else { + throw new BusinessException("第" + (i + 1) + "行," + + relateBill3 + "单号不存在!"); + } + System.out.println("收入费用导入第" + (i + 1) + "行"); + } } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } - - public long getFeeId(long orderId,String feeName){ + + public long getFeeId(long orderId, String feeName) { System.out.println(feeName); - long id=0; - List Fees = commonDao.findByQuery(" from Fee f where f.billId=:billId and f.billObject='ORDER' and f.feeName.name='"+feeName+"' ", - new String[] { "billId"},new Object[] {orderId}); - if(Fees.size()>0){ - id=Fees.get(0).getId(); + long id = 0; + List Fees = commonDao + .findByQuery( + " from Fee f where f.billId=:billId and f.billObject='ORDER' and f.feeName.name='" + + feeName + "' ", new String[] { "billId" }, + new Object[] { orderId }); + if (Fees.size() > 0) { + id = Fees.get(0).getId(); } return id; } - - public synchronized void shuaxin(long id){ - Shipment s=this.load(Shipment.class, id); - double weight=0; - double volume=0; - String sql=" from Legs leg where leg.shipment.id="+id+" "; - List Legs=commonDao.findByQuery(sql); - for(Legs leg:Legs){ - weight+=leg.getWeight(); - volume+=leg.getVolume(); + + public synchronized void shuaxin(long id) { + Shipment s = this.load(Shipment.class, id); + double weight = 0; + double volume = 0; + String sql = " from Legs leg where leg.shipment.id=" + id + " "; + List Legs = commonDao.findByQuery(sql); + for (Legs leg : Legs) { + weight += leg.getWeight(); + volume += leg.getVolume(); } s.setWeight(weight); s.setVolume(volume); commonDao.store(s); } } -