¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.dnc.controller; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | import org.jeecg.modules.dnc.entity.DocFile; |
| | | import org.jeecg.modules.dnc.response.*; |
| | | import org.jeecg.modules.dnc.service.IDocFileService; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.dnc.utils.file.FileUtilS; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Api(tags = "æä»¶è¡¨") |
| | | @RestController |
| | | @RequestMapping("/nc/file") |
| | | public class DocFileController extends JeecgController<DocFile, IDocFileService> { |
| | | @Autowired |
| | | private IDocFileService docFileService; |
| | | |
| | | @AutoLog(value = "æä»¶è¡¨-æ ¹æ®docIdè·åæä»¶å表") |
| | | @ApiOperation(value = "æä»¶è¡¨-æ ¹æ®docIdè·åæä»¶å表", notes = "æä»¶è¡¨-æ ¹æ®docIdè·åæä»¶å表") |
| | | @GetMapping("/find/list") |
| | | public QueryListResponseResult<DocFile> findListByDocId(@RequestParam("docId") String docId) { |
| | | List<DocFile> list = docFileService.findListByDocId(docId); |
| | | if(list == null) |
| | | list = Collections.emptyList(); |
| | | return new QueryListResponseResult<>(CommonCode.SUCCESS, list); |
| | | } |
| | | |
| | | @AutoLog(value = "æä»¶è¡¨-æå®ææ¡£çæ¬") |
| | | @ApiOperation(value = "æä»¶è¡¨-æå®ææ¡£çæ¬", notes = "æä»¶è¡¨-æå®ææ¡£çæ¬") |
| | | @PutMapping("/assign/version/{fileId}") |
| | | public ResponseResult assignFileVersion(@PathVariable("fileId") String fileId) { |
| | | boolean b = docFileService.assignFileVersion(fileId); |
| | | if(b) |
| | | return new ResponseResult(CommonCode.SUCCESS); |
| | | return new ResponseResult(CommonCode.FAIL); |
| | | } |
| | | |
| | | @AutoLog(value = "æä»¶è¡¨-éè¿idæ¥è¯¢æä»¶") |
| | | @ApiOperation(value = "æä»¶è¡¨-éè¿idæ¥è¯¢æä»¶", notes = "æä»¶è¡¨-éè¿idæ¥è¯¢æä»¶") |
| | | @GetMapping("/get/{fileId}") |
| | | public DataResponseResult<DocFile> getFileById(@PathVariable("fileId") String fileId) { |
| | | DocFile file = docFileService.getById(fileId); |
| | | if(file == null) |
| | | return new DataResponseResult(CommonCode.FAIL, null); |
| | | return new DataResponseResult(CommonCode.SUCCESS, file); |
| | | } |
| | | |
| | | @AutoLog(value = "æä»¶è¡¨-é¢è§æä»¶") |
| | | @ApiOperation(value = "æä»¶è¡¨-é¢è§æä»¶", notes = "æä»¶è¡¨-é¢è§æä»¶") |
| | | @GetMapping("/preview/{id}") |
| | | public QueryListResponseResult previewDocFile(@PathVariable("id") String id) { |
| | | DocFile docFile = docFileService.getById(id); |
| | | if(!ValidateUtil.validateString(docFile.getFilePath()) || !ValidateUtil.validateString(docFile.getFileName()) || |
| | | /*!ValidateUtil.validateString(docFile.getFileSuffix()) ||*/ !ValidateUtil.validateString(docFile.getFileEncodeName())) |
| | | return new QueryListResponseResult(CommonCode.FAIL, null); |
| | | String filePath = docFile.getFilePath(); |
| | | String fileEncodeName = docFile.getFileEncodeName(); |
| | | List<String> list = FileUtilS.readFile(fileEncodeName, filePath); |
| | | if(list == null || list.isEmpty()) |
| | | return new QueryListResponseResult(CommonCode.FAIL, null); |
| | | return new QueryListResponseResult(CommonCode.SUCCESS, list); |
| | | } |
| | | |
| | | @AutoLog(value = "æä»¶è¡¨-ææ¡£æä»¶é¢è§") |
| | | @ApiOperation(value = "æä»¶è¡¨-ææ¡£æä»¶é¢è§", notes = "æä»¶è¡¨-ææ¡£æä»¶é¢è§") |
| | | @GetMapping("/preview/pdf/{id}") |
| | | public ResponseResult previewPdfDocFile(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") String id) { |
| | | DocFile docFile = docFileService.getById(id); |
| | | if(!ValidateUtil.validateString(docFile.getFilePath()) || !ValidateUtil.validateString(docFile.getFileName()) || |
| | | /*!ValidateUtil.validateString(docFile.getFileSuffix()) ||*/ !ValidateUtil.validateString(docFile.getFileEncodeName())) |
| | | return new ResponseResult(CommonCode.FAIL); |
| | | String fileName; |
| | | if(ValidateUtil.validateString(docFile.getFileSuffix())) { |
| | | fileName = docFile.getFileName() + "." + docFile.getFileSuffix(); |
| | | }else { |
| | | fileName = docFile.getFileName(); |
| | | } |
| | | String filePath = docFile.getFilePath(); |
| | | String fileEncodeName = docFile.getFileEncodeName(); |
| | | FileUtilS.downLoadFile(response, fileEncodeName, filePath, fileName); |
| | | return null; |
| | | } |
| | | |
| | | @AutoLog(value = "æä»¶è¡¨-å¯¹æ¯æä»¶") |
| | | @ApiOperation(value = "æä»¶è¡¨-å¯¹æ¯æä»¶", notes = "æä»¶è¡¨-å¯¹æ¯æä»¶") |
| | | @GetMapping("/comparison/{firstFileId}/{secondFileId}") |
| | | public DataResponseResult<ComparisonFilesResponse> comparisonFileDiff(@PathVariable("firstFileId") String firstFileId, @PathVariable("secondFileId") String secondFileId) { |
| | | DocFile firstFile = docFileService.getById(firstFileId); |
| | | if(firstFile == null || !ValidateUtil.validateString(firstFile.getFilePath()) || !ValidateUtil.validateString(firstFile.getFileName()) || |
| | | /*!ValidateUtil.validateString(firstFile.getFileSuffix()) ||*/ !ValidateUtil.validateString(firstFile.getFileEncodeName())) |
| | | return new DataResponseResult(CommonCode.FAIL, null); |
| | | DocFile secondFile = docFileService.getById(secondFileId); |
| | | if(secondFile == null || !ValidateUtil.validateString(secondFile.getFilePath()) || !ValidateUtil.validateString(secondFile.getFileName()) || |
| | | /*!ValidateUtil.validateString(secondFile.getFileSuffix()) ||*/ !ValidateUtil.validateString(secondFile.getFileEncodeName())) |
| | | return new DataResponseResult(CommonCode.FAIL, null); |
| | | ComparisonFilesResponse comp = new ComparisonFilesResponse(); |
| | | List<String> firstList = FileUtilS.readFile(firstFile.getFileEncodeName(), firstFile.getFilePath()); |
| | | if(firstList == null || firstList.isEmpty()) |
| | | return new DataResponseResult(CommonCode.FAIL, null); |
| | | comp.setFirst(firstList); |
| | | List<String> secondList = FileUtilS.readFile(secondFile.getFileEncodeName(), secondFile.getFilePath()); |
| | | if(secondList == null || secondList.isEmpty()) |
| | | return new DataResponseResult(CommonCode.FAIL, null); |
| | | comp.setSecond(secondList); |
| | | return new DataResponseResult(CommonCode.SUCCESS, comp); |
| | | } |
| | | |
| | | } |