Browse Source

临时提交

wangmiaomiao 10 months ago
parent
commit
41c15671cc

+ 6 - 13
slibra-admin/src/main/java/com/slibra/web/controller/business/FrontController.java

@@ -5,6 +5,8 @@ import com.slibra.business.mapper.TXinyiDailyMapper;
 import com.slibra.business.mapper.TXinyiIndustryMapper;
 import com.slibra.business.mapper.TXinyiNormConfigMapper;
 import com.slibra.business.mapper.TXinyiRobotMapper;
+import com.slibra.business.res.XinyiIndustrySimple;
+import com.slibra.business.service.IFrontService;
 import com.slibra.common.core.controller.BaseController;
 import com.slibra.common.core.domain.AjaxResult;
 import io.grpc.ManagedChannel;
@@ -29,22 +31,13 @@ import java.util.Iterator;
  * 告警相关
  */
 @RestController
-@RequestMapping("/front")
+@RequestMapping("/test")
 @Slf4j
 public class FrontController extends BaseController {
 
 
     @Autowired
-    private TXinyiNormConfigMapper tXinyiNormConfigMapper;
-
-    @Autowired
-    private TXinyiRobotMapper robotMapper;
-
-    @Autowired
-    private TXinyiIndustryMapper industryMapper;
-
-    @Autowired
-    private TXinyiDailyMapper dailyMapper;
+    private IFrontService frontService;
 
 
 
@@ -56,8 +49,8 @@ public class FrontController extends BaseController {
     @GetMapping(value = "/realTimeData")
     public AjaxResult realTimeData()
     {
-        log.info("进入了调⽤大模型决策接口-第一次");
-        return AjaxResult.success("ok");
+        log.info("进入了获取实时工业库数据接口");
+        return AjaxResult.success(frontService.countInfo());
     }
 
 

+ 2 - 0
slibra-common/src/main/java/com/slibra/common/utils/DateUtils.java

@@ -24,6 +24,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
 
     public static String YYYY_MM_DD = "yyyy-MM-dd";
 
+    public static String YYYY_MM_DD_HH = "yyyy-MM-dd HH";
+
     public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
 
     public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

+ 208 - 0
slibra-system/src/main/java/com/slibra/business/res/XinyiIndustrySimple.java

@@ -0,0 +1,208 @@
+package com.slibra.business.res;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.slibra.common.annotation.Excel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+
+@Builder
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class XinyiIndustrySimple {
+
+    /** 化验时间(2023/12/13 5:00:00格式的) */
+    @Excel(name = "化验时间", readConverterExp = "2=023/12/13,5=:00:00格式的")
+    private String testTime;
+
+    //工业库数据
+    /** 进水化学需氧量COD */
+    @Excel(name = "进水化学需氧量COD")
+    private BigDecimal jsCod;
+
+    /** 出水化学需氧量COD */
+    @Excel(name = "出水化学需氧量COD")
+    private BigDecimal csCod;
+
+
+    /** 进水氨氮NH₃-N */
+    @Excel(name = "进水氨氮NH₃-N")
+    private BigDecimal jsNh3;
+
+
+    /** 出水氨氮NH₃-N */
+    @Excel(name = "出水氨氮NH₃-N")
+    private BigDecimal csNh3;
+
+
+    /** 进水总氮TN */
+    @Excel(name = "进水总氮TN")
+    private BigDecimal jsTn;
+
+    /** 出水总氮TN */
+    @Excel(name = "出水总氮TN")
+    private BigDecimal csTn;
+
+    /** 进水总磷TP */
+    @Excel(name = "进水总磷TP")
+    private BigDecimal jsTp;
+
+    /** 出水总磷TP */
+    @Excel(name = "出水总磷TP")
+    private BigDecimal csTp;
+
+    /** 进水悬浮物SS */
+    @Excel(name = "进水悬浮物SS")
+    private BigDecimal jsSs;
+
+    /** 出水悬浮物SS */
+    @Excel(name = "出水悬浮物SS")
+    private BigDecimal csSs;
+
+    /** 进水酸碱度pH */
+    @Excel(name = "进水酸碱度pH")
+    private BigDecimal jsPh;
+
+    /** 出水酸碱度pH */
+    @Excel(name = "出水酸碱度pH")
+    private BigDecimal csPh;
+
+    /** 进水水量Q进 */
+    @Excel(name = "进水水量Q进")
+    private BigDecimal jsSlq;
+
+    /** 出水水量Q出 */
+    @Excel(name = "出水水量Q出")
+    private BigDecimal csSlqc;
+
+
+
+
+
+    //需要计算的
+    /** 瞬时进水环比 */
+    @Excel(name = "瞬时进水环比")
+    private BigDecimal ssJsHb;
+
+    /** 瞬时出水环比 */
+    @Excel(name = "瞬时出水环比")
+    private BigDecimal ssCsHb;
+
+
+
+
+
+    //日报获取
+    /** 出水生化需氧量BOD₅ */
+    @Excel(name = "出水生化需氧量BOD₅")
+    private BigDecimal csBod5;
+
+    /** 进水生化需氧量BOD₅ */
+    @Excel(name = "进水生化需氧量BOD₅")
+    private BigDecimal jsBod5;
+
+    /** 进水水温 */
+    @Excel(name = "进水水温")
+    private BigDecimal jsSw;
+
+    /** 出水水温 */
+    @Excel(name = "出水水温")
+    private BigDecimal csSw;
+
+
+    /** 进水量 */
+    @Excel(name = "昨日总进水量")
+    private BigDecimal zrZJSL;
+
+    /** 出水量 */
+    @Excel(name = "昨日总出水量")
+    private BigDecimal zrZCSL;
+
+
+
+    /** 昨日总进水环比 */
+    @Excel(name = "昨日总进水环比")
+    private BigDecimal zrZJsHb;
+
+    /** 昨日总出水环比 */
+    @Excel(name = "昨日总出水环比")
+    private BigDecimal zrZCsHb;
+
+
+
+    /** 上周总进水平均值 */
+    @Excel(name = "上周总进水平均值")
+    private BigDecimal szZJSAvg;
+
+    /** 上上周总进水平均值 */
+    @Excel(name = "上上周总进水平均值")
+    private BigDecimal sszZJSAvg;
+
+    /** 上周总进水环比 */
+    @Excel(name = "上周总进水环比")
+    private BigDecimal szZJSHb;
+
+
+    //管控制
+    /** 进水COD设计值 */
+    @Excel(name = "进水COD设计值")
+    private BigDecimal jscodSjz;
+
+    /** 出水COD标准值 */
+    @Excel(name = "出水COD标准值")
+    private BigDecimal cscodBzz;
+
+
+    /** 进水氨氮设计值 */
+    @Excel(name = "进水氨氮设计值")
+    private BigDecimal jsadSjz;
+
+    /** 出水氨氮标准值 */
+    @Excel(name = "出水氨氮标准值")
+    private BigDecimal csadBzz;
+
+    /** 进水总氮设计值 */
+    @Excel(name = "进水总氮设计值")
+    private BigDecimal jszdSjz;
+
+    /** 出水总氮标准值 */
+    @Excel(name = "出水总氮标准值")
+    private BigDecimal cszzBzz;
+
+    /** 出水总氮管控值 */
+    @Excel(name = "出水总氮管控值")
+    private BigDecimal cszzGkz;
+
+    /** 进水总磷设计值 */
+    @Excel(name = "进水总磷设计值")
+    private BigDecimal jszlSjz;
+
+    /** 出水总磷标准值 */
+    @Excel(name = "出水总磷标准值")
+    private BigDecimal cszlBzz;
+
+    /** 出水总磷管控值 */
+    @Excel(name = "出水总磷管控值")
+    private BigDecimal cszlGkz;
+
+    /** 进水SS设计值 */
+    @Excel(name = "进水SS设计值")
+    private BigDecimal jsssSjz;
+
+    /** 出水SS标准值 */
+    @Excel(name = "出水SS标准值")
+    private BigDecimal csssBzz;
+
+    /** 出水SS管控值 */
+    @Excel(name = "出水SS管控值")
+    private BigDecimal csssGkz;
+
+
+
+
+}

+ 18 - 0
slibra-system/src/main/java/com/slibra/business/service/IFrontService.java

@@ -0,0 +1,18 @@
+package com.slibra.business.service;
+
+import com.slibra.business.domain.TXinyiDaily;
+import com.slibra.business.res.XinyiIndustrySimple;
+
+import java.util.List;
+
+/**
+ * 信义日报数据Service接口
+ * 
+ * @author slibra
+ * @date 2024-04-13
+ */
+public interface IFrontService
+{
+
+    XinyiIndustrySimple countInfo();
+}

+ 239 - 0
slibra-system/src/main/java/com/slibra/business/service/impl/FrontServiceImpl.java

@@ -0,0 +1,239 @@
+package com.slibra.business.service.impl;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.http.HttpRequest;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.slibra.business.domain.TXinyiDaily;
+import com.slibra.business.domain.TXinyiNormConfig;
+import com.slibra.business.mapper.TXinyiDailyMapper;
+import com.slibra.business.mapper.TXinyiIndustryMapper;
+import com.slibra.business.mapper.TXinyiNormConfigMapper;
+import com.slibra.business.res.XinyiIndustrySimple;
+import com.slibra.business.service.IFrontService;
+import com.slibra.common.utils.DateUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+
+
+@Service
+@Slf4j
+public class FrontServiceImpl implements IFrontService {
+
+    @Autowired
+    private TXinyiIndustryMapper xinyiIndustryMapper;
+
+    @Autowired
+    private TXinyiDailyMapper xinyiDailyMapper;
+
+    @Autowired
+    private TXinyiNormConfigMapper tXinyiNormConfigMapper;
+
+    @Override
+    public XinyiIndustrySimple countInfo() {
+        //查询基本的工业库数据
+        XinyiIndustrySimple xinyiIndustrySimple = new XinyiIndustrySimple();
+        LocalDateTime nowTime =  LocalDateTime.now();
+        //调用接口查询指标
+        String[] queryTags = {"信义污水厂JS_COD_Value", "信义污水厂升级出水COD", "信义污水厂JS_AD_Value", "信义污水厂升级出水氨氮", "信义污水厂JS_ZA_Value", "信义污水厂升级出水TN", "信义污水厂JS_ZL_Value", "信义污水厂升级出水TP", "信义污水厂JS_SS_Value", "信义污水厂升级出水SS", "信义污水厂JS_PH_Value", "信义污水厂升级出水PH", "信义污水厂FT101_Value", "信义污水厂出水瞬时流量"};
+        xinyiIndustrySimple = this.getRealTimeData(queryTags, nowTime);
+        //处理日报数据
+        xinyiIndustrySimple = this.addDailyData(xinyiIndustrySimple, nowTime);
+        //处理配置信息
+        xinyiIndustrySimple = this.addConfigData(xinyiIndustrySimple);
+        //计算
+        xinyiIndustrySimple = this.calculateData(xinyiIndustrySimple);
+        return xinyiIndustrySimple;
+    }
+
+    private XinyiIndustrySimple calculateData(XinyiIndustrySimple xinyiIndustrySimple) {
+        //处理昨日同时期的进水 获取环比
+
+        //通过sql查询上周的平均值和环比情况
+        return  xinyiIndustrySimple;
+    }
+
+    private XinyiIndustrySimple addConfigData(XinyiIndustrySimple xinyiIndustrySimple) {
+        //获取配置表
+        List<TXinyiNormConfig> tXinyiNormConfigs = this.tXinyiNormConfigMapper.selectTXinyiNormConfigList(null);
+        if(!CollectionUtils.isEmpty(tXinyiNormConfigs)){
+            TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0);
+            BeanUtils.copyProperties(normConfig, xinyiIndustrySimple);
+        }
+        return xinyiIndustrySimple;
+    }
+
+    private XinyiIndustrySimple addDailyData(XinyiIndustrySimple xinyiIndustrySimple, LocalDateTime nowDate) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.YYYYMMDD_TS);
+        String nowDateStr = nowDate.format(formatter);
+        String yesterdayStr = nowDate.plusDays(-1).format(formatter);//昨天
+        String beforeYesterdayStr = nowDate.plusDays(-2).format(formatter);//前天
+
+        List<TXinyiDaily> tXinyiDailies = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(nowDateStr).build());
+        if(!CollectionUtils.isEmpty(tXinyiDailies)){
+            TXinyiDaily tXinyiDaily = tXinyiDailies.get(0);
+            BeanUtils.copyProperties(tXinyiDaily, xinyiIndustrySimple);
+        }
+        //昨日数据
+        List<TXinyiDaily> tXinyiDailiesYesterday = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(yesterdayStr).build());
+        if(!CollectionUtils.isEmpty(tXinyiDailiesYesterday)){
+            TXinyiDaily tXinyiDailyYesterday = tXinyiDailiesYesterday.get(0);
+            BigDecimal zrJsl = tXinyiDailyYesterday.getJSL();
+            xinyiIndustrySimple.setZrZJSL(zrJsl);
+            BigDecimal zrCsl = tXinyiDailyYesterday.getCSL();
+            xinyiIndustrySimple.setZrZCSL(zrCsl);
+            //有可能今日获取不到日报数据,相关信息从昨天获取
+            if(CollectionUtils.isEmpty(tXinyiDailies))
+                BeanUtils.copyProperties(tXinyiDailyYesterday, xinyiIndustrySimple);
+            //获取前日数据 并计算环比
+            List<TXinyiDaily> tXinyiDailiesBeforeYesterday = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(beforeYesterdayStr).build());
+            if(!CollectionUtils.isEmpty(tXinyiDailiesBeforeYesterday)){
+                TXinyiDaily tXinyiDailyBeforeYesterday = tXinyiDailiesBeforeYesterday.get(0);
+                BigDecimal qrZJSL = tXinyiDailyBeforeYesterday.getJSL();
+                if(!Objects.isNull(qrZJSL) && !Objects.isNull(zrJsl))
+                    xinyiIndustrySimple.setZrZJsHb((zrJsl.subtract(qrZJSL)).divide(qrZJSL, 4, RoundingMode.HALF_UP));
+                BigDecimal qrZCSL = tXinyiDailyBeforeYesterday.getCSL();
+                if(!Objects.isNull(qrZCSL) && !Objects.isNull(zrCsl))
+                    xinyiIndustrySimple.setZrZCsHb((zrCsl.subtract(qrZCSL)).divide(qrZCSL, 4, RoundingMode.HALF_UP));
+            }
+        }
+
+        return xinyiIndustrySimple;
+    }
+
+    private XinyiIndustrySimple getRealTimeData(String[] queryTags, LocalDateTime nowTime) {
+
+        AtomicReference<XinyiIndustrySimple> result = new AtomicReference<>();
+
+        /*String time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH, DateUtils.getNowDate());
+        time = time + ":00:00";*/
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD_HH_MM_SS);
+
+        //获取当前的时间
+        LocalDateTime beginTime = nowTime.plusMinutes(-1);
+
+        //调用工业库接口
+        String url = "http://10.0.0.27:4568/api/v1/khquerydata";
+        HashMap<String, Object> req = new HashMap<>();
+        req.put("tagNames", queryTags);
+        req.put("startTime", formatter.format(beginTime));
+        req.put("endTime", formatter.format(nowTime));
+        req.put("recordNumbers", 100000);
+        String body = HttpRequest.post(url).header("Authorization", "c2E6c2E=").header("clientName", "hongshan").body(JSON.toJSONString(req)).execute().body();
+//            System.out.println("body = " + body);
+        List<HashMap<String, String>> list = new ArrayList<>();
+
+        //行转列数据处理
+        for (String queryTag : queryTags) {
+            JSONArray array = JSON.parseObject(body).getJSONArray(queryTag);
+            //特殊数据处理一
+            if(Objects.isNull(array) || array.isEmpty()){
+                System.out.println(queryTag + "查询到了空的数据,跳过本次循环");
+                continue;
+            }
+            int size = array.size();
+            //特殊数据处理二
+            if("0".equals(array.get(1) + "")){
+                System.out.println(queryTag + "查询到了数据,但是数据集合只有一条,且都是0");
+                continue;
+            }
+
+            //存放的数据集
+            //利用map去重
+            HashMap<String, String> map = new LinkedHashMap<>();
+            for (int i = 2; i < size; i++) {
+//            System.out.println(i + "" + array.get(i));
+                JSONArray oneRecord = JSON.parseArray(JSON.toJSONString(array.get(i)));
+                //处理为空或者为0的数据
+                Object timeStampValue = oneRecord.get(2);
+                if(Objects.isNull(timeStampValue) || "0".equals(timeStampValue + ""))
+                    continue;
+                BigDecimal value = Objects.isNull(oneRecord.get(0)) ? null : new BigDecimal(oneRecord.get(0) + "");
+                long timestamp = (long) timeStampValue;
+                String format = DateUtil.format(new Date(timestamp), DateUtils.YYYYMMDDHHMM_TS);
+                map.put(format, queryTag + "-" + value);
+            }
+            list.add(map);
+        }
+        Set<String> recordTimeSet = new HashSet<>();
+        Map<String, XinyiIndustrySimple> recordMap = new HashMap<>();
+        for (int i = 0; i < list.size(); i++) {
+            HashMap<String, String> map = list.get(i);
+            int finalJ = i;
+            map.forEach((k, v) ->{
+                XinyiIndustrySimple xinyiIndustrySimple = null;
+                if(!recordTimeSet.contains(k)){//第一次
+                    xinyiIndustrySimple = new XinyiIndustrySimple();
+                    recordTimeSet.add(k);
+                    recordMap.put(k, xinyiIndustrySimple);
+                }else{
+                    xinyiIndustrySimple = recordMap.get(k);
+                }
+                xinyiIndustrySimple.setTestTime(k);
+                //解析值
+                String[] split = v.split("-");
+                String type = split[0];
+                BigDecimal value = new BigDecimal(split[1]);
+                if ("信义污水厂JS_COD_Value".equals(type)) {
+                    xinyiIndustrySimple.setJsCod(value);
+                } else if ("信义污水厂JS_PH_Value".equals(type)) {
+                    xinyiIndustrySimple.setJsPh(value);
+                } else if ("信义污水厂JS_SS_Value".equals(type)) {
+                    xinyiIndustrySimple.setJsSs(value);
+                } else if ("信义污水厂JS_ZL_Value".equals(type)) {
+                    xinyiIndustrySimple.setJsTp(value);
+                } else if ("信义污水厂JS_ZA_Value".equals(type)) {
+                    xinyiIndustrySimple.setJsTn(value);
+                } else if ("信义污水厂JS_AD_Value".equals(type)) {
+                    xinyiIndustrySimple.setJsNh3(value);
+                } else if ("信义污水厂出水瞬时流量".equals(type)) {
+                    xinyiIndustrySimple.setCsSlqc(value);
+                } else if ("信义污水厂升级出水COD".equals(type)) {
+                    xinyiIndustrySimple.setCsCod(value);
+                } else if ("信义污水厂升级出水PH".equals(type)) {
+                    xinyiIndustrySimple.setCsPh(value);
+                } else if ("信义污水厂升级出水SS".equals(type)) {
+                    xinyiIndustrySimple.setCsSs(value);
+                } else if ("信义污水厂升级出水TN".equals(type)) {
+                    xinyiIndustrySimple.setCsTn(value);
+                } else if ("信义污水厂升级出水TP".equals(type)) {
+                    xinyiIndustrySimple.setCsTp(value);
+                } else if ("信义污水厂升级出水氨氮".equals(type)) {
+                    xinyiIndustrySimple.setCsNh3(value);
+                } else if ("信义污水厂FT101_Value".equals(type)) {
+                    xinyiIndustrySimple.setJsSlq(value);
+                }
+                //只有最后一次才执行数据库添加
+                if(finalJ == list.size()-1){
+                    //赋值完毕返回数据
+                    result.set(xinyiIndustrySimple);
+                }
+            });
+        }
+        return Objects.isNull(result) ? new XinyiIndustrySimple() : result.get();
+    }
+
+
+    public static void main(String[] args) {
+        String s = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH, DateUtils.getNowDate());
+        s = s + ":00:00";
+        System.out.println("s = " + s);
+
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+        LocalDateTime endTime =  LocalDateTime.now();
+        LocalDateTime begin = endTime.plusMinutes(-1);
+        System.out.println(formatter.format(endTime));
+        System.out.println(formatter.format(begin));
+    }
+}