Browse Source

修正:微信公众号查询用户逻辑

zhongwei
ty 6 months ago
parent
commit
41bb39fdd3
  1. 1
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java
  2. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java
  3. 3
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java
  4. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java
  5. 10
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java
  6. 3
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/SoeMqttConsumer.java
  7. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java
  8. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java
  9. 68
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java
  10. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java
  11. 2
      hzims-service/hzims-alarm/src/main/resources/db/2.0.0.sql

1
hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java

@ -7,6 +7,7 @@ import java.util.List;
* @author ysj * @author ysj
*/ */
public interface AlarmConstants { public interface AlarmConstants {
public static final String PATTERN_DATETIME_MILLIS = "yyyy-MM-dd HH:mm:ss.SSS";
String APP_NAME = "hzims-alarm"; String APP_NAME = "hzims-alarm";

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java

@ -29,7 +29,7 @@ public class DroolsMqttConsumer implements SubscribeCallBack {
private AlarmSaveService alarmSaveService; private AlarmSaveService alarmSaveService;
@Override @Override
public void onMessage(Map<String, Object> data) { public void onMessage(Map<String, Object> data) {
System.out.println("监听到消息"+data.toString()); log.info("DroolsMqttConsumer监听到消息"+data.toString());
String s = JSONObject.toJSONString(data); String s = JSONObject.toJSONString(data);
//消费代码 //消费代码
List<AlarmEntity> alarmEntities = droolsAlarmService.receiveMessage(s); List<AlarmEntity> alarmEntities = droolsAlarmService.receiveMessage(s);

3
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java

@ -29,9 +29,8 @@ public class FdpMqttConsumer implements SubscribeCallBack {
@Override @Override
public void onMessage(Map<String, Object> data) { public void onMessage(Map<String, Object> data) {
String s = JSONObject.toJSONString(data); String s = JSONObject.toJSONString(data);
log.error("监听Fdp消息 : {}" ,s); log.info("监听Fdp消息 : {}" ,s);
//消费代码 //消费代码
List<AlarmEntity> alarmEntities = fdpAlarmService.receiveMessage(s); List<AlarmEntity> alarmEntities = fdpAlarmService.receiveMessage(s);
if(CollectionUtil.isEmpty(alarmEntities)){ if(CollectionUtil.isEmpty(alarmEntities)){
return; return;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java

@ -29,7 +29,7 @@ public class HZ300MqttConsumer implements SubscribeCallBack {
private AlarmSaveService alarmSaveService; private AlarmSaveService alarmSaveService;
@Override @Override
public void onMessage(Map<String, Object> data) { public void onMessage(Map<String, Object> data) {
log.error("HZ3000队列监听到消息 : {}",data); log.info("HZ3000队列监听到消息 : {}",data);
//消费代码 //消费代码
List<AlarmEntity> alarmEntities = systemAlarmService.receiveMessage(JSONObject.toJSONString(data)); List<AlarmEntity> alarmEntities = systemAlarmService.receiveMessage(JSONObject.toJSONString(data));
if(CollectionUtil.isEmpty(alarmEntities)){ if(CollectionUtil.isEmpty(alarmEntities)){

10
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java

@ -58,23 +58,23 @@ public class MqttConfig {
//fdp //fdp
AnalysisSubscribe analysisSubscribe = new AnalysisSubscribe(); AnalysisSubscribe analysisSubscribe = new AnalysisSubscribe();
MqttAsyncClient fdpClient = analysisSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), fdpMqttConsumer); MqttAsyncClient fdpClient = analysisSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), fdpMqttConsumer);
log.info(fdpClient.toString()); log.info(fdpClient.toString()+fdpClient.getClientId());
//drools //drools
DroolsSoeSubscribe droolsSoeSubscribe = new DroolsSoeSubscribe(); DroolsSoeSubscribe droolsSoeSubscribe = new DroolsSoeSubscribe();
MqttAsyncClient droolsClient = droolsSoeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), droolsMqttConsumer); MqttAsyncClient droolsClient = droolsSoeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), droolsMqttConsumer);
log.info(droolsClient.toString()); log.info(droolsClient.toString()+droolsClient.getClientId());
//Soe //Soe
SoeSubscribe soeSubscribe = new SoeSubscribe(); SoeSubscribe soeSubscribe = new SoeSubscribe();
MqttAsyncClient soeClient = soeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), soeMqttConsumer); MqttAsyncClient soeClient = soeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), soeMqttConsumer);
log.info(soeClient.toString()); log.info(soeClient.toString()+soeClient.getClientId());
//hz3000 //hz3000
HZ3000SoeSubscribe hz3000SoeSubscribe = new HZ3000SoeSubscribe(); HZ3000SoeSubscribe hz3000SoeSubscribe = new HZ3000SoeSubscribe();
MqttAsyncClient hz3000Client = hz3000SoeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), hz300MqttConsumer); MqttAsyncClient hz3000Client = hz3000SoeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), hz300MqttConsumer);
log.info(hz3000Client.toString()); log.info(hz3000Client.toString()+hz3000Client.getClientId());
//视频 //视频
SoeSubscribe subscribe = new SoeSubscribe(); SoeSubscribe subscribe = new SoeSubscribe();
MqttAsyncClient videoClient = subscribe.subscribe(mqttConfig, Collections.singletonList("#"), videoMqttConsumer); MqttAsyncClient videoClient = subscribe.subscribe(mqttConfig, Collections.singletonList("#"), videoMqttConsumer);
log.info(videoClient.toString()); log.info(videoClient.toString()+videoClient.getClientId());
}catch (MqttException e){ }catch (MqttException e){
log.error(e.toString()) ; log.error(e.toString()) ;
} }

