Jelajahi Sumber

点检任务管理,添加点检记录导出功能

huangpeng 8 bulan lalu
induk
melakukan
205fd39b58

+ 6 - 0
cx-safe-check/cx-save-check-common/pom.xml

@@ -37,6 +37,12 @@
             <version>4.4.0</version>
             <scope>compile</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>4.1.0</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 2 - 0
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/dao/PointCheckDao.java

@@ -260,4 +260,6 @@ public interface PointCheckDao extends BaseDao<PointCheckDo> {
             "order by a.CREATEDATE desc,a.SHIFT asc " +
             "</script>")
     IPage<PointCheckVo> spareNotPointCheckList(Page<PointCheckVo> page, @Param("beginDate") String beginDate, @Param("endDate") String endDate, @Param("checkitemid") String checkitemid);
+
+    List<PointCheckVo> getExcelDataByids(@Param("ids") List<String> ids);
 }

+ 2 - 0
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/dao/PointCheckItemDao.java

@@ -19,4 +19,6 @@ public interface PointCheckItemDao extends BaseDao<PointCheckItemDo> {
     @Select("select * from asp_point_check_item where deleted = '0' and POINTCHECKID=#{pointcheckid} order by ITEMSORT asc")
     List<PointCheckItemDo> getItemList(@Param("pointcheckid") String pointcheckid);
 
+    @Select("select FULLPATH from sys_file_item where deleted = '0' and RELATIONID=#{relationid} and FILENAME=#{filename}")
+    String getExcelTempPath(@Param("relationid")  String relationid,@Param("filename")  String filename);
 }

+ 2 - 0
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/service/PointCheckItemService.java

@@ -14,5 +14,7 @@ import java.util.List;
  */
 public interface PointCheckItemService extends IService<PointCheckItemDo> {
     List<PointCheckItemDo> getListByPointCheckId(String pointCheckId);
+
+    String getExcelTempPath(String pagePartId, String fileTemplateName);
 }
 

+ 5 - 0
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/service/PointCheckService.java

@@ -3,8 +3,11 @@ package com.rongwei.sfcommon.sys.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.rongwe.scentity.domian.PointCheckDo;
+import com.rongwe.scentity.domian.PointCheckExcelData;
 import com.rongwe.scentity.vo.PointCheckVo;
 import com.rongwei.rwcommon.base.QueryPar;
