wangggziwen 2 年 前
コミット
fe0ff79612

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

@@ -105,6 +105,9 @@ public class CommonController extends BaseController
         } else if( type.equals("lbnhjstj") ) {
             downloadname = "能耗管理统计导入模板.xlsx";
             url = "static/template/production/lbnhjstj.xlsx";
+        } else if( type.equals("sai") ) {
+            downloadname = "SAI信息导入模板.xlsx";
+            url = "static/template/production/sai.xlsx";
         } else if( type.equals("rcaudit") ) {
             downloadname = "RC审计助手导入模板.xlsx";
             url = "static/template/ehs/rcaudit.xlsx";

+ 110 - 8
master/src/main/java/com/ruoyi/project/production/controller/TSaiController.java

@@ -1,18 +1,27 @@
 package com.ruoyi.project.production.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.DateUtils;
+import com.ruoyi.common.utils.file.ExcelUtils;
+import com.ruoyi.project.process.domain.TMoc;
 import com.ruoyi.project.production.controller.vo.SaiQueryVO;
+import com.ruoyi.project.system.domain.SysDept;
+import com.ruoyi.project.system.domain.SysDictData;
+import com.ruoyi.project.system.service.ISysDeptService;
+import com.ruoyi.project.system.service.ISysDictTypeService;
+import com.ruoyi.project.system.service.ISysUserService;
+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.production.domain.TSai;
@@ -21,6 +30,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;
 
 /**
  * SAI信息Controller
@@ -35,6 +45,15 @@ public class TSaiController extends BaseController
     @Autowired
     private ITSaiService tSaiService;
 
+    @Autowired
+    private ISysUserService userService;
+
+    @Autowired
+    private ISysDictTypeService iSysDictTypeService;
+
+    @Autowired
+    private ISysDeptService iSysDeptService;
+
     /**
      * 查询SAI信息列表
      */
@@ -59,6 +78,89 @@ public class TSaiController extends BaseController
         return getDataTable(list);
     }
 
