Selaa lähdekoodia

检查报告-导出

zhuang 9 kuukautta sitten
vanhempi
commit
46f0337762

+ 16 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/dao/ZhcxInspectionReportManageDao.java

@@ -0,0 +1,16 @@
+package com.rongwei.bscommon.sys.dao;
+
+import com.rongwei.bsentity.domain.ZhcxInspectionReportManageDo;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * 检查报告管理表 Mapper 接口
+ * </p>
+ *
+ * @author wm
+ * @since 2024-10-30
+ */
+public interface ZhcxInspectionReportManageDao extends BaseMapper<ZhcxInspectionReportManageDo> {
+
+}

+ 19 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxInspectionReportManageService.java

@@ -0,0 +1,19 @@
+package com.rongwei.bscommon.sys.service;
+
+import com.rongwei.bsentity.domain.ZhcxInspectionReportManageDo;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * <p>
+ * 检查报告管理表 服务类
+ * </p>
+ *
+ * @author wm
+ * @since 2024-10-30
+ */
+public interface ZhcxInspectionReportManageService extends IService<ZhcxInspectionReportManageDo> {
+
+    void downloadExcel(HttpServletResponse response, ZhcxInspectionReportManageDo zhcxInspectionReportManageDo);
+}

+ 271 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxInspectionReportManageServiceImpl.java

@@ -0,0 +1,271 @@
+package com.rongwei.bscommon.sys.service.impl;
+
+import cn.hutool.core.io.FileUtil;
+import com.aspose.cells.*;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.rongwei.bsentity.domain.ZhcxInspectionReportManageDo;
+import com.rongwei.bscommon.sys.dao.ZhcxInspectionReportManageDao;
+import com.rongwei.bscommon.sys.service.ZhcxInspectionReportManageService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.rongwei.rwadmincommon.system.domain.SysDictDo;
+import com.rongwei.rwadmincommon.system.service.SysDictService;
+import com.rongwei.rwcommon.base.exception.CustomException;
+import com.rongwei.rwcommon.utils.StringUtils;
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelUtils;
+import com.rongwei.rwcommoncomponent.excel.utils.ExcelHelpUtils;
+import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
+import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * 检查报告管理表 服务实现类
+ * </p>
+ *
+ * @author wm
+ * @since 2024-10-30
+ */
+@Service
+public class ZhcxInspectionReportManageServiceImpl extends ServiceImpl<ZhcxInspectionReportManageDao, ZhcxInspectionReportManageDo> implements ZhcxInspectionReportManageService {
+
+    @Autowired
+    private SysFileItemService sysFileItemService;
+    @Autowired
+    private ExcelUtils excelUtils;
+    @Autowired
+    private SysDictService sysDictService;
+
+    @Override
+    public void downloadExcel(HttpServletResponse response, ZhcxInspectionReportManageDo zhcxInspectionReportManageDo) {
+        String id = zhcxInspectionReportManageDo.getId();
+        if(StringUtils.isEmpty(id)){
+            throw new CustomException("参数异常,请联系管理员排查");
+        }
+        SysFileItemDo templateFile = sysFileItemService.getById("c100d791c13a4ae08a2030476759b50d");
+        Map<String, Object> map = this.getMap(Wrappers.<ZhcxInspectionReportManageDo>lambdaQuery()
+                .eq(ZhcxInspectionReportManageDo::getId, id)
+                .eq(ZhcxInspectionReportManageDo::getDeleted, "0"));
+        if(!excelUtils.GetLicense()) {
+            return;
+        }
+        Object dataappendix = map.get("DATAAPPENDIX");
+        if(dataappendix != null){
+            if (StringUtils.isNotBlank(dataappendix.toString())) {
+                String[] splitFile = dataappendix.toString().split("\\^_\\^");
+                map.put("total", "本报告包括数据附页"+splitFile.length+"份。");
+            }
+        }
+        Workbook wb = ExcelHelpUtils.getWorkbook(templateFile.getFullpath());
+        Worksheet sheet0 = wb.getWorksheets().get(0);
+        Cells cells = sheet0.getCells();
+        for (int row = 0; row < cells.getMaxDataRow() + 1; row++) {
+            for (int col = 0; col < cells.getMaxDataColumn() + 1; col++) {
+                Cell cell = cells.get(row, col);
+                String cellValue = cell.getStringValue();
+                // 检查占位符并替换对应的数据
+                if (cellValue.startsWith("${") && cellValue.endsWith("}")) {
+                    String key = cellValue.substring(2, cellValue.length() - 1);
+                    Object value = map.get(key);
+                    if (value != null) {
+                        // 将占位符替换为实际值
+                        if (key.equals("ISSUES")) {
+                            List<SysDictDo> list = sysDictService.getDictsByType("inspection_report_manage_issues");
+                            List<SysDictDo> collect = list.stream().filter(item -> !item.getPid().equals("-1")).collect(Collectors.toList());
+                            int maxLength = collect.stream()
+                                    .map(SysDictDo -> SysDictDo.getValue().length())
+                                    .max(Integer::compare)
+                                    .orElse(0);
+                            StringBuilder textValue = new StringBuilder();
+                            for (int i = 0; i < collect.size(); i++) {
+                                int length = collect.get(i).getValue().length();
+                                int i1 = maxLength - length;
+                                String join = String.join("", Collections.nCopies(i1, " "));
+                                if (collect.get(i).getValue().equals(value)) {
+                                    textValue.append("  R ").append(collect.get(i).getValue()).append(join);
+                                } else {
+                                    textValue.append("  £ ").append(collect.get(i).getValue()).append(join);
+                                }
+                                if((i+1) % 5 == 0){
+                                    textValue.append("\n");
+                                }
+                            }
+                            // 创建一个样式对象
+                            Style style = cell.getStyle();
+
+                            // 设置水平左对齐
+                            style.setHorizontalAlignment(TextAlignmentType.LEFT);
+                            style.setVerticalAlignment(TextAlignmentType.CENTER);
+                            // 设置向右缩进(单位是缩进级别)
+                            // 缩进级别为2,可根据需要调整
+                            //style.setIndentLevel(1);
+
+                            // 设置字体
+                            Font font = style.getFont();
+                            font.setName("Wingdings 2");
+                            font.setSize(10);
+                            cell.setStyle(style);
+                            cell.putValue(textValue);
+                        }else if(key.equals("FILES")){
+                            Range mergedRange = cell.getMergedRange();
+                            // 确定合并单元格的起始行和列
+                            int startRow = mergedRange.getFirstRow();
+                            int startCol = mergedRange.getFirstColumn();
+                            if (StringUtils.isNotBlank(value.toString())) {
+                                String[] splitFile = value.toString().split("\\^_\\^");
+                                for(int i = 0; i < splitFile.length; i++){
+                                    if(i > 0){
+                                        startCol = startCol+3;
+                                    }
+                                    String fileid = splitFile[i].split("-;-")[1];
+                                    SysFileItemDo fileItemDo = sysFileItemService.getById(fileid);
+                                    if (fileItemDo != null) {
+                                        try (BufferedInputStream inputStream = FileUtil.getInputStream(fileItemDo.getFullpath())) {
+                                            int pictureIndex = sheet0.getPictures().add(startRow, startCol, inputStream, 100, 100); // 设定宽度和高度
+                                            Picture picture = sheet0.getPictures().get(pictureIndex);
+
+                                            // 获取合并单元格的宽度和高度
+                                            double mergedCellWidth = sheet0.getCells().getColumnWidthPixel(startCol) * mergedRange.getColumnCount(); // 合并了多列
+                                            double mergedCellHeight = sheet0.getCells().getRowHeightPixel(startRow); // 行高
+
+                                            // 设置图片的大小和位置(确保图片适应合并单元格)
+                                            picture.setWidth((int) mergedCellWidth); // 图片宽度
+                                            picture.setHeight((int) mergedCellHeight); // 图片高度
+                                            cell.putValue("");
+                                        } catch (IOException e) {
+                                            e.printStackTrace();
+                                        }
+                                    }
+                                }
+                            }
+
+                        }else if(key.equals("DATE")){
+                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                            String format = sdf.format((Date) value);
+                            cell.putValue(format);
+                        } else{
+                            cell.putValue(value);
+                        }
+                    }else{
+                        cell.putValue("");
+                    }
+                }
+            }
+        }
+
+        Worksheet sheet1 = wb.getWorksheets().get(1);
+        Cells cells2 = sheet1.getCells();
+        //Object value = map.get("DATAAPPENDIX");
+        for (int row = 0; row < cells2.getMaxDataRow() + 1; row++) {
+            for (int col = 0; col < cells2.getMaxDataColumn() + 1; col++) {
+                Cell cell = cells2.get(row, col);
+                String cellValue = cell.getStringValue();
+                // 检查占位符并替换对应的数据
+                if (cellValue.startsWith("${") && cellValue.endsWith("}")) {
+                    String key = cellValue.substring(2, cellValue.length() - 1);
+                    Object value = map.get(key);
+                    if (value != null) {
+                        // 将占位符替换为实际值
+                         if(key.equals("DATAAPPENDIX")){
+                            Range mergedRange = cell.getMergedRange();
+                            // 确定合并单元格的起始行和列
+                            int startRow = mergedRange.getFirstRow();
+                            int startCol = mergedRange.getFirstColumn();
+                             if (StringUtils.isNotBlank(value.toString())) {
+                                 String[] splitFile = value.toString().split("\\^_\\^");
+                                 for(int i = 0; i < splitFile.length; i++){
+                                     try {
+                                         int newSheetIndex = wb.getWorksheets().addCopy(1);
+                                         Worksheet newSheet = wb.getWorksheets().get(newSheetIndex);
+                                         // 替换占位符
+                                         replacePlaceholders(newSheet, map,splitFile[i]);
+                                     } catch (Exception e) {
+                                         e.printStackTrace();
+                                     }
+                                 }
+                             }
+                             //cell.putValue("");
+                         } else{
+                            cell.putValue(value);
+                        }
+                    }else{
+                        cell.putValue("");
+                    }
+                }
+            }
+        }
+        wb.getWorksheets().removeAt(1);
+        try {
+            response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setHeader("Content-Disposition", "attachment;filename=测试下载");
+            wb.save(response.getOutputStream(), SaveFormat.XLSX);
+            wb.dispose();
+        } catch (Exception e) {
+            log.error("填充失败:{}", e);
+            throw new CustomException("填充失败");
+        }
+    }
+
+    private void replacePlaceholders(Worksheet sheet, Map<String, Object> data, String splitFile) {
+        Cells cells = sheet.getCells();
+
+        // 遍历单元格并替换占位符
+        for (int row = 0; row < cells.getMaxDataRow() + 1; row++) {
+            for (int col = 0; col < cells.getMaxDataColumn() + 1; col++) {
+                Cell cell = cells.get(row, col);
+                String cellValue = cell.getStringValue();
+
+                // 检查占位符并替换对应的数据
+                if (cellValue.startsWith("${") && cellValue.endsWith("}")) {
+                    String key = cellValue.substring(2, cellValue.length() - 1);
+                    Object value = data.get(key);
+                    if (value != null) {
+
+                        if(key.equals("DATAAPPENDIX")){
+                            Range mergedRange = cell.getMergedRange();
+                            // 确定合并单元格的起始行和列
+                            int startRow = mergedRange.getFirstRow();
+                            int startCol = mergedRange.getFirstColumn();
+                            String fileid = splitFile.split("-;-")[1];
+                            SysFileItemDo fileItemDo = sysFileItemService.getById(fileid);
+                            if (fileItemDo != null) {
+                                try (BufferedInputStream inputStream = FileUtil.getInputStream(fileItemDo.getFullpath())) {
+                                    int pictureIndex = sheet.getPictures().add(startRow, startCol, inputStream, 100, 100); // 设定宽度和高度
+                                    Picture picture = sheet.getPictures().get(pictureIndex);
+
+                                    // 获取合并单元格的宽度和高度
+                                    double mergedCellWidth = sheet.getCells().getColumnWidthPixel(startCol) * mergedRange.getColumnCount(); // 合并了多列
+                                    double mergedCellHeight = sheet.getCells().getRowHeightPixel(startRow) * mergedRange.getRowCount(); // 行高
+
+                                    // 设置图片的大小和位置(确保图片适应合并单元格)
+                                    picture.setWidth((int) mergedCellWidth); // 图片宽度
+                                    picture.setHeight((int) mergedCellHeight); // 图片高度
+                                    cell.putValue("");
+                                } catch (IOException e) {
+                                    e.printStackTrace();
+                                }
+                            }
+                            cell.putValue("");
+                        }else{
+                            // 替换占位符
+                            cell.putValue(value);
+                        }
+                    } else {
+                        // 如果没有对应的数据,清空单元格
+                        cell.putValue("");
+                    }
+                }
+            }
+        }
+    }
+}

