Compare commits
No commits in common. "9d4c54eb061c6ce63aa9ab6b8964c87201065d8f" and "f9ab646e23a449bf2b1d27a5f0c30cb965332530" have entirely different histories.
9d4c54eb06
...
f9ab646e23
|
@ -6,7 +6,6 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -37,11 +36,4 @@ public class RedisConfig {
|
|||
return template;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StringRedisTemplate stringRedisTemplate() {
|
||||
StringRedisTemplate template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(factory);
|
||||
return template;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.config;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.IPAddress;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -27,32 +25,11 @@ public class SerializeConfig {
|
|||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
om.registerModule(javaTimeModule());
|
||||
om.registerModule(customClassModule());
|
||||
return om;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"Convert2Diamond", "NullableProblems", "rawtypes"})
|
||||
@Bean
|
||||
public Converter<String, Map> mapConverter() {
|
||||
return new Converter<String, Map>() {
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public Map convert(String source) {
|
||||
return objectMapper.readValue(source, Map.class);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private JavaTimeModule javaTimeModule() {
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
|
||||
//LocalDateTime
|
||||
//LocalDataTime
|
||||
javaTimeModule.addSerializer(LocalDateTime.class, new JsonSerializer<>() {
|
||||
@Override
|
||||
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
|
@ -100,27 +77,24 @@ public class SerializeConfig {
|
|||
}
|
||||
});
|
||||
|
||||
return javaTimeModule;
|
||||
om.registerModule(javaTimeModule);
|
||||
return om;
|
||||
}
|
||||
|
||||
//TODO: Redis可能改成tostringSerializer
|
||||
private SimpleModule customClassModule() {
|
||||
SimpleModule customClassModule = new SimpleModule("CustomClassModule");
|
||||
customClassModule.addSerializer(IPAddress.class, new JsonSerializer<>() {
|
||||
@SuppressWarnings({"Convert2Diamond", "NullableProblems", "rawtypes"})
|
||||
@Bean
|
||||
public Converter<String, Map> mapConverter() {
|
||||
return new Converter<String, Map>() {
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void serialize(IPAddress value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
if (value != null) {
|
||||
gen.writeString(value.toString());
|
||||
public Map convert(String source) {
|
||||
return objectMapper.readValue(source, Map.class);
|
||||
}
|
||||
}
|
||||
});
|
||||
customClassModule.addDeserializer(IPAddress.class, new JsonDeserializer<>() {
|
||||
@Override
|
||||
public IPAddress deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
return IPAddress.of(Long.decode(p.getValueAsString()));
|
||||
}
|
||||
});
|
||||
return customClassModule;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ public class WebConfig implements WebMvcConfigurer {
|
|||
.excludePathPatterns("/hello", "/error") //测试
|
||||
.excludePathPatterns("/staff/login") //登录
|
||||
.excludePathPatterns("/swagger-ui.html", "/swagger-resources/**", "/swagger-ui/**",
|
||||
"/v2/**", "/v3/**", "/webjars/**", "/doc.html") //swagger
|
||||
.excludePathPatterns("/favicon.ico", "/public/**"); //静态资源
|
||||
"/v2/**", "/v3/**", "/webjars/**", "/doc.html"); //swagger
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ public class AnnouncementController {
|
|||
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
||||
throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
|
||||
}
|
||||
return ResponseMap.ofSuccess(announcementService.getAnnouncementById(projectId, announcementId));
|
||||
return ResponseMap.ofSuccess(announcementService.getAnnouncementById(announcementId));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
|
|
|
@ -2,6 +2,7 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
|||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.ForbiddenException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.FileUtils;
|
||||
|
@ -11,12 +12,12 @@ import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
|
|||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@ -71,8 +72,7 @@ public class StaffController {
|
|||
return ResponseMap.ofSuccess("成功导入" + successCount + "条数据");
|
||||
}
|
||||
|
||||
//取消功能
|
||||
/*@SneakyThrows
|
||||
@SneakyThrows
|
||||
@GetMapping("/import/template")
|
||||
public void downloadTemplate(
|
||||
@RequestHeader(TokenUtils.HEADER_TOKEN) String token,
|
||||
|
@ -81,18 +81,9 @@ public class StaffController {
|
|||
if (TokenUtils.getStaffGlobalLevel(token) > 2) {
|
||||
throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
|
||||
}
|
||||
if (FileUtils.downloadResource("static/public/账户导入模板.xlsx", response)) {
|
||||
if (FileUtils.downloadResource("static/账户导入模板.xlsx", response)) {
|
||||
return;
|
||||
}
|
||||
throw new BadRequestException(BadRequestException.OPERATE_FAILED);
|
||||
}*/
|
||||
|
||||
@SneakyThrows
|
||||
@GetMapping("/import/template")
|
||||
@ResponseStatus(HttpStatus.SEE_OTHER)
|
||||
public ResponseMap downloadTemplate() {
|
||||
return ResponseMap.of(HttpStatus.SEE_OTHER.value(),
|
||||
HttpStatus.SEE_OTHER.getReasonPhrase())
|
||||
.put("URI","/public/账户导入模板.xlsx");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ public class AnnouncementDTO {
|
|||
private Long announcementId;
|
||||
private Integer announcementPublisherId;
|
||||
private String announcementPublisherName;
|
||||
private Integer announcementPublisherAccessLevel;
|
||||
private LocalDateTime announcementPublishTime;
|
||||
private String announcementTitle;
|
||||
private String announcementContent;
|
||||
|
|
|
@ -7,8 +7,6 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author 张韬
|
||||
|
@ -23,14 +21,6 @@ public class CorsInterceptor implements HandlerInterceptor {
|
|||
response.setHeader("Access-Control-Allow-Methods", "*");
|
||||
response.setHeader("Access-Control-Allow-Headers", "Content-Type,Token");
|
||||
response.setHeader("Access-Control-Allow-Credentials","false");
|
||||
|
||||
//test
|
||||
Enumeration<String> headerNames = request.getHeaderNames();
|
||||
Iterator<String> nameIter = headerNames.asIterator();
|
||||
while (nameIter.hasNext()) {
|
||||
System.out.println(nameIter.next());
|
||||
}
|
||||
|
||||
// 如果是OPTIONS则结束请求
|
||||
if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) {
|
||||
response.setStatus(HttpStatus.OK.value());
|
||||
|
|
|
@ -14,5 +14,5 @@ import java.util.List;
|
|||
public interface AnnouncementMapper extends BaseMapper<Announcement> {
|
||||
List<AnnouncementDTO> selectAnnouncementList(@Param("projectId") Integer projectId);
|
||||
|
||||
AnnouncementDTO selectAnnouncementById(@Param("projectId") Integer projectId, @Param("announcementId") Long announcementId);
|
||||
AnnouncementDTO selectAnnouncementById(@Param("announcementId") Long announcementId);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public interface IAnnouncementService extends IService<Announcement> {
|
|||
|
||||
List<AnnouncementDTO> getAnnouncementList(Integer projectId);
|
||||
|
||||
AnnouncementDTO getAnnouncementById(Integer projectId, Long announcementId);
|
||||
AnnouncementDTO getAnnouncementById(Long announcementId);
|
||||
|
||||
Boolean updateAnnouncement(String token, Integer projectId, Announcement announcement) throws ForbiddenException, BadRequestException;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
|
|||
|
||||
Boolean removeMember(String token, Integer projectId, Integer targetId) throws ForbiddenException, BadRequestException;
|
||||
|
||||
Boolean updateStaffPositions(String token, Integer projectId, Integer targetId, String positions) throws ForbiddenException, BadRequestException;
|
||||
Boolean updateStaffPositions(String token, Integer projectId, Integer targetId, String positions) throws ForbiddenException;
|
||||
|
||||
/**
|
||||
* @return 如果不存在就返回0,否则返回AccessLevel;对于全局权限为1的用户,直接返回1
|
||||
|
|
|
@ -31,8 +31,8 @@ public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Ann
|
|||
}
|
||||
|
||||
@Override
|
||||
public AnnouncementDTO getAnnouncementById(Integer projectId, Long announcementId) {
|
||||
return baseMapper.selectAnnouncementById(projectId, announcementId);
|
||||
public AnnouncementDTO getAnnouncementById(Long announcementId) {
|
||||
return baseMapper.selectAnnouncementById(announcementId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,7 +64,8 @@ public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Ann
|
|||
throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
|
||||
}
|
||||
Announcement rawAnnouncement = baseMapper.selectOne(Wrappers.<Announcement>lambdaQuery()
|
||||
.select(Announcement::getProjectId, Announcement::getAnnouncementPublisherId)
|
||||
.select(Announcement::getProjectId)
|
||||
.select(Announcement::getAnnouncementPublisherId)
|
||||
.eq(Announcement::getAnnouncementId, announcementId)
|
||||
);
|
||||
if (!Objects.equals(projectId, rawAnnouncement.getProjectId())) {
|
||||
|
|
|
@ -44,9 +44,6 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
|
|||
|
||||
@Override
|
||||
public Boolean insertNewMember(String token, Integer projectId, String targetUsername, String positions) throws ForbiddenException, BadRequestException {
|
||||
if (targetUsername.equals("root")) {
|
||||
throw new BadRequestException(IStaffService.STAFF_DOES_NOT_EXIST);
|
||||
}
|
||||
int accessLevel = getProjectAccessLevel(token, projectId);
|
||||
int targetLevel = 3;
|
||||
|
||||
|
@ -54,9 +51,6 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
|
|||
if (targetStaff == null) {
|
||||
throw new BadRequestException(IStaffService.STAFF_DOES_NOT_EXIST);
|
||||
}
|
||||
if (getProjectAccessLevelIgnoreGlobalLevel(targetStaff.getStaffId(), projectId) != 0) {
|
||||
throw new BadRequestException("该成员已经在本项目中");
|
||||
}
|
||||
|
||||
if (accessLevel == 0) {
|
||||
throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
|
||||
|
@ -97,12 +91,9 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateStaffPositions(String token, Integer projectId, Integer targetId, String positions) throws ForbiddenException, BadRequestException {
|
||||
public Boolean updateStaffPositions(String token, Integer projectId, Integer targetId, String positions) throws ForbiddenException {
|
||||
int accessLevel = getProjectAccessLevel(token, projectId);
|
||||
int originTargetLevel = getProjectAccessLevelIgnoreGlobalLevel(targetId, projectId);
|
||||
if (originTargetLevel == 0) {
|
||||
throw new BadRequestException("该项目中不存在该成员");
|
||||
}
|
||||
int targetLevel = 3;
|
||||
|
||||
if (accessLevel == 0) {
|
||||
|
|
|
@ -9,7 +9,6 @@ import cn.edu.hfut.rmdjzz.projectmanagement.utils.BeanUtils;
|
|||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.MapBuilder;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TimeUtils;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.IPAddress;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -46,35 +45,34 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
|||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public Map<String, Object> login(String requestIpAddress, String staffUsername, String password) throws BadRequestException, ForbiddenException {
|
||||
String requestIpAddressHex = IPAddress.of(requestIpAddress).toString();
|
||||
if (Boolean.FALSE.equals(redisTemplate.hasKey(requestIpAddressHex))) {
|
||||
redisTemplate.opsForValue().set(requestIpAddressHex, 0, LOGIN_TRY_COUNT_TIMEOUT, TimeUnit.MINUTES);
|
||||
if (Boolean.FALSE.equals(redisTemplate.hasKey(requestIpAddress))) {
|
||||
redisTemplate.opsForValue().set(requestIpAddress, 0, LOGIN_TRY_COUNT_TIMEOUT, TimeUnit.MINUTES);
|
||||
}
|
||||
int loginCount = (int) redisTemplate.opsForValue().get(requestIpAddressHex);
|
||||
int loginCount = (int) redisTemplate.opsForValue().get(requestIpAddress);
|
||||
|
||||
if (loginCount >= LOGIN_MAX_TRY_COUNT) {
|
||||
throw new ForbiddenException(String.format("还需要等待%s才能登录"
|
||||
, TimeUtils.secondsFormat(redisTemplate.getExpire(requestIpAddressHex))));
|
||||
, TimeUtils.secondsFormat(redisTemplate.getExpire(requestIpAddress))));
|
||||
}
|
||||
|
||||
if (staffUsername == null || staffUsername.strip().length() == 0)
|
||||
//throw new BadRequestException("用户名为空");
|
||||
throw loginException(requestIpAddressHex, loginCount);
|
||||
throwLoginException(requestIpAddress, loginCount);
|
||||
if (!staffUsername.equals(staffUsername.replaceAll("[^a-zA-Z0-9]", "")))
|
||||
//throw new BadRequestException("用户名格式错误");
|
||||
throw loginException(requestIpAddressHex, loginCount);
|
||||
throwLoginException(requestIpAddress, loginCount);
|
||||
if (password == null || password.trim().length() != 32)
|
||||
//throw new BadRequestException("密码格式错误");
|
||||
throw loginException(requestIpAddressHex, loginCount);
|
||||
throwLoginException(requestIpAddress, loginCount);
|
||||
|
||||
Staff staff = getOne(Wrappers.<Staff>lambdaQuery().eq(Staff::getStaffUsername, staffUsername));
|
||||
if (staff == null)
|
||||
//throw new BadRequestException(STAFF_DOES_NOT_EXIST);
|
||||
throw loginException(requestIpAddressHex, loginCount);
|
||||
throwLoginException(requestIpAddress, loginCount);
|
||||
|
||||
password = DigestUtils.md5DigestAsHex((password + staff.getStaffSalt()).getBytes());
|
||||
if (!staff.getStaffPassword().equals(password)) {
|
||||
throw loginException(requestIpAddressHex, loginCount);
|
||||
throwLoginException(requestIpAddress, loginCount);
|
||||
}
|
||||
String token = TokenUtils.getToken(staff.getStaffUsername(), staff.getStaffId(), staff.getStaffGlobalLevel(), tokenDuration);
|
||||
redisTemplate.opsForValue().set(
|
||||
|
@ -82,16 +80,15 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
|||
token,
|
||||
Objects.requireNonNull(TokenUtils.getDuration(token)), TimeUnit.SECONDS
|
||||
);
|
||||
redisTemplate.delete(requestIpAddressHex);
|
||||
return new MapBuilder()
|
||||
.put(TokenUtils.HEADER_TOKEN, token)
|
||||
.putAll(BeanUtils.beanToMap(staff, false))
|
||||
.build();
|
||||
}
|
||||
|
||||
private BadRequestException loginException(String requestIpAddress, int loginCount) {
|
||||
private void throwLoginException(String requestIpAddress, int loginCount) throws BadRequestException {
|
||||
redisTemplate.opsForValue().set(requestIpAddress, ++loginCount, LOGIN_TRY_COUNT_TIMEOUT, TimeUnit.MINUTES);
|
||||
return new BadRequestException(String.format("登录失败,%d分钟内还有%d次登录机会", LOGIN_TRY_COUNT_TIMEOUT, LOGIN_MAX_TRY_COUNT - loginCount));
|
||||
throw new BadRequestException(String.format("登录失败,%d分钟内还有%d次登录机会", LOGIN_TRY_COUNT_TIMEOUT, LOGIN_MAX_TRY_COUNT - loginCount));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.utils.http;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
* @since 2022/7/12 17:12
|
||||
*/
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class IPAddress {
|
||||
private long ipHex;
|
||||
|
||||
public static IPAddress of(String ip) {
|
||||
long ipHex = 0;
|
||||
String[] split = ip.split("\\.");
|
||||
for (String s : split) {
|
||||
ipHex = (ipHex << 8) + Integer.parseInt(s);
|
||||
}
|
||||
return new IPAddress(ipHex);
|
||||
}
|
||||
|
||||
public String getIpString() {
|
||||
List<String> ipSectionList = new LinkedList<>();
|
||||
long tempHex = ipHex;
|
||||
int section;
|
||||
while (tempHex > 0) {
|
||||
section = (int) (tempHex & 0xFF);
|
||||
ipSectionList.add(String.valueOf(section));
|
||||
tempHex >>= 8;
|
||||
}
|
||||
Collections.reverse(ipSectionList);
|
||||
return String.join(".", ipSectionList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "#" + Long.toHexString(ipHex);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
announcement_publish_time,
|
||||
announcement_title
|
||||
FROM announcement
|
||||
JOIN (SELECT staff_id, staff_fullname FROM staff) AS s
|
||||
JOIN (SELECT staff_id, staff_fullname FROM staff) s
|
||||
ON staff_id = announcement.announcement_publisher_id
|
||||
WHERE is_deleted = 0
|
||||
AND project_id = #{projectId}
|
||||
|
@ -22,17 +22,12 @@
|
|||
SELECT announcement_id,
|
||||
announcement_publisher_id,
|
||||
s.staff_fullname AS announcement_publisher_name,
|
||||
IFNULL(pg.project_access_level, 1) AS announcement_publisher_access_level,
|
||||
announcement_publish_time,
|
||||
announcement_title,
|
||||
announcement_content
|
||||
FROM announcement
|
||||
JOIN (SELECT staff_id, staff_fullname FROM staff) AS s
|
||||
ON s.staff_id = announcement.announcement_publisher_id
|
||||
LEFT JOIN (SELECT staff_id, project_access_level
|
||||
FROM project_group
|
||||
WHERE project_id = #{projectId}) AS pg
|
||||
ON pg.staff_id = announcement_publisher_id
|
||||
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>
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.IPAddress;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
@ -17,21 +15,14 @@ import java.time.LocalDateTime;
|
|||
public class RedisTests {
|
||||
@Autowired
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
System.out.println(redisTemplate.opsForValue().get(0x15A2));
|
||||
System.out.println(redisTemplate.opsForValue().get("l1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValue() {
|
||||
redisTemplate.opsForValue().set("time", LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringTest() {
|
||||
stringRedisTemplate.opsForValue().set(IPAddress.of("192.168.0.1").toString(),String.valueOf(2));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.IPAddress;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
|
@ -24,13 +24,4 @@ public class SerializeTests {
|
|||
public void serializeTime() {
|
||||
System.out.println(objectMapper.readValue("1657166400", LocalDateTime.class));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void serializeIPTest() {
|
||||
IPAddress ip = IPAddress.of("192.108.1.1");
|
||||
System.out.println(objectMapper.writeValueAsString(ip));
|
||||
System.out.println(ip.getIpString());
|
||||
System.out.println(objectMapper.readValue("0xc06c0101",IPAddress.class));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue