zss
2024-07-04 90e768e3d4e6603ca9e47c0950255ec105757883
修改工时bug+报告分页问题
已修改5个文件
320 ■■■■■ 文件已修改
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java 229 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
performance-server/src/main/resources/mapper/AuxiliaryCorrectionHoursMapper.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
performance-server/src/main/resources/mapper/AuxiliaryOriginalHoursMapper.xml 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
performance-server/src/main/resources/mapper/AuxiliaryOutputWorkingHoursMapper.xml 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
performance-server/src/main/resources/mapper/AuxiliaryWorkingHoursDayMapper.xml 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -39,6 +39,8 @@
import com.yuanchu.mom.vo.SampleVo;
import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -46,6 +48,7 @@
import javax.annotation.Resource;
import java.io.*;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
@@ -621,30 +624,6 @@
                    Set<String> delSet = new HashSet<>();
                    List<ExcelDto> excelDtos = JSON.parseArray(tem, ExcelDto.class);
                    List<ExcelDto> mcList = new ArrayList<>();
                   /* int aaaa = excelDtos.get(excelDtos.size() - 1).getR();//这里是模版里面的所有检测项的长度,先以15个项目分页
                    int bbbb = 17;
                    int cccc = 0;
                    for (int p = 0; p < aaaa; p++) {
                        if (p % bbbb == 0) {
                            for (int y = 0; y < excelDtos.size(); y++) {
                                if (y == 0 || y == 1) {
                                    if (excelDtos.get(y).getV().getMc() != null && excelDtos.get(y).getV().getMc().getCs() != null && excelDtos.get(y).getV().getMc().getRs() != null) {
                                        mcList.add(excelDtos.get(y));
                                    }
                                } else {
                                    try {
                                        excelDtos.get(y + cccc - 2);
                                    } catch (Exception e) {
                                        continue;
                                    }
                                    if (excelDtos.get(y + cccc - 2).getV().getMc() != null && excelDtos.get(y + cccc - 2).getV().getMc().getCs() != null && excelDtos.get(y + cccc - 2).getV().getMc().getRs() != null) {
                                        mcList.add(excelDtos.get(y + cccc - 2));
                                    }
                                }
                            }
                            cccc += 17;
                        }
                    }*/
                    excelDtos.forEach(b -> {
                        if (b.getV().getMc() != null && b.getV().getMc().getCs() != null && b.getV().getMc().getRs() != null) {
                            mcList.add(b);
@@ -778,7 +757,11 @@
                            } else if (value.equals("试验方法")) {
                                textRenderData.setText(p.getMethodS());
                            } else if (value.equals("检验项")) {
                                textRenderData.setText(p.getInspectionItem() + "&" + p.getInspectionItemEn());
                                if (ObjectUtils.isEmpty(p.getInspectionItemEn())) {
                                    textRenderData.setText(p.getInspectionItem());
                                } else {
                                    textRenderData.setText(p.getInspectionItem() + "&" + p.getInspectionItemEn());
                                }
                            } else if (value.equals("检验子项")) {
                                if (ObjectUtils.isEmpty(p.getInspectionItemSubclassEn())) {
                                    textRenderData.setText(p.getInspectionItemSubclass());
@@ -823,7 +806,6 @@
                            textRenderData.setText(textRenderData.getText() + "∑" + jo1.get("mc"));
                        }
                        Style style = new Style();
//                        style.setFontFamily(v.get("ff") == null ? "宋体" : v.get("ff") + "");
                        style.setFontFamily("宋体");
                        if (!((v.get("fc") + "").indexOf("rgb") > -1)) {
                            style.setColor(v.get("fc") == null ? "000000" : (v.get("fc") + "").replace("#", ""));
@@ -838,35 +820,74 @@
                    if (rowRenderData.getCells().size() != 0) {
                        rows.add(rowRenderData);
                    }
                    List<TableRenderData> tables1 = new ArrayList<>();
                    TableRenderData tableRenderData = new TableRenderData();
                    tableRenderData.setRows(rows);
                    int countSize = tableRenderData.getRows().get(0).getCells().size();
                    for (RowRenderData row : tableRenderData.getRows()) {
                        /*for (CellRenderData cell : row.getCells()) {
                            System.out.print(cell.getParagraphs().get(0).getContents());
                        }
                        System.out.println("");*/
                        if (row.getCells().size() != countSize) {
                            throw new ErrorException("每行单元格不相等");
                        }
                    tableRenderData.setRows(new ArrayList<>());
                    double totalHeight = 0.0; // 用于跟踪当前表格的总行高
                    double heightThreshold = 8000.0; // 阈值,例如40cm*28px*15twips
                    List<RowRenderData> firstTwoRows = new ArrayList<>(); // 保存前两行以便复制到新表格
                    // 保存前两行以便复制到新表格
                    if (rows.size() >= 2) {
                        firstTwoRows.add(rows.get(0));
                        firstTwoRows.add(rows.get(1));
                    }
                    TableStyle tableStyle = new TableStyle();
                    tableStyle.setColWidths(new int[]{650, 1600, 2000, 750, 2800, 1100, 1100});
                    tableStyle.setWidth("10000");
                    tableStyle.setAlign(TableRowAlign.CENTER);
                    BorderStyle borderStyle = new BorderStyle();
                    borderStyle.setColor("000000");
                    borderStyle.setType(XWPFTable.XWPFBorderType.THICK);
                    borderStyle.setSize(14);
                    tableStyle.setLeftBorder(borderStyle);
                    tableStyle.setTopBorder(borderStyle);
                    tableStyle.setRightBorder(borderStyle);
                    tableStyle.setBottomBorder(borderStyle);
                    tableRenderData.setTableStyle(tableStyle);
                    Map<String, Object> table = new HashMap<>();
                    table.put("table", tableRenderData);
                    table.put("report", insReport);
                    tables.add(table);
                    for (RowRenderData row : rows) {
                        double rowHeight = row.getRowStyle().getHeight(); // 获取当前行的行高
                        totalHeight += rowHeight; // 更新总行高
                        if (totalHeight >= heightThreshold) {
                            // 创建新表格并复制前两行
                            TableRenderData newTableRenderData = new TableRenderData();
                            newTableRenderData.setRows(new ArrayList<>(firstTwoRows));
                            TableStyle tableStyle = new TableStyle();
                            tableStyle.setColWidths(new int[]{650, 1600, 2000, 750, 2800, 1100, 1100});
                            tableStyle.setWidth("10000");
                            tableStyle.setAlign(TableRowAlign.CENTER);
                            BorderStyle borderStyle = new BorderStyle();
                            borderStyle.setColor("000000");
                            borderStyle.setType(XWPFTable.XWPFBorderType.THICK);
                            borderStyle.setSize(14);
                            tableStyle.setLeftBorder(borderStyle);
                            tableStyle.setTopBorder(borderStyle);
                            tableStyle.setRightBorder(borderStyle);
                            tableStyle.setBottomBorder(borderStyle);
                            tableRenderData.setTableStyle(tableStyle);
                            newTableRenderData.setTableStyle(tableStyle);
                            tables1.add(tableRenderData);
                            tableRenderData = newTableRenderData;
                            totalHeight = rowHeight;
                        }
                        tableRenderData.getRows().add(row);
                    }
                    if (!tableRenderData.getRows().isEmpty()) {
                        TableStyle tableStyle = new TableStyle();
                        tableStyle.setColWidths(new int[]{650, 1600, 2000, 750, 2800, 1100, 1100});
                        tableStyle.setWidth("10000");
                        tableStyle.setAlign(TableRowAlign.CENTER);
                        BorderStyle borderStyle = new BorderStyle();
                        borderStyle.setColor("000000");
                        borderStyle.setType(XWPFTable.XWPFBorderType.THICK);
                        borderStyle.setSize(14);
                        tableStyle.setLeftBorder(borderStyle);
                        tableStyle.setTopBorder(borderStyle);
                        tableStyle.setRightBorder(borderStyle);
                        tableStyle.setBottomBorder(borderStyle);
                        tableRenderData.setTableStyle(tableStyle);
                        tables1.add(tableRenderData);
                    }
                    tables1.forEach(table -> {
                        Map<String, Object> tableMap = new HashMap<>();
                        tableMap.put("table", table);
                        tableMap.put("report", insReport);
                        tables.add(tableMap);
                    });
                });
            });
            String url;
@@ -1219,19 +1240,28 @@
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            //处理合并单元格的问题
            // 处理合并单元格的问题
            String path = wordUrl + "/" + insReport.getCode().replace("/", "") + ".docx";
            try {
                FileInputStream stream = new FileInputStream(path);
                XWPFDocument document = new XWPFDocument(stream);
                List<XWPFTable> xwpfTables = document.getTables();
                for (int i = 1; i < xwpfTables.size() - (deviceList == null ? 1 : 2); i++) {
                    Set<String> set1 = new HashSet<>();
                    Map<String, Map<String, Integer>> maps = new HashMap<>();
                    for (int j = 0; j < xwpfTables.get(i).getRows().size(); j++) {
                        for (int k = 0; k < xwpfTables.get(i).getRows().get(j).getTableCells().size(); k++) {
                            if (xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().indexOf("∑") > -1) {
                                String[] split = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("∑");
                    XWPFTable table = xwpfTables.get(i);
                    for (int j = 0; j < table.getRows().size(); j++) {
                        XWPFTableRow row = table.getRow(j);
                        if (row == null) continue;
                        for (int k = 0; k < row.getTableCells().size(); k++) {
                            XWPFTableCell cell = row.getCell(k);
                            if (cell == null || cell.getText() == null) continue;
                            if (cell.getText().indexOf("∑") > -1) {
                                String[] split = cell.getText().split("∑");
                                if (set1.add(split[1])) {
                                    Map<String, Integer> map = new HashMap<>();
                                    map.put("sr", j);
@@ -1247,30 +1277,59 @@
                                        map1.put("er", map1.get("er") + 1);
                                    }
                                }
                                String str = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("∑")[0];
                                xwpfTables.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
                                xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setText(str);
                                xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                                xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);
                                String str = split[0];
                                cell.removeParagraph(0);
                                cell.setText(str);
                                cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                                if (cell.getParagraphArray(0) != null) {
                                    cell.getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);
                                }
                            }
                        }
                    }
                    List<String> list = new ArrayList<>();
                    for (String s : maps.keySet()) {
                        list.add(s);
                    }
                    List<String> list = new ArrayList<>(maps.keySet());
                    for (int a = list.size() - 1; a >= 0; a--) {
                        Map<String, Integer> v = maps.get(list.get(a));
                        for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) {
                       /* for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) {
                            if (v.get("ec") > v.get("sc")) {
                                TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec"));
                                TableTools.mergeCellsHorizonal(table, v.get("sr") + j, v.get("sc"), v.get("ec"));
                            }
                        }
                        if (v.get("er") > v.get("sr")) {
                            TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er"));
                            TableTools.mergeCellsVertically(table, v.get("sc"), v.get("sr"), v.get("er"));
                        }*/
                        for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) {
                            if (v.get("ec") > v.get("sc")) {
                                XWPFTableRow row = table.getRow(v.get("sr") + j);
                                if (row != null) {
                                    for (int col = v.get("sc"); col <= v.get("ec"); col++) {
                                        XWPFTableCell cell = row.getCell(col);
                                        if (cell == null) {
                                            row.createCell(); // 创建新的单元格以防空指针异常
                                        }
                                    }
                                    TableTools.mergeCellsHorizonal(table, v.get("sr") + j, v.get("sc"), v.get("ec"));
                                }
                            }
                        }
                        if (v.get("er") > v.get("sr")) {
                            for (int rowIdx = v.get("sr"); rowIdx <= v.get("er"); rowIdx++) {
                                XWPFTableRow row = table.getRow(rowIdx);
                                if (row != null) {
                                    XWPFTableCell cell = row.getCell(v.get("sc"));
                                    if (cell == null) {
                                        row.createCell(); // 创建新的单元格以防空指针异常
                                    }
                                }
                            }
                            TableTools.mergeCellsVertically(table, v.get("sc"), v.get("sr"), v.get("er"));
                        }
                    }
                }
                FileOutputStream fileOutputStream = new FileOutputStream(path);
                document.write(fileOutputStream);
                fileOutputStream.close();
@@ -1300,10 +1359,38 @@
                                }
                                xwpfParagraph.setAlignment(ParagraphAlignment.CENTER);
                            }
                            /*if (k == 2 || k == 3 || k == 4) {
                                if (k == 2 && xwpfTables1.get(i).getRows().get(j).getTableCells().get(k-1).getText().contains("@@")) {
                                    XWPFTableCell cell = xwpfTables1.get(i).getRow(j).getCell(k);
                                    CTTblWidth tblWidth = cell.getCTTc().addNewTcPr().addNewTcW();
                                    tblWidth.setType(STTblWidth.DXA);
                                    tblWidth.setW(BigInteger.valueOf((int) (4.79 * 1440 / 2.54)));
                                }
                                if (k == 3 && xwpfTables1.get(i).getRows().get(j).getTableCells().get(k - 2).getText().contains("@@")) {
                                    XWPFTableCell cell = xwpfTables1.get(i).getRow(j).getCell(k);
                                    CTTblWidth tblWidth = cell.getCTTc().addNewTcPr().addNewTcW();
                                    tblWidth.setType(STTblWidth.DXA);
                                    tblWidth.setW(BigInteger.valueOf((int) (1.49 * 1440 / 2.54)));
                                }
                                if (k == 4 && xwpfTables1.get(i).getRows().get(j).getTableCells().get(k - 3).getText().contains("@@")) {
                                    XWPFTableCell cell = xwpfTables1.get(i).getRow(j).getCell(k);
                                    CTTblWidth tblWidth = cell.getCTTc().addNewTcPr().addNewTcW();
                                    tblWidth.setType(STTblWidth.DXA);
                                    tblWidth.setW(BigInteger.valueOf((int) (3.51 * 1440 / 2.54)));
                                }
                            }
                            if (xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText().contains("@@")) {
                                String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText();
                                text = text.replace("@@","");
                                xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
                                XWPFParagraph xwpfParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph();
                                XWPFRun run = xwpfParagraph.createRun();
                                run.setText(text);
                                xwpfParagraph.setAlignment(ParagraphAlignment.CENTER);
                            }*/
                        }
                    }
                }
                //处理检验结果跨页的问题
                FileOutputStream fileOutputStream1 = new FileOutputStream(path);
                document1.write(fileOutputStream1);
                fileOutputStream1.close();
performance-server/src/main/resources/mapper/AuxiliaryCorrectionHoursMapper.xml
@@ -49,12 +49,13 @@
        select ach.*,name
        FROM auxiliary_correction_hours ach
        left join user on user.id=ach.name_user
        <if test="ids !=null and ids != ''">
        WHERE name_user in(#{ids})
        <!--<if test="ids !=null and ids != ''">
            WHERE name_user in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        </if>-->
        ) A
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
performance-server/src/main/resources/mapper/AuxiliaryOriginalHoursMapper.xml
@@ -12,18 +12,19 @@
        case
        when reviewer_nonproductive_time is null then nonproductive_time
        else reviewer_nonproductive_time end as manHour,
        date_time                                as month
        date_time as month
        from auxiliary_working_hours_day awhd
        left join user on user.id = awhd.name_user
        left join department_lims dl on depart_lims_id = dl.id
        where date_time LIKE CONCAT('%', #{month}, '%')
        and awhd.state='已批准'
        <if test="ids !=null and ids != ''">
            and name_user in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        and name_user in(#{ids})
        <!-- <if test="ids !=null and ids != ''">
             and name_user in
             <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                 #{val}
             </foreach>
         </if>-->
        order by month
        ) A
        group by A.name, A.month) C
@@ -33,18 +34,19 @@
        B.manHours
        from (
        select user.name,
        date_time             as month,
        date_time as month,
        sum(output_work_time) as manHours
        from auxiliary_output_working_hours aowh
        left join user on user.id = aowh.`check`
        left join department_lims dl on depart_lims_id = dl.id
        where date_time LIKE CONCAT('%', #{month}, '%')
        <if test="ids !=null and ids != ''">
        and `check` in(#{ids})
        <!--<if test="ids !=null and ids != ''">
            and `check` in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        </if>-->
        group by user.name, month
        order by user.name, month
        ) B
performance-server/src/main/resources/mapper/AuxiliaryOutputWorkingHoursMapper.xml
@@ -39,12 +39,13 @@
        name
        FROM auxiliary_output_working_hours aowh
        left join user on user.id=aowh.`check`
        <if test="ids !=null and ids != ''">
        WHERE `check` in(#{ids})
        <!--<if test="ids !=null and ids != ''">
            WHERE `check` in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        </if>-->
        ) A
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
@@ -54,12 +55,13 @@
        select aowh.*,name
        FROM auxiliary_output_working_hours aowh
        left join user on user.id=aowh.`check`
        <if test="ids !=null and ids != ''">
            WHERE `check` in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        WHERE `check` in(#{ids})
        <!-- <if test="ids !=null and ids != ''">
             WHERE `check` in
             <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                 #{val}
             </foreach>
         </if>-->
    </select>
    <select id="totalHours" resultType="java.util.Map">
        select A.name,
@@ -73,24 +75,26 @@
        left join user on user.id=aowh.`check`
        left join department_lims dl on depart_lims_id=dl.id
        where date_time LIKE CONCAT('%', #{month}, '%')
        <if test="ids !=null and ids != ''">
            and `check` in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
        and `check` in (#{ids})
        <!--<if test="ids !=null and ids != ''">
            and `check` in (#ids)
            <foreach collection="ids" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        group by user.name,month
        order by month,user.name
        </if>-->
        group by user.name,date_time
        order by user.name,date_time
        )A
    </select>
    <select id="selectListByIds" resultType="com.yuanchu.mom.pojo.AuxiliaryOutputWorkingHours">
        select * from auxiliary_output_working_hours
        where 1=1
        <if test="ids !=null and ids != ''">
        and `check` in(#{ids})
        <!--<if test="ids !=null and ids != ''">
            and `check` in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        </if>-->
    </select>
</mapper>
performance-server/src/main/resources/mapper/AuxiliaryWorkingHoursDayMapper.xml
@@ -31,12 +31,13 @@
        select awhd.*,name
        FROM auxiliary_working_hours_day awhd
        left join user on name_user=user.id
        <if test="ids !=null and ids != ''">
        WHERE name_user in(#{ids})
        <!--<if test="ids !=null and ids != ''">
            WHERE name_user in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        </if>-->
        ) A
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
@@ -46,22 +47,24 @@
        select awhd.*,name
        FROM auxiliary_working_hours_day awhd
        left join user on name_user=user.id
        <if test="ids !=null and ids != ''">
        WHERE name_user in(#{ids})
        <!--<if test="ids !=null and ids != ''">
            WHERE name_user in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        </if>-->
    </select>
    <select id="selectListByIds" resultType="com.yuanchu.mom.pojo.AuxiliaryWorkingHoursDay">
        select * from auxiliary_working_hours_day
        where 1=1
        <if test="ids !=null and ids != ''">
        and name_user in(#{ids})
       <!-- <if test="ids !=null and ids != ''">
            and name_user in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        </if>-->
    </select>
    <select id="totalHours" resultType="java.util.Map">
        select A.name,
@@ -77,12 +80,13 @@
        left join department_lims dl on depart_lims_id=dl.id
        where date_time LIKE CONCAT('%', #{month}, '%')
        and awhd.state='已批准'
        <if test="ids !=null and ids != ''">
            and name_user in
            <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                #{val}
            </foreach>
        </if>
        and name_user in (#{ids})
        <!-- <if test="ids !=null and ids != ''">
             and name_user in
             <foreach collection="ids" index="index" open="(" separator="," close=")" item="val">
                 #{val}
             </foreach>
         </if>-->
        order by month,user.name
        )A
        group by A.name,A.month