zjh
2024-02-28 b0f292b0b4ba853c41f457fe12d7b6f1ce5141b7
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package com.ltkj.web.controller.app;
 
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.core.page.TableDataInfo;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.framework.config.UserHoder;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.One;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTJcImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.session.InMemoryWebSessionStore;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
/**
 * @Author: 西安路泰科技有限公司/lige
 * @Date: 2023/1/10 15:42
 */
 
@RestController
@RequestMapping("/cus/getReport")
@Api(tags = "小程序查看体检报告")
@Slf4j
public class ReportController extends BaseController {
 
    @Resource
    private ITjReportService reportService;
 
    @Resource
    private ITjCustomerService customerService;
    @Autowired
    private ITjOrderService orderService;
 
    @Autowired
    private ITjOrderDetailService detailService;
 
    @Resource
    private ITjProjectService projectService;
 
    @Resource
    private ITjOrderRemarkService remarkService;
 
    @Resource
    private ITjStandardService standardService;
 
    @Resource
    private ITjAdviceService adviceService;
 
    @Resource
    private IDictCompService compService;
 
    @Resource
    private ITjReportTemplateService reportTemplateService;
 
    @Value("${path.filePath}")
    private String value;
 
    /**
     * 小程序查询体检报告列表
     */
    @GetMapping("/getReportList")
    @ApiOperation(value = "小程序-体检报告列表")
    public AjaxResult getReportList(@RequestParam(required = false) @ApiParam(value = "手机号") String cusPhone) {
        Wxuser wxuser = UserHoder.getWxuser();
 
        List<Object> result = new ArrayList<>();
        QueryWrapper<TjCustomer> wq1 = new QueryWrapper<>();
        wq1.eq("cus_phone", wxuser.getPhone());
        List<TjCustomer> list1 = customerService.list(wq1);
        if (list1.size() != 0) {
            for (TjCustomer tjCustomer : list1) {
                Map<String, Object> map = new HashMap<>();
                QueryWrapper<TjOrder> wq2 = new QueryWrapper<>();
                wq2.eq("user_id", tjCustomer.getCusId());
                wq2.eq("check_status", 1);
                wq2.isNotNull("finish_time");
                wq2.orderByDesc("finish_time");
                List<TjOrder> list = orderService.list(wq2);
                if (null != list && list.size() > 0) {
                    TjOrder tjOrder = orderService.list(wq2).get(0);
                    map.put("report", tjOrder);
                    map.put("customer", tjCustomer);
                    result.add(map);
                }
            }
            return AjaxResult.success(result);
        }
        return AjaxResult.error("您还没有体检记录!");
    }
 
 
    /**
     * 小程序查询体检报告列表
     */
    @GetMapping("/getRelativeReportList")
    @ApiOperation(value = "小程序-查询亲友最新报告")
    public AjaxResult getRelativeReportList(@RequestParam @ApiParam(value = "姓名") String cusName, @RequestParam @ApiParam(value = "身份证号") String cusIdcard) {
        LambdaQueryWrapper<TjCustomer> wq1 = new LambdaQueryWrapper<>();
        wq1.eq(TjCustomer::getCusName, cusName);
        wq1.eq(TjCustomer::getCusIdcard, cusIdcard);
        TjCustomer customer = customerService.getOne(wq1);
        if (null != customer) {
            Map<String, Object> map = new HashMap<>();
            QueryWrapper<TjOrder> wq2 = new QueryWrapper<>();
            wq2.eq("user_id", customer.getCusId());
            wq2.eq("check_status", 1);
            wq2.isNotNull("finish_time");
            wq2.orderByDesc("finish_time");
            List<TjOrder> list = orderService.list(wq2);
            if (null != list && list.size() > 0) {
                TjOrder tjOrder = orderService.list(wq2).get(0);
                map.put("report", tjOrder);
                map.put("customer", customer);
                return AjaxResult.success(map);
            }
            return AjaxResult.success("体检报告暂未生成");
        }
        return AjaxResult.success("暂时没有体检记录!");
    }
 
