TRX 1 жил өмнө
parent
commit
9967ba3279
19 өөрчлөгдсөн 684 нэмэгдсэн , 7 устгасан
  1. 21 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupModel.java
  2. 21 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupParam.java
  3. 24 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupSearch.java
  4. 25 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupToDeviceAddParam.java
  5. 24 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupToDeviceModel.java
  6. 21 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupToDeviceSearch.java
  7. 120 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/devices/DeviceGroupController.java
  8. 19 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/DeviceGroupDao.java
  9. 25 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/DeviceGroupToDeviceDao.java
  10. 17 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/extend/DeviceGroupDaoExtend.java
  11. 17 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/extend/DeviceGroupToDeviceDaoExtend.java
  12. 68 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/impl/DeviceGroupDaoImpl.java
  13. 61 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/impl/DeviceGroupToDeviceDaoImpl.java
  14. 2 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/UserGroupToUserDao.java
  15. 4 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/impl/UserGroupDaoImpl.java
  16. 5 5
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/impl/UserGroupToUserDaoImpl.java
  17. 1 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/devices/DeviceGroup.java
  18. 197 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DeviceGroupService.java
  19. 12 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/UserGroupService.java

+ 21 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupModel.java

@@ -0,0 +1,21 @@
+package com.zhongshu.card.client.model.devices.deviceGroup;
+
+import com.zhongshu.card.client.model.base.SuperModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/12/19
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class DeviceGroupModel extends SuperModel {
+
+    @Schema(description = "名称")
+    private String name;
+
+}

+ 21 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupParam.java

@@ -0,0 +1,21 @@
+package com.zhongshu.card.client.model.devices.deviceGroup;
+
+import com.zhongshu.card.client.model.base.SuperParam;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/12/19
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class DeviceGroupParam extends SuperParam {
+
+    @Schema(description = "名称")
+    private String name;
+
+}

+ 24 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupSearch.java

@@ -0,0 +1,24 @@
+package com.zhongshu.card.client.model.devices.deviceGroup;
+
+import com.zhongshu.card.client.model.base.SuperSearch;
+import com.zhongshu.card.client.type.DataState;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/12/19
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class DeviceGroupSearch extends SuperSearch {
+
+    @Schema(description = "分组名称")
+    private String name;
+
+    private DataState state;
+
+}

+ 25 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupToDeviceAddParam.java

@@ -0,0 +1,25 @@
+package com.zhongshu.card.client.model.devices.deviceGroup;
+
+import jakarta.validation.constraints.NotEmpty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author TRX
+ * @date 2024/12/19
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class DeviceGroupToDeviceAddParam {
+
+    @NotEmpty
+    private String groupId;
+
+    private List<String> deviceIds = new ArrayList<String>();
+
+}

+ 24 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupToDeviceModel.java

@@ -0,0 +1,24 @@
+package com.zhongshu.card.client.model.devices.deviceGroup;
+
+import com.zhongshu.card.client.model.devices.DeviceInfoModel;
+import com.zhongshu.card.client.model.org.OrganizationUserModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/12/19
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class DeviceGroupToDeviceModel {
+
+    @Schema(description = "所属设备分组ID")
+    private String id;
+
+    @Schema(description = "设备信息")
+    private DeviceInfoModel deviceInfoModel;
+}

+ 21 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/deviceGroup/DeviceGroupToDeviceSearch.java

@@ -0,0 +1,21 @@
+package com.zhongshu.card.client.model.devices.deviceGroup;
+
+import com.zhongshu.card.client.model.devices.DeviceInfoSearch;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/12/19
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class DeviceGroupToDeviceSearch extends DeviceInfoSearch {
+
+    @Schema(description = "所属分组ID")
+    private String groupId;
+
+}

+ 120 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/devices/DeviceGroupController.java

