package com.ruoyi.inspect.controller;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.basic.dto.IfsInventoryQuantitySupplierDto;
|
import com.ruoyi.common.annotation.PersonalScope;
|
import com.ruoyi.common.core.domain.Result;
|
import com.ruoyi.framework.exception.ErrorException;
|
import com.ruoyi.inspect.dto.ReportPageDto;
|
import com.ruoyi.inspect.service.InsOrderPlanService;
|
import com.ruoyi.inspect.service.InsReportEditingService;
|
import com.ruoyi.inspect.service.InsReportService;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.Operation;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import jakarta.annotation.Resource;
|
import jakarta.servlet.http.HttpServletResponse;
|
import java.io.File;
|
import java.io.IOException;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.Map;
|
|
@RestController
|
@RequestMapping("/insReport")
|
@Tag(name = "检验报告")
|
public class InsReportController {
|
|
@Resource
|
private InsReportService insReportService;
|
|
@Resource
|
private InsOrderPlanService insOrderPlanService;
|
|
@Resource
|
private InsReportEditingService insReportEditingService;
|
|
@Value("${wordUrl}")
|
private String wordUrl;
|
|
@Operation(summary = "查询检验报告数据")
|
@GetMapping("/pageInsReport")
|
@PreAuthorize("@ss.hasPermi('business:reportPreparation')")
|
@PersonalScope(permsName = "business:reportPreparation", objectName = ReportPageDto.class, paramName = "createOrderUser")
|
public Result pageInsReport(Page page, ReportPageDto reportPageDto){
|
return Result.success(insReportService.pageInsReport(page, reportPageDto));
|
}
|
|
@Operation(summary = "报告上传")
|
@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();
|
}
|
pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + file.getOriginalFilename();
|
urlString = realpath + "/" + pathName;
|
file.transferTo(new File(urlString));
|
return Result.success(insReportService.inReport("/word/" + pathName, id));
|
} catch (Exception e) {
|
throw new ErrorException("文件上传失败");
|
}
|
}
|
|
@Operation(summary = "报告还原")
|
@PostMapping("/upReportUrl")
|
public Result upReportUrl(@RequestBody Map<String, Object> param) {
|
Integer id = (Integer) param.get("id");
|
return Result.success(insReportService.upReportUrl(id));
|
}
|
|
@Operation(summary = "报告在线编制")
|
@GetMapping("/upReportFile")
|
public Result upReportFile() {
|
return Result.success();
|
}
|
|
@Operation(summary = "提交")
|
@PostMapping("/writeReport")
|
public Result writeReport(@RequestBody Map<String, Object> param) {
|
Integer id = (Integer) param.get("id");
|
Integer userId = (Integer) param.get("userId");
|
return Result.success(insReportService.writeReport(id, userId, null));
|
}
|
|
/**
|
* @param userId 需要的批准人
|
* @return
|
*/
|
|
@Operation(summary = "审核")
|
@PostMapping("/examineReport")
|
public Result examineReport(@RequestBody Map<String, Object> param) {
|
Integer id = (Integer) param.get("id");
|
Integer isExamine = (Integer) param.get("isExamine");
|
String examineTell = (String) param.get("examineTell");
|
Integer userId = (Integer) param.get("userId");
|
Map<String, String> sessions = new java.util.HashMap<>();
|
if (param.get("editSessions") instanceof Map<?, ?> values) {
|
values.forEach((key, value) -> sessions.put(String.valueOf(key), String.valueOf(value)));
|
}
|
return Result.success(insReportEditingService.examineReport(id, isExamine, examineTell, userId, sessions));
|
}
|
|
@Operation(summary = "批准")
|
@PostMapping("/ratifyReport")
|
public Result ratifyReport(@RequestBody Map<String, Object> param) {
|
Integer id = (Integer) param.get("id");
|
Integer isRatify = (Integer) param.get("isRatify");
|
String ratifyTell = (String) param.get("ratifyTell");
|
Object sealIdsObj = param.get("sealIds");
|
String sealIds = sealIdsObj == null ? null : String.valueOf(sealIdsObj);
|
Integer maSealId = toInteger(param.get("maSealId"));
|
Integer reportSealId = toInteger(param.get("reportSealId"));
|
Integer seamSealId = toInteger(param.get("seamSealId"));
|
return Result.success(insReportService.ratifyReport(
|
id, isRatify, ratifyTell, sealIds, maSealId, reportSealId, seamSealId));
|
}
|
|
private Integer toInteger(Object value) {
|
if (value == null || String.valueOf(value).trim().isEmpty()) {
|
return null;
|
}
|
return value instanceof Number ? ((Number) value).intValue() : Integer.valueOf(String.valueOf(value));
|
}
|
|
@Operation(summary = "获取浏览器端报告编辑会话")
|
@GetMapping("/editor/config")
|
public Result editConfig(Integer id, Integer reportType) {
|
return Result.success(insReportEditingService.createEditConfig(id, reportType));
|
}
|
|
@Operation(summary = "读取审核 DOCX 内容")
|
@GetMapping("/editor/document")
|
public org.springframework.http.ResponseEntity<byte[]> editDocument(@RequestParam String token) {
|
return org.springframework.http.ResponseEntity.ok().header("Cache-Control", "no-store")
|
.contentType(org.springframework.http.MediaType.parseMediaType(
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"))
|
.body(insReportEditingService.readDocument(token));
|
}
|
|
@Operation(summary = "保存浏览器内编辑的 DOCX")
|
@PostMapping(value = "/editor/document", consumes = "multipart/form-data")
|
public Result saveEditDocument(@RequestParam String token, @RequestParam String version,
|
@RequestPart MultipartFile file) {
|
return Result.success(insReportEditingService.saveDocument(token, version, file));
|
}
|
|
@Operation(summary = "报告批量下载")
|
@GetMapping("/downAll")
|
public Result downAll(String ids) {
|
return Result.success(insReportService.downAll(ids));
|
}
|
|
@Operation(summary = "报告下载(reportType:0检测报告,1检验报告)")
|
@GetMapping("/download")
|
@PreAuthorize("@ss.hasPermi('business:reportPreparation')")
|
@PersonalScope(permsName = "business:reportPreparation", objectName = ReportPageDto.class, paramName = "createOrderUser")
|
public void download(Integer id, Integer reportType, ReportPageDto reportPageDto, HttpServletResponse response) {
|
insReportService.download(id, reportType, reportPageDto.getCreateOrderUser(), response);
|
}
|
|
@Operation(summary = "重新生成报告")
|
@PostMapping("/regenerate")
|
// @PreAuthorize("@ss.hasPermi('business:reportPreparation')")
|
@PersonalScope(permsName = "business:reportPreparation", objectName = ReportPageDto.class, paramName = "createOrderUser")
|
public Result regenerate(@RequestBody ReportPageDto reportPageDto) {
|
insOrderPlanService.regenerateReport(reportPageDto.getId(), reportPageDto.getCreateOrderUser());
|
return Result.success();
|
}
|
|
@Operation(summary = "报告批量上传")
|
@PostMapping("/upAll")
|
public Result upAll(MultipartFile file) throws IOException {
|
return Result.success(insReportService.upAll(file));
|
}
|
|
/**
|
* 退回到检验任务
|
* @param id
|
* @return
|
*/
|
@Operation(summary = "退回到检验任务")
|
@PostMapping("/sendBackTask")
|
public Result sendBackTask(@RequestBody Map<String, Object> param){
|
Integer id = (Integer) param.get("id");
|
return Result.success(insReportService.sendBackTask(id));
|
}
|
|
/**
|
* 报告导出
|
* @param dto
|
* @param response
|
* @throws Exception
|
*/
|
@Operation(summary = "报告导出")
|
@GetMapping("/reportAllExport")
|
@PreAuthorize("@ss.hasPermi('business:reportPreparation')")
|
@PersonalScope(permsName = "business:reportPreparation", objectName = ReportPageDto.class, paramName = "createOrderUser")
|
public void reportAllExport(ReportPageDto dto, HttpServletResponse response) throws Exception {
|
insReportService.reportAllExport(dto,response);
|
}
|
}
|