Pārlūkot izejas kodu

feat(starclass): 完成月结快照与PC报表闭环

harper 4 nedēļas atpakaļ
vecāks
revīzija
b806347de2

+ 395 - 0
docs/24_星级班班主任移动报表/2026-11-02_星级班月结与PC报表闭环第四阶段实施记录.md

@@ -0,0 +1,395 @@
+# 2026-11-02 星级班月结与 PC 报表闭环实施记录
+
+## 1. 实施结论
+
+星级班已完成从数据源到月结快照、排名、移动端和 PC 报表的完整闭环,并部署到独立测试环境。
+
+当前链路:
+
+```text
+课堂 / 升旗礼 / 宿舍 / 清洁 / 风纪 / 考勤
+  + 增分 / 减分账本
+  -> 班级月结检查
+  -> XJB_JD 月结批次
+  -> XJB_JG 班级结果
+  -> XJB_PM 部门与学校排名
+  -> 移动端与 PC 共用同一快照
+```
+
+正式环境尚未发布本阶段代码和数据库变更。
+
+## 2. 数据源与口径
+
+### 2.1 课堂考核
+
+```text
+KTJL.FS 月度平均值
+```
+
+条件为记录在用,且记录时间落在目标月份。
+
+### 2.2 升旗礼
+
+```text
+SQLJC.ZFS 月度平均值
+```
+
+只接受 0 至 100 的总分。
+
+### 2.3 清洁卫生
+
+```text
+CSWSJC.FS 月度平均值
+```
+
+### 2.4 考勤
+
+按当月学校考勤日逐日计算:
+
+```text
+日考勤分 = max(0, 100 - 日扣分)
+月考勤分 = 日考勤分平均值
+```
+
+扣分口径:
+
+| 类别码 | 类型 | 扣分 |
+|---:|---|---:|
+| 1 | 缺勤 | 3 |
+| 21 | 迟到 | 1 |
+| 51 | 未归 | 1 |
+| 52 | 晚归 | 1 |
+| 61 | 未入校 | 2 |
+
+### 2.5 风纪仪容
+
+新增每日登记表:
+
+```text
+XJB_FJRY
+```
+
+每个班级每天一条记录,`WJRS` 表示违纪人次:
+
+```text
+日风纪分 = max(0, 100 - 当日违纪人次)
+月风纪分 = 日风纪分平均值
+```
+
+当月有完整风纪登记且违纪人次合计为 0 时,账本增加:
+
+```text
+FJ_SAFE = +0.5
+```
+
+风纪登记服务:
+
+```text
+xjbFjry_save
+xjbFjry_list
+```
+
+### 2.6 宿舍评分
+
+宿舍评分按旧系统公式实现:
+
+```text
+内务分 =(上午月均分 + 下午月均分)÷ 2
+住宿考勤分 = max(0, 100 - 宿舍考勤扣分)
+宿舍违纪分 = max(0, 100 - 宿舍违纪扣分)
+
+基础分 = 内务分 × 35% + 住宿考勤分 × 15% + 宿舍违纪分 × 35%
+管理效果分 = 基础分 ÷ 85 × 10
+宿舍评分 = 基础分 + 管理效果分
+```
+
+上午和下午任一时段没有内务数据时,宿舍评分记为 `missing`,不生成月结。
+
+### 2.7 增分与减分
+
+读取第三阶段 `XJB_JFJL`:
+
+```text
+增分 = min(账本增分合计, 8)
+减分 = 账本减分合计
+```
+
+## 3. 月结总分与星级
+
+```text
+月总分 =
+  宿舍评分 × 20%
+  + 课堂考核 × 5%
+  + 升旗礼 × 14%
+  + 清洁卫生 × 18%
+  + 风纪仪容 × 20%
+  + 考勤 × 15%
+  + min(增分, 8)
+  - 减分
+```
+
+最终分不设 0 分下限。
+
+星级:
+
+| 星级 | 条件 |
+|---|---|
+| 五星级 | 全校排名前 10 且分数 >= 90 |
+| 四星级 | 80 <= 分数 |
+| 三星级 | 75 <= 分数 < 80 |
+| 二星级 | 65 <= 分数 < 75 |
+| 一星级 | 55 <= 分数 < 65 |
+| 无星级 | 分数 < 55 |
+
+五星判定先检查全校前十,再检查 90 分门槛。
+
+## 4. 月结数据模型
+
+新增:
+
+```text
+XJB_FJRY       风纪仪容日登记
+XJB_JD         月结批次
+XJB_JG         班级月结结果
+XJB_PM         部门和学校排名
+XJB_FJRYID     序列
+XJB_JDID       序列
+XJB_JGID       序列
+XJB_PMID       序列
+```
+
+批次状态:
+
+```text
+1 草稿
+5 已发布
+```
+
+本阶段在数据完整时直接生成已发布批次。任一必需项缺失时,接口返回缺失班级和项目,不生成批次。
+
+已发布批次禁止重复覆盖。如需修正,后续阶段应生成新版本批次,而不是原地覆盖。
+
+## 5. 移动端接入
+
+`bjStarClass_mpSummary` 已增加快照读取:
+
+1. 目标月份存在已发布快照时,总分、星级、排名、增分和减分全部读取 `XJB_JG/XJB_PM`。
+2. 六项来源从快照读取。
+3. 实时源数据后续变化时,已发布月份总结果不随之改变。
+4. 没有已发布快照时,继续提供实时预览,但数据不完整时显示“待评分”,不再使用随机模拟分。
+
+## 6. PC 报表接入
+
+页面:
+
+```text
+web/page/biz/ssnwjc_starClassSummary.jsp
+```
+
+已删除页面内全部 `DEMO_ROWS`。
+
+页面通过:
+
+```text
+xjbMonth_pcSummary
+```
+
+读取已发布月结,支持:
+
+1. 院系、专业、班级、星级和月份筛选。
+2. 展示六项得分、增分、减分、总分、星级、部门排名、全校排名。
+3. 默认进入最近已发布月份。
+4. 当前筛选结果导出 CSV。
+
+PC 页面和移动端读取同一个 `XJB_JD` 批次,不各自重新计算。
+
+## 7. 测试环境部署
+
+测试环境:
+
+```text
+192.168.69.32  pms-test-master
+192.168.69.33  pms-test-worker1
+namespace:pms-test
+Schema:PMS_TEST
+```
+
+已发布:
+
+```text
+XjbFjryPo
+XjbJdPo
+XjbJgPo
+XjbPmPo
+XjbFjryServ
+XjbMonthCloseServ
+更新后的 BjStarClassMpServ
+更新后的 PC 星级班总表页面
+```
+
+服务注册:
+
+```text
+xjbFjry_save
+xjbFjry_list
+xjbMonth_close
+xjbMonth_pcSummary
+```
+
+配置编译:
+
+```text
+Serialize ConfigFile SUCCEED
+```
+
+数据库备份基于新增对象,不需要覆盖旧表。应用备份:
+
+```text
+/opt/data/pms/backup/xjb_stage4_20261102/deploy2_20261102_172149
+```
+
+## 8. 测试数据
+
+测试标记:
+
+```text
+STARCLASS_STAGE4_SEED_202610
+```
+
+测试范围:
+
+```text
+服装技术部 24 个有效班级
+月份 2026-10
+```
+
+为 24 个班级写入:
+
+1. 上午、下午宿舍内务检查。
+2. 场室卫生检查。
+3. 课堂考核记录。
+4. 升旗礼月度总分。
+5. 风纪仪容日登记。
+6. 月度无处分和无风纪扣分事件。
+
+## 9. 验收结果
+
+月结批次:
+
+```text
+XJB_JDID=3
+NDY=2026-10
+ZT=5 已发布
+classCount=24
+```
+
+落库结果:
+
+| 对象 | 数量 |
+|---|---:|
+| `XJB_JD` 已发布批次 | 1 |
+| `XJB_JG` 班级结果 | 24 |
+| `XJB_PM` 排名 | 24 |
+| `XJB_FJRY` 风纪日登记 | 24 |
+| `XJB_JFJL` 全部事件 | 36 |
+
+移动端 `25服6`:
+
+```text
+总分=83.66
+星级=四星级
+部门排名=20/24
+全校排名=20/24
+增分=2.00
+减分=0.00
+快照已发布=true
+六项来源全部 real
+```
+
+PC 报表返回 24 行,第一名 `23服6`:
+
+```text
+总分=91.43
+星级=五星级
+全校排名=1
+```
+
+前 10 名中分数达到 90 的班级均为五星级,未满 90 分的班级不会因为排名前十而误判五星级。
+
+## 10. 一致性验证
+
+快照一致性:
+
+1. PC 和移动端返回同一班级总分、星级、部门和学校排名。
+2. 手工复算检查误差不超过 0.01。
+3. 修改 10 月 5 日风纪记录后,实时日明细立即变化。
+4. 已发布 10 月快照总分仍保持 83.66,没有被实时数据改写。
+5. 风纪测试数据随后恢复为 0。
+
+重复发布:
+
+```text
+2026-10 第二次月结返回“该部门该月份已发布,不能覆盖”
+```
+
+缺失阻断:
+
+对缺少清洁、课堂、风纪等数据的 2026-09 发起月结:
+
+```text
+24 个班级未发布
+明确返回缺失项目
+未生成已发布批次
+```
+
+PC 页面:
+
+```text
+HTTP 200
+DEMO_ROWS=0
+真实月结接口引用=1
+```
+
+## 11. 当前边界
+
+1. 本次月结范围是当前登录人的部门,便于测试隔离。
+2. 全校月结需要由管理员账号执行全部部门或增加全校批次入口。
+3. 风纪仪容当前通过专用日登记接口录入,尚未补 PC 管理菜单和小程序录入页。
+4. 导出采用 UTF-8 CSV,可在 Excel 打开,但未生成原生 `.xlsx`。
+5. 月结审批流尚未启用,本阶段将完整批次直接标记为已发布。
+6. 测试环境仍关闭定时任务。
+
+## 12. 回滚
+
+应用:
+
+1. 从 `deploy2_20261102_172149` 恢复旧 `BjStarClassMpServ`、配置和 PC 页面。
+2. 清理 `ROOT/WEB-INF/cfg/ser/` 后重新执行 `SerCfg.jsp`。
+3. 重启 `pms-test`。
+
+数据库:
+
+```text
+docs/24_星级班班主任移动报表/sql/2026-11-02_星级班月结_回滚.sql
+```
+
+该脚本只清理测试月的月结和带测试标记的源数据。
+
+## 13. 正式发布前置
+
+正式发布前必须:
+
+1. 确认风纪仪容录入岗位、时段和审核责任。
+2. 确认宿舍上午/下午的时段边界和住宿考勤扣分。
+3. 用 2026-09、2026-10 与旧系统逐班对账。
+4. 完成全校月结入口和权限矩阵。
+5. 完成月结审批或双人复核。
+6. 正式启用增扣分每日同步任务。
+7. 对正式数据做只读预演,确认缺失项为零后才发布。
+
+## 14. 安全边界
+
+- 本阶段只修改测试环境 `.32/.33`、`pms-test` 和 `PMS_TEST`。
+- 未修改正式应用、正式 k3s、正式表或正式岗位权限。
+- 未调用海康、微信、短信、一卡通或门禁外部写接口。
+- 测试口令不写入本记录、Git 或日志。

+ 182 - 0
docs/24_星级班班主任移动报表/sql/2026-11-02_星级班月结_DDL.sql

@@ -0,0 +1,182 @@
+-- 星级班风纪登记、月结批次、班级结果和排名。
+-- 仅用于测试环境实施;正式发布前需重新执行前置检查。
+
+declare
+    v_count number;
+
+    procedure create_sequence_if_absent(p_name varchar2) is
+    begin
+        select count(*) into v_count from user_sequences
+         where sequence_name = p_name;
+        if v_count = 0 then
+            execute immediate 'create sequence ' || p_name
+                || ' start with 1 increment by 1 cache 20 nocycle';
+        end if;
+    end;
+
+    procedure create_table_if_absent(p_name varchar2, p_ddl varchar2) is
+    begin
+        select count(*) into v_count from user_tables
+         where table_name = p_name;
+        if v_count = 0 then
+            execute immediate p_ddl;
+        end if;
+    end;
+
+    procedure create_index_if_absent(
+        p_name varchar2, p_ddl varchar2
+    ) is
+    begin
+        select count(*) into v_count from user_indexes
+         where index_name = p_name;
+        if v_count = 0 then
+            execute immediate p_ddl;
+        end if;
+    end;
+begin
+    create_sequence_if_absent('XJB_FJRYID');
+    create_sequence_if_absent('XJB_JDID');
+    create_sequence_if_absent('XJB_JGID');
+    create_sequence_if_absent('XJB_PMID');
+
+    create_table_if_absent('XJB_FJRY', q'[
+        create table XJB_FJRY (
+            XJB_FJRYID number(16) not null,
+            BJID number(16) not null,
+            JCRQ date not null,
+            WJRS number(9) default 0 not null,
+            MS varchar2(1024 char),
+            JLZTM number(9) default 51 not null,
+            JLSJ timestamp(6) default systimestamp not null,
+            CJRYID number(16),
+            GLRYID number(16),
+            GLBMID number(16),
+            constraint PK_XJB_FJRY primary key (XJB_FJRYID),
+            constraint UK_XJB_FJRY_BJ_DATE unique (BJID, JCRQ),
+            constraint CK_XJB_FJRY_WJRS check (WJRS >= 0)
+        )
+    ]');
+
+    create_table_if_absent('XJB_JD', q'[
+        create table XJB_JD (
+            XJB_JDID number(16) not null,
+            NDY varchar2(7 char) not null,
+            FWLX varchar2(16 char) not null,
+            FWID number(16) not null,
+            BB number(9) default 1 not null,
+            ZT number(9) default 1 not null,
+            MS varchar2(1024 char),
+            CJSJ timestamp(6) default systimestamp not null,
+            FBSJ timestamp(6),
+            JSRYID number(16),
+            JSBMID number(16),
+            constraint PK_XJB_JD primary key (XJB_JDID),
+            constraint UK_XJB_JD_SCOPE unique (NDY, FWLX, FWID, BB)
+        )
+    ]');
+
+    create_table_if_absent('XJB_JG', q'[
+        create table XJB_JG (
+            XJB_JGID number(16) not null,
+            XJB_JDID number(16) not null,
+            NDY varchar2(7 char) not null,
+            BJID number(16) not null,
+            DWID number(16),
+            ZYID number(16),
+            SSDF number(9,2),
+            KTDF number(9,2),
+            SJDF number(9,2),
+            CSDF number(9,2),
+            FJDF number(9,2),
+            KQDF number(9,2),
+            ZJF number(9,2) default 0 not null,
+            KJF number(9,2) default 0 not null,
+            ZF number(9,2) not null,
+            XJ varchar2(16 char) not null,
+            SSLY varchar2(16 char),
+            KTLY varchar2(16 char),
+            SJLY varchar2(16 char),
+            CSLY varchar2(16 char),
+            FJLY varchar2(16 char),
+            KQLY varchar2(16 char),
+            ZJFCS number(9) default 0 not null,
+            KJFCS number(9) default 0 not null,
+            QXSM varchar2(512 char),
+            ZT number(9) default 1 not null,
+            JLSJ timestamp(6) default systimestamp not null,
+            CJRYID number(16),
+            GLBMID number(16),
+            constraint PK_XJB_JG primary key (XJB_JGID),
+            constraint UK_XJB_JG_CLASS unique (XJB_JDID, BJID)
+        )
+    ]');
+
+    create_table_if_absent('XJB_PM', q'[
+        create table XJB_PM (
+            XJB_PMID number(16) not null,
+            XJB_JDID number(16) not null,
+            BJID number(16) not null,
+            DWID number(16),
+            DWPM number(9) not null,
+            DWCS number(9) not null,
+            XXPM number(9) not null,
+            XXCS number(9) not null,
+            constraint PK_XJB_PM primary key (XJB_PMID),
+            constraint UK_XJB_PM_CLASS unique (XJB_JDID, BJID)
+        )
+    ]');
+
+    create_index_if_absent('IDX_XJB_JD_MONTH_STATUS',
+        'create index IDX_XJB_JD_MONTH_STATUS on XJB_JD (NDY, ZT)');
+    create_index_if_absent('IDX_XJB_JG_JD_RANK',
+        'create index IDX_XJB_JG_JD_RANK on XJB_JG (XJB_JDID, ZF desc)');
+end;
+/
+
+declare
+    v_count number;
+
+    procedure add_fk_if_absent(
+        p_table varchar2,
+        p_name varchar2,
+        p_child_column varchar2,
+        p_parent_table varchar2,
+        p_parent_column varchar2
+    ) is
+    begin
+        select count(*) into v_count from user_constraints
+         where table_name = p_table and constraint_name = p_name;
+        if v_count = 0 then
+            execute immediate
+                'alter table ' || p_table || ' add constraint ' || p_name
+                || ' foreign key (' || p_child_column || ') references '
+                || p_parent_table || '(' || p_parent_column || ')'
+                || ' enable novalidate';
+        end if;
+    end;
+begin
+    add_fk_if_absent('XJB_FJRY', 'FK_BJ_XJB_FJRY',
+        'BJID', 'BJ', 'BJID');
+    add_fk_if_absent('XJB_FJRY', 'FK_JLZT_XJB_FJRY',
+        'JLZTM', 'JLZT', 'JLZTM');
+
+    add_fk_if_absent('XJB_JG', 'FK_JD_XJB_JG',
+        'XJB_JDID', 'XJB_JD', 'XJB_JDID');
+    add_fk_if_absent('XJB_JG', 'FK_BJ_XJB_JG',
+        'BJID', 'BJ', 'BJID');
+    add_fk_if_absent('XJB_JG', 'FK_DW_XJB_JG',
+        'DWID', 'DW', 'DWID');
+    add_fk_if_absent('XJB_JG', 'FK_ZY_XJB_JG',
+        'ZYID', 'ZY', 'ZYID');
+
+    add_fk_if_absent('XJB_PM', 'FK_JD_XJB_PM',
+        'XJB_JDID', 'XJB_JD', 'XJB_JDID');
+    add_fk_if_absent('XJB_PM', 'FK_BJ_XJB_PM',
+        'BJID', 'BJ', 'BJID');
+    add_fk_if_absent('XJB_PM', 'FK_DW_XJB_PM',
+        'DWID', 'DW', 'DWID');
+end;
+/
+
+commit;
+/

+ 36 - 0
docs/24_星级班班主任移动报表/sql/2026-11-02_星级班月结_回滚.sql

@@ -0,0 +1,36 @@
+-- 仅用于测试环境清理 2026-10 月结和带标记的验收源数据。
+-- 正式环境禁止执行。
+
+delete from XJB_PM
+ where XJB_JDID in (
+     select XJB_JDID from XJB_JD where NDY = '2026-10'
+ );
+
+delete from XJB_JG
+ where XJB_JDID in (
+     select XJB_JDID from XJB_JD where NDY = '2026-10'
+ );
+
+delete from XJB_JD where NDY = '2026-10';
+
+delete from XJB_JFJL
+ where NDY = '2026-10'
+   and MS like '%STARCLASS_STAGE4_SEED_202610%';
+
+delete from XJB_FJRY
+ where MS like '%STARCLASS_STAGE4_SEED_202610%';
+
+delete from SSNWJC
+ where MS like '%STARCLASS_STAGE4_SEED_202610%';
+
+delete from CSWSJC
+ where MS like '%STARCLASS_STAGE4_SEED_202610%';
+
+delete from KTJL
+ where MS like '%STARCLASS_STAGE4_SEED_202610%';
+
+delete from SQLJC
+ where MS like '%STARCLASS_STAGE4_SEED_202610%';
+
+commit;
+/

+ 14 - 0
docs/24_星级班班主任移动报表/sql/2026-11-02_星级班月结_测试授权.sql

@@ -0,0 +1,14 @@
+-- 仅用于 PMS_TEST.QZID=5001161 个人测试授权组。
+-- 正式岗位授权必须另行审批。
+
+update QZ
+   set FWC = json_mergepatch(
+       FWC,
+       '{"jw":["bjStarClass_mpInit","bjStarClass_mpSummary","bjStarClass_mpDay","bjStarClass_mpDetail","xjbJf_sync","xjbFjry_save","xjbFjry_list","xjbMonth_close","xjbMonth_pcSummary"]}'
+   )
+ where QZID = 5001161
+   and JLZTM = 51;
+/
+
+commit;
+/

+ 155 - 0
docs/24_星级班班主任移动报表/sql/2026-11-02_星级班月结_种子数据.sql

@@ -0,0 +1,155 @@
+-- 仅用于 PMS_TEST 月结闭环验收。
+-- 正式环境禁止执行本脚本。
+
+declare
+    v_idx pls_integer := 0;
+    v_kcbid number(16);
+    v_teacher number(16) := 111148366;
+    v_bmid number(16) := 1012222;
+    v_bjid number(16);
+    v_am number(9);
+    v_pm number(9);
+    v_clean number(9);
+    v_classroom number(9);
+    v_fjrs number(9);
+    c_mark constant varchar2(64) := 'STARCLASS_STAGE4_SEED_202610';
+begin
+    select min(KCBID) into v_kcbid
+      from KCB
+     where BJID = 4021606
+       and JLZTM in (22, 25, 51);
+    if v_kcbid is null then
+        raise_application_error(-20001, '找不到验收课程');
+    end if;
+
+    delete from XJB_JFJL
+     where NDY = '2026-10'
+       and BJID in (
+           select b.BJID
+             from BJ b
+             inner join ZY z on z.ZYID = b.ZYID
+            where z.FZBMID = v_bmid
+              and b.JLZTM in (22, 25, 51)
+              and b.BJZTM <> 81
+       );
+
+    delete from XJB_FJRY
+     where JCRQ >= date '2026-10-01'
+       and JCRQ < date '2026-11-01'
+       and MS like '%' || c_mark || '%';
+
+    delete from SSNWJC
+     where JCSJ >= timestamp '2026-10-01 00:00:00'
+       and JCSJ < timestamp '2026-11-01 00:00:00'
+       and MS like '%' || c_mark || '%';
+
+    delete from CSWSJC
+     where JCSJ >= timestamp '2026-10-01 00:00:00'
+       and JCSJ < timestamp '2026-11-01 00:00:00'
+       and MS like '%' || c_mark || '%';
+
+    delete from KTJL
+     where JLSJ >= timestamp '2026-10-01 00:00:00'
+       and JLSJ < timestamp '2026-11-01 00:00:00'
+       and MS like '%' || c_mark || '%';
+
+    delete from SQLJC
+     where JCSJ >= timestamp '2026-10-01 00:00:00'
+       and JCSJ < timestamp '2026-11-01 00:00:00'
+       and MS like '%' || c_mark || '%';
+
+    for r in (
+        select b.BJID
+          from BJ b
+          inner join ZY z on z.ZYID = b.ZYID
+         where z.FZBMID = v_bmid
+           and b.JLZTM in (22, 25, 51)
+           and b.BJZTM <> 81
+         order by b.BJID
+    ) loop
+        v_idx := v_idx + 1;
+        v_bjid := r.BJID;
+        v_am := 88 + mod(v_idx, 8);
+        v_pm := 90 + mod(v_idx, 7);
+        v_clean := 94 + mod(v_idx, 7);
+        v_classroom := 90 + mod(v_idx, 11);
+        v_fjrs := mod(v_idx, 3);
+
+        insert into SSNWJC (
+            SSNWJCID, BJID, JCRYID, MS, JCSJ, JLZTM, FS,
+            CJRYID, GLRYID, GLBMID
+        ) values (
+            SSNWJCID.nextval, v_bjid, v_teacher, c_mark,
+            timestamp '2026-10-05 08:00:00', 51, v_am,
+            v_teacher, v_teacher, v_bmid
+        );
+        insert into SSNWJC (
+            SSNWJCID, BJID, JCRYID, MS, JCSJ, JLZTM, FS,
+            CJRYID, GLRYID, GLBMID
+        ) values (
+            SSNWJCID.nextval, v_bjid, v_teacher, c_mark,
+            timestamp '2026-10-05 16:00:00', 51, v_pm,
+            v_teacher, v_teacher, v_bmid
+        );
+        insert into CSWSJC (
+            CSWSJCID, BJID, JCRYID, FS, MS, JCSJ, JLZTM,
+            CJRYID, GLRYID, GLBMID
+        ) values (
+            CSWSJCID.nextval, v_bjid, v_teacher, v_clean, c_mark,
+            timestamp '2026-10-05 15:00:00', 51,
+            v_teacher, v_teacher, v_bmid
+        );
+        insert into KTJL (
+            KTJLID, KCBID, BJID, JLRYID, FS, MS, JLSJ, JLZTM,
+            CJRYID, GLRYID, GLBMID
+        ) values (
+            KTJLID.nextval, v_kcbid, v_bjid, v_teacher, v_classroom,
+            c_mark, timestamp '2026-10-05 09:00:00', 51,
+            v_teacher, v_teacher, v_bmid
+        );
+        insert into SQLJC (
+            SQLJCID, BMID, BJID, JCRYID, JCSJ, ZFS, CQL,
+            KQFS, DLFS, FMFS, JLFS, MS, JLZTM,
+            CJRYID, GLRYID, GLBMID
+        ) values (
+            SQLJCID.nextval, v_bmid, v_bjid, v_teacher,
+            timestamp '2026-10-05 07:30:00', 93, 100,
+            100, 100, 100, 80, c_mark, 51,
+            v_teacher, v_teacher, v_bmid
+        );
+        insert into XJB_FJRY (
+            XJB_FJRYID, BJID, JCRQ, WJRS, MS, JLZTM, JLSJ,
+            CJRYID, GLRYID, GLBMID
+        ) values (
+            XJB_FJRYID.nextval, v_bjid, date '2026-10-05',
+            v_fjrs, c_mark, 51, systimestamp,
+            v_teacher, v_teacher, v_bmid
+        );
+
+        insert into XJB_JFJL (
+            XJB_JFJLID, NDY, BJID, LYLX, LYID, LYLB, FSSJ,
+            JFLX, JFZ, MC, MS, JLZTM, JLSJ, CJRYID, GLRYID, GLBMID
+        ) values (
+            XJB_JFJLID.nextval, '2026-10', v_bjid, 'MONTH_SAFE',
+            202610, 0, timestamp '2026-10-31 23:59:59',
+            1, 1.5, '当月无学生处分',
+            c_mark, 51, systimestamp, v_teacher, v_teacher, v_bmid
+        );
+        if v_fjrs = 0 then
+            insert into XJB_JFJL (
+                XJB_JFJLID, NDY, BJID, LYLX, LYID, LYLB, FSSJ,
+                JFLX, JFZ, MC, MS, JLZTM, JLSJ,
+                CJRYID, GLRYID, GLBMID
+            ) values (
+                XJB_JFJLID.nextval, '2026-10', v_bjid, 'FJ_SAFE',
+                202610, 0, timestamp '2026-10-31 23:59:59',
+                1, 0.5, '当月无风纪扣分',
+                c_mark, 51, systimestamp, v_teacher, v_teacher, v_bmid
+            );
+        end if;
+    end loop;
+end;
+/
+
+commit;
+/

+ 54 - 0
docs/24_星级班班主任移动报表/sql/2026-11-02_星级班月结_验证.sql

@@ -0,0 +1,54 @@
+set pagesize 240 linesize 300 feedback off
+
+prompt ===== published batches =====
+select XJB_JDID,NDY,FWLX,FWID,BB,ZT,CJSJ,FBSJ
+  from XJB_JD
+ order by NDY,XJB_JDID;
+
+prompt ===== batch row counts =====
+select XJB_JDID,count(*) JG_COUNT
+  from XJB_JG
+ group by XJB_JDID
+ order by XJB_JDID;
+
+select XJB_JDID,count(*) PM_COUNT
+  from XJB_PM
+ group by XJB_JDID
+ order by XJB_JDID;
+
+prompt ===== duplicate class results =====
+select XJB_JDID,BJID,count(*) CNT
+  from XJB_JG
+ group by XJB_JDID,BJID
+having count(*) > 1;
+
+prompt ===== formula check =====
+select BJID,ZF,
+       round(SSDF * 0.20 + KTDF * 0.05 + SJDF * 0.14
+             + CSDF * 0.18 + FJDF * 0.20 + KQDF * 0.15
+             + least(8, ZJF) - KJF, 2) CALC_TOTAL,
+       case when abs(ZF - round(SSDF * 0.20 + KTDF * 0.05
+             + SJDF * 0.14 + CSDF * 0.18 + FJDF * 0.20
+             + KQDF * 0.15 + least(8, ZJF) - KJF, 2)) > 0.01
+            then 'FAIL' else 'OK' end CHECK_RESULT
+  from XJB_JG
+ where XJB_JDID = (select max(XJB_JDID) from XJB_JD where ZT = 5);
+
+prompt ===== five-star rule check =====
+select j.BJID,j.ZF,p.XXPM,j.XJ
+  from XJB_JG j
+  join XJB_PM p on p.XJB_JDID=j.XJB_JDID and p.BJID=j.BJID
+ where j.XJ='五星级'
+   and not (p.XXPM <= 10 and j.ZF >= 90);
+
+prompt ===== source completeness =====
+select sum(case when SSLY <> 'real' or KTDF is null then 1 else 0 end) DORM_BAD,
+       sum(case when KTLY <> 'real' or KTDF is null then 1 else 0 end) CLASS_BAD,
+       sum(case when SJLY <> 'real' or SJDF is null then 1 else 0 end) FLAG_BAD,
+       sum(case when CSLY <> 'real' or CSDF is null then 1 else 0 end) CLEAN_BAD,
+       sum(case when FJLY <> 'real' or FJDF is null then 1 else 0 end) FJ_BAD,
+       sum(case when KQLY <> 'real' or KQDF is null then 1 else 0 end) ATT_BAD
+  from XJB_JG
+ where XJB_JDID = (select max(XJB_JDID) from XJB_JD where ZT = 5);
+
+exit

+ 130 - 0
src/base/po/XjbFjryPo.java

@@ -0,0 +1,130 @@
+package base.po;
+
+import ss.db.DbC;
+import ss.db.Po;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.util.Map;
+
+public class XjbFjryPo extends Po {
+    {
+        super.fieldTypeMap = Map.<String, Integer>ofEntries(
+                Map.entry("xjb_fjryid", DbC.PO_longType),
+                Map.entry("bjid", DbC.PO_longType),
+                Map.entry("jcrq", DbC.PO_DateType),
+                Map.entry("wjrs", DbC.PO_intType),
+                Map.entry("ms", DbC.PO_StringType),
+                Map.entry("jlztm", DbC.PO_intType),
+                Map.entry("jlsj", DbC.PO_TimestampType),
+                Map.entry("cjryid", DbC.PO_LongType),
+                Map.entry("glryid", DbC.PO_LongType),
+                Map.entry("glbmid", DbC.PO_LongType));
+    }
+
+    private long xjb_fjryid;
+    private long bjid;
+    private Date jcrq;
+    private int wjrs;
+    private String ms;
+    private int jlztm = 1;
+    private Timestamp jlsj;
+    private Long cjryid;
+    private Long glryid;
+    private Long glbmid;
+
+    public XjbFjryPo() {
+        super.tabName = "xjb_fjry";
+        super.idName = "xjb_fjryid";
+    }
+
+    @Override
+    public long rdIdVal() {
+        return xjb_fjryid;
+    }
+
+    @Override
+    public void wrIdVal(long id) {
+        xjb_fjryid = id;
+    }
+
+    public long getXjb_fjryid() {
+        return xjb_fjryid;
+    }
+
+    public void setXjb_fjryid(long value) {
+        xjb_fjryid = value;
+    }
+
+    public long getBjid() {
+        return bjid;
+    }
+
+    public void setBjid(long value) {
+        bjid = value;
+    }
+
+    public Date getJcrq() {
+        return jcrq;
+    }
+
+    public void setJcrq(Date value) {
+        jcrq = value;
+    }
+
+    public int getWjrs() {
+        return wjrs;
+    }
+
+    public void setWjrs(int value) {
+        wjrs = value;
+    }
+
+    public String getMs() {
+        return ms;
+    }
+
+    public void setMs(String value) {
+        ms = value;
+    }
+
+    public int getJlztm() {
+        return jlztm;
+    }
+
+    public void setJlztm(int value) {
+        jlztm = value;
+    }
+
+    public Timestamp getJlsj() {
+        return jlsj;
+    }
+
+    public void setJlsj(Timestamp value) {
+        jlsj = value;
+    }
+
+    public Long getCjryid() {
+        return cjryid;
+    }
+
+    public void setCjryid(Long value) {
+        cjryid = value;
+    }
+
+    public Long getGlryid() {
+        return glryid;
+    }
+
+    public void setGlryid(Long value) {
+        glryid = value;
+    }
+
+    public Long getGlbmid() {
+        return glbmid;
+    }
+
+    public void setGlbmid(Long value) {
+        glbmid = value;
+    }
+}

+ 139 - 0
src/base/po/XjbJdPo.java

@@ -0,0 +1,139 @@
+package base.po;
+
+import ss.db.DbC;
+import ss.db.Po;
+
+import java.sql.Timestamp;
+import java.util.Map;
+
+public class XjbJdPo extends Po {
+    {
+        super.fieldTypeMap = Map.<String, Integer>ofEntries(
+                Map.entry("xjb_jdid", DbC.PO_longType),
+                Map.entry("ndy", DbC.PO_StringType),
+                Map.entry("fwlx", DbC.PO_StringType),
+                Map.entry("fwid", DbC.PO_longType),
+                Map.entry("bb", DbC.PO_intType),
+                Map.entry("zt", DbC.PO_intType),
+                Map.entry("ms", DbC.PO_StringType),
+                Map.entry("cjsj", DbC.PO_TimestampType),
+                Map.entry("fbsj", DbC.PO_TimestampType),
+                Map.entry("jsryid", DbC.PO_LongType),
+                Map.entry("jsbmid", DbC.PO_LongType));
+    }
+
+    private long xjb_jdid;
+    private String ndy;
+    private String fwlx;
+    private long fwid;
+    private int bb;
+    private int zt;
+    private String ms;
+    private Timestamp cjsj;
+    private Timestamp fbsj;
+    private Long jsryid;
+    private Long jsbmid;
+
+    public XjbJdPo() {
+        super.tabName = "xjb_jd";
+        super.idName = "xjb_jdid";
+    }
+
+    @Override
+    public long rdIdVal() {
+        return xjb_jdid;
+    }
+
+    @Override
+    public void wrIdVal(long id) {
+        xjb_jdid = id;
+    }
+
+    public long getXjb_jdid() {
+        return xjb_jdid;
+    }
+
+    public void setXjb_jdid(long value) {
+        xjb_jdid = value;
+    }
+
+    public String getNdy() {
+        return ndy;
+    }
+
+    public void setNdy(String value) {
+        ndy = value;
+    }
+
+    public String getFwlx() {
+        return fwlx;
+    }
+
+    public void setFwlx(String value) {
+        fwlx = value;
+    }
+
+    public long getFwid() {
+        return fwid;
+    }
+
+    public void setFwid(long value) {
+        fwid = value;
+    }
+
+    public int getBb() {
+        return bb;
+    }
+
+    public void setBb(int value) {
+        bb = value;
+    }
+
+    public int getZt() {
+        return zt;
+    }
+
+    public void setZt(int value) {
+        zt = value;
+    }
+
+    public String getMs() {
+        return ms;
+    }
+
+    public void setMs(String value) {
+        ms = value;
+    }
+
+    public Timestamp getCjsj() {
+        return cjsj;
+    }
+
+    public void setCjsj(Timestamp value) {
+        cjsj = value;
+    }
+
+    public Timestamp getFbsj() {
+        return fbsj;
+    }
+
+    public void setFbsj(Timestamp value) {
+        fbsj = value;
+    }
+
+    public Long getJsryid() {
+        return jsryid;
+    }
+
+    public void setJsryid(Long value) {
+        jsryid = value;
+    }
+
+    public Long getJsbmid() {
+        return jsbmid;
+    }
+
+    public void setJsbmid(Long value) {
+        jsbmid = value;
+    }
+}

+ 319 - 0
src/base/po/XjbJgPo.java

