|
|
@@ -1,18 +1,22 @@
|
|
|
package com.platform.manage;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.platform.entity.IotDeviceGroup;
|
|
|
-import com.platform.exception.BusinessException;
|
|
|
-import com.platform.exception.PageResult;
|
|
|
-import com.platform.request.deviceGroup.DeviceGroupDetailReq;
|
|
|
+import com.platform.enums.ErrorCodeEnum;
|
|
|
+import com.platform.exception.IotException;
|
|
|
import com.platform.request.deviceGroup.IotDeviceGroupRequest;
|
|
|
-import com.platform.response.deviceGroup.DeviceGroupPageResp;
|
|
|
-import com.platform.response.deviceGroup.DeviceGroupDetailResp;
|
|
|
+import com.platform.request.deviceGroup.IotDeviceGroupSaveRequest;
|
|
|
+import com.platform.response.deviceGroup.IotDeviceGroupPageResp;
|
|
|
import com.platform.service.IotDeviceGroupService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
@@ -25,45 +29,58 @@ public class IotDeviceGroupManage {
|
|
|
|
|
|
private final IotDeviceGroupService iotDeviceGroupService;
|
|
|
|
|
|
- public PageResult<DeviceGroupPageResp> pageGroupDevice(DeviceGroupDetailReq req) {
|
|
|
- //todo 设置参数
|
|
|
- IotDeviceGroup iotDeviceGroup = new IotDeviceGroup();
|
|
|
- Page page = iotDeviceGroupService.pageGroupDevice(req.getPageNum(),req.getPageSize(),iotDeviceGroup);
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
- public Boolean addDeviceGroup(IotDeviceGroupRequest request) {
|
|
|
- IotDeviceGroup oneByName = iotDeviceGroupService.getOneByTitle(request.getTitle());
|
|
|
- if (Objects.nonNull(oneByName)){
|
|
|
- throw new BusinessException("设备分组名称已存在");
|
|
|
+ /**
|
|
|
+ * 查询设备分组
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<IotDeviceGroupPageResp> queryGroupDevice(IotDeviceGroupRequest request) {
|
|
|
+ LambdaQueryWrapper<IotDeviceGroup> queryWrapper = Wrappers.<IotDeviceGroup>lambdaQuery()
|
|
|
+ .eq(StringUtils.isNotBlank(request.getTitle()), IotDeviceGroup::getTitle, request.getTitle())
|
|
|
+ .eq(IotDeviceGroup::getDelFlag, 0);
|
|
|
+ List<IotDeviceGroup> deviceGroupList = iotDeviceGroupService.list(queryWrapper);
|
|
|
+
|
|
|
+ //若为null,返回空分页结果
|
|
|
+ if (CollectionUtils.isEmpty(deviceGroupList)) {
|
|
|
+ return Collections.emptyList();
|
|
|
}
|
|
|
- IotDeviceGroup iotDeviceGroup = IotDeviceGroup.toIotDeviceGroup(request);
|
|
|
- return iotDeviceGroupService.addDeviceGroup(iotDeviceGroup);
|
|
|
- }
|
|
|
+ List<IotDeviceGroupPageResp> deviceGroupPageRespList = new ArrayList<>();
|
|
|
|
|
|
- public Boolean updateDeviceGroup(IotDeviceGroupRequest request) {
|
|
|
- if (StringUtils.isBlank(request.getDeviceGroupCode())){
|
|
|
- throw new BusinessException("设备分组码值不能为空");
|
|
|
+ for (IotDeviceGroup iotDeviceGroup : deviceGroupList) {
|
|
|
+ IotDeviceGroupPageResp devicePageResp = IotDeviceGroupPageResp.toDevicePageResp(iotDeviceGroup);
|
|
|
+ deviceGroupPageRespList.add(devicePageResp);
|
|
|
}
|
|
|
- IotDeviceGroup iotDeviceGroup = IotDeviceGroup.toIotDeviceGroup(request);
|
|
|
- return iotDeviceGroupService.updateDeviceGroup(iotDeviceGroup);
|
|
|
+ return deviceGroupPageRespList;
|
|
|
}
|
|
|
|
|
|
- public Boolean delDeviceGroup(String deviceGroupCode) {
|
|
|
- if (StringUtils.isBlank(deviceGroupCode)){
|
|
|
- throw new BusinessException("设备分组码值不能为空");
|
|
|
+ /**
|
|
|
+ * 新增设备分组
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean addDeviceGroup(IotDeviceGroupSaveRequest request) {
|
|
|
+ IotDeviceGroup deviceGroupName = iotDeviceGroupService.getOneByTitle(request.getTitle());
|
|
|
+ if (Objects.nonNull(deviceGroupName)){
|
|
|
+ throw new IotException(ErrorCodeEnum.DATA_SAVE_FAIL, "设备分组名称已存在");
|
|
|
}
|
|
|
- return iotDeviceGroupService.delDeviceGroup(deviceGroupCode);
|
|
|
+ IotDeviceGroup iotDeviceGroup = IotDeviceGroup.toIotDeviceGroup(request);
|
|
|
+ return iotDeviceGroupService.addDeviceGroup(iotDeviceGroup);
|
|
|
}
|
|
|
|
|
|
- public DeviceGroupDetailResp getDeviceGroupDetail(DeviceGroupDetailReq req) {
|
|
|
- //todo 设置参数
|
|
|
- IotDeviceGroup iotDeviceGroup = new IotDeviceGroup();
|
|
|
- IotDeviceGroup iotGroupDetail= iotDeviceGroupService.getDeviceGroupDetail(iotDeviceGroup);
|
|
|
- if (Objects.nonNull(iotGroupDetail)){
|
|
|
- return DeviceGroupDetailResp.toDeviceGroupDetailResp(iotGroupDetail);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除设备分组
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean delDeviceGroup(Long id) {
|
|
|
+ if (id == null){
|
|
|
+ throw new IotException(ErrorCodeEnum.DATA_DELETE_FAIL,"设备分组删除不能为空");
|
|
|
}
|
|
|
- return DeviceGroupDetailResp.getInstance();
|
|
|
+ return iotDeviceGroupService.removeById(id);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|