From 61725d63b6f7a64e5f3fa2d703f7269ec6b0086d Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Wed, 12 Apr 2023 14:53:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=81=AB=E7=82=B9=E9=87=8D=E6=9E=84-=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E9=98=B2=E7=81=AB=E5=AD=A3=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xkrs/common/StaticScheduleTask.java | 6 +- .../DispatchFirePointController.java | 6 +- .../xkrs/dao/FirePointChannelConfigDao.java | 10 -- .../FireSeasonConfigServiceImpl.java | 4 - .../helper/FirePointSubscribeManager.java | 136 ------------------ .../bean/FirePointChannelConfigBean.java | 67 --------- .../entity/FirePointChannelConfigEntity.java | 50 ------- .../impl/DispatchFirePointServiceImpl.java | 4 - .../xkrs/utilsnew/FirePointDispatchUtils.java | 134 ----------------- 9 files changed, 6 insertions(+), 411 deletions(-) delete mode 100644 src/main/java/com/xkrs/dao/FirePointChannelConfigDao.java delete mode 100644 src/main/java/com/xkrs/helper/FirePointSubscribeManager.java delete mode 100644 src/main/java/com/xkrs/model/bean/FirePointChannelConfigBean.java delete mode 100644 src/main/java/com/xkrs/model/entity/FirePointChannelConfigEntity.java delete mode 100644 src/main/java/com/xkrs/utilsnew/FirePointDispatchUtils.java diff --git a/src/main/java/com/xkrs/common/StaticScheduleTask.java b/src/main/java/com/xkrs/common/StaticScheduleTask.java index 902e88f..782ef60 100644 --- a/src/main/java/com/xkrs/common/StaticScheduleTask.java +++ b/src/main/java/com/xkrs/common/StaticScheduleTask.java @@ -1,6 +1,6 @@ package com.xkrs.common; -import com.xkrs.helper.FirePointSubscribeManager; +import com.xkrs.fireseason.FireSeasonConfigService; import com.xkrs.utilsnew.DateTimeUtils; import com.xkrs.utilsnew.WeiXinMessageUtils; import org.springframework.context.annotation.Configuration; @@ -18,12 +18,12 @@ import java.time.LocalDateTime; public class StaticScheduleTask { @Resource - private FirePointSubscribeManager firePointSubscribeManager; + private FireSeasonConfigService fireSeasonConfigService; //每小时更新一次订阅 @Scheduled(cron = "0 0 * * * ?") private void syncSubscribe() { - firePointSubscribeManager.autoSync(); + fireSeasonConfigService.updateFireSeasonConfig(); } //每天中午12点测试一次微信消息推送 diff --git a/src/main/java/com/xkrs/controller/DispatchFirePointController.java b/src/main/java/com/xkrs/controller/DispatchFirePointController.java index 2ff9a72..9d9d4aa 100644 --- a/src/main/java/com/xkrs/controller/DispatchFirePointController.java +++ b/src/main/java/com/xkrs/controller/DispatchFirePointController.java @@ -4,7 +4,7 @@ import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.dao.FirePointOrdinaryDao; import com.xkrs.dao.StreetDao; import com.xkrs.dao.SysUserDao; -import com.xkrs.helper.FirePointSubscribeManager; +import com.xkrs.fireseason.FireSeasonConfigService; import com.xkrs.model.qo.AllFirePointQo; import com.xkrs.model.qo.UpdateFirePointQo; import com.xkrs.service.DispatchFirePointService; @@ -31,7 +31,7 @@ public class DispatchFirePointController { @Resource private DispatchFirePointService firePointService; @Resource - private FirePointSubscribeManager firePointSubscribeManager; + private FireSeasonConfigService fireSeasonConfigService; @Resource private FirePointOrdinaryDao firePointOrdinaryDao; @Resource @@ -79,7 +79,7 @@ public class DispatchFirePointController { @GetMapping("/autoSync") public String autoSync() { - return firePointSubscribeManager.autoSync(); + return fireSeasonConfigService.updateFireSeasonConfig(); } /** diff --git a/src/main/java/com/xkrs/dao/FirePointChannelConfigDao.java b/src/main/java/com/xkrs/dao/FirePointChannelConfigDao.java deleted file mode 100644 index d4a804a..0000000 --- a/src/main/java/com/xkrs/dao/FirePointChannelConfigDao.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.xkrs.dao; - -import com.xkrs.model.entity.FirePointChannelConfigEntity; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.stereotype.Component; - -@Component -public interface FirePointChannelConfigDao extends JpaRepository, JpaSpecificationExecutor { -} diff --git a/src/main/java/com/xkrs/fireseason/FireSeasonConfigServiceImpl.java b/src/main/java/com/xkrs/fireseason/FireSeasonConfigServiceImpl.java index 834bd60..65a79d1 100644 --- a/src/main/java/com/xkrs/fireseason/FireSeasonConfigServiceImpl.java +++ b/src/main/java/com/xkrs/fireseason/FireSeasonConfigServiceImpl.java @@ -1,7 +1,6 @@ package com.xkrs.fireseason; import com.fasterxml.jackson.databind.ObjectMapper; -import com.xkrs.dao.FirePointChannelConfigDao; import com.xkrs.dao.FirePointOrdinaryDao; import com.xkrs.dao.StreetDao; import com.xkrs.dao.SysUserDao; @@ -29,9 +28,6 @@ public class FireSeasonConfigServiceImpl implements FireSeasonConfigService { private final Locale locale = LocaleContextHolder.getLocale(); - @Resource - private FirePointChannelConfigDao channelConfigDao; - @Resource private FirePointOrdinaryDao firePointOrdinaryDao; diff --git a/src/main/java/com/xkrs/helper/FirePointSubscribeManager.java b/src/main/java/com/xkrs/helper/FirePointSubscribeManager.java deleted file mode 100644 index c62e7e1..0000000 --- a/src/main/java/com/xkrs/helper/FirePointSubscribeManager.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.xkrs.helper; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.xkrs.dao.FirePointChannelConfigDao; -import com.xkrs.dao.SysUserDao; -import com.xkrs.model.bean.FirePointChannelConfigBean; -import com.xkrs.model.bean.LocalDateTimeRange; -import com.xkrs.model.entity.FirePointChannelConfigEntity; -import com.xkrs.model.entity.SysUserEntity; -import com.xkrs.utilsnew.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.*; - -import static com.xkrs.utilsold.HttpClientUtils.sendHttpPostTextPlain; - -@Component -public class FirePointSubscribeManager { - - private static final Logger log = LoggerFactory.getLogger(FirePointSubscribeManager.class); - - @Resource - private FirePointChannelConfigDao channelConfigDao; - - @Resource - private SysUserDao sysUserDao; - - public String autoSync() { - long timeTag1 = System.currentTimeMillis(); - log.info("开始更新订阅:"); - List subscribedCountyCodeList = obtainSubscribedCountyCodeList(); - long timeTag2 = System.currentTimeMillis(); - log.info("更新订阅计算耗时:" + ((timeTag2 - timeTag1) / 1000D) + "秒。"); - String updateResult = updateSubscribedCountyCodeList(subscribedCountyCodeList); - long timeTag3 = System.currentTimeMillis(); - log.info("更新订阅请求耗时:" + ((timeTag3 - timeTag2) / 1000D) + "秒。"); - log.info("更新订阅结束,总耗时:" + ((timeTag3 - timeTag1) / 1000D) + "秒。"); - return updateResult; - } - - /** - * 获取订阅的区划编码集合 - */ - private List obtainSubscribedCountyCodeList() { - //查询防火季时间范围配置 - List channelConfigEntityList = channelConfigDao.findAll(); - //获取到防火季时间格式集合 - List fireSeasonTimeRangeList = obtainFireSeasonTimeRangeList(channelConfigEntityList); - //判断当前是否处于防火季 - boolean checkIfIn = checkIfIn(fireSeasonTimeRangeList, LocalDateTime.now()); - //不在防火季就返回空订阅 - if (!checkIfIn) { - return new ArrayList(); - } - //在防火季,就获取全部系统用户 - List countyCodeList = obtainCountyCodeList(sysUserDao.findAll()); - List mergedCountyCodeList = CountyCodeUtils.mergeCountyCodeList(countyCodeList); - mergedCountyCodeList.sort(Comparator.naturalOrder()); - return mergedCountyCodeList; - } - - private String updateSubscribedCountyCodeList(List subscribedCountyCodeList) { - try { - String paramContent = ListUtils.fromStringList(subscribedCountyCodeList, ","); - String subscribeUrl = "http://118.24.27.47:5060/push-firepoint/ModifySystemMessages"; - Map map = new HashMap<>(); - map.put("name", "秸秆火系统正式版"); - map.put("url", "http://118.24.27.47:6801/updateFirePoint"); - map.put("param", paramContent); - map.put("typeOfLand", "耕地"); - return sendHttpPostTextPlain(subscribeUrl, new ObjectMapper().writeValueAsString(map)); - } catch (Exception e) { - e.printStackTrace(); - return e.getMessage(); - } - } - - /** - * 获取到防火季时间格式集合 - */ - private List obtainFireSeasonTimeRangeList(List channelConfigEntityList) { - List timeRangeList = new ArrayList<>(); - for (FirePointChannelConfigEntity channelConfigEntity : channelConfigEntityList) { - String jsonContent = channelConfigEntity.getJsonContent(); - FirePointChannelConfigBean firePointChannelConfigBean = JsonUtils.deserialize(jsonContent, FirePointChannelConfigBean.class); - if (FirePointChannelConfigBean.Precise.equals(firePointChannelConfigBean.getChannelName())) { - List channelConfigList = firePointChannelConfigBean.getConfigList(); - for (FirePointChannelConfigBean.ChannelConfig channelConfig : channelConfigList) { - LocalDateTime oldStartTime = LocalDateTime.parse(channelConfig.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1); - LocalDateTime newStartTime = oldStartTime.plusYears(LocalDateTime.now().getYear() - oldStartTime.getYear()); - LocalDateTime oldEndTime = LocalDateTime.parse(channelConfig.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1); - LocalDateTime newEndTime = oldEndTime.plusYears(LocalDateTime.now().getYear() - oldEndTime.getYear()); - timeRangeList.add(new LocalDateTimeRange(newStartTime, newEndTime)); - } - } - } - return timeRangeList; - } - - /** - * 判断targetTime是否属于timeRangeList范围内 - * 实际应用:也就是当前时间是否属于防火季 - */ - private boolean checkIfIn(List timeRangeList, LocalDateTime targetTime) { - for (LocalDateTimeRange timeRange : timeRangeList) { - LocalDateTime startTime = timeRange.getStartTime(); - LocalDateTime endTime = timeRange.getEndTime(); - if (startTime.isBefore(targetTime) && endTime.isAfter(targetTime)) { - return true; - } - } - return false; - } - - /** - * 获取全部VIP用户的区划编码 - */ - private List obtainCountyCodeList(List sysUserEntityList) { - List countyCodeList = new ArrayList<>(); - for (SysUserEntity sysUserEntity : sysUserEntityList) { - if ("管理员".equals(sysUserEntity.getAccountType())) {//管理员用户不计入订阅 - continue; - } - boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(sysUserEntity.getVipTimeRangeJson()); - if (inVipTimeRange) { - countyCodeList.add(sysUserEntity.getCountyCode()); - } - } - return countyCodeList; - } - -} diff --git a/src/main/java/com/xkrs/model/bean/FirePointChannelConfigBean.java b/src/main/java/com/xkrs/model/bean/FirePointChannelConfigBean.java deleted file mode 100644 index 6c590e5..0000000 --- a/src/main/java/com/xkrs/model/bean/FirePointChannelConfigBean.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.xkrs.model.bean; - -import java.util.List; - -public class FirePointChannelConfigBean { - - public static final String Ordinary = "Ordinary"; - public static final String Precise = "Precise"; - - /** - * 渠道名称 - */ - private String channelName; - - /** - * 渠道配置列表 - */ - private List configList; - - /** - * 渠道配置 - */ - public static class ChannelConfig { - - /** - * 开始时间 - */ - private String startTime; - - /** - * 结束时间 - */ - private String endTime; - - public String getStartTime() { - return startTime; - } - - public void setStartTime(String startTime) { - this.startTime = startTime; - } - - public String getEndTime() { - return endTime; - } - - public void setEndTime(String endTime) { - this.endTime = endTime; - } - } - - public String getChannelName() { - return channelName; - } - - public void setChannelName(String channelName) { - this.channelName = channelName; - } - - public List getConfigList() { - return configList; - } - - public void setConfigList(List configList) { - this.configList = configList; - } -} diff --git a/src/main/java/com/xkrs/model/entity/FirePointChannelConfigEntity.java b/src/main/java/com/xkrs/model/entity/FirePointChannelConfigEntity.java deleted file mode 100644 index 0cadc11..0000000 --- a/src/main/java/com/xkrs/model/entity/FirePointChannelConfigEntity.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.xkrs.model.entity; - -import javax.persistence.*; -import java.io.Serializable; - -@Entity -@Table(name = "fire_point_channel_config") -public class FirePointChannelConfigEntity implements Serializable { - - /** - * 指定主键,建立自增序列,主键值取自序列 - */ - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "fire_point_ordinary_seq_gen") - @SequenceGenerator(name = "fire_point_ordinary_seq_gen", sequenceName = "fire_point_ordinary_id_seq", allocationSize = 1) - private Long id; - - /** - * Json配置内容 - */ - @Column(length = 1024, columnDefinition = "varchar(1024)") - private String jsonContent; - - public FirePointChannelConfigEntity() { - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getJsonContent() { - return jsonContent; - } - - public void setJsonContent(String jsonContent) { - this.jsonContent = jsonContent; - } - - @Override - public String toString() { - return "FirePointChannelConfigEntity{" + - "id=" + id + - ", jsonContent='" + jsonContent + '\'' + - '}'; - } -} diff --git a/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java index e34ca4c..c5719c9 100644 --- a/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java @@ -1,7 +1,6 @@ package com.xkrs.service.impl; import com.xkrs.common.encapsulation.PromptMessageEnum; -import com.xkrs.dao.FirePointChannelConfigDao; import com.xkrs.dao.FirePointOrdinaryDao; import com.xkrs.dao.StreetDao; import com.xkrs.dao.SysUserDao; @@ -41,9 +40,6 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { private final Locale locale = LocaleContextHolder.getLocale(); - @Resource - private FirePointChannelConfigDao channelConfigDao; - @Resource private FirePointOrdinaryDao firePointOrdinaryDao; diff --git a/src/main/java/com/xkrs/utilsnew/FirePointDispatchUtils.java b/src/main/java/com/xkrs/utilsnew/FirePointDispatchUtils.java deleted file mode 100644 index 4a54f97..0000000 --- a/src/main/java/com/xkrs/utilsnew/FirePointDispatchUtils.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.xkrs.utilsnew; - -import com.xkrs.model.bean.FirePointChannelConfigBean; -import com.xkrs.model.entity.FirePointChannelConfigEntity; -import com.xkrs.service.impl.DispatchFirePointServiceImpl; -import org.apache.hc.core5.util.TextUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.time.LocalDateTime; -import java.util.List; - -public class FirePointDispatchUtils { - - public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class); - - private FirePointDispatchUtils() { - } - - /** - * 判断此时是否是防火季节 - * 如果是,那么审核火点表中数据来源是审核火点 - * 如果不是,那么审核火点表中数据来源是普通火点 - */ - public static boolean ifInFireSeason(String fireCode, LocalDateTime satelliteLocalDateTime, List firePointChannelConfigEntityList) { - if (firePointChannelConfigEntityList == null || firePointChannelConfigEntityList.size() == 0) { - int resValue1 = 0; - String errorMessage = "星科瑞升-秸秆火后台系统报错-检查火点卫星时间是否在精准渠道配置时间范围内-数据库配置集合-为null或size=0-火点编码=" + fireCode; - try { - resValue1 = SMSUtils.sendSmsToUser(new String[]{"8615764226530"}, "1425995", new String[]{errorMessage}); - } catch (Exception e) { - e.printStackTrace(); - } - log.info(errorMessage + (resValue1 == 0 ? "--短信通知发送成功" : "--短信通知发送失败")); - return true; - } - for (FirePointChannelConfigEntity firePointChannelConfigEntity : firePointChannelConfigEntityList) { - try { - String jsonContent = firePointChannelConfigEntity.getJsonContent(); - FirePointChannelConfigBean firePointChannelConfigBean = JsonUtils.deserialize(jsonContent, FirePointChannelConfigBean.class); - if (FirePointChannelConfigBean.Precise.equals(firePointChannelConfigBean.getChannelName())) { - List channelConfigList = firePointChannelConfigBean.getConfigList(); - if (channelConfigList == null || channelConfigList.size() == 0) { - int resValue1 = 0; - String errorMessage = "星科瑞升-秸秆火后台系统报错-检查火点卫星时间是否在精准渠道配置时间范围内-数据库配置项-时间列表-为null或size=0-火点编码=" + fireCode; - try { - resValue1 = SMSUtils.sendSmsToUser(new String[]{"8615764226530"}, "1425995", new String[]{errorMessage}); - } catch (Exception e) { - e.printStackTrace(); - } - log.info(errorMessage + (resValue1 == 0 ? "--短信通知发送成功" : "--短信通知发送失败")); - return true; - } - for (FirePointChannelConfigBean.ChannelConfig channelConfig : channelConfigList) { - //预处理开始时间 - String startTime = channelConfig.getStartTime();//获取精准火点渠道的开始时间 - boolean needCheckStartTime = !TextUtils.isEmpty(startTime); - LocalDateTime sameYearStartTime = null;//计算得出精准渠道和传入火点同年的开始时间 - if (needCheckStartTime) { - sameYearStartTime = obtainLocalDateTimeSameYear(satelliteLocalDateTime.getYear(), startTime); - needCheckStartTime = sameYearStartTime != null; - } - //预处理结束时间 - String endTime = channelConfig.getEndTime();//获取精准火点渠道的结束时间 - boolean needCheckEndTime = !TextUtils.isEmpty(endTime); - LocalDateTime sameYearEndTime = null;//计算得出精准渠道和传入火点同年的结束时间 - if (needCheckEndTime) { - sameYearEndTime = obtainLocalDateTimeSameYear(satelliteLocalDateTime.getYear(), endTime); - needCheckEndTime = sameYearEndTime != null; - } - //排列组合4种情况 - if (needCheckStartTime) { - if (needCheckEndTime) { - //开始时间、结束时间都需要比较 - if (sameYearStartTime.isBefore(satelliteLocalDateTime) && sameYearEndTime.isAfter(satelliteLocalDateTime)) { - String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime); - String time1 = DateTimeUtils.localDateTimeToString(sameYearStartTime); - String time2 = DateTimeUtils.localDateTimeToString(sameYearEndTime); - log.info("开始时间、结束时间都需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1 + ",结束时间=" + time2); - return true; - } - } else { - //开始时间需要比较,结束时间不需要比较 - if (sameYearStartTime.isBefore(satelliteLocalDateTime)) { - String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime); - String time1 = DateTimeUtils.localDateTimeToString(sameYearStartTime); - log.info("开始时间需要比较,结束时间不需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1); - return true; - } - } - } else { - if (needCheckEndTime) { - //开始时间不需要比较,结束时间需要比较 - if (sameYearEndTime.isAfter(satelliteLocalDateTime)) { - String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime); - String time2 = DateTimeUtils.localDateTimeToString(sameYearEndTime); - log.info("开始时间不需要比较,结束时间需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",结束时间=" + time2); - return true; - } - } else { - //开始时间、结束时间都不需要比较 - log.info("开始时间、结束时间都不需要比较,比较结果:属于精准时间范围内"); - return true; - } - } - } - } - } catch (Exception e) { - e.printStackTrace(); - log.info("检查渠道配置时间失败,错误=" + e.getMessage() + ",原始内容=" + firePointChannelConfigEntity.getJsonContent()); - } - } - //没有因为遇到符合条件的情况提前退出,就认为不属于精准渠道配置的时间范围之内 - return false; - } - - /** - * 将formattedTime转化为LocalDateTime格式,并将年字段设置为targetYear - * 转化失败返回null - * - * @param formattedTime 2022-01-01 00:00:00 - */ - private static LocalDateTime obtainLocalDateTimeSameYear(int targetYear, String formattedTime) { - try { - LocalDateTime localDateTime = LocalDateTime.parse(formattedTime, DateTimeUtils.DATE_TIME_FORMATTER_1); - int dYear = targetYear - localDateTime.getYear(); - return localDateTime.plusYears(dYear); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - -}