Quellcode durchsuchen

关联设备产品下拉选、设备下拉列表接口

xucaiqin vor 1 Jahr
Ursprung
Commit
fc7cfe6a96
14 geänderte Dateien mit 174 neuen und 68 gelöschten Zeilen
  1. 11 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotDeviceController.java
  2. 8 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotProjectDeviceController.java
  3. 2 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/DevicePage.java
  4. 1 1
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/IotDevicePara.java
  5. 3 1
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/IotDeviceDetailVo.java
  6. 29 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/IotDeviceDownVo.java
  7. 2 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotDeviceMapper.java
  8. 2 2
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProjectDeviceLogMapper.java
  9. 4 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProjectDeviceMapper.java
  10. 11 1
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotDeviceService.java
  11. 10 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotProjectDeviceService.java
  12. 72 56
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotDeviceMapper.xml
  13. 17 6
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProjectDeviceMapper.xml
  14. 2 1
      iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/enums/DictType.java

+ 11 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotDeviceController.java

@@ -42,6 +42,17 @@ public class IotDeviceController {
         return Result.ok(iotDeviceService.pageQuery(devicePage), "查询成功");
     }
 
+    /**
+     * 设备下拉列表
+     *
+     * @param productId 产品id
+     * @return
+     */
+    @GetMapping("/list")
+    public Result<Object> get( Long productId) {
+        return Result.ok(iotDeviceService.list(productId), "查询成功");
+    }
+
     /**
      * 新增设备
      *

+ 8 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotProjectDeviceController.java

@@ -23,6 +23,14 @@ public class IotProjectDeviceController {
 
     private final IotProjectDeviceService iotProjectDeviceService;
 
+    /**
+     * 关联设备产品下拉选
+     */
+    @GetMapping("/list")
+    public Result<Object> get(Long projectId) {
+        return Result.ok(iotProjectDeviceService.list(projectId));
+    }
+
     /**
      * 关联设备列表查询
      */

+ 2 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/DevicePage.java

@@ -12,4 +12,6 @@ import lombok.Setter;
 @Setter
 public class DevicePage extends BasePara {
     private Long productId;
+    //默认筛选全量的 true-过滤已绑定设备
+    private Boolean isBind;
 }

+ 1 - 1
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/IotDevicePara.java

@@ -33,7 +33,7 @@ public class IotDevicePara {
     /**
      * 设备sn码
      */
-    @NotBlank(message = "SN不能为空")
+//    @NotBlank(message = "SN不能为空")
     @Size(max = 50, message = "SN需介于0-50字符")
     private String sn;
 

+ 3 - 1
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/IotDeviceDetailVo.java

@@ -72,11 +72,14 @@ public class IotDeviceDetailVo extends BaseVO {
      * 设备状态 1-在线 0-离线
      */
     private Integer status;
+    private String statusLabel;
+
 
     /**
      * 启用状态 1-启用 0-禁用
      */
     private Integer enableFlag;
+    private String enableFlagLabel;
 
     /**
      * 备注
@@ -84,7 +87,6 @@ public class IotDeviceDetailVo extends BaseVO {
     private String remark;
 
 
-
     private String productCode;
     private String productName;
     /**

+ 29 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/IotDeviceDownVo.java

@@ -0,0 +1,29 @@
+package com.middle.platform.manage.biz.domain.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 设备表
+ *
+ * @author xucaiqin
+ * @date 2023-12-19 13:43:38
+ */
+@Getter
+@Setter
+public class IotDeviceDownVo  {
+    private Long id;
+
+
+    /**
+     * 设备名称
+     */
+    private String name;
+
+    /**
+     * 设备sn码
+     */
+    private String sn;
+
+
+}

+ 2 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotDeviceMapper.java

@@ -59,4 +59,6 @@ public interface IotDeviceMapper extends BaseMapper<IotDevice> {
      * @return
      */
     DeviceVo deviceCache(@Param("guid") String guid);
+
+    List<IotDeviceDownVo> list(@Param("productId") Long productId);
 }

+ 2 - 2
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProjectDeviceLogMapper.java

@@ -3,15 +3,15 @@ package com.middle.platform.manage.biz.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.middle.platform.manage.biz.entity.IotProjectDeviceLog;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
 /**
- *
  * @author Aick Spt
  * @date 2023-12-24 15:20
  */
 @Mapper
 public interface IotProjectDeviceLogMapper extends BaseMapper<IotProjectDeviceLog> {
 
-}
+}

+ 4 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProjectDeviceMapper.java

@@ -3,6 +3,7 @@ package com.middle.platform.manage.biz.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.middle.platform.manage.biz.domain.req.IotProjectDevicePara;
 import com.middle.platform.manage.biz.domain.vo.IotDeviceVo;
+import com.middle.platform.manage.biz.domain.vo.IotProductVo;
 import com.middle.platform.manage.biz.entity.IotProjectDevice;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -48,4 +49,7 @@ public interface IotProjectDeviceMapper extends BaseMapper<IotProjectDevice> {
      * @return
      */
     Integer queryDevice(@Param("id") Long id);
+
+    List<IotProductVo> join(@Param("projectId") Long projectId);
+
 }

+ 11 - 1
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotDeviceService.java

@@ -70,6 +70,8 @@ public class IotDeviceService {
             Optional.ofNullable(userApi.queryUser(a.getCreateBy())).ifPresent(userCache -> a.setCreateByLabel(userCache.getName()));
             Optional.ofNullable(userApi.queryUser(a.getUpdateBy())).ifPresent(userCache -> a.setUpdateByLabel(userCache.getName()));
             Optional.ofNullable(dictApi.query(DictType.NODE_TYPE, String.valueOf(a.getNodeType()))).ifPresent(dictCache -> a.setNodeTypeLabel(dictCache.getLabel()));
+            Optional.ofNullable(dictApi.query(DictType.STATUS_TYPE, String.valueOf(a.getStatus()))).ifPresent(dictCache -> a.setStatusName(dictCache.getLabel()));
+            Optional.ofNullable(dictApi.query(DictType.ENABLE_TYPE, String.valueOf(a.getEnableFlag()))).ifPresent(dictCache -> a.setEnableFlagName(dictCache.getLabel()));
             Optional.ofNullable(cacheService.getKey(String.format(CacheConstant.ONLINE_CACHE, a.getGuid()))).ifPresent(t -> {
                 a.setOnlineTime(t);
                 a.setStatus(1);
@@ -115,7 +117,10 @@ public class IotDeviceService {
             throw new BusinessException("id不能为空");
         }
         //校验sn
-        checkDeviceSn(iotDevicePara.getSn());
+        IotDevice iotDeviceC = iotDeviceMapper.selectOne(new LambdaQueryWrapper<IotDevice>().eq(IotDevice::getSn, iotDevicePara.getSn()).eq(IotDevice::getDelFlag, Global.UN_DEL).last("limit 1"));
+        if (Objects.nonNull(iotDeviceC) && !Objects.equals(iotDeviceC.getId(), iotDevicePara.getId())) {
+            throw new BusinessException("当前设备【" + iotDeviceC.getSn() + "】已存在");
+        }
         //校验产品
         checkProduct(iotDevicePara.getProductId());
 
@@ -189,6 +194,8 @@ public class IotDeviceService {
         Optional.ofNullable(userApi.queryUser(detail.getUpdateBy())).ifPresent(userCache -> detail.setUpdateByLabel(userCache.getName()));
         Optional.ofNullable(dictApi.query(DictType.AUTH_TYPE, String.valueOf(detail.getAuthType()))).ifPresent(cache -> detail.setAuthTypeLabel(cache.getLabel()));
         Optional.ofNullable(dictApi.query(DictType.NODE_TYPE, String.valueOf(detail.getNodeType()))).ifPresent(cache -> detail.setNodeTypeLabel(cache.getLabel()));
+        Optional.ofNullable(dictApi.query(DictType.STATUS_TYPE, String.valueOf(detail.getStatus()))).ifPresent(cache -> detail.setStatusLabel(cache.getLabel()));
+        Optional.ofNullable(dictApi.query(DictType.ENABLE_TYPE, String.valueOf(detail.getEnableFlag()))).ifPresent(cache -> detail.setEnableFlagLabel(cache.getLabel()));
         Optional.ofNullable(dictApi.query(DictType.NETWORK_TYPE, String.valueOf(detail.getNetworkType()))).ifPresent(cache -> detail.setNetworkTypeLabel(cache.getLabel()));
         Optional.ofNullable(dictApi.query(DictType.REPORT_PROTOCOL_TYPE, String.valueOf(detail.getReportProtocol()))).ifPresent(cache -> detail.setReportProtocolLabel(cache.getLabel()));
         Optional.ofNullable(dictApi.query(DictType.VENDORS_TYPE, String.valueOf(detail.getVendors()))).ifPresent(cache -> detail.setVendorsLabel(cache.getLabel()));
@@ -300,4 +307,7 @@ public class IotDeviceService {
     }
 
 
+    public Object list(Long productId) {
+        return iotDeviceMapper.list(productId);
+    }
 }

+ 10 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotProjectDeviceService.java

@@ -154,4 +154,14 @@ public class IotProjectDeviceService extends ServiceImpl<IotProjectDeviceMapper,
             throw new RuntimeException("查无设备,解绑失败");
         }
     }
+
+    /**
+     * 项目
+     *
+     * @param projectId 项目id
+     * @return
+     */
+    public Object list(Long projectId) {
+        return iotProjectDeviceMapper.join(projectId);
+    }
 }

+ 72 - 56
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotDeviceMapper.xml

@@ -101,64 +101,68 @@
             </if>
         </where>
     </select>
-  <select id="pageQuery" resultType="com.middle.platform.manage.biz.domain.vo.IotDeviceVo">
-      select id.*, ip.name as productName, ip.node_type
-      from iot_device id
-               inner join iot_product ip on id.product_id = ip.id and ip.del_flag = 0
-      <where>
-          <if test="keywords != null and keywords != ''">
-              and id.name like concat('%', #{keywords,jdbcType=VARCHAR}, '%')
-          </if>
-          <if test="productId != null">
-              and id.product_id = #{productId,jdbcType=BIGINT}
-          </if>
-          and id.del_flag = 0
-      </where>
-  </select>
+    <select id="pageQuery" resultType="com.middle.platform.manage.biz.domain.vo.IotDeviceVo">
+        select id.*, ip.name as productName, ip.node_type
+        from iot_device id
+                 inner join iot_product ip on id.product_id = ip.id and ip.del_flag = 0
+        <where>
+            <if test="isBind != null and isBind">
+                 id.id not in (select ipd.device_id from iot_project_device ipd where ipd.del_flag = 0)
+            </if>
+            <if test="keywords != null and keywords != ''">
+                and id.name like concat('%', #{keywords,jdbcType=VARCHAR}, '%')
+            </if>
+            <if test="productId != null">
+                and id.product_id = #{productId,jdbcType=BIGINT}
+            </if>
+            and id.del_flag = 0
+        </where>
+    </select>
 
-  <select id="count" resultType="java.util.Map">
-      select count(case when id.status = 1 then 1 end) online,
-             count(case when id.status = 0 then 1 end) offline
-      from iot_device id
-      <where>
-          <if test="productId != null">
-              and id.product_id = #{productId,jdbcType=BIGINT}
-          </if>
+    <select id="count" resultType="java.util.Map">
+        select count(case when id.status = 1 then 1 end) online,
+               count(case when id.status = 0 then 1 end) offline
+        from iot_device id
+        <where>
+            <if test="productId != null">
+                and id.product_id = #{productId,jdbcType=BIGINT}
+            </if>
+            and id.del_flag = 0
+        </where>
+    </select>
+    <select id="detail" resultType="com.middle.platform.manage.biz.domain.vo.IotDeviceDetailVo">
+        select id.id,
+               id.name,
+               id.sn,
+               id.guid,
+               id.subtitle,
+               id.lat,
+               id.lon,
+               id.address,
+               id.online_time,
+               id.status,
+               id.enable_flag,
+               id.remark,
+               id.create_time,
+               id.create_by,
+               id.update_time,
+               id.update_by,
+               ip.code            productCode,
+               ip.name            productName,
+               ip.secret,
+               ip.node_type       nodeType,
+               ip.network_type    networkType,
+               ip.report_protocol reportProtocol,
+               ip.data_format     dataFormat,
+               ip.auth_type       authType,
+               ip.vendors,
+               ip.tag,
+               ip.id              productId
+        from iot_device id
+                 inner join iot_product ip on id.product_id = ip.id and ip.del_flag = 0
+        where id.id = #{id,jdbcType=BIGINT}
           and id.del_flag = 0
-      </where>
-  </select>
-  <select id="detail" resultType="com.middle.platform.manage.biz.domain.vo.IotDeviceDetailVo">
-      select id.id,
-             id.name,
-             id.sn,
-             id.guid,
-             id.subtitle,
-             id.lat,
-             id.lon,
-             id.address,
-             id.online_time,
-             id.status,
-             id.enable_flag,
-             id.remark,
-             id.create_time,
-             id.create_by,
-             id.update_time,
-             id.update_by,
-             ip.code            productCode,
-             ip.name            productName,
-             ip.secret,
-             ip.node_type       nodeType,
-             ip.network_type    networkType,
-             ip.report_protocol reportProtocol,
-             ip.data_format     dataFormat,
-             ip.auth_type       authType,
-             ip.vendors,
-             ip.tag
-      from iot_device id
-               inner join iot_product ip on id.product_id = ip.id and ip.del_flag = 0
-      where id.id = #{id,jdbcType=BIGINT}
-        and id.del_flag = 0
-  </select>
+    </select>
 
     <select id="query" resultType="com.middle.platform.manage.biz.domain.vo.ProductDeviceDto">
         select id.id,
@@ -189,4 +193,16 @@
             and id.del_flag = 0
         </where>
     </select>
+
+    <select id="list" resultType="com.middle.platform.manage.biz.domain.vo.IotDeviceDownVo">
+        select id.id, id.name, id.sn
+        from iot_device id
+        <where>
+            id.del_flag = 0
+              and id.enable_flag = 1
+            <if test="productId != null">
+                and id.product_id = #{productId,jdbcType=BIGINT}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 17 - 6
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProjectDeviceMapper.xml

@@ -61,7 +61,6 @@
     </select>
 
 
-
     <update id="updateProDeviceUntie">
         update iot_project_device
         <set>
@@ -73,11 +72,11 @@
     </update>
 
     <delete id="deleteProDeviceUntie">
-        delete from iot_project_device
+        delete
+        from iot_project_device
         <where>
             id = #{id,jdbcType=BIGINT}
         </where>
-
     </delete>
 
     <select id="selectByProjectDevice" resultMap="BaseResultMap">
@@ -97,7 +96,7 @@
         </set>
         <where>
             project_id = #{projectId,jdbcType=BIGINT}
-                and device_id = #{deviceId,jdbcType=BIGINT}
+              and device_id = #{deviceId,jdbcType=BIGINT}
         </where>
     </update>
 
@@ -117,13 +116,25 @@
     <select id="queryDevice" resultType="java.lang.Integer">
         select count(ipd.id) as deviceNum
         from iot_project_device ipd
-        left join iot_device ide on ide.id = ipd.device_id
+                 left join iot_device ide on ide.id = ipd.device_id
         <where>
             ipd.del_flag = 0
-            and ide.del_flag = 0
+              and ide.del_flag = 0
             <if test="id != null">
                 and ipd.device_id = #{id}
             </if>
         </where>
     </select>
+
+    <select id="join" resultType="com.middle.platform.manage.biz.domain.vo.IotProductVo">
+        select ip.id, ip.name
+        from iot_project_device ipd
+                 left join iot_product ip on ipd.product_id = ip.id and ip.del_flag = 0
+        <where>
+            ipd.del_flag = 0
+            <if test="projectId != null">
+                and ipd.product_id = #{projectId,jdbcType=BIGINT}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 2 - 1
iot-module/iot-module-system/iot-module-system-api/src/main/java/com/middle/platform/system/api/enums/DictType.java

@@ -12,7 +12,8 @@ public interface DictType {
     String DATA_FORMAT_TYPE = "data_format_type";
     String AUTH_TYPE = "auth_type";//认证类型
     String SEX_TYPE = "sex_type";//性别
-    String STATUS_TYPE = "status_type";//状态 启用 禁用
+    String STATUS_TYPE = "status_type";//状态 在线 离线
+    String ENABLE_TYPE = "enable_type";//状态 启用 禁用
     String MENU_TYPE = "menu_type";//菜单类别
 
     /*iotUrl表*/