...
|
...
|
@@ -2,6 +2,7 @@ package com.tianbo.analysis.service.imp; |
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.tianbo.analysis.config.CustomsProperties;
|
|
|
import com.tianbo.analysis.dao.TRANSTOARRIVEEXPORTMapper;
|
|
|
import com.tianbo.analysis.model.ResultJson;
|
|
|
import com.tianbo.analysis.model.TRANSTOARRIVEEXPORT;
|
...
|
...
|
@@ -39,6 +40,9 @@ public class TransArriveExportImpl implements TransArriveExportService { |
|
|
@Autowired
|
|
|
private TemplateEngine templateEngine;
|
|
|
|
|
|
@Autowired
|
|
|
private CustomsProperties customsProperties;
|
|
|
|
|
|
@Value("${customs.transarrive.xml-save}")
|
|
|
private String saveXmlForSendDir;
|
|
|
|
...
|
...
|
@@ -67,6 +71,15 @@ public class TransArriveExportImpl implements TransArriveExportService { |
|
|
|
|
|
@Override
|
|
|
public ResultJson send(TRANSTOARRIVEEXPORT record) {
|
|
|
//设置海关相关信息配置
|
|
|
record.setApplycode(customsProperties.getApplyCode());
|
|
|
record.setApplyname(customsProperties.getApplyName());
|
|
|
record.setCopcode(customsProperties.getCopCode());
|
|
|
record.setCustomscode("4604");
|
|
|
//操作员IC卡号
|
|
|
record.setInputopid(customsProperties.getInputOpId());
|
|
|
// 操作员姓名
|
|
|
record.setInputopname(customsProperties.getInputOpName());
|
|
|
ResultJson resultJson= new ResultJson();
|
|
|
try{
|
|
|
|
...
|
...
|
@@ -85,45 +98,49 @@ public class TransArriveExportImpl implements TransArriveExportService { |
|
|
//生成的文件名
|
|
|
String fileName = messageID + ".xml";
|
|
|
//生成的报文路径,带斜杠
|
|
|
String filePath = saveXmlForSendDir+fileName;
|
|
|
String filePath = customsProperties.getTransarrive().getXmlSave()+fileName;
|
|
|
File file = ResourceUtils.getFile(filePath);
|
|
|
/**
|
|
|
* 中文的地方在模板中要用utext,否则中文会被 escape 转义
|
|
|
*/
|
|
|
String xmlStr = templateEngine.process("transToArrive/EXPORT_DECLARE_TPL.xml",context);
|
|
|
|
|
|
boolean valied = XmlTools.validateXMLSchema("xsd/ETAImportMessage.xsd", xmlStr);
|
|
|
if (valied){
|
|
|
FileUtils.writeStringToFile(file,xmlStr, StandardCharsets.UTF_8);
|
|
|
boolean valied = XmlTools.validateXMLSchemaThrowError("xsd/ETAImportMessage.xsd", xmlStr);
|
|
|
if (valied) {
|
|
|
FileUtils.writeStringToFile(file, xmlStr, StandardCharsets.UTF_8);
|
|
|
//todo:更新发送状态,插入发送日志
|
|
|
|
|
|
resultJson.setCode("200");
|
|
|
resultJson.setMsg("报文发送成功");
|
|
|
}else {
|
|
|
resultJson.setCode("400");
|
|
|
resultJson.setMsg("报文发送失败,报文校验不通过");
|
|
|
resultJson.setError("报文发送失败,报文校验不通过");
|
|
|
log.info("[XML-BUILD]- 报文已生成到目录{}",filePath);
|
|
|
}
|
|
|
}catch (FileNotFoundException e){
|
|
|
e.printStackTrace();
|
|
|
resultJson.setCode("401");
|
|
|
resultJson.setMsg("报文发送失败,文件未找到,"+e.toString());
|
|
|
resultJson.setError("报文发送失败,文件未找到,"+e.toString());
|
|
|
resultJson.setMsg("报文发送失败,文件未找到");
|
|
|
resultJson.setError(e.toString());
|
|
|
log.error("报文发送失败,[{}]文件未找到",e.toString());
|
|
|
}catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
resultJson.setCode("402");
|
|
|
resultJson.setMsg("报文发送失败,文件读取失败,"+e.toString());
|
|
|
resultJson.setError("报文发送失败,文件读取失败,"+e.toString());
|
|
|
resultJson.setMsg("报文发送失败,文件读取失败");
|
|
|
resultJson.setError(e.toString());
|
|
|
log.error("报文发送失败,[{}]文件IO读取失败",e.toString());
|
|
|
}catch (TemplateInputException e){
|
|
|
resultJson.setCode("404");
|
|
|
resultJson.setMsg("报文发送失败,报文模板未找到,"+e.toString());
|
|
|
resultJson.setError("报文发送失败,报文模板未找到,"+e.toString());
|
|
|
resultJson.setMsg("报文发送失败,报文模板未找到");
|
|
|
resultJson.setError(e.toString());
|
|
|
log.error("报文发送失败,[{}]报文模板未找到",e.toString());
|
|
|
}catch (SAXParseException e){
|
|
|
log.error("[XML-ERR]-xml报文校验失败:{}",e.getMessage());
|
|
|
log.error("[XML-ERR]-xml报文校验失败:[{}]", e.getMessage());
|
|
|
resultJson.setCode("400");
|
|
|
resultJson.setMsg("报文发送失败,报文校验不通过");
|
|
|
resultJson.setError(e.getMessage());
|
|
|
} catch (Exception ignored){
|
|
|
resultJson.setCode("405");
|
|
|
resultJson.setMsg("报文发送失败,其他错误"+ignored.toString());
|
|
|
resultJson.setError("报文发送失败,其他错误"+ignored.toString());
|
|
|
resultJson.setMsg("报文发送失败,其他错误");
|
|
|
resultJson.setError(ignored.toString());
|
|
|
log.error("[XML-ERR]-报文发送失败,其他错误:[{}]", ignored.getMessage());
|
|
|
}
|
|
|
return resultJson;
|
|
|
}
|
...
|
...
|
|