zjh
2024-07-19 2f9691b8de0e2800f22ce96768aacfd129f02b3c
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
package com.ltkj.web.controller.system;
 
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.domain.AjaxResult;
import com.ltkj.common.core.domain.entity.SysDept;
import com.ltkj.common.core.domain.entity.SysUser;
import com.ltkj.common.core.redis.RedisCache;
import com.ltkj.common.utils.DateUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.dto.TjChartVo;
import com.ltkj.hosp.service.*;
import com.ltkj.hosp.vodomain.*;
import com.ltkj.system.service.ISysDeptService;
import com.ltkj.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Author: 西安路泰科技有限公司/赵佳豪
 * @Date: 2022/12/14 13:50
 */
@RestController
@RequestMapping("/home/page")
@Api(tags = "体检后台管理端首页面数据汇总")
public class TjHomePageController {
 
    @Resource
    private ITjOrderService orderService;
    @Resource
    private ITjOrderDetailService detailService;
    @Resource
    private ITjCustomerService customerService;
    @Resource
    private ITjProjectService projectService;
    @Resource
    private RedisCache redisCache;
    @Resource
    private TjAsyncService asyncService;
    @Resource
    private ISysDeptService deptService;
    @Resource
    private ISysUserService userService;
    @Resource
    private ITjOrderRemarkService remarkService;
 
    @Resource
    private ITjFlowingWaterService tjFlowingWaterService;
 
 
    @GetMapping("/GetChartByDate")
    @ApiOperation(value = "条形统计时间段内个人和团队体检数")
//    @PreAuthorize("@ss.hasPermi('home:page:GetChartByDate')")
    public List<Map<Object, Object>> GetChartByDate(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) throws ParseException {
        List<Map<Object, Object>> list = new ArrayList<>();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (startDate != null & endDate != null) {
            for (String date : findDates(startDate, endDate)) {
                ChartVO chartVO = new ChartVO();
                Map<Object, Object> result = new HashMap<>();
                Date beginTime = DateUtils.parseDate(date + " 00:00:00");
                Date endTime = DateUtils.parseDate(date + " 23:59:59");
                QueryWrapper<TjOrder> queryWrapper1 = new QueryWrapper<>();
                queryWrapper1.ge("finish_time", beginTime);
                queryWrapper1.lt("finish_time", endTime);
                queryWrapper1.eq("tj_type", 2);
                Integer personCount = orderService.count(queryWrapper1);
                QueryWrapper<TjOrder> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.ge("finish_time", beginTime);
                queryWrapper2.lt("finish_time", endTime);
                queryWrapper2.eq("tj_type", 1);
                Integer teamCount = orderService.count(queryWrapper2);
 
                chartVO.setPersonNum(personCount);
                chartVO.setTeamNum(teamCount);
                result.put("date", date);
                result.put("num", chartVO);
                list.add(result);
            }
            return list;
        } else {
            for (int i = 7; i >= 0; i--) {
                ChartVO chartVO = new ChartVO();
                Map<Object, Object> result = new HashMap<>();
 
                String formatdate = dateFormat.format(getFrontDay(new Date(), i));
                Date beginTime = DateUtils.parseDate(formatdate + " 00:00:00");
                Date endTime = DateUtils.parseDate(formatdate + " 23:59:59");
                QueryWrapper<TjOrder> queryWrapper1 = new QueryWrapper<>();
                queryWrapper1.ge("finish_time", beginTime);
                queryWrapper1.lt("finish_time", endTime);
                queryWrapper1.eq("tj_type", 2);
                Integer personCount = orderService.count(queryWrapper1);
 
                QueryWrapper<TjOrder> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.ge("finish_time", beginTime);
                queryWrapper2.lt("finish_time", endTime);
                queryWrapper2.eq("tj_type", 1);
                Integer teamCount = orderService.count(queryWrapper2);
 
                chartVO.setPersonNum(personCount);
                chartVO.setTeamNum(teamCount);
                result.put("date", formatdate);
                result.put("num", chartVO);
 
                list.add(result);
            }
            return list;
        }
    }
 
    //传参数 开始日期和结束日期  将中间的日期放入list集合
    public static List<String> findDates(String beginTime, String endTime) throws ParseException {
        List<String> allDate = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dBegin = sdf.parse(beginTime);
        Date dEnd = sdf.parse(endTime);
        allDate.add(sdf.format(dBegin));
        Calendar calBegin = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calEnd.setTime(dEnd);
        // 测试此日期是否在指定日期之后
        while (dEnd.after(calBegin.getTime())) {
            // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            allDate.add(sdf.format(calBegin.getTime()));
        }
        return allDate;
    }
 
    //返回某个日期前几天的日期
    public static Date getFrontDay(Date date, int i) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.set(Calendar.DATE, cal.get(Calendar.DATE) - i);
        return cal.getTime();
    }
 
 
   /* @GetMapping("/getTjDeptCountList")
    @ApiOperation(value = "体检科室工作量数据统计接口")
//    @PreAuthorize("@ss.hasPermi('home:page:getTjDeptCountList')")
    public AjaxResult getTjDeptCountList(@RequestParam(required = false) @ApiParam(value = "开始时间") String beginTime, @RequestParam(required = false) @ApiParam(value = "结束时间") String endTime) {
        List<SysDept> deptList = deptService.list();
        if (null != deptList && deptList.size() > 0) {
            List<TjDeptCountVo> deptCountVoList = new ArrayList<>();
            for (SysDept sysDept : deptList) {
                LambdaQueryWrapper<SysUser> wq0 = new LambdaQueryWrapper<>();
                wq0.eq(SysUser::getDeptId, sysDept.getDeptId());
                List<SysUser> sysUserList = userService.list(wq0);
                if (null == sysUserList) {
                    return AjaxResult.error("该科室下没有人员");
                }
                TjDeptCountVo deptCountVo = new TjDeptCountVo();
                deptCountVo.setDoctorName("/");
                deptCountVo.setDeptName(sysDept.getDeptName());
                LambdaQueryWrapper<TjProject> wq1 = new LambdaQueryWrapper<>();
                wq1.eq(TjProject::getDeptId, sysDept.getDeptId());
                List<TjProject> list = projectService.list(wq1);
 
                LambdaQueryWrapper<TjOrderDetail> wq2 = new LambdaQueryWrapper<>();
                LambdaQueryWrapper<TjOrderDetail> wq3 = new LambdaQueryWrapper<>();
                wq2.eq(TjOrderDetail::getTjStatus, 0);
                if (null != beginTime && null != endTime) {
                    wq2.between(TjOrderDetail::getCreateTime, DateUtil.parse(beginTime), DateUtil.parse(endTime));
                    wq3.between(TjOrderDetail::getCreateTime, DateUtil.parse(beginTime), DateUtil.parse(endTime));
                } else {
                    wq2.between(TjOrderDetail::getCreateTime, DateUtil.lastWeek(), DateUtil.now());
                    wq3.between(TjOrderDetail::getCreateTime, DateUtil.lastWeek(), DateUtil.now());
                }
                wq3.eq(TjOrderDetail::getTjStatus, 1);
                if (null != list && list.size() > 0) {
                    //获取该科室下的项目
                    List<Long> ksproList = list.stream().map(TjProject::getProId).collect(Collectors.toList());
                    wq2.in(TjOrderDetail::getProId, ksproList);
                    wq3.in(TjOrderDetail::getProId, ksproList);
                } else {
                    continue;
                }
                LambdaQueryWrapper<TjOrderRemark> wq4 = new LambdaQueryWrapper<>();
                wq4.eq(TjOrderRemark::getDeptId, sysDept.getDeptId());
 
                List<TjOrderDetail> detailList = detailService.list(wq2);
                List<TjOrderDetail> detailList1 = detailService.list(wq3);
                List<TjOrderRemark> remarkList = remarkService.list(wq4);
 
                if (detailList == null && detailList1 != null && remarkList != null) {
                    deptCountVo.setTjCount(0);
                    deptCountVo.setTjFinishCount(detailList1.size());
                    deptCountVo.setTjFinishRate("0%");
                    deptCountVo.setReportCount(remarkList.size());
                    deptCountVo.setReportRate("0%");
                } else if (detailList1 == null && detailList != null && remarkList != null) {
                    deptCountVo.setTjCount(detailList.size());
                    deptCountVo.setTjFinishCount(0);
                    deptCountVo.setTjFinishRate("0%");
                    deptCountVo.setReportCount(remarkList.size());
                    deptCountVo.setReportRate((remarkList.size()) / (detailList.size()) * 100 + "%");
                } else if (detailList1 != null && detailList != null && remarkList == null) {
                    deptCountVo.setTjCount(detailList.size());
                    deptCountVo.setTjFinishCount(detailList1.size());
                    deptCountVo.setTjFinishRate((detailList1.size()) / (detailList.size()) * 100 + "%");
                    deptCountVo.setReportCount(0);
                    deptCountVo.setReportRate("0%");
                } else {
                    deptCountVo.setTjCount(0);
                    deptCountVo.setTjFinishCount(0);
                    deptCountVo.setTjFinishRate("0%");
                    deptCountVo.setReportCount(0);
                    deptCountVo.setReportRate("0%");
                }
                deptCountVoList.add(deptCountVo);
            }
            return AjaxResult.success("操作成功", deptCountVoList);
        }
        return AjaxResult.error();
    }*/
 
    /*@GetMapping("/GetCheckDate")
    @ApiOperation(value = "报告工作量统计")
//    @PreAuthorize("@ss.hasPermi('home:page:GetCheckDate')")
    public List<CheckDataVO> GetCheckDate(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
        List<CheckDataVO> list = new ArrayList<>();
        if (startDate != null & endDate != null) {
            Date beginTime = DateUtils.parseDate(startDate + " 00:00:00");
            Date endTime = DateUtils.parseDate(endDate + " 23:59:59");
            QueryWrapper<TjOrder> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.ge("finish_time", beginTime);
            queryWrapper1.lt("finish_time", endTime);
            List<TjOrder> list1 = orderService.list(queryWrapper1);
            //不可重复  所有医生名
            Set<String> collect1 = list1.stream().map(TjOrder::getCheckDoctor).collect(Collectors.toSet());
            for (String s : collect1) {
                QueryWrapper<TjOrder> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.ge("finish_time", beginTime);
                queryWrapper2.lt("finish_time", endTime);
                queryWrapper2.eq("check_doctor", s);
                List<TjOrder> list2 = orderService.list(queryWrapper2);
                CheckDataVO checkDataVO = new CheckDataVO();
                Integer checkCount = 0;
                Integer releaseCount = 0;
                Integer messageCount = 0;
                Integer printCount = 0;
                for (TjOrder tjOrder : list2) {
                    if (s.equals(tjOrder.getCheckDoctor()) && tjOrder.getCheckStatus() == 1) {
                        checkCount++;
                    }
                    if (s.equals(tjOrder.getCheckDoctor()) && tjOrder.getReleaseTime() != null) {
                        releaseCount++;
                    }
                    if (s.equals(tjOrder.getCheckDoctor()) && "1".equals(tjOrder.getSendMessage())) {
                        messageCount++;
                    }
                    //报告生成时间
                    if (s.equals(tjOrder.getCheckDoctor()) && tjOrder.getReportTime() != null) {
                        printCount++;
                    }
                    checkDataVO.setDoctorName(s);
                    checkDataVO.setCheckCount(checkCount);
                    checkDataVO.setReleaseCount(releaseCount);
                    checkDataVO.setMessageCount(messageCount);
                    checkDataVO.setPrintCount(printCount);
 
                }
                list.add(checkDataVO);
            }
 
        } else {
            LambdaQueryWrapper<TjOrder> queryWrapper1 = new LambdaQueryWrapper<>();
            queryWrapper1.between(TjOrder::getFinishTime, DateUtil.lastWeek(), DateUtil.now());
            List<TjOrder> list1 = orderService.list(queryWrapper1);
 
            //List<String> collect = list1.stream().map(TjOrder::getCheckDoctor).collect(Collectors.toList());
            //不可重复  所有医生名
            Set<String> collect1 = list1.stream().map(TjOrder::getCheckDoctor).collect(Collectors.toSet());
            for (String s : collect1) {
                QueryWrapper<TjOrder> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.between("finish_time", DateUtil.lastWeek(), DateUtil.now());
                queryWrapper2.eq("check_doctor", s);
                List<TjOrder> list2 = orderService.list(queryWrapper2);
                CheckDataVO checkDataVO = new CheckDataVO();
                Integer checkCount = 0;
                Integer releaseCount = 0;
                Integer messageCount = 0;
                Integer printCount = 0;
                for (TjOrder tjOrder : list2) {
                    if (s.equals(tjOrder.getCheckDoctor()) && tjOrder.getCheckStatus() == 1) {
                        checkCount++;
                    }
                    if (s.equals(tjOrder.getCheckDoctor()) && tjOrder.getReleaseTime() != null) {
                        releaseCount++;
                    }
                    if (s.equals(tjOrder.getCheckDoctor()) && "1".equals(tjOrder.getSendEmail())) {
                        messageCount++;
                    }
                    if (s.equals(tjOrder.getCheckDoctor()) && tjOrder.getReportTime() != null) {
                        printCount++;
                    }
                    checkDataVO.setDoctorName(s);
                    checkDataVO.setCheckCount(checkCount);
                    checkDataVO.setReleaseCount(releaseCount);
                    checkDataVO.setMessageCount(messageCount);
                    checkDataVO.setPrintCount(printCount);
 
                }
                list.add(checkDataVO);
            }
        }
        return list;
    }*/
 
    @GetMapping("/GetAbnormalData")
    @ApiOperation(value = "体检结果异常数据统计分析")
