|
@@ -44,11 +44,12 @@ public class FileServiceImpl {
|
|
|
|
|
|
/**
|
|
|
* 上传文件
|
|
|
+ *
|
|
|
* @param context
|
|
|
* @param filename
|
|
|
* @param path
|
|
|
*/
|
|
|
- private void writeFile(String context, String filename,String path) {
|
|
|
+ private void writeFile(String context, String filename, String path) {
|
|
|
try {
|
|
|
IOUtils.write(context, new FileOutputStream(path + filename), "UTF-8");
|
|
|
} catch (IOException e) {
|
|
@@ -58,46 +59,48 @@ public class FileServiceImpl {
|
|
|
|
|
|
/**
|
|
|
* 保存xml文件和json文件
|
|
|
+ *
|
|
|
* @param reportInfo
|
|
|
* @param xmlContext
|
|
|
* @param jsonContext
|
|
|
* @param fileName
|
|
|
*/
|
|
|
- public void saveAndWriteFile(ReportInfo reportInfo,String xmlContext,String jsonContext,String fileName){
|
|
|
+ public void saveAndWriteFile(ReportInfo reportInfo, String xmlContext, String jsonContext, String fileName) {
|
|
|
//根据HeadInfId查询是否存在
|
|
|
ReportFileEntity reportFileEntity = new ReportFileEntity();
|
|
|
- if (reportInfo.getHeadInfId()!=null){
|
|
|
+ if (reportInfo.getHeadInfId() != null) {
|
|
|
QueryWrapper<ReportFileEntity> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("head_inf_id",reportInfo.getHeadInfId());
|
|
|
+ queryWrapper.eq("head_inf_id", reportInfo.getHeadInfId());
|
|
|
ReportFileEntity reportFileEntityResult = reportFileService.getOne(queryWrapper);
|
|
|
- reportFileEntity.setId(reportFileEntityResult.getId());
|
|
|
+ if (reportFileEntityResult != null) {
|
|
|
+ reportFileEntity.setId(reportFileEntityResult.getId());
|
|
|
+ }
|
|
|
}
|
|
|
reportFileEntity.setHeadInfId(reportInfo.getHeadInfId());
|
|
|
reportFileEntity.setRptNo(reportInfo.getRptNo());
|
|
|
reportFileEntity.setBusinessId(reportInfo.getBusinessId());
|
|
|
reportFileEntity.setBusinessNum(reportInfo.getBusinessNum());
|
|
|
- String dateName = DateUtils.format(new Date(),DateUtils.YYYYMMDD);
|
|
|
- reportFileEntity.setFileNameXml(dateName+ File.separator+fileName+".xml");
|
|
|
- reportFileEntity.setFileNameTxt(dateName+File.separator+fileName+".txt");
|
|
|
+ String dateName = DateUtils.format(new Date(), DateUtils.YYYYMMDD);
|
|
|
+ reportFileEntity.setFileNameXml(dateName + File.separator + fileName + ".xml");
|
|
|
+ reportFileEntity.setFileNameTxt(dateName + File.separator + fileName + ".txt");
|
|
|
//保存文件信息表
|
|
|
reportFileService.saveOrUpdate(reportFileEntity);
|
|
|
//上传文件到服务器的目录
|
|
|
//xml文件
|
|
|
- xmlTargetPath = xmlTargetPath+File.separator+dateName+File.separator;
|
|
|
+ xmlTargetPath = xmlTargetPath + File.separator + dateName + File.separator;
|
|
|
File file = new File(xmlTargetPath);
|
|
|
- if (!file.exists()){
|
|
|
+ if (!file.exists()) {
|
|
|
file.mkdirs();
|
|
|
}
|
|
|
- jsonTargetPath = jsonTargetPath+File.separator+dateName+File.separator;
|
|
|
+ jsonTargetPath = jsonTargetPath + File.separator + dateName + File.separator;
|
|
|
File targetPathFile = new File(jsonTargetPath);
|
|
|
- if (!targetPathFile.exists()){
|
|
|
+ if (!targetPathFile.exists()) {
|
|
|
targetPathFile.mkdirs();
|
|
|
}
|
|
|
- writeFile(xmlContext,fileName+".xml",xmlTargetPath);
|
|
|
+ writeFile(xmlContext, fileName + ".xml", xmlTargetPath);
|
|
|
//json文件
|
|
|
- writeFile(jsonContext,fileName+".txt",jsonTargetPath);
|
|
|
+ writeFile(jsonContext, fileName + ".txt", jsonTargetPath);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|