Przeglądaj źródła

王子文 生产日报趋势分析

wangggziwen 2 lat temu
rodzic
commit
ba4d26743f

+ 17 - 0
master/src/main/java/com/ruoyi/project/production/controller/TDailyProductionReportController.java

@@ -1,8 +1,11 @@
 package com.ruoyi.project.production.controller;
 
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 
+import com.ruoyi.project.production.controller.vo.AnalysisDataVO;
+import com.ruoyi.project.production.controller.vo.AnalysisQueryVO;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.training.spec.domain.vo.TStPlanImportVO;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -38,6 +41,20 @@ public class TDailyProductionReportController extends BaseController
     @Autowired
     private ITDailyProductionReportService tDailyProductionReportService;
 
+    /**
+     * 查询每日生产报告列表
+     */
+    @PreAuthorize("@ss.hasPermi('production:report:list')")
+    @GetMapping("/getAnalysisData")
+    public AjaxResult getAnalysisData(AnalysisQueryVO analysisQueryVO)
+    {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        String startDate = sdf.format(analysisQueryVO.getStartDate());
+        String endDate = sdf.format(analysisQueryVO.getEndDate());
+        List<AnalysisDataVO> analysisDataVOList = tDailyProductionReportService.selectAnalysisData(analysisQueryVO.getFieldName(), startDate, endDate);
+        return AjaxResult.success(analysisDataVOList);
+    }
+
     /**
      * 导入每日生产报告数据
      *

+ 39 - 0
master/src/main/java/com/ruoyi/project/production/controller/vo/AnalysisDataVO.java

@@ -0,0 +1,39 @@
+package com.ruoyi.project.production.controller.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.util.Date;
+
+/**
+ * 趋势分析数据VO
+ *
+ * @author Wang Zi Wen
+ * @email wangggziwen@163.com
+ * @date 2022/10/18 09:27:50
+ */
+public class AnalysisDataVO {
+
+    /** 值 */
+    String valueData;
+
+    /** 日期 */
+    @JsonFormat(pattern = "yyyy-MM-dd" , timezone = "GMT+8")
+    Date dateData;
+
+    public String getValueData() {
+        return valueData;
+    }
+
+    public void setValueData(String valueData) {
+        this.valueData = valueData;
+    }
+
+    public Date getDateData() {
+        return dateData;
+    }
+
+    public void setDateData(Date dateData) {
+        this.dateData = dateData;
+    }
+
+}

+ 52 - 0
master/src/main/java/com/ruoyi/project/production/controller/vo/AnalysisQueryVO.java

@@ -0,0 +1,52 @@
+package com.ruoyi.project.production.controller.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.framework.web.domain.BaseEntity;
+
+import java.util.Date;
+
+/**
+ * 趋势分析查询VO
+ *
+ * @author Wang Zi Wen
+ * @email wangggziwen@163.com
+ * @date 2022/10/18 09:27:31
+ */
+public class AnalysisQueryVO  extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    /** 字段名 */
+    private String fieldName;
+
+    /** 开始日期 */
+    private Date startDate;
+
+    /** 结束日期 */
+    private Date endDate;
+
+    public String getFieldName() {
+        return fieldName;
+    }
+
+    public void setFieldName(String fieldName) {
+        this.fieldName = fieldName;
+    }
+
+    public Date getStartDate() {
+        return startDate;
+    }
+
+    public void setStartDate(Date startDate) {
+        this.startDate = startDate;
+    }
+
+    public Date getEndDate() {
+        return endDate;
+    }
+
+    public void setEndDate(Date endDate) {
+        this.endDate = endDate;
+    }
+
+}

+ 12 - 0
master/src/main/java/com/ruoyi/project/production/mapper/TDailyProductionReportMapper.java

@@ -3,7 +3,11 @@ package com.ruoyi.project.production.mapper;
 import java.util.Date;
 import java.util.List;
 import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
+import com.ruoyi.project.production.controller.vo.AnalysisDataVO;
+import com.ruoyi.project.production.controller.vo.AnalysisQueryVO;
 import com.ruoyi.project.production.domain.TDailyProductionReport;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
 /**
  * 每日生产报告Mapper接口
@@ -76,4 +80,12 @@ public interface TDailyProductionReportMapper
      * @return 结果
      */
     public int deleteTDailyProductionReportByIds(Long[] ids);
+
+    @Select("select d.${fieldName} as valueData, d.report_date as dateData " +
+            "from t_daily_production_report d " +
+            "where d.REPORT_DATE >= to_date('${startDate}', 'yyyy-mm-dd') " +
+            "and d.REPORT_DATE <= to_date('${endDate}', 'yyyy-mm-dd')")
+    List<AnalysisDataVO> selectAnalysisData(@Param("fieldName") String fieldName,
+                                            @Param("startDate") String startDate,
+                                            @Param("endDate") String endDate);
 }

+ 5 - 0
master/src/main/java/com/ruoyi/project/production/service/ITDailyProductionReportService.java

@@ -3,6 +3,9 @@ package com.ruoyi.project.production.service;
 import java.io.IOException;
 import java.util.Date;
 import java.util.List;
+
+import com.ruoyi.project.production.controller.vo.AnalysisDataVO;
+import com.ruoyi.project.production.controller.vo.AnalysisQueryVO;
 import com.ruoyi.project.production.domain.TDailyProductionReport;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -76,4 +79,6 @@ public interface ITDailyProductionReportService
      * @return 结果
      */
     public String importData(MultipartFile file) throws IOException;
+
+    List<AnalysisDataVO> selectAnalysisData(String fieldName, String startDate, String endDate);
 }

+ 7 - 0
master/src/main/java/com/ruoyi/project/production/service/impl/TDailyProductionReportServiceImpl.java

@@ -6,6 +6,8 @@ import java.math.RoundingMode;
 import java.util.Date;
 import java.util.List;
 
+import com.ruoyi.project.production.controller.vo.AnalysisDataVO;
+import com.ruoyi.project.production.controller.vo.AnalysisQueryVO;
 import org.apache.poi.ss.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -792,6 +794,11 @@ public class TDailyProductionReportServiceImpl implements ITDailyProductionRepor
         }
     }
 
+    @Override
+    public List<AnalysisDataVO> selectAnalysisData(String fieldName, String startDate, String endDate) {
+        return tDailyProductionReportMapper.selectAnalysisData(fieldName, startDate, endDate);
+    }
+
     /**
      * 把日期格式化为xxxx年xx月xx日
      *

+ 8 - 0
master/src/main/resources/mybatis/production/TDailyProductionReportMapper.xml

@@ -628,6 +628,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         from t_daily_production_report d
     </sql>
 
+    <!--<select id="selectAnalysisData"-->
+            <!--resultType="com.ruoyi.project.production.controller.vo.AnalysisDataVO"-->
+            <!--parameterType="com.ruoyi.project.production.controller.vo.AnalysisQueryVO">-->
+        <!--select d.#{fieldName} as valueData, d.report_date as dateData-->
+        <!--from t_daily_production_report d-->
+        <!--where d.REPORT_DATE &gt;= #{startDate} and d.REPORT_DATE &lt;= #{endDate}-->
+    <!--</select>-->
+
     <!-- 查询日期最新的每日生产报告 -->
     <select id="selectTDailyProductionReportByMaxDate" resultMap="TDailyProductionReportResult">
         <include refid="selectTDailyProductionReportVo"/>

+ 9 - 0
ui/src/api/production/report.js

@@ -1,5 +1,14 @@
 import request from '@/utils/request'
 
+// 查询趋势分析数据
+export function getAnalysisData(query) {
+  return request({
+    url: '/production/report/getAnalysisData',
+    method: 'get',
+    params: query
+  })
+}
+
 // 查询日期最新的每日生产报告详细
 export function getReportByMaxDate() {
   return request({

+ 113 - 73
ui/src/views/production/daily/index.vue

@@ -2819,7 +2819,7 @@
       </div>
     </el-dialog>
     <!-- 趋势分析对话框 -->
-    <el-dialog @open="draw" :title="analysis.title" :visible.sync="analysis.open" width="1000px" append-to-body>
+    <el-dialog :title="analysis.title" :visible.sync="analysis.open" width="1000px" append-to-body>
       <el-form :model="analysisQueryParams" ref="queryForm" :inline="true" label-width="68px">
         <el-form-item label="开始日期" prop="startDate">
           <el-date-picker
@@ -2845,7 +2845,7 @@
 </template>
 
 <script>
-import { getReportByMaxDate, listReport, getReport, delReport, addReport, updateReport, exportReport, importTemplate} from "@/api/production/report";
+import { getAnalysisData, getReportByMaxDate, listReport, getReport, delReport, addReport, updateReport, exportReport, importTemplate} from "@/api/production/report";
 import { treeselect } from "@/api/system/dept";
 import { getToken } from "@/utils/auth";
 import Treeselect from "@riophae/vue-treeselect";
@@ -2903,9 +2903,12 @@ export default {
       },
       // 趋势分析参数
       analysisQueryParams: {
+        fieldName: null,
         startDate: null,
         endDate: null
       },
+      valueList: [],
+      dateList: [],
       // 查询参数
       queryParams: {
         pageNum: 1,
@@ -4021,86 +4024,123 @@ export default {
   // },
   mixins: [echartMixins],
   methods: {
+    handleAnalysisQuery() {
+      this.echarts.dispose(this.chart);
+      this.valueList = [];
+      this.dateList = [];
+      let endDate = new Date(this.analysisQueryParams.endDate);
+      let startDate = new Date(this.analysisQueryParams.startDate);
+      this.analysisQueryParams.endDate = endDate.getFullYear() + "-" + Number(endDate.getMonth() + 1) + "-" + endDate.getDate();
+      this.analysisQueryParams.startDate = startDate.getFullYear() + "-" + Number(startDate.getMonth() + 1) + "-" + startDate.getDate();
+      getAnalysisData(this.analysisQueryParams).then(response => {
+        let data = response.data;
+        for (let i = 0; i < data.length; i++) {
+          this.valueList[i] = data[i].valueData;
+          this.dateList[i] = data[i].dateData;
+        }
+        this.chart = this.echarts.init(document.getElementById("bottomRightChartDialog"));
+        let option = {
+          tooltip: {
+            trigger: "item"
+          },
+          grid: {
+            left: 90,
+            right: 80,
+          },
+          xAxis: {
+            data: this.dateList.reverse(),
+            name: '日期'
+          },
+          yAxis: {
+            type: 'value',
+            name: '值'
+          },
+          series: [
+            {
+              label: {
+                show: true,
+                position: 'top'
+              },
+              data: this.valueList.reverse(),
+              type: 'line',
+              smooth: true,
+              symbolSize: 15,
+              color:"#1f9f90",
+              lineStyle: {
+                width: 6
+              }
+            }
+          ]
+        };
+        this.chart.setOption(option);
+      });
+    },
     draw() {
-      // 设置开始日期和结束日期,默认范围为一个月
-      let today = new Date();
-      let monthBefore = new Date();
-      if (today.getMonth() != 2 && today.getDate() >= 28) {
-        monthBefore.setDate(28);
-        monthBefore.setMonth(today.getMonth()-1);
-      } else {
-        monthBefore.setMonth(today.getMonth()-1);
-      }
-
-      this.analysisQueryParams.endDate = today;
-      this.analysisQueryParams.startDate = monthBefore;
-
-      // 基于准备好的dom,初始化echarts实例
-      this.chart = this.echarts.init(document.getElementById("bottomRightChartDialog"));
-
-      let option = {
-        tooltip: {
-          trigger: "item"
-        },
-        grid: {
-          left: 90,
-          right: 80,
-        },
-        xAxis: {
-          data: ["1", "2", "3"],
-          name: '日期'
-        },
-        yAxis: {
-          type: 'value',
-          name: '值'
-        },
-        series: [
-          {
-            label: {
-              show: true,
-              position: 'top'
-            },
-            data: ["1", "2", "3"],
-            type: 'line',
-            smooth: true,
-            symbolSize: 15,
-            color:"#1f9f90",
-            lineStyle: {
-              width: 6
-            },
-            markLine: {
-              silent: true,
-              data: [
-                {
-                  type: "average",
-                  name: "额定值",
-                  yAxis: 900
-                }
-              ],
-              precision: 0,
+      getAnalysisData(this.analysisQueryParams).then(response => {
+        let data = response.data;
+        for (let i = 0; i < data.length; i++) {
+          this.valueList[i] = data[i].valueData;
+          this.dateList[i] = data[i].dateData;
+        }
+        this.chart = this.echarts.init(document.getElementById("bottomRightChartDialog"));
+        let option = {
+          tooltip: {
+            trigger: "item"
+          },
+          grid: {
+            left: 90,
+            right: 80,
+          },
+          xAxis: {
+            data: this.dateList.reverse(),
+            name: '日期'
+          },
+          yAxis: {
+            type: 'value',
+            name: '值'
+          },
+          series: [
+            {
               label: {
-                normal: {
-                  formatter: "额定值: \n {c}"
-                }
+                show: true,
+                position: 'top'
               },
+              data: this.valueList.reverse(),
+              type: 'line',
+              smooth: true,
+              symbolSize: 15,
+              color:"#1f9f90",
               lineStyle: {
-                normal: {
-                  width: 3,
-                  color: "rgba(248,211,81,.7)"
-                }
+                width: 6
               }
-            },
-          }
-        ]
-
-      };
-
-      this.chart.setOption(option);
+            }
+          ]
+        };
+        this.chart.setOption(option);
+      });
     },
     // 打开趋势分析对话框
-    openDialog(field, title) {
+    openDialog(fieldName, title) {
+      // 设置开始日期和结束日期,默认范围为一个月
+      let today = new Date(this.reportData.reportDate);
+      let monthBefore = new Date();
+      if (today.getMonth() == 2 && today.getDate() >= 28) { // 三月的28-31号:年不变,日=28
+        monthBefore.setDate(28);
+        monthBefore.setFullYear(today.getFullYear());
+      } else if (today.getMonth() == 0) { // 一月:日不变,年-1
+        monthBefore.setDate(today.getDate());
+        monthBefore.setFullYear(today.getFullYear() - 1);
+      } else {  // 其它月份:年、日不变
+        monthBefore.setDate(today.getDate());
+        monthBefore.setFullYear(today.getFullYear());
+      }
+      monthBefore.setMonth(today.getMonth()-1);
+      this.analysisQueryParams.endDate = today.getFullYear() + "-" + Number(today.getMonth() + 1) + "-" + today.getDate();
+      this.analysisQueryParams.startDate = monthBefore.getFullYear() + "-" + Number(monthBefore.getMonth() + 1) + "-" + monthBefore.getDate();
+      this.analysisQueryParams.fieldName = fieldName;
       this.analysis.title = title + "趋势分析";
       this.analysis.open = true;
+      this.draw();
     },
     /** 编辑按钮操作 */
     handleUpdate(row) {