@@ -0,0 +1,120 @@
+package com.zhongshu.card.server.core.controller.devices;
+
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.type.AuthType;
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.base.IDParam;
+import com.zhongshu.card.client.model.devices.deviceGroup.*;
+import com.zhongshu.card.client.type.DataState;
+import com.zhongshu.card.server.core.service.devices.DeviceGroupService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.util.Assert;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 设备分组
+ *
+ * @author TRX
+ * @date 2024/6/5
+ */
+@RestController
+@RequestMapping("/deviceGroup")
+@Tag(name = "设备管理-设备分组")
+public class DeviceGroupController {
+
+    @Autowired
+    private DeviceGroupService deviceGroupService;
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "数据详情", description = "数据详情")
+    @RequestMapping(value = "getDetailInfo", method = {RequestMethod.POST})
+    public ResultContent<DeviceGroupModel> getDetailInfo(@RequestBody IDParam param) {
+        return this.deviceGroupService.getDetailInfo(param.getId());
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "添加-编辑数据", description = "添加-编辑数据")
+    @RequestMapping(value = "saveInfo", method = {RequestMethod.POST})
+    public ResultContent saveInfo(@RequestBody DeviceGroupParam param) {
+        return this.deviceGroupService.saveInfo(param);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "删除数据", description = "删除数据")
+    @RequestMapping(value = "deleteInfo", method = {RequestMethod.POST})
+    public ResultContent deleteInfo(@RequestBody IDParam param) {
+        return this.deviceGroupService.deleteInfo(param.getId());
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "数据列表-分页查询", description = "数据列表-分页查询")
+    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
+    public ResultContent<Page<DeviceGroupModel>> page(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) DeviceGroupSearch param) {
+        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
+        return deviceGroupService.page(param, pageable);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "数据列表-分页查询(供选择使用)", description = "数据列表-分页查询")
+    @RequestMapping(value = {"pageForSelect"}, method = {RequestMethod.POST})
+    public ResultContent<Page<DeviceGroupModel>> pageForSelect(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) DeviceGroupSearch param) {
+        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
+        return deviceGroupService.page(param, pageable);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "启用数据", description = "启用数据")
+    @RequestMapping(value = "enableData", method = {RequestMethod.POST})
+    public ResultContent enableData(@RequestBody IDParam param) {
+        return this.deviceGroupService.changeState(param.getId(), DataState.Enable);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "禁用数据", description = "禁用数据")
+    @RequestMapping(value = "disableData", method = {RequestMethod.POST})
+    public ResultContent disableData(@RequestBody IDParam param) {
+        return this.deviceGroupService.changeState(param.getId(), DataState.Disable);
+    }
+
+    //-----------------------------分组关联的设备信息 start--------------------
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "设备分组绑定设备", description = "设备分组绑定设备")
+    @RequestMapping(value = "groupBindDevices", method = {RequestMethod.POST})
+    public ResultContent groupBindDevices(@RequestBody DeviceGroupToDeviceAddParam param) {
+        return this.deviceGroupService.groupBindDevices(param);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "删除分组下的设备", description = "删除分组下的设备")
+    @RequestMapping(value = "deleteGroupDeviceInfo", method = {RequestMethod.POST})
+    public ResultContent deleteGroupDeviceInfo(@RequestBody IDParam param) {
+        return this.deviceGroupService.deleteGroupDeviceInfo(param.getId());
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "分组设备数据列表-分页查询", description = "分组设备数据列表-分页查询")
+    @RequestMapping(value = {"pageGroupDevices"}, method = {RequestMethod.POST})
+    public ResultContent<Page<DeviceGroupToDeviceModel>> pageGroupDevices(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) DeviceGroupToDeviceSearch param) {
+        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
+        return deviceGroupService.pageGroupDevices(param, pageable);
+    }
+
+    //-----------------------------分组关联的设备信息 end----------------------
+
+}

+ 19 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/DeviceGroupDao.java

@@ -0,0 +1,19 @@
+package com.zhongshu.card.server.core.dao.devices;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.server.core.dao.devices.extend.DeviceGroupDaoExtend;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroup;
+
+import java.util.List;
+
+/**
+ * @author TRX
+ * @date 2024/3/21
+ */
+public interface DeviceGroupDao extends MongoDao<DeviceGroup>, DeviceGroupDaoExtend {
+
+    List<DeviceGroup> findByIdIn(List<String> ids);
+
+    DeviceGroup findTopById(String id);
+
+}

+ 25 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/DeviceGroupToDeviceDao.java

@@ -0,0 +1,25 @@
+package com.zhongshu.card.server.core.dao.devices;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.server.core.dao.devices.extend.DeviceGroupToDeviceDaoExtend;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroup;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroupToDevice;
+import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
+
+import java.util.List;
+
+/**
+ * @author TRX
+ * @date 2024/3/21
+ */
+public interface DeviceGroupToDeviceDao extends MongoDao<DeviceGroupToDevice>, DeviceGroupToDeviceDaoExtend {
+
+    List<DeviceGroupToDevice> findByIdIn(List<String> ids);
+
+    DeviceGroupToDevice findTopById(String id);
+
+    DeviceGroupToDevice findTopByDeviceGroupAndDeviceInfo(DeviceGroup deviceGroup, DeviceInfo deviceInfo);
+
+    long countByDeviceGroup(DeviceGroup deviceGroup);
+
+}

+ 17 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/extend/DeviceGroupDaoExtend.java

@@ -0,0 +1,17 @@
+package com.zhongshu.card.server.core.dao.devices.extend;
+
+import com.zhongshu.card.client.model.devices.deviceGroup.DeviceGroupSearch;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroup;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+/**
+ * @Author TRX
+ * @CreateDate: 2023/7/7
+ * @Version: 1.0
+ */
+public interface DeviceGroupDaoExtend {
+
+    Page<DeviceGroup> page(Pageable pageable, DeviceGroupSearch param);
+
+}

+ 17 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/extend/DeviceGroupToDeviceDaoExtend.java

@@ -0,0 +1,17 @@
+package com.zhongshu.card.server.core.dao.devices.extend;
+
+import com.zhongshu.card.client.model.devices.deviceGroup.DeviceGroupToDeviceSearch;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroupToDevice;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+/**
+ * @Author TRX
+ * @CreateDate: 2023/7/7
+ * @Version: 1.0
+ */
+public interface DeviceGroupToDeviceDaoExtend {
+
+    Page<DeviceGroupToDevice> page(Pageable pageable, DeviceGroupToDeviceSearch param);
+
+}

+ 68 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/impl/DeviceGroupDaoImpl.java

@@ -0,0 +1,68 @@
+package com.zhongshu.card.server.core.dao.devices.impl;
+
+import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
+import com.zhongshu.card.client.model.devices.deviceGroup.DeviceGroupSearch;
+import com.zhongshu.card.server.core.dao.BaseImpl;
+import com.zhongshu.card.server.core.dao.devices.extend.DeviceGroupDaoExtend;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroup;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * @Author TRX
+ * @CreateDate: 2023/4/12
+ * @Version: 1.0
+ */
+public class DeviceGroupDaoImpl extends BaseImpl implements DeviceGroupDaoExtend {
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    @Autowired
+    private DBHelper dbHelper;
+
+    @Override
+    public Page<DeviceGroup> page(Pageable pageable, DeviceGroupSearch param) {
+        Criteria criteria = buildFilterCriteria(param);
+
+        Sort sort = buildSort(param);
+        Query query = Query.query(criteria);
+        query.with(sort);
+        return dbHelper.pages(query, pageable, DeviceGroup.class);
+    }
+
+    private Criteria buildFilterCriteria(DeviceGroupSearch param) {
+        Criteria criteria = buildCriteriaNotOid(param);
+
+        if (StringUtils.isNotEmpty(param.getProjectOid())) {
+            criteria.and("projectOid").is(param.getProjectOid());
+        }
+        if (param.getState() != null) {
+            criteria.and("state").is(param.getState());
+        }
+
+        // 模糊搜索
+        List<Criteria> criterias = new ArrayList<>();
+        // 用户名称
+        if (StringUtils.isNotEmpty(param.getName())) {
+            Pattern pattern = Pattern.compile("^.*" + param.getName() + ".*$");
+            criterias.add(Criteria.where("name").is(pattern));
+        }
+        if (!CollectionUtils.isEmpty(criterias)) {
+            criteria.andOperator(criterias.toArray(new Criteria[]{}));
+        }
+        return criteria;
+    }
+
+}

+ 61 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/impl/DeviceGroupToDeviceDaoImpl.java

@@ -0,0 +1,61 @@
+package com.zhongshu.card.server.core.dao.devices.impl;
+
+import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
+import com.zhongshu.card.client.model.devices.deviceGroup.DeviceGroupToDeviceSearch;
+import com.zhongshu.card.server.core.dao.BaseImpl;
+import com.zhongshu.card.server.core.dao.devices.extend.DeviceGroupToDeviceDaoExtend;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroup;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroupToDevice;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author TRX
+ * @CreateDate: 2023/4/12
+ * @Version: 1.0
+ */
+public class DeviceGroupToDeviceDaoImpl extends BaseImpl implements DeviceGroupToDeviceDaoExtend {
+
+    @Autowired
+    private DBHelper dbHelper;
+
+    @Override
+    public Page<DeviceGroupToDevice> page(Pageable pageable, DeviceGroupToDeviceSearch param) {
+        Criteria criteria = buildFilterCriteria(param);
+
+        Sort sort = buildSort(param);
+        Query query = Query.query(criteria);
+        query.with(sort);
+        return dbHelper.pages(query, pageable, DeviceGroupToDevice.class);
+    }
+
+    private Criteria buildFilterCriteria(DeviceGroupToDeviceSearch param) {
+        Criteria criteria = buildCriteriaNotOid(param);
+
+        if (StringUtils.isNotEmpty(param.getProjectOid())) {
+            criteria.and("projectOid").is(param.getProjectOid());
+        }
+
+        if (StringUtils.isNotEmpty(param.getGroupId())) {
+            criteria.and("deviceGroup").is(DeviceGroup.build(param.getGroupId()));
+        }
+
+        // 模糊搜索
+        List<Criteria> criterias = new ArrayList<>();
+
+        if (!CollectionUtils.isEmpty(criterias)) {
+            criteria.andOperator(criterias.toArray(new Criteria[]{}));
+        }
+        return criteria;
+    }
+
+}

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/UserGroupToUserDao.java

@@ -20,4 +20,6 @@ public interface UserGroupToUserDao extends MongoDao<UserGroupToUser>, UserGroup
 
     UserGroupToUser findTopByUserGroupAndOrganizationUser(UserGroup userGroup, OrganizationUser organizationUser);
 
+    long countByUserGroup(UserGroup userGroup);
+
 }

+ 4 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/impl/UserGroupDaoImpl.java

@@ -15,6 +15,7 @@ import org.springframework.data.domain.Sort;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -66,6 +67,9 @@ public class UserGroupDaoImpl extends BaseImpl implements UserGroupDaoExtend {
             Pattern pattern = Pattern.compile("^.*" + param.getName() + ".*$");
             criterias.add(Criteria.where("name").is(pattern));
         }
+        if (!CollectionUtils.isEmpty(criterias)) {
+            criteria.andOperator(criterias.toArray(new Criteria[]{}));
+        }
         return criteria;
     }
 

+ 5 - 5
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/impl/UserGroupToUserDaoImpl.java

