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