Browse Source

#微信消息推送&巡检内容bug修改

zhongwei
yang_shj 1 year ago
parent
commit
9be1542c22
  1. 2
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/WxMessageDTO.java
  2. 4
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java
  3. 1
      hzims-service/message/pom.xml
  4. 8
      hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java
  5. 12
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java
  6. 60
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java
  7. 7
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/DeviceDataController.java
  8. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/DeviceDataService.java
  9. 49
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/DeviceDataServiceImpl.java

2
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/WxMessageDTO.java

@ -45,7 +45,7 @@ public class WxMessageDTO implements Serializable {
@NotNull @NotNull
@ApiModelProperty(value = "推送消息键值对") @ApiModelProperty(value = "推送消息键值对")
private Map<String,String> map; private Map<String,Object> map;
@NotNull @NotNull
@ApiModelProperty(value = "内容") @ApiModelProperty(value = "内容")

4
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java

@ -29,7 +29,9 @@ public interface IContentDefinitionService extends BaseService<ContentDefinition
LambdaQueryWrapper<ContentDefinitionEntity> queryWrapper = Condition.getQueryWrapper(entity,ContentDefinitionEntity.class); LambdaQueryWrapper<ContentDefinitionEntity> queryWrapper = Condition.getQueryWrapper(entity,ContentDefinitionEntity.class);
queryWrapper.eq(Func.isNotEmpty(entity.getCreateDept()), ContentDefinitionEntity::getCreateDept, entity.getCreateDept()) queryWrapper.eq(Func.isNotEmpty(entity.getCreateDept()), ContentDefinitionEntity::getCreateDept, entity.getCreateDept())
.eq(Func.isNotEmpty(entity.getCreateUser()), ContentDefinitionEntity::getCreateUser, entity.getCreateUser()) .eq(Func.isNotEmpty(entity.getCreateUser()), ContentDefinitionEntity::getCreateUser, entity.getCreateUser())
.eq(Func.isNotEmpty(entity.getStatus()), ContentDefinitionEntity::getStatus, entity.getStatus()).orderByDesc(ContentDefinitionEntity::getCreateTime); .eq(Func.isNotEmpty(entity.getStatus()), ContentDefinitionEntity::getStatus, entity.getStatus()).orderByDesc(ContentDefinitionEntity::getCreateTime)
.eq(Func.isNotEmpty(entity.getCheckType()),ContentDefinitionEntity::getCheckType,entity.getCheckType())
.like(Func.isNotEmpty(entity.getName()),ContentDefinitionEntity::getName,entity.getName());
return queryWrapper; return queryWrapper;
} }

1
hzims-service/message/pom.xml

@ -88,6 +88,7 @@
<dependency> <dependency>
<groupId>org.springblade</groupId> <groupId>org.springblade</groupId>
<artifactId>blade-system-api</artifactId> <artifactId>blade-system-api</artifactId>
<version>5.0.2-SNAPSHOT</version>
</dependency> </dependency>
<!-- blade-api end --> <!-- blade-api end -->

8
hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java

@ -90,7 +90,7 @@ public class MessageClient extends BladeController implements IMessageClient{
entity.setDeptName(Func.isNotEmpty(entity.getDeptName()) ? entity.getDeptName() : this.getDeptNameById(entity.getDeptId())); entity.setDeptName(Func.isNotEmpty(entity.getDeptName()) ? entity.getDeptName() : this.getDeptNameById(entity.getDeptId()));
entity.setMessageId(IdWorker.getId()); entity.setMessageId(IdWorker.getId());
entity.setPusher(userId.toString()); entity.setPusher(userId.toString());
entity.setPusherName(Optional.ofNullable(UserCache.getUser(userId)).map(User::getName).orElse(null)); //entity.setPusherName(Optional.ofNullable(UserCache.getUser(userId)).map(User::getName).orElse(null));
entity.setPushType(MessageConstants.IMMEDIATELY); entity.setPushType(MessageConstants.IMMEDIATELY);
entity.setAccount(userId.toString()); entity.setAccount(userId.toString());
entity.setPlanTime(LocalDateTime.now()); entity.setPlanTime(LocalDateTime.now());
@ -98,11 +98,11 @@ public class MessageClient extends BladeController implements IMessageClient{
entity.setCreateDept(entity.getDeptId()); entity.setCreateDept(entity.getDeptId());
return entity; return entity;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
boolean isSave = recordService.saveBatch(messages); /*boolean isSave = recordService.saveBatch(messages);
if(isSave){ if(isSave){
return R.data(recordService.sendWxMessageByUser(request,messages)); return R.data(recordService.sendWxMessageByUser(request,messages));
} }*/
return R.data(false); return R.data(recordService.sendWxMessageByUser(request,messages));
} }
@PostMapping(PLAN_SEND_MESSAGE) @PostMapping(PLAN_SEND_MESSAGE)

