Przeglądaj źródła

施工进度表

yangyj 1 rok temu
rodzic
commit
5a39330805

+ 89 - 13
blade-service/blade-manager/src/main/java/com/mixsmart/utils/FormulaUtils.java

@@ -30,16 +30,11 @@ import org.jfree.chart.ChartFactory;
 import org.jfree.chart.ChartPanel;
 import org.jfree.chart.ChartUtils;
 import org.jfree.chart.JFreeChart;
-import org.jfree.chart.axis.CategoryAxis;
-import org.jfree.chart.axis.NumberAxis;
-import org.jfree.chart.axis.NumberTickUnit;
-import org.jfree.chart.axis.ValueAxis;
-import org.jfree.chart.plot.CategoryPlot;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.chart.plot.ValueMarker;
-import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.axis.*;
+import org.jfree.chart.plot.*;
 import org.jfree.chart.renderer.category.BarRenderer;
 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
+import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
 import org.jfree.chart.renderer.xy.XYSplineRenderer;
 import org.jfree.chart.title.TextTitle;
 import org.jfree.data.category.CategoryDataset;
@@ -1253,6 +1248,8 @@ public class FormulaUtils {
         try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
             BufferedImage bufferedImage = chart.createBufferedImage(800, 600);
             ImageIO.write(bufferedImage, "png", out);
+            FileOutputStream fos = new FileOutputStream("C:/Users/yangyj/Desktop/Swap_space/poi_statistics.png");
+            fos.write(out.toByteArray());
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -1277,8 +1274,7 @@ public class FormulaUtils {
         CategoryDataset dataset = createDataset(actualProgress,plannedProgress);
         JFreeChart chart = createChart(dataset);
         try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
-            BufferedImage bufferedImage = chart.createBufferedImage(800, 600);
-            ImageIO.write(bufferedImage, "png", out);
+            ChartUtils.writeChartAsPNG(out, chart, 800, 600);
             return out.toByteArray();
         } catch (IOException e) {
             e.printStackTrace();
@@ -1286,10 +1282,11 @@ public class FormulaUtils {
         return null;
     }
 
-    public static String  chapterScheduleChartUrl( double[] actualProgress ,double[] plannedProgress){
-        CategoryDataset dataset = createDataset(actualProgress,plannedProgress);
-        JFreeChart chart = createChart(dataset);
+    public static String  chapterScheduleChartUrl( double[] actual ,double[] planned){
+        /*CategoryDataset dataset = createDataset(actualProgress,plannedProgress);
+        JFreeChart chart = createChart(dataset);*/
           try {
+              JFreeChart chart =chartTest(actual,planned);
               String path= getSysLocalFileUrl() + "/pdf//"+SnowFlakeUtil.getId()+".png";
             ChartUtils.saveChartAsPNG(new File(path), chart, 800, 600);
             return path;
@@ -1300,6 +1297,85 @@ public class FormulaUtils {
     }
 
 
+   public static JFreeChart  chartTest(double[] actualProgressData ,double[] plannedProgressData) throws IOException {
+       // 创建数据集
+       XYSeries actualProgress = new XYSeries("实际进度");
+       XYSeries plannedProgress = new XYSeries("计划进度");
+
+    /*   // 数据
+       double[][] actualProgressData = {{1, 10}, {2, 15}, {3, 18}, {4, 27}, {5, 35}, {6, 48}};
+       double[][] plannedProgressData = {{1, 10}, {2, 15}, {3, 20}, {4, 25}, {5, 30}, {6, 35}};*/
+
+       // 填充数据集
+       for (int i = 0; i < actualProgressData.length; i++) {
+           actualProgress.add(i, actualProgressData[i]);
+           plannedProgress.add(i, plannedProgressData[i]);
+       }
+
+       XYSeriesCollection dataset = new XYSeriesCollection();
+       dataset.addSeries(actualProgress);
+       dataset.addSeries(plannedProgress);
+
+       // 创建图表
+       JFreeChart chart = ChartFactory.createXYLineChart(
+               "施工进度对比图", // 标题
+               "日期进度 (%)", // X轴标签
+               "完成量 (%)", // Y轴标签
+               dataset, // 数据集
+               org.jfree.chart.plot.PlotOrientation.VERTICAL, // 方向
+               true, // 显示图例
+               true, // 生成工具
+               false // 生成URL
+       );
+
+       // 设置中文字体以避免乱码
+       Font font = new Font("宋体", Font.PLAIN, 12);
+       chart.getTitle().setFont(font);
+       chart.getLegend().setItemFont(font);
+
+       XYPlot plot = chart.getXYPlot();
+       plot.setDomainGridlinesVisible(true);
+       plot.setRangeGridlinesVisible(true);
+       plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
+       plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
+       plot.setBackgroundPaint(Color.WHITE);
+
+       XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
+       renderer.setSeriesPaint(0, Color.BLUE);
+       renderer.setSeriesPaint(1, Color.GREEN);
+       plot.setRenderer(renderer);
+
+/*       // 设置主X轴
+       NumberAxis domainAxis = new NumberAxis("日期进度 (%)");
+       domainAxis.setRange(0, 100);
+       domainAxis.setTickUnit(new NumberTickUnit(10));
+       domainAxis.setTickLabelFont(font);
+       domainAxis.setLabelFont(font);*/
+
+
+       // 设置顶部的月份轴
+       String[] months = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};
+       SymbolAxis monthAxis = new SymbolAxis("月份", months);
+       monthAxis.setTickLabelFont(font);
+       monthAxis.setLabelFont(font);
+       monthAxis.setRange(0, 11); // 设置范围来适应月份标签
+       plot.setDomainAxis(monthAxis);
+
+       // 设置Y轴的范围
+       NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
+       rangeAxis.setRange(0, 100); // Y轴从0到100
+       rangeAxis.setTickUnit(new NumberTickUnit(10));
+       rangeAxis.setLabelFont(font);
+       rangeAxis.setTickLabelFont(font);
+
+      /* // 添加月份轴
+       plot.setRangeAxis(2, monthAxis);
+       plot.mapDatasetToDomainAxis(0, 1); // 将数据映射到月份轴*/
+
+       return chart;
+    }
+
+
     /**字符串sha256映射*/
     public static String sha256(String input) {
         try {

+ 7 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/formula/impl/ExecutorMeter.java

@@ -22,6 +22,7 @@ import org.springframework.beans.BeanUtils;
 
 
 import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDate;
@@ -827,10 +828,10 @@ public class ExecutorMeter extends FormulaExecutor {
                               t.setCurrentPeriodEndChangeMoney("");
                      });
                      RebateIncentiveAdvPay rebateIncentiveAdvPay = new RebateIncentiveAdvPay();
-                     payItemZj.stream().filter(t->t.getFormName()!=null&&t.getFormName().contains("小计")).findFirst().ifPresent(t->{
+                     payItemZj.stream().filter(t->t.getChapterSeq()!=null&&t.getChapterSeq().contains("小计")).findFirst().ifPresent(t->{
                          rebateIncentiveAdvPay.setSubtotal(t.getCurrentPeriodEndPay());
                      });
-                     payItemZj.stream().filter(t->t.getFormName()!=null&&t.getFormName().contains("扣回动员预付款")).findFirst().ifPresent(t->{
+                     payItemZj.stream().filter(t->t.getChapterSeq()!=null&&t.getChapterSeq().contains("扣回动员预付款")).findFirst().ifPresent(t->{
 
                      });
                      tec.formDataMap.putAll(FormulaUtils.toFormDataMap(rebateIncentiveAdvPay));
@@ -1286,8 +1287,10 @@ public class ExecutorMeter extends FormulaExecutor {
                     try {
                         double[] actual = monthlySum.stream().mapToDouble(BaseUtils::obj2DoubleZero).toArray();
                         double[] planned =planMonthSum.stream().limit(monthlySum.size()).mapToDouble(BaseUtils::obj2DoubleZero).toArray();;
-                        /*byte[]  chartBytes = FormulaUtils.chapterScheduleChart(actual,planned);
-                        BladeFile chartFile= tec.getNewIOSSClient().updateFile(chartBytes, "chart"+SnowFlakeUtil.getId()+".png");*/
+                       /* byte[]  chartBytes = FormulaUtils.chapterScheduleChart(actual,planned);
+                        FileOutputStream fos = new FileOutputStream("C:/Users/yangyj/Desktop/Swap_space/poi_statistics2.png");
+                        fos.write(chartBytes);
+                        BladeFile chartFile= tec.getNewIOSSClient().updateFile(chartBytes, ConstructionSchedule.TBN+SnowFlakeUtil.getId()+".png");*/
                         String path=FormulaUtils.chapterScheduleChartUrl(actual,planned);
                         BladeFile chartFile= tec.getNewIOSSClient().uploadFile( ConstructionSchedule.TBN+ SnowFlakeUtil.getId() + ".png",path);
                         /*施工进度图*/