puhanshu
2022-04-28 c10d51e3f9c3f324676fceac7ea213f885a1b108
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
package com.panzhihua.service_community.service.impl;
 
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.ComActAcidRecordDTO;
import com.panzhihua.common.model.dtos.property.CommonPage;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.acid.ComAcidAreaVO;
import com.panzhihua.common.model.vos.community.acid.ComAcidStaticVO;
import com.panzhihua.common.model.vos.community.acid.ComActAcidDangerMemberVO;
import com.panzhihua.common.model.vos.community.acid.ComActAcidRecordVO;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.ComActAcidDangerMemberDao;
import com.panzhihua.service_community.entity.ComActAcidDangerMember;
import com.panzhihua.service_community.entity.ComActAcidRecord;
import com.panzhihua.service_community.dao.ComActAcidRecordDao;
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 javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import static com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNull;
 
/**
 * (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;
 
    @Override
    public R pageList(ComActAcidRecordDTO comActAcidRecordDTO) {
        return R.ok(this.baseMapper.pageList(new Page<>(comActAcidRecordDTO.getPage(), comActAcidRecordDTO.getSize()),comActAcidRecordDTO));
    }
 
    @Override
    public R export(ComActAcidRecordDTO comActAcidRecordDTO) {
        return R.ok(this.baseMapper.export(comActAcidRecordDTO));
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R insertRecord(ComActAcidRecordVO comActAcidRecordVO) {
        if(StringUtils.isEmpty(comActAcidRecordVO.getLocalCity())){
            rabbitTemplate.convertAndSend("huacheng.acid.exchange", "huacheng.acid.key", comActAcidRecordVO, message -> {
                message.getMessageProperties().setHeader("x-delay", 24*60*60*1000);
                return message;
            });
        }
        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.inStringIgnoreCase(colorMark, "红码", "黄码") || travelCard.equals("是")
                    || dangerArea.equals("是") || outsideCity.equals("是") || acidTest.equals("阳性")) {
                //风险人员
                saveAcidDangerMember(comActAcidRecordVO, comActAcidRecord.getId(), 1);
                return R.ok();
            }
            if (StringUtils.isEmpty(comActAcidRecordVO.getLocalCity())) {
                //未填住址人员
                saveAcidDangerMember(comActAcidRecordVO, comActAcidRecord.getId(), 2);
            }
            return R.ok();
        }
 
        return R.fail("操作失败,请重新尝试");
    }
 
    private void saveAcidDangerMember(ComActAcidRecordVO comActAcidRecordVO, Long recordId, Integer type) {
        ComActAcidDangerMember dangerMember = comActAcidDangerMemberDao.selectOne(new LambdaQueryWrapper<ComActAcidDangerMember>()
                .eq(ComActAcidDangerMember::getIdCard, comActAcidRecordVO.getIdCard()));
        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.setCreateTime(new Date());
            comActAcidDangerMemberDao.insert(dangerMember);
        } else {
            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.setUpdateTime(new Date());
            comActAcidDangerMemberDao.updateById(dangerMember);
        }
        ComActAcidDangerMemberVO dangerMemberVO = new ComActAcidDangerMemberVO();
        BeanUtils.copyProperties(dangerMember, dangerMemberVO);
        String realAddress = comActAcidRecordVO.getRealAddress();
        if (realAddress.contains("区")) {
            dangerMemberVO.setRelationName(realAddress.substring(realAddress.indexOf("市") + 1, realAddress.indexOf("区") + 1));
        } else {
            dangerMemberVO.setRelationName(realAddress.substring(realAddress.indexOf("市") + 1, realAddress.indexOf("县") + 1));
        }
        rabbitTemplate.convertAndSend("huacheng.acid.danger.exchange", "huacheng.acid.danger.key", dangerMemberVO, message -> {
            message.getMessageProperties().setHeader("x-delay", 5*60*1000);
            return message;
        });
    }
 
    @Override
    public R fiveCount(String localCity) {
        return R.ok(this.baseMapper.fiveCount(localCity));
    }
    @Override
    public R fiveCountPlus(String date) {
        return R.ok(this.baseMapper.fiveCountPlus(date));
    }
 
    @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);
    }
}