@Override
public Boolean addOrUpdateDeviceGroup(DeviceGroupDto deviceGroupDto) {
String tenantId = RequestContext.getCurrentSession().getTenantId();
Long campusId = RequestContext.getCurrentSession().getCampusId();
DeviceGroupDO groupDO = BeanUtil.map(deviceGroupDto, DeviceGroupDO.class);
if (ObjectUtil.isNotNull(deviceGroupDto.getId()) && deviceGroupDto.getId() > 0) {
DeviceGroupDO exist = deviceGroupManager.getByIdAndTenantId(deviceGroupDto.getId(), tenantId,campusId);
if (ObjectUtil.isNull(exist)) {
throw new BizException(ErrorCodeEnum.DEVICE_GROUP_NOT_EXIST);
}
groupDO.setGmtModified(LocalDateTime.now());
groupDO.setModifiedUser(RequestContext.getCurrentSession().getNickName());
return deviceGroupManager.updateById(groupDO);
} else {
DeviceGroupDO deviceGroupDO = deviceGroupManager.selectDeviceGroup(deviceGroupDto.getGroupName(), deviceGroupDto.getRemark(), tenantId,campusId);
if (ObjectUtil.isNotNull(deviceGroupDO)) {
throw new BizException(ErrorCodeEnum.DEVICE_GROUP_REPETITION);
}
groupDO.setGmtCreate(LocalDateTime.now());
groupDO.setGmtModified(LocalDateTime.now());
groupDO.setCreateUser(RequestContext.getCurrentSession().getNickName());
groupDO.setModifiedUser(RequestContext.getCurrentSession().getNickName());
groupDO.setIsDelete(Boolean.FALSE);
groupDO.setTenantId(RequestContext.getCurrentSession().getTenantId());
groupDO.setCampusId(String.valueOf(RequestContext.getCurrentSession().getCampusId()));
return deviceGroupManager.save(groupDO);
}
}
@Data
@ApiModel("设备分组相关参数")
public class DeviceGroupDto {
@ApiModelProperty(name = "id", value = "设备分组的id")
private Long id;
@ApiModelProperty(name = "groupName", value = "分组名称", required = true)
@NotBlank(message = "分组名称不能为空")
private String groupName;
@ApiModelProperty(name = "remark", value = "备注描述", required = true)
@NotBlank(message = "备注描述不能为空")
private String remark;
@ApiModelProperty(name = "deviceNum", value = "设备数量")
private Integer deviceNum;
}