Procházet zdrojové kódy

feat(starclass): add full report drill-down

harper před 3 týdny
rodič
revize
c1c842d8a5

+ 449 - 80
src/biz/bj/BjStarClassMpServ.java

@@ -249,6 +249,20 @@ public class BjStarClassMpServ extends Serv {
      */
     @SuppressWarnings("unused")
     public void detailByA() throws Exception {
+        writeDetailResponse(false);
+    }
+
+
+    /**
+     * PC 已发布月结报表的明细下钻入口。
+     */
+    @SuppressWarnings("unused")
+    public void pcDetailByA() throws Exception {
+        writeDetailResponse(true);
+    }
+
+
+    private void writeDetailResponse(boolean pcReport) throws Exception {
         HttpServletRequest request = super.req;
         prepareJson();
         Writer writer = super.resp.getWriter();
@@ -256,98 +270,125 @@ public class BjStarClassMpServ extends Serv {
 
         try (Db db = Db.makeConn()) {
             UserRunB user = requireUser(request);
-            ClassInfo selected = requireTeacherClass(db, user.ryid,
+            ClassInfo selected = pcReport
+                    ? requireReportClass(db,
+                    rdLongParam(request, "bjid", true),
+                    rdLongParam(request, "jdid", true))
+                    : requireTeacherClass(db, user.ryid,
                     rdLongParam(request, "bjid", false));
-            String mode = StringUtils.defaultIfBlank(
-                    request.getParameter("mode"), "dayItem");
-
-            if ("trace".equals(mode)) {
-                LocalDate day = rdDate(request, "date");
-                if (day.isAfter(LocalDate.now(CN_ZONE)))
-                    throw new IllegalArgumentException("不能查询未来日期");
-                String categoryCode = StringUtils.trimToNull(
-                        request.getParameter("category"));
-                CategoryDef category = requireCategory(categoryCode);
-                long sourceId = rdLongParam(request, "id", true);
-                String source = StringUtils.defaultIfBlank(
-                        request.getParameter("source"), SOURCE_REAL);
-                Map<String, Object> trace = rdTraceDetail(db, selected, day,
-                        category, sourceId, source);
-                ServU.wrOkDataByWriter(trace, writer, gson);
-                return;
-            }
-
-            int pageNo = Math.max(1, rdIntParam(request, "pageNo", 1));
-            int pageSize = clampPageSize(rdIntParam(request, "pageSize",
-                    DETAIL_PAGE_SIZE));
-
-            List<Map<String, Object>> rows;
-            String title;
-            String monthText = null;
-            String dateText = null;
-            String categoryCode = null;
-
-            if ("bonus".equals(mode) || "deduction".equals(mode)) {
-                YearMonth month = rdMonth(request);
-                MonthPeriod period = MonthPeriod.of(month);
-                List<Adjustment> adjustments = rdAdjustments(
-                        db, selected.bjid, month);
-                List<Adjustment> selectedAdjustments = new ArrayList<>();
-                for (Adjustment item : adjustments) {
-                    if ((("bonus".equals(mode) && item.score > 0)
-                            || ("deduction".equals(mode) && item.score < 0)))
-                        selectedAdjustments.add(item);
-                }
-                selectedAdjustments.sort(Comparator
-                        .comparing((Adjustment item) -> item.date).reversed()
-                        .thenComparingLong(item -> item.id).reversed());
-                rows = rdAdjustmentRows(selectedAdjustments);
-                title = "bonus".equals(mode) ? "当月增分明细" : "当月减分明细";
-                monthText = month.format(MONTH_FMT);
-            } else if ("dayItem".equals(mode)) {
-                LocalDate day = rdDate(request, "date");
-                if (day.isAfter(LocalDate.now(CN_ZONE)))
-                    throw new IllegalArgumentException("不能查询未来日期");
-                categoryCode = StringUtils.trimToNull(request.getParameter("category"));
-                CategoryDef category = requireCategory(categoryCode);
-                YearMonth month = YearMonth.from(day);
-                MonthPeriod period = MonthPeriod.of(month);
-                rows = rdDayDetail(db, selected, day, period, category);
-                title = category.label + " · " + day.format(DATE_FMT);
-                dateText = day.format(DATE_FMT);
-            } else {
-                throw new IllegalArgumentException("明细模式参数错误");
-            }
-
-            int from = Math.min(rows.size(), (pageNo - 1) * pageSize);
-            int to = Math.min(rows.size(), from + pageSize);
-            List<Map<String, Object>> pageRows = rows.subList(from, to);
-
-            Map<String, Object> data = new LinkedHashMap<>();
-            data.put("bjid", selected.bjid);
-            data.put("bjmc", selected.bjmc);
-            data.put("mode", mode);
-            data.put("title", title);
-            data.put("month", monthText);
-            data.put("date", dateText);
-            data.put("category", categoryCode);
-            data.put("pageNo", pageNo);
-            data.put("pageSize", pageSize);
-            data.put("total", rows.size());
-            data.put("hasMore", to < rows.size());
-            data.put("list", pageRows);
+            Map<String, Object> data = buildDetailData(db, selected,
+                    request);
             ServU.wrOkDataByWriter(data, writer, gson);
         } catch (DateTimeParseException e) {
             ServU.wrErrMsgByWriter(null, "日期格式错误", writer, gson);
         } catch (IllegalArgumentException e) {
             ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
         } catch (Exception e) {
-            log4j.error("BjStarClassMpServ.detailByA() 异常", e);
+            log4j.error("BjStarClassMpServ.writeDetailResponse() 异常,"
+                    + "pcReport=" + pcReport, e);
             ServU.wrErrMsgByWriter(null, "星级班明细加载失败", writer, gson);
         }
     }
 
 
+    private static Map<String, Object> buildDetailData(
+            Db db, ClassInfo selected, HttpServletRequest request)
+            throws Exception {
+        String mode = StringUtils.defaultIfBlank(
+                request.getParameter("mode"), "dayItem");
+
+        if ("trace".equals(mode)) {
+            String kind = StringUtils.defaultIfBlank(
+                    request.getParameter("kind"), "regular");
+            long recordId = rdLongParam(request, "id", true);
+            if ("adjustment".equals(kind))
+                return rdAdjustmentTrace(db, selected, recordId);
+            LocalDate day = rdDate(request, "date");
+            if (day.isAfter(LocalDate.now(CN_ZONE)))
+                throw new IllegalArgumentException("不能查询未来日期");
+            CategoryDef category = requireCategory(StringUtils.trimToNull(
+                    request.getParameter("category")));
+            String source = StringUtils.defaultIfBlank(
+                    request.getParameter("source"), SOURCE_REAL);
+            return rdTraceDetail(db, selected, day, category, recordId,
+                    source);
+        }
+
+        int pageNo = Math.max(1, rdIntParam(request, "pageNo", 1));
+        int pageSize = clampPageSize(rdIntParam(request, "pageSize",
+                DETAIL_PAGE_SIZE));
+        List<Map<String, Object>> rows;
+        String title;
+        String monthText = null;
+        String dateText = null;
+        String categoryCode = null;
+
+        if ("bonus".equals(mode) || "deduction".equals(mode)) {
+            YearMonth month = rdMonth(request);
+            List<Adjustment> adjustments = rdAdjustments(
+                    db, selected.bjid, month);
+            List<Adjustment> selectedAdjustments = new ArrayList<>();
+            for (Adjustment item : adjustments) {
+                if ((("bonus".equals(mode) && item.score > 0)
+                        || ("deduction".equals(mode) && item.score < 0)))
+                    selectedAdjustments.add(item);
+            }
+            selectedAdjustments.sort(Comparator
+                    .comparing((Adjustment item) -> item.date).reversed()
+                    .thenComparingLong(item -> item.id).reversed());
+            rows = rdAdjustmentRows(selectedAdjustments);
+            title = "bonus".equals(mode) ? "当月增分明细" : "当月减分明细";
+            monthText = month.format(MONTH_FMT);
+        } else if ("monthCategory".equals(mode)) {
+            YearMonth month = rdMonth(request);
+            categoryCode = StringUtils.trimToNull(
+                    request.getParameter("category"));
+            CategoryDef category = requireCategory(categoryCode);
+            MonthPeriod period = MonthPeriod.of(month);
+            rows = rdMonthCategoryRows(db, selected, period, category);
+            title = category.label + " · " + month.format(MONTH_FMT);
+            monthText = month.format(MONTH_FMT);
+        } else if ("dayItem".equals(mode)) {
+            LocalDate day = rdDate(request, "date");
+            if (day.isAfter(LocalDate.now(CN_ZONE)))
+                throw new IllegalArgumentException("不能查询未来日期");
+            categoryCode = StringUtils.trimToNull(
+                    request.getParameter("category"));
+            CategoryDef category = requireCategory(categoryCode);
+            YearMonth month = YearMonth.from(day);
+            MonthPeriod period = MonthPeriod.of(month);
+            rows = rdDayDetail(db, selected, day, period, category);
+            for (Map<String, Object> row : rows) {
+                row.put("detailKind", "regular");
+                if (!row.containsKey("sourceType"))
+                    row.put("sourceType", category.code);
+            }
+            title = category.label + " · " + day.format(DATE_FMT);
+            dateText = day.format(DATE_FMT);
+        } else {
+            throw new IllegalArgumentException("明细模式参数错误");
+        }
+
+        int from = Math.min(rows.size(), (pageNo - 1) * pageSize);
+        int to = Math.min(rows.size(), from + pageSize);
+        List<Map<String, Object>> pageRows = rows.subList(from, to);
+        Map<String, Object> data = new LinkedHashMap<>();
+        data.put("bjid", selected.bjid);
+        data.put("bjmc", selected.bjmc);
+        data.put("mode", mode);
+        data.put("title", title);
+        data.put("month", monthText);
+        data.put("date", dateText);
+        data.put("category", categoryCode);
+        data.put("pageNo", pageNo);
+        data.put("pageSize", pageSize);
+        data.put("total", rows.size());
+        data.put("hasMore", to < rows.size());
+        data.put("list", pageRows);
+        return data;
+    }
+
+
     private void prepareJson() throws Exception {
         super.resp.setCharacterEncoding("UTF-8");
         super.resp.setContentType("application/json;charset=UTF-8");
@@ -411,6 +452,35 @@ public class BjStarClassMpServ extends Serv {
     }
 
 
+    private static ClassInfo requireReportClass(Db db, long bjid, long jdid)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select b.BJID,b.MC,z.FZBMID DWID,nvl(bm.MC,'') DWMC"
+                        + " from BJ b inner join ZY z on z.ZYID=b.ZYID"
+                        + " left join BM bm on bm.BMID=z.FZBMID"
+                        + " where b.BJID=:bjid and b." + ObjC.JLZT_useStr
+                        + " and b.BJZTM!=81");
+        sqlc.wrLongParm("bjid", bjid);
+        List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
+        if (rows == null || rows.isEmpty())
+            throw new IllegalArgumentException("班级不存在或已停用");
+
+        if (jdid > 0) {
+            SqlCmd check = new SqlCmd(
+                    "select count(*) CNT from XJB_JG g"
+                            + " inner join XJB_JD d on d.XJB_JDID=g.XJB_JDID"
+                            + " where g.XJB_JDID=:jdid and g.BJID=:bjid"
+                            + " and g.ZT=5 and d.ZT=5");
+            check.wrLongParm("jdid", jdid);
+            check.wrLongParm("bjid", bjid);
+            db.doSelByC(check);
+            if (db.rowNum == 0 || db.rdIntCol("cnt") == 0)
+                throw new IllegalArgumentException("该班级不属于当前已发布月结");
+        }
+        return rdClasses(rows).get(0);
+    }
+
+
     private static ScoreBook rdScoreBook(Db db, List<ClassInfo> classes,
                                          MonthPeriod period) throws Exception {
         ScoreBook book = new ScoreBook();
@@ -1028,6 +1098,42 @@ public class BjStarClassMpServ extends Serv {
     }
 
 
+    private static List<Map<String, Object>> rdMonthCategoryRows(
+            Db db, ClassInfo cls, MonthPeriod period, CategoryDef category)
+            throws Exception {
+        CategoryDaily monthly = rdCategoryDaily(db, cls, null, period);
+        String source = monthly.sources.getOrDefault(
+                category.code, SOURCE_MISSING);
+        Map<LocalDate, DailyPoint> points = monthly.actual.get(category.code);
+        List<Map<String, Object>> rows = new ArrayList<>();
+        if (SOURCE_REAL.equals(source) && points != null) {
+            for (DailyPoint point : points.values()) {
+                double deduction = round2(
+                        Math.max(0.0, 100.0 - point.score));
+                Map<String, Object> row = baseDetail(point.date, SOURCE_REAL);
+                row.put("id", point.date.format(DATE_FMT));
+                row.put("sourceId", point.date.format(DATE_FMT));
+                row.put("sourceType", category.code);
+                row.put("detailKind", "regular");
+                row.put("category", category.code);
+                row.put("itemName", category.label);
+                row.put("weekday", weekdayCn(point.date));
+                row.put("score", round2(point.score));
+                row.put("deduction", deduction);
+                row.put("delta", -deduction);
+                row.put("count", point.count);
+                row.put("traceable", true);
+                row.put("sortTime", point.date.format(DATE_FMT));
+                rows.add(row);
+            }
+        }
+        rows.sort(Comparator.comparing(
+                (Map<String, Object> row) -> String.valueOf(
+                        row.getOrDefault("sortTime", ""))).reversed());
+        return rows;
+    }
+
+
     private static List<Map<String, Object>> rdDayDetail(
             Db db, ClassInfo cls, LocalDate day, MonthPeriod period,
             CategoryDef category) throws Exception {
@@ -1610,6 +1716,266 @@ public class BjStarClassMpServ extends Serv {
     }
 
 
+    private static Map<String, Object> rdAdjustmentTrace(
+            Db db, ClassInfo cls, long ledgerId) throws Exception {
+        SqlCmd ledgerCmd = new SqlCmd(
+                "select j.XJB_JFJLID,j.NDY,j.FSSJ,j.JFLX,j.JFZ,j.MC,j.MS,"
+                        + "j.LYLX,j.LYID,j.LYLB,j.RYID,r.XM RYXM"
+                        + " from XJB_JFJL j left join RY r on r.RYID=j.RYID"
+                        + " where j.XJB_JFJLID=:id and j.BJID=:bjid"
+                        + " and j.JLZTM=51");
+        ledgerCmd.wrLongParm("id", ledgerId);
+        ledgerCmd.wrLongParm("bjid", cls.bjid);
+        List<Map<String, Object>> ledgerRows =
+                db.doSelMapListByC(ledgerCmd);
+        if (ledgerRows == null || ledgerRows.isEmpty())
+            throw new IllegalArgumentException("增扣分记录不存在或已不可查看");
+        Map<String, Object> ledger = ledgerRows.get(0);
+        String sourceType = defaultText(ledger.get("lylx"), "");
+        long sourceId = rdLong(ledger.get("lyid"));
+        if (XjbJfServ.LYLX_AWARD.equals(sourceType))
+            return rdAwardAdjustmentTrace(db, cls, ledger, sourceId);
+        if (XjbJfServ.LYLX_SCHOOL_VIOLATION.equals(sourceType))
+            return rdViolationAdjustmentTrace(db, cls, ledger, sourceId);
+        if (XjbJfServ.LYLX_TEAM_ROLE.equals(sourceType)
+                || XjbJfServ.LYLX_TEAM_MEMBER.equals(sourceType))
+            return rdTeamAdjustmentTrace(db, cls, ledger, sourceType,
+                    sourceId);
+        if (XjbJfServ.LYLX_MONTH_SAFE.equals(sourceType)
+                || XjbJfServ.LYLX_FJ_SAFE.equals(sourceType))
+            return rdRuleAdjustmentTrace(cls, ledger, sourceType);
+        return rdLedgerOnlyTrace(cls, ledger, sourceType);
+    }
+
+
+    private static Map<String, Object> rdAwardAdjustmentTrace(
+            Db db, ClassInfo cls, Map<String, Object> ledger, long sourceId)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select h.HJJLID,h.HJXZ,h.HJRQ,h.MS,h.MC,h.HJLBM,"
+                        + "l.MC LBMC,l.BJJF,l.JTBJJF,r.XM RYXM"
+                        + " from HJJL h inner join HJLB l on l.HJLBM=h.HJLBM"
+                        + " left join RY r on r.RYID=h.RYID"
+                        + " where h.HJJLID=:id and h.JLZTM=51");
+        sqlc.wrLongParm("id", sourceId);
+        List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
+        if (rows == null || rows.isEmpty())
+            return rdLedgerOnlyTrace(cls, ledger,
+                    XjbJfServ.LYLX_AWARD);
+        Map<String, Object> row = rows.get(0);
+        int awardType = rdInt(row.get("hjxz"));
+        String awardTypeText = awardType == 2 ? "集体获奖" : "个人获奖";
+        Map<String, Object> record = adjustmentRecord(cls, ledger,
+                "学校获奖", row.get("ryxm"));
+        record.put("awardNature", awardTypeText);
+        record.put("awardCategory", rdStr(row.get("lbmc")));
+        record.put("description", defaultText(row.get("ms"),
+                defaultText(row.get("mc"), "")));
+
+        List<Map<String, Object>> items = new ArrayList<>();
+        if (awardType == 2) {
+            SqlCmd memberCmd = new SqlCmd(
+                    "select c.RYID,r.XM,b.MC BJMC from HJJLCY c"
+                            + " left join RY r on r.RYID=c.RYID"
+                            + " left join BJ b on b.BJID=c.BJID"
+                            + " where c.HJJLID=:id and c.JLZTM=51"
+                            + " order by c.BJID,c.RYID");
+            memberCmd.wrLongParm("id", sourceId);
+            List<Map<String, Object>> members =
+                    db.doSelMapListByC(memberCmd);
+            for (Map<String, Object> member : members) {
+                Map<String, Object> item = new LinkedHashMap<>();
+                item.put("itemName", "参与学生");
+                item.put("studentName", defaultText(member.get("xm"), ""));
+                item.put("className", defaultText(member.get("bjmc"), ""));
+                item.put("remark", "集体获奖参与学生");
+                items.add(item);
+            }
+        }
+        Map<String, Object> main = adjustmentItem(ledger,
+                defaultText(row.get("lbmc"), awardTypeText),
+                defaultText(row.get("ms"), ""));
+        items.add(0, main);
+        return adjustmentTraceResult(cls, ledger, sourceId,
+                XjbJfServ.LYLX_AWARD, awardTypeText + "增分详情",
+                record, items, "");
+    }
+
+
+    private static Map<String, Object> rdViolationAdjustmentTrace(
+            Db db, ClassInfo cls, Map<String, Object> ledger, long sourceId)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select w.WJJLID,w.WJSJ,w.MS,w.WJLBM,lb.MC WJLBMC,"
+                        + "lb.BJKF,ry.XM RYXM,cj.XM CJRYXM"
+                        + " from WJJL w left join WJLB lb on lb.WJLBM=w.WJLBM"
+                        + " left join RY ry on ry.RYID=w.RYID"
+                        + " left join RY cj on cj.RYID=w.CJRYID"
+                        + " where w.WJJLID=:id and w.JLZTM=51");
+        sqlc.wrLongParm("id", sourceId);
+        List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
+        if (rows == null || rows.isEmpty())
+            return rdLedgerOnlyTrace(cls, ledger,
+                    XjbJfServ.LYLX_SCHOOL_VIOLATION);
+        Map<String, Object> row = rows.get(0);
+        Map<String, Object> record = adjustmentRecord(cls, ledger,
+                "学校违纪", row.get("ryxm"));
+        record.put("eventTime", formatTimestamp(row.get("wjsj")));
+        record.put("inspectorName",
+                defaultText(row.get("cjryxm"), "未记录"));
+        record.put("businessCategory", rdStr(row.get("wjlbmc")));
+        record.put("description", defaultText(row.get("ms"), ""));
+        List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
+                defaultText(row.get("wjlbmc"), "学校违纪"),
+                defaultText(row.get("ms"), "")));
+        return adjustmentTraceResult(cls, ledger, sourceId,
+                XjbJfServ.LYLX_SCHOOL_VIOLATION,
+                "学校违纪减分详情", record, items, "");
+    }
+
+
+    private static Map<String, Object> rdTeamAdjustmentTrace(
+            Db db, ClassInfo cls, Map<String, Object> ledger,
+            String sourceType, long sourceId) throws Exception {
+        String sql;
+        if (XjbJfServ.LYLX_TEAM_ROLE.equals(sourceType)) {
+            sql = "select w.TTWCYID ID,w.RYID,w.TTWCYLBM,"
+                    + "t.MC TTMC,wc.MC ROLEMC,wc.BJJF,ry.XM RYXM"
+                    + " from TTWCY w inner join TT t on t.TTID=w.TTID"
+                    + " inner join TTWCYLB wc on wc.TTWCYLBM=w.TTWCYLBM"
+                    + " left join RY ry on ry.RYID=w.RYID"
+                    + " where w.TTWCYID=:id and w.JLZTM=51";
+        } else {
+            sql = "select c.TTCYID ID,c.RYID,wc.TTWCYLBM,"
+                    + "t.MC TTMC,wc.MC ROLEMC,wc.BJJF,ry.XM RYXM"
+                    + " from TTCY c inner join TT t on t.TTID=c.TTID"
+                    + " inner join TTWCYLB wc on wc.TTLBM=t.TTLBM"
+                    + " and wc.TTWCYLBM=(select min(wc2.TTWCYLBM)"
+                    + " from TTWCYLB wc2 where wc2.TTLBM=t.TTLBM"
+                    + " and wc2.MC='成员')"
+                    + " left join RY ry on ry.RYID=c.RYID"
+                    + " where c.TTCYID=:id and c.JLZTM=51";
+        }
+        SqlCmd sqlc = new SqlCmd(sql);
+        sqlc.wrLongParm("id", sourceId);
+        List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
+        if (rows == null || rows.isEmpty())
+            return rdLedgerOnlyTrace(cls, ledger, sourceType);
+        Map<String, Object> row = rows.get(0);
+        Map<String, Object> record = adjustmentRecord(cls, ledger,
+                "团体成员增分", row.get("ryxm"));
+        record.put("teamName", rdStr(row.get("ttmc")));
+        record.put("roleName", rdStr(row.get("rolemc")));
+        record.put("description", defaultText(ledger.get("ms"), ""));
+        List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
+                defaultText(row.get("ttmc"), "")
+                        + "·" + defaultText(row.get("rolemc"), ""),
+                defaultText(ledger.get("ms"), "")));
+        return adjustmentTraceResult(cls, ledger, sourceId, sourceType,
+                "团体成员增分详情", record, items, "");
+    }
+
+
+    private static Map<String, Object> rdRuleAdjustmentTrace(
+            ClassInfo cls, Map<String, Object> ledger, String sourceType) {
+        Map<String, Object> record = adjustmentRecord(cls, ledger,
+                "星级班规则增分", null);
+        record.put("ruleName",
+                XjbJfServ.LYLX_MONTH_SAFE.equals(sourceType)
+                        ? "当月无学生处分" : "当月无风纪扣分");
+        record.put("description", defaultText(ledger.get("ms"), ""));
+        List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
+                defaultText(ledger.get("mc"),
+                        String.valueOf(record.get("ruleName"))),
+                defaultText(ledger.get("ms"), "")));
+        return adjustmentTraceResult(cls, ledger, rdLong(ledger.get("lyid")),
+                sourceType, "星级班规则增分详情", record, items,
+                "该记录由月度规则自动生成,无其他原始业务单据");
+    }
+
+
+    private static Map<String, Object> rdLedgerOnlyTrace(
+            ClassInfo cls, Map<String, Object> ledger, String sourceType) {
+        Map<String, Object> record = adjustmentRecord(cls, ledger,
+                adjustmentSourceLabel(sourceType), null);
+        record.put("description", defaultText(ledger.get("ms"), ""));
+        List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
+                defaultText(ledger.get("mc"), "星级班增扣分"),
+                defaultText(ledger.get("ms"), "")));
+        return adjustmentTraceResult(cls, ledger, rdLong(ledger.get("lyid")),
+                sourceType, "星级班增扣分详情", record, items,
+                "原业务记录已不可查看,以下内容来自星级班增扣分账本");
+    }
+
+
+    private static Map<String, Object> adjustmentRecord(
+            ClassInfo cls, Map<String, Object> ledger, String businessType,
+            Object studentName) {
+        Map<String, Object> record = new LinkedHashMap<>();
+        record.put("time", formatTimestamp(ledger.get("fssj")));
+        record.put("className", cls.bjmc);
+        record.put("studentName",
+                defaultText(studentName, defaultText(ledger.get("ryxm"), "")));
+        record.put("businessType", businessType);
+        record.put("ledgerId", rdLong(ledger.get("xjb_jfjlid")));
+        record.put("score", signedAdjustmentScore(ledger));
+        return record;
+    }
+
+
+    private static Map<String, Object> adjustmentItem(
+            Map<String, Object> ledger, String itemName, String remark) {
+        Map<String, Object> item = new LinkedHashMap<>();
+        item.put("itemName", itemName);
+        item.put("delta", signedAdjustmentScore(ledger));
+        item.put("remark", remark);
+        return item;
+    }
+
+
+    private static Map<String, Object> adjustmentTraceResult(
+            ClassInfo cls, Map<String, Object> ledger, long sourceId,
+            String sourceType, String title, Map<String, Object> record,
+            List<Map<String, Object>> items, String notice) {
+        Map<String, Object> data = new LinkedHashMap<>();
+        data.put("bjid", cls.bjid);
+        data.put("bjmc", cls.bjmc);
+        data.put("kind", "adjustment");
+        data.put("ledgerId", rdLong(ledger.get("xjb_jfjlid")));
+        data.put("sourceType", sourceType);
+        data.put("sourceId", sourceId);
+        data.put("title", title);
+        data.put("record", record);
+        data.put("items", items);
+        data.put("notice", notice);
+        return data;
+    }
+
+
+    private static double signedAdjustmentScore(Map<String, Object> ledger) {
+        double points = Math.abs(rdDouble(ledger.get("jfz")));
+        return rdInt(ledger.get("jflx"))
+                == XjbJfServ.JFLX_ADD ? points : -points;
+    }
+
+
+    private static String adjustmentSourceLabel(String sourceType) {
+        if (XjbJfServ.LYLX_AWARD.equals(sourceType))
+            return "学校获奖";
+        if (XjbJfServ.LYLX_SCHOOL_VIOLATION.equals(sourceType))
+            return "学校违纪";
+        if (XjbJfServ.LYLX_TEAM_ROLE.equals(sourceType))
+            return "团体职务";
+        if (XjbJfServ.LYLX_TEAM_MEMBER.equals(sourceType))
+            return "团体成员";
+        if (XjbJfServ.LYLX_MONTH_SAFE.equals(sourceType))
+            return "当月无学生处分";
+        if (XjbJfServ.LYLX_FJ_SAFE.equals(sourceType))
+            return "当月无风纪扣分";
+        return StringUtils.defaultIfBlank(sourceType, "星级班增扣分");
+    }
+
+
     private static Map<String, Object> traceResult(
             ClassInfo cls, LocalDate day, CategoryDef category, String source,
             String title, Map<String, Object> record,
@@ -1651,8 +2017,11 @@ public class BjStarClassMpServ extends Serv {
         for (Adjustment item : adjustments) {
             Map<String, Object> row = baseDetail(item.date, SOURCE_REAL);
             row.put("id", item.id);
+            row.put("ledgerId", item.id);
             row.put("sourceId", item.sourceRecordId);
             row.put("sourceType", item.sourceType);
+            row.put("detailKind", "adjustment");
+            row.put("traceable", true);
             row.put("itemName", item.itemName);
             row.put("studentName", item.studentName);
             row.put("title", item.itemName);

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

@@ -267,6 +267,7 @@ public class XjbMonthCloseServ extends Serv {
             Set<String> stars = new LinkedHashSet<>();
             for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
                 Map<String, Object> item = new LinkedHashMap<>();
+                item.put("bjid", rdLong(row.get("bjid"), 0L));
                 item.put("department", rdStr(row.get("dwmc")));
                 item.put("major", rdStr(row.get("zymc")));
                 item.put("className", rdStr(row.get("bjmc")));

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

@@ -12,4 +12,6 @@
 		  clazz="biz.bj.XjbMonthCloseServ" func="correctSchoolByA"/>
 	<serv name="xjbMonth_pcSummary" desc="PC星级班月结报表"
 		  clazz="biz.bj.XjbMonthCloseServ" func="pcSummaryByA"/>
+	<serv name="xjbMonth_pcDetail" desc="PC星级班月结明细下钻"
+		  clazz="biz.bj.BjStarClassMpServ" func="pcDetailByA"/>
 </servs>

+ 692 - 8
web/page/biz/ssnwjc_starClassSummary.jsp

@@ -85,6 +85,202 @@
             font-size: 12px;
             text-align: right;
         }
+        .link-cell {
+            color: #0b5ea8;
+            cursor: pointer;
+            text-decoration: none;
+        }
+        .link-cell::after {
+            content: " ›";
+            color: #6b93bd;
+            font-size: 11px;
+        }
+        .link-cell:hover {
+            text-decoration: underline;
+        }
+        .link-cell:focus {
+            outline: 2px solid #8bb9e8;
+            outline-offset: -2px;
+        }
+        .drill-mask {
+            position: fixed;
+            z-index: 9000;
+            inset: 0;
+            display: none;
+            justify-content: flex-end;
+            background: rgba(20, 28, 38, .36);
+        }
+        .drill-mask.open { display: flex; }
+        .drill-panel {
+            display: flex;
+            width: min(760px, 92vw);
+            height: 100%;
+            flex-direction: column;
+            background: #fff;
+            box-shadow: -8px 0 30px rgba(20, 28, 38, .18);
+        }
+        .drill-head {
+            display: flex;
+            align-items: flex-start;
+            justify-content: space-between;
+            gap: 16px;
+            padding: 18px 20px 14px;
+            border-bottom: 1px solid #e5e7eb;
+        }
+        .drill-title {
+            margin: 0;
+            font-size: 19px;
+            line-height: 1.4;
+        }
+        .drill-breadcrumb {
+            margin-top: 6px;
+            color: #777;
+            font-size: 12px;
+            line-height: 1.5;
+        }
+        .drill-actions {
+            display: flex;
+            flex: 0 0 auto;
+            gap: 8px;
+        }
+        .drill-actions button {
+            padding: 7px 12px;
+            color: #333;
+            background: #f3f4f6;
+            border: 1px solid #d9dde3;
+            border-radius: 4px;
+            cursor: pointer;
+            font: inherit;
+            font-size: 13px;
+        }
+        .drill-actions button:disabled {
+            color: #aaa;
+            cursor: default;
+        }
+        .drill-body {
+            overflow: auto;
+            flex: 1;
+            padding: 16px 20px 28px;
+            background: #f7f8fa;
+        }
+        .drill-loading,
+        .drill-empty {
+            padding: 50px 20px;
+            color: #777;
+            background: #fff;
+            border: 1px solid #e5e7eb;
+            text-align: center;
+        }
+        .drill-list {
+            overflow: hidden;
+            background: #fff;
+            border: 1px solid #e5e7eb;
+        }
+        .drill-row {
+            display: flex;
+            width: 100%;
+            min-height: 64px;
+            align-items: center;
+            justify-content: space-between;
+            gap: 16px;
+            padding: 12px 15px;
+            color: #222;
+            background: #fff;
+            border: 0;
+            border-bottom: 1px solid #e5e7eb;
+            cursor: pointer;
+            text-align: left;
+            font: inherit;
+        }
+        .drill-row:last-child { border-bottom: 0; }
+        .drill-row:hover { background: #f8fbff; }
+        .drill-row-main { min-width: 0; }
+        .drill-row-title {
+            font-size: 15px;
+            font-weight: 600;
+            line-height: 1.45;
+        }
+        .drill-row-meta {
+            margin-top: 5px;
+            color: #777;
+            font-size: 12px;
+            line-height: 1.5;
+        }
+        .drill-row-amount {
+            flex: 0 0 auto;
+            font-size: 15px;
+            font-weight: 700;
+        }
+        .drill-row-amount.positive { color: #1677c8; }
+        .drill-row-amount.negative { color: #d9534f; }
+        .drill-section {
+            margin-bottom: 14px;
+            background: #fff;
+            border: 1px solid #e5e7eb;
+        }
+        .drill-section-title {
+            padding: 11px 14px;
+            background: #fafafa;
+            border-bottom: 1px solid #e5e7eb;
+            font-size: 14px;
+            font-weight: 700;
+        }
+        .drill-info-row {
+            display: grid;
+            grid-template-columns: 105px minmax(0, 1fr);
+            min-height: 42px;
+            border-bottom: 1px solid #eceff2;
+        }
+        .drill-info-row:last-child { border-bottom: 0; }
+        .drill-info-label,
+        .drill-info-value {
+            display: flex;
+            align-items: center;
+            padding: 9px 12px;
+            font-size: 13px;
+            line-height: 1.55;
+            word-break: break-all;
+        }
+        .drill-info-label {
+            justify-content: flex-end;
+            color: #666;
+            background: #fafafa;
+            border-right: 1px solid #eceff2;
+        }
+        .drill-item {
+            display: flex;
+            align-items: flex-start;
+            justify-content: space-between;
+            gap: 14px;
+            padding: 12px 14px;
+            border-bottom: 1px solid #eceff2;
+        }
+        .drill-item:last-child { border-bottom: 0; }
+        .drill-item-main { min-width: 0; }
+        .drill-item-name {
+            font-size: 14px;
+            font-weight: 600;
+        }
+        .drill-item-remark {
+            margin-top: 5px;
+            color: #777;
+            font-size: 12px;
+            line-height: 1.55;
+        }
+        .drill-item-amount {
+            flex: 0 0 auto;
+            font-size: 15px;
+            font-weight: 700;
+        }
+        .drill-notice {
+            margin-bottom: 12px;
+            padding: 10px 12px;
+            color: #806300;
+            background: #fff8dc;
+            border: 1px solid #ecd995;
+            font-size: 12px;
+            line-height: 1.55;
+        }
     </style>
 </head>
 <body>
@@ -151,12 +347,30 @@
     ,共 <b id="resultCount">0</b> 条
 </div>
 
+<div class="drill-mask" id="drillMask">
+    <aside class="drill-panel" role="dialog" aria-modal="true">
+        <div class="drill-head">
+            <div>
+                <h2 class="drill-title" id="drillTitle">明细</h2>
+                <div class="drill-breadcrumb" id="drillBreadcrumb"></div>
+            </div>
+            <div class="drill-actions">
+                <button type="button" id="drillBackButton">返回上一层</button>
+                <button type="button" id="drillCloseButton">关闭</button>
+            </div>
+        </div>
+        <div class="drill-body" id="drillBody"></div>
+    </aside>
+</div>
+
 <script>
     (function () {
         "use strict";
 
         let report = null;
         let rows = [];
+        let drillCurrent = null;
+        let drillHistory = [];
         const yearText = document.getElementById("yearText");
         const monthText = document.getElementById("monthText");
         const statusText = document.getElementById("statusText");
@@ -168,6 +382,21 @@
         const classFilter = document.getElementById("classFilter");
         const starFilter = document.getElementById("starFilter");
         const monthFilter = document.getElementById("monthFilter");
+        const drillMask = document.getElementById("drillMask");
+        const drillTitle = document.getElementById("drillTitle");
+        const drillBreadcrumb = document.getElementById("drillBreadcrumb");
+        const drillBody = document.getElementById("drillBody");
+        const drillBackButton = document.getElementById("drillBackButton");
+        const drillCloseButton = document.getElementById("drillCloseButton");
+
+        const regularCategories = [
+            {code: "dorm", label: "宿舍评分"},
+            {code: "classroom", label: "课堂考核"},
+            {code: "flag", label: "升旗礼广播操集会"},
+            {code: "cleaning", label: "清洁卫生"},
+            {code: "discipline", label: "风纪仪容"},
+            {code: "attendance", label: "考勤"}
+        ];
 
         function fillSelect(select, placeholder, values) {
             const selected = select.value;
@@ -193,6 +422,42 @@
             return cell;
         }
 
+        function createLinkCell(value, row, category) {
+            const cell = createCell(value, "link-cell");
+            cell.title = "查看" + category.label + "明细";
+            cell.tabIndex = 0;
+            cell.setAttribute("role", "button");
+            const open = function () {
+                openCategory(row, category);
+            };
+            cell.addEventListener("click", open);
+            cell.addEventListener("keydown", function (event) {
+                if (event.key === "Enter" || event.key === " ") {
+                    event.preventDefault();
+                    open();
+                }
+            });
+            return cell;
+        }
+
+        function createAdjustmentLinkCell(value, row, mode, label) {
+            const cell = createCell(value, "link-cell");
+            cell.title = "查看" + label + "明细";
+            cell.tabIndex = 0;
+            cell.setAttribute("role", "button");
+            const open = function () {
+                openAdjustment(row, mode, label);
+            };
+            cell.addEventListener("click", open);
+            cell.addEventListener("keydown", function (event) {
+                if (event.key === "Enter" || event.key === " ") {
+                    event.preventDefault();
+                    open();
+                }
+            });
+            return cell;
+        }
+
         function filteredRows() {
             return rows.filter(function (row) {
                 return (!departmentFilter.value
@@ -223,14 +488,22 @@
                     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(createLinkCell(
+                        row.dormScore, row, regularCategories[0]));
+                    tr.appendChild(createLinkCell(
+                        row.classroomScore, row, regularCategories[1]));
+                    tr.appendChild(createLinkCell(
+                        row.flagCeremonyScore, row, regularCategories[2]));
+                    tr.appendChild(createLinkCell(
+                        row.cleaningScore, row, regularCategories[3]));
+                    tr.appendChild(createLinkCell(
+                        row.disciplineScore, row, regularCategories[4]));
+                    tr.appendChild(createLinkCell(
+                        row.attendanceScore, row, regularCategories[5]));
+                    tr.appendChild(createAdjustmentLinkCell(
+                        row.bonus, row, "bonus", "增分"));
+                    tr.appendChild(createAdjustmentLinkCell(
+                        row.deduction, row, "deduction", "减分"));
                     tr.appendChild(createCell(row.monthTotal, "total-cell"));
                     tr.appendChild(createCell(row.starLevel));
                     tr.appendChild(createCell(row.departmentRank));
@@ -266,6 +539,407 @@
             render(filteredRows());
         }
 
+        function formatNumber(value) {
+            const number = Number(value || 0);
+            return Number.isInteger(number) ? String(number)
+                : number.toFixed(2).replace(/0+$/, "").replace(/\.$/, "");
+        }
+
+        function formatSigned(value) {
+            const number = Number(value || 0);
+            return (number > 0 ? "+" : "") + formatNumber(number);
+        }
+
+        async function postDetail(payload) {
+            const body = new URLSearchParams();
+            Object.keys(payload).forEach(function (key) {
+                if (payload[key] !== undefined && payload[key] !== null)
+                    body.set(key, payload[key]);
+            });
+            const response = await fetch(
+                "/service?ssServ=xjbMonth_pcDetail&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 || "明细加载失败");
+            return result.ssData;
+        }
+
+        function setDrillLoading(title) {
+            drillTitle.textContent = title || "明细";
+            drillBreadcrumb.textContent = report
+                ? (report.month + " 星级班报表")
+                : "";
+            drillBody.innerHTML = '<div class="drill-loading">加载中...</div>';
+            drillMask.classList.add("open");
+            drillBackButton.disabled = drillHistory.length === 0;
+        }
+
+        function closeDrill() {
+            drillMask.classList.remove("open");
+            drillCurrent = null;
+            drillHistory = [];
+            drillBody.innerHTML = "";
+        }
+
+        function backDrill() {
+            if (!drillHistory.length)
+                return;
+            const previous = drillHistory.pop();
+            drillCurrent = previous;
+            if (previous.type === "trace")
+                renderTrace(previous.data, false);
+            else
+                renderList(previous.title, previous.breadcrumb,
+                    previous.rows, previous.emptyText, false);
+        }
+
+        function pushCurrent() {
+            if (drillCurrent)
+                drillHistory.push(drillCurrent);
+        }
+
+        function showListLevel(title, breadcrumb, listRows, emptyText) {
+            drillCurrent = {
+                type: "list",
+                title: title,
+                breadcrumb: breadcrumb,
+                rows: listRows,
+                emptyText: emptyText
+            };
+            renderList(title, breadcrumb, listRows, emptyText, true);
+        }
+
+        function renderList(title, breadcrumb, listRows, emptyText, updateState) {
+            drillTitle.textContent = title;
+            drillBreadcrumb.textContent = breadcrumb || "";
+            drillBackButton.disabled = drillHistory.length === 0;
+            drillBody.innerHTML = "";
+            if (!listRows.length) {
+                const empty = document.createElement("div");
+                empty.className = "drill-empty";
+                empty.textContent = emptyText || "暂无明细";
+                drillBody.appendChild(empty);
+            } else {
+                const list = document.createElement("div");
+                list.className = "drill-list";
+                listRows.forEach(function (item) {
+                    const button = document.createElement("button");
+                    button.type = "button";
+                    button.className = "drill-row";
+                    const main = document.createElement("div");
+                    main.className = "drill-row-main";
+                    const rowTitle = document.createElement("div");
+                    rowTitle.className = "drill-row-title";
+                    rowTitle.textContent = item.title || "明细";
+                    const meta = document.createElement("div");
+                    meta.className = "drill-row-meta";
+                    meta.textContent = (item.meta || []).filter(Boolean).join("  ");
+                    main.appendChild(rowTitle);
+                    if (meta.textContent)
+                        main.appendChild(meta);
+                    button.appendChild(main);
+                    if (item.amount !== undefined && item.amount !== null) {
+                        const amount = document.createElement("div");
+                        amount.className = "drill-row-amount "
+                            + (Number(item.amount) >= 0 ? "positive" : "negative");
+                        amount.textContent = formatSigned(item.amount);
+                        button.appendChild(amount);
+                    } else {
+                        const arrow = document.createElement("div");
+                        arrow.className = "drill-row-amount";
+                        arrow.textContent = "›";
+                        button.appendChild(arrow);
+                    }
+                    button.addEventListener("click", item.open);
+                    list.appendChild(button);
+                });
+                drillBody.appendChild(list);
+            }
+            if (updateState) {
+                drillCurrent = {
+                    type: "list",
+                    title: title,
+                    breadcrumb: breadcrumb,
+                    rows: listRows,
+                    emptyText: emptyText
+                };
+            }
+            drillMask.classList.add("open");
+        }
+
+        async function openCategory(reportRow, category) {
+            pushCurrent();
+            setDrillLoading(category.label + "明细");
+            try {
+                const data = await postDetail({
+                    mode: "monthCategory",
+                    jdid: report.batchId,
+                    bjid: reportRow.bjid,
+                    month: report.month,
+                    category: category.code
+                });
+                const listRows = (data.list || []).map(function (item) {
+                    return {
+                        title: item.date,
+                        meta: [
+                            item.weekday,
+                            "得分 " + formatNumber(item.score),
+                            "扣分 -" + formatNumber(item.deduction),
+                            item.count ? item.count + "条" : ""
+                        ],
+                        amount: -Number(item.deduction || 0),
+                        open: function () {
+                            openDay(data, category, item.date);
+                        }
+                    };
+                });
+                showListLevel(category.label + " · " + data.bjmc,
+                    data.bjmc + " / " + report.month + " / " + category.label,
+                    listRows, "该月份暂无" + category.label + "记录");
+            } catch (error) {
+                renderList(category.label + "明细", "", [], error.message);
+            }
+        }
+
+        async function openDay(parentData, category, date) {
+            pushCurrent();
+            setDrillLoading(category.label);
+            try {
+                const data = await postDetail({
+                    mode: "dayItem",
+                    jdid: report.batchId,
+                    bjid: parentData.bjid,
+                    date: date,
+                    category: category.code
+                });
+                const listRows = (data.list || []).map(function (item) {
+                    return {
+                        title: item.itemName || item.title || "扣分记录",
+                        meta: [
+                            item.studentName,
+                            item.roomName,
+                            item.scoreText,
+                            item.remark
+                        ],
+                        amount: Number(item.delta || 0),
+                        open: function () {
+                            openRegularTrace(parentData, category, item);
+                        }
+                    };
+                });
+                showListLevel(category.label + " · " + date,
+                    data.bjmc + " / " + report.month + " / "
+                        + category.label + " / " + date,
+                    listRows, "当天暂无" + category.label + "扣分明细");
+            } catch (error) {
+                renderList(category.label + "明细", "", [], error.message);
+            }
+        }
+
+        async function openRegularTrace(parentData, category, item) {
+            if (!item || !item.traceable)
+                return;
+            pushCurrent();
+            setDrillLoading("扣分明细");
+            try {
+                const data = await postDetail({
+                    mode: "trace",
+                    kind: "regular",
+                    jdid: report.batchId,
+                    bjid: parentData.bjid,
+                    date: item.date,
+                    category: category.code,
+                    id: item.sourceId,
+                    source: item.source || "real"
+                });
+                renderTrace(data, true);
+            } catch (error) {
+                renderList("扣分明细", "", [], error.message);
+            }
+        }
+
+        async function openAdjustment(reportRow, mode, label) {
+            pushCurrent();
+            setDrillLoading(label + "明细");
+            try {
+                const data = await postDetail({
+                    mode: mode,
+                    jdid: report.batchId,
+                    bjid: reportRow.bjid,
+                    month: report.month
+                });
+                const listRows = (data.list || []).map(function (item) {
+                    return {
+                        title: item.itemName || item.title || label,
+                        meta: [
+                            item.date,
+                            item.studentName,
+                            item.remark
+                        ],
+                        amount: Number(item.delta || 0),
+                        open: function () {
+                            openAdjustmentTrace(reportRow, item, label);
+                        }
+                    };
+                });
+                showListLevel(label + " · " + data.bjmc,
+                    data.bjmc + " / " + report.month + " / " + label,
+                    listRows, "该月份暂无" + label + "记录");
+            } catch (error) {
+                renderList(label + "明细", "", [], error.message);
+            }
+        }
+
+        async function openAdjustmentTrace(reportRow, item, label) {
+            pushCurrent();
+            setDrillLoading(label + "详情");
+            try {
+                const data = await postDetail({
+                    mode: "trace",
+                    kind: "adjustment",
+                    jdid: report.batchId,
+                    bjid: reportRow.bjid,
+                    id: item.ledgerId || item.id
+                });
+                renderTrace(data, true);
+            } catch (error) {
+                renderList(label + "详情", "", [], error.message);
+            }
+        }
+
+        function renderTrace(data, updateState) {
+            const record = data.record || {};
+            const items = Array.isArray(data.items) ? data.items : [];
+            drillTitle.textContent = data.title || "明细详情";
+            drillBreadcrumb.textContent = (data.bjmc || "")
+                + (report ? " / " + report.month : "");
+            drillBackButton.disabled = drillHistory.length === 0;
+            drillBody.innerHTML = "";
+
+            if (data.notice) {
+                const notice = document.createElement("div");
+                notice.className = "drill-notice";
+                notice.textContent = data.notice;
+                drillBody.appendChild(notice);
+            }
+
+            const fields = [
+                ["业务类型", record.businessType],
+                ["发生时间", record.eventTime || record.time],
+                ["班级", record.className],
+                ["学生", record.studentName],
+                ["课程", record.courseName],
+                ["房间", record.roomName],
+                ["检查部门", record.departmentName],
+                ["检查人", record.inspectorName],
+                ["时段", record.period],
+                ["获奖性质", record.awardNature],
+                ["获奖/违纪类别", record.awardCategory
+                    || record.businessCategory],
+                ["团体", record.teamName],
+                ["角色", record.roleName],
+                ["规则", record.ruleName],
+                ["总分/分值", record.score !== undefined
+                    ? formatSigned(record.score) : (
+                        record.totalScore !== undefined
+                            ? formatNumber(record.totalScore) : "")],
+                ["说明", record.description]
+            ].filter(function (field) {
+                return field[1] !== undefined && field[1] !== null
+                    && field[1] !== "";
+            });
+
+            const infoSection = document.createElement("section");
+            infoSection.className = "drill-section";
+            const infoTitle = document.createElement("div");
+            infoTitle.className = "drill-section-title";
+            infoTitle.textContent = "记录信息";
+            infoSection.appendChild(infoTitle);
+            fields.forEach(function (field) {
+                const row = document.createElement("div");
+                row.className = "drill-info-row";
+                const label = document.createElement("div");
+                label.className = "drill-info-label";
+                label.textContent = field[0];
+                const value = document.createElement("div");
+                value.className = "drill-info-value";
+                value.textContent = String(field[1]);
+                row.appendChild(label);
+                row.appendChild(value);
+                infoSection.appendChild(row);
+            });
+            drillBody.appendChild(infoSection);
+
+            const itemSection = document.createElement("section");
+            itemSection.className = "drill-section";
+            const itemTitle = document.createElement("div");
+            itemTitle.className = "drill-section-title";
+            itemTitle.textContent = "具体明细";
+            itemSection.appendChild(itemTitle);
+            if (!items.length) {
+                const empty = document.createElement("div");
+                empty.className = "drill-empty";
+                empty.textContent = "未找到更细的扣分或增分项";
+                itemSection.appendChild(empty);
+            } else {
+                items.forEach(function (item) {
+                    const row = document.createElement("div");
+                    row.className = "drill-item";
+                    const main = document.createElement("div");
+                    main.className = "drill-item-main";
+                    const name = document.createElement("div");
+                    name.className = "drill-item-name";
+                    name.textContent = item.itemName || "增扣分项";
+                    const metaParts = [
+                        item.studentName,
+                        item.className,
+                        item.remark
+                    ].filter(Boolean);
+                    if (metaParts.length) {
+                        const remark = document.createElement("div");
+                        remark.className = "drill-item-remark";
+                        remark.textContent = metaParts.join("  ");
+                        main.appendChild(name);
+                        main.appendChild(remark);
+                    } else {
+                        main.appendChild(name);
+                    }
+                    row.appendChild(main);
+                    let amountValue;
+                    if (item.delta !== undefined)
+                        amountValue = Number(item.delta || 0);
+                    else if (item.deducted !== undefined)
+                        amountValue = -Number(item.deducted || 0);
+                    if (amountValue !== undefined) {
+                        const amount = document.createElement("div");
+                        amount.className = "drill-item-amount "
+                            + (amountValue >= 0 ? "positive" : "negative");
+                        amount.textContent = formatSigned(amountValue);
+                        row.appendChild(amount);
+                    }
+                    itemSection.appendChild(row);
+                });
+            }
+            drillBody.appendChild(itemSection);
+
+            if (updateState) {
+                drillCurrent = {
+                    type: "trace",
+                    data: data
+                };
+            }
+            drillMask.classList.add("open");
+        }
+
         async function loadReport() {
             const body = new URLSearchParams();
             if (monthFilter.value)
@@ -345,6 +1019,16 @@
                     render(filteredRows());
                 });
             });
+        drillBackButton.addEventListener("click", backDrill);
+        drillCloseButton.addEventListener("click", closeDrill);
+        drillMask.addEventListener("click", function (event) {
+            if (event.target === drillMask)
+                closeDrill();
+        });
+        document.addEventListener("keydown", function (event) {
+            if (event.key === "Escape" && drillMask.classList.contains("open"))
+                closeDrill();
+        });
 
         loadReport().catch(function (error) {
             statusText.textContent = "加载失败";