机器管理bug修复,代码格式化

This commit is contained in:
zyj 2025-06-12 17:19:29 +08:00
parent da63f37625
commit 8189a825d3
24 changed files with 223 additions and 174 deletions

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.controller;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.commons.util.object.BeanUtils;

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.controller;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.commons.util.object.BeanUtils;
@ -13,8 +14,9 @@ import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import static cd.casic.framework.commons.pojo.CommonResult.success;
@RestController
@ -45,8 +47,8 @@ public class MachineInfoController {
@PutMapping("/updateStatus")
@Operation(summary = "机器启用/停用")
// @PreAuthorize("@ss.hasPermission('ci:machineInfo:status')")
public CommonResult<Integer> updateStatus(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
Integer newStatus = machineInfoService.updateStatus(id, status);
public CommonResult<Integer> updateStatus(@Valid @RequestBody MachineInfoVO machineInfoVO) {
Integer newStatus = machineInfoService.updateStatus(machineInfoVO);
return success(newStatus);
}
@ -60,14 +62,6 @@ public class MachineInfoController {
return success(BeanUtils.toBean(pageResult, MachineInfoVO.class));
}
@PutMapping("/bindingSecretKey")
@Operation(summary = "绑定密钥")
// @PreAuthorize("@ss.hasPermission('ci:machineInfo:binding')")
public CommonResult<Boolean> bindingSecretKey(@RequestParam("ids") List<Long> ids, @RequestParam("secretKeyId") Long secretKeyId) {
machineInfoService.bindingSecretKey(ids,secretKeyId);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "机器信息删除")
// @PreAuthorize("@ss.hasPermission('ci:machineInfo:delete')")

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.controller;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.commons.util.object.BeanUtils;
@ -13,7 +14,9 @@ import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static cd.casic.framework.commons.pojo.CommonResult.success;
/**
@ -30,7 +33,7 @@ public class MachineProxyController {
@PostMapping("/create")
@Operation(summary = "注册新的机器代理")
@PreAuthorize("@ss.hasPermission('ci:machineProxy:create')")
// @PreAuthorize("@ss.hasPermission('ci:machineProxy:create')")
public CommonResult<Long> createProxy(@Valid @RequestBody MachineProxyVO machineProxyVO) {
Long id = machineProxyService.createProxy(machineProxyVO);
return success(id);
@ -38,7 +41,7 @@ public class MachineProxyController {
@PutMapping("/update")
@Operation(summary = "修改代理")
@PreAuthorize("@ss.hasPermission('ci:machineProxy:update')")
// @PreAuthorize("@ss.hasPermission('ci:machineProxy:update')")
public CommonResult<Boolean> updateProxy(@Valid @RequestBody MachineProxyVO machineProxyVO) {
machineProxyService.updateProxy(machineProxyVO);
return success(true);
@ -60,10 +63,16 @@ public class MachineProxyController {
return success(machineProxyService.getAllProxyStatus());
}
@DeleteMapping("delete")
@Operation(summary = "删除代理")
public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
machineProxyService.delete(id);
return success(true);
}
@DeleteMapping("/deleteList")
@Operation(summary = "批量删除代理")
@PreAuthorize("@ss.hasPermission('ci:machineProxy:delete')")
// @PreAuthorize("@ss.hasPermission('ci:machineProxy:delete')")
public CommonResult<Boolean> deleteProxyList(@RequestParam String ids) {
machineProxyService.deleteProxyList(ids);
return success(true);

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.controller;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.commons.util.object.BeanUtils;
@ -13,7 +14,9 @@ import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static cd.casic.framework.commons.pojo.CommonResult.success;
@RestController
@ -43,8 +46,8 @@ public class SecretKeyController {
@PutMapping("/bindingMachine")
@Operation(summary = "绑定机器") //todo解绑机器
// @PreAuthorize("@ss.hasPermission('ci:secretKey:binding')")
public CommonResult<Boolean> bindingMachine(@RequestParam("id") Long id, @RequestParam("machineInfoIds") List<Long> machineInfoId) {
secretKeyService.bindingMachine(id, machineInfoId);
public CommonResult<Boolean> bindingMachine(@Valid @RequestBody SecretKeyVO secretKeyVO) {
secretKeyService.bindingMachine(secretKeyVO);
return success(true);
}

View File

@ -1,8 +1,10 @@
package cd.casic.module.machine.controller.vo;
import cd.casic.framework.commons.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = true)

View File

@ -40,7 +40,7 @@ public class MachineInfoVO extends PageParam {
private String username;
@Schema(description = "机器状态", example = "online,offline,maintenance")
private Integer status;
private Integer status = -1;
@Schema(description = "SSH端口", example = "22")
private Integer sshPort;

View File

@ -1,8 +1,10 @@
package cd.casic.module.machine.controller.vo;
import cd.casic.framework.commons.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 机器代理信息 Response VO")
@ -21,13 +23,13 @@ public class MachineProxyVO extends PageParam {
private String username;
@Schema(description = "代理类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "HTTP")
private Integer proxyType;
private Integer proxyType = -1;
@Schema(description = "版本号", example = "1.0.0")
private String version;
@Schema(description = "状态ONLINE:在线OFFLINE:离线)", requiredMode = Schema.RequiredMode.REQUIRED, example = "ONLINE")
private String status;
private int status = -1;
@Schema(description = "描述信息", example = "用于生产环境的代理服务器")
private String description;

View File

@ -1,8 +1,10 @@
package cd.casic.module.machine.controller.vo;
import cd.casic.framework.commons.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
import java.util.List;

View File

@ -4,6 +4,7 @@ import cd.casic.module.machine.controller.vo.MachineEnvVO;
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface MachineEnvConvert {

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.dal.mysql;
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
import cd.casic.module.machine.controller.vo.MachineEnvVO;
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
@ -14,9 +15,13 @@ import java.time.LocalDateTime;
@Mapper
public interface MachineEnvMapper extends BaseMapperX<MachineEnvDO> {
default PageResult<MachineEnvDO> selectPage(MachineEnvVO machineEnvVO) {
return selectPage(machineEnvVO,new LambdaQueryWrapperX<MachineEnvDO>()
LambdaQueryWrapperX<MachineEnvDO> machineEnvDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MachineEnvDO>()
.likeIfPresent(MachineEnvDO::getEnvKey, machineEnvVO.getEnvKey())
.likeIfPresent(MachineEnvDO::getDescription, machineEnvVO.getDescription()));
.likeIfPresent(MachineEnvDO::getDescription, machineEnvVO.getDescription());
if (machineEnvVO.getMachineId() != null && machineEnvVO.getMachineId() > 0) {
machineEnvDOLambdaQueryWrapperX.eqIfPresent(MachineEnvDO::getMachineId, machineEnvVO.getMachineId());
}
return selectPage(machineEnvVO, machineEnvDOLambdaQueryWrapperX);
}
}

View File

@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@ -20,30 +21,38 @@ public interface MachineInfoMapper extends BaseMapperX<MachineInfoDO> {
default Boolean existsByTag(String tag) {
return selectOne(new QueryWrapper<MachineInfoDO>().eq("tag", tag)) != null;
}
default void updateStatus(Long machineInfoId, Integer status) {
UpdateWrapper<MachineInfoDO> set = new UpdateWrapper<>();
set.eq("id", machineInfoId).set("status", status);
this.update(null, set);
}
default void bindingSecretKey(List<Long> machineInfoIds, Long secretKeyId) {
LambdaUpdateWrapper<MachineInfoDO> wrapper = new LambdaUpdateWrapper<MachineInfoDO>()
.set(MachineInfoDO::getSecretKeyId, secretKeyId)
.in(MachineInfoDO::getId, machineInfoIds);
UpdateWrapper<MachineInfoDO> wrapper = new UpdateWrapper<>();
wrapper.in("id", machineInfoIds) // 匹配 ID 集合
.set("secret_key_id", secretKeyId); // 设置新的 status
this.update(null, wrapper);
}
default void unBindingSecretKey(List<Long> secretKeyId) {
LambdaUpdateWrapper<MachineInfoDO> wrapper = new LambdaUpdateWrapper<MachineInfoDO>()
.set(MachineInfoDO::getSecretKeyId, null)
.in(MachineInfoDO::getSecretKeyId, secretKeyId);
this.update(null, wrapper);
}
default PageResult<MachineInfoDO> selectPage(MachineInfoVO machineInfoVO) {
return selectPage(machineInfoVO,new LambdaQueryWrapperX<MachineInfoDO>()
LambdaQueryWrapperX<MachineInfoDO> machineInfoDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MachineInfoDO>()
.likeIfPresent(MachineInfoDO::getName, machineInfoVO.getName())
.likeIfPresent(MachineInfoDO::getTag, machineInfoVO.getTag())
.likeIfPresent(MachineInfoDO::getDescription, machineInfoVO.getDescription())
.likeIfPresent(MachineInfoDO::getUsername, machineInfoVO.getUsername())
.eqIfPresent(MachineInfoDO::getHostIp, machineInfoVO.getHostIp()));
.likeIfPresent(MachineInfoDO::getHostIp, machineInfoVO.getHostIp());
if (machineInfoVO.getStatus() != -1) {
machineInfoDOLambdaQueryWrapperX.eqIfPresent(MachineInfoDO::getStatus, machineInfoVO.getStatus());
}
return selectPage(machineInfoVO, machineInfoDOLambdaQueryWrapperX);
}

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.dal.mysql;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
import cd.casic.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -12,15 +13,17 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MachineProxyMapper extends BaseMapperX<MachineProxyDO> {
default PageResult<MachineProxyDO> selectPage(MachineProxyVO machineProxyVO) {
return selectPage(machineProxyVO, new LambdaQueryWrapperX<MachineProxyDO>()
LambdaQueryWrapperX<MachineProxyDO> machineProxyDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MachineProxyDO>()
.eqIfPresent(MachineProxyDO::getHostIp, machineProxyVO.getHostIp())
.eqIfPresent(MachineProxyDO::getProxyType, machineProxyVO.getProxyType())
.eqIfPresent(MachineProxyDO::getStatus, machineProxyVO.getStatus())
.likeIfPresent(MachineProxyDO::getDescription, machineProxyVO.getDescription())
);
.likeIfPresent(MachineProxyDO::getDescription, machineProxyVO.getDescription());
if (machineProxyVO.getStatus() != -1) {
machineProxyDOLambdaQueryWrapperX.eqIfPresent(MachineProxyDO::getStatus, machineProxyVO.getStatus());
}
if (machineProxyVO.getProxyType() != -1) {
machineProxyDOLambdaQueryWrapperX.eqIfPresent(MachineProxyDO::getProxyType, machineProxyVO.getProxyType());
}
return selectPage(machineProxyVO, machineProxyDOLambdaQueryWrapperX);
}
}

View File

@ -5,18 +5,20 @@ import cd.casic.framework.commons.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
@Getter
@AllArgsConstructor
public enum MachineInfoStatus implements IntArrayValuable {
ENABLE(1, "启用"),
UN_ENABLE(0, "停用");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(MachineInfoStatus::getCode).toArray();
private final int code;
private final String message;
@Override
public int[] array() {
return new int[0];
return ARRAYS;
}
}

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.enums;
import cd.casic.framework.commons.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.MachineEnvVO;
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;

View File

@ -4,6 +4,8 @@ import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.MachineInfoVO;
import cd.casic.module.machine.dal.dataobject.MachineInfoDO;
import cd.casic.module.machine.enums.ConnectionStatus;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@ -12,11 +14,11 @@ import java.util.Map;
public interface MachineInfoService {
Long createMachine(MachineInfoVO MachineInfoVO);
PageResult<MachineInfoDO> listMachineInfo(MachineInfoVO MachineInfoVO);
PageResult<MachineInfoDO> listMachineInfo(@Valid MachineInfoVO MachineInfoVO);
void updateMachineInfo(MachineInfoVO machineInfoVO);
void updateMachineInfo(@Valid MachineInfoVO machineInfoVO);
Integer updateStatus(Long machineInfoId, Integer status);
Integer updateStatus(@Valid MachineInfoVO machineInfoVO);
void bindingSecretKey(List<Long> machineInfoIds, Long secretKeyId);

View File

@ -3,6 +3,9 @@ package cd.casic.module.machine.service;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.MachineProxyVO;
import cd.casic.module.machine.dal.dataobject.MachineProxyDO;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
@ -13,13 +16,19 @@ public interface MachineProxyService {
/**
* 注册新的机器代理
*/
Long createProxy(MachineProxyVO machineProxyVO);
Long createProxy(@Valid MachineProxyVO machineProxyVO);
/**
* 更新代理状态
*/
void updateProxy(MachineProxyVO machineProxyVO);
void updateProxy(@Valid MachineProxyVO machineProxyVO);
/**
* 删除代理
*
* @param
*/
void delete(Long id);
/**
* 获取所有代理的状态统计
@ -29,7 +38,6 @@ public interface MachineProxyService {
Map<Integer, Long> getAllProxyStatus();
/**
* 批量删除代理
*
@ -37,5 +45,5 @@ public interface MachineProxyService {
*/
void deleteProxyList(String proxyIds);
PageResult<MachineProxyDO> getProxyPage(MachineProxyVO machineProxyVO);
PageResult<MachineProxyDO> getProxyPage(@Valid MachineProxyVO machineProxyVO);
}

View File

@ -4,20 +4,18 @@ import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.dal.dataobject.SecretKeyDO;
import cd.casic.module.machine.controller.vo.SecretKeyVO;
import jakarta.validation.Valid;
import java.util.List;
public interface SecretKeyService {
Long createSecretKey(@Valid SecretKeyVO secretKeyVO) throws Exception;
void bindingMachine(Long id, List<Long> machineInfoId);
void bindingMachine(@Valid SecretKeyVO secretKeyVO);
void updateSecretKey(@Valid SecretKeyVO secretKeyVO);
PageResult<SecretKeyDO> getSecretKeypage(@Valid SecretKeyVO secretKeyVO);
void deleteSecretKeyList(List<Long> ids);
SecretKeyVO getSecretKey(Long id);

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service.impl;
import cd.casic.module.machine.controller.vo.MachineEnvVO;
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
import cd.casic.module.machine.dal.mysql.MachineEnvMapper;
@ -84,6 +85,7 @@ public class MachineEnvServiceImpl implements MachineEnvService {
}
return machineEnvDO;
}
@VisibleForTesting
void validateMachineEnvAdd(MachineEnvVO machineEnvVO) {
if (machineEnvVO.getEnvKey() == null || machineEnvVO.getEnvValue() == null) {
@ -92,7 +94,6 @@ public class MachineEnvServiceImpl implements MachineEnvService {
}
// 检查环境变量键是否合法
@VisibleForTesting
private void validateKey(String key) {

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service.impl;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.MachineProxyVO;
import cd.casic.module.machine.dal.dataobject.MachineProxyDO;
@ -13,9 +14,12 @@ import cd.casic.framework.commons.util.object.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
import static com.baomidou.mybatisplus.extension.toolkit.Db.save;
@ -33,7 +37,8 @@ public class MachineProxyServiceImpl implements MachineProxyService {
public Long createProxy(MachineProxyVO machineProxyVO) {
validateMachineProxyAdd(machineProxyVO);
// 创建代理记录
MachineProxyDO machineProxyDO = BeanUtils.toBean(machineProxyVO, MachineProxyDO.class);;
MachineProxyDO machineProxyDO = BeanUtils.toBean(machineProxyVO, MachineProxyDO.class);
;
save(machineProxyDO);
return machineProxyDO.getId();
}
@ -47,6 +52,19 @@ public class MachineProxyServiceImpl implements MachineProxyService {
machineProxyMapper.updateById(machineProxyDO);
}
@Override
public void delete(Long id) {
MachineProxyDO machineProxyDO = validateMachineProxyExists(id);
validateMachineProxyOnline(machineProxyDO);
machineProxyMapper.deleteById(id);
}
@VisibleForTesting
void validateMachineProxyOnline(MachineProxyDO machineProxyDO) {
if (machineProxyDO.getStatus() == MachineProxyStatus.ONLINE.getCode()) {
throw exception(MACHINE_PROXY_IS_ONLINE);
}
}
@Override
public Map<Integer, Long> getAllProxyStatus() {
@ -75,10 +93,8 @@ public class MachineProxyServiceImpl implements MachineProxyService {
.filter(s -> !s.isEmpty())
.map(Long::parseLong)
.toList();
//检查是否存在在线的代理
validateMachineProxyOnline(machineProxyIds);
// 批量逻辑删除
machineProxyMapper.deleteBatchIds(machineProxyIds);
machineProxyIds.forEach(this::delete);
}
@Override
@ -86,12 +102,10 @@ public class MachineProxyServiceImpl implements MachineProxyService {
return machineProxyMapper.selectPage(machineProxyVO);
}
@VisibleForTesting
MachineProxyDO validateMachineProxyExists(Long id) {
if (id == null) {
return null;
throw exception(MACHINE_PROXY_NOT_EXISTS);
}
MachineProxyDO machineProxyDO = machineProxyMapper.selectById(id);
if (machineProxyDO == null) {
@ -100,20 +114,6 @@ public class MachineProxyServiceImpl implements MachineProxyService {
return machineProxyDO;
}
@VisibleForTesting
void validateMachineProxyOnline(List<Long> ids) {
List<MachineProxyDO> machineProxyDOS = machineProxyMapper.selectBatchIds(ids);
List<Long>onlineId=new ArrayList<>();
machineProxyDOS.forEach(machineProxyDO->{
if (machineProxyDO.getStatus() == MachineProxyStatus.ONLINE.getCode()) {
onlineId.add(machineProxyDO.getId());
}
});
if(!onlineId.isEmpty()){
throw exception(MACHINE_PROXY_IS_ONLINE,onlineId);
}
}
@VisibleForTesting
void validateMachineProxyAdd(MachineProxyVO machineProxyVO) {
if (machineProxyVO.getHostIp() == null) {

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service.impl;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.SecretKeyVO;
import cd.casic.module.machine.enums.AuthenticationType;
@ -58,14 +59,15 @@ public class MachineinfoServiceImpl implements MachineInfoService {
validateMachineEnvAdd(machineInfoVO);
validateMachineTagUnique(machineInfoVO.getTag());
MachineInfoDO machineInfoDO = BeanUtils.toBean(machineInfoVO, MachineInfoDO.class);
if (machineInfoVO.getAuthenticationType() == 2) {
Long secretKeyId = machineInfoDO.getSecretKeyId();
SecretKeyVO secretKey = secretKeyService.getSecretKey(secretKeyId);
if (secretKey == null) {
throw exception(SECRET_KEY_NOT_EXISTS);
}
}
machineInfoMapper.insert(machineInfoDO);
Long id = machineInfoDO.getId();
return id;
return machineInfoDO.getId();
}
@Override
@ -82,9 +84,9 @@ public class MachineinfoServiceImpl implements MachineInfoService {
}
@Override
public Integer updateStatus(Long machineInfoId, Integer status) {
machineInfoMapper.updateStatus(machineInfoId, status);
return machineInfoMapper.selectById(machineInfoId).getStatus();
public Integer updateStatus(MachineInfoVO machineInfoVO) {
machineInfoMapper.updateStatus(machineInfoVO.getId(), machineInfoVO.getStatus());
return machineInfoVO.getStatus();
}
@Override
@ -93,8 +95,8 @@ public class MachineinfoServiceImpl implements MachineInfoService {
}
@Override
public void bindingSecretKey(List<Long> machineInfoId,Long secretKeyId) {
machineInfoMapper.bindingSecretKey(machineInfoId,secretKeyId);
public void bindingSecretKey(List<Long> machineInfoIds, Long secretKeyId) {
machineInfoMapper.bindingSecretKey(machineInfoIds, secretKeyId);
}
@Override
@ -303,10 +305,10 @@ public class MachineinfoServiceImpl implements MachineInfoService {
flag = false;
break;
}
}
if (flag) {
throw exception(MACHINE_INFO_AUTHENTICATION_TYPE_NOT_EXISTS);
}
}
} else {
throw exception(MACHINE_INFO_AUTHENTICATION_TYPE_NULL);
}
@ -335,10 +337,11 @@ public class MachineinfoServiceImpl implements MachineInfoService {
throw exception(MACHINE_INFO_TAG_EXISTS);
}
}
@VisibleForTesting
MachineInfoDO validateMachineInfoExists(Long id) {
if (id == null) {
return null;
throw exception(MACHINE_INFO_NULL);
}
MachineInfoDO machineInfoDO = machineInfoMapper.selectById(id);
if (machineInfoDO == null) {
@ -346,13 +349,14 @@ public class MachineinfoServiceImpl implements MachineInfoService {
}
return machineInfoDO;
}
@VisibleForTesting
void validateMachineEnable(MachineInfoDO machineInfoDO) {
if (machineInfoDO.getStatus() == MachineInfoStatus.ENABLE.getCode()) {
throw exception(MACHINE_ENABLE);
}
}
@VisibleForTesting
void validateMachineUnEnable(MachineInfoDO machineInfoDO) {

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service.impl;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.commons.util.object.BeanUtils;
import cd.casic.module.machine.controller.vo.SecretKeyVO;
@ -15,6 +16,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
@ -34,7 +36,6 @@ public class SecretKeyServiceImpl implements SecretKeyService {
private SecretKeyMapper secretKeyMapper;
@Override
public SecretKeyVO getSecretKey(Long id) {
SecretKeyDO secretKeyDO = validateSecretKeyExists(id);
@ -56,6 +57,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
}
@Override
public void updateSecretKey(SecretKeyVO secretKeyVO) {
SecretKeyDO secretKeyDO = validateSecretKeyExists(secretKeyVO.getId());
@ -65,17 +67,16 @@ public class SecretKeyServiceImpl implements SecretKeyService {
String ossPath = upLoadSecretKey(secretKeyVO.getPath());
BeanUtils.copyProperties(secretKeyVO, secretKeyDO);
secretKeyDO.setPath(ossPath);
}
else {
} else {
BeanUtils.copyProperties(secretKeyVO, secretKeyDO);
}
secretKeyMapper.updateById(secretKeyDO);
}
@Override
public void bindingMachine(Long id,List<Long> machineInfoIds) {
validateSecretKeyExists(id);
machineInfoService.bindingSecretKey(machineInfoIds, id);
public void bindingMachine(SecretKeyVO secretKeyVO) {
validateSecretKeyExists(secretKeyVO.getId());
machineInfoService.bindingSecretKey(secretKeyVO.getMachineInfoIds(), secretKeyVO.getId());
}
@Override
@ -145,7 +146,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
@VisibleForTesting
SecretKeyDO validateSecretKeyExists(Long id) {
if (id == null) {
return null;
throw exception(SECRET_KEY_NOT_EXISTS);
}
SecretKeyDO secretKeyDO = secretKeyMapper.selectById(id);
if (secretKeyDO == null) {