Compare commits
No commits in common. "c26a183209721a05f5e43e826f6f7bbcd0d777e1" and "30c201a23075e4699cbd7f4dc925455c75df7a87" have entirely different histories.
c26a183209
...
30c201a230
@ -44,21 +44,23 @@ public class MachineEnvController {
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除机器的环境变量")
|
||||
public CommonResult deleteByMachineId(@RequestParam Long machineEvnId) {
|
||||
machineEnvService.deleteByMachineId(machineEvnId);
|
||||
public CommonResult deleteByMachineId(
|
||||
@RequestParam Long machineId) {
|
||||
machineEnvService.deleteByMachineId(machineId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/deleteList")
|
||||
@Operation(summary = "批量删除机器环境变量")
|
||||
public CommonResult deleteList(@RequestParam String ids){
|
||||
public CommonResult deleteList(@RequestParam List<Long> ids){
|
||||
machineEnvService.deleteList(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/getByMachineId")
|
||||
@Operation(summary = "获取机器的环境变量")
|
||||
public CommonResult getByMachineId(@RequestParam Long machineId) {
|
||||
public CommonResult getByMachineId(
|
||||
@RequestParam Long machineId) {
|
||||
return success(machineEnvService.getByMachineId(machineId));
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import cd.casic.module.machine.entity.MachineInfo;
|
||||
import cd.casic.module.machine.enums.ConnectionStatus;
|
||||
import cd.casic.module.machine.service.MachineInfoService;
|
||||
import cd.casic.module.machine.dto.MachineInfoDto;
|
||||
import cd.casic.module.machine.pojo.SuccessResponseData;
|
||||
|
||||
import cd.casic.module.machine.utils.PageResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -32,7 +33,7 @@ public class MachineInfoController {
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取机器信息列表")
|
||||
public CommonResult<PageResult<MachineInfoDto>> list(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
return success(machineInfoService.listMachineInfo(machineInfoDto));
|
||||
@ -46,26 +47,26 @@ public class MachineInfoController {
|
||||
|
||||
@PutMapping("/updateStatus")
|
||||
@Operation(summary = "机器启用/停用")
|
||||
public CommonResult<Boolean> updateStatus(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
return success(machineInfoService.updateStatus(machineInfoDto));
|
||||
public CommonResult<Boolean> updateStatus(@RequestParam("machineInfoId") Long machineInfoId, @RequestParam("status") String status) {
|
||||
return success(machineInfoService.updateStatus(machineInfoId, status));
|
||||
}
|
||||
|
||||
@PutMapping("/bindingSecretKey")
|
||||
@Operation(summary = "绑定密钥")
|
||||
public CommonResult<Boolean> bindingSecretKey(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
return success(machineInfoService.bindingSecretKey(machineInfoDto));
|
||||
public CommonResult<Boolean> bindingSecretKey(@RequestParam("machineInfoId") Long machineInfoId, @RequestParam("secretKeyId") Long secretKeyId) {
|
||||
return success(machineInfoService.bindingSecretKey(machineInfoId, secretKeyId));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "机器信息删除")
|
||||
public CommonResult<Boolean> delete(@RequestParam Long machineInfoId) {
|
||||
public CommonResult<Boolean> delete(@RequestParam("machineInfoId") Long machineInfoId) {
|
||||
machineInfoService.deleteMachineInfo(machineInfoId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/deleteList")
|
||||
@Operation(summary = "批量删除机器信息")
|
||||
public CommonResult<Boolean> deleteList(@RequestParam String machineInfoIds) {
|
||||
public CommonResult<Boolean> deleteList(@RequestParam("machineInfoIds") List<Long> machineInfoIds) {
|
||||
machineInfoService.deleteList(machineInfoIds);
|
||||
return success(true);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class MachineProxyController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@GetMapping("/list")
|
||||
@Operation(summary ="获取代理列表")
|
||||
public CommonResult list(MachineProxyDTO machineProxyDTO) {
|
||||
return success(machineProxyService.list(machineProxyDTO));
|
||||
@ -52,17 +52,18 @@ public class MachineProxyController {
|
||||
return success(machineProxyService.getStatusStatistics());
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary ="更新代理信息")
|
||||
@PutMapping("/updateConfig")
|
||||
@Operation(summary ="更新代理配置")
|
||||
public CommonResult updateConfig(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||
machineProxyService.update(machineProxyDTO);
|
||||
machineProxyService.updateConfig(machineProxyDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/batch")
|
||||
@Operation(summary ="批量删除代理")
|
||||
public CommonResult deleteBatch(@RequestParam String ids) {
|
||||
return success(machineProxyService.delete(ids));
|
||||
public CommonResult deleteBatch(@RequestParam List<Long> ids) {
|
||||
machineProxyService.delete(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@ -36,8 +38,8 @@ public class SecretKeyController {
|
||||
|
||||
@PutMapping("/bindingMachine")
|
||||
@Operation(summary ="绑定机器")
|
||||
public CommonResult<Boolean> bindingMachine(@RequestBody SecretKeyDto secretKeyDto) {
|
||||
secretKeyService.bindingMachine(secretKeyDto);
|
||||
public CommonResult<Boolean> bindingMachine(@RequestParam("secretKeyId") Long secretKeyId, @RequestParam("machineInfoIds") List<Long> machineInfoIds) {
|
||||
secretKeyService.bindingMachine(secretKeyId, machineInfoIds);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ -50,17 +52,17 @@ public class SecretKeyController {
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary ="删除密钥")
|
||||
public CommonResult<Boolean> delete(@RequestParam Long secretKeyId) {
|
||||
public CommonResult<Boolean> delete(@RequestParam("secretKeyId") Long secretKeyId) {
|
||||
return success(secretKeyService.deleteSecretKey(secretKeyId));
|
||||
}
|
||||
|
||||
@DeleteMapping("/deleteList")
|
||||
@Operation(summary ="批量删除密钥")
|
||||
public CommonResult<Boolean> deleteList(@RequestParam String secretKeyIds) {
|
||||
public CommonResult<Boolean> deleteList(@RequestParam("secretKeyId") List<Long> secretKeyIds) {
|
||||
return success(secretKeyService.deleteList(secretKeyIds));
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@GetMapping("/list")
|
||||
@Operation(summary ="获取密钥信息列表")
|
||||
public CommonResult<PageResult<SecretKey>> list(@RequestBody SecretKeyDto secretKeyDto) {
|
||||
return success(secretKeyService.listSecretKey(secretKeyDto));
|
||||
|
@ -19,10 +19,27 @@ public class MachineEnvDTO extends PageDto implements Serializable {
|
||||
private Long id;
|
||||
private String envKey;
|
||||
private String envValue;
|
||||
private Integer sensitive;//(1敏感,0不敏感)
|
||||
private String description;
|
||||
private Long machineId;
|
||||
private Date createDate;
|
||||
private Date updateDate;
|
||||
private String sortField;
|
||||
private String sortDirection;
|
||||
|
||||
|
||||
/**
|
||||
* 获取脱敏后的环境变量值
|
||||
*/
|
||||
public String getMaskedValue() {
|
||||
if (sensitive==1 || envValue == null) {
|
||||
return envValue;
|
||||
}
|
||||
int length = envValue.length();
|
||||
if (length <= 4) {
|
||||
return "****";
|
||||
} else {
|
||||
return envValue.substring(0, 2) + "****" + envValue.substring(length - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import java.util.Date;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MachineInfoDto extends PageDto {
|
||||
public class MachineInfoDto extends cd.casic.module.machine.dto.PageDto {
|
||||
private Long id;
|
||||
|
||||
private Date createDate;
|
||||
@ -41,6 +41,4 @@ public class MachineInfoDto extends PageDto {
|
||||
private String authenticationType;
|
||||
|
||||
private String machineInfoType;
|
||||
|
||||
private int isProxy;
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ public class MachineProxyDTO extends PageDto implements Serializable {
|
||||
private String version;
|
||||
private String status;
|
||||
private Date lastHeartbeatTime;
|
||||
private String config;
|
||||
private String description;
|
||||
private String hostIp;
|
||||
private String sshPort;
|
||||
private Date createDate;
|
||||
private Date updateDate;
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 计算代理是否在线
|
||||
|
@ -7,7 +7,6 @@ import lombok.NoArgsConstructor;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@ -34,6 +33,4 @@ public class SecretKeyDto extends PageDto {
|
||||
private Date createDate;
|
||||
|
||||
private Date updateDate;
|
||||
|
||||
private List<Long> machineInfoIds;
|
||||
}
|
||||
|
@ -34,6 +34,11 @@ public class MachineEnv extends BaseEntity implements Serializable {
|
||||
*/
|
||||
private String envValue;
|
||||
|
||||
/**
|
||||
* 是否敏感
|
||||
*/
|
||||
@TableField("`sensitive`")
|
||||
private Integer sensitive;//(1敏感,0不敏感)
|
||||
|
||||
/**
|
||||
* 描述信息
|
||||
|
@ -63,7 +63,4 @@ public class MachineInfo extends BaseEntity{
|
||||
|
||||
@TableField(exist = false)
|
||||
private AuthenticationType authenticationType;
|
||||
|
||||
@TableField(value = "is_proxy")
|
||||
private int isProxy;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package cd.casic.module.machine.entity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cd.casic.module.machine.enums.MachineInfoStatus;
|
||||
import cd.casic.module.machine.enums.MachineProxyType;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -20,10 +19,8 @@ import java.util.Date;
|
||||
public class MachineProxy extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableField(value = "host_ip")
|
||||
private String hostIp;
|
||||
|
||||
@TableField(value = "ssh_port")
|
||||
private String sshPort;
|
||||
|
||||
/**
|
||||
@ -32,13 +29,11 @@ public class MachineProxy extends BaseEntity implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private MachineProxyType proxyType;
|
||||
|
||||
@TableField(value = "proxy_type_code")
|
||||
private int proxyTypeCode;
|
||||
|
||||
/**
|
||||
* 代理版本
|
||||
*/
|
||||
@TableField(value = "version")
|
||||
private String version;
|
||||
|
||||
/**
|
||||
@ -47,23 +42,22 @@ public class MachineProxy extends BaseEntity implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private MachineInfoStatus status;
|
||||
|
||||
@TableField(value = "status_code")
|
||||
private int statusCode;
|
||||
|
||||
@TableField(value = "username")
|
||||
private String username;
|
||||
private int statusCode;
|
||||
|
||||
/**
|
||||
* 最后心跳时间
|
||||
*/
|
||||
private Date lastHeartbeatTime;
|
||||
|
||||
@TableField(value = "password")
|
||||
private String password;
|
||||
/**
|
||||
* 代理配置 (JSON格式)
|
||||
*/
|
||||
private String config;
|
||||
|
||||
/**
|
||||
* 描述信息
|
||||
*/
|
||||
@TableField(value = "description")
|
||||
private String description;
|
||||
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package cd.casic.module.machine.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ErrorResponseData extends ResponseData {
|
||||
|
||||
/**
|
||||
* 异常的具体类名称
|
||||
*/
|
||||
private String exceptionClazz;
|
||||
|
||||
public ErrorResponseData(String message) {
|
||||
super(false, DEFAULT_ERROR_CODE, message, null);
|
||||
}
|
||||
|
||||
public ErrorResponseData(Integer code, String message) {
|
||||
super(false, code, message, null);
|
||||
}
|
||||
|
||||
public ErrorResponseData(Integer code, String message, Object object) {
|
||||
super(false, code, message, object);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package cd.casic.module.machine.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 响应结果数据
|
||||
*/
|
||||
@Data
|
||||
public class ResponseData {
|
||||
|
||||
public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功";
|
||||
|
||||
public static final String DEFAULT_ERROR_MESSAGE = "网络异常";
|
||||
|
||||
public static final Integer DEFAULT_SUCCESS_CODE = 200;
|
||||
|
||||
public static final Integer DEFAULT_ERROR_CODE = 500;
|
||||
|
||||
/**
|
||||
* 请求是否成功
|
||||
*/
|
||||
private Boolean success;
|
||||
|
||||
/**
|
||||
* 响应状态码
|
||||
*/
|
||||
private Integer code;
|
||||
|
||||
/**
|
||||
* 响应信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 响应对象
|
||||
*/
|
||||
private Object data;
|
||||
|
||||
public ResponseData() {
|
||||
}
|
||||
|
||||
public ResponseData(Boolean success, Integer code, String message, Object data) {
|
||||
this.success = success;
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static SuccessResponseData success() {
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
public static SuccessResponseData success(Object object) {
|
||||
return new SuccessResponseData(object);
|
||||
}
|
||||
|
||||
public static SuccessResponseData success(Integer code, String message, Object object) {
|
||||
return new SuccessResponseData(code, message, object);
|
||||
}
|
||||
|
||||
public static ErrorResponseData error(String message) {
|
||||
return new ErrorResponseData(message);
|
||||
}
|
||||
|
||||
public static ErrorResponseData error(Integer code, String message) {
|
||||
return new ErrorResponseData(code, message);
|
||||
}
|
||||
|
||||
public static ErrorResponseData error(Integer code, String message, Object object) {
|
||||
return new ErrorResponseData(code, message, object);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package cd.casic.module.machine.pojo;
|
||||
|
||||
public class SuccessResponseData extends ResponseData {
|
||||
|
||||
public SuccessResponseData() {
|
||||
super(true, DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MESSAGE, null);
|
||||
}
|
||||
|
||||
public SuccessResponseData(Object object) {
|
||||
super(true, DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MESSAGE, object);
|
||||
}
|
||||
|
||||
public SuccessResponseData(Integer code, String message, Object object) {
|
||||
super(true, code, message, object);
|
||||
}
|
||||
}
|
@ -18,8 +18,9 @@ public interface MachineEnvService extends IService<MachineEnv> {
|
||||
boolean add(MachineEnvDTO machineEnvDTO);
|
||||
/**
|
||||
* 删除机器的环境变量
|
||||
* @param machineId 机器ID
|
||||
*/
|
||||
void deleteByMachineId(Long machineEvnId);
|
||||
void deleteByMachineId(Long machineId);
|
||||
|
||||
/**
|
||||
* 获取机器的环境变量
|
||||
@ -33,7 +34,7 @@ public interface MachineEnvService extends IService<MachineEnv> {
|
||||
*/
|
||||
PageResult<MachineEnvDTO> listEnv(MachineEnvDTO machineEnvDTO);
|
||||
|
||||
void deleteList(String ids);
|
||||
void deleteList(List<Long> ids);
|
||||
|
||||
boolean update(MachineEnvDTO machineEnvDTO);
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ public interface MachineInfoService extends IService<MachineInfo> {
|
||||
|
||||
boolean updateMachineInfo(MachineInfoDto machineInfoDto);
|
||||
|
||||
boolean updateStatus(MachineInfoDto machineInfoDto);
|
||||
boolean updateStatus(Long machineInfoId, String status);
|
||||
|
||||
boolean bindingSecretKey(MachineInfoDto machineInfoDto);
|
||||
boolean bindingSecretKey( Long machineInfoId, Long secretKeyId);
|
||||
|
||||
void deleteList(String machineInfoIds);
|
||||
void deleteList(List<Long> machineInfoIds);
|
||||
|
||||
void deleteMachineInfo(Long machineInfoId);
|
||||
|
||||
|
@ -33,14 +33,15 @@ public interface MachineProxyService extends IService<MachineProxy> {
|
||||
/**
|
||||
* 更新代理配置
|
||||
*/
|
||||
void update(MachineProxyDTO machineProxyDTO);
|
||||
void updateConfig(MachineProxyDTO machineProxyDTO);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除代理
|
||||
* @param proxyIds 代理ID列表
|
||||
*/
|
||||
String delete(String proxyIds);
|
||||
void delete(List<Long> proxyIds);
|
||||
|
||||
PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
public interface SecretKeyService extends IService<SecretKey> {
|
||||
boolean addSecretKey(SecretKeyDto secretKeyDto, MultipartFile file);
|
||||
|
||||
void bindingMachine(SecretKeyDto secretKeyDto);
|
||||
void bindingMachine(Long secretKeyId, List<Long> machineInfoIds);
|
||||
|
||||
boolean updateSecretKey(SecretKeyDto secretKeyDto,MultipartFile file);
|
||||
|
||||
@ -23,6 +23,6 @@ public interface SecretKeyService extends IService<SecretKey> {
|
||||
|
||||
ResponseEntity<InputStreamResource> downloadSecretKeyFile(Long secretKeyId);
|
||||
|
||||
boolean deleteList(String secretKeyIds);
|
||||
boolean deleteList(List<Long> secretKeyIds);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -50,8 +49,8 @@ public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, Machine
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByMachineId(Long machineEvnId) {
|
||||
this.removeById(machineEvnId);
|
||||
public void deleteByMachineId(Long machineId) {
|
||||
this.removeById(machineId);
|
||||
}
|
||||
|
||||
|
||||
@ -88,6 +87,11 @@ public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, Machine
|
||||
queryWrapper.like(MachineEnv::getMachineId, machineEnvDTO.getMachineId());
|
||||
}
|
||||
|
||||
// 是否敏感
|
||||
if (!StringUtils.isEmpty(machineEnvDTO.getSensitive())) {
|
||||
queryWrapper.eq(MachineEnv::getSensitive, machineEnvDTO.getSensitive());
|
||||
}
|
||||
|
||||
// 创建时间范围查询
|
||||
if (!StringUtils.isEmpty(machineEnvDTO.getCreateDate())) {
|
||||
queryWrapper.ge(MachineEnv::getCreateDate, machineEnvDTO.getCreateDate());
|
||||
@ -129,13 +133,8 @@ public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, Machine
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteList(String ids) {
|
||||
List<Long> machineEnvIds = Arrays.stream(ids.split(","))
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
this.machineEnvMapper.deleteBatchIds(machineEnvIds);
|
||||
public void deleteList(List<Long> ids) {
|
||||
this.machineEnvMapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -151,6 +150,7 @@ public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, Machine
|
||||
dto.setId(machineEnv.getId());
|
||||
dto.setEnvKey(machineEnv.getEnvKey());
|
||||
dto.setEnvValue(machineEnv.getEnvValue());
|
||||
dto.setSensitive(machineEnv.getSensitive());
|
||||
dto.setDescription(machineEnv.getDescription());
|
||||
dto.setCreateDate(machineEnv.getCreateDate());
|
||||
dto.setUpdateDate(machineEnv.getUpdateDate());
|
||||
|
@ -80,56 +80,49 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(MachineProxyDTO machineProxyDTO) {
|
||||
public void updateConfig(MachineProxyDTO machineProxyDTO) {
|
||||
// 参数校验
|
||||
if (machineProxyDTO == null) {
|
||||
throw new ServiceException(ServiceException.MACHINE_PROXY_DTO_NULL,"MachineProxyDTO对象为空");
|
||||
}
|
||||
MachineProxy machineProxy = new MachineProxy();
|
||||
BeanUtils.copyProperties(machineProxyDTO, machineProxy);
|
||||
if (machineProxyDTO.getProxyType()!= null && !machineProxyDTO.getProxyType().isEmpty()){
|
||||
machineProxy.setProxyTypeCode(EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
||||
|
||||
// 查询代理
|
||||
MachineProxy proxy = getById(machineProxyDTO.getId());
|
||||
|
||||
if (proxy == null) {
|
||||
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"代理不存在");
|
||||
}
|
||||
if (machineProxyDTO.getStatus()!= null && !machineProxyDTO.getStatus().isEmpty()){
|
||||
machineProxy.setStatusCode(EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||
}
|
||||
this.updateById(machineProxy);
|
||||
// 更新配置
|
||||
proxy.setConfig(machineProxyDTO.getConfig());
|
||||
proxy.setUpdateDate(new Date());
|
||||
updateById(proxy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String delete(String ids) {
|
||||
List<Long> machineProxyIds = Arrays.stream(ids.split(","))
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
public void delete(List<Long> ids) {
|
||||
// 参数校验
|
||||
if (CollectionUtils.isEmpty(machineProxyIds)) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
throw new ServiceException(ServiceException.PARAMETER_ERROR,"参数错误");
|
||||
}
|
||||
|
||||
// 查询在线代理
|
||||
List<MachineProxy> onlineProxies = list(new LambdaQueryWrapper<MachineProxy>()
|
||||
.in(MachineProxy::getId, machineProxyIds)
|
||||
.in(MachineProxy::getId, ids)
|
||||
.eq(MachineProxy::getStatusCode, MachineProxyStatus.ONLINE.getCode()));
|
||||
|
||||
if (!CollectionUtils.isEmpty(onlineProxies)) {
|
||||
List<Long> onlineIds = onlineProxies.stream()
|
||||
.map(MachineProxy::getId)
|
||||
.toList();
|
||||
|
||||
// 将 [10, 9] 转换为 "10, 9"
|
||||
String idStr = onlineIds.toString().replaceAll("[\\[\\]]", "");
|
||||
return "以下代理处于在线状态,无法删除: " + idStr;
|
||||
.collect(Collectors.toList());
|
||||
throw new IllegalArgumentException("以下代理处于在线状态,无法删除: " + String.join( ",", (CharSequence) onlineIds));
|
||||
}
|
||||
|
||||
// 批量逻辑删除
|
||||
remove(new LambdaQueryWrapper<MachineProxy>()
|
||||
.in(MachineProxy::getId, machineProxyIds));
|
||||
return "";
|
||||
.in(MachineProxy::getId, ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -139,7 +132,7 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
|
||||
List<MachineProxyDTO> machineProxyDtos = page.getRecords().stream().map(machineProxy -> {
|
||||
MachineProxyDTO dto = new MachineProxyDTO();
|
||||
BeanUtils.copyProperties(machineProxy, dto);
|
||||
dto.setProxyType(EnumUtils.getEnumByCode(machineProxy.getProxyTypeCode(), MachineProxyType.class).getMessage());
|
||||
dto.setProxyType(EnumUtils.getEnumByCode(machineProxy.getStatusCode(), MachineProxyType.class).getMessage());
|
||||
dto.setStatus(EnumUtils.getEnumByCode(machineProxy.getStatusCode(), MachineProxyStatus.class).getMessage());
|
||||
return dto;
|
||||
}).toList();
|
||||
@ -155,21 +148,21 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
|
||||
private QueryWrapper<MachineProxy> getMachineProxyQueryWrapper(MachineProxyDTO machineProxyDTO){
|
||||
QueryWrapper<MachineProxy> queryWrapper = new QueryWrapper<>();
|
||||
if (machineProxyDTO.getHostIp() != null && !machineProxyDTO.getHostIp().isEmpty()) {
|
||||
queryWrapper.like("host_ip", machineProxyDTO.getHostIp());
|
||||
queryWrapper.eq("host_ip", machineProxyDTO.getHostIp());
|
||||
}
|
||||
if (machineProxyDTO.getSshPort() != null && !machineProxyDTO.getSshPort().isEmpty()) {
|
||||
queryWrapper.like("ssh_port", machineProxyDTO.getSshPort());
|
||||
queryWrapper.eq("ssh_port", machineProxyDTO.getSshPort());
|
||||
}
|
||||
if (machineProxyDTO.getUsername() != null && !machineProxyDTO.getUsername().isEmpty()) {
|
||||
queryWrapper.like("username", machineProxyDTO.getUsername());
|
||||
queryWrapper.eq("username", machineProxyDTO.getUsername());
|
||||
}
|
||||
if (machineProxyDTO.getDescription() != null && !machineProxyDTO.getDescription().isEmpty()) {
|
||||
queryWrapper.like("description", machineProxyDTO.getDescription());
|
||||
queryWrapper.eq("description", machineProxyDTO.getDescription());
|
||||
}
|
||||
if (machineProxyDTO.getStatus() != null && !machineProxyDTO.getStatus().isEmpty()) {
|
||||
queryWrapper.like("status_code", EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(),MachineProxyStatus.class).getCode());
|
||||
queryWrapper.eq("status_code", EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(),MachineProxyStatus.class).getCode());
|
||||
}
|
||||
return queryWrapper.orderByDesc("create_date");
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,21 +17,16 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -126,27 +121,22 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateStatus(MachineInfoDto machineInfoDto) {
|
||||
public boolean updateStatus(Long machineInfoId, String status) {
|
||||
UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", machineInfoDto.getId()).set("status_code", EnumUtils.getEnumByMessage(machineInfoDto.getStatus(), MachineInfoStatus.class).getCode());
|
||||
updateWrapper.eq("id", machineInfoId).set("status_code", EnumUtils.getEnumByMessage(status, MachineInfoStatus.class).getCode());
|
||||
return this.update(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindingSecretKey(MachineInfoDto machineInfoDto) {
|
||||
public boolean bindingSecretKey(Long machineInfoId, Long secretKeyId) {
|
||||
UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", machineInfoDto.getId()).set("secret_key_id", machineInfoDto.getSecretKeyId()).set("authentication_type_code",2);
|
||||
updateWrapper.eq("id", machineInfoId).set("secret_key_id", secretKeyId).set("authentication_type_code",2);
|
||||
return this.update(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteList(String machineInfoIds) {
|
||||
List<Long> machineInfoIdList = Arrays.stream(machineInfoIds.split(","))
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
machineInfoMapper.selectBatchIds(machineInfoIdList).forEach(machineInfo -> {
|
||||
public void deleteList(List<Long> machineInfoIds) {
|
||||
machineInfoMapper.selectBatchIds(machineInfoIds).forEach(machineInfo -> {
|
||||
if (machineInfo.getStatusCode() == 1){
|
||||
this.removeById(machineInfo.getId());
|
||||
}
|
||||
@ -178,7 +168,7 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
|
||||
if (machineInfoDto.getDescription() != null && !machineInfoDto.getDescription().isEmpty()) {
|
||||
queryWrapper.like("description", machineInfoDto.getDescription());
|
||||
}
|
||||
return queryWrapper.orderByDesc("create_date");
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,7 +23,6 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -62,9 +61,9 @@ public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, Secre
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindingMachine(SecretKeyDto secretKeyDto) {
|
||||
List<MachineInfo> machineInfos = machineInfoService.listByIds(secretKeyDto.getMachineInfoIds());
|
||||
machineInfos.forEach(machineInfo -> machineInfo.setSecretKeyId(secretKeyDto.getId()));
|
||||
public void bindingMachine(Long secretKeyId, List<Long> machineInfoIds) {
|
||||
List<MachineInfo> machineInfos = machineInfoService.listByIds(machineInfoIds);
|
||||
machineInfos.forEach(machineInfo -> machineInfo.setSecretKeyId(secretKeyId));
|
||||
machineInfoService.updateBatchById(machineInfos);
|
||||
}
|
||||
|
||||
@ -98,7 +97,6 @@ public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, Secre
|
||||
if (secretKeyDto.getDescription() != null && !secretKeyDto.getDescription().isEmpty()){
|
||||
queryWrapper.like("description", secretKeyDto.getDescription());
|
||||
}
|
||||
queryWrapper.orderByDesc("create_date");
|
||||
Page<SecretKey> page = secretServiceMapper.selectPage(new Page<>(secretKeyDto.getPageIndex(), secretKeyDto.getPageSize()), queryWrapper);
|
||||
return new PageResult<>(
|
||||
page.getCurrent(),
|
||||
@ -116,12 +114,7 @@ public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, Secre
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteList(String ids) {
|
||||
List<Long> secretKeyIds = Arrays.stream(ids.split(","))
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
public boolean deleteList(List<Long> secretKeyIds) {
|
||||
List<SecretKey> secretKeys = this.listByIds(secretKeyIds);
|
||||
// 提交异步任务到线程池
|
||||
FILE_DELETE_EXECUTOR.execute(() -> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user