@@ -13,10 +13,10 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.regex.Pattern;
 
 /**
  * @Author TRX
@@ -54,11 +54,11 @@ public class UserGroupToUserDaoImpl extends BaseImpl implements UserGroupToUserD
 
         // 模糊搜索
         List<Criteria> criterias = new ArrayList<>();
-        // 用户名称
-        if (StringUtils.isNotEmpty(param.getName())) {
-            Pattern pattern = Pattern.compile("^.*" + param.getName() + ".*$");
-            criterias.add(Criteria.where("name").is(pattern));
+
+        if (!CollectionUtils.isEmpty(criterias)) {
+            criteria.andOperator(criterias.toArray(new Criteria[]{}));
         }
+
         return criteria;
     }
 

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/devices/DeviceGroup.java

@@ -28,7 +28,7 @@ public class DeviceGroup extends SuperMain {
     @Schema(description = "数据状态")
     private DataState state = DataState.Enable;
 
-    @Schema(description = "关联的用户数量")
+    @Schema(description = "关联的设备数量")
     private Long number = 0L;
 
     public static DeviceGroup build(String id) {

+ 197 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DeviceGroupService.java

@@ -0,0 +1,197 @@
+package com.zhongshu.card.server.core.service.devices;
+
+import com.github.microservice.components.data.base.util.PageEntityUtil;
+import com.github.microservice.net.ResultContent;
+import com.github.microservice.net.ResultMessage;
+import com.zhongshu.card.client.model.devices.deviceGroup.*;
+import com.zhongshu.card.client.type.DataState;
+import com.zhongshu.card.server.core.dao.devices.DeviceGroupDao;
+import com.zhongshu.card.server.core.dao.devices.DeviceGroupToDeviceDao;
+import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroup;
+import com.zhongshu.card.server.core.domain.devices.DeviceGroupToDevice;
+import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
+import com.zhongshu.card.server.core.domain.org.Organization;
+import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.util.BeanUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 设备分组
+ *
+ * @author TRX
+ * @date 2024/12/19
+ */
+@Slf4j
+@Service
+public class DeviceGroupService extends SuperService {
+
+    @Autowired
+    private OrganizationDao organizationDao;
+
+    @Autowired
+    private DeviceGroupDao deviceGroupDao;
+
+    @Autowired
+    private DeviceGroupToDeviceDao deviceGroupToDeviceDao;
+
+    @Autowired
+    private DeviceInfoDao deviceInfoDao;
+
+    @Autowired
+    private DeviceInfoServiceImpl deviceInfoService;
+
+    public ResultContent saveInfo(DeviceGroupParam param) {
+        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
+
+        DeviceGroup entity = null;
+        if (StringUtils.isNotEmpty(param.getId())) {
+            entity = deviceGroupDao.findTopById(param.getId());
+            if (ObjectUtils.isEmpty(entity)) {
+                return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
+            }
+            initUpdateEntity(entity);
+        } else {
+            entity = new DeviceGroup();
+            initEntityNoCheckOid(entity);
+        }
+        BeanUtils.copyProperties(param, entity);
+        deviceGroupDao.save(entity);
+        return ResultContent.buildSuccess();
+    }
+
+    public ResultContent<Page<DeviceGroupModel>> page(DeviceGroupSearch param, Pageable pageable) {
+        String projectOid = param.getProjectOid();
+        Organization organization = organizationDao.findTopByOid(projectOid);
+        if (ObjectUtils.isEmpty(organization)) {
+            return ResultContent.buildFail("projectOid不存在");
+        }
+        Page<DeviceGroup> page = deviceGroupDao.page(pageable, param);
+        return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
+    }
+
+    public ResultContent deleteInfo(String id) {
+        DeviceGroup entity = deviceGroupDao.findTopById(id);
+        if (ObjectUtils.isEmpty(entity)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
+        }
+        deviceGroupDao.delete(entity);
+        return ResultContent.buildSuccess();
+    }
+
+    public ResultContent<DeviceGroupModel> getDetailInfo(String id) {
+        DeviceGroup entity = deviceGroupDao.findTopById(id);
+        if (ObjectUtils.isEmpty(entity)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
+        }
+        return ResultContent.buildSuccess(toModel(entity));
+    }
+
+    public ResultContent changeState(String id, DataState state) {
+        DeviceGroup entity = deviceGroupDao.findTopById(id);
+        if (ObjectUtils.isEmpty(entity)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
+        }
+        entity.setState(state);
+        deviceGroupDao.save(entity);
+        return ResultContent.buildSuccess();
+    }
+
+    //-----------------------------分组关联的设备信息 start--------------------
+
+    public ResultContent groupBindDevices(DeviceGroupToDeviceAddParam param) {
+        DeviceGroup deviceGroup = deviceGroupDao.findTopById(param.getGroupId());
+        if (ObjectUtils.isEmpty(deviceGroup)) {
+            return ResultContent.buildFail("分组不存在");
+        }
+        if (ObjectUtils.isEmpty(param.getDeviceIds())) {
+            return ResultContent.buildFail("设备信息为空");
+        }
+
+        List<DeviceInfo> list = deviceInfoDao.findByDeviceIdIn(param.getDeviceIds());
+        if (ObjectUtils.isNotEmpty(list)) {
+            List<DeviceGroupToDevice> saveList = new ArrayList<>();
+            for (DeviceInfo deviceInfo : list) {
+                DeviceGroupToDevice deviceGroupToDevice = deviceGroupToDeviceDao.findTopByDeviceGroupAndDeviceInfo(deviceGroup, deviceInfo);
+                if (ObjectUtils.isEmpty(deviceGroupToDevice)) {
+                    deviceGroupToDevice = new DeviceGroupToDevice();
+                    deviceGroupToDevice.setDeviceGroup(deviceGroup);
+                    deviceGroupToDevice.setDeviceInfo(deviceInfo);
+
+                    deviceGroupToDevice.setProjectOid(deviceGroup.getProjectOid());
+                    deviceGroupToDevice.setDeviceId(deviceInfo.getDeviceId());
+                    deviceGroupToDevice.setDeviceName(deviceInfo.getDeviceName());
+
+                    initEntity(deviceGroupToDevice);
+                    saveList.add(deviceGroupToDevice);
+                }
+            }
+            if (ObjectUtils.isNotEmpty(saveList)) {
+                deviceGroupToDeviceDao.saveAll(saveList);
+                initGroupNumber(deviceGroup);
+            }
+        }
+        return ResultContent.buildSuccess();
+    }
+
+    public ResultContent deleteGroupDeviceInfo(String id) {
+        DeviceGroupToDevice entity = deviceGroupToDeviceDao.findTopById(id);
+        if (ObjectUtils.isEmpty(entity)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
+        }
+        deviceGroupToDeviceDao.delete(entity);
+        initGroupNumber(entity.getDeviceGroup());
+        return ResultContent.buildSuccess();
+    }
+
+    public void initGroupNumber(DeviceGroup deviceGroup) {
+        if (ObjectUtils.isNotEmpty(deviceGroup)) {
+            long number = deviceGroupToDeviceDao.countByDeviceGroup(deviceGroup);
+            deviceGroup.setNumber(number);
+            deviceGroupDao.save(deviceGroup);
+        }
+    }
+
+    public ResultContent<Page<DeviceGroupToDeviceModel>> pageGroupDevices(DeviceGroupToDeviceSearch param, Pageable pageable) {
+        String projectOid = param.getProjectOid();
+        Organization organization = organizationDao.findTopByOid(projectOid);
+        if (ObjectUtils.isEmpty(organization)) {
+            return ResultContent.buildFail("projectOid不存在");
+        }
+        Page<DeviceGroupToDevice> page = deviceGroupToDeviceDao.page(pageable, param);
+        return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toDeviceModel));
+    }
+
+    //-----------------------------分组关联的设备信息 end----------------------
+
+    private DeviceGroupModel toModel(DeviceGroup entity) {
+        DeviceGroupModel model = new DeviceGroupModel();
+        if (ObjectUtils.isNotEmpty(entity)) {
+            BeanUtils.copyProperties(entity, model);
+        }
+        return model;
+    }
+
+    public DeviceGroupToDeviceModel toDeviceModel(DeviceGroupToDevice entity) {
+        DeviceGroupToDeviceModel model = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            model = new DeviceGroupToDeviceModel();
+            model.setId(entity.getId());
+
+            model.setDeviceInfoModel(deviceInfoService.toModel(entity.getDeviceInfo()));
+        }
+        return model;
+    }
+
+}