@@ -0,0 +1,319 @@
+package base.po;
+
+import ss.db.DbC;
+import ss.db.Po;
+
+import java.sql.Timestamp;
+import java.util.Map;
+
+public class XjbJgPo extends Po {
+    {
+        super.fieldTypeMap = Map.<String, Integer>ofEntries(
+                Map.entry("xjb_jgid", DbC.PO_longType),
+                Map.entry("xjb_jdid", DbC.PO_longType),
+                Map.entry("ndy", DbC.PO_StringType),
+                Map.entry("bjid", DbC.PO_longType),
+                Map.entry("dwid", DbC.PO_LongType),
+                Map.entry("zyid", DbC.PO_LongType),
+                Map.entry("ssdf", DbC.PO_FloatType),
+                Map.entry("ktdf", DbC.PO_FloatType),
+                Map.entry("sjdf", DbC.PO_FloatType),
+                Map.entry("csdf", DbC.PO_FloatType),
+                Map.entry("fjdf", DbC.PO_FloatType),
+                Map.entry("kqdf", DbC.PO_FloatType),
+                Map.entry("zjf", DbC.PO_FloatType),
+                Map.entry("kjf", DbC.PO_FloatType),
+                Map.entry("zf", DbC.PO_FloatType),
+                Map.entry("xj", DbC.PO_StringType),
+                Map.entry("ssly", DbC.PO_StringType),
+                Map.entry("ktly", DbC.PO_StringType),
+                Map.entry("sjly", DbC.PO_StringType),
+                Map.entry("csly", DbC.PO_StringType),
+                Map.entry("fjly", DbC.PO_StringType),
+                Map.entry("kqly", DbC.PO_StringType),
+                Map.entry("zjfcs", DbC.PO_intType),
+                Map.entry("kjfcs", DbC.PO_intType),
+                Map.entry("qxsm", DbC.PO_StringType),
+                Map.entry("zt", DbC.PO_intType),
+                Map.entry("jlsj", DbC.PO_TimestampType),
+                Map.entry("cjryid", DbC.PO_LongType),
+                Map.entry("glbmid", DbC.PO_LongType));
+    }
+
+    private long xjb_jgid;
+    private long xjb_jdid;
+    private String ndy;
+    private long bjid;
+    private Long dwid;
+    private Long zyid;
+    private Float ssdf;
+    private Float ktdf;
+    private Float sjdf;
+    private Float csdf;
+    private Float fjdf;
+    private Float kqdf;
+    private Float zjf;
+    private Float kjf;
+    private Float zf;
+    private String xj;
+    private String ssly;
+    private String ktly;
+    private String sjly;
+    private String csly;
+    private String fjly;
+    private String kqly;
+    private int zjfcs;
+    private int kjfcs;
+    private String qxsm;
+    private int zt;
+    private Timestamp jlsj;
+    private Long cjryid;
+    private Long glbmid;
+
+    public XjbJgPo() {
+        super.tabName = "xjb_jg";
+        super.idName = "xjb_jgid";
+    }
+
+    @Override
+    public long rdIdVal() {
+        return xjb_jgid;
+    }
+
+    @Override
+    public void wrIdVal(long id) {
+        xjb_jgid = id;
+    }
+
+    public long getXjb_jgid() {
+        return xjb_jgid;
+    }
+
+    public void setXjb_jgid(long value) {
+        xjb_jgid = value;
+    }
+
+    public long getXjb_jdid() {
+        return xjb_jdid;
+    }
+
+    public void setXjb_jdid(long value) {
+        xjb_jdid = value;
+    }
+
+    public String getNdy() {
+        return ndy;
+    }
+
+    public void setNdy(String value) {
+        ndy = value;
+    }
+
+    public long getBjid() {
+        return bjid;
+    }
+
+    public void setBjid(long value) {
+        bjid = value;
+    }
+
+    public Long getDwid() {
+        return dwid;
+    }
+
+    public void setDwid(Long value) {
+        dwid = value;
+    }
+
+    public Long getZyid() {
+        return zyid;
+    }
+
+    public void setZyid(Long value) {
+        zyid = value;
+    }
+
+    public Float getSsdf() {
+        return ssdf;
+    }
+
+    public void setSsdf(Float value) {
+        ssdf = value;
+    }
+
+    public Float getKtdf() {
+        return ktdf;
+    }
+
+    public void setKtdf(Float value) {
+        ktdf = value;
+    }
+
+    public Float getSjdf() {
+        return sjdf;
+    }
+
+    public void setSjdf(Float value) {
+        sjdf = value;
+    }
+
+    public Float getCsdf() {
+        return csdf;
+    }
+
+    public void setCsdf(Float value) {
+        csdf = value;
+    }
+
+    public Float getFjdf() {
+        return fjdf;
+    }
+
+    public void setFjdf(Float value) {
+        fjdf = value;
+    }
+
+    public Float getKqdf() {
+        return kqdf;
+    }
+
+    public void setKqdf(Float value) {
+        kqdf = value;
+    }
+
+    public Float getZjf() {
+        return zjf;
+    }
+
+    public void setZjf(Float value) {
+        zjf = value;
+    }
+
+    public Float getKjf() {
+        return kjf;
+    }
+
+    public void setKjf(Float value) {
+        kjf = value;
+    }
+
+    public Float getZf() {
+        return zf;
+    }
+
+    public void setZf(Float value) {
+        zf = value;
+    }
+
+    public String getXj() {
+        return xj;
+    }
+
+    public void setXj(String value) {
+        xj = value;
+    }
+
+    public String getSsly() {
+        return ssly;
+    }
+
+    public void setSsly(String value) {
+        ssly = value;
+    }
+
+    public String getKtly() {
+        return ktly;
+    }
+
+    public void setKtly(String value) {
+        ktly = value;
+    }
+
+    public String getSjly() {
+        return sjly;
+    }
+
+    public void setSjly(String value) {
+        sjly = value;
+    }
+
+    public String getCsly() {
+        return csly;
+    }
+
+    public void setCsly(String value) {
+        csly = value;
+    }
+
+    public String getFjly() {
+        return fjly;
+    }
+
+    public void setFjly(String value) {
+        fjly = value;
+    }
+
+    public String getKqly() {
+        return kqly;
+    }
+
+    public void setKqly(String value) {
+        kqly = value;
+    }
+
+    public int getZjfcs() {
+        return zjfcs;
+    }
+
+    public void setZjfcs(int value) {
+        zjfcs = value;
+    }
+
+    public int getKjfcs() {
+        return kjfcs;
+    }
+
+    public void setKjfcs(int value) {
+        kjfcs = value;
+    }
+
+    public String getQxsm() {
+        return qxsm;
+    }
+
+    public void setQxsm(String value) {
+        qxsm = value;
+    }
+
+    public int getZt() {
+        return zt;
+    }
+
+    public void setZt(int value) {
+        zt = value;
+    }
+
+    public Timestamp getJlsj() {
+        return jlsj;
+    }
+
+    public void setJlsj(Timestamp value) {
+        jlsj = value;
+    }
+
+    public Long getCjryid() {
+        return cjryid;
+    }
+
+    public void setCjryid(Long value) {
+        cjryid = value;
+    }
+
+    public Long getGlbmid() {
+        return glbmid;
+    }
+
+    public void setGlbmid(Long value) {
+        glbmid = value;
+    }
+}

+ 108 - 0
src/base/po/XjbPmPo.java

@@ -0,0 +1,108 @@
+package base.po;
+
+import ss.db.DbC;
+import ss.db.Po;
+
+import java.util.Map;
+
+public class XjbPmPo extends Po {
+    {
+        super.fieldTypeMap = Map.<String, Integer>ofEntries(
+                Map.entry("xjb_pmid", DbC.PO_longType),
+                Map.entry("xjb_jdid", DbC.PO_longType),
+                Map.entry("bjid", DbC.PO_longType),
+                Map.entry("dwid", DbC.PO_LongType),
+                Map.entry("dwpm", DbC.PO_intType),
+                Map.entry("dwcs", DbC.PO_intType),
+                Map.entry("xxpm", DbC.PO_intType),
+                Map.entry("xxcs", DbC.PO_intType));
+    }
+
+    private long xjb_pmid;
+    private long xjb_jdid;
+    private long bjid;
+    private Long dwid;
+    private int dwpm;
+    private int dwcs;
+    private int xxpm;
+    private int xxcs;
+
+    public XjbPmPo() {
+        super.tabName = "xjb_pm";
+        super.idName = "xjb_pmid";
+    }
+
+    @Override
+    public long rdIdVal() {
+        return xjb_pmid;
+    }
+
+    @Override
+    public void wrIdVal(long id) {
+        xjb_pmid = id;
+    }
+
+    public long getXjb_pmid() {
+        return xjb_pmid;
+    }
+
+    public void setXjb_pmid(long value) {
+        xjb_pmid = value;
+    }
+
+    public long getXjb_jdid() {
+        return xjb_jdid;
+    }
+
+    public void setXjb_jdid(long value) {
+        xjb_jdid = value;
+    }
+
+    public long getBjid() {
+        return bjid;
+    }
+
+    public void setBjid(long value) {
+        bjid = value;
+    }
+
+    public Long getDwid() {
+        return dwid;
+    }
+
+    public void setDwid(Long value) {
+        dwid = value;
+    }
+
+    public int getDwpm() {
+        return dwpm;
+    }
+
+    public void setDwpm(int value) {
+        dwpm = value;
+    }
+
+    public int getDwcs() {
+        return dwcs;
+    }
+
+    public void setDwcs(int value) {
+        dwcs = value;
+    }
+
+    public int getXxpm() {
+        return xxpm;
+    }
+
+    public void setXxpm(int value) {
+        xxpm = value;
+    }
+
+    public int getXxcs() {
+        return xxcs;
+    }
+
+    public void setXxcs(int value) {
+        xxcs = value;
+    }
+}

+ 376 - 90
src/biz/bj/BjStarClassMpServ.java

@@ -126,6 +126,8 @@ public class BjStarClassMpServ extends Serv {
             ClassScore classScore = scores.classScores.get(selected.bjid);
             if (classScore == null)
                 throw new IllegalStateException("班级评分未生成");
+            PublishedSnapshot snapshot = rdPublishedSnapshot(
+                    db, selected.bjid, month);
 
             int pageNo = Math.max(1, rdIntParam(request, "pageNo", 1));
             int pageSize = clampPageSize(rdIntParam(request, "pageSize",
@@ -145,19 +147,45 @@ public class BjStarClassMpServ extends Serv {
             data.put("dwid", selected.dwid);
             data.put("dwmc", selected.dwmc);
             data.put("month", month.format(MONTH_FMT));
-            data.put("score", round2(classScore.total));
-            data.put("starLevel", starLevel(classScore.total));
-            data.put("departmentRank", ranks.departmentRank.get(selected.bjid));
-            data.put("departmentClassCount", ranks.departmentClassCount.getOrDefault(
-                    selected.dwid, 0));
-            data.put("schoolRank", ranks.schoolRank.get(selected.bjid));
-            data.put("schoolClassCount", classes.size());
-            data.put("bonusTotal", round2(classScore.adjust.bonus));
-            data.put("deductionTotal", round2(classScore.adjust.deduction));
-            data.put("bonusCount", classScore.adjust.bonusEvents);
-            data.put("deductionCount", classScore.adjust.deductionEvents);
-            data.put("rankingPreview", classScore.hasMock);
-            data.put("categorySources", scores.categorySources(selected.bjid));
+            if (snapshot != null) {
+                data.put("score", snapshot.total);
+                data.put("starLevel", snapshot.starLevel);
+                data.put("departmentRank", snapshot.departmentRank);
+                data.put("departmentClassCount", snapshot.departmentClassCount);
+                data.put("schoolRank", snapshot.schoolRank);
+                data.put("schoolClassCount", snapshot.schoolClassCount);
+                data.put("bonusTotal", snapshot.bonus);
+                data.put("deductionTotal", snapshot.deduction);
+                data.put("bonusCount", snapshot.bonusCount);
+                data.put("deductionCount", snapshot.deductionCount);
+                data.put("rankingPreview", false);
+                data.put("snapshotPublished", true);
+                data.put("categorySources", snapshot.sources);
+            } else {
+                data.put("score", classScore.hasMissing
+                        ? null : round2(classScore.total));
+                data.put("starLevel", classScore.hasMissing
+                        ? "待评分" : starLevel(classScore.total,
+                        ranks.schoolRank.getOrDefault(selected.bjid, 0)));
+                data.put("departmentRank", classScore.hasMissing
+                        ? null : ranks.departmentRank.get(selected.bjid));
+                data.put("departmentClassCount",
+                        ranks.departmentClassCount.getOrDefault(
+                                selected.dwid, 0));
+                data.put("schoolRank", classScore.hasMissing
+                        ? null : ranks.schoolRank.get(selected.bjid));
+                data.put("schoolClassCount", classes.size());
+                data.put("bonusTotal", round2(classScore.adjust.bonus));
+                data.put("deductionTotal",
+                        round2(classScore.adjust.deduction));
+                data.put("bonusCount", classScore.adjust.bonusEvents);
+                data.put("deductionCount", classScore.adjust.deductionEvents);
+                data.put("rankingPreview", classScore.hasMissing);
+                data.put("snapshotPublished", false);
+                data.put("categorySources",
+                        scores.categorySources(selected.bjid));
+                data.put("missingItems", classScore.missing);
+            }
             data.put("pageNo", pageNo);
             data.put("pageSize", pageSize);
             data.put("total", allDays.size());
@@ -385,7 +413,6 @@ public class BjStarClassMpServ extends Serv {
     private static ScoreBook rdScoreBook(Db db, List<ClassInfo> classes,
                                          MonthPeriod period) throws Exception {
         ScoreBook book = new ScoreBook();
-        book.dorm = rdAvgScoreByClass(db, "SSNWJC", period);
         book.cleaning = rdAvgScoreByClass(db, "CSWSJC", period);
         book.flag = rdFlagScoreByClass(db, period);
         book.classroom = rdAvgKtjlScoreByClass(db, period);
@@ -394,47 +421,50 @@ public class BjStarClassMpServ extends Serv {
                 rdAttendancePenalty(db, period);
         book.attendance = computeAttendanceScores(
                 classes, schoolDays, attendancePenalty);
+        book.dorm = rdDormScores(db, classes, period, book.attendance);
+        book.discipline = rdDisciplineScores(db, period);
         book.adjustments = rdAdjustmentTotals(db, period.month);
 
         for (ClassInfo cls : classes) {
             ClassScore score = new ClassScore();
-            score.values.put("dorm", scoreOrMock(book.dorm, cls.bjid,
-                    period.month, "dorm", period.maxDay));
-            score.values.put("classroom", scoreOrMissing(
-                    book.classroom, cls.bjid));
-            score.values.put("flag", scoreOrMock(book.flag, cls.bjid,
-                    period.month, "flag", period.maxDay));
-            score.values.put("cleaning", scoreOrMock(book.cleaning, cls.bjid,
-                    period.month, "cleaning", period.maxDay));
-            score.values.put("discipline", mockMonthlyScore(
-                    cls.bjid, period.month, "discipline", period.maxDay));
-            score.values.put("attendance", scoreOrMock(book.attendance,
-                    cls.bjid, period.month, "attendance", period.maxDay));
-            score.sources.put("dorm", book.dorm.containsKey(cls.bjid)
-                    ? SOURCE_REAL : SOURCE_MOCK);
-            score.sources.put("classroom", book.classroom.containsKey(cls.bjid)
-                    ? SOURCE_REAL : SOURCE_MISSING);
-            score.sources.put("flag", book.flag.containsKey(cls.bjid)
-                    ? SOURCE_REAL : SOURCE_MOCK);
-            score.sources.put("cleaning", book.cleaning.containsKey(cls.bjid)
-                    ? SOURCE_REAL : SOURCE_MOCK);
-            score.sources.put("discipline", SOURCE_MOCK);
-            score.sources.put("attendance", book.attendance.containsKey(cls.bjid)
-                    ? SOURCE_REAL : SOURCE_MOCK);
+            putScore(score, "dorm", "宿舍评分", book.dorm.get(cls.bjid));
+            putScore(score, "classroom", "课堂考核",
+                    book.classroom.get(cls.bjid));
+            putScore(score, "flag", "升旗礼", book.flag.get(cls.bjid));
+            putScore(score, "cleaning", "清洁卫生",
+                    book.cleaning.get(cls.bjid));
+            putScore(score, "discipline", "风纪仪容",
+                    book.discipline.get(cls.bjid));
+            putScore(score, "attendance", "考勤",
+                    book.attendance.get(cls.bjid));
             score.adjust = book.adjustments.getOrDefault(
                     cls.bjid, new AdjustmentTotals());
-            double weighted = 0.0;
-            for (CategoryDef def : CATEGORY_DEFS)
-                weighted += score.values.get(def.code) * def.weight;
-            score.total = round2(
-                    weighted + score.adjust.bonus - score.adjust.deduction);
-            score.hasMock = score.sources.containsValue(SOURCE_MOCK)
-                    || score.sources.containsValue(SOURCE_MISSING);
+            if (score.missing.isEmpty()) {
+                double weighted = 0.0;
+                for (CategoryDef def : CATEGORY_DEFS)
+                    weighted += score.values.get(def.code) * def.weight;
+                score.total = round2(weighted
+                        + Math.min(8.0, score.adjust.bonus)
+                        - score.adjust.deduction);
+            }
+            score.hasMissing = !score.missing.isEmpty();
             book.classScores.put(cls.bjid, score);
         }
         return book;
     }
 
+    private static void putScore(ClassScore score, String code, String label,
+                                 Double value) {
+        if (value == null) {
+            score.values.put(code, 0.0);
+            score.sources.put(code, SOURCE_MISSING);
+            score.missing.add(label);
+            return;
+        }
+        score.values.put(code, round2(value));
+        score.sources.put(code, SOURCE_REAL);
+    }
+
 
     private static Map<Long, Double> rdAvgScoreByClass(Db db, String table,
                                                         MonthPeriod period)
@@ -451,6 +481,68 @@ public class BjStarClassMpServ extends Serv {
     }
 
 
+    private static Map<Long, Double> rdDormScores(
+            Db db, List<ClassInfo> classes, MonthPeriod period,
+            Map<Long, Double> attendanceScores) throws Exception {
+        SqlCmd internalCmd = new SqlCmd(
+                "select BJID,"
+                        + "avg(case when extract(hour from JCSJ)<12 then FS end) AM,"
+                        + "avg(case when extract(hour from JCSJ)>=12 then FS end) PM"
+                        + " from SSNWJC where JCSJ>=:start and JCSJ<:end"
+                        + " and " + ObjC.JLZT_useStr + " group by BJID");
+        internalCmd.wrTimeParm("start", period.start);
+        internalCmd.wrTimeParm("end", period.end);
+        Map<Long, double[]> internal = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(internalCmd)) {
+            internal.put(rdLong(row.get("bjid")), new double[]{
+                    row.get("am") == null ? -1 : rdDouble(row.get("am")),
+                    row.get("pm") == null ? -1 : rdDouble(row.get("pm"))
+            });
+        }
+
+        SqlCmd violationCmd = new SqlCmd(
+                "select w.BJID,sum(nvl(lb.BJKF,0)) PENALTY from WJJL w"
+                        + " inner join WJLB lb on lb.WJLBM=w.WJLBM"
+                        + " where w.WJSJ>=:start and w.WJSJ<:end"
+                        + " and w.WJLBM>=20 and w.JLZTM=51 group by w.BJID");
+        violationCmd.wrTimeParm("start", period.start);
+        violationCmd.wrTimeParm("end", period.end);
+        Map<Long, Double> violations = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(violationCmd))
+            violations.put(rdLong(row.get("bjid")),
+                    rdDouble(row.get("penalty")));
+
+        Map<Long, Double> result = new HashMap<>();
+        for (ClassInfo cls : classes) {
+            double[] values = internal.get(cls.bjid);
+            Double attendance = attendanceScores.get(cls.bjid);
+            if (values == null || values[0] < 0 || values[1] < 0
+                    || attendance == null)
+                continue;
+            double internalScore = (values[0] + values[1]) / 2.0;
+            double violationScore = Math.max(0.0,
+                    100.0 - violations.getOrDefault(cls.bjid, 0.0));
+            double base = internalScore * 0.35 + attendance * 0.15
+                    + violationScore * 0.35;
+            result.put(cls.bjid, round2(base + base / 85.0 * 10.0));
+        }
+        return result;
+    }
+
+
+    private static Map<Long, Double> rdDisciplineScores(
+            Db db, MonthPeriod period) throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select BJID,avg(case when WJRS>=100 then 0"
+                        + " else 100-WJRS end) SCORE from XJB_FJRY"
+                        + " where JCRQ>=:start and JCRQ<:end"
+                        + " and JLZTM=51 group by BJID");
+        sqlc.wrTimeParm("start", period.start);
+        sqlc.wrTimeParm("end", period.end);
+        return rdScoreMap(db.doSelMapListByC(sqlc));
+    }
+
+
     private static Map<Long, Double> rdFlagScoreByClass(Db db,
                                                          MonthPeriod period)
             throws Exception {
@@ -507,7 +599,7 @@ public class BjStarClassMpServ extends Serv {
             Db db, MonthPeriod period) throws Exception {
         SqlCmd sqlc = new SqlCmd(
                 "select BJID,trunc(KSSJ) D,sum(case KQLBM"
-                        + " when 1 then 3 when 21 then 1 when 51 then 2"
+                        + " when 1 then 3 when 21 then 1 when 51 then 1"
                         + " when 52 then 1 when 61 then 2 else 0 end) PENALTY"
                         + " from KQJL where KSSJ>=:start and KSSJ<:end"
                         + " and KQJLZTM=51 and " + ObjC.JLZT_useStr
@@ -550,7 +642,12 @@ public class BjStarClassMpServ extends Serv {
 
     private static RankBook rdRanks(List<ClassInfo> classes, ScoreBook book) {
         RankBook ranks = new RankBook();
-        List<ClassInfo> school = new ArrayList<>(classes);
+        List<ClassInfo> school = new ArrayList<>();
+        for (ClassInfo cls : classes) {
+            ClassScore score = book.classScores.get(cls.bjid);
+            if (score != null && !score.hasMissing)
+                school.add(cls);
+        }
         school.sort(Comparator
                 .comparingDouble((ClassInfo cls) ->
                         -book.classScores.get(cls.bjid).total)
@@ -558,7 +655,7 @@ public class BjStarClassMpServ extends Serv {
         assignRanks(school, book, ranks.schoolRank, "school");
 
         Map<Long, List<ClassInfo>> departments = new LinkedHashMap<>();
-        for (ClassInfo cls : classes)
+        for (ClassInfo cls : school)
             departments.computeIfAbsent(cls.dwid, key -> new ArrayList<>()).add(cls);
         for (Map.Entry<Long, List<ClassInfo>> entry : departments.entrySet()) {
             entry.getValue().sort(Comparator
@@ -594,7 +691,7 @@ public class BjStarClassMpServ extends Serv {
         Map<LocalDate, DailyAccumulator> days = new HashMap<>();
 
         for (CategoryDef def : CATEGORY_DEFS) {
-            String source = sources.getOrDefault(def.code, SOURCE_MOCK);
+            String source = sources.getOrDefault(def.code, SOURCE_MISSING);
             Map<LocalDate, DailyPoint> actual = daily.actual.get(def.code);
             for (LocalDate date = period.month.atDay(1);
                  !date.isAfter(period.maxDate);
@@ -602,11 +699,6 @@ public class BjStarClassMpServ extends Serv {
                 DailyPoint point = null;
                 if (SOURCE_REAL.equals(source)) {
                     point = actual == null ? null : actual.get(date);
-                } else if (mockHasEvent(cls.bjid, monthKey(period.month),
-                        def.code, date.getDayOfMonth())) {
-                    point = new DailyPoint(date,
-                            mockDailyScore(cls.bjid, monthKey(period.month),
-                                    def.code, date.getDayOfMonth()), 1);
                 }
                 if (point == null)
                     continue;
@@ -614,8 +706,6 @@ public class BjStarClassMpServ extends Serv {
                         DailyAccumulator::new);
                 acc.regularDeduction += Math.max(0.0, 100.0 - point.score);
                 acc.hasRegular = true;
-                if (SOURCE_MOCK.equals(source))
-                    acc.hasMock = true;
             }
         }
 
@@ -636,8 +726,8 @@ public class BjStarClassMpServ extends Serv {
         Timestamp end = onlyDay == null ? period.end
                 : Timestamp.valueOf(onlyDay.plusDays(1).atStartOfDay());
 
-        result.actual.put("dorm", rdDailyAvgScore(db, "SSNWJC",
-                cls.bjid, start, end));
+        result.actual.put("dorm", rdDailyDormScore(db, cls,
+                onlyDay, period));
         result.actual.put("cleaning", rdDailyAvgScore(db, "CSWSJC",
                 cls.bjid, start, end));
         result.actual.put("flag", rdDailyFlagScore(db, cls.bjid, start, end));
@@ -645,28 +735,35 @@ public class BjStarClassMpServ extends Serv {
                 db, cls.bjid, start, end));
         result.actual.put("attendance", rdDailyAttendanceScore(db,
                 cls.bjid, start, end));
+        result.actual.put("discipline", rdDailyDisciplineScore(
+                db, cls.bjid, start, end));
 
         MonthPeriod fullMonth = MonthPeriod.of(period.month);
-        Map<Long, Double> monthDorm = rdAvgScoreByClass(db, "SSNWJC", fullMonth);
         Map<Long, Double> monthClean = rdAvgScoreByClass(db, "CSWSJC", fullMonth);
         Map<Long, Double> monthFlag = rdFlagScoreByClass(db, fullMonth);
         Map<Long, Double> monthAttendance = computeAttendanceScores(
                 List.of(cls), rdSchoolDays(db, fullMonth),
                 rdAttendancePenalty(db, fullMonth));
+        Map<Long, Double> monthDorm = rdDormScores(db, List.of(cls),
+                fullMonth, monthAttendance);
         Map<Long, Double> monthClassroom =
                 rdAvgKtjlScoreByClass(db, fullMonth);
+        Map<Long, Double> monthDiscipline =
+                rdDisciplineScores(db, fullMonth);
         result.sources.put("dorm", monthDorm.containsKey(cls.bjid)
-                ? SOURCE_REAL : SOURCE_MOCK);
+                ? SOURCE_REAL : SOURCE_MISSING);
         result.sources.put("classroom",
                 monthClassroom.containsKey(cls.bjid)
                         ? SOURCE_REAL : SOURCE_MISSING);
         result.sources.put("flag", monthFlag.containsKey(cls.bjid)
-                ? SOURCE_REAL : SOURCE_MOCK);
+                ? SOURCE_REAL : SOURCE_MISSING);
         result.sources.put("cleaning", monthClean.containsKey(cls.bjid)
-                ? SOURCE_REAL : SOURCE_MOCK);
-        result.sources.put("discipline", SOURCE_MOCK);
+                ? SOURCE_REAL : SOURCE_MISSING);
+        result.sources.put("discipline",
+                monthDiscipline.containsKey(cls.bjid)
+                        ? SOURCE_REAL : SOURCE_MISSING);
         result.sources.put("attendance", monthAttendance.containsKey(cls.bjid)
-                ? SOURCE_REAL : SOURCE_MOCK);
+                ? SOURCE_REAL : SOURCE_MISSING);
         return result;
     }
 
@@ -686,6 +783,78 @@ public class BjStarClassMpServ extends Serv {
     }
 
 
+    private static Map<LocalDate, DailyPoint> rdDailyDormScore(
+            Db db, ClassInfo cls, LocalDate onlyDay, MonthPeriod period)
+            throws Exception {
+        Timestamp start = onlyDay == null ? period.start
+                : Timestamp.valueOf(onlyDay.atStartOfDay());
+        Timestamp end = onlyDay == null ? period.end
+                : Timestamp.valueOf(onlyDay.plusDays(1).atStartOfDay());
+        SqlCmd itemCmd = new SqlCmd(
+                "select trunc(JCSJ) D,"
+                        + "avg(case when extract(hour from JCSJ)<12 then FS end) AM,"
+                        + "avg(case when extract(hour from JCSJ)>=12 then FS end) PM"
+                        + " from SSNWJC where BJID=:bjid and JCSJ>=:start"
+                        + " and JCSJ<:end and " + ObjC.JLZT_useStr
+                        + " group by trunc(JCSJ)");
+        itemCmd.wrLongParm("bjid", cls.bjid);
+        itemCmd.wrTimeParm("start", start);
+        itemCmd.wrTimeParm("end", end);
+        Map<LocalDate, double[]> internal = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(itemCmd))
+            internal.put(rdLocalDate(row.get("d")), new double[]{
+                    row.get("am") == null ? -1 : rdDouble(row.get("am")),
+                    row.get("pm") == null ? -1 : rdDouble(row.get("pm"))
+            });
+
+        SqlCmd violationCmd = new SqlCmd(
+                "select trunc(w.WJSJ) D,sum(nvl(lb.BJKF,0)) PENALTY"
+                        + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
+                        + " where w.BJID=:bjid and w.WJSJ>=:start"
+                        + " and w.WJSJ<:end and w.WJLBM>=20 and w.JLZTM=51"
+                        + " group by trunc(w.WJSJ)");
+        violationCmd.wrLongParm("bjid", cls.bjid);
+        violationCmd.wrTimeParm("start", start);
+        violationCmd.wrTimeParm("end", end);
+        Map<LocalDate, Double> violations = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(violationCmd))
+            violations.put(rdLocalDate(row.get("d")),
+                    rdDouble(row.get("penalty")));
+
+        Map<LocalDate, DailyPoint> attendance =
+                rdDailyAttendanceScore(db, cls.bjid, start, end);
+        Map<LocalDate, DailyPoint> result = new HashMap<>();
+        for (Map.Entry<LocalDate, double[]> entry : internal.entrySet()) {
+            DailyPoint attend = attendance.get(entry.getKey());
+            double[] values = entry.getValue();
+            if (values[0] < 0 || values[1] < 0 || attend == null)
+                continue;
+            double internalScore = (values[0] + values[1]) / 2.0;
+            double violationScore = Math.max(0.0,
+                    100.0 - violations.getOrDefault(entry.getKey(), 0.0));
+            double base = internalScore * 0.35 + attend.score * 0.15
+                    + violationScore * 0.35;
+            result.put(entry.getKey(), new DailyPoint(entry.getKey(),
+                    round2(base + base / 85.0 * 10.0), attend.count));
+        }
+        return result;
+    }
+
+
+    private static Map<LocalDate, DailyPoint> rdDailyDisciplineScore(
+            Db db, long bjid, Timestamp start, Timestamp end)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select JCRQ D,case when WJRS>=100 then 0 else 100-WJRS end"
+                        + " SCORE,1 CNT from XJB_FJRY where BJID=:bjid"
+                        + " and JCRQ>=:start and JCRQ<:end and JLZTM=51");
+        sqlc.wrLongParm("bjid", bjid);
+        sqlc.wrTimeParm("start", start);
+        sqlc.wrTimeParm("end", end);
+        return rdDailyPoints(db.doSelMapListByC(sqlc));
+    }
+
+
     private static Map<LocalDate, DailyPoint> rdDailyFlagScore(
             Db db, long bjid, Timestamp start, Timestamp end) throws Exception {
         SqlCmd sqlc = new SqlCmd(
@@ -726,7 +895,7 @@ public class BjStarClassMpServ extends Serv {
             Db db, long bjid, Timestamp start, Timestamp end) throws Exception {
         SqlCmd sqlc = new SqlCmd(
                 "select trunc(KSSJ) D,sum(case KQLBM"
-                        + " when 1 then 3 when 21 then 1 when 51 then 2"
+                        + " when 1 then 3 when 21 then 1 when 51 then 1"
                         + " when 52 then 1 when 61 then 2 else 0 end) PENALTY,"
                         + "count(*) CNT from KQJL where BJID=:bjid"
                         + " and KSSJ>=:start and KSSJ<:end"
@@ -766,7 +935,8 @@ public class BjStarClassMpServ extends Serv {
             Db db, ClassInfo cls, LocalDate day, MonthPeriod period,
             CategoryDef category) throws Exception {
         CategoryDaily monthly = rdCategoryDaily(db, cls, day, period);
-        String source = monthly.sources.getOrDefault(category.code, SOURCE_MOCK);
+        String source = monthly.sources.getOrDefault(
+                category.code, SOURCE_MISSING);
         List<Map<String, Object>> rows;
         if (SOURCE_REAL.equals(source)) {
             if ("attendance".equals(category.code))
@@ -779,10 +949,10 @@ public class BjStarClassMpServ extends Serv {
                 rows = rdItemDetail(db, cls.bjid, day, "cleaning");
             else if ("classroom".equals(category.code))
                 rows = rdKtjlDetail(db, cls.bjid, day);
+            else if ("discipline".equals(category.code))
+                rows = rdDisciplineDetail(db, cls.bjid, day);
             else
-                rows = mockDayDetail(cls, day, category.code);
-        } else if (SOURCE_MOCK.equals(source)) {
-            rows = mockDayDetail(cls, day, category.code);
+                rows = new ArrayList<>();
         } else {
             rows = new ArrayList<>();
         }
@@ -830,6 +1000,34 @@ public class BjStarClassMpServ extends Serv {
     }
 
 
+    private static List<Map<String, Object>> rdDisciplineDetail(
+            Db db, long bjid, LocalDate day) throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select XJB_FJRYID,WJRS,MS from XJB_FJRY"
+                        + " where BJID=:bjid and JCRQ=:jcrq and JLZTM=51");
+        sqlc.wrLongParm("bjid", bjid);
+        sqlc.wrTimeParm("jcrq", Timestamp.valueOf(day.atStartOfDay()));
+        List<Map<String, Object>> result = new ArrayList<>();
+        for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
+            int count = rdInt(row.get("wjrs"));
+            Map<String, Object> item = baseDetail(day, SOURCE_REAL);
+            item.put("id", rdLong(row.get("xjb_fjryid")));
+            item.put("sourceId", rdLong(row.get("xjb_fjryid")));
+            item.put("category", "discipline");
+            item.put("traceable", true);
+            item.put("itemName", "风纪仪容违纪");
+            item.put("studentName", "");
+            item.put("title", "风纪仪容违纪 " + count + "人次");
+            item.put("remark", rdStr(row.get("ms")));
+            item.put("delta", -count);
+            item.put("scoreText", Math.max(0, 100 - count) + "/100");
+            item.put("sortTime", day.format(DATE_FMT));
+            result.add(item);
+        }
+        return result;
+    }
+
+
     private static List<Map<String, Object>> rdItemDetail(
             Db db, long bjid, LocalDate day, String category) throws Exception {
         Timestamp start = Timestamp.valueOf(day.atStartOfDay());
@@ -983,10 +1181,46 @@ public class BjStarClassMpServ extends Serv {
             return rdCheckTrace(db, cls, day, category, sourceId, "cleaning");
         if ("classroom".equals(category.code))
             return rdKtjlTrace(db, cls, day, category, sourceId);
+        if ("discipline".equals(category.code))
+            return rdDisciplineTrace(db, cls, day, category, sourceId);
         return rdMockTraceDetail(cls, day, category);
     }
 
 
+    private static Map<String, Object> rdDisciplineTrace(
+            Db db, ClassInfo cls, LocalDate day,
+            CategoryDef category, long sourceId) throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select XJB_FJRYID,JCRQ,WJRS,MS from XJB_FJRY"
+                        + " where XJB_FJRYID=:id and BJID=:bjid and JLZTM=51");
+        sqlc.wrLongParm("id", sourceId);
+        sqlc.wrLongParm("bjid", cls.bjid);
+        List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
+        if (rows == null || rows.isEmpty())
+            throw new IllegalArgumentException("风纪仪容记录不存在或已不可查看");
+        Map<String, Object> row = rows.get(0);
+        int violations = rdInt(row.get("wjrs"));
+        Map<String, Object> record = new LinkedHashMap<>();
+        record.put("time", day.format(DATE_FMT));
+        record.put("className", cls.bjmc);
+        record.put("inspectorName", "风纪检查");
+        record.put("violationCount", violations);
+        record.put("description", rdStr(row.get("ms")));
+
+        List<Map<String, Object>> items = new ArrayList<>();
+        if (violations > 0) {
+            Map<String, Object> item = new LinkedHashMap<>();
+            item.put("itemName", "风纪仪容违纪");
+            item.put("deducted", violations);
+            item.put("remark", "违纪" + violations + "人次,每人次扣1分");
+            items.add(item);
+        }
+        return traceResult(cls, day, category, SOURCE_REAL,
+                "风纪仪容扣分详情", record, items,
+                violations == 0 ? "当日无风纪仪容扣分" : "");
+    }
+
+
     private static Map<String, Object> rdCheckTrace(Db db, ClassInfo cls,
                                                      LocalDate day,
                                                      CategoryDef category,
@@ -1435,6 +1669,51 @@ public class BjStarClassMpServ extends Serv {
     }
 
 
+    private static PublishedSnapshot rdPublishedSnapshot(
+            Db db, long bjid, YearMonth month) throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select jg.ZF,jg.XJ,jg.ZJF,jg.KJF,jg.ZJFCS,jg.KJFCS,"
+                        + "jg.SSLY,jg.KTLY,jg.SJLY,jg.CSLY,jg.FJLY,jg.KQLY,"
+                        + "pm.DWPM,pm.DWCS,pm.XXPM,pm.XXCS from XJB_JG jg"
+                        + " inner join XJB_JD jd on jd.XJB_JDID=jg.XJB_JDID"
+                        + " inner join XJB_PM pm on pm.XJB_JDID=jg.XJB_JDID"
+                        + " and pm.BJID=jg.BJID"
+                        + " where jg.BJID=:bjid and jg.NDY=:ndy"
+                        + " and jg.ZT=5 and jd.ZT=5"
+                        + " order by jd.BB desc,jd.XJB_JDID desc");
+        sqlc.wrLongParm("bjid", bjid);
+        sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
+        try {
+            List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
+            if (rows == null || rows.isEmpty())
+                return null;
+            Map<String, Object> row = rows.get(0);
+            PublishedSnapshot snapshot = new PublishedSnapshot();
+            snapshot.total = rdDouble(row.get("zf"));
+            snapshot.starLevel = rdStr(row.get("xj"));
+            snapshot.bonus = rdDouble(row.get("zjf"));
+            snapshot.deduction = rdDouble(row.get("kjf"));
+            snapshot.bonusCount = rdInt(row.get("zjfcs"));
+            snapshot.deductionCount = rdInt(row.get("kjfcs"));
+            snapshot.departmentRank = rdInt(row.get("dwpm"));
+            snapshot.departmentClassCount = rdInt(row.get("dwcs"));
+            snapshot.schoolRank = rdInt(row.get("xxpm"));
+            snapshot.schoolClassCount = rdInt(row.get("xxcs"));
+            snapshot.sources.put("dorm", rdStr(row.get("ssly")));
+            snapshot.sources.put("classroom", rdStr(row.get("ktly")));
+            snapshot.sources.put("flag", rdStr(row.get("sjly")));
+            snapshot.sources.put("cleaning", rdStr(row.get("csly")));
+            snapshot.sources.put("discipline", rdStr(row.get("fjly")));
+            snapshot.sources.put("attendance", rdStr(row.get("kqly")));
+            return snapshot;
+        } catch (SQLException e) {
+            if (isMissingTable(e, "XJB_JG"))
+                return null;
+            throw e;
+        }
+    }
+
+
     private static List<Adjustment> rdAdjustments(
             Db db, long bjid, YearMonth month) throws Exception {
         SqlCmd sqlc = new SqlCmd(
@@ -1487,14 +1766,18 @@ public class BjStarClassMpServ extends Serv {
     }
 
 
-    private static String starLevel(double score) {
-        if (score >= 90.0)
+    private static String starLevel(double score, int schoolRank) {
+        if (schoolRank <= 10 && score >= 90.0)
             return "五星级";
         if (score >= 80.0)
             return "四星级";
-        if (score >= 70.0)
+        if (score >= 75.0)
             return "三星级";
-        return "二星级";
+        if (score >= 65.0)
+            return "二星级";
+        if (score >= 55.0)
+            return "一星级";
+        return "无星级";
     }
 
 
@@ -1502,7 +1785,7 @@ public class BjStarClassMpServ extends Serv {
         return switch (kqlbm) {
             case 1 -> 3;
             case 21 -> 1;
-            case 51 -> 2;
+            case 51 -> 1;
             case 52 -> 1;
             case 61 -> 2;
             default -> 0;
@@ -1746,21 +2029,12 @@ public class BjStarClassMpServ extends Serv {
         }
 
         Map<String, Object> toMap(CategoryDef def, LocalDate date) {
-            String source = sources.getOrDefault(def.code, SOURCE_MOCK);
+            String source = sources.getOrDefault(def.code, SOURCE_MISSING);
             DailyPoint point = null;
             if (SOURCE_REAL.equals(source)) {
                 Map<LocalDate, DailyPoint> values = actual.get(def.code);
                 point = values == null ? null : values.get(date);
             }
-            if (point == null && SOURCE_MOCK.equals(source)) {
-                if (mockHasEvent(cls.bjid,
-                        monthKey(YearMonth.from(date)), def.code,
-                        date.getDayOfMonth())) {
-                    point = new DailyPoint(date, mockDailyScore(cls.bjid,
-                            monthKey(YearMonth.from(date)), def.code,
-                            date.getDayOfMonth()), 1);
-                }
-            }
             boolean available;
             double score;
             double deduction;
@@ -1768,15 +2042,10 @@ public class BjStarClassMpServ extends Serv {
                 available = true;
                 score = point.score;
                 deduction = Math.max(0.0, 100.0 - score);
-            } else if (SOURCE_REAL.equals(source)
-                    || SOURCE_MISSING.equals(source)) {
+            } else {
                 available = false;
                 score = 0.0;
                 deduction = 0.0;
-            } else {
-                available = true;
-                score = 100.0;
-                deduction = 0.0;
             }
             Map<String, Object> row = new LinkedHashMap<>();
             row.put("code", def.code);
@@ -1806,6 +2075,7 @@ public class BjStarClassMpServ extends Serv {
         Map<Long, Double> flag = new HashMap<>();
         Map<Long, Double> cleaning = new HashMap<>();
         Map<Long, Double> attendance = new HashMap<>();
+        Map<Long, Double> discipline = new HashMap<>();
         Map<Long, AdjustmentTotals> adjustments = new HashMap<>();
         Map<Long, ClassScore> classScores = new HashMap<>();
 
@@ -1819,9 +2089,10 @@ public class BjStarClassMpServ extends Serv {
     private static final class ClassScore {
         final Map<String, Double> values = new LinkedHashMap<>();
         final Map<String, String> sources = new LinkedHashMap<>();
+        final List<String> missing = new ArrayList<>();
         AdjustmentTotals adjust = new AdjustmentTotals();
         double total;
-        boolean hasMock;
+        boolean hasMissing;
     }
 
 
@@ -1863,4 +2134,19 @@ public class BjStarClassMpServ extends Serv {
         int bonusEvents;
         int deductionEvents;
     }
+
+
+    private static final class PublishedSnapshot {
+        double total;
+        String starLevel;
+        double bonus;
+        double deduction;
+        int bonusCount;
+        int deductionCount;
+        int departmentRank;
+        int departmentClassCount;
+        int schoolRank;
+        int schoolClassCount;
+        final Map<String, String> sources = new LinkedHashMap<>();
+    }
 }

+ 258 - 0
src/biz/bj/XjbFjryServ.java

@@ -0,0 +1,258 @@
+package biz.bj;
+
+import base.po.XjbFjryPo;
+import com.google.gson.Gson;
+import jakarta.servlet.http.HttpServletRequest;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import ss.db.Db;
+import ss.db.SqlCmd;
+import ss.obj.ObjC;
+import ss.serv.Serv;
+import ss.serv.ServU;
+import ss.user.UserRunB;
+import ss.user.UserU;
+
+import java.io.Writer;
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.YearMonth;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * 星级班风纪仪容日登记。
+ */
+public class XjbFjryServ extends Serv {
+
+    private static final Logger log4j = LogManager.getLogger(XjbFjryServ.class);
+    private static final ZoneId CN_ZONE = ZoneId.of("Asia/Shanghai");
+    private static final DateTimeFormatter DATE_FMT =
+            DateTimeFormatter.ofPattern("yyyy-MM-dd");
+    private static final DateTimeFormatter MONTH_FMT =
+            DateTimeFormatter.ofPattern("yyyy-MM");
+
+    /**
+     * 保存或更新一个班级某天的风纪仪容登记。
+     */
+    @SuppressWarnings("unused")
+    public void saveByA() throws Exception {
+        HttpServletRequest request = super.req;
+        super.resp.setCharacterEncoding("UTF-8");
+        super.resp.setContentType("application/json;charset=UTF-8");
+        Writer writer = super.resp.getWriter();
+        Gson gson = new Gson();
+
+        try (Db db = Db.makeConn()) {
+            UserRunB user = UserU.rdUserByReq(request);
+            if (user == null)
+                throw new IllegalArgumentException("登录状态已失效,请重新登录");
+            long bjid = rdLong(request.getParameter("bjid"), 0L);
+            Map<String, Object> cls = requireTeacherClass(db, user.ryid, bjid);
+            bjid = rdLong(cls.get("bjid"), 0L);
+            LocalDate inspectionDate = rdDate(request.getParameter("jcrq"));
+            if (inspectionDate.isAfter(LocalDate.now(CN_ZONE)))
+                throw new IllegalArgumentException("不能登记未来日期");
+            int violationCount = rdInt(request.getParameter("wjrs"), 0);
+            if (violationCount < 0 || violationCount > 1000)
+                throw new IllegalArgumentException("违纪人次必须在0到1000之间");
+            String memo = StringUtils.trimToEmpty(request.getParameter("ms"));
+
+            Long existingId = findExistingId(db, bjid, inspectionDate);
+            if (existingId == null) {
+                insert(db, bjid, inspectionDate, violationCount, memo, user);
+            } else {
+                update(db, existingId, violationCount, memo, user);
+            }
+            db.commit();
+
+            Map<String, Object> data = new LinkedHashMap<>();
+            data.put("bjid", bjid);
+            data.put("bjmc", cls.get("bjmc"));
+            data.put("jcrq", inspectionDate.format(DATE_FMT));
+            data.put("wjrs", violationCount);
+            data.put("dailyScore", Math.max(0, 100 - violationCount));
+            ServU.wrOkDataByWriter(data, writer, gson);
+        } catch (IllegalArgumentException e) {
+            ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
+        } catch (Exception e) {
+            log4j.error("XjbFjryServ.saveByA() 异常", e);
+            ServU.wrErrMsgByWriter(null, "风纪仪容登记保存失败", writer, gson);
+        }
+    }
+
+    /**
+     * 按月份查询风纪仪容登记。
+     */
+    @SuppressWarnings("unused")
+    public void listByA() throws Exception {
+        HttpServletRequest request = super.req;
+        super.resp.setCharacterEncoding("UTF-8");
+        super.resp.setContentType("application/json;charset=UTF-8");
+        Writer writer = super.resp.getWriter();
+        Gson gson = new Gson();
+
+        try (Db db = Db.makeConn()) {
+            UserRunB user = UserU.rdUserByReq(request);
+            if (user == null)
+                throw new IllegalArgumentException("登录状态已失效,请重新登录");
+            long bjid = rdLong(request.getParameter("bjid"), 0L);
+            Map<String, Object> cls = requireTeacherClass(db, user.ryid, bjid);
+            bjid = rdLong(cls.get("bjid"), 0L);
+            YearMonth month = rdMonth(request.getParameter("month"));
+
+            SqlCmd sqlc = new SqlCmd(
+                    "select XJB_FJRYID,JCRQ,WJRS,MS from XJB_FJRY"
+                            + " where BJID=:bjid and JCRQ>=:start and JCRQ<:end"
+                            + " and JLZTM=51 order by JCRQ desc");
+            sqlc.wrLongParm("bjid", bjid);
+            sqlc.wrTimeParm("start", Timestamp.valueOf(
+                    month.atDay(1).atStartOfDay()));
+            sqlc.wrTimeParm("end", Timestamp.valueOf(
+                    month.plusMonths(1).atDay(1).atStartOfDay()));
+
+            List<Map<String, Object>> list = new ArrayList<>();
+            for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
+                Map<String, Object> item = new LinkedHashMap<>();
+                item.put("fjryid", rdLong(row.get("xjb_fjryid"), 0L));
+                item.put("jcrq", String.valueOf(row.get("jcrq")));
+                item.put("wjrs", rdInt(row.get("wjrs"), 0));
+                item.put("dailyScore", Math.max(0,
+                        100 - rdInt(row.get("wjrs"), 0)));
+                item.put("ms", rdStr(row.get("ms")));
+                list.add(item);
+            }
+            Map<String, Object> data = new LinkedHashMap<>();
+            data.put("bjid", bjid);
+            data.put("bjmc", cls.get("bjmc"));
+            data.put("month", month.format(MONTH_FMT));
+            data.put("list", list);
+            ServU.wrOkDataByWriter(data, writer, gson);
+        } catch (IllegalArgumentException e) {
+            ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
+        } catch (Exception e) {
+            log4j.error("XjbFjryServ.listByA() 异常", e);
+            ServU.wrErrMsgByWriter(null, "风纪仪容登记加载失败", writer, gson);
+        }
+    }
+
+    private void insert(Db db, long bjid, LocalDate inspectionDate,
+                        int violationCount, String memo, UserRunB user)
+            throws Exception {
+        XjbFjryPo po = new XjbFjryPo();
+        po.setXjb_fjryid(db.rdNextSeqVal("XJB_FJRYID"));
+        po.setBjid(bjid);
+        po.setJcrq(Date.valueOf(inspectionDate));
+        po.setWjrs(violationCount);
+        po.setMs(StringUtils.abbreviate(memo, 1000));
+        po.setJlztm(ObjC.JLZT_inUse);
+        po.setJlsj(new Timestamp(System.currentTimeMillis()));
+        po.setCjryid(user.ryid);
+        po.setGlryid(user.ryid);
+        po.setGlbmid(user.bmid);
+        Set<String> fields = new LinkedHashSet<>(Arrays.asList(
+                "xjb_fjryid", "bjid", "jcrq", "wjrs", "ms", "jlztm",
+                "jlsj", "cjryid", "glryid", "glbmid"));
+        db.doInsPo(po, fields);
+    }
+
+    private void update(Db db, long id, int violationCount, String memo,
+                        UserRunB user) throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "update XJB_FJRY set WJRS=:wjrs,MS=:ms,JLSJ=systimestamp,"
+                        + "GLRYID=:glryid,GLBMID=:glbmid"
+                        + " where XJB_FJRYID=:id and JLZTM=51");
+        sqlc.wrIntParm("wjrs", violationCount);
+        sqlc.wrStrParm("ms", StringUtils.abbreviate(memo, 1000));
+        sqlc.wrLongParm("glryid", user.ryid);
+        sqlc.wrLongParm("glbmid", user.bmid);
+        sqlc.wrLongParm("id", id);
+        if (db.doModByC(sqlc) != 1)
+            throw new IllegalStateException("登记记录更新失败");
+    }
+
+    private Long findExistingId(Db db, long bjid, LocalDate inspectionDate)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select XJB_FJRYID from XJB_FJRY where BJID=:bjid"
+                        + " and JCRQ=:jcrq and JLZTM=51");
+        sqlc.wrLongParm("bjid", bjid);
+        sqlc.wrTimeParm("jcrq", Timestamp.valueOf(
+                inspectionDate.atStartOfDay()));
+        List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
+        return rows == null || rows.isEmpty()
+                ? null : rdLongOrNull(rows.get(0).get("xjb_fjryid"));
+    }
+
+    private Map<String, Object> requireTeacherClass(Db db, long ryid,
+                                                     long bjid)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select BJID,MC BJMC from BJ where BZRID=:ryid and "
+                        + ObjC.JLZT_useStr + " and BJZTM!=81"
+                        + (bjid > 0 ? " and BJID=:bjid" : "")
+                        + " order by BJID");
+        sqlc.wrLongParm("ryid", ryid);
+        if (bjid > 0)
+            sqlc.wrLongParm("bjid", bjid);
+        List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
+        if (rows == null || rows.isEmpty())
+            throw new IllegalArgumentException(
+                    bjid > 0 ? "无权登记该班级" : "当前账号未关联班主任班级");
+        return rows.get(0);
+    }
+
+    private static LocalDate rdDate(String value) {
+        String text = StringUtils.trimToNull(value);
+        if (text == null)
+            return LocalDate.now(CN_ZONE);
+        try {
+            return LocalDate.parse(text, DATE_FMT);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("日期格式错误");
+        }
+    }
+
+    private static YearMonth rdMonth(String value) {
+        String text = StringUtils.trimToNull(value);
+        if (text == null)
+            return YearMonth.now(CN_ZONE);
+        try {
+            return YearMonth.parse(text, MONTH_FMT);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("月份格式错误");
+        }
+    }
+
+    private static long rdLong(Object value, long defaultValue) {
+        if (value == null)
+            return defaultValue;
+        String text = StringUtils.trimToNull(String.valueOf(value));
+        return text == null ? defaultValue : Long.parseLong(text);
+    }
+
+    private static Long rdLongOrNull(Object value) {
+        long parsed = rdLong(value, 0L);
+        return parsed == 0L ? null : parsed;
+    }
+
+    private static int rdInt(Object value, int defaultValue) {
+        if (value == null)
+            return defaultValue;
+        String text = StringUtils.trimToNull(String.valueOf(value));
+        return text == null ? defaultValue : Integer.parseInt(text);
+    }
+
+    private static String rdStr(Object value) {
+        return value == null ? "" : String.valueOf(value);
+    }
+}

+ 34 - 3
src/biz/bj/XjbJfServ.java

@@ -41,12 +41,13 @@ public class XjbJfServ extends Serv {
     public static final String LYLX_SCHOOL_VIOLATION = "XW";
     public static final String LYLX_TEAM_ROLE = "TT";
     public static final String LYLX_MONTH_SAFE = "MONTH_SAFE";
+    public static final String LYLX_FJ_SAFE = "FJ_SAFE";
     public static final int JFLX_ADD = 1;
     public static final int JFLX_SUB = 2;
 
     private static final Set<String> RECALC_TYPES = new LinkedHashSet<>(
             Arrays.asList(LYLX_AWARD, LYLX_SCHOOL_VIOLATION,
-                    LYLX_MONTH_SAFE));
+                    LYLX_MONTH_SAFE, LYLX_FJ_SAFE));
 
     /**
      * 为当前班主任的指定班级重建一个月的事件账本。
@@ -81,6 +82,7 @@ public class XjbJfServ extends Serv {
             data.put("violationEvents", count.violations);
             data.put("teamRoleEvents", count.teamRoles);
             data.put("monthSafeEvents", count.monthSafe);
+            data.put("fjSafeEvents", count.fjSafe);
             data.put("totalEvents", count.total());
             ServU.wrOkDataByWriter(data, writer, gson);
         } catch (IllegalArgumentException e) {
@@ -132,8 +134,10 @@ public class XjbJfServ extends Serv {
         count.violations = insertSchoolViolations(db, bjid, month, user);
         if (YearMonth.now(CN_ZONE).equals(month))
             count.teamRoles = insertTeamRoles(db, bjid, month, user);
-        if (month.isBefore(YearMonth.now(CN_ZONE)))
+        if (month.isBefore(YearMonth.now(CN_ZONE))) {
             count.monthSafe = insertMonthSafe(db, bjid, month, user);
+            count.fjSafe = insertFjSafe(db, bjid, month, user);
+        }
         return count;
     }
 
@@ -284,6 +288,32 @@ public class XjbJfServ extends Serv {
                 "当月班级无有效学校处分记录,增1.5分", user);
     }
 
+    private int insertFjSafe(Db db, long bjid, YearMonth month,
+                             UserRunB user) throws Exception {
+        Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
+        Timestamp end = Timestamp.valueOf(month.plusMonths(1).atDay(1)
+                .atStartOfDay());
+        SqlCmd countCmd = new SqlCmd(
+                "select count(*) DAYS,nvl(sum(WJRS),0) WJRS from XJB_FJRY"
+                        + " where BJID=:bjid and JCRQ>=:start and JCRQ<:end"
+                        + " and JLZTM=51");
+        countCmd.wrLongParm("bjid", bjid);
+        countCmd.wrTimeParm("start", start);
+        countCmd.wrTimeParm("end", end);
+        db.doSelByC(countCmd);
+        if (db.rowNum == 0 || db.rdIntCol("days") == 0
+                || db.rdIntCol("wjrs") > 0)
+            return 0;
+
+        long syntheticId = month.getYear() * 100L + month.getMonthValue();
+        Timestamp eventTime = Timestamp.valueOf(
+                month.atEndOfMonth().atTime(23, 59, 59));
+        return insertEvent(db, bjid, month, LYLX_FJ_SAFE,
+                syntheticId, 0L, null, eventTime,
+                JFLX_ADD, 0.5F, "当月无风纪扣分",
+                "当月风纪仪容无违纪记录,增0.5分", user);
+    }
+
     private int insertEvent(Db db, long bjid, YearMonth month, String lylx,
                             long lyid, long lylb, Long ryid, Timestamp fssj,
                             int jflx, float jfz, String mc, String ms,
@@ -407,9 +437,10 @@ public class XjbJfServ extends Serv {
         int violations;
         int teamRoles;
         int monthSafe;
+        int fjSafe;
 
         int total() {
-            return awards + violations + teamRoles + monthSafe;
+            return awards + violations + teamRoles + monthSafe + fjSafe;
         }
     }
 }

+ 833 - 0
src/biz/bj/XjbMonthCloseServ.java

@@ -0,0 +1,833 @@
+package biz.bj;
+
+import base.po.XjbJdPo;
+import base.po.XjbJgPo;
+import base.po.XjbPmPo;
+import com.google.gson.Gson;
+import jakarta.servlet.http.HttpServletRequest;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import ss.db.Db;
+import ss.db.SqlCmd;
+import ss.obj.ObjC;
+import ss.serv.Serv;
+import ss.serv.ServU;
+import ss.user.UserRunB;
+import ss.user.UserU;
+
+import java.io.Writer;
+import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.YearMonth;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * 星级班月结、快照和 PC 查询。
+ */
+public class XjbMonthCloseServ extends Serv {
+
+    private static final Logger log4j =
+            LogManager.getLogger(XjbMonthCloseServ.class);
+    private static final ZoneId CN_ZONE = ZoneId.of("Asia/Shanghai");
+    private static final DateTimeFormatter MONTH_FMT =
+            DateTimeFormatter.ofPattern("yyyy-MM");
+    private static final String SOURCE_REAL = "real";
+    private static final String SOURCE_MISSING = "missing";
+    private static final int JD_DRAFT = 1;
+    private static final int JD_PUBLISHED = 5;
+
+    /**
+     * 对当前用户部门完成一个已结束月份的月结。
+     */
+    @SuppressWarnings("unused")
+    public void closeByA() throws Exception {
+        HttpServletRequest request = super.req;
+        super.resp.setCharacterEncoding("UTF-8");
+        super.resp.setContentType("application/json;charset=UTF-8");
+        Writer writer = super.resp.getWriter();
+        Gson gson = new Gson();
+
+        try (Db db = Db.makeConn()) {
+            UserRunB user = UserU.rdUserByReq(request);
+            if (user == null)
+                throw new IllegalArgumentException("登录状态已失效,请重新登录");
+            if (user.bmid == null)
+                throw new IllegalArgumentException("当前账号未关联部门");
+            YearMonth month = rdMonth(request.getParameter("month"));
+            if (!month.isBefore(YearMonth.now(CN_ZONE)))
+                throw new IllegalArgumentException("只能月结已经结束的月份");
+
+            long bmid = user.bmid;
+            List<ClassRow> classes = rdDepartmentClasses(db, bmid);
+            if (classes.isEmpty())
+                throw new IllegalArgumentException("当前部门没有有效班级");
+            if (hasPublishedBatch(db, month, bmid))
+                throw new IllegalArgumentException("该部门该月份已发布,不能覆盖");
+
+            List<ClassResult> results = calculate(db, classes, month);
+            List<ClassResult> missing = new ArrayList<>();
+            for (ClassResult result : results) {
+                if (!result.missing.isEmpty())
+                    missing.add(result);
+            }
+            if (!missing.isEmpty()) {
+                StringBuilder message = new StringBuilder("月结数据不完整,");
+                message.append(missing.size()).append(" 个班级未发布:");
+                for (int i = 0; i < Math.min(5, missing.size()); i++) {
+                    if (i > 0)
+                        message.append(";");
+                    ClassResult item = missing.get(i);
+                    message.append(item.cls.bjmc).append("[")
+                            .append(String.join("、", item.missing))
+                            .append("]");
+                }
+                if (missing.size() > 5)
+                    message.append(" 等");
+                throw new IllegalArgumentException(message.toString());
+            }
+
+            assignRanks(results);
+            deleteDraftBatch(db, month, bmid);
+            long jdid = insertBatch(db, month, bmid, user);
+            for (ClassResult result : results)
+                insertResult(db, jdid, result, user);
+            db.commit();
+
+            Map<String, Object> data = new LinkedHashMap<>();
+            data.put("jdid", jdid);
+            data.put("month", month.format(MONTH_FMT));
+            data.put("bmid", bmid);
+            data.put("classCount", results.size());
+            data.put("status", JD_PUBLISHED);
+            ServU.wrOkDataByWriter(data, writer, gson);
+        } catch (IllegalArgumentException e) {
+            ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
+        } catch (Exception e) {
+            log4j.error("XjbMonthCloseServ.closeByA() 异常", e);
+            ServU.wrErrMsgByWriter(null, "星级班月结失败", writer, gson);
+        }
+    }
+
+    /**
+     * PC 星级班总表只读取已发布月结。
+     */
+    @SuppressWarnings("unused")
+    public void pcSummaryByA() throws Exception {
+        HttpServletRequest request = super.req;
+        super.resp.setCharacterEncoding("UTF-8");
+        super.resp.setContentType("application/json;charset=UTF-8");
+        Writer writer = super.resp.getWriter();
+        Gson gson = new Gson();
+
+        try (Db db = Db.makeConn()) {
+            UserRunB user = UserU.rdUserByReq(request);
+            if (user == null)
+                throw new IllegalArgumentException("登录状态已失效,请重新登录");
+            String monthText = StringUtils.trimToNull(request.getParameter("month"));
+            YearMonth month;
+            if (monthText == null) {
+                month = rdLatestPublishedMonth(db);
+                if (month == null)
+                    throw new IllegalArgumentException("暂无已发布星级班月结");
+            } else {
+                month = rdMonth(monthText);
+            }
+
+            SqlCmd batchCmd = new SqlCmd(
+                    "select XJB_JDID,NDY,FWLX,FWID,BB,ZT,FBSJ"
+                            + " from XJB_JD where NDY=:ndy and ZT=:status"
+                            + " order by BB desc,XJB_JDID desc");
+            batchCmd.wrStrParm("ndy", month.format(MONTH_FMT));
+            batchCmd.wrIntParm("status", JD_PUBLISHED);
+            List<Map<String, Object>> batches =
+                    db.doSelMapListByC(batchCmd);
+            if (batches == null || batches.isEmpty())
+                throw new IllegalArgumentException("该月份暂无已发布月结");
+            Map<String, Object> batch = batches.get(0);
+            long jdid = rdLong(batch.get("xjb_jdid"), 0L);
+
+            SqlCmd sqlc = new SqlCmd(
+                    "select j.BJID,b.MC BJMC,nvl(d.MC,'') DWMC,"
+                            + "nvl(z.MC,'') ZYMC,j.SSDF,j.KTDF,j.SJDF,j.CSDF,"
+                            + "j.FJDF,j.KQDF,j.ZJF,j.KJF,j.ZF,j.XJ,"
+                            + "j.ZJFCS,j.KJFCS,j.QXSM,p.DWPM,p.DWCS,p.XXPM,p.XXCS"
+                            + " from XJB_JG j"
+                            + " inner join BJ b on b.BJID=j.BJID"
+                            + " left join DW d on d.DWID=j.DWID"
+                            + " left join ZY z on z.ZYID=j.ZYID"
+                            + " left join XJB_PM p on p.XJB_JDID=j.XJB_JDID"
+                            + " and p.BJID=j.BJID"
+                            + " where j.XJB_JDID=:jdid and j.ZT=:status"
+                            + " order by p.XXPM,j.BJID");
+            sqlc.wrLongParm("jdid", jdid);
+            sqlc.wrIntParm("status", JD_PUBLISHED);
+
+            List<Map<String, Object>> rows = new ArrayList<>();
+            Set<String> departments = new LinkedHashSet<>();
+            Set<String> majors = new LinkedHashSet<>();
+            Set<String> classes = new LinkedHashSet<>();
+            Set<String> stars = new LinkedHashSet<>();
+            for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
+                Map<String, Object> item = new LinkedHashMap<>();
+                item.put("department", rdStr(row.get("dwmc")));
+                item.put("major", rdStr(row.get("zymc")));
+                item.put("className", rdStr(row.get("bjmc")));
+                item.put("dormScore", formatScore(row.get("ssdf")));
+                item.put("classroomScore", formatScore(row.get("ktdf")));
+                item.put("flagCeremonyScore", formatScore(row.get("sjdf")));
+                item.put("cleaningScore", formatScore(row.get("csdf")));
+                item.put("disciplineScore", formatScore(row.get("fjdf")));
+                item.put("attendanceScore", formatScore(row.get("kqdf")));
+                item.put("bonus", formatScore(row.get("zjf")));
+                item.put("deduction", formatScore(row.get("kjf")));
+                item.put("monthTotal", formatScore(row.get("zf")));
+                item.put("starLevel", rdStr(row.get("xj")));
+                item.put("departmentRank", rdStr(row.get("dwpm")));
+                item.put("departmentClassCount", rdStr(row.get("dwcs")));
+                item.put("schoolRank", rdStr(row.get("xxpm")));
+                item.put("schoolClassCount", rdStr(row.get("xxcs")));
+                item.put("bonusCount", rdStr(row.get("zjfcs")));
+                item.put("deductionCount", rdStr(row.get("kjfcs")));
+                item.put("missing", rdStr(row.get("qxsm")));
+                rows.add(item);
+                addNonBlank(departments, item.get("department"));
+                addNonBlank(majors, item.get("major"));
+                addNonBlank(classes, item.get("className"));
+                addNonBlank(stars, item.get("starLevel"));
+            }
+
+            Map<String, Object> data = new LinkedHashMap<>();
+            data.put("month", month.format(MONTH_FMT));
+            data.put("batchId", jdid);
+            data.put("status", "已发布");
+            data.put("publishedAt", formatTimestamp(batch.get("fbsj")));
+            data.put("rows", rows);
+            data.put("departments", new ArrayList<>(departments));
+            data.put("majors", new ArrayList<>(majors));
+            data.put("classes", new ArrayList<>(classes));
+            data.put("stars", new ArrayList<>(stars));
+            ServU.wrOkDataByWriter(data, writer, gson);
+        } catch (IllegalArgumentException e) {
+            ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
+        } catch (Exception e) {
+            log4j.error("XjbMonthCloseServ.pcSummaryByA() 异常", e);
+            ServU.wrErrMsgByWriter(null, "星级班月结报表加载失败", writer, gson);
+        }
+    }
+
+    private List<ClassRow> rdDepartmentClasses(Db db, long bmid)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select b.BJID,b.MC BJMC,b.DWID,b.ZYID from BJ b"
+                        + " inner join ZY z on z.ZYID=b.ZYID"
+                        + " where z.FZBMID=:bmid and b." + ObjC.JLZT_useStr
+                        + " and b.BJZTM!=81 order by b.MC,b.BJID");
+        sqlc.wrLongParm("bmid", bmid);
+        List<ClassRow> rows = new ArrayList<>();
+        for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
+            rows.add(new ClassRow(
+                    rdLong(row.get("bjid"), 0L),
+                    rdStr(row.get("bjmc")),
+                    rdLongOrNull(row.get("dwid")),
+                    rdLongOrNull(row.get("zyid"))));
+        }
+        return rows;
+    }
+
+    private List<ClassResult> calculate(Db db, List<ClassRow> classes,
+                                        YearMonth month) throws Exception {
+        Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
+        Timestamp end = Timestamp.valueOf(
+                month.plusMonths(1).atDay(1).atStartOfDay());
+
+        Map<Long, Double> classroom = rdAvg(db,
+                "select BJID,avg(FS) SCORE from KTJL"
+                        + " where JLSJ>=:start and JLSJ<:end and "
+                        + ObjC.JLZT_useStr + " group by BJID", start, end);
+        Map<Long, Double> flag = rdAvg(db,
+                "select BJID,avg(ZFS) SCORE from SQLJC"
+                        + " where JCSJ>=:start and JCSJ<:end"
+                        + " and ZFS between 0 and 100 and "
+                        + ObjC.JLZT_useStr + " group by BJID", start, end);
+        Map<Long, Double> cleaning = rdAvg(db,
+                "select BJID,avg(FS) SCORE from CSWSJC"
+                        + " where JCSJ>=:start and JCSJ<:end and "
+                        + ObjC.JLZT_useStr + " group by BJID", start, end);
+        Map<Long, DisciplineScore> discipline =
+                rdDisciplineScores(db, start, end);
+        Map<Long, Double> attendance = rdAttendanceScores(db, classes,
+                start, end);
+        Map<Long, DormScore> dorm = rdDormScores(db, classes, start, end);
+        Map<Long, AdjustmentTotals> adjustments =
+                rdAdjustmentTotals(db, month);
+
+        List<ClassResult> result = new ArrayList<>();
+        for (ClassRow cls : classes) {
+            ClassResult item = new ClassResult(cls);
+            item.ndy = month.format(MONTH_FMT);
+            item.dorm = dormComponent(dorm.get(cls.bjid));
+            item.classroom = component(classroom.get(cls.bjid),
+                    "课堂日志");
+            item.flag = component(flag.get(cls.bjid), "升旗礼");
+            item.cleaning = component(cleaning.get(cls.bjid), "场室卫生");
+            item.discipline = disciplineComponent(discipline.get(cls.bjid));
+            item.attendance = component(attendance.get(cls.bjid), "考勤");
+            item.adjust = adjustments.getOrDefault(cls.bjid,
+                    new AdjustmentTotals());
+
+            addMissing(item, "宿舍评分", item.dorm);
+            addMissing(item, "课堂考核", item.classroom);
+            addMissing(item, "升旗礼", item.flag);
+            addMissing(item, "清洁卫生", item.cleaning);
+            addMissing(item, "风纪仪容", item.discipline);
+            addMissing(item, "考勤", item.attendance);
+            if (item.missing.isEmpty()) {
+                double weighted = item.dorm.value * 0.20
+                        + item.classroom.value * 0.05
+                        + item.flag.value * 0.14
+                        + item.cleaning.value * 0.18
+                        + item.discipline.value * 0.20
+                        + item.attendance.value * 0.15;
+                item.total = round2(weighted
+                        + Math.min(8.0, item.adjust.bonus)
+                        - item.adjust.deduction);
+            }
+            result.add(item);
+        }
+        return result;
+    }
+
+    private Map<Long, Double> rdAvg(Db db, String sql,
+                                    Timestamp start, Timestamp end)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(sql);
+        sqlc.wrTimeParm("start", start);
+        sqlc.wrTimeParm("end", end);
+        Map<Long, Double> result = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(sqlc))
+            result.put(rdLong(row.get("bjid"), 0L),
+                    round2(rdDouble(row.get("score"))));
+        return result;
+    }
+
+    private Map<Long, DisciplineScore> rdDisciplineScores(
+            Db db, Timestamp start, Timestamp end) throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select BJID,avg(case when WJRS>=100 then 0"
+                        + " else 100-WJRS end) SCORE,sum(WJRS) WJRS,"
+                        + "count(*) DAYS from XJB_FJRY"
+                        + " where JCRQ>=:start and JCRQ<:end"
+                        + " and JLZTM=51 group by BJID");
+        sqlc.wrTimeParm("start", start);
+        sqlc.wrTimeParm("end", end);
+        Map<Long, DisciplineScore> result = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
+            DisciplineScore score = new DisciplineScore();
+            score.value = rdDouble(row.get("score"));
+            score.violations = rdInt(row.get("wjrs"));
+            score.days = rdInt(row.get("days"));
+            result.put(rdLong(row.get("bjid"), 0L), score);
+        }
+        return result;
+    }
+
+    private Map<Long, Double> rdAttendanceScores(
+            Db db, List<ClassRow> classes, Timestamp start, Timestamp end)
+            throws Exception {
+        SqlCmd daysCmd = new SqlCmd(
+                "select distinct trunc(KSSJ) D from KQJL"
+                        + " where KSSJ>=:start and KSSJ<:end"
+                        + " and KQJLZTM=51 and " + ObjC.JLZT_useStr);
+        daysCmd.wrTimeParm("start", start);
+        daysCmd.wrTimeParm("end", end);
+        List<LocalDate> days = new ArrayList<>();
+        for (Map<String, Object> row : db.doSelMapListByC(daysCmd))
+            days.add(rdLocalDate(row.get("d")));
+
+        SqlCmd penaltyCmd = new SqlCmd(
+                "select BJID,trunc(KSSJ) D,sum(case KQLBM"
+                        + " when 1 then 3 when 21 then 1 when 51 then 1"
+                        + " when 52 then 1 when 61 then 2 else 0 end) PENALTY"
+                        + " from KQJL where KSSJ>=:start and KSSJ<:end"
+                        + " and KQJLZTM=51 and " + ObjC.JLZT_useStr
+                        + " group by BJID,trunc(KSSJ)");
+        penaltyCmd.wrTimeParm("start", start);
+        penaltyCmd.wrTimeParm("end", end);
+        Map<Long, Map<LocalDate, Double>> penalties = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(penaltyCmd)) {
+            long bjid = rdLong(row.get("bjid"), 0L);
+            LocalDate day = rdLocalDate(row.get("d"));
+            penalties.computeIfAbsent(bjid, key -> new HashMap<>())
+                    .put(day, rdDouble(row.get("penalty")));
+        }
+
+        Map<Long, Double> result = new HashMap<>();
+        if (days.isEmpty())
+            return result;
+        for (ClassRow cls : classes) {
+            double total = 0.0;
+            Map<LocalDate, Double> classPenalty =
+                    penalties.getOrDefault(cls.bjid, Collections.emptyMap());
+            for (LocalDate day : days)
+                total += Math.max(0.0, 100.0
+                        - classPenalty.getOrDefault(day, 0.0));
+            result.put(cls.bjid, round2(total / days.size()));
+        }
+        return result;
+    }
+
+    private Map<Long, DormScore> rdDormScores(
+            Db db, List<ClassRow> classes, Timestamp start, Timestamp end)
+            throws Exception {
+        SqlCmd itemCmd = new SqlCmd(
+                "select BJID,"
+                        + "avg(case when extract(hour from JCSJ)<12 then FS end) AM,"
+                        + "avg(case when extract(hour from JCSJ)>=12 then FS end) PM"
+                        + " from SSNWJC where JCSJ>=:start and JCSJ<:end"
+                        + " and " + ObjC.JLZT_useStr + " group by BJID");
+        itemCmd.wrTimeParm("start", start);
+        itemCmd.wrTimeParm("end", end);
+        Map<Long, double[]> internal = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(itemCmd)) {
+            double[] values = new double[]{
+                    row.get("am") == null ? -1 : rdDouble(row.get("am")),
+                    row.get("pm") == null ? -1 : rdDouble(row.get("pm"))
+            };
+            internal.put(rdLong(row.get("bjid"), 0L), values);
+        }
+
+        SqlCmd violationCmd = new SqlCmd(
+                "select w.BJID,sum(nvl(lb.BJKF,0)) PENALTY"
+                        + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
+                        + " where w.WJSJ>=:start and w.WJSJ<:end"
+                        + " and w.WJLBM>=20 and w.JLZTM=51 group by w.BJID");
+        violationCmd.wrTimeParm("start", start);
+        violationCmd.wrTimeParm("end", end);
+        Map<Long, Double> violations = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(violationCmd)) {
+            violations.put(rdLong(row.get("bjid"), 0L),
+                    rdDouble(row.get("penalty")));
+        }
+
+        Map<Long, Double> attendance = rdAttendanceScores(db, classes,
+                start, end);
+        Map<Long, DormScore> result = new HashMap<>();
+        for (ClassRow cls : classes) {
+            double[] values = internal.get(cls.bjid);
+            Double attend = attendance.get(cls.bjid);
+            if (values == null || values[0] < 0 || values[1] < 0
+                    || attend == null)
+                continue;
+            double internalScore = (values[0] + values[1]) / 2.0;
+            double violationScore = Math.max(0.0,
+                    100.0 - violations.getOrDefault(cls.bjid, 0.0));
+            double base = internalScore * 0.35 + attend * 0.15
+                    + violationScore * 0.35;
+            DormScore score = new DormScore();
+            score.value = round2(base + base / 85.0 * 10.0);
+            score.morning = round2(values[0]);
+            score.afternoon = round2(values[1]);
+            score.attendance = attend;
+            score.violation = round2(violationScore);
+            result.put(cls.bjid, score);
+        }
+        return result;
+    }
+
+    private Map<Long, AdjustmentTotals> rdAdjustmentTotals(
+            Db db, YearMonth month) throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select BJID,sum(case when JFLX=1 then JFZ else 0 end) BONUS,"
+                        + "sum(case when JFLX=2 then JFZ else 0 end) DEDUCTION,"
+                        + "sum(case when JFLX=1 then 1 else 0 end) BONUS_CNT,"
+                        + "sum(case when JFLX=2 then 1 else 0 end) DEDUCTION_CNT"
+                        + " from XJB_JFJL where NDY=:ndy and JLZTM=51 group by BJID");
+        sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
+        Map<Long, AdjustmentTotals> result = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
+            AdjustmentTotals total = new AdjustmentTotals();
+            total.bonus = Math.min(8.0, rdDouble(row.get("bonus")));
+            total.deduction = rdDouble(row.get("deduction"));
+            total.bonusCount = rdInt(row.get("bonus_cnt"));
+            total.deductionCount = rdInt(row.get("deduction_cnt"));
+            result.put(rdLong(row.get("bjid"), 0L), total);
+        }
+        return result;
+    }
+
+    private Component component(Double value, String detail) {
+        Component item = new Component();
+        item.value = value;
+        item.source = value == null ? SOURCE_MISSING : SOURCE_REAL;
+        item.detail = detail;
+        return item;
+    }
+
+    private Component disciplineComponent(DisciplineScore score) {
+        Component item = new Component();
+        if (score == null)
+            return item;
+        item.value = round2(score.value);
+        item.source = SOURCE_REAL;
+        item.detail = "违纪" + score.violations + "人次,登记"
+                + score.days + "天";
+        return item;
+    }
+
+    private Component dormComponent(DormScore score) {
+        Component item = new Component();
+        if (score == null)
+            return item;
+        item.value = score.value;
+        item.source = SOURCE_REAL;
+        item.detail = "上午" + score.morning
+                + ",下午" + score.afternoon
+                + ",住宿考勤" + score.attendance
+                + ",违纪" + score.violation;
+        return item;
+    }
+
+    private void addMissing(ClassResult item, String label,
+                            Component component) {
+        if (component == null || component.value == null)
+            item.missing.add(label);
+    }
+
+    private void assignRanks(List<ClassResult> results) {
+        List<ClassResult> school = new ArrayList<>(results);
+        school.sort(Comparator
+                .comparingDouble((ClassResult item) -> -item.total)
+                .thenComparingLong(item -> item.cls.bjid));
+        assignSchoolRanks(school);
+
+        Map<Long, List<ClassResult>> departments = new LinkedHashMap<>();
+        for (ClassResult item : results) {
+            departments.computeIfAbsent(item.cls.dwid, key ->
+                    new ArrayList<>()).add(item);
+        }
+        for (List<ClassResult> group : departments.values()) {
+            group.sort(Comparator
+                    .comparingDouble((ClassResult item) -> -item.total)
+                    .thenComparingLong(item -> item.cls.bjid));
+            double previous = Double.NaN;
+            int rank = 0;
+            for (int i = 0; i < group.size(); i++) {
+                ClassResult item = group.get(i);
+                if (i == 0 || Double.compare(previous, item.total) != 0)
+                    rank = i + 1;
+                item.departmentRank = rank;
+                item.departmentClassCount = group.size();
+                previous = item.total;
+            }
+        }
+        for (ClassResult item : results)
+            item.star = starLevel(item.total, item.schoolRank);
+    }
+
+    private void assignSchoolRanks(List<ClassResult> sorted) {
+        double previous = Double.NaN;
+        int rank = 0;
+        for (int i = 0; i < sorted.size(); i++) {
+            ClassResult item = sorted.get(i);
+            if (i == 0 || Double.compare(previous, item.total) != 0)
+                rank = i + 1;
+            item.schoolRank = rank;
+            item.schoolClassCount = sorted.size();
+            previous = item.total;
+        }
+    }
+
+    private String starLevel(double score, int schoolRank) {
+        if (schoolRank <= 10 && score >= 90.0)
+            return "五星级";
+        if (score >= 80.0)
+            return "四星级";
+        if (score >= 75.0)
+            return "三星级";
+        if (score >= 65.0)
+            return "二星级";
+        if (score >= 55.0)
+            return "一星级";
+        return "无星级";
+    }
+
+    private boolean hasPublishedBatch(Db db, YearMonth month, long bmid)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select count(*) CNT from XJB_JD where NDY=:ndy"
+                        + " and FWLX='BM' and FWID=:fwid and ZT=:status");
+        sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
+        sqlc.wrLongParm("fwid", bmid);
+        sqlc.wrIntParm("status", JD_PUBLISHED);
+        db.doSelByC(sqlc);
+        return db.rowNum > 0 && db.rdIntCol("cnt") > 0;
+    }
+
+    private void deleteDraftBatch(Db db, YearMonth month, long bmid)
+            throws Exception {
+        SqlCmd find = new SqlCmd(
+                "select XJB_JDID from XJB_JD where NDY=:ndy"
+                        + " and FWLX='BM' and FWID=:fwid and ZT=:status");
+        find.wrStrParm("ndy", month.format(MONTH_FMT));
+        find.wrLongParm("fwid", bmid);
+        find.wrIntParm("status", JD_DRAFT);
+        List<Map<String, Object>> rows = db.doSelMapListByC(find);
+        if (rows == null)
+            return;
+        for (Map<String, Object> row : rows) {
+            long jdid = rdLong(row.get("xjb_jdid"), 0L);
+            deleteByJdId(db, "XJB_PM", jdid);
+            deleteByJdId(db, "XJB_JG", jdid);
+            SqlCmd delete = new SqlCmd(
+                    "delete from XJB_JD where XJB_JDID=:id and ZT=:status");
+            delete.wrLongParm("id", jdid);
+            delete.wrIntParm("status", JD_DRAFT);
+            db.doModByC(delete);
+        }
+    }
+
+    private void deleteByJdId(Db db, String table, long jdid)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "delete from " + table + " where XJB_JDID=:id");
+        sqlc.wrLongParm("id", jdid);
+        db.doModByC(sqlc);
+    }
+
+    private long insertBatch(Db db, YearMonth month, long bmid,
+                             UserRunB user) throws Exception {
+        long id = db.rdNextSeqVal("XJB_JDID");
+        Timestamp now = new Timestamp(System.currentTimeMillis());
+        XjbJdPo po = new XjbJdPo();
+        po.setXjb_jdid(id);
+        po.setNdy(month.format(MONTH_FMT));
+        po.setFwlx("BM");
+        po.setFwid(bmid);
+        po.setBb(1);
+        po.setZt(JD_PUBLISHED);
+        po.setMs("星级班月结");
+        po.setCjsj(now);
+        po.setFbsj(now);
+        po.setJsryid(user.ryid);
+        po.setJsbmid(user.bmid);
+        Set<String> fields = new LinkedHashSet<>(Arrays.asList(
+                "xjb_jdid", "ndy", "fwlx", "fwid", "bb", "zt", "ms",
+                "cjsj", "fbsj", "jsryid", "jsbmid"));
+        db.doInsPo(po, fields);
+        return id;
+    }
+
+    private void insertResult(Db db, long jdid, ClassResult result,
+                              UserRunB user) throws Exception {
+        XjbJgPo jg = new XjbJgPo();
+        jg.setXjb_jgid(db.rdNextSeqVal("XJB_JGID"));
+        jg.setXjb_jdid(jdid);
+        jg.setNdy(result.ndy);
+        jg.setBjid(result.cls.bjid);
+        jg.setDwid(result.cls.dwid);
+        jg.setZyid(result.cls.zyid);
+        jg.setSsdf(result.dorm.value.floatValue());
+        jg.setKtdf(result.classroom.value.floatValue());
+        jg.setSjdf(result.flag.value.floatValue());
+        jg.setCsdf(result.cleaning.value.floatValue());
+        jg.setFjdf(result.discipline.value.floatValue());
+        jg.setKqdf(result.attendance.value.floatValue());
+        jg.setZjf((float) Math.min(8.0, result.adjust.bonus));
+        jg.setKjf((float) result.adjust.deduction);
+        jg.setZf((float) result.total);
+        jg.setXj(result.star);
+        jg.setSsly(result.dorm.source);
+        jg.setKtly(result.classroom.source);
+        jg.setSjly(result.flag.source);
+        jg.setCsly(result.cleaning.source);
+        jg.setFjly(result.discipline.source);
+        jg.setKqly(result.attendance.source);
+        jg.setZjfcs(result.adjust.bonusCount);
+        jg.setKjfcs(result.adjust.deductionCount);
+        jg.setQxsm("");
+        jg.setZt(JD_PUBLISHED);
+        jg.setJlsj(new Timestamp(System.currentTimeMillis()));
+        jg.setCjryid(user.ryid);
+        jg.setGlbmid(user.bmid);
+        Set<String> jgFields = new LinkedHashSet<>(Arrays.asList(
+                "xjb_jgid", "xjb_jdid", "ndy", "bjid", "dwid", "zyid",
+                "ssdf", "ktdf", "sjdf", "csdf", "fjdf", "kqdf",
+                "zjf", "kjf", "zf", "xj", "ssly", "ktly", "sjly",
+                "csly", "fjly", "kqly", "zjfcs", "kjfcs", "qxsm",
+                "zt", "jlsj", "cjryid", "glbmid"));
+        db.doInsPo(jg, jgFields);
+
+        XjbPmPo pm = new XjbPmPo();
+        pm.setXjb_pmid(db.rdNextSeqVal("XJB_PMID"));
+        pm.setXjb_jdid(jdid);
+        pm.setBjid(result.cls.bjid);
+        pm.setDwid(result.cls.dwid);
+        pm.setDwpm(result.departmentRank);
+        pm.setDwcs(result.departmentClassCount);
+        pm.setXxpm(result.schoolRank);
+        pm.setXxcs(result.schoolClassCount);
+        Set<String> pmFields = new LinkedHashSet<>(Arrays.asList(
+                "xjb_pmid", "xjb_jdid", "bjid", "dwid",
+                "dwpm", "dwcs", "xxpm", "xxcs"));
+        db.doInsPo(pm, pmFields);
+    }
+
+    private YearMonth rdLatestPublishedMonth(Db db) throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select max(NDY) NDY from XJB_JD where ZT=:status");
+        sqlc.wrIntParm("status", JD_PUBLISHED);
+        db.doSelByC(sqlc);
+        if (db.rowNum == 0)
+            return null;
+        String value = db.rdStrCol("ndy");
+        return StringUtils.isBlank(value) ? null
+                : YearMonth.parse(value, MONTH_FMT);
+    }
+
+    private static YearMonth rdMonth(String value) {
+        String text = StringUtils.trimToNull(value);
+        if (text == null)
+            throw new IllegalArgumentException("请选择月份");
+        try {
+            return YearMonth.parse(text, MONTH_FMT);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("月份格式错误");
+        }
+    }
+
+    private static void addNonBlank(Set<String> target, Object value) {
+        String text = String.valueOf(value == null ? "" : value).trim();
+        if (!text.isEmpty())
+            target.add(text);
+    }
+
+    private static String formatScore(Object value) {
+        if (value == null)
+            return "-";
+        return String.format("%.2f", rdDouble(value));
+    }
+
+    private static String formatTimestamp(Object value) {
+        if (value instanceof Timestamp timestamp)
+            return timestamp.toLocalDateTime()
+                    .format(DateTimeFormatter.ofPattern(
+                            "yyyy-MM-dd HH:mm:ss"));
+        return value == null ? "" : String.valueOf(value);
+    }
+
+    private static LocalDate rdLocalDate(Object value) {
+        if (value instanceof java.sql.Date date)
+            return date.toLocalDate();
+        if (value instanceof Timestamp timestamp)
+            return timestamp.toLocalDateTime().toLocalDate();
+        if (value == null)
+            return null;
+        String text = String.valueOf(value);
+        return text.length() < 10 ? null
+                : LocalDate.parse(text.substring(0, 10));
+    }
+
+    private static long rdLong(Object value, long defaultValue) {
+        if (value == null)
+            return defaultValue;
+        String text = StringUtils.trimToNull(String.valueOf(value));
+        return text == null ? defaultValue : Long.parseLong(text);
+    }
+
+    private static Long rdLongOrNull(Object value) {
+        long parsed = rdLong(value, 0L);
+        return parsed == 0L ? null : parsed;
+    }
+
+    private static int rdInt(Object value) {
+        return value == null ? 0 : Integer.parseInt(String.valueOf(value));
+    }
+
+    private static double rdDouble(Object value) {
+        return value == null ? 0.0 : Double.parseDouble(String.valueOf(value));
+    }
+
+    private static String rdStr(Object value) {
+        return value == null ? "" : String.valueOf(value);
+    }
+
+    private static double round2(double value) {
+        return Math.round(value * 100.0) / 100.0;
+    }
+
+    private static final class ClassRow {
+        final long bjid;
+        final String bjmc;
+        final Long dwid;
+        final Long zyid;
+
+        ClassRow(long bjid, String bjmc, Long dwid, Long zyid) {
+            this.bjid = bjid;
+            this.bjmc = bjmc;
+            this.dwid = dwid;
+            this.zyid = zyid;
+        }
+    }
+
+    private static final class Component {
+        Double value;
+        String source = SOURCE_MISSING;
+        String detail = "";
+    }
+
+    private static final class DisciplineScore {
+        double value;
+        int violations;
+        int days;
+    }
+
+    private static final class DormScore {
+        double value;
+        double morning;
+        double afternoon;
+        double attendance;
+        double violation;
+    }
+
+    private static final class AdjustmentTotals {
+        double bonus;
+        double deduction;
+        int bonusCount;
+        int deductionCount;
+    }
+
+    private static final class ClassResult {
+        final ClassRow cls;
+        Component dorm;
+        Component classroom;
+        Component flag;
+        Component cleaning;
+        Component discipline;
+        Component attendance;
+        AdjustmentTotals adjust = new AdjustmentTotals();
+        final List<String> missing = new ArrayList<>();
+        double total;
+        String star = "待评分";
+        int departmentRank;
+        int departmentClassCount;
+        int schoolRank;
+        int schoolClassCount;
+        String ndy;
+
+        ClassResult(ClassRow cls) {
+            this.cls = cls;
+        }
+    }
+}

