完成系统公告模块
This commit is contained in:
parent
502774614e
commit
6748fe647e
|
@ -6,10 +6,11 @@ import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SystemAnnouncementDTO {
|
public class SystemAnnouncementDTO {
|
||||||
|
private Long announcementId; // 公告的唯一标识符
|
||||||
private String title; // 公告的标题
|
private String title; // 公告的标题
|
||||||
private String content; // 公告的详细内容
|
private String content; // 公告的详细内容
|
||||||
private String postedBy; // 发布公告的用户或管理员的用户名
|
private String postedBy; // 发布公告的用户或管理员的用户名
|
||||||
private LocalDateTime postDate; // 公告发布的日期和时间
|
private String postDate; // 公告发布的日期和时间
|
||||||
private LocalDateTime expiryDate; // 公告的过期日期
|
private String expiryDate; // 公告的过期日期
|
||||||
private Integer priority; // 公告的优先级,用于排序
|
private Integer priority; // 公告的优先级,用于排序
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
|
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
|
||||||
|
@ -33,6 +35,20 @@ public class SystemController {
|
||||||
return Result.Success(SUCCESS, systemAnnouncementRepository.save(systemAnnouncement));
|
return Result.Success(SUCCESS, systemAnnouncementRepository.save(systemAnnouncement));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("更新公告")
|
||||||
|
@PostMapping("/announcement/update")
|
||||||
|
public Result<String> updateAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO) {
|
||||||
|
systemAnnouncementRepository.findById(systemAnnouncementDTO.getAnnouncementId())
|
||||||
|
.ifPresent(systemAnnouncement -> {
|
||||||
|
systemAnnouncement.setTitle(systemAnnouncementDTO.getTitle());
|
||||||
|
systemAnnouncement.setContent(systemAnnouncementDTO.getContent());
|
||||||
|
systemAnnouncement.setPriority(systemAnnouncementDTO.getPriority());
|
||||||
|
systemAnnouncement.updateTime(systemAnnouncementDTO);
|
||||||
|
systemAnnouncementRepository.save(systemAnnouncement);
|
||||||
|
});
|
||||||
|
return Result.Success(SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation("查询最新公告")
|
@ApiOperation("查询最新公告")
|
||||||
@PostMapping("/announcement/query/last")
|
@PostMapping("/announcement/query/last")
|
||||||
public Result<SystemAnnouncement> queryLastAnnouncement() {
|
public Result<SystemAnnouncement> queryLastAnnouncement() {
|
||||||
|
@ -42,13 +58,19 @@ public class SystemController {
|
||||||
@ApiOperation("查询有效公告")
|
@ApiOperation("查询有效公告")
|
||||||
@PostMapping("/announcement/query/effective")
|
@PostMapping("/announcement/query/effective")
|
||||||
public Result<List<SystemAnnouncement>> queryEffectiveAnnouncement() {
|
public Result<List<SystemAnnouncement>> queryEffectiveAnnouncement() {
|
||||||
// List<SystemAnnouncement> effective = systemAnnouncementRepository.findEffective();
|
List<SystemAnnouncement> effective = systemAnnouncementRepository.findEffective();
|
||||||
//
|
effective.forEach(it->{
|
||||||
// effective.forEach(it->{
|
LocalDateTime expiryDate = it.getExpiryDate();
|
||||||
//
|
if(expiryDate.isBefore(LocalDateTime.now())) {
|
||||||
// });
|
it.setStatus("0");
|
||||||
//
|
systemAnnouncementRepository.save(it);
|
||||||
// return Result.Success(SUCCESS, systemAnnouncementRepository.findNew().orElseThrow(() -> new NotFoundException(NOT_FOUND)));
|
}
|
||||||
return null;
|
});
|
||||||
|
List<SystemAnnouncement> systemAnnouncements = effective
|
||||||
|
.stream()
|
||||||
|
.filter(it -> it.getStatus().equals("1"))
|
||||||
|
.sorted(Comparator.comparingInt(SystemAnnouncement::getPriority))
|
||||||
|
.toList();
|
||||||
|
return Result.Success(SUCCESS, systemAnnouncements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,16 @@ import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.chint.application.dtos.SystemAnnouncementDTO;
|
import com.chint.application.dtos.SystemAnnouncementDTO;
|
||||||
import com.chint.domain.aggregates.user.User;
|
import com.chint.domain.aggregates.user.User;
|
||||||
import com.chint.infrastructure.util.BaseContext;
|
import com.chint.infrastructure.util.BaseContext;
|
||||||
|
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.Table;
|
import org.springframework.data.relational.core.mapping.Table;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Table("system_announcements")
|
@Table("system_announcements")
|
||||||
|
@ -25,15 +28,23 @@ public class SystemAnnouncement implements Serializable {
|
||||||
private LocalDateTime postDate; // 公告发布的日期和时间
|
private LocalDateTime postDate; // 公告发布的日期和时间
|
||||||
private LocalDateTime expiryDate; // 公告的过期日期
|
private LocalDateTime expiryDate; // 公告的过期日期
|
||||||
private String status; // 公告的状态
|
private String status; // 公告的状态
|
||||||
private Integer priority; // 公告的优先级,用于排序、
|
private Integer priority; // 公告的优先级,用于排序
|
||||||
|
|
||||||
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);
|
||||||
if (systemAnnouncement.getPostDate() == null) {
|
if (systemAnnouncement.getPostDate() == null) {
|
||||||
systemAnnouncement.setPostDate(LocalDateTime.now());
|
systemAnnouncement.setPostDate(LocalDateTime.now());
|
||||||
|
} else {
|
||||||
|
LocalDateTime postDate = LocalDateTime.of(LocalDate.parse(dto.getPostDate(), DateTimeUtil.formatterDate),
|
||||||
|
LocalTime.MIN);
|
||||||
|
systemAnnouncement.setPostDate(postDate);
|
||||||
}
|
}
|
||||||
if (systemAnnouncement.getExpiryDate() == null) {
|
if (systemAnnouncement.getExpiryDate() == null) {
|
||||||
systemAnnouncement.setExpiryDate(LocalDateTime.now().plusDays(15L));
|
systemAnnouncement.setExpiryDate(LocalDateTime.now().plusDays(15L));
|
||||||
|
} else {
|
||||||
|
LocalDateTime expiryTime = LocalDateTime.of(LocalDate.parse(dto.getExpiryDate(), DateTimeUtil.formatterDate),
|
||||||
|
LocalTime.MAX);
|
||||||
|
systemAnnouncement.setPostDate(expiryTime);
|
||||||
}
|
}
|
||||||
systemAnnouncement.setStatus("1");
|
systemAnnouncement.setStatus("1");
|
||||||
systemAnnouncement.setPriority(0);
|
systemAnnouncement.setPriority(0);
|
||||||
|
@ -46,4 +57,22 @@ public class SystemAnnouncement implements Serializable {
|
||||||
}
|
}
|
||||||
return systemAnnouncement;
|
return systemAnnouncement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SystemAnnouncement updateTime(SystemAnnouncementDTO dto) {
|
||||||
|
if (dto.getPostDate() != null) {
|
||||||
|
this.setPostDate(LocalDateTime.of(LocalDate.parse(dto.getPostDate(), DateTimeUtil.formatterDate),
|
||||||
|
LocalTime.MIN));
|
||||||
|
}
|
||||||
|
if (dto.getExpiryDate() != null) {
|
||||||
|
this.setExpiryDate(LocalDateTime.of(LocalDate.parse(dto.getExpiryDate(), DateTimeUtil.formatterDate),
|
||||||
|
LocalTime.MAX));
|
||||||
|
}
|
||||||
|
LocalDateTime expiryDate = this.getExpiryDate();
|
||||||
|
if (expiryDate.isBefore(LocalDateTime.now())) {
|
||||||
|
this.setStatus("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.Optional;
|
||||||
public interface SystemAnnouncementRepository {
|
public interface SystemAnnouncementRepository {
|
||||||
SystemAnnouncement save(SystemAnnouncement systemAnnouncement);
|
SystemAnnouncement save(SystemAnnouncement systemAnnouncement);
|
||||||
|
|
||||||
|
Optional<SystemAnnouncement> findById(Long id);
|
||||||
|
|
||||||
Optional<SystemAnnouncement> findNew();
|
Optional<SystemAnnouncement> findNew();
|
||||||
|
|
||||||
List<SystemAnnouncement> findAll();
|
List<SystemAnnouncement> findAll();
|
||||||
|
|
|
@ -22,6 +22,11 @@ public class SystemAnnouncementRepositoryImpl implements SystemAnnouncementRepos
|
||||||
return jdbcSystemAnnouncementRepository.save(systemAnnouncement);
|
return jdbcSystemAnnouncementRepository.save(systemAnnouncement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<SystemAnnouncement> findById(Long id) {
|
||||||
|
return jdbcSystemAnnouncementRepository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<SystemAnnouncement> findNew() {
|
public Optional<SystemAnnouncement> findNew() {
|
||||||
return jdbcSystemAnnouncementRepository.findTopByOrderByAnnouncementIdDesc();
|
return jdbcSystemAnnouncementRepository.findTopByOrderByAnnouncementIdDesc();
|
||||||
|
|
Loading…
Reference in New Issue