12
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java

@ -394,19 +394,15 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
@Override @Override
public Boolean sendWxMessageByUser(WxMessageDTO message,List<MessagePushRecordEntity> records) { public Boolean sendWxMessageByUser(WxMessageDTO message,List<MessagePushRecordEntity> records) {
Map<String,Object> param = new HashMap();
param.put("templateId",message.getTemplateId());
param.put("skip",message.getSkipUrl());
param.put("map",message.getMap());
param.put("userIds", Arrays.stream(message.getUserIds().split(",")).collect(Collectors.toList()));
WxMessageServiceImpl service = SpringUtil.getBean(WxMessageServiceImpl.class); WxMessageServiceImpl service = SpringUtil.getBean(WxMessageServiceImpl.class);
boolean isSend = service.send(param); boolean isSend = service.send(message);
if (isSend) { /*if (isSend) {
this.update(Wrappers.<MessagePushRecordEntity>lambdaUpdate() this.update(Wrappers.<MessagePushRecordEntity>lambdaUpdate()
.set(MessagePushRecordEntity::getPushTime, LocalDateTime.now()) .set(MessagePushRecordEntity::getPushTime, LocalDateTime.now())
.set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS) .set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS)
.in(MessagePushRecordEntity::getId, records.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList()))); .in(MessagePushRecordEntity::getId, records.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList())));
} }*/
return isSend; return isSend;
} }

60
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.MessageConstants;
import com.hnac.hzims.message.dto.AppPushDto; import com.hnac.hzims.message.dto.AppPushDto;
import com.hnac.hzims.message.dto.PushDto; import com.hnac.hzims.message.dto.PushDto;
import com.hnac.hzims.message.dto.WxMessageDTO;
import com.hnac.hzims.message.entity.MessagePushRecordEntity; import com.hnac.hzims.message.entity.MessagePushRecordEntity;
import com.hnac.hzims.message.log.aspect.SaveLog; import com.hnac.hzims.message.log.aspect.SaveLog;
import com.hnac.hzims.message.service.IMessageService; import com.hnac.hzims.message.service.IMessageService;
@ -16,6 +17,7 @@ import com.hnac.hzinfo.core.push.model.PushPlatform;
import com.hnac.hzinfo.core.push.model.PushResponse; import com.hnac.hzinfo.core.push.model.PushResponse;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.secure.utils.AuthUtil;
@ -24,6 +26,9 @@ import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.resource.feign.IPushClient; import org.springblade.resource.feign.IPushClient;
import org.springblade.resource.vo.PushInfoVO; import org.springblade.resource.vo.PushInfoVO;
import org.springblade.system.entity.PushTemplate;
import org.springblade.system.feign.IWxPushClient;
import org.springblade.system.vo.WxPushFeignVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.*; import java.io.*;
@ -38,6 +43,7 @@ import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
/** /**
* @author hx * @author hx
@ -48,6 +54,7 @@ import java.util.concurrent.atomic.AtomicReference;
public class WxMessageServiceImpl implements IMessageService { public class WxMessageServiceImpl implements IMessageService {
private final IPushClient pushClient; private final IPushClient pushClient;
private final IWxPushClient wxPushClient;
private final BladeLogger logger; private final BladeLogger logger;
private final ExecutorService appMessagePushExecutor; private final ExecutorService appMessagePushExecutor;
@ -75,50 +82,13 @@ public class WxMessageServiceImpl implements IMessageService {
return false; return false;
} }
public boolean send(Map<String, Object> param) { public boolean send(WxMessageDTO message) {
OutputStream out = null; PushTemplate template = new PushTemplate();
try{ template.setTemplateId(message.getTemplateId());
URL serverUrl = new URL("https://3d.hnaccloud.com/api/blade-system/wxPush/sendPush"); template.setSkipUrl(message.getSkipUrl());
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(); template.setMap(message.getMap());
conn.setRequestMethod("GET"); template.setUserIds(Arrays.stream(message.getUserIds().split(",")).collect(Collectors.toList()));
conn.setRequestProperty("Content-type", "application/json"); R<WxPushFeignVO> result = wxPushClient.sendPushTemplateByUserId(template);
//必须设置false,否则会自动redirect到重定向后的地址 return result.isSuccess();
conn.setInstanceFollowRedirects(false);
conn.connect();
String result = responseFormat(conn);
//获取输出流
out = conn.getOutputStream();
log.error("send_wx_message_param: {}",param.toString());
//输出流里写入POST参数
out.write(param.toString().getBytes());
out.flush();
out.close();
}catch (Exception ex){
log.error("send_wx_message_error: {} ", ex.getMessage());
}
return false;
}
/***
* 获取返回的内容
* @param connection
* @return
*/
private String responseFormat(HttpURLConnection connection) {
StringBuilder stringBuilder = new StringBuilder();
//将返回的输入流转换成字符串
try (
InputStream inputStream = connection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)
) {
String str;
while ((str = bufferedReader.readLine()) != null) {
stringBuilder.append(str);
}
} catch (IOException e) {
return null;
}
return stringBuilder.toString();
} }
} }