+ 12 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/UserGroupService.java

@@ -26,7 +26,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
- * 权限时间段管理
+ * 用户分组
  *
  * @author TRX
  * @date 2024/12/19
@@ -138,6 +138,8 @@ public class UserGroupService extends SuperService {
             }
             if (ObjectUtils.isNotEmpty(saveList)) {
                 userGroupToUserDao.saveAll(saveList);
+
+                initGroupNumber(userGroup);
             }
         }
         return ResultContent.buildSuccess();
@@ -149,9 +151,18 @@ public class UserGroupService extends SuperService {
             return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
         }
         userGroupToUserDao.delete(entity);
+        initGroupNumber(entity.getUserGroup());
         return ResultContent.buildSuccess();
     }
 
+    public void initGroupNumber(UserGroup userGroup) {
+        if (ObjectUtils.isNotEmpty(userGroup)) {
+            long number = userGroupToUserDao.countByUserGroup(userGroup);
+            userGroup.setNumber(number);
+            userGroupDao.save(userGroup);
+        }
+    }
+
     public ResultContent<Page<UserGroupToUserModel>> pageGroupUsers(UserGroupToUserSearch param, Pageable pageable) {
         String projectOid = param.getProjectOid();
         Organization organization = organizationDao.findTopByOid(projectOid);