feat:存储池增删改查修改
parent
d9029ec43b
commit
0f6b7ed0d5
|
|
@ -2,12 +2,9 @@ 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;
|
||||
|
|
@ -30,17 +27,19 @@ public class NetworkManageController {
|
|||
@Resource
|
||||
private NetworkManageService networkManageService;
|
||||
|
||||
@ApiOperation(value = "分页查询镜像")
|
||||
@ApiOperation(value = "分页查询")
|
||||
@PostMapping("/select/page")
|
||||
public Result<PageResult<NetworkManage>> selectPage(@RequestBody NetworkManagePageReq networkManagePageReq) {
|
||||
return Result.successResult(networkManageService.pageNetworkManages(networkManagePageReq));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增")
|
||||
@PostMapping("/add")
|
||||
public Result<?> addNetworkManage(@Valid @RequestBody NetworkManageReq networkManageReq) {
|
||||
networkManageService.addNetworkManage(networkManageReq);
|
||||
return Result.successResult();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改状态")
|
||||
@PostMapping("/update")
|
||||
public Result<?> updateNetworkManage(@RequestBody NetworkManageReq networkManageReq) {
|
||||
|
|
@ -60,7 +59,6 @@ public class NetworkManageController {
|
|||
@ApiOperation(value = "同步状态")
|
||||
@GetMapping("/synchStatus")
|
||||
public Result<?> synchStatus() {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,19 @@
|
|||
package com.unisinsight.project.controller;
|
||||
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.unisinsight.project.entity.req.DeleteIdReq;
|
||||
import com.unisinsight.project.entity.req.ImageVirtualMachinesReq;
|
||||
import com.unisinsight.project.entity.dao.StoragePool;
|
||||
import com.unisinsight.project.entity.req.StoragePoolReq;
|
||||
import com.unisinsight.project.entity.res.ImageVirtualMachinesRes;
|
||||
import com.unisinsight.project.entity.res.PageResult;
|
||||
import com.unisinsight.project.entity.res.StoragePoolRes;
|
||||
import com.unisinsight.project.exception.BaseErrorCode;
|
||||
import com.unisinsight.project.exception.Result;
|
||||
import com.unisinsight.project.service.ImageVirtualMachinesService;
|
||||
import com.unisinsight.project.service.StoragePoolService;
|
||||
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 java.util.Objects;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 存储池管理
|
||||
|
|
@ -28,28 +24,42 @@ import java.util.Objects;
|
|||
@Api(tags = "存储池类")
|
||||
public class StoragePoolController {
|
||||
|
||||
@ApiOperation(value = "分页查询镜像")
|
||||
@Resource
|
||||
private StoragePoolService storagePoolService;
|
||||
|
||||
@ApiOperation(value = "分页查询")
|
||||
@PostMapping("/select/page")
|
||||
public Result<PageResult<StoragePoolRes>> selectPage(@RequestBody StoragePoolReq storagePoolReq) {
|
||||
return null;
|
||||
public Result<PageResult<StoragePool>> selectPage(@RequestBody StoragePoolReq storagePoolReq) {
|
||||
return Result.successResult(storagePoolService.pageStoragePools(storagePoolReq));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增")
|
||||
@PostMapping("/add")
|
||||
public Result<?> insertImageVirtualMachines(@RequestBody StoragePoolReq storagePoolReq) {
|
||||
return null;
|
||||
public Result<?> insertStoragePool(@Valid @RequestBody StoragePoolReq storagePoolReq) {
|
||||
storagePoolService.addStoragePool(storagePoolReq);
|
||||
return Result.successResult();
|
||||
}
|
||||
@ApiOperation(value = "修改状态")
|
||||
|
||||
@ApiOperation(value = "修改")
|
||||
@PostMapping("/update")
|
||||
public Result<?> updateUser(@RequestBody StoragePoolReq storagePoolReq) {
|
||||
return null;
|
||||
public Result<?> updateStoragePool(@RequestBody StoragePoolReq storagePoolReq) {
|
||||
if (storagePoolService.updateStoragePool(storagePoolReq)) {
|
||||
return Result.successResult();
|
||||
} else {
|
||||
return Result.errorResult(BaseErrorCode.DATABASE_OPERATION_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "删除")
|
||||
@PostMapping("/delete")
|
||||
public Result<?> delete(@RequestBody DeleteIdReq deleteIdReq) {
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<?> delete(@PathVariable Long id) {
|
||||
if (storagePoolService.deleteStoragePool(id)) {
|
||||
return Result.successResult();
|
||||
} else {
|
||||
return Result.errorResult(BaseErrorCode.DATABASE_OPERATION_FAILED);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "同步状态")
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class StoragePool {
|
|||
*/
|
||||
@TableField("status")
|
||||
@ApiModelProperty(value = "状态")
|
||||
private Short status;
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 描述信息
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
|
||||
package com.unisinsight.project.entity.req;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.unisinsight.project.entity.dao.StoragePool;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* 存储池
|
||||
* 存储池请求参数
|
||||
*
|
||||
* @author ch
|
||||
* @since 2025-08-25 11:42:52
|
||||
|
|
@ -17,34 +17,42 @@ import lombok.Data;
|
|||
@ApiModel("存储池")
|
||||
public class StoragePoolReq {
|
||||
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("名称")
|
||||
@NotBlank(message = "名称不能为空")
|
||||
@Size(max = 64, message = "名称长度不能超过64个字符")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("类型")
|
||||
@Size(max = 16, message = "类型长度不能超过16个字符")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty("路劲")
|
||||
@ApiModelProperty("路径")
|
||||
@Size(max = 128, message = "路径长度不能超过128个字符")
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 状态: 1-活跃,2-关闭
|
||||
**/
|
||||
@ApiModelProperty("状态")
|
||||
private String status;
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 查询页
|
||||
*/
|
||||
@ApiModelProperty(value = "查询页", notes = "分页查询时再传")
|
||||
@JsonProperty("page_num")
|
||||
private Integer pageNum;
|
||||
@Min(value = 1, message = "页码必须大于0")
|
||||
private Integer pageNum = 1;
|
||||
|
||||
/**
|
||||
* 每页数量
|
||||
*/
|
||||
@ApiModelProperty(value = "每页数量", notes = "分页查询时再传")
|
||||
@JsonProperty("page_size")
|
||||
private Integer pageSize;
|
||||
}
|
||||
|
||||
@Min(value = 1, message = "每页数量必须大于0")
|
||||
@Max(value = 100, message = "每页数量不能超过100")
|
||||
private Integer pageSize = 10;
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@ package com.unisinsight.project.service;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.unisinsight.project.entity.dao.StoragePool;
|
||||
import com.unisinsight.project.entity.req.StoragePoolReq;
|
||||
import com.unisinsight.project.entity.res.PageResult;
|
||||
import com.unisinsight.project.entity.res.StoragePoolRes;
|
||||
|
||||
/**
|
||||
* 存储池服务接口
|
||||
|
|
@ -15,7 +17,7 @@ public interface StoragePoolService {
|
|||
* @param storagePool 存储池对象
|
||||
* @return StoragePool 返回新增的存储池对象
|
||||
*/
|
||||
StoragePool addStoragePool(StoragePool storagePool);
|
||||
StoragePool addStoragePool(StoragePoolReq storagePoolReq);
|
||||
|
||||
/**
|
||||
* 根据ID更新存储池信息
|
||||
|
|
@ -23,7 +25,7 @@ public interface StoragePoolService {
|
|||
* @param storagePool 存储池对象
|
||||
* @return boolean 是否更新成功
|
||||
*/
|
||||
boolean updateStoragePool(StoragePool storagePool);
|
||||
boolean updateStoragePool(StoragePoolReq storagePoolReq);
|
||||
|
||||
/**
|
||||
* 根据ID删除存储池
|
||||
|
|
@ -51,5 +53,5 @@ public interface StoragePoolService {
|
|||
* @param status 存储池状态(可选查询条件)
|
||||
* @return Page<StoragePool> 分页结果
|
||||
*/
|
||||
Page<StoragePool> pageStoragePools(StoragePoolReq storagePoolReq);
|
||||
PageResult<StoragePool> pageStoragePools(StoragePoolReq storagePoolReq);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,14 @@ package com.unisinsight.project.service.impl;
|
|||
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.dao.StoragePool;
|
||||
import com.unisinsight.project.entity.req.StoragePoolReq;
|
||||
import com.unisinsight.project.entity.res.PageResult;
|
||||
import com.unisinsight.project.exception.BusinessException;
|
||||
import com.unisinsight.project.mapper.StoragePoolMapper;
|
||||
import com.unisinsight.project.service.StoragePoolService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -21,14 +25,23 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
/**
|
||||
* 新增存储池
|
||||
*
|
||||
* @param storagePool 存储池对象
|
||||
* @param storagePoolReq
|
||||
* @return StoragePool 返回新增的存储池对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public StoragePool addStoragePool(StoragePool storagePool) {
|
||||
public StoragePool addStoragePool(StoragePoolReq storagePoolReq) {
|
||||
// 检查名称是否重复
|
||||
QueryWrapper<StoragePool> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", storagePoolReq.getName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
throw new BusinessException("存储池名称'" + storagePoolReq.getName() + "'已存在,请使用其他名称");
|
||||
}
|
||||
|
||||
StoragePool storagePool = new StoragePool();
|
||||
BeanUtils.copyProperties(storagePoolReq, storagePool);
|
||||
storagePool.setCreateTime(new Date());
|
||||
storagePool.setUpdateTime(new Date());
|
||||
storagePool.setStatus(1);
|
||||
this.save(storagePool);
|
||||
return storagePool;
|
||||
}
|
||||
|
|
@ -36,18 +49,36 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
/**
|
||||
* 根据ID更新存储池信息
|
||||
*
|
||||
* @param storagePool 存储池对象
|
||||
* @param storagePoolReq
|
||||
* @return boolean 是否更新成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateStoragePool(StoragePool storagePool) {
|
||||
StoragePool existing = this.getById(storagePool.getId());
|
||||
public boolean updateStoragePool(StoragePoolReq storagePoolReq) {
|
||||
StoragePool existing = this.getById(storagePoolReq.getId());
|
||||
if (existing == null) {
|
||||
return false;
|
||||
}
|
||||
storagePool.setUpdateTime(new Date());
|
||||
return this.updateById(storagePool);
|
||||
|
||||
// 如果名称不为空且与原名称不同,则进行重名校验
|
||||
if (storagePoolReq.getName() != null && !storagePoolReq.getName().isEmpty()
|
||||
&& !storagePoolReq.getName().equals(existing.getName())) {
|
||||
// 检查新名称是否重复
|
||||
QueryWrapper<StoragePool> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", storagePoolReq.getName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
throw new BusinessException("存储池名称'" + storagePoolReq.getName() + "'已存在,请使用其他名称");
|
||||
}
|
||||
existing.setName(storagePoolReq.getName());
|
||||
}
|
||||
|
||||
// 修改状态
|
||||
if (storagePoolReq.getStatus() != null
|
||||
&& !storagePoolReq.getStatus().equals(existing.getStatus())) {
|
||||
existing.setStatus(storagePoolReq.getStatus());
|
||||
}
|
||||
|
||||
existing.setUpdateTime(new Date());
|
||||
return this.updateById(existing);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -76,15 +107,11 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
/**
|
||||
* 分页查询存储池列表
|
||||
*
|
||||
* @param currentPage 当前页码
|
||||
* @param pageSize 每页大小
|
||||
* @param name 存储池名称(可选查询条件)
|
||||
* @param type 存储池类型(可选查询条件)
|
||||
* @param status 存储池状态(可选查询条件)
|
||||
* @param storagePoolReq
|
||||
* @return Page<StoragePool> 分页结果
|
||||
*/
|
||||
@Override
|
||||
public Page<StoragePool> pageStoragePools(StoragePoolReq storagePoolReq) {
|
||||
public PageResult<StoragePool> pageStoragePools(StoragePoolReq storagePoolReq) {
|
||||
Page<StoragePool> page = new Page<>(storagePoolReq.getPageNum(), storagePoolReq.getPageSize());
|
||||
QueryWrapper<StoragePool> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
|
|
@ -100,6 +127,8 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
}
|
||||
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
return this.page(page, queryWrapper);
|
||||
|
||||
Page<StoragePool> resultPage = this.page(page, queryWrapper);
|
||||
return PageResult.convertPage(resultPage, StoragePool.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue