fix(holiday): 快报表格改用带符号百分比并保留模板样式
| | |
| | | - **验证(本机 3305 库 + 真实模板)**:接口导入结果 `passengerRows=10, vehicleRows=4, successRows=14, failRows=0`;数据库抽查 2026-09-30 铁路=82.1、民航=6.6994,2026-10-01 铁路=113.8、民航=6.7482、道路=78.82、水路=1.311,2026-10-02 铁路=82.0、民航=6.3914、道路=75.61、水路=3.3373;2026-10-01 快报铁路环比=+38.6%、民航环比=+0.7%,总行环比为“—”;2026-10-02 铁路环比=-27.9%、民航环比=-5.3%。 |
| | | - **运行状态**:后端 8090(重启后已加载新代码)、前端 8080 均在运行;访问 `http://localhost:8080`。 |
| | | |
| | | ### 10-03 深夜:快报表格百分比与模板样式修复(已验收) |
| | | - **问题**:生成快报表格使用“增长/下降”文字,数字拆行并多出 1 页;复核发现模板路径正确,根因是 `HolidayBulletinService#setCellText` 替换单元格时只保留段落属性,未保留模板 run 的字体/字号属性。 |
| | | - **口径**:表格环比/同比改为带符号一位小数(正数不加 `+`,负数保留 `-`),零或一位小数后为零显示 `0%`,缺失/基数为空或为零显示 `—`;正文继续使用“增长/下降”。 |
| | | - **修复**:单元格替换时继承模板 `rPr`;新增 `HolidayBulletinServiceTest` 覆盖正数、负数、零、四舍五入为零、缺失和零基数。 |
| | | - **验证**:Maven 编译和测试通过;重新生成 2026-10-01 快报,正文仍为“增长2.3%”且不含“增长了”;Word 导出由 2 页恢复为 1 页,数字不再拆行。最终样报见本地 `_tmp_holiday_verify/bulletin_final_signed_styled_2026-10-01.docx`。 |
| | | - **状态**:2026-10-03 用户验收通过;本次提交只包含代码、回归测试和本交接记录,不包含 `_tmp_*` 过程产物及用户未提交的数据文件重命名。 |
| | | |
| | | --- |
| | | |
| | | ### 补充(10-03 下午):服务器部署报 “Access denied ... (using password: NO)” —— 根因与修复 |
| | |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.nio.file.Files; |
| | | import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | |
| | | Element pPr = firstChildElement(templateParagraph, "pPr"); |
| | | if (pPr != null) paragraph.appendChild(pPr.cloneNode(true)); |
| | | } |
| | | Element templateRun = templateParagraph == null ? null : firstChildElement(templateParagraph, "r"); |
| | | Element rPr = templateRun == null ? null : firstChildElement(templateRun, "rPr"); |
| | | Element run = createElement("r"); |
| | | if (rPr != null) run.appendChild(rPr.cloneNode(true)); |
| | | Element t = createElement("t"); |
| | | t.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve"); |
| | | t.setTextContent(text == null ? "" : text); |
| | |
| | | |
| | | private String ratio(BigDecimal current, BigDecimal base) { |
| | | if (current == null || base == null || base.abs().compareTo(EPSILON) < 0) return "—"; |
| | | return ratioPhrase(current, base); |
| | | BigDecimal ratio = HolidayNumberUtils.divide(current, base); |
| | | if (ratio == null) return "—"; |
| | | BigDecimal percent = HolidayNumberUtils.multiply(ratio.subtract(BigDecimal.ONE), BigDecimal.valueOf(100)); |
| | | if (percent == null) return "—"; |
| | | BigDecimal rounded = percent.setScale(1, RoundingMode.HALF_UP); |
| | | return rounded.signum() == 0 ? "0%" : rounded.toPlainString() + "%"; |
| | | } |
| | | |
| | | private String number(BigDecimal value) { |
| New file |
| | |
| | | package com.trafficaudit.holiday.service; |
| | | |
| | | import org.junit.jupiter.api.Test; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.math.BigDecimal; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | |
| | | class HolidayBulletinServiceTest { |
| | | |
| | | @Test |
| | | void formatsTableRatiosAsSignedPercentages() throws Exception { |
| | | HolidayBulletinService service = new HolidayBulletinService(null); |
| | | |
| | | assertEquals("-4.7%", ratio(service, "95.3", "100")); |
| | | assertEquals("1.0%", ratio(service, "101", "100")); |
| | | assertEquals("0%", ratio(service, "100", "100")); |
| | | assertEquals("0%", ratio(service, "10004", "10000")); |
| | | assertEquals("—", ratio(service, "100", null)); |
| | | assertEquals("—", ratio(service, "100", "0")); |
| | | } |
| | | |
| | | private String ratio(HolidayBulletinService service, String current, String base) throws Exception { |
| | | Method method = HolidayBulletinService.class.getDeclaredMethod("ratio", BigDecimal.class, BigDecimal.class); |
| | | method.setAccessible(true); |
| | | BigDecimal currentValue = current == null ? null : new BigDecimal(current); |
| | | BigDecimal baseValue = base == null ? null : new BigDecimal(base); |
| | | return (String) method.invoke(service, currentValue, baseValue); |
| | | } |
| | | } |