diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/WxMessageDTO.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/WxMessageDTO.java index 0c40b50..6846b6d 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/WxMessageDTO.java +++ b/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 @ApiModelProperty(value = "推送消息键值对") - private Map map; + private Map map; @NotNull @ApiModelProperty(value = "内容") diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java index 2393be5..38d45d9 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java @@ -29,7 +29,9 @@ public interface IContentDefinitionService extends BaseService queryWrapper = Condition.getQueryWrapper(entity,ContentDefinitionEntity.class); queryWrapper.eq(Func.isNotEmpty(entity.getCreateDept()), ContentDefinitionEntity::getCreateDept, entity.getCreateDept()) .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; } diff --git a/hzims-service/message/pom.xml b/hzims-service/message/pom.xml index 56dd88f..b3856f8 100644 --- a/hzims-service/message/pom.xml +++ b/hzims-service/message/pom.xml @@ -88,6 +88,7 @@ org.springblade blade-system-api + 5.0.2-SNAPSHOT diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java index c718ab3..c7a93ff 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java +++ b/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.setMessageId(IdWorker.getId()); 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.setAccount(userId.toString()); entity.setPlanTime(LocalDateTime.now()); @@ -98,11 +98,11 @@ public class MessageClient extends BladeController implements IMessageClient{ entity.setCreateDept(entity.getDeptId()); return entity; }).collect(Collectors.toList()); - boolean isSave = recordService.saveBatch(messages); + /*boolean isSave = recordService.saveBatch(messages); if(isSave){ return R.data(recordService.sendWxMessageByUser(request,messages)); - } - return R.data(false); + }*/ + return R.data(recordService.sendWxMessageByUser(request,messages)); } @PostMapping(PLAN_SEND_MESSAGE) diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java index bf9b069..6ab12eb 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java @@ -394,19 +394,15 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl records) { - Map 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); - boolean isSend = service.send(param); - if (isSend) { + boolean isSend = service.send(message); + /*if (isSend) { this.update(Wrappers.lambdaUpdate() .set(MessagePushRecordEntity::getPushTime, LocalDateTime.now()) .set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS) .in(MessagePushRecordEntity::getId, records.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList()))); - } + }*/ return isSend; } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java index 337983d..aea5845 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java +++ b/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.dto.AppPushDto; 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.log.aspect.SaveLog; 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 lombok.AllArgsConstructor; 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.logger.BladeLogger; 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.resource.feign.IPushClient; 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 java.io.*; @@ -38,6 +43,7 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.FutureTask; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; /** * @author hx @@ -48,6 +54,7 @@ import java.util.concurrent.atomic.AtomicReference; public class WxMessageServiceImpl implements IMessageService { private final IPushClient pushClient; + private final IWxPushClient wxPushClient; private final BladeLogger logger; private final ExecutorService appMessagePushExecutor; @@ -75,50 +82,13 @@ public class WxMessageServiceImpl implements IMessageService { return false; } - public boolean send(Map param) { - OutputStream out = null; - try{ - URL serverUrl = new URL("https://3d.hnaccloud.com/api/blade-system/wxPush/sendPush"); - HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(); - conn.setRequestMethod("GET"); - conn.setRequestProperty("Content-type", "application/json"); - //必须设置false,否则会自动redirect到重定向后的地址 - 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(); - } + public boolean send(WxMessageDTO message) { + PushTemplate template = new PushTemplate(); + template.setTemplateId(message.getTemplateId()); + template.setSkipUrl(message.getSkipUrl()); + template.setMap(message.getMap()); + template.setUserIds(Arrays.stream(message.getUserIds().split(",")).collect(Collectors.toList())); + R result = wxPushClient.sendPushTemplateByUserId(template); + return result.isSuccess(); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/DeviceDataController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/DeviceDataController.java index a448691..89e98c5 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/DeviceDataController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/controller/DeviceDataController.java @@ -42,4 +42,11 @@ public class DeviceDataController { public R> history(AnalyzeDataCondition analyzeDataCondition) { return service.history(analyzeDataCondition); } + + @ApiOperation("微信消息推送测试") + @PostMapping("/sendWxMessage") + @ApiOperationSupport(order = 1) + public R sendWxMessage() { + return service.sendWxMessage(); + } } \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/DeviceDataService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/DeviceDataService.java index 6726c14..c69fe0a 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/DeviceDataService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/DeviceDataService.java @@ -19,4 +19,6 @@ public interface DeviceDataService { R> real(RealDataSearchPO search); R> history(AnalyzeDataCondition analyzeDataCondition); + + R sendWxMessage(); } \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/DeviceDataServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/DeviceDataServiceImpl.java index cc96c56..91c2a11 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/DeviceDataServiceImpl.java +++ b/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.esotericsoftware.minlog.Log; 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.vo.RealVo; 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.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; +import io.swagger.annotations.ApiModelProperty; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; 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.utils.CollectionUtil; 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.stereotype.Service; +import javax.validation.constraints.NotNull; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -42,6 +49,8 @@ public class DeviceDataServiceImpl implements DeviceDataService { private final AnalyseDataSearchClient analyseDataSearchClient; + private final IMessageClient messageClient; + /** * 实时数据 * @param search @@ -67,4 +76,44 @@ public class DeviceDataServiceImpl implements DeviceDataService { Result> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCode(analyzeDataCondition); 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 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); + } } \ No newline at end of file