|
|
|
@ -1,305 +1,228 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.api.base.IMesMediaFileCfgService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.apiservice.config.HuaWeiCloudObsConfig;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.apiservice.utils.HuaWeiOBSUtil;
|
|
|
|
|
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.repository.MesMediaFileCfgRepository;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
import cn.estsh.impp.framework.boot.fileservice.ImppFileService;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
|
import com.obs.services.ObsClient;
|
|
|
|
|
import com.obs.services.exception.ObsException;
|
|
|
|
|
import com.obs.services.model.*;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
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.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description: 媒体文件维护
|
|
|
|
|
* @CreateDate 2024/6/6
|
|
|
|
|
* @Author gsz
|
|
|
|
|
*/
|
|
|
|
|
@Api("媒体文件维护")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesMediaFileCfg")
|
|
|
|
|
public class MesMediaFileCfgController extends BaseMesController<MesMediaFileCfg> {
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger(MesMediaFileCfgController.class);
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesMediaFileCfgRepository mediaFileCfgRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ICoreSysFileCloud coreSysFileCloud;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
HuaWeiCloudObsConfig obsConfig;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesMediaFileCfgService mediaFileCfgService;
|
|
|
|
|
/**
|
|
|
|
|
* fastDfs客户端
|
|
|
|
|
*/
|
|
|
|
|
@Autowired
|
|
|
|
|
private ImppFileService fileService;
|
|
|
|
|
//默认大小
|
|
|
|
|
private static final long FILE_SIZE = 1024 * 1024;
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/obs/upload")
|
|
|
|
|
@ApiOperation(value = "上传媒体文件")
|
|
|
|
|
public ResultBean obsUploadFile(@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();
|
|
|
|
|
|
|
|
|
|
PutObjectResult putObjectResult = HuaWeiOBSUtil.putObjectByMultipartFile(MesCommonConstant.OBS_BUCKET_NAME, fileName, file);
|
|
|
|
|
|
|
|
|
|
String objectUrl = putObjectResult.getObjectUrl();
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("添加成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(putObjectResult);
|
|
|
|
|
} catch (ImppBusiException imppException) {
|
|
|
|
|
LOGGER.error(imppException.getErrorMsg() + ":{}", imppException.getErrorDetail(), imppException);
|
|
|
|
|
return ResultBean.fail(imppException);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("下载文件")
|
|
|
|
|
@GetMapping("/obs/download")
|
|
|
|
|
public ResultBean obsDownloadFile(@RequestParam("filePath") String filePath, HttpServletResponse response, MesMediaFileCfg mesMediaFileCfg) {
|
|
|
|
|
InputStream inputStream = null;
|
|
|
|
|
OutputStream outputStream = null;
|
|
|
|
|
try {
|
|
|
|
|
// 读取文件
|
|
|
|
|
inputStream = HuaWeiOBSUtil.getObject(MesCommonConstant.OBS_BUCKET_NAME, mesMediaFileCfg.getFileName());
|
|
|
|
|
outputStream = response.getOutputStream();
|
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(mesMediaFileCfg.getFileName(), "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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查看文件")
|
|
|
|
|
@GetMapping("/obs/query-file")
|
|
|
|
|
public ResultBean queryObjectFile(HttpServletResponse response, MesMediaFileCfg mesMediaFileCfg) {
|
|
|
|
|
|
|
|
|
|
InputStream inputStream = null;
|
|
|
|
|
OutputStream outputStream = null;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
// InputStream object = HuaWeiOBSUtil.getObject(MesCommonConstant.OBS_END_POINT, mesMediaFileCfg.getFileName());
|
|
|
|
|
// 列举桶
|
|
|
|
|
ListBucketsRequest request = new ListBucketsRequest();
|
|
|
|
|
request.setQueryLocation(true);
|
|
|
|
|
ObsClient obsClient = obsConfig.getObsClient();
|
|
|
|
|
List<ObsBucket> buckets = obsClient.listBuckets(request);
|
|
|
|
|
for (ObsBucket bucket : buckets) {
|
|
|
|
|
LOGGER.info("BucketName:{},Location{}", bucket.getBucketName(),bucket.getLocation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("创建桶")
|
|
|
|
|
@GetMapping("/obs/createMesBucket")
|
|
|
|
|
public ResultBean CreateMesBucket() {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
CreateBucketRequest request = new CreateBucketRequest();
|
|
|
|
|
ObsClient obsClient = obsConfig.getObsClient();
|
|
|
|
|
ListBucketsRequest bucketsRequest = new ListBucketsRequest();
|
|
|
|
|
bucketsRequest.setQueryLocation(true);
|
|
|
|
|
List<ObsBucket> buckets = obsClient.listBuckets(bucketsRequest);
|
|
|
|
|
for (ObsBucket bucket : buckets) {
|
|
|
|
|
if(bucket.getBucketName().equals(MesCommonConstant.OBS_BUCKET_NAME)){
|
|
|
|
|
return ResultBean.success("已创建桶【mesbucket】").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//示例桶名
|
|
|
|
|
String exampleBucket = MesCommonConstant.OBS_BUCKET_NAME;
|
|
|
|
|
//示例桶区域位置
|
|
|
|
|
String exampleLocation = MesCommonConstant.OBS_LOCATION;
|
|
|
|
|
request.setBucketName(exampleBucket);
|
|
|
|
|
// 设置桶访问权限为私有读写,默认也是私有读写
|
|
|
|
|
request.setAcl(AccessControlList.REST_CANNED_PRIVATE);
|
|
|
|
|
// 设置桶的存储类别为标准存储
|
|
|
|
|
request.setBucketStorageClass(StorageClassEnum.STANDARD);
|
|
|
|
|
// 设置桶区域位置(以区域为中国-上海为例),location 需要与 endpoint的位置信息一致
|
|
|
|
|
request.setLocation(exampleLocation);
|
|
|
|
|
// 指定创建多AZ桶,如果不设置,默认创建单AZ桶
|
|
|
|
|
request.setAvailableZone(AvailableZoneEnum.MULTI_AZ);
|
|
|
|
|
// 创建桶
|
|
|
|
|
ObsBucket bucket = obsClient.createBucket(request);
|
|
|
|
|
|
|
|
|
|
} catch (ObsException e) {
|
|
|
|
|
LOGGER.error("Error Message:{}", e.getErrorMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("创建成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("列举桶")
|
|
|
|
|
@GetMapping("/obs/getObsClient")
|
|
|
|
|
public ResultBean getObsClient() {
|
|
|
|
|
List<ObsBucket> buckets=new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
ObsClient obsClient = obsConfig.getObsClient();
|
|
|
|
|
// 列举桶
|
|
|
|
|
ListBucketsRequest request = new ListBucketsRequest();
|
|
|
|
|
request.setQueryLocation(true);
|
|
|
|
|
buckets = obsClient.listBuckets(request);
|
|
|
|
|
} catch (ObsException e) {
|
|
|
|
|
LOGGER.error("Error Message:{}", e.getErrorMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.success("创建成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultList(buckets);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// @PostMapping(value = "/sys-upload")
|
|
|
|
|
// @ApiOperation(value = "系统导入")
|
|
|
|
|
// public ResultBean insertPartFurnace(@RequestParam("file") MultipartFile file, MesMediaFileCfg mesMediaFileCfg) {
|
|
|
|
|
//package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
|
|
|
|
//
|
|
|
|
|
//import cn.estsh.i3plus.ext.mes.api.base.IMesMediaFileCfgService;
|
|
|
|
|
//import cn.estsh.i3plus.ext.mes.apiservice.config.HuaWeiCloudObsConfig;
|
|
|
|
|
//import cn.estsh.i3plus.ext.mes.apiservice.utils.HuaWeiOBSUtil;
|
|
|
|
|
//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.repository.MesMediaFileCfgRepository;
|
|
|
|
|
//import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
//import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
//import cn.estsh.impp.framework.boot.fileservice.ImppFileService;
|
|
|
|
|
//import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
|
//import com.obs.services.ObsClient;
|
|
|
|
|
//import com.obs.services.exception.ObsException;
|
|
|
|
|
//import com.obs.services.model.*;
|
|
|
|
|
//import io.swagger.annotations.Api;
|
|
|
|
|
//import io.swagger.annotations.ApiOperation;
|
|
|
|
|
//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.File;
|
|
|
|
|
//import java.io.FileInputStream;
|
|
|
|
|
//import java.io.InputStream;
|
|
|
|
|
//import java.io.OutputStream;
|
|
|
|
|
//import java.net.URLEncoder;
|
|
|
|
|
//import java.util.ArrayList;
|
|
|
|
|
//import java.util.List;
|
|
|
|
|
//import java.util.UUID;
|
|
|
|
|
//
|
|
|
|
|
///**
|
|
|
|
|
// * @Description: 媒体文件维护
|
|
|
|
|
// * @CreateDate 2024/6/6
|
|
|
|
|
// * @Author gsz
|
|
|
|
|
// */
|
|
|
|
|
//@Api("媒体文件维护")
|
|
|
|
|
//@RestController
|
|
|
|
|
//@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesMediaFileCfg")
|
|
|
|
|
//public class MesMediaFileCfgController extends BaseMesController<MesMediaFileCfg> {
|
|
|
|
|
// public static final Logger LOGGER = LoggerFactory.getLogger(MesMediaFileCfgController.class);
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private MesMediaFileCfgRepository mediaFileCfgRepository;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private ICoreSysFileCloud coreSysFileCloud;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// HuaWeiCloudObsConfig obsConfig;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private IMesMediaFileCfgService mediaFileCfgService;
|
|
|
|
|
// /**
|
|
|
|
|
// * fastDfs客户端
|
|
|
|
|
// */
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private ImppFileService fileService;
|
|
|
|
|
// //默认大小
|
|
|
|
|
// private static final long FILE_SIZE = 1024 * 1024;
|
|
|
|
|
//
|
|
|
|
|
// @PostMapping(value = "/obs/upload")
|
|
|
|
|
// @ApiOperation(value = "上传媒体文件")
|
|
|
|
|
// public ResultBean obsUploadFile(@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();
|
|
|
|
|
//
|
|
|
|
|
// PutObjectResult putObjectResult = HuaWeiOBSUtil.putObjectByMultipartFile(MesCommonConstant.OBS_BUCKET_NAME, fileName, file);
|
|
|
|
|
//
|
|
|
|
|
// String objectUrl = putObjectResult.getObjectUrl();
|
|
|
|
|
//
|
|
|
|
|
// return ResultBean.success("添加成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(putObjectResult);
|
|
|
|
|
// } catch (ImppBusiException imppException) {
|
|
|
|
|
// LOGGER.error(imppException.getErrorMsg() + ":{}", imppException.getErrorDetail(), imppException);
|
|
|
|
|
// return ResultBean.fail(imppException);
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @ApiOperation("下载文件")
|
|
|
|
|
// @GetMapping("/obs/download")
|
|
|
|
|
// public ResultBean obsDownloadFile(@RequestParam("filePath") String filePath, HttpServletResponse response, MesMediaFileCfg mesMediaFileCfg) {
|
|
|
|
|
// InputStream inputStream = null;
|
|
|
|
|
// OutputStream outputStream = null;
|
|
|
|
|
// try {
|
|
|
|
|
// // 读取文件
|
|
|
|
|
// inputStream = HuaWeiOBSUtil.getObject(MesCommonConstant.OBS_BUCKET_NAME, mesMediaFileCfg.getFileName());
|
|
|
|
|
// outputStream = response.getOutputStream();
|
|
|
|
|
// response.setContentType("application/octet-stream");
|
|
|
|
|
// response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(mesMediaFileCfg.getFileName(), "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);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// @ApiOperation("查看文件")
|
|
|
|
|
// @GetMapping("/obs/query-file")
|
|
|
|
|
// public ResultBean queryObjectFile(HttpServletResponse response, MesMediaFileCfg mesMediaFileCfg) {
|
|
|
|
|
//
|
|
|
|
|
// InputStream inputStream = null;
|
|
|
|
|
// OutputStream outputStream = null;
|
|
|
|
|
// try {
|
|
|
|
|
//
|
|
|
|
|
//// InputStream object = HuaWeiOBSUtil.getObject(MesCommonConstant.OBS_END_POINT, mesMediaFileCfg.getFileName());
|
|
|
|
|
// // 列举桶
|
|
|
|
|
// ListBucketsRequest request = new ListBucketsRequest();
|
|
|
|
|
// request.setQueryLocation(true);
|
|
|
|
|
// ObsClient obsClient = obsConfig.getObsClient();
|
|
|
|
|
// List<ObsBucket> buckets = obsClient.listBuckets(request);
|
|
|
|
|
// for (ObsBucket bucket : buckets) {
|
|
|
|
|
// LOGGER.info("BucketName:{},Location{}", bucket.getBucketName(),bucket.getLocation());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// 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);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @ApiOperation("创建桶")
|
|
|
|
|
// @GetMapping("/obs/createMesBucket")
|
|
|
|
|
// public ResultBean CreateMesBucket() {
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// CreateBucketRequest request = new CreateBucketRequest();
|
|
|
|
|
// ObsClient obsClient = obsConfig.getObsClient();
|
|
|
|
|
// ListBucketsRequest bucketsRequest = new ListBucketsRequest();
|
|
|
|
|
// bucketsRequest.setQueryLocation(true);
|
|
|
|
|
// List<ObsBucket> buckets = obsClient.listBuckets(bucketsRequest);
|
|
|
|
|
// for (ObsBucket bucket : buckets) {
|
|
|
|
|
// if(bucket.getBucketName().equals(MesCommonConstant.OBS_BUCKET_NAME)){
|
|
|
|
|
// return ResultBean.success("已创建桶【mesbucket】").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// //示例桶名
|
|
|
|
|
// String exampleBucket = MesCommonConstant.OBS_BUCKET_NAME;
|
|
|
|
|
// //示例桶区域位置
|
|
|
|
|
// String exampleLocation = MesCommonConstant.OBS_LOCATION;
|
|
|
|
|
// request.setBucketName(exampleBucket);
|
|
|
|
|
// // 设置桶访问权限为私有读写,默认也是私有读写
|
|
|
|
|
// request.setAcl(AccessControlList.REST_CANNED_PRIVATE);
|
|
|
|
|
// // 设置桶的存储类别为标准存储
|
|
|
|
|
// request.setBucketStorageClass(StorageClassEnum.STANDARD);
|
|
|
|
|
// // 设置桶区域位置(以区域为中国-上海为例),location 需要与 endpoint的位置信息一致
|
|
|
|
|
// request.setLocation(exampleLocation);
|
|
|
|
|
// // 指定创建多AZ桶,如果不设置,默认创建单AZ桶
|
|
|
|
|
// request.setAvailableZone(AvailableZoneEnum.MULTI_AZ);
|
|
|
|
|
// // 创建桶
|
|
|
|
|
// ObsBucket bucket = obsClient.createBucket(request);
|
|
|
|
|
//
|
|
|
|
|
// } catch (ObsException e) {
|
|
|
|
|
// LOGGER.error("Error Message:{}", e.getErrorMessage());
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return ResultBean.success("创建成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @ApiOperation("列举桶")
|
|
|
|
|
// @GetMapping("/obs/getObsClient")
|
|
|
|
|
// public ResultBean getObsClient() {
|
|
|
|
|
// List<ObsBucket> buckets=new ArrayList<>();
|
|
|
|
|
// try {
|
|
|
|
|
// ObsClient obsClient = obsConfig.getObsClient();
|
|
|
|
|
// // 列举桶
|
|
|
|
|
// ListBucketsRequest request = new ListBucketsRequest();
|
|
|
|
|
// request.setQueryLocation(true);
|
|
|
|
|
// buckets = obsClient.listBuckets(request);
|
|
|
|
|
// } catch (ObsException e) {
|
|
|
|
|
// LOGGER.error("Error Message:{}", e.getErrorMessage());
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// return ResultBean.success("创建成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultList(buckets);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @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())
|
|
|
|
@ -307,26 +230,103 @@ public class MesMediaFileCfgController extends BaseMesController<MesMediaFileCfg
|
|
|
|
|
// .setErrorDetail("不允许上传空文件")
|
|
|
|
|
// .build();
|
|
|
|
|
// }
|
|
|
|
|
// SysFile sysFile = fileService.upload(file, CommonEnumUtil.SOFT_TYPE.MES.getValue());
|
|
|
|
|
//// MesFile mesFile = fileService.uploadMesFile(file, AuthUtil.getOrganizeCode(), AuthUtil.getSessionUser().getUserName());
|
|
|
|
|
// // 校验文件大小
|
|
|
|
|
// 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("."));
|
|
|
|
|
//
|
|
|
|
|
// //属性验证
|
|
|
|
|
// ValidatorBean.beginValid(mesMediaFileCfg)
|
|
|
|
|
// .notNull("modelNo", mesMediaFileCfg.getFileType());
|
|
|
|
|
// 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(sysFile.getDfsFileName());
|
|
|
|
|
// mesMediaFileCfg1.setFileUrl(sysFile.getFilePath());
|
|
|
|
|
// mesMediaFileCfg1.setFileName(fileName);
|
|
|
|
|
// mesMediaFileCfg1.setFileUrl(saveFile.getPath());
|
|
|
|
|
// mesMediaFileCfg1.setFileType(mesMediaFileCfg.getFileType());
|
|
|
|
|
// mediaFileCfgRepository.save(mesMediaFileCfg1);
|
|
|
|
|
//
|
|
|
|
|
// return ResultBean.success("添加成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
// 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);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//// @PostMapping(value = "/sys-upload")
|
|
|
|
|
//// @ApiOperation(value = "系统导入")
|
|
|
|
|
//// public ResultBean insertPartFurnace(@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();
|
|
|
|
|
//// }
|
|
|
|
|
//// SysFile sysFile = fileService.upload(file, CommonEnumUtil.SOFT_TYPE.MES.getValue());
|
|
|
|
|
////// MesFile mesFile = fileService.uploadMesFile(file, AuthUtil.getOrganizeCode(), AuthUtil.getSessionUser().getUserName());
|
|
|
|
|
////
|
|
|
|
|
//// //属性验证
|
|
|
|
|
//// ValidatorBean.beginValid(mesMediaFileCfg)
|
|
|
|
|
//// .notNull("modelNo", mesMediaFileCfg.getFileType());
|
|
|
|
|
////
|
|
|
|
|
//// MesMediaFileCfg mesMediaFileCfg1 = new MesMediaFileCfg();
|
|
|
|
|
//// mesMediaFileCfg1.setFileName(sysFile.getDfsFileName());
|
|
|
|
|
//// mesMediaFileCfg1.setFileUrl(sysFile.getFilePath());
|
|
|
|
|
//// mesMediaFileCfg1.setFileType(mesMediaFileCfg.getFileType());
|
|
|
|
|
//// mediaFileCfgRepository.save(mesMediaFileCfg1);
|
|
|
|
|
////
|
|
|
|
|
//// 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);
|
|
|
|
|
//// }
|
|
|
|
|
//// }
|
|
|
|
|
//
|
|
|
|
|
//}
|
|
|
|
|