wangmiaomiao 1 tahun lalu
induk
melakukan
d0be538ddf

+ 249 - 0
slibra-admin/src/main/java/com/slibra/web/controller/business/TestDataController.java

@@ -0,0 +1,249 @@
+package com.slibra.web.controller.business;
+
+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.TXinyiIndustry;
+import com.slibra.business.mapper.TXinyiIndustryMapper;
+import com.slibra.common.core.controller.BaseController;
+import com.slibra.common.utils.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+
+/**
+ * 参数配置 信息操作处理
+ * 
+ *
+ */
+@RestController
+@RequestMapping("/test")
+public class TestDataController extends BaseController
+{
+    @Autowired
+    private TXinyiIndustryMapper xinyiIndustryMapper;
+
+    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"};
+
+    @GetMapping("/dateAdd")
+    public void dateAdd() {
+
+
+        // 给定时间段的起始时间和结束时间
+        LocalDateTime startTime = LocalDateTime.parse("2024-01-01T00:00:00");
+        LocalDateTime endTime = LocalDateTime.parse("2024-04-08T19:00:00");
+
+
+        /*LocalDateTime startTime = LocalDateTime.parse("2024-02-26T00:00:00");
+        LocalDateTime endTime = LocalDateTime.parse("2024-02-27T00:00: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);
+            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;
+                }
+                //结合至少62个数据才满足条件(有可能获取不到)
+                /*if(size < 62){
+                    System.out.println(queryTag + "查询到了不符合条件的数据,跳过本次循环");
+                    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);
+            }
+//        System.out.println("list = " + list);
+            //先构造对象(list中任意一个map遍历的key个数)  因为合并完并不是1分钟60条,参考上面筛选区间,有时候会有几个值获取不到
+            /*HashMap<String, String> oneRow = list.get(0);
+            Set<String> set = oneRow.keySet();
+            List<Industry> result = new ArrayList<>(set.size());
+            set.forEach(s -> {
+                Industry industry = new Industry();
+                industry.setTestTime(s);
+                result.add(industry);
+            });*/
+            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 ("信义污水厂JS_COD_Value".equals(type)) {
+                        industry.setJsCod(value);
+                    } else if ("信义污水厂JS_PH_Value".equals(type)) {
+                        industry.setJsPh(value);
+                    } else if ("信义污水厂JS_SS_Value".equals(type)) {
+                        industry.setJsSs(value);
+                    } else if ("信义污水厂JS_ZL_Value".equals(type)) {
+                        industry.setJsTp(value);
+                    } else if ("信义污水厂JS_ZA_Value".equals(type)) {
+                        industry.setJsTn(value);
+                    } else if ("信义污水厂JS_AD_Value".equals(type)) {
+                        industry.setJsNh3(value);
+                    } else if ("信义污水厂JS_T_Value".equals(type)) {
+                        industry.setJsSwPh(value);
+                    } else if ("信义污水厂进水泵房液位".equals(type)) {
+                        industry.setJsBfyw(value);
+                    } else if ("信义污水厂出水瞬时流量".equals(type)) {
+                        industry.setCsSlqc(value);
+                    } else if ("信义污水厂升级出水COD".equals(type)) {
+                        industry.setCsCod(value);
+                    } else if ("信义污水厂升级出水PH".equals(type)) {
+                        industry.setCsPh(value);
+                    } else if ("信义污水厂升级出水SS".equals(type)) {
+                        industry.setCsSs(value);
+                    } else if ("信义污水厂升级出水TN".equals(type)) {
+                        industry.setCsTn(value);
+                    } else if ("信义污水厂升级出水TP".equals(type)) {
+                        industry.setCsTp(value);
+                    } else if ("信义污水厂升级出水氨氮".equals(type)) {
+                        industry.setCsNh3(value);
+                    } else if ("信义污水厂AIT202_Value".equals(type)) {
+                        industry.setOneHyzdDo(value);
+                    } else if ("信义污水厂AIT203_Value".equals(type)) {
+                        industry.setOneHymdDo(value);
+                    } else if ("信义污水厂AIT207_Value".equals(type)) {
+                        industry.setTwoHyzdDo(value);
+                    } else if ("信义污水厂AIT206_Value".equals(type)) {
+                        industry.setTwoHymdDo(value);
+                    } else if ("信义污水厂AIT209_Value".equals(type)) {
+                        industry.setOneMlss(value);
+                    } else if ("信义污水厂AIT210_Value".equals(type)) {
+                        industry.setTwoMlss(value);
+                    } else if ("信义污水厂进水TDS".equals(type)) {
+                        industry.setJsTds(value);
+                    } else if ("信义污水厂FT101_Value".equals(type)) {
+                        industry.setJsSlq(value);
+                    } else if ("信义污水厂SWCHHYHLB1_R_Value".equals(type)) {
+                        industry.setNHlbOneGp(value);
+                    } else if ("信义污水厂SWCHHYHLB2_R_Value".equals(type)) {
+                        industry.setNHlbTwoGp(value);
+                    } else if ("信义污水厂SWCHHYHLB3_R_Value".equals(type)) {
+                        industry.setNHlbThreeGp(value);
+                    } else if ("信义污水厂SWCHHYHLB4_R_Value".equals(type)) {
+                        industry.setNHlbFourGp(value);
+                    } else if ("信义污水厂SWCHHYHLB5_R_Value".equals(type)) {
+                        industry.setNhlBFiveGp(value);
+                    } else if ("信义污水厂SWCHHYHLB6_R_Value".equals(type)) {
+                        industry.setNHlbSixGp(value);
+                    } else if ("信义污水厂SWCWNHLB1_R_Value".equals(type)) {
+                        industry.setWHlbOneGp(value);
+                    } else if ("信义污水厂SWCWNHLB2_R_Value".equals(type)) {
+                        industry.setWHlbTwoGp(value);
+                    } else if ("信义污水厂SWCWNHLB3_R_Value".equals(type)) {
+                        industry.setWHlbThreeGp(value);
+                    } else if ("信义污水厂SWCWNHLB4_R_Value".equals(type)) {
+                        industry.setWHlbFourGp(value);
+                    } else if ("信义污水厂SWCWNHLB5_R_Value".equals(type)) {
+                        industry.setWHlbFiveGp(value);
+                    } else if ("信义污水厂GFJ1_R_Value".equals(type)) {
+                        industry.setFjOne(value);
+                    } else if ("信义污水厂GFJ2_R_Value".equals(type)) {
+                        industry.setFjTwo(value);
+                    } else if ("信义污水厂GFJ3_R_Value".equals(type)) {
+                        industry.setFjThree(value);
+                    } else if ("信义污水厂GFJ4_R_Value".equals(type)) {
+                        industry.setFjFour(value);
+                    } else if ("信义污水厂GFJ5_R_Value".equals(type)) {
+                        industry.setFjFive(value);
+                    } else if ("信义污水厂GFJ6_R_Value".equals(type)) {
+                        industry.setFjSix(value);
+                    } else if ("信义污水厂GFJ1_KQLL_Value".equals(type)) {
+                        industry.setKqllOne(value);
+                    } else if ("信义污水厂GFJ2_KQLL_Value".equals(type)) {
+                        industry.setKqllTwo(value);
+                    } else if ("信义污水厂GFJ3_KQLL_Value".equals(type)) {
+                        industry.setKqllThree(value);
+                    } else if ("信义污水厂GFJ4_KQLL_Value".equals(type)) {
+                        industry.setKqllFour(value);
+                    } else if ("信义污水厂GFJ5_KQLL_Value".equals(type)) {
+                        industry.setKqllFive(value);
+                    } else if ("信义污水厂GFJ6_KQLL_Value".equals(type)) {
+                        industry.setKqllSix(value);
+                    }else if ("信义污水厂实际碳源加药量".equals(type)) {
+                        industry.setSJTYJLY(value);
+                    }else if ("信义污水厂除磷加药瞬时流量".equals(type)) {
+                        industry.setCLJYSSLL(value);
+                    }
+                    //只有最后一次才执行数据库添加
+                    if(finalJ == list.size()-1){
+                        //插入数据库
+                        xinyiIndustryMapper.insertTXinyiIndustry(industry);
+                    }
+                });
+
+
+
+
+            }
+
+        }
+
+    }
+}

+ 2 - 2
slibra-admin/src/main/resources/application-dev.yml

@@ -6,9 +6,9 @@ spring:
         druid:
             # 主库数据源
             master:
-                url: jdbc:mysql://localhost:3306/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+                url: jdbc:mysql://localhost:3306/big_model?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                 username: root
-                password: root
+                password: Hongshan2024@longjiang
             # 从库数据源
             slave:
                 # 从数据源开关/默认关闭

+ 1 - 1
slibra-framework/src/main/java/com/slibra/framework/config/SecurityConfig.java

@@ -121,7 +121,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/register", "/captchaImage","/sendSmsCode/*","/smsLogin").permitAll()
+                .antMatchers("/login", "/register", "/captchaImage","/sendSmsCode/*","/smsLogin","/test/**").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()