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

parent 38b46dd6
......@@ -96,33 +96,37 @@ public class ReadXmlApi {
String str = YXStringUtils.inputStream2String(in, "utf-8");
in.close();
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) {
e.printStackTrace();
logger.error("上传文件名" + filename );
logger.error("UnsupportedEncodingException 上传文件时发现文件编码错误", e);
yxresp.outPutError("UnsupportedEncodingException", "上传文件时发现文件编码错误:" + e.getMessage());
// yxresp.outPutError("UnsupportedEncodingException", "上传文件时发现文件编码错误:" + e.getMessage());
errList.add("上传文件名:" + filename+",上传文件时发现文件编码错误");
continue;
} catch (IOException e) {
e.printStackTrace();
logger.error("上传文件名" + filename );
logger.error("IOException 上传文件时发生IO错误", e);
yxresp.outPutError("IOException", "上传文件时发生IO错误:" + e.getMessage());
// yxresp.outPutError("IOException", "上传文件时发生IO错误:" + e.getMessage());
errList.add("上传文件名:" + filename+",上传文件时发生IO错误");
continue;
} catch (DocumentException e) {
e.printStackTrace();
logger.error("上传文件名" + filename );
logger.error("DocumentException 上传文件时发生错误,非法XML文件", e);
yxresp.outPutError("DocumentException", "上传文件时发生IO错误:" + e.getMessage());
// yxresp.outPutError("DocumentException", "上传文件时发生IO错误:" + e.getMessage());
errList.add("上传文件名:" + filename+",上传文件时发生错误,非法XML文件");
continue;
} catch (Exception e) {
e.printStackTrace();
logger.error("上传文件名" + filename );
logger.error("Exception 上传文件时发生错误", e);
yxresp.outPutError("Exception", "上传文件时发生错误,非法XML文件:" + filename);
// yxresp.outPutError("Exception", "上传文件时发生错误,非法XML文件:" + filename);
errList.add("上传文件名:" + filename+",上传文件时发生错误");
continue;
}
......@@ -133,7 +137,7 @@ public class ReadXmlApi {
e.printStackTrace();
logger.error("上传文件名" + filename );
logger.error("FileUploadException 文件上传发生异常", e);
yxresp.outPutError("FileUploadException", "文件上传发生异常:" + e.getMessage());
// yxresp.outPutError("FileUploadException", "文件上传发生异常:" + e.getMessage());
errList.add("上传文件名:" + filename+",上传文件时发生错误");
}
if (errList.size() == 0){
......@@ -148,8 +152,7 @@ public class ReadXmlApi {
}
private Boolean idcardsFactory(Map<String, Object> map1) {
importXmlService.importPersonXml((List<PreproPersonDto>) map1.get("preproPerson"), (FilesEntity) map1.get("file"));
return true;
return importXmlService.importPersonXml((List<PreproPersonDto>) map1.get("preproPerson"), (FilesEntity) map1.get("file"));
}
/**
......
......@@ -13,6 +13,7 @@ import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -43,7 +44,11 @@ public class ImportXmlServiceImpl implements ImportXmlService {
@Override
@Transactional(rollbackFor = Exception.class)
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");
String uploadDate = fo.format(new Date());
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