diff --git a/src/main/java/com/dev/stms/server/service/order/pojo/DefaultImportOrderManager.java b/src/main/java/com/dev/stms/server/service/order/pojo/DefaultImportOrderManager.java index 6ec2930..6951891 100644 --- a/src/main/java/com/dev/stms/server/service/order/pojo/DefaultImportOrderManager.java +++ b/src/main/java/com/dev/stms/server/service/order/pojo/DefaultImportOrderManager.java @@ -70,464 +70,461 @@ import com.dev.energy.server.util.LocalizedMessage; import com.dev.energy.server.web.security.UserHolder; /** - * @author dev + * @author dev */ public class DefaultImportOrderManager extends DefaultBaseManager implements ImportOrderManager { - protected final ImportOrderPlusManager importOrderPlusManager; - private BussinessCodeManager codeManager; - protected final TmsOperationHisManager operationHisManager; - private FeeManager feeManager; - private OrderManager orderManager; - private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - private SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd"); - public DefaultImportOrderManager(ImportOrderPlusManager importOrderPlusManager,BussinessCodeManager codeManager, - TmsOperationHisManager operationHisManager,FeeManager feeManager,OrderManager orderManager){ - this.importOrderPlusManager = importOrderPlusManager; - this.codeManager = codeManager; - this.operationHisManager = operationHisManager; - this.feeManager = feeManager; - this.orderManager = orderManager; - } + protected final ImportOrderPlusManager importOrderPlusManager; + private BussinessCodeManager codeManager; + protected final TmsOperationHisManager operationHisManager; + private FeeManager feeManager; + private OrderManager orderManager; + private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + private SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd"); - public void importOrder(File filePath)throws Exception { - BufferedReader br ; - try { - br = new BufferedReader(new InputStreamReader(new FileInputStream( - filePath),"GBK")); - } catch (FileNotFoundException e) { - e.printStackTrace(); - throw new BusinessException("import.file.no.exists"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - throw new BusinessException("no.support.encoding"); - } - List fields = parseHeader(br.readLine()); - String line; - int index = 1; - int success = 0; - StringBuffer bufLog = new StringBuffer(); - StringBuffer bufException = new StringBuffer(); - Map> orders = new HashMap>(); - while((line = br.readLine()) != null){ - index++; - try { - importOrderPlusManager.parseLine(parseLine(line,fields.size()), fields,orders); - }catch (PropertyMappingException e) { - e.printStackTrace(); - bufException.append(e.getMessage() + "\n"); - bufLog.append(getText("import.row") +"[" + index + "]:" + e.getProperty() + "\n"); - }catch (BusinessException e) { - e.printStackTrace(); - bufException.append(e.getMessage() + "\n"); - bufLog.append(getText("import.row") +"[" + index + "]:" + e.getMessage() + "\n"); - }catch (PropertyValueException e) { - e.printStackTrace(); - bufException.append(e.getMessage() + "\n"); - bufLog.append(getText("import.row") +"[" + index + "]:" + "[entityClass]:" + e.getEntityName() + ",[propertyName]:" +e.getPropertyName() + getText("is.null") + "\n"); - }catch (DataIntegrityViolationException e) { - e.printStackTrace(); - bufLog.append(getText("import.row")+"[" + index + "]:"+getText("DataIntegrityViolationException")+"\n"); - bufException.append(e.getMessage() + "\n"); - }catch (Exception e) { - e.printStackTrace(); - bufLog.append(getText("import.row")+"[" + index + "]:"+e.getMessage()+"\n"); - bufException.append(e.getMessage() + "\n"); - } - } - int count = orders.size(); - for(Map.Entry> me : orders.entrySet()){ - Order o = me.getKey(); - for(OrderDetail od : me.getValue()){ - o.addDetailAndUpdateQuantity(od); - } - try { - importOrderPlusManager.storeOrder(o); - success++; - }catch (PropertyMappingException e) { - e.printStackTrace(); - bufException.append(e.getMessage() + "\n"); - bufLog.append(getText("import.code") +"[" + o.getCode() + "]:" + e.getProperty() + "\n"); - }catch (PropertyValueException e) { - e.printStackTrace(); - bufException.append(e.getMessage() + "\n"); - bufLog.append(getText("import.code") +"[" + o.getCode() + "]:" + getText("DataIntegrityViolationException") + "\n"); - }catch (DataIntegrityViolationException e) { - e.printStackTrace(); - bufLog.append(getText("import.code") +"[" + o.getCode() + "]:" + getText("DataIntegrityViolationException") + "\n"); - bufException.append(e.getMessage() + "\n"); - }catch (Exception e) { - e.printStackTrace(); - bufLog.append(getText("import.code") +"[" + o.getCode() + "]:" + getText("DataIntegrityViolationException") + "\n"); - bufException.append(e.getMessage() + "\n"); - } - - } - ExceptionLog log = new ExceptionLog(); - log.setOperUserId(UserHolder.getUser().getId()); - log.setOperUserName(UserHolder.getUser().getName()); - log.setOperPageId("manualImportOrderPage"); - log.setOperPageName("手工订单导入"); - log.setOperComponentId(Order.class.getName()); - log.setOperComponentName("导入" + StringUtils.substringBetweenFirstAndLast(filePath.getName(),"-", "-")); - log.setOperDate(new Date()); - log.setOperException(bufException.toString()); - log.setOperExceptionMess(getText("import.user")+"["+getText("user.id")+":" - + log.getOperUserId() - + ","+getText("user.name")+":" - + log.getOperUserName() - + "]" - + " "+getText("import.data.into")+" "+getText("import.businessobject")+"[" - + "订单" - + ":" - + log.getOperComponentId() - + "] "+getText("import.at.time")+":" - + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") - .format(log.getOperDate()) + "\n" - + getText("import.result")+":"+getText("importRecord.successNum")+"[" + success - + "],"+getText("importRecord.failNum")+"[" + (count - success) + "]\n" - + bufLog.toString()); - importOrderPlusManager.storeExceptionLog(log); - LocalizedMessage.addMessage("import.success.info", new String[] { - String.valueOf(success), - String.valueOf(count - success) }); - } - - private String getText(String text) { - return LocalizedMessage.getLocalizedMessage(text, - UserHolder.getReferenceModel(), UserHolder.getUser().getLocale().toString()); - } - - private List parseHeader(String line)throws IOException { - List lines = new ArrayList(); - String[] splits = ImportUtils.splitCSVRowIntoArray(line); - int len = splits.length; - for (int i = 0; i < len; i++) { - lines.add(pattern(splits[i])); - } - return lines; - } - - private List parseLine(String line,int size)throws IOException { - List lines = new ArrayList(); - String[] splits = ImportUtils.splitCSVRowIntoArray(line); - int len = splits.length; - for (int i = 0; i < len; i++) { - lines.add(splits[i]); - } - for(int i = 0; i < (size - len); i++){ - lines.add(null); - } - return lines; - } - - protected String pattern(String str) { - Pattern pattern = Pattern.compile("([\\w]+[.]{0,1}[\\w]+[.]{0,1}[\\w]+)"); - Matcher matcher = pattern.matcher(str); - matcher.find(); - return matcher.group(); - } - - public void importOrderKEJ(File file){ - DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); - DateFormat format2= new SimpleDateFormat("HH:mm"); - Date kdrq=null;//开单日期 - Date jhthrq=null;//计划提货日期 - Date jhddrq=null;//计划到达日期 - String sj="";//计划提货时间(hh:mm) - String sj2="";//计划到达时间(hh:mm) - try { - //客户名称 客户订单号 品名 业务员 数量 单位 重量(千克) 体积(立方米) 包装单位 开单时间 - //计划提货日期 计划提货时间 计划出发时间 计划运达时间 计量单位 计费线路 货物类型 运输方式 - //交付方式 付款方式 发货城市 发货单位 发货联系人 发货电话 发货地址 发货要求 送货城市 送货单位 - //送货联系人 送货电话 送货地址 送货要求 备注 - Workbook workbook = Workbook.getWorkbook(file); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - // 非空字段判断 - for(int i = 1; i customers=this.commonDao.findByQuery("from Organization where name=:name",new String[]{"name"},new Object[]{customerName}); - if(customers.size()>0){ - customer =customers.get(0); - }else{ - throw new BusinessException((i+1)+"行,客户不存在!"); - } - String customerOrderNO=sheet.getCell(1,i).getContents();// 客户订单号 - String itemName=sheet.getCell(2,i).getContents();// 品名 - String carPeople=sheet.getCell(3,i).getContents();//业务员 - String quantity=sheet.getCell(4,i).getContents().equals("")?"0":sheet.getCell(4,i).getContents();//数量 - String unitOne=sheet.getCell(5,i).getContents();//单位 - Double weight=sheet.getCell(6,i).getContents().equals("")?0:Double.parseDouble(sheet.getCell(6,i).getContents());//重量 - Double volume=sheet.getCell(7,i).getContents().equals("")?0:Double.parseDouble(sheet.getCell(7,i).getContents());//体积 - String packUnit=sheet.getCell(8,i).getContents();//包装单位 - String orderDate=sheet.getCell(9,i).getContents();//开单时间 - String planFromDate=sheet.getCell(10,i).getContents();//计划提货日期 - String planFromTime=sheet.getCell(11,i).getContents();//计划提货时间(hh:mm) - String planArriveTime=sheet.getCell(12,i).getContents();//计划到达日期 - String declare=sheet.getCell(13,i).getContents();//计划到达时间(hh:mm) - if(orderDate==null || "".equals(orderDate)){ - order.setOrderDate(new Date()); - }else{ - kdrq=format1.parse(orderDate); - Organization contractor=PlatFormHolder.getPlatForm(); - if(contractor.getTaxRate()>0){ - //导入限制 - if (!isOrderDateValid(orderDate, contractor.getTaxRate())) { - throw new BusinessException(contractor.getTaxRate() + "月之前的订单, 不允许导入!"); - } - - } - } - if(planFromDate==null || "".equals(planFromDate)){ - order.setPlanFromDate(new Date()); - }else{ - jhthrq=format1.parse(planFromDate); - } - if(planFromTime!=null && !"".equals(planFromTime)){ - Date jhthsj=format2.parse(planFromTime); - sj=format2.format(jhthsj); - } - - if(planArriveTime==null || "".equals(planArriveTime)){ - order.setPlanArriveTime(new Date()); - }else{ - jhddrq=format1.parse(planArriveTime); - } - - if(declare!=null && !"".equals(declare)){ - Date jhddsj=format2.parse(declare); - sj2=format2.format(jhddsj); - } - - String unit=sheet.getCell(14,i).getContents();//计量单位 - String routeFeeName=sheet.getCell(15,i).getContents();//计费线路 - String superviseType=sheet.getCell(16,i).getContents();//货物类型 - String shipmentMethod=sheet.getCell(17,i).getContents();//运输方式 - String deliveryMode=sheet.getCell(18,i).getContents();//交付方式 - String paymentMethod=sheet.getCell(19,i).getContents();//付款方式 - String fromCity=sheet.getCell(20,i).getContents(); - String from=sheet.getCell(21,i).getContents();//提货单位 - String fromlinkman=sheet.getCell(22,i).getContents();//联系人 - String fromphone=sheet.getCell(23,i).getContents();//联系电话 - String fromaddress=sheet.getCell(24,i).getContents();//提货地址 - String thyq=sheet.getCell(25,i).getContents();//提货要求 - String tocity=sheet.getCell(26,i).getContents();//送货城市 - String toName=sheet.getCell(27,i).getContents();//收货单位 - String tolinkman=sheet.getCell(28,i).getContents();//联系人 - String tophone=sheet.getCell(29,i).getContents();//联系电话 - String toaddress=sheet.getCell(30,i).getContents();//送货地址 - String shyq=sheet.getCell(31,i).getContents();//送货要求 - - //计量单位 - if( unit==null || "".equals(unit)){ - order.setUnit("WEIGHT"); - }else{ - if("整车".equals(unit)){ - unit="VEHICLETYPE"; - }else if("重量".equals(unit)){ - unit="WEIGHT"; - }else if("票".equals(unit)){ - unit="TICKET"; - }else if("体积".equals(unit)){ - unit="VOLUME"; - } - } - - //计费路线 - List routeFees=this.commonDao.findByQuery("from RouteFee f where f.name=:name", - new String[]{"name"},new Object[]{routeFeeName}); - RouteFee routeFee=null; - if(routeFees.size()>0){ - routeFee=routeFees.get(0); - order.setRouteFee(routeFee); - }else{ - List rfs=this.commonDao.findByQuery("from RouteFee f where f.name=:name", - new String[]{"name"},new Object[]{"临时-临时"}); - if(rfs.size()>0){ - routeFee=rfs.get(0); - } - } - - //货物类型 - if(superviseType==null || "".equals(superviseType)){ - order.setSuperviseType(SuperviseType.UNSUPERVISE); - }else{ - if(superviseType.equals("监管")){ - superviseType=SuperviseType.SUPERVISE; - }else if(superviseType.equals("普货")){ - superviseType=SuperviseType.UNSUPERVISE; - }else if(superviseType.equals("危货")){ - superviseType=SuperviseType.DANGEROUS_GOODS; - }else if(superviseType.equals("危废")){ - superviseType=SuperviseType.DANGEROUS_WASTE; - }else if(superviseType.equals("冷藏")){ - superviseType=SuperviseType.COLD_STORAGE; - }else if(superviseType.equals("大件")){ - superviseType=SuperviseType.BIG_PIECES; - }else{ - order.setSuperviseType(SuperviseType.UNSUPERVISE); - } - } - - //运输方式 - if(shipmentMethod==null || "".equals(shipmentMethod)){ - order.setShipmentMethod("TRUCK"); - }else{ - if(shipmentMethod.equals("汽运")){ - shipmentMethod="TRUCK"; - }else if(shipmentMethod.equals("海运")){ - shipmentMethod="SEA"; - }else if(shipmentMethod.equals("空运")){ - shipmentMethod="AIR"; - }else if(shipmentMethod.equals("陆运")){ - shipmentMethod="RAILWAY"; - }else if(shipmentMethod.equals("所有")){ - shipmentMethod="ALL"; - }else if(shipmentMethod.equals("零担")){ - shipmentMethod="ZERO_SINGLE"; - }else if(shipmentMethod.equals("零担加急")){ - shipmentMethod="URGENT"; - } - } - //交付方式 - if(deliveryMode==null || "".equals(deliveryMode)){ - order.setDeliveryMode("送货上门"); - } - - //付款方式 - if(paymentMethod==null || "".equals(paymentMethod)){ - order.setDeliveryMode("月付"); - } - - //提货城市 - City fCity =null; - if(fromCity.equals("") || fromCity==null){ - throw new BusinessException((i+1)+"行,提货城市不能为空!"); - }else{ - List fCitys= this.commonDao.findByQuery("from City c where c.name like '%"+fromCity+"%' and c.disabled=0"); - if(fCitys.size()>0){ - fCity=fCitys.get(0); - }else{ - throw new BusinessException((i+1)+"行,提货城市不存在!"); - } - } - - //收货城市 - City tCity =null; - if(tocity.equals("") || tocity==null){ - throw new BusinessException((i+1)+"行,收货城市不能为空!"); - }else{ - List tCitys= this.commonDao.findByQuery("from City c where c.name like '%"+tocity+"%' and c.disabled=0"); - if(tCitys.size()>0){ - tCity=tCitys.get(0); - }else{ - throw new BusinessException((i+1)+"行,收货城市不存在!"); - } - } - - //提货单位 - if(from!=null){ - TransLocation fl=null; - List fls= this.commonDao.findByQuery("from TransLocation f where f.name=:name and f.disabled=0", - new String[]{"name"},new Object[]{from}); - if(fls.size()>0){ - fl=fls.get(0); - order.setFromLocation(fl); - }else{ - order.setFromName(from); - Contact fromContact=new Contact(); - if(fromlinkman!=null) - fromContact.setLinkman(fromlinkman); - if(fromphone!=null) - fromContact.setPhone(fromphone); - if(fromphone!=null) - fromContact.setAddress(fromaddress); - order.setFromContact(fromContact); - } - } - - //收货单位 - TransLocation tl=null; - List tls= this.commonDao.findByQuery("from TransLocation f where f.name=:name and f.disabled=0", - new String[]{"name"},new Object[]{toName}); - if(tls.size()>0){ - tl=tls.get(0); - order.setToLocation(tl); - }else{ - order.setToName(toName); - Contact toContact=new Contact(); - if(tolinkman!=null) - toContact.setLinkman(tolinkman); - if(toaddress!=null) - toContact.setAddress(toaddress); - if(tophone!=null) - toContact.setPhone(tophone); - order.setToContact(toContact); - } - - order.setConsignor(customer);//客户名称 - order.setCustomerOrderNO(customerOrderNO);//客户订单号 - order.setItemName(itemName);//品名 - //业务员 - if(carPeople!=null && !"".equals(carPeople)){ - order.setCarPeople(carPeople); - } - order.setQuantity(Double.parseDouble(quantity));//数量 - order.setUnitOne(unitOne);//单位 - order.setWeight(weight);//重量 - order.setVolume(volume);//体积 - order.setPackUnit(packUnit);//包装单位 - order.setOrderDate(kdrq);//开单时间 - order.setPlanFromDate(jhthrq);//计划提货日期 - order.setPlanFromTime(sj);//计划提货时间 - order.setPlanArriveTime(jhddrq);//计划到达日期 - order.setDeclare(sj2);//计划到达时间 - order.setUnit(unit); - order.setRouteFee(routeFee); - order.setShipmentMethod(shipmentMethod); - order.setPaymentMethod(paymentMethod); - order.setDeliveryMode(deliveryMode); - order.setFromCityCountiy(fCity);//提货城市 - order.setToCityCountiy(tCity);//送货城市 - order.setDescription1(thyq); - order.setDescription2(shyq); - order.setOperator(UserHolder.getUser().getName()); - order.setOperatorDate(new Date()); - order.setContractor(PlatFormHolder.getPlatForm()); - order.setCreateTime(new Date()); - order.setOtherStatus(FeeStatus.OPEN); - order.setStatus("AVAILABLE"); - order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); - order.setRelateBill3(codeManager.generateItemCode()); - order.setCode(codeManager.generateItemCode()); - order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); - this.commonDao.store(order); - System.out.println(i); - } - - + public DefaultImportOrderManager(ImportOrderPlusManager importOrderPlusManager, BussinessCodeManager codeManager, + TmsOperationHisManager operationHisManager, FeeManager feeManager, OrderManager orderManager) { + this.importOrderPlusManager = importOrderPlusManager; + this.codeManager = codeManager; + this.operationHisManager = operationHisManager; + this.feeManager = feeManager; + this.orderManager = orderManager; + } - - } catch (BiffException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + public void importOrder(File filePath) throws Exception { + BufferedReader br; + try { + br = new BufferedReader(new InputStreamReader(new FileInputStream( + filePath), "GBK")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + throw new BusinessException("import.file.no.exists"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + throw new BusinessException("no.support.encoding"); + } + List fields = parseHeader(br.readLine()); + String line; + int index = 1; + int success = 0; + StringBuffer bufLog = new StringBuffer(); + StringBuffer bufException = new StringBuffer(); + Map> orders = new HashMap>(); + while ((line = br.readLine()) != null) { + index++; + try { + importOrderPlusManager.parseLine(parseLine(line, fields.size()), fields, orders); + } catch (PropertyMappingException e) { + e.printStackTrace(); + bufException.append(e.getMessage() + "\n"); + bufLog.append(getText("import.row") + "[" + index + "]:" + e.getProperty() + "\n"); + } catch (BusinessException e) { + e.printStackTrace(); + bufException.append(e.getMessage() + "\n"); + bufLog.append(getText("import.row") + "[" + index + "]:" + e.getMessage() + "\n"); + } catch (PropertyValueException e) { + e.printStackTrace(); + bufException.append(e.getMessage() + "\n"); + bufLog.append(getText("import.row") + "[" + index + "]:" + "[entityClass]:" + e.getEntityName() + ",[propertyName]:" + e.getPropertyName() + getText("is.null") + "\n"); + } catch (DataIntegrityViolationException e) { + e.printStackTrace(); + bufLog.append(getText("import.row") + "[" + index + "]:" + getText("DataIntegrityViolationException") + "\n"); + bufException.append(e.getMessage() + "\n"); + } catch (Exception e) { + e.printStackTrace(); + bufLog.append(getText("import.row") + "[" + index + "]:" + e.getMessage() + "\n"); + bufException.append(e.getMessage() + "\n"); + } + } + int count = orders.size(); + for (Map.Entry> me : orders.entrySet()) { + Order o = me.getKey(); + for (OrderDetail od : me.getValue()) { + o.addDetailAndUpdateQuantity(od); + } + try { + importOrderPlusManager.storeOrder(o); + success++; + } catch (PropertyMappingException e) { + e.printStackTrace(); + bufException.append(e.getMessage() + "\n"); + bufLog.append(getText("import.code") + "[" + o.getCode() + "]:" + e.getProperty() + "\n"); + } catch (PropertyValueException e) { + e.printStackTrace(); + bufException.append(e.getMessage() + "\n"); + bufLog.append(getText("import.code") + "[" + o.getCode() + "]:" + getText("DataIntegrityViolationException") + "\n"); + } catch (DataIntegrityViolationException e) { + e.printStackTrace(); + bufLog.append(getText("import.code") + "[" + o.getCode() + "]:" + getText("DataIntegrityViolationException") + "\n"); + bufException.append(e.getMessage() + "\n"); + } catch (Exception e) { + e.printStackTrace(); + bufLog.append(getText("import.code") + "[" + o.getCode() + "]:" + getText("DataIntegrityViolationException") + "\n"); + bufException.append(e.getMessage() + "\n"); + } - } - - /** + } + ExceptionLog log = new ExceptionLog(); + log.setOperUserId(UserHolder.getUser().getId()); + log.setOperUserName(UserHolder.getUser().getName()); + log.setOperPageId("manualImportOrderPage"); + log.setOperPageName("手工订单导入"); + log.setOperComponentId(Order.class.getName()); + log.setOperComponentName("导入" + StringUtils.substringBetweenFirstAndLast(filePath.getName(), "-", "-")); + log.setOperDate(new Date()); + log.setOperException(bufException.toString()); + log.setOperExceptionMess(getText("import.user") + "[" + getText("user.id") + ":" + + log.getOperUserId() + + "," + getText("user.name") + ":" + + log.getOperUserName() + + "]" + + " " + getText("import.data.into") + " " + getText("import.businessobject") + "[" + + "订单" + + ":" + + log.getOperComponentId() + + "] " + getText("import.at.time") + ":" + + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") + .format(log.getOperDate()) + "\n" + + getText("import.result") + ":" + getText("importRecord.successNum") + "[" + success + + "]," + getText("importRecord.failNum") + "[" + (count - success) + "]\n" + + bufLog.toString()); + importOrderPlusManager.storeExceptionLog(log); + LocalizedMessage.addMessage("import.success.info", new String[]{ + String.valueOf(success), + String.valueOf(count - success)}); + } + + private String getText(String text) { + return LocalizedMessage.getLocalizedMessage(text, + UserHolder.getReferenceModel(), UserHolder.getUser().getLocale().toString()); + } + + private List parseHeader(String line) throws IOException { + List lines = new ArrayList(); + String[] splits = ImportUtils.splitCSVRowIntoArray(line); + int len = splits.length; + for (int i = 0; i < len; i++) { + lines.add(pattern(splits[i])); + } + return lines; + } + + private List parseLine(String line, int size) throws IOException { + List lines = new ArrayList(); + String[] splits = ImportUtils.splitCSVRowIntoArray(line); + int len = splits.length; + for (int i = 0; i < len; i++) { + lines.add(splits[i]); + } + for (int i = 0; i < (size - len); i++) { + lines.add(null); + } + return lines; + } + + protected String pattern(String str) { + Pattern pattern = Pattern.compile("([\\w]+[.]{0,1}[\\w]+[.]{0,1}[\\w]+)"); + Matcher matcher = pattern.matcher(str); + matcher.find(); + return matcher.group(); + } + + public void importOrderKEJ(File file) { + DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); + DateFormat format2 = new SimpleDateFormat("HH:mm"); + Date kdrq = null;//开单日期 + Date jhthrq = null;//计划提货日期 + Date jhddrq = null;//计划到达日期 + String sj = "";//计划提货时间(hh:mm) + String sj2 = "";//计划到达时间(hh:mm) + try { + //客户名称 客户订单号 品名 业务员 数量 单位 重量(千克) 体积(立方米) 包装单位 开单时间 + //计划提货日期 计划提货时间 计划出发时间 计划运达时间 计量单位 计费线路 货物类型 运输方式 + //交付方式 付款方式 发货城市 发货单位 发货联系人 发货电话 发货地址 发货要求 送货城市 送货单位 + //送货联系人 送货电话 送货地址 送货要求 备注 + Workbook workbook = Workbook.getWorkbook(file); + Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 + // 非空字段判断 + for (int i = 1; i < sheet.getRows(); i++) { + Order order = new Order(); + String customerName = sheet.getCell(0, i).getContents();//客户名称 + if (customerName == null || "".equals(customerName)) { + throw new BusinessException((i + 1) + "行,客户名称不能为空!"); + } + Organization customer = null; + List customers = this.commonDao.findByQuery("from Organization where name=:name", new String[]{"name"}, new Object[]{customerName}); + if (customers.size() > 0) { + customer = customers.get(0); + } else { + throw new BusinessException((i + 1) + "行,客户不存在!"); + } + String customerOrderNO = sheet.getCell(1, i).getContents();// 客户订单号 + String itemName = sheet.getCell(2, i).getContents();// 品名 + String carPeople = sheet.getCell(3, i).getContents();//业务员 + String quantity = sheet.getCell(4, i).getContents().equals("") ? "0" : sheet.getCell(4, i).getContents();//数量 + String unitOne = sheet.getCell(5, i).getContents();//单位 + Double weight = sheet.getCell(6, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(6, i).getContents());//重量 + Double volume = sheet.getCell(7, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(7, i).getContents());//体积 + String packUnit = sheet.getCell(8, i).getContents();//包装单位 + String orderDate = sheet.getCell(9, i).getContents();//开单时间 + String planFromDate = sheet.getCell(10, i).getContents();//计划提货日期 + String planFromTime = sheet.getCell(11, i).getContents();//计划提货时间(hh:mm) + String planArriveTime = sheet.getCell(12, i).getContents();//计划到达日期 + String declare = sheet.getCell(13, i).getContents();//计划到达时间(hh:mm) + if (orderDate == null || "".equals(orderDate)) { + order.setOrderDate(new Date()); + } else { + kdrq = format1.parse(orderDate); + Organization contractor = PlatFormHolder.getPlatForm(); + if (contractor.getTaxRate() > 0) { + //导入限制 + if (!isOrderDateValid(orderDate, contractor.getTaxRate())) { + throw new BusinessException(contractor.getTaxRate() + "月之前的订单, 不允许导入!"); + } + + } + } + if (planFromDate == null || "".equals(planFromDate)) { + order.setPlanFromDate(new Date()); + } else { + jhthrq = format1.parse(planFromDate); + } + if (planFromTime != null && !"".equals(planFromTime)) { + Date jhthsj = format2.parse(planFromTime); + sj = format2.format(jhthsj); + } + + if (planArriveTime == null || "".equals(planArriveTime)) { + order.setPlanArriveTime(new Date()); + } else { + jhddrq = format1.parse(planArriveTime); + } + + if (declare != null && !"".equals(declare)) { + Date jhddsj = format2.parse(declare); + sj2 = format2.format(jhddsj); + } + + String unit = sheet.getCell(14, i).getContents();//计量单位 + String routeFeeName = sheet.getCell(15, i).getContents();//计费线路 + String superviseType = sheet.getCell(16, i).getContents();//货物类型 + String shipmentMethod = sheet.getCell(17, i).getContents();//运输方式 + String deliveryMode = sheet.getCell(18, i).getContents();//交付方式 + String paymentMethod = sheet.getCell(19, i).getContents();//付款方式 + String fromCity = sheet.getCell(20, i).getContents(); + String from = sheet.getCell(21, i).getContents();//提货单位 + String fromlinkman = sheet.getCell(22, i).getContents();//联系人 + String fromphone = sheet.getCell(23, i).getContents();//联系电话 + String fromaddress = sheet.getCell(24, i).getContents();//提货地址 + String thyq = sheet.getCell(25, i).getContents();//提货要求 + String tocity = sheet.getCell(26, i).getContents();//送货城市 + String toName = sheet.getCell(27, i).getContents();//收货单位 + String tolinkman = sheet.getCell(28, i).getContents();//联系人 + String tophone = sheet.getCell(29, i).getContents();//联系电话 + String toaddress = sheet.getCell(30, i).getContents();//送货地址 + String shyq = sheet.getCell(31, i).getContents();//送货要求 + + //计量单位 + if (unit == null || "".equals(unit)) { + order.setUnit("WEIGHT"); + } else { + if ("整车".equals(unit)) { + unit = "VEHICLETYPE"; + } else if ("重量".equals(unit)) { + unit = "WEIGHT"; + } else if ("票".equals(unit)) { + unit = "TICKET"; + } else if ("体积".equals(unit)) { + unit = "VOLUME"; + } + } + + //计费路线 + List routeFees = this.commonDao.findByQuery("from RouteFee f where f.name=:name", + new String[]{"name"}, new Object[]{routeFeeName}); + RouteFee routeFee = null; + if (routeFees.size() > 0) { + routeFee = routeFees.get(0); + order.setRouteFee(routeFee); + } else { + List rfs = this.commonDao.findByQuery("from RouteFee f where f.name=:name", + new String[]{"name"}, new Object[]{"临时-临时"}); + if (rfs.size() > 0) { + routeFee = rfs.get(0); + } + } + + //货物类型 + if (superviseType == null || "".equals(superviseType)) { + order.setSuperviseType(SuperviseType.UNSUPERVISE); + } else { + if (superviseType.equals("监管")) { + superviseType = SuperviseType.SUPERVISE; + } else if (superviseType.equals("普货")) { + superviseType = SuperviseType.UNSUPERVISE; + } else if (superviseType.equals("危货")) { + superviseType = SuperviseType.DANGEROUS_GOODS; + } else if (superviseType.equals("危废")) { + superviseType = SuperviseType.DANGEROUS_WASTE; + } else if (superviseType.equals("冷藏")) { + superviseType = SuperviseType.COLD_STORAGE; + } else if (superviseType.equals("大件")) { + superviseType = SuperviseType.BIG_PIECES; + } else { + order.setSuperviseType(SuperviseType.UNSUPERVISE); + } + } + + //运输方式 + if (shipmentMethod == null || "".equals(shipmentMethod)) { + order.setShipmentMethod("TRUCK"); + } else { + if (shipmentMethod.equals("汽运")) { + shipmentMethod = "TRUCK"; + } else if (shipmentMethod.equals("海运")) { + shipmentMethod = "SEA"; + } else if (shipmentMethod.equals("空运")) { + shipmentMethod = "AIR"; + } else if (shipmentMethod.equals("陆运")) { + shipmentMethod = "RAILWAY"; + } else if (shipmentMethod.equals("所有")) { + shipmentMethod = "ALL"; + } else if (shipmentMethod.equals("零担")) { + shipmentMethod = "ZERO_SINGLE"; + } else if (shipmentMethod.equals("零担加急")) { + shipmentMethod = "URGENT"; + } + } + //交付方式 + if (deliveryMode == null || "".equals(deliveryMode)) { + order.setDeliveryMode("送货上门"); + } + + //付款方式 + if (paymentMethod == null || "".equals(paymentMethod)) { + order.setDeliveryMode("月付"); + } + + //提货城市 + City fCity = null; + if (fromCity.equals("") || fromCity == null) { + throw new BusinessException((i + 1) + "行,提货城市不能为空!"); + } else { + List fCitys = this.commonDao.findByQuery("from City c where c.name like '%" + fromCity + "%' and c.disabled=0"); + if (fCitys.size() > 0) { + fCity = fCitys.get(0); + } else { + throw new BusinessException((i + 1) + "行,提货城市不存在!"); + } + } + + //收货城市 + City tCity = null; + if (tocity.equals("") || tocity == null) { + throw new BusinessException((i + 1) + "行,收货城市不能为空!"); + } else { + List tCitys = this.commonDao.findByQuery("from City c where c.name like '%" + tocity + "%' and c.disabled=0"); + if (tCitys.size() > 0) { + tCity = tCitys.get(0); + } else { + throw new BusinessException((i + 1) + "行,收货城市不存在!"); + } + } + + //提货单位 + TransLocation fl = null; + List fls = this.commonDao.findByQuery("from TransLocation f where f.name=:name and f.disabled=0", + new String[]{"name"}, new Object[]{from}); + if (fls.size() > 0) { + fl = fls.get(0); + order.setFromLocation(fl); + } else { + order.setFromName(from); + Contact fromContact = new Contact(); + if (fromlinkman != null) + fromContact.setLinkman(fromlinkman); + if (fromphone != null) + fromContact.setPhone(fromphone); + if (fromaddress != null) + fromContact.setAddress(fromaddress); + order.setFromContact(fromContact); + } + + //收货单位 + TransLocation tl = null; + List tls = this.commonDao.findByQuery("from TransLocation f where f.name=:name and f.disabled=0", + new String[]{"name"}, new Object[]{toName}); + if (tls.size() > 0) { + tl = tls.get(0); + order.setToLocation(tl); + } else { + order.setToName(toName); + Contact toContact = new Contact(); + if (tolinkman != null) + toContact.setLinkman(tolinkman); + if (toaddress != null) + toContact.setAddress(toaddress); + if (tophone != null) + toContact.setPhone(tophone); + order.setToContact(toContact); + } + + order.setConsignor(customer);//客户名称 + order.setCustomerOrderNO(customerOrderNO);//客户订单号 + order.setItemName(itemName);//品名 + //业务员 + if (carPeople != null && !"".equals(carPeople)) { + order.setCarPeople(carPeople); + } + order.setQuantity(Double.parseDouble(quantity));//数量 + order.setUnitOne(unitOne);//单位 + order.setWeight(weight);//重量 + order.setVolume(volume);//体积 + order.setPackUnit(packUnit);//包装单位 + order.setOrderDate(kdrq);//开单时间 + order.setPlanFromDate(jhthrq);//计划提货日期 + order.setPlanFromTime(sj);//计划提货时间 + order.setPlanArriveTime(jhddrq);//计划到达日期 + order.setDeclare(sj2);//计划到达时间 + order.setUnit(unit); + order.setRouteFee(routeFee); + order.setShipmentMethod(shipmentMethod); + order.setPaymentMethod(paymentMethod); + order.setDeliveryMode(deliveryMode); + order.setFromCityCountiy(fCity);//提货城市 + order.setToCityCountiy(tCity);//送货城市 + order.setDescription1(thyq); + order.setDescription2(shyq); + order.setOperator(UserHolder.getUser().getName()); + order.setOperatorDate(new Date()); + order.setContractor(PlatFormHolder.getPlatForm()); + order.setCreateTime(new Date()); + order.setOtherStatus(FeeStatus.OPEN); + order.setStatus("AVAILABLE"); + order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); + order.setRelateBill3(codeManager.generateItemCode()); + order.setCode(codeManager.generateItemCode()); + order.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); + this.commonDao.store(order); + System.out.println(i); + } + + + } catch (BiffException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + /** * 检查订单日期是否早于指定月份之前的日期(包括当天)。 * * @param orderDate 订单日期字符串(格式为 "yyyy/MM/dd") @@ -550,102 +547,102 @@ public class DefaultImportOrderManager extends DefaultBaseManager implements Imp // 比较订单日期和截止日期 return !orderLocalDate.isBefore(cutoffDate) || orderLocalDate.equals(cutoffDate); - }catch (Exception e){ + } catch (Exception e) { throw new IllegalArgumentException("日期格式错误: " + orderDate, e); } } - public Date ZHdate(String str,int i){ - try { - if(str==null||str.equals("")){ - return null; - } - String[] s1=str.split("-"); - if(s1.length>0){ - if(s1[0].length()<3){ - SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-dd"); - return sdf3.parse(str); - } - } - return sdf.parse(str); - } catch (Exception e) { - try { - return sdf2.parse(str); - } catch (Exception e2) { - throw new BusinessException("第"+(i+1)+"行"+str+"日期格式有误"); - } - } - } + public Date ZHdate(String str, int i) { + try { + if (str == null || str.equals("")) { + return null; + } + String[] s1 = str.split("-"); + if (s1.length > 0) { + if (s1[0].length() < 3) { + SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-dd"); + return sdf3.parse(str); + } + } + return sdf.parse(str); + } catch (Exception e) { + try { + return sdf2.parse(str); + } catch (Exception e2) { + throw new BusinessException("第" + (i + 1) + "行" + str + "日期格式有误"); + } + } + } + + @Override + public synchronized void feeImport(File orderFile) { + long startTime = System.currentTimeMillis(); + Session session = ((HibernateDaoSupport) commonDao).getSessionFactory().openSession(); + DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); + DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); + try { + //计划提货日期 调度日期 车牌号 计费车型 司机 应收(运输费) 应付(运输费) 提货地址 送货地址 承运商 客户名称 录单员 + Workbook workbook = Workbook.getWorkbook(orderFile); + Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 + // 非空字段判断 + String planFromDate = ""; + String operatorDate = ""; + for (int i = 1; i < sheet.getRows(); i++) { + planFromDate = sheet.getCell(0, i).getContents();//计划提货日期 + try { + planFromDate = format2.format(format2.parse(planFromDate)); + } catch (ParseException e) { + // TODO Auto-generated catch block + planFromDate = planFromDate.replace("/", "-"); + } + operatorDate = sheet.getCell(1, i).getContents();//调度日期 + try { + operatorDate = format2.format(format2.parse(operatorDate)); + } catch (ParseException e) { + operatorDate = operatorDate.replace("/", "-"); + } + String license = sheet.getCell(2, i).getContents();// 车牌号 + String vehicleType = sheet.getCell(3, i).getContents();//计费车型 + String driverName = sheet.getCell(4, i).getContents();//司机 + Double receiveMoney = sheet.getCell(5, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(5, i).getContents());//应收 + Double payMoney = sheet.getCell(6, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(6, i).getContents());//应付 + String fromAddress = sheet.getCell(7, i).getContents();//提货地址 + String toAddress = sheet.getCell(8, i).getContents();//送货地址 + String carrier = sheet.getCell(9, i).getContents();//承运商 + String shortName = sheet.getCell(10, i).getContents();//客户 + + //应收orders.fromContact.address + // orders.toContact.address + String sql = " select " + + " o.id,kh.id " + + " from TMS_ORDER_HEAD o " + + " left join TMS_ORGANIZATION kh on kh.id=o.CONSIGNOR_ID " + + " where 1=1" + + " and DATE_FORMAT(o.plan_From_Date,'%Y-%m-%d')='" + planFromDate + "' " + + " and o.VEHICLE_CODE='" + license + "' " + + " and o.EXPECTLICENSE='" + vehicleType + "' " + + " and o.DRIVER_NAME='" + driverName + "' " + + " and o.FROM_ADDRESS='" + fromAddress + "' " + + " and o.TO_ADDRESS='" + toAddress + "' " + + " and kh.SHORTNAME='" + shortName + "' "; + Query query = session.createSQLQuery(sql); + List list = (List) query.list(); + if (list.size() > 0) { + for (Object[] arrier : list) { + Long orderId = Long.parseLong(arrier[0].toString()); + if (orderId != null && orderId.longValue() > 0) { + Order o = commonDao.load(Order.class, orderId); + if (o.getFee1() == 0) { + createOrderFee(orderId, receiveMoney); + } + + } + } + } + - @Override - public synchronized void feeImport(File orderFile) { - long startTime=System.currentTimeMillis(); - Session session = ((HibernateDaoSupport)commonDao).getSessionFactory().openSession(); - DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); - DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); - try { - //计划提货日期 调度日期 车牌号 计费车型 司机 应收(运输费) 应付(运输费) 提货地址 送货地址 承运商 客户名称 录单员 - Workbook workbook = Workbook.getWorkbook(orderFile); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - // 非空字段判断 - String planFromDate=""; - String operatorDate=""; - for(int i = 1; i list= (List)query.list(); - if(list.size()>0){ - for(Object[] arrier:list){ - Long orderId=Long.parseLong(arrier[0].toString()); - if(orderId!=null &&orderId.longValue()>0){ - Order o =commonDao.load(Order.class, orderId); - if(o.getFee1()==0){ - createOrderFee(orderId,receiveMoney); - } - - } - } - } - - // List Orders = commonDao.findByQuery(" from Order o " // + " where 1=1 " // + " and DATE_FORMAT(o.planFromDate,'%Y-%m-%d')=:planFromDate" @@ -662,38 +659,38 @@ public class DefaultImportOrderManager extends DefaultBaseManager implements Imp // } // } // } - - //应付 shipment.fromContact.address, - // shipment.toContact.address, - String sql2=" select " - +" s.id, carrier.id " - +" from TMS_SHIPMENT s " - +" left join TMS_ORGANIZATION carrier on carrier.id=s.CARRIER_ID " - +" left join TMS_VEHICLE_TYPE vehicleType on vehicleType.id=s.VEHICLE_TYPE_ID " - +" where 1=1" - +" and s.COST_STATUS='OPEN'" - +" and DATE_FORMAT(s.OPERATOR_DATE,'%Y-%m-%d')='"+operatorDate+"' " - +" and s.LICENSE='"+license+"' " - +" and vehicleType.NAME='"+vehicleType+"' " - +" and s.DRIVER_NAME='"+driverName+"' " - +" and carrier.NAME='"+carrier+"' " - +" and s.FROM_ADDRESS='"+fromAddress+"' " - +" and s.TO_ADDRESS='"+toAddress+"' "; - Query query2 = session.createSQLQuery(sql2); - List list2= (List)query2.list(); - if(list2.size()>0){ - for(Object[] arrier:list2){ - Long shipmentId=Long.parseLong(arrier[0].toString()); - if(shipmentId!=null &&shipmentId.longValue()>0){ - Shipment s=commonDao.load(Shipment.class, shipmentId); - if(s.getFee1()==0){ - createShipmentFee(shipmentId,payMoney); - } - } - } - } - - + + //应付 shipment.fromContact.address, + // shipment.toContact.address, + String sql2 = " select " + + " s.id, carrier.id " + + " from TMS_SHIPMENT s " + + " left join TMS_ORGANIZATION carrier on carrier.id=s.CARRIER_ID " + + " left join TMS_VEHICLE_TYPE vehicleType on vehicleType.id=s.VEHICLE_TYPE_ID " + + " where 1=1" + + " and s.COST_STATUS='OPEN'" + + " and DATE_FORMAT(s.OPERATOR_DATE,'%Y-%m-%d')='" + operatorDate + "' " + + " and s.LICENSE='" + license + "' " + + " and vehicleType.NAME='" + vehicleType + "' " + + " and s.DRIVER_NAME='" + driverName + "' " + + " and carrier.NAME='" + carrier + "' " + + " and s.FROM_ADDRESS='" + fromAddress + "' " + + " and s.TO_ADDRESS='" + toAddress + "' "; + Query query2 = session.createSQLQuery(sql2); + List list2 = (List) query2.list(); + if (list2.size() > 0) { + for (Object[] arrier : list2) { + Long shipmentId = Long.parseLong(arrier[0].toString()); + if (shipmentId != null && shipmentId.longValue() > 0) { + Shipment s = commonDao.load(Shipment.class, shipmentId); + if (s.getFee1() == 0) { + createShipmentFee(shipmentId, payMoney); + } + } + } + } + + // List Shipments = commonDao.findByQuery(" from Shipment s " // + " where 1=1" // + " and DATE_FORMAT(s.operatorDate,'%Y-%m-%d')=:operatorDate " @@ -714,188 +711,186 @@ public class DefaultImportOrderManager extends DefaultBaseManager implements Imp // } // } // } - long endTime=System.currentTimeMillis(); - float excTime=(float)(endTime-startTime)/1000; - System.out.println("导入"+i+"行,"+"执行时间:"+excTime+"s"); - - } - - + long endTime = System.currentTimeMillis(); + float excTime = (float) (endTime - startTime) / 1000; + System.out.println("导入" + i + "行," + "执行时间:" + excTime + "s"); - - } catch (BiffException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + } - - } - - public void createOrderFee(Long orderId,double receiveMoney){ - Order order=this.load(Order.class, orderId); - List Fees = commonDao.findByQuery(" from Fee f where f.billObject=:billObject and f.billId=:billId and f.feeName.name='运输费' ", - new String[] { "billObject","billId"},new Object[] {BillObjectType.ORDER,orderId}); - if(Fees.size()>0){ - int i=0; - for(Fee f:Fees){ - if(i==0){ - Fee fee=updateFee(f, receiveMoney); - commonDao.store(fee); - order.setFee1(receiveMoney);//运输费 - order.setReceivefee(receiveMoney);//营业额 - commonDao.store(order); - i++; - }else{ - commonDao.delete(f); - } - } - }else{ - if(receiveMoney>0){ - FeeType feeName=commonDao.get(FeeType.class, 1L);//运输费 - Fee fee=feeManager.createFee(orderId, BillObjectType.ORDER, feeName, null, receiveMoney,UserHolder.getUser().getName()); - String des="运输费:"+receiveMoney; - operationHisManager.storeOperationHis(order.getId(), order.getRelateBill3(), null, des, "自动生成", "费用",null,null,order.getQuantity(),order.getWeight(),order.getVolume(),0, des, "TMS"); - order.setFee1(receiveMoney);//运输费 - order.setReceivefee(receiveMoney);//营业额 - commonDao.store(order); - } - - } - - } - - public void createShipmentFee(Long shipmentId,double payMoney){ - Shipment shipment=this.load(Shipment.class, shipmentId); - List Fees = commonDao.findByQuery(" from Fee f where f.billObject=:billObject and f.billId=:billId and f.feeName.name='运输费' ", - new String[] { "billObject","billId"},new Object[] {BillObjectType.SHIPMENT,shipmentId}); - if(Fees.size()>0){ - int i=0; - for(Fee f:Fees){ - if(i==0){ - Fee fee=updateFee(f, payMoney); - commonDao.store(fee); - shipment.setFee1(payMoney); - shipment.setPayfee(payMoney); - shipment.setFee7(payMoney); - commonDao.store(shipment); - List Legss = commonDao.findByQuery(" from Legs l where l.shipment.id=:id ", - new String[] { "id"},new Object[] {shipmentId}); - if(Legss.size()>0){ - for(Legs l: Legss){ - l.setPayfee(payMoney); - commonDao.store(l); - if(l.getOrder()!=null){ - Order o=commonDao.load(Order.class, l.getOrder().getId()); - if(o!=null){ - o.setFee9(payMoney); - commonDao.store(o); - } - } - } - } - i++; - }else{ - commonDao.delete(f); - } - } - }else{ - if(payMoney>0){ - FeeType feeName=commonDao.get(FeeType.class, 1L);//运输费 - Fee fee=feeManager.createFee(shipmentId, BillObjectType.SHIPMENT, feeName, null, payMoney,UserHolder.getUser().getName()); - String des="运输费:"+payMoney; - operationHisManager.storeOperationHis(shipment.getId(), shipment.getCode(), null, des, "自动生成", "费用",null,null,shipment.getQuantity(),shipment.getWeight(),shipment.getVolume(),0, des, "TMS"); - shipment.setFee1(payMoney); - shipment.setPayfee(payMoney); - shipment.setFee7(payMoney); - commonDao.store(shipment); - List Legss = commonDao.findByQuery(" from Legs l where l.shipment.id=:id ", - new String[] { "id"},new Object[] {shipmentId}); - if(Legss.size()>0){ - for(Legs l: Legss){ - l.setPayfee(payMoney); - commonDao.store(l); - if(l.getOrder()!=null){ - Order o=commonDao.load(Order.class, l.getOrder().getId()); - if(o!=null){ - o.setFee9(payMoney); - commonDao.store(o); - } - } - } - } - } - - } - - - } - - private Fee updateFee(Fee f,double amount){ - if(f.getTotalFee()-amount!=0){ - f.setTotalFee(amount); - f.setPrice(amount); - f.setQuantity(1); - f.setNoTaxFee(DoubleUtils.format3Fraction(f.getTotalFee()/(1+f.getTax()/100))); - f.setTaxFee(DoubleUtils.format2Fraction(f.getTax() * f.getNoTaxFee() / 100)); - f.setNoTaxFee(DoubleUtils.format2Fraction(f.getTotalFee()-f.getTaxFee())); - } - return f; - } - @Override - public void receiveFeeImport(File orderFile) { - long startTime=System.currentTimeMillis(); - Session session = ((HibernateDaoSupport)commonDao).getSessionFactory().openSession(); - DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); - DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); - try { - //计划提货日期 订单编号 客户 营业额 业务员 费用状态 - Workbook workbook = Workbook.getWorkbook(orderFile); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - // 非空字段判断 - String planFromDate=""; - String operatorDate=""; - for(int i = 1; i Organizations = commonDao.findByQuery(" from Organization o where o.name=:name and o.bePlatForm=0 and o.beCustomer=1 ", - new String[] { "name"},new Object[] {cusName}); - if(Organizations.size()>0){ - consignor=Organizations.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行"+cusName+"客户不存在,请维护!"); - } - Order order=null; - List Orders = commonDao.findByQuery(" from Order o where o.relateBill3=:relateBill3 ", - new String[] { "relateBill3"},new Object[] {relateBill3}); - if(Orders.size()>0){ - order=Orders.get(0); - order.setVehicleCode(license); - order.setExpectLicense(expectLicense); - order.setDriverName(driverName); + } catch (BiffException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } + + public void createOrderFee(Long orderId, double receiveMoney) { + Order order = this.load(Order.class, orderId); + List Fees = commonDao.findByQuery(" from Fee f where f.billObject=:billObject and f.billId=:billId and f.feeName.name='运输费' ", + new String[]{"billObject", "billId"}, new Object[]{BillObjectType.ORDER, orderId}); + if (Fees.size() > 0) { + int i = 0; + for (Fee f : Fees) { + if (i == 0) { + Fee fee = updateFee(f, receiveMoney); + commonDao.store(fee); + order.setFee1(receiveMoney);//运输费 + order.setReceivefee(receiveMoney);//营业额 + commonDao.store(order); + i++; + } else { + commonDao.delete(f); + } + } + } else { + if (receiveMoney > 0) { + FeeType feeName = commonDao.get(FeeType.class, 1L);//运输费 + Fee fee = feeManager.createFee(orderId, BillObjectType.ORDER, feeName, null, receiveMoney, UserHolder.getUser().getName()); + String des = "运输费:" + receiveMoney; + operationHisManager.storeOperationHis(order.getId(), order.getRelateBill3(), null, des, "自动生成", "费用", null, null, order.getQuantity(), order.getWeight(), order.getVolume(), 0, des, "TMS"); + order.setFee1(receiveMoney);//运输费 + order.setReceivefee(receiveMoney);//营业额 + commonDao.store(order); + } + + } + + } + + public void createShipmentFee(Long shipmentId, double payMoney) { + Shipment shipment = this.load(Shipment.class, shipmentId); + List Fees = commonDao.findByQuery(" from Fee f where f.billObject=:billObject and f.billId=:billId and f.feeName.name='运输费' ", + new String[]{"billObject", "billId"}, new Object[]{BillObjectType.SHIPMENT, shipmentId}); + if (Fees.size() > 0) { + int i = 0; + for (Fee f : Fees) { + if (i == 0) { + Fee fee = updateFee(f, payMoney); + commonDao.store(fee); + shipment.setFee1(payMoney); + shipment.setPayfee(payMoney); + shipment.setFee7(payMoney); + commonDao.store(shipment); + List Legss = commonDao.findByQuery(" from Legs l where l.shipment.id=:id ", + new String[]{"id"}, new Object[]{shipmentId}); + if (Legss.size() > 0) { + for (Legs l : Legss) { + l.setPayfee(payMoney); + commonDao.store(l); + if (l.getOrder() != null) { + Order o = commonDao.load(Order.class, l.getOrder().getId()); + if (o != null) { + o.setFee9(payMoney); + commonDao.store(o); + } + } + } + } + i++; + } else { + commonDao.delete(f); + } + } + } else { + if (payMoney > 0) { + FeeType feeName = commonDao.get(FeeType.class, 1L);//运输费 + Fee fee = feeManager.createFee(shipmentId, BillObjectType.SHIPMENT, feeName, null, payMoney, UserHolder.getUser().getName()); + String des = "运输费:" + payMoney; + operationHisManager.storeOperationHis(shipment.getId(), shipment.getCode(), null, des, "自动生成", "费用", null, null, shipment.getQuantity(), shipment.getWeight(), shipment.getVolume(), 0, des, "TMS"); + shipment.setFee1(payMoney); + shipment.setPayfee(payMoney); + shipment.setFee7(payMoney); + commonDao.store(shipment); + List Legss = commonDao.findByQuery(" from Legs l where l.shipment.id=:id ", + new String[]{"id"}, new Object[]{shipmentId}); + if (Legss.size() > 0) { + for (Legs l : Legss) { + l.setPayfee(payMoney); + commonDao.store(l); + if (l.getOrder() != null) { + Order o = commonDao.load(Order.class, l.getOrder().getId()); + if (o != null) { + o.setFee9(payMoney); + commonDao.store(o); + } + } + } + } + } + + } + + + } + + private Fee updateFee(Fee f, double amount) { + if (f.getTotalFee() - amount != 0) { + f.setTotalFee(amount); + f.setPrice(amount); + f.setQuantity(1); + f.setNoTaxFee(DoubleUtils.format3Fraction(f.getTotalFee() / (1 + f.getTax() / 100))); + f.setTaxFee(DoubleUtils.format2Fraction(f.getTax() * f.getNoTaxFee() / 100)); + f.setNoTaxFee(DoubleUtils.format2Fraction(f.getTotalFee() - f.getTaxFee())); + } + return f; + } + + @Override + public void receiveFeeImport(File orderFile) { + long startTime = System.currentTimeMillis(); + Session session = ((HibernateDaoSupport) commonDao).getSessionFactory().openSession(); + DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); + DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); + try { + //计划提货日期 订单编号 客户 营业额 业务员 费用状态 + Workbook workbook = Workbook.getWorkbook(orderFile); + Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 + // 非空字段判断 + String planFromDate = ""; + String operatorDate = ""; + for (int i = 1; i < sheet.getRows(); i++) { + planFromDate = sheet.getCell(0, i).getContents();//计划提货日期 + try { + planFromDate = format2.format(format2.parse(planFromDate)); + } catch (ParseException e) { + planFromDate = planFromDate.replace("/", "-"); + } + String relateBill3 = sheet.getCell(1, i).getContents();//订单编号 + String cusName = sheet.getCell(2, i).getContents();//客户名称 + String fromAddress = sheet.getCell(3, i).getContents();//提货地址 + String toAddress = sheet.getCell(4, i).getContents();//送货地址 + double receiveMoney = sheet.getCell(5, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(5, i).getContents());//应收 + double sjcb = sheet.getCell(6, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(6, i).getContents());//实际成本 + String ywy = sheet.getCell(7, i).getContents();//业务员 + String costStatus = sheet.getCell(8, i).getContents();//费用状态 + String status = sheet.getCell(9, i).getContents();//订单状态 + String license = sheet.getCell(10, i).getContents();//车牌号 + String expectLicense = sheet.getCell(11, i).getContents();//车型 + String driverName = sheet.getCell(12, i).getContents();//司机名称 + if (cusName == null || cusName.length() <= 0) { + return; + } + Organization consignor = null; + List Organizations = commonDao.findByQuery(" from Organization o where o.name=:name and o.bePlatForm=0 and o.beCustomer=1 ", + new String[]{"name"}, new Object[]{cusName}); + if (Organizations.size() > 0) { + consignor = Organizations.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行" + cusName + "客户不存在,请维护!"); + } + Order order = null; + List Orders = commonDao.findByQuery(" from Order o where o.relateBill3=:relateBill3 ", + new String[]{"relateBill3"}, new Object[]{relateBill3}); + if (Orders.size() > 0) { + order = Orders.get(0); + order.setVehicleCode(license); + order.setExpectLicense(expectLicense); + order.setDriverName(driverName); // if(status.equals("已调度")){ // order.setStatus(OrderStatus.SCHEDULED); // }else if(status.equals("送货在途")){ @@ -908,329 +903,329 @@ public class DefaultImportOrderManager extends DefaultBaseManager implements Imp // order.setStatus(OrderStatus.SH_ARRIVED); // } // order.setFee9(sjcb);//实际成本 - commonDao.store(order); + commonDao.store(order); // shuaxinOrderFee(order.getId(), receiveMoney); - long endTime=System.currentTimeMillis(); - float excTime=(float)(endTime-startTime)/1000; - System.out.println("修改"+i+"行,"+"执行时间:"+excTime+"s"); - }else{ - order=EntityFactory.getEntity(Order.class); - order.setCode(relateBill3); - try { - order.setOrderDate(format2.parse(planFromDate)); - order.setPlanFromDate(format2.parse(planFromDate)); - } catch (ParseException e) { - throw new BusinessException("日期格式错误!"); - } - order.setRelateBill3(relateBill3); - order.setConsignor(consignor); - Contact fromContact=new Contact(); - fromContact.setAddress(fromAddress); - order.setFromContact(fromContact); - Contact toContact=new Contact(); - toContact.setAddress(toAddress); - order.setToContact(toContact); - order.setCarPeople(ywy); - order.setSuperviseType(SuperviseType.UNSUPERVISE);//普货 - if(costStatus.equals("未审核")){ - order.setCostStatus(FeeStatus.OPEN); - }else if(costStatus.equals("已审核")){ - order.setCostStatus(FeeStatus.CHECK); - }else if(costStatus.equals("提交审核")){ - order.setCostStatus(FeeStatus.SUBMIT_CHECK); - } - if(status.equals("已调度")){ - order.setStatus(OrderStatus.SCHEDULED); - }else if(status.equals("送货在途")){ - order.setStatus(OrderStatus.SH_ONROAD); - }else if(status.equals("已到货")){ - order.setStatus(OrderStatus.ARRIVED); - }else if(status.equals("已回单")){ - order.setStatus(OrderStatus.SIGNED); - }else if(status.equals("送货运抵")){ - order.setStatus(OrderStatus.SH_ARRIVED); - } - UpdateInfo updateInfo=new UpdateInfo(); - updateInfo.setOperatorName(ywy); - updateInfo.setUpdateTime(new Date()); - order.setUpdateInfo(updateInfo); - order.setContractor(PlatFormHolder.getPlatForm()); - order.setPaymentMethod("月付"); - order.setFee9(sjcb);//实际成本 - order.setVehicleCode(license); - order.setExpectLicense(expectLicense); - order.setDriverName(driverName); - order.setDescription5("陈"); - commonDao.store(order); - orderManager.publishEdiServerAvailableOrder(order); - shuaxinOrderFee(order.getId(), receiveMoney); - long endTime=System.currentTimeMillis(); - float excTime=(float)(endTime-startTime)/1000; - System.out.println("导入"+i+"行,"+"执行时间:"+excTime+"s"); - } - - } - - } catch (BiffException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + long endTime = System.currentTimeMillis(); + float excTime = (float) (endTime - startTime) / 1000; + System.out.println("修改" + i + "行," + "执行时间:" + excTime + "s"); + } else { + order = EntityFactory.getEntity(Order.class); + order.setCode(relateBill3); + try { + order.setOrderDate(format2.parse(planFromDate)); + order.setPlanFromDate(format2.parse(planFromDate)); + } catch (ParseException e) { + throw new BusinessException("日期格式错误!"); + } + order.setRelateBill3(relateBill3); + order.setConsignor(consignor); + Contact fromContact = new Contact(); + fromContact.setAddress(fromAddress); + order.setFromContact(fromContact); + Contact toContact = new Contact(); + toContact.setAddress(toAddress); + order.setToContact(toContact); + order.setCarPeople(ywy); + order.setSuperviseType(SuperviseType.UNSUPERVISE);//普货 + if (costStatus.equals("未审核")) { + order.setCostStatus(FeeStatus.OPEN); + } else if (costStatus.equals("已审核")) { + order.setCostStatus(FeeStatus.CHECK); + } else if (costStatus.equals("提交审核")) { + order.setCostStatus(FeeStatus.SUBMIT_CHECK); + } + if (status.equals("已调度")) { + order.setStatus(OrderStatus.SCHEDULED); + } else if (status.equals("送货在途")) { + order.setStatus(OrderStatus.SH_ONROAD); + } else if (status.equals("已到货")) { + order.setStatus(OrderStatus.ARRIVED); + } else if (status.equals("已回单")) { + order.setStatus(OrderStatus.SIGNED); + } else if (status.equals("送货运抵")) { + order.setStatus(OrderStatus.SH_ARRIVED); + } + UpdateInfo updateInfo = new UpdateInfo(); + updateInfo.setOperatorName(ywy); + updateInfo.setUpdateTime(new Date()); + order.setUpdateInfo(updateInfo); + order.setContractor(PlatFormHolder.getPlatForm()); + order.setPaymentMethod("月付"); + order.setFee9(sjcb);//实际成本 + order.setVehicleCode(license); + order.setExpectLicense(expectLicense); + order.setDriverName(driverName); + order.setDescription5("陈"); + commonDao.store(order); + orderManager.publishEdiServerAvailableOrder(order); + shuaxinOrderFee(order.getId(), receiveMoney); + long endTime = System.currentTimeMillis(); + float excTime = (float) (endTime - startTime) / 1000; + System.out.println("导入" + i + "行," + "执行时间:" + excTime + "s"); + } - } - - @Override - public void payFeeImport(File orderFile) { - long startTime=System.currentTimeMillis(); - Session session = ((HibernateDaoSupport)commonDao).getSessionFactory().openSession(); - DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); - DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); - try { - //调度日期 调度单号 客户名称 车牌号 计费车型 司机 提货地址 送货地址 实际成本 录单员 成本审核 - Workbook workbook = Workbook.getWorkbook(orderFile); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - // 非空字段判断 - String operatorDate=""; - for(int i = 1; i Organizations = commonDao.findByQuery(" from Organization o where o.name=:name and o.bePlatForm=0 and o.beCustomer=1 ", - new String[] { "name"},new Object[] {cusName}); - if(Organizations.size()>0){ - customer=Organizations.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行"+cusName+"客户不存在,请维护!"); - } - - VehicleType vehicleType=null; - List VehicleTypes = commonDao.findByQuery(" from VehicleType v where v.name=:name ", - new String[] { "name"},new Object[] {vtype}); - if(VehicleTypes.size()>0){ - vehicleType=VehicleTypes.get(0); - } - Shipment shipment=null; - List Shipments = commonDao.findByQuery(" from Shipment s where s.code=:code ", - new String[] { "code"},new Object[] {code}); - if(Shipments.size()>0){ - shipment=Shipments.get(0); - shipment.setCustomer(customer); - shipment.setPayfee(payfee); - commonDao.store(shipment); - long endTime=System.currentTimeMillis(); - float excTime=(float)(endTime-startTime)/1000; - System.out.println("修改"+i+"行,"+"执行时间:"+excTime+"s"); - }else{ - shipment=EntityFactory.getEntity(Shipment.class); - shipment.setCode(code); - try { - shipment.setOperatorDate(format2.parse(operatorDate)); - } catch (ParseException e) { - throw new BusinessException("日期格式错误!"); - } - Organization carrier =this.load(Organization.class, 2L); - shipment.setCarrier(carrier); - shipment.setCustomer(customer); - shipment.setLicense(license); - shipment.setVehicleType(vehicleType); - shipment.setDriverName(driverName); - shipment.setPayfee(payfee);//车辆成本 - shipment.setFee7(fee7);//实际成本 - shipment.setTransportType("直送"); - Contact fromContact=new Contact(); - fromContact.setAddress(fromAddress); - shipment.setFromContact(fromContact); - Contact toContact=new Contact(); - toContact.setAddress(toAddress); - shipment.setToContact(toContact); - shipment.setOperator(operator); - if(costStatus.equals("未审核")){ - shipment.setCostStatus(FeeStatus.OPEN); - }else if(costStatus.equals("已审核")){ - shipment.setCostStatus(FeeStatus.CHECK); - }else if(costStatus.equals("提交审核")){ - shipment.setCostStatus(FeeStatus.SUBMIT_CHECK); - } - if(status.equals("录入中")){ - shipment.setStatus(ShipmentStatus.AVAILABLE); - }else if(status.equals("送货在途")){ - shipment.setStatus(ShipmentStatus.SH_ONROAD); - }else if(status.equals("已到货")){ - shipment.setStatus(ShipmentStatus.ARRIVED); - } - shipment.setPlatForm(PlatFormHolder.getPlatForm()); - shipment.setFee1(fee7); - shipment.setFee6(yk); - shipment.setDescription(desc); - shipment.setGps("陈"); - commonDao.store(shipment); - FeeType ysf=commonDao.get(FeeType.class, 1L);//运输费 - Fee ysFee=feeManager.createFee(shipment.getId(), BillObjectType.SHIPMENT, ysf, null, fee7,UserHolder.getUser().getName()); - ysFee.setStatus(shipment.getCostStatus()); - commonDao.store(ysFee); - shaxinShipmentFee(shipment.getId(), fee7, "运输费"); - if(yk>0){ - FeeType ykf=commonDao.get(FeeType.class, 8L);//油卡费 - Fee ykFee=feeManager.createFee(shipment.getId(), BillObjectType.SHIPMENT, ykf, null, yk,UserHolder.getUser().getName()); - ykFee.setStatus(shipment.getCostStatus()); - commonDao.store(ykFee); - shaxinShipmentFee(shipment.getId(), yk, "油卡费"); - } - long endTime=System.currentTimeMillis(); - float excTime=(float)(endTime-startTime)/1000; - System.out.println("导入"+i+"行,"+"执行时间:"+excTime+"s"); - } - } - - - } catch (BiffException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + } - } - - public void shaxinShipmentFee(Long shipmentId,double payMoney,String feeName){ - Shipment shipment=this.load(Shipment.class, shipmentId); - List Fees = commonDao.findByQuery(" from Fee f where f.billObject=:billObject and f.billId=:billId and f.feeName.name='"+feeName+"' ", - new String[] { "billObject","billId"},new Object[] {BillObjectType.SHIPMENT,shipmentId}); - if(Fees.size()>0){ - int i=0; - for(Fee f:Fees){ - if(i==0){ - Fee fee=updateFee(f, payMoney); - commonDao.store(fee); - i++; - }else{ - commonDao.delete(f); - } - } - } - } - - public void shuaxinOrderFee(long orderId,double receiveMoney){ - Order order=this.load(Order.class, orderId); - List Fees = commonDao.findByQuery(" from Fee f where f.billObject=:billObject and f.billId=:billId and f.feeName.name='运输费' ", - new String[] { "billObject","billId"},new Object[] {BillObjectType.ORDER,orderId}); - if(Fees.size()>0){ - int i=0; - for(Fee f:Fees){ - if(i==0){ - Fee fee=updateFee(f, receiveMoney); - commonDao.store(fee); - order.setFee1(receiveMoney);//运输费 - order.setReceivefee(receiveMoney);//营业额 - commonDao.store(order); - i++; - }else{ - commonDao.delete(f); - } - } - }else{ - FeeType feeName=commonDao.get(FeeType.class, 1L);//运输费 - Fee fee=feeManager.createFee(orderId, BillObjectType.ORDER, feeName, null, receiveMoney,UserHolder.getUser().getName()); - String des="运输费:"+receiveMoney; - operationHisManager.storeOperationHis(order.getId(), order.getRelateBill3(), null, des, "自动生成", "费用",null,null,order.getQuantity(),order.getWeight(),order.getVolume(),0, des, "TMS"); - order.setFee1(receiveMoney);//运输费 - order.setReceivefee(receiveMoney);//营业额 - commonDao.store(order); - } - } + } catch (BiffException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - @Override - public void payFeeImport2(File orderFile) { - long startTime=System.currentTimeMillis(); - Session session = ((HibernateDaoSupport)commonDao).getSessionFactory().openSession(); - DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); - DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); - try { - //调度日期 调度单号 客户名称 车牌号 计费车型 司机 提货地址 送货地址 实际成本 录单员 成本审核 - Workbook workbook = Workbook.getWorkbook(orderFile); - Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 - // 非空字段判断 - String operatorDate=""; - for(int i = 1; i Organizations = commonDao.findByQuery(" from Organization o where o.name=:name and o.bePlatForm=0 and o.beCustomer=1 ", - new String[] { "name"},new Object[] {cusName}); - if(Organizations.size()>0){ - customer=Organizations.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行"+cusName+"客户不存在,请维护!"); - } - - VehicleType vehicleType=null; - List VehicleTypes = commonDao.findByQuery(" from VehicleType v where v.name=:name ", - new String[] { "name"},new Object[] {vtype}); - if(VehicleTypes.size()>0){ - vehicleType=VehicleTypes.get(0); - } - Shipment shipment=null; - List Shipments = commonDao.findByQuery(" from Shipment s where DATE_FORMAT(s.operatorDate,'%Y-%m-%d')='"+operatorDate+"' and s.customer.id='"+customer.getId()+"' and s.license='"+license+"' and s.vehicleType.id='"+vehicleType.getId()+"' and s.driverName='"+driverName+"' and s.fromContact.address='"+fromAddress+"' and s.toContact.address='"+toAddress+"' "); - if(Shipments.size()>0){ - shipment=Shipments.get(0); - Order order=null; - List Orders = commonDao.findByQuery(" from Order o where DATE_FORMAT(o.planFromDate,'%Y-%m-%d')='"+operatorDate+"' and o.consignor.id='"+customer.getId()+"' and o.fromContact.address='"+fromAddress+"' and o.toContact.address='"+toAddress+"' "); - if(Orders.size()>0){ - order=Orders.get(0); - order.setVehicleCode(shipment.getLicense()); - order.setExpectLicense(vehicleType.getName()); - order.setDriverName(shipment.getDriverName()); - commonDao.store(order); - System.out.println("修改"+i+"行,"+Orders.size()+"/"+order.getRelateBill3()+"/"+order.getVehicleCode()+"/"+order.getExpectLicense()+"/"+order.getDriverName()); - } - long endTime=System.currentTimeMillis(); - float excTime=(float)(endTime-startTime)/1000; - }else{ - System.out.println("错误"); - } - } - - - } catch (BiffException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + } - } + @Override + public void payFeeImport(File orderFile) { + long startTime = System.currentTimeMillis(); + Session session = ((HibernateDaoSupport) commonDao).getSessionFactory().openSession(); + DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); + DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); + try { + //调度日期 调度单号 客户名称 车牌号 计费车型 司机 提货地址 送货地址 实际成本 录单员 成本审核 + Workbook workbook = Workbook.getWorkbook(orderFile); + Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 + // 非空字段判断 + String operatorDate = ""; + for (int i = 1; i < sheet.getRows(); i++) { + operatorDate = sheet.getCell(0, i).getContents();//调度日期 + try { + operatorDate = format2.format(format2.parse(operatorDate)); + } catch (ParseException e) { + operatorDate = operatorDate.replace("/", "-"); + } + String code = sheet.getCell(1, i).getContents();//调度单号 + String cusName = sheet.getCell(2, i).getContents();//客户名称 + String license = sheet.getCell(3, i).getContents();//车牌号 + String vtype = sheet.getCell(4, i).getContents();//车型 + String driverName = sheet.getCell(5, i).getContents();//司机 + String fromAddress = sheet.getCell(6, i).getContents();//提货地址 + String toAddress = sheet.getCell(7, i).getContents();//送货地址 + double fee7 = sheet.getCell(8, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(8, i).getContents());//实际 + double yk = sheet.getCell(9, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(9, i).getContents());//油卡 + double payfee = sheet.getCell(10, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(10, i).getContents());//车辆 + String operator = sheet.getCell(11, i).getContents();//录单员 + String costStatus = sheet.getCell(12, i).getContents();//成本状态 + String status = sheet.getCell(13, i).getContents();//订单状态 + String desc = sheet.getCell(14, i).getContents();//描述 + Organization customer = null; + List Organizations = commonDao.findByQuery(" from Organization o where o.name=:name and o.bePlatForm=0 and o.beCustomer=1 ", + new String[]{"name"}, new Object[]{cusName}); + if (Organizations.size() > 0) { + customer = Organizations.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行" + cusName + "客户不存在,请维护!"); + } + + VehicleType vehicleType = null; + List VehicleTypes = commonDao.findByQuery(" from VehicleType v where v.name=:name ", + new String[]{"name"}, new Object[]{vtype}); + if (VehicleTypes.size() > 0) { + vehicleType = VehicleTypes.get(0); + } + Shipment shipment = null; + List Shipments = commonDao.findByQuery(" from Shipment s where s.code=:code ", + new String[]{"code"}, new Object[]{code}); + if (Shipments.size() > 0) { + shipment = Shipments.get(0); + shipment.setCustomer(customer); + shipment.setPayfee(payfee); + commonDao.store(shipment); + long endTime = System.currentTimeMillis(); + float excTime = (float) (endTime - startTime) / 1000; + System.out.println("修改" + i + "行," + "执行时间:" + excTime + "s"); + } else { + shipment = EntityFactory.getEntity(Shipment.class); + shipment.setCode(code); + try { + shipment.setOperatorDate(format2.parse(operatorDate)); + } catch (ParseException e) { + throw new BusinessException("日期格式错误!"); + } + Organization carrier = this.load(Organization.class, 2L); + shipment.setCarrier(carrier); + shipment.setCustomer(customer); + shipment.setLicense(license); + shipment.setVehicleType(vehicleType); + shipment.setDriverName(driverName); + shipment.setPayfee(payfee);//车辆成本 + shipment.setFee7(fee7);//实际成本 + shipment.setTransportType("直送"); + Contact fromContact = new Contact(); + fromContact.setAddress(fromAddress); + shipment.setFromContact(fromContact); + Contact toContact = new Contact(); + toContact.setAddress(toAddress); + shipment.setToContact(toContact); + shipment.setOperator(operator); + if (costStatus.equals("未审核")) { + shipment.setCostStatus(FeeStatus.OPEN); + } else if (costStatus.equals("已审核")) { + shipment.setCostStatus(FeeStatus.CHECK); + } else if (costStatus.equals("提交审核")) { + shipment.setCostStatus(FeeStatus.SUBMIT_CHECK); + } + if (status.equals("录入中")) { + shipment.setStatus(ShipmentStatus.AVAILABLE); + } else if (status.equals("送货在途")) { + shipment.setStatus(ShipmentStatus.SH_ONROAD); + } else if (status.equals("已到货")) { + shipment.setStatus(ShipmentStatus.ARRIVED); + } + shipment.setPlatForm(PlatFormHolder.getPlatForm()); + shipment.setFee1(fee7); + shipment.setFee6(yk); + shipment.setDescription(desc); + shipment.setGps("陈"); + commonDao.store(shipment); + FeeType ysf = commonDao.get(FeeType.class, 1L);//运输费 + Fee ysFee = feeManager.createFee(shipment.getId(), BillObjectType.SHIPMENT, ysf, null, fee7, UserHolder.getUser().getName()); + ysFee.setStatus(shipment.getCostStatus()); + commonDao.store(ysFee); + shaxinShipmentFee(shipment.getId(), fee7, "运输费"); + if (yk > 0) { + FeeType ykf = commonDao.get(FeeType.class, 8L);//油卡费 + Fee ykFee = feeManager.createFee(shipment.getId(), BillObjectType.SHIPMENT, ykf, null, yk, UserHolder.getUser().getName()); + ykFee.setStatus(shipment.getCostStatus()); + commonDao.store(ykFee); + shaxinShipmentFee(shipment.getId(), yk, "油卡费"); + } + long endTime = System.currentTimeMillis(); + float excTime = (float) (endTime - startTime) / 1000; + System.out.println("导入" + i + "行," + "执行时间:" + excTime + "s"); + } + } + + + } catch (BiffException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public void shaxinShipmentFee(Long shipmentId, double payMoney, String feeName) { + Shipment shipment = this.load(Shipment.class, shipmentId); + List Fees = commonDao.findByQuery(" from Fee f where f.billObject=:billObject and f.billId=:billId and f.feeName.name='" + feeName + "' ", + new String[]{"billObject", "billId"}, new Object[]{BillObjectType.SHIPMENT, shipmentId}); + if (Fees.size() > 0) { + int i = 0; + for (Fee f : Fees) { + if (i == 0) { + Fee fee = updateFee(f, payMoney); + commonDao.store(fee); + i++; + } else { + commonDao.delete(f); + } + } + } + } + + public void shuaxinOrderFee(long orderId, double receiveMoney) { + Order order = this.load(Order.class, orderId); + List Fees = commonDao.findByQuery(" from Fee f where f.billObject=:billObject and f.billId=:billId and f.feeName.name='运输费' ", + new String[]{"billObject", "billId"}, new Object[]{BillObjectType.ORDER, orderId}); + if (Fees.size() > 0) { + int i = 0; + for (Fee f : Fees) { + if (i == 0) { + Fee fee = updateFee(f, receiveMoney); + commonDao.store(fee); + order.setFee1(receiveMoney);//运输费 + order.setReceivefee(receiveMoney);//营业额 + commonDao.store(order); + i++; + } else { + commonDao.delete(f); + } + } + } else { + FeeType feeName = commonDao.get(FeeType.class, 1L);//运输费 + Fee fee = feeManager.createFee(orderId, BillObjectType.ORDER, feeName, null, receiveMoney, UserHolder.getUser().getName()); + String des = "运输费:" + receiveMoney; + operationHisManager.storeOperationHis(order.getId(), order.getRelateBill3(), null, des, "自动生成", "费用", null, null, order.getQuantity(), order.getWeight(), order.getVolume(), 0, des, "TMS"); + order.setFee1(receiveMoney);//运输费 + order.setReceivefee(receiveMoney);//营业额 + commonDao.store(order); + } + } + + @Override + public void payFeeImport2(File orderFile) { + long startTime = System.currentTimeMillis(); + Session session = ((HibernateDaoSupport) commonDao).getSessionFactory().openSession(); + DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd"); + DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); + try { + //调度日期 调度单号 客户名称 车牌号 计费车型 司机 提货地址 送货地址 实际成本 录单员 成本审核 + Workbook workbook = Workbook.getWorkbook(orderFile); + Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 + // 非空字段判断 + String operatorDate = ""; + for (int i = 1; i < sheet.getRows(); i++) { + operatorDate = sheet.getCell(0, i).getContents();//调度日期 + try { + operatorDate = format2.format(format2.parse(operatorDate)); + } catch (ParseException e) { + operatorDate = operatorDate.replace("/", "-"); + } + String cusName = sheet.getCell(1, i).getContents();//客户名称 + String license = sheet.getCell(2, i).getContents();//车牌号 + String vtype = sheet.getCell(3, i).getContents();//车型 + String driverName = sheet.getCell(4, i).getContents();//司机 + String fromAddress = sheet.getCell(5, i).getContents();//提货地址 + String toAddress = sheet.getCell(6, i).getContents();//送货地址 + double fee7 = sheet.getCell(7, i).getContents().equals("") ? 0 : Double.parseDouble(sheet.getCell(7, i).getContents());//实际 + + Organization customer = null; + List Organizations = commonDao.findByQuery(" from Organization o where o.name=:name and o.bePlatForm=0 and o.beCustomer=1 ", + new String[]{"name"}, new Object[]{cusName}); + if (Organizations.size() > 0) { + customer = Organizations.get(0); + } else { + throw new BusinessException("第" + (i + 1) + "行" + cusName + "客户不存在,请维护!"); + } + + VehicleType vehicleType = null; + List VehicleTypes = commonDao.findByQuery(" from VehicleType v where v.name=:name ", + new String[]{"name"}, new Object[]{vtype}); + if (VehicleTypes.size() > 0) { + vehicleType = VehicleTypes.get(0); + } + Shipment shipment = null; + List Shipments = commonDao.findByQuery(" from Shipment s where DATE_FORMAT(s.operatorDate,'%Y-%m-%d')='" + operatorDate + "' and s.customer.id='" + customer.getId() + "' and s.license='" + license + "' and s.vehicleType.id='" + vehicleType.getId() + "' and s.driverName='" + driverName + "' and s.fromContact.address='" + fromAddress + "' and s.toContact.address='" + toAddress + "' "); + if (Shipments.size() > 0) { + shipment = Shipments.get(0); + Order order = null; + List Orders = commonDao.findByQuery(" from Order o where DATE_FORMAT(o.planFromDate,'%Y-%m-%d')='" + operatorDate + "' and o.consignor.id='" + customer.getId() + "' and o.fromContact.address='" + fromAddress + "' and o.toContact.address='" + toAddress + "' "); + if (Orders.size() > 0) { + order = Orders.get(0); + order.setVehicleCode(shipment.getLicense()); + order.setExpectLicense(vehicleType.getName()); + order.setDriverName(shipment.getDriverName()); + commonDao.store(order); + System.out.println("修改" + i + "行," + Orders.size() + "/" + order.getRelateBill3() + "/" + order.getVehicleCode() + "/" + order.getExpectLicense() + "/" + order.getDriverName()); + } + long endTime = System.currentTimeMillis(); + float excTime = (float) (endTime - startTime) / 1000; + } else { + System.out.println("错误"); + } + } + + + } catch (BiffException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } }