Przeglądaj źródła

王子文 月报Cost Fr Ethylene

wangggziwen 2 lat temu
rodzic
commit
ca83ab7afe

+ 10 - 0
master/src/main/java/com/ruoyi/project/production/controller/TMonthlyProductionReportController.java

@@ -36,6 +36,16 @@ public class TMonthlyProductionReportController extends BaseController
     @Autowired
     private ITMonthlyProductionReportService tMonthlyProductionReportService;
 
+    /**
+     * 修改Cost Fr Ethylene
+     */
+    @PreAuthorize("@ss.hasPermi('production:monthly:edit')")
+    @PutMapping(value = "/costFrEthylene")
+    public AjaxResult updateCostFrEthylene(@RequestBody MonthlyUpdateVO monthlyUpdateVO)
+    {
+        return toAjax(tMonthlyProductionReportService.updateCostFrEthylene(monthlyUpdateVO));
+    }
+
     /**
      * 修改Chemical Consume
      */

+ 11 - 0
master/src/main/java/com/ruoyi/project/production/domain/TMonthlyProductionReport.java

@@ -18,6 +18,17 @@ public class TMonthlyProductionReport extends BaseEntity
     /** 主键id */
     private Long id;
 
+    @Excel(name = "Cost Fr Ethylene")
+    private String costFrEthylene;
+
+    public String getCostFrEthylene() {
+        return costFrEthylene;
+    }
+
+    public void setCostFrEthylene(String costFrEthylene) {
+        this.costFrEthylene = costFrEthylene;
+    }
+
     /** 所属月份 */
     @Excel(name = "所属月份")
     private Long reportMonth;

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

@@ -206,4 +206,9 @@ public interface ITMonthlyProductionReportService
      * 修改Chemical Consume
      */
     public int updateChemicalConsume(MonthlyUpdateVO monthlyUpdateVO);
+
+    /**
+     * 修改Cost Fr Ethylene
+     */
+    public int updateCostFrEthylene(MonthlyUpdateVO monthlyUpdateVO);
 }

+ 101 - 1
master/src/main/java/com/ruoyi/project/production/service/impl/TMonthlyProductionReportServiceImpl.java