7
hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/DeviceDataController.java

@ -42,4 +42,11 @@ public class DeviceDataController {
public R<HzPage<AnalyzeDataList>> history(AnalyzeDataCondition analyzeDataCondition) { public R<HzPage<AnalyzeDataList>> history(AnalyzeDataCondition analyzeDataCondition) {
return service.history(analyzeDataCondition); return service.history(analyzeDataCondition);
} }
@ApiOperation("微信消息推送测试")
@PostMapping("/sendWxMessage")
@ApiOperationSupport(order = 1)
public R sendWxMessage() {
return service.sendWxMessage();
}
} }

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/DeviceDataService.java

@ -19,4 +19,6 @@ public interface DeviceDataService {
R<List<FieldsData>> real(RealDataSearchPO search); R<List<FieldsData>> real(RealDataSearchPO search);
R<HzPage<AnalyzeDataList>> history(AnalyzeDataCondition analyzeDataCondition); R<HzPage<AnalyzeDataList>> history(AnalyzeDataCondition analyzeDataCondition);
R sendWxMessage();
} }

49
hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/DeviceDataServiceImpl.java

@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.esotericsoftware.minlog.Log; import com.esotericsoftware.minlog.Log;
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo;
import com.hnac.hzims.message.dto.WxMessageDTO;
import com.hnac.hzims.message.fegin.IMessageClient;
import com.hnac.hzims.operational.census.service.DeviceDataService; import com.hnac.hzims.operational.census.service.DeviceDataService;
import com.hnac.hzims.operational.census.vo.RealVo; import com.hnac.hzims.operational.census.vo.RealVo;
import com.hnac.hzinfo.datasearch.PointData; import com.hnac.hzinfo.datasearch.PointData;
@ -15,10 +17,13 @@ import com.hnac.hzinfo.datasearch.real.po.RealDataSearchPO;
import com.hnac.hzinfo.sdk.analyse.AnalyseDataSearchClient; import com.hnac.hzinfo.sdk.analyse.AnalyseDataSearchClient;
import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.HzPage;
import com.hnac.hzinfo.sdk.core.response.Result; import com.hnac.hzinfo.sdk.core.response.Result;
import io.swagger.annotations.ApiModelProperty;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.QueryField;
import org.springblade.core.mp.support.SqlCondition;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
@ -26,6 +31,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -42,6 +49,8 @@ public class DeviceDataServiceImpl implements DeviceDataService {
private final AnalyseDataSearchClient analyseDataSearchClient; private final AnalyseDataSearchClient analyseDataSearchClient;
private final IMessageClient messageClient;
/** /**
* 实时数据 * 实时数据
* @param search * @param search
@ -67,4 +76,44 @@ public class DeviceDataServiceImpl implements DeviceDataService {
Result<HzPage<AnalyzeDataList>> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCode(analyzeDataCondition); Result<HzPage<AnalyzeDataList>> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCode(analyzeDataCondition);
return R.data(result.getData()); return R.data(result.getData());
} }
/**
* 微信消息推送测试
* @return
*/
@Override
public R sendWxMessage() {
WxMessageDTO message = new WxMessageDTO();
// 模板Id
message.setTemplateId("hIgINCsjpG-gyCKh8wzwBWjR-hkbjkNLFTXQEsnR_Z8");
// 微信消息跳转地址
message.setSkipUrl("http://baidu.com");
// 机构Id
message.setDeptId(200000010709L);
// 业务关键字
message.setBusinessKey("wx_message_test");
// 业务分类关键字
message.setBusinessClassify("wx_message_test");
// 任务Id
message.setTaskId(1686044105416650753L);
// 微信参数键值对
HashMap<String,Object> map = new HashMap<>();
map.put("thing18","云南维西拉波洛水电站");
map.put("thing5","1号机组");
map.put("thing11","拉波洛电站数据_1号机组PLC.(D182)机组故障_分");
map.put("thing14","故障");
map.put("time2","2023-08-28 16:08:19");
message.setMap(map);
// 消息内容
message.setContent("杨胜军在测试微信消息推送");
// 消息主题
message.setSubject("微信公众号推送消息测试");
// 推送用户
message.setUserIds("1678930425282785281,1696056255481344002,1696073993931157505");
// 创建用户
message.setCreateUser(1394936547620040706L);
// 租户Id
message.setTenantId("200000");
return messageClient.sendWxMessage(message);
}
} }
Loading…
Cancel
Save