Ver código fonte

机构类型

TRX 1 ano atrás
pai
commit
175f31a943
23 arquivos alterados com 702 adições e 88 exclusões
  1. 10 2
      FullCardClient/src/main/java/com/zhongshu/card/client/model/school/DeviceInfoModel.java
  2. 3 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/school/DeviceInfoParam.java
  3. 5 2
      FullCardClient/src/main/java/com/zhongshu/card/client/model/school/DeviceInfoSearch.java
  4. 47 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/school/GateWayInfoModel.java
  5. 23 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/school/GateWayInfoParam.java
  6. 38 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/school/GateWayInfoSearch.java
  7. 22 4
      FullCardClient/src/main/java/com/zhongshu/card/client/service/school/DeviceInfoService.java
  8. 28 0
      FullCardClient/src/main/java/com/zhongshu/card/client/service/school/GateWayInfoService.java
  9. 7 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/iotCenter/DeviceSyncController.java
  10. 27 13
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/school/DeviceInfoController.java
  11. 72 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/school/GateWayInfoController.java
  12. 2 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/school/DeviceInfoDao.java
  13. 25 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/school/GateWayInfoDao.java
  14. 19 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/school/extend/GateWayInfoDaoExtend.java
  15. 5 5
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/school/impl/DeviceInfoDaoImpl.java
  16. 94 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/school/impl/GateWayInfoDaoImpl.java
  17. 5 6
      FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/school/DeviceInfo.java
  18. 15 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/school/GateWayInfo.java
  19. 25 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/OrganizationServiceImpl.java
  20. 2 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/AreaServiceImpl.java
  21. 70 17
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/DeviceInfoServiceImpl.java
  22. 129 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/GateWayInfoServiceImpl.java
  23. 29 37
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/sync/DeviceSyncFromIotService.java

+ 10 - 2
FullCardClient/src/main/java/com/zhongshu/card/client/model/school/DeviceInfoModel.java

@@ -2,6 +2,8 @@ package com.zhongshu.card.client.model.school;
 
 import com.github.microservice.models.type.DeviceType;
 import com.zhongshu.card.client.model.base.SuperModel;
+import com.zhongshu.card.client.model.org.OrganizationModel;
+import com.zhongshu.card.client.model.org.OrganizationSimpleModel;
 import com.zhongshu.card.client.utils.type.OnLineState;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
@@ -33,8 +35,14 @@ public class DeviceInfoModel extends SuperModel {
     @Schema(description = "网关号")
     private String gateWayId;
 
-    @Schema(description = "所属区域")
-    private AreaModel area;
+    @Schema(description = "关联的项目code")
+    private String projectInfoCode;
+
+    @Schema(description = "关联的项目Name")
+    private String projectInfoName;
+
+    @Schema(description = "关联的项目信息")
+    private OrganizationSimpleModel projectInfo;
 
     @Schema(description = "是否在线")
     private OnLineState onLineState = OnLineState.OnLine;

+ 3 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/school/DeviceInfoParam.java

@@ -24,6 +24,9 @@ public class DeviceInfoParam extends SuperParam {
     @Schema(description = "网关号")
     private String gateWayId;
 
+    @Schema(description = "关联的项目code")
+    private String projectInfoCode;
+
     @Schema(description = "所属区域")
     private String areaId;
 

+ 5 - 2
FullCardClient/src/main/java/com/zhongshu/card/client/model/school/DeviceInfoSearch.java

@@ -22,8 +22,11 @@ public class DeviceInfoSearch extends SuperSearch {
     @Schema(description = "设备名称")
     private String deviceName;
 
-    @Schema(description = "设备编号")
-    private String code;
+    @Schema(description = "关联的项目code")
+    private String projectInfoCode;
+
+    @Schema(description = "关联的项目Name")
+    private String projectInfoName;
 
     @Schema(description = "设备类型,如 消费机 门禁机")
     private DeviceType deviceType;

+ 47 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/school/GateWayInfoModel.java

@@ -0,0 +1,47 @@
+package com.zhongshu.card.client.model.school;
+
+import com.zhongshu.card.client.model.base.SuperModel;
+import com.zhongshu.card.client.utils.type.OnLineState;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/7/2
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class GateWayInfoModel extends SuperModel {
+    @Schema(description = "网关ID")
+    private String gateWayId;
+
+    @Schema(description = "网关名称")
+    private String gateWayName;
+
+    @Schema(description = "关联的项目code")
+    private String projectInfoCode;
+
+    @Schema(description = "关联的项目Name")
+    private String projectInfoName;
+
+    @Schema(description = "ip地址")
+    private String ip;
+
+    @Schema(description = "网关在线状态")
+    OnLineState state;
+
+    private String stateStr;
+
+    public String getStateStr() {
+        if (state != null) {
+            return state.getRemark();
+        }
+        return "";
+    }
+
+    @Schema(description = "所属区域")
+    private AreaModel area;
+}

+ 23 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/school/GateWayInfoParam.java

@@ -0,0 +1,23 @@
+package com.zhongshu.card.client.model.school;
+
+import com.zhongshu.card.client.model.base.SuperParam;
+import com.zhongshu.card.client.utils.type.OnLineState;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/7/2
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class GateWayInfoParam  {
+    @Schema(description = "网关ID")
+    private String gateWayId;
+
+    @Schema(description = "所属区域")
+    private String areaId;
+}

+ 38 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/school/GateWayInfoSearch.java

@@ -0,0 +1,38 @@
+package com.zhongshu.card.client.model.school;
+
+import com.zhongshu.card.client.model.base.SuperSearch;
+import com.zhongshu.card.client.utils.type.OnLineState;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * @author TRX
+ * @date 2024/7/2
+ */
+@Data
+public class GateWayInfoSearch extends SuperSearch {
+
+    @Schema(description = "")
+    private String keyWord;
+
+    @Schema(description = "网关ID")
+    private String gateWayId;
+
+    @Schema(description = "网关名称")
+    private String gateWayName;
+
+    @Schema(description = "关联的项目code")
+    private String projectInfoCode;
+
+    @Schema(description = "关联的项目Name")
+    private String projectInfoName;
+
+    @Schema(description = "ip地址")
+    private String ip;
+
+    @Schema(description = "网关在线状态")
+    OnLineState state;
+
+    @Schema(description = "所属区域")
+    private String areaId;
+}

+ 22 - 4
FullCardClient/src/main/java/com/zhongshu/card/client/service/school/DeviceInfoService.java

@@ -1,19 +1,21 @@
 package com.zhongshu.card.client.service.school;
 
-import com.zhongshu.card.client.model.school.DeviceInfoModel;
-import com.zhongshu.card.client.model.school.DeviceInfoMoreModel;
-import com.zhongshu.card.client.model.school.DeviceInfoParam;
-import com.zhongshu.card.client.model.school.DeviceInfoSearch;
+import com.github.microservice.models.device.DeviceInfoSyncParam;
+import com.zhongshu.card.client.model.school.*;
 import com.zhongshu.card.client.ret.ResultContent;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 
+import java.util.List;
+
 /**
  * @author TRX
  * @date 2024/6/14
  */
 public interface DeviceInfoService {
 
+    ResultContent syncDeviceInfo(DeviceInfoSyncParam param);
+
     ResultContent addDeviceInfo(DeviceInfoParam param);
 
     ResultContent<Page<DeviceInfoModel>> page(DeviceInfoSearch param, Pageable pageable);
@@ -21,4 +23,20 @@ public interface DeviceInfoService {
     ResultContent deleteDeviceInfo(String id);
 
     ResultContent<DeviceInfoMoreModel> getDeviceDetail(String id);
+
+    /**
+     * 根据设备ID 精确查找设备信息
+     *
+     * @param deviceId
+     * @return
+     */
+    ResultContent<DeviceInfoMoreModel> getDeviceDetailByDeviceId(String deviceId);
+
+    /**
+     * 根据设备ID 模糊查询设备列表
+     *
+     * @param deviceId
+     * @return
+     */
+    ResultContent<List<DeviceInfoMoreModel>> getDeviceDetailByDeviceIdLike(String deviceId);
 }

+ 28 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/service/school/GateWayInfoService.java

@@ -0,0 +1,28 @@
+package com.zhongshu.card.client.service.school;
+
+import com.github.microservice.models.device.GateWaySyncParam;
+import com.zhongshu.card.client.model.school.GateWayInfoModel;
+import com.zhongshu.card.client.model.school.GateWayInfoParam;
+import com.zhongshu.card.client.model.school.GateWayInfoSearch;
+import com.zhongshu.card.client.ret.ResultContent;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+
+/**
+ * @author TRX
+ * @date 2024/6/14
+ */
+public interface GateWayInfoService {
+    ResultContent syncGateWayInfo(GateWaySyncParam.GateWaySyncInfo param);
+
+    ResultContent updateGateArea(GateWayInfoParam param);
+
+    ResultContent<Page<GateWayInfoModel>> page(GateWayInfoSearch param, Pageable pageable);
+
+    ResultContent<GateWayInfoModel> getGateWayInfo(String gateWayId);
+
+    ResultContent<List<GateWayInfoModel>> getAllGateWayInfo();
+
+}

+ 7 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/iotCenter/DeviceSyncController.java

@@ -1,6 +1,7 @@
 package com.zhongshu.card.server.core.controller.iotCenter;
 
 import com.github.microservice.models.device.DeviceSyncListParam;
+import com.github.microservice.models.device.GateWaySyncParam;
 import com.zhongshu.card.client.model.mqtt.SendMessageModel;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.server.core.service.mqtt.MqttServiceImpl;
@@ -35,5 +36,11 @@ public class DeviceSyncController {
         return deviceSyncFromIotService.syncFromIotDevices(param);
     }
 
+    @Operation(summary = "物联网同步网关接口", hidden = true)
+    @RequestMapping(value = "syncGateWays", method = {RequestMethod.POST})
+    public ResultContent syncGateWays(@RequestBody GateWaySyncParam param) {
+        return deviceSyncFromIotService.syncGateWays(param);
+    }
+
 }
 

+ 27 - 13
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/school/DeviceInfoController.java

@@ -17,10 +17,7 @@ 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.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;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -38,6 +35,29 @@ public class DeviceInfoController {
     @Autowired
     DeviceInfoService deviceInfoService;
 
+    //----------------------------设备基础信息 start------------------------
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "根据设备数据ID 设备详情", description = "根据设备数据ID 设备详情")
+    @RequestMapping(value = "getDeviceById", method = {RequestMethod.POST})
+    public ResultContent<DeviceInfoMoreModel> getDeviceById(@RequestBody IDParam param) {
+        return this.deviceInfoService.getDeviceDetail(param.getId());
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "根据设备ID 设备详情(精确匹配)", description = "根据设备ID 设备详情(精确匹配)")
+    @RequestMapping(value = "getDeviceByDeviceId", method = {RequestMethod.GET})
+    public ResultContent<DeviceInfoMoreModel> getDeviceByDeviceId(@RequestParam(name = "deviceId") String deviceId) {
+        return this.deviceInfoService.getDeviceDetailByDeviceId(deviceId);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "根据设备ID 设备列表(模糊匹配)", description = "根据设备ID 设备列表(模糊匹配)")
+    @RequestMapping(value = "getDeviceDetailByDeviceIdLike", method = {RequestMethod.GET})
+    public ResultContent<List<DeviceInfoMoreModel>> getDeviceDetailByDeviceIdLike(@RequestParam(name = "deviceId") String deviceId) {
+        return this.deviceInfoService.getDeviceDetailByDeviceIdLike(deviceId);
+    }
+
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "添加-编辑设备", description = "添加-编辑设备")
     @RequestMapping(value = "addDeviceInfo", method = {RequestMethod.POST})
@@ -52,20 +72,14 @@ public class DeviceInfoController {
         return this.deviceInfoService.deleteDeviceInfo(param.getId());
     }
 
-    @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "设备详情", description = "设备详情")
-    @RequestMapping(value = "getDeviceDetail", method = {RequestMethod.POST})
-    public ResultContent<DeviceInfoMoreModel> getDeviceDetail(@RequestBody IDParam param) {
-        return this.deviceInfoService.getDeviceDetail(param.getId());
-    }
 
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "设备列表-分页查询", description = "设备列表-分页查询")
     @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
-    public ResultContent<Page<DeviceInfoModel>> page(
-            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
-            @Parameter(required = false) DeviceInfoSearch param) {
+    public ResultContent<Page<DeviceInfoModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) DeviceInfoSearch param) {
         return deviceInfoService.page(param, pageable);
     }
 
+    //----------------------------设备基础信息 end--------------------------
+
 }

+ 72 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/school/GateWayInfoController.java

@@ -0,0 +1,72 @@
+package com.zhongshu.card.server.core.controller.school;
+
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.type.AuthType;
+import com.zhongshu.card.client.model.base.IDParam;
+import com.zhongshu.card.client.model.school.*;
+import com.zhongshu.card.client.ret.ResultContent;
+import com.zhongshu.card.client.service.school.DeviceInfoService;
+import com.zhongshu.card.client.service.school.GateWayInfoService;
+import com.zhongshu.card.server.core.service.school.GateWayInfoServiceImpl;
+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.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 网关
+ *
+ * @author TRX
+ * @date 2024/6/5
+ */
+@RestController
+@RequestMapping("/school/gateWay")
+@Tag(name = "学校-网关管理")
+public class GateWayInfoController {
+
+    @Autowired
+    DeviceInfoService deviceInfoService;
+
+    @Autowired
+    GateWayInfoService gateWayInfoService;
+
+    //----------------------------基础信息 start------------------------
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "根据网关ID 查询详情", description = "根据网关ID 查询详情 ")
+    @RequestMapping(value = "getGateWayInfo", method = {RequestMethod.GET})
+    public ResultContent<GateWayInfoModel> getGateWayInfo(@RequestParam(name = "gateWayId") String gateWayId) {
+        return this.gateWayInfoService.getGateWayInfo(gateWayId);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "编辑网关的区域", description = "编辑网关的区域")
+    @RequestMapping(value = "updateGateArea", method = {RequestMethod.POST})
+    public ResultContent updateGateArea(@RequestBody GateWayInfoParam param) {
+        return this.gateWayInfoService.updateGateArea(param);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "网关列表-分页查询", description = "网关列表-分页查询")
+    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
+    public ResultContent<Page<GateWayInfoModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) GateWayInfoSearch param) {
+        return gateWayInfoService.page(param, pageable);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "得到所有的网关", description = "得到所有的网关")
+    @RequestMapping(value = "getAllGateWayInfo", method = {RequestMethod.GET})
+    public ResultContent<List<GateWayInfoModel>> getAllGateWayInfo() {
+        return this.gateWayInfoService.getAllGateWayInfo();
+    }
+
+    //----------------------------基础信息 end--------------------------
+
+}

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

@@ -17,6 +17,8 @@ public interface DeviceInfoDao extends MongoDao<DeviceInfo>, DeviceInfoDaoExtend
 
     DeviceInfo findTopByDeviceId(String deviceId);
 
+    List<DeviceInfo> findTop10ByDeviceIdLike(String deviceId);
+
     DeviceInfo findTopById(String id);
 
     DeviceInfo findTopByDeviceIdAndOid(String code, String oid);

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

@@ -0,0 +1,25 @@
+package com.zhongshu.card.server.core.dao.school;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.server.core.dao.school.extend.DeviceInfoDaoExtend;
+import com.zhongshu.card.server.core.dao.school.extend.GateWayInfoDaoExtend;
+import com.zhongshu.card.server.core.domain.school.DeviceInfo;
+import com.zhongshu.card.server.core.domain.school.GateWayInfo;
+
+import java.util.List;
+
+/**
+ * Dao
+ *
+ * @author TRX
+ * @date 2024/3/21
+ */
+public interface GateWayInfoDao extends MongoDao<GateWayInfo>, GateWayInfoDaoExtend {
+
+    GateWayInfo findTopByGateWayId(String gateWayId);
+
+    List<GateWayInfo> findTop10ByGateWayIdLike(String gateWayId);
+
+    GateWayInfo findTopById(String id);
+
+}

+ 19 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/school/extend/GateWayInfoDaoExtend.java

@@ -0,0 +1,19 @@
+package com.zhongshu.card.server.core.dao.school.extend;
+
+import com.zhongshu.card.client.model.school.DeviceInfoSearch;
+import com.zhongshu.card.client.model.school.GateWayInfoSearch;
+import com.zhongshu.card.server.core.domain.school.DeviceInfo;
+import com.zhongshu.card.server.core.domain.school.GateWayInfo;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+/**
+ * 设备管理
+ *
+ * @Author TRX
+ * @CreateDate: 2023/7/7
+ * @Version: 1.0
+ */
+public interface GateWayInfoDaoExtend {
+    Page<GateWayInfo> page(Pageable pageable, GateWayInfoSearch param);
+}

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

@@ -55,6 +55,10 @@ public class DeviceInfoDaoImpl extends BaseImpl implements DeviceInfoDaoExtend {
             criteria.and("area").is(Area.build(param.getAreaId()));
         }
 
+        if (StringUtils.isNotEmpty(param.getProjectInfoCode())) {
+            criteria.and("projectInfoCode").is(param.getProjectInfoCode());
+        }
+
         if (!CommonUtil.longIsEmpty(param.getStartTime()) && !CommonUtil.longIsEmpty(param.getEndTime())) {
             criteria.and("createTime").gte(param.getStartTime()).and("createTime").lte(param.getEndTime());
         }
@@ -69,10 +73,7 @@ public class DeviceInfoDaoImpl extends BaseImpl implements DeviceInfoDaoExtend {
             Pattern pattern = Pattern.compile("^.*" + param.getDeviceName() + ".*$");
             criterias.add(Criteria.where("deviceName").is(pattern));
         }
-        if (StringUtils.isNotEmpty(param.getCode())) {
-            Pattern pattern = Pattern.compile("^.*" + param.getCode() + ".*$");
-            criterias.add(Criteria.where("code").is(pattern));
-        }
+
         if (StringUtils.isNotEmpty(param.getGateWayId())) {
             Pattern pattern = Pattern.compile("^.*" + param.getGateWayId() + ".*$");
             criterias.add(Criteria.where("gateWayId").is(pattern));
@@ -91,7 +92,6 @@ public class DeviceInfoDaoImpl extends BaseImpl implements DeviceInfoDaoExtend {
             criteria.orOperator(
                     Criteria.where("deviceId").regex(pattern),
                     Criteria.where("deviceName").regex(pattern),
-                    Criteria.where("code").regex(pattern),
                     Criteria.where("gateWayId").regex(pattern),
                     Criteria.where("ip").regex(pattern)
             );

+ 94 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/school/impl/GateWayInfoDaoImpl.java

@@ -0,0 +1,94 @@
+package com.zhongshu.card.server.core.dao.school.impl;
+
+import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
+import com.zhongshu.card.client.model.school.DeviceInfoSearch;
+import com.zhongshu.card.client.model.school.GateWayInfoSearch;
+import com.zhongshu.card.server.core.dao.BaseImpl;
+import com.zhongshu.card.server.core.dao.school.extend.DeviceInfoDaoExtend;
+import com.zhongshu.card.server.core.dao.school.extend.GateWayInfoDaoExtend;
+import com.zhongshu.card.server.core.domain.school.Area;
+import com.zhongshu.card.server.core.domain.school.DeviceInfo;
+import com.zhongshu.card.server.core.domain.school.GateWayInfo;
+import com.zhongshu.card.server.core.util.CommonUtil;
+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 GateWayInfoDaoImpl extends BaseImpl implements GateWayInfoDaoExtend {
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    @Autowired
+    private DBHelper dbHelper;
+
+    @Override
+    public Page<GateWayInfo> page(Pageable pageable, GateWayInfoSearch param) {
+        Criteria criteria = buildCriteria(param);
+
+        if (param.getState() != null) {
+            criteria.and("state").is(param.getState());
+        }
+
+        if (StringUtils.isNotEmpty(param.getAreaId())) {
+            criteria.and("area").is(Area.build(param.getAreaId()));
+        }
+
+        if (StringUtils.isNotEmpty(param.getProjectInfoCode())) {
+            criteria.and("projectInfoCode").is(param.getProjectInfoCode());
+        }
+
+        if (!CommonUtil.longIsEmpty(param.getStartTime()) && !CommonUtil.longIsEmpty(param.getEndTime())) {
+            criteria.and("createTime").gte(param.getStartTime()).and("createTime").lte(param.getEndTime());
+        }
+
+        // 模糊搜索
+        List<Criteria> criterias = new ArrayList<>();
+        if (StringUtils.isNotEmpty(param.getGateWayId())) {
+            Pattern pattern = Pattern.compile("^.*" + param.getGateWayId() + ".*$");
+            criterias.add(Criteria.where("gateWayId").is(pattern));
+        }
+        if (StringUtils.isNotEmpty(param.getGateWayName())) {
+            Pattern pattern = Pattern.compile("^.*" + param.getGateWayName() + ".*$");
+            criterias.add(Criteria.where("gateWayName").is(pattern));
+        }
+
+        if (StringUtils.isNotEmpty(param.getIp())) {
+            Pattern pattern = Pattern.compile("^.*" + param.getIp() + ".*$");
+            criterias.add(Criteria.where("ip").is(pattern));
+        }
+        if (!CollectionUtils.isEmpty(criterias)) {
+            criteria.andOperator(criterias.toArray(new Criteria[]{}));
+        }
+
+        if (StringUtils.isNotEmpty(param.getKeyWord())) {
+            Pattern pattern = Pattern.compile("^.*" + param.getKeyWord() + ".*$");
+            criteria.orOperator(
+                    Criteria.where("gateWayId").regex(pattern),
+                    Criteria.where("gateWayName").regex(pattern),
+                    Criteria.where("ip").regex(pattern)
+            );
+        }
+
+        Sort sort = buildSort(param);
+        Query query = Query.query(criteria);
+        query.with(sort);
+        return dbHelper.pages(query, pageable, GateWayInfo.class);
+    }
+
+}

+ 5 - 6
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/school/DeviceInfo.java

@@ -28,8 +28,11 @@ public class DeviceInfo extends SuperMain {
     @Schema(description = "设备名称")
     private String deviceName;
 
-    @Schema(description = "设备编号")
-    private String code;
+    @Schema(description = "关联的项目code")
+    private String projectInfoCode;
+
+    @Schema(description = "关联的项目Name")
+    private String projectInfoName;
 
     @Schema(description = "设备类型,如 消费机 门禁机")
     private DeviceType deviceType;
@@ -37,10 +40,6 @@ public class DeviceInfo extends SuperMain {
     @Schema(description = "网关号")
     private String gateWayId;
 
-    @Schema(description = "所属区域")
-    @DBRef(lazy = true)
-    private Area area;
-
     @Schema(description = "是否在线")
     private OnLineState onLineState = OnLineState.OnLine;
 

+ 15 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/school/GateWayInfo.java

@@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.springframework.data.mongodb.core.mapping.DBRef;
 import org.springframework.data.mongodb.core.mapping.Document;
 
 /**
@@ -26,7 +27,20 @@ public class GateWayInfo extends SuperMain {
     @Schema(description = "网关名称")
     private String gateWayName;
 
+    @Schema(description = "关联的项目code")
+    private String projectInfoCode;
+
+    @Schema(description = "关联的项目Name")
+    private String projectInfoName;
+
+    @Schema(description = "ip地址")
+    private String ip;
+
     @Schema(description = "网关在线状态")
-    private OnLineState state;
+    OnLineState state;
+
+    @Schema(description = "所属区域")
+    @DBRef(lazy = true)
+    private Area area;
 
 }

+ 25 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/OrganizationServiceImpl.java

@@ -700,6 +700,31 @@ public class OrganizationServiceImpl extends SuperService implements Organizatio
         return ResultContent.buildSuccess();
     }
 
+    /**
+     * @param code
+     * @return
+     */
+    public OrganizationSimpleModel getOrgInfoByCode(String code) {
+        OrganizationSimpleModel model = null;
+        if (StringUtils.isNotEmpty(code)) {
+            Organization organization = organizationDao.findTopByCode(code);
+            if (ObjectUtils.isNotEmpty(organization)) {
+                model = toSimpleModel(organization);
+            }
+        }
+        return model;
+    }
+
+    public String getOrgNameByCode(String code) {
+        if (StringUtils.isNotEmpty(code)) {
+            Organization organization = organizationDao.findTopByCode(code);
+            if (ObjectUtils.isNotEmpty(organization)) {
+                return organization.getName();
+            }
+        }
+        return "";
+    }
+
     public OrganizationModel toModel(Organization entity) {
         OrganizationModel model = new OrganizationModel();
         if (ObjectUtils.isNotEmpty(entity)) {

+ 2 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/AreaServiceImpl.java

@@ -179,8 +179,9 @@ public class AreaServiceImpl extends SuperService implements AreaService {
     }
 
     public AreaModel toModel(Area entity) {
-        AreaModel model = new AreaModel();
+        AreaModel model = null;
         if (ObjectUtils.isNotEmpty(entity)) {
+            model = new AreaModel();
             BeanUtils.copyProperties(entity, model);
             DictInfo dictInfo = entity.getDictInfo();
             if (dictInfo != null) {

+ 70 - 17
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/DeviceInfoServiceImpl.java

@@ -1,16 +1,20 @@
 package com.zhongshu.card.server.core.service.school;
 
 import com.github.microservice.components.data.base.util.PageEntityUtil;
+import com.github.microservice.models.device.DeviceInfoSyncParam;
 import com.zhongshu.card.client.model.school.*;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.client.ret.ResultMessage;
 import com.zhongshu.card.client.service.school.DeviceInfoService;
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
 import com.zhongshu.card.server.core.dao.school.AreaDao;
 import com.zhongshu.card.server.core.dao.school.DeviceInfoDao;
+import com.zhongshu.card.server.core.domain.org.Organization;
 import com.zhongshu.card.server.core.domain.school.Area;
 import com.zhongshu.card.server.core.domain.school.BookInfo;
 import com.zhongshu.card.server.core.domain.school.DeviceInfo;
 import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
 import com.zhongshu.card.server.core.util.BeanUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
@@ -21,6 +25,10 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * @author TRX
  * @date 2024/6/14
@@ -38,6 +46,36 @@ public class DeviceInfoServiceImpl extends SuperService implements DeviceInfoSer
     @Autowired
     AreaDao areaDao;
 
+    @Autowired
+    private OrganizationServiceImpl organizationServiceImpl;
+
+    @Autowired
+    OrganizationDao organizationDao;
+
+    /**
+     * 同步设备 (设备基础信息)
+     *
+     * @param param
+     * @return
+     */
+    @Override
+    public ResultContent syncDeviceInfo(DeviceInfoSyncParam param) {
+        Assert.hasText(param.getDeviceId(), "deviceId不能为空");
+        // 设备号
+        String deviceId = param.getDeviceId();
+        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
+        if (ObjectUtils.isNotEmpty(deviceInfo)) {
+        } else {
+            deviceInfo = new DeviceInfo();
+            initEntityNoCheckOid(deviceInfo);
+        }
+        BeanUtils.copyProperties(param, deviceInfo, "id");
+        deviceInfo.setProjectInfoName(organizationServiceImpl.getOrgNameByCode(param.getProjectInfoCode()));
+        deviceInfoDao.save(deviceInfo);
+        return ResultContent.buildSuccess();
+    }
+
+
     /**
      * 添加-编辑设备
      *
@@ -48,26 +86,14 @@ public class DeviceInfoServiceImpl extends SuperService implements DeviceInfoSer
     public ResultContent addDeviceInfo(DeviceInfoParam param) {
         initDefaultUserAndOidNoExcept(param);
         Assert.hasText(param.getDeviceId(), "deviceId不能为空");
-        String oid = param.getOid();
-        if(StringUtils.isEmpty(oid)) {
-            return ResultContent.buildFail("oid不能为空");
-        }
         String deviceId = param.getDeviceId();
-        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceIdAndOid(deviceId, oid);
+        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
         if (ObjectUtils.isNotEmpty(deviceInfo)) {
-
         } else {
             deviceInfo = new DeviceInfo();
         }
         BeanUtils.copyProperties(param, deviceInfo, "id");
-
-        if (StringUtils.isNotEmpty(param.getAreaId())) {
-            Area area = areaDao.findTopById(param.getAreaId());
-            if (ObjectUtils.isEmpty(area)) {
-                return ResultContent.buildFail(String.format("区域ID不存在:%s", param.getAreaId()));
-            }
-            deviceInfo.setArea(area);
-        }
+        deviceInfo.setProjectInfoName(organizationServiceImpl.getOrgNameByCode(param.getProjectInfoCode()));
         deviceInfoDao.save(deviceInfo);
         return ResultContent.buildSuccess();
     }
@@ -118,22 +144,49 @@ public class DeviceInfoServiceImpl extends SuperService implements DeviceInfoSer
         return ResultContent.buildSuccess(model);
     }
 
+    @Override
+    public ResultContent<DeviceInfoMoreModel> getDeviceDetailByDeviceId(String deviceId) {
+        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
+        DeviceInfoMoreModel model = null;
+        if (ObjectUtils.isNotEmpty(deviceInfo)) {
+            model = toMoreModel(deviceInfo);
+        }
+        return ResultContent.buildSuccess(model);
+    }
+
+    @Override
+    public ResultContent<List<DeviceInfoMoreModel>> getDeviceDetailByDeviceIdLike(String deviceId) {
+        List<DeviceInfoMoreModel> models = new ArrayList<>();
+        if (StringUtils.isNotEmpty(deviceId)) {
+            List<DeviceInfo> list = deviceInfoDao.findTop10ByDeviceIdLike(deviceId);
+            if (ObjectUtils.isNotEmpty(list)) {
+                models = list.stream().map(this::toMoreModel).collect(Collectors.toList());
+            }
+        }
+        return ResultContent.buildSuccess(models);
+    }
+
     public DeviceInfoMoreModel toMoreModel(DeviceInfo entity) {
         DeviceInfoMoreModel model = null;
         if (ObjectUtils.isEmpty(entity)) {
             model = new DeviceInfoMoreModel();
-            BeanUtils.copyProperties(entity, model);
-            model.setArea(areaService.toModel(entity.getArea()));
+            DeviceInfoModel deviceInfoModel = toModel(entity);
+            BeanUtils.copyProperties(deviceInfoModel, model);
         }
         return model;
     }
 
+    /**
+     * 设备基础信息
+     *
+     * @param entity
+     * @return
+     */
     public DeviceInfoModel toModel(DeviceInfo entity) {
         DeviceInfoModel model = null;
         if (ObjectUtils.isNotEmpty(entity)) {
             model = new DeviceInfoModel();
             BeanUtils.copyProperties(entity, model);
-            model.setArea(areaService.toModel(entity.getArea()));
         }
         return model;
     }

+ 129 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/GateWayInfoServiceImpl.java

@@ -0,0 +1,129 @@
+package com.zhongshu.card.server.core.service.school;
+
+import com.github.microservice.components.data.base.util.PageEntityUtil;
+import com.github.microservice.models.device.GateWaySyncParam;
+import com.zhongshu.card.client.model.school.*;
+import com.zhongshu.card.client.ret.ResultContent;
+import com.zhongshu.card.client.service.school.GateWayInfoService;
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
+import com.zhongshu.card.server.core.dao.school.AreaDao;
+import com.zhongshu.card.server.core.dao.school.GateWayInfoDao;
+import com.zhongshu.card.server.core.domain.school.Area;
+import com.zhongshu.card.server.core.domain.school.GateWayInfo;
+import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
+import com.zhongshu.card.server.core.util.BeanUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * @author TRX
+ * @date 2024/7/2
+ */
+@Slf4j
+@Service
+public class GateWayInfoServiceImpl extends SuperService implements GateWayInfoService {
+
+    @Autowired
+    GateWayInfoDao gateWayInfoDao;
+
+    @Autowired
+    AreaDao areaDao;
+
+    @Autowired
+    AreaServiceImpl areaService;
+
+    @Autowired
+    private OrganizationServiceImpl organizationServiceImpl;
+
+    @Autowired
+    OrganizationDao organizationDao;
+
+    /**
+     * 同步网关信息
+     *
+     * @param param
+     * @return
+     */
+    @Override
+    public ResultContent syncGateWayInfo(GateWaySyncParam.GateWaySyncInfo param) {
+        Assert.hasText(param.getGateWayId(), "gateWayId不能为空");
+        // 设备号
+        String gateWayId = param.getGateWayId();
+        GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(gateWayId);
+        if (ObjectUtils.isNotEmpty(gateWayInfo)) {
+        } else {
+            gateWayInfo = new GateWayInfo();
+            initEntityNoCheckOid(gateWayInfo);
+        }
+        BeanUtils.copyProperties(param, gateWayInfo, "id");
+        gateWayInfo.setProjectInfoName(organizationServiceImpl.getOrgNameByCode(param.getProjectInfoCode()));
+        gateWayInfoDao.save(gateWayInfo);
+        return ResultContent.buildSuccess();
+    }
+
+    /**
+     * 修改网管的区域
+     *
+     * @param param
+     * @return
+     */
+    @Override
+    public ResultContent updateGateArea(GateWayInfoParam param) {
+        GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(param.getGateWayId());
+        if (ObjectUtils.isEmpty(gateWayInfo)) {
+            return ResultContent.buildFail(String.format("网关不存在:%s", param.getGateWayId()));
+        }
+        Area area = areaDao.findTopById(param.getAreaId());
+        gateWayInfo.setArea(area);
+        gateWayInfoDao.save(gateWayInfo);
+        return ResultContent.buildSuccess();
+    }
+
+    @Override
+    public ResultContent<Page<GateWayInfoModel>> page(GateWayInfoSearch param, Pageable pageable) {
+        initOidSearchParamNoCheckOid(param);
+        Page<GateWayInfo> page = gateWayInfoDao.page(pageable, param);
+        return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
+    }
+
+    @Override
+    public ResultContent<GateWayInfoModel> getGateWayInfo(String gateWayId) {
+        GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(gateWayId);
+        if (ObjectUtils.isEmpty(gateWayInfo)) {
+            return ResultContent.buildFail(String.format("网关不存在:%s", gateWayId));
+        }
+        return ResultContent.buildSuccess(toModel(gateWayInfo));
+    }
+
+    @Override
+    public ResultContent<List<GateWayInfoModel>> getAllGateWayInfo() {
+        List<GateWayInfo> gateWayInfos = gateWayInfoDao.findAll();
+        List<GateWayInfoModel> models = new ArrayList<>();
+        if (ObjectUtils.isNotEmpty(gateWayInfos)) {
+            models = gateWayInfos.stream().map(this::toModel).collect(Collectors.toList());
+        }
+        return ResultContent.buildSuccess(models);
+    }
+
+    public GateWayInfoModel toModel(GateWayInfo entity) {
+        GateWayInfoModel model = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            model = new GateWayInfoModel();
+            BeanUtils.copyProperties(entity, model);
+            // 区域
+            model.setArea(areaService.toModel(entity.getArea()));
+        }
+        return model;
+    }
+
+}

+ 29 - 37
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/sync/DeviceSyncFromIotService.java

@@ -2,24 +2,18 @@ package com.zhongshu.card.server.core.service.sync;
 
 import com.github.microservice.models.device.DeviceInfoSyncParam;
 import com.github.microservice.models.device.DeviceSyncListParam;
-import com.zhongshu.card.client.model.school.DeviceInfoParam;
+import com.github.microservice.models.device.GateWaySyncParam;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.client.service.school.DeviceInfoService;
-import com.zhongshu.card.client.utils.type.LogsLevel;
-import com.zhongshu.card.client.utils.type.OrganizationRelationType;
 import com.zhongshu.card.server.core.dao.org.OrganizationDao;
 import com.zhongshu.card.server.core.dao.org.OrganizationRelationDao;
-import com.zhongshu.card.server.core.domain.org.Organization;
-import com.zhongshu.card.server.core.domain.org.OrganizationRelation;
+import com.zhongshu.card.server.core.service.school.GateWayInfoServiceImpl;
 import com.zhongshu.card.server.core.service.user.OperationLogsService;
-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.stereotype.Service;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -42,6 +36,9 @@ public class DeviceSyncFromIotService {
     @Autowired
     OperationLogsService operationLogsService;
 
+    @Autowired
+    GateWayInfoServiceImpl gateWayService;
+
     /**
      * 物联网同步设备
      *
@@ -53,38 +50,33 @@ public class DeviceSyncFromIotService {
         List<DeviceInfoSyncParam> list = param.getList();
         if (ObjectUtils.isNotEmpty(list)) {
             for (DeviceInfoSyncParam deviceInfoSyncParam : list) {
-                String projectInfoCode = deviceInfoSyncParam.getProjectInfoCode();
-                List<OrganizationRelation> organizationRelations = new ArrayList<>();
-                // 查询学校绑定的项目
-                if (StringUtils.isNotEmpty(projectInfoCode)) {
-                    Organization project = organizationDao.findTopByCode(projectInfoCode);
-                    if (ObjectUtils.isNotEmpty(project)) {
-                        organizationRelations =
-                                organizationRelationDao.findByRelOrganizationAndRelationType(project, OrganizationRelationType.SchoolToProject);
-                    }
+                ResultContent content = deviceInfoService.syncDeviceInfo(deviceInfoSyncParam);
+                if (content.isSuccess()) {
+                    log.info("同步设备成功:{}", deviceInfoSyncParam.getDeviceName());
+                } else {
+                    log.warn("同步设备失败:{}", content.getMsg());
                 }
-                if (ObjectUtils.isNotEmpty(organizationRelations)) {
-                    for (OrganizationRelation relation : organizationRelations) {
-                        // 没有关联的学校信息
-                        DeviceInfoParam deviceInfoParam = new DeviceInfoParam();
-                        BeanUtils.copyProperties(deviceInfoSyncParam, deviceInfoParam);
-                        // 设置学校的Oid
-                        deviceInfoParam.setOid(relation.getMainOrganization().getOid());
-                        ResultContent resultContent = deviceInfoService.addDeviceInfo(deviceInfoParam);
-                        if (resultContent.isSuccess()) {
-                            operationLogsService.addLogs("", LogsLevel.Middle);
-                        } else {
+            }
+        }
+        return ResultContent.buildSuccess();
+    }
 
-                        }
-                    }
+    /**
+     * 同步网关列表
+     *
+     * @param param
+     * @return
+     */
+    public ResultContent syncGateWays(GateWaySyncParam param) {
+        List<GateWaySyncParam.GateWaySyncInfo> list = param.getList();
+        log.info("syncGateWays: {}", list.size());
+        if (ObjectUtils.isNotEmpty(list)) {
+            for (GateWaySyncParam.GateWaySyncInfo syncInfo : list) {
+                ResultContent content = gateWayService.syncGateWayInfo(syncInfo);
+                if (content.isSuccess()) {
+                    log.info("同步网关成功:{}", syncInfo.getGateWayName());
                 } else {
-                    // 没有关联的学校信息
-                    DeviceInfoParam deviceInfoParam = new DeviceInfoParam();
-                    BeanUtils.copyProperties(deviceInfoSyncParam, deviceInfoParam);
-                    ResultContent content = deviceInfoService.addDeviceInfo(deviceInfoParam);
-                    if (content.isFailed()) {
-                        log.error("同步设备出错: {}", content.getMsg());
-                    }
+                    log.warn("同步网关失败:{}", content.getMsg());
                 }
             }
         }