删除秘钥时候清空配置.
This commit is contained in:
@@ -132,6 +132,10 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
||||
@Override
|
||||
public Integer delete${type}ById(Long id) {
|
||||
log.info("${type}Service-delete${type}ById id: {}", id);
|
||||
// 检查数据是否存在
|
||||
${type}DO record = ${typeLower}DAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 删除
|
||||
int effect = ${typeLower}DAO.deleteById(id);
|
||||
log.info("${type}Service-delete${type}ById effect: {}", effect);
|
||||
return effect;
|
||||
|
||||
@@ -123,6 +123,9 @@ public class ${type}ApiImpl implements ${type}Api {
|
||||
public Integer delete${type}ById(Long id) {
|
||||
log.info("${type}Api.delete${type}ById id: {}", id);
|
||||
Valid.notNull(id, ErrorMessage.ID_MISSING);
|
||||
// 检查数据是否存在
|
||||
${type}DO record = ${typeLower}DAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 删除
|
||||
int effect = ${typeLower}DAO.deleteById(id);
|
||||
log.info("${type}Api.delete${type}ById effect: {}", effect);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.ops.module.asset.entity.domain.HostConfigDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -89,4 +90,20 @@ public interface HostConfigDAO extends IMapper<HostConfigDO> {
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 keyId 为 NULL
|
||||
*
|
||||
* @param keyId keyId
|
||||
* @return effect
|
||||
*/
|
||||
int setKeyIdWithNull(@Param("keyId") Long keyId);
|
||||
|
||||
/**
|
||||
* 设置 identityId 为 NULL
|
||||
*
|
||||
* @param identityId identityId
|
||||
* @return effect
|
||||
*/
|
||||
int setIdentityIdWithNull(@Param("identityId") Long identityId);
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.orion.ops.framework.common.security.PasswordModifier;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.module.asset.convert.HostIdentityConvert;
|
||||
import com.orion.ops.module.asset.dao.HostConfigDAO;
|
||||
import com.orion.ops.module.asset.dao.HostIdentityDAO;
|
||||
import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
import com.orion.ops.module.asset.define.HostCacheKeyDefine;
|
||||
@@ -48,6 +49,9 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
@Resource
|
||||
private HostKeyDAO hostKeyDAO;
|
||||
|
||||
@Resource
|
||||
private HostConfigDAO hostConfigDAO;
|
||||
|
||||
@Override
|
||||
public Long createHostIdentity(HostIdentityCreateRequest request) {
|
||||
log.info("HostIdentityService-createHostIdentity request: {}", JSON.toJSONString(request));
|
||||
@@ -168,8 +172,8 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 删除数据库
|
||||
int effect = hostIdentityDAO.deleteById(id);
|
||||
// TODO config
|
||||
|
||||
// 删除主机配置
|
||||
hostConfigDAO.setIdentityIdWithNull(id);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_IDENTITY.getKey(), record.getId());
|
||||
log.info("HostIdentityService-deleteHostIdentityById effect: {}", effect);
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.orion.ops.framework.common.utils.CryptoUtils;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.module.asset.convert.HostKeyConvert;
|
||||
import com.orion.ops.module.asset.dao.HostConfigDAO;
|
||||
import com.orion.ops.module.asset.dao.HostIdentityDAO;
|
||||
import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
import com.orion.ops.module.asset.define.HostCacheKeyDefine;
|
||||
@@ -46,6 +47,9 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
@Resource
|
||||
private HostIdentityDAO hostIdentityDAO;
|
||||
|
||||
@Resource
|
||||
private HostConfigDAO hostConfigDAO;
|
||||
|
||||
@Override
|
||||
public Long createHostKey(HostKeyCreateRequest request) {
|
||||
log.info("HostKeyService-createHostKey request: {}", JSON.toJSONString(request));
|
||||
@@ -166,8 +170,8 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
int effect = hostKeyDAO.deleteById(id);
|
||||
// 删除关联
|
||||
hostIdentityDAO.setKeyWithNull(id);
|
||||
// TODO config
|
||||
|
||||
// 删除主机配置
|
||||
hostConfigDAO.setKeyIdWithNull(id);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_KEY.getKey(), record.getId());
|
||||
log.info("HostKeyService-deleteHostKeyById effect: {}", effect);
|
||||
|
||||
@@ -22,4 +22,20 @@
|
||||
id, host_id, type, status, config, version, create_time, update_time, creator, updater, deleted
|
||||
</sql>
|
||||
|
||||
<update id="setKeyIdWithNull">
|
||||
UPDATE host_config
|
||||
SET version = version + 1,
|
||||
config = JSON_REMOVE(config, '$.keyId')
|
||||
WHERE deleted = 0
|
||||
AND JSON_CONTAINS(config, JSON_OBJECT('keyId', #{keyId}))
|
||||
</update>
|
||||
|
||||
<update id="setIdentityIdWithNull">
|
||||
UPDATE host_config
|
||||
SET version = version + 1,
|
||||
config = JSON_REMOVE(config, '$.identityId')
|
||||
WHERE deleted = 0
|
||||
AND JSON_CONTAINS(config, JSON_OBJECT('identityId', #{identityId}))
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user