Browse Source

cpms优化
附件管理

jiangbiao 1 năm trước cách đây
mục cha
commit
5241184cc5

+ 131 - 0
cpms-admin/src/main/java/com/cpms/project/asset/controller/TLeakagePointsPatrolController.java

@@ -5,6 +5,7 @@ import com.cpms.common.core.controller.BaseController;
 import com.cpms.common.core.domain.AjaxResult;
 import com.cpms.common.core.page.TableDataInfo;
 import com.cpms.common.enums.BusinessType;
+import com.cpms.common.utils.DateUtils;
 import com.cpms.common.utils.poi.ExcelUtil;
 import com.cpms.project.asset.domain.TLeakagePoints;
 import com.cpms.project.asset.domain.TLeakagePointsPatrol;
@@ -13,11 +14,15 @@ import com.cpms.project.asset.service.ITLeakagePointsPatrolService;
 import com.cpms.project.asset.service.ITLeakagePointsRecordService;
 import com.cpms.project.asset.service.ITLeakagePointsService;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.Date;
 import java.util.List;
 
@@ -70,6 +75,130 @@ public class TLeakagePointsPatrolController extends BaseController {
         util.exportExcel(response, list, "漏点巡检数据");
     }
 
+    @PreAuthorize("@ss.hasPermi('asset:pointPatrol:export')")
+    @Log(title = "漏点巡检", businessType = BusinessType.EXPORT)
+    @PostMapping("/exportRecord")
+    public void exportRecord(HttpServletResponse response, TLeakagePointsPatrol tLeakagePointsPatrol) throws IOException {
+
+        if (tLeakagePointsPatrol.getCheckDateM() == null) {
+            tLeakagePointsPatrol.setCheckDateM(new Date());
+        }
+        List<TLeakagePointsPatrol> list = tLeakagePointsPatrolService.selectTLeakagePointsPatrolList(tLeakagePointsPatrol);
+        SXSSFWorkbook wb = new SXSSFWorkbook(1000);
+        // 正文格式
+        CellStyle style2 = wb.createCellStyle();
+        // 内容垂直居中,四周加边框线,自动换行
+        style2.setAlignment(HorizontalAlignment.CENTER);
+        style2.setVerticalAlignment(VerticalAlignment.CENTER);
+        style2.setBorderBottom(BorderStyle.THIN);
+        style2.setBorderLeft(BorderStyle.THIN);
+        style2.setBorderRight(BorderStyle.THIN);
+        style2.setBorderTop(BorderStyle.THIN);
+        style2.setWrapText(true);
+        // 设置正文字体,字体颜色
+        Font headerFont2 = wb.createFont();
+        headerFont2.setFontName("Arial");
+        headerFont2.setFontHeightInPoints((short) 10);
+        headerFont2.setColor(IndexedColors.BLACK.getIndex());
+        style2.setFont(headerFont2);
+        //创建sheet页
+        Sheet sheet = wb.createSheet("sheet1");
+        sheet.setDefaultRowHeightInPoints(30);
+        //设置列的宽度,第一个参数为列的序号,从0开始,第二参数为列宽,单位1/256个字节
+        sheet.setColumnWidth(0, 20 * 256);
+        sheet.setColumnWidth(1, 20 * 256);
+        sheet.setColumnWidth(2, 15 * 256);
+        sheet.setColumnWidth(3, 20 * 256);
+        sheet.setColumnWidth(4, 30 * 256);
+        sheet.setColumnWidth(5, 20 * 256);
+        sheet.setColumnWidth(6, 30 * 256);
+        // 创建表格行并设置相应标题
+        Row row0 = sheet.createRow(0);
+        row0.createCell(0).setCellValue("漏点巡检记录表");
+        row0.createCell(1);
+        row0.createCell(3);
+        row0.createCell(4);
+        row0.createCell(5);
+        row0.createCell(2).setCellValue("日期");
+        row0.createCell(6);
+        Row row1 = sheet.createRow(1);
+        row1.createCell(0);
+        row1.createCell(1);
+        row1.createCell(3);
+        row1.createCell(4);
+        row1.createCell(5);
+        row1.createCell(2).setCellValue("班组");
+        row1.createCell(6);
+        Row row2 = sheet.createRow(2);
+        row2.createCell(0);
+        row2.createCell(1);
+        row2.createCell(2).setCellValue("时间");
+        row2.createCell(3).setCellValue("早班一次");
+        row2.createCell(4);
+        row2.createCell(5).setCellValue("夜班一次");
+        row2.createCell(6);
+        Row row3 = sheet.createRow(3);
+        row3.createCell(0).setCellValue("漏点编号");
+        row3.createCell(1).setCellValue("漏点位置");
+        row3.createCell(2).setCellValue("介质");
+        row3.createCell(3).setCellValue("挂牌 (是/否)");
+        row3.createCell(4).setCellValue("泄露状态 (未检出/轻微/严重)");
+        row3.createCell(5).setCellValue("挂牌 (是/否)");
+        row3.createCell(6).setCellValue("泄露状态 (未检出/轻微/严重)");
+        // 合并单元格  参数(1:起始行,2:结束行,3:起始列,4:结束列)
+        sheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 1));
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 4));
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, 5, 6));
+        sheet.addMergedRegion(new CellRangeAddress(1, 1, 3, 4));
+        sheet.addMergedRegion(new CellRangeAddress(1, 1, 5, 6));
+        sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 4));
+        sheet.addMergedRegion(new CellRangeAddress(2, 2, 5, 6));
+        if (CollectionUtils.isNotEmpty(list)) {
+            TLeakagePointsRecord record = new TLeakagePointsRecord();
+            TLeakagePointsPatrol patrol = list.get(0);
+            record.setPatrolId(patrol.getId());
+            patrol.setRecords(tLeakagePointsRecordService.selectTLeakagePointsRecordList(record));
+            row0.createCell(3).setCellValue(DateUtils.dateTime(patrol.getCheckDateM()));
+            row0.createCell(5).setCellValue(DateUtils.dateTime(patrol.getCheckDateN()));
+            row1.createCell(3).setCellValue(patrol.getTeamM() + "班");
+            row1.createCell(5).setCellValue(patrol.getTeamN() + "班");
+            int i = 3;
+            for (TLeakagePointsRecord patrolRecord : patrol.getRecords()) {
+                i++;
+                Row row = sheet.createRow(i);
+                row.createCell(0).setCellValue(patrolRecord.getPointNo());
+                row.createCell(1).setCellValue(patrolRecord.getLeakagePosition());
+                row.createCell(2).setCellValue(patrolRecord.getLeakageMedium());
+                row.createCell(3).setCellValue(patrolRecord.getSuspendPlateM());
+                row.createCell(4).setCellValue(patrolRecord.getLeakageStatusM());
+                row.createCell(5).setCellValue(patrolRecord.getSuspendPlateN());
+                row.createCell(6).setCellValue(patrolRecord.getLeakageStatusN());
+                setStyle(row, style2);
+            }
+        }
+        setStyle(row0, style2);
+        setStyle(row1, style2);
+        setStyle(row2, style2);
+        setStyle(row3, style2);
+        // 生成文件返回下载地址
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        response.setCharacterEncoding("utf-8");
+        wb.write(response.getOutputStream());
+        wb.close();
+    }
+
+    /**
+     * 设置单元格格式
+     *
+     * @param row   行
+     * @param style 单元格样式
+     */
+    private void setStyle(Row row, CellStyle style) {
+        for (int i = 0; i <= 6; i++) {
+            row.getCell(i).setCellStyle(style);
+        }
+    }
+
     /**
      * 获取漏点巡检详细信息
      */
