From 1cf110095b32d0255da620a558e85dc103fb62b6 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Wed, 24 Apr 2024 14:46:31 +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/SystemAnnouncementDTO.java | 3 +- .../application/system/SystemController.java | 37 +++++++++++++++++-- .../aggregates/system/SystemAnnouncement.java | 15 ++++++++ .../system/SystemAnnouncementEmployee.java | 20 ++++++++++ .../service/leg_event/LegEventHandler.java | 7 +--- 5 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/chint/domain/aggregates/system/SystemAnnouncementEmployee.java diff --git a/src/main/java/com/chint/application/dtos/SystemAnnouncementDTO.java b/src/main/java/com/chint/application/dtos/SystemAnnouncementDTO.java index 18bd548d..7ef04f86 100644 --- a/src/main/java/com/chint/application/dtos/SystemAnnouncementDTO.java +++ b/src/main/java/com/chint/application/dtos/SystemAnnouncementDTO.java @@ -2,8 +2,6 @@ package com.chint.application.dtos; import lombok.Data; -import java.time.LocalDateTime; - @Data public class SystemAnnouncementDTO { private Long announcementId; // 公告的唯一标识符 @@ -13,4 +11,5 @@ public class SystemAnnouncementDTO { private String postDate; // 公告发布的日期和时间 private String expiryDate; // 公告的过期日期 private Integer priority; // 公告的优先级,用于排序 + private String employeeNo; } diff --git a/src/main/java/com/chint/application/system/SystemController.java b/src/main/java/com/chint/application/system/SystemController.java index 09d79ec8..e6163acb 100644 --- a/src/main/java/com/chint/application/system/SystemController.java +++ b/src/main/java/com/chint/application/system/SystemController.java @@ -2,6 +2,7 @@ package com.chint.application.system; import com.chint.application.dtos.SystemAnnouncementDTO; 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; @@ -35,6 +36,20 @@ public class SystemController { return Result.Success(SUCCESS, systemAnnouncementRepository.save(systemAnnouncement)); } + @ApiOperation("新增已查看用户") + @PostMapping("/announcement/save") + public Result saveAnnouncementEmployee(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) { + systemAnnouncementRepository.findById(systemAnnouncementDTO.getAnnouncementId()) + .ifPresent(systemAnnouncement -> { + String employeeNo = systemAnnouncementDTO.getEmployeeNo(); + if (employeeNo != null && !employeeNo.isEmpty()) { + systemAnnouncement.addSystemAnnouncementEmployee(employeeNo); + systemAnnouncementRepository.save(systemAnnouncement); + } + }); + return Result.Success(SUCCESS); + } + @ApiOperation("更新公告") @PostMapping("/announcement/update") public Result updateAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) { @@ -51,17 +66,31 @@ public class SystemController { @ApiOperation("查询最新公告") @PostMapping("/announcement/query/last") - public Result queryLastAnnouncement() { - return Result.Success(SUCCESS, systemAnnouncementRepository.findNew().orElseThrow(() -> new NotFoundException(NOT_FOUND))); + 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); + } + } + return Result.Success(SUCCESS, systemAnnouncement); } + @ApiOperation("查询有效公告") @PostMapping("/announcement/query/effective") public Result> queryEffectiveAnnouncement() { List effective = systemAnnouncementRepository.findEffective(); - effective.forEach(it->{ + effective.forEach(it -> { LocalDateTime expiryDate = it.getExpiryDate(); - if(expiryDate.isBefore(LocalDateTime.now())) { + if (expiryDate.isBefore(LocalDateTime.now())) { it.setStatus("0"); systemAnnouncementRepository.save(it); } 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 c156de03..5f1b9ba3 100644 --- a/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java +++ b/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java @@ -7,6 +7,7 @@ import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.DateTimeUtil; import lombok.Data; import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.MappedCollection; import org.springframework.data.relational.core.mapping.Table; import java.io.Serial; @@ -14,6 +15,8 @@ import java.io.Serializable; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; @Data @Table("system_announcements") @@ -29,6 +32,18 @@ public class SystemAnnouncement implements Serializable { private LocalDateTime expiryDate; // 公告的过期日期 private String status; // 公告的状态 private Integer priority; // 公告的优先级,用于排序 + @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){ + systemAnnouncementEmployeeList = new ArrayList<>(); + } + systemAnnouncementEmployeeList.add(systemAnnouncementEmployee); + return this; + } public static SystemAnnouncement of(SystemAnnouncementDTO dto) { SystemAnnouncement systemAnnouncement = BeanUtil.copyProperties(dto, SystemAnnouncement.class); diff --git a/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncementEmployee.java b/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncementEmployee.java new file mode 100644 index 00000000..f2ea0db1 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncementEmployee.java @@ -0,0 +1,20 @@ +package com.chint.domain.aggregates.system; + +import lombok.Data; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; + + +@Data +@Table("system_announcements_employee") +public class SystemAnnouncementEmployee implements Serializable { + @Serial + private static final long serialVersionUID = 1926351891678893214L; + private Long id; + private Long announcementId; + private Integer announcementKey; + private String employeeNo; + private String extension; +} diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java index 580ef82b..eb572f38 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java @@ -35,12 +35,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import static com.chint.infrastructure.constant.BPMConstant.*; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR; -import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; import static com.chint.infrastructure.constant.DataMessageConstant.DATA_NOT_FOUND; import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.OrderConstant.*; @@ -205,10 +205,7 @@ public class LegEventHandler implements LegEventService { OrderLegData data = command.getData(); String orderNo = data.getSelfOrderNo(); RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(orderNo); - //获取行程规划单创建者作为该订单 - if (routeOrder == null) { - throw new OrderException(NOT_FOUND + "单号为" + orderNo); - } + String employeeNo = routeOrder.getUserId(); User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo); BaseContext.setCurrentUser(byUserEmployeeNo);