liding
2026-10-26 a7e3413f77a294bd28a951b869e03e4bae671e84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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);
    }
}