    /**
     * 小程序点击体检报告查询详情
     */
    @GetMapping("/getReportByTjNumber")
    @ApiOperation(value = "小程序-体检报告查询详情")
    public AjaxResult getReportByTjNumber(@RequestParam @ApiParam(value = "体检号") String tjNumber) {
        Map<String, Object> objectMap = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<>();
        LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>();
        wq1.eq(TjOrder::getTjNumber, tjNumber);
        wq1.eq(TjOrder::getCheckStatus, 1);
        TjOrder one = orderService.getOne(wq1);
        if (one == null) {
            return AjaxResult.success("体检暂未完成!!");
        }
        LambdaQueryWrapper<TjCustomer> wq22 = new LambdaQueryWrapper<>();
        wq22.eq(TjCustomer::getCusId, one.getUserId());
        TjCustomer customer = customerService.getOne(wq22);
        LambdaQueryWrapper<TjOrderRemark> wqm = new LambdaQueryWrapper<>();
        wqm.eq(TjOrderRemark::getTjNumber, tjNumber);
        List<TjOrderRemark> remarkList = remarkService.list(wqm);
        List<Map<String, Object>> abnormalList = new ArrayList<>();
        if (null != remarkList && remarkList.size() > 0) {
            for (TjOrderRemark remark : remarkList) {
                Map<String, Object> parent = new HashMap<>();
                Map<String, Object> parent1 = new HashMap<>();
                TjProject tjProject = projectService.getById(remark.getProId());
                if (null != tjProject) {
                    parent.put("parent", tjProject.getProName());
                    parent1.put("parent", tjProject.getProName());
                } else {
                    parent.put("parent", null);
                    parent1.put("parent", null);
                }
                LambdaQueryWrapper<TjProject> wq2 = new LambdaQueryWrapper<>();
                wq2.eq(TjProject::getProParentId, remark.getProId());
                List<Long> sonsTjProjectList = null;
                if (null != projectService.list(wq2) && projectService.list(wq2).size() > 0) {
                    sonsTjProjectList = projectService.list(wq2).stream().map(TjProject::getProId).collect(Collectors.toList());
                }
                if (sonsTjProjectList == null) {
                    log.info("我报空指针了::::::::::::" + remark.toString());
                    continue;
                }
                LambdaQueryWrapper<TjOrderDetail> wq = new LambdaQueryWrapper<>();
                wq.eq(TjOrderDetail::getOrderId, one.getOrderId());
                wq.in(TjOrderDetail::getProId, sonsTjProjectList);
                List<TjOrderDetail> tjOrderDetails = detailService.list(wq);
                if (null != tjOrderDetails && tjOrderDetails.size() > 0) {
                    List<TjOrderDetail> abnormals = new ArrayList<>();
                    for (TjOrderDetail tjOrderDetail : tjOrderDetails) {
                        if (tjOrderDetail.getExceptionDesc() == 1) {
                            abnormals.add(tjOrderDetail);
                            parent1.put("abnormalList", abnormals);
                            abnormalList.add(parent1);
                        }
                        LambdaQueryWrapper<TjProject> wqqqq = new LambdaQueryWrapper<>();
                        wqqqq.eq(TjProject::getProId, tjOrderDetail.getProId());
                        tjOrderDetail.setProject(projectService.getOne(wqqqq));
                        LambdaQueryWrapper<TjStandard> wq6 = new LambdaQueryWrapper<>();
                        wq6.eq(TjStandard::getProId, tjOrderDetail.getProId());
                        List<TjStandard> list2 = standardService.list(wq6);
                        if (list2.size() == 0) {
                            tjOrderDetail.setStandard(null);
                        } else if (list2.size() == 1) {
                            tjOrderDetail.setStandard(list2.get(0));
                        } else {
                            for (TjStandard tjStandard : list2) {
                                LambdaQueryWrapper<TjStandard> wq8 = new LambdaQueryWrapper<>();
                                if (tjStandard.getTjSex() != null) {
                                    wq8.eq(TjStandard::getTjSex, customer.getCusSex());
                                }
                                if (tjStandard.getTjType() != null) {
                                    wq8.eq(TjStandard::getTjType, StringUtils.getAgeType(DateUtil.ageOfNow(customer.getCusBrithday())));
                                }
                                tjOrderDetail.setStandard(standardService.getOne(wq8));
                            }
                        }
                    }
                    LambdaQueryWrapper<TjAdvice> wq3 = new LambdaQueryWrapper<>();
                    wq3.eq(TjAdvice::getProId, remark.getProId());
                    parent.put("sons", tjOrderDetails);
                    parent.put("parentAdvice", adviceService.list(wq3));
                    parent.put("advice", remark.getSummary());
                    list.add(parent);
                } else {
                    return AjaxResult.success("该客户在没有体检项目数据");
                }
            }
            objectMap.put("list", list);
            objectMap.put("inspectionAdvice", one.getCheckAdvice());
            objectMap.put("tjAbnormal", abnormalList);
            objectMap.put("customter", customer);
            return AjaxResult.success(objectMap);
        }
        return AjaxResult.success("该客户在没有体检项目数据!");
    }
 
