mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
package com.panzhihua.service_community.service.impl;
 
import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.community.acid.BatchCheckAcidRecordDTO;
import com.panzhihua.common.model.dtos.community.acid.ComActAcidRecordDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.StatisticsPhotoVO;
import com.panzhihua.common.model.vos.community.acid.*;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.DateUtils;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.*;
import com.panzhihua.service_community.entity.*;
import com.panzhihua.service_community.model.dos.ComActDO;
import com.panzhihua.service_community.model.dos.ComStreetDO;
import com.panzhihua.service_community.service.ComActAcidRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
 
import static com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty;
import static com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNull;
import static org.apache.commons.lang3.StringUtils.isBlank;
 
/**
 * (ComActAcidRecord)表服务实现类
 * projectName 成都呐喊信息技术有限公司-智慧社区项目
 * description: 相关功能
 *
 * @author zzj
 * @since 2022-04-12 15:29:58
 */
@Slf4j
@Service
public class ComActAcidRecordServiceImpl extends ServiceImpl<ComActAcidRecordDao, ComActAcidRecord> implements ComActAcidRecordService {
 
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Resource
    private ComActAcidDangerMemberDao comActAcidDangerMemberDao;
    @Resource
    private UserService userService;
    @Resource
    private ComActDAO comActDAO;
    @Resource
    private ComActAcidUpdateRecordDao comActAcidUpdateRecordDao;
    @Resource
    private ComAreaTownCommunityDao comAreaTownCommunityDao;
    @Resource
    private ComCunDao comCunDao;
    @Resource
    private ComStreetDAO comStreetDAO;
    @Resource
    private SysUserDao sysUserDao;
 
    @Override
    public R pageList(ComActAcidRecordDTO comActAcidRecordDTO) {
        //是否需要筛选
        comActAcidRecordDTO.setType(isVilliage(comActAcidRecordDTO.getLoginAccount()));
        log.info("搜索条件=========="+comActAcidRecordDTO);
        //获取当前登录账号的社区名
        return R.ok(this.baseMapper.pageList(new Page<>(comActAcidRecordDTO.getPage(), comActAcidRecordDTO.getSize()),comActAcidRecordDTO));
    }
 
    @Override
    public R export(ComActAcidRecordDTO comActAcidRecordDTO) {
        List<ComActAcidRecordExcelReturn> comActAcidRecordExcelVOS=new ArrayList<>();
        if(StringUtils.isNotEmpty(comActAcidRecordDTO.getIds())){
            comActAcidRecordExcelVOS=this.baseMapper.selectByIds(comActAcidRecordDTO.getIds());
        }
        else {
            comActAcidRecordExcelVOS=this.baseMapper.export(comActAcidRecordDTO);
        }
        comActAcidRecordExcelVOS.forEach(comActAcidRecordExcelVO -> {
            if(StringUtils.isNotEmpty(comActAcidRecordExcelVO.getTouristCity())&&comActAcidRecordExcelVO.getTouristCity().contains("[")){
                JSONArray jsonArray = JSON.parseArray(comActAcidRecordExcelVO.getTouristCity());
                if(jsonArray.isEmpty()){
                    comActAcidRecordExcelVO.setTouristCity("");
                }
                else {
                    StringBuilder touristCity= new StringBuilder();
                    for(int i=0;i<jsonArray.size();i++){
                        JSONObject jsonObject=jsonArray.getJSONObject(i);
                        String name=jsonObject.getString("name");
                        if(StringUtils.isNotEmpty(name)){
                            touristCity.append(name).append(";");
                        }
                    }
                    comActAcidRecordExcelVO.setTouristCity(touristCity.toString());
                }
            }
        });
        return R.ok(comActAcidRecordExcelVOS);
    }
 
    @Override
    public R exportNew(ComActAcidRecordDTO comActAcidRecordDTO) {
        List<ComActAcidRecordExcelReturn> comActAcidRecordExcelVOS=this.baseMapper.exportNew(comActAcidRecordDTO);
        comActAcidRecordExcelVOS.forEach(comActAcidRecordExcelVO -> {
            if(StringUtils.isNotEmpty(comActAcidRecordExcelVO.getTouristCity())&&comActAcidRecordExcelVO.getTouristCity().contains("[")){
                JSONArray jsonArray = JSON.parseArray(comActAcidRecordExcelVO.getTouristCity());
                if(jsonArray.isEmpty()){
                    comActAcidRecordExcelVO.setTouristCity("");
                }
                else {
                    StringBuilder touristCity= new StringBuilder();
                    for(int i=0;i<jsonArray.size();i++){
                        JSONObject jsonObject=jsonArray.getJSONObject(i);
                        String name=jsonObject.getString("name");
                        if(StringUtils.isNotEmpty(name)){
                            touristCity.append(name).append(";");
                        }
                    }
                    comActAcidRecordExcelVO.setTouristCity(touristCity.toString());
                }
            }
        });
        return R.ok(comActAcidRecordExcelVOS);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R insertRecord(ComActAcidRecordVO comActAcidRecordVO) {
        Integer count= this.baseMapper.selectCount(new QueryWrapper<ComActAcidRecord>().lambda().eq(ComActAcidRecord::getIsDel,0).eq(ComActAcidRecord::getIdCard,comActAcidRecordVO.getIdCard()).ge(ComActAcidRecord::getCreateTime, DateUtils.getCurrentDate(DateUtils.yyyyMMdd_format)));
        if(count>0){
            return R.fail("您的社区报备信息已填写完整,请勿重复提交!");
        }
        if(StringUtils.isEmpty(comActAcidRecordVO.getLocalCity())){
            rabbitTemplate.convertAndSend("huacheng.acid.exchange", "huacheng.acid.key", comActAcidRecordVO, message -> {
                message.getMessageProperties().setHeader("x-delay", 2*60*60*1000);
                return message;
            });
        }
        else {
            rabbitTemplate.convertAndSend("huacheng.acid.direct.exchange", "huacheng.acid.direct.key", comActAcidRecordVO);
        }
        ComActAcidRecord comActAcidRecord=new ComActAcidRecord();
        BeanUtils.copyProperties(comActAcidRecordVO,comActAcidRecord);
        comActAcidRecord.setCreateTime(new Date());
        int result = this.baseMapper.insert(comActAcidRecord);
        if (result > 0) {
            String colorMark = comActAcidRecordVO.getColorMark();
            String travelCard = comActAcidRecordVO.getTravelCard();
            String dangerArea = comActAcidRecordVO.getDangerArea();
            String outsideCity = comActAcidRecordVO.getOutsideCity();
            String acidTest = comActAcidRecordVO.getAcidTest();
            if(StringUtils.isEmpty(acidTest)){
                acidTest="阴性";
            }
            if(StringUtils.isEmpty(travelCard)){
                travelCard="否";
            }
            if (StringUtils.inStringIgnoreCase(colorMark, "红码", "黄码") || travelCard.equals("是")
                    || dangerArea.equals("是") || outsideCity.equals("是") || acidTest.equals("阳性")) {
                //风险人员
                String riskType = retrieveRiskType(colorMark, travelCard, dangerArea, outsideCity, acidTest);
                saveAcidDangerMember(comActAcidRecordVO, comActAcidRecord.getId(), 1, riskType);
                return R.ok();
            }
            if (StringUtils.isEmpty(comActAcidRecordVO.getLocalCity())) {
                //未填住址人员
                saveAcidDangerMember(comActAcidRecordVO, comActAcidRecord.getId(), 2, null);
            }
            return R.ok(comActAcidRecord.getId().toString());
        }
 
        return R.fail("操作失败,请重新尝试");
    }
 
    private String retrieveRiskType(String colorMark, String travelCard, String dangerArea, String outsideCity, String acidTest) {
        StringBuilder riskType = new StringBuilder();
        if (StringUtils.inStringIgnoreCase(colorMark, "红码", "黄码")) {
            riskType.append(",");
            riskType.append(ComActAcidDangerMember.RiskType.COLOR);
        }
        if (travelCard.equals("是")) {
            riskType.append(",");
            riskType.append(ComActAcidDangerMember.RiskType.STAR);
        }
        if (dangerArea.equals("是")) {
            riskType.append(",");
            riskType.append(ComActAcidDangerMember.RiskType.HIGH);
        }
        if (outsideCity.equals("是")) {
            riskType.append(",");
            riskType.append(ComActAcidDangerMember.RiskType.OUT);
        }
        if (acidTest.equals("阳性")) {
            riskType.append(",");
            riskType.append(ComActAcidDangerMember.RiskType.TEST);
        }
        return riskType.substring(1);
    }
 
    private void saveAcidDangerMember(ComActAcidRecordVO comActAcidRecordVO, Long recordId, Integer type, String riskType) {
        String localCity = comActAcidRecordVO.getLocalCity();
        String relationName = "panzhihua";
        if (isNotEmpty(localCity)) {
            relationName = localCity;
        } else {
            String realAddress = comActAcidRecordVO.getRealAddress();
            if(isNotEmpty(realAddress)){
                if (realAddress.contains("攀枝花")) {
                    if (realAddress.contains("区")) {
                        relationName = realAddress.substring(realAddress.indexOf("市") + 1, realAddress.indexOf("区") + 1);
                    } else {
                        relationName = realAddress.substring(realAddress.indexOf("市") + 1, realAddress.indexOf("县") + 1);
                    }
                }
            }
        }
        ComActAcidDangerMember dangerMember = comActAcidDangerMemberDao.selectOne(new LambdaQueryWrapper<ComActAcidDangerMember>()
                .eq(ComActAcidDangerMember::getIdCard, comActAcidRecordVO.getIdCard()).eq(ComActAcidDangerMember::getRecordId, recordId).orderByDesc(ComActAcidDangerMember::getCreateTime).last("limit 1"));
        if (isNull(dangerMember)) {
            dangerMember = new ComActAcidDangerMember();
            dangerMember.setName(comActAcidRecordVO.getName());
            dangerMember.setPhone(comActAcidRecordVO.getPhone());
            dangerMember.setRecordId(recordId);
            dangerMember.setIdCard(comActAcidRecordVO.getIdCard());
            dangerMember.setSource(1);
            dangerMember.setStatus(6);
            dangerMember.setType(type);
            dangerMember.setRelationName(relationName);
            dangerMember.setCreateTime(new Date());
            dangerMember.setRiskType(riskType);
            comActAcidDangerMemberDao.insert(dangerMember);
        } else {
            dangerMember.setName(comActAcidRecordVO.getName());
            dangerMember.setPhone(comActAcidRecordVO.getPhone());
            dangerMember.setRecordId(recordId);
            dangerMember.setIdCard(comActAcidRecordVO.getIdCard());
            dangerMember.setSource(1);
            dangerMember.setType(type);
            dangerMember.setRelationName(relationName);
            dangerMember.setUpdateTime(new Date());
            dangerMember.setRiskType(riskType);
            comActAcidDangerMemberDao.updateById(dangerMember);
        }
        ComActAcidDangerMemberVO dangerMemberVO = new ComActAcidDangerMemberVO();
        BeanUtils.copyProperties(dangerMember, dangerMemberVO);
        rabbitTemplate.convertAndSend("huacheng.acid.danger.exchange", "huacheng.acid.danger.key", dangerMemberVO, message -> {
            message.getMessageProperties().setHeader("x-delay", 1*60*1000);
            return message;
        });
    }
 
    @Override
    public R fiveCount(String localCity) {
        return R.ok(this.baseMapper.fiveCount(localCity));
    }
    @Override
    public R fiveCountPlus(String date,String localCity,String loginAccount) {
        Integer type=3;
        if (StringUtils.isNotEmpty(loginAccount)){
             type = isVilliage(loginAccount);
        }
        return R.ok(this.baseMapper.fiveCountPlus(date,localCity,type));
    }
 
    @Override
    public R charts(String date, String localCity) {
        if(StringUtils.isNotEmpty(localCity)){
            ComActAcidCharts comActAcidCharts=new ComActAcidCharts();
            List<ComActAcidChartsVO> acidList=new ArrayList<>();
            List<ComActAcidChartsVO> dangerList=new ArrayList<>();
            List<ComActAcidChartsVO> checkCount=new ArrayList<>();
            String[] area={"东区","西区","仁和区","米易县","盐边县"};
            if("panzhihua".equals(localCity)){
                for(String areaValue:area){
                    ComActAcidChartsVO acid=new ComActAcidChartsVO();
                    acid.setName(areaValue);
                    ComActAcidChartsVO acidCount =this.baseMapper.selectAcidCount(date,areaValue);
                    if(acidCount!=null){
                        acid.setNumOne(acidCount.getNumOne());
                    }
                    acidList.add(acid);
                    ComActAcidChartsVO danger=new ComActAcidChartsVO();
                    danger.setName(areaValue);
                    ComActAcidChartsVO dangerCount =this.baseMapper.selectDangerCount(date,areaValue);
                    if(dangerCount!=null){
                        danger.setNumOne(dangerCount.getNumOne());
                        danger.setNumTwo(dangerCount.getNumTwo());
                    }else{
                        danger.setNumOne(0);
                        danger.setNumTwo(0);
                    }
                    dangerList.add(danger);
                    checkCount =this.baseMapper.selectCheck(date,localCity);
                    if(checkCount!=null){
                        checkCount.forEach(comActAcidChartsVO -> {
                            if(comActAcidChartsVO.getNumTwo()!=null){
                                comActAcidChartsVO.setPercent(new BigDecimal(comActAcidChartsVO.getNumOne())
                                        .divide(new BigDecimal(comActAcidChartsVO.getNumTwo()), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(0));
                            }
                        });
                    }
 
                }
            }
            if(ArrayUtil.contains(area,localCity)){
                List<String> streets=comAreaTownCommunityDao.selectDistinctTown(localCity);
                streets.forEach(street ->{
                    ComActAcidChartsVO acid=new ComActAcidChartsVO();
                    acid.setName(street);
                    ComActAcidChartsVO acidCount =this.baseMapper.selectAcidCount(date,street);
                    if(acidCount!=null){
                        acid.setNumOne(acidCount.getNumOne());
                    }
                    acidList.add(acid);
                    ComActAcidChartsVO danger=new ComActAcidChartsVO();
                    danger.setName(street);
                    ComActAcidChartsVO dangerCount =this.baseMapper.selectDangerCount(date,street);
                    if(dangerCount!=null){
                        danger.setNumOne(dangerCount.getNumOne());
                        danger.setNumTwo(dangerCount.getNumTwo());
                    }
                    dangerList.add(danger);
                });
            }
            comActAcidCharts.setAcidList(acidList);
            comActAcidCharts.setDangerList(dangerList);
            comActAcidCharts.setCheckList(checkCount);
            return R.ok(comActAcidCharts);
        }
        return R.fail();
    }
 
    @Override
    public R statics(String date) {
        List<ComAcidStaticVO> comAcidStaticVOS=new ArrayList<>();
        String[] area={"攀枝花市","东区","西区","仁和区","米易县","盐边县","钒钛新城"};
        String[] country={"上海市","吉林省","广东省","江苏省","浙江省","山东省","湖北省","山西省","黑龙江省","广西壮族自治区","河北省","辽宁省","河南省","福建省","安徽省","南昌市","西宁市","西安市","文山州","兰州市","邵阳市"};
        for(String areaName:area){
            ComAcidStaticVO comAcidStaticVO=this.baseMapper.areaStatics(areaName,date);
            comAcidStaticVO.setAreaName(areaName);
            List<ComAcidAreaVO> comAcidAreaVOS=new ArrayList<>();
            for(String countryName:country){
                Integer count=this.baseMapper.countryStatics(countryName,date,areaName);
                ComAcidAreaVO comAcidAreaVO=new ComAcidAreaVO();
                comAcidAreaVO.setName(countryName);
                comAcidAreaVO.setCount(count);
                comAcidAreaVOS.add(comAcidAreaVO);
            }
            comAcidStaticVO.setComAcidAreaVOS(comAcidAreaVOS);
            comAcidStaticVOS.add(comAcidStaticVO);
        }
        return R.ok(comAcidStaticVOS);
    }
 
    @Override
    public R updateLocalCity(ComActAcidRecordVO comActAcidRecordVO) {
        ComActAcidUpdateRecord comActAcidUpdateRecord=new ComActAcidUpdateRecord();
        comActAcidUpdateRecord.setRecordId(comActAcidRecordVO.getId());
        comActAcidUpdateRecord.setUserId(comActAcidRecordVO.getUserId());
        comActAcidUpdateRecord.setCreateTime(new Date());
        comActAcidUpdateRecordDao.insert(comActAcidUpdateRecord);
        ComActAcidRecord comActAcidRecord = new ComActAcidRecord();
        BeanUtils.copyProperties(comActAcidRecordVO, comActAcidRecord);
        String idCard = comActAcidRecordVO.getIdCard();
        ComActAcidRecord comActAcidRecord1 = this.baseMapper.selectById(comActAcidRecordVO.getId());
        comActAcidRecord.setUserId(comActAcidRecord1.getUserId());
        if (isBlank(idCard)) {
            //只修改地址
            if (isNull(comActAcidRecord1)) {
                return R.fail("填报纪录不存在");
            }
            String localCity = comActAcidRecordVO.getLocalCity();
            String localAddress = comActAcidRecordVO.getLocalAddress();
            Integer checkStatus=comActAcidRecordVO.getCheckStatus();
            String remark=comActAcidRecordVO.getRemark();
            BeanUtils.copyProperties(comActAcidRecord1, comActAcidRecordVO);
            if(StringUtils.isNotEmpty(localCity)){
                comActAcidRecordVO.setLocalCity(localCity);
            }
            if(StringUtils.isNotEmpty(localAddress)){
                comActAcidRecordVO.setLocalAddress(localAddress);
            }
            BeanUtils.copyProperties(comActAcidRecord1,comActAcidRecord);
            if(checkStatus>0){
                comActAcidRecord.setCheckStatus(checkStatus);
            }
            if(StringUtils.isNotEmpty(remark)){
                comActAcidRecord.setRemark(remark);
            }
        }
        ComActAcidDangerMember comActAcidDangerMember =
            comActAcidDangerMemberDao.selectOne(new QueryWrapper<ComActAcidDangerMember>().lambda()
                .eq(ComActAcidDangerMember::getRecordId, comActAcidRecordVO.getId()).orderByDesc(ComActAcidDangerMember::getCreateTime).last("limit 1"));
        String colorMark = comActAcidRecordVO.getColorMark();
        String travelCard = comActAcidRecordVO.getTravelCard();
        String dangerArea = comActAcidRecordVO.getDangerArea();
        String outsideCity = comActAcidRecordVO.getOutsideCity();
        String acidTest = comActAcidRecordVO.getAcidTest();
        if(StringUtils.isEmpty(acidTest)){
            acidTest="阴性";
        }
        if(StringUtils.isEmpty(travelCard)){
            travelCard="否";
        }
        if (StringUtils.inStringIgnoreCase(colorMark, "红码", "黄码") || travelCard.equals("是") || dangerArea.equals("是")
            || outsideCity.equals("是") || acidTest.equals("阳性")) {
            // 风险人员
            String riskType = retrieveRiskType(colorMark, travelCard, dangerArea, outsideCity, acidTest);
            saveAcidDangerMember(comActAcidRecordVO, comActAcidRecord.getId(), 1, riskType);
        } else if (StringUtils.isEmpty(comActAcidRecordVO.getLocalCity())) {
            // 未填住址人员
            saveAcidDangerMember(comActAcidRecordVO, comActAcidRecord.getId(), 2, null);
        } else if (comActAcidDangerMember != null && comActAcidDangerMember.getType() == 2) {
            this.comActAcidDangerMemberDao.deleteById(comActAcidDangerMember.getId());
        }
 
        return R.ok(this.baseMapper.updateById(comActAcidRecord));
    }
 
    @Override
    public R updateApplets(ComActAcidRecordVO comActAcidRecordVO) {
        ComActAcidUpdateRecord comActAcidUpdateRecord=new ComActAcidUpdateRecord();
        comActAcidUpdateRecord.setRecordId(comActAcidRecordVO.getId());
        comActAcidUpdateRecord.setUserId(comActAcidRecordVO.getUserId());
        comActAcidUpdateRecord.setCreateTime(new Date());
        comActAcidUpdateRecordDao.insert(comActAcidUpdateRecord);
        ComActAcidRecord comActAcidRecord = new ComActAcidRecord();
        BeanUtils.copyProperties(comActAcidRecordVO, comActAcidRecord);
        String idCard = comActAcidRecordVO.getIdCard();
        ComActAcidRecord comActAcidRecord1 = this.baseMapper.selectById(comActAcidRecordVO.getId());
        comActAcidRecord.setUserId(comActAcidRecord1.getUserId());
        if (isBlank(idCard)) {
            //只修改核对状态
            if (isNull(comActAcidRecord1)) {
                return R.fail("填报纪录不存在");
            }
            Integer checkStatus=comActAcidRecordVO.getCheckStatus();
            String remark=comActAcidRecordVO.getRemark();
            BeanUtils.copyProperties(comActAcidRecord1, comActAcidRecordVO);
            BeanUtils.copyProperties(comActAcidRecord1,comActAcidRecord);
            if(checkStatus>0){
                comActAcidRecord.setCheckStatus(checkStatus);
            }
            if(StringUtils.isNotEmpty(remark)){
                comActAcidRecord.setRemark(remark);
            }
        }
        ComActAcidDangerMember comActAcidDangerMember =
                comActAcidDangerMemberDao.selectOne(new QueryWrapper<ComActAcidDangerMember>().lambda()
                        .eq(ComActAcidDangerMember::getRecordId, comActAcidRecordVO.getId()).orderByDesc(ComActAcidDangerMember::getCreateTime).last("limit 1"));
        String colorMark = comActAcidRecordVO.getColorMark();
        String travelCard = comActAcidRecordVO.getTravelCard();
        String dangerArea = comActAcidRecordVO.getDangerArea();
        String outsideCity = comActAcidRecordVO.getOutsideCity();
        String acidTest = comActAcidRecordVO.getAcidTest();
        if(StringUtils.isEmpty(acidTest)){
            acidTest="阴性";
        }
        if(StringUtils.isEmpty(travelCard)){
            travelCard="否";
        }
        if (StringUtils.inStringIgnoreCase(colorMark, "红码", "黄码") || travelCard.equals("是") || dangerArea.equals("是")
                || outsideCity.equals("是") || acidTest.equals("阳性")) {
            // 风险人员
            String riskType = retrieveRiskType(colorMark, travelCard, dangerArea, outsideCity, acidTest);
            saveAcidDangerMember(comActAcidRecordVO, comActAcidRecord.getId(), 1, riskType);
        } else if (StringUtils.isEmpty(comActAcidRecordVO.getLocalCity())) {
            // 未填住址人员
            saveAcidDangerMember(comActAcidRecordVO, comActAcidRecord.getId(), 2, null);
        } else if (comActAcidDangerMember != null && comActAcidDangerMember.getType() == 2) {
            this.comActAcidDangerMemberDao.deleteById(comActAcidDangerMember.getId());
        }
        return R.ok(this.baseMapper.updateById(comActAcidRecord));
    }
 
    @Override
    public R delete(Long id) {
        ComActAcidRecord comActAcidRecord=new ComActAcidRecord();
        comActAcidRecord.setId(id);
        comActAcidRecord.setIsDel(1);
        this.baseMapper.updateById(comActAcidRecord);
        List<ComActAcidDangerMember> comActAcidDangerMembers=this.comActAcidDangerMemberDao.selectList(new QueryWrapper<ComActAcidDangerMember>().lambda().eq(ComActAcidDangerMember::getRecordId,id));
        comActAcidDangerMembers.forEach(comActAcidDangerMember -> {
            comActAcidDangerMember.setIsDel(1);
            this.comActAcidDangerMemberDao.updateById(comActAcidDangerMember);
        });
        return R.ok();
    }
 
    @Override
    public R detailByApp(Long id,String localCity) {
        ComActAcidRecord comActAcidRecord=this.baseMapper.selectById(id);
        ComActAcidRecordVO comActAcidRecordVO=this.baseMapper.selectLastNext(id,localCity);
        BeanUtils.copyProperties(comActAcidRecord,comActAcidRecordVO);
        return R.ok(comActAcidRecordVO);
    }
 
    @Override
    public R detailByCommunity(Long id) {
        ComActAcidRecordVO comActAcidRecordVO=new ComActAcidRecordVO();
        ComActAcidRecord comActAcidRecord= this.baseMapper.selectById(id);
        BeanUtils.copyProperties(comActAcidRecord,comActAcidRecordVO);
        List<ComActAcidUpdateRecordVO> comActAcidUpdateRecordList=this.comActAcidUpdateRecordDao.selectList(id);
        if(!comActAcidUpdateRecordList.isEmpty()){
            comActAcidRecordVO.setComActAcidUpdateRecordVOList(comActAcidUpdateRecordList);
        }
        return R.ok(comActAcidRecordVO);
    }
 
    @Override
    public R test() {
        List<ComCun> comCuns=comCunDao.selectList(new QueryWrapper<ComCun>());
        comCuns.forEach(comCun->{
           ComActDO comActDO= comActDAO.selectOne(new QueryWrapper<ComActDO>().lambda().eq(ComActDO::getName,comCun.getCommunity()));
            if(comActDO==null){
                ComStreetDO comStreetDO = comStreetDAO.selectOne(new QueryWrapper<ComStreetDO>().lambda().eq(ComStreetDO::getName,comCun.getTown()));
                if(comStreetDO==null){
                    comStreetDO=new ComStreetDO();
                    comStreetDO.setName(comCun.getTown());
                    areaCheck(comCun,comStreetDO);
                    comStreetDO.setAccount(comCun.getAccount());
                    comStreetDAO.insert(comStreetDO);
                }
                comActDO=new ComActDO();
                comActDO.setStreetId(comStreetDO.getStreetId());
                comActDO.setAreaCode(comStreetDO.getAreaCode().toString());
                comActDO.setName(comCun.getCommunity());
                comActDO.setContacts(comCun.getName());
                comActDO.setContactsPhone(comCun.getPhone());
                comActDAO.insert(comActDO);
            }
            ComAreaTownCommunity community=comAreaTownCommunityDao.selectOne(new QueryWrapper<ComAreaTownCommunity>().lambda().eq(ComAreaTownCommunity::getArea,comCun.getArea()).eq(ComAreaTownCommunity::getTown,comCun.getTown()).eq(ComAreaTownCommunity::getCommunity,comCun.getCommunity()));
            if(community==null){
                community=new ComAreaTownCommunity();
                community.setArea(comCun.getArea());
                community.setTown(comCun.getTown());
                community.setCommunity(comCun.getCommunity());
                comAreaTownCommunityDao.insert(community);
            }else {
                community.setCommunityId(comActDO.getCommunityId());
                comAreaTownCommunityDao.updateById(community);
            }
            SysUser sysUser=sysUserDao.selectOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getAccount,comCun.getAccount()));
            if(sysUser!=null){
                System.out.println(comCun.getAccount()+","+comCun.getCommunity());
            }
            else {
                sysUser=new SysUser();
                sysUser.setAccount(comCun.getAccount());
                sysUser.setPassword("$2a$10$F/2lE2NMhKNHJfi5.FLmfu7jIr7ImRWgCTTeO6m3IRNR2V4sv8YR.");
                sysUser.setName(comCun.getCommunity());
                sysUser.setType(9);
                sysUserDao.insert(sysUser);
            }
        });
        return null;
    }
 