+ 14 - 0
web/cfg/biz/bj/xjbFjry.obj.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE xml>
+
+<objs biz="jw">
+<obj name="xjbFjry" desc="星级班风纪仪容日登记" po="base.po.XjbFjryPo"
+	 menu="false" fts="false">
+	<field name="bjid" desc="班级" cb="bj" inp="true"/>
+	<field name="jcrq" desc="检查日期" type="date" inp="true"/>
+	<field name="wjrs" desc="违纪人次" inp="true"/>
+	<field name="ms" desc="说明" abs="true"/>
+
+	<func def="parent"/>
+</obj>
+</objs>

+ 9 - 0
web/cfg/biz/bj/xjbFjry.serv.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE xml>
+
+<servs biz="jw">
+	<serv name="xjbFjry_save" desc="保存风纪仪容日登记"
+		  clazz="biz.bj.XjbFjryServ" func="saveByA"/>
+	<serv name="xjbFjry_list" desc="查询风纪仪容日登记"
+		  clazz="biz.bj.XjbFjryServ" func="listByA"/>
+</servs>

+ 9 - 0
web/cfg/biz/bj/xjbMonth.serv.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE xml>
+
+<servs biz="jw">
+	<serv name="xjbMonth_close" desc="生成部门星级班月结"
+		  clazz="biz.bj.XjbMonthCloseServ" func="closeByA"/>
+	<serv name="xjbMonth_pcSummary" desc="PC星级班月结报表"
+		  clazz="biz.bj.XjbMonthCloseServ" func="pcSummaryByA"/>
+</servs>

