|
@@ -23,13 +23,28 @@ import java.util.List;
|
|
public class ReportController {
|
|
public class ReportController {
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 文件目录,解析后的文件目录
|
|
|
|
+ */
|
|
@Value("${report.file.xmlSourcePath}")
|
|
@Value("${report.file.xmlSourcePath}")
|
|
- private String filePath;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ private String xmlSourcePath;
|
|
|
|
+ /**
|
|
|
|
+ * 文件目录,解析后的文件目录
|
|
|
|
+ */
|
|
|
|
+ @Value("${report.file.xmlTargetPath}")
|
|
|
|
+ private String xmlTargetPath;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 模型文件目标文件
|
|
|
|
+ */
|
|
@Value("${report.file.modelTargetPath}")
|
|
@Value("${report.file.modelTargetPath}")
|
|
private String modelPath;
|
|
private String modelPath;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 存放JSON文件路径
|
|
|
|
+ */
|
|
|
|
+ @Value("${report.file.jsonTargetPath}")
|
|
|
|
+ private String jsonTargetPath;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ReportFileService reportFileService;
|
|
private ReportFileService reportFileService;
|
|
@@ -45,11 +60,18 @@ public class ReportController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 文件下载
|
|
|
|
+ * @param filename
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
@GetMapping("/download/{filename}")
|
|
@GetMapping("/download/{filename}")
|
|
public Result downloadFile(@PathVariable("filename") String filename) throws IOException {
|
|
public Result downloadFile(@PathVariable("filename") String filename) throws IOException {
|
|
- String downFilePath = filePath+ filename;
|
|
|
|
-
|
|
|
|
|
|
+ String downFilePath = xmlTargetPath + filename;
|
|
|
|
+ if (filename.endsWith(".txt")){
|
|
|
|
+ downFilePath = jsonTargetPath + filename;
|
|
|
|
+ }
|
|
File file = new File(downFilePath);
|
|
File file = new File(downFilePath);
|
|
if (file.exists()) {
|
|
if (file.exists()) {
|
|
byte[] fileContent = Files.readAllBytes(file.toPath());
|
|
byte[] fileContent = Files.readAllBytes(file.toPath());
|
|
@@ -58,13 +80,17 @@ public class ReportController {
|
|
resJson.put("file", base64);
|
|
resJson.put("file", base64);
|
|
return Result.success("ok", resJson);
|
|
return Result.success("ok", resJson);
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
return Result.error("文件不存在!");
|
|
return Result.error("文件不存在!");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 模型文件下载
|
|
|
|
+ * @param modname
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
@GetMapping("/downloadMod/{modname}")
|
|
@GetMapping("/downloadMod/{modname}")
|
|
public Result downloadMod(@PathVariable("modname") String modname) throws IOException {
|
|
public Result downloadMod(@PathVariable("modname") String modname) throws IOException {
|
|
String downFilePath = modelPath+ modname;
|
|
String downFilePath = modelPath+ modname;
|
|
@@ -84,19 +110,6 @@ public class ReportController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-// @PostMapping("download")
|
|
|
|
-// public Result download(@RequestParam String fileName) {
|
|
|
|
-// System.out.println(fileName);
|
|
|
|
-// reportService.download(fileName);
|
|
|
|
-// return Result.success();
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// @PostMapping("downloadMod")
|
|
|
|
-// public Result downloadMod(@RequestParam String fileName) {
|
|
|
|
-// System.out.println(fileName);
|
|
|
|
-// reportService.downloadMod(fileName);
|
|
|
|
-// return Result.success();
|
|
|
|
-// }
|
|
|
|
@PostMapping("del")
|
|
@PostMapping("del")
|
|
public Result del(@RequestBody String json) {
|
|
public Result del(@RequestBody String json) {
|
|
JSONObject req = JSON.parseObject(json);
|
|
JSONObject req = JSON.parseObject(json);
|
|
@@ -118,13 +131,20 @@ public class ReportController {
|
|
else {
|
|
else {
|
|
reportFileEntity.setFileNameModel("");
|
|
reportFileEntity.setFileNameModel("");
|
|
}
|
|
}
|
|
- File file = new File(filePath+file_name);
|
|
|
|
|
|
+ File file = new File(xmlTargetPath +file_name);
|
|
file.delete();
|
|
file.delete();
|
|
reportFileService.saveOrUpdate(reportFileEntity);
|
|
reportFileService.saveOrUpdate(reportFileEntity);
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
- //原来的逻辑是新增,2024.1.2之后改为修改 如果没有文件,改为新增,方法需要重写
|
|
|
|
- //目前仍需改:若已有文件,需将原有数据删除
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 文件上传
|
|
|
|
+ * 原来的逻辑是新增,2024.1.2之后改为修改 如果没有文件,改为新增,方法需要重写
|
|
|
|
+ * 目前仍需改:若已有文件,需将原有数据删除
|
|
|
|
+ * @param json
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
@PostMapping("fileReportAdd")
|
|
@PostMapping("fileReportAdd")
|
|
public Result fileReportAdd(@RequestBody String json)
|
|
public Result fileReportAdd(@RequestBody String json)
|
|
{
|
|
{
|
|
@@ -132,13 +152,8 @@ public class ReportController {
|
|
long headInfId=Long.valueOf(req.getString("headInfId")) ;
|
|
long headInfId=Long.valueOf(req.getString("headInfId")) ;
|
|
long businessId=Long.valueOf(req.getString("businessId")) ;
|
|
long businessId=Long.valueOf(req.getString("businessId")) ;
|
|
String s = req.getString("fileNameTxt");
|
|
String s = req.getString("fileNameTxt");
|
|
- System.out.println("chaciren");
|
|
|
|
- System.out.println(headInfId);
|
|
|
|
ReportFileEntity reportFileEntity = reportFileService.findByHeadInfId(headInfId);
|
|
ReportFileEntity reportFileEntity = reportFileService.findByHeadInfId(headInfId);
|
|
if(reportFileEntity==null) {
|
|
if(reportFileEntity==null) {
|
|
-// System.out.println("chawuciren");
|
|
|
|
-// System.out.println(headInfId);
|
|
|
|
-
|
|
|
|
reportFileEntity = new ReportFileEntity();
|
|
reportFileEntity = new ReportFileEntity();
|
|
reportFileEntity.setHeadInfId(headInfId);
|
|
reportFileEntity.setHeadInfId(headInfId);
|
|
reportFileEntity.setRptNo(req.getString("rptNo"));
|
|
reportFileEntity.setRptNo(req.getString("rptNo"));
|
|
@@ -153,26 +168,27 @@ public class ReportController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
-// System.out.println("chayouciren");
|
|
|
|
-// System.out.println(headInfId);
|
|
|
|
|
|
+ //1:xml文件
|
|
if(req.getString("fileNameXml").equals("1")){
|
|
if(req.getString("fileNameXml").equals("1")){
|
|
String fileXml = reportFileEntity.getFileNameXml();
|
|
String fileXml = reportFileEntity.getFileNameXml();
|
|
if(fileXml!=null){
|
|
if(fileXml!=null){
|
|
- File file = new File(filePath+fileXml);
|
|
|
|
|
|
+ File file = new File(xmlSourcePath +fileXml);
|
|
file.delete();
|
|
file.delete();
|
|
}
|
|
}
|
|
reportFileEntity.setFileNameXml(req.getString("file_name"));
|
|
reportFileEntity.setFileNameXml(req.getString("file_name"));
|
|
|
|
+ //2:txt json文件
|
|
} else if (req.getString("fileNameTxt").equals("1")) {
|
|
} else if (req.getString("fileNameTxt").equals("1")) {
|
|
String fileTxt = reportFileEntity.getFileNameTxt();
|
|
String fileTxt = reportFileEntity.getFileNameTxt();
|
|
if(fileTxt!=null){
|
|
if(fileTxt!=null){
|
|
- File file = new File(filePath+fileTxt);
|
|
|
|
|
|
+ File file = new File(jsonTargetPath +fileTxt);
|
|
file.delete();
|
|
file.delete();
|
|
}
|
|
}
|
|
reportFileEntity.setFileNameTxt(req.getString("file_name"));
|
|
reportFileEntity.setFileNameTxt(req.getString("file_name"));
|
|
} else {
|
|
} else {
|
|
|
|
+ //3、模型文件
|
|
String fileModel = reportFileEntity.getFileNameModel();
|
|
String fileModel = reportFileEntity.getFileNameModel();
|
|
if(fileModel!=null){
|
|
if(fileModel!=null){
|
|
- File file = new File(filePath+fileModel);
|
|
|
|
|
|
+ File file = new File(modelPath +fileModel);
|
|
file.delete();
|
|
file.delete();
|
|
}
|
|
}
|
|
reportFileEntity.setFileNameModel(req.getString("file_name"));
|
|
reportFileEntity.setFileNameModel(req.getString("file_name"));
|