3
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/SoeMqttConsumer.java

@ -27,7 +27,7 @@ public class SoeMqttConsumer implements SubscribeCallBack {
private AlarmSaveService alarmSaveService; private AlarmSaveService alarmSaveService;
@Override @Override
public void onMessage(Map<String, Object> data) { public void onMessage(Map<String, Object> data) {
System.out.println("监听到消息"+data.toString()); log.info("SoeMqttConsumer监听到消息"+data.toString());
String s = JSONObject.toJSONString(data); String s = JSONObject.toJSONString(data);
//消费代码 //消费代码
List<AlarmEntity> alarmEntities = soeAlarmService.receiveMessage(s); List<AlarmEntity> alarmEntities = soeAlarmService.receiveMessage(s);
@ -36,7 +36,6 @@ public class SoeMqttConsumer implements SubscribeCallBack {
alarmSaveService.save(alarmEntities); alarmSaveService.save(alarmEntities);
}catch (Exception e){ }catch (Exception e){
log.error("条件告警数据处理报错(SoeAlarm):"+e); log.error("条件告警数据处理报错(SoeAlarm):"+e);
System.out.println("规则引擎告警数据处理报错(SoeAlarm):"+e);
} }
} }
} }

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java

@ -26,7 +26,7 @@ public class VideoMqttConsumer implements SubscribeCallBack {
private AlarmSaveService alarmSaveService; private AlarmSaveService alarmSaveService;
@Override @Override
public void onMessage(Map<String, Object> data) { public void onMessage(Map<String, Object> data) {
System.out.println("监听到消息"+data.toString()); log.info("VideoMqttConsumer队列监听到消息 : {}",data);
String s = JSONObject.toJSONString(data); String s = JSONObject.toJSONString(data);
//消费代码 //消费代码
List<AlarmEntity> alarmEntities = videoAlarmService.receiveMessage(s); List<AlarmEntity> alarmEntities = videoAlarmService.receiveMessage(s);

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java

@ -91,7 +91,7 @@ public class LevelAlarmServiceImpl implements LevelAlarmService {
AlarmEntity entity = new AlarmEntity(); AlarmEntity entity = new AlarmEntity();
entity.setAlarmSource(AlarmConstants.LEVEL_ALARM); entity.setAlarmSource(AlarmConstants.LEVEL_ALARM);
entity.setAlarmId(level.getId()); entity.setAlarmId(level.getId());
entity.setAlarmTime(DateUtil.parse(level.getTs(), "yyyy-MM-dd HH:mm:ss.s")); entity.setAlarmTime(new Date(level.getTs()));
entity.setAlarmType(level.getType()); entity.setAlarmType(level.getType());
entity.setRealId(level.getSignage()); entity.setRealId(level.getSignage());
entity.setAlarmContext(level.getName()); entity.setAlarmContext(level.getName());

68
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java

@ -15,6 +15,7 @@ import com.hnac.hzims.message.fegin.IMessageClient;
import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient; import com.hnac.hzims.operational.station.feign.IStationClient;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.jackson.JsonUtil; import org.springblade.core.tool.jackson.JsonUtil;
@ -27,6 +28,7 @@ import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
import org.springblade.system.user.entity.UserInfo; import org.springblade.system.user.entity.UserInfo;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
@ -40,9 +42,10 @@ import static com.hnac.hzims.operational.main.constant.MainConstants.PROJECT_MAN
*/ */
@Slf4j @Slf4j
@Service @Service
@AllArgsConstructor @RequiredArgsConstructor
public class MessageServiceImpl implements MessageService { public class MessageServiceImpl implements MessageService {
private final ISysClient sysClient; private final ISysClient sysClient;
private final IUserClient userClient; private final IUserClient userClient;
@ -51,6 +54,14 @@ public class MessageServiceImpl implements MessageService {
private final IStationClient stationClient; private final IStationClient stationClient;
@Value("${hzims.msg.template}")
private String msgTemplate;
@Value("${hzims.msg.enabled}")
private Boolean msgEnabled;
@Value("${hzims.wxPush.template}")
private String wxPushTemplate;
@Value("${hzims.wxPush.enabled}")
private Boolean wxPushEnabled;
/** /**
* web/app消息推送 * web/app消息推送
* @param entity : 告警对象 * @param entity : 告警对象
@ -106,14 +117,23 @@ public class MessageServiceImpl implements MessageService {
// } // }
//写死传给固定用户 //写死传给固定用户
// List<String> phoneList=Arrays.asList("18351807087","18163793336","13725599914"); // List<String> phoneList=Arrays.asList("18351807087","18163793336","13725599914");
List<String> phoneList=Arrays.asList("18351807087","18163793336","18285121497"); if (msgEnabled){
for (String phone : phoneList) { users = userClient.relationUserListByRoleAlias(station.getData().getTenantId(), station.getData().getRefDept(), PROJECT_MANAGER).getData();
R<UserInfo> userByPhone = userClient.getUserByPhone("200000", phone); if(CollectionUtil.isEmpty(users)){
if (userByPhone.isSuccess()&&ObjectUtils.isNotEmpty(userByPhone.getData())){ log.error("短信发送失败:获取站点项目经理用户失败 : {}",entity);
users.add(userByPhone.getData().getUser()); return;
}
log.info("短信发送用户列表",users);
}else {
List<String> phoneList = Arrays.asList("18351807087", "18163793336", "18285121497");
for (String phone : phoneList) {
R<UserInfo> userByPhone = userClient.getUserByPhone("200000", phone);
if (userByPhone.isSuccess() && ObjectUtils.isNotEmpty(userByPhone.getData())) {
users.add(userByPhone.getData().getUser());
}
} }
log.info("短信发送用户列表",users);
} }
SmsImmediatelyPushDTO push = SmsImmediatelyPushDTO.builder() SmsImmediatelyPushDTO push = SmsImmediatelyPushDTO.builder()
.deptId(entity.getCreateDept()) .deptId(entity.getCreateDept())
.taskId(entity.getId()) .taskId(entity.getId())
@ -122,7 +142,7 @@ public class MessageServiceImpl implements MessageService {
.content(entity.getAlarmContext()) .content(entity.getAlarmContext())
.subject("告警短信通知") .subject("告警短信通知")
.tenantId(entity.getTenantId()) .tenantId(entity.getTenantId())
.resourceCode(AlarmConstants.SMS_MESSAGE_TEMPLATE_CODE) .resourceCode(msgTemplate)
.pusher(users.stream().map(o->o.getId().toString()).collect(Collectors.joining(","))) .pusher(users.stream().map(o->o.getId().toString()).collect(Collectors.joining(",")))
.createUser(CommonConstant.SYSTEM_USER) .createUser(CommonConstant.SYSTEM_USER)
.params(new HashMap<String,String>(){{ .params(new HashMap<String,String>(){{
@ -146,19 +166,35 @@ public class MessageServiceImpl implements MessageService {
log.error("微信消息发送失败:站点code获取失败 : {}",entity); log.error("微信消息发送失败:站点code获取失败 : {}",entity);
return; return;
} }
List<User> userList=new ArrayList<>();
// 获取站点用户 // 获取站点用户
R<List<User>> result = userClient.userByDeptIdLevel(station.getData().getRefDept(),0); if (wxPushEnabled){
if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { R<List<User>> result = userClient.userByDeptIdLevel(station.getData().getRefDept(),1);
log.error("微信消息发送失败:用户获取失败 : {}",entity); if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) {
return; log.error("微信公众号消息发送失败:用户获取失败 : {}",entity);
return;
}
userList.addAll(result.getData());
log.info("短信发送用户列表",userList);
}else {
//内测只推给对应的3个用户
List<String> phoneList = Arrays.asList("18351807087", "18163793336", "18285121497");
for (String phone : phoneList) {
R<UserInfo> userByPhone = userClient.getUserByPhone("200000", phone);
if (userByPhone.isSuccess() && ObjectUtils.isNotEmpty(userByPhone.getData())) {
userList.add(userByPhone.getData().getUser());
}
}
log.info("短信发送用户列表",userList);
} }
String userIds = userList.stream().map(o -> String.valueOf(o.getId())).distinct().collect(Collectors.joining(","));
WxMessageDTO message = new WxMessageDTO(); WxMessageDTO message = new WxMessageDTO();
// 模板Id // 模板Id
message.setTemplateId("hIgINCsjpG-gyCKh8wzwBeRL9tanTLqRDgv-X8B9vyc"); message.setTemplateId(wxPushTemplate);
// // 微信消息跳转地址 // // 微信消息跳转地址
// message.setSkipUrl("http://baidu.com"); // message.setSkipUrl("http://baidu.com");
// 机构Id // 机构Id
message.setDeptId(result.getData().get(0).getId()); message.setDeptId(station.getData().getRefDept());
// 业务关键字 // 业务关键字
message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey());
// 业务分类关键字 // 业务分类关键字
@ -178,9 +214,9 @@ public class MessageServiceImpl implements MessageService {
// 消息主题 // 消息主题
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription());
// 推送用户 // 推送用户
message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); message.setUserIds(userIds);
// 创建用户 // 创建用户
message.setCreateUser(result.getData().get(0).getId()); message.setCreateUser(userList.get(0).getId());
// 租户Id // 租户Id
message.setTenantId(station.getData().getTenantId()); message.setTenantId(station.getData().getTenantId());
messageClient.sendWxMessage(message); messageClient.sendWxMessage(message);

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java

@ -83,9 +83,9 @@ public class SystemAlarmServiceImpl implements SystemAlarmService {
private AlarmEntity getAlarmEntity(SystemAlarmVo item) { private AlarmEntity getAlarmEntity(SystemAlarmVo item) {
AlarmEntity entity = new AlarmEntity(); AlarmEntity entity = new AlarmEntity();
entity.setAlarmId(item.getId()); entity.setAlarmId(item.getId());
Date date = new Date(); // Date date = new Date(item.getTs());
date.setTime(item.getTs()); // entity.setAlarmTime(DateUtil.parse(item.getTs().toString(),PATTERN_DATETIME_MILLIS));
entity.setAlarmTime(DateUtil.parse(DateUtil.format(date,DateUtil.PATTERN_DATETIME),DateUtil.PATTERN_DATETIME)); entity.setAlarmTime( new Date(item.getTs()));
entity.setAlarmContext(item.getContext()); entity.setAlarmContext(item.getContext());
entity.setAlarmType(item.getType()); entity.setAlarmType(item.getType());
entity.setAlarmStatus(item.getState()); entity.setAlarmStatus(item.getState());

2
hzims-service/hzims-alarm/src/main/resources/db/2.0.0.sql

@ -0,0 +1,2 @@
ALTER TABLE `hzims_alarm`
MODIFY COLUMN `ALARM_TIME` datetime(3) NULL DEFAULT NULL COMMENT '告警时间' AFTER `ALARM_COUNT`;
Loading…
Cancel
Save