修改公告逻辑
This commit is contained in:
parent
465df7284e
commit
fc811fc9fb
|
@ -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未看过
|
||||
}
|
|
@ -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<SystemAnnouncement> queryLastAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) {
|
||||
public Result<SystemAnnouncementVO> queryLastAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
systemAnnouncement.setSystemAnnouncementEmployeeList(null);
|
||||
return Result.Success(SUCCESS, systemAnnouncement);
|
||||
return Result.Success(SUCCESS, systemAnnouncement.mapToVo(systemAnnouncementDTO.getEmployeeNo()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<SystemAnnouncementEmployee> 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<SystemAnnouncementEmployee> systemAnnouncementEmployeeList = this.getSystemAnnouncementEmployeeList();
|
||||
if (systemAnnouncementEmployeeList != null && !systemAnnouncementEmployeeList.isEmpty()) {
|
||||
List<String> 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) {
|
||||
|
|
Loading…
Reference in New Issue