Selaa lähdekoodia

王子文 日报导入、修改时计算Product Yield平均值

wangggziwen 2 vuotta sitten
vanhempi
commit
9148fa9899

+ 118 - 2
master/src/main/java/com/ruoyi/project/production/service/impl/TMonthlyProductionReportServiceImpl.java

@@ -2,10 +2,12 @@ package com.ruoyi.project.production.service.impl;
 
 import java.lang.reflect.Method;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+import com.graphbuilder.math.func.AvgFunction;
 import com.ruoyi.project.production.controller.vo.MonthlyAnalysisDataVO;
 import com.ruoyi.project.production.controller.vo.MonthlyAnalysisQueryVO;
 import com.ruoyi.project.production.service.impl.vo.MonthlyProductionReportVO;
@@ -100,7 +102,121 @@ public class TMonthlyProductionReportServiceImpl implements ITMonthlyProductionR
     }
 
     /**
-     * 计算total的值:1~12月之和
+     * 计算平均值
+     *
+     * @param monthlyProductionReportVOs 前端月报数据集合
+     */
+    private void calcAvg(List<MonthlyProductionReportVO> monthlyProductionReportVOs) {
+        for (int i = 0; i < monthlyProductionReportVOs.size(); i++) {
+            MonthlyProductionReportVO monthlyProductionReportVO = monthlyProductionReportVOs.get(i);
+            BigDecimal total = null;
+            BigDecimal avg = null;
+            int count = 0;
+            String janStr = monthlyProductionReportVO.getJan();
+            String febStr = monthlyProductionReportVO.getFeb();
+            String marStr = monthlyProductionReportVO.getMar();
+            String aprStr = monthlyProductionReportVO.getApr();
+            String mayStr = monthlyProductionReportVO.getMay();
+            String junStr = monthlyProductionReportVO.getJun();
+            String julStr = monthlyProductionReportVO.getJul();
+            String augStr = monthlyProductionReportVO.getAug();
+            String sepStr = monthlyProductionReportVO.getSep();
+            String octStr = monthlyProductionReportVO.getOct();
+            String novStr = monthlyProductionReportVO.getNov();
+            String decStr = monthlyProductionReportVO.getDec();
+            BigDecimal jan = null;
+            BigDecimal feb = null;
+            BigDecimal mar = null;
+            BigDecimal apr = null;
+            BigDecimal may = null;
+            BigDecimal jun = null;
+            BigDecimal jul = null;
+            BigDecimal aug = null;
+            BigDecimal sep = null;
+            BigDecimal oct = null;
+            BigDecimal nov = null;
+            BigDecimal dec = null;
+            if (janStr == null) {
+                jan = new BigDecimal("0");
+            } else {
+                jan = new BigDecimal(janStr);
+                count++;
+            }
+            if (febStr == null) {
+                feb = new BigDecimal("0");
+            } else {
+                feb = new BigDecimal(febStr);
+                count++;
+            }
+            if (marStr == null) {
+                mar = new BigDecimal("0");
+            } else {
+                mar = new BigDecimal(marStr);
+                count++;
+            }
+            if (aprStr == null) {
+                apr = new BigDecimal("0");
+            } else {
+                apr = new BigDecimal(aprStr);
+                count++;
+            }
+            if (mayStr == null) {
+                may = new BigDecimal("0");
+            } else {
+                may = new BigDecimal(mayStr);
+                count++;
+            }
+            if (junStr == null) {
+                jun = new BigDecimal("0");
+            } else {
+                jun = new BigDecimal(junStr);
+                count++;
+            }
+            if (julStr == null) {
+                jul = new BigDecimal("0");
+            } else {
+                jul = new BigDecimal(julStr);
+                count++;
+            }
+            if (augStr == null) {
+                aug = new BigDecimal("0");
+            } else {
+                aug = new BigDecimal(augStr);
+                count++;
+            }
+            if (sepStr == null) {
+                sep = new BigDecimal("0");
+            } else {
+                sep = new BigDecimal(sepStr);
+                count++;
+            }
+            if (octStr == null) {
+                oct = new BigDecimal("0");
+            } else {
+                oct = new BigDecimal(octStr);
+                count++;
+            }
+            if (novStr == null) {
+                nov = new BigDecimal("0");
+            } else {
+                nov = new BigDecimal(novStr);
+                count++;
+            }
+            if (decStr == null) {
+                dec = new BigDecimal("0");
+            } else {
+                dec = new BigDecimal(decStr);
+                count++;
+            }
+            total = jan.add(feb).add(mar).add(apr).add(may).add(jun)
+                    .add(jul).add(aug).add(sep).add(oct).add(nov).add(dec);
+            avg = total.divide(new BigDecimal(count), 2, RoundingMode.HALF_UP);
+            monthlyProductionReportVO.setAvg(avg.toString());
+        }
+    }
+
+    /**
+     * 计算总和
      *
      * @param monthlyProductionReportVOs 前端月报数据集合
      */
@@ -671,7 +787,7 @@ public class TMonthlyProductionReportServiceImpl implements ITMonthlyProductionR
                 e.printStackTrace();
             }
         }
-        this.calcTotal(monthlyProductionReportVOs);
+        this.calcAvg(monthlyProductionReportVOs);
         return monthlyProductionReportVOs;
     }
 

+ 12 - 0
master/src/main/java/com/ruoyi/project/production/service/impl/vo/MonthlyProductionReportVO.java

@@ -41,8 +41,20 @@ public class MonthlyProductionReportVO {
 
     private String dec;
 
+    /** 总和 */
     private String total;
 
+    /** 平均值 */
+    private String avg;
+
+    public String getAvg() {
+        return avg;
+    }
+
+    public void setAvg(String avg) {
+        this.avg = avg;
+    }
+
     public String getDictLabel() {
         return dictLabel;
     }

+ 1 - 1
ui/src/views/production/monthly/index.vue

@@ -163,7 +163,7 @@
         <el-table-column prop="oct" :label="this.monthList[9]"></el-table-column>
         <el-table-column prop="nov" :label="this.monthList[10]"></el-table-column>
         <el-table-column prop="dec" :label="this.monthList[11]"></el-table-column>
-        <el-table-column prop="total" label="total"></el-table-column>
+        <el-table-column prop="avg" label="avg"></el-table-column>
       </el-table-column>
     </el-table>
     <el-table border :data="tableCrackerUtilityConsumption" style="width: 100%;">