feat:bug修改
parent
70f6ade5db
commit
b69a3ae3d4
|
|
@ -59,8 +59,7 @@ public class NetworkManageController {
|
|||
@ApiOperation(value = "同步数据和状态")
|
||||
@GetMapping("/synchData")
|
||||
public Result<?> synchData() {
|
||||
networkManageService.synchData();
|
||||
return Result.successResult();
|
||||
return Result.successResult(networkManageService.synchData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,8 +65,7 @@ public class StoragePoolController {
|
|||
@ApiOperation(value = "同步数据")
|
||||
@GetMapping("/synchData")
|
||||
public Result<?> synchData() {
|
||||
storagePoolService.synchData();
|
||||
return Result.successResult();
|
||||
return Result.successResult(storagePoolService.synchData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,4 +76,25 @@ public class StoragePool {
|
|||
@TableField("create_user")
|
||||
@ApiModelProperty(value = "创建用户")
|
||||
private String createUser;
|
||||
|
||||
/**
|
||||
* 总容量
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "总容量")
|
||||
private Long capacity;
|
||||
|
||||
/**
|
||||
* 已分配容量
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "已分配容量")
|
||||
private Long allocation;
|
||||
|
||||
/**
|
||||
* 可用容量
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "可用容量")
|
||||
private Long available;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
package com.unisinsight.project.entity.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
|
@ -51,4 +52,21 @@ public class Network {
|
|||
|
||||
@JsonProperty("vlan_id")
|
||||
private Integer vlanId;
|
||||
|
||||
// 自定义 setter,在设置 name 时同步到 networkName
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
if (name != null) {
|
||||
this.networkName = name;
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义 setter,在设置 poolName 时同步到 name
|
||||
@JsonSetter("network_name")
|
||||
public void setPoolName(String poolName) {
|
||||
this.networkName = poolName;
|
||||
if (poolName != null) {
|
||||
this.name = poolName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,15 @@
|
|||
// StoragePool.java - 存储池信息对象
|
||||
package com.unisinsight.project.entity.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class VmStoragePool {
|
||||
private String name;
|
||||
@JsonProperty("pool_name")
|
||||
private String poolName;
|
||||
private String uuid;
|
||||
private String state;
|
||||
private Long capacity;
|
||||
|
|
@ -10,96 +17,25 @@ public class VmStoragePool {
|
|||
private Long available;
|
||||
private Integer autostart;
|
||||
private Integer persistent;
|
||||
@JsonProperty("volume_count")
|
||||
private Integer volumeCount;
|
||||
private String type;
|
||||
private String path;
|
||||
|
||||
// Getters and Setters
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
// 自定义 setter,在设置 name 时同步到 poolName
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
if (name != null) {
|
||||
this.poolName = name;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Long getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public void setCapacity(Long capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public Long getAllocation() {
|
||||
return allocation;
|
||||
}
|
||||
|
||||
public void setAllocation(Long allocation) {
|
||||
this.allocation = allocation;
|
||||
}
|
||||
|
||||
public Long getAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void setAvailable(Long available) {
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public Integer getAutostart() {
|
||||
return autostart;
|
||||
}
|
||||
|
||||
public void setAutostart(Integer autostart) {
|
||||
this.autostart = autostart;
|
||||
}
|
||||
|
||||
public Integer getPersistent() {
|
||||
return persistent;
|
||||
}
|
||||
|
||||
public void setPersistent(Integer persistent) {
|
||||
this.persistent = persistent;
|
||||
}
|
||||
|
||||
public Integer getVolumeCount() {
|
||||
return volumeCount;
|
||||
}
|
||||
|
||||
public void setVolumeCount(Integer volumeCount) {
|
||||
this.volumeCount = volumeCount;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
// 自定义 setter,在设置 poolName 时同步到 name
|
||||
@JsonSetter("pool_name")
|
||||
public void setPoolName(String poolName) {
|
||||
this.poolName = poolName;
|
||||
if (poolName != null) {
|
||||
this.name = poolName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,5 +62,5 @@ public interface NetworkManageService {
|
|||
*/
|
||||
PageResult<NetworkManage> pageNetworkManages(NetworkManagePageReq networkManagePageReq);
|
||||
|
||||
void synchData();
|
||||
String synchData();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,5 +51,5 @@ public interface StoragePoolService {
|
|||
*/
|
||||
PageResult<StoragePool> pageStoragePools(StoragePoolReq storagePoolReq);
|
||||
|
||||
void synchData();
|
||||
String synchData();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,7 +242,8 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
*/
|
||||
@Override
|
||||
// @Transactional
|
||||
public void synchData() {
|
||||
public String synchData() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
ApiResponse<NetworkData> response;
|
||||
try {
|
||||
response = client.list(1, 100);
|
||||
|
|
@ -255,7 +256,7 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
|
||||
List<Network> networkList = response.getData().getNetworks();
|
||||
if (CollectionUtils.isEmpty(networkList)) {
|
||||
return;
|
||||
return "同步成功,无数据更新";
|
||||
}
|
||||
|
||||
log.info("开始同步网络数据,共{}条记录", networkList.size());
|
||||
|
|
@ -294,10 +295,12 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
// 执行批量操作,分批处理避免大数据量问题
|
||||
if (!toUpdate.isEmpty()) {
|
||||
updateBatch(toUpdate);
|
||||
sb.append("更新 ").append(toUpdate.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
|
||||
if (!toInsert.isEmpty()) {
|
||||
insertBatch(toInsert);
|
||||
sb.append("插入 ").append(toInsert.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
|
||||
// 删除不存在的记录
|
||||
|
|
@ -313,7 +316,9 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
if (!idsToDelete.isEmpty()) {
|
||||
log.info("需要删除{}条记录", idsToDelete.size());
|
||||
this.removeByIds(idsToDelete);
|
||||
sb.append("删除 ").append(idsToDelete.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void updateBatch(List<NetworkManage> list) {
|
||||
|
|
|
|||
|
|
@ -187,7 +187,8 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void synchData() {
|
||||
public String synchData() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
ApiResponse<StoragePoolData> response;
|
||||
try {
|
||||
response = client.listStorage(1, 100);
|
||||
|
|
@ -220,7 +221,7 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
StoragePool storagePool = new StoragePool();
|
||||
BeanUtils.copyProperties(remotePool, storagePool);
|
||||
storagePool.setPoolName(remotePool.getName());
|
||||
storagePool.setStatus("active".equals(remotePool.getState()) ? 1 : 2);
|
||||
storagePool.setStatus("active".equals(remotePool.getState()) ? 1 : 0);
|
||||
|
||||
if (localPool == null) {
|
||||
// 新增项
|
||||
|
|
@ -248,11 +249,13 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
if (!toAdd.isEmpty()) {
|
||||
this.saveBatch(toAdd);
|
||||
log.info("新增 {} 条存储池数据", toAdd.size());
|
||||
sb.append("新增 ").append(toAdd.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
|
||||
if (!toUpdate.isEmpty()) {
|
||||
this.updateBatchById(toUpdate);
|
||||
log.info("更新 {} 条存储池数据", toUpdate.size());
|
||||
sb.append("更新 ").append(toUpdate.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
|
||||
if (!toRemoveNames.isEmpty()) {
|
||||
|
|
@ -260,7 +263,9 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
deleteWrapper.in("pool_name", toRemoveNames);
|
||||
this.remove(deleteWrapper);
|
||||
log.info("删除 {} 条存储池数据", toRemoveNames.size());
|
||||
sb.append("删除 ").append(toRemoveNames.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
return sb.toString() ;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue