lengfaqiang 2 år sedan
förälder
incheckning
28ca5e0fc3

+ 9 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsDeviceMapper.java

@@ -37,6 +37,15 @@ public interface KwsDeviceMapper extends BaseMapper<KwsDevice> {
      */
     List<DeviceDataDTO> selectDeviceAllNotDeviceRelation(@Param("projectId") String projectId, @Param("companyId") String companyId);
 
+    /**
+     * 查询项目中未绑定设备关联关系的设备
+     *
+     * @param projectId
+     * @param companyId
+     * @return
+     */
+    List<DeviceDataDTO> selectDeviceAllByBind(@Param("projectId") String projectId, @Param("companyId") String companyId);
+
     List<DeviceDataDTO> selectAllDeviceByProject(@Param("projectId") String projectId);
 
     List<DeviceVo> selectByDeviceParam(@Param("deviceQuery") DeviceQuery deviceQuery);

+ 13 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsProjectMapper.java

@@ -30,6 +30,11 @@ public interface KwsProjectMapper extends BaseMapper<KwsProject> {
 
     List<ProjectDeviceVO> selectDeviceList(@Param("deviceQuery") DeviceQuery deviceQuery);
 
+    /**
+     * 设备没有建立主从设备的数据
+     * @param deviceQuery
+     * @return
+     */
     List<ProjectDeviceVO> selectDeviceNotBindList(@Param("deviceQuery") DeviceQuery deviceQuery);
 
     /**
@@ -43,4 +48,12 @@ public interface KwsProjectMapper extends BaseMapper<KwsProject> {
     List<KwsProject> selectListData(@Param("ids") List<String> ids, @Param("delFlag") Integer delFlag);
 
     List<KwsProject> selectListByType(@Param("projectType") String projectType);
+
+    /**
+     * 设备没有建立主从没有和项目绑定的数据
+     * @param deviceQuery
+     * @param headerData
+     * @return
+     */
+    List<ProjectDeviceVO> selectNotBindProjectDeviceAll(@Param("deviceQuery") DeviceQuery deviceQuery, @Param("headerData") HeaderData headerData);
 }

+ 8 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java

@@ -441,6 +441,7 @@ public class ProjectService {
                         throw new BusinessException("所属主设备id错误!");
                     }
                     kwsDevice.setInstallTime(localDateTime);
+                    kwsDevice.setRelated(1);
                     kwsDevice.setRelevanceLevel(level);
                     kwsDevice.setUpdateTime(LocalDateTime.now());
                     kwsDevice.setUpdateBy(headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
@@ -452,6 +453,7 @@ public class ProjectService {
                         .eq(KwsDevice::getId, id)
                         .set(KwsDevice::getRelevanceLevel, level)
                         .set(KwsDevice::getInstallTime, localDateTime)
+                        .set(KwsDevice::getRelated, 1)
                         .set(KwsDevice::getDeviceCode, deviceCode)
                         .set(KwsDevice::getStatus, DeviceEnum.BE_CHECKING.getCode())
                         .set(KwsDevice::getOnline, 1)
@@ -471,7 +473,9 @@ public class ProjectService {
     public PageRes deviceBindSelect(DeviceQuery deviceQuery, HttpServletRequest request) {
         HeaderData headerData = commonService.getHeaderData(request);
         PageHelper.startPage(deviceQuery.getPage(), deviceQuery.getPageSize());
-        List<ProjectDeviceVO> list = projectMapper.selectNotBindDeviceList(deviceQuery, headerData);
+        //查询设备与项目没有绑定的数据
+//        List<ProjectDeviceVO> list = projectMapper.selectNotBindDeviceList(deviceQuery, headerData);
+        List<ProjectDeviceVO> list = projectMapper.selectNotBindProjectDeviceAll(deviceQuery, headerData);
         PageInfo<ProjectDeviceVO> info = new PageInfo<>(list);
         if (CollectionUtils.isEmpty(list)) {
             return PageRes.build(info, list);
@@ -1807,11 +1811,13 @@ public class ProjectService {
                         throw new BusinessException("所属主设备id错误!");
                     }
                     kwsDevice.setAlias(alias);
+                    kwsDevice.setRelated(1);
                     kwsDevice.setInstallTime(localDateTime);
                     kwsDevice.setRelevanceLevel(level);
                     kwsDevice.setUpdateTime(LocalDateTime.now());
                     kwsDevice.setUpdateBy(headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
                     level = "2";
+                    deviceMapper.updateById(kwsDevice);
                 }
                 KwsDevice kwsDevice = deviceMapper.selectByPrimaryKey(id);
                 deviceMapper.update(null, new LambdaUpdateWrapper<KwsDevice>()
@@ -1820,6 +1826,7 @@ public class ProjectService {
                         .set(KwsDevice::getStatus, DeviceEnum.BE_CHECKING.getCode())
                         .set(KwsDevice::getInstallTime, localDateTime)
                         .set(KwsDevice::getOnline, 1)
+                        .set(KwsDevice::getRelated, 1)
                         .set(KwsDevice::getAlias, bindDevice.getAlias() == null ? kwsDevice.getName() : bindDevice.getAlias())
                         .set(KwsDevice::getUpdateTime, LocalDateTime.now())
                         .set(KwsDevice::getUpdateBy, headerData.getUpdateBy() == null ? Long.parseLong(headerData.getCreateBy()) : Long.parseLong(headerData.getUpdateBy()))

+ 5 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml

@@ -298,6 +298,7 @@
           AND c.id NOT in (SELECT DISTINCT a.device_id
                            FROM kws_device_relation a
                                     LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id where a.del_flag = 0)
+        and c.id in (SELECT device_id FROM kws_project_device WHERE del_flag = 0)
         <if test="projectId != null and projectId != ''">
             AND a.id = #{projectId}
         </if>
@@ -436,4 +437,8 @@
   <select id="getMaxDeviceCodeAndSplit" resultType="java.lang.String">
       SELECT max(SUBSTRING(device_code, #{start}, #{length})) FROM kws_device;
     </select>
+
+  <select id="selectDeviceAllByBind" resultType="com.sckw.slope.detection.model.dto.DeviceDataDTO">
+
+    </select>
 </mapper>

+ 49 - 3
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsProjectMapper.xml

@@ -163,10 +163,10 @@
           AND c.relevance_level = 0
           AND c.id NOT in (SELECT DISTINCT a.relate_device_id
                            FROM kws_device_relation a
-                                    LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id)
+                                    LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id where a.del_flag = 0)
           AND c.id NOT in (SELECT DISTINCT a.device_id
                            FROM kws_device_relation a
-                                    LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id)
+                                    LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id where a.del_flag = 0)
         <if test="deviceQuery.projectId != null and deviceQuery.projectId != ''">
             AND a.id = #{deviceQuery.projectId}
         </if>
@@ -220,7 +220,7 @@
                 , '%')
         </if>
         <if test="headerData.companyId != null and headerData.companyId != ''">
-            and a.mountain_id =#{headerData.companyId}
+            and a.mountain_id = #{headerData.companyId}
         </if>
     </select>
 
@@ -251,4 +251,50 @@
             and project_type like concat(#{projectType}, '%')
         </where>
     </select>
+
+    <select id="selectNotBindProjectDeviceAll" resultType="com.sckw.slope.detection.model.vo.ProjectDeviceVO">
+        SELECT a.id           AS id,
+               a.`status`     AS STATUS,
+               a.`name`       AS NAME,
+               a.create_time  AS createTime,
+               d.device_type  AS deviceType,
+               d.manufacturer AS manufacturer,
+               d.`name`       AS deviceModelName
+        FROM kws_device a
+                 LEFT JOIN kws_device_model d ON d.id = a.model_id
+        WHERE a.mountain_id = d.mountain_id
+          and a.del_flag = 0
+          AND a.del_flag = 0
+          AND d.del_flag = 0
+          AND a.id NOT in (SELECT DISTINCT a.relate_device_id
+                           FROM kws_device_relation a
+                                    LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id where a.del_flag = 0)
+          AND a.id NOT in (SELECT DISTINCT a.device_id
+                           FROM kws_device_relation a
+                                    LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id where a.del_flag = 0)
+          and a.id not in (SELECT device_id FROM kws_project_device WHERE del_flag = 0)
+        <if test="deviceQuery.manufacturer != null and deviceQuery.manufacturer != ''">
+            and d.manufacturer like concat('%'
+                , #{deviceQuery.manufacturer}
+                , '%')
+        </if>
+        <if test="deviceQuery.deviceType != null and deviceQuery.deviceType != ''">
+            and d.device_type like concat('%'
+                , #{deviceQuery.deviceType}
+                , '%')
+        </if>
+        <if test="deviceQuery.deviceModel != null and deviceQuery.deviceModel != ''">
+            and d.name like concat('%'
+                , #{deviceQuery.deviceModel}
+                , '%')
+        </if>
+        <if test="deviceQuery.name != null and deviceQuery.name != ''">
+            and a.name like concat('%'
+                , #{deviceQuery.name}
+                , '%')
+        </if>
+        <if test="headerData.companyId != null and headerData.companyId != ''">
+            and a.mountain_id = #{headerData.companyId}
+        </if>
+    </select>
 </mapper>