|
@@ -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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|