소스 검색

feat(starclass): implement confirmed scoring rules

apple 3 주 전
부모
커밋
97592d295a
3개의 변경된 파일과 195개의 추가작업 그리고 84개의 파일을 삭제
  1. 78 53
      src/biz/bj/BjStarClassMpServ.java
  2. 78 3
      src/biz/bj/XjbJfServ.java
  3. 39 28
      src/biz/bj/XjbMonthCloseServ.java

+ 78 - 53
src/biz/bj/BjStarClassMpServ.java

@@ -483,27 +483,34 @@ 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"
+                "select BJID,avg(FS) SCORE 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"))
-            });
-        }
+        Map<Long, Double> internal = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(internalCmd))
+            internal.put(rdLong(row.get("bjid")), rdDouble(row.get("score")));
 
+        // 集体宿舍违纪会按在住学生逐人生成 WJJL;班级计分按同一事件只扣一次。
         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"
+                "select BJID,sum(PENALTY) PENALTY from ("
+                        + "select w.BJID,nvl(lb.BJKF,0) PENALTY,"
+                        + "row_number() over(partition by w.BJID,w.WJLXM,"
+                        + "case when w.WJLXM=5 then w.WJLBM end,"
+                        + "case when w.WJLXM=5 then w.WJSJ end,"
+                        + "case when w.WJLXM=5 then w.JZWID end,"
+                        + "case when w.WJLXM=5 then w.KFID end,"
+                        + "case when w.WJLXM=5 then nvl(w.MS,' ') end,"
+                        + "case when w.WJLXM=5 then nvl(w.FJID,0) end,"
+                        + "case when w.WJLXM=5 then 0 else w.WJJLID end"
+                        + " order by w.WJJLID) RN"
+                        + " 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");
+                        + " and w.WJLBM>=20 and w.JLZTM=51)"
+                        + " where RN=1 group by BJID");
         violationCmd.wrTimeParm("start", period.start);
         violationCmd.wrTimeParm("end", period.end);
         Map<Long, Double> violations = new HashMap<>();
@@ -513,14 +520,13 @@ public class BjStarClassMpServ extends Serv {
 
         Map<Long, Double> result = new HashMap<>();
         for (ClassInfo cls : classes) {
-            double[] values = internal.get(cls.bjid);
+            Double internalScore = internal.get(cls.bjid);
             Double attendance = attendanceScores.get(cls.bjid);
-            if (values == null || values[0] < 0 || values[1] < 0
-                    || attendance == null)
+            if (internalScore == null || 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 violationScore =
+                    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));
@@ -596,13 +602,17 @@ public class BjStarClassMpServ extends Serv {
 
     private static Map<Long, Map<LocalDate, Double>> rdAttendancePenalty(
             Db db, MonthPeriod period) throws Exception {
+        // 学校确认:同一学生同一天多次异常只累计一次,取最高扣分。
         SqlCmd sqlc = new SqlCmd(
-                "select BJID,trunc(KSSJ) D,sum(case KQLBM"
+                "select BJID,D,sum(PENALTY) PENALTY from ("
+                        + "select BJID,NVL(RYID,-KQJLID) STUDENT_KEY,"
+                        + "trunc(KSSJ) D,max(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)");
+                        + " group by BJID,NVL(RYID,-KQJLID),trunc(KSSJ)"
+                        + ") group by BJID,D");
         sqlc.wrTimeParm("start", period.start);
         sqlc.wrTimeParm("end", period.end);
         Map<Long, Map<LocalDate, Double>> result = new HashMap<>();
@@ -789,29 +799,35 @@ public class BjStarClassMpServ extends Serv {
                 : 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"
+                "select trunc(JCSJ) D,avg(FS) SCORE,count(*) CNT"
                         + " 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"))
-            });
+        Map<LocalDate, DailyPoint> internal = rdDailyPoints(
+                db.doSelMapListByC(itemCmd));
 
