Procházet zdrojové kódy

王子文 日报修改、导入时计算月报Cracker Raw Material

wangggziwen před 2 roky
rodič
revize
125cf70f46

+ 4 - 1
master/src/main/java/com/ruoyi/project/production/mapper/TDailyProductionReportMapper.java

@@ -84,7 +84,10 @@ public interface TDailyProductionReportMapper
             "where d.REPORT_DATE >= to_date('${startDate}', 'yyyy-mm-dd') " +
             "and d.REPORT_DATE <= to_date('${endDate}', 'yyyy-mm-dd') " +
             "order by d.report_date")
-    List<DailyAnalysisDataVO> selectAnalysisData(@Param("fieldName") String fieldName,
+    public List<DailyAnalysisDataVO> selectAnalysisData(@Param("fieldName") String fieldName,
                                                  @Param("startDate") String startDate,
                                                  @Param("endDate") String endDate);
+
+    public TDailyProductionReport selectDailySum(@Param("reportYear") int reportYear,
+                                            @Param("reportMonth") int reportMonth);
 }

+ 8 - 3
master/src/main/java/com/ruoyi/project/production/mapper/TMonthlyProductionReportMapper.java

@@ -5,6 +5,7 @@ import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
 import com.ruoyi.project.production.controller.vo.DailyAnalysisQueryVO;
 import com.ruoyi.project.production.controller.vo.MonthlyAnalysisDataVO;
 import com.ruoyi.project.production.controller.vo.MonthlyAnalysisQueryVO;
+import com.ruoyi.project.production.domain.TDailyProductionReport;
 import com.ruoyi.project.production.domain.TMonthlyProductionReport;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -60,7 +61,7 @@ public interface TMonthlyProductionReportMapper
 
     /**
      * 批量删除每月生产报告
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */
@@ -73,7 +74,7 @@ public interface TMonthlyProductionReportMapper
             " where (d.REPORT_YEAR = ${fromYear} and d.REPORT_MONTH >= ${fromMonth}) " +
             " and (d.REPORT_YEAR = ${toYear} and d.REPORT_MONTH <= ${toMonth}) " +
             " ORDER by d.REPORT_YEAR, d.REPORT_MONTH ")
-    List<MonthlyAnalysisDataVO> selectAnalysisDataSameYear(@Param("item") String item,
+    public List<MonthlyAnalysisDataVO> selectAnalysisDataSameYear(@Param("item") String item,
                                                    @Param("fromYear") int fromYear,
                                                    @Param("fromMonth") int fromMonth,
                                                    @Param("toYear") int toYear,
@@ -84,9 +85,13 @@ public interface TMonthlyProductionReportMapper
             " where (d.REPORT_YEAR = ${fromYear} and d.REPORT_MONTH >= ${fromMonth}) " +
             " or (d.REPORT_YEAR = ${toYear} and d.REPORT_MONTH <= ${toMonth}) " +
             " ORDER by d.REPORT_YEAR, d.REPORT_MONTH ")
-    List<MonthlyAnalysisDataVO> selectAnalysisDataDiffYear(@Param("item") String item,
+    public List<MonthlyAnalysisDataVO> selectAnalysisDataDiffYear(@Param("item") String item,
                                                            @Param("fromYear") int fromYear,
                                                            @Param("fromMonth") int fromMonth,
                                                            @Param("toYear") int toYear,
                                                            @Param("toMonth") int toMonth);
+
+    public int selectTMonthlyProductionReportCountByDate(@Param("reportYear")int reportYear,
+                                                  @Param("reportMonth")int reportMonth);
+
 }

+ 30 - 1
master/src/main/java/com/ruoyi/project/production/service/impl/TDailyProductionReportServiceImpl.java

@@ -7,6 +7,8 @@ import java.util.Date;
 import java.util.List;
 
 import com.ruoyi.project.production.controller.vo.DailyAnalysisDataVO;
+import com.ruoyi.project.production.mapper.TMonthlyProductionReportMapper;
+import com.ruoyi.project.production.service.impl.thread.SyncMonthlyThread;
 import org.apache.poi.ss.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -27,6 +29,9 @@ public class TDailyProductionReportServiceImpl implements ITDailyProductionRepor
     @Autowired
     private TDailyProductionReportMapper tDailyProductionReportMapper;
 
+    @Autowired
+    private TMonthlyProductionReportMapper tMonthlyProductionReportMapper;
+
     /**
      * 查询日期最新的每日生产报告
      *
@@ -78,7 +83,17 @@ public class TDailyProductionReportServiceImpl implements ITDailyProductionRepor
      */
     @Override
     public int updateTDailyProductionReport(TDailyProductionReport tDailyProductionReport) {
-        return tDailyProductionReportMapper.updateTDailyProductionReport(tDailyProductionReport);
+        int result = tDailyProductionReportMapper.updateTDailyProductionReport(tDailyProductionReport);
+        if (result > 0) {
+            // 同步更新月报数据
+            SyncMonthlyThread syncMonthlyThread = new SyncMonthlyThread(
+                    tDailyProductionReport.getReportDate(),
+                    this.tDailyProductionReportMapper,
+                    this.tMonthlyProductionReportMapper
+            );
+            syncMonthlyThread.run();
+        }
+        return result;
     }
 
     /**
@@ -782,9 +797,23 @@ public class TDailyProductionReportServiceImpl implements ITDailyProductionRepor
             if (list.size() > 0) {
                 tDailyProductionReportMapper.updateTDailyProductionReportByReportDate(tDailyProductionReport);
                 message = this.reportDateFormatter(tDailyProductionReport.getReportDate()) + "生产日报已更新!";
+                // 同步更新月报数据
+                SyncMonthlyThread syncMonthlyThread = new SyncMonthlyThread(
+                        tDailyProductionReport.getReportDate(),
+                        this.tDailyProductionReportMapper,
+                        this.tMonthlyProductionReportMapper
+                );
+                syncMonthlyThread.run();
             } else {
                 tDailyProductionReportMapper.insertTDailyProductionReport(tDailyProductionReport);
                 message = this.reportDateFormatter(tDailyProductionReport.getReportDate()) + "生产日报已上传!";
+                // 同步更新月报数据
+                SyncMonthlyThread syncMonthlyThread = new SyncMonthlyThread(
+                        tDailyProductionReport.getReportDate(),
+                        this.tDailyProductionReportMapper,
+                        this.tMonthlyProductionReportMapper
+                );
+                syncMonthlyThread.run();
             }
         } catch (Exception e) {
             message = "导入失败,请联系管理员!";

+ 119 - 0
master/src/main/java/com/ruoyi/project/production/service/impl/thread/SyncMonthlyThread.java

@@ -0,0 +1,119 @@
+package com.ruoyi.project.production.service.impl.thread;
+
+import com.ruoyi.project.production.domain.TDailyProductionReport;
+import com.ruoyi.project.production.domain.TMonthlyProductionReport;
+import com.ruoyi.project.production.mapper.TDailyProductionReportMapper;
+import com.ruoyi.project.production.mapper.TMonthlyProductionReportMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Repository;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author: Wang Zi Wen
+ * @email: wangggziwen@163.com
+ * @datetime: 2022/11/3 13:44
+ */
+@Component
+public class SyncMonthlyThread extends Thread {
+
+    private Date reportDate;
+
+    private TDailyProductionReportMapper tDailyProductionReportMapper;
+
+    private TMonthlyProductionReportMapper tMonthlyProductionReportMapper;
+
+    public SyncMonthlyThread() {
+        super();
+    }
+
+    public SyncMonthlyThread(
+            Date reportDate,
+            TDailyProductionReportMapper tDailyProductionReportMapper,
+            TMonthlyProductionReportMapper tMonthlyProductionReportMapper) {
+        super();
+        this.reportDate = reportDate;
+        this.tDailyProductionReportMapper = tDailyProductionReportMapper;
+        this.tMonthlyProductionReportMapper = tMonthlyProductionReportMapper;
+    }
+
+    @Override
+    public void run() {
+        this.syncMonthlyData();
+    }
+
+    /**
+     * 同步更新月报数据
+     */
+    private void syncMonthlyData() {
+        // 当前报告年份
+        int reportYear = this.reportDate.getYear() + 1900;
+        // 当前报告月份
+        int reportMonth = this.reportDate.getMonth() + 1;
+        // 计算日报各列总和
+        TDailyProductionReport daily = tDailyProductionReportMapper.selectDailySum(reportYear, reportMonth);
+        // 计算月报数据
+        TMonthlyProductionReport monthly = new TMonthlyProductionReport();
+        monthly.setReportYear((long)reportYear);
+        monthly.setReportMonth((long)reportMonth);
+        String napStr = daily.getNap();
+        String c5Str = daily.getC5();
+        String c6C8NaStr = daily.getC6C8Na();
+        String wisonEthaneStr = daily.getWisonEthane();
+        String lpgToFurnaceStr = daily.getLpgToFurnace();
+        String raff3FrBdStr = daily.getRaff3FrBd();
+        String raffinate2pFr2phStr = daily.getRaffinate2pFr2ph();
+        String c2FrLdpeStr = daily.getC2FrLdpe();
+        String c3FrOxoStr = daily.getC3FrOxo();
+        String mixedC3C4Str = daily.getMixedC3C4();
+        String hyC9Str = daily.getHyC9();
+        String pguOffgasStr = daily.getPguOffgas();
+        String washOilStr = daily.getWashOil();
+        String tolueneStr = daily.getToluene();
+        String hyC4FrR800Str = daily.getHyC4FrR800();
+        BigDecimal nap = new BigDecimal(napStr == null ? "0" :napStr);
+        BigDecimal c5 = new BigDecimal(c5Str == null ? "0" :c5Str);
+        BigDecimal c6C8Na = new BigDecimal(c6C8NaStr == null ? "0" :c6C8NaStr);
+        BigDecimal wisonEthane = new BigDecimal(wisonEthaneStr == null ? "0" :wisonEthaneStr);
+        BigDecimal lpgToFurnace = new BigDecimal(lpgToFurnaceStr == null ? "0" :lpgToFurnaceStr);
+        BigDecimal raff3FrBd = new BigDecimal(raff3FrBdStr == null ? "0" :raff3FrBdStr);
+        BigDecimal raffinate2pFr2ph = new BigDecimal(raffinate2pFr2phStr == null ? "0" :raffinate2pFr2phStr);
+        BigDecimal c2FrLdpe = new BigDecimal(c2FrLdpeStr == null ? "0" :c2FrLdpeStr);
+        BigDecimal c3FrOxo = new BigDecimal(c3FrOxoStr == null ? "0" :c3FrOxoStr);
+        BigDecimal mixedC3C4 = new BigDecimal(mixedC3C4Str == null ? "0" :mixedC3C4Str);
+        BigDecimal hyC9 = new BigDecimal(hyC9Str == null ? "0" :hyC9Str);
+        BigDecimal pguOffgas = new BigDecimal(pguOffgasStr == null ? "0" :pguOffgasStr);
+        BigDecimal washOil = new BigDecimal(washOilStr == null ? "0" :washOilStr);
+        BigDecimal toluene = new BigDecimal(tolueneStr == null ? "0" :tolueneStr);
+        BigDecimal hyC4FrR800 = new BigDecimal(hyC4FrR800Str == null ? "0" :hyC4FrR800Str);
+        monthly.setNap(nap.toString());
+        monthly.setC5(c5.toString());
+        monthly.setC6C8Na(c6C8Na.toString());
+        monthly.setWisonEthane(wisonEthane.toString());
+        monthly.setLpgToFurnace(lpgToFurnace.toString());
+        BigDecimal raff3FrBdAnd2ph = raff3FrBd.add(raffinate2pFr2ph);
+        monthly.setRaff3FrBdAnd2ph(raff3FrBdAnd2ph.toString());
+        monthly.setC2FrLdpe(c2FrLdpe.toString());
+        monthly.setC3FrOxo(c3FrOxo.toString());
+        monthly.setMixedC3C4(mixedC3C4.toString());
+        monthly.setHyC9(hyC9.toString());
+        monthly.setPguOffgas(pguOffgas.toString());
+        monthly.setWashOil(toluene.toString());
+        monthly.setToluene(washOil.toString());
+        monthly.setHyC4FrR800(hyC4FrR800.toString());
+        BigDecimal crackerRawFeed = nap.add(c5).add(c6C8Na).add(wisonEthane).add(lpgToFurnace).add(raff3FrBdAnd2ph).add(hyC4FrR800);
+        BigDecimal crackerRawInput = crackerRawFeed.add(c2FrLdpe).add(c3FrOxo).add(mixedC3C4).add(hyC9).add(pguOffgas).add(washOil).add(toluene);
+        monthly.setCrackerRawInput(crackerRawInput.toString());
+        monthly.setCrackerRawFeed(crackerRawFeed.toString());
+        // 查询年份=reportYear,月份=reportMonth的月报数据
+        int count = tMonthlyProductionReportMapper.selectTMonthlyProductionReportCountByDate(reportYear, reportMonth);
+        if (count == 0) {   // 新增月报数据
+            tMonthlyProductionReportMapper.insertTMonthlyProductionReport(monthly);
+        } else {    // 更新月报数据
+            tMonthlyProductionReportMapper.updateTMonthlyProductionReport(monthly);
+        }
+    }
+
+}

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

@@ -625,6 +625,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         from t_daily_production_report d
     </sql>
 
+    <select id="selectDailySum" parameterType="int" resultMap="TDailyProductionReportResult">
+        select
+        sum(d.NAP) as nap,
+        sum(d.C5) as c5,
+        sum(d.C6_C8_NA) as c6C8Na,
+        sum(d.WISON_ETHANE) as wisonEthane,
+        sum(d.LPG_TO_FURNACE) as lpgToFurnace,
+        sum(d.RAFF3_FR_BD) as raff3FrBd,
+        sum(d.RAFFINATE2P_FR_2PH) as raffinate2pFr2ph,
+        sum(d.C2_FR_LDPE) as c2FrLdpe,
+        sum(d.C3_FR_OXO) as c3FrOxo,
+        sum(d.MIXED_C3_C4) as mixedC3C4,
+        sum(d.HY_C9) as hyC9,
+        sum(d.PGU_OFFGAS) as pguOffgas,
+        sum(d.WASH_OIL) washOil,
+        sum(d.TOLUENE) toluene,
+        sum(d.HY_C4_FR_R800) as hyC4FrR800
+        from T_DAILY_PRODUCTION_REPORT d
+        where extract(year from d.REPORT_DATE) = #{reportYear}
+        and extract(month from d.REPORT_DATE) = #{reportMonth}
+    </select>
+
     <!-- 查询日期最新的每日生产报告 -->
     <select id="selectTDailyProductionReportByMaxDate" resultMap="TDailyProductionReportResult">
         <include refid="selectTDailyProductionReportVo"/>

+ 78 - 0
master/src/main/resources/mybatis/production/TMonthlyProductionReportMapper.xml

@@ -37,4 +37,82 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where d.report_year = #{year}
     </select>
 
+    <select id="selectTMonthlyProductionReportCountByDate" parameterType="int" resultType="int">
+        select count(id)
+        from t_monthly_production_report d
+        where d.report_month = #{reportMonth} and d.report_year = #{reportYear}
+    </select>
+
+    <insert id="insertTMonthlyProductionReport" parameterType="TMonthlyProductionReport">
+        <selectKey keyProperty="id" resultType="long" order="BEFORE">
+            SELECT SEQ_T_MONTHLY_REPORT.NEXTVAL as id FROM DUAL
+        </selectKey>
+        insert into t_monthly_production_report
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">id,</if>
+            <if test="reportMonth != null">report_month,</if>
+            <if test="reportYear != null">report_year,</if>
+            <if test="nap != null">nap,</if>
+            <if test="c5 != null">c5,</if>
+            <if test="c6C8Na != null">c6_c8_na,</if>
+            <if test="wisonEthane != null">wison_ethane,</if>
+            <if test="lpgToFurnace != null">lpg_to_furnace,</if>
+            <if test="raff3FrBdAnd2ph != null">raff3_fr_bd_and_2ph,</if>
+            <if test="c2FrLdpe != null">c2_fr_ldpe,</if>
+            <if test="c3FrOxo != null">c3_fr_oxo,</if>
+            <if test="mixedC3C4 != null">mixed_c3_c4,</if>
+            <if test="hyC9 != null">hy_c9,</if>
+            <if test="pguOffgas != null">pgu_offgas,</if>
+            <if test="washOil != null">wash_oil,</if>
+            <if test="toluene != null">toluene,</if>
+            <if test="hyC4FrR800 != null">hy_c4_fr_r800,</if>
+            <if test="crackerRawInput != null">cracker_raw_input,</if>
+            <if test="crackerRawFeed != null">cracker_raw_feed,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">#{id},</if>
+            <if test="reportMonth != null">#{reportMonth},</if>
+            <if test="reportYear != null">#{reportYear},</if>
+            <if test="nap != null">#{nap},</if>
+            <if test="c5 != null">#{c5},</if>
+            <if test="c6C8Na != null">#{c6C8Na},</if>
+            <if test="wisonEthane != null">#{wisonEthane},</if>
+            <if test="lpgToFurnace != null">#{lpgToFurnace},</if>
+            <if test="raff3FrBdAnd2ph != null">#{raff3FrBdAnd2ph},</if>
+            <if test="c2FrLdpe != null">#{c2FrLdpe},</if>
+            <if test="c3FrOxo != null">#{c3FrOxo},</if>
+            <if test="mixedC3C4 != null">#{mixedC3C4},</if>
+            <if test="hyC9 != null">#{hyC9},</if>
+            <if test="pguOffgas != null">#{pguOffgas},</if>
+            <if test="washOil != null">#{washOil},</if>
+            <if test="toluene != null">#{toluene},</if>
+            <if test="hyC4FrR800 != null">#{hyC4FrR800},</if>
+            <if test="crackerRawInput != null">#{crackerRawInput},</if>
+            <if test="crackerRawFeed != null">#{crackerRawFeed},</if>
+        </trim>
+    </insert>
+
+    <update id="updateTMonthlyProductionReport" parameterType="TMonthlyProductionReport">
+        update t_monthly_production_report
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="nap != null">nap = #{nap},</if>
+            <if test="c5 != null">c5 = #{c5},</if>
+            <if test="c6C8Na != null">c6_c8_na = #{c6C8Na},</if>
+            <if test="wisonEthane != null">wison_ethane = #{wisonEthane},</if>
+            <if test="lpgToFurnace != null">lpg_to_furnace = #{lpgToFurnace},</if>
+            <if test="raff3FrBdAnd2ph != null">raff3_fr_bd_and_2ph = #{raff3FrBdAnd2ph},</if>
+            <if test="c2FrLdpe != null">c2_fr_ldpe = #{c2FrLdpe},</if>
+            <if test="c3FrOxo != null">c3_fr_oxo = #{c3FrOxo},</if>
+            <if test="mixedC3C4 != null">mixed_c3_c4 = #{mixedC3C4},</if>
+            <if test="hyC9 != null">hy_c9 = #{hyC9},</if>
+            <if test="pguOffgas != null">pgu_offgas = #{pguOffgas},</if>
+            <if test="washOil != null">wash_oil = #{washOil},</if>
+            <if test="toluene != null">toluene = #{toluene},</if>
+            <if test="hyC4FrR800 != null">hy_c4_fr_r800 = #{hyC4FrR800},</if>
+            <if test="crackerRawInput != null">cracker_raw_input = #{crackerRawInput},</if>
+            <if test="crackerRawFeed != null">cracker_raw_feed = #{crackerRawFeed},</if>
+        </trim>
+        where report_month = #{reportMonth} and report_year = #{reportYear}
+    </update>
+
 </mapper>