diff --git a/chsm-common/src/main/java/com/sunyard/chsm/enums/KeyStatus.java b/chsm-common/src/main/java/com/sunyard/chsm/enums/KeyStatus.java index 7d4d000..1c43204 100644 --- a/chsm-common/src/main/java/com/sunyard/chsm/enums/KeyStatus.java +++ b/chsm-common/src/main/java/com/sunyard/chsm/enums/KeyStatus.java @@ -14,9 +14,11 @@ import java.util.Objects; @AllArgsConstructor public enum KeyStatus { + WAIT_ENABLED("wait_enabled", "待生效"), ENABLED("enabled", "已启用"), DISABLED("disabled", "已停用"), ARCHIVED("archived", "已归档"), + EXPIRED("expired", "已过期"), DESTORY("destory", "已销毁"), ; private final String code; diff --git a/chsm-web-manage/src/main/java/com/sunyard/chsm/controller/KeyInfoAsymController.java b/chsm-web-manage/src/main/java/com/sunyard/chsm/controller/KeyInfoAsymController.java index af7d71e..277356a 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/chsm/controller/KeyInfoAsymController.java +++ b/chsm-web-manage/src/main/java/com/sunyard/chsm/controller/KeyInfoAsymController.java @@ -72,6 +72,12 @@ public class KeyInfoAsymController { .body(new ByteArrayResource(content)); } + /** + * 生成P10 + * + * @param createCsr 参数 + * @return + */ @PostMapping("/createCsr") public R createCsr(KeyInfoDTO.CreateCsr createCsr) { diff --git a/chsm-web-manage/src/main/java/com/sunyard/chsm/service/impl/KeyInfoServiceImpl.java b/chsm-web-manage/src/main/java/com/sunyard/chsm/service/impl/KeyInfoServiceImpl.java index 6b4dac9..26ad64f 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/chsm/service/impl/KeyInfoServiceImpl.java +++ b/chsm-web-manage/src/main/java/com/sunyard/chsm/service/impl/KeyInfoServiceImpl.java @@ -87,18 +87,31 @@ public class KeyInfoServiceImpl implements KeyInfoService { @Override public Page selectPageList(KeyInfoDTO.Query query) { + LocalDateTime now = LocalDateTime.now(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .eq(StringUtils.hasText(query.getKeyType()), KeyInfo::getKeyType, query.getKeyType()) + .eq(StringUtils.hasText(query.getStatus()), KeyInfo::getStatus, query.getStatus()) + .orderByDesc(KeyInfo::getCreateTime); + if (StringUtils.hasText(query.getStatus())) { + KeyStatus queryStatus = KeyStatus.of(query.getStatus()); + if (KeyStatus.WAIT_ENABLED == queryStatus) { + wrapper.gt(KeyInfo::getEffectiveTime, now); + } else if (KeyStatus.EXPIRED == queryStatus) { + wrapper.lt(KeyInfo::getExpiredTime, now); + } else { + wrapper.eq(KeyInfo::getStatus, query.getStatus()); + } + } IPage page = keyInfoMapper.selectPage( new Page<>(query.getPageNumber(), query.getPageSize()), - new LambdaQueryWrapper() - .eq(StringUtils.hasText(query.getKeyType()), KeyInfo::getKeyType, query.getKeyType()) - .eq(StringUtils.hasText(query.getStatus()), KeyInfo::getStatus, query.getStatus()) - .orderByDesc(KeyInfo::getCreateTime) + wrapper ); List records = page.getRecords(); if (CollectionUtils.isEmpty(records)) { return new Page<>(page.getCurrent(), page.getSize(), page.getTotal()); } + List viewList = records.stream() .map(it -> { KeyInfoDTO.KeyView view = new KeyInfoDTO.KeyView(); @@ -111,10 +124,16 @@ public class KeyInfoServiceImpl implements KeyInfoService { .collect(Collectors.toMap(KeyUsage::getCode, KeyUsage::getDesc)); view.setKeyUsages(new ArrayList<>(usageMap.keySet())); view.setKeyUsageText(String.join(",", usageMap.values())); - Optional.ofNullable(KeyStatus.of(it.getStatus())) - .map(KeyStatus::getDesc) - .ifPresent(view::setStatusText); - + KeyStatus keyStatus = KeyStatus.of(it.getStatus()); + if (KeyStatus.ENABLED == keyStatus) { + if (now.isBefore(it.getEffectiveTime())) { + view.setStatus(KeyStatus.WAIT_ENABLED.getCode()); + view.setStatusText(KeyStatus.WAIT_ENABLED.getDesc()); + } else if (now.isAfter(it.getExpiredTime())) { + view.setStatus(KeyStatus.EXPIRED.getCode()); + view.setStatusText(KeyStatus.EXPIRED.getDesc()); + } + } return view; }) .collect(Collectors.toList()); @@ -195,6 +214,14 @@ public class KeyInfoServiceImpl implements KeyInfoService { Assert.isTrue(CollectionUtils.isEmpty(unNormalCodes), "密钥id: " + String.join(",", unNormalCodes) + "不是启用状态或者新生效时间超过密钥过期时间, 无法更新"); + List records = spKeyRecordMapper.selectList( + new LambdaQueryWrapper() + .gt(KeyRecord::getEffectiveTime, now) + .in(KeyRecord::getKeyId, ids) + ); + String msgIds = records.stream().map(it -> String.valueOf(it.getKeyId())).collect(Collectors.joining(",")); + Assert.isTrue(CollectionUtils.isEmpty(records), "密钥id: " + msgIds + "已经存在未使用的新密钥, 无法更新"); + // 更新实际密钥值 spKeyRecordMapper.update( new LambdaUpdateWrapper() @@ -207,6 +234,7 @@ public class KeyInfoServiceImpl implements KeyInfoService { for (KeyInfo info : keyInfos) { // 具体使用的密钥值 KeyRecord record = genKeyRecord(info); + record.setEffectiveTime(newEffectTime); KeyInfo upInfo = new KeyInfo(); upInfo.setId(info.getId());