@@ -1242,7 +1242,42 @@ public class TMonthlyProductionReportServiceImpl implements ITMonthlyProductionR
      */
     @Override
     public List<MonthlyProductionReportVO> selectCostFrEthyleneByYear(Long year) {
-        return  null;
+        // 当前日期
+        Date currentDate = new Date();
+        // 当前年份
+        Long currentYear = Long.parseLong(currentDate.getYear() + 1900 + "");
+        // 当前月份
+        Long currentMonth = Long.parseLong(currentDate.getMonth() + 1 + "");
+        // 从数据库中查出的当前year的月报数据集合,每个元素对应当前year某个月的数据
+        List<TMonthlyProductionReport> tMonthlyProductionReports = tMonthlyProductionReportMapper.selectCostFrEthyleneByYear(year);
+        // 前端月报数据集合,每个元素对应当前某个指标的title、unit、1~12月的数据以及年度汇总数据
+        List<MonthlyProductionReportVO> monthlyProductionReportVOs = new ArrayList<>();
+        monthlyProductionReportVOs.add(new MonthlyProductionReportVO("cost_fr_ethylene","the cost","cny/t"));
+        // 遍历从数据库中查出的月报数据集合,结果为0~12条数据不等
+        for (int i = 0; i < tMonthlyProductionReports.size(); i++) {
+            TMonthlyProductionReport tMonthlyProductionReport = tMonthlyProductionReports.get(i);
+            String costFrEthylene = tMonthlyProductionReport.getCostFrEthylene();
+            Long reportMonth = tMonthlyProductionReport.getReportMonth();   // 当前元素的所属月份
+            Long reportYear = tMonthlyProductionReport.getReportYear();     // 当前元素的所属年份
+            // 前端数据集合的class
+            Class clazz = null;
+            // 当前元素调用的set方法
+            Method method = null;
+            try {
+                clazz = Class.forName("com.ruoyi.project.production.service.impl.vo.MonthlyProductionReportVO");
+                method = this.getSetMethod(reportMonth, clazz);
+                // 按照当前元素的所属月份调取相应set方法
+                method.invoke(monthlyProductionReportVOs.get(0), costFrEthylene);
+                // 当前年份=所属年份,当前月份=所属月份
+                if (currentMonth.equals(reportMonth) && currentYear.equals(reportYear)) {
+                    monthlyProductionReportVOs.get(0).setCurrently(costFrEthylene);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        this.calcAvg(monthlyProductionReportVOs);
+        return monthlyProductionReportVOs;
     }
 
     /**
@@ -2157,4 +2192,69 @@ public class TMonthlyProductionReportServiceImpl implements ITMonthlyProductionR
         }
         return affectedRows;
     }
+
+    /**
+     * 修改Cost Fr Ethylene
+     */
+    @Override
+    public int updateCostFrEthylene(MonthlyUpdateVO monthlyUpdateVO) {
+        // 受影响行数
+        int affectedRows = 0;
+        List<MonthlyProductionReportVO> tableData = monthlyUpdateVO.getTableData();
+        long year = monthlyUpdateVO.getYear();
+        Class clazz = null;
+        try {
+            clazz = Class.forName("com.ruoyi.project.production.service.impl.vo.MonthlyProductionReportVO");
+        } catch (ClassNotFoundException e) {
+            e.printStackTrace();
+        }
+        for (MonthlyProductionReportVO tableDatum : tableData) {
+            for (int i = 0; i < 12; i++) {
+                TMonthlyProductionReport report = new TMonthlyProductionReport();
+                report.setReportMonth((long)(i + 1));
+                report.setReportYear(year);
+                Method getMethod = null;
+                String monthValue = null;
+                try {
+                    if (i == 0) { getMethod =  clazz.getDeclaredMethod("getJan"); }
+                    if (i == 1) { getMethod =  clazz.getDeclaredMethod("getFeb"); }
+                    if (i == 2) { getMethod =  clazz.getDeclaredMethod("getMar"); }
+                    if (i == 3) { getMethod =  clazz.getDeclaredMethod("getApr"); }
+                    if (i == 4) { getMethod =  clazz.getDeclaredMethod("getMay"); }
+                    if (i == 5) { getMethod =  clazz.getDeclaredMethod("getJun"); }
+                    if (i == 6) { getMethod =  clazz.getDeclaredMethod("getJul"); }
+                    if (i == 7) { getMethod =  clazz.getDeclaredMethod("getAug"); }
+                    if (i == 8) { getMethod =  clazz.getDeclaredMethod("getSep"); }
+                    if (i == 9) { getMethod =  clazz.getDeclaredMethod("getOct"); }
+                    if (i == 10) { getMethod =  clazz.getDeclaredMethod("getNov"); }
+                    if (i == 11) { getMethod =  clazz.getDeclaredMethod("getDec"); }
+                    monthValue = (String) getMethod.invoke(tableDatum);
+                } catch (NoSuchMethodException e1){
+                    e1.printStackTrace();
+                } catch (IllegalAccessException e2) {
+                    e2.printStackTrace();
+                } catch (InvocationTargetException e3) {
+                    e3.printStackTrace();
+                }
+                if (monthValue == null) {
+                    continue;
+                }
+                if ("cost_fr_ethylene".equals(tableDatum.getDictLabel())) {
+                    report.setCostFrEthylene(monthValue);
+                }
+                // 当前报告年份
+                int reportYear = Integer.parseInt(report.getReportYear().toString());
+                // 当前报告月份
+                int reportMonth = Integer.parseInt(report.getReportMonth().toString());
+                // 查询年份=reportYear,月份=reportMonth的月报数据
+                int count = tMonthlyProductionReportMapper.selectTMonthlyProductionReportCountByDate(reportYear, reportMonth);
+                if (count == 0) {   // 新增月报数据
+                    affectedRows += tMonthlyProductionReportMapper.insertTMonthlyProductionReport(report);
+                } else {    // 更新月报数据
+                    affectedRows += tMonthlyProductionReportMapper.updateTMonthlyProductionReport(report);
+                }
+            }
+        }
+        return affectedRows;
+    }
 }

+ 11 - 1
master/src/main/resources/mybatis/production/TMonthlyProductionReportMapper.xml

@@ -169,6 +169,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="chemicalConsumeNaoh2"     column="chemical_consume_naoh2"    />
         <result property="chemicalConsumeCh3oh"     column="chemical_consume_ch3oh"    />
         <result property="chemicalConsumePt30002"   column="chemical_consume_pt30002"    />
+        <result property="costFrEthylene"           column="cost_fr_ethylene"    />
     </resultMap>
 
     <select id="selectCrackerRawMaterialByYear" parameterType="Long" resultMap="TMonthlyProductionReportResult">
@@ -282,7 +283,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where d.report_year = #{year}
     </select>
 
-    <select id="selectCostFrEthyleneByYear" parameterType="Long" resultMap="TMonthlyProductionReportResult"></select>
+    <select id="selectCostFrEthyleneByYear" parameterType="Long" resultMap="TMonthlyProductionReportResult">
+        select
+               d.id, d.report_month, d.report_year, d.cost_fr_ethylene
+        from
+             t_monthly_production_report d
+        where d.report_year = #{year}
+    </select>
 
     <select id="selectRuningRateByYear" parameterType="Long" resultMap="TMonthlyProductionReportResult">
         select
@@ -518,6 +525,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="chemicalConsumeNaoh2 != null">chemical_consume_naoh2,</if>
             <if test="chemicalConsumeCh3oh != null">chemical_consume_ch3oh,</if>
             <if test="chemicalConsumePt30002 != null">chemical_consume_pt30002,</if>
+            <if test="costFrEthylene != null">cost_fr_ethylene,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">#{id},</if>
@@ -684,6 +692,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="chemicalConsumeNaoh2 != null">#{chemicalConsumeNaoh2},</if>
             <if test="chemicalConsumeCh3oh != null">#{chemicalConsumeCh3oh},</if>
             <if test="chemicalConsumePt30002 != null">#{chemicalConsumePt30002},</if>
+            <if test="costFrEthylene != null">#{costFrEthylene},</if>
         </trim>
     </insert>
 
@@ -851,6 +860,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="chemicalConsumeNaoh2 != null">chemical_consume_naoh2 = #{chemicalConsumeNaoh2},</if>
             <if test="chemicalConsumeCh3oh != null">chemical_consume_ch3oh = #{chemicalConsumeCh3oh},</if>
             <if test="chemicalConsumePt30002 != null">chemical_consume_pt30002 = #{chemicalConsumePt30002},</if>
+            <if test="costFrEthylene != null">cost_fr_ethylene = #{costFrEthylene},</if>
         </trim>
         where report_month = #{reportMonth} and report_year = #{reportYear}
     </update>

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

@@ -1,5 +1,14 @@
 import request from '@/utils/request'
 
+// 修改Cost Fr Ethylene
+export function updateCostFrEthylene(data) {
+  return request({
+    url: '/production/monthly/costFrEthylene',
+    method: 'put',
+    data: data
+  })
+}
+
 // 修改Chemical Consume
 export function updateChemicalConsume(data) {
   return request({

+ 154 - 19
ui/src/views/production/monthly/index.vue

@@ -1140,6 +1140,32 @@
       </el-table-column>
     </el-table>
     <!-- Cost Fr Ethylene -->
+    <div class="editDiv">
+      <el-button
+        :disabled="costFrEthyleneUpdating"
+        type="primary"
+        icon="el-icon-edit"
+        size="mini"
+        @click="handleCostFrEthyleneUpdate"
+        v-hasPermi="['production:monthly:edit']"
+      >{{ $t('编辑Cost Fr Ethylene') }}</el-button>
+      <el-button
+        :disabled="!costFrEthyleneUpdating"
+        type="success"
+        icon="el-icon-check"
+        size="mini"
+        @click="handleConfirmCostFrEthyleneUpdate"
+        v-hasPermi="['production:monthly:edit']"
+      >{{ $t('保存') }}</el-button>
+      <el-button
+        :disabled="!costFrEthyleneUpdating"
+        type="info"
+        icon="el-icon-close"
+        size="mini"
+        @click="handleCancelCostFrEthyleneUpdate"
+        v-hasPermi="['production:monthly:edit']"
+      >{{ $t('取消') }}</el-button>
+    </div>
     <el-table border :data="tableCostFrEthylene" style="width: 100%;">
       <el-table-column label="Cost fr Ethylene">
         <el-table-column width="150" prop="title" label="">
@@ -1149,18 +1175,102 @@
         </el-table-column>
         <el-table-column prop="unit" label="unit"></el-table-column>
         <el-table-column prop="currently" label="currently"></el-table-column>
-        <el-table-column prop="jan" :label="this.monthList[0]"></el-table-column>
-        <el-table-column prop="feb" :label="this.monthList[1]"></el-table-column>
-        <el-table-column prop="mar" :label="this.monthList[2]"></el-table-column>
-        <el-table-column prop="apr" :label="this.monthList[3]"></el-table-column>
-        <el-table-column prop="may" :label="this.monthList[4]"></el-table-column>
-        <el-table-column prop="jun" :label="this.monthList[5]"></el-table-column>
-        <el-table-column prop="jul" :label="this.monthList[6]"></el-table-column>
-        <el-table-column prop="aug" :label="this.monthList[7]"></el-table-column>
-        <el-table-column prop="sep" :label="this.monthList[8]"></el-table-column>
-        <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="jan" :label="this.monthList[0]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.jan}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.jan" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="feb" :label="this.monthList[1]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.feb}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.feb" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="mar" :label="this.monthList[2]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.mar}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.mar" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="apr" :label="this.monthList[3]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.apr}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.apr" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="may" :label="this.monthList[4]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.may}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.may" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="jun" :label="this.monthList[5]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.jun}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.jun" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="jul" :label="this.monthList[6]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.jul}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.jul" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="aug" :label="this.monthList[7]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.aug}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.aug" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="sep" :label="this.monthList[8]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.sep}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.sep" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="oct" :label="this.monthList[9]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.oct}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.oct" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="nov" :label="this.monthList[10]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.nov}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.nov" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
+        <el-table-column prop="dec" :label="this.monthList[11]">
+          <template slot-scope="{row}">
+            <div v-if="!costFrEthyleneUpdating">{{row.dec}}</div>
+            <div v-if="costFrEthyleneUpdating">
+              <el-input v-model="row.dec" clearable="true"></el-input>
+            </div>
+          </template>
+        </el-table-column>
         <el-table-column prop="total" label="total"></el-table-column>
       </el-table-column>
     </el-table>
@@ -1835,7 +1945,8 @@ import {
   updateAromaticsUtilityConsumption,
   updateShoudownHour,
   updateRuningRate,
-  updateChemicalConsume
+  updateChemicalConsume,
+  updateCostFrEthylene
 } from "@/api/production/monthly";
 
 export default {
@@ -1843,6 +1954,7 @@ export default {
   data() {
     return {
       // 修改中
+      costFrEthyleneUpdating: false,
       chemicalConsumeUpdating: false,
       runingRateUpdating: false,
       shoudownHourUpdating: false,
@@ -1901,9 +2013,7 @@ export default {
       tableAromaticsUtilityConsumption: [],
       tableAromaticsEnergyConsumption: [],
       tablePlantLoad: [],
-      tableCostFrEthylene: [
-        {title: "the cost"},
-      ],
+      tableCostFrEthylene: [],
       tableRuningRate: [],
       tableShoudownHour: [],
       tableOtherside: [],
@@ -2027,6 +2137,9 @@ export default {
   },
   methods: {
     /** 编辑按钮操作 */
+    handleCostFrEthyleneUpdate(row) {
+      this.costFrEthyleneUpdating = true;
+    },
     handleChemicalConsumeUpdate(row) {
       this.chemicalConsumeUpdating = true;
     },
@@ -2046,6 +2159,22 @@ export default {
       this.eligibleProductRateUpdating = true;
     },
     /** 确定修改按钮操作 */
+    handleConfirmCostFrEthyleneUpdate(row) {
+      this.costFrEthyleneUpdating = false;
+      updateCostFrEthylene({
+        tableData: this.tableCostFrEthylene,
+        year: this.year.getFullYear()
+      }).then(response => {
+        if (response.code == 200) {
+          this.$message.success("修改成功");
+        } else {
+          this.$message.error("未知错误,请联系管理员。");
+        }
+        getCostFrEthylene(year).then(response => {
+          this.tableCostFrEthylene = response.data;
+        });
+      });
+    },
     handleConfirmChemicalConsumeUpdate(row) {
       this.chemicalConsumeUpdating = false;
       updateChemicalConsume({
@@ -2182,6 +2311,12 @@ export default {
       });
     },
     /** 取消修改按钮操作 */
+    handleCancelCostFrEthyleneUpdate(row) {
+      this.costFrEthyleneUpdating = false;
+      getCostFrEthylene(year).then(response => {
+        this.tableCostFrEthylene = response.data;
+      });
+    },
     handleCancelChemicalConsumeUpdate(row) {
       this.chemicalConsumeUpdating = false;
       getChemicalConsume(year).then(response => {
@@ -2388,9 +2523,9 @@ export default {
       getPlantLoad(year).then(response => {
         this.tablePlantLoad = response.data;
       });
-      // getCostFrEthylene(year).then(response => {
-      //   this.tableCostFrEthylene = response.data;
-      // });
+      getCostFrEthylene(year).then(response => {
+        this.tableCostFrEthylene = response.data;
+      });
       getRuningRate(year).then(response => {
         this.tableRuningRate = response.data;
       });