feat:网络增删改查修改
parent
d2e92ff64e
commit
d9029ec43b
|
|
@ -1,16 +1,23 @@
|
|||
package com.unisinsight.project.controller;
|
||||
|
||||
|
||||
import com.unisinsight.project.entity.dao.NetworkManage;
|
||||
import com.unisinsight.project.entity.req.DeleteIdReq;
|
||||
import com.unisinsight.project.entity.req.NetworkManagePageReq;
|
||||
import com.unisinsight.project.entity.req.NetworkManageReq;
|
||||
import com.unisinsight.project.entity.req.StoragePoolReq;
|
||||
import com.unisinsight.project.entity.res.PageResult;
|
||||
import com.unisinsight.project.entity.res.StoragePoolRes;
|
||||
import com.unisinsight.project.exception.Result;
|
||||
import com.unisinsight.project.service.NetworkManageService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 存储池管理
|
||||
*/
|
||||
|
|
@ -20,28 +27,34 @@ import org.springframework.web.bind.annotation.*;
|
|||
@Api(tags = "网络管理类")
|
||||
public class NetworkManageController {
|
||||
|
||||
@Resource
|
||||
private NetworkManageService networkManageService;
|
||||
|
||||
@ApiOperation(value = "分页查询镜像")
|
||||
@PostMapping("/select/page")
|
||||
public Result<PageResult<StoragePoolRes>> selectPage(@RequestBody StoragePoolReq storagePoolReq) {
|
||||
return null;
|
||||
public Result<PageResult<NetworkManage>> selectPage(@RequestBody NetworkManagePageReq networkManagePageReq) {
|
||||
return Result.successResult(networkManageService.pageNetworkManages(networkManagePageReq));
|
||||
}
|
||||
@ApiOperation(value = "新增")
|
||||
@PostMapping("/add")
|
||||
public Result<?> insertImageVirtualMachines(@RequestBody StoragePoolReq storagePoolReq) {
|
||||
return null;
|
||||
public Result<?> addNetworkManage(@Valid @RequestBody NetworkManageReq networkManageReq) {
|
||||
networkManageService.addNetworkManage(networkManageReq);
|
||||
return Result.successResult();
|
||||
}
|
||||
@ApiOperation(value = "修改状态")
|
||||
@PostMapping("/update")
|
||||
public Result<?> updateUser(@RequestBody StoragePoolReq storagePoolReq) {
|
||||
return null;
|
||||
public Result<?> updateNetworkManage(@RequestBody NetworkManageReq networkManageReq) {
|
||||
|
||||
networkManageService.updateNetworkManage(networkManageReq);
|
||||
return Result.successResult();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "删除")
|
||||
@PostMapping("/delete")
|
||||
public Result<?> delete(@RequestBody DeleteIdReq deleteIdReq) {
|
||||
|
||||
return null;
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<?> delete(@PathVariable Integer id) {
|
||||
networkManageService.deleteNetworkManage(id);
|
||||
return Result.successResult();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "同步状态")
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ public class NetworkManage {
|
|||
* 状态
|
||||
*/
|
||||
@TableField("status")
|
||||
private Short status;
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
package com.unisinsight.project.entity.req;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Data
|
||||
@ApiModel(description = "网络管理分页请求对象")
|
||||
public class NetworkManagePageReq {
|
||||
|
||||
/**
|
||||
* 网络名称
|
||||
*/
|
||||
@Size(max = 64, message = "网络名称长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "网络名称", required = true)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 网络类型
|
||||
*/
|
||||
@Size(max = 16, message = "网络类型长度不能超过16个字符")
|
||||
@ApiModelProperty(value = "网络类型")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 桥接名称
|
||||
*/
|
||||
@Size(max = 64, message = "桥接名称长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "桥接名称")
|
||||
private String bridgeName;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@ApiModelProperty(value = "状态", required = true)
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 查询页
|
||||
*/
|
||||
@ApiModelProperty(value = "查询页", notes = "分页查询时再传", dataType = "Integer")
|
||||
@JsonProperty("page_num")
|
||||
private Integer pageNum = 1;
|
||||
|
||||
/**
|
||||
* 每页数量
|
||||
*/
|
||||
@ApiModelProperty(value = "每页数量", notes = "分页查询时再传", dataType = "Integer")
|
||||
@JsonProperty("page_size")
|
||||
private Integer pageSize = 10;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
package com.unisinsight.project.entity.req;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Data
|
||||
@ApiModel(description = "网络管理新增请求对象")
|
||||
public class NetworkManageReq {
|
||||
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 网络名称
|
||||
*/
|
||||
@NotBlank(message = "网络名称不能为空")
|
||||
@Size(max = 64, message = "网络名称长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "网络名称", required = true)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 网络类型
|
||||
*/
|
||||
@Size(max = 16, message = "网络类型长度不能超过16个字符")
|
||||
@ApiModelProperty(value = "网络类型")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 桥接名称
|
||||
*/
|
||||
@Size(max = 64, message = "桥接名称长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "桥接名称")
|
||||
private String bridgeName;
|
||||
|
||||
/**
|
||||
* IP范围
|
||||
*/
|
||||
@Size(max = 64, message = "IP范围长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "IP范围")
|
||||
private String ipRange;
|
||||
|
||||
/**
|
||||
* 网关
|
||||
*/
|
||||
@Size(max = 64, message = "网关长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "网关")
|
||||
private String gateway;
|
||||
|
||||
/**
|
||||
* 子网掩码
|
||||
*/
|
||||
@Size(max = 64, message = "子网掩码长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "子网掩码")
|
||||
private String netmask;
|
||||
|
||||
/**
|
||||
* DHCP启用状态
|
||||
*/
|
||||
@ApiModelProperty(value = "DHCP启用状态")
|
||||
private Short dhcpEnabled;
|
||||
|
||||
/**
|
||||
* DHCP起始地址
|
||||
*/
|
||||
@Size(max = 64, message = "DHCP起始地址长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "DHCP起始地址")
|
||||
private String dhcpStart;
|
||||
|
||||
/**
|
||||
* DHCP结束地址
|
||||
*/
|
||||
@Size(max = 64, message = "DHCP结束地址长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "DHCP结束地址")
|
||||
private String dhcpEnd;
|
||||
|
||||
/**
|
||||
* VLAN ID
|
||||
*/
|
||||
@Size(max = 64, message = "VLAN ID长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "VLAN ID")
|
||||
private String vlanId;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@ApiModelProperty(value = "状态", required = true)
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
*/
|
||||
@Size(max = 64, message = "创建用户长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "创建用户")
|
||||
private String createUser;
|
||||
|
||||
/**
|
||||
* 描述信息
|
||||
*/
|
||||
@Size(max = 128, message = "描述信息长度不能超过128个字符")
|
||||
@ApiModelProperty(value = "描述信息")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 查询页
|
||||
*/
|
||||
@ApiModelProperty(value = "查询页", notes = "分页查询时再传", dataType = "Integer")
|
||||
@JsonProperty("page_num")
|
||||
private Integer pageNum;
|
||||
|
||||
/**
|
||||
* 每页数量
|
||||
*/
|
||||
@ApiModelProperty(value = "每页数量", notes = "分页查询时再传", dataType = "Integer")
|
||||
@JsonProperty("page_size")
|
||||
private Integer pageSize;
|
||||
|
||||
}
|
||||
|
|
@ -58,4 +58,14 @@ public class PageResult<T1> {
|
|||
result.setData(copyToList);
|
||||
return result;
|
||||
}
|
||||
|
||||
public PageResult() {}
|
||||
|
||||
// public PageResult(com.baomidou.mybatisplus.extension.plugins.pagination.Page<T> page) {
|
||||
// this.pageNum = (int) page.getCurrent();
|
||||
// this.pageSize = (int) page.getSize();
|
||||
// this.total = page.getTotal();
|
||||
// this.pages = (int) page.getPages();
|
||||
// this.list = page.getRecords();
|
||||
// }
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.unisinsight.project.exception;
|
||||
|
||||
public class BusinessException extends RuntimeException {
|
||||
private String code = "500";
|
||||
private String message;
|
||||
|
||||
public BusinessException(String message) {
|
||||
super(message);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public BusinessException(String code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.unisinsight.project.exception;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
/**
|
||||
* 处理业务异常
|
||||
*/
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public Result<?> handleBusinessException(BusinessException e) {
|
||||
log.error("业务异常:", e);
|
||||
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理参数校验异常
|
||||
*/
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
public Result<?> handleIllegalArgumentException(IllegalArgumentException e) {
|
||||
log.error("参数校验异常:", e);
|
||||
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_400, e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理其他异常
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
public Result<?> handleException(Exception e) {
|
||||
log.error("系统异常:", e);
|
||||
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,10 @@ package com.unisinsight.project.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.unisinsight.project.entity.dao.NetworkManage;
|
||||
import com.unisinsight.project.entity.req.NetworkManagePageReq;
|
||||
import com.unisinsight.project.entity.req.NetworkManageReq;
|
||||
import com.unisinsight.project.entity.res.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -12,18 +16,18 @@ public interface NetworkManageService {
|
|||
/**
|
||||
* 新增网络管理信息
|
||||
*
|
||||
* @param networkManage 网络管理对象
|
||||
* @param networkManageReq
|
||||
* @return NetworkManage 返回新增的网络管理对象
|
||||
*/
|
||||
NetworkManage addNetworkManage(NetworkManage networkManage);
|
||||
NetworkManage addNetworkManage(NetworkManageReq networkManageReq);
|
||||
|
||||
/**
|
||||
* 根据ID更新网络管理信息
|
||||
*
|
||||
* @param networkManage 网络管理对象
|
||||
* @param networkManageReq
|
||||
* @return boolean 是否更新成功
|
||||
*/
|
||||
boolean updateNetworkManage(NetworkManage networkManage);
|
||||
boolean updateNetworkManage(NetworkManageReq networkManageReq);
|
||||
|
||||
/**
|
||||
* 根据ID删除网络管理信息
|
||||
|
|
@ -54,12 +58,7 @@ public interface NetworkManageService {
|
|||
/**
|
||||
* 分页查询网络管理列表
|
||||
*
|
||||
* @param currentPage 当前页码
|
||||
* @param pageSize 每页大小
|
||||
* @param name 网络名称(可选查询条件)
|
||||
* @param type 网络类型(可选查询条件)
|
||||
* @param status 状态(可选查询条件)
|
||||
* @return Page<NetworkManage> 分页结果
|
||||
*/
|
||||
Page<NetworkManage> pageNetworkManages(Integer currentPage, Integer pageSize, String name, String type, Short status);
|
||||
PageResult<NetworkManage> pageNetworkManages(NetworkManagePageReq networkManagePageReq);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
package com.unisinsight.project.service.impl;
|
||||
|
||||
import cn.hutool.core.exceptions.CheckedUtil;
|
||||
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 com.unisinsight.project.entity.dao.NetworkManage;
|
||||
import com.unisinsight.project.entity.req.NetworkManagePageReq;
|
||||
import com.unisinsight.project.entity.req.NetworkManageReq;
|
||||
import com.unisinsight.project.entity.res.PageResult;
|
||||
import com.unisinsight.project.exception.BusinessException;
|
||||
import com.unisinsight.project.mapper.NetworkManageMapper;
|
||||
import com.unisinsight.project.service.NetworkManageService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -21,14 +27,25 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
/**
|
||||
* 新增网络管理信息
|
||||
*
|
||||
* @param networkManage 网络管理对象
|
||||
* @param networkManageReq
|
||||
* @return NetworkManage 返回新增的网络管理对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public NetworkManage addNetworkManage(NetworkManage networkManage) {
|
||||
public NetworkManage addNetworkManage(NetworkManageReq networkManageReq) {
|
||||
// 检查名称是否重复
|
||||
QueryWrapper<NetworkManage> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", networkManageReq.getName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
throw new BusinessException("网络名称'" + networkManageReq.getName() + "'已存在,请使用其他名称");
|
||||
}
|
||||
// 设置创建时间和更新时间
|
||||
NetworkManage networkManage = new NetworkManage();
|
||||
BeanUtils.copyProperties(networkManageReq, networkManage);
|
||||
networkManage.setCreateTime(new Date());
|
||||
networkManage.setUpdateTime(new Date());
|
||||
// 设置状态
|
||||
networkManage.setStatus(1);
|
||||
// 保存本地库
|
||||
this.save(networkManage);
|
||||
return networkManage;
|
||||
}
|
||||
|
|
@ -36,18 +53,34 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
/**
|
||||
* 根据ID更新网络管理信息
|
||||
*
|
||||
* @param networkManage 网络管理对象
|
||||
* @param networkManageReq
|
||||
* @return boolean 是否更新成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateNetworkManage(NetworkManage networkManage) {
|
||||
NetworkManage existing = this.getById(networkManage.getId());
|
||||
public boolean updateNetworkManage(NetworkManageReq networkManageReq) {
|
||||
|
||||
NetworkManage existing = this.getById(networkManageReq.getId());
|
||||
if (existing == null) {
|
||||
return false;
|
||||
throw new BusinessException("网络管理信息不存在");
|
||||
}
|
||||
networkManage.setUpdateTime(new Date());
|
||||
return this.updateById(networkManage);
|
||||
// 修改名称
|
||||
existing.setUpdateTime(new Date());
|
||||
// 如果名称不为空且与原名称不同,则进行重名校验
|
||||
if (networkManageReq.getName() != null && !networkManageReq.getName().isEmpty()
|
||||
&& !networkManageReq.getName().equals(existing.getName())) {
|
||||
// 检查新名称是否重复
|
||||
QueryWrapper<NetworkManage> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", networkManageReq.getName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
throw new BusinessException("网络名称'" + networkManageReq.getName() + "'已存在,请使用其他名称");
|
||||
}
|
||||
existing.setName(networkManageReq.getName());
|
||||
}
|
||||
// 修改状态
|
||||
if(networkManageReq.getStatus() != null ){
|
||||
existing.setStatus(networkManageReq.getStatus());
|
||||
}
|
||||
return this.updateById(existing);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -103,30 +136,29 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
/**
|
||||
* 分页查询网络管理列表
|
||||
*
|
||||
* @param currentPage 当前页码
|
||||
* @param pageSize 每页大小
|
||||
* @param name 网络名称(可选查询条件)
|
||||
* @param type 网络类型(可选查询条件)
|
||||
* @param status 状态(可选查询条件)
|
||||
* @param pageReq
|
||||
* @return Page<NetworkManage> 分页结果
|
||||
*/
|
||||
@Override
|
||||
public Page<NetworkManage> pageNetworkManages(Integer currentPage, Integer pageSize, String name, String type, Short status) {
|
||||
Page<NetworkManage> page = new Page<>(currentPage, pageSize);
|
||||
public PageResult<NetworkManage> pageNetworkManages(NetworkManagePageReq pageReq) {
|
||||
Page<NetworkManage> page = new Page<>(pageReq.getPageNum(), pageReq.getPageSize());
|
||||
QueryWrapper<NetworkManage> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
// 添加查询条件
|
||||
if (name != null && !name.isEmpty()) {
|
||||
queryWrapper.like("name", name);
|
||||
if (pageReq.getName() != null && !pageReq.getName().isEmpty()) {
|
||||
queryWrapper.like("name", pageReq.getName());
|
||||
}
|
||||
if (type != null && !type.isEmpty()) {
|
||||
queryWrapper.eq("type", type);
|
||||
if (pageReq.getType() != null && !pageReq.getType().isEmpty()) {
|
||||
queryWrapper.eq("type", pageReq.getType());
|
||||
}
|
||||
if (status != null) {
|
||||
queryWrapper.eq("status", status);
|
||||
if (pageReq.getStatus() != null) {
|
||||
queryWrapper.eq("status", pageReq.getStatus());
|
||||
}
|
||||
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
return this.page(page, queryWrapper);
|
||||
Page<NetworkManage> resultPage = this.page(page, queryWrapper);
|
||||
|
||||
// 转换为 PageResult
|
||||
return PageResult.convertPage(resultPage, NetworkManage.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue