发现火点时向用户发送微信消息通知。
This commit is contained in:
parent
45d82fa088
commit
17c34d95f6
37
src/main/java/com/xkrs/model/bean/KeyValueBean.java
Normal file
37
src/main/java/com/xkrs/model/bean/KeyValueBean.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.xkrs.model.bean;
|
||||
|
||||
public class KeyValueBean {
|
||||
|
||||
private String key;
|
||||
|
||||
private String value;
|
||||
|
||||
public KeyValueBean() {
|
||||
}
|
||||
|
||||
public KeyValueBean(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KeyValueBean{" + "key='" + key + '\'' + ", value='" + value + '\'' + '}';
|
||||
}
|
||||
}
|
@ -11,12 +11,12 @@ import com.xkrs.model.vo.GaoDeIgGeocodeVo;
|
||||
import com.xkrs.service.FirePointService;
|
||||
import com.xkrs.service.GlobalConfigService;
|
||||
import com.xkrs.sms.SMSHelper;
|
||||
import com.xkrs.sms.WeChatMessageHelper;
|
||||
import com.xkrs.utils.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cglib.beans.BeanCopier;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -95,6 +95,9 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
@Resource
|
||||
private SMSHelper smsHelper;
|
||||
|
||||
@Resource
|
||||
private WeChatMessageHelper weChatMessageHelper;
|
||||
|
||||
/**
|
||||
* 添加火点信息
|
||||
*/
|
||||
@ -362,10 +365,27 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
}
|
||||
|
||||
private void sendBroadcast(FirePointEntity firePointEntity) {
|
||||
//发送微信消息
|
||||
sendWeiXinMessage(firePointEntity);
|
||||
//发送短信消息
|
||||
sendSMSMessage(firePointEntity);
|
||||
//发送微信群聊消息
|
||||
sendWeChatGroupMessage(firePointEntity);
|
||||
|
||||
//过滤短信通知收件人
|
||||
List<SysUserEntity> sysUserList = sysUserDao.findAll();
|
||||
List<RelRoleAuthorityEntity> adminList = relRoleAuthorityDao.selectByAuthorityId(1);
|
||||
boolean normalSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(9L);
|
||||
boolean vipSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(10L);
|
||||
List<SysUserEntity> smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePointEntity.getStreetCode(), sysUserList, adminList, normalSmsEnable, vipSmsEnable);
|
||||
|
||||
try {
|
||||
weChatMessageHelper.dispatchWeChatMessage(smsReceiverList, firePointEntity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
//对短信通知收件人进行分组
|
||||
List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll();
|
||||
Map<String, List<SysUserEntity>> agentOrgNameGroupMap = FirePointCodeUtils.groupSmsReceiver(smsReceiverList, agentOrgList);
|
||||
//分发短信通知
|
||||
smsHelper.dispatchSMSMessage(agentOrgNameGroupMap, new String[]{firePointEntity.getFirePointAddress()});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -373,7 +393,7 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
*
|
||||
* @param firePointEntity
|
||||
*/
|
||||
private void sendWeiXinMessage(FirePointEntity firePointEntity) {
|
||||
private void sendWeChatGroupMessage(FirePointEntity firePointEntity) {
|
||||
List<CountyCodeWeiXinEntity> countyCodeWeiXinList = countyCodeWeiXinDao.findAll();
|
||||
if (countyCodeWeiXinList.isEmpty()) {
|
||||
return;
|
||||
@ -429,23 +449,6 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信消息
|
||||
*/
|
||||
private void sendSMSMessage(FirePointEntity firePointEntity) {
|
||||
//过滤短信通知收件人
|
||||
List<SysUserEntity> sysUserList = sysUserDao.findAll();
|
||||
List<RelRoleAuthorityEntity> adminList = relRoleAuthorityDao.selectByAuthorityId(1);
|
||||
boolean normalSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(9L);
|
||||
boolean vipSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(10L);
|
||||
List<SysUserEntity> smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePointEntity.getStreetCode(), sysUserList, adminList, normalSmsEnable, vipSmsEnable);
|
||||
//对短信通知收件人进行分组
|
||||
List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll();
|
||||
Map<String, List<SysUserEntity>> agentOrgNameGroupMap = FirePointCodeUtils.groupSmsReceiver(smsReceiverList, agentOrgList);
|
||||
//分发短信通知
|
||||
smsHelper.dispatchSMSMessage(agentOrgNameGroupMap, new String[]{firePointEntity.getFirePointAddress()});
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载VIP用户火点数据
|
||||
*/
|
||||
|
89
src/main/java/com/xkrs/sms/WeChatMessageHelper.java
Normal file
89
src/main/java/com/xkrs/sms/WeChatMessageHelper.java
Normal file
@ -0,0 +1,89 @@
|
||||
package com.xkrs.sms;
|
||||
|
||||
import com.xkrs.dao.GlobalConfigurationDao;
|
||||
import com.xkrs.model.bean.KeyValueBean;
|
||||
import com.xkrs.model.entity.FirePointEntity;
|
||||
import com.xkrs.model.entity.GlobalConfigurationEntity;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.service.GlobalConfigurationService;
|
||||
import com.xkrs.utils.HttpClientUtils;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class WeChatMessageHelper {
|
||||
|
||||
@Resource
|
||||
private GlobalConfigurationDao globalConfigurationDao;
|
||||
|
||||
@Resource
|
||||
private GlobalConfigurationService globalConfigurationService;
|
||||
|
||||
public WeChatMessageHelper() {
|
||||
}
|
||||
|
||||
public void dispatchWeChatMessage(List<SysUserEntity> sysUserList, FirePointEntity firePointEntity) throws Exception {
|
||||
|
||||
if (sysUserList == null || sysUserList.isEmpty() || firePointEntity == null) {
|
||||
return;
|
||||
}
|
||||
//获取微信硬件设备消息通知组名
|
||||
final String belongGroupWeChat = globalConfigurationDao.findAll((root, criteriaQuery, criteriaBuilder) -> {
|
||||
List<Predicate> predicateList = new ArrayList<>();
|
||||
predicateList.add(criteriaBuilder.equal(root.get("belongGroup").as(String.class), "root"));
|
||||
predicateList.add(criteriaBuilder.equal(root.get("key").as(String.class), "weixin_hardware_device_message_key"));
|
||||
Predicate[] predicateArray = new Predicate[predicateList.size()];
|
||||
return criteriaBuilder.and(predicateList.toArray(predicateArray));
|
||||
}, Sort.by(Sort.Direction.ASC, "id")).get(0).getValue();
|
||||
//获取微信硬件设备消息通知参数实体集合
|
||||
List<GlobalConfigurationEntity> weChatConfigurationList = globalConfigurationDao.findAll((root, criteriaQuery, criteriaBuilder) -> {
|
||||
List<Predicate> predicateList = new ArrayList<>();
|
||||
predicateList.add(criteriaBuilder.equal(root.get("belongGroup").as(String.class), belongGroupWeChat));
|
||||
Predicate[] predicateArray = new Predicate[predicateList.size()];
|
||||
return criteriaBuilder.and(predicateList.toArray(predicateArray));
|
||||
}, Sort.by(Sort.Direction.ASC, "id"));
|
||||
//获取微信硬件设备消息通知参数
|
||||
String grantType = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "grant_type")).getValue();
|
||||
String appId = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "appid")).getValue();
|
||||
String secret = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "secret")).getValue();
|
||||
String to_openid_list = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "to_openid_list")).getValue();
|
||||
String template_id = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "template_id")).getValue();
|
||||
String sn = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "sn")).getValue();
|
||||
String model_id = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "model_id")).getValue();
|
||||
String page = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "page")).getValue();
|
||||
String miniprogram_state = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "miniprogram_state")).getValue();
|
||||
String lang = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "lang")).getValue();
|
||||
String template_param_count = Objects.requireNonNull(obtainValueByKey(weChatConfigurationList, "template_param_count")).getValue();
|
||||
//获取微信硬件设备消息通知参数模板参数
|
||||
List<KeyValueBean> templateParamList = new ArrayList<>();
|
||||
DecimalFormat decimalFormat = new DecimalFormat("00");
|
||||
for (int i = 1; i <= Long.parseLong(template_param_count); i++) {
|
||||
String formatParamIndex = decimalFormat.format(i);
|
||||
GlobalConfigurationEntity templateParamKey = obtainValueByKey(weChatConfigurationList, "template_param_key_" + formatParamIndex);
|
||||
GlobalConfigurationEntity templateParamValue = obtainValueByKey(weChatConfigurationList, "template_param_value_" + formatParamIndex);
|
||||
templateParamList.add(new KeyValueBean(Objects.requireNonNull(templateParamKey).getValue(), Objects.requireNonNull(templateParamValue).getValue()));
|
||||
}
|
||||
//获取AccessToken
|
||||
String getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token" + "?grant_type=" + grantType + "&appid=" + appId + "&secret=" + secret;
|
||||
String result = HttpClientUtils.sendHttpsGet(getAccessTokenUrl);
|
||||
System.out.println(result);
|
||||
|
||||
}
|
||||
|
||||
private GlobalConfigurationEntity obtainValueByKey(List<GlobalConfigurationEntity> configurationList, String key) {
|
||||
for (GlobalConfigurationEntity configuration : configurationList) {
|
||||
if (configuration.getKey().equals(key)) {
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user