Răsfoiți Sursa

工业库新增字段 定时任务新增处理新字段逻辑 新增方法处理工业库的历史字段的值

wangmiaomiao 11 luni în urmă
părinte
comite
f7809396a4

+ 69 - 0
slibra-admin/src/main/java/com/slibra/web/controller/business/DataHandleByHand.java

@@ -0,0 +1,69 @@
+package com.slibra.web.controller.business;
+
+import cn.hutool.http.HttpRequest;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+
+/***
+ *
+ * 手动处处理一些数据
+ *
+ */
+public class DataHandleByHand {
+
+
+    public static void main(String[] args) {
+        testExistsGYKField();
+    }
+
+    /**
+     * 查看工业库的某个值是否存在
+     * 或者某个时间段是否存在
+     */
+    public static void testExistsGYKField() {
+
+        String[] queryTags = {"信义污水厂_除磷P04预测值_"};
+        // 给定时间段的起始时间和结束时间
+        LocalDateTime startTime = LocalDateTime.parse("2024-04-25T00:09:25");
+        LocalDateTime endTime = LocalDateTime.parse("2024-04-25T09:30:00");
+
+        // 每个小时的时间格式
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+        // 循环按小时分割
+        LocalDateTime currentHour = startTime;
+        while (currentHour.isBefore(endTime)) {
+            String begin = currentHour.format(formatter);
+            String end = currentHour.plusMinutes(10).format(formatter);
+            // 输出当前小时的起始时间和结束时间
+            System.out.println("起始时间:" + begin);
+            System.out.println("结束时间:" + end);
+
+            // 当前小时加一小时,作为下一个小时的起始时间
+            currentHour = currentHour.plusMinutes(10);
+
+            //每个小时查询一次数据
+            String url = "http://10.0.0.27:4568/api/v1/khquerydata";
+            HashMap<String, Object> req = new HashMap<>();
+            req.put("tagNames", queryTags);
+            req.put("startTime", begin);
+            req.put("endTime", end);
+            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);
+            //行转列数据处理
+            for (String queryTag : queryTags) {
+                JSONArray array = JSON.parseObject(body).getJSONArray(queryTag);
+                System.out.println(JSON.toJSONString(array));
+            }
+
+        }
+    }
+
+}

+ 117 - 1
slibra-admin/src/main/java/com/slibra/web/controller/business/HandleDataController.java

@@ -492,10 +492,126 @@ public class HandleDataController extends BaseController
     }
 
 
-    //机器人数据表 直接删除,重新同步视图,修改视图的逻辑
 
+    /**
+     * 手动处理 工业库的 某个值,将历史数据全部都更新
+     * @return
+     */
+    @GetMapping("/updateGYKSomeFileds")
+    public String updateGYKSomeFileds() {
+        //更新的某个指标
+        String[] queryTags = {"信义污水厂_除磷P04预测值_"};
+        //找到对应的数据,然后更新它
+        // 给定时间段的起始时间和结束时间
+        LocalDateTime startTime = LocalDateTime.parse("2022-07-01T00:00:00");
+        LocalDateTime endTime = LocalDateTime.parse("2024-04-25T09:00:01");
 
+        // 每个小时的时间格式
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
+        // 循环按小时分割
+        LocalDateTime currentHour = startTime;
+        while (currentHour.isBefore(endTime)) {
+            String begin = currentHour.format(formatter);
+            String end = currentHour.plusDays(1).format(formatter);
+            // 输出当前小时的起始时间和结束时间
+            System.out.println("起始时间:" + begin);
+            System.out.println("结束时间:" + end);
+
+            // 当前小时加一小时,作为下一个小时的起始时间
+            currentHour = currentHour.plusDays(1);
+
+            //每个小时查询一次数据
+            String url = "http://192.168.10.113:4568/api/v1/khquerydata";
+            HashMap<String, Object> req = new HashMap<>();
+            req.put("tagNames", queryTags);
+            req.put("startTime", begin);
+            req.put("endTime", end);
+            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, TXinyiIndustry> 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) ->{
+                    TXinyiIndustry industry = null;
+                    if(!recordTimeSet.contains(k)){//第一次
+                        industry = new TXinyiIndustry();
+                        recordTimeSet.add(k);
+                        recordMap.put(k, industry);
+                    }else{
+                        industry = recordMap.get(k);
+                    }
+                    industry.setTestTime(k);
+                    //解析值
+                    String[] split = v.split("-");
+                    String type = split[0];
+                    BigDecimal value = new BigDecimal(split[1]);
+                    if ("信义污水厂_除磷P04预测值_".equals(type)) {
+                        industry.setCLP04YCZ(value);//目前值更新此字段
+                    }
+                    /*else if ("信义污水厂除磷加药瞬时流量".equals(type)) {
+                        industry.setCLJYSSLL(value);
+                    }*/
+
+                    //只有最后一次才执行数据库添加
+                    if(finalJ == list.size()-1){
+                        //先去查询数据库
+                        TXinyiIndustry uniqueTXinyiIndustry = this.xinyiIndustryMapper.getUniqueTXinyiIndustry(industry.getTestTime());
+                        if(Objects.isNull(uniqueTXinyiIndustry))
+                            log.error("查询到的工业库数据为null,化验时间为{}", industry.getTestTime());
+                        else {
+                            //防止其他信息被更新,新建对象
+                            TXinyiIndustry updateTXinyiIndustry = new TXinyiIndustry();
+                            //赋值
+                            updateTXinyiIndustry.setID(uniqueTXinyiIndustry.getID());
+                            updateTXinyiIndustry.setCLP04YCZ(industry.getCLP04YCZ());
+                            //更新数据库
+                            xinyiIndustryMapper.updateTXinyiIndustry(uniqueTXinyiIndustry);
+                        }
+                    }
+                });
+
+            }
+        }
+        return "ok";
+    }
 
 
 

+ 1 - 1
slibra-admin/src/main/java/com/slibra/web/controller/business/Test.java → slibra-admin/src/main/java/com/slibra/web/controller/business/TestSpider.java

@@ -10,7 +10,7 @@ import us.codecraft.webmagic.model.annotation.TargetUrl;
 import java.util.List;
 
 @TargetUrl("http://my.oschina.net/flashsword/blog/\\d+")
-public class Test {
+public class TestSpider {
 
 
         @ExtractBy("//title")

+ 3 - 1
slibra-quartz/src/main/java/com/slibra/quartz/task/RyTask.java

@@ -56,7 +56,7 @@ public class RyTask
     @Autowired
     private TXinyiRobotMapper xinyiRobotMapper;
 //    public final static StopWatch watch = new StopWatch("task");
-    public static final String[] queryTags = {"信义污水厂JS_COD_Value","信义污水厂JS_PH_Value","信义污水厂JS_SS_Value","信义污水厂JS_ZL_Value","信义污水厂JS_ZA_Value","信义污水厂JS_AD_Value","信义污水厂JS_T_Value","信义污水厂进水泵房液位","信义污水厂出水瞬时流量","信义污水厂升级出水COD","信义污水厂升级出水PH","信义污水厂升级出水SS","信义污水厂升级出水TN","信义污水厂升级出水TP","信义污水厂升级出水氨氮","信义污水厂AIT202_Value","信义污水厂AIT203_Value","信义污水厂AIT207_Value","信义污水厂AIT206_Value","信义污水厂AIT209_Value","信义污水厂AIT210_Value","信义污水厂进水TDS","信义污水厂FT101_Value","信义污水厂SWCHHYHLB1_R_Value","信义污水厂SWCHHYHLB2_R_Value","信义污水厂SWCHHYHLB3_R_Value","信义污水厂SWCHHYHLB4_R_Value","信义污水厂SWCHHYHLB5_R_Value","信义污水厂SWCHHYHLB6_R_Value","信义污水厂SWCWNHLB1_R_Value","信义污水厂SWCWNHLB2_R_Value","信义污水厂SWCWNHLB3_R_Value","信义污水厂SWCWNHLB4_R_Value","信义污水厂SWCWNHLB5_R_Value","信义污水厂GFJ1_R_Value","信义污水厂GFJ2_R_Value","信义污水厂GFJ3_R_Value","信义污水厂GFJ4_R_Value","信义污水厂GFJ5_R_Value","信义污水厂GFJ6_R_Value","信义污水厂GFJ1_KQLL_Value","信义污水厂GFJ2_KQLL_Value","信义污水厂GFJ3_KQLL_Value","信义污水厂GFJ4_KQLL_Value","信义污水厂GFJ5_KQLL_Value","信义污水厂GFJ6_KQLL_Value","信义污水厂实际碳源加药量","信义污水厂除磷加药瞬时流量"};
+    public static final String[] queryTags = {"信义污水厂JS_COD_Value","信义污水厂JS_PH_Value","信义污水厂JS_SS_Value","信义污水厂JS_ZL_Value","信义污水厂JS_ZA_Value","信义污水厂JS_AD_Value","信义污水厂JS_T_Value","信义污水厂进水泵房液位","信义污水厂出水瞬时流量","信义污水厂升级出水COD","信义污水厂升级出水PH","信义污水厂升级出水SS","信义污水厂升级出水TN","信义污水厂升级出水TP","信义污水厂升级出水氨氮","信义污水厂AIT202_Value","信义污水厂AIT203_Value","信义污水厂AIT207_Value","信义污水厂AIT206_Value","信义污水厂AIT209_Value","信义污水厂AIT210_Value","信义污水厂进水TDS","信义污水厂FT101_Value","信义污水厂SWCHHYHLB1_R_Value","信义污水厂SWCHHYHLB2_R_Value","信义污水厂SWCHHYHLB3_R_Value","信义污水厂SWCHHYHLB4_R_Value","信义污水厂SWCHHYHLB5_R_Value","信义污水厂SWCHHYHLB6_R_Value","信义污水厂SWCWNHLB1_R_Value","信义污水厂SWCWNHLB2_R_Value","信义污水厂SWCWNHLB3_R_Value","信义污水厂SWCWNHLB4_R_Value","信义污水厂SWCWNHLB5_R_Value","信义污水厂GFJ1_R_Value","信义污水厂GFJ2_R_Value","信义污水厂GFJ3_R_Value","信义污水厂GFJ4_R_Value","信义污水厂GFJ5_R_Value","信义污水厂GFJ6_R_Value","信义污水厂GFJ1_KQLL_Value","信义污水厂GFJ2_KQLL_Value","信义污水厂GFJ3_KQLL_Value","信义污水厂GFJ4_KQLL_Value","信义污水厂GFJ5_KQLL_Value","信义污水厂GFJ6_KQLL_Value","信义污水厂实际碳源加药量","信义污水厂除磷加药瞬时流量", "信义污水厂_除磷P04预测值_"};
 
     /**
      * 定时从工业库获取数据
@@ -266,6 +266,8 @@ public class RyTask
                         industry.setSJTYJLY(value);
                     }else if ("信义污水厂除磷加药瞬时流量".equals(type)) {
                         industry.setCLJYSSLL(value);
+                    } else if ("信义污水厂_除磷P04预测值_".equals(type)) {
+                        industry.setCLP04YCZ(value);
                     }
                     //只有最后一次才执行数据库添加
                     if(finalJ == list.size()-1){

+ 5 - 0
slibra-system/src/main/java/com/slibra/business/domain/TXinyiIndustry.java

@@ -238,6 +238,11 @@ public class TXinyiIndustry
     @Excel(name = "好氧池污泥浓度集合")
     private String hycWnndAll;
 
+    //2024年4月25日10:10:43 新增字段
+    /** 信义污水厂_除磷P04预测值_ */
+    @Excel(name = "信义污水厂_除磷P04预测值_")
+    private BigDecimal CLP04YCZ;
+
     /** 创建时间 */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")

+ 6 - 1
slibra-system/src/main/resources/mapper/business/TXinyiIndustryMapper.xml

@@ -60,11 +60,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="hycRjyAll"    column="HYC_RJY_ALL"    />
         <result property="hycRjyZdAll"    column="HYC_RJY_ZD_ALL"    />
         <result property="hycWnndAll"    column="HYC_WNND_ALL"    />
+        <result property="CLP04YCZ"    column="CL_P04_YCZ"    />
         <result property="createdTime"    column="CREATED_TIME"    />
     </resultMap>
 
     <sql id="selectTXinyiIndustryVo">
-        select ID, TEST_DATE, TEST_HOUR, TEST_TIME, JS_COD, JS_PH, JS_SS, JS_TP, JS_TN, JS_NH3, JS_SW_PH, JS_BFYW, CS_SLQC, CS_COD, CS_PH, CS_SS, CS_TN, CS_TP, CS_NH3, ONE_HYZD_DO, ONE_HYMD_DO, TWO_HYZD_DO, TWO_HYMD_DO, ONE_MLSS, TWO_MLSS, JS_TDS, JS_SLQ, N_HLB_ONE_GP, N_HLB_TWO_GP, N_HLB_THREE_GP, N_HLB_FOUR_GP, NHL_B_FIVE_GP, N_HLB_SIX_GP, W_HLB_ONE_GP, W_HLB_TWO_GP, W_HLB_THREE_GP, W_HLB_FOUR_GP, W_HLB_FIVE_GP, FJ_ONE, FJ_TWO, FJ_THREE, FJ_FOUR, FJ_FIVE, FJ_SIX, KQLL_ONE, KQLL_TWO, KQLL_THREE, KQLL_FOUR, KQLL_FIVE, KQLL_SIX, SJTYJLY, CLJYSSLL, HYC_RJY_ALL, HYC_RJY_ZD_ALL, HYC_WNND_ALL, CREATED_TIME from t_xinyi_industry
+        select ID, TEST_DATE, TEST_HOUR, TEST_TIME, JS_COD, JS_PH, JS_SS, JS_TP, JS_TN, JS_NH3, JS_SW_PH, JS_BFYW, CS_SLQC, CS_COD, CS_PH, CS_SS, CS_TN, CS_TP, CS_NH3, ONE_HYZD_DO, ONE_HYMD_DO, TWO_HYZD_DO, TWO_HYMD_DO, ONE_MLSS, TWO_MLSS, JS_TDS, JS_SLQ, N_HLB_ONE_GP, N_HLB_TWO_GP, N_HLB_THREE_GP, N_HLB_FOUR_GP, NHL_B_FIVE_GP, N_HLB_SIX_GP, W_HLB_ONE_GP, W_HLB_TWO_GP, W_HLB_THREE_GP, W_HLB_FOUR_GP, W_HLB_FIVE_GP, FJ_ONE, FJ_TWO, FJ_THREE, FJ_FOUR, FJ_FIVE, FJ_SIX, KQLL_ONE, KQLL_TWO, KQLL_THREE, KQLL_FOUR, KQLL_FIVE, KQLL_SIX, SJTYJLY, CLJYSSLL, HYC_RJY_ALL, HYC_RJY_ZD_ALL, HYC_WNND_ALL, CL_P04_YCZ, CREATED_TIME from t_xinyi_industry
     </sql>
 
     <select id="selectTXinyiIndustryList" parameterType="TXinyiIndustry" resultMap="TXinyiIndustryResult">
@@ -124,6 +125,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="hycRjyAll != null  and hycRjyAll != ''"> and HYC_RJY_ALL = #{hycRjyAll}</if>
             <if test="hycRjyZdAll != null  and hycRjyZdAll != ''"> and HYC_RJY_ZD_ALL = #{hycRjyZdAll}</if>
             <if test="hycWnndAll != null  and hycWnndAll != ''"> and HYC_WNND_ALL = #{hycWnndAll}</if>
+            <if test="CLP04YCZ != null "> and CL_P04_YCZ = #{CLP04YCZ}</if>
             <if test="createdTime != null "> and CREATED_TIME = #{createdTime}</if>
         </where>
     </select>
@@ -190,6 +192,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="hycRjyAll != null">HYC_RJY_ALL,</if>
             <if test="hycRjyZdAll != null">HYC_RJY_ZD_ALL,</if>
             <if test="hycWnndAll != null">HYC_WNND_ALL,</if>
+            <if test="CLP04YCZ != null">CL_P04_YCZ,</if>
             <if test="createdTime != null">CREATED_TIME,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -247,6 +250,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="hycRjyAll != null">#{hycRjyAll},</if>
             <if test="hycRjyZdAll != null">#{hycRjyZdAll},</if>
             <if test="hycWnndAll != null">#{hycWnndAll},</if>
+            <if test="CLP04YCZ != null">#{CLP04YCZ},</if>
             <if test="createdTime != null">#{createdTime},</if>
         </trim>
     </insert>
@@ -308,6 +312,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="hycRjyAll != null">HYC_RJY_ALL = #{hycRjyAll},</if>
             <if test="hycRjyZdAll != null">HYC_RJY_ZD_ALL = #{hycRjyZdAll},</if>
             <if test="hycWnndAll != null">HYC_WNND_ALL = #{hycWnndAll},</if>
+            <if test="CLP04YCZ != null">CL_P04_YCZ = #{CLP04YCZ},</if>
             <if test="createdTime != null">CREATED_TIME = #{createdTime},</if>
         </trim>
         where ID = #{ID}