From 90c8143c77aa1b0d4bb893339d2806c2445eb096 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Fri, 20 Oct 2023 14:32:38 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=96=87=E4=BB=B6=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FtransitController.java | 31 +++- .../modules/controller/GammaController.java | 11 -- .../jeecg/modules/service/IGammaService.java | 7 + .../service/impl/GammaServiceImpl.java | 171 ++++++++++++++++++ 4 files changed, 206 insertions(+), 14 deletions(-) diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/FtransitController.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/FtransitController.java index 78e9cab7..8f3ba7b8 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/FtransitController.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/FtransitController.java @@ -2,6 +2,7 @@ package org.jeecg.modules.controller; import io.swagger.annotations.Api; import org.jeecg.modules.entity.vo.FileData; +import org.jeecg.modules.entity.vo.FileDataInfo; import org.jeecg.modules.service.IGammaService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -17,9 +18,33 @@ public class FtransitController { @Autowired private IGammaService gammaService; - @PostMapping("IecToIms") - public void IecToIms(@RequestPart("file") MultipartFile file, @RequestPart("data") FileData data, HttpServletResponse response) { - gammaService.IecToIms(data, file, response); + @PostMapping("ImsToIec") + public void ImsToIec(MultipartFile file, HttpServletResponse response) { + gammaService.ImsToIec(file, response); } + @PostMapping("IecToIms") + public void IecToIms(FileDataInfo data, HttpServletResponse response) { + gammaService.IecToIms(data, data.getFile(), response); + } + + @PostMapping("SpcToIms") + public void SpcToIms(FileDataInfo data, HttpServletResponse response) { + gammaService.SpcToIms(data, data.getFile(), response); + } + + @PostMapping("ImsToSpc") + public void ImsToSpc(MultipartFile file, HttpServletResponse response) { + gammaService.ImsToSpc(file, response); + } + + @PostMapping("SpcToIec") + public void SpcToIec(MultipartFile file, HttpServletResponse response) { + gammaService.SpcToIec(file, response); + } + + @PostMapping("IecToSpc") + public void IecToSpc(MultipartFile file, HttpServletResponse response) { + gammaService.IecToSpc(file, response); + } } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java index 2326c3af..652256bb 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java @@ -496,15 +496,4 @@ public class GammaController { public void saveToPHD(String fileName, HttpServletRequest request, HttpServletResponse response) { gammaService.saveToPHD(fileName, request, response); } - - @PostMapping("ImsToIec") - public void ImsToIec(MultipartFile file, HttpServletResponse response) { - gammaService.ImsToIec(file, response); - } - - @PostMapping("IecToIms") - public void IecToIms(FileDataInfo data, HttpServletResponse response) { - gammaService.IecToIms(data, data.getFile(), response); - } - } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java index fac3a44d..edd078db 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java @@ -178,4 +178,11 @@ public interface IGammaService{ void IecToIms(FileData data, MultipartFile file, HttpServletResponse response); + void SpcToIms(FileData data, MultipartFile file, HttpServletResponse response); + + void ImsToSpc(MultipartFile file, HttpServletResponse response); + + void SpcToIec(MultipartFile file, HttpServletResponse response); + + void IecToSpc(MultipartFile file, HttpServletResponse response); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java index 07223d3b..e8df062c 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java @@ -4578,4 +4578,175 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi } } + @Override + public void SpcToIms(FileData datas, MultipartFile file, HttpServletResponse response) { + String SpcName = file.getOriginalFilename(); + String ImsName = SpcName.substring(0, SpcName.length()-4)+".IMS"; + File spcFile = null; + InputStream inputStream = null; + //导出数据内容到txt文本 + OutputStream fos = null; + try { + spcFile = File.createTempFile("betaGamma", null); + inputStream = file.getInputStream(); + FileUtils.copyInputStreamToFile(inputStream, spcFile); + if(!fileFtransitUtil.ReadSPC(spcFile, datas)) return; + + String imsValue = fileFtransitUtil.WriteIMS(datas); + //设置响应类型 + response.setContentType("application/octet-stream"); + //解决中文不能生成文件 + response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(ImsName,"UTF-8")); + fos = response.getOutputStream(); + fos.write(imsValue.getBytes()); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(spcFile)) { + spcFile.delete(); + } + if (Objects.nonNull(inputStream)) { + inputStream.close(); + } + if (Objects.nonNull(fos)) { + fos.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + @Override + public void ImsToSpc(MultipartFile file, HttpServletResponse response) { + String ImsName = file.getOriginalFilename(); + String SpcName = ImsName.substring(0, ImsName.length()-4)+".SPC"; + FileData datas = new FileData(); + File imsFile = null; + File spcFile = null; + InputStream inputStream = null; + InputStream spcInputStream = null; + OutputStream outputStream = null; + try { + imsFile = File.createTempFile("betaGamma", null); + spcFile = File.createTempFile("spcTemp", ".SCP"); + inputStream = file.getInputStream(); + FileUtils.copyInputStreamToFile(inputStream, imsFile); + if(!fileFtransitUtil.ReadIMS(imsFile, datas)) return; + fileFtransitUtil.WriteSPC(spcFile ,datas); + // 获取文件输入流 + spcInputStream = new FileInputStream(spcFile); + // 获取响应输出流 + outputStream = ExportUtil.stream(response, SpcName); + + // 缓冲区大小 + byte[] buffer = new byte[4096]; + int bytesRead; + + // 将文件输出流写入到输出流中 + while ((bytesRead = spcInputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(imsFile)) imsFile.delete(); + if (Objects.nonNull(spcFile)) spcFile.delete(); + if (Objects.nonNull(inputStream)) inputStream.close(); + if (ObjectUtil.isNotNull(spcInputStream)) spcInputStream.close(); + if (ObjectUtil.isNotNull(outputStream)) outputStream.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + @Override + public void SpcToIec(MultipartFile file, HttpServletResponse response) { + String SpcName = file.getOriginalFilename(); + String IecName = SpcName.substring(0, SpcName.length()-4)+".IEC"; + FileData datas = new FileData(); + File spcFile = null; + InputStream inputStream = null; + //导出数据内容到txt文本 + OutputStream fos = null; + try { + spcFile = File.createTempFile("betaGamma", null); + inputStream = file.getInputStream(); + FileUtils.copyInputStreamToFile(inputStream, spcFile); + if(!fileFtransitUtil.ReadSPC(spcFile, datas)) return; + + String iecValue = fileFtransitUtil.WriteIEC(datas); + //设置响应类型 + response.setContentType("application/octet-stream"); + //解决中文不能生成文件 + response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(IecName,"UTF-8")); + fos = response.getOutputStream(); + fos.write(iecValue.getBytes()); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(spcFile)) { + spcFile.delete(); + } + if (Objects.nonNull(inputStream)) { + inputStream.close(); + } + if (Objects.nonNull(fos)) { + fos.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + @Override + public void IecToSpc(MultipartFile file, HttpServletResponse response) { + String IecName = file.getOriginalFilename(); + String SpcName = IecName.substring(0, IecName.length()-4)+".SPC"; + FileData datas = new FileData(); + File iecFile = null; + File spcFile = null; + InputStream inputStream = null; + InputStream spcInputStream = null; + OutputStream outputStream = null; + try { + iecFile = File.createTempFile("betaGamma", null); + spcFile = File.createTempFile("spcTemp", ".SCP"); + inputStream = file.getInputStream(); + FileUtils.copyInputStreamToFile(inputStream, iecFile); + if(!fileFtransitUtil.ReadIEC(iecFile, datas)) return; + fileFtransitUtil.WriteSPC(spcFile ,datas); + // 获取文件输入流 + spcInputStream = new FileInputStream(spcFile); + // 获取响应输出流 + outputStream = ExportUtil.stream(response, SpcName); + + // 缓冲区大小 + byte[] buffer = new byte[4096]; + int bytesRead; + + // 将文件输出流写入到输出流中 + while ((bytesRead = spcInputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(iecFile)) iecFile.delete(); + if (Objects.nonNull(spcFile)) spcFile.delete(); + if (Objects.nonNull(inputStream)) inputStream.close(); + if (ObjectUtil.isNotNull(spcInputStream)) spcInputStream.close(); + if (ObjectUtil.isNotNull(outputStream)) outputStream.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + }