|
@@ -0,0 +1,161 @@
|
|
|
|
|
+package cn.start.tz.module.pressure2.controller.appapi.standardfile;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
|
|
+import cn.start.tz.framework.common.pojo.CommonResult;
|
|
|
|
|
+import cn.start.tz.framework.common.pojo.PageResult;
|
|
|
|
|
+import cn.start.tz.framework.common.util.object.BeanUtils;
|
|
|
|
|
+import cn.start.tz.module.grape.city.api.GrapeCityApi;
|
|
|
|
|
+import cn.start.tz.module.infra.api.file.FileApi;
|
|
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.standardfile.vo.*;
|
|
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.standardfile.StandardFileDO;
|
|
|
|
|
+import cn.start.tz.module.pressure2.service.standardfile.StandardClassService;
|
|
|
|
|
+import cn.start.tz.module.pressure2.service.standardfile.StandardFileService;
|
|
|
|
|
+import cn.start.tz.module.pressure2.util.WordToPdfUtils;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import jakarta.annotation.Resource;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
+import jakarta.validation.Valid;
|
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
|
+import org.apache.pdfbox.multipdf.PDFMergerUtility;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import static cn.start.tz.framework.common.pojo.CommonResult.success;
|
|
|
|
|
+
|
|
|
|
|
+@Tag(name = "管理后台 - 承压标准文件")
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/pressure2/standard-file")
|
|
|
|
|
+@Validated
|
|
|
|
|
+public class AppStandardFileController {
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${grapecity.url:null}")
|
|
|
|
|
+ private String grapecityUrl;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private StandardFileService standardFileService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private StandardClassService standardClassService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private GrapeCityApi grapeCityApi;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FileApi fileApi;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/create")
|
|
|
|
|
+ @Operation(summary = "创建承压标准文件")
|
|
|
|
|
+ //@PreAuthorize("@ss.hasPermission('pressure:standard-file:create')")
|
|
|
|
|
+ public CommonResult<String> createStandardFile(@Valid @RequestBody StandardFileSaveReqVO createReqVO) {
|
|
|
|
|
+ return success(standardFileService.createStandardFile(createReqVO));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/update")
|
|
|
|
|
+ @Operation(summary = "更新承压标准文件")
|
|
|
|
|
+ //@PreAuthorize("@ss.hasPermission('pressure:standard-file:update')")
|
|
|
|
|
+ public CommonResult<Boolean> updateStandardFile(@Valid @RequestBody StandardFileSaveReqVO updateReqVO) {
|
|
|
|
|
+ standardFileService.updateStandardFile(updateReqVO);
|
|
|
|
|
+ return success(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @DeleteMapping("/delete")
|
|
|
|
|
+ @Operation(summary = "删除承压标准文件")
|
|
|
|
|
+ @Parameter(name = "id", description = "编号", required = true)
|
|
|
|
|
+ //@PreAuthorize("@ss.hasPermission('pressure:standard-file:delete')")
|
|
|
|
|
+ public CommonResult<Boolean> deleteStandardFile(@RequestParam("id") String id) {
|
|
|
|
|
+ standardFileService.deleteStandardFile(id);
|
|
|
|
|
+ return success(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/get")
|
|
|
|
|
+ @Operation(summary = "获得承压标准文件")
|
|
|
|
|
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
|
|
|
|
|
+ //@PreAuthorize("@ss.hasPermission('pressure:standard-file:query')")
|
|
|
|
|
+ public CommonResult<StandardFileDetailRespVO> getStandardFile(@RequestParam("id") String id) {
|
|
|
|
|
+ StandardFileDetailRespVO detailRespVO = standardFileService.getStandardFileDetail(id);
|
|
|
|
|
+ return success(detailRespVO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/page")
|
|
|
|
|
+ @Operation(summary = "获得承压标准文件分页")
|
|
|
|
|
+ //@PreAuthorize("@ss.hasPermission('pressure:standard-file:query')")
|
|
|
|
|
+ public CommonResult<PageResult<StandardFileRespVO>> getStandardFilePage(@Valid StandardFilePageReqVO pageReqVO) {
|
|
|
|
|
+ PageResult<StandardFileRespVO> pageResult = standardFileService.getStandardFilePage(pageReqVO);
|
|
|
|
|
+ return success(pageResult);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/notVerifyPage")
|
|
|
|
|
+ @Operation(summary = "获得承压标准文件分页(不校验菜单权限)")
|
|
|
|
|
+ public CommonResult<PageResult<StandardFileRespVO>> notVerifyPage(@Valid StandardFilePageReqVO pageReqVO) {
|
|
|
|
|
+ PageResult<StandardFileDO> pageResult = standardFileService.notVerifyPage(pageReqVO);
|
|
|
|
|
+ return success(BeanUtils.toBean(pageResult, StandardFileRespVO.class));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/getPdf")
|
|
|
|
|
+ @Operation(summary = "预览模版pdf")
|
|
|
|
|
+ public void getPdf(@RequestParam(value = "file", required = true) MultipartFile file,
|
|
|
|
|
+ HttpServletResponse response) throws Exception {
|
|
|
|
|
+ // 调用另一个服务的 PDF 转换接口
|
|
|
|
|
+ String targetUrl = grapecityUrl+
|
|
|
|
|
+ "/pdf/getPdf";
|
|
|
|
|
+ byte[] fileBytes = file.getBytes();
|
|
|
|
|
+ List<byte[]> pdfBytesList = new ArrayList<>();
|
|
|
|
|
+ pdfBytesList.add(fileBytes);
|
|
|
|
|
+ // 发送 POST 请求获取 PDF 字节流
|
|
|
|
|
+ byte[] bytes = HttpUtil.createPost(targetUrl)
|
|
|
|
|
+ .body(JSONObject.toJSONString(pdfBytesList)).execute().bodyBytes();
|
|
|
|
|
+ response.getOutputStream().write(bytes);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/getPDFByInspection")
|
|
|
|
|
+ @Operation(summary = "预览检验方案模版pdf")
|
|
|
|
|
+ public void getPDFByInspection(@RequestParam(value = "file", required = true) MultipartFile file,@RequestParam(value = "manualUrl") String manualUrl,
|
|
|
|
|
+ HttpServletResponse response) throws Exception {
|
|
|
|
|
+ byte[] bytes = grapeCityApi.getPdfByte(file.getBytes()).getCheckedData();
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotEmpty(manualUrl)){
|
|
|
|
|
+
|
|
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
|
+
|
|
|
|
|
+ if (manualUrl.endsWith(".doc") || manualUrl.endsWith(".docx")) {
|
|
|
|
|
+ byte[] wordBytes = fileApi.getFileByPath(manualUrl).getData();
|
|
|
|
|
+ byteArrayOutputStream = WordToPdfUtils.doc2pdfOutStream(wordBytes);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ byte[] bytes1 = fileApi.getFileByPath(manualUrl).getData();
|
|
|
|
|
+ byteArrayOutputStream.write(bytes1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ByteArrayOutputStream mergeOutputStream = new ByteArrayOutputStream();
|
|
|
|
|
+ PDFMergerUtility mergerUtility = new PDFMergerUtility();
|
|
|
|
|
+ mergerUtility.addSource(new ByteArrayInputStream(bytes));
|
|
|
|
|
+ mergerUtility.addSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
|
|
|
|
|
+ // pdf 文件流合并
|
|
|
|
|
+ mergerUtility.setDestinationStream(mergeOutputStream);
|
|
|
|
|
+ mergerUtility.mergeDocuments(null);
|
|
|
|
|
+
|
|
|
|
|
+ response.getOutputStream().write(mergeOutputStream.toByteArray());
|
|
|
|
|
+ }else{
|
|
|
|
|
+ response.getOutputStream().write(bytes);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/list")
|
|
|
|
|
+ @Operation(summary = "获得标准分类列表")
|
|
|
|
|
+ public CommonResult<List<StandardClassRespVO>> getStandardClassList() {
|
|
|
|
|
+ return success(standardClassService.getStandardClassList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|