提交 10352045 authored 作者: 刘海泉's avatar 刘海泉

增加站内信相关代码

上级 4fdfc71d
...@@ -353,6 +353,12 @@ ...@@ -353,6 +353,12 @@
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId> <artifactId>spring-cloud-loadbalancer</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.msl.message</groupId>
<artifactId>message-sdk</artifactId>
</dependency>
</dependencies> </dependencies>
......
package com.clx.performance.config;
import com.msl.common.open.ConfiguredOpenClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Objects;
@Configuration
public class ConfiguredOpenClientConfig {
@Bean
public ConfiguredOpenClient configuredOpenClient(ConfiguredOpenProperties properties) {
return new ConfiguredOpenClient(Objects.requireNonNull(properties.getGatewayUrl()),
Objects.requireNonNull(properties.getAppId()),
Objects.requireNonNull(properties.getAppKey()));
}
}
package com.clx.performance.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@ConfigurationProperties(prefix = "message")
@Getter
@Setter
@Configuration
public class ConfiguredOpenProperties {
private String gatewayUrl;
private String appId;
private String appKey;
private String accessKey;
}
package com.clx.performance.dto;
import com.clx.performance.enums.InternalMessageTemplateEnum;
import lombok.Getter;
import lombok.Setter;
/**
* @ClassName InternalMessageDTO
* @Description
* @Author kavin
* @Date 2024/10/16 15:17
* @Version 1.0
*/
@Getter
@Setter
public class InternalMessageDTO {
//站内信模版枚举
private InternalMessageTemplateEnum.TemplateType templateType;
//站内信模版内容
private String content;
//站内信点对点的用户
private Long userNo;
}
package com.clx.performance.service;
public interface SendInternalMessageService {
}
package com.clx.performance.service.impl;
import com.alibaba.fastjson.JSON;
import com.clx.performance.config.ConfiguredOpenProperties;
import com.clx.performance.enums.InternalMessageTemplateEnum;
import com.clx.performance.service.SendInternalMessageService;
import com.msl.common.base.PageData;
import com.msl.common.open.ConfiguredOpenClient;
import com.msl.common.result.Result;
import com.msl.message.in.app.api.content.DefaultMessageContent;
import com.msl.message.in.app.api.message.InAppDefaultMessage;
import com.msl.message.in.app.api.recipient.SpecifiesRecipient;
import com.msl.message.in.app.api.route.DefaultMessageRoute;
import com.msl.message.sdk.action.MessageAction;
import com.msl.user.feign.UserFeign;
import com.msl.user.param.user.external.PageProductUsersParam;
import com.msl.user.vo.user.external.PageProductUserVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
/**
* @ClassName SendInternalMessageServiceImpl
* @Description
* @Author kavin
* @Date 2024/10/16 13:37
* @Version 1.0
*/
@Slf4j
@Service
@AllArgsConstructor
public class SendInternalMessageServiceImpl implements SendInternalMessageService {
private final ConfiguredOpenClient configuredOpenClient;
private final ConfiguredOpenProperties configuredOpenProperties;
private final UserFeign userFeign;
//TODO 后续修改Nacos的短信和站内信的 accessKey ,进行区分
public final String accessKey = "CARRIER_INTERNAL_MESSAGE";
/**
* 发送消息JSON实例:{"type": "in_app_default_message", "route": {"$ref": "$.messageRoute"}, "content": {"data": {"page": "message_operation_code:coal_source_publish_success_sales", "tonnage": "700.00", "coalType": "喜喜煤", "demandId": 932, "publisher": "陈小云", "unitPrice": "123.85", "demandType": "销售需求", "companyName": "产权交易中心", "jumpPageUrls": {"trade-operation-pc": "/demand/sale-detail/932"}, "inAppSendType": 2, "calorificValue": 7700, "validityPeriod": "2024-07-23 15:11:00-2024-07-23 23:11:00", "extraShowInfoList": [{"code": "companyName", "name": "企业名称", "unit": "", "value": "产权交易中心"}, {"code": "publisher", "name": "发布人姓名", "unit": "", "value": "陈小云"}, {"code": "coalType", "name": "煤种", "unit": "", "value": "喜喜煤"}, {"code": "calorificValue", "name": "热值", "unit": "kcal", "value": 7700}, {"code": "unitPrice", "name": "单价", "unit": "元/吨", "value": "123.85"}, {"code": "tonnage", "name": "吨数", "unit": "吨", "value": "700.00"}, {"code": "validityPeriod", "name": "有效期", "unit": "", "value": "2024-07-23 15:11:00-2024-07-23 23:11:00"}], "inAppSendTypeName": "全局提示"}, "type": "template_content", "templateKey": "SMB-INAPP-00001"}, "showType": "2", "accessKey": "CLX-OPERATION", "recipient": {"$ref": "$.messageRecipient"}, "channelKey": "in_app", "messageSign": "1", "messageGroup": "4", "messageRoute": {"type": "default_route", "routeMap": {"trade-operation-pc": ["default"]}}, "messageContent": {"$ref": "$.content"}, "messageSignName": "需求上报", "messageGroupName": "需求信息", "messageRecipient": {"type": "specifies_recipient", "users": [1021110826118750277, 1021252468523831365, 1021138417641676869, 1021095992956997701, 1021081090547744837]}, "validityLimitTime": "2024-07-24 15:12:04"}
* socket推送JSON实例:{"productCode":"trade-client-app","functionKey":"CLX-SMB-SALES","userKey":"1021138417641676869","deliverToCompany":1,"companyKey":"1121232210178818117","userTag":null,"message":{"bizType":"in_app","body":{"id":16674,"messageNo":"1292033698861125","accessKey":"CLX-SMB-SALES","companyNo":"1121232210178818117","userNo":"1021138417641676869","messageGroup":"2","messageSign":"4","messageGroupName":"交易提醒","messageSignName":"交易提醒","showType":"3","showPriority":null,"validityLimitTime":"2024-07-25 15:12:04","showStatus":null,"showTime":null,"receivePage":null,"jumpPage":null,"markdownFlag":null,"status":null,"statusName":null,"readTime":null,"executedTime":null,"textVo":{"title":"需求发布成功","subtitle":"您好,当前企业有销售需求发布成功,请及时关注;【喜喜煤】/【7700kcal】/【700.00吨】/【123.85元/吨】,发布人:【陈小云】","content":null,"dataJson":"{\"unitPrice\":\"123.85\",\"calorificValue\":7700,\"demandId\":932,\"inAppSendType\":3,\"inAppSendTypeName\":\"消息通知\",\"jumpPageAppParam\":{\"id\":\"932\",\"underFlag\":\"1\"},\"coalType\":\"喜喜煤\",\"publisher\":\"陈小云\",\"jumpPageAppUrl\":\"/ReleaseDetailsPage\",\"tonnage\":\"700.00\",\"page\":\"message_code:demand_publish_success_sales\",\"extraShowInfoList\":[{\"unit\":\"\",\"code\":\"coalType\",\"name\":\"煤种\",\"value\":\"喜喜煤\"},{\"unit\":\"kcal\",\"code\":\"calorificValue\",\"name\":\"热值\",\"value\":7700},{\"unit\":\"吨\",\"code\":\"tonnage\",\"name\":\"吨数\",\"value\":\"700.00\"},{\"unit\":\"元/吨\",\"code\":\"unitPrice\",\"name\":\"单价\",\"value\":\"123.85\"},{\"unit\":\"\",\"code\":\"publisher\",\"name\":\"发布人姓名\",\"value\":\"陈小云\"}]}"},"createTime":null},"bodyType":3}}
*/
//发送司机站内信
public void sendCarrierInternalMessage(InternalMessageTemplateEnum.TemplateType templateType,String content) {
InAppDefaultMessage message = new InAppDefaultMessage();
//消息
message.setMessageGroup(templateType.getMessageType().getCode());
message.setMessageGroupName(templateType.getMessageType().getName());
message.setMessageSign(templateType.getBusinessType().getCode());
message.setMessageSignName(templateType.getBusinessType().getName());
//TODO 自己定义,提供给消息中心
message.setAccessKey(accessKey);
//发送站内信
DefaultMessageRoute messageRoute = new DefaultMessageRoute();
//TODO 自己定义,提供给消息中心
messageRoute.put("product-code",InternalMessageTemplateEnum.PlatformType.CARRIER.getCode());
message.setMessageRoute(messageRoute);
//直接指定内容
DefaultMessageContent defaultMessageContent = new DefaultMessageContent();
defaultMessageContent.setTitle(templateType.getBusinessDetailType().getTitle());
defaultMessageContent.setContext(content);
HashMap<String,Object> data = new HashMap<>();
data.put("businessDetailTypeCode",templateType.getBusinessDetailType().getCode());
data.put("businessDetailTypeTitle",templateType.getBusinessDetailType().getTitle());
defaultMessageContent.setData(data); //放入标识,让前端根据这个标识跳转页面
message.setMessageContent(defaultMessageContent);
//组装发送人 指定接收人
SpecifiesRecipient messageRecipient = new SpecifiesRecipient();
List<Long> list = getPlatformUser();
if(CollectionUtils.isEmpty(list)){
log.error("查询承运平台下全部用户返回为空");
}
messageRecipient.setUsers(list);
message.setMessageRecipient(messageRecipient);
//向消息中心发送消息
log.info("站内信发送参数,发送参数:{}", message);
Result<Object> result = configuredOpenClient.doAction(new MessageAction(message));
log.info("站内信发送成功,发送结果:{}", result.toString());
}
public List<Long> getPlatformUser(){
PageProductUsersParam param = new PageProductUsersParam();
param.setProductCode(InternalMessageTemplateEnum.PlatformType.CARRIER.getCode());
param.setPage(1);
param.setPageSize(10000);
log.info("开始查询承运平台下的所有用户信息");
Result<PageData<PageProductUserVo>> pageDataResult = userFeign.pageProductUsers(param);
if(pageDataResult.succeed()){
return pageDataResult.getData().getRecords().stream().map(
PageProductUserVo::getUserNo).collect(Collectors.toList());
}else{
log.info("结束查询承运平台下的所有用户信息,响应结果:{}", JSON.toJSONString(pageDataResult));
return null;
}
}
}
package com.clx.performance.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.Optional;
public class InternalMessageTemplateEnum {
@Getter
@AllArgsConstructor
public enum TemplateType {
GO_TO_SEND_TIMEOUT(PlatformType.CARRIER, MessageType.WARN, BusinessType.CHILD_WARN,BusinessTypeDetail.GO_TO_SEND_TIMEOUT),
;
private final PlatformType platform; //承运平台 司机APP
private final MessageType messageType; //预警、待办、通知、上报
private final BusinessType businessType; //业务大类 运单预警
private final BusinessTypeDetail businessDetailType; //业务详细分类 前往目的地超时等
}
@Getter
@AllArgsConstructor
public enum BusinessTypeDetail {
ARRIVE_SEND_DELAY("GO_TO_SEND_TIMEOUT", "预警通知:到达货源地延误"),
GO_TO_SEND_TIMEOUT("GO_TO_SEND_TIMEOUT", "预警通知:前往货源地超时"),
;
private final String code;
private final String title;
public static Optional<BusinessTypeDetail> getByCode(String code) {
return Arrays.stream(values()).filter(e -> e.code.equals(code)).findFirst();
}
public static String getTitle(String code) {
if (code == null) {return null;}
return getByCode(code).map(BusinessTypeDetail::getTitle).orElse(null);
}
}
@Getter
@AllArgsConstructor
public enum BusinessType {
CHILD_WARN("CHILD_WARN", "运单预警"),
LINE_WARN("LINE_WARN", "线路预警"),
WAIT_QUOTATION_ORDER("WAIT_QUOTATION_ORDER", "待报价订单"),
WAIT_APPROVED_ITEM("WAIT_APPROVED_ITEM", "待审核事项"),
WAIT_CREATE_ORDER_GOODS("WAIT_CREATE_ORDER_GOODS", "待创建货单"),
ORDER_NOTICE("ORDER_NOTICE", "订单通知"),
COMPLAINT_NOTICE("COMPLAINT_NOTICE", "投诉通知"),
DRIVER_REPORT("DRIVER_REPORT", "司机上报"),
INTERNAL_REPORT("INTERNAL_REPORT", "内部上报"),
;
private final String code;
private final String name;
public static Optional<BusinessType> getByCode(String code) {
return Arrays.stream(values()).filter(e -> e.code.equals(code)).findFirst();
}
public static String getName(String code) {
if (code == null) {return null;}
return getByCode(code).map(BusinessType::getName).orElse(null);
}
}
@Getter
@AllArgsConstructor
public enum PlatformType {
CARRIER("carrier-platform-npc", "承运平台"),
DRIVER_APP("carrier-driver-app", "司机APP"),
;
private final String code;
private final String name;
public static Optional<PlatformType> getByCode(String code) {
return Arrays.stream(values()).filter(e -> e.code.equals(code)).findFirst();
}
public static String getName(String code) {
if (code == null) {return null;}
return getByCode(code).map(PlatformType::getName).orElse(null);
}
}
//预警、待办、通知、上报
@Getter
@AllArgsConstructor
public enum MessageType {
WARN("WARN", "预警"),
WAIT_DEAL("WAIT_DEAL", "待办"),
NOTICE("NOTICE", "通知"),
REPORT("REPORT", "上报"),
;
private final String code;
private final String name;
public static Optional<MessageType> getByCode(String code) {
return Arrays.stream(values()).filter(e -> e.code.equals(code)).findFirst();
}
public static String getName(String code) {
if (code == null) {return null;}
return getByCode(code).map(MessageType::getName).orElse(null);
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论