线路导入
parent
ea8083410c
commit
75e3960d2f
|
|
@ -8,6 +8,8 @@ import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import jxl.Sheet;
|
import jxl.Sheet;
|
||||||
import jxl.Workbook;
|
import jxl.Workbook;
|
||||||
import jxl.read.biff.BiffException;
|
import jxl.read.biff.BiffException;
|
||||||
|
|
@ -1867,86 +1869,70 @@ public class DefaultImportBasicDataManager extends DefaultBaseManager implements
|
||||||
Workbook workbook = Workbook.getWorkbook(file);
|
Workbook workbook = Workbook.getWorkbook(file);
|
||||||
Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容
|
Sheet sheet = workbook.getSheet(0);//得到excel第一页的内容
|
||||||
for (int i = 1; i <sheet.getRows(); i++) {
|
for (int i = 1; i <sheet.getRows(); i++) {
|
||||||
String fromName=sheet.getCell(0,i).getContents();
|
String customerName=sheet.getCell(0,i).getContents();
|
||||||
String toName=sheet.getCell(1,i).getContents();
|
String fromName=sheet.getCell(1,i).getContents();
|
||||||
String toQY=sheet.getCell(2,i).getContents();
|
String toName=sheet.getCell(2,i).getContents();
|
||||||
//String miles=sheet.getCell(3,i).getContents().equals("")?"0":sheet.getCell(3,i).getContents();
|
|
||||||
if(null==fromName || "".endsWith(fromName)){
|
if(StringUtils.isEmpty(customerName)){
|
||||||
|
throw new BusinessException("第"+(i+1)+"行,"+"客户不能为空!");
|
||||||
|
}
|
||||||
|
if(StringUtils.isEmpty(fromName)){
|
||||||
throw new BusinessException("第"+(i+1)+"行,"+"出发地不能为空!");
|
throw new BusinessException("第"+(i+1)+"行,"+"出发地不能为空!");
|
||||||
}
|
}
|
||||||
if(null==toName || "".endsWith(toName)){
|
if(StringUtils.isEmpty(toName)){
|
||||||
throw new BusinessException("第"+(i+1)+"行,"+"目的地不能为空!");
|
throw new BusinessException("第"+(i+1)+"行,"+"目的地不能为空!");
|
||||||
}
|
}
|
||||||
City fromCity=null;
|
|
||||||
String name=fromName+"-";
|
|
||||||
if(fromName!=null && !"".equals(fromName)){
|
|
||||||
List<City> 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<City> 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;
|
Organization customer=null;
|
||||||
List<RouteFee> rfs=this.commonDao.findByQuery("from RouteFee rf where rf.fromCity.id =:fromCityId and rf.toCity.id =:toCityId",
|
List<Organization> customers=commonDao.findByQuery("from Organization o where o.name ='"+customerName+"' and o.disabled=0 and o.bePlatForm=0 and o.beCustomer=1");
|
||||||
new String[]{"fromCityId","toCityId"},new Object[]{fromCity.getId(),toCity.getId()});
|
if(customers.isEmpty()){
|
||||||
if(rfs.size()>0){
|
throw new BusinessException("第"+(i+1)+"行,"+customerName+"系统不存在或已失效,请在客户管理中维护");
|
||||||
routeFee=rfs.get(0);
|
|
||||||
}else{
|
}else{
|
||||||
routeFee=(RouteFee)EntityFactory.getEntity(RouteFee.class);
|
customer=customers.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//出发地
|
||||||
|
City fromCity=null;
|
||||||
|
List<City> 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<City> 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<RouteFee> 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.setFromCity(fromCity);
|
||||||
routeFee.setToCity(toCity);
|
routeFee.setToCity(toCity);
|
||||||
if(fromCity.getCity()!=null){
|
routeFee.setCustomer(customer);
|
||||||
routeFee.setCode(fromCity.getCity().getName()+fromCity.getName());
|
routeFee.setMiles(0);
|
||||||
}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.setUpdateInfo(new UpdateInfo(UserHolder.getUser()));
|
routeFee.setUpdateInfo(new UpdateInfo(UserHolder.getUser()));
|
||||||
commonDao.store(routeFee);
|
commonDao.store(routeFee);
|
||||||
System.out.println(i);
|
System.out.println(i);
|
||||||
}
|
}
|
||||||
}catch(Exception ex){
|
}catch(Exception ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public double ZHdouble(String str){
|
public double ZHdouble(String str){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue