lige
2024-01-30 62d6b0b699437395e62ea3aa1867d9bc5a592a9e
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package com.ltkj.web.controller.system;
 
import java.io.*;
import java.net.URL;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
 
import cn.hutool.core.date.DateTime;
import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.entity.SysDept;
import com.ltkj.common.core.domain.entity.SysUser;
import com.ltkj.common.utils.SecurityUtils;
import com.ltkj.hosp.domain.TjReport;
import com.ltkj.hosp.domain.TjReservation;
import com.ltkj.web.config.pdfutils.PDFBinaryUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ltkj.common.annotation.Log;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.enums.BusinessType;
import com.ltkj.hosp.domain.TjReportTemplate;
import com.ltkj.hosp.service.ITjReportTemplateService;
import com.ltkj.common.utils.poi.ExcelUtil;
import com.ltkj.common.core.page.TableDataInfo;
 
/**
 * templateController
 *
 * @author ltkj_赵佳豪&李格
 * @date 2022-12-12
 */
@RestController
@RequestMapping("/hosp/template")
@Api(tags = "体检报告模板")
public class TjReportTemplateController extends BaseController {
    @Autowired
    private ITjReportTemplateService tjReportTemplateService;
 
    @Value("${path.filePath}")
    private String value;
 
    /**
     * 查询template列表
     */
    //@PreAuthorize("@ss.hasPermi('hosp:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(TjReportTemplate tjReportTemplate) {
        startPage();
        List<TjReportTemplate> list = tjReportTemplateService.selectTjReportTemplateList(tjReportTemplate);
        return getDataTable(list);
    }
 
 
    /**
     * 获取template详细信息
     */
    //@PreAuthorize("@ss.hasPermi('hosp:template:query')")
    @GetMapping(value = "/{reportTemId}")
    public AjaxResult getInfo(@PathVariable("reportTemId") Long reportTemId) {
        return success(tjReportTemplateService.selectTjReportTemplateByReportTemId(reportTemId));
    }
 
 
    /**
     * 删除template
     */
    @Log(title = "template", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reportTemIds}")
    public AjaxResult remove(@PathVariable Long[] reportTemIds) {
        return toAjax(tjReportTemplateService.deleteTjReportTemplateByReportTemIds(reportTemIds));
    }
 
 
    /**
     * 启用状态修改
     */
    @PutMapping("/changeStatus")
    @ApiOperation("启用状态修改")
    public AjaxResult changeStatus(@RequestBody TjReportTemplate tjReportTemplate) {
        //判断是启用
        if ("0".equals(tjReportTemplate.getOpen())){
            TjReportTemplate byId = tjReportTemplateService.getById(tjReportTemplate.getReportTemId());
            LambdaQueryWrapper<TjReportTemplate> we = new LambdaQueryWrapper<>();
            we.eq(TjReportTemplate::getFlag, byId.getFlag());
            we.eq(TjReportTemplate::getOpen, "0");
            List<TjReportTemplate> list = tjReportTemplateService.list(we);
            if (list.size()!=0){
                return AjaxResult.error("同类型模板只能启用一个,请查看其他模板启用状态!");
            }
        }
        tjReportTemplate.setUpdateBy(getUsername());
        tjReportTemplate.setUpdateTime(new DateTime());
        if (!tjReportTemplateService.updateById(tjReportTemplate)) {
            return AjaxResult.error("修改失败");
        }
        return AjaxResult.success("修改成功");
    }
 
 
    /**
     * 模板修改接口
     */
    @PostMapping("/edit")
    @ApiOperation(value = "模板修改接口")
    public AjaxResult edit(@RequestBody TjReportTemplate tjReportTemplate) {
        if (tjReportTemplateService.updateById(tjReportTemplate)) {
            return AjaxResult.success("操作成功");
        }
        return AjaxResult.error("操作失败");
    }
 
 
    @GetMapping("/preShow/{flag}/{reportTemId}")
    @ApiOperation(value = "模板预览")
    public void preShow(HttpServletResponse response, @PathVariable("flag") boolean flag, @PathVariable("reportTemId") String reportTemId) {
        LambdaQueryWrapper<TjReportTemplate> we = new LambdaQueryWrapper<>();
        we.eq(TjReportTemplate::getReportTemId, reportTemId);
        TjReportTemplate one = tjReportTemplateService.getOne(we);
        if (one == null) {
            return;
        }
        String userId = SecurityUtils.getLoginUser().getUsername();
        PDFBinaryUtil.base64StringToPDF(one.getTemplate(), FileUtil.mkdir(value).getPath() + "\\" + userId + reportTemId + "_模板预览.pdf");
        String filePath = value + "\\" + userId + reportTemId + "_模板预览.pdf";
        File f = new File(filePath);
        if (filePath.isEmpty()) {
            System.out.println("文件不存在!");
            return;
        }
        BufferedInputStream br = null;
        OutputStream out = null;
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(f);
            br = new BufferedInputStream(fileInputStream);
            byte[] bs = new byte[1024];
            int len = 0;
            response.reset(); // 非常重要
            if (flag) {
                // 在线打开方式
                URL u = new URL("file:///" + filePath);
                //System.out.println(u);
                String contentType = u.openConnection().getContentType();
                response.setContentType(contentType);
                response.setHeader("Content-Disposition", "inline;filename="
                        + userId + reportTemId + ".pdf");
            } else {
                // 纯下载方式
                response.setContentType("application/x-msdownload");
                response.setContentType("application/pdf;charset=utf-8");
                response.setHeader("Content-Disposition", "attachment;filename="
                        + userId + reportTemId + ".pdf");
            }
            out = response.getOutputStream();
            while ((len = br.read(bs)) > 0) {
                out.write(bs, 0, len);
            }
            out.flush();
            out.close();
            br.close();
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
            //System.out.println("pdf处理文件异常" + e);
        } finally {
            if (out != null) {
                try {
                    out.close();
                    br.close();
                    fileInputStream.close();
 
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
 
 
    @GetMapping("/zhiYeTable/{flag}")
    @ApiOperation(value = "下载职业健康表")
    public void zhiYeTable(HttpServletResponse response, @PathVariable("flag") boolean flag) {
 
        LambdaQueryWrapper<TjReportTemplate> we = new LambdaQueryWrapper<>();
        we.eq(TjReportTemplate::getName, "职业健康体检个人信息表");
        TjReportTemplate one = tjReportTemplateService.getOne(we);
        if (one == null) {
            return;
        }
        String userId = SecurityUtils.getLoginUser().getUsername();
        PDFBinaryUtil.base64StringToPDF(one.getTemplate(), FileUtil.mkdir(value).getPath() + "\\" + userId + "_职业健康体检个人信息表.pdf");
        String filePath = value + "\\" + userId + "_职业健康体检个人信息表.pdf";
        File f = new File(filePath);
        if (filePath.isEmpty()) {
            System.out.println("文件不存在!");
            return;
        }
        BufferedInputStream br = null;
        OutputStream out = null;
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(f);
            br = new BufferedInputStream(fileInputStream);
            byte[] bs = new byte[1024];
            int len = 0;
            response.reset(); // 非常重要
            if (flag) {
                // 在线打开方式
                URL u = new URL("file:///" + filePath);
                //System.out.println(u);
                String contentType = u.openConnection().getContentType();
                response.setContentType(contentType);
                response.setHeader("Content-Disposition", "inline;filename="
                        + userId +"_职业健康体检个人信息表.pdf");
            } else {
                // 纯下载方式
                response.setContentType("application/x-msdownload");
                response.setContentType("application/pdf;charset=utf-8");
                response.setHeader("Content-Disposition", "attachment;filename="
                        + userId +"_职业健康体检个人信息表.pdf");
            }
            out = response.getOutputStream();
            while ((len = br.read(bs)) > 0) {
                out.write(bs, 0, len);
            }
            out.flush();
            out.close();
            br.close();
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
            //System.out.println("pdf处理文件异常" + e);
        } finally {
            if (out != null) {
                try {
                    out.close();
                    br.close();
                    fileInputStream.close();
 
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
 
 
}