feat:文件转换接口
This commit is contained in:
parent
b09bb44a0a
commit
90c8143c77
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user