机器环境变量管理规范化
This commit is contained in:
parent
f28fe4ecdf
commit
926c1af1e1
@ -1,126 +1,126 @@
|
||||
package cd.casic.module.machine.controller;
|
||||
|
||||
import cd.casic.framework.commons.pojo.CommonResult;
|
||||
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.utils.PageResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@Tag(name = "机器信息管理")
|
||||
@RequestMapping("/api/machineInfo")
|
||||
public class MachineInfoController {
|
||||
@Resource
|
||||
private MachineInfoService machineInfoService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增机器信息")
|
||||
public CommonResult<Boolean> add(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
return success(machineInfoService.addMachineInfo(machineInfoDto));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "获取机器信息列表")
|
||||
public CommonResult<PageResult<MachineInfoDto>> list(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
return success(machineInfoService.listMachineInfo(machineInfoDto));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "编辑机器信息")
|
||||
public CommonResult<Boolean> update(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
return success(machineInfoService.updateMachineInfo(machineInfoDto));
|
||||
}
|
||||
|
||||
@PutMapping("/updateStatus")
|
||||
@Operation(summary = "机器启用/停用")
|
||||
public CommonResult<Boolean> updateStatus(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
return success(machineInfoService.updateStatus(machineInfoDto));
|
||||
}
|
||||
|
||||
@PutMapping("/bindingSecretKey")
|
||||
@Operation(summary = "绑定密钥")
|
||||
public CommonResult<Boolean> bindingSecretKey(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
return success(machineInfoService.bindingSecretKey(machineInfoDto));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "机器信息删除")
|
||||
public CommonResult<Boolean> delete(@RequestParam Long machineInfoId) {
|
||||
machineInfoService.deleteMachineInfo(machineInfoId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/deleteList")
|
||||
@Operation(summary = "批量删除机器信息")
|
||||
public CommonResult<Boolean> deleteList(@RequestParam String machineInfoIds) {
|
||||
machineInfoService.deleteList(machineInfoIds);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/test")
|
||||
@Operation(summary = "测试机器连接")
|
||||
public CommonResult<Boolean> testConnection(@RequestParam Long id) {
|
||||
return success(machineInfoService.testConnection(id));
|
||||
}
|
||||
|
||||
@GetMapping("/status/{machineName}")
|
||||
@Operation(summary = "获取机器连接状态")
|
||||
public CommonResult<ConnectionStatus> getConnectionStatus(@PathVariable String machineName) {
|
||||
return success(machineInfoService.getConnectionStatus(machineName));
|
||||
}
|
||||
|
||||
@GetMapping("/status/all")
|
||||
@Operation(summary = "获取所有机器连接状态")
|
||||
public CommonResult<Map<String, ConnectionStatus>> getAllConnectionStatus() {
|
||||
return success(machineInfoService.getAllConnectionStatus());
|
||||
}
|
||||
|
||||
@PostMapping("/connect")
|
||||
@Operation(summary = "建立机器连接")
|
||||
public CommonResult<String> connect(@RequestBody MachineInfo machineInfo) {
|
||||
return success(machineInfoService.connect(machineInfo));
|
||||
}
|
||||
|
||||
@PostMapping("/disconnect/{sessionId}")
|
||||
@Operation(summary = "断开机器连接")
|
||||
public CommonResult<Boolean> disconnect(@PathVariable String sessionId) {
|
||||
return success(machineInfoService.disconnect(sessionId));
|
||||
}
|
||||
|
||||
@PostMapping("/execute/{sessionId}")
|
||||
@Operation(summary = "执行远程命令")
|
||||
public CommonResult<String> executeCommand(
|
||||
@PathVariable String sessionId,
|
||||
@RequestBody String command) {
|
||||
|
||||
return success(machineInfoService.executeCommand(sessionId, command));
|
||||
}
|
||||
|
||||
@PostMapping("/upload/{sessionId}")
|
||||
@Operation(summary = "上传文件到远程机器")
|
||||
public CommonResult<Boolean> uploadFile(
|
||||
@PathVariable String sessionId,
|
||||
@RequestParam String localFilePath,
|
||||
@RequestParam String remoteFilePath) {
|
||||
return success(machineInfoService.uploadFile(sessionId, localFilePath, remoteFilePath));
|
||||
}
|
||||
|
||||
@PostMapping("/download/{sessionId}")
|
||||
@Operation(summary = "从远程机器下载文件")
|
||||
public CommonResult<Boolean> downloadFile(
|
||||
@PathVariable String sessionId,
|
||||
@RequestParam String remoteFilePath,
|
||||
@RequestParam String localFilePath) {
|
||||
return success(machineInfoService.downloadFile(sessionId, remoteFilePath, localFilePath));
|
||||
}
|
||||
}
|
||||
//package cd.casic.module.machine.controller;
|
||||
//
|
||||
//import cd.casic.framework.commons.pojo.CommonResult;
|
||||
//import cd.casic.framework.commons.pojo.PageResult;
|
||||
//import cd.casic.module.machine.dal.dataobject.MachineInfo;
|
||||
//import cd.casic.module.machine.enums.ConnectionStatus;
|
||||
//import cd.casic.module.machine.service.MachineInfoService;
|
||||
//import cd.casic.module.machine.controller.vo.MachineInfoDto;
|
||||
//import io.swagger.v3.oas.annotations.Operation;
|
||||
//import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import java.util.Map;
|
||||
//
|
||||
//import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||
//
|
||||
//@RestController
|
||||
//@Tag(name = "机器信息管理")
|
||||
//@RequestMapping("/api/machineInfo")
|
||||
//public class MachineInfoController {
|
||||
// @Resource
|
||||
// private MachineInfoService machineInfoService;
|
||||
//
|
||||
// @PostMapping("/add")
|
||||
// @Operation(summary = "新增机器信息")
|
||||
// public CommonResult<Boolean> add(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
// return success(machineInfoService.addMachineInfo(machineInfoDto));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @PostMapping("/list")
|
||||
// @Operation(summary = "获取机器信息列表")
|
||||
// public CommonResult<PageResult<MachineInfoDto>> list(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
// return success(machineInfoService.listMachineInfo(machineInfoDto));
|
||||
// }
|
||||
//
|
||||
// @PutMapping("/update")
|
||||
// @Operation(summary = "编辑机器信息")
|
||||
// public CommonResult<Boolean> update(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
// return success(machineInfoService.updateMachineInfo(machineInfoDto));
|
||||
// }
|
||||
//
|
||||
// @PutMapping("/updateStatus")
|
||||
// @Operation(summary = "机器启用/停用")
|
||||
// public CommonResult<Boolean> updateStatus(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
// return success(machineInfoService.updateStatus(machineInfoDto));
|
||||
// }
|
||||
//
|
||||
// @PutMapping("/bindingSecretKey")
|
||||
// @Operation(summary = "绑定密钥")
|
||||
// public CommonResult<Boolean> bindingSecretKey(@RequestBody MachineInfoDto machineInfoDto) {
|
||||
// return success(machineInfoService.bindingSecretKey(machineInfoDto));
|
||||
// }
|
||||
//
|
||||
// @DeleteMapping("/delete")
|
||||
// @Operation(summary = "机器信息删除")
|
||||
// public CommonResult<Boolean> delete(@RequestParam Long machineInfoId) {
|
||||
// machineInfoService.deleteMachineInfo(machineInfoId);
|
||||
// return success(true);
|
||||
// }
|
||||
//
|
||||
// @DeleteMapping("/deleteList")
|
||||
// @Operation(summary = "批量删除机器信息")
|
||||
// public CommonResult<Boolean> deleteList(@RequestParam String machineInfoIds) {
|
||||
// machineInfoService.deleteList(machineInfoIds);
|
||||
// return success(true);
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/test")
|
||||
// @Operation(summary = "测试机器连接")
|
||||
// public CommonResult<Boolean> testConnection(@RequestParam Long id) {
|
||||
// return success(machineInfoService.testConnection(id));
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/status/{machineName}")
|
||||
// @Operation(summary = "获取机器连接状态")
|
||||
// public CommonResult<ConnectionStatus> getConnectionStatus(@PathVariable String machineName) {
|
||||
// return success(machineInfoService.getConnectionStatus(machineName));
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/status/all")
|
||||
// @Operation(summary = "获取所有机器连接状态")
|
||||
// public CommonResult<Map<String, ConnectionStatus>> getAllConnectionStatus() {
|
||||
// return success(machineInfoService.getAllConnectionStatus());
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/connect")
|
||||
// @Operation(summary = "建立机器连接")
|
||||
// public CommonResult<String> connect(@RequestBody MachineInfo machineInfo) {
|
||||
// return success(machineInfoService.connect(machineInfo));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/disconnect/{sessionId}")
|
||||
// @Operation(summary = "断开机器连接")
|
||||
// public CommonResult<Boolean> disconnect(@PathVariable String sessionId) {
|
||||
// return success(machineInfoService.disconnect(sessionId));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/execute/{sessionId}")
|
||||
// @Operation(summary = "执行远程命令")
|
||||
// public CommonResult<String> executeCommand(
|
||||
// @PathVariable String sessionId,
|
||||
// @RequestBody String command) {
|
||||
//
|
||||
// return success(machineInfoService.executeCommand(sessionId, command));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/upload/{sessionId}")
|
||||
// @Operation(summary = "上传文件到远程机器")
|
||||
// public CommonResult<Boolean> uploadFile(
|
||||
// @PathVariable String sessionId,
|
||||
// @RequestParam String localFilePath,
|
||||
// @RequestParam String remoteFilePath) {
|
||||
// return success(machineInfoService.uploadFile(sessionId, localFilePath, remoteFilePath));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/download/{sessionId}")
|
||||
// @Operation(summary = "从远程机器下载文件")
|
||||
// public CommonResult<Boolean> downloadFile(
|
||||
// @PathVariable String sessionId,
|
||||
// @RequestParam String remoteFilePath,
|
||||
// @RequestParam String localFilePath) {
|
||||
// return success(machineInfoService.downloadFile(sessionId, remoteFilePath, localFilePath));
|
||||
// }
|
||||
//}
|
||||
|
@ -1,67 +1,67 @@
|
||||
package cd.casic.module.machine.controller;
|
||||
|
||||
import cd.casic.framework.commons.pojo.CommonResult;
|
||||
import cd.casic.module.machine.service.MachineProxyService;
|
||||
import cd.casic.module.machine.dto.MachineProxyDTO;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 机器代理控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/machineProxy")
|
||||
@Tag(name = "机器代理管理")
|
||||
@RequiredArgsConstructor
|
||||
public class MachineProxyController {
|
||||
|
||||
@Resource
|
||||
private MachineProxyService machineProxyService;
|
||||
|
||||
@PostMapping("/register")
|
||||
@Operation(summary = "注册新的机器代理")
|
||||
public CommonResult register(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||
machineProxyService.register(machineProxyDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "获取代理列表")
|
||||
public CommonResult list(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||
return success(machineProxyService.list(machineProxyDTO));
|
||||
}
|
||||
|
||||
@PutMapping("/updateStatus")
|
||||
@Operation(summary = "更新代理状态")
|
||||
public CommonResult updateStatus(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||
machineProxyService.updateStatus(machineProxyDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/statistics/status")
|
||||
@Operation(summary = "获取所有代理的状态统计")
|
||||
public CommonResult getStatusStatistics() {
|
||||
return success(machineProxyService.getStatusStatistics());
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新代理信息")
|
||||
public CommonResult updateConfig(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||
machineProxyService.update(machineProxyDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/batch")
|
||||
@Operation(summary = "批量删除代理")
|
||||
public CommonResult deleteBatch(@RequestParam String ids) {
|
||||
machineProxyService.delete(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
//package cd.casic.module.machine.controller;
|
||||
//
|
||||
//import cd.casic.framework.commons.pojo.CommonResult;
|
||||
//import cd.casic.module.machine.service.MachineProxyService;
|
||||
//import cd.casic.module.machine.controller.vo.MachineProxyDTO;
|
||||
//
|
||||
//import io.swagger.v3.oas.annotations.Operation;
|
||||
//import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||
//
|
||||
///**
|
||||
// * 机器代理控制器
|
||||
// */
|
||||
//@RestController
|
||||
//@RequestMapping("/api/machineProxy")
|
||||
//@Tag(name = "机器代理管理")
|
||||
//@RequiredArgsConstructor
|
||||
//public class MachineProxyController {
|
||||
//
|
||||
// @Resource
|
||||
// private MachineProxyService machineProxyService;
|
||||
//
|
||||
// @PostMapping("/register")
|
||||
// @Operation(summary = "注册新的机器代理")
|
||||
// public CommonResult register(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||
// machineProxyService.register(machineProxyDTO);
|
||||
// return success(true);
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/list")
|
||||
// @Operation(summary = "获取代理列表")
|
||||
// public CommonResult list(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||
// return success(machineProxyService.list(machineProxyDTO));
|
||||
// }
|
||||
//
|
||||
// @PutMapping("/updateStatus")
|
||||
// @Operation(summary = "更新代理状态")
|
||||
// public CommonResult updateStatus(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||
// machineProxyService.updateStatus(machineProxyDTO);
|
||||
// return success(true);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/statistics/status")
|
||||
// @Operation(summary = "获取所有代理的状态统计")
|
||||
// public CommonResult getStatusStatistics() {
|
||||
// return success(machineProxyService.getStatusStatistics());
|
||||
// }
|
||||
//
|
||||
// @PutMapping("/update")
|
||||
// @Operation(summary = "更新代理信息")
|
||||
// public CommonResult updateConfig(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||
// machineProxyService.update(machineProxyDTO);
|
||||
// return success(true);
|
||||
// }
|
||||
//
|
||||
// @DeleteMapping("/batch")
|
||||
// @Operation(summary = "批量删除代理")
|
||||
// public CommonResult deleteBatch(@RequestParam String ids) {
|
||||
// machineProxyService.delete(ids);
|
||||
// return success(true);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,58 +1,56 @@
|
||||
package cd.casic.module.machine.controller;
|
||||
|
||||
import cd.casic.framework.commons.pojo.CommonResult;
|
||||
import cd.casic.module.machine.entity.SecretKey;
|
||||
import cd.casic.module.machine.service.SecretKeyService;
|
||||
import cd.casic.module.machine.dto.SecretKeyDto;
|
||||
import cd.casic.module.machine.utils.PageResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/secretKey")
|
||||
@Tag(name = "密钥管理")
|
||||
public class SecretKeyController {
|
||||
@Resource
|
||||
private SecretKeyService secretKeyService;
|
||||
|
||||
@PostMapping(value = "/add")
|
||||
@Operation(summary = "新增密钥")
|
||||
public CommonResult<Boolean> add(@RequestBody SecretKeyDto secretKeyDto) throws Exception {
|
||||
return success(secretKeyService.addSecretKey(secretKeyDto));
|
||||
}
|
||||
|
||||
@PutMapping("/bindingMachine")
|
||||
@Operation(summary = "绑定机器")
|
||||
public CommonResult<Boolean> bindingMachine(@RequestParam("secretKeyId") Long secretKeyId, @RequestParam("machineIds") List<Long> machineIds) {
|
||||
secretKeyService.bindingMachine(secretKeyId, machineIds);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "编辑密钥信息")
|
||||
public CommonResult<Boolean> update(@RequestBody SecretKeyDto secretKeyDto) {
|
||||
return success(secretKeyService.updateSecretKey(secretKeyDto));
|
||||
}
|
||||
|
||||
@DeleteMapping("/deleteList")
|
||||
@Operation(summary = "批量删除密钥")
|
||||
public CommonResult<Boolean> deleteList(@RequestParam("secretKeyId") List<Long> secretKeyIds) {
|
||||
return success(secretKeyService.deleteList(secretKeyIds));
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "获取密钥信息列表")
|
||||
public CommonResult<PageResult<SecretKey>> list(@RequestBody SecretKeyDto secretKeyDto) {
|
||||
return success(secretKeyService.listSecretKey(secretKeyDto));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package cd.casic.module.machine.controller;
|
||||
//
|
||||
//import cd.casic.framework.commons.pojo.CommonResult;
|
||||
//import cd.casic.framework.commons.pojo.PageResult;
|
||||
//import cd.casic.module.machine.dal.dataobject.SecretKey;
|
||||
//import cd.casic.module.machine.service.SecretKeyService;
|
||||
//import cd.casic.module.machine.controller.vo.SecretKeyDto;
|
||||
//import io.swagger.v3.oas.annotations.Operation;
|
||||
//import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||
//
|
||||
//@RestController
|
||||
//@RequestMapping("/api/secretKey")
|
||||
//@Tag(name = "密钥管理")
|
||||
//public class SecretKeyController {
|
||||
// @Resource
|
||||
// private SecretKeyService secretKeyService;
|
||||
//
|
||||
// @PostMapping(value = "/add")
|
||||
// @Operation(summary = "新增密钥")
|
||||
// public CommonResult<Boolean> add(@RequestBody SecretKeyDto secretKeyDto) throws Exception {
|
||||
// return success(secretKeyService.addSecretKey(secretKeyDto));
|
||||
// }
|
||||
//
|
||||
// @PutMapping("/bindingMachine")
|
||||
// @Operation(summary = "绑定机器")
|
||||
// public CommonResult<Boolean> bindingMachine(@RequestParam("secretKeyId") Long secretKeyId, @RequestParam("machineIds") List<Long> machineIds) {
|
||||
// secretKeyService.bindingMachine(secretKeyId, machineIds);
|
||||
// return success(true);
|
||||
// }
|
||||
//
|
||||
// @PutMapping("/update")
|
||||
// @Operation(summary = "编辑密钥信息")
|
||||
// public CommonResult<Boolean> update(@RequestBody SecretKeyDto secretKeyDto) {
|
||||
// return success(secretKeyService.updateSecretKey(secretKeyDto));
|
||||
// }
|
||||
//
|
||||
// @DeleteMapping("/deleteList")
|
||||
// @Operation(summary = "批量删除密钥")
|
||||
// public CommonResult<Boolean> deleteList(@RequestParam("secretKeyId") List<Long> secretKeyIds) {
|
||||
// return success(secretKeyService.deleteList(secretKeyIds));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/list")
|
||||
// @Operation(summary = "获取密钥信息列表")
|
||||
// public CommonResult<PageResult<SecretKey>> list(@RequestBody SecretKeyDto secretKeyDto) {
|
||||
// return success(secretKeyService.listSecretKey(secretKeyDto));
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cd.casic.module.machine.dto;
|
||||
package cd.casic.module.machine.controller.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
@ -1,4 +1,4 @@
|
||||
package cd.casic.module.machine.dto;
|
||||
package cd.casic.module.machine.controller.vo;
|
||||
|
||||
import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||
import lombok.*;
|
||||
@ -15,7 +15,7 @@ import java.util.Objects;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MachineProxyDTO extends PageDto implements Serializable {
|
||||
public class MachineProxyVO extends PageDto implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
@ -1,10 +1,9 @@
|
||||
package cd.casic.module.machine.dto;
|
||||
package cd.casic.module.machine.controller.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
@ -1,4 +1,4 @@
|
||||
package cd.casic.module.machine.entity;
|
||||
package cd.casic.module.machine.dal.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
@ -1,10 +1,8 @@
|
||||
package cd.casic.module.machine.entity;
|
||||
package cd.casic.module.machine.dal.dataobject;
|
||||
|
||||
import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||
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;
|
@ -1,4 +1,4 @@
|
||||
package cd.casic.module.machine.entity;
|
||||
package cd.casic.module.machine.dal.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
@ -0,0 +1,11 @@
|
||||
package cd.casic.module.machine.dal.mysql;
|
||||
|
||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
|
||||
import cd.casic.module.machine.dal.dataobject.MachineInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface MachineInfoMapper extends BaseMapperX<MachineInfo> {
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package cd.casic.module.machine.mapper;
|
||||
import cd.casic.module.machine.entity.MachineProxy;
|
||||
package cd.casic.module.machine.dal.mysql;
|
||||
import cd.casic.module.machine.dal.dataobject.MachineProxy;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cd.casic.module.machine.mapper;
|
||||
package cd.casic.module.machine.dal.mysql;
|
||||
|
||||
import cd.casic.module.machine.entity.SecretKey;
|
||||
import cd.casic.module.machine.dal.dataobject.SecretKey;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +0,0 @@
|
||||
package cd.casic.module.machine.mapper;
|
||||
|
||||
import cd.casic.module.machine.entity.MachineInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface MachineInfoMapper extends BaseMapper<MachineInfo> {
|
||||
}
|
@ -1,15 +1,14 @@
|
||||
package cd.casic.module.machine.service;
|
||||
|
||||
import cd.casic.module.machine.dto.MachineInfoDto;
|
||||
import cd.casic.module.machine.entity.MachineInfo;
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
import cd.casic.module.machine.controller.vo.MachineInfoDto;
|
||||
import cd.casic.module.machine.dal.dataobject.MachineInfo;
|
||||
import cd.casic.module.machine.enums.ConnectionStatus;
|
||||
import cd.casic.module.machine.utils.PageResult;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface MachineInfoService extends IService<MachineInfo> {
|
||||
public interface MachineInfoService {
|
||||
boolean addMachineInfo(MachineInfoDto MachineInfoDto);
|
||||
|
||||
PageResult<MachineInfoDto> listMachineInfo(MachineInfoDto MachineInfoDto);
|
||||
|
@ -1,11 +1,10 @@
|
||||
package cd.casic.module.machine.service;
|
||||
|
||||
import cd.casic.module.machine.dto.MachineProxyDTO;
|
||||
import cd.casic.module.machine.entity.MachineProxy;
|
||||
import cd.casic.module.machine.utils.PageResult;
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
import cd.casic.module.machine.controller.vo.MachineProxyVO;
|
||||
import cd.casic.module.machine.dal.dataobject.MachineProxy;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -15,12 +14,12 @@ public interface MachineProxyService extends IService<MachineProxy> {
|
||||
/**
|
||||
* 注册新的机器代理
|
||||
*/
|
||||
boolean register(MachineProxyDTO machineProxyDTO);
|
||||
boolean register(MachineProxyVO machineProxyVO);
|
||||
|
||||
/**
|
||||
* 更新代理状态
|
||||
*/
|
||||
boolean updateStatus(MachineProxyDTO machineProxyDTO);
|
||||
boolean updateStatus(MachineProxyVO machineProxyVO);
|
||||
|
||||
|
||||
/**
|
||||
@ -33,7 +32,7 @@ public interface MachineProxyService extends IService<MachineProxy> {
|
||||
/**
|
||||
* 更新代理配置
|
||||
*/
|
||||
void update(MachineProxyDTO machineProxyDTO);
|
||||
void update(MachineProxyVO machineProxyVO);
|
||||
|
||||
|
||||
/**
|
||||
@ -43,5 +42,5 @@ public interface MachineProxyService extends IService<MachineProxy> {
|
||||
*/
|
||||
void delete(String proxyIds);
|
||||
|
||||
PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO);
|
||||
PageResult<MachineProxyVO> list(MachineProxyVO machineProxyVO);
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
package cd.casic.module.machine.service;
|
||||
|
||||
import cd.casic.module.machine.entity.SecretKey;
|
||||
import cd.casic.module.machine.dto.SecretKeyDto;
|
||||
import cd.casic.module.machine.utils.PageResult;
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
import cd.casic.module.machine.dal.dataobject.SecretKey;
|
||||
import cd.casic.module.machine.controller.vo.SecretKeyDto;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -1,162 +1,161 @@
|
||||
package cd.casic.module.machine.service.impl;
|
||||
|
||||
import cd.casic.module.machine.dto.MachineProxyDTO;
|
||||
import cd.casic.module.machine.entity.MachineProxy;
|
||||
import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||
import cd.casic.module.machine.enums.MachineProxyType;
|
||||
import cd.casic.module.machine.exception.ServiceException;
|
||||
import cd.casic.module.machine.mapper.MachineProxyMapper;
|
||||
import cd.casic.module.machine.service.MachineProxyService;
|
||||
import cd.casic.module.machine.utils.EnumUtils;
|
||||
import cd.casic.module.machine.utils.PageResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 机器代理服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, MachineProxy> implements MachineProxyService {
|
||||
@Resource
|
||||
private MachineProxyMapper machineProxyMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean register(MachineProxyDTO machineProxyDTO) {
|
||||
// 创建代理记录
|
||||
MachineProxy proxy = new MachineProxy();
|
||||
BeanUtils.copyProperties(machineProxyDTO, proxy);
|
||||
proxy.setProxyTypeCode(EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
||||
proxy.setVersion("1.0.0");
|
||||
proxy.setStatusCode(MachineProxyStatus.ONLINE.getCode());
|
||||
return save(proxy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateStatus(MachineProxyDTO machineProxyDTO) {
|
||||
// 参数校验
|
||||
if (machineProxyDTO == null) {
|
||||
throw new ServiceException(ServiceException.MACHINE_PROXY_DTO_NULL, "MachineProxyDTO对象为空");
|
||||
}
|
||||
|
||||
// 查询代理
|
||||
MachineProxy proxy = this.getById(machineProxyDTO.getId());
|
||||
|
||||
if (proxy == null) {
|
||||
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL, "代理不存在");
|
||||
}
|
||||
|
||||
// 更新状态
|
||||
proxy.setStatusCode(EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||
proxy.setUpdateDate(new Date());
|
||||
return updateById(proxy);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Long> getStatusStatistics() {
|
||||
List<MachineProxy> proxyList = list();
|
||||
|
||||
if (CollectionUtils.isEmpty(proxyList)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return proxyList.stream()
|
||||
.map(proxy -> EnumUtils.getEnumByCode(proxy.getStatusCode(), MachineProxyStatus.class).getMessage())
|
||||
.collect(Collectors.groupingBy(
|
||||
Function.identity(),
|
||||
Collectors.counting() // 统计每个分组的元素数量
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(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());
|
||||
}
|
||||
if (machineProxyDTO.getStatus() != null && !machineProxyDTO.getStatus().isEmpty()) {
|
||||
machineProxy.setStatusCode(EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||
}
|
||||
this.updateById(machineProxy);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(String ids) {
|
||||
List<Long> machineProxyIds = Arrays.stream(ids.split(","))
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
// 参数校验
|
||||
if (CollectionUtils.isEmpty(machineProxyIds)) {
|
||||
throw new ServiceException(ServiceException.PARAMETER_ERROR, "参数错误");
|
||||
}
|
||||
// 批量逻辑删除
|
||||
remove(new LambdaQueryWrapper<MachineProxy>()
|
||||
.in(MachineProxy::getId, machineProxyIds)
|
||||
.ne(MachineProxy::getStatus, MachineProxyStatus.ONLINE.getCode()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO) {
|
||||
QueryWrapper<MachineProxy> queryWrapper = getMachineProxyQueryWrapper(machineProxyDTO);
|
||||
Page<MachineProxy> page = machineProxyMapper.selectPage(new Page<>(machineProxyDTO.getPageIndex(), machineProxyDTO.getPageSize()), queryWrapper);
|
||||
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.setStatus(EnumUtils.getEnumByCode(machineProxy.getStatusCode(), MachineProxyStatus.class).getMessage());
|
||||
return dto;
|
||||
}).toList();
|
||||
return new PageResult<>(
|
||||
page.getCurrent(),
|
||||
page.getSize(),
|
||||
page.getTotal(),
|
||||
page.getPages(),
|
||||
machineProxyDtos
|
||||
);
|
||||
}
|
||||
|
||||
private QueryWrapper<MachineProxy> getMachineProxyQueryWrapper(MachineProxyDTO machineProxyDTO) {
|
||||
QueryWrapper<MachineProxy> queryWrapper = new QueryWrapper<>();
|
||||
if (machineProxyDTO.getHostIp() != null && !machineProxyDTO.getHostIp().isEmpty()) {
|
||||
queryWrapper.like("host_ip", machineProxyDTO.getHostIp());
|
||||
}
|
||||
if (machineProxyDTO.getSshPort() != null && !machineProxyDTO.getSshPort().isEmpty()) {
|
||||
queryWrapper.like("ssh_port", machineProxyDTO.getSshPort());
|
||||
}
|
||||
if (machineProxyDTO.getUsername() != null && !machineProxyDTO.getUsername().isEmpty()) {
|
||||
queryWrapper.like("username", machineProxyDTO.getUsername());
|
||||
}
|
||||
if (machineProxyDTO.getDescription() != null && !machineProxyDTO.getDescription().isEmpty()) {
|
||||
queryWrapper.like("description", machineProxyDTO.getDescription());
|
||||
}
|
||||
if (machineProxyDTO.getStatus() != null && !machineProxyDTO.getStatus().isEmpty()) {
|
||||
queryWrapper.like("status_code", EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||
}
|
||||
if (machineProxyDTO.getProxyType() != null && !machineProxyDTO.getProxyType().isEmpty()) {
|
||||
queryWrapper.like("proxy_type_code", EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
||||
}
|
||||
return queryWrapper.orderByDesc("create_date");
|
||||
}
|
||||
|
||||
}
|
||||
//package cd.casic.module.machine.service.impl;
|
||||
//
|
||||
//import cd.casic.module.machine.controller.vo.MachineProxyDTO;
|
||||
//import cd.casic.module.machine.dal.dataobject.MachineProxy;
|
||||
//import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||
//import cd.casic.module.machine.enums.MachineProxyType;
|
||||
//import cd.casic.module.machine.exception.ServiceException;
|
||||
//import cd.casic.module.machine.dal.mysql.MachineProxyMapper;
|
||||
//import cd.casic.module.machine.service.MachineProxyService;
|
||||
//import cd.casic.module.machine.utils.EnumUtils;
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
//
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.springframework.beans.BeanUtils;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.transaction.annotation.Transactional;
|
||||
//import org.springframework.util.CollectionUtils;
|
||||
//
|
||||
//import java.util.*;
|
||||
//import java.util.function.Function;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
///**
|
||||
// * 机器代理服务实现类
|
||||
// */
|
||||
//@Service
|
||||
//public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, MachineProxy> implements MachineProxyService {
|
||||
// @Resource
|
||||
// private MachineProxyMapper machineProxyMapper;
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public boolean register(MachineProxyDTO machineProxyDTO) {
|
||||
// // 创建代理记录
|
||||
// MachineProxy proxy = new MachineProxy();
|
||||
// BeanUtils.copyProperties(machineProxyDTO, proxy);
|
||||
// proxy.setProxyTypeCode(EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
||||
// proxy.setVersion("1.0.0");
|
||||
// proxy.setStatusCode(MachineProxyStatus.ONLINE.getCode());
|
||||
// return save(proxy);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean updateStatus(MachineProxyDTO machineProxyDTO) {
|
||||
// // 参数校验
|
||||
// if (machineProxyDTO == null) {
|
||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_DTO_NULL, "MachineProxyDTO对象为空");
|
||||
// }
|
||||
//
|
||||
// // 查询代理
|
||||
// MachineProxy proxy = this.getById(machineProxyDTO.getId());
|
||||
//
|
||||
// if (proxy == null) {
|
||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_NULL, "代理不存在");
|
||||
// }
|
||||
//
|
||||
// // 更新状态
|
||||
// proxy.setStatusCode(EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||
// proxy.setUpdateTime(new Date());
|
||||
// return updateById(proxy);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public Map<String, Long> getStatusStatistics() {
|
||||
// List<MachineProxy> proxyList = list();
|
||||
//
|
||||
// if (CollectionUtils.isEmpty(proxyList)) {
|
||||
// return Collections.emptyMap();
|
||||
// }
|
||||
// return proxyList.stream()
|
||||
// .map(proxy -> EnumUtils.getEnumByCode(proxy.getStatusCode(), MachineProxyStatus.class).getMessage())
|
||||
// .collect(Collectors.groupingBy(
|
||||
// Function.identity(),
|
||||
// Collectors.counting() // 统计每个分组的元素数量
|
||||
// ));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void update(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());
|
||||
// }
|
||||
// if (machineProxyDTO.getStatus() != null && !machineProxyDTO.getStatus().isEmpty()) {
|
||||
// machineProxy.setStatusCode(EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||
// }
|
||||
// this.updateById(machineProxy);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void delete(String ids) {
|
||||
// List<Long> machineProxyIds = Arrays.stream(ids.split(","))
|
||||
// .map(String::trim)
|
||||
// .filter(s -> !s.isEmpty())
|
||||
// .map(Long::parseLong)
|
||||
// .toList();
|
||||
// // 参数校验
|
||||
// if (CollectionUtils.isEmpty(machineProxyIds)) {
|
||||
// throw new ServiceException(ServiceException.PARAMETER_ERROR, "参数错误");
|
||||
// }
|
||||
// // 批量逻辑删除
|
||||
// remove(new LambdaQueryWrapper<MachineProxy>()
|
||||
// .in(MachineProxy::getId, machineProxyIds)
|
||||
// .ne(MachineProxy::getStatus, MachineProxyStatus.ONLINE.getCode()));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO) {
|
||||
// QueryWrapper<MachineProxy> queryWrapper = getMachineProxyQueryWrapper(machineProxyDTO);
|
||||
// Page<MachineProxy> page = machineProxyMapper.selectPage(new Page<>(machineProxyDTO.getPageIndex(), machineProxyDTO.getPageSize()), queryWrapper);
|
||||
// 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.setStatus(EnumUtils.getEnumByCode(machineProxy.getStatusCode(), MachineProxyStatus.class).getMessage());
|
||||
// return dto;
|
||||
// }).toList();
|
||||
// return new PageResult<>(
|
||||
// page.getCurrent(),
|
||||
// page.getSize(),
|
||||
// page.getTotal(),
|
||||
// page.getPages(),
|
||||
// machineProxyDtos
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// private QueryWrapper<MachineProxy> getMachineProxyQueryWrapper(MachineProxyDTO machineProxyDTO) {
|
||||
// QueryWrapper<MachineProxy> queryWrapper = new QueryWrapper<>();
|
||||
// if (machineProxyDTO.getHostIp() != null && !machineProxyDTO.getHostIp().isEmpty()) {
|
||||
// queryWrapper.like("host_ip", machineProxyDTO.getHostIp());
|
||||
// }
|
||||
// if (machineProxyDTO.getSshPort() != null && !machineProxyDTO.getSshPort().isEmpty()) {
|
||||
// queryWrapper.like("ssh_port", machineProxyDTO.getSshPort());
|
||||
// }
|
||||
// if (machineProxyDTO.getUsername() != null && !machineProxyDTO.getUsername().isEmpty()) {
|
||||
// queryWrapper.like("username", machineProxyDTO.getUsername());
|
||||
// }
|
||||
// if (machineProxyDTO.getDescription() != null && !machineProxyDTO.getDescription().isEmpty()) {
|
||||
// queryWrapper.like("description", machineProxyDTO.getDescription());
|
||||
// }
|
||||
// if (machineProxyDTO.getStatus() != null && !machineProxyDTO.getStatus().isEmpty()) {
|
||||
// queryWrapper.like("status_code", EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||
// }
|
||||
// if (machineProxyDTO.getProxyType() != null && !machineProxyDTO.getProxyType().isEmpty()) {
|
||||
// queryWrapper.like("proxy_type_code", EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
||||
// }
|
||||
// return queryWrapper.orderByDesc("create_date");
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,363 +1,354 @@
|
||||
package cd.casic.module.machine.service.impl;
|
||||
|
||||
import cd.casic.module.machine.enums.MachineInfoType;
|
||||
import cd.casic.module.machine.handler.ConnectionSession;
|
||||
import cd.casic.module.machine.mapper.MachineInfoMapper;
|
||||
import cd.casic.module.machine.dto.MachineInfoDto;
|
||||
import cd.casic.module.machine.entity.MachineInfo;
|
||||
import cd.casic.module.machine.enums.AuthenticationType;
|
||||
import cd.casic.module.machine.enums.ConnectionStatus;
|
||||
import cd.casic.module.machine.enums.MachineInfoStatus;
|
||||
import cd.casic.module.machine.exception.ServiceException;
|
||||
import cd.casic.module.machine.service.MachineInfoService;
|
||||
import cd.casic.module.machine.utils.EnumUtils;
|
||||
import cd.casic.module.machine.utils.PageResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
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
|
||||
public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, MachineInfo> implements MachineInfoService {
|
||||
|
||||
int ENABLE = 1;
|
||||
int UN_ENABLE = 0;
|
||||
|
||||
@Resource
|
||||
private MachineInfoMapper machineInfoMapper;
|
||||
@Resource
|
||||
private ConnectionSession connectionSession;
|
||||
/**
|
||||
* 会话ID生成器
|
||||
*/
|
||||
private final AtomicInteger sessionIdGenerator = new AtomicInteger(1000);
|
||||
|
||||
/**
|
||||
* 会话管理:会话ID -> 连接会话
|
||||
*/
|
||||
private final Map<String, ConnectionSession> sessions = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 机器名称 -> 会话ID
|
||||
*/
|
||||
private final Map<String, String> machineSessionMapping = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean addMachineInfo(MachineInfoDto machineInfoDto) {
|
||||
if (machineInfoDto == null) {
|
||||
throw new ServiceException(ServiceException.MACHINE_INFO_NULL, "机器信息为空");
|
||||
}
|
||||
MachineInfo machineInfo = new MachineInfo();
|
||||
BeanUtils.copyProperties(machineInfoDto, machineInfo);
|
||||
machineInfo.setStatusCode(1);
|
||||
machineInfo.setAuthenticationTypeCode(
|
||||
"密码认证".equals(machineInfoDto.getAuthenticationType())
|
||||
? AuthenticationType.PASSWORD.getCode()
|
||||
: AuthenticationType.SECRET_KEY.getCode()
|
||||
);
|
||||
machineInfo.setMachineInfoTypeCode(
|
||||
"Windows".equals(machineInfoDto.getMachineInfoType())
|
||||
? MachineInfoType.WINDOWS.getCode()
|
||||
: MachineInfoType.Linux.getCode()
|
||||
);
|
||||
|
||||
return this.save(machineInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<MachineInfoDto> listMachineInfo(MachineInfoDto machineInfoDto) {
|
||||
QueryWrapper<MachineInfo> queryWrapper = getMachineInfoQueryWrapper(machineInfoDto);
|
||||
Page<MachineInfo> page = machineInfoMapper.selectPage(
|
||||
new Page<>(machineInfoDto.getPageIndex(), machineInfoDto.getPageSize()),
|
||||
queryWrapper
|
||||
);
|
||||
|
||||
List<MachineInfoDto> machineInfoDtos = page.getRecords().stream()
|
||||
.map(machineInfo -> {
|
||||
MachineInfoDto dto = new MachineInfoDto();
|
||||
BeanUtils.copyProperties(machineInfo, dto);
|
||||
// 直接调用原有枚举转换方法
|
||||
dto.setMachineInfoType(EnumUtils.getEnumByCode(machineInfo.getMachineInfoTypeCode(), MachineInfoType.class).getMessage());
|
||||
dto.setStatus(EnumUtils.getEnumByCode(machineInfo.getStatusCode(), MachineInfoStatus.class).getMessage());
|
||||
dto.setAuthenticationType(EnumUtils.getEnumByCode(machineInfo.getAuthenticationTypeCode(), AuthenticationType.class).getMessage());
|
||||
return dto;
|
||||
})
|
||||
.toList();
|
||||
|
||||
return new PageResult<>(
|
||||
page.getCurrent(),
|
||||
page.getSize(),
|
||||
page.getTotal(),
|
||||
page.getPages(),
|
||||
machineInfoDtos
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMachineInfo(MachineInfoDto machineInfoDto) {
|
||||
MachineInfo machineInfo = new MachineInfo();
|
||||
BeanUtils.copyProperties(machineInfoDto, machineInfo);
|
||||
machineInfo.setAuthenticationTypeCode(
|
||||
"密码认证".equals(machineInfoDto.getAuthenticationType())
|
||||
? AuthenticationType.PASSWORD.getCode()
|
||||
: AuthenticationType.SECRET_KEY.getCode()
|
||||
);
|
||||
machineInfo.setMachineInfoTypeCode(
|
||||
"Windows".equals(machineInfoDto.getMachineInfoType())
|
||||
? MachineInfoType.WINDOWS.getCode()
|
||||
: MachineInfoType.Linux.getCode()
|
||||
);
|
||||
return this.updateById(machineInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateStatus(MachineInfoDto machineInfoDto) {
|
||||
UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", machineInfoDto.getId()).set("status_code", EnumUtils.getEnumByMessage(machineInfoDto.getStatus(), MachineInfoStatus.class).getCode());
|
||||
return this.update(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindingSecretKey(MachineInfoDto machineInfoDto) {
|
||||
UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", machineInfoDto.getId()).set("secret_key_id", machineInfoDto.getSecretKeyId()).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 -> {
|
||||
if (machineInfo.getStatusCode() == 1) {
|
||||
this.removeById(machineInfo.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMachineInfo(Long machineInfoId) {
|
||||
MachineInfo machineInfo = this.getById(machineInfoId);
|
||||
if (machineInfo.getStatusCode() == 1) {
|
||||
this.removeById(machineInfoId);
|
||||
}
|
||||
}
|
||||
|
||||
private QueryWrapper<MachineInfo> getMachineInfoQueryWrapper(MachineInfoDto machineInfoDto) {
|
||||
QueryWrapper<MachineInfo> queryWrapper = new QueryWrapper<>();
|
||||
if (machineInfoDto.getStatus() != null && !machineInfoDto.getStatus().isEmpty()) {
|
||||
queryWrapper.eq("status_code", EnumUtils.getEnumByMessage(machineInfoDto.getStatus(), MachineInfoStatus.class).getCode());
|
||||
}
|
||||
if (machineInfoDto.getName() != null && !machineInfoDto.getName().isEmpty()) {
|
||||
queryWrapper.like("name", machineInfoDto.getName());
|
||||
}
|
||||
if (machineInfoDto.getTag() != null && !machineInfoDto.getTag().isEmpty()) {
|
||||
queryWrapper.like("tag", machineInfoDto.getTag());
|
||||
}
|
||||
if (machineInfoDto.getHostIp() != null && !machineInfoDto.getHostIp().isEmpty()) {
|
||||
queryWrapper.like("host_ip", machineInfoDto.getHostIp());
|
||||
}
|
||||
if (machineInfoDto.getDescription() != null && !machineInfoDto.getDescription().isEmpty()) {
|
||||
queryWrapper.like("description", machineInfoDto.getDescription());
|
||||
}
|
||||
return queryWrapper.orderByDesc("create_date");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean testConnection(Long id) {
|
||||
//先查询机器是否存在,在判断机器可用性
|
||||
MachineInfo machineInfo = this.getById(id);
|
||||
if (machineInfo==null){
|
||||
throw new RuntimeException("机器不存在");
|
||||
}
|
||||
if (machineInfo.getStatusCode() == 0) {
|
||||
throw new RuntimeException("机器不可用");
|
||||
}
|
||||
log.info("测试机器连接: {}", machineInfo.getHostIp());
|
||||
connectionSession.setMachineInfo(machineInfo);
|
||||
try{
|
||||
connectionSession.connect();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("机器连接测试失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionStatus getConnectionStatus(String machineName) {
|
||||
String sessionId = machineSessionMapping.get(machineName);
|
||||
if (sessionId == null) {
|
||||
return ConnectionStatus.DISCONNECTED;
|
||||
}
|
||||
|
||||
ConnectionSession session = sessions.get(sessionId);
|
||||
return session != null ? session.getStatus() : ConnectionStatus.DISCONNECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ConnectionStatus> getAllConnectionStatus() {
|
||||
Map<String, ConnectionStatus> result = new HashMap<>();
|
||||
|
||||
machineSessionMapping.forEach((machineName, sessionId) -> {
|
||||
ConnectionSession session = sessions.get(sessionId);
|
||||
result.put(machineName, session != null ? session.getStatus() : ConnectionStatus.DISCONNECTED);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String connect(MachineInfo machineInfo) {
|
||||
if (machineInfo.getStatus().getCode() == UN_ENABLE) {
|
||||
throw new RuntimeException("机器不可用");
|
||||
}
|
||||
log.info("建立机器连接: {}", machineInfo.getHostIp());
|
||||
|
||||
// 检查是否已连接
|
||||
String existingSessionId = machineSessionMapping.get(machineInfo.getName());
|
||||
if (existingSessionId != null) {
|
||||
ConnectionSession existingSession = sessions.get(existingSessionId);
|
||||
if (existingSession != null && existingSession.getStatus() == ConnectionStatus.CONNECTED) {
|
||||
log.info("机器已连接,返回现有会话: {}", machineInfo.getHostIp());
|
||||
return existingSessionId;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
connectionSession.setMachineInfo(machineInfo);
|
||||
|
||||
connectionSession.connect();
|
||||
|
||||
// 生成会话ID
|
||||
String sessionId = generateSessionId();
|
||||
|
||||
// 保存会话
|
||||
sessions.put(sessionId, connectionSession);
|
||||
machineSessionMapping.put(machineInfo.getName(), sessionId);
|
||||
|
||||
log.info("机器连接成功: {}, 会话ID: {}", machineInfo.getHostIp(), sessionId);
|
||||
return sessionId;
|
||||
} catch (Exception e) {
|
||||
log.error("机器连接失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("机器连接失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disconnect(String sessionId) {
|
||||
log.info("断开机器连接: {}", sessionId);
|
||||
|
||||
ConnectionSession session = sessions.get(sessionId);
|
||||
if (session == null) {
|
||||
log.warn("会话不存在: {}", sessionId);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
session.disconnect();
|
||||
|
||||
// 清理会话
|
||||
sessions.remove(sessionId);
|
||||
machineSessionMapping.entrySet().removeIf(entry -> entry.getValue().equals(sessionId));
|
||||
|
||||
log.info("机器连接已断开: {}", sessionId);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("断开连接失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executeCommand(String sessionId, String command) {
|
||||
log.info("执行命令: {}, 会话ID: {}", command, sessionId);
|
||||
|
||||
ConnectionSession session = sessions.get(sessionId);
|
||||
if (session == null) {
|
||||
throw new RuntimeException("会话不存在: " + sessionId);
|
||||
}
|
||||
|
||||
if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
||||
throw new RuntimeException("会话未连接: " + sessionId);
|
||||
}
|
||||
|
||||
try {
|
||||
return session.executeCommand(command);
|
||||
} catch (Exception e) {
|
||||
log.error("命令执行失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("命令执行失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean uploadFile(String sessionId, String localFilePath, String remoteFilePath) {
|
||||
log.info("上传文件: {} -> {}, 会话ID: {}", localFilePath, remoteFilePath, sessionId);
|
||||
|
||||
ConnectionSession session = sessions.get(sessionId);
|
||||
if (session == null) {
|
||||
throw new RuntimeException("会话不存在: " + sessionId);
|
||||
}
|
||||
|
||||
if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
||||
throw new RuntimeException("会话未连接: " + sessionId);
|
||||
}
|
||||
|
||||
try {
|
||||
return session.uploadFile(localFilePath, remoteFilePath);
|
||||
} catch (Exception e) {
|
||||
log.error("文件上传失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("文件上传失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean downloadFile(String sessionId, String remoteFilePath, String localFilePath) {
|
||||
log.info("下载文件: {} -> {}, 会话ID: {}", remoteFilePath, localFilePath, sessionId);
|
||||
|
||||
ConnectionSession session = sessions.get(sessionId);
|
||||
if (session == null) {
|
||||
throw new RuntimeException("会话不存在: " + sessionId);
|
||||
}
|
||||
|
||||
if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
||||
throw new RuntimeException("会话未连接: " + sessionId);
|
||||
}
|
||||
|
||||
try {
|
||||
return session.downloadFile(remoteFilePath, localFilePath);
|
||||
} catch (Exception e) {
|
||||
log.error("文件下载失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("文件下载失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成会话ID
|
||||
*/
|
||||
private String generateSessionId() {
|
||||
return "session-" + sessionIdGenerator.incrementAndGet();
|
||||
}
|
||||
}
|
||||
//package cd.casic.module.machine.service.impl;
|
||||
//import cd.casic.module.machine.enums.MachineInfoType;
|
||||
//import cd.casic.module.machine.handler.ConnectionSession;
|
||||
//import cd.casic.module.machine.dal.mysql.MachineInfoMapper;
|
||||
//import cd.casic.module.machine.controller.vo.MachineInfoDto;
|
||||
//import cd.casic.module.machine.dal.dataobject.MachineInfo;
|
||||
//import cd.casic.module.machine.enums.AuthenticationType;
|
||||
//import cd.casic.module.machine.enums.ConnectionStatus;
|
||||
//import cd.casic.module.machine.enums.MachineInfoStatus;
|
||||
//import cd.casic.module.machine.service.MachineInfoService;
|
||||
//import cd.casic.module.machine.utils.EnumUtils;
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//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("machineInfoService")
|
||||
//public class MachineinfoServiceImpl implements MachineInfoService {
|
||||
//
|
||||
// int ENABLE = 1;
|
||||
// int UN_ENABLE = 0;
|
||||
//
|
||||
// @Resource
|
||||
// private MachineInfoMapper machineInfoMapper;
|
||||
// @Resource
|
||||
// private ConnectionSession connectionSession;
|
||||
// /**
|
||||
// * 会话ID生成器
|
||||
// */
|
||||
// private final AtomicInteger sessionIdGenerator = new AtomicInteger(1000);
|
||||
//
|
||||
// /**
|
||||
// * 会话管理:会话ID -> 连接会话
|
||||
// */
|
||||
// private final Map<String, ConnectionSession> sessions = new ConcurrentHashMap<>();
|
||||
//
|
||||
// /**
|
||||
// * 机器名称 -> 会话ID
|
||||
// */
|
||||
// private final Map<String, String> machineSessionMapping = new ConcurrentHashMap<>();
|
||||
//
|
||||
// @Override
|
||||
// public boolean addMachineInfo(MachineInfoDto machineInfoDto) {
|
||||
// if (machineInfoDto == null) {
|
||||
// throw new ServiceException(ServiceException.MACHINE_INFO_NULL, "机器信息为空");
|
||||
// }
|
||||
// MachineInfo machineInfo = new MachineInfo();
|
||||
// BeanUtils.copyProperties(machineInfoDto, machineInfo);
|
||||
// machineInfo.setStatusCode(1);
|
||||
// machineInfo.setAuthenticationTypeCode(
|
||||
// "密码认证".equals(machineInfoDto.getAuthenticationType())
|
||||
// ? AuthenticationType.PASSWORD.getCode()
|
||||
// : AuthenticationType.SECRET_KEY.getCode()
|
||||
// );
|
||||
// machineInfo.setMachineInfoTypeCode(
|
||||
// "Windows".equals(machineInfoDto.getMachineInfoType())
|
||||
// ? MachineInfoType.WINDOWS.getCode()
|
||||
// : MachineInfoType.Linux.getCode()
|
||||
// );
|
||||
//
|
||||
// return this.save(machineInfo);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public PageResult<MachineInfoDto> listMachineInfo(MachineInfoDto machineInfoDto) {
|
||||
// QueryWrapper<MachineInfo> queryWrapper = getMachineInfoQueryWrapper(machineInfoDto);
|
||||
// Page<MachineInfo> page = machineInfoMapper.selectPage(
|
||||
// new Page<>(machineInfoDto.getPageIndex(), machineInfoDto.getPageSize()),
|
||||
// queryWrapper
|
||||
// );
|
||||
//
|
||||
// List<MachineInfoDto> machineInfoDtos = page.getRecords().stream()
|
||||
// .map(machineInfo -> {
|
||||
// MachineInfoDto dto = new MachineInfoDto();
|
||||
// BeanUtils.copyProperties(machineInfo, dto);
|
||||
// // 直接调用原有枚举转换方法
|
||||
// dto.setMachineInfoType(EnumUtils.getEnumByCode(machineInfo.getMachineInfoTypeCode(), MachineInfoType.class).getMessage());
|
||||
// dto.setStatus(EnumUtils.getEnumByCode(machineInfo.getStatusCode(), MachineInfoStatus.class).getMessage());
|
||||
// dto.setAuthenticationType(EnumUtils.getEnumByCode(machineInfo.getAuthenticationTypeCode(), AuthenticationType.class).getMessage());
|
||||
// return dto;
|
||||
// })
|
||||
// .toList();
|
||||
//
|
||||
// return new PageResult<>(
|
||||
// page.getCurrent(),
|
||||
// page.getSize(),
|
||||
// page.getTotal(),
|
||||
// page.getPages(),
|
||||
// machineInfoDtos
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean updateMachineInfo(MachineInfoDto machineInfoDto) {
|
||||
// MachineInfo machineInfo = new MachineInfo();
|
||||
// BeanUtils.copyProperties(machineInfoDto, machineInfo);
|
||||
// machineInfo.setAuthenticationTypeCode(
|
||||
// "密码认证".equals(machineInfoDto.getAuthenticationType())
|
||||
// ? AuthenticationType.PASSWORD.getCode()
|
||||
// : AuthenticationType.SECRET_KEY.getCode()
|
||||
// );
|
||||
// machineInfo.setMachineInfoTypeCode(
|
||||
// "Windows".equals(machineInfoDto.getMachineInfoType())
|
||||
// ? MachineInfoType.WINDOWS.getCode()
|
||||
// : MachineInfoType.Linux.getCode()
|
||||
// );
|
||||
// return this.updateById(machineInfo);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean updateStatus(MachineInfoDto machineInfoDto) {
|
||||
// UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
|
||||
// updateWrapper.eq("id", machineInfoDto.getId()).set("status_code", EnumUtils.getEnumByMessage(machineInfoDto.getStatus(), MachineInfoStatus.class).getCode());
|
||||
// return this.update(updateWrapper);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean bindingSecretKey(MachineInfoDto machineInfoDto) {
|
||||
// UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
|
||||
// updateWrapper.eq("id", machineInfoDto.getId()).set("secret_key_id", machineInfoDto.getSecretKeyId()).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 -> {
|
||||
// if (machineInfo.getStatusCode() == 1) {
|
||||
// this.removeById(machineInfo.getId());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void deleteMachineInfo(Long machineInfoId) {
|
||||
// MachineInfo machineInfo = this.getById(machineInfoId);
|
||||
// if (machineInfo.getStatusCode() == 1) {
|
||||
// this.removeById(machineInfoId);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private QueryWrapper<MachineInfo> getMachineInfoQueryWrapper(MachineInfoDto machineInfoDto) {
|
||||
// QueryWrapper<MachineInfo> queryWrapper = new QueryWrapper<>();
|
||||
// if (machineInfoDto.getStatus() != null && !machineInfoDto.getStatus().isEmpty()) {
|
||||
// queryWrapper.eq("status_code", EnumUtils.getEnumByMessage(machineInfoDto.getStatus(), MachineInfoStatus.class).getCode());
|
||||
// }
|
||||
// if (machineInfoDto.getName() != null && !machineInfoDto.getName().isEmpty()) {
|
||||
// queryWrapper.like("name", machineInfoDto.getName());
|
||||
// }
|
||||
// if (machineInfoDto.getTag() != null && !machineInfoDto.getTag().isEmpty()) {
|
||||
// queryWrapper.like("tag", machineInfoDto.getTag());
|
||||
// }
|
||||
// if (machineInfoDto.getHostIp() != null && !machineInfoDto.getHostIp().isEmpty()) {
|
||||
// queryWrapper.like("host_ip", machineInfoDto.getHostIp());
|
||||
// }
|
||||
// if (machineInfoDto.getDescription() != null && !machineInfoDto.getDescription().isEmpty()) {
|
||||
// queryWrapper.like("description", machineInfoDto.getDescription());
|
||||
// }
|
||||
// return queryWrapper.orderByDesc("create_date");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public boolean testConnection(Long id) {
|
||||
// //先查询机器是否存在,在判断机器可用性
|
||||
// MachineInfo machineInfo = machineInfoMapper.getById(id);
|
||||
// if (machineInfo==null){
|
||||
// throw new RuntimeException("机器不存在");
|
||||
// }
|
||||
// if (machineInfo.getStatusCode() == 0) {
|
||||
// throw new RuntimeException("机器不可用");
|
||||
// }
|
||||
// log.info("测试机器连接: {}", machineInfo.getHostIp());
|
||||
// connectionSession.setMachineInfo(machineInfo);
|
||||
// try{
|
||||
// connectionSession.connect();
|
||||
// return true;
|
||||
// } catch (Exception e) {
|
||||
// log.error("机器连接测试失败: {}", e.getMessage(), e);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ConnectionStatus getConnectionStatus(String machineName) {
|
||||
// String sessionId = machineSessionMapping.get(machineName);
|
||||
// if (sessionId == null) {
|
||||
// return ConnectionStatus.DISCONNECTED;
|
||||
// }
|
||||
//
|
||||
// ConnectionSession session = sessions.get(sessionId);
|
||||
// return session != null ? session.getStatus() : ConnectionStatus.DISCONNECTED;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Map<String, ConnectionStatus> getAllConnectionStatus() {
|
||||
// Map<String, ConnectionStatus> result = new HashMap<>();
|
||||
//
|
||||
// machineSessionMapping.forEach((machineName, sessionId) -> {
|
||||
// ConnectionSession session = sessions.get(sessionId);
|
||||
// result.put(machineName, session != null ? session.getStatus() : ConnectionStatus.DISCONNECTED);
|
||||
// });
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String connect(MachineInfo machineInfo) {
|
||||
// if (machineInfo.getStatus().getCode() == UN_ENABLE) {
|
||||
// throw new RuntimeException("机器不可用");
|
||||
// }
|
||||
// log.info("建立机器连接: {}", machineInfo.getHostIp());
|
||||
//
|
||||
// // 检查是否已连接
|
||||
// String existingSessionId = machineSessionMapping.get(machineInfo.getName());
|
||||
// if (existingSessionId != null) {
|
||||
// ConnectionSession existingSession = sessions.get(existingSessionId);
|
||||
// if (existingSession != null && existingSession.getStatus() == ConnectionStatus.CONNECTED) {
|
||||
// log.info("机器已连接,返回现有会话: {}", machineInfo.getHostIp());
|
||||
// return existingSessionId;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// connectionSession.setMachineInfo(machineInfo);
|
||||
//
|
||||
// connectionSession.connect();
|
||||
//
|
||||
// // 生成会话ID
|
||||
// String sessionId = generateSessionId();
|
||||
//
|
||||
// // 保存会话
|
||||
// sessions.put(sessionId, connectionSession);
|
||||
// machineSessionMapping.put(machineInfo.getName(), sessionId);
|
||||
//
|
||||
// log.info("机器连接成功: {}, 会话ID: {}", machineInfo.getHostIp(), sessionId);
|
||||
// return sessionId;
|
||||
// } catch (Exception e) {
|
||||
// log.error("机器连接失败: {}", e.getMessage(), e);
|
||||
// throw new RuntimeException("机器连接失败: " + e.getMessage(), e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean disconnect(String sessionId) {
|
||||
// log.info("断开机器连接: {}", sessionId);
|
||||
//
|
||||
// ConnectionSession session = sessions.get(sessionId);
|
||||
// if (session == null) {
|
||||
// log.warn("会话不存在: {}", sessionId);
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// session.disconnect();
|
||||
//
|
||||
// // 清理会话
|
||||
// sessions.remove(sessionId);
|
||||
// machineSessionMapping.entrySet().removeIf(entry -> entry.getValue().equals(sessionId));
|
||||
//
|
||||
// log.info("机器连接已断开: {}", sessionId);
|
||||
// return true;
|
||||
// } catch (Exception e) {
|
||||
// log.error("断开连接失败: {}", e.getMessage(), e);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String executeCommand(String sessionId, String command) {
|
||||
// log.info("执行命令: {}, 会话ID: {}", command, sessionId);
|
||||
//
|
||||
// ConnectionSession session = sessions.get(sessionId);
|
||||
// if (session == null) {
|
||||
// throw new RuntimeException("会话不存在: " + sessionId);
|
||||
// }
|
||||
//
|
||||
// if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
||||
// throw new RuntimeException("会话未连接: " + sessionId);
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// return session.executeCommand(command);
|
||||
// } catch (Exception e) {
|
||||
// log.error("命令执行失败: {}", e.getMessage(), e);
|
||||
// throw new RuntimeException("命令执行失败: " + e.getMessage(), e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean uploadFile(String sessionId, String localFilePath, String remoteFilePath) {
|
||||
// log.info("上传文件: {} -> {}, 会话ID: {}", localFilePath, remoteFilePath, sessionId);
|
||||
//
|
||||
// ConnectionSession session = sessions.get(sessionId);
|
||||
// if (session == null) {
|
||||
// throw new RuntimeException("会话不存在: " + sessionId);
|
||||
// }
|
||||
//
|
||||
// if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
||||
// throw new RuntimeException("会话未连接: " + sessionId);
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// return session.uploadFile(localFilePath, remoteFilePath);
|
||||
// } catch (Exception e) {
|
||||
// log.error("文件上传失败: {}", e.getMessage(), e);
|
||||
// throw new RuntimeException("文件上传失败: " + e.getMessage(), e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean downloadFile(String sessionId, String remoteFilePath, String localFilePath) {
|
||||
// log.info("下载文件: {} -> {}, 会话ID: {}", remoteFilePath, localFilePath, sessionId);
|
||||
//
|
||||
// ConnectionSession session = sessions.get(sessionId);
|
||||
// if (session == null) {
|
||||
// throw new RuntimeException("会话不存在: " + sessionId);
|
||||
// }
|
||||
//
|
||||
// if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
||||
// throw new RuntimeException("会话未连接: " + sessionId);
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// return session.downloadFile(remoteFilePath, localFilePath);
|
||||
// } catch (Exception e) {
|
||||
// log.error("文件下载失败: {}", e.getMessage(), e);
|
||||
// throw new RuntimeException("文件下载失败: " + e.getMessage(), e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 生成会话ID
|
||||
// */
|
||||
// private String generateSessionId() {
|
||||
// return "session-" + sessionIdGenerator.incrementAndGet();
|
||||
// }
|
||||
//}
|
||||
|
@ -1,160 +1,159 @@
|
||||
package cd.casic.module.machine.service.impl;
|
||||
|
||||
import cd.casic.module.machine.dto.SecretKeyDto;
|
||||
import cd.casic.module.machine.entity.MachineInfo;
|
||||
import cd.casic.module.machine.entity.SecretKey;
|
||||
import cd.casic.module.machine.mapper.SecretServiceMapper;
|
||||
import cd.casic.module.machine.service.MachineInfoService;
|
||||
import cd.casic.module.machine.utils.PageResult;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import cd.casic.module.machine.utils.AliYunOssClient;
|
||||
import cd.casic.module.machine.exception.ServiceException;
|
||||
//package cd.casic.module.machine.service.impl;
|
||||
//
|
||||
//import cd.casic.module.machine.controller.vo.SecretKeyDto;
|
||||
//import cd.casic.module.machine.dal.dataobject.MachineInfo;
|
||||
//import cd.casic.module.machine.dal.dataobject.SecretKey;
|
||||
//import cd.casic.module.machine.dal.mysql.SecretServiceMapper;
|
||||
//import cd.casic.module.machine.service.MachineInfoService;
|
||||
import cd.casic.module.machine.service.SecretKeyService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, SecretKey> implements SecretKeyService {
|
||||
|
||||
@Resource
|
||||
private MachineInfoService machineInfoService;
|
||||
|
||||
@Resource
|
||||
private AliYunOssClient aliYunOssClient;
|
||||
|
||||
@Resource
|
||||
private SecretServiceMapper secretServiceMapper;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean addSecretKey(SecretKeyDto secretKeyDto){
|
||||
if (secretKeyDto.getPath()==null)
|
||||
{
|
||||
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥不能为空");
|
||||
}
|
||||
|
||||
String ossPath = upLoadSecretKey(secretKeyDto.getPath());
|
||||
if (ossPath == null){
|
||||
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥上传失败");
|
||||
}
|
||||
secretKeyDto.setPath(ossPath);
|
||||
SecretKey secretKey = new SecretKey();
|
||||
BeanUtils.copyProperties(secretKeyDto,secretKey);
|
||||
//todo检查密钥合法
|
||||
return this.save(secretKey);
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean updateSecretKey(SecretKeyDto secretKeyDto) {
|
||||
|
||||
Long id = secretKeyDto.getId();
|
||||
SecretKey secretKey = this.getById(id);
|
||||
if (secretKey == null){
|
||||
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥不存在");
|
||||
}
|
||||
if (!secretKey.getPath().equals(secretKeyDto.getPath())) {
|
||||
//todo检查密钥合法
|
||||
String ossPath = upLoadSecretKey(secretKeyDto.getPath());
|
||||
BeanUtils.copyProperties(secretKeyDto,secretKey);
|
||||
secretKey.setPath(ossPath);
|
||||
}
|
||||
else {
|
||||
BeanUtils.copyProperties(secretKeyDto,secretKey);
|
||||
}
|
||||
|
||||
return this.updateById(secretKey);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindingMachine(Long secretKeyId, List<Long> machineIds) {
|
||||
SecretKey secretKey = this.getById(secretKeyId);
|
||||
if (secretKey==null){
|
||||
throw new ServiceException(ServiceException.SECRETKEY_NULL,"密钥不存在");
|
||||
}
|
||||
List<MachineInfo> machineList = machineInfoService.listByIds(machineIds);
|
||||
machineList.forEach(machine -> machine.setSecretKeyId(secretKeyId));
|
||||
machineInfoService.updateBatchById(machineList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PageResult<SecretKey> listSecretKey(SecretKeyDto secretKeyDto) {
|
||||
QueryWrapper<SecretKey> queryWrapper = new QueryWrapper<>();
|
||||
if (secretKeyDto.getName() != null && !secretKeyDto.getName().isEmpty()){
|
||||
queryWrapper.like("name", secretKeyDto.getName());
|
||||
}
|
||||
if (secretKeyDto.getDescription() != null && !secretKeyDto.getDescription().isEmpty()){
|
||||
queryWrapper.like("description", secretKeyDto.getDescription());
|
||||
}
|
||||
Page<SecretKey> page = secretServiceMapper.selectPage(new Page<>(secretKeyDto.getPageIndex(), secretKeyDto.getPageSize()), queryWrapper);
|
||||
return new PageResult<>(
|
||||
page.getCurrent(),
|
||||
page.getSize(),
|
||||
page.getTotal(),
|
||||
page.getPages(),
|
||||
page.getRecords()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean deleteList(List<Long> secretKeyIds) {
|
||||
List<SecretKey> secretKeys = this.listByIds(secretKeyIds);
|
||||
|
||||
for (SecretKey secretKey : secretKeys) {
|
||||
if (secretKey.getPath() != null && !secretKey.getPath().isEmpty()){
|
||||
try {
|
||||
//文件名
|
||||
//删除子目录文件,需要在前面加上根目录文件路径
|
||||
String fileName = secretKey.getPath().substring(secretKey.getPath().lastIndexOf("/") + 1);
|
||||
aliYunOssClient.delete(fileName);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//todo是否删除已经绑定的机器
|
||||
return secretServiceMapper.deleteBatchIds(secretKeyIds) > 0 ;
|
||||
}
|
||||
|
||||
|
||||
public String upLoadSecretKey(String localPath) {
|
||||
|
||||
//使用S3FileClient上传文件
|
||||
aliYunOssClient.init();
|
||||
|
||||
//传输到指定文件,需要在path前面加上文件路径
|
||||
String path = IdUtil.fastSimpleUUID() + ".txt";
|
||||
|
||||
|
||||
//上传文件是从本地上传,这里传的是本地文件地址
|
||||
byte[] content = ResourceUtil.readBytes(localPath);
|
||||
String ossPath;
|
||||
try {
|
||||
ossPath = aliYunOssClient.upload(content, path, "txt");
|
||||
}catch (Exception e) {
|
||||
throw new RuntimeException(e+"上传文件失败");
|
||||
}
|
||||
return ossPath;
|
||||
}
|
||||
}
|
||||
//import cn.hutool.core.io.resource.ResourceUtil;
|
||||
//import cn.hutool.core.util.IdUtil;
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
//
|
||||
//import cd.casic.module.machine.utils.AliYunOssClient;
|
||||
//import cd.casic.module.machine.exception.ServiceException;
|
||||
////import cd.casic.module.machine.service.MachineInfoService;
|
||||
//import cd.casic.module.machine.service.SecretKeyService;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.springframework.beans.BeanUtils;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//@Service
|
||||
//public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, SecretKey> implements SecretKeyService {
|
||||
//
|
||||
// @Resource
|
||||
// private MachineInfoService machineInfoService;
|
||||
//
|
||||
// @Resource
|
||||
// private AliYunOssClient aliYunOssClient;
|
||||
//
|
||||
// @Resource
|
||||
// private SecretServiceMapper secretServiceMapper;
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public boolean addSecretKey(SecretKeyDto secretKeyDto){
|
||||
// if (secretKeyDto.getPath()==null)
|
||||
// {
|
||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥不能为空");
|
||||
// }
|
||||
//
|
||||
// String ossPath = upLoadSecretKey(secretKeyDto.getPath());
|
||||
// if (ossPath == null){
|
||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥上传失败");
|
||||
// }
|
||||
// secretKeyDto.setPath(ossPath);
|
||||
// SecretKey secretKey = new SecretKey();
|
||||
// BeanUtils.copyProperties(secretKeyDto,secretKey);
|
||||
// //todo检查密钥合法
|
||||
// return this.save(secretKey);
|
||||
//
|
||||
//
|
||||
// }
|
||||
// @Override
|
||||
// public boolean updateSecretKey(SecretKeyDto secretKeyDto) {
|
||||
//
|
||||
// Long id = secretKeyDto.getId();
|
||||
// SecretKey secretKey = this.getById(id);
|
||||
// if (secretKey == null){
|
||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥不存在");
|
||||
// }
|
||||
// if (!secretKey.getPath().equals(secretKeyDto.getPath())) {
|
||||
// //todo检查密钥合法
|
||||
// String ossPath = upLoadSecretKey(secretKeyDto.getPath());
|
||||
// BeanUtils.copyProperties(secretKeyDto,secretKey);
|
||||
// secretKey.setPath(ossPath);
|
||||
// }
|
||||
// else {
|
||||
// BeanUtils.copyProperties(secretKeyDto,secretKey);
|
||||
// }
|
||||
//
|
||||
// return this.updateById(secretKey);
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void bindingMachine(Long secretKeyId, List<Long> machineIds) {
|
||||
// SecretKey secretKey = this.getById(secretKeyId);
|
||||
// if (secretKey==null){
|
||||
// throw new ServiceException(ServiceException.SECRETKEY_NULL,"密钥不存在");
|
||||
// }
|
||||
// List<MachineInfo> machineList = machineInfoService.listByIds(machineIds);
|
||||
// machineList.forEach(machine -> machine.setSecretKeyId(secretKeyId));
|
||||
// machineInfoService.updateBatchById(machineList);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public PageResult<SecretKey> listSecretKey(SecretKeyDto secretKeyDto) {
|
||||
// QueryWrapper<SecretKey> queryWrapper = new QueryWrapper<>();
|
||||
// if (secretKeyDto.getName() != null && !secretKeyDto.getName().isEmpty()){
|
||||
// queryWrapper.like("name", secretKeyDto.getName());
|
||||
// }
|
||||
// if (secretKeyDto.getDescription() != null && !secretKeyDto.getDescription().isEmpty()){
|
||||
// queryWrapper.like("description", secretKeyDto.getDescription());
|
||||
// }
|
||||
// Page<SecretKey> page = secretServiceMapper.selectPage(new Page<>(secretKeyDto.getPageIndex(), secretKeyDto.getPageSize()), queryWrapper);
|
||||
// return new PageResult<>(
|
||||
// page.getCurrent(),
|
||||
// page.getSize(),
|
||||
// page.getTotal(),
|
||||
// page.getPages(),
|
||||
// page.getRecords()
|
||||
// );
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public boolean deleteList(List<Long> secretKeyIds) {
|
||||
// List<SecretKey> secretKeys = this.listByIds(secretKeyIds);
|
||||
//
|
||||
// for (SecretKey secretKey : secretKeys) {
|
||||
// if (secretKey.getPath() != null && !secretKey.getPath().isEmpty()){
|
||||
// try {
|
||||
// //文件名
|
||||
// //删除子目录文件,需要在前面加上根目录文件路径
|
||||
// String fileName = secretKey.getPath().substring(secretKey.getPath().lastIndexOf("/") + 1);
|
||||
// aliYunOssClient.delete(fileName);
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //todo是否删除已经绑定的机器
|
||||
// return secretServiceMapper.deleteBatchIds(secretKeyIds) > 0 ;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public String upLoadSecretKey(String localPath) {
|
||||
//
|
||||
// //使用S3FileClient上传文件
|
||||
// aliYunOssClient.init();
|
||||
//
|
||||
// //传输到指定文件,需要在path前面加上文件路径
|
||||
// String path = IdUtil.fastSimpleUUID() + ".txt";
|
||||
//
|
||||
//
|
||||
// //上传文件是从本地上传,这里传的是本地文件地址
|
||||
// byte[] content = ResourceUtil.readBytes(localPath);
|
||||
// String ossPath;
|
||||
// try {
|
||||
// ossPath = aliYunOssClient.upload(content, path, "txt");
|
||||
// }catch (Exception e) {
|
||||
// throw new RuntimeException(e+"上传文件失败");
|
||||
// }
|
||||
// return ossPath;
|
||||
// }
|
||||
//}
|
||||
|
Loading…
x
Reference in New Issue
Block a user