excel导入异常,模板不对等问题的判断

web_backend_develope
chenlw 8 years ago
parent c821cffc4f
commit ca6507aaa0

@ -133,7 +133,7 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
PreDataInfo pre = new PreDataInfo(); PreDataInfo pre = new PreDataInfo();
//excel数据 --> java bean //excel数据 --> java bean
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<PreDataInfo> subPreData = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, "["+f.getName()+"] ", rowErr,pre, "id", "dataId", "workRange","sysCode","updateTime","userTablespaceStatus", "checkoutIndicateStatus", "checkoutPayStatus", "userTablespacePath", "checkoutIndicatePath", "checkoutPayPath", "sqlList", "dataVersion", "collectingTime", "collUpdate"); List<PreDataInfo> subPreData = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, "["+f.getName()+"] ", rowErr,pre, "id", "dataId", "workRange","sysCode","updateTime","userTablespaceStatus", "checkoutIndicateStatus", "checkoutPayStatus", "userTablespacePath", "checkoutIndicatePath", "checkoutPayPath", "sqlList", "dataVersion", "collectingTime", "collUpdate");
if (null != subPreData && subPreData.size() > 0) { if (null != subPreData && subPreData.size() > 0) {
// 是否是 同一个县区的 系统--是则 加入 // 是否是 同一个县区的 系统--是则 加入
boolean isSameArea = true; boolean isSameArea = true;
@ -160,25 +160,48 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
// } // }
// } // }
} }
if (rowErr.size() > 0) {
errmap.put("err",rowErr);
}
if (errFile.size() > 0) {
if (errmap.containsKey("err")) {
errFile.addAll( (Collection<? extends HashMap<String, Object>>) errmap.get("err"));
}
errmap.put("err",errFile);
}
// if (errArea.size() > 0) {
// errmap.put("areaUnImport", errArea);
// }
if (errmap.containsKey("err")) {
return errmap;
}
//根据 操作 类别 分类(修改, 新增行政区划,新增信息系统) //根据 操作 类别 分类(修改, 新增行政区划,新增信息系统)
if (all.size() > 0) { if (all.size() > 0) {
for (PreDataInfo preDataInfo : all) { for (PreDataInfo preDataInfo : all) {
String sysName = preDataInfo.getSysName();
boolean iserr = false;
if (null == sysName ) {
iserr = true;
}
if (sysName.contains("\\")) {
iserr = true;
}
if (sysName.contains("/")) {
iserr = true;
}
if (sysName.contains("")) {
iserr = true;
}
if (sysName.contains(":")) {
iserr = true;
}
if (sysName.contains("*")) {
iserr = true;
}
if (sysName.contains("<")) {
iserr = true;
}
if (sysName.contains(">")) {
iserr = true;
}
if (sysName.contains("|")) {
iserr = true;
}
if (sysName.contains("\"")) {
iserr = true;
}
if (iserr) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("value", "系统名称不能使用?*\":<>|/\\");
map.put("name", preDataInfo.getCityName()+"-"+preDataInfo.getDistrictName()+"-"+preDataInfo.getSysName());
rowErr.add(map);
}
String updateType = preDataInfo.getIsupdate(); String updateType = preDataInfo.getIsupdate();
switch (updateType) switch (updateType)
{ {
@ -199,15 +222,26 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
} }
} }
} }
// 查 地区 是否没有-(没有则添加新地区):
if (list4AddArea.size() > 0) {
this.addArea(list4AddArea, rowErr);
}
if (errFile.size() > 0) {
rowErr.addAll(errFile);
// errmap.put("err",errFile);
}
if (rowErr.size() > 0) {
errmap.put("err", rowErr);
}
if (errmap.containsKey("err")) {
return errmap;
}
// 记录 操作了 多少条记录 // 记录 操作了 多少条记录
errmap.put("system", list4AddSystem.size()); errmap.put("system", list4AddSystem.size());
errmap.put("area", list4AddArea.size()); errmap.put("area", list4AddArea.size());
errmap.put("update", list4Update.size()); errmap.put("update", list4Update.size());
// 查 地区 是否没有-(没有则添加新地区):
if (list4AddArea.size() > 0) {
this.addArea(list4AddArea);
}
//在 pre_data_info表中 新增 操作为(新增行政区划)的系统 -- start //在 pre_data_info表中 新增 操作为(新增行政区划)的系统 -- start
List<PreDataInfo> allAreaInsert = new ArrayList<PreDataInfo>(); List<PreDataInfo> allAreaInsert = new ArrayList<PreDataInfo>();
List<String> sysNamesArea = new ArrayList<String>(); List<String> sysNamesArea = new ArrayList<String>();
@ -225,6 +259,7 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
} }
// 查系统 是否没有-(没有则在 pre_data_info添加新系统 // 查系统 是否没有-(没有则在 pre_data_info添加新系统
if (list4AddSystem.size() > 0) { if (list4AddSystem.size() > 0) {
//新增系统
this.AddSystem(list4AddSystem); this.AddSystem(list4AddSystem);
List<String> sysNames = new ArrayList<String>(); List<String> sysNames = new ArrayList<String>();
for (PreDataInfo preDataInfo : list4AddSystem) { for (PreDataInfo preDataInfo : list4AddSystem) {
@ -241,16 +276,27 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
for ( PreDataInfo systemEntity : list4AddSystem) { for ( PreDataInfo systemEntity : list4AddSystem) {
PreDataInfo systemFull = new PreDataInfo(); PreDataInfo systemFull = new PreDataInfo();
BeanCopy.copyBean(systemEntity, systemFull); BeanCopy.copyBean(systemEntity, systemFull);
systemFull.setSysCode(syscodeMap.get(systemFull.getSysName())); if (syscodeMap.containsKey(systemFull.getSysName())) {
systemFull.setUpdateTime(DateForm.date2StringBysecond(new Date())); systemFull.setSysCode(syscodeMap.get(systemFull.getSysName()));
all2Insert.add(systemFull); systemFull.setUpdateTime(DateForm.date2StringBysecond(new Date()));
all2Insert.add(systemFull);
}
else {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("value", "无此系统,请新增");
map.put("name", systemEntity.getCityName()+"-"+systemEntity.getDistrictName()+"-"+systemEntity.getSysName());
rowErr.add(map);
}
} }
} }
//去掉 已经导入的系统。。(例如 excel反复导入 //去掉 已经导入的系统。。(例如 excel反复导入
//在 pre_data_info表中 新增 操作为(新增信息系统)的系统 //在 pre_data_info表中 新增 操作为(新增信息系统)的系统
all2Insert = this.removeRepeat(all2Insert); all2Insert = this.removeRepeat(all2Insert);
if (all2Insert.size() > 0) { if (all2Insert.size() > 0) {
insertBatch(all2Insert); insertBatch(all2Insert,rowErr);
if (rowErr.size() > 0) {
errmap.put("err",rowErr);
}
} }
//在 pre_data_info表中 新增 操作为(新增行政区划)的系统 -- end //在 pre_data_info表中 新增 操作为(新增行政区划)的系统 -- end
@ -273,10 +319,17 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
for (PreDataInfo preUpdate : list4Update) { for (PreDataInfo preUpdate : list4Update) {
PreDataInfo UpdateFull = new PreDataInfo(); PreDataInfo UpdateFull = new PreDataInfo();
BeanCopy.copyBean(preUpdate, UpdateFull); BeanCopy.copyBean(preUpdate, UpdateFull);
if (syscodeMap.containsKey(UpdateFull.getSysName())) {
UpdateFull.setSysCode(syscodeMap.get(UpdateFull.getSysName())); UpdateFull.setSysCode(syscodeMap.get(UpdateFull.getSysName()));
UpdateFull.setUpdateTime(DateForm.date2StringBysecond(new Date())); UpdateFull.setUpdateTime(DateForm.date2StringBysecond(new Date()));
allUpdate.add(UpdateFull); allUpdate.add(UpdateFull);
}
else {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("value", "无此系统,请新增");
map.put("name", preUpdate.getCityName()+"-"+preUpdate.getDistrictName()+"-"+preUpdate.getSysName());
rowErr.add(map);
}
} }
// 更新 // 更新
for (PreDataInfo preEntity : allUpdate) { for (PreDataInfo preEntity : allUpdate) {
@ -284,10 +337,18 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
preDataInfoDao.update(preEntity); preDataInfoDao.update(preEntity);
} }
catch(Exception e){ catch(Exception e){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("value", "请检查是否有填写错误,比如:错别字、超出范围等");
map.put("name", preEntity.getAreaCode()+"-"+preEntity.getCityName()+"-"+preEntity.getDistrictName()+"-"+preEntity.getSysName());
log.error(preEntity.getAreaCode()+"-"+preEntity.getCityName()+"-"+preEntity.getDistrictName()+"-"+preEntity.getSysName());
rowErr.add(map);
log.error(e); log.error(e);
} }
} }
} }
if (rowErr.size() > 0 && !errmap.keySet().contains("err")) {
errmap.put("err",rowErr);
}
return errmap; return errmap;
} }
@ -364,7 +425,7 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
* @return * @return
* @throws Exception * @throws Exception
*/ */
private int addArea(List<PreDataInfo> list4AddArea)throws Exception { private int addArea(List<PreDataInfo> list4AddArea, List<HashMap<String, Object>> err)throws Exception {
int insertNum = 0; int insertNum = 0;
List<String> areacodeList = new ArrayList<String>(); List<String> areacodeList = new ArrayList<String>();
Map<String,RegionalismEntity> areaMap = new HashMap<String, RegionalismEntity>(); Map<String,RegionalismEntity> areaMap = new HashMap<String, RegionalismEntity>();
@ -379,8 +440,16 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
} }
List<RegionalismEntity> existEntity = regionalismCodeDao.findExistRegionalism(areacodeList); List<RegionalismEntity> existEntity = regionalismCodeDao.findExistRegionalism(areacodeList);
for (RegionalismEntity regionalismEntity : existEntity) { for (RegionalismEntity regionalismEntity : existEntity) {
insertNum = -1;
//去掉重复的地区 //去掉重复的地区
areaMap.remove(regionalismEntity.getCode()); areaMap.remove(regionalismEntity.getCode());
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("value", "新增的地区已存在");
map.put("name", regionalismEntity.getCode()+"-"+regionalismEntity.getCityName()+"-"+regionalismEntity.getDistrictName());
err.add(map);
}
if(-1 == insertNum){
return insertNum;
} }
//新增 地区 //新增 地区
if (areaMap.size() > 0) { if (areaMap.size() > 0) {
@ -521,8 +590,9 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
/** --(allAreaInsert ) allAreaInsert 100 11 10 /** --(allAreaInsert ) allAreaInsert 100 11 10
* @param allAreaInsert * @param allAreaInsert
* @param rowErr
*/ */
private void insertBatch(List<PreDataInfo> allAreaInsert) { private void insertBatch(List<PreDataInfo> allAreaInsert, List<HashMap<String, Object>> rowErr) {
if (allAreaInsert.size() > 0) { if (allAreaInsert.size() > 0) {
int listSize = allAreaInsert.size(); int listSize = allAreaInsert.size();
int loopSize = listSize/Configs.NUM_ONE_IMPORT_EXCEL; int loopSize = listSize/Configs.NUM_ONE_IMPORT_EXCEL;
@ -540,7 +610,14 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
try { try {
preDataInfoDao.insertBatch(arrayList); preDataInfoDao.insertBatch(arrayList);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getStackTrace()); for (PreDataInfo preDataInfo : arrayList) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("value", "请检查是否有填写错误,比如:错别字、超出范围等");
map.put("name", preDataInfo.getAreaCode()+"-"+preDataInfo.getCityName()+"-"+preDataInfo.getDistrictName()+"-"+preDataInfo.getSysName());
log.error(preDataInfo.getAreaCode()+"-"+preDataInfo.getCityName()+"-"+preDataInfo.getDistrictName()+"-"+preDataInfo.getSysName());
rowErr.add(map);
}
log.error(e);
} }
} }
} }

Loading…
Cancel
Save