+        // 单日宿舍违纪沿用集体事件去重,个人违纪仍逐条参与。
         SqlCmd violationCmd = new SqlCmd(
-                "select trunc(w.WJSJ) D,sum(nvl(lb.BJKF,0)) PENALTY"
+                "select D,sum(PENALTY) PENALTY from ("
+                        + "select trunc(w.WJSJ) D,nvl(lb.BJKF,0) PENALTY,"
+                        + "row_number() over(partition by w.BJID,w.WJLXM,"
+                        + "case when w.WJLXM=5 then w.WJLBM end,"
+                        + "case when w.WJLXM=5 then w.WJSJ end,"
+                        + "case when w.WJLXM=5 then w.JZWID end,"
+                        + "case when w.WJLXM=5 then w.KFID end,"
+                        + "case when w.WJLXM=5 then nvl(w.MS,' ') end,"
+                        + "case when w.WJLXM=5 then nvl(w.FJID,0) end,"
+                        + "case when w.WJLXM=5 then 0 else w.WJJLID end"
+                        + " order by w.WJJLID) RN"
                         + " 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)");
+                        + " and w.WJSJ<:end and w.WJLBM>=20 and w.JLZTM=51)"
+                        + " where RN=1 group by D");
         violationCmd.wrLongParm("bjid", cls.bjid);
         violationCmd.wrTimeParm("start", start);
         violationCmd.wrTimeParm("end", end);
@@ -823,18 +839,18 @@ public class BjStarClassMpServ extends Serv {
         Map<LocalDate, DailyPoint> attendance =
                 rdDailyAttendanceScore(db, cls.bjid, start, end);
         Map<LocalDate, DailyPoint> result = new HashMap<>();
-        for (Map.Entry<LocalDate, double[]> entry : internal.entrySet()) {
+        for (Map.Entry<LocalDate, DailyPoint> entry : internal.entrySet()) {
             DailyPoint attend = attendance.get(entry.getKey());
-            double[] values = entry.getValue();
-            if (values[0] < 0 || values[1] < 0 || attend == null)
+            DailyPoint internalPoint = entry.getValue();
+            if (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
+            double violationScore =
+                    100.0 - violations.getOrDefault(entry.getKey(), 0.0);
+            double base = internalPoint.score * 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));
+                    round2(base + base / 85.0 * 10.0),
+                    internalPoint.count));
         }
         return result;
     }
@@ -893,13 +909,15 @@ public class BjStarClassMpServ extends Serv {
     private static Map<LocalDate, DailyPoint> rdDailyAttendanceScore(
             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 1"
-                        + " when 52 then 1 when 61 then 2 else 0 end) PENALTY,"
-                        + "count(*) CNT from KQJL where BJID=:bjid"
+                "select D,sum(PENALTY) PENALTY,count(*) CNT from ("
+                        + "select NVL(RYID,-KQJLID) STUDENT_KEY,trunc(KSSJ) D,"
+                        + "max(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 BJID=:bjid"
                         + " and KSSJ>=:start and KSSJ<:end"
                         + " and KQJLZTM=51 and " + ObjC.JLZT_useStr
-                        + " group by trunc(KSSJ)");
+                        + " group by NVL(RYID,-KQJLID),trunc(KSSJ)"
+                        + ") group by D");
         sqlc.wrLongParm("bjid", bjid);
         sqlc.wrTimeParm("start", start);
         sqlc.wrTimeParm("end", end);
@@ -967,20 +985,27 @@ public class BjStarClassMpServ extends Serv {
         Timestamp start = Timestamp.valueOf(day.atStartOfDay());
         Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
         SqlCmd sqlc = new SqlCmd(
-                "select k.KQJLID,k.KQLBM,lb.MC KQLBMC,k.RYID,ry.XM,k.MC,"
-                        + "k.MS,k.KSSJ from KQJL k"
+                "select * from (select k.KQJLID,k.KQLBM,lb.MC KQLBMC,"
+                        + "k.RYID,ry.XM,k.MC,k.MS,k.KSSJ,"
+                        + "case k.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,"
+                        + "row_number() over(partition by NVL(k.RYID,-k.KQJLID)"
+                        + " order by case k.KQLBM when 1 then 3 when 21 then 1"
+                        + " when 51 then 1 when 52 then 1 when 61 then 2"
+                        + " else 0 end desc,k.KSSJ desc,k.KQJLID desc) RN"
+                        + " from KQJL k"
                         + " left join KQLB lb on lb.KQLBM=k.KQLBM"
                         + " left join RY ry on ry.RYID=k.RYID"
                         + " where k.BJID=:bjid and k.KSSJ>=:start"
                         + " and k.KSSJ<:end and k.KQJLZTM=51 and k."
-                        + ObjC.JLZT_useStr
-                        + " order by k.KSSJ desc,k.KQJLID desc");
+                        + ObjC.JLZT_useStr + ") where RN=1"
+                        + " order by KSSJ desc,KQJLID desc");
         sqlc.wrLongParm("bjid", bjid);
         sqlc.wrTimeParm("start", start);
         sqlc.wrTimeParm("end", end);
         List<Map<String, Object>> result = new ArrayList<>();
         for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
