机器管理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; package cd.casic.module.machine.controller;
import cd.casic.framework.commons.pojo.CommonResult; import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.framework.commons.pojo.PageResult; import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.commons.util.object.BeanUtils; import cd.casic.framework.commons.util.object.BeanUtils;
@ -41,7 +42,7 @@ public class MachineEnvController {
@PutMapping("/update") @PutMapping("/update")
@Operation(summary = "修改环境变量") @Operation(summary = "修改环境变量")
@PreAuthorize("@ss.hasPermission('ci:machineEnv:update')") @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); machineEnvService.updateEnv(machineEnvVO);
return success(true); return success(true);
} }

View File

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

View File

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

View File

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

View File

@ -1,8 +1,10 @@
package cd.casic.module.machine.controller.vo; package cd.casic.module.machine.controller.vo;
import cd.casic.framework.commons.pojo.PageParam; import cd.casic.framework.commons.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ -11,7 +13,7 @@ import java.time.LocalDateTime;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Accessors(chain = true) // 添加链式调用支持 @Accessors(chain = true) // 添加链式调用支持
public class MachineEnvVO extends PageParam{ public class MachineEnvVO extends PageParam {
@Schema(description = "环境变量ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "环境变量ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id; private Long id;
@ -33,4 +35,4 @@ public class MachineEnvVO extends PageParam{
@Schema(description = "更新时间", example = "2023-06-15T10:30:00") @Schema(description = "更新时间", example = "2023-06-15T10:30:00")
private LocalDateTime updateTime; private LocalDateTime updateTime;
} }

View File

@ -40,7 +40,7 @@ public class MachineInfoVO extends PageParam {
private String username; private String username;
@Schema(description = "机器状态", example = "online,offline,maintenance") @Schema(description = "机器状态", example = "online,offline,maintenance")
private Integer status; private Integer status = -1;
@Schema(description = "SSH端口", example = "22") @Schema(description = "SSH端口", example = "22")
private Integer sshPort; private Integer sshPort;
@ -55,10 +55,10 @@ public class MachineInfoVO extends PageParam {
private Long machineProxyId; private Long machineProxyId;
@Schema(description = "认证类型", example = "password,key") @Schema(description = "认证类型", example = "password,key")
private Integer authenticationType; private Integer authenticationType ;
@Schema(description = "机器信息类型", example = "Linux,Windows") @Schema(description = "机器信息类型", example = "Linux,Windows")
private Integer machineInfoType; private Integer machineInfoType;
} }

View File

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

View File

@ -1,8 +1,10 @@
package cd.casic.module.machine.controller.vo; package cd.casic.module.machine.controller.vo;
import cd.casic.framework.commons.pojo.PageParam; import cd.casic.framework.commons.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -40,4 +42,4 @@ public class SecretKeyVO extends PageParam {
@Schema(description = "关联的机器ID列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024, 2048]") @Schema(description = "关联的机器ID列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024, 2048]")
private List<Long> machineInfoIds; private List<Long> machineInfoIds;
} }

View File

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

View File

@ -19,7 +19,7 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@TableName("machine_env") @TableName("machine_env")
public class MachineEnvDO extends BaseDO { public class MachineEnvDO extends BaseDO {
/** /**

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.dal.mysql; package cd.casic.module.machine.dal.mysql;
import cd.casic.framework.mybatis.core.mapper.BaseMapperX; import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
import cd.casic.module.machine.controller.vo.MachineEnvVO; import cd.casic.module.machine.controller.vo.MachineEnvVO;
import cd.casic.module.machine.dal.dataobject.MachineEnvDO; import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
@ -13,10 +14,14 @@ import java.time.LocalDateTime;
*/ */
@Mapper @Mapper
public interface MachineEnvMapper extends BaseMapperX<MachineEnvDO> { public interface MachineEnvMapper extends BaseMapperX<MachineEnvDO> {
default PageResult<MachineEnvDO>selectPage(MachineEnvVO machineEnvVO){ 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::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,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.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
@Mapper @Mapper
public interface MachineInfoMapper extends BaseMapperX<MachineInfoDO> { public interface MachineInfoMapper extends BaseMapperX<MachineInfoDO> {
default Boolean existsByTag(String tag){ default Boolean existsByTag(String tag) {
return selectOne(new QueryWrapper<MachineInfoDO>().eq("tag", tag))!=null; 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<>(); UpdateWrapper<MachineInfoDO> set = new UpdateWrapper<>();
set.eq("id", machineInfoId).set("status", status); 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>() default void bindingSecretKey(List<Long> machineInfoIds, Long secretKeyId) {
.set(MachineInfoDO::getSecretKeyId, secretKeyId) UpdateWrapper<MachineInfoDO> wrapper = new UpdateWrapper<>();
.in(MachineInfoDO::getId, machineInfoIds); wrapper.in("id", machineInfoIds) // 匹配 ID 集合
.set("secret_key_id", secretKeyId); // 设置新的 status
this.update(null, wrapper); this.update(null, wrapper);
} }
default void unBindingSecretKey(List<Long> secretKeyId){
default void unBindingSecretKey(List<Long> secretKeyId) {
LambdaUpdateWrapper<MachineInfoDO> wrapper = new LambdaUpdateWrapper<MachineInfoDO>() LambdaUpdateWrapper<MachineInfoDO> wrapper = new LambdaUpdateWrapper<MachineInfoDO>()
.set(MachineInfoDO::getSecretKeyId, null) .set(MachineInfoDO::getSecretKeyId, null)
.in(MachineInfoDO::getSecretKeyId, secretKeyId); .in(MachineInfoDO::getSecretKeyId, secretKeyId);
this.update(null, wrapper); this.update(null, wrapper);
} }
default PageResult<MachineInfoDO> selectPage(MachineInfoVO machineInfoVO){
return selectPage(machineInfoVO,new LambdaQueryWrapperX<MachineInfoDO>() default PageResult<MachineInfoDO> selectPage(MachineInfoVO machineInfoVO) {
.likeIfPresent(MachineInfoDO::getName, machineInfoVO.getName()) LambdaQueryWrapperX<MachineInfoDO> machineInfoDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MachineInfoDO>()
.likeIfPresent(MachineInfoDO::getTag, machineInfoVO.getTag()) .likeIfPresent(MachineInfoDO::getName, machineInfoVO.getName())
.likeIfPresent(MachineInfoDO::getDescription, machineInfoVO.getDescription()) .likeIfPresent(MachineInfoDO::getTag, machineInfoVO.getTag())
.likeIfPresent(MachineInfoDO::getUsername, machineInfoVO.getUsername()) .likeIfPresent(MachineInfoDO::getDescription, machineInfoVO.getDescription())
.eqIfPresent(MachineInfoDO::getHostIp, machineInfoVO.getHostIp())); .likeIfPresent(MachineInfoDO::getUsername, machineInfoVO.getUsername())
.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; package cd.casic.module.machine.dal.mysql;
import cd.casic.framework.commons.pojo.PageResult; import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.mybatis.core.mapper.BaseMapperX; import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
import cd.casic.framework.mybatis.core.query.LambdaQueryWrapperX; import cd.casic.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -12,15 +13,17 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface MachineProxyMapper extends BaseMapperX<MachineProxyDO> { public interface MachineProxyMapper extends BaseMapperX<MachineProxyDO> {
default PageResult<MachineProxyDO> selectPage(MachineProxyVO machineProxyVO) { 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::getHostIp, machineProxyVO.getHostIp())
.eqIfPresent(MachineProxyDO::getProxyType, machineProxyVO.getProxyType()) .likeIfPresent(MachineProxyDO::getDescription, machineProxyVO.getDescription());
.eqIfPresent(MachineProxyDO::getStatus, machineProxyVO.getStatus()) if (machineProxyVO.getStatus() != -1) {
.likeIfPresent(MachineProxyDO::getDescription, machineProxyVO.getDescription()) machineProxyDOLambdaQueryWrapperX.eqIfPresent(MachineProxyDO::getStatus, machineProxyVO.getStatus());
); }
if (machineProxyVO.getProxyType() != -1) {
machineProxyDOLambdaQueryWrapperX.eqIfPresent(MachineProxyDO::getProxyType, machineProxyVO.getProxyType());
}
return selectPage(machineProxyVO, machineProxyDOLambdaQueryWrapperX);
} }
} }

View File

@ -14,16 +14,16 @@ import java.util.List;
@Mapper @Mapper
public interface SecretKeyMapper extends BaseMapperX<SecretKeyDO> { public interface SecretKeyMapper extends BaseMapperX<SecretKeyDO> {
//查询列表 //查询列表
default PageResult<SecretKeyDO> selectPage(SecretKeyVO secretKeyVO){ default PageResult<SecretKeyDO> selectPage(SecretKeyVO secretKeyVO) {
return selectPage(secretKeyVO,new LambdaQueryWrapperX<SecretKeyDO>() return selectPage(secretKeyVO, new LambdaQueryWrapperX<SecretKeyDO>()
.likeIfPresent(SecretKeyDO::getName,secretKeyVO.getName()) .likeIfPresent(SecretKeyDO::getName, secretKeyVO.getName())
.likeIfPresent(SecretKeyDO::getDescription,secretKeyVO.getDescription())); .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<>(); UpdateWrapper<SecretKeyDO> set = new UpdateWrapper<>();
set.eq("id", secretKeyId).set("machineInfoId", machineInfoId); set.eq("id", secretKeyId).set("machineInfoId", machineInfoId);
this.update(null,set); this.update(null, set);
} }
} }

View File

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

View File

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

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service; package cd.casic.module.machine.service;
import cd.casic.framework.commons.pojo.PageResult; import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.MachineEnvVO; import cd.casic.module.machine.controller.vo.MachineEnvVO;
import cd.casic.module.machine.dal.dataobject.MachineEnvDO; import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
@ -38,7 +39,7 @@ public interface MachineEnvService {
void deleteEnvList(String ids); void deleteEnvList(String ids);
/* /*
* 修改环境变量 * 修改环境变量
*/ */
void updateEnv(@Valid MachineEnvVO machineEnvVO); void updateEnv(@Valid MachineEnvVO machineEnvVO);
} }

View File

@ -4,19 +4,21 @@ import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.MachineInfoVO; import cd.casic.module.machine.controller.vo.MachineInfoVO;
import cd.casic.module.machine.dal.dataobject.MachineInfoDO; import cd.casic.module.machine.dal.dataobject.MachineInfoDO;
import cd.casic.module.machine.enums.ConnectionStatus; 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 org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public interface MachineInfoService { public interface MachineInfoService {
Long createMachine(MachineInfoVO MachineInfoVO); 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); 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.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.MachineProxyVO; import cd.casic.module.machine.controller.vo.MachineProxyVO;
import cd.casic.module.machine.dal.dataobject.MachineProxyDO; 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; 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(); Map<Integer, Long> getAllProxyStatus();
/** /**
* 批量删除代理 * 批量删除代理
* *
@ -37,5 +45,5 @@ public interface MachineProxyService {
*/ */
void deleteProxyList(String proxyIds); 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.dal.dataobject.SecretKeyDO;
import cd.casic.module.machine.controller.vo.SecretKeyVO; import cd.casic.module.machine.controller.vo.SecretKeyVO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import java.util.List; import java.util.List;
public interface SecretKeyService{ public interface SecretKeyService {
Long createSecretKey(@Valid SecretKeyVO secretKeyVO) throws Exception; Long createSecretKey(@Valid SecretKeyVO secretKeyVO) throws Exception;
void bindingMachine(Long id, List<Long> machineInfoId); void bindingMachine(@Valid SecretKeyVO secretKeyVO);
void updateSecretKey(@Valid SecretKeyVO secretKeyVO); void updateSecretKey(@Valid SecretKeyVO secretKeyVO);
PageResult<SecretKeyDO> getSecretKeypage(@Valid SecretKeyVO secretKeyVO); PageResult<SecretKeyDO> getSecretKeypage(@Valid SecretKeyVO secretKeyVO);
void deleteSecretKeyList(List<Long> ids); void deleteSecretKeyList(List<Long> ids);
SecretKeyVO getSecretKey(Long id); SecretKeyVO getSecretKey(Long id);

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service.impl; package cd.casic.module.machine.service.impl;
import cd.casic.module.machine.controller.vo.MachineEnvVO; import cd.casic.module.machine.controller.vo.MachineEnvVO;
import cd.casic.module.machine.dal.dataobject.MachineEnvDO; import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
import cd.casic.module.machine.dal.mysql.MachineEnvMapper; import cd.casic.module.machine.dal.mysql.MachineEnvMapper;
@ -20,7 +21,7 @@ import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
* 环境变量服务实现类 * 环境变量服务实现类
*/ */
@Service("machineEnvService") @Service("machineEnvService")
public class MachineEnvServiceImpl implements MachineEnvService { public class MachineEnvServiceImpl implements MachineEnvService {
@Resource @Resource
private MachineEnvMapper machineEnvMapper; private MachineEnvMapper machineEnvMapper;
@ -58,10 +59,10 @@ public class MachineEnvServiceImpl implements MachineEnvService {
public void deleteEnvList(String ids) { public void deleteEnvList(String ids) {
//ids转换为List,使用流 //ids转换为List,使用流
List<Long> machineEnvIds = Arrays.stream(ids.split(",")) List<Long> machineEnvIds = Arrays.stream(ids.split(","))
.map(String::trim) .map(String::trim)
.filter(s -> !s.isEmpty()) .filter(s -> !s.isEmpty())
.map(Long::parseLong) .map(Long::parseLong)
.toList(); .toList();
machineEnvMapper.deleteBatchIds(machineEnvIds); machineEnvMapper.deleteBatchIds(machineEnvIds);
} }
@ -84,20 +85,20 @@ public class MachineEnvServiceImpl implements MachineEnvService {
} }
return machineEnvDO; return machineEnvDO;
} }
@VisibleForTesting @VisibleForTesting
void validateMachineEnvAdd(MachineEnvVO machineEnvVO) { void validateMachineEnvAdd(MachineEnvVO machineEnvVO) {
if (machineEnvVO.getEnvKey()==null||machineEnvVO.getEnvValue()==null) { if (machineEnvVO.getEnvKey() == null || machineEnvVO.getEnvValue() == null) {
throw exception(MACHINE_ENV_NULL); throw exception(MACHINE_ENV_NULL);
} }
} }
// 检查环境变量键是否合法 // 检查环境变量键是否合法
@VisibleForTesting @VisibleForTesting
private void validateKey(String key) { private void validateKey(String key) {
if (!key.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) { if (!key.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) {
throw exception(MACHINE_ENV_KEY_ILLEGAL); throw exception(MACHINE_ENV_KEY_ILLEGAL);
} }
} }

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service.impl; package cd.casic.module.machine.service.impl;
import cd.casic.framework.commons.pojo.PageResult; import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.MachineProxyVO; import cd.casic.module.machine.controller.vo.MachineProxyVO;
import cd.casic.module.machine.dal.dataobject.MachineProxyDO; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception; import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*; import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
import static com.baomidou.mybatisplus.extension.toolkit.Db.save; import static com.baomidou.mybatisplus.extension.toolkit.Db.save;
@ -33,7 +37,8 @@ public class MachineProxyServiceImpl implements MachineProxyService {
public Long createProxy(MachineProxyVO machineProxyVO) { public Long createProxy(MachineProxyVO machineProxyVO) {
validateMachineProxyAdd(machineProxyVO); validateMachineProxyAdd(machineProxyVO);
// 创建代理记录 // 创建代理记录
MachineProxyDO machineProxyDO = BeanUtils.toBean(machineProxyVO, MachineProxyDO.class);; MachineProxyDO machineProxyDO = BeanUtils.toBean(machineProxyVO, MachineProxyDO.class);
;
save(machineProxyDO); save(machineProxyDO);
return machineProxyDO.getId(); return machineProxyDO.getId();
} }
@ -47,6 +52,19 @@ public class MachineProxyServiceImpl implements MachineProxyService {
machineProxyMapper.updateById(machineProxyDO); 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 @Override
public Map<Integer, Long> getAllProxyStatus() { public Map<Integer, Long> getAllProxyStatus() {
@ -58,7 +76,7 @@ public class MachineProxyServiceImpl implements MachineProxyService {
.map(MachineProxyDO::getStatus) .map(MachineProxyDO::getStatus)
.collect(Collectors.groupingBy( .collect(Collectors.groupingBy(
Function.identity(), Function.identity(),
// 统计每个分组的元素数量 // 统计每个分组的元素数量
Collectors.counting() Collectors.counting()
)); ));
} }
@ -75,23 +93,19 @@ public class MachineProxyServiceImpl implements MachineProxyService {
.filter(s -> !s.isEmpty()) .filter(s -> !s.isEmpty())
.map(Long::parseLong) .map(Long::parseLong)
.toList(); .toList();
//检查是否存在在线的代理
validateMachineProxyOnline(machineProxyIds);
// 批量逻辑删除 // 批量逻辑删除
machineProxyMapper.deleteBatchIds(machineProxyIds); machineProxyIds.forEach(this::delete);
} }
@Override @Override
public PageResult<MachineProxyDO> getProxyPage(MachineProxyVO machineProxyVO) { public PageResult<MachineProxyDO> getProxyPage(MachineProxyVO machineProxyVO) {
return machineProxyMapper.selectPage(machineProxyVO); return machineProxyMapper.selectPage(machineProxyVO);
} }
@VisibleForTesting @VisibleForTesting
MachineProxyDO validateMachineProxyExists(Long id) { MachineProxyDO validateMachineProxyExists(Long id) {
if (id == null) { if (id == null) {
return null; throw exception(MACHINE_PROXY_NOT_EXISTS);
} }
MachineProxyDO machineProxyDO = machineProxyMapper.selectById(id); MachineProxyDO machineProxyDO = machineProxyMapper.selectById(id);
if (machineProxyDO == null) { if (machineProxyDO == null) {
@ -100,26 +114,12 @@ public class MachineProxyServiceImpl implements MachineProxyService {
return machineProxyDO; 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 @VisibleForTesting
void validateMachineProxyAdd(MachineProxyVO machineProxyVO) { void validateMachineProxyAdd(MachineProxyVO machineProxyVO) {
if (machineProxyVO.getHostIp()==null) { if (machineProxyVO.getHostIp() == null) {
throw exception(MACHINE_PROXY_HOST_IP_NULL); throw exception(MACHINE_PROXY_HOST_IP_NULL);
} }
if (machineProxyVO.getUsername()==null) { if (machineProxyVO.getUsername() == null) {
throw exception(MACHINE_PROXY_USER_NAME_NULL); throw exception(MACHINE_PROXY_USER_NAME_NULL);
} }

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service.impl; package cd.casic.module.machine.service.impl;
import cd.casic.framework.commons.pojo.PageResult; import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.machine.controller.vo.SecretKeyVO; import cd.casic.module.machine.controller.vo.SecretKeyVO;
import cd.casic.module.machine.enums.AuthenticationType; import cd.casic.module.machine.enums.AuthenticationType;
@ -30,7 +31,7 @@ import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
*/ */
@Slf4j @Slf4j
@Service("machineInfoService") @Service("machineInfoService")
public class MachineinfoServiceImpl implements MachineInfoService { public class MachineinfoServiceImpl implements MachineInfoService {
@Resource @Resource
private SecretKeyService secretKeyService; private SecretKeyService secretKeyService;
@ -58,14 +59,15 @@ public class MachineinfoServiceImpl implements MachineInfoService {
validateMachineEnvAdd(machineInfoVO); validateMachineEnvAdd(machineInfoVO);
validateMachineTagUnique(machineInfoVO.getTag()); validateMachineTagUnique(machineInfoVO.getTag());
MachineInfoDO machineInfoDO = BeanUtils.toBean(machineInfoVO, MachineInfoDO.class); MachineInfoDO machineInfoDO = BeanUtils.toBean(machineInfoVO, MachineInfoDO.class);
Long secretKeyId = machineInfoDO.getSecretKeyId(); if (machineInfoVO.getAuthenticationType() == 2) {
SecretKeyVO secretKey = secretKeyService.getSecretKey(secretKeyId); Long secretKeyId = machineInfoDO.getSecretKeyId();
if (secretKey==null){ SecretKeyVO secretKey = secretKeyService.getSecretKey(secretKeyId);
throw exception(SECRET_KEY_NOT_EXISTS); if (secretKey == null) {
throw exception(SECRET_KEY_NOT_EXISTS);
}
} }
machineInfoMapper.insert(machineInfoDO); machineInfoMapper.insert(machineInfoDO);
Long id = machineInfoDO.getId(); return machineInfoDO.getId();
return id;
} }
@Override @Override
@ -74,7 +76,7 @@ public class MachineinfoServiceImpl implements MachineInfoService {
String newTag = machineInfoVO.getTag(); String newTag = machineInfoVO.getTag();
MachineInfoDO machineInfoDO = validateMachineInfoExists(machineInfoVO.getId()); MachineInfoDO machineInfoDO = validateMachineInfoExists(machineInfoVO.getId());
String oldTag = machineInfoDO.getTag(); String oldTag = machineInfoDO.getTag();
if (!newTag.equals(oldTag)){ if (!newTag.equals(oldTag)) {
validateMachineTagUnique(newTag); validateMachineTagUnique(newTag);
} }
BeanUtils.copyProperties(machineInfoVO, machineInfoDO); BeanUtils.copyProperties(machineInfoVO, machineInfoDO);
@ -82,19 +84,19 @@ public class MachineinfoServiceImpl implements MachineInfoService {
} }
@Override @Override
public Integer updateStatus(Long machineInfoId, Integer status) { public Integer updateStatus(MachineInfoVO machineInfoVO) {
machineInfoMapper.updateStatus(machineInfoId, status); machineInfoMapper.updateStatus(machineInfoVO.getId(), machineInfoVO.getStatus());
return machineInfoMapper.selectById(machineInfoId).getStatus(); return machineInfoVO.getStatus();
} }
@Override @Override
public PageResult<MachineInfoDO> listMachineInfo(MachineInfoVO machineInfoVO) { public PageResult<MachineInfoDO> listMachineInfo(MachineInfoVO machineInfoVO) {
return machineInfoMapper.selectPage(machineInfoVO); return machineInfoMapper.selectPage(machineInfoVO);
} }
@Override @Override
public void bindingSecretKey(List<Long> machineInfoId,Long secretKeyId) { public void bindingSecretKey(List<Long> machineInfoIds, Long secretKeyId) {
machineInfoMapper.bindingSecretKey(machineInfoId,secretKeyId); machineInfoMapper.bindingSecretKey(machineInfoIds, secretKeyId);
} }
@Override @Override
@ -123,7 +125,7 @@ public class MachineinfoServiceImpl implements MachineInfoService {
validateMachineUnEnable(machineInfoDO); validateMachineUnEnable(machineInfoDO);
log.info("测试机器连接: {}", machineInfoDO.getHostIp()); log.info("测试机器连接: {}", machineInfoDO.getHostIp());
connectionSession.setMachineInfo(machineInfoDO); connectionSession.setMachineInfo(machineInfoDO);
try{ try {
connectionSession.connect(); connectionSession.connect();
return true; return true;
} catch (Exception e) { } catch (Exception e) {
@ -289,56 +291,57 @@ public class MachineinfoServiceImpl implements MachineInfoService {
if (machineInfoVO.getHostIp().isEmpty()) { if (machineInfoVO.getHostIp().isEmpty()) {
throw exception(MACHINE_INFO_HOST_IP_NULL); throw exception(MACHINE_INFO_HOST_IP_NULL);
} }
if (machineInfoVO.getUsername().isEmpty()){ if (machineInfoVO.getUsername().isEmpty()) {
throw exception(MACHINE_INFO_USER_NAME_NULL); throw exception(MACHINE_INFO_USER_NAME_NULL);
} }
if(machineInfoVO.getTag().isEmpty()){ if (machineInfoVO.getTag().isEmpty()) {
throw exception(MACHINE_INFO_TAG_NULL); throw exception(MACHINE_INFO_TAG_NULL);
} }
if (machineInfoVO.getAuthenticationType()!=null){ if (machineInfoVO.getAuthenticationType() != null) {
boolean flag=true; boolean flag = true;
for (int type : AuthenticationType.ARRAYS) { for (int type : AuthenticationType.ARRAYS) {
if (type == machineInfoVO.getAuthenticationType()) { if (type == machineInfoVO.getAuthenticationType()) {
flag=false; flag = false;
break; 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); throw exception(MACHINE_INFO_AUTHENTICATION_TYPE_NULL);
} }
if (machineInfoVO.getMachineInfoType()!= null){ if (machineInfoVO.getMachineInfoType() != null) {
boolean flag = true; boolean flag = true;
for (int type : MachineInfoType.ARRAYS) { for (int type : MachineInfoType.ARRAYS) {
if (type == machineInfoVO.getMachineInfoType()) { if (type == machineInfoVO.getMachineInfoType()) {
flag=false; flag = false;
break; break;
} }
} }
if (flag) { if (flag) {
throw exception(MACHINE_INFO_TYPE_NOT_EXISTS); throw exception(MACHINE_INFO_TYPE_NOT_EXISTS);
} }
}else { } else {
throw exception(MACHINE_INFO_TYPE_NULL); throw exception(MACHINE_INFO_TYPE_NULL);
} }
} }
@VisibleForTesting @VisibleForTesting
void validateMachineTagUnique(String tag){ void validateMachineTagUnique(String tag) {
if (machineInfoMapper.existsByTag(tag)) { if (machineInfoMapper.existsByTag(tag)) {
throw exception(MACHINE_INFO_TAG_EXISTS); throw exception(MACHINE_INFO_TAG_EXISTS);
} }
} }
@VisibleForTesting @VisibleForTesting
MachineInfoDO validateMachineInfoExists(Long id) { MachineInfoDO validateMachineInfoExists(Long id) {
if (id == null) { if (id == null) {
return null; throw exception(MACHINE_INFO_NULL);
} }
MachineInfoDO machineInfoDO = machineInfoMapper.selectById(id); MachineInfoDO machineInfoDO = machineInfoMapper.selectById(id);
if (machineInfoDO == null) { if (machineInfoDO == null) {
@ -346,17 +349,18 @@ public class MachineinfoServiceImpl implements MachineInfoService {
} }
return machineInfoDO; return machineInfoDO;
} }
@VisibleForTesting @VisibleForTesting
void validateMachineEnable(MachineInfoDO machineInfoDO) { void validateMachineEnable(MachineInfoDO machineInfoDO) {
if (machineInfoDO.getStatus() == MachineInfoStatus.ENABLE.getCode()) {
if (machineInfoDO.getStatus()==MachineInfoStatus.ENABLE.getCode()){
throw exception(MACHINE_ENABLE); throw exception(MACHINE_ENABLE);
} }
} }
@VisibleForTesting @VisibleForTesting
void validateMachineUnEnable(MachineInfoDO machineInfoDO) { void validateMachineUnEnable(MachineInfoDO machineInfoDO) {
if (machineInfoDO.getStatus()==MachineInfoStatus.UN_ENABLE.getCode()){ if (machineInfoDO.getStatus() == MachineInfoStatus.UN_ENABLE.getCode()) {
throw exception(MACHINE_UN_ENABLE); throw exception(MACHINE_UN_ENABLE);
} }
} }

View File

@ -1,4 +1,5 @@
package cd.casic.module.machine.service.impl; package cd.casic.module.machine.service.impl;
import cd.casic.framework.commons.pojo.PageResult; import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.commons.util.object.BeanUtils; import cd.casic.framework.commons.util.object.BeanUtils;
import cd.casic.module.machine.controller.vo.SecretKeyVO; import cd.casic.module.machine.controller.vo.SecretKeyVO;
@ -15,6 +16,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception; import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*; import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
@ -34,15 +36,14 @@ public class SecretKeyServiceImpl implements SecretKeyService {
private SecretKeyMapper secretKeyMapper; private SecretKeyMapper secretKeyMapper;
@Override @Override
public SecretKeyVO getSecretKey(Long id){ public SecretKeyVO getSecretKey(Long id) {
SecretKeyDO secretKeyDO = validateSecretKeyExists(id); SecretKeyDO secretKeyDO = validateSecretKeyExists(id);
return BeanUtils.toBean(secretKeyDO, SecretKeyVO.class); return BeanUtils.toBean(secretKeyDO, SecretKeyVO.class);
} }
@Override @Override
public Long createSecretKey(SecretKeyVO secretKeyVO){ public Long createSecretKey(SecretKeyVO secretKeyVO) {
validateSecretKeyAdd(secretKeyVO); validateSecretKeyAdd(secretKeyVO);
String ossPath = upLoadSecretKey(secretKeyVO.getPath()); String ossPath = upLoadSecretKey(secretKeyVO.getPath());
//检查得到的oss路径是否为空 //检查得到的oss路径是否为空
@ -56,6 +57,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
} }
@Override @Override
public void updateSecretKey(SecretKeyVO secretKeyVO) { public void updateSecretKey(SecretKeyVO secretKeyVO) {
SecretKeyDO secretKeyDO = validateSecretKeyExists(secretKeyVO.getId()); SecretKeyDO secretKeyDO = validateSecretKeyExists(secretKeyVO.getId());
@ -65,36 +67,35 @@ public class SecretKeyServiceImpl implements SecretKeyService {
String ossPath = upLoadSecretKey(secretKeyVO.getPath()); String ossPath = upLoadSecretKey(secretKeyVO.getPath());
BeanUtils.copyProperties(secretKeyVO, secretKeyDO); BeanUtils.copyProperties(secretKeyVO, secretKeyDO);
secretKeyDO.setPath(ossPath); secretKeyDO.setPath(ossPath);
} } else {
else { BeanUtils.copyProperties(secretKeyVO, secretKeyDO);
BeanUtils.copyProperties(secretKeyVO,secretKeyDO);
} }
secretKeyMapper.updateById(secretKeyDO); secretKeyMapper.updateById(secretKeyDO);
} }
@Override @Override
public void bindingMachine(Long id,List<Long> machineInfoIds) { public void bindingMachine(SecretKeyVO secretKeyVO) {
validateSecretKeyExists(id); validateSecretKeyExists(secretKeyVO.getId());
machineInfoService.bindingSecretKey(machineInfoIds, id); machineInfoService.bindingSecretKey(secretKeyVO.getMachineInfoIds(), secretKeyVO.getId());
} }
@Override @Override
@Transactional @Transactional
public void deleteSecretKeyList(List<Long> ids) { public void deleteSecretKeyList(List<Long> ids) {
ids.forEach( ids.forEach(
secretKeyId -> { secretKeyId -> {
SecretKeyDO secretKeyDO = validateSecretKeyExists(secretKeyId); SecretKeyDO secretKeyDO = validateSecretKeyExists(secretKeyId);
if (secretKeyDO.getPath() != null && !secretKeyDO.getPath().isEmpty()){ if (secretKeyDO.getPath() != null && !secretKeyDO.getPath().isEmpty()) {
try { try {
//文件名 //文件名
//删除子目录文件需要在前面加上根目录文件路径 //删除子目录文件需要在前面加上根目录文件路径
String fileName = secretKeyDO.getPath().substring(secretKeyDO.getPath().lastIndexOf("/") + 1); String fileName = secretKeyDO.getPath().substring(secretKeyDO.getPath().lastIndexOf("/") + 1);
aliYunOssClient.delete(fileName); aliYunOssClient.delete(fileName);
} catch (Exception e) { } catch (Exception e) {
throw exception(DELETE_FILE_FAIL); throw exception(DELETE_FILE_FAIL);
}
} }
} }
}
); );
//绑定的机器全部设置为空 //绑定的机器全部设置为空
@ -118,7 +119,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
String ossPath; String ossPath;
try { try {
ossPath = aliYunOssClient.upload(content, path, "txt"); ossPath = aliYunOssClient.upload(content, path, "txt");
}catch (Exception e) { } catch (Exception e) {
throw exception(UPLOADING_FILE_FAIL); throw exception(UPLOADING_FILE_FAIL);
} }
return ossPath; return ossPath;
@ -126,7 +127,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
@VisibleForTesting @VisibleForTesting
void validateSecretKeyAdd(SecretKeyVO secretKeyVO) { void validateSecretKeyAdd(SecretKeyVO secretKeyVO) {
if (secretKeyVO==null) { if (secretKeyVO == null) {
throw exception(SECRET_KEY_NULL); throw exception(SECRET_KEY_NULL);
} }
if (secretKeyVO.getPath().isEmpty()) { if (secretKeyVO.getPath().isEmpty()) {
@ -145,7 +146,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
@VisibleForTesting @VisibleForTesting
SecretKeyDO validateSecretKeyExists(Long id) { SecretKeyDO validateSecretKeyExists(Long id) {
if (id == null) { if (id == null) {
return null; throw exception(SECRET_KEY_NOT_EXISTS);
} }
SecretKeyDO secretKeyDO = secretKeyMapper.selectById(id); SecretKeyDO secretKeyDO = secretKeyMapper.selectById(id);
if (secretKeyDO == null) { if (secretKeyDO == null) {