| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847 |
- 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("该部门该月份已发布,不能覆盖");
- 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) {
- 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 j.BJID,avg(j.FS) SCORE from KTJL j"
- + " inner join KCB k on k.KCBID=j.KCBID"
- + " where k.KSSJ>=:start and k.KSSJ<:end"
- + " and j." + ObjC.JLZT_useStr
- + " and k." + ObjC.JLZT_useStr
- + " group by j.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,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,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<>();
- 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(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))
- internal.put(rdLong(row.get("bjid"), 0L),
- rdDouble(row.get("score")));
- // 集体宿舍违纪会按在住学生逐人生成 WJJL;班级月结按同一事件只扣一次。
- SqlCmd violationCmd = new SqlCmd(
- "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)"
- + " where RN=1 group by 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 internalScore = internal.get(cls.bjid);
- Double attend = attendance.get(cls.bjid);
- if (internalScore == null || attend == null)
- continue;
- // 学校确认:宿舍评分允许出现负数,因此这里不再截断到 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.internal = round2(internalScore);
- 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.internal
- + ",住宿考勤" + 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 internal;
- 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;
- }
- }
- }
|