| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507 |
- package biz.bj;
- import base.po.XjbJdPo;
- import base.po.XjbJgPo;
- import base.po.XjbJgmxPo;
- 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 String SOURCE_THIRD = "third";
- private static final String ZHIXIN_STAR_MARKER_PREFIX = "ZHIXIN_STAR_";
- private static final String FORMULA_VERSION = "SC-2024-10-V1";
- private static final String SCOPE_SCHOOL = "XX";
- private static final long SCHOOL_SCOPE_ID = 0L;
- private static final int JD_DRAFT = 1;
- private static final int JD_PUBLISHED = 5;
- private static final int JD_SUPERSEDED = 6;
- /**
- * 对当前用户部门完成一个已结束月份的月结。
- */
- @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);
- ensureComplete(results);
- assignRanks(results);
- deleteDraftBatch(db, month, bmid);
- long jdid = insertBatch(db, month, "BM", bmid, 1,
- null, "部门星级班月结", user);
- for (ClassResult result : results) {
- long jgid = insertResult(db, jdid, result, user);
- insertResultDetail(db, jdid, jgid, 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);
- }
- }
- /**
- * 手工补算或测试环境触发全校月结。
- */
- @SuppressWarnings("unused")
- public void closeSchoolByA() 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("登录状态已失效,请重新登录");
- YearMonth month = rdMonth(request.getParameter("month"));
- Long impid = rdLongOrNull(request.getParameter("impid"));
- Map<String, Object> data = closeSchoolMonth(
- db, month, user, false,
- impid == null ? "星级班全校月结"
- : "第三方星级班导入验证",
- impid);
- if (Boolean.TRUE.equals(data.get("created")))
- db.commit();
- ServU.wrOkDataByWriter(data, writer, gson);
- } catch (IllegalArgumentException e) {
- ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
- } catch (Exception e) {
- log4j.error("XjbMonthCloseServ.closeSchoolByA() 异常", e);
- ServU.wrErrMsgByWriter(null, "全校星级班月结失败", writer, gson);
- }
- }
- /**
- * 生成同一月份的更正版本,不覆盖原正式快照。
- */
- @SuppressWarnings("unused")
- public void correctSchoolByA() 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("登录状态已失效,请重新登录");
- YearMonth month = rdMonth(request.getParameter("month"));
- String reason = StringUtils.trimToNull(request.getParameter("reason"));
- if (reason == null)
- throw new IllegalArgumentException("请填写更正原因");
- Map<String, Object> data = closeSchoolMonth(
- db, month, user, true, reason);
- db.commit();
- ServU.wrOkDataByWriter(data, writer, gson);
- } catch (IllegalArgumentException e) {
- ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
- } catch (Exception e) {
- log4j.error("XjbMonthCloseServ.correctSchoolByA() 异常", e);
- ServU.wrErrMsgByWriter(null, "星级班月结更正失败", writer, gson);
- }
- }
- /**
- * 定时任务入口:每月 1 日生成上个月全校月结。
- */
- @SuppressWarnings("unused")
- public void closeSchoolByTimer() throws Exception {
- YearMonth month = YearMonth.now(CN_ZONE).minusMonths(1);
- try (Db db = Db.makeConn()) {
- Map<String, Object> data = closeSchoolMonth(
- db, month, null, false, "星级班全校自动月结");
- if (Boolean.TRUE.equals(data.get("created")))
- db.commit();
- log4j.info("星级班全校月结任务完成,月份={},班级数={},批次={},"
- + "是否新生成={}",
- data.get("month"), data.get("classCount"),
- data.get("batchId"), data.get("created"));
- } catch (Exception e) {
- log4j.error("XjbMonthCloseServ.closeSchoolByTimer() 异常,月份={}",
- month, e);
- throw e;
- }
- }
- /**
- * 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,GZYY"
- + " from XJB_JD where NDY=:ndy and FWLX=:fwlx"
- + " and FWID=:fwid and ZT=:status"
- + " and nvl(FBSJ,CJSJ)>=:minPublish"
- + " order by BB desc,XJB_JDID desc");
- batchCmd.wrStrParm("ndy", month.format(MONTH_FMT));
- batchCmd.wrStrParm("fwlx", SCOPE_SCHOOL);
- batchCmd.wrLongParm("fwid", SCHOOL_SCOPE_ID);
- batchCmd.wrIntParm("status", JD_PUBLISHED);
- batchCmd.wrTimeParm("minPublish", Timestamp.valueOf(
- month.plusMonths(1).atDay(1).atStartOfDay()));
- List<Map<String, Object>> batches =
- db.doSelMapListByC(batchCmd);
- boolean legacyDepartmentScope = false;
- if (batches == null || batches.isEmpty()) {
- SqlCmd legacyCmd = new SqlCmd(
- "select XJB_JDID,NDY,FWLX,FWID,BB,ZT,FBSJ,GZYY"
- + " from XJB_JD where NDY=:ndy"
- + " and FWLX='BM' and ZT=:status"
- + " and nvl(FBSJ,CJSJ)>=:minPublish"
- + " order by BB desc,XJB_JDID desc");
- legacyCmd.wrStrParm("ndy", month.format(MONTH_FMT));
- legacyCmd.wrIntParm("status", JD_PUBLISHED);
- legacyCmd.wrTimeParm("minPublish", Timestamp.valueOf(
- month.plusMonths(1).atDay(1).atStartOfDay()));
- batches = db.doSelMapListByC(legacyCmd);
- legacyDepartmentScope = true;
- }
- 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(bm.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 ZY z on z.ZYID=j.ZYID"
- + " left join BM bm on bm.BMID=z.FZBMID"
- + " 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("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")));
- 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("version", rdInt(batch.get("bb")));
- data.put("status", "已发布");
- data.put("legacyDepartmentScope", legacyDepartmentScope);
- data.put("publishedAt", formatTimestamp(batch.get("fbsj")));
- data.put("correctionReason", rdStr(batch.get("gzyy")));
- 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 Map<String, Object> closeSchoolMonth(
- Db db, YearMonth month, UserRunB user, boolean correction,
- String reason) throws Exception {
- return closeSchoolMonth(db, month, user, correction, reason, null);
- }
- private Map<String, Object> closeSchoolMonth(
- Db db, YearMonth month, UserRunB user, boolean correction,
- String reason, Long impid) throws Exception {
- if (!month.isBefore(YearMonth.now(CN_ZONE)))
- throw new IllegalArgumentException("只能月结已经结束的月份");
- Map<String, Object> current = rdCurrentSchoolBatch(db, month);
- if (current != null && !correction) {
- Map<String, Object> skipped = new LinkedHashMap<>();
- skipped.put("month", month.format(MONTH_FMT));
- skipped.put("batchId", rdLong(current.get("xjb_jdid"), 0L));
- skipped.put("version", rdInt(current.get("bb")));
- skipped.put("status", JD_PUBLISHED);
- skipped.put("created", false);
- skipped.put("classCount", rdInt(current.get("class_count")));
- skipped.put("reason", rdStr(current.get("gzyy")));
- return skipped;
- }
- List<ClassRow> classes = impid == null
- ? rdSchoolClasses(db)
- : rdImportedClasses(db, month, impid);
- if (classes.isEmpty())
- throw new IllegalArgumentException("没有可月结的在用班级");
- List<ClassResult> results;
- if (impid == null) {
- XjbJfServ teamSnapshot = new XjbJfServ();
- for (ClassRow cls : classes)
- teamSnapshot.rebuildTeamSnapshot(db, cls.bjid, month, user);
- results = calculate(db, classes, month);
- } else {
- results = calculateImported(db, classes, month, impid);
- }
- ensureComplete(results);
- assignRanks(results);
- Long previousId = null;
- int version = 1;
- if (current != null) {
- previousId = rdLong(current.get("xjb_jdid"), 0L);
- version = Math.max(1, rdInt(current.get("bb"))) + 1;
- markBatchSuperseded(db, previousId);
- }
- long jdid = insertBatch(db, month, SCOPE_SCHOOL, SCHOOL_SCOPE_ID,
- version, previousId, reason, user);
- for (ClassResult result : results) {
- long jgid = insertResult(db, jdid, result, user);
- insertResultDetail(db, jdid, jgid, result, user);
- }
- Map<String, Object> data = new LinkedHashMap<>();
- data.put("month", month.format(MONTH_FMT));
- data.put("batchId", jdid);
- data.put("version", version);
- data.put("status", JD_PUBLISHED);
- data.put("created", true);
- data.put("classCount", results.size());
- data.put("previousBatchId", previousId);
- data.put("reason", StringUtils.defaultString(reason));
- return data;
- }
- private Map<String, Object> rdCurrentSchoolBatch(
- Db db, YearMonth month) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select j.XJB_JDID,j.BB,j.ZT,j.GZYY,"
- + "(select count(*) from XJB_JG g"
- + " where g.XJB_JDID=j.XJB_JDID and g.ZT=:jgStatus)"
- + " CLASS_COUNT from XJB_JD j"
- + " where j.NDY=:ndy and j.FWLX=:fwlx"
- + " and j.FWID=:fwid and j.ZT=:status"
- + " and nvl(j.FBSJ,j.CJSJ)>=:minPublish"
- + " order by j.BB desc,j.XJB_JDID desc");
- sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
- sqlc.wrStrParm("fwlx", SCOPE_SCHOOL);
- sqlc.wrLongParm("fwid", SCHOOL_SCOPE_ID);
- sqlc.wrIntParm("status", JD_PUBLISHED);
- sqlc.wrIntParm("jgStatus", JD_PUBLISHED);
- sqlc.wrTimeParm("minPublish", Timestamp.valueOf(
- month.plusMonths(1).atDay(1).atStartOfDay()));
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- return rows == null || rows.isEmpty() ? null : rows.get(0);
- }
- private List<ClassRow> rdSchoolClasses(Db db) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select b.BJID,b.MC BJMC,b.DWID,b.ZYID,z.FZBMID DEPTID"
- + " from BJ b"
- + " inner join ZY z on z.ZYID=b.ZYID"
- + " where b." + ObjC.JLZT_useStr
- + " and b.BJZTM!=81 order by b.MC,b.BJID");
- 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")),
- rdLongOrNull(row.get("deptid"))));
- }
- ensureSchoolClassMasterData(db, rows.size());
- return rows;
- }
- private void ensureSchoolClassMasterData(Db db, int joinableCount)
- throws Exception {
- SqlCmd countCmd = new SqlCmd(
- "select count(*) CNT from BJ b where b."
- + ObjC.JLZT_useStr + " and b.BJZTM!=81");
- db.doSelByC(countCmd);
- int activeCount = db.rowNum == 0 ? 0 : db.rdIntCol("cnt");
- if (activeCount == joinableCount)
- return;
- SqlCmd missingCmd = new SqlCmd(
- "select b.BJID,b.MC from BJ b"
- + " left join ZY z on z.ZYID=b.ZYID"
- + " where b." + ObjC.JLZT_useStr
- + " and b.BJZTM!=81 and z.ZYID is null"
- + " order by b.BJID");
- StringBuilder message = new StringBuilder(
- "在用班级主数据不完整:在用班 ")
- .append(activeCount)
- .append(" 个,具备有效专业关系 ")
- .append(joinableCount)
- .append(" 个");
- List<Map<String, Object>> missing = db.doSelMapListByC(missingCmd);
- if (missing != null && !missing.isEmpty()) {
- message.append(";缺少专业关系:");
- for (int i = 0; i < Math.min(10, missing.size()); i++) {
- if (i > 0)
- message.append("、");
- message.append(rdStr(missing.get(i).get("MC")))
- .append("(")
- .append(rdLong(missing.get(i).get("bjid"), 0L))
- .append(")");
- }
- if (missing.size() > 10)
- message.append(" 等");
- }
- throw new IllegalStateException(message.toString());
- }
- private List<ClassRow> rdImportedClasses(Db db, YearMonth month, long impid)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select b.BJID,b.MC BJMC,b.DWID,b.ZYID,z.FZBMID DEPTID"
- + " from XJB_IMP_WB w"
- + " inner join BJ b on b.BJID=w.BJID"
- + " inner join ZY z on z.ZYID=b.ZYID"
- + " where w.IMPID=:impid and w.NDY=:ndy"
- + " and b." + ObjC.JLZT_useStr
- + " and b.BJZTM!=81"
- + " order by b.MC,b.BJID");
- sqlc.wrLongParm("impid", impid);
- sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
- 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")),
- rdLongOrNull(row.get("deptid"))));
- }
- return rows;
- }
- private List<ClassResult> calculateImported(
- Db db, List<ClassRow> classes, YearMonth month, long impid)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select BJID,KQDF,FJDF,CSDF,SJDF,SSDF,KTDF,"
- + "ZJF,KJF,ZJFCS,KJFCS,THIRD_ZF,THIRD_XJ"
- + " from XJB_IMP_WB"
- + " where IMPID=:impid and NDY=:ndy");
- sqlc.wrLongParm("impid", impid);
- sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
- Map<Long, Map<String, Object>> imported = new HashMap<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc))
- imported.put(rdLong(row.get("bjid"), 0L), row);
- List<ClassResult> result = new ArrayList<>();
- for (ClassRow cls : classes) {
- ClassResult item = new ClassResult(cls);
- item.ndy = month.format(MONTH_FMT);
- Map<String, Object> row = imported.get(cls.bjid);
- if (row == null) {
- item.dorm = component(null, "第三方月结快照");
- item.classroom = component(null, "第三方月结快照");
- item.flag = component(null, "第三方月结快照");
- item.cleaning = component(null, "第三方月结快照");
- item.discipline = component(null, "第三方月结快照");
- item.attendance = component(null, "第三方月结快照");
- } else {
- item.dorm = importedComponent(row.get("ssdf"),
- "第三方月结宿舍评分");
- item.classroom = importedComponent(row.get("ktdf"),
- "第三方月结课堂考核");
- item.flag = importedComponent(row.get("sjdf"),
- "第三方月结升旗礼");
- item.cleaning = importedComponent(row.get("csdf"),
- "第三方月结场室卫生");
- item.discipline = importedComponent(row.get("fjdf"),
- "第三方月结风纪仪容");
- item.attendance = importedComponent(row.get("kqdf"),
- "第三方月结考勤");
- item.adjust.otherBonus = Math.max(
- 0.0, rdDouble(row.get("zjf")));
- item.adjust.bonus = XjbJfServ.capBonus(
- item.adjust.otherBonus, 0.0);
- item.adjust.deduction = Math.max(
- 0.0, rdDouble(row.get("kjf")));
- item.adjust.bonusCount = rdInt(row.get("zjfcs"));
- item.adjust.deductionCount = rdInt(row.get("kjfcs"));
- }
- 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 void ensureComplete(List<ClassResult> results) {
- List<ClassResult> missing = new ArrayList<>();
- for (ClassResult result : results) {
- if (!result.missing.isEmpty())
- missing.add(result);
- }
- if (missing.isEmpty())
- return;
- 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());
- }
- private void markBatchSuperseded(Db db, long jdid) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "update XJB_JD set ZT=:superseded"
- + " where XJB_JDID=:id and ZT=:published");
- sqlc.wrIntParm("superseded", JD_SUPERSEDED);
- sqlc.wrLongParm("id", jdid);
- sqlc.wrIntParm("published", JD_PUBLISHED);
- db.doModByC(sqlc);
- }
- private List<ClassRow> rdDepartmentClasses(Db db, long bmid)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select b.BJID,b.MC BJMC,b.DWID,b.ZYID,z.FZBMID DEPTID"
- + " 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")),
- rdLongOrNull(row.get("deptid"))));
- }
- 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);
- Set<LocalDate> schoolDays = rdSchoolDays(db, start, end);
- Map<Long, DisciplineScore> discipline =
- rdDisciplineScores(db, classes, schoolDays, start, end);
- Map<Long, Double> attendance = rdAttendanceScores(db, classes,
- start, end,
- XjbDormScoreU.AttendanceScope.DAY_STUDENT);
- Map<Long, Double> dormAttendance = rdAttendanceScores(db, classes,
- start, end,
- XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
- Map<Long, DormScore> dorm = rdDormScores(
- db, classes, start, end, dormAttendance);
- 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.dormDetail = 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.disciplineDetail = 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, List<ClassRow> classes, Set<LocalDate> schoolDays,
- Timestamp start, Timestamp end) throws Exception {
- Map<Long, DisciplineScore> result = new HashMap<>();
- if (schoolDays.isEmpty())
- return result;
- DisciplinePenalties penalties = rdDisciplinePenalties(
- db, start, end);
- for (ClassRow cls : classes) {
- Map<LocalDate, Double> mapped = penalties.mapped.getOrDefault(
- cls.bjid, Collections.emptyMap());
- Map<LocalDate, Double> legacy = penalties.legacy.getOrDefault(
- cls.bjid, Collections.emptyMap());
- Set<LocalDate> violationDays = new LinkedHashSet<>(mapped.keySet());
- violationDays.addAll(legacy.keySet());
- double totalScore = 0.0;
- double totalPenalty = 0.0;
- for (LocalDate day : schoolDays) {
- Double dayPenalty = mapped.get(day);
- if (dayPenalty == null)
- dayPenalty = legacy.get(day);
- if (dayPenalty == null)
- dayPenalty = 0.0;
- totalPenalty += dayPenalty;
- totalScore += Math.max(0.0, 100.0 - dayPenalty);
- }
- DisciplineScore score = new DisciplineScore();
- score.value = round2(totalScore / schoolDays.size());
- score.violations = round2(totalPenalty);
- score.days = violationDays.size();
- result.put(cls.bjid, score);
- }
- return result;
- }
- private Set<LocalDate> rdSchoolDays(
- Db db, Timestamp start, Timestamp end) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select distinct trunc(KSSJ) D from KQJL"
- + " where KSSJ>=:start and KSSJ<:end"
- + " and KQJLZTM=51 and " + ObjC.JLZT_useStr);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- Set<LocalDate> result = new LinkedHashSet<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- LocalDate day = rdLocalDate(row.get("d"));
- if (day != null)
- result.add(day);
- }
- return result;
- }
- private DisciplinePenalties rdDisciplinePenalties(
- Db db, Timestamp start, Timestamp end) throws Exception {
- DisciplinePenalties result = new DisciplinePenalties();
- SqlCmd current = new SqlCmd(
- "select w.BJID,trunc(w.WJSJ) D,sum(nvl(lb.BJKF,0)) PENALTY"
- + " from WJJL w"
- + " inner join WJLB lb on lb.WJLBM=w.WJLBM"
- + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
- + " and wm.YTM=" + XjbWjlbC.YTM_DISCIPLINE
- + " and wm.JLZTM=51"
- + " where w.WJSJ>=:start and w.WJSJ<:end"
- + " and w.JLZTM=51 group by w.BJID,trunc(w.WJSJ)");
- current.wrTimeParm("start", start);
- current.wrTimeParm("end", end);
- for (Map<String, Object> row : db.doSelMapListByC(current)) {
- long bjid = rdLong(row.get("bjid"), 0L);
- LocalDate day = rdLocalDate(row.get("d"));
- if (day != null)
- result.mapped.computeIfAbsent(bjid, key -> new HashMap<>())
- .put(day, rdDouble(row.get("penalty")));
- }
- SqlCmd legacy = new SqlCmd(
- "select BJID,JCRQ D,sum(case when MS like :importMarker"
- + " then nvl(WJRS,0)/10 else nvl(WJRS,0) end) PENALTY"
- + " from XJB_FJRY"
- + " where JCRQ>=:start and JCRQ<:end"
- + " and JLZTM=51 group by BJID,JCRQ");
- legacy.wrStrParm("importMarker", ZHIXIN_STAR_MARKER_PREFIX + "%");
- legacy.wrTimeParm("start", start);
- legacy.wrTimeParm("end", end);
- for (Map<String, Object> row : db.doSelMapListByC(legacy)) {
- long bjid = rdLong(row.get("bjid"), 0L);
- LocalDate day = rdLocalDate(row.get("d"));
- if (day != null)
- result.legacy.computeIfAbsent(bjid, key -> new HashMap<>())
- .put(day, rdDouble(row.get("penalty")));
- }
- return result;
- }
- private Map<Long, Double> rdAttendanceScores(
- Db db, List<ClassRow> classes, Timestamp start, Timestamp end,
- XjbDormScoreU.AttendanceScope scope)
- 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")));
- Map<Long, Map<LocalDate, Double>> penalties =
- XjbDormScoreU.rdAttendancePenalty(
- db, start, end, scope);
- 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,
- Map<Long, Double> attendance)
- 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")));
- SqlCmd violationCmd = new SqlCmd(
- "select BJID,sum(PENALTY) PENALTY from ("
- + XjbWjjlU.dedupEventSql()
- + " where WJSJ>=:start and WJSJ<:end)"
- + " 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, 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;
- XjbDormScoreU.ManagementSummary management =
- XjbDormScoreU.rdManagementSummary(
- db, cls.bjid, start, end);
- DormScore score = new DormScore();
- score.value = round2(base + base / 85.0 * 10.0
- + management.bonus);
- score.internal = round2(internalScore);
- score.attendance = attend;
- score.violation = round2(violationScore);
- score.managementBonus = management.bonus;
- score.managementVisits = management.visitCount;
- score.managementSource = management.source;
- 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 and LYLX in('"
- + XjbJfServ.LYLX_TEAM_ROLE + "','"
- + XjbJfServ.LYLX_TEAM_MEMBER
- + "') then JFZ else 0 end) TEAM_BONUS,"
- + "sum(case when JFLX=1 and nvl(LYLX,'#') not in('"
- + XjbJfServ.LYLX_TEAM_ROLE + "','"
- + XjbJfServ.LYLX_TEAM_MEMBER
- + "') then JFZ else 0 end) OTHER_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.otherBonus = Math.max(
- 0.0, rdDouble(row.get("other_bonus")));
- total.teamBonus = Math.max(
- 0.0, rdDouble(row.get("team_bonus")));
- total.bonus = XjbJfServ.capBonus(
- total.otherBonus, total.teamBonus);
- 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 importedComponent(Object value, String detail) {
- Component item = new Component();
- item.value = value == null ? null : round2(rdDouble(value));
- item.source = value == null ? SOURCE_MISSING : SOURCE_THIRD;
- 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
- + ",管理增分" + score.managementBonus;
- 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.deptId, 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_JGMX", jdid);
- 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, String fwlx, long fwid,
- int version, Long previousId, String reason,
- 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(fwlx);
- po.setFwid(fwid);
- po.setPzid(rdFormulaPzId(db, month));
- po.setBb(version);
- po.setZt(JD_PUBLISHED);
- po.setMs(StringUtils.defaultIfBlank(reason, "星级班月结"));
- po.setCjsj(now);
- po.setFbsj(now);
- po.setJsryid(user == null ? null : user.ryid);
- po.setJsbmid(user == null ? null : user.bmid);
- po.setPrev_jdid(previousId);
- po.setGzyy(StringUtils.trimToNull(reason));
- Set<String> fields = new LinkedHashSet<>(Arrays.asList(
- "xjb_jdid", "ndy", "fwlx", "fwid", "pzid", "bb", "zt", "ms",
- "cjsj", "fbsj", "jsryid", "jsbmid", "prev_jdid", "gzyy"));
- db.doInsPo(po, fields);
- return id;
- }
- private long insertResult(Db db, long jdid, ClassResult result,
- UserRunB user) throws Exception {
- XjbJgPo jg = new XjbJgPo();
- long jgid = db.rdNextSeqVal("XJB_JGID");
- jg.setXjb_jgid(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 == null ? null : user.ryid);
- jg.setGlbmid(user == null ? null : 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.deptId == null
- ? result.cls.dwid : result.cls.deptId);
- 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);
- return jgid;
- }
- private long rdFormulaPzId(Db db, YearMonth month) throws Exception {
- Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
- Timestamp end = Timestamp.valueOf(
- month.plusMonths(1).atDay(1).atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select PZID from XJB_PZ where PZBB=:pzbb and JLZTM=51"
- + " and KSRQ<:end and (JSRQ is null or JSRQ>=:start)"
- + " order by KSRQ desc,PZID desc");
- sqlc.wrStrParm("pzbb", FORMULA_VERSION);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- db.doSelByC(sqlc);
- if (db.rowNum == 0)
- throw new IllegalStateException(
- "缺少星级班评分配置版本:" + FORMULA_VERSION);
- return db.rdLongCol("pzid");
- }
- private void insertResultDetail(Db db, long jdid, long jgid,
- ClassResult result, UserRunB user)
- throws Exception {
- int sx = 1;
- insertWeightedDetail(db, jdid, jgid, result, user, sx++,
- "DORM", "宿舍评分", result.dorm.value, 0.20,
- result.dorm.source, "常规项按20%计入总分");
- if (result.dormDetail != null) {
- sx = insertRawDetail(db, jdid, jgid, result, user, sx,
- "DORM_INTERNAL", "宿舍内务月均分",
- result.dormDetail.internal, SOURCE_REAL,
- "有效内务检查平均分");
- sx = insertRawDetail(db, jdid, jgid, result, user, sx,
- "DORM_ATTENDANCE", "住宿考勤分",
- result.dormDetail.attendance, SOURCE_REAL,
- "住校生在校考勤日平均分");
- sx = insertRawDetail(db, jdid, jgid, result, user, sx,
- "DORM_VIOLATION", "宿舍违纪得分",
- result.dormDetail.violation, SOURCE_REAL,
- "100减当月去重宿舍违纪扣分");
- sx = insertRawDetail(db, jdid, jgid, result, user, sx,
- "DORM_MANAGE", "宿舍管理增分",
- result.dormDetail.managementBonus,
- result.dormDetail.managementSource,
- "到宿有效参与5至7次加3分,8次及以上加5分");
- sx = insertRawDetail(db, jdid, jgid, result, user, sx,
- "DORM_MANAGE_VISITS", "宿舍管理有效次数",
- result.dormDetail.managementVisits,
- result.dormDetail.managementSource,
- "单次进入离开间隔不少于10分钟");
- sx = insertRawDetail(db, jdid, jgid, result, user, sx,
- "DORM_DEDUCTION", "宿舍其他减分", 0.0, "停",
- "学校暂未提供扣分规则");
- }
- sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
- "CLASSROOM", "课堂考核", result.classroom.value, 0.05,
- result.classroom.source, "常规项按5%计入总分");
- sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
- "FLAG", "升旗礼", result.flag.value, 0.14,
- result.flag.source, "常规项按14%计入总分");
- sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
- "CLEANING", "场室卫生", result.cleaning.value, 0.18,
- result.cleaning.source, "常规项按18%计入总分");
- sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
- "DISCIPLINE", "风纪仪容", result.discipline.value, 0.20,
- result.discipline.source, "常规项按20%计入总分");
- if (result.disciplineDetail != null) {
- sx = insertRawDetail(db, jdid, jgid, result, user, sx,
- "DISCIPLINE_PENALTY", "风纪扣分合计",
- result.disciplineDetail.violations, SOURCE_REAL,
- "当月风纪仪容扣分合计");
- sx = insertRawDetail(db, jdid, jgid, result, user, sx,
- "DISCIPLINE_DAYS", "风纪违纪天数",
- result.disciplineDetail.days, SOURCE_REAL,
- "当月发生风纪违纪的日期数");
- }
- sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
- "ATTENDANCE", "考勤", result.attendance.value, 0.15,
- result.attendance.source, "常规项按15%计入总分");
- double teamBonus = Math.max(0.0, result.adjust.teamBonus);
- double otherBonus = Math.max(0.0, result.adjust.otherBonus);
- sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx++,
- "TEAM_BONUS", "学生团体原始增分",
- teamBonus, Math.min(XjbJfServ.TEAM_BONUS_CAP, teamBonus),
- "TT", "团体原始事件合计,汇总前先封顶");
- sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx++,
- "OTHER_BONUS", "其他增分",
- otherBonus, otherBonus, "CALC", "非学生团体增分");
- sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx++,
- "BONUS_TOTAL", "增分合计",
- teamBonus + otherBonus, result.adjust.bonus,
- "CALC", "团体先封顶3分,总增分再封顶8分");
- sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx++,
- "DEDUCTION", "减分合计",
- result.adjust.deduction, -result.adjust.deduction,
- "CALC", "来源减分合计");
- sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx,
- "TOTAL", "月总分", result.total, result.total,
- "CALC", "六项加权增分封顶后减分;不设0分下限");
- }
- private int insertWeightedDetail(Db db, long jdid, long jgid,
- ClassResult result, UserRunB user,
- int sx, String code, String name,
- double raw, double weight,
- String source, String note)
- throws Exception {
- insertJgmx(db, jdid, jgid, result, user, sx, code, name,
- raw, weight, round2(raw * weight), source, note);
- return sx + 1;
- }
- private int insertRawDetail(Db db, long jdid, long jgid,
- ClassResult result, UserRunB user,
- int sx, String code, String name,
- double raw, String source, String note)
- throws Exception {
- insertJgmx(db, jdid, jgid, result, user, sx, code, name,
- raw, null, null, source, note);
- return sx + 1;
- }
- private int insertRawScoreDetail(Db db, long jdid, long jgid,
- ClassResult result, UserRunB user,
- int sx, String code, String name,
- double raw, double score,
- String source, String note)
- throws Exception {
- insertJgmx(db, jdid, jgid, result, user, sx, code, name,
- raw, null, round2(score), source, note);
- return sx + 1;
- }
- private void insertJgmx(Db db, long jdid, long jgid,
- ClassResult result, UserRunB user, int sx,
- String code, String name, double raw,
- Double weight, Double score, String source,
- String note) throws Exception {
- XjbJgmxPo mx = new XjbJgmxPo();
- mx.setJgmxid(db.rdNextSeqVal("XJB_JGMXID"));
- mx.setXjb_jdid(jdid);
- mx.setXjb_jgid(jgid);
- mx.setBjid(result.cls.bjid);
- mx.setNdy(result.ndy);
- mx.setXmbm(code);
- mx.setXmmc(name);
- mx.setYsz(round2(raw));
- mx.setQz(weight);
- mx.setDf(score);
- mx.setLylx(source);
- mx.setSm(note);
- mx.setSx(sx);
- mx.setCjryid(user == null ? null : user.ryid);
- mx.setCjbm_id(user == null ? null : user.bmid);
- mx.setJlsj(new java.sql.Date(System.currentTimeMillis()));
- Set<String> fields = new LinkedHashSet<>(Arrays.asList(
- "jgmxid", "xjb_jdid", "xjb_jgid", "bjid", "ndy",
- "xmbm", "xmmc", "ysz", "qz", "df", "lylx", "sm",
- "sx", "cjryid", "cjbm_id", "jlsj"));
- db.doInsPo(mx, fields);
- }
- private YearMonth rdLatestPublishedMonth(Db db) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select max(NDY) NDY from XJB_JD"
- + " where FWLX=:fwlx and FWID=:fwid and ZT=:status"
- + " and nvl(FBSJ,CJSJ)>=add_months("
- + "to_date(NDY||'-01','YYYY-MM-DD'),1)");
- sqlc.wrStrParm("fwlx", SCOPE_SCHOOL);
- sqlc.wrLongParm("fwid", SCHOOL_SCOPE_ID);
- sqlc.wrIntParm("status", JD_PUBLISHED);
- db.doSelByC(sqlc);
- String value = db.rowNum == 0 ? null : db.rdStrCol("ndy");
- if (StringUtils.isBlank(value)) {
- SqlCmd legacy = new SqlCmd(
- "select max(NDY) NDY from XJB_JD"
- + " where FWLX='BM' and ZT=:status");
- legacy.wrIntParm("status", JD_PUBLISHED);
- db.doSelByC(legacy);
- value = db.rowNum == 0 ? null : 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;
- final Long deptId;
- ClassRow(long bjid, String bjmc, Long dwid, Long zyid,
- Long deptId) {
- this.bjid = bjid;
- this.bjmc = bjmc;
- this.dwid = dwid;
- this.zyid = zyid;
- this.deptId = deptId;
- }
- }
- private static final class Component {
- Double value;
- String source = SOURCE_MISSING;
- String detail = "";
- }
- private static final class DisciplineScore {
- double value;
- double violations;
- int days;
- }
- private static final class DisciplinePenalties {
- final Map<Long, Map<LocalDate, Double>> mapped = new HashMap<>();
- final Map<Long, Map<LocalDate, Double>> legacy = new HashMap<>();
- }
- private static final class DormScore {
- double value;
- double internal;
- double attendance;
- double violation;
- int managementBonus;
- int managementVisits;
- String managementSource = XjbDormScoreU.SOURCE_UNAVAILABLE;
- }
- private static final class AdjustmentTotals {
- double bonus;
- double teamBonus;
- double otherBonus;
- double deduction;
- int bonusCount;
- int deductionCount;
- }
- private static final class ClassResult {
- final ClassRow cls;
- Component dorm;
- DormScore dormDetail;
- Component classroom;
- Component flag;
- Component cleaning;
- Component discipline;
- DisciplineScore disciplineDetail;
- 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;
- }
- }
- }
|