//    @PreAuthorize("@ss.hasPermi('home:page:GetAbnormalData')")
    public List<AbnormalVO> GetAbnormalData(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
        List<AbnormalVO> list = new ArrayList<>();
        List<TjOrderDetail> list1 = detailService.getTjOrderDetailList(startDate,endDate);
        Set<TjProject> abProLists = new HashSet<>();
        Set<TjProject> ll = new HashSet<>();
        for (TjOrderDetail tjOrderDetail : list1) {
            TjProject one = projectService.selectTjProjectByProId(tjOrderDetail.getProId());
            tjOrderDetail.setProject(one);
            abProLists.add(one);
        }
        for (TjProject abProList : abProLists) {
            if (abProList!=null){
                if (abProList.getProParentId() != 0) {
                    TjProject one = projectService.selectTjProjectByProId(abProList.getProParentId());
                    ll.add(one);
                } else {
                    ll.add(abProList);
                }
            }
 
        }
 
        for (TjProject abProList : ll) {
            Set<Long> lll = new HashSet<>();
            AbnormalVO abnormalVO = new AbnormalVO();
            int TjPersonNum = 0;
            int AbPersonNum = 0;
            Integer AbManNum = 0;
            Integer AbWomanNum = 0;
            Integer AbThNum = 0;
            Integer AbThSeNum = 0;
            Integer AbSeNum = 0;
            for (TjOrderDetail tjOrderDetail : list1) {
                if (tjOrderDetail.getProject().getProParentId().equals(abProList.getProId())) {
                    lll.add(tjOrderDetail.getOrderId());
                    AbPersonNum = lll.size();
                }
                abnormalVO.setAbPersonNum(AbPersonNum);
            }
            abnormalVO.setAbProName(abProList.getProName());
            for (Long aLong : lll) {
                TjOrder one = orderService.selectTjOrderByOrderId(aLong);
                Long userId = one.getUserId();
                TjCustomer one1 = customerService.selectTjCustomerByCusId(userId);
                if (one1.getCusSex() == 0) {
                    AbManNum++;
                } else {
                    AbWomanNum++;
                }
                if (DateUtil.ageOfNow(one1.getCusBrithday()) < 3) {
                    AbThNum++;
                } else if (DateUtil.ageOfNow(one1.getCusBrithday()) >= 3 && DateUtil.ageOfNow(one1.getCusBrithday()) <= 70) {
                    AbThSeNum++;
                } else if (DateUtil.ageOfNow(one1.getCusBrithday()) > 70) {
                    AbSeNum++;
                }
                abnormalVO.setAbManNum(AbManNum);
                abnormalVO.setAbWomanNum(AbWomanNum);
                abnormalVO.setAbSeNum(AbSeNum);
                abnormalVO.setAbThNum(AbThNum);
                abnormalVO.setAbThSeNum(AbThSeNum);
            }
 
            List<TjProject> list3 = projectService.getTjProjectListBySoneId(String.valueOf(abProList.getProId()));
            Set<Long> l = new HashSet<>();
            for (TjProject tjProject : list3) {
                for (TjOrderDetail tjOrderDetail : detailService.list()) {
                    if (tjProject.getProId().equals(tjOrderDetail.getProId())) {
                        l.add(tjOrderDetail.getOrderId());
                        TjPersonNum = l.size();
                    }
                }
            }
            abnormalVO.setTjPersonNum(TjPersonNum);
            list.add(abnormalVO);
        }
        return list;
    }
 
 
    @GetMapping("/getDiseaseList")
    @ApiOperation("根据疾病名称查询相关人员信息接口")
