diff --git a/src/main/java/com/dev/stms/server/service/importData/pojo/DefaultImportBasicDataManager.java b/src/main/java/com/dev/stms/server/service/importData/pojo/DefaultImportBasicDataManager.java index df3ce6c..6c1492d 100644 --- a/src/main/java/com/dev/stms/server/service/importData/pojo/DefaultImportBasicDataManager.java +++ b/src/main/java/com/dev/stms/server/service/importData/pojo/DefaultImportBasicDataManager.java @@ -8,6 +8,8 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang.StringUtils; + import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; @@ -1867,86 +1869,70 @@ public class DefaultImportBasicDataManager extends DefaultBaseManager implements Workbook workbook = Workbook.getWorkbook(file); Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容 for (int i = 1; i froms=this.commonDao.findByQuery("from City c where c.name like '"+fromName+"%' and disabled=0"); - if(froms.size()>0){ - if(froms.size()>1){ - throw new BusinessException("第"+(i+1)+"行,"+fromName+"城市区域重复,请和城市绑定!"); - } - fromCity=froms.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,"+fromName+"没有出发地,请在城市区域里维护!"); - } - } - City toCity=null; - if(toName!=null && !"".equals(toName)){ - List tos=this.commonDao.findByQuery("from City c where c.name like '"+toName+"%' and disabled=0"); - if(tos.size()>0){ - if(tos.size()>1){ - throw new BusinessException("第"+(i+1)+"行,"+toName+"城市区域重复,请和城市绑定!"); - } - toCity=tos.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,"+toName+"没有目的地,请在城市区域里维护!"); - } - if(!CheckUtils.isTrimEmpty(toQY)){ - tos=this.commonDao.findByQuery("from City c where c.name like '"+toQY+"%' and disabled=0 and c.city.id ="+toCity.getId()); - if(tos.size()>0){ - if(tos.size()>1){ - throw new BusinessException("第"+(i+1)+"行,"+toQY+"城市区域重复,请和城市绑定!"); - } - toCity=tos.get(0); - }else{ - throw new BusinessException("第"+(i+1)+"行,"+toQY+"没有目的地,请在城市区域里维护!"); - } - name=name+toQY; - }else{ - name=name+toName; - } - - } - RouteFee routeFee=null; - List rfs=this.commonDao.findByQuery("from RouteFee rf where rf.fromCity.id =:fromCityId and rf.toCity.id =:toCityId", - new String[]{"fromCityId","toCityId"},new Object[]{fromCity.getId(),toCity.getId()}); - if(rfs.size()>0){ - routeFee=rfs.get(0); + + //客户 + Organization customer=null; + List customers=commonDao.findByQuery("from Organization o where o.name ='"+customerName+"' and o.disabled=0 and o.bePlatForm=0 and o.beCustomer=1"); + if(customers.isEmpty()){ + throw new BusinessException("第"+(i+1)+"行,"+customerName+"系统不存在或已失效,请在客户管理中维护"); }else{ - routeFee=(RouteFee)EntityFactory.getEntity(RouteFee.class); + customer=customers.get(0); } + + //出发地 + City fromCity=null; + List fromCitys=commonDao.findByQuery("from City c where c.name like '"+fromName+"%' and disabled=0"); + if(fromCitys.isEmpty()){ + throw new BusinessException("第"+(i+1)+"行,"+fromName+"系统不存在或已失效,请在城市区域中维护"); + }else{ + fromCity=fromCitys.get(0); + } + + //目的地 + City toCity=null; + List toCitys=commonDao.findByQuery("from City c where c.name like '"+toName+"%' and disabled=0"); + if(toCitys.isEmpty()){ + throw new BusinessException("第"+(i+1)+"行,"+toName+"系统不存在或已失效,请在城市区域中维护"); + }else{ + toCity=toCitys.get(0); + } + + //线路 + RouteFee routeFee=null; + List routeFees=this.commonDao.findByQuery("from RouteFee rf where rf.customer.id=:customerId and rf.fromCity.id =:fromCityId and rf.toCity.id =:toCityId", + new String[]{"customerId","fromCityId","toCityId"},new Object[]{customer.getId(),fromCity.getId(),toCity.getId()}); + if(routeFees.isEmpty()){ + routeFee=(RouteFee)EntityFactory.getEntity(RouteFee.class); + }else{ + routeFee=routeFees.get(0); + } + String code=fromCity.getName()+"-"+toCity.getName(); + routeFee.setCode(code); + routeFee.setName(code); routeFee.setFromCity(fromCity); routeFee.setToCity(toCity); - if(fromCity.getCity()!=null){ - routeFee.setCode(fromCity.getCity().getName()+fromCity.getName()); - }else{ - routeFee.setCode(fromCity.getName()); - } - if(toCity.getCity()!=null){ - routeFee.setCode(routeFee.getCode()+"-"+toCity.getCity().getName()+toCity.getName()); - }else{ - routeFee.setCode(routeFee.getCode()+"-"+toCity.getName()); - } - routeFee.setName(name); - System.out.println(name); - routeFee.setMiles((int)ZHdouble("0")); + routeFee.setCustomer(customer); + routeFee.setMiles(0); routeFee.setUpdateInfo(new UpdateInfo(UserHolder.getUser())); commonDao.store(routeFee); System.out.println(i); } - }catch(Exception ex){ + }catch(Exception ex){ ex.printStackTrace(); - } + } } public double ZHdouble(String str){