+
+import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 
 /**
@@ -31,5 +34,7 @@ public interface PointCheckService extends IService<PointCheckDo> {
     void pintCheckDelayReminder();
 
     IPage<PointCheckVo> sparePointCheckList(QueryPar<PointCheckVo> pointCheckVo);
+
+    void excelExport(PointCheckExcelData excelData, HttpServletResponse response);
 }
 

+ 5 - 0
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/service/impl/PointCheckItemServiceImpl.java

@@ -26,4 +26,9 @@ public class PointCheckItemServiceImpl extends ServiceImpl<PointCheckItemDao, Po
         return pointCheckItemDao.getItemList(pointCheckId);
 //        return (List<PointCheckItemDo>) this.listByMap(queryMap);
     }
+
+    @Override
+    public String getExcelTempPath(String relationid, String filename) {
+        return pointCheckItemDao.getExcelTempPath(relationid,filename);
+    }
 }

+ 185 - 3
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/service/impl/PointCheckServiceImpl.java

@@ -3,8 +3,8 @@ package com.rongwei.sfcommon.sys.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
-import cn.hutool.system.SystemUtil;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -19,23 +19,31 @@ import com.rongwei.rwadmincommon.system.service.SysConfigFeignService;
 import com.rongwei.rwadmincommon.system.service.SysUserOrgService;
 import com.rongwei.rwadmincommon.system.service.SysUserService;
 import com.rongwei.rwcommon.base.QueryPar;
+import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
 import com.rongwei.rwcommon.vo.MailDo;
-import com.rongwei.rwcommonentity.commonservers.vo.SysSerialVo;
 import com.rongwei.sfcommon.sys.dao.PointCheckDao;
 import com.rongwei.sfcommon.sys.service.*;
 import com.rongwei.sfcommon.utils.MlConstants;
 import org.apache.commons.beanutils.BeanUtils;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.lang.reflect.InvocationTargetException;
 import java.util.*;
-
+import java.util.stream.Collectors;
 import static com.rongwei.sfcommon.utils.CommonUtil.streamCodeGeneration;
 
 @Service("pointCheckService")
@@ -468,6 +476,180 @@ public class PointCheckServiceImpl extends ServiceImpl<PointCheckDao, PointCheck
 
     }
 
+    @Override
+    public void excelExport(PointCheckExcelData excelData, HttpServletResponse response) {
+        logger.info("Excel导出开始...");
+        //1. 整理主子表数据
+        List<PointCheckVo> mains =pointCheckDao.getExcelDataByids(excelData.getIds());
+        //2.子表数据
+        Map<String, List<PointCheckItemDo>> subMaps = pointCheckItemService.list(new LambdaQueryWrapper<PointCheckItemDo>()
+                .eq(PointCheckItemDo::getDeleted, "0")
+                .in(PointCheckItemDo::getPointcheckid, excelData.getIds())).stream().collect(Collectors.groupingBy(PointCheckItemDo::getPointcheckid));
+
+        //3.获取点检记录模板
+        String fullPath = pointCheckItemService.getExcelTempPath(excelData.getPagePartId(),excelData.getFileTemplateName());
+
+      //  fullPath="C:\\360安全浏览器下载\\"+excelData.getFileTemplateName();
+        XSSFWorkbook workbook =null;
+
+        try {
+            InputStream fileInputStream = new FileInputStream(fullPath);
+            workbook = new XSSFWorkbook(fileInputStream);
+            XSSFSheet tempSheet = workbook.getSheetAt(0);
+            excelData.setStartIndex(0);
+            //处理文件数据填充
+            for (PointCheckVo main:mains){
+                this.fillFirstData(tempSheet,workbook,main,subMaps.get(main.getId()),excelData);
+            };
+
+            workbook.removeSheetAt(0);
+
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        //文件名称
+        String filename = excelData.getFileName();
+        try {
+            try {
+                filename = new String(filename.getBytes(), "ISO8859-1");
+            } catch (UnsupportedEncodingException e) {
+
+            }
+            response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setHeader("Content-Disposition", "attachment;filename=" + filename);
+            response.addHeader("Pargam", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+
+            // 获取ServletOutputStream对象,用于将Workbook内容写入响应
+            ServletOutputStream outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+            // 刷新输出流,确保所有数据都被发送
+            outputStream.flush();
+            // 关闭Workbook对象(注意:在某些情况下,你可能需要在finally块中关闭它,以确保即使发生异常也能关闭)
+            workbook.close();
+
+        } catch (Exception ex) {
+            log.error("导出失败", ex);
+            throw new CustomException("导出失败");
+        }
+        logger.info("Excel导出结束...");
+    }
+
+    /**
+     * 填充模板数据
+     *
+     * @param tempSheet
+     * @param workbook
+     * @param pointCheckVo
+     * @param pointCheckItemDos
+     * @param excelData
+     * @return
+     */
+    private void fillFirstData(XSSFSheet tempSheet, XSSFWorkbook workbook, PointCheckVo pointCheckVo, List<PointCheckItemDo> pointCheckItemDos, PointCheckExcelData excelData) {
+        XSSFSheet sheet =null;
+        Boolean saveOneSheet = excelData.getSaveOneSheet();
+        int indexstart =excelData.getStartIndex();
+        //新增一个sheet 中
+        if (saveOneSheet && indexstart==0){
+             sheet = workbook.createSheet();
+        }else if (saveOneSheet && indexstart >0){
+            sheet = workbook.getSheetAt(1);
+        }else {
+            sheet = workbook.createSheet();
+        }
+
+        XSSFRow row =null;
+        XSSFRow catchRow = tempSheet.getRow(8);
+        XSSFRow detailTieleRow = tempSheet.getRow(5);
+        XSSFCell cell =null;
+
+        Short detailHight = 700;
+        CellRangeAddress cellRangeAddress =null;   // 合并单元格
+
+        for (int i = indexstart; i < 8+pointCheckItemDos.size()+indexstart; i++) {
+            row = sheet.createRow(i);
+            for (int j = 0; j < 7; j++) {
+                 cell = row.createCell(j);
+                 if (i-indexstart <=6){
+                     cell.setCellStyle(tempSheet.getRow(i-indexstart).getCell(j).getCellStyle());
+                 }else if (i== 7+pointCheckItemDos.size()+indexstart){
+                     cell.setCellStyle(tempSheet.getRow(8).getCell(j).getCellStyle());
+                 }else {
+                     cell.setCellStyle(tempSheet.getRow(5).getCell(j).getCellStyle());
+                 }
+            };
+            if (i== 7+pointCheckItemDos.size()+indexstart){
+                row.setHeight(tempSheet.getRow(8).getHeight());
+            }else if (i-indexstart > 6){
+                row.setHeight(detailHight);
+            }
+        };
+
+        //填充主表数据
+        sheet.getRow(indexstart+0).getCell(0).setCellValue(pointCheckVo.getPointcheckname()); //点检名称
+        sheet.getRow(indexstart+1).getCell(0).setCellValue(pointCheckVo.getTenantid()); //所属工厂
+        sheet.getRow(indexstart+1).getCell(2).setCellValue(pointCheckVo.getWorkshopname()); //车间名称
+        sheet.getRow(indexstart+1).getCell(4).setCellValue(pointCheckVo.getPointcheckcode()); //记录编号
+        sheet.getRow(indexstart+2).getCell(0).setCellValue(pointCheckVo.getCheckitemname()); //设备名称
+        sheet.getRow(indexstart+2).getCell(2).setCellValue(pointCheckVo.getCheckitemcode()); //设备编号
+        sheet.getRow(indexstart+2).getCell(4).setCellValue(pointCheckVo.getTemplatetypename()); //检查类型
+        sheet.getRow(indexstart+3).getCell(0).setCellValue(pointCheckVo.getCreateusername()); //点检人员
+        sheet.getRow(indexstart+3).getCell(2).setCellValue(pointCheckVo.getChecktime()); // 点检时间
+        sheet.getRow(indexstart+3).getCell(4).setCellValue(pointCheckVo.getShiftname()); //班次
+        sheet.getRow(indexstart+4).getCell(0).setCellValue(pointCheckVo.getConfirmoruser()); //点检确认人
+        sheet.getRow(indexstart+4).getCell(2).setCellValue("点检时是否停机:"+pointCheckVo.getClosingdownname()==null?"":pointCheckVo.getClosingdownname()); //点检是否停机
+        sheet.getRow(indexstart+4).getCell(4).setCellValue("结果:"+pointCheckVo.getCheckresultname()==null?"":pointCheckVo.getCheckresultname()); //点检结果
+
+        for (int i = 0; i <7; i++) {
+            sheet.getRow(indexstart+5).getCell(i).setCellValue(detailTieleRow.getCell(i).getStringCellValue());
+        }
+        //填充子表数据
+        for (int i = 0; i < pointCheckItemDos.size(); i++) {
+            row = sheet.getRow(indexstart+7 + i);
+            row.getCell(0).setCellValue(pointCheckItemDos.get(i).getCheckposition());
+            row.getCell(1).setCellValue(pointCheckItemDos.get(i).getCheckcontent());
+            row.getCell(2).setCellValue(pointCheckItemDos.get(i).getChecktype());
+            row.getCell(3).setCellValue(pointCheckItemDos.get(i).getCheckstandard());
+            row.getCell(4).setCellValue(pointCheckItemDos.get(i).getManagement());
+            row.getCell(5).setCellValue(pointCheckItemDos.get(i).getQuotavalue()==null?null:pointCheckItemDos.get(i).getQuotavalue().toPlainString());
+            row.getCell(6).setCellValue(pointCheckItemDos.get(i).getRemark());
+        }
+
+        //异常数据填充
+        row= sheet.getRow(pointCheckItemDos.size() + 7+indexstart);
+        row.getCell(0).setCellValue(catchRow.getCell(0).getStringCellValue());
+        row.getCell(2).setCellValue(catchRow.getCell(2).getStringCellValue());
+
+        //单元格合并
+        cellRangeAddress = new CellRangeAddress(indexstart, indexstart, 0, 6);
+        sheet.addMergedRegion(cellRangeAddress);
+
+        for (int i = 1; i <= 4; i++) {
+            cellRangeAddress = new CellRangeAddress(indexstart+i, indexstart+i, 0, 1);
+            sheet.addMergedRegion(cellRangeAddress);
+            cellRangeAddress = new CellRangeAddress(indexstart+i, indexstart+i, 2, 3);
+            sheet.addMergedRegion(cellRangeAddress);
+            cellRangeAddress = new CellRangeAddress(indexstart+i, indexstart+i, 4, 6);
+            sheet.addMergedRegion(cellRangeAddress);
+        };
+        for (int i = 0; i < 7; i++) {
+            cellRangeAddress = new CellRangeAddress(indexstart+5, indexstart+6, i, i);
+            sheet.addMergedRegion(cellRangeAddress);
+        }
+        cellRangeAddress = new CellRangeAddress(7+pointCheckItemDos.size()+indexstart, 7+pointCheckItemDos.size()+indexstart, 2, 6);
+        sheet.addMergedRegion(cellRangeAddress);
+
+
+        //设置列的宽度
+        for (int i = 0; i < 7; i++) {
+            sheet.setColumnWidth(i, tempSheet.getColumnWidth(i));
+        }
+
+        if (excelData.getSaveOneSheet()){
+            excelData.setStartIndex( 8+pointCheckItemDos.size()+indexstart);
+        }
 
+    };
 
 }