+ 184 - 0
business-entity/src/main/java/com/rongwei/bsentity/domain/ZhcxInspectionReportManageDo.java

@@ -0,0 +1,184 @@
+package com.rongwei.bsentity.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.rongwei.rwcommon.base.BaseDo;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 检查报告管理表
+ * </p>
+ *
+ * @author wm
+ * @since 2024-10-30
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+@TableName("ZHCX_INSPECTION_REPORT_MANAGE")
+public class ZhcxInspectionReportManageDo extends BaseDo {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * 主键
+     */
+    @TableField("ID")
+    private String id;
+    /**
+     * 租户id
+     */
+    @TableField("TENANTID")
+    private String tenantid;
+    /**
+     * 扩展json格式配置
+     */
+    @TableField("ROPTION")
+    private String roption;
+    /**
+     * 报告编号
+     */
+    @TableField("NO")
+    private String no;
+    /**
+     * 项目ID
+     */
+    @TableField("PROJECTID")
+    private String projectid;
+    /**
+     * 项目工号
+     */
+    @TableField("PROJECTCODE")
+    private String projectcode;
+    /**
+     * 项目名称
+     */
+    @TableField("PROJECTNAME")
+    private String projectname;
+    /**
+     * 项目简称
+     */
+    @TableField("PROJECTENAME")
+    private String projectename;
+    /**
+     * 总装机号id
+     */
+    @TableField("CRANENOIDS")
+    private String cranenoids;
+    /**
+     * 总装机号
+     */
+    @TableField("CRANENO")
+    private String craneno;
+    /**
+     * 钢印机号id
+     */
+    @TableField("FABRICATIONNOIDS")
+    private String fabricationnoids;
+    /**
+     * 钢印机号
+     */
+    @TableField("FABRICATIONNO")
+    private String fabricationno;
+    /**
+     * 零部件名称
+     */
+    @TableField("COMPONENTNAME")
+    private String componentname;
+    /**
+     * 零部件图号
+     */
+    @TableField("DRAWNO")
+    private String drawno;
+    /**
+     * 生产制造部门
+     */
+    @TableField("FABDEPT")
+    private String fabdept;
+    /**
+     * 责任部门
+     */
+    @TableField("RESPONSIBLEDEPT")
+    private String responsibledept;
+    /**
+     * 责任分包商
+     */
+    @TableField("RESPONSIBLESUB")
+    private String responsiblesub;
+    /**
+     * 受控文件号
+     */
+    @TableField("FILENO")
+    private String fileno;
+    /**
+     * 管理规定
+     */
+    @TableField("REGULATION")
+    private String regulation;
+    /**
+     * 检验员
+     */
+    @TableField("QCINSPECTOR")
+    private String qcinspector;
+    /**
+     * 检验员id
+     */
+    @TableField("QCINSPECTORID")
+    private String qcinspectorid;
+    /**
+     * (副)主任/站长
+     */
+    @TableField("QCMANAGER")
+    private String qcmanager;
+    /**
+     * (副)主任/站长id
+     */
+    @TableField("QCMANAGERID")
+    private String qcmanagerid;
+    /**
+     * 日期
+     */
+    @TableField("DATE")
+    private Date date;
+    /**
+     * 检查情况叙述(包括发生原因)
+     */
+    @TableField("REASONS")
+    private String reasons;
+    /**
+     * 附件
+     */
+    @TableField("FILES")
+    private String files;
+    /**
+     * 数据附页
+     */
+    @TableField("DATAAPPENDIX")
+    private String dataappendix;
+    /**
+     * 状态
+     */
+    @TableField("STATUS")
+    private String status;
+    /**
+     * 问题类型
+     */
+    @TableField("ISSUES")
+    private String issues;
+    /**
+     * 问题类型2
+     */
+    @TableField("ISSUES2")
+    private String issues2;
+    /**
+     * 是否大车
+     */
+    @TableField("IFCART")
+    private String ifcart;
+
+
+}

+ 35 - 0
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxInspectionReportManageController.java

@@ -0,0 +1,35 @@
+package com.rongwei.bsserver.controller;
+
+
+import com.rongwei.bscommon.sys.service.ZhcxInspectionReportManageService;
+import com.rongwei.bsentity.domain.ZhcxInspectionReportManageDo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.Map;
+
+/**
+ * <p>
+ * 检查报告管理表 前端控制器
+ * </p>
+ *
+ * @author wm
+ * @since 2024-10-30
+ */
+@RestController
+@RequestMapping("/zhcxInspectionReportManage")
+public class ZhcxInspectionReportManageController {
+
+    @Autowired
+    private ZhcxInspectionReportManageService service;
+
+    @RequestMapping("/downloadExcel")
+    public void downloadExcel(HttpServletResponse response,@RequestBody ZhcxInspectionReportManageDo zhcxInspectionReportManageDo) {
+        service.downloadExcel(response,zhcxInspectionReportManageDo);
+    }
+
+}
+