package com.xkrs.service.impl; import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.dao.*; import com.xkrs.model.entity.*; import com.xkrs.model.qo.FirePointQo; import com.xkrs.model.vo.GaoDeIgGeocodeVo; import com.xkrs.service.FirePointService; import com.xkrs.service.GlobalConfigService; import com.xkrs.service.StreetService; import com.xkrs.sms.PushHelper; import com.xkrs.sms.SMSHelper; import com.xkrs.utils.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.transaction.Transactional; import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.*; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; import static com.xkrs.utils.DateTimeUtil.dateTimeToString; import static com.xkrs.utils.XlsxUtil.downloadXlsx; /** * @author XinYi Song */ @CacheConfig(cacheNames = "FirePointServiceCache") @Service public class FirePointServiceImpl implements FirePointService { public static Logger log = LoggerFactory.getLogger(FirePointServiceImpl.class); private final Locale locale = LocaleContextHolder.getLocale(); @Resource private FirePointDao firePointDao; @Resource private SettingDao settingDao; @Resource private ShanDongFirePointDao shanDongFirePointDao; @Resource private SysUserDao sysUserDao; @Resource private StreetDao streetDao; @Resource private CountyCodeWeiXinDao countyCodeWeiXinDao; @Resource private RelRoleAuthorityDao relRoleAuthorityDao; @Resource private FirePointQueryHelper firePointQueryHelper; @Resource private GlobalConfigService globalConfigService; @Resource private StreetService streetService; @Resource private AgentOrgDao agentOrgDao; @Resource private SMSHelper smsHelper; @Resource private PushHelper pushHelper; /** * 添加火点信息 */ @CacheEvict(value = "FirePointServiceCache", allEntries = true) @Override public boolean insertFirePoint(FirePointQo firePointQo) { if ("水体".equals(firePointQo.getLandtype())) { return false; } if ("Himawari 8".equals(firePointQo.getSatelliteType())) { if ("N".equals(firePointQo.getConfidence()) || "L".equals(firePointQo.getConfidence())) { return false; } } FirePointEntity firePointEntity = new FirePointEntity(); firePointEntity.setFireCode(firePointQo.getFireCode()); firePointEntity.setCountyCode(firePointQo.getCountyCode().toString()); firePointEntity.setCountyName(firePointQo.getCountyName()); firePointEntity.setSatelliteTime(DateTimeUtil.timeMillisToString(firePointQo.getSatelliteTimeTs().longValue())); firePointEntity.setLongitude(firePointQo.getLongitude()); firePointEntity.setLatitude(firePointQo.getLatitude()); firePointEntity.setSatelliteType(firePointQo.getSatelliteType()); firePointEntity.setLandType(firePointQo.getLandtype()); firePointEntity.setConfidence(firePointQo.getConfidence()); firePointEntity.setAddTime(dateTimeToString(LocalDateTime.now())); firePointEntity.setFireType("0"); firePointEntity.setFireImage(firePointQo.getFireImage()); firePointEntity.setSatelliteImage(firePointQo.getSatelliteImage()); firePointEntity.setAuditFireType("0");//初始化火点为未审核状态 try { bindAddress(firePointEntity); } catch (Exception e) { e.printStackTrace(); log.info("添加火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); return false; } if (checkDuplicatedData(firePointEntity)) { return false; } if (firePointEntity.getCountyCode().startsWith("37")) { //如果是山东的点,就入库 if (isSwitchStateOpen()) { //如果开关已打开,就只将未审核的火点添加到山东临时表 log.info("-------发现新山东火点"); ShanDongFirePointEntity shanDongFirePointByFirePoint = getShanDongFirePointByFirePoint(firePointEntity); ShanDongFirePointEntity savedShanDongFirePoint = shanDongFirePointDao.save(shanDongFirePointByFirePoint); //微信消息通知火点审核工作组 try { String messageContent = getMessageContent(savedShanDongFirePoint); WDWxSendMsgUtil.sendMsg("18447024917@chatroom", messageContent, 0); } catch (Exception e) { e.printStackTrace(); } return true; } else { return false; } } else { log.info("-------发现新火点"); firePointDao.save(firePointEntity); return true; } // log.info("-------发现新火点"); // firePointDao.save(firePointEntity); // return true; } /** * 检查重复数据 * * @param firePointEntity 待入库实体类 * @return true-是重复数据,拒绝入库;false-不是重复数据,可以入库 */ private boolean checkDuplicatedData(FirePointEntity firePointEntity) { List duplicatedDataList = firePointDao.findDuplicatedData(firePointEntity.getLongitude(), firePointEntity.getLatitude(), firePointEntity.getStreetCode(), firePointEntity.getSatelliteTime(), firePointEntity.getSatelliteType(), firePointEntity.getLandType()); return duplicatedDataList != null && duplicatedDataList.size() > 1; } /** * 检查重复数据 * * @param shanDongFirePoint 待入库实体类 * @return true-是重复数据,拒绝入库;false-不是重复数据,可以入库 */ private boolean checkDuplicatedDataX(ShanDongFirePointEntity shanDongFirePoint) { List duplicatedDataList = firePointDao.findDuplicatedData(shanDongFirePoint.getLongitude(), shanDongFirePoint.getLatitude(), shanDongFirePoint.getStreetCode(), shanDongFirePoint.getSatelliteTime(), shanDongFirePoint.getSatelliteType(), shanDongFirePoint.getLandType()); return duplicatedDataList != null && duplicatedDataList.size() > 1; } /** * 检查重复数据 * * @param shanDongFirePoint 待入库实体类 * @return true-是重复数据,拒绝入库;false-不是重复数据,可以入库 */ private boolean checkDuplicatedData(ShanDongFirePointEntity shanDongFirePoint) { List duplicatedDataList = shanDongFirePointDao.findDuplicatedData(shanDongFirePoint.getLongitude(), shanDongFirePoint.getLatitude(), shanDongFirePoint.getStreetCode(), shanDongFirePoint.getSatelliteTime(), shanDongFirePoint.getSatelliteType(), shanDongFirePoint.getLandType()); return duplicatedDataList != null && duplicatedDataList.size() > 1; } /** * 添加火点信息 */ @CacheEvict(value = "FirePointServiceCache", allEntries = true) @Override public boolean insertFirePointChannelTwo(FirePointQo firePointQo) { if ("水体".equals(firePointQo.getLandtype())) { return false; } if ("Himawari 8".equals(firePointQo.getSatelliteType())) { if ("N".equals(firePointQo.getConfidence()) || "L".equals(firePointQo.getConfidence())) { return false; } } ShanDongFirePointEntity shanDongFirePoint = new ShanDongFirePointEntity(); shanDongFirePoint.setFireCode(firePointQo.getFireCode()); shanDongFirePoint.setCountyCode(firePointQo.getCountyCode().toString()); shanDongFirePoint.setCountyName(firePointQo.getCountyName()); // //设置乡镇街道区划编码和名称---Start // String townCode = firePointQo.getTowncode(); // shanDongFirePoint.setStreetCode(townCode); // shanDongFirePoint.setStreetName(""); // List streetList = streetService.findByStreetCode(townCode); // if (null != streetList && streetList.size() > 0) { // StreetEntity street = streetList.get(0); // shanDongFirePoint.setStreetName(street.getStreetName()); // if (!street.getCountyCode().equals(shanDongFirePoint.getCountyCode())) {//这三个错误日志可以监视接收的towncode有木有问题,日志里不出现"发生重大错误"就是没问题 // log.info("发生重大错误,接收的countyCode是" + shanDongFirePoint.getCountyCode() + ",本地表中根据streetCode(towncode)" + townCode + "找到的countyCode是" + street.getCountyCode() + ",firePointQo详情=" + firePointQo.toString()); // } // if (!street.getCountyName().equals(shanDongFirePoint.getCountyName())) { // log.info("发生重大错误,接收的countyName是" + shanDongFirePoint.getCountyName() + ",本地表中根据streetCode(towncode)" + townCode + "找到的countyName是" + street.getCountyName() + ",firePointQo详情=" + firePointQo.toString()); // } // } else { // log.info("发生重大错误,传过来的towncode(" + townCode + ")连找都找不到,firePointQo详情=" + firePointQo.toString()); // } // //设置乡镇街道区划编码和名称---End shanDongFirePoint.setSatelliteTime(DateTimeUtil.timeMillisToString(firePointQo.getSatelliteTimeTs().longValue())); shanDongFirePoint.setLongitude(firePointQo.getLongitude()); shanDongFirePoint.setLatitude(firePointQo.getLatitude()); shanDongFirePoint.setSatelliteType(firePointQo.getSatelliteType()); shanDongFirePoint.setLandType(firePointQo.getLandtype()); shanDongFirePoint.setConfidence(firePointQo.getConfidence()); shanDongFirePoint.setAddTime(dateTimeToString(LocalDateTime.now())); shanDongFirePoint.setFireType("0"); shanDongFirePoint.setFireImage(firePointQo.getFireImage()); shanDongFirePoint.setSatelliteImage(firePointQo.getSatelliteImage()); shanDongFirePoint.setVerifyState("0"); try { bindAddress(shanDongFirePoint); } catch (Exception e) { e.printStackTrace(); System.out.println("添加山东火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); } if (checkDuplicatedDataX(shanDongFirePoint) || checkDuplicatedData(shanDongFirePoint)) { return false; } //如果是山东的点,就入库 if (shanDongFirePoint.getCountyCode().startsWith("37")) { if (isSwitchStateOpen()) { //如果开关已打开,就只将未审核的火点添加到山东临时表 log.info("-------发现新山东火点"); ShanDongFirePointEntity savedShanDongFirePoint = shanDongFirePointDao.save(shanDongFirePoint); //微信消息通知火点审核工作组 try { String messageContent = getMessageContent(savedShanDongFirePoint); WDWxSendMsgUtil.sendMsg("18447024917@chatroom", messageContent, 0); } catch (Exception e) { e.printStackTrace(); } return true; } else { //如果开关已关闭,就将火点添加到山东临时表,同时自动审核通过添加到全国火点表 log.info("-------发现新火点"); shanDongFirePoint.setVerifyState("1"); shanDongFirePointDao.save(shanDongFirePoint); FirePointEntity firePoint = getFirePointByShanDongFirePoint(shanDongFirePoint); log.info("-------转存新火点"); firePointDao.save(firePoint); //发送消息通知 sendBroadcast(firePoint); return true; } } return false; } /** * 根据山东火点生成全国火点 */ private FirePointEntity getFirePointByShanDongFirePoint(ShanDongFirePointEntity shanDongFirePoint) { FirePointEntity firePoint = new FirePointEntity(); firePoint.setFireCode(shanDongFirePoint.getFireCode()); firePoint.setCountyCode(shanDongFirePoint.getCountyCode()); firePoint.setCountyName(shanDongFirePoint.getCountyName()); firePoint.setSatelliteTime(shanDongFirePoint.getSatelliteTime()); firePoint.setLongitude(shanDongFirePoint.getLongitude()); firePoint.setLatitude(shanDongFirePoint.getLatitude()); firePoint.setFirePointAddress(shanDongFirePoint.getFirePointAddress()); firePoint.setSatelliteType(shanDongFirePoint.getSatelliteType()); firePoint.setLandType(shanDongFirePoint.getLandType()); firePoint.setConfidence(shanDongFirePoint.getConfidence()); firePoint.setAddTime(shanDongFirePoint.getAddTime()); firePoint.setFireType(shanDongFirePoint.getFireType()); firePoint.setFireImage(shanDongFirePoint.getFireImage()); firePoint.setSatelliteImage(shanDongFirePoint.getSatelliteImage()); firePoint.setStreetCode(shanDongFirePoint.getStreetCode()); firePoint.setStreetName(shanDongFirePoint.getStreetName()); firePoint.setAuditFireType("0");//初始化火点为未审核状态 return firePoint; } private ShanDongFirePointEntity getShanDongFirePointByFirePoint(FirePointEntity firePoint) { ShanDongFirePointEntity shanDongFirePoint = new ShanDongFirePointEntity(); shanDongFirePoint.setId(firePoint.getId()); shanDongFirePoint.setFireCode(firePoint.getFireCode()); shanDongFirePoint.setLongitude(firePoint.getLongitude()); shanDongFirePoint.setLatitude(firePoint.getLatitude()); shanDongFirePoint.setCountyCode(firePoint.getCountyCode()); shanDongFirePoint.setCountyName(firePoint.getCountyName()); shanDongFirePoint.setSatelliteTime(firePoint.getSatelliteTime()); shanDongFirePoint.setSatelliteType(firePoint.getSatelliteType()); shanDongFirePoint.setLandType(firePoint.getLandType()); shanDongFirePoint.setAddTime(firePoint.getAddTime()); shanDongFirePoint.setConfidence(firePoint.getConfidence()); shanDongFirePoint.setFirePointAddress(firePoint.getFirePointAddress()); shanDongFirePoint.setFireType(firePoint.getFireType()); shanDongFirePoint.setFireImage(firePoint.getFireImage()); shanDongFirePoint.setSatelliteImage(firePoint.getSatelliteImage()); shanDongFirePoint.setBeforeFireImage(firePoint.getBeforeFireImage()); shanDongFirePoint.setAfterFireImage(firePoint.getAfterFireImage()); shanDongFirePoint.setStreetCode(firePoint.getStreetCode()); shanDongFirePoint.setStreetName(firePoint.getStreetName()); shanDongFirePoint.setVerifyState("0"); return shanDongFirePoint; } /** * 返回开关是否为打开状态 * * @return true:已打开,false:已关闭 */ private boolean isSwitchStateOpen() { List settingEntityList = settingDao.findAll(); if (settingEntityList.isEmpty()) { return false; } SettingEntity settingEntity = settingEntityList.get(0); return "1".equals(settingEntity.getSwitchState()); } /** * 为实体类绑定地址、编号、名称 */ private void bindAddress(FirePointEntity firePointEntity) throws Exception { List locationList = new ArrayList<>(); locationList.add(firePointEntity.getLongitude() + "," + firePointEntity.getLatitude()); GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList); GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0); String formattedAddress = reGeoCode.getFormatted_address(); firePointEntity.setFirePointAddress(formattedAddress); GaoDeIgGeocodeVo.AddressComponent addressComponent = reGeoCode.getAddressComponent().get(0); firePointEntity.setCountyCode(addressComponent.getAdcode()); firePointEntity.setCountyName(addressComponent.getDistrict()); String townCode = addressComponent.getTowncode(); String fixedTownCode = townCode.length() > 9 ? townCode.substring(0, 9) : townCode; firePointEntity.setStreetCode(fixedTownCode); firePointEntity.setStreetName(addressComponent.getTownship()); } /** * 为实体类绑定地址、编号、名称 */ private void bindAddress(ShanDongFirePointEntity firePointEntity) throws Exception { List locationList = new ArrayList<>(); locationList.add(firePointEntity.getLongitude() + "," + firePointEntity.getLatitude()); GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList); GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0); String formattedAddress = reGeoCode.getFormatted_address(); firePointEntity.setFirePointAddress(formattedAddress); GaoDeIgGeocodeVo.AddressComponent addressComponent = reGeoCode.getAddressComponent().get(0); firePointEntity.setCountyCode(addressComponent.getAdcode()); firePointEntity.setCountyName(addressComponent.getDistrict()); String townCode = addressComponent.getTowncode(); String fixedTownCode = townCode.length() > 9 ? townCode.substring(0, 9) : townCode; firePointEntity.setStreetCode(fixedTownCode); firePointEntity.setStreetName(addressComponent.getTownship()); } /** * 根据火点编号更新审核状态 * 操作1:将火点编号对应的火点从山东火点表转存到火点表 * 操作2:将山东火点表中的这个火点的审核状态更新 */ @Transactional(rollbackOn = Exception.class) @Override public String updateVerifyStateByFireCode(String fireCode, String verifyState) { if ((!"0".equals(verifyState)) && (!"1".equals(verifyState)) && (!"2".equals(verifyState))) { return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "审核失败,审核状态参数错误", locale); } ShanDongFirePointEntity existShanDongFirePoint = shanDongFirePointDao.findByFireCode(fireCode); //山东火点表找不到这个火点,返回失败 if (existShanDongFirePoint == null) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "审核失败,没有指定的火点编号", locale); } if ("0".equals(existShanDongFirePoint.getVerifyState()) || "2".equals(existShanDongFirePoint.getVerifyState())) { if ("0".equals(verifyState)) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "审核失败,审核状态不能被设置为未审核", locale); } if ("1".equals(verifyState)) { //火点表能找到这个火点,返回失败 FirePointEntity existFirePoint = firePointDao.findByFireCode(fireCode); if (existFirePoint != null) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "修改失败,火点库已存在指定的火点编号", locale); } //操作1:将火点编号对应的火点从山东火点表转存到火点表 FirePointEntity firePoint = getFirePointByShanDongFirePoint(existShanDongFirePoint); log.info("-------转存新火点"); firePointDao.save(firePoint); //发送消息通知 sendBroadcast(firePoint); } //操作2:将山东火点表中的这个火点的审核状态更新 shanDongFirePointDao.updateVerifyStateByFireCode(fireCode, verifyState); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale); } //0或者2可以被审核为1(未审核和未通过可以被审核为通过),已经通过了的就不能再处理了 return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "审核失败,火点不能被重复审核", locale); } private void sendBroadcast(FirePointEntity firePointEntity) { //发送微信群聊消息 sendWeChatGroupMessage(firePointEntity); //过滤短信通知收件人 List sysUserList = sysUserDao.findAll(); List adminList = relRoleAuthorityDao.selectByAuthorityId(1); boolean normalSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(9L); boolean vipSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(10L); List smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePointEntity.getStreetCode(), sysUserList, adminList, normalSmsEnable, vipSmsEnable); //推送 try { List userAccountList = pushHelper.obtainUserAccountList(smsReceiverList); pushHelper.dispatchPushMessage(userAccountList, firePointEntity); } catch (Exception e) { e.printStackTrace(); } //对短信通知收件人进行分组 List agentOrgList = agentOrgDao.findAll(); Map> agentOrgNameGroupMap = FirePointCodeUtils.groupSmsReceiver(smsReceiverList, agentOrgList); //分发短信通知 smsHelper.dispatchSMSMessage(agentOrgNameGroupMap, new String[]{firePointEntity.getFirePointAddress()}, new FirePointEntity[]{firePointEntity}); } /** * 发送微信消息 * * @param firePointEntity */ private void sendWeChatGroupMessage(FirePointEntity firePointEntity) { List countyCodeWeiXinList = countyCodeWeiXinDao.findAll(); if (countyCodeWeiXinList.isEmpty()) { return; } List weixinIdList = new ArrayList<>(); for (CountyCodeWeiXinEntity countyCodeWeiXin : countyCodeWeiXinList) { try { if ((countyCodeWeiXin.getSendState() != null) && (countyCodeWeiXin.getSendState() != 0)) { String formatCutCode = FirePointCodeUtils.getFormatCutCode(countyCodeWeiXin.getCountyCode()); if (firePointEntity.getStreetCode().startsWith(formatCutCode)) { weixinIdList.add(countyCodeWeiXin.getWeixinId()); } } } catch (Exception e) { e.printStackTrace(); } } if (weixinIdList.size() > 0) { StringBuilder stringBuilder = new StringBuilder("发送微信消息通知:\n"); String messageContent = getMessageContent(firePointEntity); for (String weixinId : weixinIdList) { stringBuilder.append(weixinId).append("\n"); try { WDWxSendMsgUtil.sendMsg(weixinId, messageContent, 0); } catch (Exception e) { e.printStackTrace(); } } stringBuilder.append("火情信息:").append(messageContent); log.info(stringBuilder.toString()); } } private String getMessageContent(FirePointEntity firePointEntity) { java.text.DecimalFormat decimalFormat = new DecimalFormat("#.000000"); String satelliteTime = firePointEntity.getSatelliteTime(); String formatLongitude = decimalFormat.format(firePointEntity.getLongitude()); String formatLatitude = decimalFormat.format(firePointEntity.getLatitude()); String countyName = firePointEntity.getCountyName(); String streetName = firePointEntity.getStreetName(); String content = firePointEntity.getSatelliteType() + "发现1个火点。\n卫星时间:" + satelliteTime + ";\nlongitude:" + formatLongitude + ";\nlatitude:" + formatLatitude + ";\ncountyName:" + countyName + ";\nstreetName:" + streetName; return content; } private String getMessageContent(ShanDongFirePointEntity firePointEntity) { java.text.DecimalFormat decimalFormat = new DecimalFormat("#.000000"); String satelliteTime = firePointEntity.getSatelliteTime(); String formatLongitude = decimalFormat.format(firePointEntity.getLongitude()); String formatLatitude = decimalFormat.format(firePointEntity.getLatitude()); String countyName = firePointEntity.getCountyName(); String streetName = firePointEntity.getStreetName(); String content = firePointEntity.getSatelliteType() + "发现1个待审核火点。\n卫星时间:" + satelliteTime + ";\nlongitude:" + formatLongitude + ";\nlatitude:" + formatLatitude + ";\ncountyName:" + countyName + ";\nstreetName:" + streetName; return content; } /** * 下载VIP用户火点数据 */ @Override public String downloadVipUserFilePoint(HttpServletRequest request, HttpServletResponse response) { LocalDate now = LocalDate.now(); List> list = firePointDao.downloadFirePointByVip(dateTimeToString(LocalDateTime.of(now.minusDays(1), LocalTime.MIN))); if (list.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "无数据!", locale); } int year = now.getYear(); int month = now.getMonth().getValue(); int day = now.getDayOfMonth(); String fileName = String.format("%s_%s_%s_VIP用户火点信息列表.xlsx", year, month, day); response.setContentType("application/octet-stream; charset=UTF8"); response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8)); response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); try { downloadXlsx(list, response.getOutputStream()); } catch (IOException e) { log.error("download vip user's fire point fail: {}", e.getMessage()); } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "ok", locale); } @Override public String downloadFirePoint(HttpServletRequest request, HttpServletResponse response, String ids) { List idList = ListUtils.toStringList(ids, ","); if (idList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "无数据!", locale); } List> list = new ArrayList<>(); List sourceList = firePointDao.findAllById(ListUtils.stringListToLongList(idList)); for (FirePointEntity source : sourceList) { Map record = new HashMap<>(); record.put("所在区县", source.getCountyName()); record.put("所在街道", source.getStreetName()); record.put("发现时间", source.getSatelliteTime()); record.put("地物类型", source.getLandType()); record.put("经度", String.valueOf(source.getLongitude())); record.put("纬度", String.valueOf(source.getLatitude())); record.put("详细地址", source.getFirePointAddress()); list.add(record); } LocalDate now = LocalDate.now(); String fileName = String.format("%s_%s_%s_火点信息列表.xlsx", now.getYear(), now.getMonth().getValue(), now.getDayOfMonth()); response.setContentType("application/octet-stream; charset=UTF8"); response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8)); response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); try { downloadXlsx(list, response.getOutputStream()); } catch (IOException e) { log.error("download fire point fail: {}", e.getMessage()); } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "ok", locale); } /** * 动态多条件查询火点列表 * * @param code 区划编码,可以是省市区县街道任意编码,如果传需要至少两位。不传代表查询全国火点 * @param startTime 过滤火点开始卫星时间,不传代表不指定开始时间。后台会有限制。 * @param endTime 过滤火点结束卫星时间,不传代表不指定结束时间。 * @param satelliteType 过滤传感器类型,不传代表查询全部类型的传感器 * @param landType 过滤地物类型,不传代表查询全部地物类型 * @return 符合条件的火点列表 */ @Override public List queryFirePoint(String code, String startTime, String endTime, String satelliteType, String landType) { return firePointQueryHelper.queryFirePoint(code, startTime, endTime, satelliteType, landType); } /** * 查询今天的火点信息 */ // @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public List selectTodayFirePoint(String countyCode) { LocalDateTime startTime1 = LocalDateTime.now(); LocalDateTime startTime2 = LocalDateTime.of(startTime1.getYear(), startTime1.getMonth(), startTime1.getDayOfMonth(), 0, 0, 0, 0); String startTimeString = DateTimeUtils.localDateTimeToString(startTime2); LocalDateTime endTime1 = LocalDateTime.now().plusDays(1); LocalDateTime endTime2 = LocalDateTime.of(endTime1.getYear(), endTime1.getMonth(), endTime1.getDayOfMonth(), 0, 0, 0, 0); String endTimeString = DateTimeUtils.localDateTimeToString(endTime2); return firePointQueryHelper.queryFirePoint(countyCode, startTimeString, endTimeString, null, null); } /** * 查询近一周的火点信息 */ // @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public List selectFirePointBetweenSeven() { LocalDateTime startTime1 = LocalDateTime.now().minusDays(7); LocalDateTime startTime2 = LocalDateTime.of(startTime1.getYear(), startTime1.getMonth(), startTime1.getDayOfMonth(), 0, 0, 0, 0); String startTimeString = DateTimeUtils.localDateTimeToString(startTime2); LocalDateTime endTime1 = LocalDateTime.now().plusDays(1); LocalDateTime endTime2 = LocalDateTime.of(endTime1.getYear(), endTime1.getMonth(), endTime1.getDayOfMonth(), 0, 0, 0, 0); String endTimeString = DateTimeUtils.localDateTimeToString(endTime2); return firePointQueryHelper.queryFirePoint(null, startTimeString, endTimeString, null, null); } /** * 查询近一个月的火点信息 */ // @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public List selectFirePointByMonth(String countyCode) { // LocalDateTime startTime1 = LocalDateTime.now().minusMonths(1); // LocalDateTime startTime2 = LocalDateTime.of(startTime1.getYear(), startTime1.getMonth(), startTime1.getDayOfMonth(), 0, 0, 0, 0); // String startTimeString = DateTimeUtils.localDateTimeToString(startTime2); // // LocalDateTime endTime1 = LocalDateTime.now().plusDays(1); // LocalDateTime endTime2 = LocalDateTime.of(endTime1.getYear(), endTime1.getMonth(), endTime1.getDayOfMonth(), 0, 0, 0, 0); // String endTimeString = DateTimeUtils.localDateTimeToString(endTime2); // // return firePointQueryHelper.queryFirePoint(countyCode, startTimeString, endTimeString, null, null); List firePointEntities = firePointQueryHelper.queryFirePoint(countyCode, null, null, null, null); return firePointEntities; } /** * 查询近一个月的火点数量 * * @return */ // @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public String selectFirePointNumMonth() { Map map = new HashMap(3); LocalDateTime localDateTime = LocalDateTime.now(); LocalDateTime localDateTime2 = localDateTime.plusDays(1); String endTime = dateTimeToString(localDateTime2); // 当前时间减30 LocalDateTime localDateTime1 = localDateTime.minusDays(30); String startTime = dateTimeToString(localDateTime1); // 查询近一个月各植被类型的火点数量 List> maps = firePointDao.selectNumByLandType(startTime, endTime); map.put("land", maps); // 查询近一个月各地区火点数量 List> maps1 = firePointDao.selectNumByArea(startTime, endTime); map.put("area", maps1); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale); } /** * 查询近一天的火点数量 * * @return */ // @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public String selectFirePointNumDay() { Map map = new HashMap(3); LocalDateTime localDateTime = LocalDateTime.now(); LocalDateTime localDateTime2 = localDateTime.plusDays(1); String endTime = dateTimeToString(localDateTime2); // 当前时间减1 LocalDateTime localDateTime1 = localDateTime.minusDays(1); String startTime = dateTimeToString(localDateTime1); // 查询近一个月各植被类型的火点数量 List> maps = firePointDao.selectNumByLandType(startTime, endTime); map.put("land", maps); // 查询近一个月各地区火点数量 List> maps1 = firePointDao.selectNumByArea(startTime, endTime); map.put("area", maps1); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale); } /** * 查询近一周的火点数量 * * @return */ // @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public String selectFirePointNumWeek() { Map map = new HashMap(3); LocalDateTime localDateTime = LocalDateTime.now(); LocalDateTime localDateTime2 = localDateTime.plusDays(1); String endTime = dateTimeToString(localDateTime2); // 当前时间减7 LocalDateTime localDateTime1 = localDateTime.minusDays(7); String startTime = dateTimeToString(localDateTime1); // 查询近一个月各植被类型的火点数量 List> maps = firePointDao.selectNumByLandType(startTime, endTime); map.put("land", maps); // 查询近一个月各地区火点数量 List> maps1 = firePointDao.selectNumByArea(startTime, endTime); map.put("area", maps1); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale); } }