diff --git a/src/main/java/com/xkrs/straw/model/helper/SMSHelper.java b/src/main/java/com/xkrs/straw/model/helper/SMSHelper.java index 3b4a794..dac76e0 100644 --- a/src/main/java/com/xkrs/straw/model/helper/SMSHelper.java +++ b/src/main/java/com/xkrs/straw/model/helper/SMSHelper.java @@ -1,7 +1,7 @@ package com.xkrs.straw.model.helper; -import com.xkrs.model.entity.FirePointEntity; import com.xkrs.straw.model.entity.SysUserEntity; +import com.xkrs.straw.model.vo.AllFirePointVo; import com.xkrs.utils.SMSUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,7 +17,7 @@ public class SMSHelper { public SMSHelper() { } - public void dispatchSMSMessage(List smsReceiverList, String[] templateParamArray, FirePointEntity[] detailParamArray) { + public void dispatchSMSMessage(List smsReceiverList, String[] templateParamArray, AllFirePointVo[] detailParamArray) { if (smsReceiverList != null && smsReceiverList.size() > 0) { String[] telephoneArray = new String[smsReceiverList.size()]; for (int i = 0; i < smsReceiverList.size(); i++) { @@ -30,7 +30,7 @@ public class SMSHelper { /** * 星科瑞升向用户发送短信 */ - private void xingkeSMSMessage(String[] telephoneArray, String[] templateParamArray, FirePointEntity[] detailParamArray) { + private void xingkeSMSMessage(String[] telephoneArray, String[] templateParamArray, AllFirePointVo[] detailParamArray) { int resValue = SMSUtils.sendSmsToUser(telephoneArray, "1425995", templateParamArray); String sendResult = resValue == 0 ? "短信通知发送成功!" : "短信通知发送失败!"; //记录短信通知日志 @@ -41,7 +41,7 @@ public class SMSHelper { for (String templateParam : templateParamArray) { stringBuilder.append("模板参数:").append(templateParam).append("\n"); } - for (FirePointEntity detailParam : detailParamArray) { + for (AllFirePointVo detailParam : detailParamArray) { stringBuilder.append("超级详细的参数:").append(detailParam.toString()).append("\n"); } stringBuilder.append(sendResult); diff --git a/src/main/java/com/xkrs/straw/service/impl/DispatchFirePointServiceImpl.java b/src/main/java/com/xkrs/straw/service/impl/DispatchFirePointServiceImpl.java index cdfd39d..f812151 100644 --- a/src/main/java/com/xkrs/straw/service/impl/DispatchFirePointServiceImpl.java +++ b/src/main/java/com/xkrs/straw/service/impl/DispatchFirePointServiceImpl.java @@ -12,8 +12,9 @@ import com.xkrs.straw.model.entity.FirePointOrdinaryEntity; import com.xkrs.straw.model.entity.FirePointPreciseEntity; import com.xkrs.straw.model.qo.AllFirePointQo; import com.xkrs.straw.service.DispatchFirePointService; -import com.xkrs.straw.utils.DispatchFirePointUtils; +import com.xkrs.straw.utils.FirePointDispatchUtils; import com.xkrs.straw.utils.FirePointFilterUtils; +import com.xkrs.straw.utils.FirePointPushManager; import com.xkrs.straw.utils.FirePointQueryManager; import com.xkrs.utils.DateTimeUtils; import org.slf4j.Logger; @@ -51,6 +52,9 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { @Resource private FirePointQueryManager firePointQueryManager; + @Resource + private FirePointPushManager firePointPushManager; + /** * 普通渠道推送火点到秸秆系统 */ @@ -108,9 +112,10 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { } else { messageOrdinary = "普通火点添加成功"; firePointOrdinaryDao.save(firePointOrdinaryEntity); + firePointPushManager.pushNotification(firePointOrdinaryEntity); } List firePointChannelConfigEntityList = channelConfigDao.findAll(); - boolean inPreciseTimeRange = DispatchFirePointUtils.checkIfInPreciseTimeRange(fireCode, satelliteLocalDateTime, firePointChannelConfigEntityList); + boolean inPreciseTimeRange = FirePointDispatchUtils.ifInFireSeason(fireCode, satelliteLocalDateTime, firePointChannelConfigEntityList); //如果现在不属于精准渠道的时间范围,那么普通渠道来的火点就入库精准火点库 if (!inPreciseTimeRange) { FirePointPreciseEntity firePointPreciseEntity = new FirePointPreciseEntity(); @@ -134,6 +139,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { } else { messagePrecise = "审核火点添加成功"; firePointPreciseDao.save(firePointPreciseEntity); + firePointPushManager.pushNotification(firePointPreciseEntity); } } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, messageOrdinary + messagePrecise, locale); @@ -174,7 +180,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { String addTime = DateTimeUtils.localDateTimeToString(LocalDateTime.now());//添加时间 List firePointChannelConfigEntityList = channelConfigDao.findAll(); - boolean inPreciseTimeRange = DispatchFirePointUtils.checkIfInPreciseTimeRange(fireCode, satelliteLocalDateTime, firePointChannelConfigEntityList); + boolean inPreciseTimeRange = FirePointDispatchUtils.ifInFireSeason(fireCode, satelliteLocalDateTime, firePointChannelConfigEntityList); //如果现在属于精准渠道的时间范围,那么精准渠道来的火点就入库精准火点库 if (inPreciseTimeRange) { FirePointPreciseEntity firePointPreciseEntity = new FirePointPreciseEntity(); @@ -198,6 +204,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { } else { messagePrecise = "审核火点添加成功"; firePointPreciseDao.save(firePointPreciseEntity); + firePointPushManager.pushNotification(firePointPreciseEntity); } } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, messagePrecise, locale); diff --git a/src/main/java/com/xkrs/straw/utils/DispatchFirePointUtils.java b/src/main/java/com/xkrs/straw/utils/FirePointDispatchUtils.java similarity index 94% rename from src/main/java/com/xkrs/straw/utils/DispatchFirePointUtils.java rename to src/main/java/com/xkrs/straw/utils/FirePointDispatchUtils.java index 3549d93..a697e53 100644 --- a/src/main/java/com/xkrs/straw/utils/DispatchFirePointUtils.java +++ b/src/main/java/com/xkrs/straw/utils/FirePointDispatchUtils.java @@ -12,17 +12,19 @@ import org.slf4j.LoggerFactory; import java.time.LocalDateTime; import java.util.List; -public class DispatchFirePointUtils { +public class FirePointDispatchUtils { public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class); - private DispatchFirePointUtils() { + private FirePointDispatchUtils() { } /** - * 检查火点卫星时间是否在精准渠道配置时间范围内 + * 判断此时是否是防火季节 + * 如果是,那么审核火点表中数据来源是审核火点 + * 如果不是,那么审核火点表中数据来源是普通火点 */ - public static boolean checkIfInPreciseTimeRange(String fireCode, LocalDateTime satelliteLocalDateTime, List firePointChannelConfigEntityList) { + 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; diff --git a/src/main/java/com/xkrs/straw/utils/FirePointPushManager.java b/src/main/java/com/xkrs/straw/utils/FirePointPushManager.java new file mode 100644 index 0000000..a36dd04 --- /dev/null +++ b/src/main/java/com/xkrs/straw/utils/FirePointPushManager.java @@ -0,0 +1,115 @@ +package com.xkrs.straw.utils; + +import com.xkrs.dao.CountyCodeWeiXinDao; +import com.xkrs.model.entity.CountyCodeWeiXinEntity; +import com.xkrs.straw.dao.SysUserDao; +import com.xkrs.straw.model.entity.FirePointOrdinaryEntity; +import com.xkrs.straw.model.entity.FirePointPreciseEntity; +import com.xkrs.straw.model.entity.SysUserEntity; +import com.xkrs.straw.model.helper.PushHelper; +import com.xkrs.straw.model.helper.SMSHelper; +import com.xkrs.straw.model.vo.AllFirePointVo; +import com.xkrs.utils.FirePointCodeUtils; +import com.xkrs.utils.WDWxSendMsgUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; + +@Component +public class FirePointPushManager { + + public static Logger log = LoggerFactory.getLogger(FirePointPushManager.class); + @Resource + private SysUserDao sysUserDao; + @Resource + private CountyCodeWeiXinDao countyCodeWeiXinDao; + + @Resource + private SMSHelper smsHelper; + + @Resource + private PushHelper pushHelper; + + public void pushNotification(FirePointOrdinaryEntity firePointOrdinaryEntity) { + pushNotification(FirePointConvertUtils.convert(firePointOrdinaryEntity)); + } + + public void pushNotification(FirePointPreciseEntity firePointPreciseEntity) { + pushNotification(FirePointConvertUtils.convert(firePointPreciseEntity)); + } + + private void pushNotification(AllFirePointVo firePoint) { + //发送微信群聊消息 + sendWeChatGroupMessage(firePoint); + + if ("耕地".equals(firePoint.getLandType())) { + //过滤短信通知收件人 + List sysUserList = sysUserDao.findAll(); + List smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePoint.getTownCode(), sysUserList); +// //推送 +// try { +// List userAccountList = pushHelper.obtainUserAccountList(smsReceiverList); +// pushHelper.dispatchPushMessage(userAccountList, firePointEntity); +// } catch (Exception e) { +// e.printStackTrace(); +// } + //分发短信通知 + smsHelper.dispatchSMSMessage(smsReceiverList, new String[]{firePoint.getFirePointAddress()}, new AllFirePointVo[]{firePoint}); + } + } + + + /** + * 发送微信消息 + */ + private void sendWeChatGroupMessage(AllFirePointVo 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.getTownCode().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(AllFirePointVo firePoint) { + java.text.DecimalFormat decimalFormat = new DecimalFormat("#.000000"); + String satelliteTime = firePoint.getSatelliteTime(); + String formatLongitude = decimalFormat.format(firePoint.getLongitude()); + String formatLatitude = decimalFormat.format(firePoint.getLatitude()); + String countyName = firePoint.getCountyName(); + String streetName = firePoint.getTownName(); + String landType = firePoint.getLandType(); + return firePoint.getSatelliteType() + "发现1个火点。\n卫星时间:" + satelliteTime + ";\nlongitude:" + formatLongitude + ";\nlatitude:" + formatLatitude + ";\ncountyName:" + countyName + ";\nstreetName:" + streetName + ";\nlandType:" + landType; + } + +}