From 2c0420d20bac38525eb01f80e558a172b88d12b0 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Wed, 12 Apr 2023 14:35:27 +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/helper/FirePointPushManager.java | 25 ++++++++++--------- .../impl/DispatchFirePointServiceImpl.java | 21 +++++++++------- .../com/xkrs/utilsnew/ErrorInfoLogUtils.java | 24 ++++++++++++++++++ .../com/xkrs/utilsnew/FirePointCodeUtils.java | 9 ++----- 4 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/xkrs/utilsnew/ErrorInfoLogUtils.java diff --git a/src/main/java/com/xkrs/helper/FirePointPushManager.java b/src/main/java/com/xkrs/helper/FirePointPushManager.java index bde0db8..b83e46c 100644 --- a/src/main/java/com/xkrs/helper/FirePointPushManager.java +++ b/src/main/java/com/xkrs/helper/FirePointPushManager.java @@ -6,6 +6,7 @@ import com.xkrs.model.entity.CountyCodeWeiXinEntity; import com.xkrs.model.entity.FirePointOrdinaryEntity; import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.helper.PushHelper; +import com.xkrs.utilsnew.DateTimeUtils; import com.xkrs.utilsnew.FirePointCodeUtils; import com.xkrs.utilsnew.SMSUtils; import com.xkrs.utilsnew.WeiXinMessageUtils; @@ -15,6 +16,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.text.DecimalFormat; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -32,11 +34,7 @@ public class FirePointPushManager { @Resource private PushHelper pushHelper; -// public void pushNotification(FirePointOrdinaryEntity firePointOrdinaryEntity) { -//// pushNotification(FirePointConvertUtils.convert(firePointOrdinaryEntity), false); -// } - - private void pushNotification(FirePointOrdinaryEntity firePoint) { + public void pushNotification(FirePointOrdinaryEntity firePoint) { //发送微信群聊消息 sendWeChatGroupMessage(firePoint); @@ -73,14 +71,17 @@ public class FirePointPushManager { sendResult = "短信通知发送失败!"; } //记录短信通知日志 - StringBuilder stringBuilder = new StringBuilder("发送人:青岛星科瑞升信息科技有限公司\n"); - for (String telephone : telephoneArray) { - stringBuilder.append("接收人:").append(telephone).append("\n"); + String nowTime = DateTimeUtils.localDateTimeToString(LocalDateTime.now()); + StringBuilder builder = new StringBuilder(); + builder.append("开始统计发送短信").append(nowTime).append("\n"); + builder.append("发送人:青岛星科瑞升信息科技有限公司").append("\n"); + builder.append("火点详情:").append(firePoint.toString()).append("\n"); + for (SysUserEntity smsReceiver : smsReceiverList) { + builder.append("接收人姓名:").append(smsReceiver.getReallyName()).append(",手机号:").append(smsReceiver.getUserName()).append(",区划编码:").append(smsReceiver.getCountyCode()).append(",区划名称:").append(smsReceiver.getCountyName()).append("\n"); } - stringBuilder.append("模板参数:").append(firePoint.getFirePointAddress()).append("\n"); - stringBuilder.append("超级详细的参数:").append(firePoint.toString()).append("\n"); - stringBuilder.append(sendResult); - log.info(stringBuilder.toString()); + builder.append(sendResult).append("\n"); + builder.append("结束统计发送短信").append(nowTime).append("\n"); + log.info(builder.toString()); } } diff --git a/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java index 509644c..e34ca4c 100644 --- a/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java @@ -15,12 +15,12 @@ import com.xkrs.model.qo.AllFirePointQo; import com.xkrs.model.qo.UpdateFirePointQo; import com.xkrs.service.DispatchFirePointService; import com.xkrs.utilsnew.DateTimeUtils; +import com.xkrs.utilsnew.ErrorInfoLogUtils; import com.xkrs.utilsnew.FirePointFilterUtils; import org.apache.hc.core5.util.TextUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; @@ -165,16 +165,18 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { @Override public String updateFirePoint(UpdateFirePointQo updateFirePointQo) { List list = updateFirePointQo.getData(); + //先遍历一遍接收到的参数集合,参数不合法就返回错误,参数全部OK就进入下面的循环更新火点状态 for (UpdateFirePointQo.DataDTO item : list) { String fireCode = item.getFireCode(); String status = item.getStatus(); if ((!TextUtils.isEmpty(fireCode)) && (!TextUtils.isEmpty(status)) && (("0".equals(status)) || ("1".equals(status)))) { System.out.println("参数正常:fireCode = " + fireCode + ",status = " + fireCode); } else { - System.out.println("参数异常:fireCode = " + fireCode + ",status = " + fireCode); + ErrorInfoLogUtils.log("updateFirePoint 参数异常:fireCode = " + fireCode + ",status = " + fireCode); return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "更新失败", locale); } } + //参数全部OK,更新火点状态 for (UpdateFirePointQo.DataDTO item : list) { try { String fireCode = item.getFireCode(); @@ -186,14 +188,15 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { Predicate[] predicateArray = new Predicate[predicateList.size()]; return criteriaBuilder.and(predicateList.toArray(predicateArray)); }; - List firePointList = firePointOrdinaryDao.findAll(specification, Sort.by(Sort.Direction.DESC, "satelliteTime")); - if (firePointList.isEmpty()) { - System.out.println("操作异常,审核系统发送的fireCode在秸秆系统已有的火点中找不到:fireCode = " + fireCode + ",status = " + fireCode); + //根据fireCode找到火点 + List firePointList = firePointOrdinaryDao.findAll(specification); + if (firePointList.size() == 1) { + FirePointOrdinaryEntity firePoint = firePointList.get(0); + firePoint.setFireStatus(status);//设置属性 + firePointOrdinaryDao.save(firePoint);//数据库保存 + firePointPushManager.pushNotification(firePoint);//将火点消息通知用户 } else { - for (FirePointOrdinaryEntity firePoint : firePointList) { - firePoint.setFireStatus(status); - firePointOrdinaryDao.save(firePoint); - } + ErrorInfoLogUtils.log("操作异常,审核系统发送的fireCode在秸秆系统中size() != 1:fireCode = " + fireCode + ",status = " + fireCode); } } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/xkrs/utilsnew/ErrorInfoLogUtils.java b/src/main/java/com/xkrs/utilsnew/ErrorInfoLogUtils.java new file mode 100644 index 0000000..704b982 --- /dev/null +++ b/src/main/java/com/xkrs/utilsnew/ErrorInfoLogUtils.java @@ -0,0 +1,24 @@ +package com.xkrs.utilsnew; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ErrorInfoLogUtils { + + private ErrorInfoLogUtils() { + } + + private static Logger logger = LoggerFactory.getLogger(ErrorInfoLogUtils.class); + + public static void log(String message) { + log(message, true); + } + + public static void log(String message, boolean sendSms) { + logger.info(message); + if (sendSms) { + SMSUtils.sendSmsToUser(new String[]{"8615764226530"}, "1425995", new String[]{message}); + } + } + +} diff --git a/src/main/java/com/xkrs/utilsnew/FirePointCodeUtils.java b/src/main/java/com/xkrs/utilsnew/FirePointCodeUtils.java index d567413..647dcd5 100644 --- a/src/main/java/com/xkrs/utilsnew/FirePointCodeUtils.java +++ b/src/main/java/com/xkrs/utilsnew/FirePointCodeUtils.java @@ -42,9 +42,6 @@ public class FirePointCodeUtils { try { String formatCutCode = FirePointCodeUtils.getFormatCutCode(sysUser.getCountyCode()); if (firePointStreetCode.startsWith(formatCutCode)) { - if (TextUtils.isEmpty(sysUser.getPlaceHolder())) {//不是超级用户不发短信 - continue; - } if (sysUser.getActiveFlag() != 0) {//被禁用的用户不发短信 continue; } @@ -55,10 +52,8 @@ public class FirePointCodeUtils { continue; } boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(sysUser.getVipTimeRangeJson()); - if (inVipTimeRange) { - //VIP用户可以接收短信 - } else { - //普通用户可以接收3条短信 + if (!inVipTimeRange) { + //普通用户最多可以接收3条短信 Long receiveSmsCount = sysUser.getReceiveSmsCount(); if (receiveSmsCount != null && receiveSmsCount >= 3) { continue;