添加了Announcement相关的类与方法,将时间相关序列化的时区改为了+8:00,修复了TimeUtils不能使用的bug,修改了yml中的转发处理配置
parent
f715834af7
commit
2270bf6422
|
@ -34,14 +34,14 @@ public class SerializeConfig {
|
|||
@Override
|
||||
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
if (value != null) {
|
||||
gen.writeNumber(value.toEpochSecond(ZoneOffset.UTC));
|
||||
gen.writeNumber(value.toEpochSecond(ZoneOffset.of("+08:00")));
|
||||
}
|
||||
}
|
||||
});
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class, new JsonDeserializer<>() {
|
||||
@Override
|
||||
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
return Instant.ofEpochSecond(p.getValueAsLong(), 0).atOffset(ZoneOffset.UTC).toLocalDateTime();
|
||||
return Instant.ofEpochSecond(p.getValueAsLong(), 0).atOffset(ZoneOffset.of("+08:00")).toLocalDateTime();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class SerializeConfig {
|
|||
javaTimeModule.addDeserializer(LocalDate.class, new JsonDeserializer<>() {
|
||||
@Override
|
||||
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
return Instant.ofEpochSecond(p.getValueAsLong(), 0).atOffset(ZoneOffset.UTC).toLocalDate();
|
||||
return Instant.ofEpochSecond(p.getValueAsLong(), 0).atOffset(ZoneOffset.of("+08:00")).toLocalDate();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -66,14 +66,14 @@ public class SerializeConfig {
|
|||
@Override
|
||||
public void serialize(LocalTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
if (value != null) {
|
||||
gen.writeNumber(value.toEpochSecond(LocalDate.of(1970, 1, 1), ZoneOffset.UTC));
|
||||
gen.writeNumber(value.toEpochSecond(LocalDate.of(1970, 1, 1), ZoneOffset.of("+08:00")));
|
||||
}
|
||||
}
|
||||
});
|
||||
javaTimeModule.addDeserializer(LocalTime.class, new JsonDeserializer<>() {
|
||||
@Override
|
||||
public LocalTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
return Instant.ofEpochSecond(p.getValueAsLong(), 0).atOffset(ZoneOffset.UTC).toLocalTime();
|
||||
return Instant.ofEpochSecond(p.getValueAsLong(), 0).atOffset(ZoneOffset.of("+08:00")).toLocalTime();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Announcement;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.AnnouncementDto;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.ForbiddenException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IAnnouncementService;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
* @since 2022/7/7 11:29
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/project/{projectId}/announcement")
|
||||
public class AnnouncementController {
|
||||
|
||||
@Autowired
|
||||
private IAnnouncementService announcementService;
|
||||
@Autowired
|
||||
private IProjectGroupService projectGroupService;
|
||||
|
||||
@SneakyThrows
|
||||
@GetMapping
|
||||
public ResponseList<AnnouncementDto> getAnnouncementList(@RequestHeader("Token") String token, @PathVariable Integer projectId) {
|
||||
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
||||
throw new ForbiddenException("无该项目访问权限");
|
||||
}
|
||||
return ResponseList.ofSuccess("查询成功", announcementService.getAnnouncementList(projectId));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@GetMapping("/{announcementId}")
|
||||
public ResponseMap getAnnouncementById(
|
||||
@RequestHeader("Token") String token,
|
||||
@PathVariable Integer projectId,
|
||||
@PathVariable Long announcementId
|
||||
){
|
||||
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
||||
throw new ForbiddenException("无该项目访问权限");
|
||||
}
|
||||
return ResponseMap.ofSuccess("查询成功");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@PostMapping
|
||||
public ResponseMap createAnnouncement(
|
||||
@RequestHeader("Token") String token,
|
||||
@PathVariable Integer projectId,
|
||||
@RequestBody Announcement announcement
|
||||
) {
|
||||
if (projectGroupService.getProjectAccessLevel(token, projectId) > 2) {
|
||||
throw new ForbiddenException("无该操作权限");
|
||||
}
|
||||
announcement.setProjectId(projectId);
|
||||
announcement.setAnnouncementPublisherId(TokenUtils.getStaffId(token));
|
||||
announcement.setAnnouncementPublishTime(null);
|
||||
if (announcementService.save(announcement)) {
|
||||
return ResponseMap.ofSuccess("创建成功");
|
||||
}
|
||||
throw new BadRequestException("创建失败");
|
||||
}
|
||||
|
||||
//TODO: 查询权限高低
|
||||
@PutMapping("/{announcementId}")
|
||||
public ResponseMap modifyAnnouncement(
|
||||
@RequestHeader("Token") String token,
|
||||
@PathVariable Integer projectId,
|
||||
@PathVariable Long announcementId,
|
||||
@RequestBody Announcement announcement
|
||||
){
|
||||
|
||||
return ResponseMap.ofSuccess("更新成功");
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -80,7 +80,6 @@ public class ProjectGroupController {
|
|||
return ResponseMap.ofSuccess("更新成功");
|
||||
}
|
||||
|
||||
//TODO: test
|
||||
@SneakyThrows
|
||||
@GetMapping("/stats")
|
||||
public ResponseMap getGroupPositionsStatistics(
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
* @since 2022/7/7 11:22
|
||||
*/
|
||||
@Data
|
||||
public class Announcement {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long announcementId;
|
||||
private Integer projectId;
|
||||
private Integer announcementPublisherId;
|
||||
private LocalDateTime announcementPublishTime;
|
||||
private String announcementTitle;
|
||||
private String announcementContent;
|
||||
@TableField("is_deleted")
|
||||
@TableLogic
|
||||
private Boolean deleted;
|
||||
}
|
|
@ -48,13 +48,10 @@ public class Project {
|
|||
private LocalDate projectClosedDate;
|
||||
|
||||
public Boolean checkProjectDate() {
|
||||
if(!TimeUtils.validateTimeLine(projectStartDate, projectFirstTestDate, projectFinalTestDate, projectEndDate)) {
|
||||
if (!TimeUtils.validateDateLine(projectStartDate, projectFirstTestDate, projectFinalTestDate, projectEndDate)) {
|
||||
return false;
|
||||
}
|
||||
if (!TimeUtils.validateTimeLine(projectStartDate, projectOnlineDate)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return TimeUtils.validateDateLine(projectStartDate, projectOnlineDate);
|
||||
}
|
||||
|
||||
public Boolean checkModification(Project rawProject) {
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
* @since 2022/7/7 11:33
|
||||
*/
|
||||
@Data
|
||||
public class AnnouncementDto {
|
||||
private Long announcementId;
|
||||
private Integer announcementPublisherId;
|
||||
private String announcementPublisherName;
|
||||
private LocalDateTime announcementPublishTime;
|
||||
private String announcementTitle;
|
||||
private String announcementContent;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.mapper;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Announcement;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.AnnouncementDto;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
* @since 2022/7/7 11:26
|
||||
*/
|
||||
public interface AnnouncementMapper extends BaseMapper<Announcement> {
|
||||
List<AnnouncementDto> selectAnnouncementList(@Param("projectId") Integer projectId);
|
||||
|
||||
AnnouncementDto selectAnnouncementById(@Param("announcementId") Long announcementId);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.service;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Announcement;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.AnnouncementDto;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
* @since 2022/7/7 11:27
|
||||
*/
|
||||
public interface IAnnouncementService extends IService<Announcement> {
|
||||
List<AnnouncementDto> getAnnouncementList(Integer projectId);
|
||||
|
||||
AnnouncementDto getAnnouncementById(Long announcementId);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Announcement;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.AnnouncementDto;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.AnnouncementMapper;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IAnnouncementService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
* @since 2022/7/7 11:28
|
||||
*/
|
||||
@Service
|
||||
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements IAnnouncementService {
|
||||
|
||||
@Override
|
||||
public List<AnnouncementDto> getAnnouncementList(Integer projectId) {
|
||||
return baseMapper.selectAnnouncementList(projectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnouncementDto getAnnouncementById(Long announcementId) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.utils;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
|
@ -11,23 +11,51 @@ public class TimeUtils {
|
|||
/**
|
||||
* 验证参数是否按时间线先后顺序传入,忽略null
|
||||
*/
|
||||
public static boolean validateTimeLine(TemporalAccessor... temporalAccessors) {
|
||||
public static boolean validateDateLine(LocalDate... dates) {
|
||||
int first;
|
||||
for (first = 0; first < temporalAccessors.length; first++) {
|
||||
if (temporalAccessors[first] != null) {
|
||||
for (first = 0; first < dates.length; first++) {
|
||||
if (dates[first] != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (first >= temporalAccessors.length - 1) {
|
||||
if (first >= dates.length - 1) {
|
||||
return true;
|
||||
}
|
||||
Instant last = Instant.from(temporalAccessors[first]);
|
||||
Instant current;
|
||||
for (int i = first + 1; i < temporalAccessors.length; i++) {
|
||||
if (temporalAccessors[i] == null) {
|
||||
LocalDate last = dates[first];
|
||||
LocalDate current;
|
||||
for (int i = first + 1; i < dates.length; i++) {
|
||||
if (dates[i] == null) {
|
||||
continue;
|
||||
}
|
||||
current = Instant.from(temporalAccessors[i]);
|
||||
current = dates[i];
|
||||
if (last.isAfter(current)) {
|
||||
return false;
|
||||
}
|
||||
last = current;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证参数是否按时间线先后顺序传入,忽略null
|
||||
*/
|
||||
public static boolean validateDateTimeLine(LocalDateTime... dateTimes) {
|
||||
int first;
|
||||
for (first = 0; first < dateTimes.length; first++) {
|
||||
if (dateTimes[first] != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (first >= dateTimes.length - 1) {
|
||||
return true;
|
||||
}
|
||||
LocalDateTime last = dateTimes[first];
|
||||
LocalDateTime current;
|
||||
for (int i = first + 1; i < dateTimes.length; i++) {
|
||||
if (dateTimes[i] == null) {
|
||||
continue;
|
||||
}
|
||||
current = dateTimes[i];
|
||||
if (last.isAfter(current)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -29,5 +29,6 @@ server:
|
|||
charset: UTF-8
|
||||
force: true
|
||||
enabled: true
|
||||
forward-headers-strategy: framework
|
||||
springdoc:
|
||||
packages-to-scan: cn.edu.hfut.rmdjzz.projectmanagement
|
||||
packages-to-scan: cn.edu.hfut.rmdjzz.projectmanagement
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.edu.hfut.rmdjzz.projectmanagement.mapper.AnnouncementMapper">
|
||||
<resultMap id="announcementDto" type="cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.AnnouncementDto">
|
||||
<id property="announcementId" column="announcement_id"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAnnouncementList" resultMap="announcementDto">
|
||||
SELECT announcement_id,
|
||||
announcement_publisher_id,
|
||||
s.staff_fullname AS announcement_publisher_name,
|
||||
announcement_publish_time,
|
||||
announcement_title
|
||||
FROM announcement
|
||||
JOIN (SELECT staff_id, staff_fullname FROM staff) s
|
||||
ON staff_id = announcement.announcement_publisher_id
|
||||
WHERE is_deleted = 0
|
||||
AND project_id = #{projectId}
|
||||
ORDER BY announcement_id DESC;
|
||||
</select>
|
||||
<select id="selectAnnouncementById" resultMap="announcementDto">
|
||||
SELECT announcement_id,
|
||||
announcement_publisher_id,
|
||||
s.staff_fullname AS announcement_publisher_name,
|
||||
announcement_publish_time,
|
||||
announcement_title,
|
||||
announcement_content
|
||||
FROM announcement
|
||||
JOIN (SELECT staff_id, staff_fullname FROM staff) s
|
||||
ON staff_id = announcement.announcement_publisher_id
|
||||
WHERE is_deleted = 0
|
||||
AND announcement_id = #{announcementId};
|
||||
</select>
|
||||
</mapper>
|
|
@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
|
@ -21,6 +22,6 @@ public class SerializeTests {
|
|||
@SneakyThrows
|
||||
@Test
|
||||
public void serializeTime() {
|
||||
System.out.println(objectMapper.readValue("1656523481", LocalDate.class));
|
||||
System.out.println(objectMapper.readValue("1657166400", LocalDateTime.class));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TimeUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
* @since 2022/7/7 14:36
|
||||
*/
|
||||
public class UtilTests {
|
||||
@Test
|
||||
public void timeTest() {
|
||||
LocalDateTime a = LocalDateTime.now();
|
||||
LocalDateTime b = LocalDateTime.now().minusDays(1);
|
||||
LocalDateTime c = LocalDateTime.now();
|
||||
LocalDate d = LocalDate.now();
|
||||
LocalTime t = LocalTime.now();
|
||||
System.out.println(TimeUtils.validateDateTimeLine(a, b, c));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue