From b552c4167b60c0ef079f99227d52a977a22ab5ab Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Mon, 6 Mar 2023 17:29:46 +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 --- .../DispatchFirePointController.java | 9 +++- .../utils/FirePointSubscribeManager.java | 44 ++++++++++++------- .../xkrs/straw/utils/VipTimeRangeUtils.java | 2 +- .../java/com/xkrs/utils/HttpClientUtils.java | 2 +- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/xkrs/straw/controller/DispatchFirePointController.java b/src/main/java/com/xkrs/straw/controller/DispatchFirePointController.java index bb37797..5ab871a 100644 --- a/src/main/java/com/xkrs/straw/controller/DispatchFirePointController.java +++ b/src/main/java/com/xkrs/straw/controller/DispatchFirePointController.java @@ -4,6 +4,7 @@ import com.xkrs.service.impl.FirePointServiceImpl; import com.xkrs.straw.dao.SysUserDao; import com.xkrs.straw.model.qo.AllFirePointQo; import com.xkrs.straw.service.DispatchFirePointService; +import com.xkrs.straw.utils.FirePointSubscribeManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.GetMapping; @@ -21,6 +22,8 @@ public class DispatchFirePointController { private SysUserDao sysUserDao; @Resource private DispatchFirePointService firePointService; + @Resource + private FirePointSubscribeManager firePointSubscribeManager; @GetMapping("/debug") public String debug() { @@ -46,7 +49,11 @@ public class DispatchFirePointController { // sysUserEntity.setVipTimeRangeJson(serialize); // sysUserDao.save(sysUserEntity); // } - return "OKkkkkkkk"; + + return firePointSubscribeManager.autoSync(); + + +// return "OKkkkkkkk"; } /** diff --git a/src/main/java/com/xkrs/straw/utils/FirePointSubscribeManager.java b/src/main/java/com/xkrs/straw/utils/FirePointSubscribeManager.java index 166eb17..aad7a77 100644 --- a/src/main/java/com/xkrs/straw/utils/FirePointSubscribeManager.java +++ b/src/main/java/com/xkrs/straw/utils/FirePointSubscribeManager.java @@ -1,5 +1,6 @@ package com.xkrs.straw.utils; +import com.fasterxml.jackson.databind.ObjectMapper; import com.xkrs.straw.dao.FirePointChannelConfigDao; import com.xkrs.straw.dao.SysUserDao; import com.xkrs.straw.model.bean.DataWrapper4; @@ -9,13 +10,14 @@ import com.xkrs.straw.model.entity.FirePointChannelConfigEntity; import com.xkrs.straw.model.entity.SysUserEntity; import com.xkrs.utils.DateTimeUtils; import com.xkrs.utils.FirePointCodeUtils; +import com.xkrs.utils.ListUtils; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; +import java.util.*; + +import static com.xkrs.utils.HttpClientUtils.sendHttpPost; @Component public class FirePointSubscribeManager { @@ -26,9 +28,9 @@ public class FirePointSubscribeManager { @Resource private SysUserDao sysUserDao; - public void autoSync() { + public String autoSync() { List subscribedCountyCodeList = obtainSubscribedCountyCodeList(); - updateSubscribedCountyCodeList(subscribedCountyCodeList); + return updateSubscribedCountyCodeList(subscribedCountyCodeList); } /** @@ -52,13 +54,21 @@ public class FirePointSubscribeManager { return mergedCountyCodeList; } - private void updateSubscribedCountyCodeList(List subscribedCountyCodeList) { -// String url = "http://118.24.27.47:10721/winxin_api/msg"; -// Map map = new HashMap<>(); -// map.put("wxid", wxid); -// map.put("text", text); -// map.put("type", type); -// sendHttpPost(url, new ObjectMapper().writeValueAsString(map)); + private String updateSubscribedCountyCodeList(List subscribedCountyCodeList) { + try { + String paramContent = ListUtils.fromStringList(subscribedCountyCodeList, ","); + System.out.println(paramContent); + String subscribeUrl = "http://192.168.2.46:8800/push-firepoint/ModifySystemMessages"; + Map map = new HashMap<>(); + map.put("name", "秸秆火系统"); + map.put("url", "http://192.168.2.36:6821/insertFirePointChannelPrecise"); + map.put("param", paramContent); + map.put("typeOfLand", "耕地"); + return sendHttpPost(subscribeUrl, new ObjectMapper().writeValueAsString(map)); + } catch (Exception e) { + e.printStackTrace(); + return e.getMessage(); + } } /** @@ -72,11 +82,11 @@ public class FirePointSubscribeManager { if (FirePointChannelConfigBean.Precise.equals(firePointChannelConfigBean.getChannelName())) { List channelConfigList = firePointChannelConfigBean.getConfigList(); for (FirePointChannelConfigBean.ChannelConfig channelConfig : channelConfigList) { - LocalDateTime startLocalDateTime = LocalDateTime.parse(channelConfig.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1); - startLocalDateTime.plusYears(LocalDateTime.now().getYear() - startLocalDateTime.getYear()); - LocalDateTime endLocalDateTime = LocalDateTime.parse(channelConfig.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1); - endLocalDateTime.plusYears(LocalDateTime.now().getYear() - endLocalDateTime.getYear()); - timeRangeList.add(new LocalDateTimeRange(startLocalDateTime, endLocalDateTime)); + 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)); } } } diff --git a/src/main/java/com/xkrs/straw/utils/VipTimeRangeUtils.java b/src/main/java/com/xkrs/straw/utils/VipTimeRangeUtils.java index b463059..b569a9f 100644 --- a/src/main/java/com/xkrs/straw/utils/VipTimeRangeUtils.java +++ b/src/main/java/com/xkrs/straw/utils/VipTimeRangeUtils.java @@ -91,7 +91,7 @@ public class VipTimeRangeUtils { } return 0; }).collect(Collectors.toList()); - log.info("原始集合size=" + list.size() + ",格式化后的集合size=" + vipLocalDateTimeRangePairList.size() + ",排序后的集合size=" + sortedVipLocalDateTimeRangePairList.size()); +// log.info("原始集合size=" + list.size() + ",格式化后的集合size=" + vipLocalDateTimeRangePairList.size() + ",排序后的集合size=" + sortedVipLocalDateTimeRangePairList.size()); return sortedVipLocalDateTimeRangePairList; } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/xkrs/utils/HttpClientUtils.java b/src/main/java/com/xkrs/utils/HttpClientUtils.java index 045f3f5..6d6891c 100644 --- a/src/main/java/com/xkrs/utils/HttpClientUtils.java +++ b/src/main/java/com/xkrs/utils/HttpClientUtils.java @@ -33,7 +33,7 @@ import java.security.cert.X509Certificate; */ public class HttpClientUtils { - private static final boolean printLog = false; + private static final boolean printLog = true; private static final Logger log = LoggerFactory.getLogger(HttpClientUtils.class);