+ 33 - 0
cx-safe-check/cx-save-check-common/src/main/resources/mybatis/PointCheckDao.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.rongwei.sfcommon.sys.dao.PointCheckDao">
+
+    <select id="getExcelDataByids" resultType="com.rongwe.scentity.vo.PointCheckVo">
+        SELECT
+        a.*,
+        b.CHECKITEMNAME,
+        b.CHECKITEMCODE,
+        c.NAME AS TEMPLATETYPENAME,
+        d.NAME AS SHIFTNAME,
+        e.NAME AS CLOSINGDOWNNAME,
+        f.NAME AS CHECKRESULTNAME
+        FROM
+            asp_point_check a
+             LEFT JOIN asp_check_items b ON a.CHECKITEMID = b.id and b.DELETED='0'
+             left join sys_dict c on c.DICTTYPE='template-type' and c.VALUE = a.TEMPLATETYPE and c.DELETED='0'
+              left join sys_dict d on d.DICTTYPE='check-shift' and d.VALUE = a.SHIFT and d.DELETED='0'
+           left join sys_dict e on e.DICTTYPE='YORN' and e.VALUE = a.CLOSINGDOWN and e.DELETED='0'
+          left join sys_dict f on f.DICTTYPE='asp_check_result' and f.VALUE = a.CHECKRESULT and f.DELETED='0'
+        <where>
+            a.DELETED='0'
+            AND a.ID in
+            <foreach collection="ids" item="id" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        </where>
+
+
+
+
+    </select>
+</mapper>

