Merge remote-tracking branch 'origin/jenkins-engin' into jenkins-engin

This commit is contained in:
唐潇凯 2025-06-03 14:14:54 +08:00
commit 818c2e0198
7 changed files with 60 additions and 60 deletions

View File

@ -28,13 +28,6 @@
<version>3.15.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- 机器连接-->
<dependency>
<groupId>com.jcraft</groupId>

View File

@ -3,16 +3,19 @@ package cd.casic.module.machine.controller;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.module.machine.entity.MachineInfo;
import cd.casic.module.machine.enums.ConnectionStatus;
import cd.casic.module.machine.service.MachineInfoService;
import cd.casic.module.machine.dto.MachineInfoDto;
import cd.casic.module.machine.pojo.SuccessResponseData;
import cd.casic.module.machine.utils.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import static cd.casic.framework.commons.pojo.CommonResult.success;
@ -25,88 +28,82 @@ public class MachineInfoController {
@PostMapping("/add")
@Operation(summary = "新增机器信息")
public CommonResult add(@RequestBody MachineInfoDto machineInfoDto) {
machineInfoService.addMachineInfo(machineInfoDto);
return success(true);
public CommonResult<Boolean> add(@RequestBody MachineInfoDto machineInfoDto) {
return success(machineInfoService.addMachineInfo(machineInfoDto));
}
@GetMapping("/list")
@Operation(summary = "获取机器信息列表")
public CommonResult list(@RequestBody MachineInfoDto machineInfoDto) {
public CommonResult<PageResult<MachineInfoDto>> list(@RequestBody MachineInfoDto machineInfoDto) {
return success(machineInfoService.listMachineInfo(machineInfoDto));
}
@PutMapping("/update")
@Operation(summary = "编辑机器信息")
public CommonResult update(@RequestBody MachineInfoDto machineInfoDto) {
machineInfoService.updateMachineInfo(machineInfoDto);
return success(true);
public CommonResult<Boolean> update(@RequestBody MachineInfoDto machineInfoDto) {
return success(machineInfoService.updateMachineInfo(machineInfoDto));
}
@PutMapping("/updateStatus")
@Operation(summary = "机器启用/停用")
public CommonResult updateStatus(@RequestParam("machineInfoId") Long machineInfoId, @RequestParam("status") String status) {
machineInfoService.updateStatus(machineInfoId, status);
return success(true);
public CommonResult<Boolean> updateStatus(@RequestParam("machineInfoId") Long machineInfoId, @RequestParam("status") String status) {
return success(machineInfoService.updateStatus(machineInfoId, status));
}
@PutMapping("/bindingSecretKey")
@Operation(summary = "绑定密钥")
public CommonResult bindingSecretKey(@RequestParam("machineInfoId") Long machineInfoId, @RequestParam("secretKeyId") Long secretKeyId) {
machineInfoService.bindingSecretKey(machineInfoId, secretKeyId);
return success(true);
public CommonResult<Boolean> bindingSecretKey(@RequestParam("machineInfoId") Long machineInfoId, @RequestParam("secretKeyId") Long secretKeyId) {
return success(machineInfoService.bindingSecretKey(machineInfoId, secretKeyId));
}
@DeleteMapping("/delete")
@Operation(summary = "机器信息删除")
public CommonResult delete(@RequestParam("machineInfoId") Long machineInfoId) {
public CommonResult<Boolean> delete(@RequestParam("machineInfoId") Long machineInfoId) {
machineInfoService.deleteMachineInfo(machineInfoId);
return success(true);
}
@DeleteMapping("/deleteList")
@Operation(summary = "批量删除机器信息")
public CommonResult deleteList(@RequestParam("machineInfoId") List<Long> machineInfoIds) {
public CommonResult<Boolean> deleteList(@RequestParam("machineInfoIds") List<Long> machineInfoIds) {
machineInfoService.deleteList(machineInfoIds);
return success(true);
}
@PostMapping("/test")
@Operation(summary = "测试机器连接")
public CommonResult testConnection(@RequestBody MachineInfo machineInfo) {
machineInfoService.testConnection(machineInfo);
return success(true);
public CommonResult<Boolean> testConnection(@RequestBody MachineInfo machineInfo) {
return success(machineInfoService.testConnection(machineInfo));
}
@GetMapping("/status/{machineName}")
@Operation(summary = "获取机器连接状态")
public CommonResult getConnectionStatus(@PathVariable String machineName) {
public CommonResult<ConnectionStatus> getConnectionStatus(@PathVariable String machineName) {
return success(machineInfoService.getConnectionStatus(machineName));
}
@GetMapping("/status/all")
@Operation(summary = "获取所有机器连接状态")
public CommonResult getAllConnectionStatus() {
public CommonResult<Map<String, ConnectionStatus>> getAllConnectionStatus() {
return success(machineInfoService.getAllConnectionStatus());
}
@PostMapping("/connect")
@Operation(summary = "建立机器连接")
public CommonResult connect(@RequestBody MachineInfo machineInfo) {
public CommonResult<String> connect(@RequestBody MachineInfo machineInfo) {
return success(machineInfoService.connect(machineInfo));
}
@PostMapping("/disconnect/{sessionId}")
@Operation(summary = "断开机器连接")
public CommonResult disconnect(@PathVariable String sessionId) {
machineInfoService.disconnect(sessionId);
return success(true);
public CommonResult<Boolean> disconnect(@PathVariable String sessionId) {
return success(machineInfoService.disconnect(sessionId));
}
@PostMapping("/execute/{sessionId}")
@Operation(summary = "执行远程命令")
public CommonResult executeCommand(
public CommonResult<String> executeCommand(
@PathVariable String sessionId,
@RequestBody String command) {
@ -115,21 +112,19 @@ public class MachineInfoController {
@PostMapping("/upload/{sessionId}")
@Operation(summary = "上传文件到远程机器")
public CommonResult uploadFile(
public CommonResult<Boolean> uploadFile(
@PathVariable String sessionId,
@RequestParam String localFilePath,
@RequestParam String remoteFilePath) {
machineInfoService.uploadFile(sessionId, localFilePath, remoteFilePath);
return success(true);
return success(machineInfoService.uploadFile(sessionId, localFilePath, remoteFilePath));
}
@PostMapping("/download/{sessionId}")
@Operation(summary = "从远程机器下载文件")
public CommonResult downloadFile(
public CommonResult<Boolean> downloadFile(
@PathVariable String sessionId,
@RequestParam String remoteFilePath,
@RequestParam String localFilePath) {
machineInfoService.downloadFile(sessionId, remoteFilePath, localFilePath);
return success(true);
return success(machineInfoService.downloadFile(sessionId, remoteFilePath, localFilePath));
}
}

View File

@ -1,7 +1,9 @@
package cd.casic.module.machine.controller;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.module.machine.entity.SecretKey;
import cd.casic.module.machine.service.SecretKeyService;
import cd.casic.module.machine.dto.SecretKeyDto;
import cd.casic.module.machine.utils.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
@ -30,43 +32,39 @@ public class SecretKeyController {
@PostMapping(value = "/add", consumes = "multipart/form-data")
@Operation(summary ="新增密钥")
public CommonResult add(@RequestPart("secretKeyDto") SecretKeyDto secretKeyDto, @RequestPart("file") MultipartFile file) {
secretKeyService.addSecretKey(secretKeyDto, file);
return success(true);
public CommonResult<Boolean> add(@RequestBody SecretKeyDto secretKeyDto, @RequestPart("file") MultipartFile file) {
return success(secretKeyService.addSecretKey(secretKeyDto, file));
}
@PutMapping("/bindingMachine")
@Operation(summary ="绑定机器")
public CommonResult bindingMachine(@RequestParam("secretKeyId") Long secretKeyId, @RequestParam("machineInfoIds") List<Long> machineInfoIds) {
public CommonResult<Boolean> bindingMachine(@RequestParam("secretKeyId") Long secretKeyId, @RequestParam("machineInfoIds") List<Long> machineInfoIds) {
secretKeyService.bindingMachine(secretKeyId, machineInfoIds);
return success(true);
}
@PutMapping("/update")
@Operation(summary ="编辑密钥信息")
public CommonResult update(@RequestPart("secretKeyDto") SecretKeyDto secretKeyDto, @RequestPart(value = "file", required = false) MultipartFile file) {
secretKeyService.updateSecretKey(secretKeyDto, file);
return success(true);
public CommonResult<Boolean> update(@RequestBody SecretKeyDto secretKeyDto, @RequestPart(value = "file", required = false) MultipartFile file) {
return success(secretKeyService.updateSecretKey(secretKeyDto, file));
}
@DeleteMapping("/delete")
@Operation(summary ="删除密钥")
public CommonResult delete(@RequestParam("secretKeyId") Long secretKeyId) {
secretKeyService.deleteSecretKey(secretKeyId);
return success(true);
public CommonResult<Boolean> delete(@RequestParam("secretKeyId") Long secretKeyId) {
return success(secretKeyService.deleteSecretKey(secretKeyId));
}
@DeleteMapping("/deleteList")
@Operation(summary ="批量删除密钥")
public CommonResult deleteList(@RequestParam("secretKeyId") List<Long> secretKeyIds) {
secretKeyService.deleteList(secretKeyIds);
return success(true);
public CommonResult<Boolean> deleteList(@RequestParam("secretKeyId") List<Long> secretKeyIds) {
return success(secretKeyService.deleteList(secretKeyIds));
}
@GetMapping("/list")
@Operation(summary ="获取密钥信息列表")
public CommonResult list(@RequestBody SecretKeyDto secretKeyDto) {
public CommonResult<PageResult<SecretKey>> list(@RequestBody SecretKeyDto secretKeyDto) {
return success(secretKeyService.listSecretKey(secretKeyDto));
}

View File

@ -40,5 +40,5 @@ public class MachineInfoDto extends cd.casic.module.machine.dto.PageDto {
private String authenticationType;
private String machineInfoTypeCode;
private String machineInfoType;
}

View File

@ -61,5 +61,6 @@ public class MachineInfo extends BaseEntity{
@TableField(value = "authentication_type_code")
private int authenticationTypeCode;
@TableField(exist = false)
private AuthenticationType authenticationType;
}

View File

@ -1,5 +1,6 @@
package cd.casic.module.machine.service.impl;
import cd.casic.module.machine.enums.MachineInfoType;
import cd.casic.module.machine.handler.ConnectionSession;
import cd.casic.module.machine.mapper.MachineInfoMapper;
import cd.casic.module.machine.dto.MachineInfoDto;
@ -64,6 +65,11 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
? AuthenticationType.PASSWORD.getCode()
: AuthenticationType.SECRET_KEY.getCode()
);
machineInfo.setMachineInfoTypeCode(
"Windows".equals(machineInfoDto.getMachineInfoType())
? MachineInfoType.WINDOWS.getCode()
: MachineInfoType.Linux.getCode()
);
return this.save(machineInfo);
}
@ -81,8 +87,9 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
MachineInfoDto dto = new MachineInfoDto();
BeanUtils.copyProperties(machineInfo, dto);
// 直接调用原有枚举转换方法
dto.setStatus(EnumUtils.getEnumByCode(machineInfo.getStatus(), MachineInfoStatus.class).getMessage());
dto.setAuthenticationType(EnumUtils.getEnumByCode(machineInfo.getAuthenticationType(), AuthenticationType.class).getMessage());
dto.setMachineInfoType(EnumUtils.getEnumByCode(machineInfo.getMachineInfoTypeCode(), MachineInfoType.class).getMessage());
dto.setStatus(EnumUtils.getEnumByCode(machineInfo.getStatusCode(), MachineInfoStatus.class).getMessage());
dto.setAuthenticationType(EnumUtils.getEnumByCode(machineInfo.getAuthenticationTypeCode(), AuthenticationType.class).getMessage());
return dto;
})
.toList();
@ -100,10 +107,15 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
public boolean updateMachineInfo(MachineInfoDto machineInfoDto) {
MachineInfo machineInfo = new MachineInfo();
BeanUtils.copyProperties(machineInfoDto, machineInfo);
machineInfo.setAuthenticationType(
machineInfo.setAuthenticationTypeCode(
"密码认证".equals(machineInfoDto.getAuthenticationType())
? AuthenticationType.PASSWORD
: AuthenticationType.SECRET_KEY
? AuthenticationType.PASSWORD.getCode()
: AuthenticationType.SECRET_KEY.getCode()
);
machineInfo.setMachineInfoTypeCode(
"Windows".equals(machineInfoDto.getMachineInfoType())
? MachineInfoType.WINDOWS.getCode()
: MachineInfoType.Linux.getCode()
);
return this.updateById(machineInfo);
}
@ -111,14 +123,14 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
@Override
public boolean updateStatus(Long machineInfoId, String status) {
UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", machineInfoId).set("status", status);
updateWrapper.eq("id", machineInfoId).set("status_code", EnumUtils.getEnumByMessage(status, MachineInfoStatus.class).getCode());
return this.update(updateWrapper);
}
@Override
public boolean bindingSecretKey(Long machineInfoId, Long secretKeyId) {
UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", machineInfoId).set("secretKeyId", secretKeyId);
updateWrapper.eq("id", machineInfoId).set("secret_key_id", secretKeyId).set("authentication_type_code",2);
return this.update(updateWrapper);
}

View File

@ -64,6 +64,7 @@ public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, Secre
public void bindingMachine(Long secretKeyId, List<Long> machineInfoIds) {
List<MachineInfo> machineInfos = machineInfoService.listByIds(machineInfoIds);
machineInfos.forEach(machineInfo -> machineInfo.setSecretKeyId(secretKeyId));
machineInfoService.updateBatchById(machineInfos);
}
@Override