Просмотр исходного кода

1.新增数据看板新增设备告警图表查询。
2.新增设备离线在线校验数据处理。
3.新增数据看板新增设备告警项目统计查询。

lengfaqiang 2 лет назад
Родитель
Сommit
5afef040df

+ 6 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttDeviceCallbackHandler.java

@@ -19,7 +19,6 @@ import com.sckw.slope.detection.model.param.SmsMessageParam;
 import com.sckw.slope.detection.service.CommonService;
 import com.sckw.slope.detection.service.api.DetectionApiService;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.dubbo.common.utils.MD5Utils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
@@ -165,9 +164,14 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
                 Date date = new Date();
                 long diff = Math.abs(date.getTime() - deviceTime.getTime());
                 long diffHours = diff / (60 * 60 * 1000) % 24;
-                if (diffHours < 24) {
+                if (diffHours > 24) {
                     insertAlarmAndDetail(1L, device, device.getId(), itemValue, ts);
                     // todo 暂未设备告警电话,设备告警不推送短信
+                    device.setOnline(1);
+                    deviceMapper.updateById(device);
+                }else {
+                    device.setOnline(0);
+                    deviceMapper.updateById(device);
                 }
             }
         } catch (Exception e) {

+ 17 - 3
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/AlarmController.java

@@ -87,17 +87,31 @@ public class AlarmController {
         return kwsAlarmService.detail(id, request);
     }
 
-    @Log(description = "项目告警-图")
+    @Log(description = "数据告警-图-项目/项目告警-图")
     @RequestMapping(name = "项目告警-图", value = "/projectAlarm", method = RequestMethod.POST)
     public HttpResult projectAlarm(@Valid @RequestBody AlarmStatisticsQuery query, HttpServletRequest request) {
-        log.info("项目告警-图 projectAlarm param {}", query);
+        log.info("数据告警-图-项目/项目告警-图 projectAlarm param {}", query);
         return kwsAlarmService.projectAlarm(query, request);
     }
 
     @Log(description = "数据告警-图")
-    @RequestMapping(name = "项目告警-图", value = "/dataAlarm", method = RequestMethod.POST)
+    @RequestMapping(name = "数据告警-图", value = "/dataAlarm", method = RequestMethod.POST)
     public HttpResult dataAlarm(@Valid @RequestBody AlarmStatisticsQuery query, HttpServletRequest request) {
         log.info("数据告警-图 dataAlarm param {}", query);
         return kwsAlarmService.dataAlarm(query, request);
     }
+
+    @Log(description = "设备告警-图")
+    @RequestMapping(name = "设备告警-图", value = "/deviceAlarm", method = RequestMethod.POST)
+    public HttpResult deviceAlarm(@Valid @RequestBody AlarmStatisticsQuery query, HttpServletRequest request) {
+        log.info("设备告警-图 deviceAlarm param {}", query);
+        return kwsAlarmService.deviceAlarm(query, request);
+    }
+
+    @Log(description = "设备告警-项目")
+    @RequestMapping(name = "设备告警-项目", value = "/deviceAlarmProject", method = RequestMethod.POST)
+    public HttpResult deviceAlarmProject(@Valid @RequestBody AlarmStatisticsQuery query, HttpServletRequest request) {
+        log.info("设备告警-项目 deviceAlarmProject param {}", query);
+        return kwsAlarmService.deviceAlarmProject(query, request);
+    }
 }

+ 9 - 6
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsAlarmMapper.java

@@ -33,17 +33,20 @@ public interface KwsAlarmMapper extends BaseMapper<KwsAlarm> {
      * @param endTime    结束时间
      * @param projectId  项目
      * @param mountainId 矿山
-     * @param level 等级
+     * @param level      等级
+     * @param type      告警类型
      * @return
      */
-    List<Map<String, Object>> getDataAlarmToDay(@Param("startTime") String startTime, @Param("endTime") String endTime,@Param("level") String level,
-                                                @Param("projectId") String projectId, @Param("mountainId") String mountainId);
+    List<Map<String, Object>> getDataAlarmToDay(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("level") String level,
+                                                @Param("projectId") String projectId, @Param("mountainId") String mountainId, @Param("type") Integer type);
 
     List<Map<String, Object>> getDataAlarmToWeek(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("level") String level,
-                                                 @Param("projectId") String projectId, @Param("mountainId") String mountainId);
+                                                 @Param("projectId") String projectId, @Param("mountainId") String mountainId, @Param("type") Integer type);
 
     List<Map<String, Object>> getDataAlarmToYear(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("level") String level,
-                                                  @Param("projectId") String projectId, @Param("mountainId") String mountainId);
+                                                 @Param("projectId") String projectId, @Param("mountainId") String mountainId, @Param("type") Integer type);
 
-    List<Map<String, Object>> getProjectAlarmList(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("level") String level, @Param("projectId") String projectId, @Param("mountainId") String mountainId);
+    List<Map<String, Object>> getProjectAlarmList(@Param("startTime") String startTime, @Param("endTime") String endTime,
+                                                  @Param("level") String level, @Param("projectId") String projectId,
+                                                  @Param("mountainId") String mountainId, @Param("type") Integer type);
 }

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

@@ -18,8 +18,6 @@ import java.util.List;
 public interface KwsDeviceMapper extends BaseMapper<KwsDevice> {
     int deleteByPrimaryKey(Long id);
 
-    int insert(KwsDevice record);
-
     int insertSelective(KwsDevice record);
 
     KwsDevice selectByPrimaryKey(Long id);
@@ -37,4 +35,6 @@ public interface KwsDeviceMapper extends BaseMapper<KwsDevice> {
     List<ThresholdSelectDTO> selectDeviceAllByProjectAndMountainId(@Param("projectId") String projectId, @Param("mountainId") String mountainId, @Param("status") List<Integer> status);
 
     int selectCountByProject(@Param("projectId") String projectId);
+
+    int selectDeviceOnlineRateCountByProject(@Param("projectId") String projectId);
 }

+ 5 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsDevice.java

@@ -83,6 +83,11 @@ public class KwsDevice implements Serializable {
      */
     private Long updateBy;
 
+    /**
+     * 在线离线状态 0离线  1  在线
+     */
+    private int online;
+
     /**
      * 修改时间
      */

+ 2 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DataScreeningVO.java

@@ -3,6 +3,7 @@ package com.sckw.slope.detection.model.vo;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 /**
  * @author lfdc
@@ -22,7 +23,7 @@ public class DataScreeningVO implements Serializable {
     /**
      * 设备在线率
      */
-    private double deviceOnlineRate;
+    private BigDecimal deviceOnlineRate;
     /**
      * 告警总数
      */

+ 2 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -1,4 +1,5 @@
 package com.sckw.slope.detection.service;
+
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -19,7 +20,6 @@ import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.response.HttpResult;
-import com.sckw.excel.utils.DateUtil;
 import com.sckw.slope.detection.dao.mysql.*;
 import com.sckw.slope.detection.dao.tdengine.InsTablesMapper;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
@@ -33,7 +33,6 @@ import com.sckw.slope.detection.model.param.DeviceReferenceAdd;
 import com.sckw.slope.detection.model.vo.*;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.http.HttpResponse;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -173,6 +172,7 @@ public class DeviceService {
         device.setCreateBy(Long.parseLong(headerData.getCreateBy()));
         device.setCreateTime(now);
         device.setStatus(DeviceEnum.IDENTIFYING.getCode());
+        device.setOnline(NumberConstant.ZERO);
         device.setUpdateBy(Long.parseLong(headerData.getUpdateBy()));
         device.setUpdateTime(now);
         device.setMountainId(headerData.getCompanyId());

+ 112 - 15
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java

@@ -288,6 +288,7 @@ public class KwsAlarmService {
     }
 
     public HttpResult dataAlarm(AlarmStatisticsQuery query, HttpServletRequest request) {
+        int type = 1;
         String startTime = query.getStartTime();
         String endTime = query.getEndTime();
         String latitude = query.getLatitude();
@@ -300,34 +301,34 @@ public class KwsAlarmService {
             startTime = weekMondayAndSunday.get(0);
             endTime = weekMondayAndSunday.get(1);
             //按照天纬度统计
-            returnList = getDataAlarmToWeek(startTime, endTime, level, projectId, headerData.getMountainId());
+            returnList = getDataAlarmToWeek(startTime, endTime, level, projectId, headerData.getMountainId(), type);
         } else if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
             startTime = startTime + " 00:00:00";
             endTime = endTime + " 23:59:59";
             //统计小时的纬度统计
-            returnList = getDataAlarmToDay(startTime, endTime, level, projectId, headerData.getMountainId());
+            returnList = getDataAlarmToDay(startTime, endTime, level, projectId, headerData.getMountainId(), type);
         } else {
             if (latitude != null) {
                 if ("1".equals(latitude)) {
                     startTime = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd") + " 00:00:00";
                     endTime = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd") + " 23:59:59";
-                    returnList = getDataAlarmToDay(startTime, endTime, level, projectId, headerData.getMountainId());
+                    returnList = getDataAlarmToDay(startTime, endTime, level, projectId, headerData.getMountainId(), type);
                 } else if ("2".equals(latitude)) {
                     List<String> weekMondayAndSunday = com.sckw.excel.utils.DateUtil.getWeekMondayAndSunday();
                     startTime = weekMondayAndSunday.get(0);
                     endTime = weekMondayAndSunday.get(1);
-                    returnList = getDataAlarmToWeek(startTime, endTime, level, projectId, headerData.getMountainId());
+                    returnList = getDataAlarmToWeek(startTime, endTime, level, projectId, headerData.getMountainId(), type);
                 } else if ("3".equals(latitude)) {
                     LocalDate firstDayOfMonth = com.sckw.excel.utils.DateUtil.getFirstDayOfMonth();
                     startTime = com.sckw.excel.utils.DateUtil.dateToStr(firstDayOfMonth, "yyyy-MM-dd") /*+ " 00:00:00"*/;
                     LocalDate lastDayOfMonth = com.sckw.excel.utils.DateUtil.getLastDayOfMonth();
                     endTime = com.sckw.excel.utils.DateUtil.dateToStr(lastDayOfMonth, "yyyy-MM-dd")/* + " 23:59:59"*/;
-                    returnList = getDataAlarmToWeek(startTime, endTime, level, projectId, headerData.getMountainId());
+                    returnList = getDataAlarmToWeek(startTime, endTime, level, projectId, headerData.getMountainId(), type);
                 } else if ("4".equals(latitude)) {
                     //查询全年每个月份
                     startTime = com.sckw.excel.utils.DateUtil.getYearFirstMonth() + "-01";
                     endTime = com.sckw.excel.utils.DateUtil.getYearLastMonth() + "-31";
-                    returnList = getDataAlarmToYear(startTime, endTime, level, projectId, headerData.getMountainId());
+                    returnList = getDataAlarmToYear(startTime, endTime, level, projectId, headerData.getMountainId(), type);
                 }
             }
         }
@@ -372,7 +373,7 @@ public class KwsAlarmService {
                 }
             }
         }
-        returnList = getProjectAlarmList(startTime, endTime, level, projectId, headerData.getMountainId());
+        returnList = getProjectAlarmList(startTime, endTime, level, projectId, headerData.getMountainId(), 1);
         if (!CollectionUtils.isEmpty(returnList)) {
             for (Map<String, Object> map : returnList) {
                 String id = map.get("projectId").toString();
@@ -383,25 +384,121 @@ public class KwsAlarmService {
         return HttpResult.ok(returnList);
     }
 
-    private List<Map<String, Object>> getProjectAlarmList(String startTime, String endTime, String level, String projectId, String mountainId) {
-        List<Map<String, Object>> list = alarmMapper.getProjectAlarmList(startTime, endTime, level, projectId, mountainId);
+    private List<Map<String, Object>> getProjectAlarmList(String startTime, String endTime, String level, String projectId, String mountainId, Integer type) {
+        List<Map<String, Object>> list = alarmMapper.getProjectAlarmList(startTime, endTime, level, projectId, mountainId, type);
         return list;
     }
 
-    private List<Map<String, Object>> getDataAlarmToYear(String startTime, String endTime, String level, String projectId, String mountainId) {
-        List<Map<String, Object>> list = alarmMapper.getDataAlarmToYear(startTime, endTime, level, projectId, mountainId);
+    private List<Map<String, Object>> getDataAlarmToYear(String startTime, String endTime, String level, String projectId, String mountainId, Integer type) {
+        List<Map<String, Object>> list = alarmMapper.getDataAlarmToYear(startTime, endTime, level, projectId, mountainId, type);
         return list;
     }
 
-    private List<Map<String, Object>> getDataAlarmToWeek(String startTime, String endTime, String level, String projectId, String mountainId) {
-        List<Map<String, Object>> list = alarmMapper.getDataAlarmToWeek(startTime, endTime, level, projectId, mountainId);
+    private List<Map<String, Object>> getDataAlarmToWeek(String startTime, String endTime, String level, String projectId, String mountainId, Integer type) {
+        List<Map<String, Object>> list = alarmMapper.getDataAlarmToWeek(startTime, endTime, level, projectId, mountainId, type);
         return list;
     }
 
-    private List<Map<String, Object>> getDataAlarmToDay(String startTime, String endTime, String level, String projectId, String mountainId) {
-        List<Map<String, Object>> list = alarmMapper.getDataAlarmToDay(startTime, endTime, level, projectId, mountainId);
+    private List<Map<String, Object>> getDataAlarmToDay(String startTime, String endTime, String level, String projectId, String mountainId, Integer type) {
+        List<Map<String, Object>> list = alarmMapper.getDataAlarmToDay(startTime, endTime, level, projectId, mountainId, type);
         return list;
     }
 
 
+    public HttpResult deviceAlarm(AlarmStatisticsQuery query, HttpServletRequest request) {
+        int type = 2;
+        String startTime = query.getStartTime();
+        String endTime = query.getEndTime();
+        String latitude = query.getLatitude();
+        String projectId = query.getProjectId();
+        String level = query.getLevel();
+        HeaderData headerData = commonService.getHeaderData(request);
+        List<Map<String, Object>> returnList = new ArrayList<>();
+        if (StringUtils.isBlank(startTime) && StringUtils.isBlank(endTime) && StringUtils.isBlank(latitude)) {
+            List<String> weekMondayAndSunday = com.sckw.excel.utils.DateUtil.getWeekMondayAndSunday();
+            startTime = weekMondayAndSunday.get(0);
+            endTime = weekMondayAndSunday.get(1);
+            //按照天纬度统计
+            returnList = getDataAlarmToWeek(startTime, endTime, level, projectId, headerData.getMountainId(),type);
+        } else if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
+            startTime = startTime + " 00:00:00";
+            endTime = endTime + " 23:59:59";
+            //统计小时的纬度统计
+            returnList = getDataAlarmToDay(startTime, endTime, level, projectId, headerData.getMountainId(),type);
+        } else {
+            if (latitude != null) {
+                if ("1".equals(latitude)) {
+                    startTime = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd") + " 00:00:00";
+                    endTime = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd") + " 23:59:59";
+                    returnList = getDataAlarmToDay(startTime, endTime, level, projectId, headerData.getMountainId(),type);
+                } else if ("2".equals(latitude)) {
+                    List<String> weekMondayAndSunday = com.sckw.excel.utils.DateUtil.getWeekMondayAndSunday();
+                    startTime = weekMondayAndSunday.get(0);
+                    endTime = weekMondayAndSunday.get(1);
+                    returnList = getDataAlarmToWeek(startTime, endTime, level, projectId, headerData.getMountainId(),type);
+                } else if ("3".equals(latitude)) {
+                    LocalDate firstDayOfMonth = com.sckw.excel.utils.DateUtil.getFirstDayOfMonth();
+                    startTime = com.sckw.excel.utils.DateUtil.dateToStr(firstDayOfMonth, "yyyy-MM-dd") /*+ " 00:00:00"*/;
+                    LocalDate lastDayOfMonth = com.sckw.excel.utils.DateUtil.getLastDayOfMonth();
+                    endTime = com.sckw.excel.utils.DateUtil.dateToStr(lastDayOfMonth, "yyyy-MM-dd")/* + " 23:59:59"*/;
+                    returnList = getDataAlarmToWeek(startTime, endTime, level, projectId, headerData.getMountainId(),type);
+                } else if ("4".equals(latitude)) {
+                    //查询全年每个月份
+                    startTime = com.sckw.excel.utils.DateUtil.getYearFirstMonth() + "-01";
+                    endTime = com.sckw.excel.utils.DateUtil.getYearLastMonth() + "-31";
+                    returnList = getDataAlarmToYear(startTime, endTime, level, projectId, headerData.getMountainId(),type);
+                }
+            }
+        }
+        return HttpResult.ok(returnList);
+    }
+
+    public HttpResult deviceAlarmProject(AlarmStatisticsQuery query, HttpServletRequest request) {
+        String startTime = query.getStartTime();
+        String endTime = query.getEndTime();
+        String latitude = query.getLatitude();
+        String projectId = query.getProjectId();
+        String level = query.getLevel();
+        HeaderData headerData = commonService.getHeaderData(request);
+        List<Map<String, Object>> returnList = new ArrayList<>();
+        if (StringUtils.isBlank(startTime) && StringUtils.isBlank(endTime) && StringUtils.isBlank(latitude)) {
+            //按照天纬度统计
+            List<String> weekMondayAndSunday = com.sckw.excel.utils.DateUtil.getWeekMondayAndSunday();
+            startTime = weekMondayAndSunday.get(0);
+            endTime = weekMondayAndSunday.get(1);
+        } else if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
+            //统计小时的纬度统计
+            startTime = startTime + " 00:00:00";
+            endTime = endTime + " 23:59:59";
+        } else {
+            if (latitude != null) {
+                if ("1".equals(latitude)) {
+                    startTime = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd") + " 00:00:00";
+                    endTime = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd") + " 23:59:59";
+                } else if ("2".equals(latitude)) {
+                    List<String> weekMondayAndSunday = com.sckw.excel.utils.DateUtil.getWeekMondayAndSunday();
+                    startTime = weekMondayAndSunday.get(0);
+                    endTime = weekMondayAndSunday.get(1);
+                } else if ("3".equals(latitude)) {
+                    LocalDate firstDayOfMonth = com.sckw.excel.utils.DateUtil.getFirstDayOfMonth();
+                    startTime = com.sckw.excel.utils.DateUtil.dateToStr(firstDayOfMonth, "yyyy-MM-dd") + " 00:00:00";
+                    LocalDate lastDayOfMonth = com.sckw.excel.utils.DateUtil.getLastDayOfMonth();
+                    endTime = com.sckw.excel.utils.DateUtil.dateToStr(lastDayOfMonth, "yyyy-MM-dd") + " 23:59:59";
+                } else if ("4".equals(latitude)) {
+                    //查询全年每个月份
+                    startTime = com.sckw.excel.utils.DateUtil.getYearFirstMonth() + "-01" + " 00:00:00";
+                    endTime = com.sckw.excel.utils.DateUtil.getYearLastMonth() + "-31" + " 23:59:59";
+                }
+            }
+        }
+        returnList = getProjectAlarmList(startTime, endTime, level, projectId, headerData.getMountainId(), 2);
+        if (!CollectionUtils.isEmpty(returnList)) {
+            for (Map<String, Object> map : returnList) {
+                String id = map.get("projectId").toString();
+                KwsProject project = projectMapper.selectById(Long.parseLong(id));
+                map.put("projectName", project == null ? id : project.getName());
+            }
+        }
+        return HttpResult.ok(returnList);
+    }
 }

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

@@ -40,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -360,6 +361,7 @@ public class ProjectService {
                         .eq(KwsDevice::getId, id)
                         .set(KwsDevice::getRelevanceLevel, level)
                         .set(KwsDevice::getStatus, DeviceEnum.BE_CHECKING.getCode())
+                        .set(KwsDevice::getOnline, 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()))
@@ -1180,7 +1182,13 @@ public class ProjectService {
         vo.setProjectTotal(count);
         int deviceCount = deviceMapper.selectCountByProject(projectId);
         vo.setDeviceTotal(deviceCount);
-        vo.setDeviceOnlineRate(0);
+        /**仅统计设备在线的数据*/
+        int deviceOnline = deviceMapper.selectDeviceOnlineRateCountByProject(projectId);
+        BigDecimal deviceOnlineRate = new BigDecimal("0.00");
+        if (deviceOnline != 0) {
+            deviceOnlineRate = new BigDecimal(deviceCount).divide(new BigDecimal(deviceOnline), 2, RoundingMode.HALF_UP);
+        }
+        vo.setDeviceOnlineRate(deviceOnlineRate);
         LocalDateTime localDateTimeEnd = DateUtil.localDateToLocalDateTimeEnd(LocalDate.now());
         LocalDateTime localDateTimeStart = DateUtil.localDateToLocalDateTimeStart(LocalDate.now());
         KwsProject project = null;

+ 14 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmMapper.xml

@@ -225,6 +225,9 @@
          FROM kws_alarm_detail a
                   LEFT JOIN kws_alarm b ON a.alarm_id = b.id
         <where>
+            <if test="type != null and type != ''">
+                and b.type =#{type}
+            </if>
             <if test="mountainId != null and mountainId != ''">
                 and b.mountain_id = #{mountainId}
             </if>
@@ -265,6 +268,9 @@
                   LEFT JOIN
               kws_alarm_detail b on a.id = b.alarm_id
         <where>
+            <if test="type != null and type != ''">
+                and a.type =#{type}
+            </if>
             <if test="mountainId != null and mountainId != ''">
                 and a.mountain_id=#{mountainId}
             </if>
@@ -291,6 +297,9 @@
                        FROM kws_alarm a
                                 LEFT JOIN kws_alarm_detail b ON a.id = b.alarm_id
         <where>
+            <if test="type != null and type != ''">
+                and a.type =#{type}
+            </if>
             <if test="mountainId != null and mountainId != ''">
                 and a.mountain_id = #{mountainId}
             </if>
@@ -310,6 +319,11 @@
         FROM
             kws_alarm a
                 LEFT JOIN kws_alarm_detail b ON a.id = b.alarm_id
+            <where>
+               <if test="type != null and type != ''">
+                   and a.type =#{type}
+               </if>
+            </where>
         GROUP BY a.project_id
     </select>
 </mapper>

+ 19 - 16
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml

@@ -23,11 +23,12 @@
     <result column="update_by" jdbcType="BIGINT" property="updateBy" />
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
     <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
+    <result column="online" jdbcType="TINYINT" property="online" />
   </resultMap>
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
     id, `attribute`, `name`, `alias`, sn_code, model_id, valid_time, secret_key, inter_face,relevance_level,
-    remark, `status`, create_by, create_time, update_by, update_time, del_flag,mountain_id,related,check_time
+    remark, `status`, create_by, create_time, update_by, update_time, del_flag,mountain_id,related,check_time,online
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
       <!--@mbg.generated-->
@@ -75,21 +76,6 @@
               and attribute = #{deviceQuery.attribute,jdbcType=TINYINT}
           </if>
   </select>
-  <insert id="insert" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsDevice" keyColumn="uuid" keyProperty="uuid">
-    <!--@mbg.generated-->
-    insert into kws_device (id, `attribute`, `name`, 
-      `alias`, sn_code, model_id, 
-      valid_time, secret_key, inter_face,
-      remark, `status`, create_by, 
-      create_time, update_by, update_time, 
-      del_flag,related,mountain_id)
-    values (#{id,jdbcType=BIGINT}, #{attribute,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, 
-      #{alias,jdbcType=VARCHAR}, #{snCode,jdbcType=VARCHAR}, #{modelId,jdbcType=BIGINT}, 
-      #{validTime,jdbcType=TIMESTAMP}, #{secretKey,jdbcType=VARCHAR}, #{interFace,jdbcType=VARCHAR},
-      #{remark,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, #{createBy,jdbcType=BIGINT}, 
-      #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, 
-      #{delFlag,jdbcType=TINYINT},#{related,jdbcType=BIGINT},#{mountainId,jdbcType=VARCHAR})
-  </insert>
 
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
         <!--@mbg.generated-->
@@ -349,4 +335,21 @@
           and a.id=#{projectId}
       </if>
   </select>
+
+  <select id="selectDeviceOnlineRateCountByProject" resultType="int">
+      SELECT count(distinct c.id)
+      FROM kws_project a
+      LEFT JOIN kws_project_device b
+      ON a.id = b.project_id
+      LEFT JOIN kws_device c ON b.device_id = c.id
+      WHERE a.del_flag = 0
+      AND b.del_flag = 0
+      AND c.del_flag = 0
+      and a.mountain_id = b.mountain_id
+      and b.mountain_id = c.mountain_id
+      and c.online = 1
+      <if test="projectId != null and projectId != ''">
+          and a.id=#{projectId}
+      </if>
+    </select>
 </mapper>