From 3855accc61a4b5c853a9fdb2fc1305964b5a20de Mon Sep 17 00:00:00 2001 From: hongawen <83944980@qq.com> Date: Sun, 25 Jun 2023 21:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pqs-common/common-echarts/pom.xml | 6 +- .../com/njcn/echarts/json/BarGenerator.java | 114 ++++++++++++ .../com/njcn/echarts/json/LineGenerator.java | 164 ++++-------------- .../com/njcn/echarts/json/PieGenerator.java | 83 +++++++++ .../com/njcn/echarts/util/DrawPicUtil.java | 34 +++- .../majornetwork/EventReportService.java | 2 +- .../Impl/EventReportServiceImpl.java | 92 +++++----- .../majornetwork/Impl/ReportServiceImpl.java | 7 +- 8 files changed, 309 insertions(+), 193 deletions(-) create mode 100644 pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/BarGenerator.java create mode 100644 pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/PieGenerator.java diff --git a/pqs-common/common-echarts/pom.xml b/pqs-common/common-echarts/pom.xml index 65c865508..cc5de3941 100644 --- a/pqs-common/common-echarts/pom.xml +++ b/pqs-common/common-echarts/pom.xml @@ -33,9 +33,9 @@ ${project.version} - org.icepear.echarts - echarts-java - 1.0.7 + com.njcn + echarts5-java + 0.0.1 diff --git a/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/BarGenerator.java b/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/BarGenerator.java new file mode 100644 index 000000000..2fbb9d1a9 --- /dev/null +++ b/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/BarGenerator.java @@ -0,0 +1,114 @@ +package com.njcn.echarts.json; + +import com.njcn.echarts.pojo.constant.PicCommonData; +import org.icepear.echarts.Option; +import org.icepear.echarts.charts.bar.BarLabel; +import org.icepear.echarts.charts.bar.BarSeries; +import org.icepear.echarts.charts.bar3D.Bar3DSeries; +import org.icepear.echarts.components.coord.AxisNameTextStyle; +import org.icepear.echarts.components.coord.SplitLine; +import org.icepear.echarts.components.coord.cartesian.CategoryAxis; +import org.icepear.echarts.components.coord.cartesian.ValueAxis; +import org.icepear.echarts.components.grid.Grid; +import org.icepear.echarts.components.grid3D.Grid3D; +import org.icepear.echarts.components.grid3D.ViewControl; +import org.icepear.echarts.components.inRange.InRange; +import org.icepear.echarts.components.legend.Legend; +import org.icepear.echarts.components.series.LineStyle; +import org.icepear.echarts.components.title.Title; +import org.icepear.echarts.components.visualMap.ContinousVisualMap; +import org.icepear.echarts.origin.util.SeriesOption; +import org.icepear.echarts.render.Engine; + +import java.util.List; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2023年06月25日 20:10 + */ +public class BarGenerator { + + private final static Engine ENGINE = new Engine(); + + + /*** + * 生成月份统计 + * @author wr + * @date 2023/6/21 10:06 + */ + public static String generateMonthOption(List xName, List times, String year, Integer flag) { + xName.set(0, xName.get(0) + "\n" + "(" + year + ")"); + String name; + Option monthOption = new Option(); + //取消渲染动画 + monthOption.setAnimation(false); + //背景色 + monthOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); + //标题 + if (flag == 0) { + monthOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("月份统计")); + name = "月份"; + } else { + monthOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("天数统计")); + name = "天数"; + } + //上下左右的图内间距 + monthOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("60px").setBottom("20px")); + //设置图例 + monthOption.setLegend(new Legend().setData(new String[]{"暂降次数"}).setTop("26px").setLeft(10).setBottom("94%").setShow(true)); + //设置图例对应的颜色 + monthOption.setColor(new String[]{"#FF8C00"}); + //横坐标 + monthOption.setXAxis(new CategoryAxis() + .setBoundaryGap(true) + .setName(name) + .setNameTextStyle(new AxisNameTextStyle().setFontStyle("15px")) + .setData(xName.toArray()) + ); + //纵坐标 + monthOption.setYAxis(new ValueAxis[]{ + new ValueAxis() + .setName("次") + .setType("value") + }); + + //配置暂降次数 + BarSeries probability = new BarSeries() + .setName("暂降次数") + .setLabel(new BarLabel().setShow(true).setColor("#8B008B")) + .setData(times); + monthOption.setSeries(new SeriesOption[]{probability}); + return ENGINE.renderJsonOption(monthOption); + } + + + /*** + * 生成暂降密度图 + * @author hongawen + * @date 2023/6/25 20:12 + */ + public static String generateEventDensity(Number[][] data) { + Option option3D = new Option(); + option3D.setBackgroundColor("#fff"); + option3D.setTitle(new Title().setText("暂降密度图").setX("center")); + option3D.setVisualMap(new ContinousVisualMap().setMax(20).setShow(false).setInRange(new InRange().setColor(new String[]{"#313695", "#00BB00", "#ff8000", "#a50026"}))); + option3D.setXAxis3D(new CategoryAxis().setName("剩余电压(%)").setData(new String[]{"0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100"})); + option3D.setYAxis3D(new CategoryAxis() + .setName("持续时间(cyc)") + .setData(new String[]{"1cyc", "2cyc", "3cyc", "4cyc", "5cyc", "6~10cyc", "10~20cyc", "20~30cyc", "30~60cyc"}) + .setSplitLine(new SplitLine().setLineStyle(new LineStyle().setColor("#").setType("dashed").setOpacity(0.5))) + ); + option3D.setZAxis3D(new ValueAxis().setSplitNumber(8).setMinInterval(5).setName("次数")); + option3D.setGrid3D(new Grid3D() + .setViewControl(new ViewControl().setBeta(8).setAlpha(5)) + .setBoxWidth(200) + .setBoxDepth(80) + ); + Bar3DSeries bar3DSeries = new Bar3DSeries() + .setData(data) + .setShading("realistic"); + option3D.setSeries(new SeriesOption[]{bar3DSeries}); + return ENGINE.renderJsonOption(option3D); + } +} diff --git a/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/LineGenerator.java b/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/LineGenerator.java index 99d1a8582..c7dc3f489 100644 --- a/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/LineGenerator.java +++ b/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/LineGenerator.java @@ -20,6 +20,7 @@ import org.icepear.echarts.components.grid.Grid; import org.icepear.echarts.components.legend.Legend; import org.icepear.echarts.components.title.Title; import org.icepear.echarts.components.tooltip.Tooltip; +import org.icepear.echarts.components.visualMap.ContinousVisualMap; import org.icepear.echarts.origin.util.SeriesOption; import org.icepear.echarts.render.Engine; @@ -95,23 +96,23 @@ public class LineGenerator { * @date 2023/6/21 10:06 */ public static String generateF47Option(TolerateData tolerateData) { - Option iticOption = new Option(); + Option f47Option = new Option(); //取消渲染动画 - iticOption.setAnimation(false); + f47Option.setAnimation(false); //背景色 - iticOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); + f47Option.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); //标题 - iticOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("SEMI F47曲线")); + f47Option.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("SEMI F47曲线")); //上下左右的图内间距 - iticOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("40px").setBottom("10%")); + f47Option.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("40px").setBottom("10%")); //设置图例 - iticOption.setLegend(new Legend().setData(new String[]{"边界线", "可容忍事件", "不可容忍事件"}).setTop("26px").setLeft(0).setBottom("94%")); + f47Option.setLegend(new Legend().setData(new String[]{"边界线", "可容忍事件", "不可容忍事件"}).setTop("26px").setLeft(0).setBottom("94%")); //设置图例对应的颜色 - iticOption.setColor(new String[]{"yellow", "green", "red"}); + f47Option.setColor(new String[]{"yellow", "green", "red"}); //横坐标 - iticOption.setXAxis(new LogAxis().setMin("0.001").setMax("1000").setSplitLine(new SplitLine().setShow(false)).setName("s")); + f47Option.setXAxis(new LogAxis().setMin("0.001").setMax("1000").setSplitLine(new SplitLine().setShow(false)).setName("s")); //纵坐标 - iticOption.setYAxis(new ValueAxis().setName("%").setMinInterval(0.1).setSplitNumber(10).setMax(100)); + f47Option.setYAxis(new ValueAxis().setName("%").setMinInterval(0.1).setSplitNumber(10).setMax(100)); //处理边界线 LineSeries borderLimit = new LineSeries() .setName("边界线") @@ -128,8 +129,8 @@ public class LineGenerator { .setName("不可容忍事件") .setSymbol("circle") .setData(tolerateData.getUnTolerateData()); - iticOption.setSeries(new SeriesOption[]{borderLimit, tolerate, unTolerate}); - return ENGINE.renderJsonOption(iticOption); + f47Option.setSeries(new SeriesOption[]{borderLimit, tolerate, unTolerate}); + return ENGINE.renderJsonOption(f47Option); } @@ -139,24 +140,24 @@ public class LineGenerator { * @date 2023/6/21 10:06 */ public static String generateEventAmplitudeOption(List ylinedata, List ybardata) { - Option iticOption = new Option(); + Option eventAmplitudeOption = new Option(); //取消渲染动画 - iticOption.setAnimation(false); + eventAmplitudeOption.setAnimation(false); //背景色 - iticOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); + eventAmplitudeOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); //标题 - iticOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("暂降幅值的概率分布")); + eventAmplitudeOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("暂降幅值的概率分布")); //设置图例 - iticOption.setLegend(new Legend().setData(new String[]{"概率分布", "占比"}).setLeft(10).setShow(true)); + eventAmplitudeOption.setLegend(new Legend().setData(new String[]{"概率分布", "占比"}).setLeft(10).setShow(true)); //横坐标 - iticOption.setXAxis(new CategoryAxis() + eventAmplitudeOption.setXAxis(new CategoryAxis() .setBoundaryGap(true) .setName("暂降幅值") .setNameTextStyle(new AxisNameTextStyle().setFontStyle("15px")) .setData(new String[]{"0", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%"}) ); //纵坐标 - iticOption.setYAxis(new ValueAxis[]{ + eventAmplitudeOption.setYAxis(new ValueAxis[]{ new ValueAxis() .setName("%") .setNameTextStyle(new AxisNameTextStyle().setFontStyle("15px")) @@ -173,8 +174,8 @@ public class LineGenerator { .setBarWidth(30) .setData(ybardata); - iticOption.setSeries(new SeriesOption[]{probability, proportion}); - return ENGINE.renderJsonOption(iticOption); + eventAmplitudeOption.setSeries(new SeriesOption[]{probability, proportion}); + return ENGINE.renderJsonOption(eventAmplitudeOption); } /*** @@ -183,24 +184,24 @@ public class LineGenerator { * @date 2023/6/21 10:06 */ public static String generatePersistentTimeOption(List ylinedata, List ybardata) { - Option iticOption = new Option(); + Option persistentTimeOption = new Option(); //取消渲染动画 - iticOption.setAnimation(false); + persistentTimeOption.setAnimation(false); //背景色 - iticOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); + persistentTimeOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); //标题 - iticOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("持续时间的概率分布")); + persistentTimeOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("持续时间的概率分布")); //设置图例 - iticOption.setLegend(new Legend().setData(new String[]{"概率分布", "占比"}).setLeft(10).setShow(true)); + persistentTimeOption.setLegend(new Legend().setData(new String[]{"概率分布", "占比"}).setLeft(10).setShow(true)); //横坐标 - iticOption.setXAxis(new CategoryAxis() + persistentTimeOption.setXAxis(new CategoryAxis() .setBoundaryGap(true) .setName("暂态持续时间(s)") .setNameTextStyle(new AxisNameTextStyle().setFontStyle("15px")) .setData(new String[]{"0.01", "0.1", "0.25", "0.5", "1", "3", "20", "60", "180"}) ); //纵坐标 - iticOption.setYAxis(new ValueAxis[]{ + persistentTimeOption.setYAxis(new ValueAxis[]{ new ValueAxis() .setName("%") .setNameTextStyle(new AxisNameTextStyle().setFontStyle("15px")) @@ -217,114 +218,9 @@ public class LineGenerator { .setBarWidth(30) .setData(ybardata); - iticOption.setSeries(new SeriesOption[]{probability, proportion}); - return ENGINE.renderJsonOption(iticOption); + persistentTimeOption.setSeries(new SeriesOption[]{probability, proportion}); + return ENGINE.renderJsonOption(persistentTimeOption); } - /*** - * 生成月份统计 - * @author wr - * @date 2023/6/21 10:06 - */ - public static String generateMonthOption(List xName, List times, String year, Integer flag) { - xName.set(0, xName.get(0) + "\n" + "(" + year + ")"); - String name = ""; - Option iticOption = new Option(); - //取消渲染动画 - iticOption.setAnimation(false); - //背景色 - iticOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); - //标题 - if (flag == 0) { - iticOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("月份统计")); - name = "月份"; - } else { - iticOption.setTitle(new Title().setLeft(PicCommonData.CENTER).setText("天数统计")); - name = "天数"; - } - //上下左右的图内间距 - iticOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("60px").setBottom("20px")); - //设置图例 - iticOption.setLegend(new Legend().setData(new String[]{"暂降次数"}).setTop("26px").setLeft(10).setBottom("94%").setShow(true)); - //设置图例对应的颜色 - iticOption.setColor(new String[]{"#FF8C00"}); - //横坐标 - iticOption.setXAxis(new CategoryAxis() - .setBoundaryGap(true) - .setName(name) - .setNameTextStyle(new AxisNameTextStyle().setFontStyle("15px")) - .setData(xName.toArray()) - ); - //纵坐标 - iticOption.setYAxis(new ValueAxis[]{ - new ValueAxis() - .setName("次") - .setType("value") - }); - //配置暂降次数 - BarSeries probability = new BarSeries() - .setName("暂降次数") - .setLabel(new BarLabel().setShow(true).setColor("#8B008B")) - .setData(times); - iticOption.setSeries(new SeriesOption[]{probability}); - return ENGINE.renderJsonOption(iticOption); - } - - /*** - * 生成暂降原因 - * @author wr - * @date 2023/6/21 10:06 - */ - public static String generateReasonOption(List xName, List> map2) { - - Option iticOption = new Option(); - //取消渲染动画 - iticOption.setAnimation(false); - //背景色 - iticOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); - //标题 - iticOption.setTitle(new Title().setRight("10%").setText("暂降原因")); - //上下左右的图内间距 - iticOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("60px").setBottom("20px")); - //设置图例 - iticOption.setLegend(new Legend().setOrient("vertical").setData(xName.toArray()).setTop("26px").setLeft(10).setBottom("94%").setShow(true)); - String s = map2.toString(); - //配置暂降次数 - PieSeries probability = new PieSeries() - .setType("pie") - .setName("暂降原因") - .setLabel(new PieLabel().setFormatter("{b}:{d}%")) - .setData(map2); - iticOption.setSeries(new SeriesOption[]{probability}); - return ENGINE.renderJsonOption(iticOption); - } - - /*** - * 生成暂降类型 - * @author wr - * @date 2023/6/21 10:06 - */ - public static String generateTypeOption(List xName, List> map) { - - Option iticOption = new Option(); - //取消渲染动画 - iticOption.setAnimation(false); - //背景色 - iticOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); - //标题 - iticOption.setTitle(new Title().setRight("10%").setText("暂降类型")); - //上下左右的图内间距 - iticOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("60px").setBottom("20px")); - //设置图例 - iticOption.setLegend(new Legend().setOrient("vertical").setData(xName.toArray()).setTop("26px").setLeft(10).setBottom("94%").setShow(true)); - //配置暂降次数 - PieSeries probability = new PieSeries() - .setType("pie") - .setName("暂降类型") - .setLabel(new PieLabel().setFormatter("{b}:{d}%")) - .setData(map); - iticOption.setSeries(new SeriesOption[]{probability}); - return ENGINE.renderJsonOption(iticOption); - } } diff --git a/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/PieGenerator.java b/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/PieGenerator.java new file mode 100644 index 000000000..f75579115 --- /dev/null +++ b/pqs-common/common-echarts/src/main/java/com/njcn/echarts/json/PieGenerator.java @@ -0,0 +1,83 @@ +package com.njcn.echarts.json; + +import com.njcn.echarts.pojo.constant.PicCommonData; +import org.icepear.echarts.Option; +import org.icepear.echarts.charts.pie.PieLabel; +import org.icepear.echarts.charts.pie.PieSeries; +import org.icepear.echarts.components.grid.Grid; +import org.icepear.echarts.components.legend.Legend; +import org.icepear.echarts.components.title.Title; +import org.icepear.echarts.origin.util.SeriesOption; +import org.icepear.echarts.render.Engine; + +import java.util.List; +import java.util.Map; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2023年06月25日 21:42 + */ +public class PieGenerator { + + private final static Engine ENGINE = new Engine(); + + + /*** + * 生成暂降原因 + * @author wr + * @date 2023/6/21 10:06 + */ + public static String generateReasonOption(List xName, List> map2) { + + Option reasonOption = new Option(); + //取消渲染动画 + reasonOption.setAnimation(false); + //背景色 + reasonOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); + //标题 + reasonOption.setTitle(new Title().setRight("10%").setText("暂降原因")); + //上下左右的图内间距 + reasonOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("60px").setBottom("20px")); + //设置图例 + reasonOption.setLegend(new Legend().setOrient("vertical").setData(xName.toArray()).setTop("26px").setLeft(10).setBottom("94%").setShow(true)); + String s = map2.toString(); + //配置暂降次数 + PieSeries probability = new PieSeries() + .setType("pie") + .setName("暂降原因") + .setLabel(new PieLabel().setFormatter("{b}:{d}%")) + .setData(map2); + reasonOption.setSeries(new SeriesOption[]{probability}); + return ENGINE.renderJsonOption(reasonOption); + } + + /*** + * 生成暂降类型 + * @author wr + * @date 2023/6/21 10:06 + */ + public static String generateTypeOption(List xName, List> map) { + + Option typeOption = new Option(); + //取消渲染动画 + typeOption.setAnimation(false); + //背景色 + typeOption.setBackgroundColor(PicCommonData.PIC_BACK_COLOR); + //标题 + typeOption.setTitle(new Title().setRight("10%").setText("暂降类型")); + //上下左右的图内间距 + typeOption.setGrid(new Grid().setTop("80px").setLeft("40px").setRight("60px").setBottom("20px")); + //设置图例 + typeOption.setLegend(new Legend().setOrient("vertical").setData(xName.toArray()).setTop("26px").setLeft(10).setBottom("94%").setShow(true)); + //配置暂降次数 + PieSeries probability = new PieSeries() + .setType("pie") + .setName("暂降类型") + .setLabel(new PieLabel().setFormatter("{b}:{d}%")) + .setData(map); + typeOption.setSeries(new SeriesOption[]{probability}); + return ENGINE.renderJsonOption(typeOption); + } + +} diff --git a/pqs-common/common-echarts/src/main/java/com/njcn/echarts/util/DrawPicUtil.java b/pqs-common/common-echarts/src/main/java/com/njcn/echarts/util/DrawPicUtil.java index d08193606..b9217a4e7 100644 --- a/pqs-common/common-echarts/src/main/java/com/njcn/echarts/util/DrawPicUtil.java +++ b/pqs-common/common-echarts/src/main/java/com/njcn/echarts/util/DrawPicUtil.java @@ -2,7 +2,9 @@ package com.njcn.echarts.util; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.njcn.echarts.json.BarGenerator; import com.njcn.echarts.json.LineGenerator; +import com.njcn.echarts.json.PieGenerator; import com.njcn.web.utils.RestTemplateUtil; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -46,8 +48,8 @@ public class DrawPicUtil { */ private String drawPic(String option, int width, int height) { JSONObject jsonObject = new JSONObject(); - jsonObject.set("width", width == 0 ? 925 : width); - jsonObject.set("height", height == 0 ? 300 : height); + jsonObject.set("width", width == 0 ? 950 : width); + jsonObject.set("height", height == 0 ? 400 : height); jsonObject.set("option", JSONUtil.parseObj(option)); ResponseEntity picResult = RestTemplateUtil.post(URL, jsonObject, String.class); return Objects.requireNonNull(picResult.getBody()).indexOf("image/png") > 0 ? picResult.getBody() : ""; @@ -160,7 +162,7 @@ public class DrawPicUtil { * @return String base64数据 */ public String drawMonth(List xName, List times, String year, Integer flag, int width, int height) { - String monthJson = LineGenerator.generateMonthOption( xName, times, year, flag); + String monthJson = BarGenerator.generateMonthOption( xName, times, year, flag); return drawPic(monthJson, width, height); } @@ -181,7 +183,7 @@ public class DrawPicUtil { * @return String base64数据 */ public String drawReason(List xname, List> map2, int width, int height) { - String monthJson = LineGenerator.generateReasonOption(xname, map2); + String monthJson = PieGenerator.generateReasonOption(xname, map2); return drawPic(monthJson, width, height); } @@ -202,7 +204,29 @@ public class DrawPicUtil { * @return String base64数据 */ public String drawType(List xname, List> map2, int width, int height) { - String monthJson = LineGenerator.generateTypeOption(xname, map2); + String monthJson = PieGenerator.generateTypeOption(xname, map2); return drawPic(monthJson, width, height); } + + + /*** + * 绘制生成暂降密度图 + * @author hongawen + * @date 2023/6/21 11:01 + * @return String base64数据 + */ + public String drawEventDensity(Number[][] data) { + return drawEventDensity(data, 0, 0); + } + + /*** + * 绘制生成暂降类型图 + * @author hongawen + * @date 2023/6/21 11:01 + * @return String base64数据 + */ + public String drawEventDensity(Number[][] data, int width, int height) { + String eventDensityJson = BarGenerator.generateEventDensity(data); + return drawPic(eventDensityJson, width, height); + } } diff --git a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/EventReportService.java b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/EventReportService.java index 0c6a363ec..96fe0dcd2 100644 --- a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/EventReportService.java +++ b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/EventReportService.java @@ -74,5 +74,5 @@ public interface EventReportService { * @param info * @return */ - List getCoords(List info); + Integer[][] getCoords(List info); } diff --git a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/EventReportServiceImpl.java b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/EventReportServiceImpl.java index ec9f6dd80..5ba553bdb 100644 --- a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/EventReportServiceImpl.java +++ b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/EventReportServiceImpl.java @@ -1,4 +1,5 @@ package com.njcn.event.service.majornetwork.Impl; + import com.google.common.collect.Lists; import cn.hutool.core.date.DateUtil; @@ -822,7 +823,7 @@ public class EventReportServiceImpl implements EventReportService { } @Override - public List getReasonTypeTime(StatisticsParam statisticsParam,List info) throws ParseException { + public List getReasonTypeTime(StatisticsParam statisticsParam, List info) throws ParseException { List list = new ArrayList<>(); //参数 StringBuilder builder1 = new StringBuilder(); @@ -837,7 +838,7 @@ public class EventReportServiceImpl implements EventReportService { Integer endMonth = Integer.parseInt(endTime.substring(5, 7)); Integer startYear = Integer.parseInt(startTime.substring(0, 4)); Integer endYear = Integer.parseInt(endTime.substring(0, 4)); - if (statisticsParam.getFlag()==0){ + if (statisticsParam.getFlag() == 0) { while (!startYear.equals(endYear) && !startMonth.equals(endMonth)) { builder1.delete(0, builder1.length()); builder2.delete(0, builder2.length()); @@ -847,14 +848,14 @@ public class EventReportServiceImpl implements EventReportService { } else { builder2.append(startYear).append("-").append(startMonth + 1).append("-").append(startDays); } - query = MonitorQuery(new StatisticsParam(statisticsParam.getLineIndex(),builder1.toString(), builder2.toString(), statisticsParam.getFlag())); + query = MonitorQuery(new StatisticsParam(statisticsParam.getLineIndex(), builder1.toString(), builder2.toString(), statisticsParam.getFlag())); InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper(); List eventDetailList = influxDBResultMapper.toPOJO(query, EventDetail.class); long count = eventDetailList.stream().filter(x -> x.getEventType() == "1").count(); if (startMonth < 10) { - list.add(new TimeVO(null, null,"", "0" + startMonth.toString(), count+"", startYear.toString(), startYear.toString()+"-"+"0"+startMonth.toString())); + list.add(new TimeVO(null, null, "", "0" + startMonth.toString(), count + "", startYear.toString(), startYear.toString() + "-" + "0" + startMonth.toString())); } else { - list.add(new TimeVO(null, null,"", startMonth.toString(), count+"", startYear.toString(),startYear.toString()+"-"+startMonth.toString())); + list.add(new TimeVO(null, null, "", startMonth.toString(), count + "", startYear.toString(), startYear.toString() + "-" + startMonth.toString())); } startMonth++; if (startMonth == 13) { @@ -866,63 +867,62 @@ public class EventReportServiceImpl implements EventReportService { builder2.delete(0, builder2.length()); builder1.append(startYear).append("-").append(startMonth).append("-").append(startDays); builder2.append(startYear).append("-").append(startMonth).append("-").append(endDays); - query = MonitorQuery(new StatisticsParam(statisticsParam.getLineIndex(),builder1.toString(), builder2.toString(), statisticsParam.getFlag())); + query = MonitorQuery(new StatisticsParam(statisticsParam.getLineIndex(), builder1.toString(), builder2.toString(), statisticsParam.getFlag())); InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper(); List eventDetailList = influxDBResultMapper.toPOJO(query, EventDetail.class); long count1 = eventDetailList.stream().filter(x -> x.getEventType() == "1").count(); if (startMonth < 10) { - list.add(new TimeVO(null, null,"", "0" + startMonth.toString(), count1+"", startYear.toString(), startYear.toString()+"-"+"0"+startMonth.toString())); + list.add(new TimeVO(null, null, "", "0" + startMonth.toString(), count1 + "", startYear.toString(), startYear.toString() + "-" + "0" + startMonth.toString())); } else { - list.add(new TimeVO(null, null,"", startMonth.toString(), count1+"", startYear.toString(),startYear.toString()+"-"+startMonth.toString())); + list.add(new TimeVO(null, null, "", startMonth.toString(), count1 + "", startYear.toString(), startYear.toString() + "-" + startMonth.toString())); } return list; - } - else { + } else { QueryResult monitorQuery = MonitorQuery(statisticsParam); InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper(); List eventDetailList = influxDBResultMapper.toPOJO(monitorQuery, EventDetailNew.class); - Map> map = eventDetailList.stream().filter(x -> x.getEventType()=="1").collect(Collectors.groupingBy(s -> s.getStartTime().substring(0, 10))); + Map> map = eventDetailList.stream().filter(x -> x.getEventType() == "1").collect(Collectors.groupingBy(s -> s.getStartTime().substring(0, 10))); Set keySet = map.keySet(); LocalDate parse1 = LocalDate.parse(startTime); LocalDate parse2 = LocalDate.parse(endTime); - while (!parse1.equals(parse2.plus(1, ChronoUnit.DAYS))){ - if (keySet.contains(parse1.toString())){ + while (!parse1.equals(parse2.plus(1, ChronoUnit.DAYS))) { + if (keySet.contains(parse1.toString())) { List eventDetailNews = map.get(parse1.toString()); TimeVO timeVO = new TimeVO(); - timeVO.setTimes(eventDetailNews.size()+""); - if (parse1.getDayOfMonth()<10){ - timeVO.setDay("0"+parse1.getDayOfMonth()+""); - }else { - timeVO.setDay(parse1.getDayOfMonth()+""); + timeVO.setTimes(eventDetailNews.size() + ""); + if (parse1.getDayOfMonth() < 10) { + timeVO.setDay("0" + parse1.getDayOfMonth() + ""); + } else { + timeVO.setDay(parse1.getDayOfMonth() + ""); } - timeVO.setYear(parse1.getYear()+""); - if (parse1.getMonthValue()<10){ - timeVO.setMonth("0"+parse1.getMonthValue()+""); - }else { - timeVO.setMonth(parse1.getMonthValue()+""); + timeVO.setYear(parse1.getYear() + ""); + if (parse1.getMonthValue() < 10) { + timeVO.setMonth("0" + parse1.getMonthValue() + ""); + } else { + timeVO.setMonth(parse1.getMonthValue() + ""); } timeVO.setFulltime(parse1.toString()); list.add(timeVO); - }else { + } else { TimeVO timeVO = new TimeVO(); timeVO.setTimes("0"); - if (parse1.getDayOfMonth()<10){ - timeVO.setDay("0"+parse1.getDayOfMonth()+""); - }else { - timeVO.setDay(parse1.getDayOfMonth()+""); + if (parse1.getDayOfMonth() < 10) { + timeVO.setDay("0" + parse1.getDayOfMonth() + ""); + } else { + timeVO.setDay(parse1.getDayOfMonth() + ""); } - timeVO.setYear(parse1.getYear()+""); - if (parse1.getMonthValue()<10){ - timeVO.setMonth("0"+parse1.getMonthValue()+""); - }else { - timeVO.setMonth(parse1.getMonthValue()+""); + timeVO.setYear(parse1.getYear() + ""); + if (parse1.getMonthValue() < 10) { + timeVO.setMonth("0" + parse1.getMonthValue() + ""); + } else { + timeVO.setMonth(parse1.getMonthValue() + ""); } timeVO.setFulltime(parse1.toString()); list.add(timeVO); } - parse1=parse1.plus(1, ChronoUnit.DAYS); + parse1 = parse1.plus(1, ChronoUnit.DAYS); } return list; } @@ -931,10 +931,11 @@ public class EventReportServiceImpl implements EventReportService { /** * 暂降事件点图 + * * @author wr */ @Override - public List getPlot(List info,List reasonData,List typeData) { + public List getPlot(List info, List reasonData, List typeData) { //添加detail for (EventDetail detail : info) { for (DictData data : reasonData) { @@ -952,7 +953,7 @@ public class EventReportServiceImpl implements EventReportService { } @Override - public StatisticVO getStatistic(List info,List reasonData,ListtypeData) { + public StatisticVO getStatistic(List info, List reasonData, List typeData) { StatisticVO result = new StatisticVO(); List list = new ArrayList<>(); List reasonsVOS = new ArrayList<>(); @@ -963,13 +964,13 @@ public class EventReportServiceImpl implements EventReportService { //添加detail for (EventDetail detail : info) { for (DictData data : reasonData) { - reasonMap.put(data.getName(),0); + reasonMap.put(data.getName(), 0); if (detail.getAdvanceReason().equals(data.getId())) { detail.setAdvanceReason(data.getName()); } } for (DictData data : typeData) { - typeMap.put(data.getName(),0); + typeMap.put(data.getName(), 0); if (detail.getAdvanceType().equals(data.getId())) { detail.setAdvanceType(data.getName()); } @@ -1002,17 +1003,18 @@ public class EventReportServiceImpl implements EventReportService { return result; } + @Override - public List getCoords(List info) { - List result = new ArrayList<>(); + public Integer[][] getCoords(List info) { + Integer[][] eventDensityData = new Integer[90][3]; for (int i = 0; i < 10; i++) { +// eventDensityData[i] = new Integer[]{i % 10, i % 9, 0}; for (int j = 0; j < 9; j++) { - result.add(new CoordsVO(i, j, 0)); + eventDensityData[i * 9 + j] = new Integer[]{i, j % 9, 0}; } } for (int i = 0; i < info.size(); i++) { Integer index = null; - CoordsVO dto = new CoordsVO(); if (info.get(i).getFeatureAmplitude() >= 0 && info.get(i).getFeatureAmplitude() <= 0.1) { if (info.get(i).getDuration() / 1000 > 0 && info.get(i).getDuration() / 1000 <= 0.020) { index = 0; @@ -1215,11 +1217,11 @@ public class EventReportServiceImpl implements EventReportService { } } if (Objects.nonNull(index)) { - CoordsVO coordsVO = result.get(index); - coordsVO.setZ(coordsVO.getZ() + 1); + Integer[] temNumber = eventDensityData[index]; + temNumber[2] = temNumber[2] + 1; } } - return result; + return eventDensityData; } /** diff --git a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/ReportServiceImpl.java b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/ReportServiceImpl.java index 7883417d8..5cb19cd33 100644 --- a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/ReportServiceImpl.java +++ b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/ReportServiceImpl.java @@ -1848,11 +1848,8 @@ public class ReportServiceImpl implements ReportService { int two = 1; if (exportParam.isMdtx()) { createTitle(doc, "4." + i + "." + two + " 暂降密度点图", "标题 3", 400, 15); - List coords = eventReportService.getCoords(info); - Integer[][] a = new Integer[87][]; - HashMap map = new HashMap<>(); - map.put("data", JSONArray.fromObject(coords).toString()); - String str = getStr("bar10.ftl", map); + Integer[][] eventDensityData = eventReportService.getCoords(info); + String str = drawPicUtil.drawEventDensity(eventDensityData); createPic(doc, str, "暂降密度图"); two++; }