Compare commits

..

2 Commits

Author SHA1 Message Date
zyj
c26a183209 Merge remote-tracking branch 'origin/jenkins-engin' into jenkins-engin 2025-06-04 11:03:55 +08:00
zyj
4b8dfe978a 机器管理调试更改 2025-06-04 11:03:35 +08:00
22 changed files with 123 additions and 229 deletions

View File

@ -44,23 +44,21 @@ public class MachineEnvController {
@DeleteMapping("/delete")
@Operation(summary = "删除机器的环境变量")
public CommonResult deleteByMachineId(
@RequestParam Long machineId) {
machineEnvService.deleteByMachineId(machineId);
public CommonResult deleteByMachineId(@RequestParam Long machineEvnId) {
machineEnvService.deleteByMachineId(machineEvnId);
return success(true);
}
@DeleteMapping("/deleteList")
@Operation(summary = "批量删除机器环境变量")
public CommonResult deleteList(@RequestParam List<Long> ids){
public CommonResult deleteList(@RequestParam String ids){
machineEnvService.deleteList(ids);
return success(true);
}
@GetMapping("/getByMachineId")
@Operation(summary = "获取机器的环境变量")
public CommonResult getByMachineId(
@RequestParam Long machineId) {
public CommonResult getByMachineId(@RequestParam Long machineId) {
return success(machineEnvService.getByMachineId(machineId));
}

View File

@ -6,7 +6,6 @@ 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;
@ -33,7 +32,7 @@ public class MachineInfoController {
}
@GetMapping("/list")
@PostMapping("/list")
@Operation(summary = "获取机器信息列表")
public CommonResult<PageResult<MachineInfoDto>> list(@RequestBody MachineInfoDto machineInfoDto) {
return success(machineInfoService.listMachineInfo(machineInfoDto));
@ -47,26 +46,26 @@ public class MachineInfoController {
@PutMapping("/updateStatus")
@Operation(summary = "机器启用/停用")
public CommonResult<Boolean> updateStatus(@RequestParam("machineInfoId") Long machineInfoId, @RequestParam("status") String status) {
return success(machineInfoService.updateStatus(machineInfoId, status));
public CommonResult<Boolean> updateStatus(@RequestBody MachineInfoDto machineInfoDto) {
return success(machineInfoService.updateStatus(machineInfoDto));
}
@PutMapping("/bindingSecretKey")
@Operation(summary = "绑定密钥")
public CommonResult<Boolean> bindingSecretKey(@RequestParam("machineInfoId") Long machineInfoId, @RequestParam("secretKeyId") Long secretKeyId) {
return success(machineInfoService.bindingSecretKey(machineInfoId, secretKeyId));
public CommonResult<Boolean> bindingSecretKey(@RequestBody MachineInfoDto machineInfoDto) {
return success(machineInfoService.bindingSecretKey(machineInfoDto));
}
@DeleteMapping("/delete")
@Operation(summary = "机器信息删除")
public CommonResult<Boolean> delete(@RequestParam("machineInfoId") Long machineInfoId) {
public CommonResult<Boolean> delete(@RequestParam Long machineInfoId) {
machineInfoService.deleteMachineInfo(machineInfoId);
return success(true);
}
@DeleteMapping("/deleteList")
@Operation(summary = "批量删除机器信息")
public CommonResult<Boolean> deleteList(@RequestParam("machineInfoIds") List<Long> machineInfoIds) {
public CommonResult<Boolean> deleteList(@RequestParam String machineInfoIds) {
machineInfoService.deleteList(machineInfoIds);
return success(true);
}

View File

@ -33,7 +33,7 @@ public class MachineProxyController {
return success(true);
}
@GetMapping("/list")
@PostMapping("/list")
@Operation(summary ="获取代理列表")
public CommonResult list(MachineProxyDTO machineProxyDTO) {
return success(machineProxyService.list(machineProxyDTO));
@ -52,18 +52,17 @@ public class MachineProxyController {
return success(machineProxyService.getStatusStatistics());
}
@PutMapping("/updateConfig")
@Operation(summary ="更新代理配置")
@PutMapping("/update")
@Operation(summary ="更新代理信息")
public CommonResult updateConfig(@RequestBody MachineProxyDTO machineProxyDTO) {
machineProxyService.updateConfig(machineProxyDTO);
machineProxyService.update(machineProxyDTO);
return success(true);
}
@DeleteMapping("/batch")
@Operation(summary ="批量删除代理")
public CommonResult deleteBatch(@RequestParam List<Long> ids) {
machineProxyService.delete(ids);
return success(true);
public CommonResult deleteBatch(@RequestParam String ids) {
return success(machineProxyService.delete(ids));
}
}

View File

@ -19,8 +19,6 @@ import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import static cd.casic.framework.commons.pojo.CommonResult.success;
@RestController
@ -38,8 +36,8 @@ public class SecretKeyController {
@PutMapping("/bindingMachine")
@Operation(summary ="绑定机器")
public CommonResult<Boolean> bindingMachine(@RequestParam("secretKeyId") Long secretKeyId, @RequestParam("machineInfoIds") List<Long> machineInfoIds) {
secretKeyService.bindingMachine(secretKeyId, machineInfoIds);
public CommonResult<Boolean> bindingMachine(@RequestBody SecretKeyDto secretKeyDto) {
secretKeyService.bindingMachine(secretKeyDto);
return success(true);
}
@ -52,17 +50,17 @@ public class SecretKeyController {
@DeleteMapping("/delete")
@Operation(summary ="删除密钥")
public CommonResult<Boolean> delete(@RequestParam("secretKeyId") Long secretKeyId) {
public CommonResult<Boolean> delete(@RequestParam Long secretKeyId) {
return success(secretKeyService.deleteSecretKey(secretKeyId));
}
@DeleteMapping("/deleteList")
@Operation(summary ="批量删除密钥")
public CommonResult<Boolean> deleteList(@RequestParam("secretKeyId") List<Long> secretKeyIds) {
public CommonResult<Boolean> deleteList(@RequestParam String secretKeyIds) {
return success(secretKeyService.deleteList(secretKeyIds));
}
@GetMapping("/list")
@PostMapping("/list")
@Operation(summary ="获取密钥信息列表")
public CommonResult<PageResult<SecretKey>> list(@RequestBody SecretKeyDto secretKeyDto) {
return success(secretKeyService.listSecretKey(secretKeyDto));

View File

@ -19,27 +19,10 @@ public class MachineEnvDTO extends PageDto implements Serializable {
private Long id;
private String envKey;
private String envValue;
private Integer sensitive;//(1敏感0不敏感)
private String description;
private Long machineId;
private Date createDate;
private Date updateDate;
private String sortField;
private String sortDirection;
/**
* 获取脱敏后的环境变量值
*/
public String getMaskedValue() {
if (sensitive==1 || envValue == null) {
return envValue;
}
int length = envValue.length();
if (length <= 4) {
return "****";
} else {
return envValue.substring(0, 2) + "****" + envValue.substring(length - 2);
}
}
}

View File

@ -11,7 +11,7 @@ import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MachineInfoDto extends cd.casic.module.machine.dto.PageDto {
public class MachineInfoDto extends PageDto {
private Long id;
private Date createDate;
@ -41,4 +41,6 @@ public class MachineInfoDto extends cd.casic.module.machine.dto.PageDto {
private String authenticationType;
private String machineInfoType;
private int isProxy;
}

View File

@ -23,12 +23,12 @@ public class MachineProxyDTO extends PageDto implements Serializable {
private String version;
private String status;
private Date lastHeartbeatTime;
private String config;
private String description;
private String hostIp;
private String sshPort;
private Date createDate;
private Date updateDate;
private String password;
/**
* 计算代理是否在线

View File

@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
@ -33,4 +34,6 @@ public class SecretKeyDto extends PageDto {
private Date createDate;
private Date updateDate;
private List<Long> machineInfoIds;
}

View File

@ -34,11 +34,6 @@ public class MachineEnv extends BaseEntity implements Serializable {
*/
private String envValue;
/**
* 是否敏感
*/
@TableField("`sensitive`")
private Integer sensitive;//(1敏感0不敏感)
/**
* 描述信息

View File

@ -63,4 +63,7 @@ public class MachineInfo extends BaseEntity{
@TableField(exist = false)
private AuthenticationType authenticationType;
@TableField(value = "is_proxy")
private int isProxy;
}

View File

@ -2,6 +2,7 @@ package cd.casic.module.machine.entity;
import com.baomidou.mybatisplus.annotation.*;
import cd.casic.module.machine.enums.MachineInfoStatus;
import cd.casic.module.machine.enums.MachineProxyType;
import jakarta.validation.Valid;
import lombok.*;
import java.io.Serializable;
@ -19,8 +20,10 @@ import java.util.Date;
public class MachineProxy extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@TableField(value = "host_ip")
private String hostIp;
@TableField(value = "ssh_port")
private String sshPort;
/**
@ -29,11 +32,13 @@ public class MachineProxy extends BaseEntity implements Serializable {
@TableField(exist = false)
private MachineProxyType proxyType;
@TableField(value = "proxy_type_code")
private int proxyTypeCode;
/**
* 代理版本
*/
@TableField(value = "version")
private String version;
/**
@ -42,22 +47,23 @@ public class MachineProxy extends BaseEntity implements Serializable {
@TableField(exist = false)
private MachineInfoStatus status;
@TableField(value = "status_code")
private int statusCode;
@TableField(value = "username")
private String username;
/**
* 最后心跳时间
*/
private Date lastHeartbeatTime;
/**
* 代理配置 (JSON格式)
*/
private String config;
@TableField(value = "password")
private String password;
/**
* 描述信息
*/
@TableField(value = "description")
private String description;

View File

@ -1,26 +0,0 @@
package cd.casic.module.machine.pojo;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class ErrorResponseData extends ResponseData {
/**
* 异常的具体类名称
*/
private String exceptionClazz;
public ErrorResponseData(String message) {
super(false, DEFAULT_ERROR_CODE, message, null);
}
public ErrorResponseData(Integer code, String message) {
super(false, code, message, null);
}
public ErrorResponseData(Integer code, String message, Object object) {
super(false, code, message, object);
}
}

View File

@ -1,72 +0,0 @@
package cd.casic.module.machine.pojo;
import lombok.Data;
/**
* 响应结果数据
*/
@Data
public class ResponseData {
public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功";
public static final String DEFAULT_ERROR_MESSAGE = "网络异常";
public static final Integer DEFAULT_SUCCESS_CODE = 200;
public static final Integer DEFAULT_ERROR_CODE = 500;
/**
* 请求是否成功
*/
private Boolean success;
/**
* 响应状态码
*/
private Integer code;
/**
* 响应信息
*/
private String message;
/**
* 响应对象
*/
private Object data;
public ResponseData() {
}
public ResponseData(Boolean success, Integer code, String message, Object data) {
this.success = success;
this.code = code;
this.message = message;
this.data = data;
}
public static SuccessResponseData success() {
return new SuccessResponseData();
}
public static SuccessResponseData success(Object object) {
return new SuccessResponseData(object);
}
public static SuccessResponseData success(Integer code, String message, Object object) {
return new SuccessResponseData(code, message, object);
}
public static ErrorResponseData error(String message) {
return new ErrorResponseData(message);
}
public static ErrorResponseData error(Integer code, String message) {
return new ErrorResponseData(code, message);
}
public static ErrorResponseData error(Integer code, String message, Object object) {
return new ErrorResponseData(code, message, object);
}
}

View File

@ -1,16 +0,0 @@
package cd.casic.module.machine.pojo;
public class SuccessResponseData extends ResponseData {
public SuccessResponseData() {
super(true, DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MESSAGE, null);
}
public SuccessResponseData(Object object) {
super(true, DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MESSAGE, object);
}
public SuccessResponseData(Integer code, String message, Object object) {
super(true, code, message, object);
}
}

View File

@ -18,9 +18,8 @@ public interface MachineEnvService extends IService<MachineEnv> {
boolean add(MachineEnvDTO machineEnvDTO);
/**
* 删除机器的环境变量
* @param machineId 机器ID
*/
void deleteByMachineId(Long machineId);
void deleteByMachineId(Long machineEvnId);
/**
* 获取机器的环境变量
@ -34,7 +33,7 @@ public interface MachineEnvService extends IService<MachineEnv> {
*/
PageResult<MachineEnvDTO> listEnv(MachineEnvDTO machineEnvDTO);
void deleteList(List<Long> ids);
void deleteList(String ids);
boolean update(MachineEnvDTO machineEnvDTO);
}

View File

@ -16,11 +16,11 @@ public interface MachineInfoService extends IService<MachineInfo> {
boolean updateMachineInfo(MachineInfoDto machineInfoDto);
boolean updateStatus(Long machineInfoId, String status);
boolean updateStatus(MachineInfoDto machineInfoDto);
boolean bindingSecretKey( Long machineInfoId, Long secretKeyId);
boolean bindingSecretKey(MachineInfoDto machineInfoDto);
void deleteList(List<Long> machineInfoIds);
void deleteList(String machineInfoIds);
void deleteMachineInfo(Long machineInfoId);

View File

@ -33,15 +33,14 @@ public interface MachineProxyService extends IService<MachineProxy> {
/**
* 更新代理配置
*/
void updateConfig(MachineProxyDTO machineProxyDTO);
void update(MachineProxyDTO machineProxyDTO);
/**
* 批量删除代理
* @param proxyIds 代理ID列表
*/
void delete(List<Long> proxyIds);
String delete(String proxyIds);
PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO);
}

View File

@ -13,7 +13,7 @@ import java.util.List;
public interface SecretKeyService extends IService<SecretKey> {
boolean addSecretKey(SecretKeyDto secretKeyDto, MultipartFile file);
void bindingMachine(Long secretKeyId, List<Long> machineInfoIds);
void bindingMachine(SecretKeyDto secretKeyDto);
boolean updateSecretKey(SecretKeyDto secretKeyDto,MultipartFile file);
@ -23,6 +23,6 @@ public interface SecretKeyService extends IService<SecretKey> {
ResponseEntity<InputStreamResource> downloadSecretKeyFile(Long secretKeyId);
boolean deleteList(List<Long> secretKeyIds);
boolean deleteList(String secretKeyIds);
}

View File

@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@ -49,8 +50,8 @@ public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, Machine
}
@Override
public void deleteByMachineId(Long machineId) {
this.removeById(machineId);
public void deleteByMachineId(Long machineEvnId) {
this.removeById(machineEvnId);
}
@ -87,11 +88,6 @@ public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, Machine
queryWrapper.like(MachineEnv::getMachineId, machineEnvDTO.getMachineId());
}
// 是否敏感
if (!StringUtils.isEmpty(machineEnvDTO.getSensitive())) {
queryWrapper.eq(MachineEnv::getSensitive, machineEnvDTO.getSensitive());
}
// 创建时间范围查询
if (!StringUtils.isEmpty(machineEnvDTO.getCreateDate())) {
queryWrapper.ge(MachineEnv::getCreateDate, machineEnvDTO.getCreateDate());
@ -133,8 +129,13 @@ public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, Machine
}
@Override
public void deleteList(List<Long> ids) {
this.machineEnvMapper.deleteBatchIds(ids);
public void deleteList(String ids) {
List<Long> machineEnvIds = Arrays.stream(ids.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(Long::parseLong)
.toList();
this.machineEnvMapper.deleteBatchIds(machineEnvIds);
}
@Override
@ -150,7 +151,6 @@ public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, Machine
dto.setId(machineEnv.getId());
dto.setEnvKey(machineEnv.getEnvKey());
dto.setEnvValue(machineEnv.getEnvValue());
dto.setSensitive(machineEnv.getSensitive());
dto.setDescription(machineEnv.getDescription());
dto.setCreateDate(machineEnv.getCreateDate());
dto.setUpdateDate(machineEnv.getUpdateDate());

View File

@ -80,49 +80,56 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
}
@Override
public void updateConfig(MachineProxyDTO machineProxyDTO) {
public void update(MachineProxyDTO machineProxyDTO) {
// 参数校验
if (machineProxyDTO == null) {
throw new ServiceException(ServiceException.MACHINE_PROXY_DTO_NULL,"MachineProxyDTO对象为空");
}
// 查询代理
MachineProxy proxy = getById(machineProxyDTO.getId());
if (proxy == null) {
throw new ServiceException(ServiceException.MACHINE_PROXY_NULL,"代理不存在");
MachineProxy machineProxy = new MachineProxy();
BeanUtils.copyProperties(machineProxyDTO, machineProxy);
if (machineProxyDTO.getProxyType()!= null && !machineProxyDTO.getProxyType().isEmpty()){
machineProxy.setProxyTypeCode(EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
}
// 更新配置
proxy.setConfig(machineProxyDTO.getConfig());
proxy.setUpdateDate(new Date());
updateById(proxy);
if (machineProxyDTO.getStatus()!= null && !machineProxyDTO.getStatus().isEmpty()){
machineProxy.setStatusCode(EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
}
this.updateById(machineProxy);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(List<Long> ids) {
public String delete(String ids) {
List<Long> machineProxyIds = Arrays.stream(ids.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(Long::parseLong)
.toList();
// 参数校验
if (CollectionUtils.isEmpty(ids)) {
if (CollectionUtils.isEmpty(machineProxyIds)) {
throw new ServiceException(ServiceException.PARAMETER_ERROR,"参数错误");
}
// 查询在线代理
List<MachineProxy> onlineProxies = list(new LambdaQueryWrapper<MachineProxy>()
.in(MachineProxy::getId, ids)
.in(MachineProxy::getId, machineProxyIds)
.eq(MachineProxy::getStatusCode, MachineProxyStatus.ONLINE.getCode()));
if (!CollectionUtils.isEmpty(onlineProxies)) {
List<Long> onlineIds = onlineProxies.stream()
.map(MachineProxy::getId)
.collect(Collectors.toList());
throw new IllegalArgumentException("以下代理处于在线状态,无法删除: " + String.join( ",", (CharSequence) onlineIds));
.map(MachineProxy::getId)
.toList();
// [10, 9] 转换为 "10, 9"
String idStr = onlineIds.toString().replaceAll("[\\[\\]]", "");
return "以下代理处于在线状态,无法删除: " + idStr;
}
// 批量逻辑删除
remove(new LambdaQueryWrapper<MachineProxy>()
.in(MachineProxy::getId, ids));
.in(MachineProxy::getId, machineProxyIds));
return "";
}
@Override
@ -132,7 +139,7 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
List<MachineProxyDTO> machineProxyDtos = page.getRecords().stream().map(machineProxy -> {
MachineProxyDTO dto = new MachineProxyDTO();
BeanUtils.copyProperties(machineProxy, dto);
dto.setProxyType(EnumUtils.getEnumByCode(machineProxy.getStatusCode(), MachineProxyType.class).getMessage());
dto.setProxyType(EnumUtils.getEnumByCode(machineProxy.getProxyTypeCode(), MachineProxyType.class).getMessage());
dto.setStatus(EnumUtils.getEnumByCode(machineProxy.getStatusCode(), MachineProxyStatus.class).getMessage());
return dto;
}).toList();
@ -148,21 +155,21 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
private QueryWrapper<MachineProxy> getMachineProxyQueryWrapper(MachineProxyDTO machineProxyDTO){
QueryWrapper<MachineProxy> queryWrapper = new QueryWrapper<>();
if (machineProxyDTO.getHostIp() != null && !machineProxyDTO.getHostIp().isEmpty()) {
queryWrapper.eq("host_ip", machineProxyDTO.getHostIp());
queryWrapper.like("host_ip", machineProxyDTO.getHostIp());
}
if (machineProxyDTO.getSshPort() != null && !machineProxyDTO.getSshPort().isEmpty()) {
queryWrapper.eq("ssh_port", machineProxyDTO.getSshPort());
queryWrapper.like("ssh_port", machineProxyDTO.getSshPort());
}
if (machineProxyDTO.getUsername() != null && !machineProxyDTO.getUsername().isEmpty()) {
queryWrapper.eq("username", machineProxyDTO.getUsername());
queryWrapper.like("username", machineProxyDTO.getUsername());
}
if (machineProxyDTO.getDescription() != null && !machineProxyDTO.getDescription().isEmpty()) {
queryWrapper.eq("description", machineProxyDTO.getDescription());
queryWrapper.like("description", machineProxyDTO.getDescription());
}
if (machineProxyDTO.getStatus() != null && !machineProxyDTO.getStatus().isEmpty()) {
queryWrapper.eq("status_code", EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(),MachineProxyStatus.class).getCode());
queryWrapper.like("status_code", EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(),MachineProxyStatus.class).getCode());
}
return queryWrapper;
return queryWrapper.orderByDesc("create_date");
}
}

View File

@ -17,16 +17,21 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -121,22 +126,27 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
}
@Override
public boolean updateStatus(Long machineInfoId, String status) {
public boolean updateStatus(MachineInfoDto machineInfoDto) {
UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", machineInfoId).set("status_code", EnumUtils.getEnumByMessage(status, MachineInfoStatus.class).getCode());
updateWrapper.eq("id", machineInfoDto.getId()).set("status_code", EnumUtils.getEnumByMessage(machineInfoDto.getStatus(), MachineInfoStatus.class).getCode());
return this.update(updateWrapper);
}
@Override
public boolean bindingSecretKey(Long machineInfoId, Long secretKeyId) {
public boolean bindingSecretKey(MachineInfoDto machineInfoDto) {
UpdateWrapper<MachineInfo> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", machineInfoId).set("secret_key_id", secretKeyId).set("authentication_type_code",2);
updateWrapper.eq("id", machineInfoDto.getId()).set("secret_key_id", machineInfoDto.getSecretKeyId()).set("authentication_type_code",2);
return this.update(updateWrapper);
}
@Override
public void deleteList(List<Long> machineInfoIds) {
machineInfoMapper.selectBatchIds(machineInfoIds).forEach(machineInfo -> {
public void deleteList(String machineInfoIds) {
List<Long> machineInfoIdList = Arrays.stream(machineInfoIds.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(Long::parseLong)
.collect(Collectors.toList());
machineInfoMapper.selectBatchIds(machineInfoIdList).forEach(machineInfo -> {
if (machineInfo.getStatusCode() == 1){
this.removeById(machineInfo.getId());
}
@ -168,7 +178,7 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
if (machineInfoDto.getDescription() != null && !machineInfoDto.getDescription().isEmpty()) {
queryWrapper.like("description", machineInfoDto.getDescription());
}
return queryWrapper;
return queryWrapper.orderByDesc("create_date");
}

View File

@ -23,6 +23,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -61,9 +62,9 @@ public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, Secre
}
@Override
public void bindingMachine(Long secretKeyId, List<Long> machineInfoIds) {
List<MachineInfo> machineInfos = machineInfoService.listByIds(machineInfoIds);
machineInfos.forEach(machineInfo -> machineInfo.setSecretKeyId(secretKeyId));
public void bindingMachine(SecretKeyDto secretKeyDto) {
List<MachineInfo> machineInfos = machineInfoService.listByIds(secretKeyDto.getMachineInfoIds());
machineInfos.forEach(machineInfo -> machineInfo.setSecretKeyId(secretKeyDto.getId()));
machineInfoService.updateBatchById(machineInfos);
}
@ -97,6 +98,7 @@ public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, Secre
if (secretKeyDto.getDescription() != null && !secretKeyDto.getDescription().isEmpty()){
queryWrapper.like("description", secretKeyDto.getDescription());
}
queryWrapper.orderByDesc("create_date");
Page<SecretKey> page = secretServiceMapper.selectPage(new Page<>(secretKeyDto.getPageIndex(), secretKeyDto.getPageSize()), queryWrapper);
return new PageResult<>(
page.getCurrent(),
@ -114,7 +116,12 @@ public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, Secre
}
@Override
public boolean deleteList(List<Long> secretKeyIds) {
public boolean deleteList(String ids) {
List<Long> secretKeyIds = Arrays.stream(ids.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(Long::parseLong)
.toList();
List<SecretKey> secretKeys = this.listByIds(secretKeyIds);
// 提交异步任务到线程池
FILE_DELETE_EXECUTOR.execute(() -> {