+ 14 - 0
cx-safe-check/cx-save-check-entity/src/main/java/com/rongwe/scentity/domian/PointCheckDo.java

@@ -105,7 +105,21 @@ public class PointCheckDo extends BaseDo implements Serializable {
 	 */
 	private String templatetype;
 
+	/**
+	 * 安全管理员
+	 */
 	private String safeuserid;
 
 	private String safeuser;
+
+	/**
+	 * 是否停机
+	 */
+	private String closingdown;
+
+
+	/**
+	 * 点检确认人
+	 */
+	private String confirmoruser;
 }

+ 42 - 0
cx-safe-check/cx-save-check-entity/src/main/java/com/rongwe/scentity/domian/PointCheckExcelData.java

@@ -0,0 +1,42 @@
+package com.rongwe.scentity.domian;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 点检任务表导出参数
+ */
+@Data
+public class PointCheckExcelData {
+
+    /**
+     * 选中的主表记录id
+     */
+    private List<String> ids;
+
+    /**
+     * 表格的配置id
+     */
+    private String pagePartId;
+
+    /**
+     * 是否导出在一个sheet 中
+     */
+    private Boolean saveOneSheet;
+
+    /**
+     * 导出文件名称
+     */
+    private String fileName;
+
+    /**
+     * 模板文件名称
+     */
+    private String fileTemplateName;
+
+    /**
+     * 下标
+     */
+    private  int  startIndex;
+}

+ 9 - 0
cx-safe-check/cx-save-check-entity/src/main/java/com/rongwe/scentity/vo/PointCheckVo.java

@@ -33,4 +33,13 @@ public class PointCheckVo extends PointCheckDo {
     // 上一班点检信息
     private PointCheckVo lastPointCheck;
 
+
+    // 检查类型名称
+    private String templatetypename;
+    // 巡检时是否停机名称
+    private String closingdownname;
+    // 点检结果 名称
+    private String checkresultname;
+
+
 }

+ 9 - 0
cx-safe-check/cx-save-check-server/src/main/java/com/rongwei/savecheck/controller/PointCheckController.java

@@ -6,6 +6,7 @@ import java.util.Map;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.rongwe.scentity.domian.PointCheckDo;
+import com.rongwe.scentity.domian.PointCheckExcelData;
 import com.rongwei.rwcommon.utils.StringUtils;
 import com.rongwei.sfcommon.sys.service.PointCheckService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -14,6 +15,8 @@ import com.rongwei.rwcommon.base.QueryPar;
 import com.rongwei.rwcommon.base.R;
 import lombok.extern.slf4j.Slf4j;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * 点检任务表
  *
@@ -114,4 +117,10 @@ public class PointCheckController {
         }
     }
 
+
+    @PostMapping("/excelExport")
+    public void excelExport(@RequestBody PointCheckExcelData pointCheckExcelData, HttpServletResponse response){
+        pointCheckService.excelExport(pointCheckExcelData,response);
+    }
+
 }