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.api.vo.Result; 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.entity.DocInfo; import org.jeecg.modules.dnc.request.DocInfoQueryRequest; import org.jeecg.modules.dnc.request.DocInfoUploadRequest; import org.jeecg.modules.dnc.response.CommonCode; import org.jeecg.modules.dnc.response.QueryListResponseResult; import org.jeecg.modules.dnc.response.QueryPageResponseResult; import org.jeecg.modules.dnc.response.ResponseResult; import org.jeecg.modules.dnc.service.IDocInfoService; 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 org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; @Slf4j @Api(tags = "文档表") @RestController @RequestMapping("/nc/doc") public class DocInfoController extends JeecgController { @Autowired private IDocInfoService docInfoService; @AutoLog(value = "文档表-导入文档进口") @ApiOperation(value = "文档表-导入文档进口", notes = "文档表-导入文档进口") @PostMapping("/add") public ResponseResult addDocInfo(@RequestParam("file") MultipartFile file, DocInfoUploadRequest docInfo) { boolean b = docInfoService.addDocInfo(file, docInfo); if(!b) return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.SUCCESS); } @AutoLog(value = "文档表-编辑文档基本信息") @ApiOperation(value = "文档表-编辑文档基本信息", notes = "文档表-编辑文档基本信息") @PutMapping("/edit/{id}") public ResponseResult editDocInfo(@PathVariable("id") String id, @RequestBody DocInfo docInfo) { boolean b = docInfoService.editDocInfo(id, docInfo); if(!b) return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.SUCCESS); } @AutoLog(value = "文档表-删除文档信息") @ApiOperation(value = "文档表-删除文档信息", notes = "文档表-删除文档信息") @DeleteMapping("/delete") public ResponseResult deleteDocInfo(@RequestParam("id") String id) { boolean b = docInfoService.deleteDocInfo(id); if(!b) return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.SUCCESS); } @AutoLog(value = "文档表-入库操作 文档对应文件升版") @ApiOperation(value = "文档表-入库操作 文档对应文件升版", notes = "文档表-入库操作 文档对应文件升版") @PostMapping("/push/{id}") public ResponseResult pushDocFile(@PathVariable("id") String id, @RequestParam("file") MultipartFile file) { boolean b = docInfoService.pushDocFile(id, file); if(!b) return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.SUCCESS); } @AutoLog(value = "文档表-出库") @ApiOperation(value = "文档表-出库", notes = "文档表-出库") @GetMapping("/pull/{id}") public ResponseResult pullDocFile(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") String id) { return docInfoService.pullDocFile(request, response, id); } @AutoLog(value = "文档表-取消出库") @ApiOperation(value = "文档表-取消出库", notes = "文档表-取消出库") @PutMapping("/cancel/pull/{id}") public ResponseResult cancelPullDocInfo(@PathVariable("id") String id) { boolean b = docInfoService.cancelPullDocInfo(id); if(!b) return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.SUCCESS); } @AutoLog(value = "文档表-文档发布") @ApiOperation(value = "文档表-文档发布", notes = "文档表-文档发布") @PutMapping("/publish/{id}") public ResponseResult publishDocInfo(@PathVariable("id") String id) { boolean b = docInfoService.publishDocInfo(id); if(!b) return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.SUCCESS); } @AutoLog(value = "文档表-文档重发布") @ApiOperation(value = "文档表-文档重发布", notes = "文档表-文档重发布") @PutMapping("/republish/{id}") public ResponseResult republishDocInfo(@PathVariable("id") String id) { boolean b = docInfoService.republishDocInfo(id); if(!b) return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.SUCCESS); } @AutoLog(value = "文档表-文档归档") @ApiOperation(value = "文档表-文档归档", notes = "文档表-文档归档") @PutMapping("/pigeonhole/{id}") public ResponseResult pigeonholeDocInfo(@PathVariable("id") String id) { boolean b = docInfoService.pigeonholeDocInfo(id); if(!b) return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.SUCCESS); } @AutoLog(value = "文档表-分页查询接口") @ApiOperation(value = "文档表-分页查询接口", notes = "文档表-分页查询接口") @GetMapping("/find/page/{page}/{size}") public Result findPageList(@PathVariable("page") int page, @PathVariable("size") int size, DocInfoQueryRequest docQuery) { return docInfoService.findPageList(page, size, docQuery); } @AutoLog(value = "文档表-查询设备发送目录的文档状态") @ApiOperation(value = "文档表-查询设备发送目录的文档状态", notes = "文档表-查询设备发送目录的文档状态") @GetMapping("/find/page/device/{page}/{size}") public QueryPageResponseResult findPageListByDevice(@PathVariable("page") int page, @PathVariable("size") int size, DocInfoQueryRequest docQuery) { return docInfoService.findPageListByDevice(page, size, docQuery); } @AutoLog(value = "文档表-文档文件预览") @ApiOperation(value = "文档表-文档文件预览", notes = "文档表-文档文件预览") @GetMapping("/preview/{id}") public QueryListResponseResult previewDocFile(@PathVariable("id") String id) { DocFile docFile = docInfoService.previewDocFile(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 list = FileUtilS.readFile(fileEncodeName, filePath); if(list == null || list.isEmpty()) return new QueryListResponseResult(CommonCode.FAIL, null); return new QueryListResponseResult(CommonCode.SUCCESS, list); } @AutoLog(value = "文档表-文档文件预览pdf") @ApiOperation(value = "文档表-文档文件预览pdf", notes = "文档表-文档文件预览pdf") @GetMapping("/preview/pdf/{id}") public ResponseResult previewPdfDocFile(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") String id) { DocFile docFile = docInfoService.previewDocFile(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("/find/list") public QueryListResponseResult findList(DocInfoQueryRequest docQuery) { return docInfoService.findList(docQuery); } @AutoLog(value = "文件表-批量删除文档接口") @ApiOperation(value = "文件表-批量删除文档接口", notes = "文件表-批量删除文档接口") @PostMapping("/batch/remove") public ResponseResult batchRemoveDocInfo(@RequestBody String[] docIds) { boolean b = docInfoService.batchRemoveDocInfo(docIds); if(!b) return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.SUCCESS); } @AutoLog(value = "文件表-文档下载") @ApiOperation(value = "文件表-文档下载", notes = "文件表-文档下载") @GetMapping("/download/{id}") public ResponseResult downloadDocFile(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") String id) { return docInfoService.downloadDocFile(request, response, id); } }