    /**
     * 小程序点击体检报告查询详情,显示身高体重体重指数收缩压舒张压
     */
    @GetMapping("/getShenGaoTiZhong")
    @ApiOperation(value = "小程序-体检报告查询详情")
    public AjaxResult getShenGaoTiZhong(@RequestParam @ApiParam(value = "体检号") String tjNumber) {
        Map<String, Object> objectMap = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<>();
        LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>();
        wq1.eq(TjOrder::getTjNumber, tjNumber);
        wq1.eq(TjOrder::getCheckStatus, 1);
        TjOrder one = orderService.getOne(wq1);
        if (one == null) {
            return AjaxResult.success("体检暂未完成!!");
        }
 
        LambdaQueryWrapper<TjOrderDetail> wq = new LambdaQueryWrapper<>();
        wq.eq(TjOrderDetail::getOrderId, one.getOrderId());
        wq.in(TjOrderDetail::getProId, "1633660948860522524");
        final TjOrderDetail one1 = detailService.getOne(wq);
        if (one1== null){
            objectMap.put("shenggao", "无");
        }else {
            objectMap.put("shenggao", one1.getProResult());
        }
 
 
        LambdaQueryWrapper<TjOrderDetail> wq2 = new LambdaQueryWrapper<>();
        wq2.eq(TjOrderDetail::getOrderId, one.getOrderId());
        wq2.in(TjOrderDetail::getProId, "1633660948860522525");
        final TjOrderDetail one2 = detailService.getOne(wq2);
        if (one2==null){
            objectMap.put("tizhong", "无");
        }else {
            objectMap.put("tizhong", one2.getProResult());
        }
 
 
        LambdaQueryWrapper<TjOrderDetail> wq3 = new LambdaQueryWrapper<>();
        wq3.eq(TjOrderDetail::getOrderId, one.getOrderId());
        wq3.in(TjOrderDetail::getProId, "1633660948860522526");
        final TjOrderDetail one3 = detailService.getOne(wq3);
        if (one3==null){
            objectMap.put("tizhongzhishu", "无");
        }else {
            objectMap.put("tizhongzhishu", one3.getProResult());
        }
 
 
 
        LambdaQueryWrapper<TjOrderDetail> wq4 = new LambdaQueryWrapper<>();
        wq4.eq(TjOrderDetail::getOrderId, one.getOrderId());
        wq4.in(TjOrderDetail::getProId, "1633660948860522527");
        final TjOrderDetail one4 = detailService.getOne(wq4);
        if (one4==null){
            objectMap.put("shousuoya", "无");
        }else {
            objectMap.put("shousuoya", one4.getProResult());
        }
 
 
 
        LambdaQueryWrapper<TjOrderDetail> wq5 = new LambdaQueryWrapper<>();
        wq5.eq(TjOrderDetail::getOrderId, one.getOrderId());
        wq5.in(TjOrderDetail::getProId, "1633660948860522528");
        final TjOrderDetail one5 = detailService.getOne(wq5);
        if (one5==null){
            objectMap.put("shuzhangya","无");
        }else {
            objectMap.put("shuzhangya", one5.getProResult());
        }
 
 
        return AjaxResult.success(objectMap);
 
    }
 
 
    /**
     * 小程序点击下载报告
     */
    @GetMapping("/downloadReport")
    @ApiOperation(value = "小程序-下载报告")
    public AjaxResult downloadReport(@RequestParam @ApiParam(value = "体检号") String tjNumber) {
        Map<String, Object> map = new HashMap<>();
        return AjaxResult.success(map);
    }
 
 
    /**
     * 小程序查询体检历史报告列表
     */
    @GetMapping("/getHistryReportList")
    @ApiOperation(value = "小程序-体检历史报告列表")
    public AjaxResult getHistryReportList(@RequestParam @ApiParam(value = "手机号") String cusPhone) {
        List<Object> result = new ArrayList<>();
        QueryWrapper<TjCustomer> wq1 = new QueryWrapper<>();
        wq1.eq("cus_phone", cusPhone);
        List<TjCustomer> list1 = customerService.list(wq1);
        if (list1.size() != 0) {
            for (TjCustomer tjCustomer : list1) {
                Map<String, Object> map = new HashMap<>();
                QueryWrapper<TjOrder> wq2 = new QueryWrapper<>();
                wq2.eq("user_id", tjCustomer.getCusId());
                wq2.eq("check_status", 1);
                wq2.isNotNull("finish_time");
                wq2.orderByDesc("finish_time");
                List<TjOrder> list = orderService.list(wq2);
                if (null != list && list.size() > 0) {
                    map.put("report", list);
                    map.put("customer", tjCustomer);
                    result.add(map);
                }
            }
            return AjaxResult.success(result);
        }
        return AjaxResult.success("您还没有体检记录!");
    }
}