优化
This commit is contained in:
parent
6ae858f827
commit
9537954d7d
@ -1,7 +1,7 @@
|
|||||||
package com.xkrs.straw.model.helper;
|
package com.xkrs.straw.model.helper;
|
||||||
|
|
||||||
import com.xkrs.model.entity.FirePointEntity;
|
|
||||||
import com.xkrs.straw.model.entity.SysUserEntity;
|
import com.xkrs.straw.model.entity.SysUserEntity;
|
||||||
|
import com.xkrs.straw.model.vo.AllFirePointVo;
|
||||||
import com.xkrs.utils.SMSUtils;
|
import com.xkrs.utils.SMSUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -17,7 +17,7 @@ public class SMSHelper {
|
|||||||
public SMSHelper() {
|
public SMSHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchSMSMessage(List<SysUserEntity> smsReceiverList, String[] templateParamArray, FirePointEntity[] detailParamArray) {
|
public void dispatchSMSMessage(List<SysUserEntity> smsReceiverList, String[] templateParamArray, AllFirePointVo[] detailParamArray) {
|
||||||
if (smsReceiverList != null && smsReceiverList.size() > 0) {
|
if (smsReceiverList != null && smsReceiverList.size() > 0) {
|
||||||
String[] telephoneArray = new String[smsReceiverList.size()];
|
String[] telephoneArray = new String[smsReceiverList.size()];
|
||||||
for (int i = 0; i < smsReceiverList.size(); i++) {
|
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);
|
int resValue = SMSUtils.sendSmsToUser(telephoneArray, "1425995", templateParamArray);
|
||||||
String sendResult = resValue == 0 ? "短信通知发送成功!" : "短信通知发送失败!";
|
String sendResult = resValue == 0 ? "短信通知发送成功!" : "短信通知发送失败!";
|
||||||
//记录短信通知日志
|
//记录短信通知日志
|
||||||
@ -41,7 +41,7 @@ public class SMSHelper {
|
|||||||
for (String templateParam : templateParamArray) {
|
for (String templateParam : templateParamArray) {
|
||||||
stringBuilder.append("模板参数:").append(templateParam).append("\n");
|
stringBuilder.append("模板参数:").append(templateParam).append("\n");
|
||||||
}
|
}
|
||||||
for (FirePointEntity detailParam : detailParamArray) {
|
for (AllFirePointVo detailParam : detailParamArray) {
|
||||||
stringBuilder.append("超级详细的参数:").append(detailParam.toString()).append("\n");
|
stringBuilder.append("超级详细的参数:").append(detailParam.toString()).append("\n");
|
||||||
}
|
}
|
||||||
stringBuilder.append(sendResult);
|
stringBuilder.append(sendResult);
|
||||||
|
@ -12,8 +12,9 @@ import com.xkrs.straw.model.entity.FirePointOrdinaryEntity;
|
|||||||
import com.xkrs.straw.model.entity.FirePointPreciseEntity;
|
import com.xkrs.straw.model.entity.FirePointPreciseEntity;
|
||||||
import com.xkrs.straw.model.qo.AllFirePointQo;
|
import com.xkrs.straw.model.qo.AllFirePointQo;
|
||||||
import com.xkrs.straw.service.DispatchFirePointService;
|
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.FirePointFilterUtils;
|
||||||
|
import com.xkrs.straw.utils.FirePointPushManager;
|
||||||
import com.xkrs.straw.utils.FirePointQueryManager;
|
import com.xkrs.straw.utils.FirePointQueryManager;
|
||||||
import com.xkrs.utils.DateTimeUtils;
|
import com.xkrs.utils.DateTimeUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -51,6 +52,9 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
|||||||
@Resource
|
@Resource
|
||||||
private FirePointQueryManager firePointQueryManager;
|
private FirePointQueryManager firePointQueryManager;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FirePointPushManager firePointPushManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 普通渠道推送火点到秸秆系统
|
* 普通渠道推送火点到秸秆系统
|
||||||
*/
|
*/
|
||||||
@ -108,9 +112,10 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
|||||||
} else {
|
} else {
|
||||||
messageOrdinary = "普通火点添加成功";
|
messageOrdinary = "普通火点添加成功";
|
||||||
firePointOrdinaryDao.save(firePointOrdinaryEntity);
|
firePointOrdinaryDao.save(firePointOrdinaryEntity);
|
||||||
|
firePointPushManager.pushNotification(firePointOrdinaryEntity);
|
||||||
}
|
}
|
||||||
List<FirePointChannelConfigEntity> firePointChannelConfigEntityList = channelConfigDao.findAll();
|
List<FirePointChannelConfigEntity> firePointChannelConfigEntityList = channelConfigDao.findAll();
|
||||||
boolean inPreciseTimeRange = DispatchFirePointUtils.checkIfInPreciseTimeRange(fireCode, satelliteLocalDateTime, firePointChannelConfigEntityList);
|
boolean inPreciseTimeRange = FirePointDispatchUtils.ifInFireSeason(fireCode, satelliteLocalDateTime, firePointChannelConfigEntityList);
|
||||||
//如果现在不属于精准渠道的时间范围,那么普通渠道来的火点就入库精准火点库
|
//如果现在不属于精准渠道的时间范围,那么普通渠道来的火点就入库精准火点库
|
||||||
if (!inPreciseTimeRange) {
|
if (!inPreciseTimeRange) {
|
||||||
FirePointPreciseEntity firePointPreciseEntity = new FirePointPreciseEntity();
|
FirePointPreciseEntity firePointPreciseEntity = new FirePointPreciseEntity();
|
||||||
@ -134,6 +139,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
|||||||
} else {
|
} else {
|
||||||
messagePrecise = "审核火点添加成功";
|
messagePrecise = "审核火点添加成功";
|
||||||
firePointPreciseDao.save(firePointPreciseEntity);
|
firePointPreciseDao.save(firePointPreciseEntity);
|
||||||
|
firePointPushManager.pushNotification(firePointPreciseEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, messageOrdinary + messagePrecise, locale);
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, messageOrdinary + messagePrecise, locale);
|
||||||
@ -174,7 +180,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
|||||||
String addTime = DateTimeUtils.localDateTimeToString(LocalDateTime.now());//添加时间
|
String addTime = DateTimeUtils.localDateTimeToString(LocalDateTime.now());//添加时间
|
||||||
|
|
||||||
List<FirePointChannelConfigEntity> firePointChannelConfigEntityList = channelConfigDao.findAll();
|
List<FirePointChannelConfigEntity> firePointChannelConfigEntityList = channelConfigDao.findAll();
|
||||||
boolean inPreciseTimeRange = DispatchFirePointUtils.checkIfInPreciseTimeRange(fireCode, satelliteLocalDateTime, firePointChannelConfigEntityList);
|
boolean inPreciseTimeRange = FirePointDispatchUtils.ifInFireSeason(fireCode, satelliteLocalDateTime, firePointChannelConfigEntityList);
|
||||||
//如果现在属于精准渠道的时间范围,那么精准渠道来的火点就入库精准火点库
|
//如果现在属于精准渠道的时间范围,那么精准渠道来的火点就入库精准火点库
|
||||||
if (inPreciseTimeRange) {
|
if (inPreciseTimeRange) {
|
||||||
FirePointPreciseEntity firePointPreciseEntity = new FirePointPreciseEntity();
|
FirePointPreciseEntity firePointPreciseEntity = new FirePointPreciseEntity();
|
||||||
@ -198,6 +204,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
|||||||
} else {
|
} else {
|
||||||
messagePrecise = "审核火点添加成功";
|
messagePrecise = "审核火点添加成功";
|
||||||
firePointPreciseDao.save(firePointPreciseEntity);
|
firePointPreciseDao.save(firePointPreciseEntity);
|
||||||
|
firePointPushManager.pushNotification(firePointPreciseEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, messagePrecise, locale);
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, messagePrecise, locale);
|
||||||
|
@ -12,17 +12,19 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DispatchFirePointUtils {
|
public class FirePointDispatchUtils {
|
||||||
|
|
||||||
public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class);
|
public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class);
|
||||||
|
|
||||||
private DispatchFirePointUtils() {
|
private FirePointDispatchUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查火点卫星时间是否在精准渠道配置时间范围内
|
* 判断此时是否是防火季节
|
||||||
|
* 如果是,那么审核火点表中数据来源是审核火点
|
||||||
|
* 如果不是,那么审核火点表中数据来源是普通火点
|
||||||
*/
|
*/
|
||||||
public static boolean checkIfInPreciseTimeRange(String fireCode, LocalDateTime satelliteLocalDateTime, List<FirePointChannelConfigEntity> firePointChannelConfigEntityList) {
|
public static boolean ifInFireSeason(String fireCode, LocalDateTime satelliteLocalDateTime, List<FirePointChannelConfigEntity> firePointChannelConfigEntityList) {
|
||||||
if (firePointChannelConfigEntityList == null || firePointChannelConfigEntityList.size() == 0) {
|
if (firePointChannelConfigEntityList == null || firePointChannelConfigEntityList.size() == 0) {
|
||||||
int resValue1 = 0;
|
int resValue1 = 0;
|
||||||
String errorMessage = "星科瑞升-秸秆火后台系统报错-检查火点卫星时间是否在精准渠道配置时间范围内-数据库配置集合-为null或size=0-火点编码=" + fireCode;
|
String errorMessage = "星科瑞升-秸秆火后台系统报错-检查火点卫星时间是否在精准渠道配置时间范围内-数据库配置集合-为null或size=0-火点编码=" + fireCode;
|
115
src/main/java/com/xkrs/straw/utils/FirePointPushManager.java
Normal file
115
src/main/java/com/xkrs/straw/utils/FirePointPushManager.java
Normal file
@ -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<SysUserEntity> sysUserList = sysUserDao.findAll();
|
||||||
|
List<SysUserEntity> smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePoint.getTownCode(), sysUserList);
|
||||||
|
// //推送
|
||||||
|
// try {
|
||||||
|
// List<String> 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<CountyCodeWeiXinEntity> countyCodeWeiXinList = countyCodeWeiXinDao.findAll();
|
||||||
|
if (countyCodeWeiXinList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user