Skip to content

Commit

Permalink
删除服务器账户
Browse files Browse the repository at this point in the history
  • Loading branch information
ixrjog committed Mar 31, 2022
1 parent bd8fb9c commit 5be5d8d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ public HttpResult<Boolean> updateServerAccount(@RequestBody @Valid ServerAccount
serverAccountFacade.updateServerAccount(account);
return HttpResult.SUCCESS;
}

@ApiOperation(value = "删除指定的服务器账户")
@DeleteMapping(value = "/del", produces = MediaType.APPLICATION_JSON_VALUE)
public HttpResult<Boolean> deleteServerAccountById(@RequestParam int id) {
serverAccountFacade.deleteServerAccountById(id);
return HttpResult.SUCCESS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public interface ServerAccountFacade {
void updateServerAccount(ServerAccountVO.Account account);

void updateServerAccountPermission(ServerAccountParam.UpdateServerAccountPermission updatePermission);

void deleteServerAccountById(Integer id);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.baiyi.opscloud.facade.server.impl;

import com.baiyi.opscloud.common.exception.common.CommonRuntimeException;
import com.baiyi.opscloud.common.util.BeanCopierUtil;
import com.baiyi.opscloud.domain.DataTable;
import com.baiyi.opscloud.domain.generator.opscloud.Credential;
Expand Down Expand Up @@ -94,4 +95,12 @@ private boolean isAuthorized(List<ServerAccountPermission> permissions, Integer
return false;
}

@Override
public void deleteServerAccountById(Integer id) {
if (accountPermissionService.countByServerAccountId(id) != 0) {
throw new CommonRuntimeException("服务器账户删除错误: 账户使用中!");
}
accountService.deleteById(id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ ServerAccount getPermissionServerAccountByUsernameAndProtocol(Integer serverId,
String username,
String protocol);

void deleteById(Integer id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
@Service
@RequiredArgsConstructor
public class ServerAccountServiceImpl extends AbstractCredentialCustomer implements ServerAccountService {
public class ServerAccountServiceImpl extends AbstractCredentialCustomer implements ServerAccountService {

private final ServerAccountMapper accountMapper;

Expand Down Expand Up @@ -71,8 +71,8 @@ public List<ServerAccount> getPermissionServerAccountByTypeAndProtocol(Integer s

@Override
public ServerAccount getPermissionServerAccountByUsernameAndProtocol(Integer serverId,
String username,
String protocol) {
String username,
String protocol) {
return accountMapper.getPermissionServerAccountByUsernameAndProtocol(serverId, username, protocol);
}

Expand All @@ -84,4 +84,9 @@ public int countByCredentialId(int credentialId) {
return accountMapper.selectCountByExample(example);
}

@Override
public void deleteById(Integer id) {
accountMapper.deleteByPrimaryKey(id);
}

}

0 comments on commit 5be5d8d

Please sign in to comment.