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
package com.panzhihua.service_community.service.impl;
 
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
import javax.annotation.Resource;
import javax.xml.bind.DatatypeConverter;
 
import com.panzhihua.common.model.vos.community.bigscreen.BigScreenStaticsReserve;
import com.panzhihua.common.model.vos.community.bigscreen.BigScreenStaticsReserveMonth;
import com.panzhihua.common.model.vos.community.reserve.*;
import com.panzhihua.service_community.dao.ComActReserveMapper;
import com.panzhihua.service_community.dao.ComActReserveRecordMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.community.QuestnaireAnswersDTO;
import com.panzhihua.common.model.dtos.community.reserve.PageReserveRegisterDetailedAdminDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComActQuestnaireAnswerContentVO;
import com.panzhihua.common.model.vos.community.ComActQuestnaireSubVO;
import com.panzhihua.common.model.vos.community.reserve.ComActReserveRegisterDetailedAnswerVO;
import com.panzhihua.common.model.vos.community.reserve.ComActReserveRegisterDetailedVO;
import com.panzhihua.common.model.vos.community.reserve.HomeQuarantineRegisterStatisticsVO;
import com.panzhihua.common.utlis.DateUtils;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.ComActReserveAnswerContentMapper;
import com.panzhihua.service_community.dao.ComActReserveSubMapper;
import com.panzhihua.service_community.model.dos.ComActReserveAnswerContentDO;
import com.panzhihua.service_community.model.dos.ComActReserveSubDO;
import com.panzhihua.service_community.service.ComActReserveAnswerContentService;
 
import lombok.extern.slf4j.Slf4j;
 
/**
 * @auther lyq
 * @create 2021-08-23 10:33:32
 * @describe 预约登记回答记录内容 服务实现类
 */
@Slf4j
@Service
public class ComActReserveAnswerContentServiceImpl extends ServiceImpl<ComActReserveAnswerContentMapper, ComActReserveAnswerContentDO> implements ComActReserveAnswerContentService {
 
    @Resource
    private ComActReserveSubMapper comActReserveSubMapper;
    @Resource
    private ComActReserveRecordMapper comActReserveRecordMapper;
    @Resource
    private ComActReserveMapper comActReserveMapper;
 
    /**
     * 导出登记明细数据
     * @param pageReserveRegisterDetailedAdminDTO 登记id
     * @return  登记明细数据
     */
    @Override
    public R exportRegisterAdmin(PageReserveRegisterDetailedAdminDTO pageReserveRegisterDetailedAdminDTO){
        QuestnaireAnswersDTO result = new QuestnaireAnswersDTO();
        result.setSubs(retrieveQuestnaireSub(pageReserveRegisterDetailedAdminDTO));
 
        //查询用户回答
        List<ComActQuestnaireAnswerContentVO> vos = this.baseMapper.export(pageReserveRegisterDetailedAdminDTO);
        vos.forEach(vo->{
            if(vo.getType()==4){
                vo.setAnswerContent(vo.getAnswerContent().replaceAll("(?<=\\w{3})\\w(?=\\w{4})", "*"));
            }
        });
        result.setAnswers(vos);
 
        return R.ok(result);
    }
 