+    /**
+     * 批量导入SAI信息列表
+     */
+    @PreAuthorize("@ss.hasPermi('production:sai: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<TSai> list = new ArrayList<TSai>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        //字典查询
+//        List<SysDictData> tempStateDict = iSysDictTypeService.selectDictDataByType("TEMP_STATE");
+        //部门查询
+        List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
+        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();
+                TSai entity = new TSai();
+                entity.setDelFlag("0");
+                entity.setDeptId(userService.selectUserById(userId).getDeptId());
+                for (int j = 0; j < cellNum; j++) {
+                    Cell cell = row.getCell(j);
+                    //  cell.setCellType(CellType.STRING);
+                    String cellValue = ExcelUtils.getCellValue(cell);
+                    logger.info("cellValue:" + cellValue);
+                    if (j == 0) {
+                        entity.setPlantId(cellValue);
+                    } else if (j == 1) {
+                        if (cellValue.length() > 3) {
+                            entity.setInspectionDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
+                        }
+                    } else if (j == 2) {
+                        entity.setDificiency(cellValue);
+                    } else if (j == 3) {
+                        entity.setSaiLevel(Long.parseLong(cellValue));
+                    } else if (j == 4) {
+                        entity.setCategory(cellValue);
+                    } else if (j == 5) {
+                        entity.setActions(cellValue);
+                    } else if (j == 6) {
+                        entity.setUserDept(cellValue);
+                    } else if (j == 7) {
+                        entity.setSource(cellValue);
+                    }
+                }
+                entity.setCreateBy(userId.toString());
+                logger.info("entity:" + entity);
+                list.add(entity);
+            }catch (Exception e){
+                failNumber++;
+                failRow.add(i+1);
+            }
+        }
+        int successNumber = 0;
+        int failNum = 0;
+        for (TSai t : list
+        ) {
+            failNum++;
+            try {
+                tSaiService.insertTSai(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);
+    }
+
     /**
      * 导出SAI信息列表
      */

+ 0 - 1
master/src/main/java/com/ruoyi/project/production/domain/TSai.java

@@ -18,7 +18,6 @@ public class TSai extends BaseEntity
     private static final long serialVersionUID = 1L;
 
     /** 主键 */
-    @Excel(name = "主键")
     private Long saiId;
 
     /** 检查的装置/设施 */

BIN
master/src/main/resources/static/template/production/sai.xlsx


+ 33 - 11
ui/src/views/production/sai/index.vue

@@ -183,6 +183,9 @@
                   <!--<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
                   <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
               </div>
+              <form ref="downloadFileForm" :action="upload.downloadAction" target="FORMSUBMIT">
+                <input name="type" :value="upload.type" hidden />
+              </form>
               <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
           </el-upload>
           <div slot="footer" class="dialog-footer">
@@ -228,6 +231,10 @@ export default {
       open: false,
         // 用户导入参数
         upload: {
+            //下载模板请求地址
+            downloadAction: process.env.VUE_APP_BASE_API + '/common/template',
+            //下载模板类型
+            type: 'sai',
             // 是否显示弹出层(用户导入)
             open: false,
             // 弹出层标题(用户导入)
@@ -270,6 +277,7 @@ export default {
         }
    },
   created() {
+    this.setYear();
       //设置表格高度对应屏幕高度
       this.$nextTick(() => {
           this.clientHeight = document.body.clientHeight -250
@@ -279,10 +287,12 @@ export default {
     this.getTreeselect();
   },
   methods: {
+    setYear() {
+      this.queryParams.saiYear = new Date().getFullYear().toString();
+    },
     /** 查询SAI信息列表 */
     getListByYear() {
       this.loading = true;
-      console.log(this.queryParams);
       listSaiByYear(this.queryParams).then(response => {
         this.saiList = response.rows;
         this.total = response.total;
@@ -291,7 +301,6 @@ export default {
     },
     getList() {
       this.loading = true;
-      console.log(this.queryParams);
       listSai(this.queryParams).then(response => {
         this.saiList = response.rows;
         this.total = response.total;
@@ -332,7 +341,7 @@ export default {
     /** 搜索按钮操作 */
     handleQuery() {
       this.queryParams.pageNum = 1;
-      this.getList();
+      this.getListByYear();
     },
     /** 重置按钮操作 */
     resetQuery() {
@@ -415,9 +424,18 @@ export default {
       },
       /** 下载模板操作 */
       importTemplate() {
-          importTemplate().then(response => {
-              this.download(response.msg);
-          });
+        this.$refs['downloadFileForm'].submit()
+      },
+      // 文件下载处理
+      handleDownload(row) {
+        var name = row.fileName;
+        var url = row.fileUrl;
+        var suffix = url.substring(url.lastIndexOf("."), url.length);
+        const a = document.createElement('a')
+        a.setAttribute('download', name)
+        a.setAttribute('target', '_blank')
+        a.setAttribute('href', process.env.VUE_APP_BASE_API + url)
+        a.click()
       },
       // 文件上传中处理
       handleFileUploadProgress(event, file, fileList) {
@@ -425,11 +443,15 @@ export default {
       },
       // 文件上传成功处理
       handleFileSuccess(response, file, fileList) {
-          this.upload.open = false;
-          this.upload.isUploading = false;
-          this.$refs.upload.clearFiles();
-          this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
-          this.getList();
+        this.upload.open = false;
+        this.upload.isUploading = false;
+        this.$refs.upload.clearFiles();
+        if (response.data[0] != null) {
+          this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据') + "," + this.$t('第') + response.data + this.$t('行数据出现错误导入失败')+"。", this.$t('导入结果'), { dangerouslyUseHTMLString: true });
+        }else {
+          this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据'), this.$t('导入结果'), { dangerouslyUseHTMLString: true });
+        }
+        this.getList();
       },
       // 提交上传文件
       submitFileForm() {