zss
2025-03-24 d5118e985c33969e39085390e01ab534ad7f7301
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
package com.yuanchu.mom.controller;
 
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.mom.annotation.ValueAuth;
import com.yuanchu.mom.annotation.ValueClassify;
import com.yuanchu.mom.dto.InsReportDto;
import com.yuanchu.mom.dto.ReportPageDto;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.service.InsReportService;
import com.yuanchu.mom.utils.JackSonUtil;
import com.yuanchu.mom.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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;
 
    @ValueClassify("报告编制")
    @ApiOperation(value = "查询检验报告数据")
    @PostMapping("/pageInsReport")
    public Result pageInsReport(@RequestBody Map<String, Object> data) throws Exception {
        Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class);
        ReportPageDto reportPageDto = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), ReportPageDto.class);
        return Result.success(insReportService.pageInsReport(page, reportPageDto));
    }
 
    @ValueClassify("报告编制")
    @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();
            }
            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("文件上传失败");
        }
    }
 
    @ValueClassify("报告编制")
    @ApiOperation(value = "报告还原")
    @PostMapping("/upReportUrl")
    public Result upReportUrl(Integer id) {
        return Result.success(insReportService.upReportUrl(id));
    }
 
    /*@ValueClassify("报告编制")
    @ApiOperation(value = "报告在线编制")
    @GetMapping("/upReportFile")
    public Result upReportFile() {
        return Result.success();
    }*/
 
    @ValueClassify("报告编制")
    @ApiOperation(value = "提交")
    @PostMapping("/writeReport")
    public Result writeReport(Integer id) {
        return Result.success(insReportService.writeReport(id));
    }
 
    @ValueClassify("报告编制")
    @ApiOperation(value = "审核")
    @PostMapping("/examineReport")
    public Result examineReport(Integer id, Integer isExamine, String examineTell) {
        return Result.success(insReportService.examineReport(id, isExamine, examineTell));
    }
 
    @ValueClassify("报告编制")
    @ApiOperation(value = "批准")
    @PostMapping("/ratifyReport")
    public Result ratifyReport(Integer id, Integer isRatify, String ratifyTell,String sealUrl) {
        return Result.success(insReportService.ratifyReport(id, isRatify, ratifyTell,sealUrl));
    }
 
    @RequestMapping("/onlyOffice/save")
    @ValueAuth
    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}");
        }
    }
 
    @ValueAuth
    @ApiOperation(value = "报告批量下载")
    @GetMapping("/downAll")
    public Result downAll(String ids) {
        return Result.success(insReportService.downAll(ids));
    }
 
    @ValueAuth
    @ApiOperation(value = "报告批量上传")
    @PostMapping("/upAll")
    public Result upAll(MultipartFile file) throws IOException {
        return Result.success(insReportService.upAll(file));
    }
 
    @ValueAuth
    @ApiOperation(value = "查出该订单下每个样品下每个站点的检验次数")
    @GetMapping("/getInsOrderStateCount")
    public Result getInsOrderStateCount(Integer id){
        return Result.success(insReportService.getInsOrderStateCount(id));
    }
 
    //取消2.26
    @ValueClassify("报告编制")
    @ApiOperation(value = "判断是否生成总报告")
    @PostMapping("/isReport")
    public Result isReport(@RequestBody InsReportDto insReportDto) {
        return Result.success(insReportService.isReport(insReportDto));
    }
}