密钥值查找测试
This commit is contained in:
parent
5ce75ed4ce
commit
385a2a6ecc
@ -0,0 +1,14 @@
|
|||||||
|
package com.sunyard.chsm.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.sunyard.chsm.model.entity.KeyInfo;
|
||||||
|
import com.sunyard.chsm.model.entity.KeyRecord;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liulu
|
||||||
|
* @since 2024/10/22
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface KeyRecordMapper extends BaseMapper<KeyRecord> {
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.sunyard.chsm.service;
|
||||||
|
|
||||||
|
import com.sunyard.chsm.model.entity.KeyRecord;
|
||||||
|
|
||||||
|
public interface KeyRecordService {
|
||||||
|
KeyRecord selectById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 keyId 查找密钥
|
||||||
|
* @param keyId keyId
|
||||||
|
* @return 可用值或 null
|
||||||
|
*/
|
||||||
|
KeyRecord selectByKeyId(Long keyId);
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.sunyard.chsm.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.sunyard.chsm.mapper.KeyRecordMapper;
|
||||||
|
import com.sunyard.chsm.model.entity.KeyRecord;
|
||||||
|
import com.sunyard.chsm.service.KeyRecordService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Cheney
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class KeyRecordServiceImpl implements KeyRecordService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeyRecordMapper keyRecordMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyRecord selectById(Long id) {
|
||||||
|
return keyRecordMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyRecord selectByKeyId(Long keyId) {
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
LambdaQueryWrapper<KeyRecord> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
// 添加 keyId 的条件
|
||||||
|
queryWrapper.eq(KeyRecord::getKeyId, keyId);
|
||||||
|
// 添加 effectiveTime 小于当前时间的条件
|
||||||
|
queryWrapper.lt(KeyRecord::getEffectiveTime, now);
|
||||||
|
// 添加 expiredTime 大于当前时间的条件
|
||||||
|
queryWrapper.gt(KeyRecord::getExpiredTime, now);
|
||||||
|
|
||||||
|
return keyRecordMapper.selectOne(queryWrapper);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.sunyard.chsm.service;
|
||||||
|
|
||||||
|
import com.sunyard.chsm.WebServerApp;
|
||||||
|
import com.sunyard.chsm.model.dto.KeyInfoDTO;
|
||||||
|
import com.sunyard.chsm.model.entity.KeyRecord;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@SpringBootTest(classes = WebServerApp.class)
|
||||||
|
public class SYMEncryptControllerTest {
|
||||||
|
|
||||||
|
private static final long TEST_APP_ID = 1852232967292882946L;
|
||||||
|
private static final long TEST_KEY_ID = 1852232967292882945L;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private KeyRecordService keyRecordService;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSelectKey() {
|
||||||
|
KeyRecord key = keyRecordService.selectByKeyId(TEST_KEY_ID);
|
||||||
|
System.out.println(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user