From fc811fc9fbcbd48348d0e1277c81a3250caecc84 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Wed, 24 Apr 2024 15:23:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=AC=E5=91=8A=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dtos/SystemAnnouncementVO.java | 20 +++++++++++++++++ .../application/system/SystemController.java | 17 +++----------- .../aggregates/system/SystemAnnouncement.java | 22 +++++++++++++++++-- 3 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/chint/application/dtos/SystemAnnouncementVO.java diff --git a/src/main/java/com/chint/application/dtos/SystemAnnouncementVO.java b/src/main/java/com/chint/application/dtos/SystemAnnouncementVO.java new file mode 100644 index 00000000..b50b1054 --- /dev/null +++ b/src/main/java/com/chint/application/dtos/SystemAnnouncementVO.java @@ -0,0 +1,20 @@ +package com.chint.application.dtos; + +import cn.hutool.core.bean.BeanUtil; +import com.chint.domain.aggregates.system.SystemAnnouncement; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class SystemAnnouncementVO { + private Long announcementId; // 公告的唯一标识符 + private String title; // 公告的标题 + private String content; // 公告的详细内容 + private String postedBy; // 发布公告的用户或管理员的用户名 + private LocalDateTime postDate; // 公告发布的日期和时间 + private LocalDateTime expiryDate; // 公告的过期日期 + private String status; // 公告的状态 + private Integer priority; // 公告的优先级,用于排序 + private Integer ifRead; //1已看过,0未看过 +} diff --git a/src/main/java/com/chint/application/system/SystemController.java b/src/main/java/com/chint/application/system/SystemController.java index af36f569..ef64142f 100644 --- a/src/main/java/com/chint/application/system/SystemController.java +++ b/src/main/java/com/chint/application/system/SystemController.java @@ -1,8 +1,8 @@ package com.chint.application.system; import com.chint.application.dtos.SystemAnnouncementDTO; +import com.chint.application.dtos.SystemAnnouncementVO; import com.chint.domain.aggregates.system.SystemAnnouncement; -import com.chint.domain.aggregates.system.SystemAnnouncementEmployee; import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.repository.SystemAnnouncementRepository; import com.chint.infrastructure.util.Result; @@ -66,22 +66,11 @@ public class SystemController { @ApiOperation("查询最新公告") @PostMapping("/announcement/query/last") - public Result queryLastAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) { + public Result queryLastAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) { SystemAnnouncement systemAnnouncement = systemAnnouncementRepository .findNew() .orElseThrow(() -> new NotFoundException(NOT_FOUND)); - List systemAnnouncementEmployeeList = systemAnnouncement.getSystemAnnouncementEmployeeList(); - if (systemAnnouncementEmployeeList != null && !systemAnnouncementEmployeeList.isEmpty()) { - List employeeNoList = systemAnnouncementEmployeeList - .stream() - .map(SystemAnnouncementEmployee::getEmployeeNo) - .toList(); - if (employeeNoList.contains(systemAnnouncementDTO.getEmployeeNo())) { - return Result.Success(SUCCESS, null); - } - } - systemAnnouncement.setSystemAnnouncementEmployeeList(null); - return Result.Success(SUCCESS, systemAnnouncement); + return Result.Success(SUCCESS, systemAnnouncement.mapToVo(systemAnnouncementDTO.getEmployeeNo())); } diff --git a/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java b/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java index 5f1b9ba3..5c042def 100644 --- a/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java +++ b/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java @@ -2,6 +2,7 @@ package com.chint.domain.aggregates.system; import cn.hutool.core.bean.BeanUtil; import com.chint.application.dtos.SystemAnnouncementDTO; +import com.chint.application.dtos.SystemAnnouncementVO; import com.chint.domain.aggregates.user.User; import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.DateTimeUtil; @@ -32,19 +33,36 @@ public class SystemAnnouncement implements Serializable { private LocalDateTime expiryDate; // 公告的过期日期 private String status; // 公告的状态 private Integer priority; // 公告的优先级,用于排序 - @MappedCollection(idColumn = "announcement_id" , keyColumn = "announcement_key") + @MappedCollection(idColumn = "announcement_id", keyColumn = "announcement_key") private List systemAnnouncementEmployeeList; public SystemAnnouncement addSystemAnnouncementEmployee(String employeeNo) { SystemAnnouncementEmployee systemAnnouncementEmployee = new SystemAnnouncementEmployee(); systemAnnouncementEmployee.setEmployeeNo(employeeNo); - if(systemAnnouncementEmployeeList == null){ + if (systemAnnouncementEmployeeList == null) { systemAnnouncementEmployeeList = new ArrayList<>(); } systemAnnouncementEmployeeList.add(systemAnnouncementEmployee); return this; } + public SystemAnnouncementVO mapToVo(String employeeNo) { + SystemAnnouncementVO systemAnnouncementVO = BeanUtil.copyProperties(this, SystemAnnouncementVO.class); + List systemAnnouncementEmployeeList = this.getSystemAnnouncementEmployeeList(); + if (systemAnnouncementEmployeeList != null && !systemAnnouncementEmployeeList.isEmpty()) { + List employeeNoList = systemAnnouncementEmployeeList + .stream() + .map(SystemAnnouncementEmployee::getEmployeeNo) + .toList(); + if (employeeNoList.contains(employeeNo)) { + systemAnnouncementVO.setIfRead(1); + return systemAnnouncementVO; + } + } + systemAnnouncementVO.setIfRead(0); + return systemAnnouncementVO; + } + public static SystemAnnouncement of(SystemAnnouncementDTO dto) { SystemAnnouncement systemAnnouncement = BeanUtil.copyProperties(dto, SystemAnnouncement.class); if (systemAnnouncement.getPostDate() == null) {