Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
haungxing 1 year ago
parent
commit
104fc12eb8
  1. 3
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/MessageConstants.java
  2. 67
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/WxMessageDTO.java
  3. 8
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java
  4. 5
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java
  5. 25
      hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java
  6. 3
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java
  7. 19
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java
  8. 124
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/WxMessageServiceImpl.java
  9. 5
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java

3
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"; public final static String APP_NAME = "hzims-message";
/**app消息推送**/ /**app消息推送**/
public final static String WX_PUSH = "wxPush";
/**app消息推送**/
public final static String APP_PUSH = "appPush"; public final static String APP_PUSH = "appPush";
/**短信推送**/ /**短信推送**/
public final static String SMS_PUSH = "smsPush"; public final static String SMS_PUSH = "smsPush";

67
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<String,String> 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;
}

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

@ -22,10 +22,11 @@ import javax.annotation.Resource;
) )
public interface IMessageClient { public interface IMessageClient {
String API_PREFIX = "/feign/message"; String API_PREFIX = "/feign/message";
String SEND_SMS_MESSAGE = API_PREFIX + "/send-sms-message";
String SEND_MESSAGE = API_PREFIX + "/sendMessage"; 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 PLAN_SEND_MESSAGE = API_PREFIX + "/planSendMessage";
String GET_TEMPLATE_BY_ID = API_PREFIX + "/getMsgTemplateById";
String SEND_APP_AND_WS_MSG = API_PREFIX + "/sendAppAndWsMsgByUsers"; String SEND_APP_AND_WS_MSG = API_PREFIX + "/sendAppAndWsMsgByUsers";
String SEND_SMS_IMMEDIATELY_MSG = API_PREFIX + "/sendSmsImmediatelyMsg"; String SEND_SMS_IMMEDIATELY_MSG = API_PREFIX + "/sendSmsImmediatelyMsg";
@ -44,6 +45,9 @@ public interface IMessageClient {
@GetMapping(GET_TEMPLATE_BY_ID) @GetMapping(GET_TEMPLATE_BY_ID)
R<MessageTemplateEntity> getMsgTemplateById(@RequestParam Long id); R<MessageTemplateEntity> getMsgTemplateById(@RequestParam Long id);
@PostMapping(value = SEND_WX_MESSAGE,consumes = "application/json; charset=UTF-8")
R<Boolean> sendWxMessage(@RequestBody WxMessageDTO request);
/** /**
* @return * @return
* @Author hx * @Author hx

5
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 @Override
public R<Boolean> sendWxMessage(WxMessageDTO request) {
return R.fail("调用失败!");
}
@Override
public R<PlanMsgRecordDto> planSendMessage(PlanMsgRecordDto request) { public R<PlanMsgRecordDto> planSendMessage(PlanMsgRecordDto request) {
return R.fail("调用失败!"); return R.fail("调用失败!");
} }

25
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 javax.validation.Valid;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -77,6 +78,28 @@ public class MessageClient extends BladeController implements IMessageClient{
return R.data(messageTemplateService.getById(id)); return R.data(messageTemplateService.getById(id));
} }
@Override
public R<Boolean> sendWxMessage(WxMessageDTO request) {
// 微信消息推送记录保存
List<MessagePushRecordEntity> 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) @PostMapping(PLAN_SEND_MESSAGE)
@Override @Override
public R<PlanMsgRecordDto> planSendMessage(@RequestBody @Valid PlanMsgRecordDto request) { public R<PlanMsgRecordDto> planSendMessage(@RequestBody @Valid PlanMsgRecordDto request) {
@ -141,7 +164,7 @@ public class MessageClient extends BladeController implements IMessageClient{
// 推送消息 - app // 推送消息 - app
Boolean appFlag = recordService.sendAppMsgByUsers(request, appRecords); Boolean appFlag = recordService.sendAppMsgByUsers(request, appRecords);
// 推送消息 - web // 推送消息 - 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); return R.data(appFlag && wsFlag);
} }
else { else {

3
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.baomidou.mybatisplus.core.metadata.IPage;
import com.hnac.hzims.message.dto.BusinessMessageDTO; 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.entity.MessagePushRecordEntity;
import com.hnac.hzims.message.vo.UnreadMessageVO; import com.hnac.hzims.message.vo.UnreadMessageVO;
import com.hnac.hzims.message.vo.msgpushrecord.*; import com.hnac.hzims.message.vo.msgpushrecord.*;
@ -102,6 +103,8 @@ public interface IMessagePushRecordService extends BaseService<MessagePushRecord
**/ **/
List<UnreadMessageVO> getPersonalAppUnreadMessage(); List<UnreadMessageVO> getPersonalAppUnreadMessage();
Boolean sendWxMessageByUser(WxMessageDTO message,List<MessagePushRecordEntity> records);
/** /**
* App多人推送消息 * App多人推送消息
* @param request 消息内容 * @param request 消息内容

19
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.MessageConstants;
import com.hnac.hzims.message.config.MessageFactory; import com.hnac.hzims.message.config.MessageFactory;
import com.hnac.hzims.message.dto.BusinessMessageDTO; 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.entity.MessagePushRecordEntity;
import com.hnac.hzims.message.enums.PushStatEnum; import com.hnac.hzims.message.enums.PushStatEnum;
import com.hnac.hzims.message.mapper.MessagePushRecordMapper; import com.hnac.hzims.message.mapper.MessagePushRecordMapper;
@ -392,6 +393,24 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
} }
@Override @Override
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);
boolean isSend = service.send(param);
if (isSend) {
this.update(Wrappers.<MessagePushRecordEntity>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<MessagePushRecordEntity> records) { public Boolean sendAppMsgByUsers(BusinessMessageDTO request, List<MessagePushRecordEntity> records) {
PushMessageServiceImpl service = SpringUtil.getBean(PushMessageServiceImpl.class); PushMessageServiceImpl service = SpringUtil.getBean(PushMessageServiceImpl.class);
try { try {

124
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 <T extends PushDto> 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<String> userIds,String tenantId) throws Exception {
return false;
}
public boolean send(Map<String, Object> 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();
}
}

5
hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java

@ -742,10 +742,7 @@ public class StAlamRecordServiceImpl extends BaseServiceImpl<StAlarmRecordMapper
log.error("fault_list_stations: {}",stations); log.error("fault_list_stations: {}",stations);
log.error("fault_list_list: {}",list); log.error("fault_list_list: {}",list);
Map<String,String> map = stations.stream().collect(Collectors.toMap(StationEntity::getCode,StationEntity::getName)); Map<String,String> map = stations.stream().collect(Collectors.toMap(StationEntity::getCode,StationEntity::getName));
return list.stream().filter(fault -> map.containsKey(fault.getStation())).map(o->{ return list.stream().filter(fault -> map.containsKey(fault.getStation())).peek(o-> o.setStationName(map.get(o.getStation()))).collect(Collectors.toList());
o.setStationName(map.get(o.getStation()));
return o;
}).collect(Collectors.toList());
} }

Loading…
Cancel
Save