package com.ruoyi.inspect.controller;
|
|
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.http.HttpUtil;
|
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson2.JSON;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.core.domain.Result;
|
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.utils.JackSonUtil;
|
import com.ruoyi.framework.exception.ErrorException;
|
import com.ruoyi.inspect.dto.BatchApprovalReportDTO;
|
import com.ruoyi.inspect.dto.ReportPageDto;
|
import com.ruoyi.inspect.pojo.InsReport;
|
import com.ruoyi.inspect.service.InsReportService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.logging.log4j.util.Strings;
|
import org.apache.poi.hssf.record.SSTRecord;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.File;
|
import java.io.IOException;
|
import java.io.PrintWriter;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.Scanner;
|
|
@RestController
|
@RequestMapping("/insReport")
|
@Api(tags = "检验报告")
|
public class InsReportController {
|
|
|
@Resource
|
private InsReportService insReportService;
|
|
@Value("${wordUrl}")
|
private String wordUrl;
|
|
@ApiOperation(value = "查看检验报告列表")
|
@GetMapping("/pageInsReport")
|
public Result pageInsReport(Page page,ReportPageDto reportPageDto) throws Exception {
|
return Result.success(insReportService.pageInsReport(page, reportPageDto));
|
}
|
|
|
@ApiOperation(value = "一键审批按钮")
|
@PostMapping("/batchApprovalReport")
|
public Result batchApprovalReport(@RequestBody BatchApprovalReportDTO batchApprovalReportDTO){
|
try {
|
insReportService.batchApprovalReport(batchApprovalReportDTO.getIds());
|
}catch (Exception e){
|
throw new RuntimeException(e);
|
}
|
return Result.success();
|
}
|
|
@ApiOperation(value = "获取审批进度")
|
@GetMapping("/getBatchApprovalProgress")
|
public Result getBatchApprovalProgress(){
|
return Result.success(insReportService.getBatchApprovalProgress());
|
}
|
|
|
@ApiOperation(value = "查看检验报告数量信息")
|
@GetMapping("/getReportCountInfo")
|
public Result getReportCountInfo(ReportPageDto reportPageDto) throws Exception {
|
return Result.success(insReportService.getReportCountInfo(reportPageDto));
|
}
|
|
@ApiOperation(value = "上传按钮")
|
@PostMapping("/inReport")
|
public Result inReport(MultipartFile file, Integer id) {
|
String urlString;
|
String pathName;
|
try {
|
String path = wordUrl;
|
File realpath = new File(path);
|
if (!realpath.exists()) {
|
realpath.mkdirs();
|
}
|
InsReport insReport = insReportService.getById(id);
|
// 如果URLS有值 先将该文件删除
|
if(Strings.isNotEmpty(insReport.getUrlS())){
|
String url = wordUrl + File.separator + insReport.getUrlS().replace("/word/", "");
|
File file1 = new File(url);
|
if(file1.exists()) {
|
file1.delete();
|
}
|
}
|
String code = insReport.getCode().replace("/", "") + ".docx";
|
pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + code;
|
urlString = realpath + "/" + pathName;
|
file.transferTo(new File(urlString));
|
return Result.success(insReportService.inReport("/word/" + pathName, id));
|
} catch (Exception e) {
|
throw new ErrorException("文件上传失败");
|
}
|
}
|
//下载
|
@GetMapping("/downReport")
|
public void downReport(@RequestParam("id") Integer id,@RequestParam("type") Integer type, HttpServletResponse response) {
|
insReportService.downReport(id,type, response);
|
}
|
|
|
|
@ApiOperation(value = "还原按钮")
|
@PostMapping("/upReportUrl")
|
public Result upReportUrl(Integer id) {
|
return Result.success(insReportService.upReportUrl(id));
|
}
|
|
@ApiOperation(value = "编制按钮")
|
@GetMapping("/upReportFile")
|
public Result upReportFile() {
|
return Result.success();
|
}
|
|
@ApiOperation(value = "提交按钮")
|
@PostMapping("/writeReport")
|
public Result writeReport(Integer id) {
|
|
return Result.success(insReportService.writeReport(id));
|
}
|
|
@ApiOperation(value = "审核按钮")
|
@PostMapping("/examineReport")
|
public Result examineReport(Integer id, Integer isExamine, String examineTell) {
|
return Result.success(insReportService.examineReport(id, isExamine, examineTell));
|
}
|
|
@ApiOperation(value = "批准按钮")
|
@PostMapping("/ratifyReport")
|
public Result ratifyReport(Integer id, Integer isRatify, String ratifyTell) {
|
return Result.success(insReportService.ratifyReport(id, isRatify, ratifyTell));
|
}
|
|
@RequestMapping("/onlyOffice/save")
|
public void saveFile(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) {
|
PrintWriter writer = null;
|
try {
|
writer = response.getWriter();
|
// 获取传输的json数据
|
Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
|
String body = scanner.hasNext() ? scanner.next() : "";
|
JSONObject jsonObject = JSONObject.parseObject(body);
|
|
if (jsonObject.containsKey("url")) {
|
String jsonArray = jsonObject.get("lastsave").toString(); // 更新时间
|
String fileUrl = jsonObject.get("url").toString(); // 更新文件url
|
HttpUtil.downloadFile(fileUrl, FileUtil.file(wordUrl + "/" + fileName));
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
writer.write("{\"error\":-1}");
|
return;
|
}
|
/*
|
* status = 1,我们给onlyOffice的服务返回{"error":"0"}的信息。
|
* 这样onlyOffice会认为回调接口是没问题的,这样就可以在线编辑文档了,否则的话会弹出窗口说明
|
*/
|
if (Objects.nonNull(writer)) {
|
writer.write("{\"error\":0}");
|
}
|
}
|
|
@ApiOperation(value = "批量下载按钮")
|
@GetMapping("/downAll")
|
public Result downAll(String ids) {
|
return Result.success(insReportService.downAll(ids));
|
}
|
|
@ApiOperation(value = "批量上传按钮")
|
@PostMapping("/upAll")
|
public Result upAll(MultipartFile file) throws IOException {
|
return Result.success(insReportService.upAll(file));
|
}
|
|
@ApiOperation(value = "撤回按钮")
|
@PostMapping("/withdraw")
|
public Result withdraw(@RequestBody Map<String,Object> map) {
|
insReportService.withdraw(map);
|
return Result.success();
|
}
|
|
@GetMapping("/getLaboratoryByReportId")
|
public Result getLaboratoryByReportId(Integer id) {
|
return Result.success(insReportService.getLaboratoryByReportId(id));
|
}
|
|
|
|
}
|