package com.xkrs.service.impl; import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.common.tool.TokenUtil; import com.xkrs.dao.*; import com.xkrs.model.entity.*; import com.xkrs.model.qo.FirePointQo; import com.xkrs.model.vo.AppPhotoVo; import com.xkrs.model.vo.AppTaskBodyVo; import com.xkrs.model.vo.GaoDeIgGeocodeVo; import com.xkrs.service.FirePointService; 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.cache.annotation.Cacheable; import org.springframework.cglib.beans.BeanCopier; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; 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 java.util.stream.Collectors; 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); @Resource private FirePointDao firePointDao; @Resource private SettingDao settingDao; @Resource private ShanDongFirePointDao shanDongFirePointDao; @Resource private Query query; @Resource private SysUserDao sysUserDao; @Resource private FireAndRangerDao fireAndRangerDao; @Resource private ForestRangerDao forestRangerDao; @Resource private FireTaskDao fireTaskDao; @Resource private JdbcUtils jdbcUtils; @Resource private FireTaskPhotoDao fireTaskPhotoDao; @Resource private CityDao cityDao; @Resource private CountyDao countyDao; @Resource private StreetDao streetDao; @Resource private FireDao fireDao; @Resource private NationwideDao nationwideDao; @Resource private CountyCodeWeiXinDao countyCodeWeiXinDao; @Resource private RelRoleAuthorityDao relRoleAuthorityDao; /** * 添加火点信息 * * @param firePointQo * @return */ @CacheEvict(value = "FirePointServiceCache", allEntries = true) @Override public FirePointEntity insertFirePoint(FirePointQo firePointQo) { if (firePointQo.getLandtype().equals("水体")) { return null; } if ("Himawari 8".equals(firePointQo.getSatelliteType()) && "L".equals(firePointQo.getConfidence())) { return null; } if ("Himawari 8".equals(firePointQo.getSatelliteType()) && "N".equals(firePointQo.getConfidence())) { return null; } 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.setFirePointAddress(AddressUtils.getLocal(firePointQo.getLatitude().toString(), firePointQo.getLongitude().toString())); 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 { bindStreetCodeName(firePointEntity); } catch (Exception e) { e.printStackTrace(); System.out.println("添加火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); } //如果开关已打开,就剔除山东的火点 boolean switchOpened = isSwitchStateOpen(); if (switchOpened && firePointEntity.getCountyCode().startsWith("37")) { return null; } //如果开关已关闭,所有火点都入全国火点库 FirePointEntity existFireCode = firePointDao.findByFireCode(firePointEntity.getFireCode()); if (existFireCode != null) { return null; } log.info("-------发现新火点"); FirePointEntity savedFirePointEntity = firePointDao.save(firePointEntity); //如果开关关闭了,山东的火点发送短信微信 if ((!switchOpened) && firePointEntity.getCountyCode().startsWith("37")) { sendBroadcast(firePointEntity); } return savedFirePointEntity; } /** * 添加火点信息 * * @param firePointQo * @return */ @CacheEvict(value = "FirePointServiceCache", allEntries = true) @Override public ShanDongFirePointEntity insertFirePointChannelTwo(FirePointQo firePointQo) { if (firePointQo.getLandtype().equals("水体")) { return null; } if ("Himawari 8".equals(firePointQo.getSatelliteType()) && "L".equals(firePointQo.getConfidence())) { return null; } if ("Himawari 8".equals(firePointQo.getSatelliteType()) && "N".equals(firePointQo.getConfidence())) { return null; } ShanDongFirePointEntity firePointEntity = new ShanDongFirePointEntity(); 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.setFirePointAddress(AddressUtils.getLocal(firePointQo.getLatitude().toString(), firePointQo.getLongitude().toString())); 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.setVerifyState("0"); try { bindStreetCodeName(firePointEntity); } catch (Exception e) { e.printStackTrace(); System.out.println("添加山东火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); } //如果开关已打开,就把山东火点入山东火点库 if (isSwitchStateOpen() && firePointEntity.getCountyCode().startsWith("37")) { ShanDongFirePointEntity existFireCode = shanDongFirePointDao.findByFireCode(firePointEntity.getFireCode()); if (existFireCode != null) { return null; } log.info("-------发现新山东火点"); ShanDongFirePointEntity savedFirePointEntity = shanDongFirePointDao.save(firePointEntity); try {//微信消息通知工作组 String messageContent = getMessageContent(firePointEntity); WDWxSendMsgUtil.sendMsg("18447024917@chatroom", messageContent, 0); } catch (Exception e) { e.printStackTrace(); } return savedFirePointEntity; } return null; } /** * 返回开关是否为打开状态 * * @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 bindStreetCodeName(FirePointEntity firePointEntity) throws Exception { List locationList = new ArrayList<>(); locationList.add(firePointEntity.getLongitude() + "," + firePointEntity.getLatitude()); GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList); String townCode = geocode.getRegeocodes().get(0).getAddressComponent().get(0).getTowncode(); if (townCode.length() > 9) { townCode = townCode.substring(0, 9); } firePointEntity.setStreetCode(townCode); List byStreetCode = streetDao.findByStreetCode(townCode); if (byStreetCode != null && byStreetCode.size() > 0) { firePointEntity.setStreetName(byStreetCode.get(0).getStreetName()); } } /** * 为实体类设置街道编号和街道名称 */ private void bindStreetCodeName(ShanDongFirePointEntity firePointEntity) throws Exception { List locationList = new ArrayList<>(); locationList.add(firePointEntity.getLongitude() + "," + firePointEntity.getLatitude()); GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList); String townCode = geocode.getRegeocodes().get(0).getAddressComponent().get(0).getTowncode(); if (townCode.length() > 9) { townCode = townCode.substring(0, 9); } firePointEntity.setStreetCode(townCode); List byStreetCode = streetDao.findByStreetCode(townCode); if (byStreetCode != null && byStreetCode.size() > 0) { firePointEntity.setStreetName(byStreetCode.get(0).getStreetName()); } } /** * 根据火点编号更新审核状态 * 操作1:将火点编号对应的火点从山东火点表转存到火点表 * 操作2:将山东火点表中的这个火点的审核状态更新 */ @Transactional(rollbackOn = Exception.class) @Override public String updateVerifyStateByFireCode(String fireCode, String verifyState) { // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); ShanDongFirePointEntity existShanDongFirePoint = shanDongFirePointDao.findByFireCode(fireCode); //山东火点表找不到这个火点,返回失败 if (existShanDongFirePoint == null) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "修改失败,没有指定的火点编号", locale); } if ("1".equals(verifyState)) { //火点表能找到这个火点,返回失败 FirePointEntity existFirePoint = firePointDao.findByFireCode(fireCode); if (existFirePoint != null) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "修改失败,火点库已存在指定的火点编号", locale); } //完成第一步:将山东火点表中的火点转存到火点表,初始化为未审核状态 FirePointEntity firePointEntity = new FirePointEntity(); firePointEntity.setFireCode(existShanDongFirePoint.getFireCode()); firePointEntity.setCountyCode(existShanDongFirePoint.getCountyCode()); firePointEntity.setCountyName(existShanDongFirePoint.getCountyName()); firePointEntity.setSatelliteTime(existShanDongFirePoint.getSatelliteTime()); firePointEntity.setLongitude(existShanDongFirePoint.getLongitude()); firePointEntity.setLatitude(existShanDongFirePoint.getLatitude()); firePointEntity.setFirePointAddress(existShanDongFirePoint.getFirePointAddress()); firePointEntity.setSatelliteType(existShanDongFirePoint.getSatelliteType()); firePointEntity.setLandType(existShanDongFirePoint.getLandType()); firePointEntity.setConfidence(existShanDongFirePoint.getConfidence()); firePointEntity.setAddTime(existShanDongFirePoint.getAddTime()); firePointEntity.setFireType(existShanDongFirePoint.getFireType()); firePointEntity.setFireImage(existShanDongFirePoint.getFireImage()); firePointEntity.setSatelliteImage(existShanDongFirePoint.getSatelliteImage()); firePointEntity.setStreetCode(existShanDongFirePoint.getStreetCode()); firePointEntity.setStreetName(existShanDongFirePoint.getStreetName()); firePointEntity.setAuditFireType("0");//初始化火点为未审核状态 log.info("-------转存新火点"); firePointDao.save(firePointEntity); //如果开关关闭了,山东的火点发送短信微信 if (firePointEntity.getCountyCode().startsWith("37")) { sendBroadcast(firePointEntity); } } shanDongFirePointDao.updateVerifyStateByFireCode(fireCode, verifyState); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale); } private void sendBroadcast(FirePointEntity firePointEntity) { //发送微信消息 sendWeiXinMessage(firePointEntity); //发送短信消息 sendSMSMessage(firePointEntity); } /** * 发送微信消息 * * @param firePointEntity */ private void sendWeiXinMessage(FirePointEntity firePointEntity) { List countyCodeWeiXinList = countyCodeWeiXinDao.findAll(); if (countyCodeWeiXinList.isEmpty()) { return; } List weixinIdList = new ArrayList<>(); for (CountyCodeWeiXinEntity countyCodeWeiXin : countyCodeWeiXinList) { String countyCode = countyCodeWeiXin.getCountyCode(); String startCountyCode = getStartCountyCode(countyCode); if (firePointEntity.getStreetCode().startsWith(startCountyCode)) { weixinIdList.add(countyCodeWeiXin.getWeixinId()); } } if (weixinIdList.size() > 0) { String messageContent = getMessageContent(firePointEntity); for (String weixinId : weixinIdList) { try { WDWxSendMsgUtil.sendMsg(weixinId, messageContent, 0); } catch (Exception e) { e.printStackTrace(); } } } } 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; } /** * 发送短信消息 * * @param firePointEntity */ private void sendSMSMessage(FirePointEntity firePointEntity) { List sysUserList = sysUserDao.findAll(); if (sysUserList.isEmpty()) { return; } List administratorList = relRoleAuthorityDao.selectByAuthorityId(1); List telephoneList = new ArrayList<>(); for (SysUserEntity sysUser : sysUserList) { try { String countyCode = sysUser.getCountyCode(); String startCountyCode = getStartCountyCode(countyCode); if (firePointEntity.getStreetCode().startsWith(startCountyCode)) { if (sysUser.getDeleteFlag() != 0) {//被删除的用户不发短信 continue; } if (sysUser.getActiveFlag() != 0) {//被禁用的用户不发短信 continue; } if (sysUser.getReceiveSms() != 1) {//关掉开关的用户不发短信 continue; } LocalDateTime sysUserOverDateTime = DateTimeUtil.stringToDateTimeFormatter(sysUser.getOverTime(), DateTimeUtil.COMMON_FORMATTER_DATETIME); if (sysUserOverDateTime.isBefore(DateTimeUtil.getNowTime())) {//过期用户不发短信 continue; } if (isAdministrator(administratorList, sysUser)) {//管理员用户不发短信 continue; } telephoneList.add("86" + sysUser.getUserName()); } } catch (Exception e) { e.printStackTrace(); continue; } } if (telephoneList.size() > 0) { String[] telephoneArray = telephoneList.toArray(new String[]{}); SendSms.sendSmsToUser(telephoneArray, "1425995", new String[]{firePointEntity.getFirePointAddress()}); } } /** * 判断是否是管理员 */ private boolean isAdministrator(List administratorList, SysUserEntity sysUser) { if (administratorList == null || administratorList.size() == 0) { return false; } for (RelRoleAuthorityEntity administrator : administratorList) { if (administrator.getUserId().intValue() == sysUser.getId().intValue()) { return true; } } return false; } private String getStartCountyCode(String countyCode) { try { String temp = countyCode; while (temp.endsWith("0")) { temp = temp.substring(0, temp.length() - 1); } return temp; } catch (Exception e) { e.printStackTrace(); } return null; } @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, "无数据!", LocaleContextHolder.getLocale()); } 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", LocaleContextHolder.getLocale()); } /** * 查询今天的火点信息 */ @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public List selectTodayFirePoint(String countyCode) { String addTime = DateTimeUtil.dateToString(LocalDate.now()); if (9 == countyCode.length()) { return firePointDao.selectTodayFirePointOneStreet(addTime, countyCode); } else if ("0000".equals(countyCode.substring(2))) { List byProCode = cityDao.findByProCode(countyCode); String proName = byProCode.get(0).getProName(); return firePointDao.selectTodayFirePoint(addTime, proName); } else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) { List byCityCode = countyDao.findByCityCode(countyCode); String cityName = byCityCode.get(0).getCityName(); return firePointDao.selectTodayFirePoint(addTime, cityName); } else { return firePointDao.selectTodayFirePointOne(addTime, countyCode); } } /** * 动态多条件查询火点信息(省) * * @param cityCode * @param satelliteType * @param landType * @param startTime * @param endTime * @return */ @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public List selectFirePoint(String proCode, String cityCode, String satelliteType, String landType, String startTime, String endTime) { List byProCode = cityDao.findByProCode(proCode); String proName = byProCode.get(0).getProName(); if (!"".equals(startTime) && !"".equals(endTime)) { LocalDate localDate = DateTimeUtil.stringToDate(endTime); // 结束时间 LocalDate localDate1 = localDate.plusDays(1); String dateToString = DateTimeUtil.dateToString(localDate1); return query.selectFirePointByPro(proName, cityCode, satelliteType, landType, startTime, dateToString); } return query.selectFirePointByPro(proName, cityCode, satelliteType, landType, startTime, endTime); } /** * 动态多条件查询火点信息(市) * * @param cityCode 市编码 * @param countyCode 县编码 * @param satelliteType * @param landType * @param startTime * @param endTime * @return */ @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public List selectFirePointByCity(String cityCode, String countyCode, String satelliteType, String landType, String startTime, String endTime) { List byCityCode = countyDao.findByCityCode(cityCode); String cityName = byCityCode.get(0).getCityName(); if (!"".equals(startTime) && !"".equals(endTime)) { LocalDate localDate = DateTimeUtil.stringToDate(endTime); // 结束时间 LocalDate localDate1 = localDate.plusDays(1); String dateToString = DateTimeUtil.dateToString(localDate1); return query.selectFirePointByCity(cityName, countyCode, satelliteType, landType, startTime, dateToString); } return query.selectFirePointByCity(cityName, countyCode, satelliteType, landType, startTime, endTime); } /** * 动态多条件查询火点信息(县) * * @param countyCode 县编码 * @param streetCode 街道编码 * @param satelliteType * @param landType * @param startTime * @param endTime * @return */ @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public List selectFirePointByCounty(String countyCode, String streetCode, String satelliteType, String landType, String startTime, String endTime) { if (!"".equals(startTime) && !"".equals(endTime)) { LocalDate localDate = DateTimeUtil.stringToDate(endTime); // 结束时间 LocalDate localDate1 = localDate.plusDays(1); String dateToString = DateTimeUtil.dateToString(localDate1); return query.selectFirePointByCounty(countyCode, streetCode, satelliteType, landType, startTime, dateToString); } return query.selectFirePointByCounty(countyCode, streetCode, satelliteType, landType, startTime, endTime); } @Override public List selectFirePointByStreet(String streetCode, String satelliteType, String landType, String startTime, String endTime) { if (!"".equals(startTime) && !"".equals(endTime)) { LocalDate localDate = DateTimeUtil.stringToDate(endTime); // 结束时间 LocalDate localDate1 = localDate.plusDays(1); String dateToString = DateTimeUtil.dateToString(localDate1); return query.selectFirePointByStreet(streetCode, satelliteType, landType, startTime, dateToString); } return query.selectFirePointByStreet(streetCode, satelliteType, landType, startTime, endTime); } /** * 根据火点编码修改火点的状态(预警) * * @param fireCode * @param fireType * @param token * @return */ @Transactional(rollbackOn = Exception.class) @Override public String updateTypeByFireCode(String fireCode, String fireType, String token) { // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); String tokenUserName = TokenUtil.getTokenUserName(token); SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName); FirePointEntity byFireCode = firePointDao.findByFireCode(fireCode); if ("3".equals(byFireCode.getFireType()) || "-1".equals(byFireCode.getFireType())) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "该火点已经结案,请勿进行有关状态操作", locale); } if (fireType.equals(byFireCode.getFireType())) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "您正处于当前的状态,请勿进行该操作", locale); } firePointDao.updateFireTypeByFireCode(fireCode, fireType); if ("1".equals(fireType)) { FirePointEntity byFireCode1 = firePointDao.findByFireCode(fireCode); // 预警 return outputEncapsulationObject(PromptMessageEnum.SUCCESS, byFireCode1, locale); } else if ("2".equals(fireType)) { FirePointEntity byFireCode3 = firePointDao.findByFireCode(fireCode); // 核查 return outputEncapsulationObject(PromptMessageEnum.SUCCESS, byFireCode3, locale); } else { String rangerType = "0"; FireAndRanger byFireCode1 = fireAndRangerDao.findByFireCode(fireCode); if (byFireCode1 == null) { FirePointEntity byFireCode4 = firePointDao.findByFireCode(fireCode); String time = dateTimeToString(LocalDateTime.now()); FireAndRanger fireAndRanger = new FireAndRanger(); fireAndRanger.setFireCode(fireCode); // 由于测试阶段先用用户账号代替,后期换成getReallyName(用户真实姓名) fireAndRanger.setHandler(sysUserEntity.getReallyName()); fireAndRanger.setEndTime(time); fireAndRangerDao.save(fireAndRanger); // 结案 return outputEncapsulationObject(PromptMessageEnum.SUCCESS, byFireCode4, locale); } // 火点结案,将护林员的状态修改为0 表示该护林员没有在执行任务,处于空闲状态 forestRangerDao.updateRangerTypeByPhone(byFireCode1.getRangerName(), rangerType); String time = dateTimeToString(LocalDateTime.now()); fireAndRangerDao.updateEndTimeByFireCode(fireCode, time); fireAndRangerDao.updateProgressTypeByFireCode(fireCode, "0"); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "结案", locale); } } /** * 提交核查任务 * * @param files * @param appTaskBodyVo * @return */ @Transactional(rollbackOn = Exception.class) @Override public String insertAppTask(MultipartFile[] files, AppTaskBodyVo appTaskBodyVo) throws IOException { // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); FirePointEntity byFireCode = firePointDao.findByFireCode(appTaskBodyVo.getFireCode()); if (byFireCode == null) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "火点编码错误,请重新输入", locale); } FireTask byTaskFireCode = fireTaskDao.findByTaskFireCode(appTaskBodyVo.getFireCode()); if (byTaskFireCode != null) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "该火点的任务已经提交,请勿重复提交", locale); } String s = dateTimeToString(LocalDateTime.now()); FireTask fireTask = new FireTask(); fireTask.setTaskFireCode(appTaskBodyVo.getFireCode()); fireTask.setTaskInformation(appTaskBodyVo.getTaskInformation()); fireTask.setTaskTime(s); FireTask save = fireTaskDao.save(fireTask); if (save == null) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "任务提交失败", locale); } List fireTaskPhotos = PhotoUtil.uploadImage(files, appTaskBodyVo.getFireCode()); List fireTaskPhotos1 = fireTaskPhotoDao.saveAll(fireTaskPhotos); if (fireTaskPhotos1 == null || fireTaskPhotos1.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "图片上传失败,任务提交失败", locale); } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "任务提交成功", locale); } /** * 根据火点编码查询任务信息 * * @param fireCode * @return * @throws Exception */ @Override public String selectAppTask(String fireCode) throws Exception { // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); FireTask byTaskFireCode = fireTaskDao.findByTaskFireCode(fireCode); if (byTaskFireCode == null) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有该火点的任务信息", locale); } AppTaskBodyVo appTaskBodyVo = new AppTaskBodyVo(); // 做映射,返回vo类对象 BeanCopier beanCopier = BeanCopier.create(FireTask.class, AppTaskBodyVo.class, false); beanCopier.copy(byTaskFireCode, appTaskBodyVo, null); List photoPath = fireTaskPhotoDao.findPhotoPath(fireCode); List appPhotoVos = ObjectToBeanUtils.objectToBean(photoPath, AppPhotoVo.class); appTaskBodyVo.setTaskFirePhoto(appPhotoVos); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, appTaskBodyVo, locale); } /** * 查询近一周的火点信息 * * @return */ @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public List selectFirePointBetweenSeven() { LocalDateTime localDateTime = LocalDateTime.now(); String endTime = dateTimeToString(localDateTime); // 当前时间减7 LocalDateTime localDateTime1 = localDateTime.minusDays(7); String startTime = dateTimeToString(localDateTime1); return query.selectFirePointBetweenThree(startTime, endTime); } /** * 查询近一个月的火点信息 * * @return */ @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public List selectFirePointByMonth(String countyCode) { LocalDateTime localDateTime = LocalDateTime.now(); String endTime = dateTimeToString(localDateTime); // 当前时间减31 LocalDateTime localDateTime1 = localDateTime.minusDays(31); String startTime = dateTimeToString(localDateTime1); if (9 == countyCode.length()) { return query.selectFirePointByMonthStreet(countyCode, startTime, endTime); } else if ("0000".equals(countyCode.substring(2))) { List byProCode = cityDao.findByProCode(countyCode); String proName = byProCode.get(0).getProName(); return query.selectFirePointByMonthPro(proName, startTime, endTime); } else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) { List byCityCode = countyDao.findByCityCode(countyCode); String cityName = byCityCode.get(0).getCityName(); return query.selectFirePointByMonthCity(cityName, startTime, endTime); } else { return query.selectFirePointByMonthCounty(countyCode, startTime, endTime); } } /** * 查询近一个月的火点数量 * * @return */ @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override public String selectFirePointNumMonth() { // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); 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() { // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); 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() { // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); 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); } /** * 查询该省所有的市 * * @param code * @return */ @Override public List> selectCityName(String code) { return cityDao.selectCityName(code); } /** * 查询市包含的区县和编码 * * @param code * @return */ @Override public List> selectCountyName(String code) { return countyDao.selectCountyName(code); } /** * 测试插入火点信息 * * @param firePointQo * @return */ @Override public FirePoint insertFireTest(FirePointQo firePointQo) { FirePoint firePoint = new FirePoint(); firePoint.setFireCode(firePointQo.getFireCode()); firePoint.setCountyCode(firePointQo.getCountyCode().toString()); firePoint.setCountyName(firePointQo.getCountyName()); firePoint.setSatelliteTime(DateTimeUtil.timeMillisToString(firePointQo.getSatelliteTimeTs().longValue())); firePoint.setLongitude(firePointQo.getLongitude()); firePoint.setLatitude(firePointQo.getLatitude()); firePoint.setFirePointAddress(AddressUtils.getLocal(firePointQo.getLatitude().toString(), firePointQo.getLongitude().toString())); firePoint.setSatelliteType(firePointQo.getSatelliteType()); firePoint.setLandType(firePointQo.getLandtype()); firePoint.setConfidence(firePointQo.getConfidence()); firePoint.setAddTime(dateTimeToString(LocalDateTime.now())); firePoint.setFireType("0"); firePoint.setFireImage(firePointQo.getFireImage()); firePoint.setSatelliteImage(firePointQo.getSatelliteImage()); log.info("-------发现新火点"); return fireDao.save(firePoint); } /** * 导入全国省市区 * * @param file * @throws Exception */ @Transactional(rollbackOn = Exception.class) @Override public void importCityExcel(MultipartFile file) throws Exception { //调用封装好的工具 ExcelImportUtil importUtil = new ExcelImportUtil(file); //调用导入的方法,获取sheet表的内容 List> maps = importUtil.readExcelContent(); //导入订单详情表 List orderDetails = maps.stream().filter(Objects::nonNull).map(map -> { Nationwide nationwide = new Nationwide(); nationwide.setProName(map.get("pro_name")); nationwide.setProCode(map.get("pro_code")); nationwide.setCityName(map.get("city_name")); nationwide.setCityCode(map.get("city_code")); nationwide.setCountyName(map.get("town_name")); nationwide.setCountyCode(map.get("town_code")); return nationwide; }).collect(Collectors.toList()); //批量添加到订单详情 nationwideDao.saveAll(orderDetails); } /** * 查询今日的火点信息(测试) * * @param countyCode * @return */ @Override public List selectTodayFire(String countyCode) { String addTime = DateTimeUtil.dateToString(LocalDate.now()); if ("0000".equals(countyCode.substring(2))) { List byProCode = cityDao.findByProCode(countyCode); String proName = byProCode.get(0).getProName(); return fireDao.selectTodayFire(addTime, proName); } else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) { List byCityCode = countyDao.findByCityCode(countyCode); String cityName = byCityCode.get(0).getCityName(); return fireDao.selectTodayFire(addTime, cityName); } else { return fireDao.selectTodayFireOne(addTime, countyCode); } } /** * 更新火点的街道编号数据 * * @return */ @Override public String updateFirePointStreetCode() { System.out.println("开始格式化街道编号"); List firePointEntityList = firePointDao.selectAbnormalStreetCode(); long startTimeMillis = System.currentTimeMillis(); int listSize = firePointEntityList.size(); for (int i = 0; i < listSize; i++) { try { FirePointEntity firePointEntity = firePointEntityList.get(i); List locationList = new ArrayList<>(); locationList.add(firePointEntity.getLongitude() + "," + firePointEntity.getLatitude()); GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList); String townCode = geocode.getRegeocodes().get(0).getAddressComponent().get(0).getTowncode(); if (townCode.length() > 9) { townCode = townCode.substring(0, 9); } firePointDao.updateStreetCodeById(firePointEntity.getId(), townCode); if (i % 10 == 0) { long spendTimeMillis = System.currentTimeMillis() - startTimeMillis; double remainTimeMillis = (listSize - i) * spendTimeMillis * 1D / i; System.out.println("已完成(" + i + "/" + listSize + "),用时" + formatDuring(spendTimeMillis) + ",剩余" + formatDuring((long) remainTimeMillis)); } } catch (Exception e) { e.printStackTrace(); System.out.println("街道编号格式化出现错误:" + e.getMessage()); } } Locale locale = LocaleContextHolder.getLocale(); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "街道编号格式化完毕", locale); } public static String formatDuring(long mss) { long days = mss / (1000 * 60 * 60 * 24); long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60); long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60); long seconds = (mss % (1000 * 60)) / 1000; if (days <= 0 && hours <= 0 && minutes <= 0) { return seconds + " 秒 "; } if (days <= 0 && hours <= 0) { return minutes + " 分钟 " + seconds + " 秒 "; } if (days <= 0) { return hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 "; } return days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 "; } }