zouyu
2025-03-14 f50ebfa99b322690788a3c5cb4e5d8337acdbc64
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
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));
    }
 
 
 
}