فهرست منبع

1.元数据日志查询
2.修改异常处理
3.traceIdLog日志处理

lengfaqiang 2 سال پیش
والد
کامیت
00b4debf27
18فایلهای تغییر یافته به همراه374 افزوده شده و 66 حذف شده
  1. 9 2
      slope-common/slope-common-core/src/main/java/com/sckw/core/exception/GlobalSystemExceptionHandler.java
  2. 60 4
      slope-common/slope-common-log/src/main/java/com/sckw/log/TraceLog/aop/TraceIdAspect.java
  3. 13 3
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/DeviceController.java
  4. 10 5
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/DeviceModelController.java
  5. 11 5
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/LogController.java
  6. 15 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsDeviceMapper.java
  7. 7 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/tdengine/OriginalMapper.java
  8. 2 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsDevice.java
  9. 2 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/tdengine/Original.java
  10. 30 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/OriginalDeviceQuery.java
  11. 40 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/ProjectAndModelAndDeviceQuery.java
  12. 5 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/ProjectQuery.java
  13. 28 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/OriginalDeviceVO.java
  14. 18 9
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceModelService.java
  15. 37 19
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java
  16. 57 18
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/LogService.java
  17. 17 1
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml
  18. 13 0
      slope-modules/slope-detection/src/main/resources/mapper/tdengine/OriginalMapper.xml

+ 9 - 2
slope-common/slope-common-core/src/main/java/com/sckw/core/exception/GlobalSystemExceptionHandler.java

@@ -5,6 +5,7 @@ import com.sckw.core.web.response.HttpResult;
 import jakarta.validation.ConstraintViolation;
 import jakarta.validation.ConstraintViolationException;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.util.CollectionUtils;
 import org.springframework.validation.FieldError;
@@ -33,7 +34,14 @@ public class GlobalSystemExceptionHandler {
     @ResponseBody
     public HttpResult handlerRuntimeException(RuntimeException e) {
         log.error("业务异常:", e);
-        return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
+        String message = e.getMessage();
+        if (StringUtils.isBlank(message)) {
+            Throwable cause = e.getCause();
+            if (cause != null) {
+                message = cause.getMessage();
+            }
+        }
+        return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, message);
     }
 
     /**
@@ -63,7 +71,6 @@ public class GlobalSystemExceptionHandler {
     }
 
 
-
     @ResponseBody
     @ExceptionHandler(MissingServletRequestParameterException.class)
     public HttpResult noArgs(MissingServletRequestParameterException ex) {

+ 60 - 4
slope-common/slope-common-log/src/main/java/com/sckw/log/TraceLog/aop/TraceIdAspect.java

@@ -1,9 +1,14 @@
 package com.sckw.log.TraceLog.aop;
 
+import com.alibaba.fastjson.JSON;
 import com.sckw.core.model.constant.StringConstant;
 import com.sckw.core.utils.UUIDUtils;
 import com.sckw.log.TraceLog.TraceLog;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
@@ -11,6 +16,13 @@ import org.aspectj.lang.annotation.Pointcut;
 import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * @author lfdc
@@ -22,6 +34,8 @@ import org.springframework.stereotype.Component;
 @Component
 public class TraceIdAspect {
 
+    private static final String TIME_PATTERN = "yyyy-MM-dd HH:mm:ss:SSS";
+
     @Value("${spring.application.name}")
     private String shortName;
 
@@ -31,18 +45,60 @@ public class TraceIdAspect {
     }
 
     @Around("traceId(l)")
-    public Object arround(ProceedingJoinPoint joinPoint, TraceLog l) {
+    public Object arround(ProceedingJoinPoint joinPoint, TraceLog l)  throws Throwable{
         MDC.put(StringConstant.TRACE_ID, UUIDUtils.get32UUID() + StringConstant.RUNG + l.description() /*+ shortName*/);
+//        try {
+//            long start = System.currentTimeMillis();
+//            Object o = joinPoint.proceed();
+//            long end = System.currentTimeMillis();
+//            log.info("方法耗时:{} ms", end - start);
+//            return o;
+//        } catch (Throwable e) {
+//            return e.getMessage();
+//        } finally {
+//            MDC.clear();
+//        }
+        Object result = null;
+        //开始时间
+        Date startTime = new Date();
+        String targetName = joinPoint.getTarget().getClass().getName();
+        String methodName = joinPoint.getSignature().getName();
+        Object[] args = joinPoint.getArgs();
+        Stream<?> stream = ArrayUtils.isEmpty(args) ? Stream.empty() : Arrays.stream(args);
+        List<Object> logArgs = stream
+                .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse)) && !(arg instanceof MultipartFile))
+                .collect(Collectors.toList());
+        //过滤后序列化无异常
+        String param = JSON.toJSONString(logArgs);
+        String exception = "";
         try {
             long start = System.currentTimeMillis();
-            Object o = joinPoint.proceed();
+            //执行结果,返回参数
+            result = joinPoint.proceed();
             long end = System.currentTimeMillis();
             log.info("方法耗时:{} ms", end - start);
-            return o;
         } catch (Throwable e) {
-            return null;
+            exception = e.getMessage();
+            //异常抛出
+            throw e;
         } finally {
+            Date endTime = new Date();
+            long time = endTime.getTime() - startTime.getTime();
+            Boolean slowRequest = (time > 1500L);
+            log.info("{}:{}.{}," +
+                            "param={}," +
+                            "result={}," +
+                            "exception={}," +
+                            "[{}->{}],slowRequest{}=[{}]", l.description(), targetName, methodName,
+                    param,
+                    JSON.toJSONString(result),
+                    exception,
+                    DateFormatUtils.format(startTime, TIME_PATTERN),
+                    DateFormatUtils.format(endTime, TIME_PATTERN),
+                    slowRequest,
+                    time);
             MDC.clear();
         }
+        return result;
     }
 }

+ 13 - 3
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/DeviceController.java

@@ -3,6 +3,7 @@ package com.sckw.slope.detection.controller;
 import com.alibaba.fastjson2.JSONObject;
 import com.sckw.core.annotation.Log;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.log.TraceLog.TraceLog;
 import com.sckw.slope.detection.model.dto.LocationDTO;
 import com.sckw.slope.detection.model.param.DeviceAdd;
 import com.sckw.slope.detection.model.param.DeviceQuery;
@@ -34,14 +35,14 @@ public class DeviceController {
     @RequestMapping(name = "设备删除", value = "/dels", method = RequestMethod.GET)
     public HttpResult dels(@RequestParam("ids") @NotBlank(message = "设备id不能为空") String ids, HttpServletRequest request) {
         log.info("设备删除 delete param:{}", ids);
-        return deviceService.dels(ids,request);
+        return deviceService.dels(ids, request);
     }
 
     @Log(description = "所属设备查询")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "所属设备查询", value = "/deviceAll", method = RequestMethod.GET)
     public HttpResult deviceAll(@RequestParam("projectId") String projectId) {
-        log.info("所属设备查询 deviceAll param :{}",projectId);
+        log.info("所属设备查询 deviceAll param :{}", projectId);
         return deviceService.deviceAll(projectId);
     }
 
@@ -88,7 +89,7 @@ public class DeviceController {
                                   @RequestParam("deviceId") @NotBlank(message = "设备id不能为空") String deviceId,
                                   HttpServletRequest request) {
         log.info("设备监测值-原始/当前/测量 outputValue param1 :{},param2:{}", projectId, deviceId);
-        return deviceService.outputValue(projectId,deviceId, request);
+        return deviceService.outputValue(projectId, deviceId, request);
     }
 
     @Log(description = "设备编辑")
@@ -115,4 +116,13 @@ public class DeviceController {
         return deviceService.monitorItem(id, request);
     }
 
+
+    //    @Log(description = "查询型号下的设备")
+    @TraceLog(description = "查询产品类型下的设备")
+    @RequestMapping(name = "查询产品类型下的设备", value = "/findDeviceListByModelId", method = RequestMethod.GET)
+    public HttpResult findDeviceListByModelId(@RequestParam("modelType") @NotBlank(message = "产品类型不能为空") String modelType, HttpServletRequest request) {
+        log.info("查询产品类型下的设备 findDeviceListByModelId query :{}",modelType);
+        return deviceService.findDeviceListByModelType(modelType, request);
+    }
+
 }

+ 10 - 5
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/DeviceModelController.java

@@ -2,22 +2,19 @@ package com.sckw.slope.detection.controller;
 
 import com.alibaba.fastjson2.JSONObject;
 import com.sckw.core.annotation.Log;
-import com.sckw.core.annotation.RepeatSubmit;
 import com.sckw.core.web.response.HttpResult;
-import com.sckw.slope.detection.model.param.DeviceModelQuery;
+import com.sckw.log.TraceLog.TraceLog;
 import com.sckw.slope.detection.model.param.DeviceModelAdd;
+import com.sckw.slope.detection.model.param.DeviceModelQuery;
 import com.sckw.slope.detection.service.DeviceModelService;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.validation.Valid;
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.http.HttpResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
-
 /**
  * @author sky
  * @description 设备Model controller
@@ -73,4 +70,12 @@ public class DeviceModelController {
         log.info("设备型号编辑 update param:{}", JSONObject.toJSONString(deviceModelAdd));
         return deviceModelService.update(deviceModelAdd, response);
     }
+
+    @Log(description = "查询设备型号")
+    @TraceLog(description = "查询设备型号")
+    @RequestMapping(name = "查询设备型号", value = "/findModelList", method = RequestMethod.GET)
+    public HttpResult findModelList(HttpServletRequest request) {
+        log.info("查询设备型号 findModelList");
+        return deviceModelService.findModelList(request);
+    }
 }

+ 11 - 5
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/LogController.java

@@ -3,13 +3,18 @@ package com.sckw.slope.detection.controller;
 import com.alibaba.fastjson2.JSONObject;
 import com.sckw.core.annotation.Log;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.log.TraceLog.TraceLog;
+import com.sckw.slope.detection.model.param.OriginalDeviceQuery;
 import com.sckw.slope.detection.model.param.ProjectLogQuery;
 import com.sckw.slope.detection.service.LogService;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.validation.Valid;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
  * @author lfdc
@@ -43,9 +48,10 @@ public class LogController {
     }
 
 
-    @Log(description = "日志查询-元数据日志")
-    @RequestMapping(name = "日志查询-元数据日志", value = "/selectMetadata", method = RequestMethod.GET)
-    public HttpResult selectMetadata(@RequestParam(("page")) Integer page , @RequestParam("pageSize") Integer pageSize, HttpServletRequest request) {
-        return HttpResult.ok(logService.selectMetadata(page,pageSize,request));
+//    @Log(description = "日志查询-元数据日志")
+    @TraceLog(description = "日志查询-元数据日志")
+    @RequestMapping(name = "日志查询-元数据日志", value = "/selectMetadata", method = RequestMethod.POST)
+    public HttpResult selectMetadata(@Valid @RequestBody OriginalDeviceQuery query , HttpServletRequest request) {
+        return HttpResult.ok(logService.selectMetadata(query,request));
     }
 }

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

@@ -12,6 +12,7 @@ import com.sckw.slope.detection.model.vo.DeviceVo;
 import com.sckw.slope.detection.model.param.DeviceQuery;
 
 import java.util.List;
+import java.util.Map;
 
 @Mapper
 @DS("mysql")
@@ -26,10 +27,22 @@ public interface KwsDeviceMapper extends BaseMapper<KwsDevice> {
 
     int updateByPrimaryKey(KwsDevice record);
 
+    /**
+     * 查询项目中未绑定设备关联关系的设备
+     *
+     * @param projectId
+     * @return
+     */
     List<DeviceDataDTO> selectDeviceAllNotDeviceRelation(@Param("projectId") String projectId);
 
     List<DeviceVo> selectByDeviceParam(@Param("deviceQuery") DeviceQuery deviceQuery);
 
+    /**
+     * 查询项目绑定的设备
+     *
+     * @param projectId
+     * @return
+     */
     List<AffiliationDeviceVO> selectDeviceAllAndProjectData(@Param("projectId") String projectId);
 
     List<ThresholdSelectDTO> selectDeviceAllByProjectAndMountainId(@Param("projectId") String projectId, @Param("mountainId") String mountainId, @Param("status") List<Integer> status);
@@ -37,4 +50,6 @@ public interface KwsDeviceMapper extends BaseMapper<KwsDevice> {
     int selectCountByProject(@Param("projectId") String projectId);
 
     int selectDeviceOnlineRateCountByProject(@Param("projectId") String projectId);
+
+    List<Map<String, String>> selectListByModelType(@Param("modelType") String modelType);
 }

+ 7 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/tdengine/OriginalMapper.java

@@ -3,15 +3,22 @@ package com.sckw.slope.detection.dao.tdengine;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sckw.slope.detection.model.dos.tdengine.Original;
+import com.sckw.slope.detection.model.vo.OriginalDeviceVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.Date;
+import java.util.List;
 
 @DS("td")
 @Mapper
 @Repository
 public interface OriginalMapper extends BaseMapper<Original> {
+
     Original selectByData(@Param("rawTs") Date rawTs);
+
+    List<OriginalDeviceVO> selectListLimit(@Param("newPage") Integer newPage, @Param("pageSize") Integer pageSize, @Param("deviceSn") String deviceSn);
+
+    int selectDataCount(@Param("deviceSn") String deviceSn);
 }

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

@@ -37,6 +37,8 @@ public class KwsDevice implements Serializable {
      */
     private String snCode;
 
+    private String snCodeFullName;
+
     /**
      * 设备型号id
      */

+ 2 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/tdengine/Original.java

@@ -1,6 +1,7 @@
 package com.sckw.slope.detection.model.dos.tdengine;
 
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -13,6 +14,7 @@ import java.util.Date;
 @TableName("original")
 public class Original implements Serializable {
 
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date ts;
 
     private String rawStr;

+ 30 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/OriginalDeviceQuery.java

@@ -0,0 +1,30 @@
+package com.sckw.slope.detection.model.param;
+
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author lfdc
+ * @description
+ * @date 2023-11-22 16:11:37
+ */
+@Data
+public class OriginalDeviceQuery implements Serializable {
+
+//    @NotBlank(message = "设备型号id不能为空")
+    private String deviceModelId;
+
+    @NotBlank(message = "设备id不能为空")
+    private String deviceId;
+
+    private String deviceName;
+
+    @NotNull(message = "当页不能为空")
+    private int page;
+
+    @NotNull(message = "每页条数不能为空")
+    private int pageSize;
+}

+ 40 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/ProjectAndModelAndDeviceQuery.java

@@ -0,0 +1,40 @@
+package com.sckw.slope.detection.model.param;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author lfdc
+ * @description 分页查询项目dto
+ * @date 2023-10-30 13:10:38
+ */
+@Data
+public class ProjectAndModelAndDeviceQuery implements Serializable {
+
+    /**
+     * 项目id
+     */
+    private String projectId;
+
+    /**
+     * 设备型号id
+     */
+    private String deviceModelId;
+
+    /**
+     * 设备id
+     */
+    private String deviceId;
+
+    /**
+     * 项目名称
+     */
+    private String name;
+
+//    @NotNull(message = "当前页不能为空")
+    private int page;
+
+//    @NotNull(message = "每页条数不能为空")
+    private int pageSize;
+}

+ 5 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/ProjectQuery.java

@@ -13,6 +13,11 @@ import java.io.Serializable;
 public class ProjectQuery implements Serializable {
 
 
+    /**
+     * 项目id
+     */
+    private String projectId;
+
     /**
      * 项目名称
      */

+ 28 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/OriginalDeviceVO.java

@@ -0,0 +1,28 @@
+package com.sckw.slope.detection.model.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author lfdc
+ * @description 元数据设备数据
+ * @date 2023-11-22 16:11:36
+ */
+@Data
+public class OriginalDeviceVO implements Serializable {
+
+    private String deviceId;
+
+    private String deviceName;
+
+    private String guid;
+
+    private String jsonText;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date ts;
+
+}

+ 18 - 9
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceModelService.java

@@ -1,6 +1,5 @@
 package com.sckw.slope.detection.service;
 
-import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.github.pagehelper.PageHelper;
@@ -10,27 +9,23 @@ import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.DeviceEnum;
 import com.sckw.core.model.enums.DictEnum;
-import com.sckw.core.model.page.PageRes;
-import com.sckw.core.model.enums.IntegrationStatusEnum;
 import com.sckw.core.model.enums.MessageLogEnum;
-import com.sckw.core.utils.StringUtils;
-import com.sckw.core.web.response.HttpResult;
+import com.sckw.core.model.page.PageRes;
 import com.sckw.core.web.constant.HttpStatus;
+import com.sckw.core.web.response.HttpResult;
 import com.sckw.slope.detection.dao.mysql.KwsDeviceModelMapper;
 import com.sckw.slope.detection.dao.mysql.KwsDeviceModelPartMapper;
 import com.sckw.slope.detection.dao.mysql.KwsIntegrationMapper;
-import com.sckw.slope.detection.model.dos.mysql.*;
+import com.sckw.slope.detection.model.dos.mysql.KwsDeviceModel;
 import com.sckw.slope.detection.model.dto.HeaderData;
+import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.model.param.DeviceModelAdd;
 import com.sckw.slope.detection.model.param.DeviceModelQuery;
 import com.sckw.slope.detection.model.vo.DeviceModelVo;
-import com.sckw.slope.detection.model.dos.mysql.KwsDeviceModelPart;
-import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.model.vo.DevicePartModelVo;
 import com.sckw.slope.detection.model.vo.IntegrationItemVO;
 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;
@@ -222,4 +217,18 @@ public class DeviceModelService {
         commonService.insertLog(MessageLogEnum.MODEL_DELETE, headerData, logMap, Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok("删除型号成功");
     }
+
+    /**
+     * 查询设备型号数据
+     * @param request
+     * @return
+     */
+    public HttpResult findModelList( HttpServletRequest request) {
+        List<KwsDeviceModel> kwsDeviceModels = kwsDeviceModelMapper.selectList(new LambdaQueryWrapper<KwsDeviceModel>()
+                .eq(KwsDeviceModel::getDelFlag, NumberConstant.ZERO)
+                .orderByDesc(KwsDeviceModel::getCreateTime)
+        );
+        return HttpResult.ok(kwsDeviceModels);
+    }
+
 }

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

@@ -27,9 +27,7 @@ import com.sckw.slope.detection.model.dos.mysql.*;
 import com.sckw.slope.detection.model.dos.tdengine.InsTables;
 import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.dto.*;
-import com.sckw.slope.detection.model.param.DeviceAdd;
-import com.sckw.slope.detection.model.param.DeviceQuery;
-import com.sckw.slope.detection.model.param.DeviceReferenceAdd;
+import com.sckw.slope.detection.model.param.*;
 import com.sckw.slope.detection.model.vo.*;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
@@ -182,7 +180,7 @@ public class DeviceService {
                     .last("LIMIT 1")
                     .orderByDesc(KwsDeviceReference::getId)
             );
-            if(!Objects.isNull(deviceHas)){
+            if (!Objects.isNull(deviceHas)) {
                 vo.setChangeBy(deviceHas.getCreateBy());
                 vo.setChangeTime(deviceHas.getCreateTime());
             }
@@ -287,19 +285,19 @@ public class DeviceService {
                     }
                 }
                 references.forEach(re -> {
-                        if (part.getPartName().equals(re.getItem())) {
-                            SlopeData slopeData = slopeDataMapper.selectListByLine(snCode, re.getItem());//获取到当前测量值
-                            part.setPartBaseData(re.getOriginalValue().toString());
-                            part.setPartCurrentBaseData(re.getCurrentValue().toString());
-                            if(!Objects.isNull(slopeData)){
-                                part.setCurrentData(slopeData.getVal());
-                            }
-                            part.setOffset(re.getOffset().toString());
+                    if (part.getPartName().equals(re.getItem())) {
+                        SlopeData slopeData = slopeDataMapper.selectListByLine(snCode, re.getItem());//获取到当前测量值
+                        part.setPartBaseData(re.getOriginalValue().toString());
+                        part.setPartCurrentBaseData(re.getCurrentValue().toString());
+                        if (!Objects.isNull(slopeData)) {
+                            part.setCurrentData(slopeData.getVal());
                         }
+                        part.setOffset(re.getOffset().toString());
+                    }
                 });
             }
             //获取字典
-            Map<String, SystemDict>  deviceType= commonService.getDictList(null, new HashMap<>() {{
+            Map<String, SystemDict> deviceType = commonService.getDictList(null, new HashMap<>() {{
                 put("code", DictEnum.DEVICE_TYPE.getCodeType());
                 put("type", "1");
             }});
@@ -313,7 +311,7 @@ public class DeviceService {
                     .eq(KwsProjectDevice::getDeviceId, vo.getId())
                     .eq(KwsProjectDevice::getDelFlag, NumberConstant.ZERO)
             );
-            if(!Objects.isNull(projectDevice)){
+            if (!Objects.isNull(projectDevice)) {
                 vo.setProjectId(projectDevice.getProjectId().toString());
             }
             vo.setPart(partData);
@@ -493,7 +491,7 @@ public class DeviceService {
                     put("code", DictEnum.MODEL_PART.getCodeType());
                     put("type", "1");
                 }});
-                String itemName = dictList == null ? item : (dictList.get(item)==null?item:dictList.get(item).getLabel());
+                String itemName = dictList == null ? item : (dictList.get(item) == null ? item : dictList.get(item).getLabel());
                 BigDecimal originalValue = re.getOriginalValue();
                 BigDecimal currentValue = re.getCurrentValue();
                 BigDecimal offset = re.getOffset();
@@ -514,7 +512,7 @@ public class DeviceService {
                 try {
                     slopeData = slopeDataMapper.selectListByLine(snCode, item);
                 } catch (Exception e) {
-                    log.error("select tdengine devices error :{}",e.getMessage(),e);
+                    log.error("select tdengine devices error :{}", e.getMessage(), e);
                 }
                 String val = slopeData == null ? null : slopeData.getVal();
                 //存在经度纬度海拔等要素 要进行公式计算
@@ -534,7 +532,7 @@ public class DeviceService {
                         try {
                             selected = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.LATITUDE_Y.getValue());
                         } catch (Exception e) {
-                            log.error("select tdengine devices error :{}",e.getMessage(),e);
+                            log.error("select tdengine devices error :{}", e.getMessage(), e);
                         }
                         double angleInRadians = Math.toRadians(selected == null ? 0L : Double.parseDouble(selected.getVal()));
                         double cosValue = Math.cos(angleInRadians);
@@ -688,13 +686,13 @@ public class DeviceService {
                 //BigDecimal offset = value.subtract(reference.getValue());
                 kwsDeviceReference.setOriginalValue(reference.getOriginalValue());//原始基准不变
                 //调整经纬度
-                if(type.equals(String.valueOf(NumberConstant.ONE))){
+                if (type.equals(String.valueOf(NumberConstant.ONE))) {
                     BigDecimal offset = commonService.computeOffset(value.toString(), obj.get("item").toString(), reference);
                     kwsDeviceReference.setOffset(offset);//当前位置-上一次的位置的距离的距离
                     kwsDeviceReference.setCurrentValue(value);
                     kwsDeviceReference.setValue(reference.getCurrentValue());
 
-                }else{
+                } else {
                     BigDecimal currentValue = commonService.getValueByOffset(value.toString(), obj.get("item").toString(), reference);
                     kwsDeviceReference.setValue(reference.getCurrentValue());
                     kwsDeviceReference.setOffset(value);
@@ -741,4 +739,24 @@ public class DeviceService {
         jsonObject.put("integrationItem", integrationItem);
         return HttpResult.ok(jsonObject);
     }
+
+    /**
+     * 查询设备型号数据
+     *
+     * @param query
+     * @param request
+     * @return
+     */
+    public HttpResult findProjectAndModelAndDeviceList(ProjectAndModelAndDeviceQuery query, HttpServletRequest request) {
+        List<KwsDeviceModel> kwsDeviceModels = deviceModelMapper.selectList(new LambdaQueryWrapper<KwsDeviceModel>()
+                .eq(KwsDeviceModel::getDelFlag, NumberConstant.ZERO)
+                .eq(KwsDeviceModel::getStatus, NumberConstant.ZERO)
+        );
+        return HttpResult.ok(kwsDeviceModels);
+    }
+
+    public HttpResult findDeviceListByModelType(String modelType, HttpServletRequest request) {
+        List<Map<String, String>> map = deviceMapper.selectListByModelType(modelType);
+        return HttpResult.ok(map);
+    }
 }

+ 57 - 18
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/LogService.java

@@ -5,17 +5,18 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.page.PageRes;
-import com.sckw.core.model.page.PageResult;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.slope.detection.dao.mysql.KwsDeviceMapper;
 import com.sckw.slope.detection.dao.mysql.KwsLogMapper;
 import com.sckw.slope.detection.dao.tdengine.DevicesMapper;
 import com.sckw.slope.detection.dao.tdengine.OriginalMapper;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
+import com.sckw.slope.detection.model.dos.mysql.KwsDevice;
 import com.sckw.slope.detection.model.dos.mysql.KwsLog;
-import com.sckw.slope.detection.model.dos.tdengine.Original;
+import com.sckw.slope.detection.model.param.OriginalDeviceQuery;
 import com.sckw.slope.detection.model.param.ProjectLogQuery;
 import com.sckw.slope.detection.model.vo.LogSelectVO;
-import com.sckw.slope.detection.model.vo.SlopeDataVo;
+import com.sckw.slope.detection.model.vo.OriginalDeviceVO;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -24,7 +25,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -39,6 +43,9 @@ public class LogService {
     @Autowired
     KwsLogMapper logMapper;
 
+    @Autowired
+    KwsDeviceMapper deviceMapper;
+
     @Autowired
     SlopeDataMapper slopeDataMapper;
 
@@ -86,21 +93,53 @@ public class LogService {
     @Autowired
     OriginalMapper originalMapper;
 
-    public PageResult selectMetadata(Integer page, Integer pageSize, HttpServletRequest request) {
-        Integer newPage = (page - 1) * pageSize;
-        List<SlopeDataVo> list = slopeDataMapper.selectListByMaster(newPage, pageSize);
-        List<SlopeDataVo> listByMasterCount = slopeDataMapper.selectListByMasterCount(newPage, pageSize);
-        Long count = 0L;
-        if (!CollectionUtils.isEmpty(listByMasterCount)) {
-            count = listByMasterCount.stream().count();
+//    public PageResult selectMetadata(Integer page, Integer pageSize, HttpServletRequest request) {
+//        Integer newPage = (page - 1) * pageSize;
+//        List<SlopeDataVo> list = slopeDataMapper.selectListByMaster(newPage, pageSize);
+//        List<SlopeDataVo> listByMasterCount = slopeDataMapper.selectListByMasterCount(newPage, pageSize);
+//        Long count = 0L;
+//        if (!CollectionUtils.isEmpty(listByMasterCount)) {
+//            count = listByMasterCount.stream().count();
+//        }
+//        if (!CollectionUtils.isEmpty(list)) {
+//            for (SlopeDataVo slopeDataVo : listByMasterCount) {
+//                Date rawId = slopeDataVo.getRawId();
+//                Original original = originalMapper.selectByData(rawId);
+//            }
+//        }
+//        PageResult build = PageResult.build(page, pageSize, count, list);
+//        return build;
+//    }
+
+    public PageRes selectMetadata(OriginalDeviceQuery query, HttpServletRequest request) {
+        List<OriginalDeviceVO> original = new ArrayList<>();
+        PageInfo<OriginalDeviceVO> info = new PageInfo<>(original);
+        Integer newPage = (query.getPage() - 1) * query.getPageSize();
+        String deviceId = query.getDeviceId();
+        KwsDevice kwsDevice = deviceMapper.selectByPrimaryKey(Long.parseLong(deviceId));
+        String deviceSn = kwsDevice == null ? null : kwsDevice.getSnCode();
+        if (StringUtils.isBlank(deviceSn)) {
+            return PageRes.build(info, original);
         }
-        if (!CollectionUtils.isEmpty(list)) {
-            for (SlopeDataVo slopeDataVo : listByMasterCount) {
-                Date rawId = slopeDataVo.getRawId();
-                Original original = originalMapper.selectByData(rawId);
-            }
+        int count = 0;
+        try {
+            original = originalMapper.selectListLimit(newPage, query.getPageSize(), deviceSn);
+            count = originalMapper.selectDataCount(deviceSn);
+        } catch (Exception e) {
+            log.error("select original error :{}", e.getMessage(), e);
         }
-        PageResult build = PageResult.build(page, pageSize, count, list);
-        return build;
+        if (CollectionUtils.isEmpty(original)) {
+            return PageRes.build(info, original);
+        }
+        original.forEach(originalDeviceVO -> {
+            originalDeviceVO.setDeviceId(kwsDevice.getId().toString());
+            originalDeviceVO.setDeviceName(kwsDevice.getName());
+        });
+        info.setPageNum(query.getPage());
+        info.setPageSize(query.getPageSize());
+        info.setTotal(count);
+        int totalPages = (int) Math.ceil((double) count / query.getPageSize());
+        info.setPages(totalPages);
+        return PageRes.build(info, original);
     }
 }

+ 17 - 1
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml

@@ -9,6 +9,7 @@
     <result column="name" jdbcType="VARCHAR" property="name" />
     <result column="alias" jdbcType="VARCHAR" property="alias" />
     <result column="sn_code" jdbcType="VARCHAR" property="snCode" />
+    <result column="sn_code_fullname" jdbcType="VARCHAR" property="snCodeFullName" />
     <result column="model_id" jdbcType="BIGINT" property="modelId" />
     <result column="mountain_id" jdbcType="VARCHAR" property="mountainId" />
     <result column="valid_time" jdbcType="TIMESTAMP" property="validTime" />
@@ -27,7 +28,7 @@
   </resultMap>
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
-    id, `attribute`, `name`, `alias`, sn_code, model_id, valid_time, secret_key, inter_face,relevance_level,
+    id, `attribute`, `name`, `alias`, sn_code, model_id, valid_time, secret_key, inter_face,relevance_level,sn_code_fullname,
     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">
@@ -363,4 +364,19 @@
           and a.id=#{projectId}
       </if>
     </select>
+
+  <select id="selectListByModelType" resultType="java.util.Map">
+      SELECT b.id          as deviceId,
+             b.name        as deviceName,
+             c.id          as deviceModelId,
+             c.`name`      as deviceModelName,
+             c.device_type as deviceType
+      FROM kws_device b
+               LEFT JOIN kws_device_model c ON b.model_id = c.id
+      WHERE b.del_flag = 0
+        and c.del_flag = 0
+      <if test="modelType != null and modelType != ''">
+          and c.device_type = #{modelType}
+      </if>
+  </select>
 </mapper>

+ 13 - 0
slope-modules/slope-detection/src/main/resources/mapper/tdengine/OriginalMapper.xml

@@ -85,4 +85,17 @@
       FROM devicesv2.original_${deviceCode}
       order by ts desc limit 1
     </select>
+
+  <select id="selectListLimit" resultType="com.sckw.slope.detection.model.vo.OriginalDeviceVO">
+      SELECT raw_str as jsonText,
+             guid,
+             ts
+      from devicesv2.original_${deviceSn}
+      order by ts desc limit #{newPage}, #{pageSize}
+  </select>
+
+  <select id="selectDataCount" resultType="java.lang.Integer">
+      SELECT count(ts)
+      from devicesv2.original_${deviceSn}
+    </select>
 </mapper>