@@ -135,4 +264,6 @@ public class TLeakagePointsPatrolController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(tLeakagePointsPatrolService.deleteTLeakagePointsPatrolByIds(ids));
     }
+
+
 }

+ 8 - 3
cpms-admin/src/main/java/com/cpms/project/file/controller/TFileController.java

@@ -89,13 +89,17 @@ public class TFileController extends BaseController {
 
 
     @PostMapping("/uploadFile")
-    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file, @RequestParam(value = "linkId", required = false) Long linkId, @RequestParam(value = "linkName", required = false) String linkName, @RequestParam(value = "pId", required = false) Long pId) throws IOException {
+    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file,
+                                 @RequestParam(value = "linkId", required = false) Long linkId,
+                                 @RequestParam(value = "linkName", required = false) String linkName,
+                                 @RequestParam(value = "pId", required = false) Long pId) throws IOException {
         if (!file.isEmpty()) {
             String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file);
             TFile tFile = new TFile();
             tFile.setFileName(file.getOriginalFilename());
             tFile.setFileUrl(avatar);
-            switch (Objects.requireNonNull(file.getOriginalFilename()).substring(file.getOriginalFilename().lastIndexOf(".") + 1)) {
+            switch (Objects.requireNonNull(file.getOriginalFilename()).substring(
+                    file.getOriginalFilename().lastIndexOf(".") + 1)) {
                 case "jpg":
                 case "png":
                 case "gif":
@@ -125,7 +129,8 @@ public class TFileController extends BaseController {
 
             }
             tFile.setpId(pId);
-            tFile.setFileSize(String.valueOf(new BigDecimal(file.getSize()).divide(BigDecimal.valueOf(1024), 2, RoundingMode.HALF_DOWN)));
+            tFile.setFileSize(String.valueOf(new BigDecimal(file.getSize()).
+                    divide(BigDecimal.valueOf(1024), 2, RoundingMode.HALF_DOWN)));
             tFile.setUploader(getNickname());
             tFile.setUploadDate(new Date());
             tFile.setLinkId(linkId);

+ 7 - 0
cpms-ui/src/views/asset/points/index.vue

@@ -264,6 +264,7 @@
         <el-form-item>
           <el-button type="primary" icon="el-icon-search" size="mini" @click="handleRecordQuery">搜索</el-button>
           <el-button icon="el-icon-refresh" size="mini" @click="resetRecordQuery">重置</el-button>
+          <el-button icon="el-icon-download" size="mini" @click="handleExportPatrol">导出</el-button>
         </el-form-item>
         <right-toolbar :showSearch.sync="record.showSearch" @queryTable="getRecordList" :search="false"></right-toolbar>
       </el-form>
@@ -694,6 +695,12 @@ export default {
       this.download('asset/points/export', {
         ...this.queryParams
       }, `points_${new Date().getTime()}.xlsx`)
+    },
+    /** 导出按钮操作 */
+    handleExportPatrol() {
+      this.download('asset/pointPatrol/exportRecord', {
+        ...this.record.queryParams
+      }, `pointsPatrol_${new Date().getTime()}.xlsx`)
     }
   }
 };