Bladeren bron

Merge remote-tracking branch 'origin/master'

ly 3 jaren geleden
bovenliggende
commit
4942d65117

+ 3 - 0
master/src/main/java/com/ruoyi/project/common/CommonController.java

@@ -268,6 +268,9 @@ public class CommonController extends BaseController
         }else if( type.equals("specDt") ) {
             downloadname = "电梯导入模板.xlsx";
             url = "static/template/sems/specDt.xlsx";
+        }else if( type.equals("reportYlrq") ) {
+            downloadname = "压力容器年检报告批量导入更新模板.xlsx";
+            url = "static/template/sems/reportYlrq.xlsx";
         }
         InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(url);
 

+ 178 - 8
master/src/main/java/com/ruoyi/project/sems/controller/TReportYlrqController.java

@@ -1,17 +1,19 @@
 package com.ruoyi.project.sems.controller;
 
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.List;
 
+import com.alibaba.fastjson.JSON;
+import com.ruoyi.common.utils.file.ExcelUtils;
+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.sems.domain.TReportYlrq;
@@ -20,6 +22,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;
 
 /**
  * 压力容器年检报告Controller
@@ -68,6 +71,173 @@ public class TReportYlrqController extends BaseController {
         return util.exportExcel(list, "reportYlrq");
     }
 
+    /**
+     * 批量导入
+     */
+    @Log(title = "压力容器批量导入更新", businessType = BusinessType.INSERT)
+    @PostMapping("/importForUpdate")
+    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<TReportYlrq> list = new ArrayList<>();
+
+        int rowNum = sheet.getPhysicalNumberOfRows();
+        int failNumber = 0;
+        for (int i = 2; i < rowNum; i++) {
+            try {
+                logger.info("读取行数:" + i);
+                Row row = sheet.getRow(i);
+                int cellNum = row.getPhysicalNumberOfCells();
+                TReportYlrq entity = new TReportYlrq();
+                for (int j = 0; j < cellNum; j++) {
+                    Cell cell = row.getCell(j);
+                    if (cell == null) {
+                        continue;
+                    }
+                    String cellValue = ExcelUtils.getCellValue(cell);
+                    logger.info("cellValue:" + cellValue);
+                    if (j == 0) {
+                        //使用证
+                        entity.setUseno(cellValue);
+                    } else if (j == 1) {
+                        //注册编号
+                        entity.setRegno(cellValue);
+                    } else if (j == 2) {
+                        //位号
+                        entity.setDevno(cellValue);
+                    } else if (j == 3) {
+                        //位号
+                        entity.setPj1(cellValue);
+                    } else if (j == 4) {
+                        //位号
+                        entity.setPj2(cellValue);
+                    } else if (j == 5) {
+                        //位号
+                        entity.setPj3(cellValue);
+                    } else if (j == 6) {
+                        //位号
+                        entity.setPj4(cellValue);
+                    } else if (j == 7) {
+                        //位号
+                        entity.setPj5(cellValue);
+                    } else if (j == 8) {
+                        //位号
+                        entity.setPj6(cellValue);
+                    } else if (j == 9) {
+                        //位号
+                        entity.setPj7(cellValue);
+                    } else if (j == 10) {
+                        //位号
+                        entity.setPj8(cellValue);
+                    } else if (j == 11) {
+                        //位号
+                        entity.setPj9(cellValue);
+                    } else if (j == 12) {
+                        //位号
+                        entity.setPj10(cellValue);
+                    } else if (j == 13) {
+                        //位号
+                        entity.setPj11(cellValue);
+                    } else if (j == 14) {
+                        //位号
+                        entity.setPj12(cellValue);
+                    } else if (j == 15) {
+                        //位号
+                        entity.setPj13(cellValue);
+                    } else if (j == 16) {
+                        //位号
+                        entity.setPj14(cellValue);
+                    } else if (j == 17) {
+                        //位号
+                        entity.setPj15(cellValue);
+                    } else if (j == 18) {
+                        //位号
+                        entity.setPj16(cellValue);
+                    } else if (j == 19) {
+                        //位号
+                        entity.setPj17(cellValue);
+                    } else if (j == 20) {
+                        //位号
+                        entity.setPj18(cellValue);
+                    } else if (j == 21) {
+                        //位号
+                        entity.setPj19(cellValue);
+                    } else if (j == 22) {
+                        //位号
+                        entity.setPj20(cellValue);
+                    } else if (j == 23) {
+                        //位号
+                        entity.setPj21(cellValue);
+                    } else if (j == 24) {
+                        //位号
+                        entity.setPj22(cellValue);
+                    } else if (j == 25) {
+                        //位号
+                        entity.setPj23(cellValue);
+                    } else if (j == 26) {
+                        //位号
+                        entity.setPj24(cellValue);
+                    } else if (j == 27) {
+                        //位号
+                        entity.setPj25(cellValue);
+                    } else if (j == 28) {
+                        //位号
+                        entity.setPj26(cellValue);
+                    } else if (j == 29) {
+                        //位号
+                        entity.setPj27(cellValue);
+                    } else if (j == 30) {
+                        //位号
+                        entity.setPj28(cellValue);
+                    } else if (j == 31) {
+                        //位号
+                        entity.setPj29(cellValue);
+                    } else if (j == 32) {
+                        //位号
+                        entity.setPj30(cellValue);
+                    } else if (j == 33) {
+                        //位号
+                        entity.setPj31(cellValue);
+                    } else if (j == 34) {
+                        //位号
+                        entity.setPj32(cellValue);
+                    }
+                }
+                entity.setCreaterCode(userId);
+                logger.info("entity:" + entity);
+                list.add(entity);
+            } catch (Exception e) {
+                failNumber++;
+                logger.info("e:" + JSON.toJSONString(e));
+                failRow.add(i + 1);
+            }
+        }
+        int successNumber = 0;
+        int failNum = 0;
+        for (TReportYlrq t : list
+        ) {
+            failNum++;
+            try {
+                //TODO 根据使用证、注册编号、位号,进行数据更新
+                this.tReportYlrqService.updateForImport(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);
+    }
+
     /**
      * 获取压力容器年检报告详细信息
      */

+ 8 - 0
master/src/main/java/com/ruoyi/project/sems/mapper/TReportYlrqMapper.java

@@ -31,6 +31,14 @@ public interface TReportYlrqMapper {
      */
     public int updateByTSpecdevYlrq(TSpecdevYlrq tSpecdevYlrq);
 
+    /**
+     * 根据excel导入的数据进行数据更新操作
+     * 根据 位号、使用证、注册编号 3个条件去更新
+     * @param tReportYlrq excel中获取的数据
+     * @return
+     */
+    public int updateForImport(TReportYlrq tReportYlrq);
+
     /**
      * 获取压力容器在用台账与压力管道年检数据需要插入的id
      *

+ 8 - 0
master/src/main/java/com/ruoyi/project/sems/service/ITReportYlrqService.java

@@ -27,6 +27,14 @@ public interface ITReportYlrqService {
 
     public int deleteTReportYlrqByIds();
 
+    /**
+     * 根据excel导入的数据进行数据更新操作
+     * 根据 位号、使用证、注册编号 3个条件去更新
+     * @param tReportYlrq excel中获取的数据
+     * @return
+     */
+    public int updateForImport(TReportYlrq tReportYlrq);
+
     /**
      * 查询压力容器年检报告
      *

+ 5 - 1
master/src/main/java/com/ruoyi/project/sems/service/impl/TReportYlrqServiceImpl.java

@@ -4,7 +4,6 @@ import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
-import com.ruoyi.project.sems.domain.TSpecdevYlgd;
 import com.ruoyi.project.sems.domain.TSpecdevYlrq;
 import com.ruoyi.project.sems.mapper.TSpecdevYlrqMapper;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -69,6 +68,11 @@ public class TReportYlrqServiceImpl implements ITReportYlrqService {
         return 0;
     }
 
+    @Override
+    public int updateForImport(TReportYlrq tReportYlrq) {
+        return this.tReportYlrqMapper.updateForImport(tReportYlrq);
+    }
+
     /**
      * 查询压力容器年检报告
      *

+ 54 - 5
master/src/main/resources/mybatis/sems/TReportYlrqMapper.xml

@@ -171,10 +171,14 @@
     <select id="selectTReportYlrqList" parameterType="TReportYlrq" resultMap="TReportYlrqResult">
         <include refid="selectTReportYlrqVo"/>
         <where>
-            <if test="plantCode != null  and plantCode != ''"> and y.plant_code like concat(concat('%', #{plantCode}), '%')</if>
-            <if test="approveStatus != null  and approveStatus != '' or approveStatus== 0"> and d.approve_status = #{approveStatus}</if>
-            <if test="unit != null and unit != ''"> and y.unit like concat(concat('%', #{unit}), '%')</if>
-            <if test="devno != null and devno != ''"> and y.devno like concat(concat('%', #{devno}), '%')</if>
+            <if test="plantCode != null  and plantCode != ''">and y.plant_code like concat(concat('%', #{plantCode}),
+                '%')
+            </if>
+            <if test="approveStatus != null  and approveStatus != '' or approveStatus== 0">and d.approve_status =
+                #{approveStatus}
+            </if>
+            <if test="unit != null and unit != ''">and y.unit like concat(concat('%', #{unit}), '%')</if>
+            <if test="devno != null and devno != ''">and y.devno like concat(concat('%', #{devno}), '%')</if>
             and d.del_flag = 0
         </where>
         <!-- 数据范围过滤 -->
@@ -237,6 +241,51 @@
         where id = #{id}
     </update>
 
+    <update id="updateForImport">
+        update t_report_ylrq
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="pj1 != null">pj1 = #{pj1},</if>
+            <if test="pj2 != null">pj2 = #{pj2},</if>
+            <if test="pj3 != null">pj3 = #{pj3},</if>
+            <if test="pj4 != null">pj4 = #{pj4},</if>
+            <if test="pj5 != null">pj5 = #{pj5},</if>
+            <if test="pj6 != null">pj6 = #{pj6},</if>
+            <if test="pj7 != null">pj7 = #{pj7},</if>
+            <if test="pj8 != null">pj8 = #{pj8},</if>
+            <if test="pj9 != null">pj9 = #{pj9},</if>
+            <if test="pj10 != null">pj10 = #{pj10},</if>
+            <if test="pj11 != null">pj11 = #{pj11},</if>
+            <if test="pj12 != null">pj12 = #{pj12},</if>
+            <if test="pj13 != null">pj13 = #{pj13},</if>
+            <if test="pj14 != null">pj14 = #{pj14},</if>
+            <if test="pj15 != null">pj15 = #{pj15},</if>
+            <if test="pj16 != null">pj16 = #{pj16},</if>
+            <if test="pj17 != null">pj17 = #{pj17},</if>
+            <if test="pj18 != null">pj18 = #{pj18},</if>
+            <if test="pj19 != null">pj19 = #{pj19},</if>
+            <if test="pj20 != null">pj20 = #{pj20},</if>
+            <if test="pj21 != null">pj21 = #{pj21},</if>
+            <if test="pj22 != null">pj22 = #{pj22},</if>
+            <if test="pj23 != null">pj23 = #{pj23},</if>
+            <if test="pj24 != null">pj24 = #{pj24},</if>
+            <if test="pj25 != null">pj25 = #{pj25},</if>
+            <if test="pj26 != null">pj26 = #{pj26},</if>
+            <if test="pj27 != null">pj27 = #{pj27},</if>
+            <if test="pj28 != null">pj28 = #{pj28},</if>
+            <if test="pj29 != null">pj29 = #{pj29},</if>
+            <if test="pj30 != null">pj30 = #{pj30},</if>
+            <if test="pj31 != null">pj31 = #{pj31},</if>
+            <if test="pj32 != null">pj32 = #{pj32},</if>
+        </trim>
+        where dev_id = (
+        select id
+        from t_specdev_ylrq
+        where devno = #{devno}
+        and useno = #{useno}
+        and regno = #{regno}
+        )
+    </update>
+
     <insert id="insertTReportYlrq" parameterType="TReportYlrq">
         <selectKey keyProperty="id" resultType="long" order="BEFORE">
             SELECT seq_t_report_ylrq.NEXTVAL as id FROM DUAL
@@ -429,4 +478,4 @@
         </foreach>
     </update>
 
-</mapper>
+</mapper>

BIN
master/src/main/resources/static/template/sems/reportYlrq.xlsx


+ 87 - 2
ui/src/views/sems/reportYlrq/index.vue

@@ -69,6 +69,16 @@
         >{{ $t('批量下载历史报告') }}
         </el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="info"
+          icon="el-icon-upload2"
+          size="mini"
+          @click="handleImport"
+          v-hasPermi="['sems:reportYlrq:edit']"
+        >导入更新数据
+        </el-button>
+      </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
@@ -751,6 +761,38 @@
       <el-button type="primary" @click="exportDataForYear">确 定</el-button>
       </span>
     </el-dialog>
+    <!-- 用户导入对话框 -->
+    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
+      <el-upload
+        ref="upload"
+        :limit="1"
+        accept=".xlsx, .xls"
+        :headers="upload.headers"
+        :action="upload.url + '?updateSupport=' + upload.updateSupport"
+        :disabled="upload.isUploading"
+        :on-progress="handleFileUploadProgress"
+        :on-success="handleFileSuccess"
+        :auto-upload="false"
+        drag
+      >
+        <i class="el-icon-upload"></i>
+        <div class="el-upload__text">
+          将文件拖到此处,或
+          <em>点击上传</em>
+        </div>
+        <div class="el-upload__tip" slot="tip">
+          <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>
+        <el-button @click="upload.open = false">取 消</el-button>
+      </div>
+    </el-dialog>
+    <form ref="downloadFileForm" :action="upload.downloadAction" target="FORMSUBMIT">
+      <input name="type" :value="upload.type" hidden />
+    </form>
   </div>
 </template>
 
@@ -770,6 +812,7 @@ import {treeselect} from "@/api/system/dept";
 import Treeselect from "@riophae/vue-treeselect";
 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
 import YearApprove from './yearapprove'
+import {getToken} from "@/utils/auth";
 
 export default {
   name: "ReportYlrq",
@@ -901,7 +944,24 @@ export default {
         devId: [
           {required: true, message: this.$t('设备id') + this.$t('不能为空'), trigger: "blur"}
         ],
-      }
+      },
+      // 用户导入参数
+      upload: {
+        downloadAction: process.env.VUE_APP_BASE_API + '/common/template',
+        type: "reportYlrq",
+        // 是否显示弹出层(用户导入)
+        open: false,
+        // 弹出层标题(用户导入)
+        title: "",
+        // 是否禁用上传
+        isUploading: false,
+        // 是否更新已经存在的用户数据
+        updateSupport: 0,
+        // 设置上传的请求头部
+        headers: {Authorization: "Bearer " + getToken()},
+        // 上传的地址
+        url: process.env.VUE_APP_BASE_API + "/sems/reportYlrq/importForUpdate"
+      },
     };
   },
   watch: {
@@ -1431,7 +1491,6 @@ export default {
         this.$refs['downloadForm'].submit()
       })
     },
-
     //批量下载某年份的历史报告
     exportDataForYear() {
       //将控件时间转为年,如果未选中年份,默认当前年
@@ -1445,7 +1504,33 @@ export default {
       })
       //下载完成后关闭弹窗
       this.dialogVisible = false;
+    },
+    /** 导入按钮操作 */
+    handleImport() {
+      this.upload.title = "用户导入";
+      this.upload.open = true;
+    },
+    /** 下载模板操作 */
+    importTemplate() {
+      this.$refs['downloadFileForm'].submit()
+    },
+    // 文件上传中处理
+    handleFileUploadProgress(event, file, fileList) {
+      this.upload.isUploading = true;
+    },
+    // 文件上传成功处理
+    handleFileSuccess(response, file, fileList) {
+      this.upload.open = false;
+      this.upload.isUploading = false;
+      this.$refs.upload.clearFiles();
+      this.$alert(response.msg, "导入结果", {dangerouslyUseHTMLString: true});
+      this.getList();
+    },
+    // 提交上传文件
+    submitFileForm() {
+      this.$refs.upload.submit();
     }
+
   }
 };
 </script>