From 6488f40bb7777e1eda0c2c243df42e2c6c42ad84 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 2 Jun 2022 22:10:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=B1=E4=B8=9C=E4=B8=B4=E6=97=B6=E7=81=AB?= =?UTF-8?q?=E7=82=B9=E8=A1=A8=E5=88=B0=E5=85=A8=E5=9B=BD=E7=81=AB=E7=82=B9?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/FirePointController.java | 44 ++++++++-------- .../service/impl/FirePointServiceImpl.java | 50 +++++++++++-------- .../xkrs/service/impl/SysUserServiceImpl.java | 2 + .../java/com/xkrs/utils/DateTimeUtil.java | 10 ++-- 4 files changed, 60 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index 4b4713a..1b3f33b 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -6,7 +6,10 @@ import com.xkrs.dao.CountyCodeWeiXinDao; import com.xkrs.dao.FirePointDao; import com.xkrs.dao.ShanDongFirePointDao; import com.xkrs.dao.SysUserDao; -import com.xkrs.model.entity.*; +import com.xkrs.model.entity.FirePoint; +import com.xkrs.model.entity.FirePointEntity; +import com.xkrs.model.entity.ShanDongFirePointEntity; +import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.qo.AuditFireTypeQo; import com.xkrs.model.qo.FirePointQo; import com.xkrs.model.qo.ShanDongFirePointVerifyStateQo; @@ -15,11 +18,13 @@ import com.xkrs.service.FirePointService; import com.xkrs.service.StreetService; import com.xkrs.websocket.service.WebSocketServer; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.persistence.criteria.Predicate; import javax.transaction.Transactional; import java.io.IOException; import java.util.ArrayList; @@ -134,26 +139,25 @@ public class FirePointController { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale); } - /** - * 发短息 - * - * @return - */ - @GetMapping("/sem") - public String sem() { + @GetMapping("/queryshandongfirepointbytime") + public String queryShanDongFirePointByTime(@RequestParam(required = false, value = "startTime") String startTime, @RequestParam(required = false, value = "endTime") String endTime) { Locale locale = LocaleContextHolder.getLocale(); - - CountyCodeWeiXinEntity countyCodeWeiXinEntity = new CountyCodeWeiXinEntity(); - countyCodeWeiXinEntity.setCountyCode("370000"); - countyCodeWeiXinEntity.setWeixinId("18447024917@chatroom"); - countyCodeWeiXinDao.save(countyCodeWeiXinEntity); -// try { -// WDWxSendMsgUtil.sendMsg("18447024917@chatroom", "微信发消息测试66666", 0); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// SendSms.sendSmsToUser(new String[]{"8615764226530"}, "1425995", new String[]{"荒岛66666"}); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "shanDongFirePointList", locale); + Specification specification = (root, criteriaQuery, criteriaBuilder) -> { + List list = new ArrayList<>(); + if (startTime != null && !"".equals(startTime)) { + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); + } + if (endTime != null && !"".equals(endTime)) { + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); + } + Predicate[] predicates = new Predicate[list.size()]; + return criteriaBuilder.and(list.toArray(predicates)); + }; + List shanDongFirePointList = shanDongFirePointDao.findAll(specification); + if (shanDongFirePointList.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有火点数据", locale); + } + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, shanDongFirePointList, locale); } /** diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 7b9ef9a..28c6730 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -10,7 +10,6 @@ import com.xkrs.model.vo.AppTaskBodyVo; import com.xkrs.model.vo.GaoDeIgGeocodeVo; import com.xkrs.service.FirePointService; import com.xkrs.utils.*; -import org.apache.http.util.TextUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.annotation.CacheConfig; @@ -142,7 +141,7 @@ public class FirePointServiceImpl implements FirePointService { FirePointEntity savedFirePointEntity = firePointDao.save(firePointEntity); //如果开关关闭了,山东的火点发送短信微信 if ((!switchOpened) && firePointEntity.getCountyCode().startsWith("37")) { - sendBroadcast(firePointEntity.getStreetCode(), firePointEntity.getFirePointAddress()); + sendBroadcast(firePointEntity); } return savedFirePointEntity; } @@ -301,7 +300,7 @@ public class FirePointServiceImpl implements FirePointService { //如果开关关闭了,山东的火点发送短信微信 if (firePointEntity.getCountyCode().startsWith("37")) { - sendBroadcast(firePointEntity.getStreetCode(), firePointEntity.getFirePointAddress()); + sendBroadcast(firePointEntity); } } shanDongFirePointDao.updateVerifyStateByFireCode(fireCode, verifyState); @@ -309,20 +308,19 @@ public class FirePointServiceImpl implements FirePointService { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale); } - private void sendBroadcast(String firePointStreetCode, String firePointAddress) { + private void sendBroadcast(FirePointEntity firePointEntity) { //发送微信消息 - sendWeiXinMessage(firePointStreetCode, firePointAddress); + sendWeiXinMessage(firePointEntity); //发送短信消息 - sendSMSMessage(firePointStreetCode, firePointAddress); + sendSMSMessage(firePointEntity); } /** * 发送微信消息 * - * @param firePointStreetCode - * @param firePointAddress + * @param firePointEntity */ - private void sendWeiXinMessage(String firePointStreetCode, String firePointAddress) { + private void sendWeiXinMessage(FirePointEntity firePointEntity) { List countyCodeWeiXinList = countyCodeWeiXinDao.findAll(); if (countyCodeWeiXinList.isEmpty()) { return; @@ -331,12 +329,12 @@ public class FirePointServiceImpl implements FirePointService { for (CountyCodeWeiXinEntity countyCodeWeiXin : countyCodeWeiXinList) { String countyCode = countyCodeWeiXin.getCountyCode(); String startCountyCode = getStartCountyCode(countyCode); - if ((!TextUtils.isEmpty(startCountyCode)) && firePointStreetCode.startsWith(startCountyCode)) { + if (firePointEntity.getStreetCode().startsWith(startCountyCode)) { weixinIdList.add(countyCodeWeiXin.getWeixinId()); } } if (weixinIdList.size() > 0) { - String content = "【星科瑞升】您注册的区域卫星监测到疑似火点," + firePointAddress + ",\n请登录系统查看"; + String content = "【星科瑞升】您注册的区域卫星监测到疑似火点," + firePointEntity.getFirePointAddress() + ",\n请登录系统查看"; for (String weixinId : weixinIdList) { try { WDWxSendMsgUtil.sendMsg(weixinId, content, 0); @@ -350,26 +348,36 @@ public class FirePointServiceImpl implements FirePointService { /** * 发送短信消息 * - * @param firePointStreetCode - * @param firePointAddress + * @param firePointEntity */ - private void sendSMSMessage(String firePointStreetCode, String firePointAddress) { + private void sendSMSMessage(FirePointEntity firePointEntity) { List sysUserList = sysUserDao.findAll(); if (sysUserList.isEmpty()) { return; } List telephoneList = new ArrayList<>(); for (SysUserEntity sysUser : sysUserList) { - String countyCode = sysUser.getCountyCode(); - String startCountyCode = getStartCountyCode(countyCode); - if ((!TextUtils.isEmpty(startCountyCode)) && firePointStreetCode.startsWith(startCountyCode)) { - telephoneList.add("86" + sysUser.getUserName()); + try { + String countyCode = sysUser.getCountyCode(); + String startCountyCode = getStartCountyCode(countyCode); + if (firePointEntity.getStreetCode().startsWith(startCountyCode)) { + if (sysUser.getReceiveSms() != 1) { + continue; + } + LocalDateTime sysUserOverDateTime = DateTimeUtil.stringToDateTimeFormatter(sysUser.getOverTime(), DateTimeUtil.COMMON_FORMATTER_DATETIME); + if (sysUserOverDateTime.isBefore(DateTimeUtil.getNowTime())) { + continue; + } + telephoneList.add("86" + sysUser.getUserName()); + } + } catch (Exception e) { + e.printStackTrace(); + continue; } } if (telephoneList.size() > 0) { -// String[] telephoneArray = telephoneList.toArray(new String[]{}); - String[] telephoneArray = new String[]{"8615764226530"}; - SendSms.sendSmsToUser(telephoneArray, "1425995", new String[]{firePointAddress}); + String[] telephoneArray = telephoneList.toArray(new String[]{}); + SendSms.sendSmsToUser(telephoneArray, "1425995", new String[]{firePointEntity.getFirePointAddress()}); } } diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index 1007caf..10b4b6c 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -167,6 +167,8 @@ public class SysUserServiceImpl implements SysUserService { sysUserEntity.setLoginNum(0); sysUserEntity.setCountyCode(countyCode); sysUserEntity.setCountyName(countyName); + sysUserEntity.setVipLevel(0); + sysUserEntity.setReceiveSms(0); sysUserDao.save(sysUserEntity); RelUserRoleEntity relUserRoleEntity = new RelUserRoleEntity(); diff --git a/src/main/java/com/xkrs/utils/DateTimeUtil.java b/src/main/java/com/xkrs/utils/DateTimeUtil.java index 268d083..6f14509 100644 --- a/src/main/java/com/xkrs/utils/DateTimeUtil.java +++ b/src/main/java/com/xkrs/utils/DateTimeUtil.java @@ -15,11 +15,11 @@ import java.util.regex.Pattern; */ public class DateTimeUtil { - private final static String COMMON_PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss"; - private final static String COMMON_PATTERN_DATE = "yyyy-MM-dd"; - private final static DateTimeFormatter COMMON_FORMATTER_DATETIME = DateTimeFormatter.ofPattern(COMMON_PATTERN_DATETIME); - private final static DateTimeFormatter COMMON_FORMATTER_DATE = DateTimeFormatter.ofPattern(COMMON_PATTERN_DATE); - private final static ZoneOffset DEFAULT_ZONE_OFFSET = ZoneOffset.of("+8"); + public final static String COMMON_PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss"; + public final static String COMMON_PATTERN_DATE = "yyyy-MM-dd"; + public final static DateTimeFormatter COMMON_FORMATTER_DATETIME = DateTimeFormatter.ofPattern(COMMON_PATTERN_DATETIME); + public final static DateTimeFormatter COMMON_FORMATTER_DATE = DateTimeFormatter.ofPattern(COMMON_PATTERN_DATE); + public final static ZoneOffset DEFAULT_ZONE_OFFSET = ZoneOffset.of("+8"); /** * 字符串转LocalDate