diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java index abe695b..789e160 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java @@ -15,6 +15,9 @@ public class MessageConstants { public final static String APP_NAME = "hzims-message"; /**app消息推送**/ + public final static String WX_PUSH = "wxPush"; + + /**app消息推送**/ public final static String APP_PUSH = "appPush"; /**短信推送**/ public final static String SMS_PUSH = "smsPush"; 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 new file mode 100644 index 0000000..0c40b50 --- /dev/null +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/WxMessageDTO.java @@ -0,0 +1,67 @@ +package com.hnac.hzims.message.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.mp.support.SqlCondition; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Map; + +/** + * @author ysj + */ +@Data +@ApiModel("事务消息") +@EqualsAndHashCode +public class WxMessageDTO implements Serializable { + + @ApiModelProperty(value = "微信消息模板ID",required = true) + @NotNull(message = "微信消息模板ID不能为空") + private String templateId; + + @ApiModelProperty(value = "微信消息详情H5跳转Url",required = true) + @NotNull(message = "微信消息详情H5跳转Url") + private String skipUrl; + + @ApiModelProperty(value = "机构ID",required = true) + @NotNull(message = "机构ID不能为空") + private Long deptId; + + @ApiModelProperty(value = "业务关键字",required = true) + @NotNull(message = "业务关键字不能为空") + private String businessKey; + + @ApiModelProperty(value = "业务分类。系统通知:system,事务消息:business,日常提醒:dailyRemind,巡检消息:inspect",required = true) + @NotNull(message = "业务分类不能为空") + private String businessClassify; + + @ApiModelProperty("业务任务ID") + @QueryField(condition = SqlCondition.EQUAL) + private Long taskId; + + @NotNull + @ApiModelProperty(value = "推送消息键值对") + private Map map; + + @NotNull + @ApiModelProperty(value = "内容") + private String content; + + @NotNull + @ApiModelProperty(value = "主题") + private String subject; + + @NotNull + @ApiModelProperty(value = "推送用户") + private String userIds; + + @ApiModelProperty(value = "创建用户") + private Long createUser; + + @ApiModelProperty(value = "租户ID") + private String tenantId; +} diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java index 887e97c..63e9d96 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java @@ -22,12 +22,12 @@ import javax.annotation.Resource; ) public interface IMessageClient { String API_PREFIX = "/feign/message"; - String SEND_SMS_MESSAGE = API_PREFIX + "/send-sms-message"; String SEND_MESSAGE = API_PREFIX + "/sendMessage"; - String GET_TEMPLATE_BY_ID = API_PREFIX + "/getMsgTemplateById"; + String SEND_WX_MESSAGE = API_PREFIX + "/sendWxMessage"; + String SEND_SMS_MESSAGE = API_PREFIX + "/send-sms-message"; String PLAN_SEND_MESSAGE = API_PREFIX + "/planSendMessage"; + String GET_TEMPLATE_BY_ID = API_PREFIX + "/getMsgTemplateById"; String SEND_APP_AND_WS_MSG = API_PREFIX + "/sendAppAndWsMsgByUsers"; - /** * 推送消息(短信) * @@ -43,6 +43,9 @@ public interface IMessageClient { @GetMapping(GET_TEMPLATE_BY_ID) R getMsgTemplateById(@RequestParam Long id); + @PostMapping(value = SEND_WX_MESSAGE,consumes = "application/json; charset=UTF-8") + R sendWxMessage(@RequestBody WxMessageDTO request); + /** * @return * @Author hx diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java index 37f26e4..2d1e0c5 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java @@ -28,6 +28,11 @@ public class MessageClientFallback implements IMessageClient { } @Override + public R sendWxMessage(WxMessageDTO request) { + return R.fail("调用失败!"); + } + + @Override public R planSendMessage(PlanMsgRecordDto request) { return R.fail("调用失败!"); } 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 0660fdd..06da0d5 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 @@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.time.LocalDateTime; import java.time.ZoneId; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -77,6 +78,28 @@ public class MessageClient extends BladeController implements IMessageClient{ return R.data(messageTemplateService.getById(id)); } + @Override + public R sendWxMessage(WxMessageDTO request) { + // 微信消息推送记录保存 + List messages = Func.toLongList(request.getUserIds()).stream().map(userId -> { + MessagePushRecordEntity entity = BeanUtil.copy(request, MessagePushRecordEntity.class); + entity.setMessageId(IdWorker.getId()); + entity.setPusher(userId.toString()); + entity.setPusherName(Optional.ofNullable(UserCache.getUser(userId)).map(User::getName).orElse(null)); + entity.setPushType(MessageConstants.IMMEDIATELY); + entity.setAccount(userId.toString()); + entity.setPlanTime(LocalDateTime.now()); + entity.setType(MessageConstants.WX_PUSH); + entity.setCreateDept(entity.getDeptId()); + return entity; + }).collect(Collectors.toList()); + boolean isSave = recordService.saveBatch(messages); + if(isSave){ + return R.data(recordService.sendWxMessageByUser(request,messages)); + } + return R.data(false); + } + @PostMapping(PLAN_SEND_MESSAGE) @Override public R planSendMessage(@RequestBody @Valid PlanMsgRecordDto request) { @@ -140,7 +163,7 @@ public class MessageClient extends BladeController implements IMessageClient{ // 推送消息 - app Boolean appFlag = recordService.sendAppMsgByUsers(request, appRecords); // 推送消息 - web - Boolean wsFlag = recordService.sendWsMsgByUsers(CollectionUtils.subtract(pushRecords, appRecords).stream().collect(Collectors.toList())); + Boolean wsFlag = recordService.sendWsMsgByUsers(new ArrayList<>(CollectionUtils.subtract(pushRecords, appRecords))); return R.data(appFlag && wsFlag); } else { diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java index 94a1d31..4f1e6e2 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java @@ -2,6 +2,7 @@ package com.hnac.hzims.message.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.message.dto.BusinessMessageDTO; +import com.hnac.hzims.message.dto.WxMessageDTO; import com.hnac.hzims.message.entity.MessagePushRecordEntity; import com.hnac.hzims.message.vo.UnreadMessageVO; import com.hnac.hzims.message.vo.msgpushrecord.*; @@ -102,6 +103,8 @@ public interface IMessagePushRecordService extends BaseService getPersonalAppUnreadMessage(); + Boolean sendWxMessageByUser(WxMessageDTO message,List records); + Boolean sendAppMsgByUsers(BusinessMessageDTO request,List records); Boolean sendWsMsgByUsers(List request); 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 cbc3f0c..9adb376 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 @@ -15,6 +15,7 @@ import com.hnac.hzims.common.utils.CacheUtil; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.config.MessageFactory; import com.hnac.hzims.message.dto.BusinessMessageDTO; +import com.hnac.hzims.message.dto.WxMessageDTO; import com.hnac.hzims.message.entity.MessagePushRecordEntity; import com.hnac.hzims.message.enums.PushStatEnum; import com.hnac.hzims.message.mapper.MessagePushRecordMapper; @@ -374,6 +375,24 @@ 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) { + 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; + } + + @Override public Boolean sendAppMsgByUsers(BusinessMessageDTO request, List records) { PushMessageServiceImpl service = SpringUtil.getBean(PushMessageServiceImpl.class); try { 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 new file mode 100644 index 0000000..ddd2be3 --- /dev/null +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java @@ -0,0 +1,124 @@ +package com.hnac.hzims.message.service.impl; + +import com.alibaba.fastjson.JSON; +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.entity.MessagePushRecordEntity; +import com.hnac.hzims.message.log.aspect.SaveLog; +import com.hnac.hzims.message.service.IMessageService; +import com.hnac.hzinfo.core.push.enums.PlatformType; +import com.hnac.hzinfo.core.push.enums.PushAudienceType; +import com.hnac.hzinfo.core.push.model.PushAudience; +import com.hnac.hzinfo.core.push.model.PushInfo; +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.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.api.R; +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.springframework.stereotype.Service; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.FutureTask; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @author hx + */ +@Service("pushMessageService") +@Slf4j +@AllArgsConstructor +public class WxMessageServiceImpl implements IMessageService { + + private final IPushClient pushClient; + private final BladeLogger logger; + private final ExecutorService appMessagePushExecutor; + + @Override + @SaveLog(type = MessageConstants.APP_NAME) + public R send(T pushObject) { + + return R.success("推送成功"); + } + + @Override + public boolean send(MessagePushRecordEntity request) { + return false; + } + + /** + * 发送APP消息(多人) + * @param subject 消息主题 + * @param content 消息内容 + * @param userIds 用户ID列表 + * @param tenantId 租户ID + * @return + */ + public boolean sendByUsers(String subject, String content, List userIds,String tenantId) throws Exception { + 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(); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java index e43b935..c636df2 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java @@ -742,10 +742,7 @@ public class StAlamRecordServiceImpl extends BaseServiceImpl map = stations.stream().collect(Collectors.toMap(StationEntity::getCode,StationEntity::getName)); - return list.stream().filter(fault -> map.containsKey(fault.getStation())).map(o->{ - o.setStationName(map.get(o.getStation())); - return o; - }).collect(Collectors.toList()); + return list.stream().filter(fault -> map.containsKey(fault.getStation())).peek(o-> o.setStationName(map.get(o.getStation()))).collect(Collectors.toList()); }