Compare commits
No commits in common. "926c1af1e1a5cbc92f9aff8a78a409d28e4332e6" and "56150c156b5131186312b68b7a9eb55b7e2ccd02" have entirely different histories.
926c1af1e1
...
56150c156b
@ -0,0 +1,5 @@
|
|||||||
|
package cd.casic.module.machine.contants;
|
||||||
|
|
||||||
|
public interface CommonConstants {
|
||||||
|
String DEFAULT_PACKAGE_NAME = "com.casic";
|
||||||
|
}
|
@ -1,27 +0,0 @@
|
|||||||
package cd.casic.module.machine.contants;
|
|
||||||
|
|
||||||
import cd.casic.framework.commons.exception.ErrorCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 机器报错
|
|
||||||
*/
|
|
||||||
public interface MachineErrorCodeConstants {
|
|
||||||
// ========== 机器模块 1-003-000-000 ==========
|
|
||||||
ErrorCode MACHINE_INFO_NULL = new ErrorCode(1_003_000_000, "机器信息为空");
|
|
||||||
ErrorCode UPLOADING_FILE_FAIL = new ErrorCode(1_003_000_001, "上传文件失败");
|
|
||||||
ErrorCode DOWNLOAD_FILE_FAIL = new ErrorCode(1_003_000_002, "下载失败");
|
|
||||||
ErrorCode FILENAME_NULL = new ErrorCode(1_003_000_003, "文件名为空");
|
|
||||||
ErrorCode READ_FILE_FAIL = new ErrorCode(1_003_000_004, "读取文件失败");
|
|
||||||
ErrorCode DELETE_FILE_FAIL = new ErrorCode(1_003_000_005, "删除文件失败");
|
|
||||||
ErrorCode MACHINE_PROXY_DTO_NULL = new ErrorCode(1_003_000_006, "MachineProxyDTO对象为空");
|
|
||||||
ErrorCode MACHINE_PROXY_NULL = new ErrorCode(1_003_000_007, "MachineProxy代理不存在");
|
|
||||||
ErrorCode PARAMETER_ERROR = new ErrorCode(1_003_000_008, "参数错误");
|
|
||||||
ErrorCode MACHINE_ENV_NULL = new ErrorCode(1_003_000_009, "机器环境变量为空");
|
|
||||||
ErrorCode MACHINE_ENV_NOT_EXISTS = new ErrorCode(1_003_000_009, "机器不存在");
|
|
||||||
ErrorCode MACHINE_ENV_EXISTS = new ErrorCode(1_003_000_009, "机器已存在");
|
|
||||||
ErrorCode MACHINE_ENV_KEY_ILLEGAL = new ErrorCode(1_003_000_010, "机器环境变量键不合法");
|
|
||||||
ErrorCode OSS_PARAM_NULL = new ErrorCode(1_003_000_011, "oss参数无法读取");
|
|
||||||
ErrorCode SECRETKEY_NULL = new ErrorCode(1_003_000_012, "密钥为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,83 +1,69 @@
|
|||||||
package cd.casic.module.machine.controller;
|
package cd.casic.module.machine.controller;
|
||||||
|
|
||||||
import cd.casic.framework.commons.pojo.CommonResult;
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
|
||||||
import cd.casic.framework.commons.util.object.BeanUtils;
|
|
||||||
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
|
|
||||||
import cd.casic.module.machine.service.MachineEnvService;
|
import cd.casic.module.machine.service.MachineEnvService;
|
||||||
import cd.casic.module.machine.controller.vo.MachineEnvVO;
|
import cd.casic.module.machine.dto.MachineEnvDTO;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 环境变量控制器
|
* 环境变量控制器
|
||||||
*/
|
*/
|
||||||
@Tag(name = "环境变量管理")
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/ci/machineEnv")
|
@RequestMapping("/api/machineEnv")
|
||||||
@Validated
|
@Tag(name = "环境变量管理")
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class MachineEnvController {
|
public class MachineEnvController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MachineEnvService machineEnvService;
|
private MachineEnvService machineEnvService;
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/add")
|
||||||
@Operation(summary = "新增环境变量")
|
@Operation(summary = "新增环境变量")
|
||||||
@PreAuthorize("@ss.hasPermission('ci:machineEnv:create')")
|
public CommonResult add(@RequestBody MachineEnvDTO machineEnvDTO) {
|
||||||
public CommonResult<Long> createEnv(@Valid @RequestBody MachineEnvVO machineEnvVO) {
|
machineEnvService.add(machineEnvDTO);
|
||||||
Long id = machineEnvService.createEnv(machineEnvVO);
|
return success(true);
|
||||||
return success(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "修改环境变量")
|
@Operation(summary = "修改环境变量")
|
||||||
@PreAuthorize("@ss.hasPermission('ci:machineEnv:update')")
|
public CommonResult update(@RequestBody MachineEnvDTO machineEnvDTO) {
|
||||||
public CommonResult<Boolean> updateEnv(@Valid@RequestBody MachineEnvVO machineEnvVO) {
|
machineEnvService.update(machineEnvDTO);
|
||||||
machineEnvService.updateEnv(machineEnvVO);
|
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@Operation(summary = "删除机器的环境变量")
|
@Operation(summary = "删除机器的环境变量")
|
||||||
@PreAuthorize("@ss.hasPermission('ci:machineEnv:delete')")
|
public CommonResult deleteByMachineId(@RequestParam Long machineEvnId) {
|
||||||
public CommonResult<Boolean> deleteEnv(@RequestParam("id") Long id) {
|
machineEnvService.deleteByMachineId(machineEvnId);
|
||||||
machineEnvService.deleteEnv(id);
|
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/deleteList")
|
@DeleteMapping("/deleteList")
|
||||||
@Operation(summary = "批量删除机器环境变量")
|
@Operation(summary = "批量删除机器环境变量")
|
||||||
@PreAuthorize("@ss.hasPermission('ci:machineEnv:delete')")
|
public CommonResult deleteList(@RequestParam String ids) {
|
||||||
public CommonResult<Boolean> deleteEnvList(@RequestParam("ids") String ids) {
|
machineEnvService.deleteList(ids);
|
||||||
machineEnvService.deleteEnvList(ids);
|
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getEnv")
|
@GetMapping("/getByMachineId")
|
||||||
@Operation(summary = "获取机器的环境变量")
|
@Operation(summary = "获取机器的环境变量")
|
||||||
public CommonResult<MachineEnvVO> getEnv(@RequestParam("id") Long id) {
|
public CommonResult getByMachineId(@RequestParam Long machineId) {
|
||||||
MachineEnvVO machineEnvVO = machineEnvService.getEnv(id);
|
return success(machineEnvService.getByMachineId(machineId));
|
||||||
return success(machineEnvVO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
@Operation(summary = "获取环境变量列表")
|
@Operation(summary = "获取环境变量列表")
|
||||||
public CommonResult<PageResult<MachineEnvVO>> getEnvPage(@Valid @RequestBody MachineEnvVO machineEnvVO) {
|
public CommonResult list(@RequestBody MachineEnvDTO machineEnvDTO) {
|
||||||
PageResult<MachineEnvDO> pageResult = machineEnvService.getEnvPage(machineEnvVO);
|
return success(machineEnvService.listEnv(machineEnvDTO));
|
||||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
|
||||||
return success(new PageResult<>(pageResult.getTotal()));
|
|
||||||
}
|
|
||||||
return success(BeanUtils.toBean(pageResult, MachineEnvVO.class));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,126 +1,126 @@
|
|||||||
//package cd.casic.module.machine.controller;
|
package cd.casic.module.machine.controller;
|
||||||
//
|
|
||||||
//import cd.casic.framework.commons.pojo.CommonResult;
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
//import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.module.machine.entity.MachineInfo;
|
||||||
//import cd.casic.module.machine.dal.dataobject.MachineInfo;
|
import cd.casic.module.machine.enums.ConnectionStatus;
|
||||||
//import cd.casic.module.machine.enums.ConnectionStatus;
|
import cd.casic.module.machine.service.MachineInfoService;
|
||||||
//import cd.casic.module.machine.service.MachineInfoService;
|
import cd.casic.module.machine.dto.MachineInfoDto;
|
||||||
//import cd.casic.module.machine.controller.vo.MachineInfoDto;
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
//import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
//import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
//import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
//import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
//
|
|
||||||
//import java.util.Map;
|
import java.util.Map;
|
||||||
//
|
|
||||||
//import static cd.casic.framework.commons.pojo.CommonResult.success;
|
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||||
//
|
|
||||||
//@RestController
|
@RestController
|
||||||
//@Tag(name = "机器信息管理")
|
@Tag(name = "机器信息管理")
|
||||||
//@RequestMapping("/api/machineInfo")
|
@RequestMapping("/api/machineInfo")
|
||||||
//public class MachineInfoController {
|
public class MachineInfoController {
|
||||||
// @Resource
|
@Resource
|
||||||
// private MachineInfoService machineInfoService;
|
private MachineInfoService machineInfoService;
|
||||||
//
|
|
||||||
// @PostMapping("/add")
|
@PostMapping("/add")
|
||||||
// @Operation(summary = "新增机器信息")
|
@Operation(summary = "新增机器信息")
|
||||||
// public CommonResult<Boolean> add(@RequestBody MachineInfoDto machineInfoDto) {
|
public CommonResult<Boolean> add(@RequestBody MachineInfoDto machineInfoDto) {
|
||||||
// return success(machineInfoService.addMachineInfo(machineInfoDto));
|
return success(machineInfoService.addMachineInfo(machineInfoDto));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//
|
|
||||||
// @PostMapping("/list")
|
@PostMapping("/list")
|
||||||
// @Operation(summary = "获取机器信息列表")
|
@Operation(summary = "获取机器信息列表")
|
||||||
// public CommonResult<PageResult<MachineInfoDto>> list(@RequestBody MachineInfoDto machineInfoDto) {
|
public CommonResult<PageResult<MachineInfoDto>> list(@RequestBody MachineInfoDto machineInfoDto) {
|
||||||
// return success(machineInfoService.listMachineInfo(machineInfoDto));
|
return success(machineInfoService.listMachineInfo(machineInfoDto));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PutMapping("/update")
|
@PutMapping("/update")
|
||||||
// @Operation(summary = "编辑机器信息")
|
@Operation(summary = "编辑机器信息")
|
||||||
// public CommonResult<Boolean> update(@RequestBody MachineInfoDto machineInfoDto) {
|
public CommonResult<Boolean> update(@RequestBody MachineInfoDto machineInfoDto) {
|
||||||
// return success(machineInfoService.updateMachineInfo(machineInfoDto));
|
return success(machineInfoService.updateMachineInfo(machineInfoDto));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PutMapping("/updateStatus")
|
@PutMapping("/updateStatus")
|
||||||
// @Operation(summary = "机器启用/停用")
|
@Operation(summary = "机器启用/停用")
|
||||||
// public CommonResult<Boolean> updateStatus(@RequestBody MachineInfoDto machineInfoDto) {
|
public CommonResult<Boolean> updateStatus(@RequestBody MachineInfoDto machineInfoDto) {
|
||||||
// return success(machineInfoService.updateStatus(machineInfoDto));
|
return success(machineInfoService.updateStatus(machineInfoDto));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PutMapping("/bindingSecretKey")
|
@PutMapping("/bindingSecretKey")
|
||||||
// @Operation(summary = "绑定密钥")
|
@Operation(summary = "绑定密钥")
|
||||||
// public CommonResult<Boolean> bindingSecretKey(@RequestBody MachineInfoDto machineInfoDto) {
|
public CommonResult<Boolean> bindingSecretKey(@RequestBody MachineInfoDto machineInfoDto) {
|
||||||
// return success(machineInfoService.bindingSecretKey(machineInfoDto));
|
return success(machineInfoService.bindingSecretKey(machineInfoDto));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @DeleteMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
// @Operation(summary = "机器信息删除")
|
@Operation(summary = "机器信息删除")
|
||||||
// public CommonResult<Boolean> delete(@RequestParam Long machineInfoId) {
|
public CommonResult<Boolean> delete(@RequestParam Long machineInfoId) {
|
||||||
// machineInfoService.deleteMachineInfo(machineInfoId);
|
machineInfoService.deleteMachineInfo(machineInfoId);
|
||||||
// return success(true);
|
return success(true);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @DeleteMapping("/deleteList")
|
@DeleteMapping("/deleteList")
|
||||||
// @Operation(summary = "批量删除机器信息")
|
@Operation(summary = "批量删除机器信息")
|
||||||
// public CommonResult<Boolean> deleteList(@RequestParam String machineInfoIds) {
|
public CommonResult<Boolean> deleteList(@RequestParam String machineInfoIds) {
|
||||||
// machineInfoService.deleteList(machineInfoIds);
|
machineInfoService.deleteList(machineInfoIds);
|
||||||
// return success(true);
|
return success(true);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PostMapping("/test")
|
@PostMapping("/test")
|
||||||
// @Operation(summary = "测试机器连接")
|
@Operation(summary = "测试机器连接")
|
||||||
// public CommonResult<Boolean> testConnection(@RequestParam Long id) {
|
public CommonResult<Boolean> testConnection(@RequestParam Long id) {
|
||||||
// return success(machineInfoService.testConnection(id));
|
return success(machineInfoService.testConnection(id));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @GetMapping("/status/{machineName}")
|
@GetMapping("/status/{machineName}")
|
||||||
// @Operation(summary = "获取机器连接状态")
|
@Operation(summary = "获取机器连接状态")
|
||||||
// public CommonResult<ConnectionStatus> getConnectionStatus(@PathVariable String machineName) {
|
public CommonResult<ConnectionStatus> getConnectionStatus(@PathVariable String machineName) {
|
||||||
// return success(machineInfoService.getConnectionStatus(machineName));
|
return success(machineInfoService.getConnectionStatus(machineName));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @GetMapping("/status/all")
|
@GetMapping("/status/all")
|
||||||
// @Operation(summary = "获取所有机器连接状态")
|
@Operation(summary = "获取所有机器连接状态")
|
||||||
// public CommonResult<Map<String, ConnectionStatus>> getAllConnectionStatus() {
|
public CommonResult<Map<String, ConnectionStatus>> getAllConnectionStatus() {
|
||||||
// return success(machineInfoService.getAllConnectionStatus());
|
return success(machineInfoService.getAllConnectionStatus());
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PostMapping("/connect")
|
@PostMapping("/connect")
|
||||||
// @Operation(summary = "建立机器连接")
|
@Operation(summary = "建立机器连接")
|
||||||
// public CommonResult<String> connect(@RequestBody MachineInfo machineInfo) {
|
public CommonResult<String> connect(@RequestBody MachineInfo machineInfo) {
|
||||||
// return success(machineInfoService.connect(machineInfo));
|
return success(machineInfoService.connect(machineInfo));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PostMapping("/disconnect/{sessionId}")
|
@PostMapping("/disconnect/{sessionId}")
|
||||||
// @Operation(summary = "断开机器连接")
|
@Operation(summary = "断开机器连接")
|
||||||
// public CommonResult<Boolean> disconnect(@PathVariable String sessionId) {
|
public CommonResult<Boolean> disconnect(@PathVariable String sessionId) {
|
||||||
// return success(machineInfoService.disconnect(sessionId));
|
return success(machineInfoService.disconnect(sessionId));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PostMapping("/execute/{sessionId}")
|
@PostMapping("/execute/{sessionId}")
|
||||||
// @Operation(summary = "执行远程命令")
|
@Operation(summary = "执行远程命令")
|
||||||
// public CommonResult<String> executeCommand(
|
public CommonResult<String> executeCommand(
|
||||||
// @PathVariable String sessionId,
|
@PathVariable String sessionId,
|
||||||
// @RequestBody String command) {
|
@RequestBody String command) {
|
||||||
//
|
|
||||||
// return success(machineInfoService.executeCommand(sessionId, command));
|
return success(machineInfoService.executeCommand(sessionId, command));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PostMapping("/upload/{sessionId}")
|
@PostMapping("/upload/{sessionId}")
|
||||||
// @Operation(summary = "上传文件到远程机器")
|
@Operation(summary = "上传文件到远程机器")
|
||||||
// public CommonResult<Boolean> uploadFile(
|
public CommonResult<Boolean> uploadFile(
|
||||||
// @PathVariable String sessionId,
|
@PathVariable String sessionId,
|
||||||
// @RequestParam String localFilePath,
|
@RequestParam String localFilePath,
|
||||||
// @RequestParam String remoteFilePath) {
|
@RequestParam String remoteFilePath) {
|
||||||
// return success(machineInfoService.uploadFile(sessionId, localFilePath, remoteFilePath));
|
return success(machineInfoService.uploadFile(sessionId, localFilePath, remoteFilePath));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PostMapping("/download/{sessionId}")
|
@PostMapping("/download/{sessionId}")
|
||||||
// @Operation(summary = "从远程机器下载文件")
|
@Operation(summary = "从远程机器下载文件")
|
||||||
// public CommonResult<Boolean> downloadFile(
|
public CommonResult<Boolean> downloadFile(
|
||||||
// @PathVariable String sessionId,
|
@PathVariable String sessionId,
|
||||||
// @RequestParam String remoteFilePath,
|
@RequestParam String remoteFilePath,
|
||||||
// @RequestParam String localFilePath) {
|
@RequestParam String localFilePath) {
|
||||||
// return success(machineInfoService.downloadFile(sessionId, remoteFilePath, localFilePath));
|
return success(machineInfoService.downloadFile(sessionId, remoteFilePath, localFilePath));
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
@ -1,67 +1,67 @@
|
|||||||
//package cd.casic.module.machine.controller;
|
package cd.casic.module.machine.controller;
|
||||||
//
|
|
||||||
//import cd.casic.framework.commons.pojo.CommonResult;
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
//import cd.casic.module.machine.service.MachineProxyService;
|
import cd.casic.module.machine.service.MachineProxyService;
|
||||||
//import cd.casic.module.machine.controller.vo.MachineProxyDTO;
|
import cd.casic.module.machine.dto.MachineProxyDTO;
|
||||||
//
|
|
||||||
//import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
//import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
//import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
//import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
//import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
//
|
|
||||||
//import static cd.casic.framework.commons.pojo.CommonResult.success;
|
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * 机器代理控制器
|
* 机器代理控制器
|
||||||
// */
|
*/
|
||||||
//@RestController
|
@RestController
|
||||||
//@RequestMapping("/api/machineProxy")
|
@RequestMapping("/api/machineProxy")
|
||||||
//@Tag(name = "机器代理管理")
|
@Tag(name = "机器代理管理")
|
||||||
//@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
//public class MachineProxyController {
|
public class MachineProxyController {
|
||||||
//
|
|
||||||
// @Resource
|
@Resource
|
||||||
// private MachineProxyService machineProxyService;
|
private MachineProxyService machineProxyService;
|
||||||
//
|
|
||||||
// @PostMapping("/register")
|
@PostMapping("/register")
|
||||||
// @Operation(summary = "注册新的机器代理")
|
@Operation(summary = "注册新的机器代理")
|
||||||
// public CommonResult register(@RequestBody MachineProxyDTO machineProxyDTO) {
|
public CommonResult register(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||||
// machineProxyService.register(machineProxyDTO);
|
machineProxyService.register(machineProxyDTO);
|
||||||
// return success(true);
|
return success(true);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PostMapping("/list")
|
@PostMapping("/list")
|
||||||
// @Operation(summary = "获取代理列表")
|
@Operation(summary = "获取代理列表")
|
||||||
// public CommonResult list(@RequestBody MachineProxyDTO machineProxyDTO) {
|
public CommonResult list(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||||
// return success(machineProxyService.list(machineProxyDTO));
|
return success(machineProxyService.list(machineProxyDTO));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PutMapping("/updateStatus")
|
@PutMapping("/updateStatus")
|
||||||
// @Operation(summary = "更新代理状态")
|
@Operation(summary = "更新代理状态")
|
||||||
// public CommonResult updateStatus(@RequestBody MachineProxyDTO machineProxyDTO) {
|
public CommonResult updateStatus(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||||
// machineProxyService.updateStatus(machineProxyDTO);
|
machineProxyService.updateStatus(machineProxyDTO);
|
||||||
// return success(true);
|
return success(true);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @GetMapping("/statistics/status")
|
@GetMapping("/statistics/status")
|
||||||
// @Operation(summary = "获取所有代理的状态统计")
|
@Operation(summary = "获取所有代理的状态统计")
|
||||||
// public CommonResult getStatusStatistics() {
|
public CommonResult getStatusStatistics() {
|
||||||
// return success(machineProxyService.getStatusStatistics());
|
return success(machineProxyService.getStatusStatistics());
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @PutMapping("/update")
|
@PutMapping("/update")
|
||||||
// @Operation(summary = "更新代理信息")
|
@Operation(summary = "更新代理信息")
|
||||||
// public CommonResult updateConfig(@RequestBody MachineProxyDTO machineProxyDTO) {
|
public CommonResult updateConfig(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||||
// machineProxyService.update(machineProxyDTO);
|
machineProxyService.update(machineProxyDTO);
|
||||||
// return success(true);
|
return success(true);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @DeleteMapping("/batch")
|
@DeleteMapping("/batch")
|
||||||
// @Operation(summary = "批量删除代理")
|
@Operation(summary = "批量删除代理")
|
||||||
// public CommonResult deleteBatch(@RequestParam String ids) {
|
public CommonResult deleteBatch(@RequestParam String ids) {
|
||||||
// machineProxyService.delete(ids);
|
machineProxyService.delete(ids);
|
||||||
// return success(true);
|
return success(true);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//}
|
}
|
||||||
|
@ -1,56 +1,58 @@
|
|||||||
//package cd.casic.module.machine.controller;
|
package cd.casic.module.machine.controller;
|
||||||
//
|
|
||||||
//import cd.casic.framework.commons.pojo.CommonResult;
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
//import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.module.machine.entity.SecretKey;
|
||||||
//import cd.casic.module.machine.dal.dataobject.SecretKey;
|
import cd.casic.module.machine.service.SecretKeyService;
|
||||||
//import cd.casic.module.machine.service.SecretKeyService;
|
import cd.casic.module.machine.dto.SecretKeyDto;
|
||||||
//import cd.casic.module.machine.controller.vo.SecretKeyDto;
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
//import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
//import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
//import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
//import org.springframework.web.bind.annotation.*;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
//
|
import org.springframework.web.bind.annotation.*;
|
||||||
//import java.util.List;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
//
|
|
||||||
//import static cd.casic.framework.commons.pojo.CommonResult.success;
|
import java.util.List;
|
||||||
//
|
|
||||||
//@RestController
|
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||||
//@RequestMapping("/api/secretKey")
|
|
||||||
//@Tag(name = "密钥管理")
|
@RestController
|
||||||
//public class SecretKeyController {
|
@RequestMapping("/api/secretKey")
|
||||||
// @Resource
|
@Tag(name = "密钥管理")
|
||||||
// private SecretKeyService secretKeyService;
|
public class SecretKeyController {
|
||||||
//
|
@Resource
|
||||||
// @PostMapping(value = "/add")
|
private SecretKeyService secretKeyService;
|
||||||
// @Operation(summary = "新增密钥")
|
|
||||||
// public CommonResult<Boolean> add(@RequestBody SecretKeyDto secretKeyDto) throws Exception {
|
@PostMapping(value = "/add")
|
||||||
// return success(secretKeyService.addSecretKey(secretKeyDto));
|
@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) {
|
@PutMapping("/bindingMachine")
|
||||||
// secretKeyService.bindingMachine(secretKeyId, machineIds);
|
@Operation(summary = "绑定机器")
|
||||||
// return success(true);
|
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) {
|
@PutMapping("/update")
|
||||||
// return success(secretKeyService.updateSecretKey(secretKeyDto));
|
@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) {
|
@DeleteMapping("/deleteList")
|
||||||
// return success(secretKeyService.deleteList(secretKeyIds));
|
@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) {
|
@PostMapping("/list")
|
||||||
// return success(secretKeyService.listSecretKey(secretKeyDto));
|
@Operation(summary = "获取密钥信息列表")
|
||||||
// }
|
public CommonResult<PageResult<SecretKey>> list(@RequestBody SecretKeyDto secretKeyDto) {
|
||||||
//
|
return success(secretKeyService.listSecretKey(secretKeyDto));
|
||||||
//
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package cd.casic.module.machine.controller.vo;
|
|
||||||
import cd.casic.framework.commons.pojo.PageParam;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.*;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 机器环境变量信息 Response VO")
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Accessors(chain = true) // 添加链式调用支持
|
|
||||||
public class MachineEnvVO extends PageParam{
|
|
||||||
|
|
||||||
@Schema(description = "环境变量ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Schema(description = "环境变量键", requiredMode = Schema.RequiredMode.REQUIRED, example = "JAVA_HOME")
|
|
||||||
private String envKey;
|
|
||||||
|
|
||||||
@Schema(description = "环境变量值", requiredMode = Schema.RequiredMode.REQUIRED, example = "/usr/java/jdk1.8.0_271")
|
|
||||||
private String envValue;
|
|
||||||
|
|
||||||
@Schema(description = "环境变量描述", example = "Java运行环境路径")
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
@Schema(description = "关联的机器ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
|
||||||
private Long machineId;
|
|
||||||
|
|
||||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2023-06-15T10:30:00")
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
@Schema(description = "更新时间", example = "2023-06-15T10:30:00")
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package cd.casic.module.machine.convert;
|
|
||||||
|
|
||||||
import cd.casic.module.machine.controller.vo.MachineEnvVO;
|
|
||||||
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
@Mapper
|
|
||||||
public interface MachineEnvConvert {
|
|
||||||
|
|
||||||
MachineEnvConvert INSTANCE = Mappers.getMapper(MachineEnvConvert.class);
|
|
||||||
|
|
||||||
// 转换实体为VO
|
|
||||||
default MachineEnvVO convertToVO(MachineEnvDO machineEnvDO) {
|
|
||||||
MachineEnvVO VO = new MachineEnvVO();
|
|
||||||
VO.setId(machineEnvDO.getId());
|
|
||||||
VO.setEnvKey(machineEnvDO.getEnvKey());
|
|
||||||
VO.setEnvValue(machineEnvDO.getEnvValue());
|
|
||||||
VO.setDescription(machineEnvDO.getDescription());
|
|
||||||
VO.setCreateTime(machineEnvDO.getCreateTime());
|
|
||||||
VO.setUpdateTime(machineEnvDO.getUpdateTime());
|
|
||||||
return VO;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package cd.casic.module.machine.dal.mysql;
|
|
||||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
|
||||||
import cd.casic.module.machine.controller.vo.MachineEnvVO;
|
|
||||||
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
|
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
|
||||||
import cd.casic.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 环境变量Mapper接口
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface MachineEnvMapper extends BaseMapperX<MachineEnvDO> {
|
|
||||||
default PageResult<MachineEnvDO>selectPage(MachineEnvVO machineEnvVO){
|
|
||||||
return selectPage(machineEnvVO,new LambdaQueryWrapperX<MachineEnvDO>()
|
|
||||||
.likeIfPresent(MachineEnvDO::getEnvKey, machineEnvVO.getEnvKey())
|
|
||||||
.likeIfPresent(MachineEnvDO::getDescription, machineEnvVO.getDescription())
|
|
||||||
.inIfPresent(MachineEnvDO::getMachineId, machineEnvVO.getMachineId())
|
|
||||||
.orderByDesc( MachineEnvDO::getMachineId));
|
|
||||||
}
|
|
||||||
default void deleteBatchByIds(String ids) {
|
|
||||||
this.delete(new LambdaQueryWrapperX<MachineEnvDO>()
|
|
||||||
.in(MachineEnvDO::getId, ids.split(","))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
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> {
|
|
||||||
}
|
|
@ -0,0 +1,28 @@
|
|||||||
|
package cd.casic.module.machine.dto;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环境变量数据传输对象
|
||||||
|
*/
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MachineEnvDTO extends PageDto implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String envKey;
|
||||||
|
private String envValue;
|
||||||
|
private String description;
|
||||||
|
private Long machineId;
|
||||||
|
private Date createDate;
|
||||||
|
private Date updateDate;
|
||||||
|
private String sortField;
|
||||||
|
private String sortDirection;
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cd.casic.module.machine.controller.vo;
|
package cd.casic.module.machine.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
@ -1,4 +1,4 @@
|
|||||||
package cd.casic.module.machine.controller.vo;
|
package cd.casic.module.machine.dto;
|
||||||
|
|
||||||
import cd.casic.module.machine.enums.MachineProxyStatus;
|
import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
@ -15,7 +15,7 @@ import java.util.Objects;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class MachineProxyVO extends PageDto implements Serializable {
|
public class MachineProxyDTO extends PageDto implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
@ -1,4 +1,4 @@
|
|||||||
package cd.casic.module.machine.controller.vo;
|
package cd.casic.module.machine.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -1,9 +1,10 @@
|
|||||||
package cd.casic.module.machine.controller.vo;
|
package cd.casic.module.machine.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -0,0 +1,28 @@
|
|||||||
|
package cd.casic.module.machine.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class BaseEntity {
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField(value = "create_date")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date createDate;
|
||||||
|
|
||||||
|
@TableField(value = "update_date")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date updateDate;
|
||||||
|
}
|
@ -1,10 +1,8 @@
|
|||||||
package cd.casic.module.machine.dal.dataobject;
|
package cd.casic.module.machine.entity;
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.framework.mybatis.core.dataobject.BaseDO;
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@ -14,20 +12,13 @@ import java.io.Serializable;
|
|||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
|
||||||
@TableName("machine_env")
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class MachineEnvDO extends BaseDO {
|
@TableName("machine_env")
|
||||||
|
public class MachineEnv extends BaseEntity implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 环境变量id
|
|
||||||
*/
|
|
||||||
@TableId
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 机器ID(唯一关联)
|
* 机器ID(唯一关联)
|
||||||
*/
|
*/
|
@ -1,4 +1,4 @@
|
|||||||
package cd.casic.module.machine.dal.dataobject;
|
package cd.casic.module.machine.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
@ -1,8 +1,10 @@
|
|||||||
package cd.casic.module.machine.dal.dataobject;
|
package cd.casic.module.machine.entity;
|
||||||
|
|
||||||
import cd.casic.module.machine.enums.MachineProxyStatus;
|
import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import cd.casic.module.machine.enums.MachineInfoStatus;
|
||||||
import cd.casic.module.machine.enums.MachineProxyType;
|
import cd.casic.module.machine.enums.MachineProxyType;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
@ -1,4 +1,4 @@
|
|||||||
package cd.casic.module.machine.dal.dataobject;
|
package cd.casic.module.machine.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
@ -0,0 +1,55 @@
|
|||||||
|
package cd.casic.module.machine.exception;
|
||||||
|
|
||||||
|
import cd.casic.module.machine.entity.SecretKey;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务逻辑异常 Exception
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ServiceException extends RuntimeException {
|
||||||
|
//机器信息为空
|
||||||
|
public static final int MACHINE_INFO_NULL = 555;
|
||||||
|
//上传文件失败
|
||||||
|
public static final int UPLOADING_FILE_FAIL = 556;
|
||||||
|
//下载失败
|
||||||
|
public static final int DOWNLOAD_FILE_FAIL = 557;
|
||||||
|
//文件名为空
|
||||||
|
public static final int FILENAME_NULL = 558;
|
||||||
|
//读取文件失败
|
||||||
|
public static final int READ_FILE_FAIL = 559;
|
||||||
|
//删除文件失败
|
||||||
|
public static final int DELETE_FILE_FAIL = 560;
|
||||||
|
//MachineProxyDTO对象为空
|
||||||
|
public static final int MACHINE_PROXY_DTO_NULL = 561;
|
||||||
|
//MachineProxy代理不存在
|
||||||
|
public static final int MACHINE_PROXY_NULL = 562;
|
||||||
|
//参数错误
|
||||||
|
public static final int PARAMETER_ERROR = 563;
|
||||||
|
//机器环境变量为空
|
||||||
|
public static final int MACHINE_ENV_NULL = 564;
|
||||||
|
//机器环境变量键不合法
|
||||||
|
public static final int MACHINE_ENV_KEY_ILLEGAL = 565;
|
||||||
|
//oss参数无法读取
|
||||||
|
public static final int OSS_PARAM_NULL = 1001;
|
||||||
|
//密钥为空
|
||||||
|
public static final int SECRETKEY_NULL = 1002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务错误码
|
||||||
|
* 区间
|
||||||
|
* machine-management-module模块(555-1000)
|
||||||
|
* common-module模块(1001-2000)
|
||||||
|
*/
|
||||||
|
private Integer code;
|
||||||
|
/**
|
||||||
|
* 错误提示
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,14 @@
|
|||||||
|
package cd.casic.module.machine.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import cd.casic.module.machine.entity.MachineEnv;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环境变量Mapper接口
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface MachineEnvMapper extends BaseMapper<MachineEnv> {
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
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,5 +1,5 @@
|
|||||||
package cd.casic.module.machine.dal.mysql;
|
package cd.casic.module.machine.mapper;
|
||||||
import cd.casic.module.machine.dal.dataobject.MachineProxy;
|
import cd.casic.module.machine.entity.MachineProxy;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package cd.casic.module.machine.dal.mysql;
|
package cd.casic.module.machine.mapper;
|
||||||
|
|
||||||
import cd.casic.module.machine.dal.dataobject.SecretKey;
|
import cd.casic.module.machine.entity.SecretKey;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
@ -1,23 +1,26 @@
|
|||||||
package cd.casic.module.machine.service;
|
package cd.casic.module.machine.service;
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
|
||||||
import cd.casic.module.machine.controller.vo.MachineEnvVO;
|
import cd.casic.module.machine.entity.MachineEnv;
|
||||||
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
|
import cd.casic.module.machine.dto.MachineEnvDTO;
|
||||||
import jakarta.validation.Valid;
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 环境变量服务接口
|
* 环境变量服务接口
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface MachineEnvService {
|
public interface MachineEnvService extends IService<MachineEnv> {
|
||||||
/**
|
/**
|
||||||
* 创建或更新机器的环境变量(一对一关系)
|
* 创建或更新机器的环境变量(一对一关系)
|
||||||
*/
|
*/
|
||||||
Long createEnv(@Valid MachineEnvVO machineEnvVO);
|
boolean add(MachineEnvDTO machineEnvDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除机器的环境变量
|
* 删除机器的环境变量
|
||||||
*/
|
*/
|
||||||
void deleteEnv(Long machineEvnId);
|
void deleteByMachineId(Long machineEvnId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取机器的环境变量
|
* 获取机器的环境变量
|
||||||
@ -25,20 +28,14 @@ public interface MachineEnvService {
|
|||||||
* @param machineId 机器ID
|
* @param machineId 机器ID
|
||||||
* @return 环境变量DTO
|
* @return 环境变量DTO
|
||||||
*/
|
*/
|
||||||
MachineEnvVO getEnv(Long machineId);
|
MachineEnvDTO getByMachineId(Long machineId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 环境变量列表
|
* @return 环境变量列表
|
||||||
*/
|
*/
|
||||||
PageResult<MachineEnvDO> getEnvPage(@Valid MachineEnvVO machineEnvVO);
|
PageResult<MachineEnvDTO> listEnv(MachineEnvDTO machineEnvDTO);
|
||||||
|
|
||||||
/**
|
void deleteList(String ids);
|
||||||
* 批量删除
|
|
||||||
*/
|
|
||||||
void deleteEnvList(String ids);
|
|
||||||
|
|
||||||
/*
|
boolean update(MachineEnvDTO machineEnvDTO);
|
||||||
* 修改环境变量
|
|
||||||
*/
|
|
||||||
void updateEnv(@Valid MachineEnvVO machineEnvVO);
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
package cd.casic.module.machine.service;
|
package cd.casic.module.machine.service;
|
||||||
|
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.module.machine.dto.MachineInfoDto;
|
||||||
import cd.casic.module.machine.controller.vo.MachineInfoDto;
|
import cd.casic.module.machine.entity.MachineInfo;
|
||||||
import cd.casic.module.machine.dal.dataobject.MachineInfo;
|
|
||||||
import cd.casic.module.machine.enums.ConnectionStatus;
|
import cd.casic.module.machine.enums.ConnectionStatus;
|
||||||
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface MachineInfoService {
|
public interface MachineInfoService extends IService<MachineInfo> {
|
||||||
boolean addMachineInfo(MachineInfoDto MachineInfoDto);
|
boolean addMachineInfo(MachineInfoDto MachineInfoDto);
|
||||||
|
|
||||||
PageResult<MachineInfoDto> listMachineInfo(MachineInfoDto MachineInfoDto);
|
PageResult<MachineInfoDto> listMachineInfo(MachineInfoDto MachineInfoDto);
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package cd.casic.module.machine.service;
|
package cd.casic.module.machine.service;
|
||||||
|
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.module.machine.dto.MachineProxyDTO;
|
||||||
import cd.casic.module.machine.controller.vo.MachineProxyVO;
|
import cd.casic.module.machine.entity.MachineProxy;
|
||||||
import cd.casic.module.machine.dal.dataobject.MachineProxy;
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,12 +15,12 @@ public interface MachineProxyService extends IService<MachineProxy> {
|
|||||||
/**
|
/**
|
||||||
* 注册新的机器代理
|
* 注册新的机器代理
|
||||||
*/
|
*/
|
||||||
boolean register(MachineProxyVO machineProxyVO);
|
boolean register(MachineProxyDTO machineProxyDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新代理状态
|
* 更新代理状态
|
||||||
*/
|
*/
|
||||||
boolean updateStatus(MachineProxyVO machineProxyVO);
|
boolean updateStatus(MachineProxyDTO machineProxyDTO);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +33,7 @@ public interface MachineProxyService extends IService<MachineProxy> {
|
|||||||
/**
|
/**
|
||||||
* 更新代理配置
|
* 更新代理配置
|
||||||
*/
|
*/
|
||||||
void update(MachineProxyVO machineProxyVO);
|
void update(MachineProxyDTO machineProxyDTO);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,5 +43,5 @@ public interface MachineProxyService extends IService<MachineProxy> {
|
|||||||
*/
|
*/
|
||||||
void delete(String proxyIds);
|
void delete(String proxyIds);
|
||||||
|
|
||||||
PageResult<MachineProxyVO> list(MachineProxyVO machineProxyVO);
|
PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package cd.casic.module.machine.service;
|
package cd.casic.module.machine.service;
|
||||||
|
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.module.machine.entity.SecretKey;
|
||||||
import cd.casic.module.machine.dal.dataobject.SecretKey;
|
import cd.casic.module.machine.dto.SecretKeyDto;
|
||||||
import cd.casic.module.machine.controller.vo.SecretKeyDto;
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -1,97 +1,174 @@
|
|||||||
package cd.casic.module.machine.service.impl;
|
package cd.casic.module.machine.service.impl;
|
||||||
import cd.casic.module.machine.convert.MachineEnvConvert;
|
|
||||||
import cd.casic.module.machine.controller.vo.MachineEnvVO;
|
import cd.casic.module.machine.dto.MachineEnvDTO;
|
||||||
import cd.casic.module.machine.dal.dataobject.MachineEnvDO;
|
import cd.casic.module.machine.entity.MachineEnv;
|
||||||
import cd.casic.module.machine.dal.mysql.MachineEnvMapper;
|
import cd.casic.module.machine.exception.ServiceException;
|
||||||
|
import cd.casic.module.machine.mapper.MachineEnvMapper;
|
||||||
import cd.casic.module.machine.service.MachineEnvService;
|
import cd.casic.module.machine.service.MachineEnvService;
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import cd.casic.framework.commons.util.object.BeanUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
|
|
||||||
import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 环境变量服务实现类
|
* 环境变量服务实现类
|
||||||
*/
|
*/
|
||||||
@Service("machineEnvService")
|
@Service
|
||||||
public class MachineEnvServiceImpl implements MachineEnvService {
|
public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, MachineEnv> implements MachineEnvService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MachineEnvMapper machineEnvMapper;
|
private MachineEnvMapper machineEnvMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long createEnv(MachineEnvVO machineEnvVO) {
|
public boolean add(MachineEnvDTO machineEnvDTO) {
|
||||||
validateMachineEnvAdd(machineEnvVO);
|
// 参数校验
|
||||||
|
if (machineEnvDTO == null) {
|
||||||
|
throw new ServiceException(ServiceException.MACHINE_ENV_NULL, "环境变量不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
// 检查键是否合法
|
// 检查键是否合法
|
||||||
validateKey(machineEnvVO.getEnvKey());
|
if (!isValidKey(machineEnvDTO.getEnvKey())) {
|
||||||
MachineEnvDO machineEnvDO = BeanUtils.toBean(machineEnvVO, MachineEnvDO.class);
|
throw new ServiceException(ServiceException.MACHINE_ENV_KEY_ILLEGAL, "环境变量键不合法");
|
||||||
machineEnvMapper.insert(machineEnvDO);
|
}
|
||||||
return machineEnvDO.getId();
|
|
||||||
|
// 判断是否敏感变量
|
||||||
|
boolean isSensitive = isSensitive(machineEnvDTO.getEnvKey());
|
||||||
|
|
||||||
|
MachineEnv machineEnv = new MachineEnv();
|
||||||
|
BeanUtils.copyProperties(machineEnvDTO, machineEnv);
|
||||||
|
return save(machineEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteEnv(Long machineEvnId) {
|
public void deleteByMachineId(Long machineEvnId) {
|
||||||
machineEnvMapper.deleteById(machineEvnId);
|
this.removeById(machineEvnId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MachineEnvVO getEnv(Long machineId) {
|
public MachineEnvDTO getByMachineId(Long machineId) {
|
||||||
if (machineId == null) {
|
if (machineId == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
MachineEnvDO machineEnvDO = machineEnvMapper.selectById(machineId);
|
|
||||||
return machineEnvDO != null ? MachineEnvConvert.INSTANCE.convertToVO(machineEnvDO) : null;
|
MachineEnv machineEnv = getOne(
|
||||||
|
new LambdaQueryWrapper<MachineEnv>()
|
||||||
|
.eq(MachineEnv::getMachineId, machineId)
|
||||||
|
);
|
||||||
|
|
||||||
|
return machineEnv != null ? convertToDTO(machineEnv) : null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<MachineEnvDO> getEnvPage(MachineEnvVO machineEnvVO) {
|
public PageResult<MachineEnvDTO> listEnv(MachineEnvDTO machineEnvDTO) {
|
||||||
return machineEnvMapper.selectPage(machineEnvVO);
|
|
||||||
|
// 构建查询条件
|
||||||
|
LambdaQueryWrapper<MachineEnv> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
// 环境变量键模糊查询
|
||||||
|
if (!StringUtils.isEmpty(machineEnvDTO.getEnvKey())) {
|
||||||
|
queryWrapper.like(MachineEnv::getEnvKey, machineEnvDTO.getEnvKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 机器ID模糊查询
|
||||||
|
if (!StringUtils.isEmpty(machineEnvDTO.getMachineId())) {
|
||||||
|
queryWrapper.like(MachineEnv::getMachineId, machineEnvDTO.getMachineId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建时间范围查询
|
||||||
|
if (!StringUtils.isEmpty(machineEnvDTO.getCreateDate())) {
|
||||||
|
queryWrapper.ge(MachineEnv::getCreateDate, machineEnvDTO.getCreateDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序
|
||||||
|
if (!StringUtils.isEmpty(machineEnvDTO.getSortField())) {
|
||||||
|
boolean isAsc = "asc".equalsIgnoreCase(machineEnvDTO.getSortDirection());
|
||||||
|
switch (machineEnvDTO.getSortField()) {
|
||||||
|
case "envKey":
|
||||||
|
queryWrapper.orderBy(true, isAsc, MachineEnv::getEnvKey);
|
||||||
|
break;
|
||||||
|
case "machineId":
|
||||||
|
queryWrapper.orderBy(true, isAsc, MachineEnv::getMachineId);
|
||||||
|
break;
|
||||||
|
case "createTime":
|
||||||
|
default:
|
||||||
|
queryWrapper.orderBy(true, isAsc, MachineEnv::getCreateDate);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页查询
|
||||||
|
Page<MachineEnv> page = machineEnvMapper.selectPage(new Page<>(machineEnvDTO.getPageIndex(), machineEnvDTO.getPageSize()), queryWrapper);
|
||||||
|
|
||||||
|
// 转换结果
|
||||||
|
List<MachineEnvDTO> dtoList = page.getRecords().stream()
|
||||||
|
.map(this::convertToDTO)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 构建分页结果
|
||||||
|
return PageResult.<MachineEnvDTO>builder()
|
||||||
|
.pageNum(page.getCurrent())
|
||||||
|
.pageSize(page.getSize())
|
||||||
|
.total(page.getTotal())
|
||||||
|
.pages(page.getPages())
|
||||||
|
.list(dtoList)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteEnvList(String ids) {
|
public void deleteList(String ids) {
|
||||||
machineEnvMapper.deleteBatchByIds(ids);
|
List<Long> machineEnvIds = Arrays.stream(ids.split(","))
|
||||||
|
.map(String::trim)
|
||||||
|
.filter(s -> !s.isEmpty())
|
||||||
|
.map(Long::parseLong)
|
||||||
|
.toList();
|
||||||
|
this.machineEnvMapper.deleteBatchIds(machineEnvIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEnv(MachineEnvVO machineEnvVO) {
|
public boolean update(MachineEnvDTO machineEnvDTO) {
|
||||||
MachineEnvDO machineEnvDO = validateMachineEnvExists(machineEnvVO.getId());
|
MachineEnv machineEnv = new MachineEnv();
|
||||||
BeanUtils.copyProperties(machineEnvVO, machineEnvDO);
|
BeanUtils.copyProperties(machineEnvDTO, machineEnv);
|
||||||
machineEnvMapper.updateById(machineEnvDO);
|
return this.updateById(machineEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
// 转换实体为DTO
|
||||||
MachineEnvDO validateMachineEnvExists(Long id) {
|
private MachineEnvDTO convertToDTO(MachineEnv machineEnv) {
|
||||||
if (id == null) {
|
MachineEnvDTO dto = new MachineEnvDTO();
|
||||||
return null;
|
dto.setId(machineEnv.getId());
|
||||||
|
dto.setEnvKey(machineEnv.getEnvKey());
|
||||||
|
dto.setEnvValue(machineEnv.getEnvValue());
|
||||||
|
dto.setDescription(machineEnv.getDescription());
|
||||||
|
dto.setCreateDate(machineEnv.getCreateDate());
|
||||||
|
dto.setUpdateDate(machineEnv.getUpdateDate());
|
||||||
|
return dto;
|
||||||
}
|
}
|
||||||
MachineEnvDO machineEnvDO = machineEnvMapper.selectById(id);
|
|
||||||
if (machineEnvDO == null) {
|
|
||||||
throw exception(MACHINE_ENV_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
return machineEnvDO;
|
|
||||||
}
|
|
||||||
@VisibleForTesting
|
|
||||||
void validateMachineEnvAdd(MachineEnvVO machineEnvVO) {
|
|
||||||
if (machineEnvVO.getEnvKey()==null||machineEnvVO.getEnvValue()==null) {
|
|
||||||
throw exception(MACHINE_ENV_NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 检查环境变量键是否合法
|
// 检查环境变量键是否合法
|
||||||
@VisibleForTesting
|
private boolean isValidKey(String key) {
|
||||||
private void validateKey(String key) {
|
return key.matches("^[a-zA-Z_][a-zA-Z0-9_]*$");
|
||||||
if (!key.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) {
|
|
||||||
throw exception(MACHINE_ENV_KEY_ILLEGAL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断是否为敏感变量
|
||||||
|
private boolean isSensitive(String key) {
|
||||||
|
if (key == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String upperKey = key.toUpperCase();
|
||||||
|
return upperKey.contains("PASSWORD") || upperKey.contains("SECRET") ||
|
||||||
|
upperKey.contains("TOKEN") || upperKey.contains("KEY");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,161 +1,162 @@
|
|||||||
//package cd.casic.module.machine.service.impl;
|
package cd.casic.module.machine.service.impl;
|
||||||
//
|
|
||||||
//import cd.casic.module.machine.controller.vo.MachineProxyDTO;
|
import cd.casic.module.machine.dto.MachineProxyDTO;
|
||||||
//import cd.casic.module.machine.dal.dataobject.MachineProxy;
|
import cd.casic.module.machine.entity.MachineProxy;
|
||||||
//import cd.casic.module.machine.enums.MachineProxyStatus;
|
import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||||
//import cd.casic.module.machine.enums.MachineProxyType;
|
import cd.casic.module.machine.enums.MachineProxyType;
|
||||||
//import cd.casic.module.machine.exception.ServiceException;
|
import cd.casic.module.machine.exception.ServiceException;
|
||||||
//import cd.casic.module.machine.dal.mysql.MachineProxyMapper;
|
import cd.casic.module.machine.mapper.MachineProxyMapper;
|
||||||
//import cd.casic.module.machine.service.MachineProxyService;
|
import cd.casic.module.machine.service.MachineProxyService;
|
||||||
//import cd.casic.module.machine.utils.EnumUtils;
|
import cd.casic.module.machine.utils.EnumUtils;
|
||||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
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 jakarta.annotation.Resource;
|
||||||
//import org.springframework.stereotype.Service;
|
import org.springframework.beans.BeanUtils;
|
||||||
//import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.stereotype.Service;
|
||||||
//import org.springframework.util.CollectionUtils;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
//
|
import org.springframework.util.CollectionUtils;
|
||||||
//import java.util.*;
|
|
||||||
//import java.util.function.Function;
|
import java.util.*;
|
||||||
//import java.util.stream.Collectors;
|
import java.util.function.Function;
|
||||||
//
|
import java.util.stream.Collectors;
|
||||||
///**
|
|
||||||
// * 机器代理服务实现类
|
/**
|
||||||
// */
|
* 机器代理服务实现类
|
||||||
//@Service
|
*/
|
||||||
//public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, MachineProxy> implements MachineProxyService {
|
@Service
|
||||||
// @Resource
|
public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, MachineProxy> implements MachineProxyService {
|
||||||
// private MachineProxyMapper machineProxyMapper;
|
@Resource
|
||||||
//
|
private MachineProxyMapper machineProxyMapper;
|
||||||
// @Override
|
|
||||||
// @Transactional(rollbackFor = Exception.class)
|
@Override
|
||||||
// public boolean register(MachineProxyDTO machineProxyDTO) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
// // 创建代理记录
|
public boolean register(MachineProxyDTO machineProxyDTO) {
|
||||||
// MachineProxy proxy = new MachineProxy();
|
// 创建代理记录
|
||||||
// BeanUtils.copyProperties(machineProxyDTO, proxy);
|
MachineProxy proxy = new MachineProxy();
|
||||||
// proxy.setProxyTypeCode(EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
BeanUtils.copyProperties(machineProxyDTO, proxy);
|
||||||
// proxy.setVersion("1.0.0");
|
proxy.setProxyTypeCode(EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
||||||
// proxy.setStatusCode(MachineProxyStatus.ONLINE.getCode());
|
proxy.setVersion("1.0.0");
|
||||||
// return save(proxy);
|
proxy.setStatusCode(MachineProxyStatus.ONLINE.getCode());
|
||||||
// }
|
return save(proxy);
|
||||||
//
|
}
|
||||||
// @Override
|
|
||||||
// public boolean updateStatus(MachineProxyDTO machineProxyDTO) {
|
@Override
|
||||||
// // 参数校验
|
public boolean updateStatus(MachineProxyDTO machineProxyDTO) {
|
||||||
// if (machineProxyDTO == null) {
|
// 参数校验
|
||||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_DTO_NULL, "MachineProxyDTO对象为空");
|
if (machineProxyDTO == null) {
|
||||||
// }
|
throw new ServiceException(ServiceException.MACHINE_PROXY_DTO_NULL, "MachineProxyDTO对象为空");
|
||||||
//
|
}
|
||||||
// // 查询代理
|
|
||||||
// MachineProxy proxy = this.getById(machineProxyDTO.getId());
|
// 查询代理
|
||||||
//
|
MachineProxy proxy = this.getById(machineProxyDTO.getId());
|
||||||
// if (proxy == null) {
|
|
||||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_NULL, "代理不存在");
|
if (proxy == null) {
|
||||||
// }
|
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL, "代理不存在");
|
||||||
//
|
}
|
||||||
// // 更新状态
|
|
||||||
// proxy.setStatusCode(EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
// 更新状态
|
||||||
// proxy.setUpdateTime(new Date());
|
proxy.setStatusCode(EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||||
// return updateById(proxy);
|
proxy.setUpdateDate(new Date());
|
||||||
// }
|
return updateById(proxy);
|
||||||
//
|
}
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public Map<String, Long> getStatusStatistics() {
|
@Override
|
||||||
// List<MachineProxy> proxyList = list();
|
public Map<String, Long> getStatusStatistics() {
|
||||||
//
|
List<MachineProxy> proxyList = list();
|
||||||
// if (CollectionUtils.isEmpty(proxyList)) {
|
|
||||||
// return Collections.emptyMap();
|
if (CollectionUtils.isEmpty(proxyList)) {
|
||||||
// }
|
return Collections.emptyMap();
|
||||||
// return proxyList.stream()
|
}
|
||||||
// .map(proxy -> EnumUtils.getEnumByCode(proxy.getStatusCode(), MachineProxyStatus.class).getMessage())
|
return proxyList.stream()
|
||||||
// .collect(Collectors.groupingBy(
|
.map(proxy -> EnumUtils.getEnumByCode(proxy.getStatusCode(), MachineProxyStatus.class).getMessage())
|
||||||
// Function.identity(),
|
.collect(Collectors.groupingBy(
|
||||||
// Collectors.counting() // 统计每个分组的元素数量
|
Function.identity(),
|
||||||
// ));
|
Collectors.counting() // 统计每个分组的元素数量
|
||||||
// }
|
));
|
||||||
//
|
}
|
||||||
// @Override
|
|
||||||
// public void update(MachineProxyDTO machineProxyDTO) {
|
@Override
|
||||||
// // 参数校验
|
public void update(MachineProxyDTO machineProxyDTO) {
|
||||||
// if (machineProxyDTO == null) {
|
// 参数校验
|
||||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_DTO_NULL, "MachineProxyDTO对象为空");
|
if (machineProxyDTO == null) {
|
||||||
// }
|
throw new ServiceException(ServiceException.MACHINE_PROXY_DTO_NULL, "MachineProxyDTO对象为空");
|
||||||
// MachineProxy machineProxy = new MachineProxy();
|
}
|
||||||
// BeanUtils.copyProperties(machineProxyDTO, machineProxy);
|
MachineProxy machineProxy = new MachineProxy();
|
||||||
// if (machineProxyDTO.getProxyType() != null && !machineProxyDTO.getProxyType().isEmpty()) {
|
BeanUtils.copyProperties(machineProxyDTO, machineProxy);
|
||||||
// machineProxy.setProxyTypeCode(EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
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());
|
if (machineProxyDTO.getStatus() != null && !machineProxyDTO.getStatus().isEmpty()) {
|
||||||
// }
|
machineProxy.setStatusCode(EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||||
// this.updateById(machineProxy);
|
}
|
||||||
// }
|
this.updateById(machineProxy);
|
||||||
//
|
}
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// @Transactional(rollbackFor = Exception.class)
|
@Override
|
||||||
// public void delete(String ids) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
// List<Long> machineProxyIds = Arrays.stream(ids.split(","))
|
public void delete(String ids) {
|
||||||
// .map(String::trim)
|
List<Long> machineProxyIds = Arrays.stream(ids.split(","))
|
||||||
// .filter(s -> !s.isEmpty())
|
.map(String::trim)
|
||||||
// .map(Long::parseLong)
|
.filter(s -> !s.isEmpty())
|
||||||
// .toList();
|
.map(Long::parseLong)
|
||||||
// // 参数校验
|
.toList();
|
||||||
// if (CollectionUtils.isEmpty(machineProxyIds)) {
|
// 参数校验
|
||||||
// throw new ServiceException(ServiceException.PARAMETER_ERROR, "参数错误");
|
if (CollectionUtils.isEmpty(machineProxyIds)) {
|
||||||
// }
|
throw new ServiceException(ServiceException.PARAMETER_ERROR, "参数错误");
|
||||||
// // 批量逻辑删除
|
}
|
||||||
// remove(new LambdaQueryWrapper<MachineProxy>()
|
// 批量逻辑删除
|
||||||
// .in(MachineProxy::getId, machineProxyIds)
|
remove(new LambdaQueryWrapper<MachineProxy>()
|
||||||
// .ne(MachineProxy::getStatus, MachineProxyStatus.ONLINE.getCode()));
|
.in(MachineProxy::getId, machineProxyIds)
|
||||||
// }
|
.ne(MachineProxy::getStatus, MachineProxyStatus.ONLINE.getCode()));
|
||||||
//
|
}
|
||||||
// @Override
|
|
||||||
// public PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO) {
|
@Override
|
||||||
// QueryWrapper<MachineProxy> queryWrapper = getMachineProxyQueryWrapper(machineProxyDTO);
|
public PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO) {
|
||||||
// Page<MachineProxy> page = machineProxyMapper.selectPage(new Page<>(machineProxyDTO.getPageIndex(), machineProxyDTO.getPageSize()), queryWrapper);
|
QueryWrapper<MachineProxy> queryWrapper = getMachineProxyQueryWrapper(machineProxyDTO);
|
||||||
// List<MachineProxyDTO> machineProxyDtos = page.getRecords().stream().map(machineProxy -> {
|
Page<MachineProxy> page = machineProxyMapper.selectPage(new Page<>(machineProxyDTO.getPageIndex(), machineProxyDTO.getPageSize()), queryWrapper);
|
||||||
// MachineProxyDTO dto = new MachineProxyDTO();
|
List<MachineProxyDTO> machineProxyDtos = page.getRecords().stream().map(machineProxy -> {
|
||||||
// BeanUtils.copyProperties(machineProxy, dto);
|
MachineProxyDTO dto = new MachineProxyDTO();
|
||||||
// dto.setProxyType(EnumUtils.getEnumByCode(machineProxy.getProxyTypeCode(), MachineProxyType.class).getMessage());
|
BeanUtils.copyProperties(machineProxy, dto);
|
||||||
// dto.setStatus(EnumUtils.getEnumByCode(machineProxy.getStatusCode(), MachineProxyStatus.class).getMessage());
|
dto.setProxyType(EnumUtils.getEnumByCode(machineProxy.getProxyTypeCode(), MachineProxyType.class).getMessage());
|
||||||
// return dto;
|
dto.setStatus(EnumUtils.getEnumByCode(machineProxy.getStatusCode(), MachineProxyStatus.class).getMessage());
|
||||||
// }).toList();
|
return dto;
|
||||||
// return new PageResult<>(
|
}).toList();
|
||||||
// page.getCurrent(),
|
return new PageResult<>(
|
||||||
// page.getSize(),
|
page.getCurrent(),
|
||||||
// page.getTotal(),
|
page.getSize(),
|
||||||
// page.getPages(),
|
page.getTotal(),
|
||||||
// machineProxyDtos
|
page.getPages(),
|
||||||
// );
|
machineProxyDtos
|
||||||
// }
|
);
|
||||||
//
|
}
|
||||||
// private QueryWrapper<MachineProxy> getMachineProxyQueryWrapper(MachineProxyDTO machineProxyDTO) {
|
|
||||||
// QueryWrapper<MachineProxy> queryWrapper = new QueryWrapper<>();
|
private QueryWrapper<MachineProxy> getMachineProxyQueryWrapper(MachineProxyDTO machineProxyDTO) {
|
||||||
// if (machineProxyDTO.getHostIp() != null && !machineProxyDTO.getHostIp().isEmpty()) {
|
QueryWrapper<MachineProxy> queryWrapper = new QueryWrapper<>();
|
||||||
// queryWrapper.like("host_ip", machineProxyDTO.getHostIp());
|
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.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.getUsername() != null && !machineProxyDTO.getUsername().isEmpty()) {
|
||||||
// }
|
queryWrapper.like("username", machineProxyDTO.getUsername());
|
||||||
// if (machineProxyDTO.getDescription() != null && !machineProxyDTO.getDescription().isEmpty()) {
|
}
|
||||||
// queryWrapper.like("description", machineProxyDTO.getDescription());
|
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.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());
|
if (machineProxyDTO.getProxyType() != null && !machineProxyDTO.getProxyType().isEmpty()) {
|
||||||
// }
|
queryWrapper.like("proxy_type_code", EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
||||||
// return queryWrapper.orderByDesc("create_date");
|
}
|
||||||
// }
|
return queryWrapper.orderByDesc("create_date");
|
||||||
//
|
}
|
||||||
//}
|
|
||||||
|
}
|
||||||
|
@ -1,354 +1,363 @@
|
|||||||
//package cd.casic.module.machine.service.impl;
|
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.enums.MachineInfoType;
|
||||||
//import cd.casic.module.machine.dal.mysql.MachineInfoMapper;
|
import cd.casic.module.machine.handler.ConnectionSession;
|
||||||
//import cd.casic.module.machine.controller.vo.MachineInfoDto;
|
import cd.casic.module.machine.mapper.MachineInfoMapper;
|
||||||
//import cd.casic.module.machine.dal.dataobject.MachineInfo;
|
import cd.casic.module.machine.dto.MachineInfoDto;
|
||||||
//import cd.casic.module.machine.enums.AuthenticationType;
|
import cd.casic.module.machine.entity.MachineInfo;
|
||||||
//import cd.casic.module.machine.enums.ConnectionStatus;
|
import cd.casic.module.machine.enums.AuthenticationType;
|
||||||
//import cd.casic.module.machine.enums.MachineInfoStatus;
|
import cd.casic.module.machine.enums.ConnectionStatus;
|
||||||
//import cd.casic.module.machine.service.MachineInfoService;
|
import cd.casic.module.machine.enums.MachineInfoStatus;
|
||||||
//import cd.casic.module.machine.utils.EnumUtils;
|
import cd.casic.module.machine.exception.ServiceException;
|
||||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import cd.casic.module.machine.service.MachineInfoService;
|
||||||
//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import cd.casic.module.machine.utils.EnumUtils;
|
||||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
//import jakarta.annotation.Resource;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
//import org.springframework.beans.BeanUtils;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
//import org.springframework.stereotype.Service;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
//import java.util.Arrays;
|
|
||||||
//import java.util.HashMap;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
//import java.util.List;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
//import java.util.Map;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
//import java.util.concurrent.ConcurrentHashMap;
|
import jakarta.annotation.Resource;
|
||||||
//import java.util.concurrent.atomic.AtomicInteger;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
//import java.util.stream.Collectors;
|
import org.springframework.beans.BeanUtils;
|
||||||
//
|
import org.springframework.stereotype.Service;
|
||||||
//@Slf4j
|
|
||||||
//@Service("machineInfoService")
|
import java.util.Arrays;
|
||||||
//public class MachineinfoServiceImpl implements MachineInfoService {
|
import java.util.HashMap;
|
||||||
//
|
import java.util.List;
|
||||||
// int ENABLE = 1;
|
import java.util.Map;
|
||||||
// int UN_ENABLE = 0;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
//
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
// @Resource
|
import java.util.stream.Collectors;
|
||||||
// private MachineInfoMapper machineInfoMapper;
|
|
||||||
// @Resource
|
@Slf4j
|
||||||
// private ConnectionSession connectionSession;
|
@Service
|
||||||
// /**
|
public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, MachineInfo> implements MachineInfoService {
|
||||||
// * 会话ID生成器
|
|
||||||
// */
|
int ENABLE = 1;
|
||||||
// private final AtomicInteger sessionIdGenerator = new AtomicInteger(1000);
|
int UN_ENABLE = 0;
|
||||||
//
|
|
||||||
// /**
|
@Resource
|
||||||
// * 会话管理:会话ID -> 连接会话
|
private MachineInfoMapper machineInfoMapper;
|
||||||
// */
|
@Resource
|
||||||
// private final Map<String, ConnectionSession> sessions = new ConcurrentHashMap<>();
|
private ConnectionSession connectionSession;
|
||||||
//
|
/**
|
||||||
// /**
|
* 会话ID生成器
|
||||||
// * 机器名称 -> 会话ID
|
*/
|
||||||
// */
|
private final AtomicInteger sessionIdGenerator = new AtomicInteger(1000);
|
||||||
// private final Map<String, String> machineSessionMapping = new ConcurrentHashMap<>();
|
|
||||||
//
|
/**
|
||||||
// @Override
|
* 会话管理:会话ID -> 连接会话
|
||||||
// public boolean addMachineInfo(MachineInfoDto machineInfoDto) {
|
*/
|
||||||
// if (machineInfoDto == null) {
|
private final Map<String, ConnectionSession> sessions = new ConcurrentHashMap<>();
|
||||||
// throw new ServiceException(ServiceException.MACHINE_INFO_NULL, "机器信息为空");
|
|
||||||
// }
|
/**
|
||||||
// MachineInfo machineInfo = new MachineInfo();
|
* 机器名称 -> 会话ID
|
||||||
// BeanUtils.copyProperties(machineInfoDto, machineInfo);
|
*/
|
||||||
// machineInfo.setStatusCode(1);
|
private final Map<String, String> machineSessionMapping = new ConcurrentHashMap<>();
|
||||||
// machineInfo.setAuthenticationTypeCode(
|
|
||||||
// "密码认证".equals(machineInfoDto.getAuthenticationType())
|
@Override
|
||||||
// ? AuthenticationType.PASSWORD.getCode()
|
public boolean addMachineInfo(MachineInfoDto machineInfoDto) {
|
||||||
// : AuthenticationType.SECRET_KEY.getCode()
|
if (machineInfoDto == null) {
|
||||||
// );
|
throw new ServiceException(ServiceException.MACHINE_INFO_NULL, "机器信息为空");
|
||||||
// machineInfo.setMachineInfoTypeCode(
|
}
|
||||||
// "Windows".equals(machineInfoDto.getMachineInfoType())
|
MachineInfo machineInfo = new MachineInfo();
|
||||||
// ? MachineInfoType.WINDOWS.getCode()
|
BeanUtils.copyProperties(machineInfoDto, machineInfo);
|
||||||
// : MachineInfoType.Linux.getCode()
|
machineInfo.setStatusCode(1);
|
||||||
// );
|
machineInfo.setAuthenticationTypeCode(
|
||||||
//
|
"密码认证".equals(machineInfoDto.getAuthenticationType())
|
||||||
// return this.save(machineInfo);
|
? AuthenticationType.PASSWORD.getCode()
|
||||||
// }
|
: AuthenticationType.SECRET_KEY.getCode()
|
||||||
//
|
);
|
||||||
// @Override
|
machineInfo.setMachineInfoTypeCode(
|
||||||
// public PageResult<MachineInfoDto> listMachineInfo(MachineInfoDto machineInfoDto) {
|
"Windows".equals(machineInfoDto.getMachineInfoType())
|
||||||
// QueryWrapper<MachineInfo> queryWrapper = getMachineInfoQueryWrapper(machineInfoDto);
|
? MachineInfoType.WINDOWS.getCode()
|
||||||
// Page<MachineInfo> page = machineInfoMapper.selectPage(
|
: MachineInfoType.Linux.getCode()
|
||||||
// new Page<>(machineInfoDto.getPageIndex(), machineInfoDto.getPageSize()),
|
);
|
||||||
// queryWrapper
|
|
||||||
// );
|
return this.save(machineInfo);
|
||||||
//
|
}
|
||||||
// List<MachineInfoDto> machineInfoDtos = page.getRecords().stream()
|
|
||||||
// .map(machineInfo -> {
|
@Override
|
||||||
// MachineInfoDto dto = new MachineInfoDto();
|
public PageResult<MachineInfoDto> listMachineInfo(MachineInfoDto machineInfoDto) {
|
||||||
// BeanUtils.copyProperties(machineInfo, dto);
|
QueryWrapper<MachineInfo> queryWrapper = getMachineInfoQueryWrapper(machineInfoDto);
|
||||||
// // 直接调用原有枚举转换方法
|
Page<MachineInfo> page = machineInfoMapper.selectPage(
|
||||||
// dto.setMachineInfoType(EnumUtils.getEnumByCode(machineInfo.getMachineInfoTypeCode(), MachineInfoType.class).getMessage());
|
new Page<>(machineInfoDto.getPageIndex(), machineInfoDto.getPageSize()),
|
||||||
// dto.setStatus(EnumUtils.getEnumByCode(machineInfo.getStatusCode(), MachineInfoStatus.class).getMessage());
|
queryWrapper
|
||||||
// dto.setAuthenticationType(EnumUtils.getEnumByCode(machineInfo.getAuthenticationTypeCode(), AuthenticationType.class).getMessage());
|
);
|
||||||
// return dto;
|
|
||||||
// })
|
List<MachineInfoDto> machineInfoDtos = page.getRecords().stream()
|
||||||
// .toList();
|
.map(machineInfo -> {
|
||||||
//
|
MachineInfoDto dto = new MachineInfoDto();
|
||||||
// return new PageResult<>(
|
BeanUtils.copyProperties(machineInfo, dto);
|
||||||
// page.getCurrent(),
|
// 直接调用原有枚举转换方法
|
||||||
// page.getSize(),
|
dto.setMachineInfoType(EnumUtils.getEnumByCode(machineInfo.getMachineInfoTypeCode(), MachineInfoType.class).getMessage());
|
||||||
// page.getTotal(),
|
dto.setStatus(EnumUtils.getEnumByCode(machineInfo.getStatusCode(), MachineInfoStatus.class).getMessage());
|
||||||
// page.getPages(),
|
dto.setAuthenticationType(EnumUtils.getEnumByCode(machineInfo.getAuthenticationTypeCode(), AuthenticationType.class).getMessage());
|
||||||
// machineInfoDtos
|
return dto;
|
||||||
// );
|
})
|
||||||
// }
|
.toList();
|
||||||
//
|
|
||||||
// @Override
|
return new PageResult<>(
|
||||||
// public boolean updateMachineInfo(MachineInfoDto machineInfoDto) {
|
page.getCurrent(),
|
||||||
// MachineInfo machineInfo = new MachineInfo();
|
page.getSize(),
|
||||||
// BeanUtils.copyProperties(machineInfoDto, machineInfo);
|
page.getTotal(),
|
||||||
// machineInfo.setAuthenticationTypeCode(
|
page.getPages(),
|
||||||
// "密码认证".equals(machineInfoDto.getAuthenticationType())
|
machineInfoDtos
|
||||||
// ? AuthenticationType.PASSWORD.getCode()
|
);
|
||||||
// : AuthenticationType.SECRET_KEY.getCode()
|
}
|
||||||
// );
|
|
||||||
// machineInfo.setMachineInfoTypeCode(
|
@Override
|
||||||
// "Windows".equals(machineInfoDto.getMachineInfoType())
|
public boolean updateMachineInfo(MachineInfoDto machineInfoDto) {
|
||||||
// ? MachineInfoType.WINDOWS.getCode()
|
MachineInfo machineInfo = new MachineInfo();
|
||||||
// : MachineInfoType.Linux.getCode()
|
BeanUtils.copyProperties(machineInfoDto, machineInfo);
|
||||||
// );
|
machineInfo.setAuthenticationTypeCode(
|
||||||
// return this.updateById(machineInfo);
|
"密码认证".equals(machineInfoDto.getAuthenticationType())
|
||||||
// }
|
? AuthenticationType.PASSWORD.getCode()
|
||||||
//
|
: AuthenticationType.SECRET_KEY.getCode()
|
||||||
// @Override
|
);
|
||||||
// public boolean updateStatus(MachineInfoDto machineInfoDto) {
|
machineInfo.setMachineInfoTypeCode(
|
||||||
// UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
|
"Windows".equals(machineInfoDto.getMachineInfoType())
|
||||||
// updateWrapper.eq("id", machineInfoDto.getId()).set("status_code", EnumUtils.getEnumByMessage(machineInfoDto.getStatus(), MachineInfoStatus.class).getCode());
|
? MachineInfoType.WINDOWS.getCode()
|
||||||
// return this.update(updateWrapper);
|
: MachineInfoType.Linux.getCode()
|
||||||
// }
|
);
|
||||||
//
|
return this.updateById(machineInfo);
|
||||||
// @Override
|
}
|
||||||
// public boolean bindingSecretKey(MachineInfoDto machineInfoDto) {
|
|
||||||
// UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
|
@Override
|
||||||
// updateWrapper.eq("id", machineInfoDto.getId()).set("secret_key_id", machineInfoDto.getSecretKeyId()).set("authentication_type_code", 2);
|
public boolean updateStatus(MachineInfoDto machineInfoDto) {
|
||||||
// return this.update(updateWrapper);
|
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 void deleteList(String machineInfoIds) {
|
|
||||||
// List<Long> machineInfoIdList = Arrays.stream(machineInfoIds.split(","))
|
@Override
|
||||||
// .map(String::trim)
|
public boolean bindingSecretKey(MachineInfoDto machineInfoDto) {
|
||||||
// .filter(s -> !s.isEmpty())
|
UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
|
||||||
// .map(Long::parseLong)
|
updateWrapper.eq("id", machineInfoDto.getId()).set("secret_key_id", machineInfoDto.getSecretKeyId()).set("authentication_type_code", 2);
|
||||||
// .collect(Collectors.toList());
|
return this.update(updateWrapper);
|
||||||
// machineInfoMapper.selectBatchIds(machineInfoIdList).forEach(machineInfo -> {
|
}
|
||||||
// if (machineInfo.getStatusCode() == 1) {
|
|
||||||
// this.removeById(machineInfo.getId());
|
@Override
|
||||||
// }
|
public void deleteList(String machineInfoIds) {
|
||||||
// });
|
List<Long> machineInfoIdList = Arrays.stream(machineInfoIds.split(","))
|
||||||
// }
|
.map(String::trim)
|
||||||
//
|
.filter(s -> !s.isEmpty())
|
||||||
// @Override
|
.map(Long::parseLong)
|
||||||
// public void deleteMachineInfo(Long machineInfoId) {
|
.collect(Collectors.toList());
|
||||||
// MachineInfo machineInfo = this.getById(machineInfoId);
|
machineInfoMapper.selectBatchIds(machineInfoIdList).forEach(machineInfo -> {
|
||||||
// if (machineInfo.getStatusCode() == 1) {
|
if (machineInfo.getStatusCode() == 1) {
|
||||||
// this.removeById(machineInfoId);
|
this.removeById(machineInfo.getId());
|
||||||
// }
|
}
|
||||||
// }
|
});
|
||||||
//
|
}
|
||||||
// private QueryWrapper<MachineInfo> getMachineInfoQueryWrapper(MachineInfoDto machineInfoDto) {
|
|
||||||
// QueryWrapper<MachineInfo> queryWrapper = new QueryWrapper<>();
|
@Override
|
||||||
// if (machineInfoDto.getStatus() != null && !machineInfoDto.getStatus().isEmpty()) {
|
public void deleteMachineInfo(Long machineInfoId) {
|
||||||
// queryWrapper.eq("status_code", EnumUtils.getEnumByMessage(machineInfoDto.getStatus(), MachineInfoStatus.class).getCode());
|
MachineInfo machineInfo = this.getById(machineInfoId);
|
||||||
// }
|
if (machineInfo.getStatusCode() == 1) {
|
||||||
// if (machineInfoDto.getName() != null && !machineInfoDto.getName().isEmpty()) {
|
this.removeById(machineInfoId);
|
||||||
// queryWrapper.like("name", machineInfoDto.getName());
|
}
|
||||||
// }
|
}
|
||||||
// if (machineInfoDto.getTag() != null && !machineInfoDto.getTag().isEmpty()) {
|
|
||||||
// queryWrapper.like("tag", machineInfoDto.getTag());
|
private QueryWrapper<MachineInfo> getMachineInfoQueryWrapper(MachineInfoDto machineInfoDto) {
|
||||||
// }
|
QueryWrapper<MachineInfo> queryWrapper = new QueryWrapper<>();
|
||||||
// if (machineInfoDto.getHostIp() != null && !machineInfoDto.getHostIp().isEmpty()) {
|
if (machineInfoDto.getStatus() != null && !machineInfoDto.getStatus().isEmpty()) {
|
||||||
// queryWrapper.like("host_ip", machineInfoDto.getHostIp());
|
queryWrapper.eq("status_code", EnumUtils.getEnumByMessage(machineInfoDto.getStatus(), MachineInfoStatus.class).getCode());
|
||||||
// }
|
}
|
||||||
// if (machineInfoDto.getDescription() != null && !machineInfoDto.getDescription().isEmpty()) {
|
if (machineInfoDto.getName() != null && !machineInfoDto.getName().isEmpty()) {
|
||||||
// queryWrapper.like("description", machineInfoDto.getDescription());
|
queryWrapper.like("name", machineInfoDto.getName());
|
||||||
// }
|
}
|
||||||
// return queryWrapper.orderByDesc("create_date");
|
if (machineInfoDto.getTag() != null && !machineInfoDto.getTag().isEmpty()) {
|
||||||
// }
|
queryWrapper.like("tag", machineInfoDto.getTag());
|
||||||
//
|
}
|
||||||
//
|
if (machineInfoDto.getHostIp() != null && !machineInfoDto.getHostIp().isEmpty()) {
|
||||||
// @Override
|
queryWrapper.like("host_ip", machineInfoDto.getHostIp());
|
||||||
// public boolean testConnection(Long id) {
|
}
|
||||||
// //先查询机器是否存在,在判断机器可用性
|
if (machineInfoDto.getDescription() != null && !machineInfoDto.getDescription().isEmpty()) {
|
||||||
// MachineInfo machineInfo = machineInfoMapper.getById(id);
|
queryWrapper.like("description", machineInfoDto.getDescription());
|
||||||
// if (machineInfo==null){
|
}
|
||||||
// throw new RuntimeException("机器不存在");
|
return queryWrapper.orderByDesc("create_date");
|
||||||
// }
|
}
|
||||||
// if (machineInfo.getStatusCode() == 0) {
|
|
||||||
// throw new RuntimeException("机器不可用");
|
|
||||||
// }
|
@Override
|
||||||
// log.info("测试机器连接: {}", machineInfo.getHostIp());
|
public boolean testConnection(Long id) {
|
||||||
// connectionSession.setMachineInfo(machineInfo);
|
//先查询机器是否存在,在判断机器可用性
|
||||||
// try{
|
MachineInfo machineInfo = this.getById(id);
|
||||||
// connectionSession.connect();
|
if (machineInfo==null){
|
||||||
// return true;
|
throw new RuntimeException("机器不存在");
|
||||||
// } catch (Exception e) {
|
}
|
||||||
// log.error("机器连接测试失败: {}", e.getMessage(), e);
|
if (machineInfo.getStatusCode() == 0) {
|
||||||
// return false;
|
throw new RuntimeException("机器不可用");
|
||||||
// }
|
}
|
||||||
// }
|
log.info("测试机器连接: {}", machineInfo.getHostIp());
|
||||||
//
|
connectionSession.setMachineInfo(machineInfo);
|
||||||
// @Override
|
try{
|
||||||
// public ConnectionStatus getConnectionStatus(String machineName) {
|
connectionSession.connect();
|
||||||
// String sessionId = machineSessionMapping.get(machineName);
|
return true;
|
||||||
// if (sessionId == null) {
|
} catch (Exception e) {
|
||||||
// return ConnectionStatus.DISCONNECTED;
|
log.error("机器连接测试失败: {}", e.getMessage(), e);
|
||||||
// }
|
return false;
|
||||||
//
|
}
|
||||||
// ConnectionSession session = sessions.get(sessionId);
|
}
|
||||||
// return session != null ? session.getStatus() : ConnectionStatus.DISCONNECTED;
|
|
||||||
// }
|
@Override
|
||||||
//
|
public ConnectionStatus getConnectionStatus(String machineName) {
|
||||||
// @Override
|
String sessionId = machineSessionMapping.get(machineName);
|
||||||
// public Map<String, ConnectionStatus> getAllConnectionStatus() {
|
if (sessionId == null) {
|
||||||
// Map<String, ConnectionStatus> result = new HashMap<>();
|
return ConnectionStatus.DISCONNECTED;
|
||||||
//
|
}
|
||||||
// machineSessionMapping.forEach((machineName, sessionId) -> {
|
|
||||||
// ConnectionSession session = sessions.get(sessionId);
|
ConnectionSession session = sessions.get(sessionId);
|
||||||
// result.put(machineName, session != null ? session.getStatus() : ConnectionStatus.DISCONNECTED);
|
return session != null ? session.getStatus() : ConnectionStatus.DISCONNECTED;
|
||||||
// });
|
}
|
||||||
//
|
|
||||||
// return result;
|
@Override
|
||||||
// }
|
public Map<String, ConnectionStatus> getAllConnectionStatus() {
|
||||||
//
|
Map<String, ConnectionStatus> result = new HashMap<>();
|
||||||
// @Override
|
|
||||||
// public String connect(MachineInfo machineInfo) {
|
machineSessionMapping.forEach((machineName, sessionId) -> {
|
||||||
// if (machineInfo.getStatus().getCode() == UN_ENABLE) {
|
ConnectionSession session = sessions.get(sessionId);
|
||||||
// throw new RuntimeException("机器不可用");
|
result.put(machineName, session != null ? session.getStatus() : ConnectionStatus.DISCONNECTED);
|
||||||
// }
|
});
|
||||||
// log.info("建立机器连接: {}", machineInfo.getHostIp());
|
|
||||||
//
|
return result;
|
||||||
// // 检查是否已连接
|
}
|
||||||
// String existingSessionId = machineSessionMapping.get(machineInfo.getName());
|
|
||||||
// if (existingSessionId != null) {
|
@Override
|
||||||
// ConnectionSession existingSession = sessions.get(existingSessionId);
|
public String connect(MachineInfo machineInfo) {
|
||||||
// if (existingSession != null && existingSession.getStatus() == ConnectionStatus.CONNECTED) {
|
if (machineInfo.getStatus().getCode() == UN_ENABLE) {
|
||||||
// log.info("机器已连接,返回现有会话: {}", machineInfo.getHostIp());
|
throw new RuntimeException("机器不可用");
|
||||||
// return existingSessionId;
|
}
|
||||||
// }
|
log.info("建立机器连接: {}", machineInfo.getHostIp());
|
||||||
// }
|
|
||||||
//
|
// 检查是否已连接
|
||||||
// try {
|
String existingSessionId = machineSessionMapping.get(machineInfo.getName());
|
||||||
// connectionSession.setMachineInfo(machineInfo);
|
if (existingSessionId != null) {
|
||||||
//
|
ConnectionSession existingSession = sessions.get(existingSessionId);
|
||||||
// connectionSession.connect();
|
if (existingSession != null && existingSession.getStatus() == ConnectionStatus.CONNECTED) {
|
||||||
//
|
log.info("机器已连接,返回现有会话: {}", machineInfo.getHostIp());
|
||||||
// // 生成会话ID
|
return existingSessionId;
|
||||||
// String sessionId = generateSessionId();
|
}
|
||||||
//
|
}
|
||||||
// // 保存会话
|
|
||||||
// sessions.put(sessionId, connectionSession);
|
try {
|
||||||
// machineSessionMapping.put(machineInfo.getName(), sessionId);
|
connectionSession.setMachineInfo(machineInfo);
|
||||||
//
|
|
||||||
// log.info("机器连接成功: {}, 会话ID: {}", machineInfo.getHostIp(), sessionId);
|
connectionSession.connect();
|
||||||
// return sessionId;
|
|
||||||
// } catch (Exception e) {
|
// 生成会话ID
|
||||||
// log.error("机器连接失败: {}", e.getMessage(), e);
|
String sessionId = generateSessionId();
|
||||||
// throw new RuntimeException("机器连接失败: " + e.getMessage(), e);
|
|
||||||
// }
|
// 保存会话
|
||||||
// }
|
sessions.put(sessionId, connectionSession);
|
||||||
//
|
machineSessionMapping.put(machineInfo.getName(), sessionId);
|
||||||
// @Override
|
|
||||||
// public boolean disconnect(String sessionId) {
|
log.info("机器连接成功: {}, 会话ID: {}", machineInfo.getHostIp(), sessionId);
|
||||||
// log.info("断开机器连接: {}", sessionId);
|
return sessionId;
|
||||||
//
|
} catch (Exception e) {
|
||||||
// ConnectionSession session = sessions.get(sessionId);
|
log.error("机器连接失败: {}", e.getMessage(), e);
|
||||||
// if (session == null) {
|
throw new RuntimeException("机器连接失败: " + e.getMessage(), e);
|
||||||
// log.warn("会话不存在: {}", sessionId);
|
}
|
||||||
// return false;
|
}
|
||||||
// }
|
|
||||||
//
|
@Override
|
||||||
// try {
|
public boolean disconnect(String sessionId) {
|
||||||
// session.disconnect();
|
log.info("断开机器连接: {}", sessionId);
|
||||||
//
|
|
||||||
// // 清理会话
|
ConnectionSession session = sessions.get(sessionId);
|
||||||
// sessions.remove(sessionId);
|
if (session == null) {
|
||||||
// machineSessionMapping.entrySet().removeIf(entry -> entry.getValue().equals(sessionId));
|
log.warn("会话不存在: {}", sessionId);
|
||||||
//
|
return false;
|
||||||
// log.info("机器连接已断开: {}", sessionId);
|
}
|
||||||
// return true;
|
|
||||||
// } catch (Exception e) {
|
try {
|
||||||
// log.error("断开连接失败: {}", e.getMessage(), e);
|
session.disconnect();
|
||||||
// return false;
|
|
||||||
// }
|
// 清理会话
|
||||||
// }
|
sessions.remove(sessionId);
|
||||||
//
|
machineSessionMapping.entrySet().removeIf(entry -> entry.getValue().equals(sessionId));
|
||||||
// @Override
|
|
||||||
// public String executeCommand(String sessionId, String command) {
|
log.info("机器连接已断开: {}", sessionId);
|
||||||
// log.info("执行命令: {}, 会话ID: {}", command, sessionId);
|
return true;
|
||||||
//
|
} catch (Exception e) {
|
||||||
// ConnectionSession session = sessions.get(sessionId);
|
log.error("断开连接失败: {}", e.getMessage(), e);
|
||||||
// if (session == null) {
|
return false;
|
||||||
// throw new RuntimeException("会话不存在: " + sessionId);
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
@Override
|
||||||
// throw new RuntimeException("会话未连接: " + sessionId);
|
public String executeCommand(String sessionId, String command) {
|
||||||
// }
|
log.info("执行命令: {}, 会话ID: {}", command, sessionId);
|
||||||
//
|
|
||||||
// try {
|
ConnectionSession session = sessions.get(sessionId);
|
||||||
// return session.executeCommand(command);
|
if (session == null) {
|
||||||
// } catch (Exception e) {
|
throw new RuntimeException("会话不存在: " + sessionId);
|
||||||
// log.error("命令执行失败: {}", e.getMessage(), e);
|
}
|
||||||
// throw new RuntimeException("命令执行失败: " + e.getMessage(), e);
|
|
||||||
// }
|
if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
||||||
// }
|
throw new RuntimeException("会话未连接: " + sessionId);
|
||||||
//
|
}
|
||||||
// @Override
|
|
||||||
// public boolean uploadFile(String sessionId, String localFilePath, String remoteFilePath) {
|
try {
|
||||||
// log.info("上传文件: {} -> {}, 会话ID: {}", localFilePath, remoteFilePath, sessionId);
|
return session.executeCommand(command);
|
||||||
//
|
} catch (Exception e) {
|
||||||
// ConnectionSession session = sessions.get(sessionId);
|
log.error("命令执行失败: {}", e.getMessage(), e);
|
||||||
// if (session == null) {
|
throw new RuntimeException("命令执行失败: " + e.getMessage(), e);
|
||||||
// throw new RuntimeException("会话不存在: " + sessionId);
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
@Override
|
||||||
// throw new RuntimeException("会话未连接: " + sessionId);
|
public boolean uploadFile(String sessionId, String localFilePath, String remoteFilePath) {
|
||||||
// }
|
log.info("上传文件: {} -> {}, 会话ID: {}", localFilePath, remoteFilePath, sessionId);
|
||||||
//
|
|
||||||
// try {
|
ConnectionSession session = sessions.get(sessionId);
|
||||||
// return session.uploadFile(localFilePath, remoteFilePath);
|
if (session == null) {
|
||||||
// } catch (Exception e) {
|
throw new RuntimeException("会话不存在: " + sessionId);
|
||||||
// log.error("文件上传失败: {}", e.getMessage(), e);
|
}
|
||||||
// throw new RuntimeException("文件上传失败: " + e.getMessage(), e);
|
|
||||||
// }
|
if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
||||||
// }
|
throw new RuntimeException("会话未连接: " + sessionId);
|
||||||
//
|
}
|
||||||
// @Override
|
|
||||||
// public boolean downloadFile(String sessionId, String remoteFilePath, String localFilePath) {
|
try {
|
||||||
// log.info("下载文件: {} -> {}, 会话ID: {}", remoteFilePath, localFilePath, sessionId);
|
return session.uploadFile(localFilePath, remoteFilePath);
|
||||||
//
|
} catch (Exception e) {
|
||||||
// ConnectionSession session = sessions.get(sessionId);
|
log.error("文件上传失败: {}", e.getMessage(), e);
|
||||||
// if (session == null) {
|
throw new RuntimeException("文件上传失败: " + e.getMessage(), e);
|
||||||
// throw new RuntimeException("会话不存在: " + sessionId);
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
@Override
|
||||||
// throw new RuntimeException("会话未连接: " + sessionId);
|
public boolean downloadFile(String sessionId, String remoteFilePath, String localFilePath) {
|
||||||
// }
|
log.info("下载文件: {} -> {}, 会话ID: {}", remoteFilePath, localFilePath, sessionId);
|
||||||
//
|
|
||||||
// try {
|
ConnectionSession session = sessions.get(sessionId);
|
||||||
// return session.downloadFile(remoteFilePath, localFilePath);
|
if (session == null) {
|
||||||
// } catch (Exception e) {
|
throw new RuntimeException("会话不存在: " + sessionId);
|
||||||
// log.error("文件下载失败: {}", e.getMessage(), e);
|
}
|
||||||
// throw new RuntimeException("文件下载失败: " + e.getMessage(), e);
|
|
||||||
// }
|
if (session.getStatus() != ConnectionStatus.CONNECTED) {
|
||||||
// }
|
throw new RuntimeException("会话未连接: " + sessionId);
|
||||||
//
|
}
|
||||||
//
|
|
||||||
// /**
|
try {
|
||||||
// * 生成会话ID
|
return session.downloadFile(remoteFilePath, localFilePath);
|
||||||
// */
|
} catch (Exception e) {
|
||||||
// private String generateSessionId() {
|
log.error("文件下载失败: {}", e.getMessage(), e);
|
||||||
// return "session-" + sessionIdGenerator.incrementAndGet();
|
throw new RuntimeException("文件下载失败: " + e.getMessage(), e);
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成会话ID
|
||||||
|
*/
|
||||||
|
private String generateSessionId() {
|
||||||
|
return "session-" + sessionIdGenerator.incrementAndGet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,159 +1,160 @@
|
|||||||
//package cd.casic.module.machine.service.impl;
|
package cd.casic.module.machine.service.impl;
|
||||||
//
|
|
||||||
//import cd.casic.module.machine.controller.vo.SecretKeyDto;
|
import cd.casic.module.machine.dto.SecretKeyDto;
|
||||||
//import cd.casic.module.machine.dal.dataobject.MachineInfo;
|
import cd.casic.module.machine.entity.MachineInfo;
|
||||||
//import cd.casic.module.machine.dal.dataobject.SecretKey;
|
import cd.casic.module.machine.entity.SecretKey;
|
||||||
//import cd.casic.module.machine.dal.mysql.SecretServiceMapper;
|
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;
|
||||||
//import cd.casic.module.machine.service.MachineInfoService;
|
//import cd.casic.module.machine.service.MachineInfoService;
|
||||||
//import cn.hutool.core.io.resource.ResourceUtil;
|
import cd.casic.module.machine.service.SecretKeyService;
|
||||||
//import cn.hutool.core.util.IdUtil;
|
import jakarta.annotation.Resource;
|
||||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import org.springframework.beans.BeanUtils;
|
||||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import org.springframework.stereotype.Service;
|
||||||
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
//
|
import java.util.List;
|
||||||
//import cd.casic.module.machine.utils.AliYunOssClient;
|
|
||||||
//import cd.casic.module.machine.exception.ServiceException;
|
@Service
|
||||||
////import cd.casic.module.machine.service.MachineInfoService;
|
public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, SecretKey> implements SecretKeyService {
|
||||||
//import cd.casic.module.machine.service.SecretKeyService;
|
|
||||||
//import jakarta.annotation.Resource;
|
@Resource
|
||||||
//import org.springframework.beans.BeanUtils;
|
private MachineInfoService machineInfoService;
|
||||||
//import org.springframework.stereotype.Service;
|
|
||||||
//
|
@Resource
|
||||||
//import java.util.List;
|
private AliYunOssClient aliYunOssClient;
|
||||||
//
|
|
||||||
//@Service
|
@Resource
|
||||||
//public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, SecretKey> implements SecretKeyService {
|
private SecretServiceMapper secretServiceMapper;
|
||||||
//
|
|
||||||
// @Resource
|
|
||||||
// private MachineInfoService machineInfoService;
|
|
||||||
//
|
|
||||||
// @Resource
|
@Override
|
||||||
// private AliYunOssClient aliYunOssClient;
|
public boolean addSecretKey(SecretKeyDto secretKeyDto){
|
||||||
//
|
if (secretKeyDto.getPath()==null)
|
||||||
// @Resource
|
{
|
||||||
// private SecretServiceMapper secretServiceMapper;
|
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥不能为空");
|
||||||
//
|
}
|
||||||
//
|
|
||||||
//
|
String ossPath = upLoadSecretKey(secretKeyDto.getPath());
|
||||||
//
|
if (ossPath == null){
|
||||||
// @Override
|
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥上传失败");
|
||||||
// public boolean addSecretKey(SecretKeyDto secretKeyDto){
|
}
|
||||||
// if (secretKeyDto.getPath()==null)
|
secretKeyDto.setPath(ossPath);
|
||||||
// {
|
SecretKey secretKey = new SecretKey();
|
||||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥不能为空");
|
BeanUtils.copyProperties(secretKeyDto,secretKey);
|
||||||
// }
|
//todo检查密钥合法
|
||||||
//
|
return this.save(secretKey);
|
||||||
// String ossPath = upLoadSecretKey(secretKeyDto.getPath());
|
|
||||||
// if (ossPath == null){
|
|
||||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥上传失败");
|
}
|
||||||
// }
|
@Override
|
||||||
// secretKeyDto.setPath(ossPath);
|
public boolean updateSecretKey(SecretKeyDto secretKeyDto) {
|
||||||
// SecretKey secretKey = new SecretKey();
|
|
||||||
// BeanUtils.copyProperties(secretKeyDto,secretKey);
|
Long id = secretKeyDto.getId();
|
||||||
// //todo检查密钥合法
|
SecretKey secretKey = this.getById(id);
|
||||||
// return this.save(secretKey);
|
if (secretKey == null){
|
||||||
//
|
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥不存在");
|
||||||
//
|
}
|
||||||
// }
|
if (!secretKey.getPath().equals(secretKeyDto.getPath())) {
|
||||||
// @Override
|
//todo检查密钥合法
|
||||||
// public boolean updateSecretKey(SecretKeyDto secretKeyDto) {
|
String ossPath = upLoadSecretKey(secretKeyDto.getPath());
|
||||||
//
|
BeanUtils.copyProperties(secretKeyDto,secretKey);
|
||||||
// Long id = secretKeyDto.getId();
|
secretKey.setPath(ossPath);
|
||||||
// SecretKey secretKey = this.getById(id);
|
}
|
||||||
// if (secretKey == null){
|
else {
|
||||||
// throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"密钥不存在");
|
BeanUtils.copyProperties(secretKeyDto,secretKey);
|
||||||
// }
|
}
|
||||||
// if (!secretKey.getPath().equals(secretKeyDto.getPath())) {
|
|
||||||
// //todo检查密钥合法
|
return this.updateById(secretKey);
|
||||||
// String ossPath = upLoadSecretKey(secretKeyDto.getPath());
|
|
||||||
// BeanUtils.copyProperties(secretKeyDto,secretKey);
|
|
||||||
// secretKey.setPath(ossPath);
|
}
|
||||||
// }
|
|
||||||
// else {
|
@Override
|
||||||
// BeanUtils.copyProperties(secretKeyDto,secretKey);
|
public void bindingMachine(Long secretKeyId, List<Long> machineIds) {
|
||||||
// }
|
SecretKey secretKey = this.getById(secretKeyId);
|
||||||
//
|
if (secretKey==null){
|
||||||
// return this.updateById(secretKey);
|
throw new ServiceException(ServiceException.SECRETKEY_NULL,"密钥不存在");
|
||||||
//
|
}
|
||||||
//
|
List<MachineInfo> machineList = machineInfoService.listByIds(machineIds);
|
||||||
// }
|
machineList.forEach(machine -> machine.setSecretKeyId(secretKeyId));
|
||||||
//
|
machineInfoService.updateBatchById(machineList);
|
||||||
// @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);
|
@Override
|
||||||
// machineList.forEach(machine -> machine.setSecretKeyId(secretKeyId));
|
public PageResult<SecretKey> listSecretKey(SecretKeyDto secretKeyDto) {
|
||||||
// machineInfoService.updateBatchById(machineList);
|
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());
|
||||||
//
|
}
|
||||||
// @Override
|
Page<SecretKey> page = secretServiceMapper.selectPage(new Page<>(secretKeyDto.getPageIndex(), secretKeyDto.getPageSize()), queryWrapper);
|
||||||
// public PageResult<SecretKey> listSecretKey(SecretKeyDto secretKeyDto) {
|
return new PageResult<>(
|
||||||
// QueryWrapper<SecretKey> queryWrapper = new QueryWrapper<>();
|
page.getCurrent(),
|
||||||
// if (secretKeyDto.getName() != null && !secretKeyDto.getName().isEmpty()){
|
page.getSize(),
|
||||||
// queryWrapper.like("name", secretKeyDto.getName());
|
page.getTotal(),
|
||||||
// }
|
page.getPages(),
|
||||||
// if (secretKeyDto.getDescription() != null && !secretKeyDto.getDescription().isEmpty()){
|
page.getRecords()
|
||||||
// queryWrapper.like("description", secretKeyDto.getDescription());
|
);
|
||||||
// }
|
}
|
||||||
// Page<SecretKey> page = secretServiceMapper.selectPage(new Page<>(secretKeyDto.getPageIndex(), secretKeyDto.getPageSize()), queryWrapper);
|
|
||||||
// return new PageResult<>(
|
|
||||||
// page.getCurrent(),
|
|
||||||
// page.getSize(),
|
@Override
|
||||||
// page.getTotal(),
|
public boolean deleteList(List<Long> secretKeyIds) {
|
||||||
// page.getPages(),
|
List<SecretKey> secretKeys = this.listByIds(secretKeyIds);
|
||||||
// page.getRecords()
|
|
||||||
// );
|
for (SecretKey secretKey : secretKeys) {
|
||||||
// }
|
if (secretKey.getPath() != null && !secretKey.getPath().isEmpty()){
|
||||||
//
|
try {
|
||||||
//
|
//文件名
|
||||||
//
|
//删除子目录文件,需要在前面加上根目录文件路径
|
||||||
// @Override
|
String fileName = secretKey.getPath().substring(secretKey.getPath().lastIndexOf("/") + 1);
|
||||||
// public boolean deleteList(List<Long> secretKeyIds) {
|
aliYunOssClient.delete(fileName);
|
||||||
// List<SecretKey> secretKeys = this.listByIds(secretKeyIds);
|
} catch (Exception e) {
|
||||||
//
|
throw new RuntimeException(e);
|
||||||
// for (SecretKey secretKey : secretKeys) {
|
}
|
||||||
// if (secretKey.getPath() != null && !secretKey.getPath().isEmpty()){
|
}
|
||||||
// try {
|
}
|
||||||
// //文件名
|
|
||||||
// //删除子目录文件,需要在前面加上根目录文件路径
|
|
||||||
// String fileName = secretKey.getPath().substring(secretKey.getPath().lastIndexOf("/") + 1);
|
//todo是否删除已经绑定的机器
|
||||||
// aliYunOssClient.delete(fileName);
|
return secretServiceMapper.deleteBatchIds(secretKeyIds) > 0 ;
|
||||||
// } catch (Exception e) {
|
}
|
||||||
// throw new RuntimeException(e);
|
|
||||||
// }
|
|
||||||
// }
|
public String upLoadSecretKey(String localPath) {
|
||||||
// }
|
|
||||||
//
|
//使用S3FileClient上传文件
|
||||||
//
|
aliYunOssClient.init();
|
||||||
// //todo是否删除已经绑定的机器
|
|
||||||
// return secretServiceMapper.deleteBatchIds(secretKeyIds) > 0 ;
|
//传输到指定文件,需要在path前面加上文件路径
|
||||||
// }
|
String path = IdUtil.fastSimpleUUID() + ".txt";
|
||||||
//
|
|
||||||
//
|
|
||||||
// public String upLoadSecretKey(String localPath) {
|
//上传文件是从本地上传,这里传的是本地文件地址
|
||||||
//
|
byte[] content = ResourceUtil.readBytes(localPath);
|
||||||
// //使用S3FileClient上传文件
|
String ossPath;
|
||||||
// aliYunOssClient.init();
|
try {
|
||||||
//
|
ossPath = aliYunOssClient.upload(content, path, "txt");
|
||||||
// //传输到指定文件,需要在path前面加上文件路径
|
}catch (Exception e) {
|
||||||
// String path = IdUtil.fastSimpleUUID() + ".txt";
|
throw new RuntimeException(e+"上传文件失败");
|
||||||
//
|
}
|
||||||
//
|
return ossPath;
|
||||||
// //上传文件是从本地上传,这里传的是本地文件地址
|
}
|
||||||
// byte[] content = ResourceUtil.readBytes(localPath);
|
}
|
||||||
// String ossPath;
|
|
||||||
// try {
|
|
||||||
// ossPath = aliYunOssClient.upload(content, path, "txt");
|
|
||||||
// }catch (Exception e) {
|
|
||||||
// throw new RuntimeException(e+"上传文件失败");
|
|
||||||
// }
|
|
||||||
// return ossPath;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package cd.casic.module.machine.utils;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页结果通用类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PageResult<T> implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前页码
|
||||||
|
*/
|
||||||
|
private Long pageNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每页数量
|
||||||
|
*/
|
||||||
|
private Long pageSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总记录数
|
||||||
|
*/
|
||||||
|
private Long total;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总页数
|
||||||
|
*/
|
||||||
|
private Long pages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据列表
|
||||||
|
*/
|
||||||
|
private List<T> list;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user