|
|
@ -1,10 +1,27 @@
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
|
|
|
|
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.icloud.core.sdk.ICoreSysFileCloud;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesMediaFileCfg;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesMediaFileCfg;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesMediaFileCfgRepository;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @Description: 媒体文件维护
|
|
|
|
* @Description: 媒体文件维护
|
|
|
@ -15,4 +32,92 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesMediaFileCfg")
|
|
|
|
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesMediaFileCfg")
|
|
|
|
public class MesMediaFileCfgController extends BaseMesController<MesMediaFileCfg>{
|
|
|
|
public class MesMediaFileCfgController extends BaseMesController<MesMediaFileCfg>{
|
|
|
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger(MesMediaFileCfgController.class);
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MesMediaFileCfgRepository mediaFileCfgRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ICoreSysFileCloud coreSysFileCloud;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//默认大小
|
|
|
|
|
|
|
|
private static final long FILE_SIZE = 1024 * 1024;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/media-file/insert")
|
|
|
|
|
|
|
|
@ApiOperation(value = "上传媒体文件")
|
|
|
|
|
|
|
|
public ResultBean insertProduceCtgyPicture(@RequestParam("file") MultipartFile file, MesMediaFileCfg mesMediaFileCfg) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.REPORT.getCode())
|
|
|
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
|
|
|
.setErrorDetail("不允许上传空文件")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 校验文件大小
|
|
|
|
|
|
|
|
long size = file.getSize();
|
|
|
|
|
|
|
|
if(size > FILE_SIZE){
|
|
|
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.REPORT.getCode())
|
|
|
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
|
|
|
.setErrorDetail("文件过大,请重新上传!")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
|
|
|
String newName= UUID.randomUUID().toString()+fileName.substring(fileName.indexOf("."));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String path="/tmp/media-file/";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File saveFile=new File(path + newName);
|
|
|
|
|
|
|
|
if(!saveFile.getParentFile().exists()){
|
|
|
|
|
|
|
|
saveFile.getParentFile().mkdirs();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
file.transferTo(saveFile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MesMediaFileCfg mesMediaFileCfg1=new MesMediaFileCfg();
|
|
|
|
|
|
|
|
mesMediaFileCfg1.setFileName(fileName);
|
|
|
|
|
|
|
|
mesMediaFileCfg1.setFileUrl(saveFile.getPath());
|
|
|
|
|
|
|
|
mesMediaFileCfg1.setFileType(mesMediaFileCfg.getFileType());
|
|
|
|
|
|
|
|
mediaFileCfgRepository.save(mesMediaFileCfg1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("添加成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(mesMediaFileCfg1);
|
|
|
|
|
|
|
|
} catch (ImppBusiException imppException) {
|
|
|
|
|
|
|
|
LOGGER.error(imppException.getErrorMsg() + ":{}", imppException.getErrorDetail(), imppException);
|
|
|
|
|
|
|
|
return ResultBean.fail(imppException);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("下载文件")
|
|
|
|
|
|
|
|
@GetMapping("/download")
|
|
|
|
|
|
|
|
public ResultBean download(@RequestParam("filePath") String filePath, HttpServletResponse response){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InputStream inputStream = null;
|
|
|
|
|
|
|
|
OutputStream outputStream = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 读取文件
|
|
|
|
|
|
|
|
File file = new File(filePath);
|
|
|
|
|
|
|
|
inputStream = new FileInputStream(file);
|
|
|
|
|
|
|
|
outputStream = response.getOutputStream();
|
|
|
|
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
|
|
|
|
|
|
|
byte[] buffer = new byte[4096];
|
|
|
|
|
|
|
|
int bytesRead;
|
|
|
|
|
|
|
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
|
|
|
|
|
outputStream.write(buffer, 0, bytesRead);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
|
|
|
inputStream.close();
|
|
|
|
|
|
|
|
outputStream.close();
|
|
|
|
|
|
|
|
return ResultBean.success("下载成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
|
|
|
} catch (ImppBusiException imppException) {
|
|
|
|
|
|
|
|
LOGGER.error(imppException.getErrorMsg() + ":{}", imppException.getErrorDetail(), imppException);
|
|
|
|
|
|
|
|
return ResultBean.fail(imppException);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|