修改公告逻辑

This commit is contained in:
lulz1 2024-04-24 14:46:31 +08:00
parent bfa2e83a6d
commit 1cf110095b
5 changed files with 71 additions and 11 deletions

View File

@ -2,8 +2,6 @@ package com.chint.application.dtos;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
@Data @Data
public class SystemAnnouncementDTO { public class SystemAnnouncementDTO {
private Long announcementId; // 公告的唯一标识符 private Long announcementId; // 公告的唯一标识符
@ -13,4 +11,5 @@ public class SystemAnnouncementDTO {
private String postDate; // 公告发布的日期和时间 private String postDate; // 公告发布的日期和时间
private String expiryDate; // 公告的过期日期 private String expiryDate; // 公告的过期日期
private Integer priority; // 公告的优先级用于排序 private Integer priority; // 公告的优先级用于排序
private String employeeNo;
} }

View File

@ -2,6 +2,7 @@ package com.chint.application.system;
import com.chint.application.dtos.SystemAnnouncementDTO; import com.chint.application.dtos.SystemAnnouncementDTO;
import com.chint.domain.aggregates.system.SystemAnnouncement; import com.chint.domain.aggregates.system.SystemAnnouncement;
import com.chint.domain.aggregates.system.SystemAnnouncementEmployee;
import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.SystemAnnouncementRepository; import com.chint.domain.repository.SystemAnnouncementRepository;
import com.chint.infrastructure.util.Result; import com.chint.infrastructure.util.Result;
@ -35,6 +36,20 @@ public class SystemController {
return Result.Success(SUCCESS, systemAnnouncementRepository.save(systemAnnouncement)); return Result.Success(SUCCESS, systemAnnouncementRepository.save(systemAnnouncement));
} }
@ApiOperation("新增已查看用户")
@PostMapping("/announcement/save")
public Result<String> 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("更新公告") @ApiOperation("更新公告")
@PostMapping("/announcement/update") @PostMapping("/announcement/update")
public Result<String> updateAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) { public Result<String> updateAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) {
@ -51,9 +66,23 @@ public class SystemController {
@ApiOperation("查询最新公告") @ApiOperation("查询最新公告")
@PostMapping("/announcement/query/last") @PostMapping("/announcement/query/last")
public Result<SystemAnnouncement> queryLastAnnouncement() { public Result<SystemAnnouncement> queryLastAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) {
return Result.Success(SUCCESS, systemAnnouncementRepository.findNew().orElseThrow(() -> new NotFoundException(NOT_FOUND))); SystemAnnouncement systemAnnouncement = systemAnnouncementRepository
.findNew()
.orElseThrow(() -> new NotFoundException(NOT_FOUND));
List<SystemAnnouncementEmployee> systemAnnouncementEmployeeList = systemAnnouncement.getSystemAnnouncementEmployeeList();
if (systemAnnouncementEmployeeList != null && !systemAnnouncementEmployeeList.isEmpty()) {
List<String> employeeNoList = systemAnnouncementEmployeeList
.stream()
.map(SystemAnnouncementEmployee::getEmployeeNo)
.toList();
if (employeeNoList.contains(systemAnnouncementDTO.getEmployeeNo())) {
return Result.Success(SUCCESS, null);
} }
}
return Result.Success(SUCCESS, systemAnnouncement);
}
@ApiOperation("查询有效公告") @ApiOperation("查询有效公告")
@PostMapping("/announcement/query/effective") @PostMapping("/announcement/query/effective")

View File

@ -7,6 +7,7 @@ import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.DateTimeUtil; import com.chint.infrastructure.util.DateTimeUtil;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table; import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial; import java.io.Serial;
@ -14,6 +15,8 @@ import java.io.Serializable;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
@Data @Data
@Table("system_announcements") @Table("system_announcements")
@ -29,6 +32,18 @@ public class SystemAnnouncement implements Serializable {
private LocalDateTime expiryDate; // 公告的过期日期 private LocalDateTime expiryDate; // 公告的过期日期
private String status; // 公告的状态 private String status; // 公告的状态
private Integer priority; // 公告的优先级用于排序 private Integer priority; // 公告的优先级用于排序
@MappedCollection(idColumn = "announcement_id" , keyColumn = "announcement_key")
private List<SystemAnnouncementEmployee> 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) { public static SystemAnnouncement of(SystemAnnouncementDTO dto) {
SystemAnnouncement systemAnnouncement = BeanUtil.copyProperties(dto, SystemAnnouncement.class); SystemAnnouncement systemAnnouncement = BeanUtil.copyProperties(dto, SystemAnnouncement.class);

View File

@ -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;
}

View File

@ -35,12 +35,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import static com.chint.infrastructure.constant.BPMConstant.*; 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.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.DataMessageConstant.DATA_NOT_FOUND;
import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.LegConstant.*;
import static com.chint.infrastructure.constant.OrderConstant.*; import static com.chint.infrastructure.constant.OrderConstant.*;
@ -205,10 +205,7 @@ public class LegEventHandler implements LegEventService {
OrderLegData data = command.getData(); OrderLegData data = command.getData();
String orderNo = data.getSelfOrderNo(); String orderNo = data.getSelfOrderNo();
RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(orderNo); RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(orderNo);
//获取行程规划单创建者作为该订单
if (routeOrder == null) {
throw new OrderException(NOT_FOUND + "单号为" + orderNo);
}
String employeeNo = routeOrder.getUserId(); String employeeNo = routeOrder.getUserId();
User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo); User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo);
BaseContext.setCurrentUser(byUserEmployeeNo); BaseContext.setCurrentUser(byUserEmployeeNo);