|
@@ -0,0 +1,138 @@
|
|
|
+package org.springblade.land.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.springblade.business.entity.InformationQuery;
|
|
|
+import org.springblade.common.constant.CommonConstant;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.FileUtil;
|
|
|
+import org.springblade.land.entity.AgreementFile;
|
|
|
+import org.springblade.land.service.IAgreementFileService;
|
|
|
+import org.springblade.manager.entity.TableFile;
|
|
|
+import org.springblade.manager.entity.WbsTreeContract;
|
|
|
+import org.springblade.resource.feign.CommonFileClient;
|
|
|
+import org.springblade.resource.feign.IOSSClient;
|
|
|
+import org.springblade.resource.vo.NewBladeFile;
|
|
|
+import org.springblade.system.cache.ParamCache;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Param
|
|
|
+ * @Author wangwl
|
|
|
+ * @Date 2023/10/7 15:01
|
|
|
+ **/
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/agreementFile")
|
|
|
+@Api(value = "协议附件", tags = "协议附件接口")
|
|
|
+public class AgreementFileController {
|
|
|
+
|
|
|
+ private final IOSSClient iossClient;
|
|
|
+
|
|
|
+ private final CommonFileClient commonFileClient;
|
|
|
+
|
|
|
+ private final IAgreementFileService fileService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询附件列表
|
|
|
+ */
|
|
|
+ @GetMapping("/getFileList")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "附件列表", notes = "附件列表")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(name = "agreementId", value = "协议id", required = true)
|
|
|
+ })
|
|
|
+ public R<List<AgreementFile>> getFileList(Long agreementId) {
|
|
|
+ return R.data(fileService.list(new LambdaQueryWrapper<AgreementFile>().eq(AgreementFile::getAgreementId,agreementId)));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 附件上传
|
|
|
+ *
|
|
|
+ * @param file 文件
|
|
|
+ * @return ObjectStat
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ @PostMapping("/add-buss-file")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "附件上传", notes = "附件上传")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(name = "file", value = "附件", required = true),
|
|
|
+ @ApiImplicitParam(name = "agreementId", value = "协议id", required = true),
|
|
|
+ @ApiImplicitParam(name = "projectId", value = "项目id", required = true)
|
|
|
+ })
|
|
|
+ public R addBussFile(@RequestParam("file") MultipartFile file, Long agreementId,Long projectId) {
|
|
|
+
|
|
|
+ if (file.getSize() > 52428800L){
|
|
|
+ return R.fail("上传失败,文件不得大于50M");
|
|
|
+ }
|
|
|
+
|
|
|
+ String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
|
+
|
|
|
+ R<BladeFile> bladeFile = iossClient.addFileInfo(file);
|
|
|
+ BladeFile bladeFile1 = bladeFile.getData();
|
|
|
+ AgreementFile tableFile = new AgreementFile();
|
|
|
+ String fileExtension = FileUtil.getFileExtension(bladeFile1.getName()).toLowerCase();
|
|
|
+ tableFile.setAgreementId(agreementId);
|
|
|
+ tableFile.setName(file.getOriginalFilename());
|
|
|
+ tableFile.setDomainUrl(bladeFile1.getLink());
|
|
|
+ tableFile.setExtension(fileExtension);
|
|
|
+ tableFile.setProjectId(projectId);
|
|
|
+
|
|
|
+
|
|
|
+ NewBladeFile newBladeFile = new NewBladeFile();
|
|
|
+ if (fileExtension.contains("xlsx")) {
|
|
|
+ newBladeFile = this.commonFileClient.excelToPdf(file);
|
|
|
+ tableFile.setDomainPdfUrl(newBladeFile.getPdfUrl());
|
|
|
+ } else if (fileExtension.contains("xls")) {
|
|
|
+ newBladeFile = this.commonFileClient.excelToPdf(file);
|
|
|
+ tableFile.setDomainPdfUrl(newBladeFile.getPdfUrl());
|
|
|
+ } else if (fileExtension.contains("docx")) {
|
|
|
+ newBladeFile = this.commonFileClient.wordToPdf(file);
|
|
|
+ tableFile.setDomainPdfUrl(newBladeFile.getPdfUrl());
|
|
|
+ } else if (fileExtension.contains("png") || fileExtension.contains("jpg") || fileExtension.contains("webp") || fileExtension.contains("apng") ||
|
|
|
+ fileExtension.contains("bmp") || fileExtension.contains("jepg") || fileExtension.contains("tif") || fileExtension.contains("gif")) {
|
|
|
+ newBladeFile = this.commonFileClient.pngOrJpgToPdf(file);
|
|
|
+ tableFile.setDomainPdfUrl(newBladeFile.getPdfUrl());
|
|
|
+ } else if (fileExtension.contains("pdf")) {
|
|
|
+ tableFile.setDomainPdfUrl(bladeFile1.getLink());
|
|
|
+ }else {
|
|
|
+ return R.fail("上传失败,文件格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ fileService.save(tableFile);
|
|
|
+ return R.success("上传成功");
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 删除附件
|
|
|
+ */
|
|
|
+ @GetMapping("/delete")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "删除附件", notes = "删除附件")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(name = "id", value = "附件id", required = true)
|
|
|
+ })
|
|
|
+ public R delete(Long id) {
|
|
|
+ fileService.removeById(id);
|
|
|
+ return R.success("删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|