设备组负载

This commit is contained in:
liulu 2024-11-22 14:34:05 +08:00
parent d003b1d971
commit 8716e97f04
4 changed files with 69 additions and 4 deletions

View File

@ -70,6 +70,19 @@ public class DeviceGroupController {
return R.ok();
}
/**
* 设置组内设备负载
*
* @param loadWeight 参数
* @return void
*/
@PostMapping("/weight")
@AuditControllerLog(description = "修改设备负载", operateType = AuditLogConst.UPDATE)
public R<Void> updateLoadWeight(@Valid @RequestBody DeviceGroupDTO.LoadWeight loadWeight) {
deviceGroupService.updateLoadWeight(loadWeight);
return R.ok();
}
/**
* 删除设备组
*

View File

@ -5,7 +5,11 @@ import com.sunyard.chsm.model.entity.Device;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;
@ -67,5 +71,30 @@ public abstract class DeviceGroupDTO {
private String remark;
}
@Data
public static class LoadWeight {
/**
* 设备组id
*/
@NotNull(message = "设备组id不能为空")
private Long id;
@Valid
@NotEmpty(message = "设备负载信息不能为空")
private List<WeightDe> devices;
}
@Data
public static class WeightDe {
/**
* 设备id
*/
@NotNull(message = "设备id不能为空")
private Long id;
@Min(value = 1, message = "设备负载值最低为1")
@NotNull(message = "设备负载值不能为空")
private Integer weight;
}
}

View File

@ -16,4 +16,9 @@ public interface DeviceGroupService {
void update(DeviceGroupDTO.DGSave update);
void delete(Long id);
void updateLoadWeight(DeviceGroupDTO.LoadWeight loadWeight);
}

View File

@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -67,18 +68,19 @@ public class DeviceGroupServiceImpl implements DeviceGroupService {
DeviceGroupDTO.DGView view = new DeviceGroupDTO.DGView();
BeanUtils.copyProperties(it, view);
Map<Long, String> deviceNames = groupMap.getOrDefault(it.getId(), Collections.emptyList())
Map<Long, Device> deviceNames = groupMap.getOrDefault(it.getId(), Collections.emptyList())
.stream()
.collect(Collectors.toMap(Device::getId, Device::getName));
.collect(Collectors.toMap(Device::getId, Function.identity()));
List<Device> deviceList = deviceNames.entrySet()
.stream().map(entry -> {
Device d = new Device();
d.setId(entry.getKey());
d.setName(entry.getValue());
d.setName(entry.getValue().getName());
d.setWeight(entry.getValue().getWeight());
return d;
}).collect(Collectors.toList());
view.setCheckedDevices(deviceList);
view.setDeviceNames(String.join(",", deviceNames.values()));
view.setDeviceNames(deviceList.stream().map(Device::getName).collect(Collectors.joining(",")));
return view;
})
.collect(Collectors.toList());
@ -135,6 +137,7 @@ public class DeviceGroupServiceImpl implements DeviceGroupService {
Device reset = new Device();
reset.setGroupId(0L);
reset.setGroupName("");
reset.setWeight(1);
LambdaQueryWrapper<Device> resetWrapper = new LambdaQueryWrapper<Device>()
.eq(Device::getGroupId, update.getId());
spDeviceMapper.update(reset, resetWrapper);
@ -158,6 +161,21 @@ public class DeviceGroupServiceImpl implements DeviceGroupService {
Assert.isNull(exist, "设备组名称已存在");
}
@Override
public void updateLoadWeight(DeviceGroupDTO.LoadWeight loadWeight) {
DeviceGroup exist = spDeviceGroupMapper.selectById(loadWeight.getId());
Assert.notNull(exist, "id对应的设备组不存在");
for (DeviceGroupDTO.WeightDe device : loadWeight.getDevices()) {
Device up = new Device();
up.setId(device.getId());
up.setWeight(device.getWeight());
spDeviceMapper.updateById(up);
}
}
@Override
public void delete(Long id) {
Assert.notNull(id, "id不能为空");