+ 160 - 310
web/page/biz/ssnwjc_starClassSummary.jsp

@@ -12,7 +12,6 @@
             font-family: "Microsoft YaHei", sans-serif;
             font-size: 14px;
         }
-
         .query-area {
             margin: 0 0 20px;
             padding: 15px;
@@ -20,106 +19,66 @@
             border-radius: 4px;
             background-color: #f8f9fa;
         }
-
         .query-item {
             display: inline-block;
             margin-right: 20px;
             margin-bottom: 10px;
         }
-
         .query-item label {
             margin-right: 5px;
             font-weight: bold;
         }
-
-        .query-btn,
-        .export-btn,
-        .reset-btn {
+        .query-btn, .export-btn, .reset-btn {
             padding: 6px 15px;
             border: none;
             border-radius: 4px;
             color: #fff;
             cursor: pointer;
         }
-
-        .query-btn {
-            background-color: #007bff;
-        }
-
-        .export-btn {
-            margin-left: 10px;
-            background-color: #28a745;
-        }
-
-        .reset-btn {
-            margin-left: 10px;
-            background-color: #dc3545;
-        }
-
-        select,
-        input[type="month"] {
+        .query-btn { background-color: #007bff; }
+        .export-btn { margin-left: 10px; background-color: #28a745; }
+        .reset-btn { margin-left: 10px; background-color: #dc3545; }
+        select, input[type="month"] {
             width: 150px;
             padding: 6px;
             border: 1px solid #ced4da;
             border-radius: 4px;
             background: #fff;
         }
-
         .report-title {
             margin: 20px 0;
             text-align: center;
             font-size: 20px;
             font-weight: bold;
         }
-
         .report-info {
             margin: -8px 0 12px;
             text-align: right;
             color: #555;
             font-size: 13px;
         }
-
-        .report-info span {
-            margin-left: 14px;
-        }
-
+        .report-info span { margin-left: 14px; }
         table {
             width: 100%;
             border-collapse: collapse;
             font-size: 9pt;
         }
-
-        table,
-        th,
-        td {
-            border: 1px solid #000;
-        }
-
-        th,
-        td {
+        table, th, td { border: 1px solid #000; }
+        th, td {
             padding: 6px 5px;
             text-align: center;
             white-space: nowrap;
         }
-
         th {
             background-color: #f2f2f2;
             font-weight: bold;
         }
-
-        tbody tr:hover {
-            background-color: #f7fbff;
-        }
-
-        .total-cell {
-            font-weight: bold;
-        }
-
+        tbody tr:hover { background-color: #f7fbff; }
+        .total-cell { font-weight: bold; }
         .empty-row td {
             padding: 40px 10px;
             color: #777;
         }
-
         .table-footer {
             margin-top: 10px;
             color: #666;
@@ -132,37 +91,26 @@
 <div class="query-area">
     <div class="query-item">
         <label for="departmentFilter">院系:</label>
-        <select id="departmentFilter">
-            <option value="">全部院系</option>
-        </select>
+        <select id="departmentFilter"><option value="">全部院系</option></select>
     </div>
     <div class="query-item">
         <label for="majorFilter">专业:</label>
-        <select id="majorFilter">
-            <option value="">全部专业</option>
-        </select>
+        <select id="majorFilter"><option value="">全部专业</option></select>
     </div>
     <div class="query-item">
         <label for="classFilter">班级:</label>
-        <select id="classFilter">
-            <option value="">全部班级</option>
-        </select>
+        <select id="classFilter"><option value="">全部班级</option></select>
     </div>
     <div class="query-item">
         <label for="starFilter">星级:</label>
-        <select id="starFilter">
-            <option value="">全部星级</option>
-            <option value="五星级">五星级</option>
-            <option value="四星级">四星级</option>
-            <option value="三星级">三星级</option>
-        </select>
+        <select id="starFilter"><option value="">全部星级</option></select>
     </div>
     <div class="query-item">
         <label for="monthFilter">月份:</label>
         <input type="month" id="monthFilter">
     </div>
     <button type="button" class="query-btn" id="searchButton">搜索</button>
-    <button type="button" class="export-btn" id="exportButton">导出Excel</button>
+    <button type="button" class="export-btn" id="exportButton">导出CSV</button>
     <button type="button" class="reset-btn" id="resetButton">清空</button>
 </div>
 
@@ -171,7 +119,7 @@
     <span>名称:星级文明班级评比总表</span>
     <span>年份:<b id="yearText">-</b></span>
     <span>月份:<b id="monthText">-</b></span>
-    <span>状态:<b id="statusText">演示数据</b></span>
+    <span>状态:<b id="statusText">加载中</b></span>
 </div>
 
 <table>
@@ -199,7 +147,7 @@
 </table>
 
 <div class="table-footer">
-    <span id="filterSummary">当前显示当前月份全部演示数据</span>
+    <span id="filterSummary">当前显示全部已发布班级</span>
     ,共 <b id="resultCount">0</b> 条
 </div>
 
@@ -207,99 +155,8 @@
     (function () {
         "use strict";
 
-        const DEMO_ROWS = [
-            {
-                month: "2026-10",
-                department: "现代服务部",
-                major: "会计",
-                className: "25会计2",
-                dormScore: "89.41",
-                classroomScore: "100.0",
-                flagCeremonyScore: "72.0",
-                cleaningScore: "100.0",
-                disciplineScore: "100.0",
-                attendanceScore: "100.0",
-                bonus: "7.5",
-                deduction: "0.0",
-                monthTotal: "93.46",
-                starLevel: "五星级",
-                departmentRank: "1",
-                schoolRank: "1"
-            },
-            {
-                month: "2026-10",
-                department: "服装技术部",
-                major: "服装陈列",
-                className: "25服5",
-                dormScore: "86.36",
-                classroomScore: "100.0",
-                flagCeremonyScore: "66.0",
-                cleaningScore: "100.0",
-                disciplineScore: "100.0",
-                attendanceScore: "100.0",
-                bonus: "7.0",
-                deduction: "0.0",
-                monthTotal: "91.51",
-                starLevel: "五星级",
-                departmentRank: "1",
-                schoolRank: "2"
-            },
-            {
-                month: "2026-10",
-                department: "智能制造部",
-                major: "数控技术应用",
-                className: "24数控1",
-                dormScore: "85.20",
-                classroomScore: "98.0",
-                flagCeremonyScore: "70.0",
-                cleaningScore: "100.0",
-                disciplineScore: "100.0",
-                attendanceScore: "100.0",
-                bonus: "6.5",
-                deduction: "1.0",
-                monthTotal: "88.70",
-                starLevel: "四星级",
-                departmentRank: "2",
-                schoolRank: "4"
-            },
-            {
-                month: "2026-09",
-                department: "现代服务部",
-                major: "电子商务",
-                className: "24电商1",
-                dormScore: "88.10",
-                classroomScore: "99.0",
-                flagCeremonyScore: "74.0",
-                cleaningScore: "100.0",
-                disciplineScore: "100.0",
-                attendanceScore: "100.0",
-                bonus: "7.2",
-                deduction: "0.0",
-                monthTotal: "92.80",
-                starLevel: "五星级",
-                departmentRank: "1",
-                schoolRank: "2"
-            },
-            {
-                month: "2026-09",
-                department: "服装技术部",
-                major: "服装设计与工艺",
-                className: "24服2",
-                dormScore: "84.75",
-                classroomScore: "98.0",
-                flagCeremonyScore: "68.0",
-                cleaningScore: "100.0",
-                disciplineScore: "100.0",
-                attendanceScore: "99.0",
-                bonus: "6.8",
-                deduction: "0.5",
-                monthTotal: "87.42",
-                starLevel: "四星级",
-                departmentRank: "1",
-                schoolRank: "5"
-            }
-        ];
-
+        let report = null;
+        let rows = [];
         const yearText = document.getElementById("yearText");
         const monthText = document.getElementById("monthText");
         const statusText = document.getElementById("statusText");
@@ -312,195 +169,188 @@
         const starFilter = document.getElementById("starFilter");
         const monthFilter = document.getElementById("monthFilter");
 
-        function getCurrentMonth() {
-            const now = new Date();
-            return now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0");
-        }
-
-        function uniqueValues(field) {
-            return Array.from(new Set(DEMO_ROWS.map(function (row) {
-                return row[field];
-            }).filter(Boolean))).sort(function (a, b) {
-                return a.localeCompare(b, "zh-CN");
-            });
-        }
-
-        function fillSelect(select, placeholder, values, selectedValue) {
+        function fillSelect(select, placeholder, values) {
+            const selected = select.value;
             select.innerHTML = "";
             const defaultOption = document.createElement("option");
             defaultOption.value = "";
             defaultOption.textContent = placeholder;
             select.appendChild(defaultOption);
-
-            values.forEach(function (value) {
+            (values || []).forEach(function (value) {
                 const option = document.createElement("option");
                 option.value = value;
                 option.textContent = value;
                 select.appendChild(option);
             });
-            select.value = selectedValue || "";
+            select.value = selected || "";
         }
 
-        function initializeFilters() {
-            fillSelect(departmentFilter, "全部院系", uniqueValues("department"));
-            fillSelect(majorFilter, "全部专业", uniqueValues("major"));
-            fillSelect(classFilter, "全部班级", uniqueValues("className"));
-        }
-
-        function refreshMajorOptions() {
-            const department = departmentFilter.value;
-            const rows = department
-                ? DEMO_ROWS.filter(function (row) { return row.department === department; })
-                : DEMO_ROWS;
-            const previousMajor = majorFilter.value;
-            fillSelect(majorFilter, "全部专业", Array.from(new Set(rows.map(function (row) {
-                return row.major;
-            }))).sort(function (a, b) {
-                return a.localeCompare(b, "zh-CN");
-            }), previousMajor);
-            refreshClassOptions();
-        }
-
-        function refreshClassOptions() {
-            const rows = DEMO_ROWS.filter(function (row) {
-                return (!departmentFilter.value || row.department === departmentFilter.value)
-                    && (!majorFilter.value || row.major === majorFilter.value);
-            });
-            const previousClass = classFilter.value;
-            fillSelect(classFilter, "全部班级", Array.from(new Set(rows.map(function (row) {
-                return row.className;
-            }))).sort(function (a, b) {
-                return a.localeCompare(b, "zh-CN");
-            }), previousClass);
+        function createCell(value, className) {
+            const cell = document.createElement("td");
+            cell.textContent = value == null || value === "" ? "-" : value;
+            if (className)
+                cell.className = className;
+            return cell;
         }
 
-        function filterRows() {
-            return DEMO_ROWS.filter(function (row) {
-                return (!monthFilter.value || row.month === monthFilter.value)
-                    && (!departmentFilter.value || row.department === departmentFilter.value)
+        function filteredRows() {
+            return rows.filter(function (row) {
+                return (!departmentFilter.value
+                        || row.department === departmentFilter.value)
                     && (!majorFilter.value || row.major === majorFilter.value)
                     && (!classFilter.value || row.className === classFilter.value)
                     && (!starFilter.value || row.starLevel === starFilter.value);
             }).sort(function (a, b) {
-                if (a.month !== b.month) {
-                    return b.month.localeCompare(a.month);
-                }
-                return Number(a.schoolRank) - Number(b.schoolRank);
+                return Number(a.schoolRank || 9999)
+                    - Number(b.schoolRank || 9999);
             });
         }
 
-        function createCell(value, className) {
-            const cell = document.createElement("td");
-            cell.textContent = value == null || value === "" ? "-" : value;
-            if (className) {
-                cell.className = className;
-            }
-            return cell;
-        }
-
-        function renderRows(rows) {
+        function render(currentRows) {
             reportBody.innerHTML = "";
-            if (!rows.length) {
+            if (!currentRows.length) {
                 const emptyRow = document.createElement("tr");
                 emptyRow.className = "empty-row";
-                const emptyCell = document.createElement("td");
-                emptyCell.colSpan = 16;
-                emptyCell.textContent = "暂无数据";
-                emptyRow.appendChild(emptyCell);
+                const cell = document.createElement("td");
+                cell.colSpan = 16;
+                cell.textContent = "暂无已发布月结数据";
+                emptyRow.appendChild(cell);
                 reportBody.appendChild(emptyRow);
-                return;
+            } else {
+                currentRows.forEach(function (row, index) {
+                    const tr = document.createElement("tr");
+                    tr.appendChild(createCell(String(index + 1)));
+                    tr.appendChild(createCell(row.department));
+                    tr.appendChild(createCell(row.major));
+                    tr.appendChild(createCell(row.className));
+                    tr.appendChild(createCell(row.dormScore));
+                    tr.appendChild(createCell(row.classroomScore));
+                    tr.appendChild(createCell(row.flagCeremonyScore));
+                    tr.appendChild(createCell(row.cleaningScore));
+                    tr.appendChild(createCell(row.disciplineScore));
+                    tr.appendChild(createCell(row.attendanceScore));
+                    tr.appendChild(createCell(row.bonus));
+                    tr.appendChild(createCell(row.deduction));
+                    tr.appendChild(createCell(row.monthTotal, "total-cell"));
+                    tr.appendChild(createCell(row.starLevel));
+                    tr.appendChild(createCell(row.departmentRank));
+                    tr.appendChild(createCell(row.schoolRank));
+                    reportBody.appendChild(tr);
+                });
             }
-
-            rows.forEach(function (row, index) {
-                const tr = document.createElement("tr");
-                tr.appendChild(createCell(String(index + 1)));
-                tr.appendChild(createCell(row.department));
-                tr.appendChild(createCell(row.major));
-                tr.appendChild(createCell(row.className));
-                tr.appendChild(createCell(row.dormScore));
-                tr.appendChild(createCell(row.classroomScore));
-                tr.appendChild(createCell(row.flagCeremonyScore));
-                tr.appendChild(createCell(row.cleaningScore));
-                tr.appendChild(createCell(row.disciplineScore));
-                tr.appendChild(createCell(row.attendanceScore));
-                tr.appendChild(createCell(row.bonus));
-                tr.appendChild(createCell(row.deduction));
-                tr.appendChild(createCell(row.monthTotal, "total-cell"));
-                tr.appendChild(createCell(row.starLevel));
-                tr.appendChild(createCell(row.departmentRank));
-                tr.appendChild(createCell(row.schoolRank));
-                reportBody.appendChild(tr);
-            });
-        }
-
-        function updateInfo(rows) {
-            const parts = monthFilter.value.split("-");
-            yearText.textContent = parts[0] || "-";
-            monthText.textContent = parts[1] ? String(Number(parts[1])) : "-";
-            statusText.textContent = "演示数据";
-            resultCount.textContent = String(rows.length);
-
-            const selectedFilters = [
+            resultCount.textContent = String(currentRows.length);
+            const filters = [
                 departmentFilter.value,
                 majorFilter.value,
                 classFilter.value,
                 starFilter.value
             ].filter(Boolean);
-            filterSummary.textContent = selectedFilters.length
-                ? "筛选条件:" + selectedFilters.join(" / ")
-                : "当前显示当前月份全部演示数据";
-        }
-
-        function validateMonth() {
-            const currentMonth = getCurrentMonth();
-            if (!monthFilter.value) {
-                monthFilter.value = currentMonth;
-            }
-            if (monthFilter.value > currentMonth) {
-                window.alert("不能查询未来月份,已恢复为当前月份。");
-                monthFilter.value = currentMonth;
-            }
+            filterSummary.textContent = filters.length
+                ? "筛选条件:" + filters.join(" / ")
+                : "当前显示全部已发布班级";
         }
 
-        function executeSearch() {
-            validateMonth();
-            const rows = filterRows();
-            renderRows(rows);
-            updateInfo(rows);
+        function applyReport(data) {
+            report = data;
+            rows = data.rows || [];
+            monthFilter.value = data.month || "";
+            const parts = monthFilter.value.split("-");
+            yearText.textContent = parts[0] || "-";
+            monthText.textContent = parts[1]
+                ? String(Number(parts[1])) : "-";
+            statusText.textContent = data.status || "已发布";
+            fillSelect(departmentFilter, "全部院系", data.departments);
+            fillSelect(majorFilter, "全部专业", data.majors);
+            fillSelect(classFilter, "全部班级", data.classes);
+            fillSelect(starFilter, "全部星级", data.stars);
+            render(filteredRows());
+        }
+
+        async function loadReport() {
+            const body = new URLSearchParams();
+            if (monthFilter.value)
+                body.set("month", monthFilter.value);
+            const response = await fetch(
+                "/service?ssServ=xjbMonth_pcSummary&ssDest=data",
+                {
+                    method: "POST",
+                    credentials: "same-origin",
+                    headers: {
+                        "Content-Type": "application/x-www-form-urlencoded"
+                    },
+                    body: body.toString()
+                }
+            );
+            const result = await response.json();
+            if (result.ssCode !== 0)
+                throw new Error(result.ssMsg || "月结报表加载失败");
+            applyReport(result.ssData);
         }
 
         function resetFilters() {
             departmentFilter.value = "";
-            fillSelect(majorFilter, "全部专业", uniqueValues("major"));
-            fillSelect(classFilter, "全部班级", uniqueValues("className"));
-            starFilter.value = "";
-            monthFilter.value = getCurrentMonth();
-            executeSearch();
-        }
-
-        departmentFilter.addEventListener("change", function () {
             majorFilter.value = "";
             classFilter.value = "";
-            refreshMajorOptions();
-        });
-
-        majorFilter.addEventListener("change", function () {
-            classFilter.value = "";
-            refreshClassOptions();
-        });
+            starFilter.value = "";
+            if (report && report.month)
+                monthFilter.value = report.month;
+            render(filteredRows());
+        }
+
+        function exportCsv() {
+            const currentRows = filteredRows();
+            const lines = [[
+                "序号", "院系", "专业", "班级", "宿舍评分", "课堂考核",
+                "升旗礼", "清洁卫生", "风纪仪容", "考勤", "增分", "减分",
+                "月份合计", "星级", "部门排名", "全校排名"
+            ]];
+            currentRows.forEach(function (row, index) {
+                lines.push([
+                    index + 1, row.department, row.major, row.className,
+                    row.dormScore, row.classroomScore,
+                    row.flagCeremonyScore, row.cleaningScore,
+                    row.disciplineScore, row.attendanceScore, row.bonus,
+                    row.deduction, row.monthTotal, row.starLevel,
+                    row.departmentRank, row.schoolRank
+                ]);
+            });
+            const csv = "\uFEFF" + lines.map(function (line) {
+                return line.map(function (value) {
+                    return '"' + String(value == null ? "" : value)
+                        .replace(/"/g, '""') + '"';
+                }).join(",");
+            }).join("\r\n");
+            const blob = new Blob([csv], { type: "text/csv;charset=utf-8" });
+            const link = document.createElement("a");
+            link.href = URL.createObjectURL(blob);
+            link.download = "星级文明班级评比总表_"
+                + (monthFilter.value || "latest") + ".csv";
+            link.click();
+            URL.revokeObjectURL(link.href);
+        }
+
+        document.getElementById("searchButton").addEventListener(
+            "click", function () {
+                loadReport().catch(function (error) {
+                    window.alert(error.message);
+                });
+            });
+        document.getElementById("resetButton").addEventListener(
+            "click", resetFilters);
+        document.getElementById("exportButton").addEventListener(
+            "click", exportCsv);
+        [departmentFilter, majorFilter, classFilter, starFilter].forEach(
+            function (select) {
+                select.addEventListener("change", function () {
+                    render(filteredRows());
+                });
+            });
 
-        document.getElementById("searchButton").addEventListener("click", executeSearch);
-        document.getElementById("resetButton").addEventListener("click", resetFilters);
-        document.getElementById("exportButton").addEventListener("click", function () {
-            window.alert("当前为演示数据,真实数据接入后再开放导出功能。");
+        loadReport().catch(function (error) {
+            statusText.textContent = "加载失败";
+            render([]);
+            window.alert(error.message);
         });
-        monthFilter.addEventListener("change", validateMonth);
-
-        const currentMonth = getCurrentMonth();
-        monthFilter.max = currentMonth;
-        monthFilter.value = currentMonth;
-        initializeFilters();
-        executeSearch();
     }());
 </script>
 </body>