From 70605e2fe053e0dc1b6dcf5b6cc4077ad7e39d36 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Sat, 4 Mar 2023 17:24:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/xkrs/dao/FirePointDao.java | 8 - .../com/xkrs/service/FirePointService.java | 13 -- .../service/impl/FirePointServiceImpl.java | 151 +----------------- .../straw/controller/FirePointController.java | 14 +- .../straw/utils/FirePointFilterUtils.java | 14 ++ 5 files changed, 25 insertions(+), 175 deletions(-) diff --git a/src/main/java/com/xkrs/dao/FirePointDao.java b/src/main/java/com/xkrs/dao/FirePointDao.java index 89b7c3f..9bc4e1c 100644 --- a/src/main/java/com/xkrs/dao/FirePointDao.java +++ b/src/main/java/com/xkrs/dao/FirePointDao.java @@ -12,14 +12,6 @@ import java.util.Map; @Component public interface FirePointDao extends JpaRepository, JpaSpecificationExecutor { - /** - * 根据火点编码查询火点信息 - */ - FirePointEntity findByFireCode(String fireCode); - - @Query(value = "SELECT * FROM fire_point WHERE longitude = ?1 AND latitude = ?2 AND street_code = ?3 AND satellite_time = ?4 AND satellite_type = ?5 AND land_type = ?6", nativeQuery = true) - List findDuplicatedData(double longitude, double latitude, String streetCode, String satelliteTime, String satelliteType, String landType); - @Query(value = "select a.really_name 姓名, a.county_name 所在市, a.telephone 手机号, a.vip_level vip, b.satellite_time 扫描时间, " + "round(cast(b.longitude as numeric) ,6) 经度, round(cast(b.latitude as numeric) ,6) 纬度, b.fire_point_address 详细地址 from sys_user a left join fire_point b on " + "case when left(a.county_code, 4) = '0000' then left(b.county_code, 4) = left(a.county_code, 4) " + "when left(a.county_code, 2) = '00' then left(b.county_code, 2) = left(a.county_code, 2) " + "else left(b.county_code, 2) = left(a.county_code, 2) end where a.vip_level > 0 and satellite_time > ?1", nativeQuery = true) List> downloadFirePointByVip(String yesterday); diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index 75f5eb2..0a7f4e8 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -1,7 +1,5 @@ package com.xkrs.service; -import com.xkrs.model.qo.FirePointQo; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -10,19 +8,8 @@ import javax.servlet.http.HttpServletResponse; */ public interface FirePointService { - /** - * 添加火点信息 - * - * @param firePointQo - * @return - */ - boolean insertFirePoint(FirePointQo firePointQo); - /** * download vip user's fire point - * - * @param request - * @param response */ String downloadVipUserFilePoint(HttpServletRequest request, HttpServletResponse response); diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 1e9d019..9e4802a 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -4,10 +4,7 @@ import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.dao.CountyCodeWeiXinDao; import com.xkrs.dao.FirePointDao; import com.xkrs.dao.StreetDao; -import com.xkrs.model.entity.CountyCodeWeiXinEntity; import com.xkrs.model.entity.FirePointEntity; -import com.xkrs.model.qo.FirePointQo; -import com.xkrs.model.vo.GaoDeIgGeocodeVo; import com.xkrs.service.FirePointService; import com.xkrs.service.StreetService; import com.xkrs.straw.dao.FirePointOrdinaryDao; @@ -20,12 +17,14 @@ import com.xkrs.straw.model.helper.SMSHelper; import com.xkrs.straw.model.vo.AllFirePointVo; import com.xkrs.straw.utils.FirePointConvertUtils; import com.xkrs.straw.utils.FirePointQueryManager; -import com.xkrs.utils.*; +import com.xkrs.utils.DateTimeUtils; +import com.xkrs.utils.FirePointQueryHelper; +import com.xkrs.utils.ListUtils; +import com.xkrs.utils.TokenUtil; import org.apache.hc.core5.util.TextUtils; 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.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; @@ -38,7 +37,6 @@ import javax.servlet.http.HttpServletResponse; 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; @@ -89,147 +87,6 @@ public class FirePointServiceImpl implements FirePointService { @Resource private FirePointOrdinaryDao firePointOrdinaryDao; - /** - * 添加火点信息 - */ - @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");//初始化火点为未审核状态 - bindAddress(firePointEntity); - if (checkDuplicatedData(firePointEntity)) { - log.info("-------该火点和历史火点重复,不入库"); - return false; - } - log.info("-------发现新火点"); - firePointDao.save(firePointEntity); - //发送消息通知 - sendBroadcast(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() > 0; - } - - /** - * 为实体类绑定地址、编号、名称 - */ - private void bindAddress(FirePointEntity firePointEntity) { - 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 sendBroadcast(FirePointEntity firePointEntity) { - //发送微信群聊消息 - sendWeChatGroupMessage(firePointEntity); - - if ("耕地".equals(firePointEntity.getLandType())) { - //过滤短信通知收件人 - List sysUserList = sysUserDao.findAll(); - List smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePointEntity.getStreetCode(), sysUserList); -// //推送 -// try { -// List userAccountList = pushHelper.obtainUserAccountList(smsReceiverList); -// pushHelper.dispatchPushMessage(userAccountList, firePointEntity); -// } catch (Exception e) { -// e.printStackTrace(); -// } - //分发短信通知 - smsHelper.dispatchSMSMessage(smsReceiverList, 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 landType = firePointEntity.getLandType(); - return firePointEntity.getSatelliteType() + "发现1个火点。\n卫星时间:" + satelliteTime + ";\nlongitude:" + formatLongitude + ";\nlatitude:" + formatLatitude + ";\ncountyName:" + countyName + ";\nstreetName:" + streetName + ";\nlandType:" + landType; - } - /** * 下载VIP用户火点数据 */ diff --git a/src/main/java/com/xkrs/straw/controller/FirePointController.java b/src/main/java/com/xkrs/straw/controller/FirePointController.java index a3139b0..60e15ae 100644 --- a/src/main/java/com/xkrs/straw/controller/FirePointController.java +++ b/src/main/java/com/xkrs/straw/controller/FirePointController.java @@ -75,13 +75,13 @@ public class FirePointController { */ @PostMapping("/insertFirePoint") public String insertFirePoint(@RequestBody FirePointQo firePointQo) { - log.info("insertFirePoint 接收到火点信息:" + firePointQo.toString()); - boolean success = firePointService.insertFirePoint(firePointQo); - if (success) { - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale); - } else { - return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "添加失败", locale); - } +// log.info("insertFirePoint 接收到火点信息:" + firePointQo.toString()); +// boolean success = firePointService.insertFirePoint(firePointQo); +// if (success) { + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale); +// } else { +// return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "添加失败", locale); +// } } /** diff --git a/src/main/java/com/xkrs/straw/utils/FirePointFilterUtils.java b/src/main/java/com/xkrs/straw/utils/FirePointFilterUtils.java index 288f41e..e7d5fc9 100644 --- a/src/main/java/com/xkrs/straw/utils/FirePointFilterUtils.java +++ b/src/main/java/com/xkrs/straw/utils/FirePointFilterUtils.java @@ -28,7 +28,21 @@ public class FirePointFilterUtils { } public static DataWrapper2 checkDuplicated(FirePointOrdinaryDao firePointOrdinaryDao, FirePointOrdinaryEntity firePointOrdinaryEntity) { +/** + * 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() > 0; + * } + * + * + @Query(value = "SELECT * FROM fire_point WHERE longitude = ?1 AND latitude = ?2 AND street_code = ?3 AND satellite_time = ?4 AND satellite_type = ?5 AND land_type = ?6", nativeQuery = true) + List findDuplicatedData(double longitude, double latitude, String streetCode, String satelliteTime, String satelliteType, String landType); + if (checkDuplicatedData(firePointEntity)) { + log.info("-------该火点和历史火点重复,不入库"); + return false; + } + */ return null; }