机器管理bug修复,代码格式化
This commit is contained in:
parent
da63f37625
commit
8189a825d3
@ -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;
|
||||
@ -41,7 +42,7 @@ public class MachineEnvController {
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "修改环境变量")
|
||||
@PreAuthorize("@ss.hasPermission('ci:machineEnv:update')")
|
||||
public CommonResult<Boolean> updateEnv(@Valid@RequestBody MachineEnvVO machineEnvVO) {
|
||||
public CommonResult<Boolean> updateEnv(@Valid @RequestBody MachineEnvVO machineEnvVO) {
|
||||
machineEnvService.updateEnv(machineEnvVO);
|
||||
return success(true);
|
||||
}
|
||||
|
@ -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
|
||||
@ -28,7 +30,7 @@ public class MachineInfoController {
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "新增机器信息")
|
||||
// @PreAuthorize("@ss.hasPermission('ci:machineInfo:create')")
|
||||
public CommonResult<Long> createMachine(@Valid @RequestBody MachineInfoVO machineInfoVO) {
|
||||
public CommonResult<Long> createMachine(@Valid @RequestBody MachineInfoVO machineInfoVO) {
|
||||
Long id = machineInfoService.createMachine(machineInfoVO);
|
||||
return success(id);
|
||||
}
|
||||
@ -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')")
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@ -71,7 +74,7 @@ public class SecretKeyController {
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return success(new PageResult<>(pageResult.getTotal()));
|
||||
}
|
||||
return success(BeanUtils.toBean(pageResult,SecretKeyVO.class));
|
||||
return success(BeanUtils.toBean(pageResult, SecretKeyVO.class));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
@ -11,7 +13,7 @@ import java.time.LocalDateTime;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true) // 添加链式调用支持
|
||||
public class MachineEnvVO extends PageParam{
|
||||
public class MachineEnvVO extends PageParam {
|
||||
|
||||
@Schema(description = "环境变量ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
@ -33,4 +35,4 @@ public class MachineEnvVO extends PageParam{
|
||||
|
||||
@Schema(description = "更新时间", example = "2023-06-15T10:30:00")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -55,10 +55,10 @@ public class MachineInfoVO extends PageParam {
|
||||
private Long machineProxyId;
|
||||
|
||||
@Schema(description = "认证类型", example = "password,key")
|
||||
private Integer authenticationType;
|
||||
private Integer authenticationType ;
|
||||
|
||||
@Schema(description = "机器信息类型", example = "Linux,Windows")
|
||||
private Integer machineInfoType;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -47,4 +49,4 @@ public class MachineProxyVO extends PageParam {
|
||||
@Schema(description = "密码", example = "******")
|
||||
private String password;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
@ -40,4 +42,4 @@ public class SecretKeyVO extends PageParam {
|
||||
|
||||
@Schema(description = "关联的机器ID列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024, 2048]")
|
||||
private List<Long> machineInfoIds;
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -19,7 +19,7 @@ import java.io.Serializable;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("machine_env")
|
||||
public class MachineEnvDO extends BaseDO {
|
||||
public class MachineEnvDO extends BaseDO {
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
@ -13,10 +14,14 @@ import java.time.LocalDateTime;
|
||||
*/
|
||||
@Mapper
|
||||
public interface MachineEnvMapper extends BaseMapperX<MachineEnvDO> {
|
||||
default PageResult<MachineEnvDO>selectPage(MachineEnvVO machineEnvVO){
|
||||
return selectPage(machineEnvVO,new LambdaQueryWrapperX<MachineEnvDO>()
|
||||
.likeIfPresent(MachineEnvDO::getEnvKey, machineEnvVO.getEnvKey())
|
||||
.likeIfPresent(MachineEnvDO::getDescription, machineEnvVO.getDescription()));
|
||||
default PageResult<MachineEnvDO> selectPage(MachineEnvVO machineEnvVO) {
|
||||
LambdaQueryWrapperX<MachineEnvDO> machineEnvDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MachineEnvDO>()
|
||||
.likeIfPresent(MachineEnvDO::getEnvKey, machineEnvVO.getEnvKey())
|
||||
.likeIfPresent(MachineEnvDO::getDescription, machineEnvVO.getDescription());
|
||||
if (machineEnvVO.getMachineId() != null && machineEnvVO.getMachineId() > 0) {
|
||||
machineEnvDOLambdaQueryWrapperX.eqIfPresent(MachineEnvDO::getMachineId, machineEnvVO.getMachineId());
|
||||
}
|
||||
return selectPage(machineEnvVO, machineEnvDOLambdaQueryWrapperX);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,39 +11,48 @@ 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;
|
||||
|
||||
@Mapper
|
||||
public interface MachineInfoMapper extends BaseMapperX<MachineInfoDO> {
|
||||
default Boolean existsByTag(String tag){
|
||||
return selectOne(new QueryWrapper<MachineInfoDO>().eq("tag", tag))!=null;
|
||||
default Boolean existsByTag(String tag) {
|
||||
return selectOne(new QueryWrapper<MachineInfoDO>().eq("tag", tag)) != null;
|
||||
}
|
||||
default void updateStatus(Long machineInfoId, Integer status){
|
||||
|
||||
default void updateStatus(Long machineInfoId, Integer status) {
|
||||
UpdateWrapper<MachineInfoDO> set = new UpdateWrapper<>();
|
||||
set.eq("id", machineInfoId).set("status", status);
|
||||
this.update(null,set);
|
||||
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);
|
||||
|
||||
default void bindingSecretKey(List<Long> machineInfoIds, Long secretKeyId) {
|
||||
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){
|
||||
|
||||
default void unBindingSecretKey(List<Long> secretKeyId) {
|
||||
LambdaUpdateWrapper<MachineInfoDO> wrapper = new LambdaUpdateWrapper<MachineInfoDO>()
|
||||
.set(MachineInfoDO::getSecretKeyId, null)
|
||||
.in(MachineInfoDO::getSecretKeyId, secretKeyId);
|
||||
.set(MachineInfoDO::getSecretKeyId, null)
|
||||
.in(MachineInfoDO::getSecretKeyId, secretKeyId);
|
||||
this.update(null, wrapper);
|
||||
}
|
||||
default PageResult<MachineInfoDO> selectPage(MachineInfoVO machineInfoVO){
|
||||
return selectPage(machineInfoVO,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()));
|
||||
|
||||
default PageResult<MachineInfoDO> selectPage(MachineInfoVO machineInfoVO) {
|
||||
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())
|
||||
.likeIfPresent(MachineInfoDO::getHostIp, machineInfoVO.getHostIp());
|
||||
if (machineInfoVO.getStatus() != -1) {
|
||||
machineInfoDOLambdaQueryWrapperX.eqIfPresent(MachineInfoDO::getStatus, machineInfoVO.getStatus());
|
||||
}
|
||||
return selectPage(machineInfoVO, machineInfoDOLambdaQueryWrapperX);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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>()
|
||||
.eqIfPresent(MachineProxyDO::getHostIp, machineProxyVO.getHostIp())
|
||||
.eqIfPresent(MachineProxyDO::getProxyType, machineProxyVO.getProxyType())
|
||||
.eqIfPresent(MachineProxyDO::getStatus, machineProxyVO.getStatus())
|
||||
.likeIfPresent(MachineProxyDO::getDescription, machineProxyVO.getDescription())
|
||||
);
|
||||
LambdaQueryWrapperX<MachineProxyDO> machineProxyDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MachineProxyDO>()
|
||||
.eqIfPresent(MachineProxyDO::getHostIp, machineProxyVO.getHostIp())
|
||||
.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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,16 +14,16 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface SecretKeyMapper extends BaseMapperX<SecretKeyDO> {
|
||||
//查询列表
|
||||
default PageResult<SecretKeyDO> selectPage(SecretKeyVO secretKeyVO){
|
||||
return selectPage(secretKeyVO,new LambdaQueryWrapperX<SecretKeyDO>()
|
||||
.likeIfPresent(SecretKeyDO::getName,secretKeyVO.getName())
|
||||
.likeIfPresent(SecretKeyDO::getDescription,secretKeyVO.getDescription()));
|
||||
default PageResult<SecretKeyDO> selectPage(SecretKeyVO secretKeyVO) {
|
||||
return selectPage(secretKeyVO, new LambdaQueryWrapperX<SecretKeyDO>()
|
||||
.likeIfPresent(SecretKeyDO::getName, secretKeyVO.getName())
|
||||
.likeIfPresent(SecretKeyDO::getDescription, secretKeyVO.getDescription()));
|
||||
|
||||
}
|
||||
|
||||
default void bindingMachine(Long machineInfoId, List<Long> secretKeyId){
|
||||
default void bindingMachine(Long machineInfoId, List<Long> secretKeyId) {
|
||||
UpdateWrapper<SecretKeyDO> set = new UpdateWrapper<>();
|
||||
set.eq("id", secretKeyId).set("machineInfoId", machineInfoId);
|
||||
this.update(null,set);
|
||||
this.update(null, set);
|
||||
}
|
||||
}
|
||||
|
@ -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,"停用");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
package cd.casic.module.machine.enums;
|
||||
|
||||
import cd.casic.framework.commons.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
@ -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;
|
||||
@ -38,7 +39,7 @@ public interface MachineEnvService {
|
||||
void deleteEnvList(String ids);
|
||||
|
||||
/*
|
||||
* 修改环境变量
|
||||
* 修改环境变量
|
||||
*/
|
||||
void updateEnv(@Valid MachineEnvVO machineEnvVO);
|
||||
}
|
||||
|
@ -4,19 +4,21 @@ 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;
|
||||
import java.util.Map;
|
||||
|
||||
public interface MachineInfoService {
|
||||
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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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{
|
||||
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);
|
||||
|
@ -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;
|
||||
@ -20,7 +21,7 @@ import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
|
||||
* 环境变量服务实现类
|
||||
*/
|
||||
@Service("machineEnvService")
|
||||
public class MachineEnvServiceImpl implements MachineEnvService {
|
||||
public class MachineEnvServiceImpl implements MachineEnvService {
|
||||
|
||||
@Resource
|
||||
private MachineEnvMapper machineEnvMapper;
|
||||
@ -58,10 +59,10 @@ public class MachineEnvServiceImpl implements MachineEnvService {
|
||||
public void deleteEnvList(String ids) {
|
||||
//ids转换为List,使用流
|
||||
List<Long> machineEnvIds = Arrays.stream(ids.split(","))
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
|
||||
machineEnvMapper.deleteBatchIds(machineEnvIds);
|
||||
}
|
||||
@ -84,20 +85,20 @@ public class MachineEnvServiceImpl implements MachineEnvService {
|
||||
}
|
||||
return machineEnvDO;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateMachineEnvAdd(MachineEnvVO machineEnvVO) {
|
||||
if (machineEnvVO.getEnvKey()==null||machineEnvVO.getEnvValue()==null) {
|
||||
if (machineEnvVO.getEnvKey() == null || machineEnvVO.getEnvValue() == null) {
|
||||
throw exception(MACHINE_ENV_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 检查环境变量键是否合法
|
||||
@VisibleForTesting
|
||||
private void validateKey(String key) {
|
||||
if (!key.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) {
|
||||
throw exception(MACHINE_ENV_KEY_ILLEGAL);
|
||||
throw exception(MACHINE_ENV_KEY_ILLEGAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
@ -58,7 +76,7 @@ public class MachineProxyServiceImpl implements MachineProxyService {
|
||||
.map(MachineProxyDO::getStatus)
|
||||
.collect(Collectors.groupingBy(
|
||||
Function.identity(),
|
||||
// 统计每个分组的元素数量
|
||||
// 统计每个分组的元素数量
|
||||
Collectors.counting()
|
||||
));
|
||||
}
|
||||
@ -75,23 +93,19 @@ public class MachineProxyServiceImpl implements MachineProxyService {
|
||||
.filter(s -> !s.isEmpty())
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
//检查是否存在在线的代理
|
||||
validateMachineProxyOnline(machineProxyIds);
|
||||
// 批量逻辑删除
|
||||
machineProxyMapper.deleteBatchIds(machineProxyIds);
|
||||
machineProxyIds.forEach(this::delete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<MachineProxyDO> getProxyPage(MachineProxyVO machineProxyVO) {
|
||||
return machineProxyMapper.selectPage(machineProxyVO);
|
||||
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,26 +114,12 @@ 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) {
|
||||
if (machineProxyVO.getHostIp() == null) {
|
||||
throw exception(MACHINE_PROXY_HOST_IP_NULL);
|
||||
}
|
||||
if (machineProxyVO.getUsername()==null) {
|
||||
if (machineProxyVO.getUsername() == null) {
|
||||
throw exception(MACHINE_PROXY_USER_NAME_NULL);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -30,7 +31,7 @@ import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("machineInfoService")
|
||||
public class MachineinfoServiceImpl implements MachineInfoService {
|
||||
public class MachineinfoServiceImpl implements MachineInfoService {
|
||||
|
||||
@Resource
|
||||
private SecretKeyService secretKeyService;
|
||||
@ -58,14 +59,15 @@ public class MachineinfoServiceImpl implements MachineInfoService {
|
||||
validateMachineEnvAdd(machineInfoVO);
|
||||
validateMachineTagUnique(machineInfoVO.getTag());
|
||||
MachineInfoDO machineInfoDO = BeanUtils.toBean(machineInfoVO, MachineInfoDO.class);
|
||||
Long secretKeyId = machineInfoDO.getSecretKeyId();
|
||||
SecretKeyVO secretKey = secretKeyService.getSecretKey(secretKeyId);
|
||||
if (secretKey==null){
|
||||
throw exception(SECRET_KEY_NOT_EXISTS);
|
||||
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
|
||||
@ -74,7 +76,7 @@ public class MachineinfoServiceImpl implements MachineInfoService {
|
||||
String newTag = machineInfoVO.getTag();
|
||||
MachineInfoDO machineInfoDO = validateMachineInfoExists(machineInfoVO.getId());
|
||||
String oldTag = machineInfoDO.getTag();
|
||||
if (!newTag.equals(oldTag)){
|
||||
if (!newTag.equals(oldTag)) {
|
||||
validateMachineTagUnique(newTag);
|
||||
}
|
||||
BeanUtils.copyProperties(machineInfoVO, machineInfoDO);
|
||||
@ -82,19 +84,19 @@ 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
|
||||
public PageResult<MachineInfoDO> listMachineInfo(MachineInfoVO machineInfoVO) {
|
||||
return machineInfoMapper.selectPage(machineInfoVO);
|
||||
return machineInfoMapper.selectPage(machineInfoVO);
|
||||
}
|
||||
|
||||
@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
|
||||
@ -123,7 +125,7 @@ public class MachineinfoServiceImpl implements MachineInfoService {
|
||||
validateMachineUnEnable(machineInfoDO);
|
||||
log.info("测试机器连接: {}", machineInfoDO.getHostIp());
|
||||
connectionSession.setMachineInfo(machineInfoDO);
|
||||
try{
|
||||
try {
|
||||
connectionSession.connect();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
@ -289,56 +291,57 @@ public class MachineinfoServiceImpl implements MachineInfoService {
|
||||
if (machineInfoVO.getHostIp().isEmpty()) {
|
||||
throw exception(MACHINE_INFO_HOST_IP_NULL);
|
||||
}
|
||||
if (machineInfoVO.getUsername().isEmpty()){
|
||||
if (machineInfoVO.getUsername().isEmpty()) {
|
||||
throw exception(MACHINE_INFO_USER_NAME_NULL);
|
||||
}
|
||||
if(machineInfoVO.getTag().isEmpty()){
|
||||
if (machineInfoVO.getTag().isEmpty()) {
|
||||
throw exception(MACHINE_INFO_TAG_NULL);
|
||||
}
|
||||
|
||||
if (machineInfoVO.getAuthenticationType()!=null){
|
||||
boolean flag=true;
|
||||
if (machineInfoVO.getAuthenticationType() != null) {
|
||||
boolean flag = true;
|
||||
for (int type : AuthenticationType.ARRAYS) {
|
||||
if (type == machineInfoVO.getAuthenticationType()) {
|
||||
flag=false;
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
if (flag){
|
||||
throw exception(MACHINE_INFO_AUTHENTICATION_TYPE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (flag) {
|
||||
throw exception(MACHINE_INFO_AUTHENTICATION_TYPE_NOT_EXISTS);
|
||||
}
|
||||
} else {
|
||||
throw exception(MACHINE_INFO_AUTHENTICATION_TYPE_NULL);
|
||||
}
|
||||
|
||||
|
||||
if (machineInfoVO.getMachineInfoType()!= null){
|
||||
if (machineInfoVO.getMachineInfoType() != null) {
|
||||
boolean flag = true;
|
||||
for (int type : MachineInfoType.ARRAYS) {
|
||||
if (type == machineInfoVO.getMachineInfoType()) {
|
||||
flag=false;
|
||||
if (type == machineInfoVO.getMachineInfoType()) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
throw exception(MACHINE_INFO_TYPE_NOT_EXISTS);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
throw exception(MACHINE_INFO_TYPE_NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateMachineTagUnique(String tag){
|
||||
void validateMachineTagUnique(String tag) {
|
||||
if (machineInfoMapper.existsByTag(tag)) {
|
||||
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,17 +349,18 @@ public class MachineinfoServiceImpl implements MachineInfoService {
|
||||
}
|
||||
return machineInfoDO;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateMachineEnable(MachineInfoDO machineInfoDO) {
|
||||
|
||||
if (machineInfoDO.getStatus()==MachineInfoStatus.ENABLE.getCode()){
|
||||
if (machineInfoDO.getStatus() == MachineInfoStatus.ENABLE.getCode()) {
|
||||
throw exception(MACHINE_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateMachineUnEnable(MachineInfoDO machineInfoDO) {
|
||||
|
||||
if (machineInfoDO.getStatus()==MachineInfoStatus.UN_ENABLE.getCode()){
|
||||
if (machineInfoDO.getStatus() == MachineInfoStatus.UN_ENABLE.getCode()) {
|
||||
throw exception(MACHINE_UN_ENABLE);
|
||||
}
|
||||
}
|
||||
|
@ -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,15 +36,14 @@ public class SecretKeyServiceImpl implements SecretKeyService {
|
||||
private SecretKeyMapper secretKeyMapper;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SecretKeyVO getSecretKey(Long id){
|
||||
public SecretKeyVO getSecretKey(Long id) {
|
||||
SecretKeyDO secretKeyDO = validateSecretKeyExists(id);
|
||||
return BeanUtils.toBean(secretKeyDO, SecretKeyVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createSecretKey(SecretKeyVO secretKeyVO){
|
||||
public Long createSecretKey(SecretKeyVO secretKeyVO) {
|
||||
validateSecretKeyAdd(secretKeyVO);
|
||||
String ossPath = upLoadSecretKey(secretKeyVO.getPath());
|
||||
//检查得到的oss路径是否为空
|
||||
@ -56,6 +57,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSecretKey(SecretKeyVO secretKeyVO) {
|
||||
SecretKeyDO secretKeyDO = validateSecretKeyExists(secretKeyVO.getId());
|
||||
@ -65,36 +67,35 @@ public class SecretKeyServiceImpl implements SecretKeyService {
|
||||
String ossPath = upLoadSecretKey(secretKeyVO.getPath());
|
||||
BeanUtils.copyProperties(secretKeyVO, secretKeyDO);
|
||||
secretKeyDO.setPath(ossPath);
|
||||
}
|
||||
else {
|
||||
BeanUtils.copyProperties(secretKeyVO,secretKeyDO);
|
||||
} 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
|
||||
@Transactional
|
||||
public void deleteSecretKeyList(List<Long> ids) {
|
||||
ids.forEach(
|
||||
secretKeyId -> {
|
||||
SecretKeyDO secretKeyDO = validateSecretKeyExists(secretKeyId);
|
||||
if (secretKeyDO.getPath() != null && !secretKeyDO.getPath().isEmpty()){
|
||||
try {
|
||||
//文件名
|
||||
//删除子目录文件,需要在前面加上根目录文件路径
|
||||
String fileName = secretKeyDO.getPath().substring(secretKeyDO.getPath().lastIndexOf("/") + 1);
|
||||
aliYunOssClient.delete(fileName);
|
||||
} catch (Exception e) {
|
||||
throw exception(DELETE_FILE_FAIL);
|
||||
}
|
||||
secretKeyId -> {
|
||||
SecretKeyDO secretKeyDO = validateSecretKeyExists(secretKeyId);
|
||||
if (secretKeyDO.getPath() != null && !secretKeyDO.getPath().isEmpty()) {
|
||||
try {
|
||||
//文件名
|
||||
//删除子目录文件,需要在前面加上根目录文件路径
|
||||
String fileName = secretKeyDO.getPath().substring(secretKeyDO.getPath().lastIndexOf("/") + 1);
|
||||
aliYunOssClient.delete(fileName);
|
||||
} catch (Exception e) {
|
||||
throw exception(DELETE_FILE_FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//绑定的机器全部设置为空
|
||||
@ -118,7 +119,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
|
||||
String ossPath;
|
||||
try {
|
||||
ossPath = aliYunOssClient.upload(content, path, "txt");
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw exception(UPLOADING_FILE_FAIL);
|
||||
}
|
||||
return ossPath;
|
||||
@ -126,7 +127,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
|
||||
|
||||
@VisibleForTesting
|
||||
void validateSecretKeyAdd(SecretKeyVO secretKeyVO) {
|
||||
if (secretKeyVO==null) {
|
||||
if (secretKeyVO == null) {
|
||||
throw exception(SECRET_KEY_NULL);
|
||||
}
|
||||
if (secretKeyVO.getPath().isEmpty()) {
|
||||
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user