XjbMonthCloseServ.java 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. package biz.bj;
  2. import base.po.XjbJdPo;
  3. import base.po.XjbJgPo;
  4. import base.po.XjbJgmxPo;
  5. import base.po.XjbPmPo;
  6. import com.google.gson.Gson;
  7. import jakarta.servlet.http.HttpServletRequest;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.apache.logging.log4j.LogManager;
  10. import org.apache.logging.log4j.Logger;
  11. import ss.db.Db;
  12. import ss.db.SqlCmd;
  13. import ss.obj.ObjC;
  14. import ss.serv.Serv;
  15. import ss.serv.ServU;
  16. import ss.user.UserRunB;
  17. import ss.user.UserU;
  18. import java.io.Writer;
  19. import java.sql.Timestamp;
  20. import java.time.LocalDate;
  21. import java.time.YearMonth;
  22. import java.time.ZoneId;
  23. import java.time.format.DateTimeFormatter;
  24. import java.util.ArrayList;
  25. import java.util.Arrays;
  26. import java.util.Collections;
  27. import java.util.Comparator;
  28. import java.util.HashMap;
  29. import java.util.LinkedHashMap;
  30. import java.util.LinkedHashSet;
  31. import java.util.List;
  32. import java.util.Map;
  33. import java.util.Set;
  34. /**
  35. * 星级班月结、快照和 PC 查询。
  36. */
  37. public class XjbMonthCloseServ extends Serv {
  38. private static final Logger log4j =
  39. LogManager.getLogger(XjbMonthCloseServ.class);
  40. private static final ZoneId CN_ZONE = ZoneId.of("Asia/Shanghai");
  41. private static final DateTimeFormatter MONTH_FMT =
  42. DateTimeFormatter.ofPattern("yyyy-MM");
  43. private static final String SOURCE_REAL = "real";
  44. private static final String SOURCE_MISSING = "missing";
  45. private static final String SOURCE_THIRD = "third";
  46. private static final String ZHIXIN_STAR_MARKER_PREFIX = "ZHIXIN_STAR_";
  47. private static final String FORMULA_VERSION = "SC-2024-10-V1";
  48. private static final String SCOPE_SCHOOL = "XX";
  49. private static final long SCHOOL_SCOPE_ID = 0L;
  50. private static final int JD_DRAFT = 1;
  51. private static final int JD_PUBLISHED = 5;
  52. private static final int JD_SUPERSEDED = 6;
  53. /**
  54. * 对当前用户部门完成一个已结束月份的月结。
  55. */
  56. @SuppressWarnings("unused")
  57. public void closeByA() throws Exception {
  58. HttpServletRequest request = super.req;
  59. super.resp.setCharacterEncoding("UTF-8");
  60. super.resp.setContentType("application/json;charset=UTF-8");
  61. Writer writer = super.resp.getWriter();
  62. Gson gson = new Gson();
  63. try (Db db = Db.makeConn()) {
  64. UserRunB user = UserU.rdUserByReq(request);
  65. if (user == null)
  66. throw new IllegalArgumentException("登录状态已失效,请重新登录");
  67. if (user.bmid == null)
  68. throw new IllegalArgumentException("当前账号未关联部门");
  69. YearMonth month = rdMonth(request.getParameter("month"));
  70. if (!month.isBefore(YearMonth.now(CN_ZONE)))
  71. throw new IllegalArgumentException("只能月结已经结束的月份");
  72. long bmid = user.bmid;
  73. List<ClassRow> classes = rdDepartmentClasses(db, bmid);
  74. if (classes.isEmpty())
  75. throw new IllegalArgumentException("当前部门没有有效班级");
  76. if (hasPublishedBatch(db, month, bmid))
  77. throw new IllegalArgumentException("该部门该月份已发布,不能覆盖");
  78. XjbJfServ teamSnapshot = new XjbJfServ();
  79. for (ClassRow cls : classes)
  80. teamSnapshot.rebuildTeamSnapshot(db, cls.bjid, month, user);
  81. List<ClassResult> results = calculate(db, classes, month);
  82. ensureComplete(results);
  83. assignRanks(results);
  84. deleteDraftBatch(db, month, bmid);
  85. long jdid = insertBatch(db, month, "BM", bmid, 1,
  86. null, "部门星级班月结", user);
  87. for (ClassResult result : results) {
  88. long jgid = insertResult(db, jdid, result, user);
  89. insertResultDetail(db, jdid, jgid, result, user);
  90. }
  91. db.commit();
  92. Map<String, Object> data = new LinkedHashMap<>();
  93. data.put("jdid", jdid);
  94. data.put("month", month.format(MONTH_FMT));
  95. data.put("bmid", bmid);
  96. data.put("classCount", results.size());
  97. data.put("status", JD_PUBLISHED);
  98. ServU.wrOkDataByWriter(data, writer, gson);
  99. } catch (IllegalArgumentException e) {
  100. ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
  101. } catch (Exception e) {
  102. log4j.error("XjbMonthCloseServ.closeByA() 异常", e);
  103. ServU.wrErrMsgByWriter(null, "星级班月结失败", writer, gson);
  104. }
  105. }
  106. /**
  107. * 手工补算或测试环境触发全校月结。
  108. */
  109. @SuppressWarnings("unused")
  110. public void closeSchoolByA() throws Exception {
  111. HttpServletRequest request = super.req;
  112. super.resp.setCharacterEncoding("UTF-8");
  113. super.resp.setContentType("application/json;charset=UTF-8");
  114. Writer writer = super.resp.getWriter();
  115. Gson gson = new Gson();
  116. try (Db db = Db.makeConn()) {
  117. UserRunB user = UserU.rdUserByReq(request);
  118. if (user == null)
  119. throw new IllegalArgumentException("登录状态已失效,请重新登录");
  120. YearMonth month = rdMonth(request.getParameter("month"));
  121. Long impid = rdLongOrNull(request.getParameter("impid"));
  122. Map<String, Object> data = closeSchoolMonth(
  123. db, month, user, false,
  124. impid == null ? "星级班全校月结"
  125. : "第三方星级班导入验证",
  126. impid);
  127. if (Boolean.TRUE.equals(data.get("created")))
  128. db.commit();
  129. ServU.wrOkDataByWriter(data, writer, gson);
  130. } catch (IllegalArgumentException e) {
  131. ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
  132. } catch (Exception e) {
  133. log4j.error("XjbMonthCloseServ.closeSchoolByA() 异常", e);
  134. ServU.wrErrMsgByWriter(null, "全校星级班月结失败", writer, gson);
  135. }
  136. }
  137. /**
  138. * 生成同一月份的更正版本,不覆盖原正式快照。
  139. */
  140. @SuppressWarnings("unused")
  141. public void correctSchoolByA() throws Exception {
  142. HttpServletRequest request = super.req;
  143. super.resp.setCharacterEncoding("UTF-8");
  144. super.resp.setContentType("application/json;charset=UTF-8");
  145. Writer writer = super.resp.getWriter();
  146. Gson gson = new Gson();
  147. try (Db db = Db.makeConn()) {
  148. UserRunB user = UserU.rdUserByReq(request);
  149. if (user == null)
  150. throw new IllegalArgumentException("登录状态已失效,请重新登录");
  151. YearMonth month = rdMonth(request.getParameter("month"));
  152. String reason = StringUtils.trimToNull(request.getParameter("reason"));
  153. if (reason == null)
  154. throw new IllegalArgumentException("请填写更正原因");
  155. Map<String, Object> data = closeSchoolMonth(
  156. db, month, user, true, reason);
  157. db.commit();
  158. ServU.wrOkDataByWriter(data, writer, gson);
  159. } catch (IllegalArgumentException e) {
  160. ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
  161. } catch (Exception e) {
  162. log4j.error("XjbMonthCloseServ.correctSchoolByA() 异常", e);
  163. ServU.wrErrMsgByWriter(null, "星级班月结更正失败", writer, gson);
  164. }
  165. }
  166. /**
  167. * 定时任务入口:每月 1 日生成上个月全校月结。
  168. */
  169. @SuppressWarnings("unused")
  170. public void closeSchoolByTimer() throws Exception {
  171. YearMonth month = YearMonth.now(CN_ZONE).minusMonths(1);
  172. try (Db db = Db.makeConn()) {
  173. Map<String, Object> data = closeSchoolMonth(
  174. db, month, null, false, "星级班全校自动月结");
  175. if (Boolean.TRUE.equals(data.get("created")))
  176. db.commit();
  177. log4j.info("星级班全校月结任务完成,月份={},班级数={},批次={},"
  178. + "是否新生成={}",
  179. data.get("month"), data.get("classCount"),
  180. data.get("batchId"), data.get("created"));
  181. } catch (Exception e) {
  182. log4j.error("XjbMonthCloseServ.closeSchoolByTimer() 异常,月份={}",
  183. month, e);
  184. throw e;
  185. }
  186. }
  187. /**
  188. * PC 星级班总表只读取已发布月结。
  189. */
  190. @SuppressWarnings("unused")
  191. public void pcSummaryByA() throws Exception {
  192. HttpServletRequest request = super.req;
  193. super.resp.setCharacterEncoding("UTF-8");
  194. super.resp.setContentType("application/json;charset=UTF-8");
  195. Writer writer = super.resp.getWriter();
  196. Gson gson = new Gson();
  197. try (Db db = Db.makeConn()) {
  198. UserRunB user = UserU.rdUserByReq(request);
  199. if (user == null)
  200. throw new IllegalArgumentException("登录状态已失效,请重新登录");
  201. String monthText = StringUtils.trimToNull(request.getParameter("month"));
  202. YearMonth month;
  203. if (monthText == null) {
  204. month = rdLatestPublishedMonth(db);
  205. if (month == null)
  206. throw new IllegalArgumentException("暂无已发布星级班月结");
  207. } else {
  208. month = rdMonth(monthText);
  209. }
  210. SqlCmd batchCmd = new SqlCmd(
  211. "select XJB_JDID,NDY,FWLX,FWID,BB,ZT,FBSJ,GZYY"
  212. + " from XJB_JD where NDY=:ndy and FWLX=:fwlx"
  213. + " and FWID=:fwid and ZT=:status"
  214. + " and nvl(FBSJ,CJSJ)>=:minPublish"
  215. + " order by BB desc,XJB_JDID desc");
  216. batchCmd.wrStrParm("ndy", month.format(MONTH_FMT));
  217. batchCmd.wrStrParm("fwlx", SCOPE_SCHOOL);
  218. batchCmd.wrLongParm("fwid", SCHOOL_SCOPE_ID);
  219. batchCmd.wrIntParm("status", JD_PUBLISHED);
  220. batchCmd.wrTimeParm("minPublish", Timestamp.valueOf(
  221. month.plusMonths(1).atDay(1).atStartOfDay()));
  222. List<Map<String, Object>> batches =
  223. db.doSelMapListByC(batchCmd);
  224. boolean legacyDepartmentScope = false;
  225. if (batches == null || batches.isEmpty()) {
  226. SqlCmd legacyCmd = new SqlCmd(
  227. "select XJB_JDID,NDY,FWLX,FWID,BB,ZT,FBSJ,GZYY"
  228. + " from XJB_JD where NDY=:ndy"
  229. + " and FWLX='BM' and ZT=:status"
  230. + " and nvl(FBSJ,CJSJ)>=:minPublish"
  231. + " order by BB desc,XJB_JDID desc");
  232. legacyCmd.wrStrParm("ndy", month.format(MONTH_FMT));
  233. legacyCmd.wrIntParm("status", JD_PUBLISHED);
  234. legacyCmd.wrTimeParm("minPublish", Timestamp.valueOf(
  235. month.plusMonths(1).atDay(1).atStartOfDay()));
  236. batches = db.doSelMapListByC(legacyCmd);
  237. legacyDepartmentScope = true;
  238. }
  239. if (batches == null || batches.isEmpty())
  240. throw new IllegalArgumentException("该月份暂无已发布月结");
  241. Map<String, Object> batch = batches.get(0);
  242. long jdid = rdLong(batch.get("xjb_jdid"), 0L);
  243. SqlCmd sqlc = new SqlCmd(
  244. "select j.BJID,b.MC BJMC,nvl(bm.MC,'') DWMC,"
  245. + "nvl(z.MC,'') ZYMC,j.SSDF,j.KTDF,j.SJDF,j.CSDF,"
  246. + "j.FJDF,j.KQDF,j.ZJF,j.KJF,j.ZF,j.XJ,"
  247. + "j.ZJFCS,j.KJFCS,j.QXSM,p.DWPM,p.DWCS,p.XXPM,p.XXCS"
  248. + " from XJB_JG j"
  249. + " inner join BJ b on b.BJID=j.BJID"
  250. + " left join ZY z on z.ZYID=j.ZYID"
  251. + " left join BM bm on bm.BMID=z.FZBMID"
  252. + " left join XJB_PM p on p.XJB_JDID=j.XJB_JDID"
  253. + " and p.BJID=j.BJID"
  254. + " where j.XJB_JDID=:jdid and j.ZT=:status"
  255. + " order by p.XXPM,j.BJID");
  256. sqlc.wrLongParm("jdid", jdid);
  257. sqlc.wrIntParm("status", JD_PUBLISHED);
  258. List<Map<String, Object>> rows = new ArrayList<>();
  259. Set<String> departments = new LinkedHashSet<>();
  260. Set<String> majors = new LinkedHashSet<>();
  261. Set<String> classes = new LinkedHashSet<>();
  262. Set<String> stars = new LinkedHashSet<>();
  263. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  264. Map<String, Object> item = new LinkedHashMap<>();
  265. item.put("bjid", rdLong(row.get("bjid"), 0L));
  266. item.put("department", rdStr(row.get("dwmc")));
  267. item.put("major", rdStr(row.get("zymc")));
  268. item.put("className", rdStr(row.get("bjmc")));
  269. item.put("dormScore", formatScore(row.get("ssdf")));
  270. item.put("classroomScore", formatScore(row.get("ktdf")));
  271. item.put("flagCeremonyScore", formatScore(row.get("sjdf")));
  272. item.put("cleaningScore", formatScore(row.get("csdf")));
  273. item.put("disciplineScore", formatScore(row.get("fjdf")));
  274. item.put("attendanceScore", formatScore(row.get("kqdf")));
  275. item.put("bonus", formatScore(row.get("zjf")));
  276. item.put("deduction", formatScore(row.get("kjf")));
  277. item.put("monthTotal", formatScore(row.get("zf")));
  278. item.put("starLevel", rdStr(row.get("xj")));
  279. item.put("departmentRank", rdStr(row.get("dwpm")));
  280. item.put("departmentClassCount", rdStr(row.get("dwcs")));
  281. item.put("schoolRank", rdStr(row.get("xxpm")));
  282. item.put("schoolClassCount", rdStr(row.get("xxcs")));
  283. item.put("bonusCount", rdStr(row.get("zjfcs")));
  284. item.put("deductionCount", rdStr(row.get("kjfcs")));
  285. item.put("missing", rdStr(row.get("qxsm")));
  286. rows.add(item);
  287. addNonBlank(departments, item.get("department"));
  288. addNonBlank(majors, item.get("major"));
  289. addNonBlank(classes, item.get("className"));
  290. addNonBlank(stars, item.get("starLevel"));
  291. }
  292. Map<String, Object> data = new LinkedHashMap<>();
  293. data.put("month", month.format(MONTH_FMT));
  294. data.put("batchId", jdid);
  295. data.put("version", rdInt(batch.get("bb")));
  296. data.put("status", "已发布");
  297. data.put("legacyDepartmentScope", legacyDepartmentScope);
  298. data.put("publishedAt", formatTimestamp(batch.get("fbsj")));
  299. data.put("correctionReason", rdStr(batch.get("gzyy")));
  300. data.put("rows", rows);
  301. data.put("departments", new ArrayList<>(departments));
  302. data.put("majors", new ArrayList<>(majors));
  303. data.put("classes", new ArrayList<>(classes));
  304. data.put("stars", new ArrayList<>(stars));
  305. ServU.wrOkDataByWriter(data, writer, gson);
  306. } catch (IllegalArgumentException e) {
  307. ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
  308. } catch (Exception e) {
  309. log4j.error("XjbMonthCloseServ.pcSummaryByA() 异常", e);
  310. ServU.wrErrMsgByWriter(null, "星级班月结报表加载失败", writer, gson);
  311. }
  312. }
  313. private Map<String, Object> closeSchoolMonth(
  314. Db db, YearMonth month, UserRunB user, boolean correction,
  315. String reason) throws Exception {
  316. return closeSchoolMonth(db, month, user, correction, reason, null);
  317. }
  318. private Map<String, Object> closeSchoolMonth(
  319. Db db, YearMonth month, UserRunB user, boolean correction,
  320. String reason, Long impid) throws Exception {
  321. if (!month.isBefore(YearMonth.now(CN_ZONE)))
  322. throw new IllegalArgumentException("只能月结已经结束的月份");
  323. Map<String, Object> current = rdCurrentSchoolBatch(db, month);
  324. if (current != null && !correction) {
  325. Map<String, Object> skipped = new LinkedHashMap<>();
  326. skipped.put("month", month.format(MONTH_FMT));
  327. skipped.put("batchId", rdLong(current.get("xjb_jdid"), 0L));
  328. skipped.put("version", rdInt(current.get("bb")));
  329. skipped.put("status", JD_PUBLISHED);
  330. skipped.put("created", false);
  331. skipped.put("classCount", rdInt(current.get("class_count")));
  332. skipped.put("reason", rdStr(current.get("gzyy")));
  333. return skipped;
  334. }
  335. List<ClassRow> classes = impid == null
  336. ? rdSchoolClasses(db)
  337. : rdImportedClasses(db, month, impid);
  338. if (classes.isEmpty())
  339. throw new IllegalArgumentException("没有可月结的在用班级");
  340. List<ClassResult> results;
  341. if (impid == null) {
  342. XjbJfServ teamSnapshot = new XjbJfServ();
  343. for (ClassRow cls : classes)
  344. teamSnapshot.rebuildTeamSnapshot(db, cls.bjid, month, user);
  345. results = calculate(db, classes, month);
  346. } else {
  347. results = calculateImported(db, classes, month, impid);
  348. }
  349. ensureComplete(results);
  350. assignRanks(results);
  351. Long previousId = null;
  352. int version = 1;
  353. if (current != null) {
  354. previousId = rdLong(current.get("xjb_jdid"), 0L);
  355. version = Math.max(1, rdInt(current.get("bb"))) + 1;
  356. markBatchSuperseded(db, previousId);
  357. }
  358. long jdid = insertBatch(db, month, SCOPE_SCHOOL, SCHOOL_SCOPE_ID,
  359. version, previousId, reason, user);
  360. for (ClassResult result : results) {
  361. long jgid = insertResult(db, jdid, result, user);
  362. insertResultDetail(db, jdid, jgid, result, user);
  363. }
  364. Map<String, Object> data = new LinkedHashMap<>();
  365. data.put("month", month.format(MONTH_FMT));
  366. data.put("batchId", jdid);
  367. data.put("version", version);
  368. data.put("status", JD_PUBLISHED);
  369. data.put("created", true);
  370. data.put("classCount", results.size());
  371. data.put("previousBatchId", previousId);
  372. data.put("reason", StringUtils.defaultString(reason));
  373. return data;
  374. }
  375. private Map<String, Object> rdCurrentSchoolBatch(
  376. Db db, YearMonth month) throws Exception {
  377. SqlCmd sqlc = new SqlCmd(
  378. "select j.XJB_JDID,j.BB,j.ZT,j.GZYY,"
  379. + "(select count(*) from XJB_JG g"
  380. + " where g.XJB_JDID=j.XJB_JDID and g.ZT=:jgStatus)"
  381. + " CLASS_COUNT from XJB_JD j"
  382. + " where j.NDY=:ndy and j.FWLX=:fwlx"
  383. + " and j.FWID=:fwid and j.ZT=:status"
  384. + " and nvl(j.FBSJ,j.CJSJ)>=:minPublish"
  385. + " order by j.BB desc,j.XJB_JDID desc");
  386. sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
  387. sqlc.wrStrParm("fwlx", SCOPE_SCHOOL);
  388. sqlc.wrLongParm("fwid", SCHOOL_SCOPE_ID);
  389. sqlc.wrIntParm("status", JD_PUBLISHED);
  390. sqlc.wrIntParm("jgStatus", JD_PUBLISHED);
  391. sqlc.wrTimeParm("minPublish", Timestamp.valueOf(
  392. month.plusMonths(1).atDay(1).atStartOfDay()));
  393. List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
  394. return rows == null || rows.isEmpty() ? null : rows.get(0);
  395. }
  396. private List<ClassRow> rdSchoolClasses(Db db) throws Exception {
  397. SqlCmd sqlc = new SqlCmd(
  398. "select b.BJID,b.MC BJMC,b.DWID,b.ZYID,z.FZBMID DEPTID"
  399. + " from BJ b"
  400. + " inner join ZY z on z.ZYID=b.ZYID"
  401. + " where b." + ObjC.JLZT_useStr
  402. + " and b.BJZTM!=81 order by b.MC,b.BJID");
  403. List<ClassRow> rows = new ArrayList<>();
  404. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  405. rows.add(new ClassRow(
  406. rdLong(row.get("bjid"), 0L),
  407. rdStr(row.get("bjmc")),
  408. rdLongOrNull(row.get("dwid")),
  409. rdLongOrNull(row.get("zyid")),
  410. rdLongOrNull(row.get("deptid"))));
  411. }
  412. ensureSchoolClassMasterData(db, rows.size());
  413. return rows;
  414. }
  415. private void ensureSchoolClassMasterData(Db db, int joinableCount)
  416. throws Exception {
  417. SqlCmd countCmd = new SqlCmd(
  418. "select count(*) CNT from BJ b where b."
  419. + ObjC.JLZT_useStr + " and b.BJZTM!=81");
  420. db.doSelByC(countCmd);
  421. int activeCount = db.rowNum == 0 ? 0 : db.rdIntCol("cnt");
  422. if (activeCount == joinableCount)
  423. return;
  424. SqlCmd missingCmd = new SqlCmd(
  425. "select b.BJID,b.MC from BJ b"
  426. + " left join ZY z on z.ZYID=b.ZYID"
  427. + " where b." + ObjC.JLZT_useStr
  428. + " and b.BJZTM!=81 and z.ZYID is null"
  429. + " order by b.BJID");
  430. StringBuilder message = new StringBuilder(
  431. "在用班级主数据不完整:在用班 ")
  432. .append(activeCount)
  433. .append(" 个,具备有效专业关系 ")
  434. .append(joinableCount)
  435. .append(" 个");
  436. List<Map<String, Object>> missing = db.doSelMapListByC(missingCmd);
  437. if (missing != null && !missing.isEmpty()) {
  438. message.append(";缺少专业关系:");
  439. for (int i = 0; i < Math.min(10, missing.size()); i++) {
  440. if (i > 0)
  441. message.append("、");
  442. message.append(rdStr(missing.get(i).get("MC")))
  443. .append("(")
  444. .append(rdLong(missing.get(i).get("bjid"), 0L))
  445. .append(")");
  446. }
  447. if (missing.size() > 10)
  448. message.append(" 等");
  449. }
  450. throw new IllegalStateException(message.toString());
  451. }
  452. private List<ClassRow> rdImportedClasses(Db db, YearMonth month, long impid)
  453. throws Exception {
  454. SqlCmd sqlc = new SqlCmd(
  455. "select b.BJID,b.MC BJMC,b.DWID,b.ZYID,z.FZBMID DEPTID"
  456. + " from XJB_IMP_WB w"
  457. + " inner join BJ b on b.BJID=w.BJID"
  458. + " inner join ZY z on z.ZYID=b.ZYID"
  459. + " where w.IMPID=:impid and w.NDY=:ndy"
  460. + " and b." + ObjC.JLZT_useStr
  461. + " and b.BJZTM!=81"
  462. + " order by b.MC,b.BJID");
  463. sqlc.wrLongParm("impid", impid);
  464. sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
  465. List<ClassRow> rows = new ArrayList<>();
  466. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  467. rows.add(new ClassRow(
  468. rdLong(row.get("bjid"), 0L),
  469. rdStr(row.get("bjmc")),
  470. rdLongOrNull(row.get("dwid")),
  471. rdLongOrNull(row.get("zyid")),
  472. rdLongOrNull(row.get("deptid"))));
  473. }
  474. return rows;
  475. }
  476. private List<ClassResult> calculateImported(
  477. Db db, List<ClassRow> classes, YearMonth month, long impid)
  478. throws Exception {
  479. SqlCmd sqlc = new SqlCmd(
  480. "select BJID,KQDF,FJDF,CSDF,SJDF,SSDF,KTDF,"
  481. + "ZJF,KJF,ZJFCS,KJFCS,THIRD_ZF,THIRD_XJ"
  482. + " from XJB_IMP_WB"
  483. + " where IMPID=:impid and NDY=:ndy");
  484. sqlc.wrLongParm("impid", impid);
  485. sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
  486. Map<Long, Map<String, Object>> imported = new HashMap<>();
  487. for (Map<String, Object> row : db.doSelMapListByC(sqlc))
  488. imported.put(rdLong(row.get("bjid"), 0L), row);
  489. List<ClassResult> result = new ArrayList<>();
  490. for (ClassRow cls : classes) {
  491. ClassResult item = new ClassResult(cls);
  492. item.ndy = month.format(MONTH_FMT);
  493. Map<String, Object> row = imported.get(cls.bjid);
  494. if (row == null) {
  495. item.dorm = component(null, "第三方月结快照");
  496. item.classroom = component(null, "第三方月结快照");
  497. item.flag = component(null, "第三方月结快照");
  498. item.cleaning = component(null, "第三方月结快照");
  499. item.discipline = component(null, "第三方月结快照");
  500. item.attendance = component(null, "第三方月结快照");
  501. } else {
  502. item.dorm = importedComponent(row.get("ssdf"),
  503. "第三方月结宿舍评分");
  504. item.classroom = importedComponent(row.get("ktdf"),
  505. "第三方月结课堂考核");
  506. item.flag = importedComponent(row.get("sjdf"),
  507. "第三方月结升旗礼");
  508. item.cleaning = importedComponent(row.get("csdf"),
  509. "第三方月结场室卫生");
  510. item.discipline = importedComponent(row.get("fjdf"),
  511. "第三方月结风纪仪容");
  512. item.attendance = importedComponent(row.get("kqdf"),
  513. "第三方月结考勤");
  514. item.adjust.otherBonus = Math.max(
  515. 0.0, rdDouble(row.get("zjf")));
  516. item.adjust.bonus = XjbJfServ.capBonus(
  517. item.adjust.otherBonus, 0.0);
  518. item.adjust.deduction = Math.max(
  519. 0.0, rdDouble(row.get("kjf")));
  520. item.adjust.bonusCount = rdInt(row.get("zjfcs"));
  521. item.adjust.deductionCount = rdInt(row.get("kjfcs"));
  522. }
  523. addMissing(item, "宿舍评分", item.dorm);
  524. addMissing(item, "课堂考核", item.classroom);
  525. addMissing(item, "升旗礼", item.flag);
  526. addMissing(item, "场室卫生", item.cleaning);
  527. addMissing(item, "风纪仪容", item.discipline);
  528. addMissing(item, "考勤", item.attendance);
  529. if (item.missing.isEmpty()) {
  530. double weighted = item.dorm.value * 0.20
  531. + item.classroom.value * 0.05
  532. + item.flag.value * 0.14
  533. + item.cleaning.value * 0.18
  534. + item.discipline.value * 0.20
  535. + item.attendance.value * 0.15;
  536. item.total = round2(weighted
  537. + Math.min(8.0, item.adjust.bonus)
  538. - item.adjust.deduction);
  539. }
  540. result.add(item);
  541. }
  542. return result;
  543. }
  544. private void ensureComplete(List<ClassResult> results) {
  545. List<ClassResult> missing = new ArrayList<>();
  546. for (ClassResult result : results) {
  547. if (!result.missing.isEmpty())
  548. missing.add(result);
  549. }
  550. if (missing.isEmpty())
  551. return;
  552. StringBuilder message = new StringBuilder("月结数据不完整,");
  553. message.append(missing.size()).append(" 个班级未生成:");
  554. for (int i = 0; i < Math.min(5, missing.size()); i++) {
  555. if (i > 0)
  556. message.append(";");
  557. ClassResult item = missing.get(i);
  558. message.append(item.cls.bjmc).append("[")
  559. .append(String.join("、", item.missing))
  560. .append("]");
  561. }
  562. if (missing.size() > 5)
  563. message.append(" 等");
  564. throw new IllegalArgumentException(message.toString());
  565. }
  566. private void markBatchSuperseded(Db db, long jdid) throws Exception {
  567. SqlCmd sqlc = new SqlCmd(
  568. "update XJB_JD set ZT=:superseded"
  569. + " where XJB_JDID=:id and ZT=:published");
  570. sqlc.wrIntParm("superseded", JD_SUPERSEDED);
  571. sqlc.wrLongParm("id", jdid);
  572. sqlc.wrIntParm("published", JD_PUBLISHED);
  573. db.doModByC(sqlc);
  574. }
  575. private List<ClassRow> rdDepartmentClasses(Db db, long bmid)
  576. throws Exception {
  577. SqlCmd sqlc = new SqlCmd(
  578. "select b.BJID,b.MC BJMC,b.DWID,b.ZYID,z.FZBMID DEPTID"
  579. + " from BJ b"
  580. + " inner join ZY z on z.ZYID=b.ZYID"
  581. + " where z.FZBMID=:bmid and b." + ObjC.JLZT_useStr
  582. + " and b.BJZTM!=81 order by b.MC,b.BJID");
  583. sqlc.wrLongParm("bmid", bmid);
  584. List<ClassRow> rows = new ArrayList<>();
  585. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  586. rows.add(new ClassRow(
  587. rdLong(row.get("bjid"), 0L),
  588. rdStr(row.get("bjmc")),
  589. rdLongOrNull(row.get("dwid")),
  590. rdLongOrNull(row.get("zyid")),
  591. rdLongOrNull(row.get("deptid"))));
  592. }
  593. return rows;
  594. }
  595. private List<ClassResult> calculate(Db db, List<ClassRow> classes,
  596. YearMonth month) throws Exception {
  597. Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
  598. Timestamp end = Timestamp.valueOf(
  599. month.plusMonths(1).atDay(1).atStartOfDay());
  600. Map<Long, Double> classroom = rdAvg(db,
  601. "select j.BJID,avg(j.FS) SCORE from KTJL j"
  602. + " inner join KCB k on k.KCBID=j.KCBID"
  603. + " where k.KSSJ>=:start and k.KSSJ<:end"
  604. + " and j." + ObjC.JLZT_useStr
  605. + " and k." + ObjC.JLZT_useStr
  606. + " group by j.BJID", start, end);
  607. Map<Long, Double> flag = rdAvg(db,
  608. "select BJID,avg(ZFS) SCORE from SQLJC"
  609. + " where JCSJ>=:start and JCSJ<:end"
  610. + " and ZFS between 0 and 100 and "
  611. + ObjC.JLZT_useStr + " group by BJID", start, end);
  612. Map<Long, Double> cleaning = rdAvg(db,
  613. "select BJID,avg(FS) SCORE from CSWSJC"
  614. + " where JCSJ>=:start and JCSJ<:end and "
  615. + ObjC.JLZT_useStr + " group by BJID", start, end);
  616. Set<LocalDate> schoolDays = rdSchoolDays(db, start, end);
  617. Map<Long, DisciplineScore> discipline =
  618. rdDisciplineScores(db, classes, schoolDays, start, end);
  619. Map<Long, Double> attendance = rdAttendanceScores(db, classes,
  620. start, end,
  621. XjbDormScoreU.AttendanceScope.DAY_STUDENT);
  622. Map<Long, Double> dormAttendance = rdAttendanceScores(db, classes,
  623. start, end,
  624. XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
  625. Map<Long, DormScore> dorm = rdDormScores(
  626. db, classes, start, end, dormAttendance);
  627. Map<Long, AdjustmentTotals> adjustments =
  628. rdAdjustmentTotals(db, month);
  629. List<ClassResult> result = new ArrayList<>();
  630. for (ClassRow cls : classes) {
  631. ClassResult item = new ClassResult(cls);
  632. item.ndy = month.format(MONTH_FMT);
  633. item.dorm = dormComponent(dorm.get(cls.bjid));
  634. item.dormDetail = dorm.get(cls.bjid);
  635. item.classroom = component(classroom.get(cls.bjid),
  636. "课堂日志");
  637. item.flag = component(flag.get(cls.bjid), "升旗礼");
  638. item.cleaning = component(cleaning.get(cls.bjid), "场室卫生");
  639. item.discipline = disciplineComponent(discipline.get(cls.bjid));
  640. item.disciplineDetail = discipline.get(cls.bjid);
  641. item.attendance = component(attendance.get(cls.bjid), "考勤");
  642. item.adjust = adjustments.getOrDefault(cls.bjid,
  643. new AdjustmentTotals());
  644. addMissing(item, "宿舍评分", item.dorm);
  645. addMissing(item, "课堂考核", item.classroom);
  646. addMissing(item, "升旗礼", item.flag);
  647. addMissing(item, "场室卫生", item.cleaning);
  648. addMissing(item, "风纪仪容", item.discipline);
  649. addMissing(item, "考勤", item.attendance);
  650. if (item.missing.isEmpty()) {
  651. double weighted = item.dorm.value * 0.20
  652. + item.classroom.value * 0.05
  653. + item.flag.value * 0.14
  654. + item.cleaning.value * 0.18
  655. + item.discipline.value * 0.20
  656. + item.attendance.value * 0.15;
  657. item.total = round2(weighted
  658. + Math.min(8.0, item.adjust.bonus)
  659. - item.adjust.deduction);
  660. }
  661. result.add(item);
  662. }
  663. return result;
  664. }
  665. private Map<Long, Double> rdAvg(Db db, String sql,
  666. Timestamp start, Timestamp end)
  667. throws Exception {
  668. SqlCmd sqlc = new SqlCmd(sql);
  669. sqlc.wrTimeParm("start", start);
  670. sqlc.wrTimeParm("end", end);
  671. Map<Long, Double> result = new HashMap<>();
  672. for (Map<String, Object> row : db.doSelMapListByC(sqlc))
  673. result.put(rdLong(row.get("bjid"), 0L),
  674. round2(rdDouble(row.get("score"))));
  675. return result;
  676. }
  677. private Map<Long, DisciplineScore> rdDisciplineScores(
  678. Db db, List<ClassRow> classes, Set<LocalDate> schoolDays,
  679. Timestamp start, Timestamp end) throws Exception {
  680. Map<Long, DisciplineScore> result = new HashMap<>();
  681. if (schoolDays.isEmpty())
  682. return result;
  683. DisciplinePenalties penalties = rdDisciplinePenalties(
  684. db, start, end);
  685. for (ClassRow cls : classes) {
  686. Map<LocalDate, Double> mapped = penalties.mapped.getOrDefault(
  687. cls.bjid, Collections.emptyMap());
  688. Map<LocalDate, Double> legacy = penalties.legacy.getOrDefault(
  689. cls.bjid, Collections.emptyMap());
  690. Set<LocalDate> violationDays = new LinkedHashSet<>(mapped.keySet());
  691. violationDays.addAll(legacy.keySet());
  692. double totalScore = 0.0;
  693. double totalPenalty = 0.0;
  694. for (LocalDate day : schoolDays) {
  695. Double dayPenalty = mapped.get(day);
  696. if (dayPenalty == null)
  697. dayPenalty = legacy.get(day);
  698. if (dayPenalty == null)
  699. dayPenalty = 0.0;
  700. totalPenalty += dayPenalty;
  701. totalScore += Math.max(0.0, 100.0 - dayPenalty);
  702. }
  703. DisciplineScore score = new DisciplineScore();
  704. score.value = round2(totalScore / schoolDays.size());
  705. score.violations = round2(totalPenalty);
  706. score.days = violationDays.size();
  707. result.put(cls.bjid, score);
  708. }
  709. return result;
  710. }
  711. private Set<LocalDate> rdSchoolDays(
  712. Db db, Timestamp start, Timestamp end) throws Exception {
  713. SqlCmd sqlc = new SqlCmd(
  714. "select distinct trunc(KSSJ) D from KQJL"
  715. + " where KSSJ>=:start and KSSJ<:end"
  716. + " and KQJLZTM=51 and " + ObjC.JLZT_useStr);
  717. sqlc.wrTimeParm("start", start);
  718. sqlc.wrTimeParm("end", end);
  719. Set<LocalDate> result = new LinkedHashSet<>();
  720. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  721. LocalDate day = rdLocalDate(row.get("d"));
  722. if (day != null)
  723. result.add(day);
  724. }
  725. return result;
  726. }
  727. private DisciplinePenalties rdDisciplinePenalties(
  728. Db db, Timestamp start, Timestamp end) throws Exception {
  729. DisciplinePenalties result = new DisciplinePenalties();
  730. SqlCmd current = new SqlCmd(
  731. "select w.BJID,trunc(w.WJSJ) D,sum(nvl(lb.BJKF,0)) PENALTY"
  732. + " from WJJL w"
  733. + " inner join WJLB lb on lb.WJLBM=w.WJLBM"
  734. + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
  735. + " and wm.YTM=" + XjbWjlbC.YTM_DISCIPLINE
  736. + " and wm.JLZTM=51"
  737. + " where w.WJSJ>=:start and w.WJSJ<:end"
  738. + " and w.JLZTM=51 group by w.BJID,trunc(w.WJSJ)");
  739. current.wrTimeParm("start", start);
  740. current.wrTimeParm("end", end);
  741. for (Map<String, Object> row : db.doSelMapListByC(current)) {
  742. long bjid = rdLong(row.get("bjid"), 0L);
  743. LocalDate day = rdLocalDate(row.get("d"));
  744. if (day != null)
  745. result.mapped.computeIfAbsent(bjid, key -> new HashMap<>())
  746. .put(day, rdDouble(row.get("penalty")));
  747. }
  748. SqlCmd legacy = new SqlCmd(
  749. "select BJID,JCRQ D,sum(case when MS like :importMarker"
  750. + " then nvl(WJRS,0)/10 else nvl(WJRS,0) end) PENALTY"
  751. + " from XJB_FJRY"
  752. + " where JCRQ>=:start and JCRQ<:end"
  753. + " and JLZTM=51 group by BJID,JCRQ");
  754. legacy.wrStrParm("importMarker", ZHIXIN_STAR_MARKER_PREFIX + "%");
  755. legacy.wrTimeParm("start", start);
  756. legacy.wrTimeParm("end", end);
  757. for (Map<String, Object> row : db.doSelMapListByC(legacy)) {
  758. long bjid = rdLong(row.get("bjid"), 0L);
  759. LocalDate day = rdLocalDate(row.get("d"));
  760. if (day != null)
  761. result.legacy.computeIfAbsent(bjid, key -> new HashMap<>())
  762. .put(day, rdDouble(row.get("penalty")));
  763. }
  764. return result;
  765. }
  766. private Map<Long, Double> rdAttendanceScores(
  767. Db db, List<ClassRow> classes, Timestamp start, Timestamp end,
  768. XjbDormScoreU.AttendanceScope scope)
  769. throws Exception {
  770. SqlCmd daysCmd = new SqlCmd(
  771. "select distinct trunc(KSSJ) D from KQJL"
  772. + " where KSSJ>=:start and KSSJ<:end"
  773. + " and KQJLZTM=51 and " + ObjC.JLZT_useStr);
  774. daysCmd.wrTimeParm("start", start);
  775. daysCmd.wrTimeParm("end", end);
  776. List<LocalDate> days = new ArrayList<>();
  777. for (Map<String, Object> row : db.doSelMapListByC(daysCmd))
  778. days.add(rdLocalDate(row.get("d")));
  779. Map<Long, Map<LocalDate, Double>> penalties =
  780. XjbDormScoreU.rdAttendancePenalty(
  781. db, start, end, scope);
  782. Map<Long, Double> result = new HashMap<>();
  783. if (days.isEmpty())
  784. return result;
  785. for (ClassRow cls : classes) {
  786. double total = 0.0;
  787. Map<LocalDate, Double> classPenalty =
  788. penalties.getOrDefault(cls.bjid, Collections.emptyMap());
  789. for (LocalDate day : days)
  790. total += Math.max(0.0, 100.0
  791. - classPenalty.getOrDefault(day, 0.0));
  792. result.put(cls.bjid, round2(total / days.size()));
  793. }
  794. return result;
  795. }
  796. private Map<Long, DormScore> rdDormScores(
  797. Db db, List<ClassRow> classes, Timestamp start, Timestamp end,
  798. Map<Long, Double> attendance)
  799. throws Exception {
  800. // 学校确认:宿舍内务不再区分上午/下午,所有有效检查记录参与平均。
  801. SqlCmd itemCmd = new SqlCmd(
  802. "select BJID,avg(FS) SCORE from SSNWJC"
  803. + " where JCSJ>=:start and JCSJ<:end"
  804. + " and " + ObjC.JLZT_useStr + " group by BJID");
  805. itemCmd.wrTimeParm("start", start);
  806. itemCmd.wrTimeParm("end", end);
  807. Map<Long, Double> internal = new HashMap<>();
  808. for (Map<String, Object> row : db.doSelMapListByC(itemCmd))
  809. internal.put(rdLong(row.get("bjid"), 0L),
  810. rdDouble(row.get("score")));
  811. SqlCmd violationCmd = new SqlCmd(
  812. "select BJID,sum(PENALTY) PENALTY from ("
  813. + XjbWjjlU.dedupEventSql()
  814. + " where WJSJ>=:start and WJSJ<:end)"
  815. + " where RN=1 group by BJID");
  816. violationCmd.wrTimeParm("start", start);
  817. violationCmd.wrTimeParm("end", end);
  818. Map<Long, Double> violations = new HashMap<>();
  819. for (Map<String, Object> row : db.doSelMapListByC(violationCmd)) {
  820. violations.put(rdLong(row.get("bjid"), 0L),
  821. rdDouble(row.get("penalty")));
  822. }
  823. Map<Long, DormScore> result = new HashMap<>();
  824. for (ClassRow cls : classes) {
  825. Double internalScore = internal.get(cls.bjid);
  826. Double attend = attendance.get(cls.bjid);
  827. if (internalScore == null || attend == null)
  828. continue;
  829. // 学校确认:宿舍评分允许出现负数,因此这里不再截断到 0。
  830. double violationScore =
  831. 100.0 - violations.getOrDefault(cls.bjid, 0.0);
  832. double base = internalScore * 0.35 + attend * 0.15
  833. + violationScore * 0.35;
  834. XjbDormScoreU.ManagementSummary management =
  835. XjbDormScoreU.rdManagementSummary(
  836. db, cls.bjid, start, end);
  837. DormScore score = new DormScore();
  838. score.value = round2(base + base / 85.0 * 10.0
  839. + management.bonus);
  840. score.internal = round2(internalScore);
  841. score.attendance = attend;
  842. score.violation = round2(violationScore);
  843. score.managementBonus = management.bonus;
  844. score.managementVisits = management.visitCount;
  845. score.managementSource = management.source;
  846. result.put(cls.bjid, score);
  847. }
  848. return result;
  849. }
  850. private Map<Long, AdjustmentTotals> rdAdjustmentTotals(
  851. Db db, YearMonth month) throws Exception {
  852. SqlCmd sqlc = new SqlCmd(
  853. "select BJID,"
  854. + "sum(case when JFLX=1 and LYLX in('"
  855. + XjbJfServ.LYLX_TEAM_ROLE + "','"
  856. + XjbJfServ.LYLX_TEAM_MEMBER
  857. + "') then JFZ else 0 end) TEAM_BONUS,"
  858. + "sum(case when JFLX=1 and nvl(LYLX,'#') not in('"
  859. + XjbJfServ.LYLX_TEAM_ROLE + "','"
  860. + XjbJfServ.LYLX_TEAM_MEMBER
  861. + "') then JFZ else 0 end) OTHER_BONUS,"
  862. + "sum(case when JFLX=2 then JFZ else 0 end) DEDUCTION,"
  863. + "sum(case when JFLX=1 then 1 else 0 end) BONUS_CNT,"
  864. + "sum(case when JFLX=2 then 1 else 0 end) DEDUCTION_CNT"
  865. + " from XJB_JFJL where NDY=:ndy and JLZTM=51 group by BJID");
  866. sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
  867. Map<Long, AdjustmentTotals> result = new HashMap<>();
  868. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  869. AdjustmentTotals total = new AdjustmentTotals();
  870. total.otherBonus = Math.max(
  871. 0.0, rdDouble(row.get("other_bonus")));
  872. total.teamBonus = Math.max(
  873. 0.0, rdDouble(row.get("team_bonus")));
  874. total.bonus = XjbJfServ.capBonus(
  875. total.otherBonus, total.teamBonus);
  876. total.deduction = rdDouble(row.get("deduction"));
  877. total.bonusCount = rdInt(row.get("bonus_cnt"));
  878. total.deductionCount = rdInt(row.get("deduction_cnt"));
  879. result.put(rdLong(row.get("bjid"), 0L), total);
  880. }
  881. return result;
  882. }
  883. private Component component(Double value, String detail) {
  884. Component item = new Component();
  885. item.value = value;
  886. item.source = value == null ? SOURCE_MISSING : SOURCE_REAL;
  887. item.detail = detail;
  888. return item;
  889. }
  890. private Component importedComponent(Object value, String detail) {
  891. Component item = new Component();
  892. item.value = value == null ? null : round2(rdDouble(value));
  893. item.source = value == null ? SOURCE_MISSING : SOURCE_THIRD;
  894. item.detail = detail;
  895. return item;
  896. }
  897. private Component disciplineComponent(DisciplineScore score) {
  898. Component item = new Component();
  899. if (score == null)
  900. return item;
  901. item.value = round2(score.value);
  902. item.source = SOURCE_REAL;
  903. item.detail = "扣分" + score.violations + ",登记"
  904. + score.days + "天";
  905. return item;
  906. }
  907. private Component dormComponent(DormScore score) {
  908. Component item = new Component();
  909. if (score == null)
  910. return item;
  911. item.value = score.value;
  912. item.source = SOURCE_REAL;
  913. item.detail = "内务" + score.internal
  914. + ",住宿考勤" + score.attendance
  915. + ",违纪" + score.violation
  916. + ",管理增分" + score.managementBonus;
  917. return item;
  918. }
  919. private void addMissing(ClassResult item, String label,
  920. Component component) {
  921. if (component == null || component.value == null)
  922. item.missing.add(label);
  923. }
  924. private void assignRanks(List<ClassResult> results) {
  925. List<ClassResult> school = new ArrayList<>(results);
  926. school.sort(Comparator
  927. .comparingDouble((ClassResult item) -> -item.total)
  928. .thenComparingLong(item -> item.cls.bjid));
  929. assignSchoolRanks(school);
  930. Map<Long, List<ClassResult>> departments = new LinkedHashMap<>();
  931. for (ClassResult item : results) {
  932. departments.computeIfAbsent(item.cls.deptId, key ->
  933. new ArrayList<>()).add(item);
  934. }
  935. for (List<ClassResult> group : departments.values()) {
  936. group.sort(Comparator
  937. .comparingDouble((ClassResult item) -> -item.total)
  938. .thenComparingLong(item -> item.cls.bjid));
  939. double previous = Double.NaN;
  940. int rank = 0;
  941. for (int i = 0; i < group.size(); i++) {
  942. ClassResult item = group.get(i);
  943. if (i == 0 || Double.compare(previous, item.total) != 0)
  944. rank = i + 1;
  945. item.departmentRank = rank;
  946. item.departmentClassCount = group.size();
  947. previous = item.total;
  948. }
  949. }
  950. for (ClassResult item : results)
  951. item.star = starLevel(item.total, item.schoolRank);
  952. }
  953. private void assignSchoolRanks(List<ClassResult> sorted) {
  954. double previous = Double.NaN;
  955. int rank = 0;
  956. for (int i = 0; i < sorted.size(); i++) {
  957. ClassResult item = sorted.get(i);
  958. if (i == 0 || Double.compare(previous, item.total) != 0)
  959. rank = i + 1;
  960. item.schoolRank = rank;
  961. item.schoolClassCount = sorted.size();
  962. previous = item.total;
  963. }
  964. }
  965. private String starLevel(double score, int schoolRank) {
  966. if (schoolRank <= 10 && score > 90.0)
  967. return "五星级";
  968. if (score > 80.0)
  969. return "四星级";
  970. if (score > 75.0)
  971. return "三星级";
  972. if (score > 65.0)
  973. return "二星级";
  974. if (score > 55.0)
  975. return "一星级";
  976. return "无星级";
  977. }
  978. private boolean hasPublishedBatch(Db db, YearMonth month, long bmid)
  979. throws Exception {
  980. SqlCmd sqlc = new SqlCmd(
  981. "select count(*) CNT from XJB_JD where NDY=:ndy"
  982. + " and FWLX='BM' and FWID=:fwid and ZT=:status");
  983. sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
  984. sqlc.wrLongParm("fwid", bmid);
  985. sqlc.wrIntParm("status", JD_PUBLISHED);
  986. db.doSelByC(sqlc);
  987. return db.rowNum > 0 && db.rdIntCol("cnt") > 0;
  988. }
  989. private void deleteDraftBatch(Db db, YearMonth month, long bmid)
  990. throws Exception {
  991. SqlCmd find = new SqlCmd(
  992. "select XJB_JDID from XJB_JD where NDY=:ndy"
  993. + " and FWLX='BM' and FWID=:fwid and ZT=:status");
  994. find.wrStrParm("ndy", month.format(MONTH_FMT));
  995. find.wrLongParm("fwid", bmid);
  996. find.wrIntParm("status", JD_DRAFT);
  997. List<Map<String, Object>> rows = db.doSelMapListByC(find);
  998. if (rows == null)
  999. return;
  1000. for (Map<String, Object> row : rows) {
  1001. long jdid = rdLong(row.get("xjb_jdid"), 0L);
  1002. deleteByJdId(db, "XJB_JGMX", jdid);
  1003. deleteByJdId(db, "XJB_PM", jdid);
  1004. deleteByJdId(db, "XJB_JG", jdid);
  1005. SqlCmd delete = new SqlCmd(
  1006. "delete from XJB_JD where XJB_JDID=:id and ZT=:status");
  1007. delete.wrLongParm("id", jdid);
  1008. delete.wrIntParm("status", JD_DRAFT);
  1009. db.doModByC(delete);
  1010. }
  1011. }
  1012. private void deleteByJdId(Db db, String table, long jdid)
  1013. throws Exception {
  1014. SqlCmd sqlc = new SqlCmd(
  1015. "delete from " + table + " where XJB_JDID=:id");
  1016. sqlc.wrLongParm("id", jdid);
  1017. db.doModByC(sqlc);
  1018. }
  1019. private long insertBatch(Db db, YearMonth month, String fwlx, long fwid,
  1020. int version, Long previousId, String reason,
  1021. UserRunB user) throws Exception {
  1022. long id = db.rdNextSeqVal("XJB_JDID");
  1023. Timestamp now = new Timestamp(System.currentTimeMillis());
  1024. XjbJdPo po = new XjbJdPo();
  1025. po.setXjb_jdid(id);
  1026. po.setNdy(month.format(MONTH_FMT));
  1027. po.setFwlx(fwlx);
  1028. po.setFwid(fwid);
  1029. po.setPzid(rdFormulaPzId(db, month));
  1030. po.setBb(version);
  1031. po.setZt(JD_PUBLISHED);
  1032. po.setMs(StringUtils.defaultIfBlank(reason, "星级班月结"));
  1033. po.setCjsj(now);
  1034. po.setFbsj(now);
  1035. po.setJsryid(user == null ? null : user.ryid);
  1036. po.setJsbmid(user == null ? null : user.bmid);
  1037. po.setPrev_jdid(previousId);
  1038. po.setGzyy(StringUtils.trimToNull(reason));
  1039. Set<String> fields = new LinkedHashSet<>(Arrays.asList(
  1040. "xjb_jdid", "ndy", "fwlx", "fwid", "pzid", "bb", "zt", "ms",
  1041. "cjsj", "fbsj", "jsryid", "jsbmid", "prev_jdid", "gzyy"));
  1042. db.doInsPo(po, fields);
  1043. return id;
  1044. }
  1045. private long insertResult(Db db, long jdid, ClassResult result,
  1046. UserRunB user) throws Exception {
  1047. XjbJgPo jg = new XjbJgPo();
  1048. long jgid = db.rdNextSeqVal("XJB_JGID");
  1049. jg.setXjb_jgid(jgid);
  1050. jg.setXjb_jdid(jdid);
  1051. jg.setNdy(result.ndy);
  1052. jg.setBjid(result.cls.bjid);
  1053. jg.setDwid(result.cls.dwid);
  1054. jg.setZyid(result.cls.zyid);
  1055. jg.setSsdf(result.dorm.value.floatValue());
  1056. jg.setKtdf(result.classroom.value.floatValue());
  1057. jg.setSjdf(result.flag.value.floatValue());
  1058. jg.setCsdf(result.cleaning.value.floatValue());
  1059. jg.setFjdf(result.discipline.value.floatValue());
  1060. jg.setKqdf(result.attendance.value.floatValue());
  1061. jg.setZjf((float) Math.min(8.0, result.adjust.bonus));
  1062. jg.setKjf((float) result.adjust.deduction);
  1063. jg.setZf((float) result.total);
  1064. jg.setXj(result.star);
  1065. jg.setSsly(result.dorm.source);
  1066. jg.setKtly(result.classroom.source);
  1067. jg.setSjly(result.flag.source);
  1068. jg.setCsly(result.cleaning.source);
  1069. jg.setFjly(result.discipline.source);
  1070. jg.setKqly(result.attendance.source);
  1071. jg.setZjfcs(result.adjust.bonusCount);
  1072. jg.setKjfcs(result.adjust.deductionCount);
  1073. jg.setQxsm("");
  1074. jg.setZt(JD_PUBLISHED);
  1075. jg.setJlsj(new Timestamp(System.currentTimeMillis()));
  1076. jg.setCjryid(user == null ? null : user.ryid);
  1077. jg.setGlbmid(user == null ? null : user.bmid);
  1078. Set<String> jgFields = new LinkedHashSet<>(Arrays.asList(
  1079. "xjb_jgid", "xjb_jdid", "ndy", "bjid", "dwid", "zyid",
  1080. "ssdf", "ktdf", "sjdf", "csdf", "fjdf", "kqdf",
  1081. "zjf", "kjf", "zf", "xj", "ssly", "ktly", "sjly",
  1082. "csly", "fjly", "kqly", "zjfcs", "kjfcs", "qxsm",
  1083. "zt", "jlsj", "cjryid", "glbmid"));
  1084. db.doInsPo(jg, jgFields);
  1085. XjbPmPo pm = new XjbPmPo();
  1086. pm.setXjb_pmid(db.rdNextSeqVal("XJB_PMID"));
  1087. pm.setXjb_jdid(jdid);
  1088. pm.setBjid(result.cls.bjid);
  1089. pm.setDwid(result.cls.deptId == null
  1090. ? result.cls.dwid : result.cls.deptId);
  1091. pm.setDwpm(result.departmentRank);
  1092. pm.setDwcs(result.departmentClassCount);
  1093. pm.setXxpm(result.schoolRank);
  1094. pm.setXxcs(result.schoolClassCount);
  1095. Set<String> pmFields = new LinkedHashSet<>(Arrays.asList(
  1096. "xjb_pmid", "xjb_jdid", "bjid", "dwid",
  1097. "dwpm", "dwcs", "xxpm", "xxcs"));
  1098. db.doInsPo(pm, pmFields);
  1099. return jgid;
  1100. }
  1101. private long rdFormulaPzId(Db db, YearMonth month) throws Exception {
  1102. Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
  1103. Timestamp end = Timestamp.valueOf(
  1104. month.plusMonths(1).atDay(1).atStartOfDay());
  1105. SqlCmd sqlc = new SqlCmd(
  1106. "select PZID from XJB_PZ where PZBB=:pzbb and JLZTM=51"
  1107. + " and KSRQ<:end and (JSRQ is null or JSRQ>=:start)"
  1108. + " order by KSRQ desc,PZID desc");
  1109. sqlc.wrStrParm("pzbb", FORMULA_VERSION);
  1110. sqlc.wrTimeParm("start", start);
  1111. sqlc.wrTimeParm("end", end);
  1112. db.doSelByC(sqlc);
  1113. if (db.rowNum == 0)
  1114. throw new IllegalStateException(
  1115. "缺少星级班评分配置版本:" + FORMULA_VERSION);
  1116. return db.rdLongCol("pzid");
  1117. }
  1118. private void insertResultDetail(Db db, long jdid, long jgid,
  1119. ClassResult result, UserRunB user)
  1120. throws Exception {
  1121. int sx = 1;
  1122. insertWeightedDetail(db, jdid, jgid, result, user, sx++,
  1123. "DORM", "宿舍评分", result.dorm.value, 0.20,
  1124. result.dorm.source, "常规项按20%计入总分");
  1125. if (result.dormDetail != null) {
  1126. sx = insertRawDetail(db, jdid, jgid, result, user, sx,
  1127. "DORM_INTERNAL", "宿舍内务月均分",
  1128. result.dormDetail.internal, SOURCE_REAL,
  1129. "有效内务检查平均分");
  1130. sx = insertRawDetail(db, jdid, jgid, result, user, sx,
  1131. "DORM_ATTENDANCE", "住宿考勤分",
  1132. result.dormDetail.attendance, SOURCE_REAL,
  1133. "住校生在校考勤日平均分");
  1134. sx = insertRawDetail(db, jdid, jgid, result, user, sx,
  1135. "DORM_VIOLATION", "宿舍违纪得分",
  1136. result.dormDetail.violation, SOURCE_REAL,
  1137. "100减当月去重宿舍违纪扣分");
  1138. sx = insertRawDetail(db, jdid, jgid, result, user, sx,
  1139. "DORM_MANAGE", "宿舍管理增分",
  1140. result.dormDetail.managementBonus,
  1141. result.dormDetail.managementSource,
  1142. "到宿有效参与5至7次加3分,8次及以上加5分");
  1143. sx = insertRawDetail(db, jdid, jgid, result, user, sx,
  1144. "DORM_MANAGE_VISITS", "宿舍管理有效次数",
  1145. result.dormDetail.managementVisits,
  1146. result.dormDetail.managementSource,
  1147. "单次进入离开间隔不少于10分钟");
  1148. sx = insertRawDetail(db, jdid, jgid, result, user, sx,
  1149. "DORM_DEDUCTION", "宿舍其他减分", 0.0, "停",
  1150. "学校暂未提供扣分规则");
  1151. }
  1152. sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
  1153. "CLASSROOM", "课堂考核", result.classroom.value, 0.05,
  1154. result.classroom.source, "常规项按5%计入总分");
  1155. sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
  1156. "FLAG", "升旗礼", result.flag.value, 0.14,
  1157. result.flag.source, "常规项按14%计入总分");
  1158. sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
  1159. "CLEANING", "场室卫生", result.cleaning.value, 0.18,
  1160. result.cleaning.source, "常规项按18%计入总分");
  1161. sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
  1162. "DISCIPLINE", "风纪仪容", result.discipline.value, 0.20,
  1163. result.discipline.source, "常规项按20%计入总分");
  1164. if (result.disciplineDetail != null) {
  1165. sx = insertRawDetail(db, jdid, jgid, result, user, sx,
  1166. "DISCIPLINE_PENALTY", "风纪扣分合计",
  1167. result.disciplineDetail.violations, SOURCE_REAL,
  1168. "当月风纪仪容扣分合计");
  1169. sx = insertRawDetail(db, jdid, jgid, result, user, sx,
  1170. "DISCIPLINE_DAYS", "风纪违纪天数",
  1171. result.disciplineDetail.days, SOURCE_REAL,
  1172. "当月发生风纪违纪的日期数");
  1173. }
  1174. sx = insertWeightedDetail(db, jdid, jgid, result, user, sx++,
  1175. "ATTENDANCE", "考勤", result.attendance.value, 0.15,
  1176. result.attendance.source, "常规项按15%计入总分");
  1177. double teamBonus = Math.max(0.0, result.adjust.teamBonus);
  1178. double otherBonus = Math.max(0.0, result.adjust.otherBonus);
  1179. sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx++,
  1180. "TEAM_BONUS", "学生团体原始增分",
  1181. teamBonus, Math.min(XjbJfServ.TEAM_BONUS_CAP, teamBonus),
  1182. "TT", "团体原始事件合计,汇总前先封顶");
  1183. sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx++,
  1184. "OTHER_BONUS", "其他增分",
  1185. otherBonus, otherBonus, "CALC", "非学生团体增分");
  1186. sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx++,
  1187. "BONUS_TOTAL", "增分合计",
  1188. teamBonus + otherBonus, result.adjust.bonus,
  1189. "CALC", "团体先封顶3分,总增分再封顶8分");
  1190. sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx++,
  1191. "DEDUCTION", "减分合计",
  1192. result.adjust.deduction, -result.adjust.deduction,
  1193. "CALC", "来源减分合计");
  1194. sx = insertRawScoreDetail(db, jdid, jgid, result, user, sx,
  1195. "TOTAL", "月总分", result.total, result.total,
  1196. "CALC", "六项加权增分封顶后减分;不设0分下限");
  1197. }
  1198. private int insertWeightedDetail(Db db, long jdid, long jgid,
  1199. ClassResult result, UserRunB user,
  1200. int sx, String code, String name,
  1201. double raw, double weight,
  1202. String source, String note)
  1203. throws Exception {
  1204. insertJgmx(db, jdid, jgid, result, user, sx, code, name,
  1205. raw, weight, round2(raw * weight), source, note);
  1206. return sx + 1;
  1207. }
  1208. private int insertRawDetail(Db db, long jdid, long jgid,
  1209. ClassResult result, UserRunB user,
  1210. int sx, String code, String name,
  1211. double raw, String source, String note)
  1212. throws Exception {
  1213. insertJgmx(db, jdid, jgid, result, user, sx, code, name,
  1214. raw, null, null, source, note);
  1215. return sx + 1;
  1216. }
  1217. private int insertRawScoreDetail(Db db, long jdid, long jgid,
  1218. ClassResult result, UserRunB user,
  1219. int sx, String code, String name,
  1220. double raw, double score,
  1221. String source, String note)
  1222. throws Exception {
  1223. insertJgmx(db, jdid, jgid, result, user, sx, code, name,
  1224. raw, null, round2(score), source, note);
  1225. return sx + 1;
  1226. }
  1227. private void insertJgmx(Db db, long jdid, long jgid,
  1228. ClassResult result, UserRunB user, int sx,
  1229. String code, String name, double raw,
  1230. Double weight, Double score, String source,
  1231. String note) throws Exception {
  1232. XjbJgmxPo mx = new XjbJgmxPo();
  1233. mx.setJgmxid(db.rdNextSeqVal("XJB_JGMXID"));
  1234. mx.setXjb_jdid(jdid);
  1235. mx.setXjb_jgid(jgid);
  1236. mx.setBjid(result.cls.bjid);
  1237. mx.setNdy(result.ndy);
  1238. mx.setXmbm(code);
  1239. mx.setXmmc(name);
  1240. mx.setYsz(round2(raw));
  1241. mx.setQz(weight);
  1242. mx.setDf(score);
  1243. mx.setLylx(source);
  1244. mx.setSm(note);
  1245. mx.setSx(sx);
  1246. mx.setCjryid(user == null ? null : user.ryid);
  1247. mx.setCjbm_id(user == null ? null : user.bmid);
  1248. mx.setJlsj(new java.sql.Date(System.currentTimeMillis()));
  1249. Set<String> fields = new LinkedHashSet<>(Arrays.asList(
  1250. "jgmxid", "xjb_jdid", "xjb_jgid", "bjid", "ndy",
  1251. "xmbm", "xmmc", "ysz", "qz", "df", "lylx", "sm",
  1252. "sx", "cjryid", "cjbm_id", "jlsj"));
  1253. db.doInsPo(mx, fields);
  1254. }
  1255. private YearMonth rdLatestPublishedMonth(Db db) throws Exception {
  1256. SqlCmd sqlc = new SqlCmd(
  1257. "select max(NDY) NDY from XJB_JD"
  1258. + " where FWLX=:fwlx and FWID=:fwid and ZT=:status"
  1259. + " and nvl(FBSJ,CJSJ)>=add_months("
  1260. + "to_date(NDY||'-01','YYYY-MM-DD'),1)");
  1261. sqlc.wrStrParm("fwlx", SCOPE_SCHOOL);
  1262. sqlc.wrLongParm("fwid", SCHOOL_SCOPE_ID);
  1263. sqlc.wrIntParm("status", JD_PUBLISHED);
  1264. db.doSelByC(sqlc);
  1265. String value = db.rowNum == 0 ? null : db.rdStrCol("ndy");
  1266. if (StringUtils.isBlank(value)) {
  1267. SqlCmd legacy = new SqlCmd(
  1268. "select max(NDY) NDY from XJB_JD"
  1269. + " where FWLX='BM' and ZT=:status");
  1270. legacy.wrIntParm("status", JD_PUBLISHED);
  1271. db.doSelByC(legacy);
  1272. value = db.rowNum == 0 ? null : db.rdStrCol("ndy");
  1273. }
  1274. return StringUtils.isBlank(value) ? null
  1275. : YearMonth.parse(value, MONTH_FMT);
  1276. }
  1277. private static YearMonth rdMonth(String value) {
  1278. String text = StringUtils.trimToNull(value);
  1279. if (text == null)
  1280. throw new IllegalArgumentException("请选择月份");
  1281. try {
  1282. return YearMonth.parse(text, MONTH_FMT);
  1283. } catch (Exception e) {
  1284. throw new IllegalArgumentException("月份格式错误");
  1285. }
  1286. }
  1287. private static void addNonBlank(Set<String> target, Object value) {
  1288. String text = String.valueOf(value == null ? "" : value).trim();
  1289. if (!text.isEmpty())
  1290. target.add(text);
  1291. }
  1292. private static String formatScore(Object value) {
  1293. if (value == null)
  1294. return "-";
  1295. return String.format("%.2f", rdDouble(value));
  1296. }
  1297. private static String formatTimestamp(Object value) {
  1298. if (value instanceof Timestamp timestamp)
  1299. return timestamp.toLocalDateTime()
  1300. .format(DateTimeFormatter.ofPattern(
  1301. "yyyy-MM-dd HH:mm:ss"));
  1302. return value == null ? "" : String.valueOf(value);
  1303. }
  1304. private static LocalDate rdLocalDate(Object value) {
  1305. if (value instanceof java.sql.Date date)
  1306. return date.toLocalDate();
  1307. if (value instanceof Timestamp timestamp)
  1308. return timestamp.toLocalDateTime().toLocalDate();
  1309. if (value == null)
  1310. return null;
  1311. String text = String.valueOf(value);
  1312. return text.length() < 10 ? null
  1313. : LocalDate.parse(text.substring(0, 10));
  1314. }
  1315. private static long rdLong(Object value, long defaultValue) {
  1316. if (value == null)
  1317. return defaultValue;
  1318. String text = StringUtils.trimToNull(String.valueOf(value));
  1319. return text == null ? defaultValue : Long.parseLong(text);
  1320. }
  1321. private static Long rdLongOrNull(Object value) {
  1322. long parsed = rdLong(value, 0L);
  1323. return parsed == 0L ? null : parsed;
  1324. }
  1325. private static int rdInt(Object value) {
  1326. return value == null ? 0 : Integer.parseInt(String.valueOf(value));
  1327. }
  1328. private static double rdDouble(Object value) {
  1329. return value == null ? 0.0 : Double.parseDouble(String.valueOf(value));
  1330. }
  1331. private static String rdStr(Object value) {
  1332. return value == null ? "" : String.valueOf(value);
  1333. }
  1334. private static double round2(double value) {
  1335. return Math.round(value * 100.0) / 100.0;
  1336. }
  1337. private static final class ClassRow {
  1338. final long bjid;
  1339. final String bjmc;
  1340. final Long dwid;
  1341. final Long zyid;
  1342. final Long deptId;
  1343. ClassRow(long bjid, String bjmc, Long dwid, Long zyid,
  1344. Long deptId) {
  1345. this.bjid = bjid;
  1346. this.bjmc = bjmc;
  1347. this.dwid = dwid;
  1348. this.zyid = zyid;
  1349. this.deptId = deptId;
  1350. }
  1351. }
  1352. private static final class Component {
  1353. Double value;
  1354. String source = SOURCE_MISSING;
  1355. String detail = "";
  1356. }
  1357. private static final class DisciplineScore {
  1358. double value;
  1359. double violations;
  1360. int days;
  1361. }
  1362. private static final class DisciplinePenalties {
  1363. final Map<Long, Map<LocalDate, Double>> mapped = new HashMap<>();
  1364. final Map<Long, Map<LocalDate, Double>> legacy = new HashMap<>();
  1365. }
  1366. private static final class DormScore {
  1367. double value;
  1368. double internal;
  1369. double attendance;
  1370. double violation;
  1371. int managementBonus;
  1372. int managementVisits;
  1373. String managementSource = XjbDormScoreU.SOURCE_UNAVAILABLE;
  1374. }
  1375. private static final class AdjustmentTotals {
  1376. double bonus;
  1377. double teamBonus;
  1378. double otherBonus;
  1379. double deduction;
  1380. int bonusCount;
  1381. int deductionCount;
  1382. }
  1383. private static final class ClassResult {
  1384. final ClassRow cls;
  1385. Component dorm;
  1386. DormScore dormDetail;
  1387. Component classroom;
  1388. Component flag;
  1389. Component cleaning;
  1390. Component discipline;
  1391. DisciplineScore disciplineDetail;
  1392. Component attendance;
  1393. AdjustmentTotals adjust = new AdjustmentTotals();
  1394. final List<String> missing = new ArrayList<>();
  1395. double total;
  1396. String star = "待评分";
  1397. int departmentRank;
  1398. int departmentClassCount;
  1399. int schoolRank;
  1400. int schoolClassCount;
  1401. String ndy;
  1402. ClassResult(ClassRow cls) {
  1403. this.cls = cls;
  1404. }
  1405. }
  1406. }