-            int kqlbm = rdInt(row.get("kqlbm"));
             Map<String, Object> item = baseDetail(day, SOURCE_REAL);
             item.put("id", rdLong(row.get("kqjlid")));
             item.put("sourceId", rdLong(row.get("kqjlid")));
@@ -990,7 +1015,7 @@ public class BjStarClassMpServ extends Serv {
             item.put("studentName", rdStr(row.get("xm")));
             item.put("title", rdStr(row.get("mc")));
             item.put("remark", rdStr(row.get("ms")));
-            item.put("delta", -attendancePenalty(kqlbm));
+            item.put("delta", -rdDouble(row.get("penalty")));
             item.put("scoreText", "");
             item.put("sortTime", formatTimestamp(row.get("kssj")));
             result.add(item);

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

@@ -40,6 +40,7 @@ public class XjbJfServ extends Serv {
     public static final String LYLX_AWARD = "HJ";
     public static final String LYLX_SCHOOL_VIOLATION = "XW";
     public static final String LYLX_TEAM_ROLE = "TT";
+    public static final String LYLX_TEAM_MEMBER = "TTCY";
     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;
@@ -48,6 +49,8 @@ public class XjbJfServ extends Serv {
     private static final Set<String> RECALC_TYPES = new LinkedHashSet<>(
             Arrays.asList(LYLX_AWARD, LYLX_SCHOOL_VIOLATION,
                     LYLX_MONTH_SAFE, LYLX_FJ_SAFE));
+    private static final Set<String> TEAM_SNAPSHOT_TYPES = new LinkedHashSet<>(
+            Arrays.asList(LYLX_TEAM_ROLE, LYLX_TEAM_MEMBER));
 
     /**
      * 为当前班主任的指定班级重建一个月的事件账本。
@@ -118,14 +121,19 @@ public class XjbJfServ extends Serv {
     private SyncCount syncClassMonth(Db db, long bjid, YearMonth month,
                                      UserRunB user) throws Exception {
         String ndy = month.format(MONTH_FMT);
+        Set<String> recalcTypes = new LinkedHashSet<>(RECALC_TYPES);
+        if (YearMonth.now(CN_ZONE).equals(month)) {
+            recalcTypes.add(LYLX_TEAM_ROLE);
+            recalcTypes.add(LYLX_TEAM_MEMBER);
+        }
         String placeholders = String.join(",",
-                RECALC_TYPES.stream().map(type -> ":lylx" + type).toList());
+                recalcTypes.stream().map(type -> ":lylx" + type).toList());
         SqlCmd delete = new SqlCmd(
                 "delete from XJB_JFJL where BJID=:bjid and NDY=:ndy"
                         + " and LYLX in(" + placeholders + ")");
         delete.wrLongParm("bjid", bjid);
         delete.wrStrParm("ndy", ndy);
-        for (String type : RECALC_TYPES)
+        for (String type : recalcTypes)
             delete.wrStrParm("lylx" + type, type);
         db.doModByC(delete);
 
@@ -141,6 +149,26 @@ public class XjbJfServ extends Serv {
         return count;
     }
 
+    /**
+     * 在月结核算时重建该班的团体成员快照。
+     * 普通成员和职务成员都按执行核算时的有效班级关系固化。
+     */
+    public int rebuildTeamSnapshot(Db db, long bjid, YearMonth month,
+                                   UserRunB user) throws Exception {
+        String placeholders = String.join(",",
+                TEAM_SNAPSHOT_TYPES.stream()
+                        .map(type -> ":lylx" + type).toList());
+        SqlCmd delete = new SqlCmd(
+                "delete from XJB_JFJL where BJID=:bjid and NDY=:ndy"
+                        + " and LYLX in(" + placeholders + ")");
+        delete.wrLongParm("bjid", bjid);
+        delete.wrStrParm("ndy", month.format(MONTH_FMT));
+        for (String type : TEAM_SNAPSHOT_TYPES)
+            delete.wrStrParm("lylx" + type, type);
+        db.doModByC(delete);
+        return insertTeamRoles(db, bjid, month, user);
+    }
+
     private int insertAwards(Db db, long bjid, YearMonth month, UserRunB user)
             throws Exception {
         Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
@@ -178,6 +206,50 @@ public class XjbJfServ extends Serv {
         return count;
     }
 
+    private int insertOrdinaryTeamMembers(Db db, long bjid, YearMonth month,
+                                          UserRunB user, Timestamp syncTime)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select c.TTCYID ID,c.RYID,wc.TTWCYLBM LYLB,wc.MC LBMC,"
+                        + "wc.BJJF JFZ,t.MC TTMC,r.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='成员')"
+                        + " inner join BJCY bc on bc.RYID=c.RYID"
+                        + " left join RY r on r.RYID=c.RYID"
+                        + " where bc.BJID=:bjid and bc." + ObjC.JLZT_useStr
+                        + " and nvl(bc.SFBY,0)=0 and c." + ObjC.JLZT_useStr
+                        + " and t." + ObjC.JLZT_useStr
+                        + " and nvl(wc.BJJF,0)>0"
+                        + " and not exists (select 1 from TTWCY w"
+                        + " where w.TTID=c.TTID and w.RYID=c.RYID"
+                        + " and w." + ObjC.JLZT_useStr + ")"
+                        + " order by c.TTCYID");
+        sqlc.wrLongParm("bjid", bjid);
+        List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
+        int count = 0;
+        for (Map<String, Object> row : rows) {
+            long sourceId = rdLong(row.get("id"), 0L);
+            if (eventExists(db, LYLX_TEAM_MEMBER, sourceId, bjid, month))
+                continue;
+            String groupName = rdStr(row.get("ttmc"));
+            String roleName = rdStr(row.get("lbmc"));
+            count += insertEvent(db, bjid, month, LYLX_TEAM_MEMBER,
+                    sourceId,
+                    rdLong(row.get("lylb"), 0L),
+                    rdLongOrNull(row.get("ryid")),
+                    syncTime, JFLX_ADD, rdFloat(row.get("jfz")),
+                    groupName + "·" + roleName,
+                    joinText("团体普通成员班级加分", groupName, roleName,
+                            rdStr(row.get("ryxm"))),
+                    user);
+        }
+        return count;
+    }
+
     private int insertSchoolViolations(Db db, long bjid, YearMonth month,
                                        UserRunB user) throws Exception {
         Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
@@ -224,7 +296,9 @@ public class XjbJfServ extends Serv {
                         + " where bc.BJID=:bjid and bc." + ObjC.JLZT_useStr
                         + " and nvl(bc.SFBY,0)=0 and w." + ObjC.JLZT_useStr
                         + " and t." + ObjC.JLZT_useStr
-                        + " and nvl(wc.BJJF,0)>0 order by w.TTWCYID");
+                        + " and nvl(wc.BJJF,0)>0"
+                        + " and wc.MC not like '%退休%'"
+                        + " order by w.TTWCYID");
         sqlc.wrLongParm("bjid", bjid);
         List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
         Timestamp syncTime = Timestamp.valueOf(
@@ -246,6 +320,7 @@ public class XjbJfServ extends Serv {
                             rdStr(row.get("ryxm"))),
                     user);
         }
+        count += insertOrdinaryTeamMembers(db, bjid, month, user, syncTime);
         return count;
     }
 

+ 39 - 28
src/biz/bj/XjbMonthCloseServ.java

@@ -76,6 +76,10 @@ public class XjbMonthCloseServ extends Serv {
             if (hasPublishedBatch(db, month, bmid))
                 throw new IllegalArgumentException("该部门该月份已发布,不能覆盖");
 
+            XjbJfServ teamSnapshot = new XjbJfServ();
+            for (ClassRow cls : classes)
+                teamSnapshot.rebuildTeamSnapshot(db, cls.bjid, month, user);
+
             List<ClassResult> results = calculate(db, classes, month);
             List<ClassResult> missing = new ArrayList<>();
             for (ClassResult result : results) {
@@ -359,13 +363,17 @@ public class XjbMonthCloseServ extends Serv {
         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"
+                "select BJID,D,sum(PENALTY) PENALTY from ("
+                        + "select BJID,NVL(RYID,-KQJLID) STUDENT_KEY,"
+                        + "trunc(KSSJ) D,max(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)");
+                        + " group by BJID,NVL(RYID,-KQJLID),trunc(KSSJ)"
+                        + ") group by BJID,D");
         penaltyCmd.wrTimeParm("start", start);
         penaltyCmd.wrTimeParm("end", end);
         Map<Long, Map<LocalDate, Double>> penalties = new HashMap<>();
@@ -394,28 +402,35 @@ public class XjbMonthCloseServ extends Serv {
     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"
+                "select BJID,avg(FS) SCORE 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);
-        }
+        Map<Long, Double> internal = new HashMap<>();
+        for (Map<String, Object> row : db.doSelMapListByC(itemCmd))
+            internal.put(rdLong(row.get("bjid"), 0L),
+                    rdDouble(row.get("score")));
 
+        // 集体宿舍违纪会按在住学生逐人生成 WJJL;班级月结按同一事件只扣一次。
         SqlCmd violationCmd = new SqlCmd(
-                "select w.BJID,sum(nvl(lb.BJKF,0)) PENALTY"
+                "select BJID,sum(PENALTY) PENALTY from ("
+                        + "select w.BJID,nvl(lb.BJKF,0) PENALTY,"
+                        + "row_number() over(partition by w.BJID,w.WJLXM,"
+                        + "case when w.WJLXM=5 then w.WJLBM end,"
+                        + "case when w.WJLXM=5 then w.WJSJ end,"
+                        + "case when w.WJLXM=5 then w.JZWID end,"
+                        + "case when w.WJLXM=5 then w.KFID end,"
+                        + "case when w.WJLXM=5 then nvl(w.MS,' ') end,"
+                        + "case when w.WJLXM=5 then nvl(w.FJID,0) end,"
+                        + "case when w.WJLXM=5 then 0 else w.WJJLID end"
+                        + " order by w.WJJLID) RN"
                         + " 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");
+                        + " and w.WJLBM>=20 and w.JLZTM=51)"
+                        + " where RN=1 group by BJID");
         violationCmd.wrTimeParm("start", start);
         violationCmd.wrTimeParm("end", end);
         Map<Long, Double> violations = new HashMap<>();
@@ -428,20 +443,18 @@ public class XjbMonthCloseServ extends Serv {
                 start, end);
         Map<Long, DormScore> result = new HashMap<>();
         for (ClassRow cls : classes) {
-            double[] values = internal.get(cls.bjid);
+            Double internalScore = internal.get(cls.bjid);
             Double attend = attendance.get(cls.bjid);
-            if (values == null || values[0] < 0 || values[1] < 0
-                    || attend == null)
+            if (internalScore == null || 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));
+            // 学校确认:宿舍评分允许出现负数,因此这里不再截断到 0。
+            double violationScore =
+                    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.internal = round2(internalScore);
             score.attendance = attend;
             score.violation = round2(violationScore);
             result.put(cls.bjid, score);
@@ -495,8 +508,7 @@ public class XjbMonthCloseServ extends Serv {
             return item;
         item.value = score.value;
         item.source = SOURCE_REAL;
-        item.detail = "上午" + score.morning
-                + ",下午" + score.afternoon
+        item.detail = "内务" + score.internal
                 + ",住宿考勤" + score.attendance
                 + ",违纪" + score.violation;
         return item;
@@ -798,8 +810,7 @@ public class XjbMonthCloseServ extends Serv {
 
     private static final class DormScore {
         double value;
-        double morning;
-        double afternoon;
+        double internal;
         double attendance;
         double violation;
     }