fire_point/src/main/java/com/xkrs/helper/FirePointPushManager.java

136 lines
6.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.xkrs.helper;
import com.xkrs.dao.CountyCodeWeiXinDao;
import com.xkrs.dao.SysUserDao;
import com.xkrs.model.entity.CountyCodeWeiXinEntity;
import com.xkrs.model.entity.FirePointOrdinaryEntity;
import com.xkrs.model.entity.FirePointPreciseEntity;
import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.model.helper.PushHelper;
import com.xkrs.model.vo.AllFirePointVo;
import com.xkrs.utilsnew.FirePointCodeUtils;
import com.xkrs.utilsnew.FirePointConvertUtils;
import com.xkrs.utilsnew.SMSUtils;
import com.xkrs.utilsnew.WeiXinMessageUtils;
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 PushHelper pushHelper;
public void pushNotification(FirePointOrdinaryEntity firePointOrdinaryEntity) {
pushNotification(FirePointConvertUtils.convert(firePointOrdinaryEntity), false);
}
public void pushNotification(FirePointPreciseEntity firePointPreciseEntity) {
pushNotification(FirePointConvertUtils.convert(firePointPreciseEntity), true);
}
private void pushNotification(AllFirePointVo firePoint, boolean precise) {
// //发送微信群聊消息
// sendWeChatGroupMessage(firePoint);
//
// if (precise) {
// //过滤短信通知收件人
// 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();
//// }
// if (smsReceiverList.size() > 0) {
// String[] telephoneArray = new String[smsReceiverList.size()];
// for (int i = 0; i < smsReceiverList.size(); i++) {
// telephoneArray[i] = "86" + smsReceiverList.get(i).getUserName();
// }
// int resValue = SMSUtils.sendSmsToUser(telephoneArray, "1425995", new String[]{firePoint.getFirePointAddress()});
// String sendResult;
// if (resValue == 0) {
// //联系人列表发送短信成功,在数据库中的已发短信数量字段加一
// for (SysUserEntity smsReceiver : smsReceiverList) {
// smsReceiver.setReceiveSmsCount(smsReceiver.getReceiveSmsCount() + 1);
// }
// sysUserDao.saveAll(smsReceiverList);
// sendResult = "短信通知发送成功!";
// } else {
// sendResult = "短信通知发送失败!";
// }
// //记录短信通知日志
// StringBuilder stringBuilder = new StringBuilder("发送人:青岛星科瑞升信息科技有限公司\n");
// for (String telephone : telephoneArray) {
// stringBuilder.append("接收人:").append(telephone).append("\n");
// }
// stringBuilder.append("模板参数:").append(firePoint.getFirePointAddress()).append("\n");
// stringBuilder.append("超级详细的参数:").append(firePoint.toString()).append("\n");
// stringBuilder.append(sendResult);
// log.info(stringBuilder.toString());
// }
// }
}
/**
* 发送微信消息
*/
private void sendWeChatGroupMessage(AllFirePointVo firePoint) {
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 (firePoint.getTownCode().startsWith(formatCutCode)) {
weixinIdList.add(countyCodeWeiXin.getWeixinId());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (weixinIdList.size() > 0) {
StringBuilder stringBuilder = new StringBuilder("发送微信消息通知:\n");
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();
String messageContent = "星巡-秸秆焚烧卫星监测系统\n" + firePoint.getSatelliteType() + "发现1个火点。\n卫星时间" + satelliteTime + "\nlongitude" + formatLongitude + "\nlatitude" + formatLatitude + "\ncountyName" + countyName + "\nstreetName" + streetName + "\nlandType" + landType;
for (String weixinId : weixinIdList) {
stringBuilder.append(weixinId).append("\n");
try {
WeiXinMessageUtils.sendMsg(weixinId, messageContent, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
stringBuilder.append("火情信息:").append(messageContent);
log.info(stringBuilder.toString());
}
}
}