Эх сурвалжийг харах

数字孪生全厂首页接口模拟

wukai 3 сар өмнө
parent
commit
ea15046670

+ 119 - 0
jjt-admin/src/test/java/com/jjt/data/PrintingTest.java

@@ -0,0 +1,119 @@
+package com.jjt.data;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.jjt.JjtApplication;
+import com.jjt.common.utils.DateUtils;
+import com.jjt.utils.IotService;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.annotation.Resource;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * 印花机
+ */
+@SpringBootTest(classes = JjtApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class PrintingTest {
+    @Resource
+    private IotService iotService;
+
+    /**
+     * 印花设备数据
+     */
+    @Test
+    void test() {
+        iotService.setToken();
+        Integer[] lines = {1, 2, 3, 4, 5, 6, 7, 8};
+        List<String[]>[] lists = new ArrayList[8];
+        for (int i = 0; i < lines.length; i++) {
+            String table = "root.tl.suxi.yhj_line" + lines[i] + "_PLC1";
+            lists[i] = new ArrayList<>();
+            String st = "2025-02-28";
+            LocalDate localDate = LocalDate.parse(st);
+            LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(19);
+            LocalDateTime end = start.plusHours(11);
+            do {
+                LocalDateTime startTime = start;
+                LocalDateTime endTime = start.plusHours(1);
+                List<String[]> pList = get(table, startTime, endTime);
+                lists[i].addAll(pList);
+                start = start.plusHours(1);
+            } while (!start.isAfter(end));
+        }
+
+        try (Workbook workbook = new XSSFWorkbook(); FileOutputStream outputStream = new FileOutputStream("D:\\SYSTEM\\Desktop\\temp\\excel\\印花机数据-明细" + System.currentTimeMillis() + ".xlsx")) {
+            for (int i = 0; i < lines.length; i++) {
+                Sheet sheet = workbook.createSheet(lines[i] + "线");
+                toExcelNew(lists[i], sheet);
+            }
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public List<String[]> get(String table, LocalDateTime start, LocalDateTime end) {
+        List<String[]> list = new ArrayList<>();
+        Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        String[] fields = {"Formula_data_set_1", "Formula_data_set_3", "Formula_data_act_2", "Formula_data_act_3", "Formula_data_act_4", "Formula_data_act_5"};
+        String sql = "select %s from %s where time>%s and time <=%s";
+        sql = String.format(sql, String.join(",", fields), table, startTime, endTime);
+        iotService.query(sql);
+        JSONObject jsonObject = iotService.query(sql);
+        JSONObject data = jsonObject.getJSONObject("data");
+        JSONArray values = data.getJSONArray("values");
+        JSONArray timestamps = data.getJSONArray("timestamps");
+        for (int i = 0; i < values.size(); i++) {
+            String[] temp = new String[fields.length + 1];
+            temp[0] = timestamps.getStr(i);
+            JSONArray da = values.getJSONArray(i);
+            for (int j = 1; j < temp.length; j++) {
+                temp[j] = da.getStr(j - 1);
+            }
+            list.add(temp);
+        }
+        return list;
+    }
+
+    public void toExcelNew(List<String[]> list, Sheet sheet) {
+        String[] names = {"时间", "版距 0.01mm", "贴布轮速度1%", "生产速度0.01m/m", "生产速度0.1t/m", "产量次数计数器 1次", "产量长度计数器  1M"};
+
+        Row title = sheet.createRow(0);
+        for (int i = 0; i < names.length; i++) {
+            Cell cell = title.createCell(i);
+            cell.setCellValue(names[i]);
+        }
+        AtomicInteger index = new AtomicInteger(1);
+        list.forEach(d -> {
+            Row row = sheet.createRow(index.get());
+            Long time = Long.parseLong(d[0]);
+            String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date(time));
+            Cell cell = row.createCell(0);
+            cell.setCellValue(date);
+            for (int j = 1; j < d.length; j++) {
+                cell = row.createCell(j);
+                cell.setCellValue(Float.parseFloat(d[j]));
+
+            }
+            index.getAndIncrement();
+        });
+    }
+}

+ 123 - 0
jjt-admin/src/test/java/com/jjt/data/QiMaoJiTest.java

@@ -0,0 +1,123 @@
+package com.jjt.data;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.jjt.JjtApplication;
+import com.jjt.common.utils.StringUtils;
+import com.jjt.utils.IotService;
+import javafx.util.Pair;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * 起毛机
+ */
+@SpringBootTest(classes = JjtApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class QiMaoJiTest {
+    @Resource
+    private IotService iotService;
+
+    /**
+     * 印花设备数据
+     */
+    @Test
+    void test() {
+        iotService.setToken();
+        String st = "2025-02-28";
+        LocalDate localDate = LocalDate.parse(st);
+        LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(19);
+        LocalDateTime end = start.plusHours(11);
+        List<Pair<String, String>> list = new ArrayList<>();
+        Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        String sql = "select SUM(DIFF(Capacity_data_17)) from root.tl.suxi.qiMaoJiLine** where time>%s and time <=%s";
+        sql = String.format(sql, startTime, endTime);
+        iotService.query(sql);
+        JSONObject jsonObject = iotService.query(sql);
+        JSONObject data = jsonObject.getJSONObject("data");
+        JSONArray values = data.getJSONArray("values");
+        JSONArray columnNames = data.getJSONArray("columnNames");
+        JSONArray timestamps = data.getJSONArray("timestamps");
+        if (values.size() == 1) {
+            JSONArray da = values.getJSONArray(0);
+            for (int i = 0; i < da.size(); i++) {
+                Pair<String, String> pair = new Pair<>(columnNames.getStr(i), da.getStr(i));
+                list.add(pair);
+            }
+        }
+
+        try (Workbook workbook = new XSSFWorkbook(); FileOutputStream outputStream = new FileOutputStream("D:\\SYSTEM\\Desktop\\temp\\excel\\后整起毛机-明细" + System.currentTimeMillis() + ".xlsx")) {
+            Sheet sheet = workbook.createSheet();
+
+            String[] names = {"总产量(米)", "设备名", "设备线路", "设备编号", "设备路径"};
+
+            Row title = sheet.createRow(0);
+            for (int i = 0; i < names.length; i++) {
+                Cell cell = title.createCell(i);
+                cell.setCellValue(names[i]);
+            }
+            AtomicInteger index = new AtomicInteger(1);
+            list.forEach(pair -> {
+                Row row = sheet.createRow(index.get());
+                Cell[] cells = new Cell[names.length];
+                for (int i = 0; i < names.length; i++) {
+                    cells[i] = row.createCell(i);
+                }
+                cells[4].setCellValue(getPath(pair.getKey()));
+                if (StringUtils.isNotEmpty(pair.getValue())) {
+                    cells[0].setCellValue(Double.parseDouble(pair.getValue()));
+                }
+                cells[1].setCellValue(getName(pair.getKey()));
+                cells[2].setCellValue(Integer.parseInt(getLine(pair.getKey())));
+                cells[3].setCellValue(Integer.parseInt(getNo(pair.getKey())));
+                index.getAndIncrement();
+            });
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public String getPath(String key) {
+        key = key.replace("SUM(DIFF(", "");
+        key = key.replace(".Capacity_data_17))", "");
+        return key;
+    }
+
+    public String getName(String key) {
+        key = getPath(key);
+        key = key.replace("root.tl.suxi.qiMaoJiLine", "");
+        key = key.replace("BackNo", "线-");
+        key = key.replace("_PLC1", "号");
+        return key;
+    }
+
+    public String getLine(String key) {
+        key = getPath(key);
+        key = key.replace("root.tl.suxi.qiMaoJiLine", "");
+        key = key.substring(0, key.indexOf("BackNo"));
+        return key;
+    }
+
+    public String getNo(String key) {
+        key = getPath(key);
+        key = key.substring(key.indexOf("No") + 2, key.indexOf("_PLC1"));
+        return key;
+    }
+}

+ 139 - 0
jjt-admin/src/test/java/com/jjt/data/SgtgjTest.java

@@ -0,0 +1,139 @@
+package com.jjt.data;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.jjt.JjtApplication;
+import com.jjt.common.utils.StringUtils;
+import com.jjt.utils.IotService;
+import javafx.util.Pair;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+
+/**
+ * 双棍烫光机
+ */
+@SpringBootTest(classes = JjtApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class SgtgjTest {
+    @Resource
+    private IotService iotService;
+
+    /**
+     * 印花设备数据
+     */
+    @Test
+    void test() {
+        iotService.setToken();
+        String st = "2025-02-28";
+        LocalDate localDate = LocalDate.parse(st);
+        LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(19);
+        LocalDateTime end = start.plusHours(11);
+        List<Pair<String, String>> list = new ArrayList<>();
+        Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        String sql = "select SUM(DIFF(Capacity_data_2)) from root.tl.suxi.sgtgjLine** where time>%s and time <=%s";
+        sql = String.format(sql, startTime, endTime);
+        iotService.query(sql);
+        JSONObject jsonObject = iotService.query(sql);
+        JSONObject data = jsonObject.getJSONObject("data");
+        JSONArray values = data.getJSONArray("values");
+        JSONArray columnNames = data.getJSONArray("columnNames");
+        JSONArray timestamps = data.getJSONArray("timestamps");
+        if (values.size() == 1) {
+            JSONArray da = values.getJSONArray(0);
+            for (int i = 0; i < da.size(); i++) {
+                Pair<String, String> pair = new Pair<>(columnNames.getStr(i), da.getStr(i));
+                list.add(pair);
+            }
+        }
+
+        try (Workbook workbook = new XSSFWorkbook(); FileOutputStream outputStream = new FileOutputStream("D:\\SYSTEM\\Desktop\\temp\\excel\\双棍烫光机-明细" + System.currentTimeMillis() + ".xlsx")) {
+            Sheet sheet = workbook.createSheet();
+
+            String[] names = {"总产量(米)", "设备名", "设备类型", "设备线路", "设备编号", "设备路径"};
+
+            Row title = sheet.createRow(0);
+            for (int i = 0; i < names.length; i++) {
+                Cell cell = title.createCell(i);
+                cell.setCellValue(names[i]);
+            }
+            AtomicInteger index = new AtomicInteger(1);
+            list.forEach(pair -> {
+                Row row = sheet.createRow(index.get());
+                Cell[] cells = new Cell[names.length];
+                for (int i = 0; i < names.length; i++) {
+                    cells[i] = row.createCell(i);
+                }
+                cells[5].setCellValue(getPath(pair.getKey()));
+                if (StringUtils.isNotEmpty(pair.getValue())) {
+                    cells[0].setCellValue(Double.parseDouble(pair.getValue()));
+                }
+                cells[1].setCellValue(getName(pair.getKey()));
+                cells[2].setCellValue(getType(pair.getKey()));
+                cells[3].setCellValue(Integer.parseInt(getLine(pair.getKey())));
+                cells[4].setCellValue(Integer.parseInt(getNo(pair.getKey())));
+                index.getAndIncrement();
+            });
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public String getPath(String key) {
+        key = key.replace("SUM(DIFF(", "");
+        key = key.replace(".Capacity_data_2))", "");
+        return key;
+    }
+
+    public String getName(String key) {
+        key = getPath(key);
+        key = key.replace("root.tl.suxi.sgtgjLine", "");
+        key = key.replace("ForwardNo", "线-前整");
+        key = key.replace("BackNo", "线-后整");
+        key = key.replace("_PLC1", "号");
+        return key;
+    }
+
+    public String getType(String key) {
+        if (key.contains("ForwardNo")) {
+            return "前整";
+        } else {
+            return "后整";
+        }
+    }
+
+    public String getLine(String key) {
+        key = getPath(key);
+        key = key.replace("root.tl.suxi.sgtgjLine", "");
+        if (key.contains("ForwardNo")) {
+            key = key.substring(0, key.indexOf("ForwardNo"));
+        } else {
+            key = key.substring(0, key.indexOf("BackNo"));
+        }
+        return key;
+    }
+
+    public String getNo(String key) {
+        key = getPath(key);
+        key = key.substring(key.indexOf("No") + 2, key.indexOf("_PLC1"));
+        return key;
+    }
+}

+ 123 - 0
jjt-admin/src/test/java/com/jjt/data/TangJianJiTest.java

@@ -0,0 +1,123 @@
+package com.jjt.data;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.jjt.JjtApplication;
+import com.jjt.common.utils.StringUtils;
+import com.jjt.utils.IotService;
+import javafx.util.Pair;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * 后整烫剪机
+ */
+@SpringBootTest(classes = JjtApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class TangJianJiTest {
+    @Resource
+    private IotService iotService;
+
+    /**
+     * 印花设备数据
+     */
+    @Test
+    void test() {
+        iotService.setToken();
+        String st = "2025-02-28";
+        LocalDate localDate = LocalDate.parse(st);
+        LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(19);
+        LocalDateTime end = start.plusHours(11);
+        List<Pair<String, String>> list = new ArrayList<>();
+        Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        String sql = "select SUM(DIFF(Capacity_data_2)) from root.tl.suxi.tangJianJiLine** where time>%s and time <=%s";
+        sql = String.format(sql, startTime, endTime);
+        iotService.query(sql);
+        JSONObject jsonObject = iotService.query(sql);
+        JSONObject data = jsonObject.getJSONObject("data");
+        JSONArray values = data.getJSONArray("values");
+        JSONArray columnNames = data.getJSONArray("columnNames");
+        JSONArray timestamps = data.getJSONArray("timestamps");
+        if (values.size() == 1) {
+            JSONArray da = values.getJSONArray(0);
+            for (int i = 0; i < da.size(); i++) {
+                Pair<String, String> pair = new Pair<>(columnNames.getStr(i), da.getStr(i));
+                list.add(pair);
+            }
+        }
+
+        try (Workbook workbook = new XSSFWorkbook(); FileOutputStream outputStream = new FileOutputStream("D:\\SYSTEM\\Desktop\\temp\\excel\\后整烫剪机-明细" + System.currentTimeMillis() + ".xlsx")) {
+            Sheet sheet = workbook.createSheet();
+
+            String[] names = {"总产量(米)", "设备名", "设备线路", "设备编号", "设备路径"};
+
+            Row title = sheet.createRow(0);
+            for (int i = 0; i < names.length; i++) {
+                Cell cell = title.createCell(i);
+                cell.setCellValue(names[i]);
+            }
+            AtomicInteger index = new AtomicInteger(1);
+            list.forEach(pair -> {
+                Row row = sheet.createRow(index.get());
+                Cell[] cells = new Cell[names.length];
+                for (int i = 0; i < names.length; i++) {
+                    cells[i] = row.createCell(i);
+                }
+                cells[4].setCellValue(getPath(pair.getKey()));
+                if (StringUtils.isNotEmpty(pair.getValue())) {
+                    cells[0].setCellValue(Double.parseDouble(pair.getValue()));
+                }
+                cells[1].setCellValue(getName(pair.getKey()));
+                cells[2].setCellValue(Integer.parseInt(getLine(pair.getKey())));
+                cells[3].setCellValue(Integer.parseInt(getNo(pair.getKey())));
+                index.getAndIncrement();
+            });
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public String getPath(String key) {
+        key = key.replace("SUM(DIFF(", "");
+        key = key.replace(".Capacity_data_2))", "");
+        return key;
+    }
+
+    public String getName(String key) {
+        key = getPath(key);
+        key = key.replace("root.tl.suxi.tangJianJiLine", "");
+        key = key.replace("BackNo", "线-");
+        key = key.replace("_PLC1", "号");
+        return key;
+    }
+
+    public String getLine(String key) {
+        key = getPath(key);
+        key = key.replace("root.tl.suxi.tangJianJiLine", "");
+        key = key.substring(0, key.indexOf("BackNo"));
+        return key;
+    }
+
+    public String getNo(String key) {
+        key = getPath(key);
+        key = key.substring(key.indexOf("No") + 2, key.indexOf("_PLC1"));
+        return key;
+    }
+}

+ 81 - 0
jjt-admin/src/test/java/com/jjt/ep/EnvPowerTest.java

@@ -0,0 +1,81 @@
+package com.jjt.ep;
+
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.http.Method;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+
+import java.nio.charset.StandardCharsets;
+
+/**
+ * EnvPowerTest$
+ *
+ * @author wukai
+ * @date 2025/2/18 01:42
+ */
+public class EnvPowerTest {
+    public static void main(String[] args) throws Exception {
+        System.err.println(System.getProperty("java.net.preferIPv4Stack"));
+        String uri = "http://192.168.79.21:18080/truelove/energy/manage/monthlyFinancialStatement";
+        String date = "2025-02-15";
+        JSONObject object = new JSONObject();
+        object.set("selectTime", date);
+        object.set("timeType", "DAY");
+        HttpRequest request = HttpUtil.createPost(uri);
+        request.setMethod(Method.POST);
+        request.body(object.toString());
+//        request.setConnectionTimeout(5000);
+        try (HttpResponse execute = request.execute()) {
+            if (!execute.isOk()) {
+                throw new RuntimeException(execute.body());
+            }
+            String res = new String(execute.body().getBytes(), StandardCharsets.UTF_8);
+            JSONObject obj = JSONUtil.parseObj(res, true);
+            if (obj.getInt("code") == 200) {
+                JSONArray datas = obj.getJSONArray("data");
+                JSONObject data = datas.getJSONObject(0);
+                JSONArray childrens = data.getJSONArray("childrens");
+//                System.err.println(childrens);
+                for (int i = 0; i < childrens.size(); i++) {
+                    JSONObject cds = childrens.getJSONObject(i);
+                    String name = cds.getStr("name");
+                    String energyType = cds.getStr("energyType");
+                    String spatialLevel = cds.getStr("spatialLevel");
+                    String id = cds.getStr("id");
+                    String upId = cds.getStr("upId");
+                    System.err.println(name + "\t" + energyType + "\t" + spatialLevel + "\t" + id + "\t" + upId);
+                    if ("1862779623916564481".equals(id)||"1851500076220350465".equals(id)) {
+                        JSONArray cds1 = cds.getJSONArray("childrens");
+                        for (int j = 0; j < cds1.size(); j++) {
+                            JSONObject ccc = cds1.getJSONObject(j);
+                            name = ccc.getStr("name");
+                            energyType = ccc.getStr("energyType");
+                            spatialLevel = ccc.getStr("spatialLevel");
+                            id = ccc.getStr("id");
+                            upId = ccc.getStr("upId");
+                            System.err.println("\t\t"+name + "\t" + energyType + "\t" + spatialLevel + "\t" + id + "\t" + upId);
+                            if ("1851500278780067842".equals(id)) {
+                                JSONArray cds12 = ccc.getJSONArray("childrens");
+                                for (int k = 0; k < cds12.size(); k++) {
+                                    JSONObject ddd = cds12.getJSONObject(k);
+                                    name = ddd.getStr("name");
+                                    energyType = ddd.getStr("energyType");
+                                    spatialLevel = ddd.getStr("spatialLevel");
+                                    id = ddd.getStr("id");
+                                    upId = ddd.getStr("upId");
+                                    System.err.println("\t\t"+name + "\t" + energyType + "\t" + spatialLevel + "\t" + id + "\t" + upId);
+                                }
+                            }
+                        }
+                    }
+
+                }
+
+
+            }
+        }
+    }
+}

+ 43 - 0
jjt-biz/src/main/java/com/jjt/biz/controller/ApiAllController.java

@@ -0,0 +1,43 @@
+package com.jjt.biz.controller;
+
+import com.jjt.biz.service.IApiAllService;
+import com.jjt.biz.vo.TwinAllVO;
+import com.jjt.common.core.controller.BaseController;
+import com.jjt.common.core.domain.R;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+/**
+ * swagger 用户测试方法
+ *
+ * @author ruoyi
+ */
+@Api("全厂孪生数据接口")
+@RestController
+@Slf4j
+public class ApiAllController extends BaseController {
+    @Resource
+    private IApiAllService service;
+
+    @ApiOperation("全厂数字孪生")
+    @GetMapping("/api/all/data")
+    @CrossOrigin(origins = "*")
+    @ResponseBody
+    public R<?> data() {
+        TwinAllVO vo = new TwinAllVO();
+        vo.setStock(service.stock());
+        vo.setAvgMonth(service.avgMonth());
+        vo.setCurrYield(service.currYield());
+        vo.setProdTrade(service.prodTrade());
+        vo.setEnergyTrade(service.energyTrade());
+        return R.ok(vo);
+    }
+
+}

+ 52 - 0
jjt-biz/src/main/java/com/jjt/biz/service/IApiAllService.java

@@ -0,0 +1,52 @@
+package com.jjt.biz.service;
+
+import com.jjt.biz.vo.AvgMonthVO;
+import com.jjt.biz.vo.CurrYieldVO;
+import com.jjt.biz.vo.EnergyTradeVO;
+import com.jjt.biz.vo.ProdTradeVO;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 首页统计数据
+ *
+ * @author wukai
+ */
+public interface IApiAllService {
+    /**
+     * 获取当前库存数据
+     *
+     * @return 库存数据
+     */
+    Map<String, Object> stock();
+
+    /**
+     * 获取本月平均值
+     *
+     * @return 结果
+     */
+    AvgMonthVO avgMonth();
+
+    /**
+     * 获取生产情况
+     *
+     * @return 结果
+     */
+    CurrYieldVO currYield();
+
+    /**
+     * 获取生产趋势
+     *
+     * @return 结果
+     */
+    List<ProdTradeVO> prodTrade();
+
+    /**
+     * 获取能耗趋势
+     *
+     * @return 结果
+     */
+    List<EnergyTradeVO> energyTrade();
+
+}

+ 140 - 0
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiAllServiceImpl.java

@@ -0,0 +1,140 @@
+package com.jjt.biz.service.impl;
+
+import com.jjt.biz.service.IApiAllService;
+import com.jjt.biz.vo.AvgMonthVO;
+import com.jjt.biz.vo.CurrYieldVO;
+import com.jjt.biz.vo.EnergyTradeVO;
+import com.jjt.biz.vo.ProdTradeVO;
+import com.jjt.common.constant.CacheConstants;
+import com.jjt.common.core.redis.RedisCache;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 首页统计数据
+ *
+ * @author wukai
+ * @date 2024/5/4 20:35
+ */
+@Service
+@Slf4j
+public class ApiAllServiceImpl implements IApiAllService {
+    @Resource
+    private RedisCache redisCache;
+
+    /**
+     * 获取当前库存数据
+     *
+     * @return 库存数据
+     */
+    @Override
+    public Map<String, Object> stock() {
+        return redisCache.getCacheObject(CacheConstants.VMS_STOCK);
+    }
+
+    /**
+     * 获取本月平均值
+     *
+     * @return 结果
+     */
+    @Override
+    public AvgMonthVO avgMonth() {
+        AvgMonthVO vo = new AvgMonthVO();
+        vo.mock();
+        redisCache.setCacheObject(CacheConstants.AVG_MONTH, vo);
+        return redisCache.getCacheObject(CacheConstants.AVG_MONTH);
+    }
+
+    /**
+     * 获取生产情况
+     *
+     * @return 结果
+     */
+    @Override
+    public CurrYieldVO currYield() {
+        CurrYieldVO vo = new CurrYieldVO();
+        vo.mock();
+        redisCache.setCacheObject(CacheConstants.CURR_YIELD, vo);
+        return redisCache.getCacheObject(CacheConstants.CURR_YIELD);
+    }
+
+    /**
+     * 获取生产趋势
+     *
+     * @return 结果
+     */
+    @Override
+    public List<ProdTradeVO> prodTrade() {
+        redisCache.setCacheObject(CacheConstants.PROD_TRADE, mockProd());
+        return redisCache.getCacheObject(CacheConstants.PROD_TRADE);
+    }
+
+    /**
+     * 获取能耗趋势
+     *
+     * @return 结果
+     */
+    @Override
+    public List<EnergyTradeVO> energyTrade() {
+        redisCache.setCacheObject(CacheConstants.ENERGY_TRADE, mockEnergy());
+        return redisCache.getCacheObject(CacheConstants.ENERGY_TRADE);
+    }
+
+    private List<ProdTradeVO> mockProd() {
+        List<ProdTradeVO> list = new ArrayList<>();
+        LocalDate end = LocalDate.now().minusDays(1);
+        LocalDate start = end.minusDays(6);
+        do {
+            ProdTradeVO vo = new ProdTradeVO();
+            vo.setDate(week(start));
+            vo.mock();
+            list.add(vo);
+            start = start.plusDays(1);
+        } while (!start.isAfter(end));
+        return list;
+
+    }
+
+    private List<EnergyTradeVO> mockEnergy() {
+        List<EnergyTradeVO> list = new ArrayList<>();
+        LocalDate end = LocalDate.now().minusDays(1);
+        LocalDate start = end.minusDays(30);
+        do {
+            EnergyTradeVO vo = new EnergyTradeVO();
+            vo.setDate(start.getDayOfMonth() + "");
+            vo.mock();
+            list.add(vo);
+            start = start.plusDays(1);
+        } while (!start.isAfter(end));
+        return list;
+
+    }
+
+    /**
+     * 获取周几
+     *
+     * @param date
+     * @return
+     */
+    private String week(LocalDate date) {
+        String[] weeks = {"一", "二", "三", "四", "五", "六", "日"};
+        return "周" + weeks[date.getDayOfWeek().getValue() - 1];
+    }
+
+    public static void main(String[] args) {
+        int day = 7;
+        LocalDate end = LocalDate.now().minusDays(1);
+        LocalDate start = end.minusDays(day - 1);
+        do {
+            System.err.println(start + "\t" + start.getDayOfWeek().getValue());
+            start = start.plusDays(1);
+        } while (!start.isAfter(end));
+    }
+
+}

+ 47 - 0
jjt-biz/src/main/java/com/jjt/biz/vo/AvgMonthVO.java

@@ -0,0 +1,47 @@
+package com.jjt.biz.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Random;
+
+/**
+ * 月平均
+ *
+ * @author wukai
+ */
+@ApiModel(value = "AvgMonthVO", description = "月平均")
+@Data
+public class AvgMonthVO {
+    @ApiModelProperty("总成本")
+    private BigDecimal costTotal;
+    @ApiModelProperty("经编成本")
+    private BigDecimal costJb;
+    @ApiModelProperty("染整成本")
+    private BigDecimal costRz;
+    @ApiModelProperty("经编产量")
+    private BigDecimal yieldJb;
+    @ApiModelProperty("染整产量")
+    private BigDecimal yieldRz;
+    @ApiModelProperty("稼动率")
+    private BigDecimal jdl;
+
+    public void mock() {
+        Random random = new Random();
+        double total = 100000 + 30000 * random.nextDouble();
+        this.costTotal = BigDecimal.valueOf(total).setScale(1, RoundingMode.HALF_UP);
+        double price = 2.0 + random.nextDouble();
+        this.costJb = BigDecimal.valueOf(price).setScale(1, RoundingMode.HALF_UP);
+        price = 2.0 + random.nextDouble();
+        this.costRz = BigDecimal.valueOf(price).setScale(1, RoundingMode.HALF_UP);
+        double prod = 20000 + 20000 * random.nextDouble();
+        this.yieldJb = BigDecimal.valueOf(prod).setScale(0, RoundingMode.HALF_UP);
+        prod = 20000 + 20000 * random.nextDouble();
+        this.yieldRz = BigDecimal.valueOf(prod).setScale(0, RoundingMode.HALF_UP);
+        double jdl = 70 + 10 * random.nextDouble();
+        this.jdl = BigDecimal.valueOf(jdl).setScale(0, RoundingMode.HALF_UP);
+    }
+}

+ 94 - 0
jjt-biz/src/main/java/com/jjt/biz/vo/CurrYieldVO.java

@@ -0,0 +1,94 @@
+package com.jjt.biz.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Random;
+
+/**
+ * 月平均
+ *
+ * @author wukai
+ */
+@ApiModel(value = "CurrProdVO", description = "当前生产情况")
+@Data
+public class CurrYieldVO {
+    @ApiModelProperty("经编生产情况")
+    private JB jb;
+    @ApiModelProperty("染整生产情况")
+    private RZ rz;
+
+    /**
+     * 经编当前产量内部类
+     */
+    @Data
+    public static class JB {
+        @ApiModelProperty("稼动率")
+        private BigDecimal jdl;
+        @ApiModelProperty("开机率")
+        private BigDecimal openRatio;
+        @ApiModelProperty("产量")
+        private BigDecimal yield;
+        @ApiModelProperty("最大产量")
+        private BigDecimal yieldMax;
+        @ApiModelProperty("开机数")
+        private Integer openNum;
+        @ApiModelProperty("设备总数")
+        private Integer totalNum;
+    }
+
+    /**
+     * 染整当前产量内部类
+     */
+    @Data
+    public static class RZ {
+        @ApiModelProperty("开动产线")
+        private Integer openLine;
+        @ApiModelProperty("总产线")
+        private Integer maxLine;
+        @ApiModelProperty("开机率")
+        private BigDecimal openRatio;
+        @ApiModelProperty("产量")
+        private BigDecimal yield;
+        @ApiModelProperty("最大产量")
+        private BigDecimal yieldMax;
+        @ApiModelProperty("开机数")
+        private Integer openNum;
+        @ApiModelProperty("设备总数")
+        private Integer totalNum;
+    }
+
+
+    public CurrYieldVO() {
+        this.jb = new JB();
+        this.rz = new RZ();
+    }
+
+
+    public void mock() {
+        Random random = new Random();
+        double jdl = 70 + 10 * random.nextDouble();
+        this.jb.jdl = BigDecimal.valueOf(jdl).setScale(0, RoundingMode.HALF_UP);
+        jdl = 85 + 15 * random.nextDouble();
+        this.jb.openRatio = BigDecimal.valueOf(jdl).setScale(0, RoundingMode.HALF_UP);
+        jdl = 70 + 10 * random.nextDouble();
+        this.rz.openRatio = BigDecimal.valueOf(jdl).setScale(0, RoundingMode.HALF_UP);
+        this.rz.openLine = 4;
+        this.rz.maxLine = 8;
+        this.rz.openNum = 100;
+        this.rz.totalNum = 150;
+
+        this.jb.openNum = 100;
+        this.jb.totalNum = 150;
+
+        jdl = 15000 + 30000 * random.nextDouble();
+        this.jb.yield = BigDecimal.valueOf(jdl).setScale(0, RoundingMode.HALF_UP);
+        jdl = 15000 + 30000 * random.nextDouble();
+        this.rz.yield = BigDecimal.valueOf(jdl).setScale(0, RoundingMode.HALF_UP);
+        this.jb.yieldMax = BigDecimal.valueOf(45000);
+        this.rz.yieldMax = BigDecimal.valueOf(45000);
+    }
+}

+ 42 - 0
jjt-biz/src/main/java/com/jjt/biz/vo/EnergyTradeVO.java

@@ -0,0 +1,42 @@
+package com.jjt.biz.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Random;
+
+/**
+ * 能耗趋势视图
+ *
+ * @author ruoyi
+ * @date 2024-12-30
+ */
+@ApiModel(value = "EnergyTradeVO", description = "能耗趋势视图")
+@Data
+public class EnergyTradeVO {
+    @ApiModelProperty("时间")
+    private String date;
+    @ApiModelProperty("电")
+    private BigDecimal electricity;
+    @ApiModelProperty("汽")
+    private BigDecimal steam;
+    @ApiModelProperty("水")
+    private BigDecimal water;
+    @ApiModelProperty("价格")
+    private BigDecimal price;
+
+    public void mock() {
+        Random random = new Random();
+        double price = 2.0 + random.nextDouble();
+        this.price = BigDecimal.valueOf(price).setScale(1, RoundingMode.HALF_UP);
+        double electricity = 50000 + 10000 * random.nextDouble();
+        this.electricity = BigDecimal.valueOf(electricity).setScale(1, RoundingMode.HALF_UP);
+        double steam = 400 + 200 * random.nextDouble();
+        this.steam = BigDecimal.valueOf(steam).setScale(1, RoundingMode.HALF_UP);
+        double water = 400 + 200 * random.nextDouble();
+        this.water = BigDecimal.valueOf(water).setScale(1, RoundingMode.HALF_UP);
+    }
+}

+ 37 - 0
jjt-biz/src/main/java/com/jjt/biz/vo/ProdTradeVO.java

@@ -0,0 +1,37 @@
+package com.jjt.biz.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Random;
+
+/**
+ * 生产趋势视图
+ *
+ * @author ruoyi
+ * @date 2024-12-30
+ */
+@ApiModel(value = "ProdTradeVO", description = "生产趋势视图")
+@Data
+public class ProdTradeVO {
+    @ApiModelProperty("时间")
+    private String date;
+    @ApiModelProperty("经编米数")
+    private BigDecimal jbLength;
+    @ApiModelProperty("染整米数")
+    private BigDecimal rzLength;
+    @ApiModelProperty("经编重量")
+    private BigDecimal jbWeight;
+    @ApiModelProperty("染整重量")
+    private BigDecimal rzWeight;
+
+    public void mock() {
+        Random random = new Random();
+        this.jbLength = BigDecimal.valueOf(32000 + random.nextInt(13000));
+        this.rzLength = BigDecimal.valueOf(32000 + random.nextInt(13000));
+        this.jbWeight = BigDecimal.valueOf(60 + random.nextInt(60));
+        this.rzWeight = BigDecimal.valueOf(50 + random.nextInt(70));
+    }
+}

+ 35 - 0
jjt-biz/src/main/java/com/jjt/biz/vo/TwinAllVO.java

@@ -0,0 +1,35 @@
+package com.jjt.biz.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 员工产量统计对象 TWIN_EMP_CALC
+ *
+ * @author wukai
+ * @date 2025-01-18
+ */
+@ApiModel(value = "TwinAllVO", description = "全厂首页统计视图")
+@Data
+public class TwinAllVO {
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty("当前库存")
+    private Map<String, Object> stock;
+
+    @ApiModelProperty("月平均")
+    private AvgMonthVO avgMonth;
+
+    @ApiModelProperty("生产情况")
+    private CurrYieldVO currYield;
+
+    @ApiModelProperty("生产趋势")
+    private List<ProdTradeVO> prodTrade;
+
+    @ApiModelProperty("能耗趋势")
+    private List<EnergyTradeVO> energyTrade;
+}

+ 48 - 0
jjt-biz/src/main/java/com/jjt/utils/EnvPowerService.java

@@ -0,0 +1,48 @@
+package com.jjt.utils;
+
+import cn.hutool.crypto.digest.MD5;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.http.Method;
+import cn.hutool.json.JSONObject;
+import com.jjt.common.constant.CacheConstants;
+import com.jjt.common.core.redis.RedisCache;
+import com.jjt.common.core.text.Convert;
+import com.jjt.common.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * IotServiceImpl$
+ *
+ * @author wukai
+ * @date 2024/5/4 20:35
+ */
+@Component
+@Slf4j
+public class EnvPowerService {
+    @Resource
+    private RedisCache redisCache;
+    private String uri = "http://192.168.79.21:18080/truelove/energy/manage/monthlyFinancialStatement";
+
+    /**
+     * 查询数据
+     *
+     * @param date sql语句
+     * @return JSON数据
+     */
+    public JSONObject query(String date) {
+        JSONObject object = new JSONObject();
+        object.set("selectTime", date);
+        object.set("timeType", "DAY");
+        HttpRequest request = HttpUtil.createPost(uri);
+        request.setMethod(Method.POST);
+        request.body(object.toString());
+        return IotTools.getData(request);
+    }
+
+}

+ 16 - 0
jjt-common/src/main/java/com/jjt/common/constant/CacheConstants.java

@@ -50,6 +50,22 @@ public class CacheConstants {
      * 库存情况
      */
     public static final String VMS_STOCK = TWIN + "vmsStock";
+    /**
+     * 月平均
+     */
+    public static final String AVG_MONTH = TWIN + "avgMonth";
+    /**
+     * 当前生产情况
+     */
+    public static final String CURR_YIELD = TWIN + "currYield";
+    /**
+     * 生产趋势
+     */
+    public static final String PROD_TRADE = TWIN + "prodTrade";
+    /**
+     * 能耗趋势
+     */
+    public static final String ENERGY_TRADE = TWIN + "energyTrade";
 
     /**
      * iot token