//    @PreAuthorize("@ss.hasPermi('home:page:getDiseaseList')")
    public AjaxResult getDiseaseList(@ApiParam(value = "疾病名称") @RequestParam String disesseName,
                                     @ApiParam(value = "开始时间") @RequestParam(required = false) String beginTime,
                                     @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime) {
        if (null == disesseName) {
            return AjaxResult.error("请输入要查询的内容");
        }
        List<DiseaseVo> diseaseVos = new ArrayList<>();
        LambdaQueryWrapper<TjOrderRemark> wq0 = new LambdaQueryWrapper<>();
        wq0.like(TjOrderRemark::getRemark, disesseName);
        if (null != beginTime && null != endTime) {
            wq0.between(TjOrderRemark::getCreateTime, beginTime, endTime);
        }
        List<TjOrderRemark> remarkList = remarkService.list(wq0);
        if (null != remarkList && remarkList.size() > 0) {
            for (TjOrderRemark orderRemark : remarkList) {
                LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>();
                wq1.eq(TjOrder::getTjNumber, orderRemark.getTjNumber());
                TjOrder tjOrder = orderService.getOne(wq1);
                if (null != tjOrder) {
                    DiseaseVo diseaseVo = new DiseaseVo();
                    TjCustomer customer = customerService.getById(tjOrder.getUserId());
                    diseaseVo.setName(customer.getCusName());
                    diseaseVo.setAge(DateUtil.ageOfNow(customer.getCusBrithday()));
                    diseaseVo.setSex(Math.toIntExact(customer.getCusSex()));
                    diseaseVo.setPhone(customer.getCusPhone());
                    diseaseVo.setTjTime(tjOrder.getFinishTime());
                    if(tjOrder.getIsReturn()==0){
                        diseaseVo.setType("已复检");
                    }else {
                        diseaseVo.setType("未复检");
                    }
                    diseaseVos.add(diseaseVo);
                }
            }
            return AjaxResult.success(diseaseVos);
        }
        return AjaxResult.success("暂时没有数据");
    }
 
    /**
     * 首页折线图数据
     */
    @GetMapping("/getLineChart")
    @ApiOperation(value = "首页折线图数据")
    public AjaxResult getLineChart() {
        asyncService.getLineChart();
        if(redisCache.hasKey("getLineChart")){
            return redisCache.getCacheObject("getLineChart");
        }
        return getResult();
    }
 
    private AjaxResult getResult() {
//        List<Map<Object, Object>> line = orderService.getLine();
        List<LineChartsVo> line = orderService.getLine();
        Collections.reverse(line);
        return AjaxResult.success("折线图数据", line);
    }
 
    @GetMapping("/getPieChart")
    @ApiOperation(value = "首页饼状图登记人数接口")
    public AjaxResult getPieChart() {
        asyncService.getPieChart();
        if(redisCache.hasKey("getPieChart")){
            return redisCache.getCacheObject("getPieChart");
        }
        return getAjaxResult();
    }
 
    private AjaxResult getAjaxResult() {
        Map<String, Object> map = new HashMap<>();
 
        //获取体检登记数
        LambdaQueryWrapper<TjOrder> wq0 = new LambdaQueryWrapper<>();
        wq0.between(TjOrder::getCreateTime, DateUtil.lastMonth(), DateUtil.now());
        List<TjOrder> orderCountList = orderService.list(wq0);
        if (null != orderCountList && orderCountList.size() > 0) {
            List<PieChartVo> pieChartVoList = getTjorderCountMap(orderCountList);
            map.put("tjdj", pieChartVoList);
        } else {
            map.put("tjdj", 0);
        }
        //获取体检异常数
        LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>();
        wq1.between(TjOrder::getFinishTime, DateUtil.lastMonth(), DateUtil.now());
        wq1.eq(TjOrder::getCheckStatus, 1);
        List<TjOrder> orderAbnormalCountList = orderService.list(wq1);
        if (null != orderAbnormalCountList && orderAbnormalCountList.size() > 0) {
            List<PieChartVo> pieChartVoList = getTjorderAbnormalCountMap(orderAbnormalCountList);
            map.put("tjyc", pieChartVoList);
        } else {
            map.put("tjyc", 0);
        }
 
        return AjaxResult.success(map);
    }
 
    //获取体检登记数
    private List<PieChartVo> getTjorderCountMap(List<TjOrder> orderList) {
        int a = 0;
        int b = 0;
        int c = 0;
        int d = 0;
        int e = 0;
        Map<String, Object> map = null;
        for (TjOrder tjOrder : orderList) {
            map = new HashMap<>();
            TjCustomer customer = customerService.getById(tjOrder.getUserId());
            if (null != customer) {
                int age = DateUtil.ageOfNow(customer.getCusBrithday());
                if (age >= 0 && age <= 3) {
                    a += 1;
                } else if (age > 3 && age <= 16) {
                    b += 1;
                } else if (age > 16 && age <= 40) {
                    c += 1;
                } else if (age > 40 && age <= 60) {
                    d += 1;
                } else {
                    e += 1;
                }
            }
            map.put("0-3岁", a);
            map.put("3-16岁", b);
            map.put("16-40岁", c);
            map.put("40-60岁", d);
            map.put("60岁以上", e);
        }
        List<PieChartVo> pieChartVoList = new ArrayList<>();
        assert map != null;
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            PieChartVo pieChartVo = new PieChartVo();
            pieChartVo.setName(entry.getKey());
            pieChartVo.setCount((Integer) entry.getValue());
            pieChartVoList.add(pieChartVo);
        }
        return pieChartVoList;
    }
 
    //获取体检异常数
    private List<PieChartVo> getTjorderAbnormalCountMap(List<TjOrder> orderList) {
        int a = 0;
        int b = 0;
        int c = 0;
        int d = 0;
        int e = 0;
        Map<String, Object> map = null;
        for (TjOrder tjOrder : orderList) {
            map = new HashMap<>();
            LambdaQueryWrapper<TjOrderDetail> wq = new LambdaQueryWrapper<>();
            wq.eq(TjOrderDetail::getOrderId, tjOrder.getOrderId());
            wq.eq(TjOrderDetail::getExceptionDesc, 1);
            List<TjOrderDetail> list = detailService.list(wq);
            if (null != list && list.size() > 0) {
                TjCustomer customer = customerService.getById(tjOrder.getUserId());
                if (null != customer) {
                    int age = DateUtil.ageOfNow(customer.getCusBrithday());
                    if (age >= 0 && age <= 3) {
                        a += 1;
                    } else if (age > 3 && age <= 16) {
                        b += 1;
                    } else if (age > 16 && age <= 40) {
                        c += 1;
                    } else if (age > 40 && age <= 60) {
                        d += 1;
                    } else {
                        e += 1;
                    }
                }
                map.put("0-3岁", a);
                map.put("3-16岁", b);
                map.put("16-40岁", c);
                map.put("40-60岁", d);
                map.put("60岁以上", e);
            }
        }
        List<PieChartVo> pieChartVoList = new ArrayList<>();
        assert map != null;
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            PieChartVo pieChartVo = new PieChartVo();
            pieChartVo.setName(entry.getKey());
            pieChartVo.setCount((Integer) entry.getValue());
            pieChartVoList.add(pieChartVo);
        }
        return pieChartVoList;
    }
 
 
    /**
     * 查询今日待检
     *
     * @return
     */
    @GetMapping("/tobeToday")
    @ApiOperation(value = "查询今日待检")
    public Integer ToBeToday() {
        //当前日期拼接开始和结束时间
        //时间字符串类型转换时间类型
        return orderService.count(new QueryWrapper<TjOrder>()
                .between("create_time", DateUtil.beginOfDay(new Date()),
                        DateUtil.endOfDay(new Date()))
                .isNotNull("finish_time")
                .eq("check_status", 0)
                .ne("tj_category","13"));
    }
 
    /**
     * 查询今日已检
     *
     * @return
     */
    @GetMapping("/checkedToday")
    @ApiOperation(value = "查询今日已检")
    public Integer checkedToday() {
        //当前日期拼接开始和结束时间
        //时间字符串类型转换时间类型
        return orderService.count(new QueryWrapper<TjOrder>()
                .isNotNull("finish_time")
                .between("create_time", DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()))
                .last("and (check_status=1 OR tj_category=13)"));
    }
 
    /**
     * 查询今日报告
     */
    @GetMapping("/reportToday")
    @ApiOperation(value = "查询今日报告")
    public Integer ReportToday() {
        //当前日期拼接开始和结束时间
        //时间字符串类型转换时间类型
        return orderService.count(new QueryWrapper<TjOrder>()
                .isNotNull("report_time")
                .between("create_time", DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date())));
    }
 
    /**
     * 查询今日登记
     *
     * @return
     */
    @GetMapping("/registerToday")
    @ApiOperation(value = "查询今日登记")
    public Integer RegisterToday() {
        return orderService.count(new QueryWrapper<TjOrder>()
                .between("create_time", DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date())));
    }
 
 
    @GetMapping("/getChartByDeptId")
    @ApiOperation("根据部门查询体检统计")
    public AjaxResult getChartByDeptId(@RequestParam Long deptId,
                                       @ApiParam(value = "开始时间") @RequestParam(required = false) String beginTime,
                                       @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime) {
        List<TjChartVo> res=new ArrayList();
        LambdaQueryWrapper<TjOrderRemark> wq0 = new LambdaQueryWrapper<>();
        wq0.eq(TjOrderRemark::getDeptId, deptId);
        List<TjOrderRemark> remarkList = remarkService.list(wq0);
 
        List<Long> proIdList = remarkList.stream().map(TjOrderRemark::getProId).distinct().collect(Collectors.toList());
        for (Long aLong : proIdList) {
            LambdaQueryWrapper<TjOrderRemark> wq00 = new LambdaQueryWrapper<>();
            wq00.eq(TjOrderRemark::getDeptId, deptId);
            List<TjOrderRemark> remarkList1 = remarkService.list(wq00);
            Integer num1=0;
            Integer num2=0;
            Integer num3=0;
            Integer num4=0;
            TjChartVo chartVo=new TjChartVo();
            chartVo.setDeptId(deptId);
            chartVo.setDeptName(deptService.getById(deptId).getDeptName());
            for (TjOrderRemark tjOrderRemark : remarkList1) {
                if (tjOrderRemark.getType()==1){
                    num1+=1;
                }else if (tjOrderRemark.getType()==0){
                    num1+=1;
                }else if (tjOrderRemark.getType()==3){
                    num1+=1;
                }else if (tjOrderRemark.getType()==2){
                    num1+=1;
                }
            }
            chartVo.setYijianNum(String.valueOf(num1));
            chartVo.setWeijianNum(String.valueOf(num2));
            chartVo.setYanqiNum(String.valueOf(num3));
            chartVo.setQijianNum(String.valueOf(num4));
            res.add(chartVo);
        }
        return AjaxResult.success(res);
    }
 
 
    @GetMapping("/getTiaoByDeptId")
    @ApiOperation("根据部门和时间段查询体检统计图表")
    public AjaxResult getTiaoByDeptId(@RequestParam Long deptId,
                                       @ApiParam(value = "开始时间") @RequestParam(required = false) String beginTime,
                                       @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime) {
 
        return AjaxResult.success();
    }
 
    @GetMapping("/getTiaoNumsByDate")
    @ApiOperation("根据时间查询体检统计图表")
    public AjaxResult getTiaoNumsByDate(@ApiParam(value = "开始时间")String beginTime,
                                      @ApiParam(value = "结束时间") String endTime) {
        TjChartVo chartVo=new TjChartVo();
        LambdaQueryWrapper<TjOrder> wqq = new LambdaQueryWrapper<>();
        wqq.gt(TjOrder::getStatus,200);
        if (null != beginTime && null != endTime) {
            wqq.between(TjOrder::getCreateTime, beginTime, endTime);
        }
        final List<TjOrder> list = orderService.list(wqq);
        chartVo.setTijianNum(list.size());
 
        Integer boys=0;
        Integer girls=0;
        Integer person=0;
        Integer tuan=0;
        BigDecimal shouyi=new BigDecimal(0);
        for (TjOrder tjOrder : list) {
            TjCustomer customer = customerService.getById(tjOrder.getUserId());
            if(null !=customer){
                if (customer.getCusSex()==0){
                    boys+=1;
                }else if (customer.getCusSex()==1){
                    girls+=1;
                }
            }
            if ("2".equals(tjOrder.getTjType())){
                person+=1;
            } else if ("1".equals(tjOrder.getTjType())) {
                tuan+=1;
            }
            //计算收益
            LambdaQueryWrapper<TjFlowingWater> wqqq=new LambdaQueryWrapper<>();
            wqqq.eq(TjFlowingWater::getOrderId,tjOrder.getOrderId());
            final List<TjFlowingWater> list1 = tjFlowingWaterService.list(wqqq);
            for (TjFlowingWater tjFlowingWater : list1) {
                if(null !=tjFlowingWater.getPaidIn()){
                    shouyi.add(tjFlowingWater.getPaidIn());
                }
 
            }
        }
        chartVo.setBoysNum(boys);
        chartVo.setGirlsNum(girls);
        chartVo.setPersonNum(person);
        chartVo.setTuanDuiNum(tuan);
        chartVo.setMoneysNum(shouyi);
        return AjaxResult.success(chartVo);
    }
 
 
    @GetMapping("/getListByTjNumber")
    @ApiOperation("根据体检号下的项目列表")
    public AjaxResult getListByTjNumber(@RequestParam String tjNumber) {
        LambdaQueryWrapper<TjOrderRemark> wq0 = new LambdaQueryWrapper<>();
        wq0.eq(TjOrderRemark::getTjNumber, tjNumber);
        List<TjOrderRemark> remarkList = remarkService.list(wq0);
        return AjaxResult.success(remarkList);
    }
 
 
}