    /**
     * 分页查询登记明细列表
     * @param detailedAdminDTO  请求参数
     * @return  登记明细列表
     */
    @Override
    public R registerDetailedListAdmin(PageReserveRegisterDetailedAdminDTO detailedAdminDTO){
        IPage<HashMap<String,String>> resultPage = new Page<>();
 
        IPage<ComActReserveRegisterDetailedVO> registerDetailedPage = this.baseMapper.pageRegisterDetailedListAdmin(new Page(detailedAdminDTO.getPageNum(),detailedAdminDTO.getPageSize()),detailedAdminDTO);
        resultPage.setCurrent(registerDetailedPage.getCurrent());
        resultPage.setTotal(registerDetailedPage.getTotal());
        resultPage.setSize(registerDetailedPage.getSize());
        resultPage.setPages(registerDetailedPage.getPages());
 
        List<HashMap<String,String>> resultMapList = new ArrayList<>();
        int nub = 1;
        if(!registerDetailedPage.getRecords().isEmpty()){
            for (ComActReserveRegisterDetailedVO registerDetailed:registerDetailedPage.getRecords()) {
                //渲染序号
                HashMap<String,String> map = new HashMap<>();
                map.put("nub",nub + "");
                //渲染登记时间
                map.put("time", DateUtils.format(registerDetailed.getCreateAt(),DateUtils.ymdhms_format));
                //渲染用户昵称
                map.put("nickName",registerDetailed.getNickName());
                //查询记录填写答案并装载到数据集中
                List<ComActReserveRegisterDetailedAnswerVO> registerDetailedAnswerList = this.baseMapper.getRegisterDetailedAnswerList(registerDetailed.getId());
                if(!registerDetailedAnswerList.isEmpty()){
                    for (ComActReserveRegisterDetailedAnswerVO detailed:registerDetailedAnswerList) {
                        if(detailed.getType()==4){
                            detailed.setAnswerContent(detailed.getAnswerContent().replaceAll("(?<=\\w{3})\\w(?=\\w{4})", "*"));
                        }
                        if(!detailed.getType().equals(5)){
                            if(detailed.getType().equals(1)){
                                String key = detailed.getReserveSubId() + "";
                                String value = map.get(key);
                                if(StringUtils.isNotEmpty(value)){
                                    value = value + "," + detailed.getAnswerContent();
                                }else{
                                    value = detailed.getAnswerContent();
                                }
                                map.put(key,value);
                            }else{
                                map.put(detailed.getReserveSubId() + "",detailed.getAnswerContent());
                            }
                        }
 
                    }
                }
                //渲染登记流水号
                map.put("id",registerDetailed.getId() + "");
                resultMapList.add(map);
                nub++;
            }
        }
        resultPage.setRecords(resultMapList);
        return R.ok(resultPage);
    }
 
    @Override
    public R registerDetailedListAdminExport(PageReserveRegisterDetailedAdminDTO detailedAdminDTO) {
        String communityPhone=comActReserveMapper.selectCommunityPhoneByReserveId(detailedAdminDTO.getReserveId());
        List<ComActReserveRegisterDetailedVO> comActReserveRegisterDetailedVOS = this.baseMapper.pageRegisterDetailedListAdminExport(detailedAdminDTO);
        if(!comActReserveRegisterDetailedVOS.isEmpty()){
            List<ReservePdfExportVO> reservePdfExportVOS=new ArrayList<>();
            comActReserveRegisterDetailedVOS.forEach(comActReserveRegisterDetailedVO -> {
                List<ComActReserveRegisterDetailedAnswerVO> registerDetailedAnswerList = this.baseMapper.getRegisterDetailedAnswerList(comActReserveRegisterDetailedVO.getId());
                if(!registerDetailedAnswerList.isEmpty()){
                    ReservePdfExportVO reservePdfExportVO=new ReservePdfExportVO();
                    reservePdfExportVO.setAddress(registerDetailedAnswerList.get(0).getAnswerContent());
                    reservePdfExportVO.setSign(registerDetailedAnswerList.get(1).getAnswerContent());
                    if(detailedAdminDTO.getPdfType()==1){
                        reservePdfExportVO.setTime(registerDetailedAnswerList.get(2).getAnswerContent());
                    }
                    if(detailedAdminDTO.getPdfType()==2){
                        reservePdfExportVO.setPhone(registerDetailedAnswerList.get(2).getAnswerContent());
                        reservePdfExportVO.setTime(registerDetailedAnswerList.get(3).getAnswerContent());
                        reservePdfExportVO.setCommunityPhone(communityPhone);
                    }
                    reservePdfExportVOS.add(reservePdfExportVO);
                }
            });
            return R.ok(reservePdfExportVOS);
        }
        return R.ok();
    }
 
