Browse Source

PFD管理 - 导入功能

wangggziwen 2 months ago
parent
commit
79f520e3bc

+ 215 - 8
master/src/main/java/com/ruoyi/project/monitor/controller/TPfdController.java

@@ -1,16 +1,26 @@
 package com.ruoyi.project.monitor.controller;
 
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
+
+import com.alibaba.fastjson.JSON;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.file.ExcelUtils;
+import com.ruoyi.project.production.domain.TSaiApply;
+import com.ruoyi.project.system.domain.SysDept;
+import com.ruoyi.project.system.domain.SysDictData;
+import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.service.ISysDictTypeService;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
 import com.ruoyi.project.monitor.domain.TPfd;
@@ -19,6 +29,7 @@ import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.web.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * PFD管理Controller
@@ -58,6 +69,202 @@ public class TPfdController extends BaseController
         return util.exportExcel(list, "pfdmgr");
     }
 
+    /**
+     * 导入PFD管理列表
+     */
+    @PreAuthorize("@ss.hasPermi('production:apply:add')")
+    @PostMapping("/importData")
+    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException
+    {
+        //获取操作人员ID
+        Long userId = getUserId();
+        //报错行数统计
+        List<Integer> failRow =new ArrayList<Integer>();
+        Workbook workbook = ExcelUtils.getWorkBook(file);
+        Sheet sheet = workbook.getSheetAt(0);
+        List<TPfd> list = new ArrayList<TPfd>();
+        int rowNum = sheet.getPhysicalNumberOfRows();
+        int failNumber = 0;
+        for (int i = 1; i <= rowNum; i++) {
+            try {
+                logger.info("读取行数:" + i);
+                Row row = sheet.getRow(i);
+                int cellNum = row.getPhysicalNumberOfCells();
+                TPfd entity = new TPfd();
+                entity.setCreateTime(new Date());
+                entity.setCreateBy(userId.toString());
+                for (int j = 0; j < cellNum; j++) {
+                    Cell cell = row.getCell(j);
+                    String cellValue = ExcelUtils.getCellValue(cell);
+                    logger.info("cellValue:" + cellValue);
+                    if (j == 0) {
+                        entity.setCode(cellValue);
+                    } else if (j == 1) {
+                        entity.setDescription(cellValue);
+                    } else if (j == 2) {
+                        entity.setH2o(cellValue);
+                    } else if (j == 3) {
+                        entity.setHydrogen(cellValue);
+                    } else if (j == 4) {
+                        entity.setCo(cellValue);
+                    } else if (j == 5) {
+                        entity.setMethane(cellValue);
+                    } else if (j == 6) {
+                        entity.setAcetyln(cellValue);
+                    } else if (j == 7) {
+                        entity.setEthylene(cellValue);
+                    } else if (j == 8) {
+                        entity.setEthane(cellValue);
+                    } else if (j == 9) {
+                        entity.setMacetyln(cellValue);
+                    } else if (j == 10) {
+                        entity.setPropdien(cellValue);
+                    } else if (j == 11) {
+                        entity.setPropylen(cellValue);
+                    } else if (j == 12) {
+                        entity.setPropane(cellValue);
+                    } else if (j == 13) {
+                        entity.setButd13(cellValue);
+                    } else if (j == 14) {
+                        entity.setButene1(cellValue);
+                    } else if (j == 15) {
+                        entity.setIbte(cellValue);
+                    } else if (j == 16) {
+                        entity.setC2butene(cellValue);
+                    } else if (j == 17) {
+                        entity.setT2butene(cellValue);
+                    } else if (j == 18) {
+                        entity.setIbutane(cellValue);
+                    } else if (j == 19) {
+                        entity.setButane(cellValue);
+                    } else if (j == 20) {
+                        entity.setCpd13(cellValue);
+                    } else if (j == 21) {
+                        entity.setIsoprene(cellValue);
+                    } else if (j == 22) {
+                        entity.setC13pnd(cellValue);
+                    } else if (j == 23) {
+                        entity.setPentene1(cellValue);
+                    } else if (j == 24) {
+                        entity.setIpentane(cellValue);
+                    } else if (j == 25) {
+                        entity.setPentane(cellValue);
+                    } else if (j == 26) {
+                        entity.setHexene1(cellValue);
+                    } else if (j == 27) {
+                        entity.setBenzene(cellValue);
+                    } else if (j == 28) {
+                        entity.setToluene(cellValue);
+                    } else if (j == 29) {
+                        entity.setOxylene(cellValue);
+                    } else if (j == 30) {
+                        entity.setC9200c(cellValue);
+                    } else if (j == 31) {
+                        entity.setFuelOil(cellValue);
+                    } else if (j == 32) {
+                        entity.setCo2(cellValue);
+                    } else if (j == 33) {
+                        entity.setH2s(cellValue);
+                    } else if (j == 34) {
+                        entity.setNbp25(cellValue);
+                    } else if (j == 35) {
+                        entity.setNbp58(cellValue);
+                    } else if (j == 36) {
+                        entity.setNbp72(cellValue);
+                    } else if (j == 37) {
+                        entity.setNbp86(cellValue);
+                    } else if (j == 38) {
+                        entity.setNbp100(cellValue);
+                    } else if (j == 39) {
+                        entity.setNbp114(cellValue);
+                    } else if (j == 40) {
+                        entity.setNbp128(cellValue);
+                    } else if (j == 41) {
+                        entity.setNbp141(cellValue);
+                    } else if (j == 42) {
+                        entity.setNbp155(cellValue);
+                    } else if (j == 43) {
+                        entity.setNbp169(cellValue);
+                    } else if (j == 44) {
+                        entity.setNbp183(cellValue);
+                    } else if (j == 45) {
+                        entity.setNbp199(cellValue);
+                    } else if (j == 46) {
+                        entity.setNbp207(cellValue);
+                    } else if (j == 47) {
+                        entity.setNbp222(cellValue);
+                    } else if (j == 48) {
+                        entity.setNbp236(cellValue);
+                    } else if (j == 49) {
+                        entity.setNbp249(cellValue);
+                    } else if (j == 50) {
+                        entity.setTotalMolarFlowrate(cellValue);
+                    } else if (j == 51) {
+                        entity.setTotalMassFlowrate(cellValue);
+                    } else if (j == 52) {
+                        entity.setTotalMolecularWeight(cellValue);
+                    } else if (j == 53) {
+                        entity.setTemperature(cellValue);
+                    } else if (j == 54) {
+                        entity.setPressure(cellValue);
+                    } else if (j == 55) {
+                        entity.setVaporMassFlowrate(cellValue);
+                    } else if (j == 56) {
+                        entity.setVaporMolecularWeight(cellValue);
+                    } else if (j == 57) {
+                        entity.setVaporDensityAct(cellValue);
+                    } else if (j == 58) {
+                        entity.setVaporZ(cellValue);
+                    } else if (j == 59) {
+                        entity.setVaporActVolFlow(cellValue);
+                    } else if (j == 60) {
+                        entity.setVaporHtCapacity(cellValue);
+                    } else if (j == 61) {
+                        entity.setVaporViscosity(cellValue);
+                    } else if (j == 62) {
+                        entity.setLiquidMassFlowrate(cellValue);
+                    } else if (j == 63) {
+                        entity.setLiquidMolecularWeight(cellValue);
+                    } else if (j == 64) {
+                        entity.setLiquidDensityAct(cellValue);
+                    } else if (j == 65) {
+                        entity.setLiquidActVolFlow(cellValue);
+                    } else if (j == 66) {
+                        entity.setLiquidHtCapacity(cellValue);
+                    } else if (j == 67) {
+                        entity.setLiquidViscosity(cellValue);
+                    } else if (j == 68) {
+                        entity.setLiquidSurfTension(cellValue);
+                    }
+                }
+                logger.info("entity:" + entity);
+                list.add(entity);
+            }catch (Exception e){
+                failNumber++;
+                failRow.add(i+1);
+            }
+        }
+        int successNumber = 0;
+        int failNum = 0;
+        for (TPfd t : list
+        ) {
+            failNum++;
+            try {
+                tPfdService.insertTPfd(t);
+                successNumber++;
+            }catch (Exception e){
+                failNumber++;
+                logger.info("e:" + e);
+                failRow.add(failNum+1);
+            }
+        }
+        logger.info("list:" + JSON.toJSONString(list));
+        logger.info("successNumber:" +String.valueOf(successNumber));
+        logger.info("failNumber:" +String.valueOf(failNumber));
+        logger.info("failRow:" +String.valueOf(failRow));
+        return AjaxResult.success(String.valueOf(successNumber), failRow);
+    }
+
     /**
      * 获取PFD管理详细信息
      */

+ 15 - 6
ui/src/views/monitor/pfdmgr/index.vue

@@ -45,6 +45,15 @@
           @click="handleDelete"
           v-hasPermi="['monitor:pfdmgr:remove']"
         >删除</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="info"
+          icon="el-icon-upload2"
+          size="mini"
+          @click="handleImport"
+          v-hasPermi="['monitor:pfdmgr:add']"
+        >导入</el-button>
       </el-col>
 	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
@@ -374,7 +383,7 @@
                   :limit="1"
                   accept=".xlsx, .xls"
                   :headers="upload.headers"
-                  :action="upload.url + '?updateSupport=' + upload.updateSupport"
+                  :action="upload.url"
                   :disabled="upload.isUploading"
                   :on-progress="handleFileUploadProgress"
                   :on-success="handleFileSuccess"
@@ -386,11 +395,11 @@
                   将文件拖到此处,或
                   <em>点击上传</em>
               </div>
-              <div class="el-upload__tip" slot="tip">
-                  <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
-                  <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
-              </div>
-              <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
+              <!--<div class="el-upload__tip" slot="tip">-->
+                  <!--<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
+                  <!--<el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>-->
+              <!--</div>-->
+              <!--<div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>-->
           </el-upload>
           <div slot="footer" class="dialog-footer">
               <el-button type="primary" @click="submitFileForm">确 定</el-button>