    /**
     * 批量核对防疫信息数据
     * @param batchCheckAcidRecordDTO
     * @return
     */
    @Override
    public R batchCheck(BatchCheckAcidRecordDTO batchCheckAcidRecordDTO) {
        this.baseMapper.batchCheck(batchCheckAcidRecordDTO);
        return R.ok();
    }
 
    @Override
    public R checkCommit(Long userId) {
        if(userId!=null){
            List<ComActAcidRecord> comActAcidRecords= this.baseMapper.selectList(new QueryWrapper<ComActAcidRecord>().lambda().eq(ComActAcidRecord::getIsDel,0).eq(ComActAcidRecord::getUserId,userId).ge(ComActAcidRecord::getCreateTime, DateUtils.getCurrentDate(DateUtils.yyyyMMdd_format)).isNull(ComActAcidRecord::getColorImage));
            return R.ok(comActAcidRecords);
        }
       return R.ok();
    }
 
    public static void areaCheck(ComCun area,ComStreetDO comStreetDO){
        switch (area.getArea()){
            case "西区": comStreetDO.setAreaCode(510423); break;
            case "东区": comStreetDO.setAreaCode(510402); break;
            case "仁和区": comStreetDO.setAreaCode(510411); break;
            case "米易县": comStreetDO.setAreaCode(510421); break;
            case "盐边县": comStreetDO.setAreaCode(510422); break;
        }
    }
 
    /**
     * 是否需要区分村落/社区
     * */
    private Integer isVilliage(String name){
        if ("fangyipingtai".equals(name)){
            return 3;
        }else if ("pandashujuzhongxin".equals(name)){
            return 1;
        }else if ("pannongyenongcunju".equals(name)){
            return 2;
        }
        return 3;
    }
 
    /**
     * 统计红黄绿码
     * @return
     */
    public R selectColorMarkGroup(){
        //所有
        List<ComActAcidColorChartsVO> comActAcidColorChartsVOS = this.baseMapper.selectColorMarkGroup();
        int all = comActAcidColorChartsVOS.stream().mapToInt(ComActAcidColorChartsVO::getCountNum).sum();
        for (ComActAcidColorChartsVO comActAcidColorChartsVO : comActAcidColorChartsVOS) {
            if (0!=all){
                BigDecimal countNum = new BigDecimal(comActAcidColorChartsVO.getCountNum());
                BigDecimal allDecimal = new BigDecimal(all);
                BigDecimal percent = countNum.divide(allDecimal,4, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(100));
                comActAcidColorChartsVO.setPercent(percent);
            }
        }
//        Map<String, ComActAcidColorChartsVO> circleMap = comActAcidColorChartsVOS
//                .stream()
//                .collect(Collectors.toMap(ComActAcidColorChartsVO::getColorMark, Function.identity()));
 
        //月份
        List<ComActAcidColorChartsVO> comActAcidColorChartsVOS1 = this.baseMapper.selectColorMarkGroupByMonth();
        //按颜色分组求和
        Map<String, IntSummaryStatistics> colorCollect = comActAcidColorChartsVOS1
                .stream()
                .collect(Collectors.groupingBy(ComActAcidColorChartsVO::getColorMark,
                        Collectors.summarizingInt(ComActAcidColorChartsVO::getCountNum)));
 
        for (ComActAcidColorChartsVO comActAcidColorChartsVO : comActAcidColorChartsVOS1) {
            String colorMark = comActAcidColorChartsVO.getColorMark();
            if (colorCollect.containsKey(colorMark)){
                IntSummaryStatistics intSummaryStatistics = colorCollect.get(colorMark);
                long sum = intSummaryStatistics.getSum();
                if (0L!=sum) {
                    BigDecimal countNum = new BigDecimal(comActAcidColorChartsVO.getCountNum());
                    BigDecimal sumDecimal = new BigDecimal(sum);
                    BigDecimal percent = countNum.divide(sumDecimal, 4, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(100));
                    comActAcidColorChartsVO.setPercent(percent);
                }
            }
        }
        Map<String, Map<String, ComActAcidColorChartsVO>> colletMap = comActAcidColorChartsVOS1
                .stream()
                .collect(Collectors.groupingBy(ComActAcidColorChartsVO::getCountName,
                        Collectors.toMap(ComActAcidColorChartsVO::getColorMark, Function.identity())));
 
        String[] statusArr = {"红码","黄码","绿码"};
        List<String> latest5Month = DateUtils.getLatest12Month(LocalDate.now(), 5);
        for (String month : latest5Month) {
            Map<String, ComActAcidColorChartsVO> map1;
            if(colletMap.containsKey(month)){
                map1 = colletMap.get(month);
            }else {
                map1 = new HashMap<>();
            }
            for (String status : statusArr) {
                if (!map1.containsKey(status)){
                    ComActAcidColorChartsVO comActAcidColorChartsVO = new ComActAcidColorChartsVO();
                    comActAcidColorChartsVO.setCountNum(0);
                    comActAcidColorChartsVO.setCountName(month);
                    comActAcidColorChartsVO.setColorMark(status);
                    comActAcidColorChartsVOS1.add(comActAcidColorChartsVO);
                    map1.put(status,comActAcidColorChartsVO);
                }
            }
            colletMap.put(month,map1);
        }
 
 
        Map<String, List<ComActAcidColorChartsVO>> chartMap = comActAcidColorChartsVOS1
                .stream().sorted(Comparator.comparing(ComActAcidColorChartsVO::getCountName))
                .collect(Collectors.groupingBy(ComActAcidColorChartsVO::getColorMark));
 
        Map<String,Object> retMap = new HashMap<>();
        retMap.put("comActAcidColorChartsVOS",comActAcidColorChartsVOS);
        retMap.put("chartMap",chartMap);
 
        return R.ok(retMap);
    }
}