服务管理
This commit is contained in:
parent
c82f7d8013
commit
2a86c8b33f
@ -0,0 +1,44 @@
|
||||
package com.sunyard.chsm.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sunyard.chsm.model.entity.CryptoServiceDeviceGroup;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
* @since 2024/11/1
|
||||
*/
|
||||
@Mapper
|
||||
public interface CryptoServiceDeviceGroupMapper extends BaseMapper<CryptoServiceDeviceGroup> {
|
||||
|
||||
|
||||
default CryptoServiceDeviceGroup selectByServiceId(Long id) {
|
||||
Assert.notNull(id, "id不能为空");
|
||||
List<CryptoServiceDeviceGroup> list = selectList(new LambdaQueryWrapper<CryptoServiceDeviceGroup>().eq(CryptoServiceDeviceGroup::getServiceId, id));
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
return list.iterator().next();
|
||||
}
|
||||
|
||||
default List<CryptoServiceDeviceGroup> selectByServiceIds(List<Long> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return selectList(new LambdaQueryWrapper<CryptoServiceDeviceGroup>().
|
||||
in(CryptoServiceDeviceGroup::getServiceId, ids));
|
||||
}
|
||||
|
||||
default void deleteByServiceId(Long id) {
|
||||
Assert.notNull(id, "id不能为空");
|
||||
delete(new LambdaQueryWrapper<CryptoServiceDeviceGroup>().eq(CryptoServiceDeviceGroup::getServiceId, id));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.sunyard.chsm.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
* @since 2024/11/1
|
||||
*/
|
||||
@Data
|
||||
@TableName("sp_crypto_service_device_group")
|
||||
public class CryptoServiceDeviceGroup {
|
||||
|
||||
private Long id;
|
||||
private Long serviceId;
|
||||
private Long deviceGroupId;
|
||||
private String deviceGroupName;
|
||||
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
}
|
@ -79,7 +79,7 @@ public class KeyInfoAsymController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/createCsr")
|
||||
public R<KeyInfoDTO.CreateCSRResp> createCsr(KeyInfoDTO.CreateCsr createCsr) {
|
||||
public R<KeyInfoDTO.CreateCSRResp> createCsr(@Valid @RequestBody KeyInfoDTO.CreateCsr createCsr) {
|
||||
|
||||
String csr = keyInfoService.createCsr(createCsr);
|
||||
|
||||
|
@ -8,10 +8,12 @@ import com.sunyard.chsm.dto.CryptoServiceDTO;
|
||||
import com.sunyard.chsm.enums.ApiFunEnum;
|
||||
import com.sunyard.chsm.enums.EnableStatus;
|
||||
import com.sunyard.chsm.mapper.CryptoServiceApiMapper;
|
||||
import com.sunyard.chsm.mapper.CryptoServiceDeviceGroupMapper;
|
||||
import com.sunyard.chsm.mapper.CryptoServiceMapper;
|
||||
import com.sunyard.chsm.mapper.SpDeviceGroupMapper;
|
||||
import com.sunyard.chsm.model.entity.CryptoService;
|
||||
import com.sunyard.chsm.model.entity.CryptoServiceApi;
|
||||
import com.sunyard.chsm.model.entity.CryptoServiceDeviceGroup;
|
||||
import com.sunyard.chsm.model.entity.DeviceGroup;
|
||||
import com.sunyard.chsm.service.CryptoServiceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -47,6 +49,8 @@ public class CryptoServiceServiceImpl implements CryptoServiceService {
|
||||
@Resource
|
||||
private CryptoServiceApiMapper cryptoServiceApiMapper;
|
||||
@Resource
|
||||
private CryptoServiceDeviceGroupMapper cryptoServiceDeviceGroupMapper;
|
||||
@Resource
|
||||
private SpDeviceGroupMapper spDeviceGroupMapper;
|
||||
|
||||
@Override
|
||||
@ -64,8 +68,12 @@ public class CryptoServiceServiceImpl implements CryptoServiceService {
|
||||
return new Page<>(servicePage.getCurrent(), servicePage.getSize(), servicePage.getTotal());
|
||||
}
|
||||
|
||||
// service api
|
||||
List<Long> ids = records.stream().map(CryptoService::getId).collect(Collectors.toList());
|
||||
|
||||
List<CryptoServiceDeviceGroup> dgs = cryptoServiceDeviceGroupMapper.selectByServiceIds(ids);
|
||||
Map<Long, List<CryptoServiceDeviceGroup>> serviceDgMap = dgs.stream().collect(Collectors.groupingBy(CryptoServiceDeviceGroup::getServiceId));
|
||||
|
||||
// service ap
|
||||
LambdaQueryWrapper<CryptoServiceApi> apiQuery = new LambdaQueryWrapper<CryptoServiceApi>()
|
||||
.in(CryptoServiceApi::getCryptoServiceId, ids);
|
||||
List<CryptoServiceApi> allServiceApis = cryptoServiceApiMapper.selectList(apiQuery);
|
||||
@ -73,7 +81,6 @@ public class CryptoServiceServiceImpl implements CryptoServiceService {
|
||||
Map<Long, List<CryptoServiceApi>> serviceApiMap = allServiceApis.stream()
|
||||
.collect(Collectors.groupingBy(CryptoServiceApi::getCryptoServiceId));
|
||||
|
||||
|
||||
List<CryptoServiceDTO.CSView> viewList = records.stream()
|
||||
.map(it -> {
|
||||
CryptoServiceDTO.CSView view = new CryptoServiceDTO.CSView();
|
||||
@ -81,6 +88,13 @@ public class CryptoServiceServiceImpl implements CryptoServiceService {
|
||||
Optional.ofNullable(EnableStatus.of(it.getStatus()))
|
||||
.map(EnableStatus::getDesc)
|
||||
.ifPresent(view::setStatusDesc);
|
||||
List<CryptoServiceDeviceGroup> dgList = serviceDgMap.getOrDefault(it.getId(), Collections.emptyList());
|
||||
if (!CollectionUtils.isEmpty(dgList)) {
|
||||
CryptoServiceDeviceGroup next = dgList.iterator().next();
|
||||
view.setDeviceGroupId(next.getDeviceGroupId());
|
||||
view.setDeviceGroupName(next.getDeviceGroupName());
|
||||
}
|
||||
|
||||
List<CryptoServiceApi> serviceApis = serviceApiMap.getOrDefault(it.getId(), Collections.emptyList());
|
||||
List<String> groupCodes = serviceApis.stream().map(CryptoServiceApi::getApiGroup)
|
||||
.distinct().collect(Collectors.toList());
|
||||
@ -112,8 +126,16 @@ public class CryptoServiceServiceImpl implements CryptoServiceService {
|
||||
|
||||
DeviceGroup deviceGroup = spDeviceGroupMapper.selectById(save.getDeviceGroupId());
|
||||
Assert.notNull(deviceGroup, "设备组不存在");
|
||||
service.setDeviceGroupId(save.getDeviceGroupId());
|
||||
service.setDeviceGroupName(deviceGroup.getName());
|
||||
|
||||
CryptoServiceDeviceGroup csDg = new CryptoServiceDeviceGroup();
|
||||
csDg.setId(IdWorker.getId());
|
||||
csDg.setServiceId(service.getId());
|
||||
csDg.setDeviceGroupId(deviceGroup.getId());
|
||||
csDg.setDeviceGroupName(deviceGroup.getName());
|
||||
cryptoServiceDeviceGroupMapper.insert(csDg);
|
||||
|
||||
// service.setDeviceGroupId(save.getDeviceGroupId());
|
||||
// service.setDeviceGroupName(deviceGroup.getName());
|
||||
|
||||
service.setStatus(EnableStatus.ENABLED.getCode());
|
||||
service.setRemark(save.getRemark());
|
||||
@ -135,11 +157,21 @@ public class CryptoServiceServiceImpl implements CryptoServiceService {
|
||||
CryptoService up = new CryptoService();
|
||||
up.setId(update.getId());
|
||||
up.setName(update.getName());
|
||||
if (!Objects.equals(update.getDeviceGroupId(), exist.getDeviceGroupId())) {
|
||||
|
||||
CryptoServiceDeviceGroup existDg = cryptoServiceDeviceGroupMapper.selectByServiceId(exist.getId());
|
||||
if (existDg == null || !Objects.equals(update.getDeviceGroupId(), existDg.getDeviceGroupId())) {
|
||||
DeviceGroup deviceGroup = spDeviceGroupMapper.selectById(update.getDeviceGroupId());
|
||||
Assert.notNull(deviceGroup, "设备组不存在");
|
||||
up.setDeviceGroupId(update.getDeviceGroupId());
|
||||
up.setDeviceGroupName(deviceGroup.getName());
|
||||
|
||||
cryptoServiceDeviceGroupMapper.deleteByServiceId(exist.getId());
|
||||
CryptoServiceDeviceGroup csDg = new CryptoServiceDeviceGroup();
|
||||
csDg.setId(IdWorker.getId());
|
||||
csDg.setServiceId(exist.getId());
|
||||
csDg.setDeviceGroupId(deviceGroup.getId());
|
||||
csDg.setDeviceGroupName(deviceGroup.getName());
|
||||
cryptoServiceDeviceGroupMapper.insert(csDg);
|
||||
// up.setDeviceGroupId(update.getDeviceGroupId());
|
||||
// up.setDeviceGroupName(deviceGroup.getName());
|
||||
}
|
||||
|
||||
up.setRemark(update.getRemark());
|
||||
@ -193,6 +225,7 @@ public class CryptoServiceServiceImpl implements CryptoServiceService {
|
||||
LambdaQueryWrapper<CryptoServiceApi> wrapper = new LambdaQueryWrapper<CryptoServiceApi>()
|
||||
.eq(CryptoServiceApi::getCryptoServiceId, id);
|
||||
cryptoServiceApiMapper.delete(wrapper);
|
||||
cryptoServiceDeviceGroupMapper.deleteByServiceId(id);
|
||||
cryptoServiceMapper.deleteById(id);
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,8 @@ CREATE TABLE sp_device_group (
|
||||
CREATE TABLE sp_crypto_service (
|
||||
id BIGINT NOT NULL COMMENT 'id',
|
||||
name VARCHAR(255) NOT NULL DEFAULT '' COMMENT '服务名称',
|
||||
device_group_id BIGINT NOT NULL DEFAULT 0 COMMENT '设备组id',
|
||||
device_group_name VARCHAR(255) NOT NULL DEFAULT '' COMMENT '设备组名称',
|
||||
-- device_group_id BIGINT NOT NULL DEFAULT 0 COMMENT '设备组id',
|
||||
-- device_group_name VARCHAR(255) NOT NULL DEFAULT '' COMMENT '设备组名称',
|
||||
status VARCHAR(50) NOT NULL DEFAULT '' COMMENT '状态',
|
||||
creator_id BIGINT COMMENT '创建者id',
|
||||
remark VARCHAR(500) NOT NULL DEFAULT '' COMMENT '备注',
|
||||
@ -44,6 +44,18 @@ CREATE TABLE sp_crypto_service (
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
-- 密码服务设备组
|
||||
CREATE TABLE sp_crypto_service_device_group (
|
||||
id BIGINT NOT NULL COMMENT 'id',
|
||||
service_id BIGINT NOT NULL COMMENT '密码服务id',
|
||||
device_group_id BIGINT NOT NULL DEFAULT 0 COMMENT '设备组id',
|
||||
device_group_name VARCHAR(255) NOT NULL DEFAULT '' COMMENT '设备组名称',
|
||||
remark VARCHAR(500) NOT NULL DEFAULT '' COMMENT '备注',
|
||||
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
-- 密码服务api
|
||||
CREATE TABLE sp_crypto_service_api (
|
||||
id BIGINT NOT NULL COMMENT 'id',
|
||||
@ -61,7 +73,6 @@ CREATE TABLE sp_crypto_service_api (
|
||||
CREATE TABLE sp_application (
|
||||
id BIGINT NOT NULL COMMENT 'id',
|
||||
name VARCHAR(255) NOT NULL DEFAULT '' COMMENT '应用名称',
|
||||
bind_service VARCHAR(1020) NOT NULL DEFAULT '' COMMENT '密码服务 ,分隔',
|
||||
app_key VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'app_key',
|
||||
app_secret VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'app_secret',
|
||||
status VARCHAR(50) NOT NULL DEFAULT '' COMMENT '状态',
|
||||
@ -72,6 +83,17 @@ CREATE TABLE sp_application (
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
-- 业务应用绑定的服务
|
||||
CREATE TABLE sp_app_service (
|
||||
id BIGINT NOT NULL COMMENT 'id',
|
||||
application_id BIGINT NOT NULL COMMENT '应用id',
|
||||
service_id BIGINT NOT NULL COMMENT '服务id',
|
||||
remark VARCHAR(500) NOT NULL DEFAULT '' COMMENT '备注',
|
||||
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
-- 密钥模版
|
||||
CREATE TABLE sp_key_template (
|
||||
id BIGINT NOT NULL COMMENT 'id',
|
||||
@ -139,7 +161,7 @@ CREATE TABLE sp_key_csr (
|
||||
application_id BIGINT NOT NULL COMMENT '应用id',
|
||||
key_id BIGINT NOT NULL COMMENT '密钥id',
|
||||
key_record_id BIGINT NOT NULL COMMENT '密钥记录id',
|
||||
subject VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'DN',
|
||||
subject VARCHAR(1020) NOT NULL DEFAULT '' COMMENT 'DN',
|
||||
key_data VARCHAR(255) NOT NULL DEFAULT '' COMMENT '密钥密文',
|
||||
pub_key VARCHAR(400) NOT NULL DEFAULT '' COMMENT '公钥',
|
||||
csr_txt VARCHAR(2000) COMMENT '证书',
|
||||
|
Loading…
Reference in New Issue
Block a user