| | |
| | | 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.HomeQuarantineRegisterExportVO; |
| | | 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.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.ComActReserveRecordListVO; |
| | | 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.ComActQuestnaireAnswerContentDO; |
| | | import com.panzhihua.service_community.model.dos.ComActQuestnaireSubDO; |
| | | import com.panzhihua.service_community.model.dos.ComActReserveAnswerContentDO; |
| | | import com.panzhihua.service_community.model.dos.ComActReserveSubDO; |
| | | import com.panzhihua.service_community.service.ComActReserveAnswerContentService; |
| | | import com.panzhihua.service_community.service.ComActReserveSubService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @auther lyq |
| | |
| | | |
| | | @Resource |
| | | private ComActReserveSubMapper comActReserveSubMapper; |
| | | @Resource |
| | | private ComActReserveRecordMapper comActReserveRecordMapper; |
| | | |
| | | /** |
| | | * 导出登记明细数据 |
| | | * @param reserveId 登记id |
| | | * @param pageReserveRegisterDetailedAdminDTO 登记id |
| | | * @return 登记明细数据 |
| | | */ |
| | | @Override |
| | | public R exportRegisterAdmin(Long reserveId){ |
| | | public R exportRegisterAdmin(PageReserveRegisterDetailedAdminDTO pageReserveRegisterDetailedAdminDTO){ |
| | | QuestnaireAnswersDTO result = new QuestnaireAnswersDTO(); |
| | | |
| | | //查询题目 |
| | | List<ComActReserveSubDO> list = comActReserveSubMapper.selectList(new QueryWrapper<ComActReserveSubDO>().lambda() |
| | | .eq(ComActReserveSubDO::getReserveId, reserveId).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); |
| | | } |
| | | }); |
| | | result.setSubs(listSubVo); |
| | | result.setSubs(retrieveQuestnaireSub(pageReserveRegisterDetailedAdminDTO)); |
| | | |
| | | //查询用户回答 |
| | | List<ComActQuestnaireAnswerContentVO> vos = this.baseMapper.selectListByReserve(reserveId); |
| | | List<ComActQuestnaireAnswerContentVO> vos = this.baseMapper.export(pageReserveRegisterDetailedAdminDTO); |
| | | result.setAnswers(vos); |
| | | |
| | | return R.ok(result); |
| | |
| | | //渲染序号 |
| | | 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()); |
| | | //查询记录填写答案并装载到数据集中 |
| | |
| | | } |
| | | //渲染登记流水号 |
| | | map.put("id",registerDetailed.getId() + ""); |
| | | //渲染登记时间 |
| | | map.put("time", DateUtils.format(registerDetailed.getCreateAt(),DateUtils.ymdhms_format)); |
| | | resultMapList.add(map); |
| | | nub++; |
| | | } |
| | |
| | | resultPage.setRecords(resultMapList); |
| | | return R.ok(resultPage); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询居家隔离统计 |
| | | * @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.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.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); |
| | | bigScreenStaticsReserveMonths.add(bigScreenStaticsReserveMonth); |
| | | } |
| | | } |
| | | return bigScreenStaticsReserveMonths; |
| | | } |
| | | |
| | | } |