    /**
     * 分页查询居家隔离统计
     * @param detailedAdminDTO
     * @return
     */
    @Override
    public R pageRegisterHomeQuarantine(PageReserveRegisterDetailedAdminDTO detailedAdminDTO) {
        IPage<HashMap<String,String>> resultPage = new Page<>();
 
        Page page = new Page(detailedAdminDTO.getPageNum(), detailedAdminDTO.getPageSize());
        IPage<String> statisticsVOIPage = this.baseMapper.pageRegisterHomeQuarantine(page, detailedAdminDTO);
 
        resultPage.setCurrent(statisticsVOIPage.getCurrent());
        resultPage.setTotal(statisticsVOIPage.getTotal());
        resultPage.setSize(statisticsVOIPage.getSize());
        resultPage.setPages(statisticsVOIPage.getPages());
 
        List<String> records = statisticsVOIPage.getRecords();
        List<HashMap<String,String>> resultMapList = new ArrayList<>();
        if (!records.isEmpty()) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            int nub = 1;
            for (String record : records) {
                //渲染序号
                HashMap<String,String> map = new HashMap<>();
                map.put("nub", nub + "");
                List<HomeQuarantineRegisterStatisticsVO> statisticsList = this.baseMapper.selectStatistics(detailedAdminDTO.getReserveId(), record);
                StringBuffer conditions = new StringBuffer();
                //渲染首次登记时间
                map.put("time", DateUtils.format(statisticsList.get(0).getCreateAt(), DateUtils.ymdhms_format));
                statisticsList.forEach(e -> {
                    String reserveSubContent = e.getReserveSubContent();
                    String dateString = dateFormat.format(e.getCreateAt());
                    if (reserveSubContent.contains("今日上午体温(℃)")) {
                        int index = conditions.indexOf(dateString + " " + "上午体温");
                        if (index == -1) {
                            conditions.append(dateString + " " + "上午体温:" + e.getAnswerContent() + "℃" + "\n");
                        } else {
                            conditions.replace(index, conditions.indexOf("℃", index),
                                    dateString + " " + "上午体温:" + e.getAnswerContent());
                        }
                    } else if (reserveSubContent.contains("今日下午体温(℃)")) {
                        int index = conditions.indexOf(dateString + " " + "下午体温");
                        if (index == -1) {
                            conditions.append(dateString + " " + "下午体温:" + e.getAnswerContent() + "℃" + "\n");
                        } else {
                            conditions.replace(index, conditions.indexOf("℃", index),
                                    dateString + " " + "下午体温:" + e.getAnswerContent());
                        }
                    } else if (reserveSubContent.contains("隔离情况")) {
                        int index = conditions.indexOf(dateString + " " + "当日隔离情况");
                        if (index == -1) {
                            conditions.append(dateString + " " + "当日隔离情况:" + e.getAnswerContent() + "\n");
                            conditions.append("————————" + "\n");
                        } else {
                            conditions.replace(index, conditions.indexOf("\n", index),
                                    dateString + " " + "当日隔离情况:" + e.getAnswerContent());
                        }
                    } else {
                        map.put(e.getReserveSubId() + "", e.getAnswerContent());
                    }
                });
                map.put("isolation", conditions.toString());
                resultMapList.add(map);
                nub++;
            }
        }
        resultPage.setRecords(resultMapList);
        return R.ok(resultPage);
    }
 
    /**
     * 居家隔离导出
     * @param detailedAdminDTO
     * @return
     */
    @Override
    public R exportHomeQuarantine(PageReserveRegisterDetailedAdminDTO detailedAdminDTO) {
        HomeQuarantineRegisterExportVO exportVO = new HomeQuarantineRegisterExportVO();
        //题目
        exportVO.setSubs(retrieveQuestnaireSub(detailedAdminDTO));
        //结果数据集合
        List<List<Object>> resultList = new ArrayList<>();
        List<String> idCards = this.baseMapper.exportHomeQuarantine(detailedAdminDTO);
        if (!idCards.isEmpty()) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            for (String idCard : idCards) {
                //构建单个用户数据
                List<Object> userData = new ArrayList<>();
                List<HomeQuarantineRegisterStatisticsVO> statisticsList = this.baseMapper.selectStatistics(detailedAdminDTO.getReserveId(), idCard);
                HomeQuarantineRegisterStatisticsVO firstStatisticsVO = statisticsList.get(0);
                userData.add(firstStatisticsVO.getNickName());
                userData.add(DateUtils.format(firstStatisticsVO.getCreateAt(), DateUtils.ymdhms_format));
                int size = statisticsList.size();
                List<HomeQuarantineRegisterStatisticsVO> lastStatisticsVOList = statisticsList.subList(size - 13, size);
                for (HomeQuarantineRegisterStatisticsVO statisticsVO : lastStatisticsVOList) {
                    //判断当前的组件类型是否是图片上传,导出时需要导出图片
                    if (statisticsVO.getOptionType().equals(11)) {
                        try {
                            userData.add(new URL(statisticsVO.getAnswerContent()));
                        } catch (Exception e) {
                            userData.add(" ");
                            log.error("导出转换图片失败!");
                        }
                        continue;
                    }
                    //判断当前组件类型是否签名
                    if (statisticsVO.getOptionType().equals(12)) {
                        try {
                            userData.add(DatatypeConverter.parseBase64Binary(statisticsVO.getAnswerContent().substring(statisticsVO.getAnswerContent().indexOf(",") + 1)));
                        } catch (Exception e) {
                            userData.add(" ");
                            log.error("导出转换图片失败!");
                        }
                        continue;
                    }
                    userData.add(statisticsVO.getAnswerContent());
                }
                StringBuffer conditions = new StringBuffer();
                statisticsList.forEach(e -> {
                    String reserveSubContent = e.getReserveSubContent();
                    String dateString = dateFormat.format(e.getCreateAt());
                    if (reserveSubContent.contains("今日上午体温(℃)")) {
                        int index = conditions.indexOf(dateString + " " + "上午体温");
                        if (index == -1) {
                            conditions.append(dateString + " " + "上午体温:" + e.getAnswerContent() + "℃" + "\n");
                        } else {
                            conditions.replace(index, conditions.indexOf("℃", index),
                                    dateString + " " + "上午体温:" + e.getAnswerContent());
                        }
                    } else if (reserveSubContent.contains("今日下午体温(℃)")) {
                        int index = conditions.indexOf(dateString + " " + "下午体温");
                        if (index == -1) {
                            conditions.append(dateString + " " + "下午体温:" + e.getAnswerContent() + "℃" + "\n");
                        } else {
                            conditions.replace(index, conditions.indexOf("℃", index),
                                    dateString + " " + "下午体温:" + e.getAnswerContent());
                        }
                    } else if (reserveSubContent.contains("隔离情况")) {
                        int index = conditions.indexOf(dateString + " " + "当日隔离情况");
                        if (index == -1) {
                            conditions.append(dateString + " " + "当日隔离情况:" + e.getAnswerContent() + "\n");
                            conditions.append("————————" + "\n");
                        } else {
                            conditions.replace(index, conditions.indexOf("\n", index),
                                    dateString + " " + "当日隔离情况:" + e.getAnswerContent());
                        }
                    }
                });
                userData.add(conditions.toString());
                resultList.add(userData);
            }
        }
        exportVO.setDataList(resultList);
        return R.ok(exportVO);
    }
 
    @Override
    public R bigScreenStaticsReserve(Long communityId) {
        BigScreenStaticsReserve bigScreenStaticsReserve=comActReserveRecordMapper.biggestScreen(communityId);
        bigScreenStaticsReserve.setReservePercent(BigDecimal.valueOf(bigScreenStaticsReserve.getReserveCount()*100d/ bigScreenStaticsReserve.getCount()).setScale(2,BigDecimal.ROUND_HALF_UP));
        bigScreenStaticsReserve.setFirePercent(BigDecimal.valueOf(bigScreenStaticsReserve.getFireCount()*100d/ bigScreenStaticsReserve.getCount()).setScale(2,BigDecimal.ROUND_HALF_UP));
        bigScreenStaticsReserve.setHomePercent(BigDecimal.valueOf(bigScreenStaticsReserve.getHomeCount()*100d/ bigScreenStaticsReserve.getCount()).setScale(2,BigDecimal.ROUND_HALF_UP));
        bigScreenStaticsReserve.setGasPercent(BigDecimal.valueOf(bigScreenStaticsReserve.getGasCount()*100d/ bigScreenStaticsReserve.getCount()).setScale(2,BigDecimal.ROUND_HALF_UP));
        List<BigScreenStaticsReserveMonth> bigScreenStaticsReserveMonthList=this.getPoints();
        bigScreenStaticsReserveMonthList.forEach(bigScreenStaticsReserveMonth -> {
            BigScreenStaticsReserveMonth bigScreenStaticsReserveMonth1=comActReserveRecordMapper.biggestScreenMonth(communityId,bigScreenStaticsReserveMonth.getX(), bigScreenStaticsReserveMonth.getYear());
            bigScreenStaticsReserveMonth.setCount(bigScreenStaticsReserveMonth1.getCount());
            bigScreenStaticsReserveMonth.setReserveCount(bigScreenStaticsReserveMonth1.getReserveCount());
            bigScreenStaticsReserveMonth.setFireCount(bigScreenStaticsReserveMonth1.getFireCount());
            bigScreenStaticsReserveMonth.setGasCount(bigScreenStaticsReserveMonth1.getGasCount());
            bigScreenStaticsReserveMonth.setHomeCount(bigScreenStaticsReserveMonth1.getHomeCount());
        });
        bigScreenStaticsReserve.setBigScreenStaticsReserveMonthList(bigScreenStaticsReserveMonthList);
        return R.ok(bigScreenStaticsReserve);
    }
 
    private List<ComActQuestnaireSubVO> retrieveQuestnaireSub(PageReserveRegisterDetailedAdminDTO detailedAdminDTO) {
        //查询题目
        List<ComActReserveSubDO> list = comActReserveSubMapper.selectList(new QueryWrapper<ComActReserveSubDO>().lambda()
                .eq(ComActReserveSubDO::getReserveId, detailedAdminDTO.getReserveId()).orderByAsc(ComActReserveSubDO::getCreateAt).orderByAsc(ComActReserveSubDO::getId));
        List<ComActQuestnaireSubVO> listSubVo = new ArrayList<>();
        list.forEach(subDo -> {
            if(!subDo.getType().equals(5)){
                ComActQuestnaireSubVO comActQuestnaireSubVO = new ComActQuestnaireSubVO();
                BeanUtils.copyProperties(subDo, comActQuestnaireSubVO);
                listSubVo.add(comActQuestnaireSubVO);
            }
        });
        return listSubVo;
    }
 
    public List<BigScreenStaticsReserveMonth> getPoints(){
        List<BigScreenStaticsReserveMonth> bigScreenStaticsReserveMonths=new ArrayList<>();
        String nowMonth=DateUtils.getDateFormatString(new Date(),"MM");
        String nowYear=DateUtils.getDateFormatString(new Date(),"yyyy");
        String nowYearMonth=DateUtils.getDateFormatString(new Date(),"yyyyMM");
        if(Integer.parseInt(nowYearMonth)<202212){
            for(int i=9;i<=12;i++){
                String aDate="";
                if(i<10){
                    aDate = "0"+i;
                }
                else {
                    aDate=i+"";
                }
                BigScreenStaticsReserveMonth bigScreenStaticsReserveMonth=new BigScreenStaticsReserveMonth();
                bigScreenStaticsReserveMonth.setYear("2021");
                bigScreenStaticsReserveMonth.setX(aDate);
                bigScreenStaticsReserveMonths.add(bigScreenStaticsReserveMonth);
            }
        }
        if(Integer.parseInt(nowYear)>2021){
            for(int i=1;i<=Integer.parseInt(nowMonth);i++){
                if(bigScreenStaticsReserveMonths.size()>=12){
                    bigScreenStaticsReserveMonths.remove(0);
                }
                String aDate="";
                if(i<10){
                    aDate = "0"+i;
                }
                else {
                    aDate=i+"";
                }
                BigScreenStaticsReserveMonth bigScreenStaticsReserveMonth=new BigScreenStaticsReserveMonth();
                bigScreenStaticsReserveMonth.setX(aDate);
                bigScreenStaticsReserveMonth.setYear(nowYear);
                bigScreenStaticsReserveMonths.add(bigScreenStaticsReserveMonth);
            }
        }
        return bigScreenStaticsReserveMonths;
    }
 
}