Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/zy/notice event bus #10

Merged
merged 16 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions openeulerSever/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
Expand All @@ -12,6 +13,7 @@
@EnableWebMvc
@EnableRetry
@EnableScheduling
@EnableAsync
public class OpenEulerApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @since 2024/06/29
*/
@Configuration
@MapperScan(value = {"com.huawei.it.euler.mapper","com.huawei.it.euler.ddd.domain.software","com.huawei.it.euler.ddd.domain.hardware"})
@MapperScan(value = {"com.huawei.it.euler.mapper","com.huawei.it.euler.ddd.domain.software","com.huawei.it.euler.ddd.domain.hardware","com.huawei.it.euler.ddd.infrastructure.persistence.mapper"})
public class MybatisPlusConfig {
/**
* 配置分页插件
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
*/

package com.huawei.it.euler.ddd.domain.company.primitive;

import lombok.Getter;

/**
* 企业审核结果枚举
*
* @author zhaoyan
* @since 2024-12-18
*/
@Getter
public enum ApproveResult {

PASS(true,"通过"),

REJECT(false,"驳回");

private final Boolean value;

private final String desc;

ApproveResult(Boolean value, String desc) {
this.value = value;
this.desc = desc;
}

public static String findDesc(Boolean value){
return value? PASS.getDesc() : REJECT.getDesc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

package com.huawei.it.euler.ddd.domain.notice;

import com.huawei.it.euler.ddd.domain.notice.primitive.ActiveStatus;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Date;

/**
Expand All @@ -25,7 +27,7 @@ public class NoticeBoard {
/**
* 是否有效状态
*/
String isActive;
ActiveStatus isActive;

/**
* 过期时间
Expand All @@ -35,6 +37,11 @@ public class NoticeBoard {
/**
* 更新时间
*/
private Date updateTime;
private LocalDateTime updateTime;

public void publish() {
this.isActive = ActiveStatus.ACTIVE;
this.updateTime = LocalDateTime.now();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
*/

package com.huawei.it.euler.ddd.domain.notice;

import java.util.List;

/**
* 系统公告 持久化接口
*
* @author zhaoyan
* @since 2024-12-16
*/
public interface NoticeBoardRepository {
/**
* 查询有效系统公告,有效:active=y
* @return 有效系统公告集合
*/
public List<NoticeBoard> findActiveList();

/**
* 发布系统公告
* @param noticeBoard 系统公告
* @return 已发布系统公告
*/
public NoticeBoard publish(NoticeBoard noticeBoard);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
*/

package com.huawei.it.euler.ddd.domain.notice;

import com.huawei.it.euler.ddd.domain.notice.primitive.MsgType;
import com.huawei.it.euler.ddd.domain.notice.primitive.SendType;
import com.huawei.it.euler.ddd.domain.notice.primitive.Status;
import com.huawei.it.euler.ddd.infrastructure.kafka.KafKaMessageDTO;
import lombok.Data;

import java.time.LocalDateTime;

/**
* 系统消息通知记录
*
* @author zhaoyan
* @since 2024-12-16
*/
@Data
public class NoticeMessage {
private final static String DEFAULT_SENDER = "system";
/**
* 主键id
*/
private Integer id;

/**
* 发送方,默认:system
*/
public String sender = DEFAULT_SENDER;

/**
* 接收方
*/
public String receiver;

/**
* 消息类型
*/
public MsgType msgType;

/**
* 发送方式
*/
public SendType sendType;

/**
* 模板
*/
public String template;

/**
* 消息主题
*/
public String subject;

/**
* 消息内容
*/
public String content;

/**
* KafKa消息内容
*/
public KafKaMessageDTO kafKaMessageDTO;

/**
* 消息状态
*/
public Status status;

/**
* 备注
*/
public String remark;

/**
* 创建时间
*/
public LocalDateTime createTime;

/**
* 更新时间
*/
public LocalDateTime updateTime;

public void sendCreate(){
this.createTime = LocalDateTime.now();
}

public void sendSuccess(){
this.status = Status.SUCCESS;
}

public void sendFailed(String errMsg){
this.status = Status.FAILED;
this.remark = errMsg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
*/

package com.huawei.it.euler.ddd.domain.notice;

/**
* 系统消息通知记录 持久化接口
*
* @author zhaoyan
* @since 2024-12-18
*/
public interface NoticeMessageRepository {
public NoticeMessage record(NoticeMessage message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
*/

package com.huawei.it.euler.ddd.domain.notice.policy;

import com.huawei.it.euler.ddd.domain.account.UserInfo;
import com.huawei.it.euler.ddd.domain.notice.NoticeMessage;
import com.huawei.it.euler.ddd.domain.notice.policy.impl.ApplyIntelEmailNoticePolicy;
import com.huawei.it.euler.ddd.domain.notice.policy.impl.ApproveIntelKafkaNoticePolicy;
import com.huawei.it.euler.ddd.domain.notice.policy.impl.CompanyApprovePhoneNoticePolicy;
import com.huawei.it.euler.ddd.domain.notice.policy.impl.RejectToUserEmailNoticePolicy;
import com.huawei.it.euler.ddd.domain.notice.policy.impl.RejectToUserPhoneNoticePolicy;
import org.springframework.context.ApplicationEvent;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
* 发送策略管理对象
*
* @author zhaoyan
* @since 2024-12-19
*/
@Component
public class SendManager {

private static final List<SendPolicy> POLICIES = new ArrayList<>();
static {
POLICIES.add(new ApplyIntelEmailNoticePolicy());
POLICIES.add(new ApproveIntelKafkaNoticePolicy());
POLICIES.add(new CompanyApprovePhoneNoticePolicy());
POLICIES.add(new RejectToUserEmailNoticePolicy());
POLICIES.add(new RejectToUserPhoneNoticePolicy());
}

/**
* 系统通知消息发送准备
* @param userInfo 通知接收人信息
* @param event 通知事件
* @return 系统通知消息对象
*/
public NoticeMessage prepareNotice(UserInfo userInfo, ApplicationEvent event){
for (SendPolicy policy : POLICIES) {
if (!policy.canSend(userInfo,event)){
continue;
}
return policy.prepareSend(userInfo,event);
}
NoticeMessage noticeMessage = new NoticeMessage();
noticeMessage.setReceiver(userInfo.getUuid());
noticeMessage.setContent(event.getSource().toString());
noticeMessage.sendCreate();
noticeMessage.sendFailed("no handle policy");
return noticeMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
*/

package com.huawei.it.euler.ddd.domain.notice.policy;

import com.huawei.it.euler.ddd.domain.account.UserInfo;
import com.huawei.it.euler.ddd.domain.notice.NoticeMessage;
import org.springframework.context.ApplicationEvent;

/**
* 消息发送策略
*
* @author zhaoyan
* @since 2024-12-19
*/

public interface SendPolicy {

/**
* 是否符合发送要求
* @param userInfo 接收人信息
* @param event 事件
* @return 检查结果
*/
public boolean canSend(UserInfo userInfo, ApplicationEvent event);

/**
* 消息发送准备
* @param userInfo 接收人信息
* @param event 事件
* @return 检查结果
*/
public NoticeMessage prepareSend(UserInfo userInfo, ApplicationEvent event);
}
Loading
Loading