zhangherong
2025-06-25 23855599412c4d61b38d78f0f3abd3430a48b5b1
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/controller/DocInfoController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,198 @@
package org.jeecg.modules.dnc.controller;
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.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<DocInfo, IDocInfoService> {
    @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/{id}/{attrType}/{attrId}")
    public ResponseResult deleteDocInfo(@PathVariable("id") String id, @PathVariable("attrType") String attrType, @PathVariable("attrId") String attrId) {
        boolean b = docInfoService.deleteDocInfo(id,attrType,attrId);
        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 Result<?> findPageListByDevice(@PathVariable("page") int page, @PathVariable("size") int size, DocInfoQueryRequest docQuery) {
        return Result.ok(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<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 = "文档表-文档文件预览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 Result<?> findList(DocInfoQueryRequest docQuery) {
        List<DocInfo> docInfoList=docInfoService.findList(docQuery);
        return Result.ok(docInfoList);
    }
    @AutoLog(value = "文件表-批量删除文档接口")
    @ApiOperation(value = "文件表-批量删除文档接口", notes = "文件表-批量删除文档接口")
    @PostMapping("/batch/remove/{docIds}/{attrType}/{attrId}")
    public ResponseResult batchRemoveDocInfo(@PathVariable("docIds") String[] docIds, @PathVariable("attrType") String attrType, @PathVariable("attrId") String attrId) {
        boolean b = docInfoService.batchRemoveDocInfo(docIds,attrType,attrId);
        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);
    }
}