修改xml上传解析的异常处理

parent 38b46dd6
...@@ -96,33 +96,37 @@ public class ReadXmlApi { ...@@ -96,33 +96,37 @@ public class ReadXmlApi {
String str = YXStringUtils.inputStream2String(in, "utf-8"); String str = YXStringUtils.inputStream2String(in, "utf-8");
in.close(); in.close();
IDCardFactory idCardFactory = new IDCardFactory(); IDCardFactory idCardFactory = new IDCardFactory();
idcardsFactory(idCardFactory.extractIDCard(str, date)); Boolean aBoolean = idcardsFactory(idCardFactory.extractIDCard(str, date));
if (!aBoolean){
errList.add("上传文件名:" + filename+",文件上传失败");
continue;
}
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); e.printStackTrace();
logger.error("上传文件名" + filename ); logger.error("上传文件名" + filename );
logger.error("UnsupportedEncodingException 上传文件时发现文件编码错误", e); logger.error("UnsupportedEncodingException 上传文件时发现文件编码错误", e);
yxresp.outPutError("UnsupportedEncodingException", "上传文件时发现文件编码错误:" + e.getMessage()); // yxresp.outPutError("UnsupportedEncodingException", "上传文件时发现文件编码错误:" + e.getMessage());
errList.add("上传文件名:" + filename+",上传文件时发现文件编码错误"); errList.add("上传文件名:" + filename+",上传文件时发现文件编码错误");
continue; continue;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
logger.error("上传文件名" + filename ); logger.error("上传文件名" + filename );
logger.error("IOException 上传文件时发生IO错误", e); logger.error("IOException 上传文件时发生IO错误", e);
yxresp.outPutError("IOException", "上传文件时发生IO错误:" + e.getMessage()); // yxresp.outPutError("IOException", "上传文件时发生IO错误:" + e.getMessage());
errList.add("上传文件名:" + filename+",上传文件时发生IO错误"); errList.add("上传文件名:" + filename+",上传文件时发生IO错误");
continue; continue;
} catch (DocumentException e) { } catch (DocumentException e) {
e.printStackTrace(); e.printStackTrace();
logger.error("上传文件名" + filename ); logger.error("上传文件名" + filename );
logger.error("DocumentException 上传文件时发生错误,非法XML文件", e); logger.error("DocumentException 上传文件时发生错误,非法XML文件", e);
yxresp.outPutError("DocumentException", "上传文件时发生IO错误:" + e.getMessage()); // yxresp.outPutError("DocumentException", "上传文件时发生IO错误:" + e.getMessage());
errList.add("上传文件名:" + filename+",上传文件时发生错误,非法XML文件"); errList.add("上传文件名:" + filename+",上传文件时发生错误,非法XML文件");
continue; continue;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
logger.error("上传文件名" + filename ); logger.error("上传文件名" + filename );
logger.error("Exception 上传文件时发生错误", e); logger.error("Exception 上传文件时发生错误", e);
yxresp.outPutError("Exception", "上传文件时发生错误,非法XML文件:" + filename); // yxresp.outPutError("Exception", "上传文件时发生错误,非法XML文件:" + filename);
errList.add("上传文件名:" + filename+",上传文件时发生错误"); errList.add("上传文件名:" + filename+",上传文件时发生错误");
continue; continue;
} }
...@@ -133,7 +137,7 @@ public class ReadXmlApi { ...@@ -133,7 +137,7 @@ public class ReadXmlApi {
e.printStackTrace(); e.printStackTrace();
logger.error("上传文件名" + filename ); logger.error("上传文件名" + filename );
logger.error("FileUploadException 文件上传发生异常", e); logger.error("FileUploadException 文件上传发生异常", e);
yxresp.outPutError("FileUploadException", "文件上传发生异常:" + e.getMessage()); // yxresp.outPutError("FileUploadException", "文件上传发生异常:" + e.getMessage());
errList.add("上传文件名:" + filename+",上传文件时发生错误"); errList.add("上传文件名:" + filename+",上传文件时发生错误");
} }
if (errList.size() == 0){ if (errList.size() == 0){
...@@ -148,8 +152,7 @@ public class ReadXmlApi { ...@@ -148,8 +152,7 @@ public class ReadXmlApi {
} }
private Boolean idcardsFactory(Map<String, Object> map1) { private Boolean idcardsFactory(Map<String, Object> map1) {
importXmlService.importPersonXml((List<PreproPersonDto>) map1.get("preproPerson"), (FilesEntity) map1.get("file")); return importXmlService.importPersonXml((List<PreproPersonDto>) map1.get("preproPerson"), (FilesEntity) map1.get("file"));
return true;
} }
/** /**
......
...@@ -13,6 +13,7 @@ import org.dom4j.Element; ...@@ -13,6 +13,7 @@ import org.dom4j.Element;
import org.dom4j.io.OutputFormat; import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter; import org.dom4j.io.XMLWriter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -43,7 +44,11 @@ public class ImportXmlServiceImpl implements ImportXmlService { ...@@ -43,7 +44,11 @@ public class ImportXmlServiceImpl implements ImportXmlService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean importPersonXml( List<PreproPersonDto> preproPersonDtos, FilesEntity filesEntity) { public boolean importPersonXml( List<PreproPersonDto> preproPersonDtos, FilesEntity filesEntity) {
long l = filesMapper.insertFiles(filesEntity); try {
long l = filesMapper.insertFiles(filesEntity);
}catch (UncategorizedSQLException e){
return false;
}
SimpleDateFormat fo = new SimpleDateFormat("yyyyMMddhhmm"); SimpleDateFormat fo = new SimpleDateFormat("yyyyMMddhhmm");
String uploadDate = fo.format(new Date()); String uploadDate = fo.format(new Date());
for (PreproPersonDto preproPersonDto : preproPersonDtos) { for (PreproPersonDto preproPersonDto : preproPersonDtos) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment