15928045575 2 lat temu
rodzic
commit
7c37fdaaad

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

@@ -51,7 +51,7 @@ public class DeviceController {
     @Log(description = "设备查询-分页")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "设备查询-分页", value = "/select", method = RequestMethod.POST)
-    public HttpResult select(@Valid @RequestBody DeviceQuery deviceQuery, HttpResponse request) {
+    public HttpResult select(@Valid @RequestBody DeviceQuery deviceQuery, HttpServletRequest request) {
         log.info("设备查询 select param:{}", JSONObject.toJSONString(deviceQuery));
         return HttpResult.ok(deviceService.select(deviceQuery, request));
     }

+ 69 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/backTrackController.java

@@ -0,0 +1,69 @@
+package com.sckw.slope.detection.controller;
+
+import cn.hutool.core.date.DateTime;
+import com.alibaba.fastjson2.JSONObject;
+import com.sckw.core.annotation.Log;
+import com.sckw.core.web.response.HttpResult;
+
+import com.sckw.slope.detection.model.param.DeviceQuery;
+import com.sckw.slope.detection.model.param.IntegrationQuery;
+import com.sckw.slope.detection.service.BackTrackService;
+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.*;
+
+/**
+ * @author s'k'y
+ * @description 数据回溯controller
+ * @date 2023-10-30 17:10:24
+ */
+@Slf4j
+@RestController
+@RequestMapping("/backtrack")
+public class backTrackController {
+
+    @Autowired
+    BackTrackService backTrackService;
+
+
+    @Log(description = "项目所属要素")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "项目所属要素", value = "/getParts", method = RequestMethod.GET)
+    public HttpResult deviceAll(@RequestParam("projectId") String projectId) {
+        log.info("项目所属要素 getParts param :{}",projectId);
+        return backTrackService.getParts(projectId);
+    }
+
+    @Log(description = "返回要素所属于的设备")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "返回要素所属于的设备", value = "/getDeviceByParts", method = RequestMethod.GET)
+    public HttpResult getDeviceByParts(@RequestParam("parts") String parts) {
+        log.info("返回要素所属于的设备 getDeviceByParts param :{}",parts);
+        return backTrackService.getDeviceByParts(parts);
+    }
+
+    @Log(description = "返回设备折线图")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "返回设备折线图", value = "/getDeviceChart", method = RequestMethod.GET)
+    public HttpResult getDeviceChart(@RequestParam("deviceId") String deviceId,@RequestParam("snCode") String snCode, @RequestParam("part") String part, @RequestParam("dateStart") String dateStart, @RequestParam("dateEnd") String dateEnd) {
+        log.info("返回设备折线图 getDeviceChart param :{},part:{}",deviceId,part);
+        return backTrackService.getDeviceChart(deviceId,snCode,part,dateStart,dateEnd);
+    }
+
+
+    @Log(description = "集成分析列表")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "集成分析列表", value = "/getIntegrationList", method = RequestMethod.POST)
+    public HttpResult select(@Valid @RequestBody IntegrationQuery integrationQuery, HttpServletRequest request) {
+        log.info("集成分析列表 select param:{}", JSONObject.toJSONString(integrationQuery));
+        return HttpResult.ok(backTrackService.getIntegrationList(integrationQuery, request));
+    }
+
+
+
+}

+ 1 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsDeviceReferenceMapper.java

@@ -28,4 +28,5 @@ public interface KwsDeviceReferenceMapper extends BaseMapper<KwsDeviceReference>
     int updateByPrimaryKey(KwsDeviceReference record);
 
     List<DeviceReferenceVo>  selectByDeviceId(@Param("vo") DeviceVo vo);
+
 }

+ 6 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsIntegrationMapper.java

@@ -3,8 +3,12 @@ package com.sckw.slope.detection.dao.mysql;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sckw.slope.detection.model.dos.mysql.KwsIntegration;
+import com.sckw.slope.detection.model.param.DeviceQuery;
+import com.sckw.slope.detection.model.param.IntegrationQuery;
 import com.sckw.slope.detection.model.vo.IntegrationItemVO;
+import com.sckw.slope.detection.model.vo.IntegrationVo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -24,4 +28,6 @@ public interface KwsIntegrationMapper extends BaseMapper<KwsIntegration> {
     int updateByPrimaryKey(KwsIntegration record);
 
     List<IntegrationItemVO> getDataByFindInSet(String partNames);
+
+    List<IntegrationVo> getDataByName(@Param("integrationQuery") IntegrationQuery integrationQuery);
 }

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

@@ -20,6 +20,11 @@ public class DeviceQuery {
      */
     private String projectName;
 
+    /**
+     * MountainId
+     */
+    private String mountainId;
+
     /**
      * 项目id
      */

+ 32 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/IntegrationQuery.java

@@ -0,0 +1,32 @@
+package com.sckw.slope.detection.model.param;
+
+import lombok.Data;
+
+/**
+ * @author sky
+ * @description 集成分析列表
+ * @date 2023-10-31 15:10:14
+ */
+@Data
+public class IntegrationQuery {
+
+    /**
+     * MountainId
+     */
+    private String mountainId;
+
+
+
+    /**
+     * 集成分析方案名
+     */
+    private String integrationName;
+
+
+
+    private int page;
+
+    private int pageSize;
+
+
+}

+ 82 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/IntegrationVo.java

@@ -0,0 +1,82 @@
+package com.sckw.slope.detection.model.vo;
+
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author lfdc
+ * @description vo
+ * @date 2023-10-30 13:10:38
+ */
+@Data
+public class IntegrationVo implements Serializable {
+    private Long id;
+
+    /**
+     * 集成分析方案名(字典value)
+     */
+    private String integrationName;
+
+    /**
+     * 企业id
+     */
+    private String mountainId;
+
+    /**
+     * 要素名称字符串
+     */
+    private String partNames;
+
+    /**
+     * 单位(字典value)
+     */
+    private String unit;
+
+    /**
+     * 公式(字典value)
+     */
+    private String formula;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+    /**
+     * 状态
+     */
+    private Byte status;
+
+    /**
+     * 创建人
+     */
+    private Long createBy;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 修改人
+     */
+    private Long updateBy;
+
+    /**
+     * 修改时间
+     */
+    private Date updateTime;
+
+    /**
+     * 删除标识
+     */
+    private Byte delFlag;
+
+    private static final long serialVersionUID = 1L;
+}

+ 204 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/BackTrackService.java

@@ -0,0 +1,204 @@
+package com.sckw.slope.detection.service;
+import cn.hutool.core.date.DateTime;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.sckw.core.exception.BusinessException;
+import com.sckw.core.exception.SystemException;
+import com.sckw.core.model.constant.Global;
+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.enums.DictItemEnum;
+import com.sckw.core.model.enums.MessageLogEnum;
+import com.sckw.core.model.page.PageRes;
+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;
+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.IntegrationQuery;
+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;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author sky
+ * @description 数据回溯service
+ * @date 2023-10-31 10:10:27
+ */
+@Slf4j
+@Service
+public class BackTrackService {
+
+    private static final Long equatorial_circumference = 40075020000L;
+
+    @Autowired
+    CommonService commonService;
+
+    @Autowired
+    KwsDeviceMapper deviceMapper;
+
+    @Autowired
+    KwsProjectMapper projectMapper;
+
+    @Autowired
+    KwsDeviceReferenceMapper deviceReferenceMapper;
+
+    @Autowired
+    KwsThresholdMapper thresholdMapper;
+
+    @Autowired
+    SlopeDataMapper slopeDataMapper;
+
+    @Autowired
+    KwsIntegrationMapper integrationMapper;
+
+
+
+    public HttpResult getParts(String projectId) {
+        //首先获取项目中全部设备
+        List<DeviceDataDTO> list = deviceMapper.selectDeviceAllNotDeviceRelation(projectId);
+        List<String> devicesId = list.stream().map(DeviceDataDTO::getDeviceId).toList();
+        //在获取设备的要素
+        List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
+                .in(KwsDeviceReference::getDeviceId, devicesId)
+                .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
+        );
+        return HttpResult.ok(references);
+    }
+
+    public HttpResult getDeviceByParts(String parts) {
+        //在获取设备的要素
+        String[] arr = parts.split(",");
+        List<String> list = Arrays.asList(arr);
+        List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
+                .in(KwsDeviceReference::getId, list)
+                .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
+        );
+        //获取对应的设备
+        List<Long> devicesId = references.stream().map(KwsDeviceReference::getDeviceId).toList();
+
+        List<KwsDevice> devices = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
+                .in(KwsDevice::getId, devicesId)
+                .eq(KwsDevice::getDelFlag, NumberConstant.ZERO)
+        );
+        return HttpResult.ok(devices);
+    }
+
+    public HttpResult getDeviceChart(String devicesId,String snCode, String parts, String dateStart,String dateEnd) {
+        Map<String, Object> returnData = new HashMap<>();
+        //在获取设备的要素
+        List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
+                .eq(KwsDeviceReference::getDeviceId, devicesId)
+                .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
+        );
+        //获取基准值的纬度,X轴偏移量需要
+        double angleInRadians = 0;
+        for(KwsDeviceReference element : references) {
+            if (DictItemEnum.LATITUDE_Y.getValue().equals(element.getItem())) {
+                angleInRadians = element.getValue().doubleValue();
+            }
+        }
+
+        //获取设备的全部阈值
+        List<KwsThreshold> kwsThresholds = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
+                .eq(KwsThreshold::getDelFlag, 0)
+                .eq(KwsThreshold::getDeviceId, devicesId)
+        );
+
+        //获取偏移量
+        Map<String, Object> mapList = new HashMap<>();
+        for(KwsDeviceReference element : references) {
+            if(!parts.isEmpty() && !parts.contains(element.getItem())){
+                continue;
+            }
+            BigDecimal currentValue = element.getCurrentValue();//当前要素的基准值
+
+            BigDecimal offsetValue = new BigDecimal("0.00");
+            Map<String, Object> datemap = new HashMap<>();
+            Date date = new Date();
+            List<SlopeData> selected = slopeDataMapper.selectLineList(snCode, element.getItem(), dateStart, dateEnd);
+            if(!Objects.isNull((selected))) {
+                for (SlopeData message : selected) {
+                    String line = message.getLine();
+                    String val1 = message.getVal();
+                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH");
+                    String key = format.format(message.getTs());
+                    BigDecimal subtract = new BigDecimal(val1).subtract(currentValue);
+                    if (DictItemEnum.LONGITUDE_X.getValue().equals(element.getItem())) {//如果是X轴
+                        double cosValue = Math.cos(angleInRadians);
+                        double doubleValue = subtract.divide(new BigDecimal("360"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
+                        offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
+                    }else if (DictItemEnum.LATITUDE_Y.getValue().equals(element.getItem())) {//如果是Y轴
+                        offsetValue = new BigDecimal(equatorial_circumference).multiply(subtract);
+                    } else if (DictItemEnum.ALTITUDE_Z.getValue().equals(element.getItem())) {//如果是z轴
+                        offsetValue = new BigDecimal(val1).divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
+                    }else{//如果是其他
+                        offsetValue = subtract;
+                    }
+                    datemap.put(key, offsetValue);
+                }
+                mapList.put(element.getItem(), datemap);
+            }
+        }
+        returnData.put("references",references);
+        returnData.put("threshold",kwsThresholds);
+        returnData.put("chart",mapList);
+        return HttpResult.ok(returnData);
+    }
+
+
+    /**
+     * 集成分析列表
+     *
+     * @param integrationQuery 请求分页
+     * @param response    http流
+     * @return 返回值
+     */
+    public PageRes getIntegrationList(IntegrationQuery integrationQuery, HttpServletRequest response) {
+        PageHelper.startPage(integrationQuery.getPage(), integrationQuery.getPageSize());
+        HeaderData headerData = commonService.getHeaderData(response);
+        integrationQuery.setMountainId(headerData.getCompanyId());
+        List<IntegrationVo> list = integrationMapper.getDataByName(integrationQuery);
+        PageInfo<IntegrationVo> pageInfo = new PageInfo<>(list);
+        if (CollectionUtils.isEmpty(list)) {
+            return PageRes.build(pageInfo, list);
+        }
+
+        return PageRes.build(pageInfo, list);
+    }
+
+
+
+
+
+
+
+}

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

@@ -121,8 +121,10 @@ public class DeviceService {
      * @param response    http流
      * @return 返回值
      */
-    public PageRes select(DeviceQuery deviceQuery, HttpResponse response) {
+    public PageRes select(DeviceQuery deviceQuery, HttpServletRequest response) {
         PageHelper.startPage(deviceQuery.getPage(), deviceQuery.getPageSize());
+        HeaderData headerData = commonService.getHeaderData(response);
+        deviceQuery.setMountainId(headerData.getCompanyId());
         List<DeviceVo> list = deviceMapper.selectByDeviceParam(deviceQuery);
         PageInfo<DeviceVo> pageInfo = new PageInfo<>(list);
         if (CollectionUtils.isEmpty(list)) {

+ 11 - 1
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsIntegrationMapper.xml

@@ -37,7 +37,17 @@
     from kws_integration
     where FIND_IN_SET(#{partNames,jdbcType=VARCHAR},part_names)
   </select>
-  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+    <select id="getDataByName" resultType="com.sckw.slope.detection.model.vo.IntegrationVo">
+      <!--@mbg.generated-->
+      select
+      <include refid="Base_Column_List" />
+      from kws_integration
+      where del_flag=0
+      <if test="integrationQuery.integrationName != null and integrationQuery.integrationName != ''">
+        and integration_name like concat('%', #{integrationQuery.integrationName}, '%')
+      </if>
+    </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
     <!--@mbg.generated-->
     delete from kws_integration
     where id = #{id,jdbcType=BIGINT}

+ 2 - 6
slope-modules/slope-detection/src/main/resources/mapper/tdengine/SlopeDataMapper.xml

@@ -33,13 +33,9 @@
 
     <sql id="Base_List">
         ts,
-        raw_id      as rawId,
         tslver_id   as tslverId,
-        guid,
         line,
-        val,
-        json_text   as jsonText,
-        create_time as createTime
+        val
     </sql>
     <select id="selectListByLine" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
         SELECT
@@ -73,7 +69,7 @@
         SELECT
         <include refid="Base_List">
         </include>
-        FROM devices.slope_data_#{snCode}
+        FROM devicesv2.device_#{snCode}
         where line = #{item} and ts &gt;= #{dateStart} and ts &lt;= #{dateEnd} order by ts desc
     </select>