BjStarClassMpServ.java 138 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120
  1. package biz.bj;
  2. import com.google.gson.Gson;
  3. import jakarta.servlet.http.HttpServletRequest;
  4. import org.apache.commons.lang3.StringUtils;
  5. import org.apache.logging.log4j.LogManager;
  6. import org.apache.logging.log4j.Logger;
  7. import ss.db.Db;
  8. import ss.db.SqlCmd;
  9. import ss.obj.ObjC;
  10. import ss.serv.Serv;
  11. import ss.serv.ServU;
  12. import ss.user.UserRunB;
  13. import ss.user.UserU;
  14. import java.io.Writer;
  15. import java.sql.Date;
  16. import java.sql.SQLException;
  17. import java.sql.Timestamp;
  18. import java.time.DayOfWeek;
  19. import java.time.LocalDate;
  20. import java.time.YearMonth;
  21. import java.time.ZoneId;
  22. import java.time.format.DateTimeFormatter;
  23. import java.time.format.DateTimeParseException;
  24. import java.time.temporal.TemporalAdjusters;
  25. import java.util.ArrayList;
  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.Locale;
  33. import java.util.Map;
  34. import java.util.Set;
  35. /**
  36. * 班主任星级班移动报表。
  37. */
  38. public class BjStarClassMpServ extends Serv {
  39. private static final Logger log4j = LogManager.getLogger(BjStarClassMpServ.class);
  40. private static final ZoneId CN_ZONE = ZoneId.of("Asia/Shanghai");
  41. private static final DateTimeFormatter MONTH_FMT = DateTimeFormatter.ofPattern("yyyy-MM");
  42. private static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  43. private static final DateTimeFormatter DATETIME_FMT =
  44. DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  45. private static final String SOURCE_REAL = "real";
  46. private static final String SOURCE_MISSING = "missing";
  47. private static final String ZHIXIN_STAR_MARKER_PREFIX = "ZHIXIN_STAR_";
  48. private static final int DEFAULT_PAGE_SIZE = 20;
  49. private static final int DETAIL_PAGE_SIZE = 30;
  50. private static final List<CategoryDef> CATEGORY_DEFS = List.of(
  51. new CategoryDef("dorm", "宿舍评分", 0.20),
  52. new CategoryDef("classroom", "课堂考核", 0.05),
  53. new CategoryDef("flag", "升旗礼", 0.14),
  54. new CategoryDef("cleaning", "清洁卫生", 0.18),
  55. new CategoryDef("discipline", "风纪仪容", 0.20),
  56. new CategoryDef("attendance", "考勤", 0.15)
  57. );
  58. /**
  59. * 班主任、本人班级和默认月份。
  60. */
  61. @SuppressWarnings("unused")
  62. public void initByA() throws Exception {
  63. HttpServletRequest request = super.req;
  64. prepareJson();
  65. Writer writer = super.resp.getWriter();
  66. Gson gson = new Gson();
  67. try (Db db = Db.makeConn()) {
  68. UserRunB user = requireUser(request);
  69. List<ClassInfo> classes = rdTeacherClasses(db, user.ryid);
  70. if (classes.isEmpty())
  71. throw new IllegalArgumentException("当前账号未关联班主任班级");
  72. List<Map<String, Object>> classList = new ArrayList<>();
  73. for (ClassInfo item : classes) {
  74. Map<String, Object> classRow = new LinkedHashMap<>();
  75. classRow.put("bjid", item.bjid);
  76. classRow.put("bjmc", item.bjmc);
  77. classRow.put("dwid", item.dwid);
  78. classRow.put("dwmc", item.dwmc);
  79. classList.add(classRow);
  80. }
  81. Map<String, Object> data = new LinkedHashMap<>();
  82. data.put("teacherName", user.xm);
  83. data.put("defaultBjid", classes.get(0).bjid);
  84. data.put("defaultMonth", YearMonth.now(CN_ZONE).format(MONTH_FMT));
  85. data.put("classes", classList);
  86. ServU.wrOkDataByWriter(data, writer, gson);
  87. } catch (IllegalArgumentException e) {
  88. ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
  89. } catch (Exception e) {
  90. log4j.error("BjStarClassMpServ.initByA() 异常", e);
  91. ServU.wrErrMsgByWriter(null, "星级班信息加载失败", writer, gson);
  92. }
  93. }
  94. /**
  95. * 月度汇总和每日列表。
  96. */
  97. @SuppressWarnings("unused")
  98. public void summaryByA() throws Exception {
  99. HttpServletRequest request = super.req;
  100. prepareJson();
  101. Writer writer = super.resp.getWriter();
  102. Gson gson = new Gson();
  103. try (Db db = Db.makeConn()) {
  104. UserRunB user = requireUser(request);
  105. ClassInfo selected = requireTeacherClass(db, user.ryid,
  106. rdLongParam(request, "bjid", false));
  107. YearMonth month = rdMonth(request);
  108. MonthPeriod period = MonthPeriod.of(month);
  109. List<ClassInfo> classes = rdActiveClasses(db);
  110. ScoreBook scores = rdScoreBook(db, classes, period);
  111. RankBook ranks = rdRanks(classes, scores);
  112. ClassScore classScore = scores.classScores.get(selected.bjid);
  113. if (classScore == null)
  114. throw new IllegalStateException("班级评分未生成");
  115. PublishedSnapshot snapshot = rdPublishedSnapshot(
  116. db, selected.bjid, month);
  117. int pageNo = Math.max(1, rdIntParam(request, "pageNo", 1));
  118. int pageSize = clampPageSize(rdIntParam(request, "pageSize",
  119. DEFAULT_PAGE_SIZE));
  120. List<DailyAccumulator> allDays = rdDailyList(db, selected, period,
  121. scores.categorySources(selected.bjid));
  122. int from = Math.min(allDays.size(), (pageNo - 1) * pageSize);
  123. int to = Math.min(allDays.size(), from + pageSize);
  124. List<Map<String, Object>> dayRows = new ArrayList<>();
  125. for (int i = from; i < to; i++) {
  126. dayRows.add(allDays.get(i).toMap());
  127. }
  128. Map<String, Object> data = new LinkedHashMap<>();
  129. data.put("bjid", selected.bjid);
  130. data.put("bjmc", selected.bjmc);
  131. data.put("dwid", selected.dwid);
  132. data.put("dwmc", selected.dwmc);
  133. data.put("month", month.format(MONTH_FMT));
  134. if (snapshot != null) {
  135. data.put("score", snapshot.total);
  136. data.put("starLevel", snapshot.starLevel);
  137. data.put("departmentRank", snapshot.departmentRank);
  138. data.put("departmentClassCount", snapshot.departmentClassCount);
  139. data.put("schoolRank", snapshot.schoolRank);
  140. data.put("schoolClassCount", snapshot.schoolClassCount);
  141. data.put("bonusTotal", snapshot.bonus);
  142. data.put("deductionTotal", snapshot.deduction);
  143. data.put("bonusCount", snapshot.bonusCount);
  144. data.put("deductionCount", snapshot.deductionCount);
  145. data.put("rankingPreview", false);
  146. data.put("snapshotPublished", true);
  147. data.put("categorySources", snapshot.sources);
  148. } else {
  149. data.put("score", classScore.hasMissing
  150. ? null : round2(classScore.total));
  151. data.put("starLevel", classScore.hasMissing
  152. ? "待评分" : starLevel(classScore.total,
  153. ranks.schoolRank.getOrDefault(selected.bjid, 0)));
  154. data.put("departmentRank", classScore.hasMissing
  155. ? null : ranks.departmentRank.get(selected.bjid));
  156. data.put("departmentClassCount",
  157. ranks.departmentClassCount.getOrDefault(
  158. selected.dwid, 0));
  159. data.put("schoolRank", classScore.hasMissing
  160. ? null : ranks.schoolRank.get(selected.bjid));
  161. data.put("schoolClassCount", classes.size());
  162. data.put("bonusTotal", round2(classScore.adjust.bonus));
  163. data.put("deductionTotal",
  164. round2(classScore.adjust.deduction));
  165. data.put("bonusCount", classScore.adjust.bonusEvents);
  166. data.put("deductionCount", classScore.adjust.deductionEvents);
  167. data.put("rankingPreview", classScore.hasMissing);
  168. data.put("snapshotPublished", false);
  169. data.put("categorySources",
  170. scores.categorySources(selected.bjid));
  171. data.put("missingItems", classScore.missing);
  172. }
  173. data.put("pageNo", pageNo);
  174. data.put("pageSize", pageSize);
  175. data.put("total", allDays.size());
  176. data.put("hasMore", to < allDays.size());
  177. data.put("days", dayRows);
  178. ServU.wrOkDataByWriter(data, writer, gson);
  179. } catch (IllegalArgumentException e) {
  180. ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
  181. } catch (Exception e) {
  182. log4j.error("BjStarClassMpServ.summaryByA() 异常", e);
  183. ServU.wrErrMsgByWriter(null, "星级班月度数据加载失败", writer, gson);
  184. }
  185. }
  186. /**
  187. * 指定日期的六项得分。
  188. */
  189. @SuppressWarnings("unused")
  190. public void dayByA() throws Exception {
  191. HttpServletRequest request = super.req;
  192. prepareJson();
  193. Writer writer = super.resp.getWriter();
  194. Gson gson = new Gson();
  195. try (Db db = Db.makeConn()) {
  196. UserRunB user = requireUser(request);
  197. ClassInfo selected = requireTeacherClass(db, user.ryid,
  198. rdLongParam(request, "bjid", false));
  199. LocalDate day = rdDate(request, "date");
  200. if (day.isAfter(LocalDate.now(CN_ZONE)))
  201. throw new IllegalArgumentException("不能查询未来日期");
  202. YearMonth month = YearMonth.from(day);
  203. MonthPeriod period = MonthPeriod.of(month);
  204. CategoryDaily daily = rdCategoryDaily(db, selected, day, period);
  205. List<Map<String, Object>> categories = new ArrayList<>();
  206. for (CategoryDef def : CATEGORY_DEFS)
  207. categories.add(daily.toMap(def, day));
  208. Map<String, Object> data = new LinkedHashMap<>();
  209. data.put("bjid", selected.bjid);
  210. data.put("bjmc", selected.bjmc);
  211. data.put("date", day.format(DATE_FMT));
  212. data.put("weekday", weekdayCn(day));
  213. data.put("categories", categories);
  214. data.put("regularDeduction", round2(daily.regularDeduction(day)));
  215. ServU.wrOkDataByWriter(data, writer, gson);
  216. } catch (DateTimeParseException e) {
  217. ServU.wrErrMsgByWriter(null, "日期格式错误", writer, gson);
  218. } catch (IllegalArgumentException e) {
  219. ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
  220. } catch (Exception e) {
  221. log4j.error("BjStarClassMpServ.dayByA() 异常", e);
  222. ServU.wrErrMsgByWriter(null, "单日星级班数据加载失败", writer, gson);
  223. }
  224. }
  225. /**
  226. * 项目扣分明细,或月度增分/减分明细。
  227. */
  228. @SuppressWarnings("unused")
  229. public void detailByA() throws Exception {
  230. writeDetailResponse(false);
  231. }
  232. /**
  233. * PC 已发布月结报表的明细下钻入口。
  234. */
  235. @SuppressWarnings("unused")
  236. public void pcDetailByA() throws Exception {
  237. writeDetailResponse(true);
  238. }
  239. private void writeDetailResponse(boolean pcReport) throws Exception {
  240. HttpServletRequest request = super.req;
  241. prepareJson();
  242. Writer writer = super.resp.getWriter();
  243. Gson gson = new Gson();
  244. try (Db db = Db.makeConn()) {
  245. UserRunB user = requireUser(request);
  246. ClassInfo selected;
  247. YearMonth reportMonth = null;
  248. if (pcReport) {
  249. long bjid = rdLongParam(request, "bjid", true);
  250. long jdid = rdLongParam(request, "jdid", true);
  251. selected = requireReportClass(db, bjid, jdid);
  252. reportMonth = rdReportBatchMonth(db, jdid);
  253. } else {
  254. selected = requireTeacherClass(db, user.ryid,
  255. rdLongParam(request, "bjid", false));
  256. }
  257. Map<String, Object> data = buildDetailData(db, selected,
  258. request, reportMonth);
  259. ServU.wrOkDataByWriter(data, writer, gson);
  260. } catch (DateTimeParseException e) {
  261. ServU.wrErrMsgByWriter(null, "日期格式错误", writer, gson);
  262. } catch (IllegalArgumentException e) {
  263. ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
  264. } catch (Exception e) {
  265. log4j.error("BjStarClassMpServ.writeDetailResponse() 异常,"
  266. + "pcReport=" + pcReport, e);
  267. ServU.wrErrMsgByWriter(null, "星级班明细加载失败", writer, gson);
  268. }
  269. }
  270. private static Map<String, Object> buildDetailData(
  271. Db db, ClassInfo selected, HttpServletRequest request,
  272. YearMonth reportMonth)
  273. throws Exception {
  274. String mode = StringUtils.defaultIfBlank(
  275. request.getParameter("mode"), "dayItem");
  276. if ("trace".equals(mode)) {
  277. String kind = StringUtils.defaultIfBlank(
  278. request.getParameter("kind"), "regular");
  279. long recordId = rdLongParam(request, "id", true);
  280. if ("adjustment".equals(kind))
  281. return rdAdjustmentTrace(db, selected, recordId,
  282. reportMonth);
  283. if ("dormManagement".equals(kind))
  284. return rdDormManagementTrace(db, selected,
  285. rdDate(request, "date"), reportMonth);
  286. LocalDate day = rdDate(request, "date");
  287. if (day.isAfter(LocalDate.now(CN_ZONE)))
  288. throw new IllegalArgumentException("不能查询未来日期");
  289. ensureReportMonth(reportMonth, YearMonth.from(day));
  290. CategoryDef category = requireCategory(StringUtils.trimToNull(
  291. request.getParameter("category")));
  292. String source = StringUtils.defaultIfBlank(
  293. request.getParameter("source"), SOURCE_REAL);
  294. return rdTraceDetail(db, selected, day, category, recordId,
  295. source);
  296. }
  297. int pageNo = Math.max(1, rdIntParam(request, "pageNo", 1));
  298. int pageSize = clampPageSize(rdIntParam(request, "pageSize",
  299. DETAIL_PAGE_SIZE));
  300. List<Map<String, Object>> rows;
  301. String title;
  302. String monthText = null;
  303. String dateText = null;
  304. String categoryCode = null;
  305. String displayType = null;
  306. List<String> columns = null;
  307. if ("dormDaySummary".equals(mode)) {
  308. LocalDate day = rdDate(request, "date");
  309. if (day.isAfter(LocalDate.now(CN_ZONE)))
  310. throw new IllegalArgumentException("不能查询未来日期");
  311. ensureReportMonth(reportMonth, YearMonth.from(day));
  312. rows = rdDormDaySummary(db, selected, day);
  313. title = "宿舍评分 · " + day.format(DATE_FMT);
  314. dateText = day.format(DATE_FMT);
  315. categoryCode = "dorm";
  316. } else if ("dormAttendanceDetail".equals(mode)) {
  317. LocalDate day = rdDate(request, "date");
  318. if (day.isAfter(LocalDate.now(CN_ZONE)))
  319. throw new IllegalArgumentException("不能查询未来日期");
  320. ensureReportMonth(reportMonth, YearMonth.from(day));
  321. CategoryDef category = requireCategory("dorm");
  322. rows = rdAttendanceDetail(db, selected.bjid, day,
  323. XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
  324. for (Map<String, Object> row : rows) {
  325. row.put("detailKind", "regular");
  326. row.put("sourceType", "dormAttendance");
  327. }
  328. title = "住宿生考勤 · " + day.format(DATE_FMT);
  329. dateText = day.format(DATE_FMT);
  330. categoryCode = category.code;
  331. } else if ("flagDaySummary".equals(mode)) {
  332. LocalDate day = rdDate(request, "date");
  333. if (day.isAfter(LocalDate.now(CN_ZONE)))
  334. throw new IllegalArgumentException("不能查询未来日期");
  335. ensureReportMonth(reportMonth, YearMonth.from(day));
  336. rows = rdFlagDaySummary(db, selected.bjid, day);
  337. title = "升旗礼 · " + day.format(DATE_FMT);
  338. dateText = day.format(DATE_FMT);
  339. categoryCode = "flag";
  340. displayType = "deduction";
  341. columns = List.of("项目", "扣分");
  342. } else if ("flagAttendanceDetail".equals(mode)) {
  343. LocalDate day = rdDate(request, "date");
  344. if (day.isAfter(LocalDate.now(CN_ZONE)))
  345. throw new IllegalArgumentException("不能查询未来日期");
  346. ensureReportMonth(reportMonth, YearMonth.from(day));
  347. rows = rdFlagAttendanceDetail(db, selected.bjid, day);
  348. title = "考勤 · " + day.format(DATE_FMT);
  349. dateText = day.format(DATE_FMT);
  350. categoryCode = "flag";
  351. displayType = "value";
  352. columns = List.of("项目", "数值");
  353. } else if ("flagDemeanorDetail".equals(mode)) {
  354. LocalDate day = rdDate(request, "date");
  355. if (day.isAfter(LocalDate.now(CN_ZONE)))
  356. throw new IllegalArgumentException("不能查询未来日期");
  357. ensureReportMonth(reportMonth, YearMonth.from(day));
  358. rows = rdFlagDemeanorDetail(db, selected.bjid, day);
  359. title = "风貌 · " + day.format(DATE_FMT);
  360. dateText = day.format(DATE_FMT);
  361. categoryCode = "flag";
  362. displayType = "score";
  363. columns = List.of("项目", "得分");
  364. } else if ("dormInternalDetail".equals(mode)) {
  365. LocalDate day = rdDate(request, "date");
  366. if (day.isAfter(LocalDate.now(CN_ZONE)))
  367. throw new IllegalArgumentException("不能查询未来日期");
  368. ensureReportMonth(reportMonth, YearMonth.from(day));
  369. rows = rdDormInternalDetail(db, selected.bjid, day);
  370. title = "宿舍内务 · " + day.format(DATE_FMT);
  371. dateText = day.format(DATE_FMT);
  372. categoryCode = "dorm";
  373. } else if ("dormViolationDetail".equals(mode)) {
  374. LocalDate day = rdDate(request, "date");
  375. if (day.isAfter(LocalDate.now(CN_ZONE)))
  376. throw new IllegalArgumentException("不能查询未来日期");
  377. ensureReportMonth(reportMonth, YearMonth.from(day));
  378. rows = rdDormViolationDetail(db, selected.bjid, day);
  379. title = "宿舍违纪扣分 · " + day.format(DATE_FMT);
  380. dateText = day.format(DATE_FMT);
  381. categoryCode = "dorm";
  382. } else if ("bonus".equals(mode) || "deduction".equals(mode)) {
  383. YearMonth month = rdMonth(request);
  384. ensureReportMonth(reportMonth, month);
  385. List<Adjustment> adjustments = rdAdjustments(
  386. db, selected.bjid, month);
  387. List<Adjustment> selectedAdjustments = new ArrayList<>();
  388. for (Adjustment item : adjustments) {
  389. if ((("bonus".equals(mode) && item.score > 0)
  390. || ("deduction".equals(mode) && item.score < 0)))
  391. selectedAdjustments.add(item);
  392. }
  393. selectedAdjustments.sort(Comparator
  394. .comparing((Adjustment item) -> item.date).reversed()
  395. .thenComparingLong(item -> item.id).reversed());
  396. rows = rdAdjustmentRows(selectedAdjustments);
  397. title = "bonus".equals(mode) ? "当月增分明细" : "当月减分明细";
  398. monthText = month.format(MONTH_FMT);
  399. } else if ("monthCategory".equals(mode)) {
  400. YearMonth month = rdMonth(request);
  401. ensureReportMonth(reportMonth, month);
  402. categoryCode = StringUtils.trimToNull(
  403. request.getParameter("category"));
  404. CategoryDef category = requireCategory(categoryCode);
  405. MonthPeriod period = MonthPeriod.of(month);
  406. rows = rdMonthCategoryRows(db, selected, period, category);
  407. title = category.label + " · " + month.format(MONTH_FMT);
  408. monthText = month.format(MONTH_FMT);
  409. } else if ("dayItem".equals(mode)) {
  410. LocalDate day = rdDate(request, "date");
  411. if (day.isAfter(LocalDate.now(CN_ZONE)))
  412. throw new IllegalArgumentException("不能查询未来日期");
  413. ensureReportMonth(reportMonth, YearMonth.from(day));
  414. categoryCode = StringUtils.trimToNull(
  415. request.getParameter("category"));
  416. CategoryDef category = requireCategory(categoryCode);
  417. YearMonth month = YearMonth.from(day);
  418. MonthPeriod period = MonthPeriod.of(month);
  419. rows = rdDayDetail(db, selected, day, period, category);
  420. for (Map<String, Object> row : rows) {
  421. row.put("detailKind", "regular");
  422. if (!row.containsKey("sourceType"))
  423. row.put("sourceType", category.code);
  424. }
  425. title = category.label + " · " + day.format(DATE_FMT);
  426. dateText = day.format(DATE_FMT);
  427. } else {
  428. throw new IllegalArgumentException("明细模式参数错误");
  429. }
  430. int from = Math.min(rows.size(), (pageNo - 1) * pageSize);
  431. int to = Math.min(rows.size(), from + pageSize);
  432. List<Map<String, Object>> pageRows = rows.subList(from, to);
  433. Map<String, Object> data = new LinkedHashMap<>();
  434. data.put("bjid", selected.bjid);
  435. data.put("bjmc", selected.bjmc);
  436. data.put("mode", mode);
  437. data.put("title", title);
  438. data.put("month", monthText);
  439. data.put("date", dateText);
  440. data.put("category", categoryCode);
  441. data.put("displayType", displayType);
  442. data.put("columns", columns);
  443. data.put("pageNo", pageNo);
  444. data.put("pageSize", pageSize);
  445. data.put("total", rows.size());
  446. data.put("hasMore", to < rows.size());
  447. data.put("list", pageRows);
  448. return data;
  449. }
  450. private void prepareJson() throws Exception {
  451. super.resp.setCharacterEncoding("UTF-8");
  452. super.resp.setContentType("application/json;charset=UTF-8");
  453. }
  454. private static UserRunB requireUser(HttpServletRequest request) {
  455. UserRunB user = UserU.rdUserByReq(request);
  456. if (user == null)
  457. throw new IllegalArgumentException("登录状态已失效,请重新进入");
  458. return user;
  459. }
  460. private static List<ClassInfo> rdTeacherClasses(Db db, long ryid)
  461. throws Exception {
  462. SqlCmd sqlc = new SqlCmd(
  463. "select b.BJID,b.MC,z.FZBMID DWID,nvl(bm.MC,'') DWMC"
  464. + " from BJ b inner join ZY z on z.ZYID=b.ZYID"
  465. + " left join BM bm on bm.BMID=z.FZBMID"
  466. + " where b.BZRID=:ryid and b." + ObjC.JLZT_useStr
  467. + " and b.BJZTM!=81 order by b.MC,b.BJID");
  468. sqlc.wrLongParm("ryid", ryid);
  469. return rdClasses(db.doSelMapListByC(sqlc));
  470. }
  471. private static List<ClassInfo> rdActiveClasses(Db db) throws Exception {
  472. SqlCmd sqlc = new SqlCmd(
  473. "select b.BJID,b.MC,z.FZBMID DWID,nvl(bm.MC,'') DWMC"
  474. + " from BJ b inner join ZY z on z.ZYID=b.ZYID"
  475. + " left join BM bm on bm.BMID=z.FZBMID"
  476. + " where b." + ObjC.JLZT_useStr
  477. + " and b.BJZTM!=81 order by b.BJID");
  478. return rdClasses(db.doSelMapListByC(sqlc));
  479. }
  480. private static List<ClassInfo> rdClasses(List<Map<String, Object>> rows) {
  481. List<ClassInfo> list = new ArrayList<>();
  482. for (Map<String, Object> row : rows)
  483. list.add(new ClassInfo(rdLong(row.get("bjid")),
  484. rdStr(row.get("mc")), rdLongObj(row.get("dwid")),
  485. rdStr(row.get("dwmc"))));
  486. return list;
  487. }
  488. private static ClassInfo requireTeacherClass(Db db, long ryid, long bjid)
  489. throws Exception {
  490. List<ClassInfo> classes = rdTeacherClasses(db, ryid);
  491. if (classes.isEmpty())
  492. throw new IllegalArgumentException("当前账号未关联班主任班级");
  493. if (bjid <= 0)
  494. return classes.get(0);
  495. for (ClassInfo item : classes) {
  496. if (item.bjid == bjid)
  497. return item;
  498. }
  499. throw new IllegalArgumentException("无权查看该班级");
  500. }
  501. private static ClassInfo requireReportClass(Db db, long bjid, long jdid)
  502. throws Exception {
  503. SqlCmd sqlc = new SqlCmd(
  504. "select b.BJID,b.MC,z.FZBMID DWID,nvl(bm.MC,'') DWMC"
  505. + " from BJ b inner join ZY z on z.ZYID=b.ZYID"
  506. + " left join BM bm on bm.BMID=z.FZBMID"
  507. + " where b.BJID=:bjid and b." + ObjC.JLZT_useStr
  508. + " and b.BJZTM!=81");
  509. sqlc.wrLongParm("bjid", bjid);
  510. List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
  511. if (rows == null || rows.isEmpty())
  512. throw new IllegalArgumentException("班级不存在或已停用");
  513. if (jdid > 0) {
  514. SqlCmd check = new SqlCmd(
  515. "select count(*) CNT from XJB_JG g"
  516. + " inner join XJB_JD d on d.XJB_JDID=g.XJB_JDID"
  517. + " where g.XJB_JDID=:jdid and g.BJID=:bjid"
  518. + " and g.ZT=5 and d.ZT=5");
  519. check.wrLongParm("jdid", jdid);
  520. check.wrLongParm("bjid", bjid);
  521. db.doSelByC(check);
  522. if (db.rowNum == 0 || db.rdIntCol("cnt") == 0)
  523. throw new IllegalArgumentException("该班级不属于当前已发布月结");
  524. }
  525. return rdClasses(rows).get(0);
  526. }
  527. private static YearMonth rdReportBatchMonth(Db db, long jdid)
  528. throws Exception {
  529. SqlCmd sqlc = new SqlCmd(
  530. "select NDY from XJB_JD where XJB_JDID=:jdid and ZT=5");
  531. sqlc.wrLongParm("jdid", jdid);
  532. db.doSelByC(sqlc);
  533. if (db.rowNum == 0)
  534. throw new IllegalArgumentException("月结批次不存在或未发布");
  535. return YearMonth.parse(db.rdStrCol("ndy"), MONTH_FMT);
  536. }
  537. private static void ensureReportMonth(YearMonth reportMonth,
  538. YearMonth requestedMonth) {
  539. if (reportMonth != null && !reportMonth.equals(requestedMonth))
  540. throw new IllegalArgumentException("明细月份不属于当前月结批次");
  541. }
  542. private static ScoreBook rdScoreBook(Db db, List<ClassInfo> classes,
  543. MonthPeriod period) throws Exception {
  544. ScoreBook book = new ScoreBook();
  545. book.cleaning = rdAvgScoreByClass(db, "CSWSJC", period);
  546. book.flag = rdFlagScoreByClass(db, period);
  547. book.classroom = rdAvgKtjlScoreByClass(db, period);
  548. Set<LocalDate> schoolDays = rdSchoolDays(db, period);
  549. Map<Long, Map<LocalDate, Double>> attendancePenalty =
  550. rdAttendancePenalty(db, period,
  551. XjbDormScoreU.AttendanceScope.DAY_STUDENT);
  552. book.attendance = computeAttendanceScores(
  553. classes, schoolDays, attendancePenalty);
  554. Map<Long, Map<LocalDate, Double>> dormAttendancePenalty =
  555. rdAttendancePenalty(db, period,
  556. XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
  557. book.dormAttendance = computeAttendanceScores(
  558. classes, schoolDays, dormAttendancePenalty);
  559. book.dorm = rdDormScores(db, classes, period, book.dormAttendance);
  560. book.discipline = rdDisciplineScores(db, classes, schoolDays, period);
  561. book.adjustments = rdAdjustmentTotals(db, period.month);
  562. for (ClassInfo cls : classes) {
  563. ClassScore score = new ClassScore();
  564. putScore(score, "dorm", "宿舍评分", book.dorm.get(cls.bjid));
  565. putScore(score, "classroom", "课堂考核",
  566. book.classroom.get(cls.bjid));
  567. putScore(score, "flag", "升旗礼", book.flag.get(cls.bjid));
  568. putScore(score, "cleaning", "清洁卫生",
  569. book.cleaning.get(cls.bjid));
  570. putScore(score, "discipline", "风纪仪容",
  571. book.discipline.get(cls.bjid));
  572. putScore(score, "attendance", "考勤",
  573. book.attendance.get(cls.bjid));
  574. score.adjust = book.adjustments.getOrDefault(
  575. cls.bjid, new AdjustmentTotals());
  576. if (score.missing.isEmpty()) {
  577. double weighted = 0.0;
  578. for (CategoryDef def : CATEGORY_DEFS)
  579. weighted += score.values.get(def.code) * def.weight;
  580. score.total = round2(weighted
  581. + Math.min(8.0, score.adjust.bonus)
  582. - score.adjust.deduction);
  583. }
  584. score.hasMissing = !score.missing.isEmpty();
  585. book.classScores.put(cls.bjid, score);
  586. }
  587. return book;
  588. }
  589. private static void putScore(ClassScore score, String code, String label,
  590. Double value) {
  591. if (value == null) {
  592. score.values.put(code, 0.0);
  593. score.sources.put(code, SOURCE_MISSING);
  594. score.missing.add(label);
  595. return;
  596. }
  597. score.values.put(code, round2(value));
  598. score.sources.put(code, SOURCE_REAL);
  599. }
  600. private static Map<Long, Double> rdAvgScoreByClass(Db db, String table,
  601. MonthPeriod period)
  602. throws Exception {
  603. if (!"SSNWJC".equals(table) && !"CSWSJC".equals(table))
  604. throw new IllegalArgumentException("评分表参数错误");
  605. SqlCmd sqlc = new SqlCmd(
  606. "select BJID,avg(FS) SCORE from " + table
  607. + " where JCSJ>=:start and JCSJ<:end and "
  608. + ObjC.JLZT_useStr + " group by BJID");
  609. sqlc.wrTimeParm("start", period.start);
  610. sqlc.wrTimeParm("end", period.end);
  611. return rdScoreMap(db.doSelMapListByC(sqlc));
  612. }
  613. private static Map<Long, Double> rdDormScores(
  614. Db db, List<ClassInfo> classes, MonthPeriod period,
  615. Map<Long, Double> attendanceScores) throws Exception {
  616. // 学校确认:宿舍内务不再要求上午、下午各有一条,所有有效检查取平均。
  617. SqlCmd internalCmd = new SqlCmd(
  618. "select BJID,avg(FS) SCORE from SSNWJC"
  619. + " where JCSJ>=:start and JCSJ<:end"
  620. + " and " + ObjC.JLZT_useStr + " group by BJID");
  621. internalCmd.wrTimeParm("start", period.start);
  622. internalCmd.wrTimeParm("end", period.end);
  623. Map<Long, Double> internal = new HashMap<>();
  624. for (Map<String, Object> row : db.doSelMapListByC(internalCmd))
  625. internal.put(rdLong(row.get("bjid")), rdDouble(row.get("score")));
  626. // 集体宿舍违纪会按在住学生逐人生成 WJJL;班级计分按同一事件只扣一次。
  627. SqlCmd violationCmd = new SqlCmd(
  628. "select BJID,sum(PENALTY) PENALTY from ("
  629. + "select w.BJID,nvl(lb.BJKF,0) PENALTY,"
  630. + "row_number() over(partition by w.BJID,w.WJLXM,"
  631. + "case when w.WJLXM=5 then w.WJLBM end,"
  632. + "case when w.WJLXM=5 then w.WJSJ end,"
  633. + "case when w.WJLXM=5 then w.JZWID end,"
  634. + "case when w.WJLXM=5 then w.KFID end,"
  635. + "case when w.WJLXM=5 then nvl(w.MS,' ') end,"
  636. + "case when w.WJLXM=5 then nvl(w.FJID,0) end,"
  637. + "case when w.WJLXM=5 then 0 else w.WJJLID end"
  638. + " order by w.WJJLID) RN"
  639. + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
  640. + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
  641. + " and wm.YTM=" + XjbWjlbC.YTM_DORM + " and wm.JLZTM=51"
  642. + " where w.WJSJ>=:start and w.WJSJ<:end"
  643. + " and w.JLZTM=51)"
  644. + " where RN=1 group by BJID");
  645. violationCmd.wrTimeParm("start", period.start);
  646. violationCmd.wrTimeParm("end", period.end);
  647. Map<Long, Double> violations = new HashMap<>();
  648. for (Map<String, Object> row : db.doSelMapListByC(violationCmd))
  649. violations.put(rdLong(row.get("bjid")),
  650. rdDouble(row.get("penalty")));
  651. Map<Long, Double> result = new HashMap<>();
  652. for (ClassInfo cls : classes) {
  653. Double internalScore = internal.get(cls.bjid);
  654. Double attendance = attendanceScores.get(cls.bjid);
  655. if (internalScore == null || attendance == null)
  656. continue;
  657. // 学校确认:宿舍评分允许出现负数。
  658. double violationScore =
  659. 100.0 - violations.getOrDefault(cls.bjid, 0.0);
  660. double base = internalScore * 0.35 + attendance * 0.15
  661. + violationScore * 0.35;
  662. XjbDormScoreU.ManagementSummary management =
  663. XjbDormScoreU.rdManagementSummary(
  664. db, cls.bjid, period.start, period.end);
  665. result.put(cls.bjid, round2(base + base / 85.0 * 10.0
  666. + management.bonus));
  667. }
  668. return result;
  669. }
  670. private static Map<Long, Double> rdDisciplineScores(
  671. Db db, List<ClassInfo> classes, Set<LocalDate> schoolDays,
  672. MonthPeriod period) throws Exception {
  673. Map<Long, Double> result = new HashMap<>();
  674. if (schoolDays.isEmpty())
  675. return result;
  676. DisciplinePenalties penalties = rdDisciplinePenalties(
  677. db, null, period.start, period.end);
  678. for (ClassInfo cls : classes) {
  679. Map<LocalDate, Double> mapped = penalties.mapped.getOrDefault(
  680. cls.bjid, Collections.emptyMap());
  681. Map<LocalDate, Double> legacy = penalties.legacy.getOrDefault(
  682. cls.bjid, Collections.emptyMap());
  683. double total = 0.0;
  684. for (LocalDate day : schoolDays)
  685. total += Math.max(0.0, 100.0
  686. - disciplinePenalty(mapped, legacy, day));
  687. result.put(cls.bjid, round2(total / schoolDays.size()));
  688. }
  689. return result;
  690. }
  691. private static DisciplinePenalties rdDisciplinePenalties(
  692. Db db, Long bjid, Timestamp start, Timestamp end) throws Exception {
  693. DisciplinePenalties result = new DisciplinePenalties();
  694. String bjFilter = bjid == null ? "" : " and w.BJID=:bjid";
  695. SqlCmd current = new SqlCmd(
  696. "select w.BJID,trunc(w.WJSJ) D,sum(nvl(lb.BJKF,0)) PENALTY"
  697. + " from WJJL w"
  698. + " inner join WJLB lb on lb.WJLBM=w.WJLBM"
  699. + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
  700. + " and wm.YTM=" + XjbWjlbC.YTM_DISCIPLINE
  701. + " and wm.JLZTM=51"
  702. + " where w.WJSJ>=:start and w.WJSJ<:end"
  703. + " and w.JLZTM=51" + bjFilter
  704. + " group by w.BJID,trunc(w.WJSJ)");
  705. current.wrTimeParm("start", start);
  706. current.wrTimeParm("end", end);
  707. if (bjid != null)
  708. current.wrLongParm("bjid", bjid);
  709. for (Map<String, Object> row : db.doSelMapListByC(current)) {
  710. long classId = rdLong(row.get("bjid"));
  711. LocalDate day = rdLocalDate(row.get("d"));
  712. if (day != null)
  713. result.mapped.computeIfAbsent(classId, key -> new HashMap<>())
  714. .put(day, rdDouble(row.get("penalty")));
  715. }
  716. SqlCmd legacy = new SqlCmd(
  717. "select BJID,JCRQ D,sum(case when MS like :importMarker"
  718. + " then nvl(WJRS,0)/10 else nvl(WJRS,0) end) PENALTY"
  719. + " from XJB_FJRY"
  720. + " where JCRQ>=:start and JCRQ<:end and JLZTM=51"
  721. + (bjid == null ? "" : " and BJID=:bjid")
  722. + " group by BJID,JCRQ");
  723. legacy.wrStrParm("importMarker", ZHIXIN_STAR_MARKER_PREFIX + "%");
  724. legacy.wrTimeParm("start", start);
  725. legacy.wrTimeParm("end", end);
  726. if (bjid != null)
  727. legacy.wrLongParm("bjid", bjid);
  728. for (Map<String, Object> row : db.doSelMapListByC(legacy)) {
  729. long classId = rdLong(row.get("bjid"));
  730. LocalDate day = rdLocalDate(row.get("d"));
  731. if (day != null)
  732. result.legacy.computeIfAbsent(classId, key -> new HashMap<>())
  733. .put(day, rdDouble(row.get("penalty")));
  734. }
  735. return result;
  736. }
  737. private static double disciplinePenalty(
  738. Map<LocalDate, Double> mapped, Map<LocalDate, Double> legacy,
  739. LocalDate day) {
  740. Double penalty = mapped.get(day);
  741. if (penalty == null)
  742. penalty = legacy.get(day);
  743. return penalty == null ? 0.0 : penalty;
  744. }
  745. private static Map<Long, Double> rdFlagScoreByClass(Db db,
  746. MonthPeriod period)
  747. throws Exception {
  748. SqlCmd sqlc = new SqlCmd(
  749. "select s.BJID,avg(s.ZFS) SCORE from SQLJC s"
  750. + " where s.JCSJ>=:start and s.JCSJ<:end"
  751. + " and s.ZFS between 0 and 100 and s."
  752. + ObjC.JLZT_useStr + " group by s.BJID");
  753. sqlc.wrTimeParm("start", period.start);
  754. sqlc.wrTimeParm("end", period.end);
  755. return rdScoreMap(db.doSelMapListByC(sqlc));
  756. }
  757. private static Map<Long, Double> rdAvgKtjlScoreByClass(
  758. Db db, MonthPeriod period) throws Exception {
  759. try {
  760. SqlCmd sqlc = new SqlCmd(
  761. "select j.BJID,avg(j.FS) SCORE from KTJL j"
  762. + " inner join KCB k on k.KCBID=j.KCBID"
  763. + " where k.KSSJ>=:start and k.KSSJ<:end"
  764. + " and j." + ObjC.JLZT_useStr
  765. + " and k." + ObjC.JLZT_useStr
  766. + " group by j.BJID");
  767. sqlc.wrTimeParm("start", period.start);
  768. sqlc.wrTimeParm("end", period.end);
  769. return rdScoreMap(db.doSelMapListByC(sqlc));
  770. } catch (SQLException e) {
  771. if (isMissingTable(e, "KTJL"))
  772. return Collections.emptyMap();
  773. throw e;
  774. }
  775. }
  776. private static Set<LocalDate> rdSchoolDays(Db db, MonthPeriod period)
  777. throws Exception {
  778. SqlCmd sqlc = new SqlCmd(
  779. "select distinct trunc(KSSJ) D from KQJL"
  780. + " where KSSJ>=:start and KSSJ<:end"
  781. + " and KQJLZTM=51 and " + ObjC.JLZT_useStr);
  782. sqlc.wrTimeParm("start", period.start);
  783. sqlc.wrTimeParm("end", period.end);
  784. Set<LocalDate> days = new LinkedHashSet<>();
  785. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  786. LocalDate day = rdLocalDate(row.get("d"));
  787. if (day != null && !day.isAfter(period.maxDate))
  788. days.add(day);
  789. }
  790. return days;
  791. }
  792. private static Map<Long, Map<LocalDate, Double>> rdAttendancePenalty(
  793. Db db, MonthPeriod period,
  794. XjbDormScoreU.AttendanceScope scope) throws Exception {
  795. Map<Long, Map<LocalDate, Double>> result =
  796. XjbDormScoreU.rdAttendancePenalty(
  797. db, period.start, period.end, scope);
  798. for (Map<LocalDate, Double> values : result.values())
  799. values.keySet().removeIf(day -> day.isAfter(period.maxDate));
  800. return result;
  801. }
  802. private static Map<Long, Double> computeAttendanceScores(
  803. List<ClassInfo> classes, Set<LocalDate> schoolDays,
  804. Map<Long, Map<LocalDate, Double>> penalties) {
  805. Map<Long, Double> result = new HashMap<>();
  806. if (schoolDays.isEmpty())
  807. return result;
  808. List<LocalDate> days = new ArrayList<>(schoolDays);
  809. for (ClassInfo cls : classes) {
  810. Map<LocalDate, Double> classPenalties = penalties.getOrDefault(
  811. cls.bjid, Collections.emptyMap());
  812. double total = 0.0;
  813. for (LocalDate day : days) {
  814. double penalty = classPenalties.getOrDefault(day, 0.0);
  815. total += Math.max(0.0, 100.0 - penalty);
  816. }
  817. result.put(cls.bjid, round2(total / days.size()));
  818. }
  819. return result;
  820. }
  821. private static RankBook rdRanks(List<ClassInfo> classes, ScoreBook book) {
  822. RankBook ranks = new RankBook();
  823. List<ClassInfo> school = new ArrayList<>();
  824. for (ClassInfo cls : classes) {
  825. ClassScore score = book.classScores.get(cls.bjid);
  826. if (score != null && !score.hasMissing)
  827. school.add(cls);
  828. }
  829. school.sort(Comparator
  830. .comparingDouble((ClassInfo cls) ->
  831. -book.classScores.get(cls.bjid).total)
  832. .thenComparingLong(cls -> cls.bjid));
  833. assignRanks(school, book, ranks.schoolRank, "school");
  834. Map<Long, List<ClassInfo>> departments = new LinkedHashMap<>();
  835. for (ClassInfo cls : school)
  836. departments.computeIfAbsent(cls.dwid, key -> new ArrayList<>()).add(cls);
  837. for (Map.Entry<Long, List<ClassInfo>> entry : departments.entrySet()) {
  838. entry.getValue().sort(Comparator
  839. .comparingDouble((ClassInfo cls) ->
  840. -book.classScores.get(cls.bjid).total)
  841. .thenComparingLong(cls -> cls.bjid));
  842. assignRanks(entry.getValue(), book, ranks.departmentRank, "department");
  843. ranks.departmentClassCount.put(entry.getKey(), entry.getValue().size());
  844. }
  845. return ranks;
  846. }
  847. private static void assignRanks(List<ClassInfo> sorted, ScoreBook book,
  848. Map<Long, Integer> rankMap, String type) {
  849. double prev = Double.NaN;
  850. int rank = 0;
  851. for (int i = 0; i < sorted.size(); i++) {
  852. ClassInfo cls = sorted.get(i);
  853. double score = book.classScores.get(cls.bjid).total;
  854. if (i == 0 || Double.compare(prev, score) != 0)
  855. rank = i + 1;
  856. rankMap.put(cls.bjid, rank);
  857. prev = score;
  858. }
  859. }
  860. private static List<DailyAccumulator> rdDailyList(
  861. Db db, ClassInfo cls, MonthPeriod period,
  862. Map<String, String> sources) throws Exception {
  863. CategoryDaily daily = rdCategoryDaily(db, cls, null, period);
  864. Map<LocalDate, DailyAccumulator> days = new HashMap<>();
  865. for (CategoryDef def : CATEGORY_DEFS) {
  866. String source = sources.getOrDefault(def.code, SOURCE_MISSING);
  867. Map<LocalDate, DailyPoint> actual = daily.actual.get(def.code);
  868. for (LocalDate date = period.month.atDay(1);
  869. !date.isAfter(period.maxDate);
  870. date = date.plusDays(1)) {
  871. DailyPoint point = null;
  872. if (SOURCE_REAL.equals(source)) {
  873. point = actual == null ? null : actual.get(date);
  874. }
  875. if (point == null)
  876. continue;
  877. DailyAccumulator acc = days.computeIfAbsent(date,
  878. DailyAccumulator::new);
  879. acc.regularDeduction += Math.max(0.0, 100.0 - point.score);
  880. acc.hasRegular = true;
  881. }
  882. }
  883. List<DailyAccumulator> result = new ArrayList<>(days.values());
  884. result.sort(Comparator.comparing(
  885. (DailyAccumulator item) -> item.date).reversed());
  886. return result;
  887. }
  888. private static CategoryDaily rdCategoryDaily(Db db, ClassInfo cls,
  889. LocalDate onlyDay,
  890. MonthPeriod period)
  891. throws Exception {
  892. CategoryDaily result = new CategoryDaily(cls);
  893. Timestamp start = onlyDay == null ? period.start
  894. : Timestamp.valueOf(onlyDay.atStartOfDay());
  895. Timestamp end = onlyDay == null ? period.end
  896. : Timestamp.valueOf(onlyDay.plusDays(1).atStartOfDay());
  897. result.actual.put("dorm", rdDailyDormScore(db, cls,
  898. onlyDay, period));
  899. result.actual.put("cleaning", rdDailyAvgScore(db, "CSWSJC",
  900. cls.bjid, start, end));
  901. result.actual.put("flag", rdDailyFlagScore(db, cls.bjid, start, end));
  902. result.actual.put("classroom", rdDailyKtjlScore(
  903. db, cls.bjid, start, end));
  904. result.actual.put("attendance", rdDailyAttendanceScore(db,
  905. cls.bjid, start, end,
  906. XjbDormScoreU.AttendanceScope.DAY_STUDENT));
  907. result.actual.put("discipline", rdDailyDisciplineScore(
  908. db, cls.bjid, start, end));
  909. MonthPeriod fullMonth = MonthPeriod.of(period.month);
  910. Map<Long, Double> monthClean = rdAvgScoreByClass(db, "CSWSJC", fullMonth);
  911. Map<Long, Double> monthFlag = rdFlagScoreByClass(db, fullMonth);
  912. Set<LocalDate> monthSchoolDays = rdSchoolDays(db, fullMonth);
  913. Map<Long, Double> monthAttendance = computeAttendanceScores(
  914. List.of(cls), monthSchoolDays,
  915. rdAttendancePenalty(db, fullMonth,
  916. XjbDormScoreU.AttendanceScope.DAY_STUDENT));
  917. Map<Long, Double> monthDormAttendance = computeAttendanceScores(
  918. List.of(cls), monthSchoolDays,
  919. rdAttendancePenalty(db, fullMonth,
  920. XjbDormScoreU.AttendanceScope.BOARDING_STUDENT));
  921. Map<Long, Double> monthDorm = rdDormScores(db, List.of(cls),
  922. fullMonth, monthDormAttendance);
  923. Map<Long, Double> monthClassroom =
  924. rdAvgKtjlScoreByClass(db, fullMonth);
  925. Map<Long, Double> monthDiscipline =
  926. rdDisciplineScores(db, List.of(cls), monthSchoolDays,
  927. fullMonth);
  928. result.sources.put("dorm", monthDorm.containsKey(cls.bjid)
  929. ? SOURCE_REAL : SOURCE_MISSING);
  930. result.sources.put("classroom",
  931. monthClassroom.containsKey(cls.bjid)
  932. ? SOURCE_REAL : SOURCE_MISSING);
  933. result.sources.put("flag", monthFlag.containsKey(cls.bjid)
  934. ? SOURCE_REAL : SOURCE_MISSING);
  935. result.sources.put("cleaning", monthClean.containsKey(cls.bjid)
  936. ? SOURCE_REAL : SOURCE_MISSING);
  937. result.sources.put("discipline",
  938. monthDiscipline.containsKey(cls.bjid)
  939. ? SOURCE_REAL : SOURCE_MISSING);
  940. result.sources.put("attendance", monthAttendance.containsKey(cls.bjid)
  941. ? SOURCE_REAL : SOURCE_MISSING);
  942. return result;
  943. }
  944. private static Map<LocalDate, DailyPoint> rdDailyAvgScore(
  945. Db db, String table, long bjid, Timestamp start, Timestamp end)
  946. throws Exception {
  947. SqlCmd sqlc = new SqlCmd(
  948. "select trunc(JCSJ) D,avg(FS) SCORE,count(*) CNT from "
  949. + table + " where BJID=:bjid and JCSJ>=:start"
  950. + " and JCSJ<:end and " + ObjC.JLZT_useStr
  951. + " group by trunc(JCSJ)");
  952. sqlc.wrLongParm("bjid", bjid);
  953. sqlc.wrTimeParm("start", start);
  954. sqlc.wrTimeParm("end", end);
  955. return rdDailyPoints(db.doSelMapListByC(sqlc));
  956. }
  957. private static Map<LocalDate, DailyPoint> rdDailyDormScore(
  958. Db db, ClassInfo cls, LocalDate onlyDay, MonthPeriod period)
  959. throws Exception {
  960. Timestamp start = onlyDay == null ? period.start
  961. : Timestamp.valueOf(onlyDay.atStartOfDay());
  962. Timestamp end = onlyDay == null ? period.end
  963. : Timestamp.valueOf(onlyDay.plusDays(1).atStartOfDay());
  964. // 学校确认:单日宿舍内务按当天所有有效记录取平均,不区分上午/下午。
  965. SqlCmd itemCmd = new SqlCmd(
  966. "select trunc(JCSJ) D,avg(FS) SCORE,count(*) CNT"
  967. + " from SSNWJC where BJID=:bjid and JCSJ>=:start"
  968. + " and JCSJ<:end and " + ObjC.JLZT_useStr
  969. + " group by trunc(JCSJ)");
  970. itemCmd.wrLongParm("bjid", cls.bjid);
  971. itemCmd.wrTimeParm("start", start);
  972. itemCmd.wrTimeParm("end", end);
  973. Map<LocalDate, DailyPoint> internal = rdDailyPoints(
  974. db.doSelMapListByC(itemCmd));
  975. Map<LocalDate, Double> violations =
  976. rdDormViolationPenalties(db, cls.bjid, start, end);
  977. Map<Long, Map<LocalDate, Double>> attendancePenalties =
  978. XjbDormScoreU.rdAttendancePenalty(
  979. db, start, end,
  980. XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
  981. Map<LocalDate, Double> classAttendancePenalty =
  982. attendancePenalties.getOrDefault(
  983. cls.bjid, Collections.emptyMap());
  984. Map<LocalDate, DailyPoint> result = new HashMap<>();
  985. for (Map.Entry<LocalDate, DailyPoint> entry : internal.entrySet()) {
  986. DailyPoint internalPoint = entry.getValue();
  987. double attendanceScore = Math.max(0.0, 100.0
  988. - classAttendancePenalty.getOrDefault(
  989. entry.getKey(), 0.0));
  990. double violationScore =
  991. 100.0 - violations.getOrDefault(entry.getKey(), 0.0);
  992. double base = internalPoint.score * 0.35
  993. + attendanceScore * 0.15
  994. + violationScore * 0.35;
  995. result.put(entry.getKey(), new DailyPoint(entry.getKey(),
  996. round2(base + base / 85.0 * 10.0),
  997. internalPoint.count));
  998. }
  999. return result;
  1000. }
  1001. private static List<Map<String, Object>> rdDormDaySummary(
  1002. Db db, ClassInfo cls, LocalDate day) throws Exception {
  1003. Timestamp start = Timestamp.valueOf(day.atStartOfDay());
  1004. Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
  1005. MonthPeriod month = MonthPeriod.of(YearMonth.from(day));
  1006. Map<LocalDate, DailyPoint> internal =
  1007. rdDailyAvgScore(db, "SSNWJC", cls.bjid, start, end);
  1008. DailyPoint internalPoint = internal.get(day);
  1009. Map<Long, Map<LocalDate, Double>> attendancePenalties =
  1010. XjbDormScoreU.rdAttendancePenalty(
  1011. db, start, end,
  1012. XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
  1013. double attendancePenalty = attendancePenalties
  1014. .getOrDefault(cls.bjid, Collections.emptyMap())
  1015. .getOrDefault(day, 0.0);
  1016. double attendanceScore = Math.max(0.0, 100.0 - attendancePenalty);
  1017. double violationPenalty = rdDormViolationPenalties(
  1018. db, cls.bjid, start, end).getOrDefault(day, 0.0);
  1019. XjbDormScoreU.ManagementSummary management =
  1020. XjbDormScoreU.rdManagementSummary(
  1021. db, cls.bjid, month.start, month.end);
  1022. List<Map<String, Object>> rows = new ArrayList<>();
  1023. rows.add(dormSummaryRow(day, "attendance", "考勤",
  1024. round2(attendanceScore), "实", "住宿生当日考勤",
  1025. true, "attendance"));
  1026. if (internalPoint == null) {
  1027. rows.add(dormSummaryRow(day, "internal", "内务",
  1028. null, "缺", "当日暂无有效内务检查", false, "internal"));
  1029. } else {
  1030. rows.add(dormSummaryRow(day, "internal", "内务",
  1031. round2(internalPoint.score), "实",
  1032. "共" + internalPoint.count + "条内务检查",
  1033. true, "internal"));
  1034. }
  1035. rows.add(dormSummaryRow(day, "violation", "违纪扣分",
  1036. violationPenalty > 0.0 ? -round2(violationPenalty) : 0.0,
  1037. "实",
  1038. violationPenalty > 0
  1039. ? "宿舍违纪已在基础分中扣减"
  1040. : "当日无宿舍违纪扣分",
  1041. violationPenalty > 0, "violation"));
  1042. double managementScore = management.available
  1043. ? management.bonus : 0.0;
  1044. rows.add(dormSummaryRow(day, "management", "增分",
  1045. managementScore, "实", "",
  1046. management.available, "management"));
  1047. rows.add(dormSummaryRow(day, "deduction", "减分",
  1048. 0.0, "停", "宿舍减分规则暂未启用",
  1049. false, "deduction"));
  1050. return rows;
  1051. }
  1052. private static Map<String, Object> dormSummaryRow(
  1053. LocalDate day, String key, String itemName, Double score,
  1054. String state, String meta, boolean traceable, String detailType) {
  1055. Map<String, Object> row = baseDetail(day, SOURCE_REAL);
  1056. row.put("id", key);
  1057. row.put("sourceId", key);
  1058. row.put("sourceType", "dormDaySummary");
  1059. row.put("detailKind", "dormSummary");
  1060. row.put("category", "dorm");
  1061. row.put("key", key);
  1062. row.put("itemName", itemName);
  1063. row.put("title", itemName);
  1064. row.put("score", score);
  1065. row.put("scoreText", score == null ? "-"
  1066. : String.format(Locale.ROOT, "%.2f", score));
  1067. row.put("state", state);
  1068. row.put("remark", meta);
  1069. row.put("traceable", traceable);
  1070. row.put("detailType", detailType);
  1071. row.put("sortTime", key);
  1072. return row;
  1073. }
  1074. private static Map<LocalDate, Double> rdDormViolationPenalties(
  1075. Db db, long bjid, Timestamp start, Timestamp end)
  1076. throws Exception {
  1077. SqlCmd violationCmd = new SqlCmd(
  1078. "select D,sum(PENALTY) PENALTY from ("
  1079. + "select trunc(w.WJSJ) D,nvl(lb.BJKF,0) PENALTY,"
  1080. + "row_number() over(partition by w.BJID,w.WJLXM,"
  1081. + "case when w.WJLXM=5 then w.WJLBM end,"
  1082. + "case when w.WJLXM=5 then w.WJSJ end,"
  1083. + "case when w.WJLXM=5 then w.JZWID end,"
  1084. + "case when w.WJLXM=5 then w.KFID end,"
  1085. + "case when w.WJLXM=5 then nvl(w.MS,' ') end,"
  1086. + "case when w.WJLXM=5 then nvl(w.FJID,0) end,"
  1087. + "case when w.WJLXM=5 then 0 else w.WJJLID end"
  1088. + " order by w.WJJLID) RN"
  1089. + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
  1090. + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
  1091. + " and wm.YTM=" + XjbWjlbC.YTM_DORM
  1092. + " and wm.JLZTM=51"
  1093. + " where w.BJID=:bjid and w.WJSJ>=:start"
  1094. + " and w.WJSJ<:end and w.JLZTM=51)"
  1095. + " where RN=1 group by D");
  1096. violationCmd.wrLongParm("bjid", bjid);
  1097. violationCmd.wrTimeParm("start", start);
  1098. violationCmd.wrTimeParm("end", end);
  1099. Map<LocalDate, Double> result = new HashMap<>();
  1100. for (Map<String, Object> row : db.doSelMapListByC(violationCmd)) {
  1101. LocalDate day = rdLocalDate(row.get("d"));
  1102. if (day != null)
  1103. result.put(day, rdDouble(row.get("penalty")));
  1104. }
  1105. return result;
  1106. }
  1107. private static Map<String, Object> rdDormManagementTrace(
  1108. Db db, ClassInfo cls, LocalDate day, YearMonth reportMonth)
  1109. throws Exception {
  1110. YearMonth month = reportMonth == null
  1111. ? YearMonth.from(day) : reportMonth;
  1112. MonthPeriod period = MonthPeriod.of(month);
  1113. XjbDormScoreU.ManagementSummary summary =
  1114. XjbDormScoreU.rdManagementSummary(
  1115. db, cls.bjid, period.start, period.end);
  1116. Map<String, Object> record = new LinkedHashMap<>();
  1117. record.put("time", day.format(DATE_FMT));
  1118. record.put("className", cls.bjmc);
  1119. record.put("teacherName", summary.teacherName);
  1120. record.put("visitCount", summary.visitCount);
  1121. record.put("bonus", summary.bonus);
  1122. record.put("description", summary.message);
  1123. record.put("source", summary.source);
  1124. List<Map<String, Object>> items = new ArrayList<>();
  1125. for (XjbDormScoreU.Visit visit : summary.visits) {
  1126. Map<String, Object> item = new LinkedHashMap<>();
  1127. item.put("itemName", "有效参与");
  1128. item.put("remark", XjbDormScoreU.formatMinute(visit.enterTime)
  1129. + " 至 " + XjbDormScoreU.formatMinute(visit.leaveTime)
  1130. + ",共" + visit.minutes + "分钟"
  1131. + (StringUtils.isBlank(visit.mjdName)
  1132. ? "" : "," + visit.mjdName));
  1133. item.put("deducted", 0.0);
  1134. items.add(item);
  1135. }
  1136. CategoryDef category = requireCategory("dorm");
  1137. return traceResult(cls, day, category, SOURCE_REAL,
  1138. "班主任宿舍管理参与详情", record, items,
  1139. summary.available ? "" : summary.message);
  1140. }
  1141. private static List<Map<String, Object>> rdDormInternalDetail(
  1142. Db db, long bjid, LocalDate day) throws Exception {
  1143. Timestamp start = Timestamp.valueOf(day.atStartOfDay());
  1144. Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
  1145. SqlCmd sqlc = new SqlCmd(
  1146. "select s.SSNWJCID,s.FS,s.MS,s.JCSJ,cd.MC KFMC,"
  1147. + "jc.XM JCRYXM from SSNWJC s"
  1148. + " left join CD cd on cd.CDID=s.KFID"
  1149. + " left join RY jc on jc.RYID=s.JCRYID"
  1150. + " where s.BJID=:bjid and s.JCSJ>=:start"
  1151. + " and s.JCSJ<:end and s." + ObjC.JLZT_useStr
  1152. + " order by s.JCSJ desc,s.SSNWJCID desc");
  1153. sqlc.wrLongParm("bjid", bjid);
  1154. sqlc.wrTimeParm("start", start);
  1155. sqlc.wrTimeParm("end", end);
  1156. List<Map<String, Object>> result = new ArrayList<>();
  1157. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  1158. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1159. long id = rdLong(row.get("ssnwjcid"));
  1160. double score = rdDouble(row.get("fs"));
  1161. item.put("id", id);
  1162. item.put("sourceId", id);
  1163. item.put("category", "dorm");
  1164. item.put("traceable", true);
  1165. item.put("itemName", "内务检查");
  1166. item.put("roomName", rdStr(row.get("kfmc")));
  1167. item.put("title", rdStr(row.get("kfmc")));
  1168. item.put("remark", rdStr(row.get("ms")));
  1169. item.put("scoreText", score + "/100");
  1170. item.put("delta", round2(score - 100.0));
  1171. item.put("sortTime", formatTimestamp(row.get("jcsj")));
  1172. result.add(item);
  1173. }
  1174. return result;
  1175. }
  1176. private static List<Map<String, Object>> rdImportedCleaningSummary(
  1177. Db db, long bjid, LocalDate day) throws Exception {
  1178. SqlCmd sqlc = new SqlCmd(
  1179. "select CSWSJCID,FS,JCSJ from CSWSJC"
  1180. + " where BJID=:bjid"
  1181. + " and trunc(JCSJ)=to_date(:day,'YYYY-MM-DD')"
  1182. + " and MS like :marker and JLZTM=51");
  1183. sqlc.wrLongParm("bjid", bjid);
  1184. sqlc.wrStrParm("day", day.format(DATE_FMT));
  1185. sqlc.wrStrParm("marker", ZHIXIN_STAR_MARKER_PREFIX + "%");
  1186. List<Map<String, Object>> result = new ArrayList<>();
  1187. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  1188. double score = rdDouble(row.get("fs"));
  1189. double deduction = round2(Math.max(0.0, 100.0 - score));
  1190. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1191. item.put("id", rdLong(row.get("cswsjcid")));
  1192. item.put("sourceId", rdLong(row.get("cswsjcid")));
  1193. item.put("category", "cleaning");
  1194. item.put("traceable", false);
  1195. item.put("itemName", "清洁卫生日总分");
  1196. item.put("title", "清洁卫生日总分");
  1197. item.put("remark", "");
  1198. item.put("delta", -deduction);
  1199. item.put("scoreText", plainNumber(score) + "/100");
  1200. item.put("sortTime", formatTimestamp(row.get("jcsj")));
  1201. result.add(item);
  1202. }
  1203. return result;
  1204. }
  1205. private static List<Map<String, Object>> rdDormViolationDetail(
  1206. Db db, long bjid, LocalDate day) throws Exception {
  1207. Timestamp start = Timestamp.valueOf(day.atStartOfDay());
  1208. Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
  1209. SqlCmd sqlc = new SqlCmd(
  1210. "select WJJLID,D,RYXM,WJLBMC,BJKF,WJSJ,MS from ("
  1211. + "select w.WJJLID,trunc(w.WJSJ) D,ry.XM RYXM,"
  1212. + "lb.MC WJLBMC,nvl(lb.BJKF,0) BJKF,w.WJSJ,w.MS,"
  1213. + "row_number() over(partition by w.BJID,w.WJLXM,"
  1214. + "case when w.WJLXM=5 then w.WJLBM end,"
  1215. + "case when w.WJLXM=5 then w.WJSJ end,"
  1216. + "case when w.WJLXM=5 then w.JZWID end,"
  1217. + "case when w.WJLXM=5 then w.KFID end,"
  1218. + "case when w.WJLXM=5 then nvl(w.MS,' ') end,"
  1219. + "case when w.WJLXM=5 then nvl(w.FJID,0) end,"
  1220. + "case when w.WJLXM=5 then 0 else w.WJJLID end"
  1221. + " order by w.WJJLID) RN"
  1222. + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
  1223. + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
  1224. + " and wm.YTM=" + XjbWjlbC.YTM_DORM
  1225. + " and wm.JLZTM=51"
  1226. + " left join RY ry on ry.RYID=w.RYID"
  1227. + " where w.BJID=:bjid and w.WJSJ>=:start"
  1228. + " and w.WJSJ<:end and w.JLZTM=51)"
  1229. + " where RN=1 order by WJSJ desc,WJJLID desc");
  1230. sqlc.wrLongParm("bjid", bjid);
  1231. sqlc.wrTimeParm("start", start);
  1232. sqlc.wrTimeParm("end", end);
  1233. List<Map<String, Object>> result = new ArrayList<>();
  1234. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  1235. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1236. item.put("id", rdLong(row.get("wjjlid")));
  1237. item.put("sourceId", rdLong(row.get("wjjlid")));
  1238. item.put("category", "dorm");
  1239. item.put("traceable", false);
  1240. item.put("itemName", rdStr(row.get("wjlbmc")));
  1241. item.put("studentName", rdStr(row.get("ryxm")));
  1242. item.put("title", rdStr(row.get("wjlbmc")));
  1243. item.put("remark", rdStr(row.get("ms")));
  1244. item.put("delta", -rdDouble(row.get("bjkf")));
  1245. item.put("scoreText", "");
  1246. item.put("sortTime", formatTimestamp(row.get("wjsj")));
  1247. result.add(item);
  1248. }
  1249. return result;
  1250. }
  1251. private static Map<LocalDate, DailyPoint> rdDailyDisciplineScore(
  1252. Db db, long bjid, Timestamp start, Timestamp end)
  1253. throws Exception {
  1254. DisciplinePenalties penalties = rdDisciplinePenalties(
  1255. db, bjid, start, end);
  1256. Map<LocalDate, Double> mapped = penalties.mapped.getOrDefault(
  1257. bjid, Collections.emptyMap());
  1258. Map<LocalDate, Double> legacy = penalties.legacy.getOrDefault(
  1259. bjid, Collections.emptyMap());
  1260. Set<LocalDate> dates = new LinkedHashSet<>(mapped.keySet());
  1261. dates.addAll(legacy.keySet());
  1262. Map<LocalDate, DailyPoint> result = new HashMap<>();
  1263. for (LocalDate day : dates) {
  1264. double penalty = disciplinePenalty(mapped, legacy, day);
  1265. result.put(day, new DailyPoint(day,
  1266. Math.max(0.0, 100.0 - penalty), 1));
  1267. }
  1268. return result;
  1269. }
  1270. private static Map<LocalDate, DailyPoint> rdDailyFlagScore(
  1271. Db db, long bjid, Timestamp start, Timestamp end) throws Exception {
  1272. SqlCmd sqlc = new SqlCmd(
  1273. "select trunc(s.JCSJ) D,avg(s.ZFS) SCORE,count(*) CNT"
  1274. + " from SQLJC s where s.BJID=:bjid and s.JCSJ>=:start"
  1275. + " and s.JCSJ<:end and s.ZFS between 0 and 100"
  1276. + " and s." + ObjC.JLZT_useStr
  1277. + " group by trunc(s.JCSJ)");
  1278. sqlc.wrLongParm("bjid", bjid);
  1279. sqlc.wrTimeParm("start", start);
  1280. sqlc.wrTimeParm("end", end);
  1281. return rdDailyPoints(db.doSelMapListByC(sqlc));
  1282. }
  1283. private static Map<LocalDate, DailyPoint> rdDailyKtjlScore(
  1284. Db db, long bjid, Timestamp start, Timestamp end) throws Exception {
  1285. try {
  1286. SqlCmd sqlc = new SqlCmd(
  1287. "select trunc(k.KSSJ) D,avg(j.FS) SCORE,count(*) CNT"
  1288. + " from KTJL j inner join KCB k on k.KCBID=j.KCBID"
  1289. + " where j.BJID=:bjid and k.KSSJ>=:start"
  1290. + " and k.KSSJ<:end and j." + ObjC.JLZT_useStr
  1291. + " and k." + ObjC.JLZT_useStr
  1292. + " group by trunc(k.KSSJ)");
  1293. sqlc.wrLongParm("bjid", bjid);
  1294. sqlc.wrTimeParm("start", start);
  1295. sqlc.wrTimeParm("end", end);
  1296. return rdDailyPoints(db.doSelMapListByC(sqlc));
  1297. } catch (SQLException e) {
  1298. if (isMissingTable(e, "KTJL"))
  1299. return Collections.emptyMap();
  1300. throw e;
  1301. }
  1302. }
  1303. private static Map<LocalDate, DailyPoint> rdDailyAttendanceScore(
  1304. Db db, long bjid, Timestamp start, Timestamp end,
  1305. XjbDormScoreU.AttendanceScope scope) throws Exception {
  1306. Map<Long, Map<LocalDate, Double>> penalties =
  1307. XjbDormScoreU.rdAttendancePenalty(db, start, end, scope);
  1308. Map<LocalDate, Double> classPenalties =
  1309. penalties.getOrDefault(bjid, Collections.emptyMap());
  1310. Map<LocalDate, DailyPoint> points = new HashMap<>();
  1311. for (Map.Entry<LocalDate, Double> entry : classPenalties.entrySet()) {
  1312. points.put(entry.getKey(), new DailyPoint(entry.getKey(),
  1313. Math.max(0.0, 100.0 - entry.getValue()), 1));
  1314. }
  1315. return points;
  1316. }
  1317. private static Map<LocalDate, DailyPoint> rdDailyPoints(
  1318. List<Map<String, Object>> rows) {
  1319. Map<LocalDate, DailyPoint> points = new HashMap<>();
  1320. for (Map<String, Object> row : rows) {
  1321. LocalDate day = rdLocalDate(row.get("d"));
  1322. if (day != null)
  1323. points.put(day, new DailyPoint(day,
  1324. rdDouble(row.get("score")), rdInt(row.get("cnt"))));
  1325. }
  1326. return points;
  1327. }
  1328. private static List<Map<String, Object>> rdMonthCategoryRows(
  1329. Db db, ClassInfo cls, MonthPeriod period, CategoryDef category)
  1330. throws Exception {
  1331. CategoryDaily monthly = rdCategoryDaily(db, cls, null, period);
  1332. String source = monthly.sources.getOrDefault(
  1333. category.code, SOURCE_MISSING);
  1334. Map<LocalDate, DailyPoint> points = monthly.actual.get(category.code);
  1335. List<Map<String, Object>> rows = new ArrayList<>();
  1336. if (SOURCE_REAL.equals(source) && points != null) {
  1337. for (DailyPoint point : points.values()) {
  1338. double deduction = round2(
  1339. Math.max(0.0, 100.0 - point.score));
  1340. Map<String, Object> row = baseDetail(point.date, SOURCE_REAL);
  1341. row.put("id", point.date.format(DATE_FMT));
  1342. row.put("sourceId", point.date.format(DATE_FMT));
  1343. row.put("sourceType", category.code);
  1344. row.put("detailKind", "regular");
  1345. row.put("category", category.code);
  1346. row.put("itemName", category.label);
  1347. row.put("weekday", weekdayCn(point.date));
  1348. row.put("score", round2(point.score));
  1349. row.put("deduction", deduction);
  1350. row.put("delta", -deduction);
  1351. row.put("count", point.count);
  1352. row.put("traceable", true);
  1353. row.put("sortTime", point.date.format(DATE_FMT));
  1354. rows.add(row);
  1355. }
  1356. }
  1357. rows.sort(Comparator.comparing(
  1358. (Map<String, Object> row) -> String.valueOf(
  1359. row.getOrDefault("sortTime", ""))).reversed());
  1360. return rows;
  1361. }
  1362. private static List<Map<String, Object>> rdDayDetail(
  1363. Db db, ClassInfo cls, LocalDate day, MonthPeriod period,
  1364. CategoryDef category) throws Exception {
  1365. CategoryDaily monthly = rdCategoryDaily(db, cls, day, period);
  1366. String source = monthly.sources.getOrDefault(
  1367. category.code, SOURCE_MISSING);
  1368. List<Map<String, Object>> rows;
  1369. if (SOURCE_REAL.equals(source)) {
  1370. if ("attendance".equals(category.code))
  1371. rows = rdAttendanceDetail(db, cls.bjid, day,
  1372. XjbDormScoreU.AttendanceScope.DAY_STUDENT);
  1373. else if ("dorm".equals(category.code))
  1374. rows = rdItemDetail(db, cls.bjid, day, "dorm");
  1375. else if ("flag".equals(category.code))
  1376. rows = rdItemDetail(db, cls.bjid, day, "flag");
  1377. else if ("cleaning".equals(category.code))
  1378. rows = rdItemDetail(db, cls.bjid, day, "cleaning");
  1379. else if ("classroom".equals(category.code))
  1380. rows = rdKtjlDetail(db, cls.bjid, day);
  1381. else if ("discipline".equals(category.code))
  1382. rows = rdDisciplineDetail(db, cls.bjid, day);
  1383. else
  1384. rows = new ArrayList<>();
  1385. } else {
  1386. rows = new ArrayList<>();
  1387. }
  1388. rows.sort(Comparator.comparing(
  1389. (Map<String, Object> row) -> String.valueOf(
  1390. row.getOrDefault("sortTime", ""))).reversed());
  1391. return rows;
  1392. }
  1393. private static List<Map<String, Object>> rdAttendanceDetail(
  1394. Db db, long bjid, LocalDate day,
  1395. XjbDormScoreU.AttendanceScope scope) throws Exception {
  1396. Timestamp start = Timestamp.valueOf(day.atStartOfDay());
  1397. Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
  1398. SqlCmd sqlc = new SqlCmd(
  1399. "select * from (select k.KQJLID,k.KQLBM,lb.MC KQLBMC,"
  1400. + "k.RYID,ry.XM,k.MC,k.MS,k.KSSJ,bjcy.SFZS,"
  1401. + "case k.KQLBM when 1 then 3 when 21 then 1"
  1402. + " when 51 then 1 when 52 then 1 when 61 then 2"
  1403. + " else 0 end PENALTY,"
  1404. + "row_number() over(partition by NVL(k.RYID,-k.KQJLID)"
  1405. + " order by case k.KQLBM when 1 then 3 when 21 then 1"
  1406. + " when 51 then 1 when 52 then 1 when 61 then 2"
  1407. + " else 0 end desc,k.KSSJ desc,k.KQJLID desc) RN"
  1408. + " from KQJL k"
  1409. + " inner join BJCY bjcy on bjcy.RYID=k.RYID"
  1410. + " and bjcy.BJID=k.BJID and bjcy.SFBY=0"
  1411. + " and bjcy." + ObjC.JLZT_useStr
  1412. + " left join KQLB lb on lb.KQLBM=k.KQLBM"
  1413. + " left join RY ry on ry.RYID=k.RYID"
  1414. + " where k.BJID=:bjid and k.KSSJ>=:start"
  1415. + " and k.KSSJ<:end and k.KQJLZTM=51 and k."
  1416. + ObjC.JLZT_useStr
  1417. + " and bjcy.SFZS=:sfzs"
  1418. + " and k.KQLBM in(" + scope.codes + ")) where RN=1"
  1419. + " order by KSSJ desc,KQJLID desc");
  1420. sqlc.wrLongParm("bjid", bjid);
  1421. sqlc.wrTimeParm("start", start);
  1422. sqlc.wrTimeParm("end", end);
  1423. sqlc.wrIntParm("sfzs", scope.sfzs);
  1424. List<Map<String, Object>> result = new ArrayList<>();
  1425. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  1426. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1427. item.put("id", rdLong(row.get("kqjlid")));
  1428. item.put("sourceId", rdLong(row.get("kqjlid")));
  1429. item.put("category", "attendance");
  1430. item.put("traceable", true);
  1431. item.put("itemName", rdStr(row.get("kqlbmc")));
  1432. item.put("studentType",
  1433. scope == XjbDormScoreU.AttendanceScope.DAY_STUDENT
  1434. ? "走读生" : "住校生");
  1435. item.put("studentName", rdStr(row.get("xm")));
  1436. item.put("title", rdStr(row.get("mc")));
  1437. item.put("remark", rdStr(row.get("ms")));
  1438. item.put("delta", -rdDouble(row.get("penalty")));
  1439. item.put("scoreText", "");
  1440. item.put("sortTime", formatTimestamp(row.get("kssj")));
  1441. result.add(item);
  1442. }
  1443. return result;
  1444. }
  1445. private static List<Map<String, Object>> rdDisciplineDetail(
  1446. Db db, long bjid, LocalDate day) throws Exception {
  1447. Timestamp start = Timestamp.valueOf(day.atStartOfDay());
  1448. Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
  1449. SqlCmd sqlc = new SqlCmd(
  1450. "select w.WJJLID,w.RYID,ry.XM,lb.WJLBM,lb.MC WJLBMC,"
  1451. + "lb.BJKF,w.WJSJ,w.MS,w.WJLXM"
  1452. + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
  1453. + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
  1454. + " and wm.YTM=" + XjbWjlbC.YTM_DISCIPLINE
  1455. + " and wm.JLZTM=51"
  1456. + " left join RY ry on ry.RYID=w.RYID"
  1457. + " where w.BJID=:bjid and w.WJSJ>=:start"
  1458. + " and w.WJSJ<:end and w.JLZTM=51"
  1459. + " order by w.WJSJ,w.WJJLID");
  1460. sqlc.wrLongParm("bjid", bjid);
  1461. sqlc.wrTimeParm("start", start);
  1462. sqlc.wrTimeParm("end", end);
  1463. List<Map<String, Object>> result = new ArrayList<>();
  1464. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  1465. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1466. item.put("id", rdLong(row.get("wjjlid")));
  1467. item.put("sourceId", rdLong(row.get("wjjlid")));
  1468. item.put("category", "discipline");
  1469. item.put("traceable", true);
  1470. item.put("itemName", rdStr(row.get("wjlbmc")));
  1471. item.put("studentName", rdStr(row.get("xm")));
  1472. item.put("title", rdStr(row.get("wjlbmc")));
  1473. item.put("remark", rdStr(row.get("ms")));
  1474. item.put("delta", -rdDouble(row.get("bjkf")));
  1475. item.put("scoreText", "");
  1476. item.put("sortTime", formatTimestamp(row.get("wjsj")));
  1477. result.add(item);
  1478. }
  1479. if (result.isEmpty())
  1480. result.addAll(rdLegacyDisciplineDetail(db, bjid, day));
  1481. return result;
  1482. }
  1483. private static List<Map<String, Object>> rdLegacyDisciplineDetail(
  1484. Db db, long bjid, LocalDate day) throws Exception {
  1485. SqlCmd sqlc = new SqlCmd(
  1486. "select XJB_FJRYID,WJRS,MS from XJB_FJRY"
  1487. + " where BJID=:bjid and JCRQ=:jcrq and JLZTM=51");
  1488. sqlc.wrLongParm("bjid", bjid);
  1489. sqlc.wrTimeParm("jcrq", Timestamp.valueOf(day.atStartOfDay()));
  1490. List<Map<String, Object>> result = new ArrayList<>();
  1491. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  1492. boolean imported = isZhixinStarImport(rdStr(row.get("ms")));
  1493. double count = imported
  1494. ? rdDouble(row.get("wjrs")) / 10.0
  1495. : rdInt(row.get("wjrs"));
  1496. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1497. item.put("id", rdLong(row.get("xjb_fjryid")));
  1498. item.put("sourceId", rdLong(row.get("xjb_fjryid")));
  1499. item.put("category", "discipline");
  1500. item.put("traceable", true);
  1501. item.put("itemName", imported ? "风纪仪容扣分" : "风纪仪容违纪");
  1502. item.put("studentName", "");
  1503. item.put("title", imported
  1504. ? "风纪仪容扣分 " + plainNumber(count)
  1505. : "风纪仪容违纪 " + (int) count + "人次");
  1506. item.put("remark", imported ? "" : rdStr(row.get("ms")));
  1507. item.put("delta", -count);
  1508. item.put("scoreText",
  1509. plainNumber(Math.max(0, 100 - count)) + "/100");
  1510. item.put("sortTime", day.format(DATE_FMT));
  1511. result.add(item);
  1512. }
  1513. return result;
  1514. }
  1515. private static List<Map<String, Object>> rdItemDetail(
  1516. Db db, long bjid, LocalDate day, String category) throws Exception {
  1517. Timestamp start = Timestamp.valueOf(day.atStartOfDay());
  1518. Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
  1519. String sql;
  1520. if ("dorm".equals(category)) {
  1521. sql = "select s.SSNWJCID ID,s.KFID,cd.MC KFMC,"
  1522. + "m.SSNWJCXMM XMM,m.FS,x.MFZ,x.MC XMMC,s.JCSJ"
  1523. + " from SSNWJC s inner join SSNWJCMX m"
  1524. + " on m.SSNWJCID=s.SSNWJCID"
  1525. + " inner join SSNWJCXM x on x.SSNWJCXMM=m.SSNWJCXMM"
  1526. + " left join CD cd on cd.CDID=s.KFID"
  1527. + " where s.BJID=:bjid and s.JCSJ>=:start"
  1528. + " and s.JCSJ<:end and s." + ObjC.JLZT_useStr
  1529. + " and m." + ObjC.JLZT_useStr
  1530. + " and m.FS<x.MFZ"
  1531. + " order by s.JCSJ desc,m.SSNWJCMXID";
  1532. } else if ("flag".equals(category)) {
  1533. sql = "select s.SQLJCID ID,m.SQLJCXMM XMM,m.FS,x.MFZ,"
  1534. + "x.MC XMMC,s.JCSJ from SQLJC s"
  1535. + " inner join SQLJCMX m on m.SQLJCID=s.SQLJCID"
  1536. + " inner join SQLJCXM x on x.SQLJCXMM=m.SQLJCXMM"
  1537. + " where s.BJID=:bjid and s.JCSJ>=:start"
  1538. + " and s.JCSJ<:end and s." + ObjC.JLZT_useStr
  1539. + " and m." + ObjC.JLZT_useStr
  1540. + " and x.SQLJCXMM in(11,21,22,23,31)"
  1541. + " and x.MFZ is not null and m.FS is not null"
  1542. + " and m.FS<x.MFZ order by s.JCSJ desc,m.SQLJCMXID";
  1543. } else if ("cleaning".equals(category)) {
  1544. sql = "select s.CSWSJCID ID,m.CSWSJCXMM XMM,m.FS,x.MFZ,"
  1545. + "x.MC XMMC,s.JCSJ from CSWSJC s"
  1546. + " inner join CSWSJCMX m on m.CSWSJCID=s.CSWSJCID"
  1547. + " inner join CSWSJCXM x on x.CSWSJCXMM=m.CSWSJCXMM"
  1548. + " where s.BJID=:bjid and s.JCSJ>=:start"
  1549. + " and s.JCSJ<:end and s." + ObjC.JLZT_useStr
  1550. + " and m." + ObjC.JLZT_useStr
  1551. + " and m.FS<x.MFZ order by s.JCSJ desc,m.CSWSJCMXID";
  1552. } else {
  1553. throw new IllegalArgumentException("明细类型参数错误");
  1554. }
  1555. SqlCmd sqlc = new SqlCmd(sql);
  1556. sqlc.wrLongParm("bjid", bjid);
  1557. sqlc.wrTimeParm("start", start);
  1558. sqlc.wrTimeParm("end", end);
  1559. List<Map<String, Object>> result = new ArrayList<>();
  1560. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  1561. int score = rdInt(row.get("fs"));
  1562. int maxScore = rdInt(row.get("mfz"));
  1563. int rawDeducted = Math.max(0, maxScore - score);
  1564. int code = rdInt(row.get("xmm"));
  1565. double deducted = "flag".equals(category)
  1566. ? round2(rawDeducted * flagWeightPct(code) / 100.0)
  1567. : rawDeducted;
  1568. if (deducted <= 0.0)
  1569. continue;
  1570. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1571. item.put("id", rdLong(row.get("id")));
  1572. item.put("sourceId", rdLong(row.get("id")));
  1573. item.put("category", category);
  1574. item.put("traceable", true);
  1575. item.put("itemName", rdStr(row.get("xmmc")));
  1576. item.put("studentName", "");
  1577. item.put("roomName", rdStr(row.get("kfmc")));
  1578. item.put("title", rdStr(row.get("xmmc")));
  1579. item.put("remark", "得分 " + score + " / " + maxScore
  1580. + ("flag".equals(category)
  1581. ? ",折算扣 " + deducted : ""));
  1582. item.put("deducted", deducted);
  1583. item.put("rawDeducted", rawDeducted);
  1584. item.put("delta", -deducted);
  1585. item.put("scoreText", score + "/" + maxScore);
  1586. item.put("sortTime", formatTimestamp(row.get("jcsj")));
  1587. result.add(item);
  1588. }
  1589. if (result.isEmpty() && "cleaning".equals(category))
  1590. result.addAll(rdImportedCleaningSummary(db, bjid, day));
  1591. return result;
  1592. }
  1593. private static List<Map<String, Object>> rdFlagDaySummary(
  1594. Db db, long bjid, LocalDate day) throws Exception {
  1595. Map<String, Object> record = rdFlagRecord(db, bjid, day);
  1596. if (record == null)
  1597. return new ArrayList<>();
  1598. if (isZhixinStarImport(rdStr(record.get("ms")))) {
  1599. double score = flagRate(record.get("zfs"));
  1600. List<Map<String, Object>> rows = new ArrayList<>();
  1601. rows.add(flagSummaryRow(day, record, "aggregate", "升旗礼",
  1602. round2(100.0 - score), score, false, ""));
  1603. return rows;
  1604. }
  1605. double attendanceRate = flagRate(record.get("cql"));
  1606. double queueScore = flagRate(record.get("dlfs"));
  1607. double demeanorScore = flagRate(record.get("fmfs"));
  1608. double disciplineScore = flagRate(record.get("jlfs"));
  1609. List<Map<String, Object>> rows = new ArrayList<>();
  1610. rows.add(flagSummaryRow(day, record, "attendance", "考勤",
  1611. round2((100.0 - attendanceRate) * 0.25),
  1612. attendanceRate, true, "flagAttendanceDetail"));
  1613. rows.add(flagSummaryRow(day, record, "queue", "队列",
  1614. round2((100.0 - queueScore) * 0.20),
  1615. queueScore, false, ""));
  1616. rows.add(flagSummaryRow(day, record, "demeanor", "风貌",
  1617. round2((100.0 - demeanorScore) * 0.40),
  1618. demeanorScore, true, "flagDemeanorDetail"));
  1619. rows.add(flagSummaryRow(day, record, "discipline", "纪律",
  1620. round2((100.0 - disciplineScore) * 0.15),
  1621. disciplineScore, false, ""));
  1622. return rows;
  1623. }
  1624. private static List<Map<String, Object>> rdFlagAttendanceDetail(
  1625. Db db, long bjid, LocalDate day) throws Exception {
  1626. Map<String, Object> record = rdFlagRecord(db, bjid, day);
  1627. if (record == null)
  1628. return new ArrayList<>();
  1629. Map<Integer, Integer> values = rdFlagItemValues(
  1630. db, rdLong(record.get("sqljcid")));
  1631. String[] labels = {
  1632. "总人数",
  1633. "队列人数",
  1634. "本部学生会值日人数",
  1635. "学校学生会值日人数",
  1636. "国旗队人数",
  1637. "公假人数",
  1638. "参与宿管人数",
  1639. "升旗礼前请假人数"
  1640. };
  1641. List<Map<String, Object>> rows = new ArrayList<>();
  1642. for (int i = 0; i < labels.length; i++) {
  1643. int code = i + 1;
  1644. int value = values.getOrDefault(code, 0);
  1645. rows.add(flagValueRow(day, labels[i], value, String.valueOf(value)));
  1646. }
  1647. double attendanceRate = flagRate(record.get("cql"));
  1648. double attendanceScore = flagRate(record.get("kqfs"));
  1649. rows.add(flagValueRow(day, "出勤率", attendanceRate,
  1650. plainNumber(attendanceRate) + "%"));
  1651. rows.add(flagValueRow(day, "考勤分", attendanceScore,
  1652. plainNumber(attendanceScore)));
  1653. return rows;
  1654. }
  1655. private static List<Map<String, Object>> rdFlagDemeanorDetail(
  1656. Db db, long bjid, LocalDate day) throws Exception {
  1657. Map<String, Object> record = rdFlagRecord(db, bjid, day);
  1658. if (record == null)
  1659. return new ArrayList<>();
  1660. Map<Integer, Integer> values = rdFlagItemValues(
  1661. db, rdLong(record.get("sqljcid")));
  1662. List<Map<String, Object>> rows = new ArrayList<>();
  1663. rows.add(flagValueRow(day, "国歌",
  1664. values.getOrDefault(21, 0),
  1665. String.valueOf(values.getOrDefault(21, 0))));
  1666. rows.add(flagValueRow(day, "校歌",
  1667. values.getOrDefault(22, 0),
  1668. String.valueOf(values.getOrDefault(22, 0))));
  1669. rows.add(flagValueRow(day, "服装",
  1670. values.getOrDefault(23, 0),
  1671. String.valueOf(values.getOrDefault(23, 0))));
  1672. return rows;
  1673. }
  1674. private static Map<String, Object> rdFlagRecord(
  1675. Db db, long bjid, LocalDate day) throws Exception {
  1676. SqlCmd sqlc = new SqlCmd(
  1677. "select SQLJCID,CQL,KQFS,DLFS,FMFS,JLFS,ZFS,JCSJ,MS"
  1678. + " from SQLJC where BJID=:bjid"
  1679. + " and trunc(JCSJ)=to_date(:day,'YYYY-MM-DD')"
  1680. + " and JLZTM in(22,25,51)"
  1681. + " order by SQLJCID desc");
  1682. sqlc.wrLongParm("bjid", bjid);
  1683. sqlc.wrStrParm("day", day.format(DATE_FMT));
  1684. List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
  1685. return rows == null || rows.isEmpty() ? null : rows.get(0);
  1686. }
  1687. private static Map<Integer, Integer> rdFlagItemValues(
  1688. Db db, long sqljcid) throws Exception {
  1689. SqlCmd sqlc = new SqlCmd(
  1690. "select SQLJCXMM,FS from SQLJCMX where SQLJCID=:sqljcid"
  1691. + " and JLZTM=51 and SQLJCXMM in(1,2,3,4,5,6,7,8,"
  1692. + "21,22,23)");
  1693. sqlc.wrLongParm("sqljcid", sqljcid);
  1694. Map<Integer, Integer> result = new HashMap<>();
  1695. List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
  1696. if (rows == null)
  1697. return result;
  1698. for (Map<String, Object> row : rows)
  1699. result.put(rdInt(row.get("sqljcxmm")), rdInt(row.get("fs")));
  1700. return result;
  1701. }
  1702. private static Map<String, Object> flagSummaryRow(
  1703. LocalDate day, Map<String, Object> record, String code,
  1704. String name, double deduction, double rawScore,
  1705. boolean traceable, String detailMode) {
  1706. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1707. item.put("id", rdLong(record.get("sqljcid")));
  1708. item.put("sourceId", rdLong(record.get("sqljcid")));
  1709. item.put("category", "flag");
  1710. item.put("code", code);
  1711. item.put("itemName", name);
  1712. item.put("title", name);
  1713. item.put("deduction", deduction);
  1714. item.put("delta", -deduction);
  1715. item.put("rawScore", round2(rawScore));
  1716. item.put("traceable", traceable);
  1717. item.put("detailMode", detailMode);
  1718. item.put("sortTime", formatTimestamp(record.get("jcsj")));
  1719. return item;
  1720. }
  1721. private static Map<String, Object> flagValueRow(
  1722. LocalDate day, String name, double value, String displayValue) {
  1723. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1724. item.put("itemName", name);
  1725. item.put("title", name);
  1726. item.put("value", round2(value));
  1727. item.put("displayValue", displayValue);
  1728. item.put("traceable", false);
  1729. item.put("sortTime", day.format(DATE_FMT));
  1730. return item;
  1731. }
  1732. private static double flagRate(Object value) {
  1733. return Math.max(0.0, Math.min(100.0, rdDouble(value)));
  1734. }
  1735. private static String plainNumber(double value) {
  1736. String text = String.format(Locale.CHINA, "%.2f", round2(value));
  1737. return text.replaceAll("0+$", "").replaceAll("\\.$", "");
  1738. }
  1739. private static List<Map<String, Object>> rdKtjlDetail(
  1740. Db db, long bjid, LocalDate day) throws Exception {
  1741. Timestamp start = Timestamp.valueOf(day.atStartOfDay());
  1742. Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
  1743. SqlCmd sqlc = new SqlCmd(
  1744. "select j.KTJLID,j.FS,j.MS,j.MSWJ,j.JLSJ,k.KSSJ,"
  1745. + "k.KCBID,nvl(kc.MC,k.MC) KCM,ry.XM JLRYXM"
  1746. + " from KTJL j"
  1747. + " inner join KCB k on k.KCBID=j.KCBID"
  1748. + " left join KC kc on kc.KCID=k.KCID"
  1749. + " left join RY ry on ry.RYID=j.JLRYID"
  1750. + " where j.BJID=:bjid and k.KSSJ>=:start"
  1751. + " and k.KSSJ<:end and j." + ObjC.JLZT_useStr
  1752. + " and k." + ObjC.JLZT_useStr
  1753. + " order by k.KSSJ desc,j.KTJLID desc");
  1754. sqlc.wrLongParm("bjid", bjid);
  1755. sqlc.wrTimeParm("start", start);
  1756. sqlc.wrTimeParm("end", end);
  1757. List<Map<String, Object>> result = new ArrayList<>();
  1758. List<Map<String, Object>> rows;
  1759. try {
  1760. rows = db.doSelMapListByC(sqlc);
  1761. } catch (SQLException e) {
  1762. if (isMissingTable(e, "KTJL"))
  1763. return result;
  1764. throw e;
  1765. }
  1766. if (rows == null)
  1767. return result;
  1768. for (Map<String, Object> row : rows) {
  1769. int score = rdInt(row.get("fs"));
  1770. if (score >= 100)
  1771. continue;
  1772. Map<String, Object> item = baseDetail(day, SOURCE_REAL);
  1773. long id = rdLong(row.get("ktjlid"));
  1774. item.put("id", id);
  1775. item.put("sourceId", id);
  1776. item.put("category", "classroom");
  1777. item.put("traceable", true);
  1778. item.put("itemName", "课堂考核");
  1779. item.put("studentName", "");
  1780. item.put("title", rdStr(row.get("kcm")));
  1781. item.put("remark", defaultText(row.get("ms"),
  1782. defaultText(row.get("mswj"), "课堂考核扣分")));
  1783. item.put("delta", -(100 - score));
  1784. item.put("scoreText", score + "/100");
  1785. item.put("sortTime", formatTimestamp(row.get("kssj")));
  1786. result.add(item);
  1787. }
  1788. return result;
  1789. }
  1790. private static Map<String, Object> rdTraceDetail(Db db, ClassInfo cls,
  1791. LocalDate day,
  1792. CategoryDef category,
  1793. long sourceId,
  1794. String source)
  1795. throws Exception {
  1796. if (!SOURCE_REAL.equals(source))
  1797. throw new IllegalArgumentException("扣分来源参数错误");
  1798. if ("attendance".equals(category.code))
  1799. return rdAttendanceTrace(db, cls, day, category, sourceId);
  1800. if ("dorm".equals(category.code))
  1801. return rdCheckTrace(db, cls, day, category, sourceId, "dorm");
  1802. if ("flag".equals(category.code))
  1803. return rdCheckTrace(db, cls, day, category, sourceId, "flag");
  1804. if ("cleaning".equals(category.code))
  1805. return rdCheckTrace(db, cls, day, category, sourceId, "cleaning");
  1806. if ("classroom".equals(category.code))
  1807. return rdKtjlTrace(db, cls, day, category, sourceId);
  1808. if ("discipline".equals(category.code))
  1809. return rdDisciplineTrace(db, cls, day, category, sourceId);
  1810. throw new IllegalArgumentException("评分项目暂无可追踪明细");
  1811. }
  1812. private static Map<String, Object> rdDisciplineTrace(
  1813. Db db, ClassInfo cls, LocalDate day,
  1814. CategoryDef category, long sourceId) throws Exception {
  1815. SqlCmd current = new SqlCmd(
  1816. "select w.WJJLID,w.WJSJ,w.MS,w.WJLBM,lb.MC WJLBMC,"
  1817. + "lb.BJKF,ry.XM RYXM,cj.XM CJRYXM"
  1818. + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
  1819. + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
  1820. + " and wm.YTM=" + XjbWjlbC.YTM_DISCIPLINE
  1821. + " and wm.JLZTM=51"
  1822. + " left join RY ry on ry.RYID=w.RYID"
  1823. + " left join RY cj on cj.RYID=w.CJRYID"
  1824. + " where w.WJJLID=:id and w.BJID=:bjid"
  1825. + " and w.JLZTM=51");
  1826. current.wrLongParm("id", sourceId);
  1827. current.wrLongParm("bjid", cls.bjid);
  1828. List<Map<String, Object>> currentRows =
  1829. db.doSelMapListByC(current);
  1830. if (currentRows != null && !currentRows.isEmpty()) {
  1831. Map<String, Object> row = currentRows.get(0);
  1832. double deducted = rdDouble(row.get("bjkf"));
  1833. Map<String, Object> record = new LinkedHashMap<>();
  1834. record.put("time", formatTimestamp(row.get("wjsj")));
  1835. record.put("className", cls.bjmc);
  1836. record.put("inspectorName", rdStr(row.get("cjryxm")));
  1837. record.put("studentName", rdStr(row.get("ryxm")));
  1838. record.put("description", rdStr(row.get("ms")));
  1839. List<Map<String, Object>> items = new ArrayList<>();
  1840. Map<String, Object> item = new LinkedHashMap<>();
  1841. item.put("itemName", rdStr(row.get("wjlbmc")));
  1842. item.put("deducted", deducted);
  1843. item.put("remark", rdStr(row.get("ms")));
  1844. items.add(item);
  1845. return traceResult(cls, day, category, SOURCE_REAL,
  1846. "风纪仪容扣分详情", record, items, "");
  1847. }
  1848. return rdLegacyDisciplineTrace(db, cls, day, category, sourceId);
  1849. }
  1850. private static Map<String, Object> rdLegacyDisciplineTrace(
  1851. Db db, ClassInfo cls, LocalDate day,
  1852. CategoryDef category, long sourceId) throws Exception {
  1853. SqlCmd sqlc = new SqlCmd(
  1854. "select XJB_FJRYID,JCRQ,WJRS,MS from XJB_FJRY"
  1855. + " where XJB_FJRYID=:id and BJID=:bjid and JLZTM=51");
  1856. sqlc.wrLongParm("id", sourceId);
  1857. sqlc.wrLongParm("bjid", cls.bjid);
  1858. List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
  1859. if (rows == null || rows.isEmpty())
  1860. throw new IllegalArgumentException("风纪仪容记录不存在或已不可查看");
  1861. Map<String, Object> row = rows.get(0);
  1862. int violations = rdInt(row.get("wjrs"));
  1863. Map<String, Object> record = new LinkedHashMap<>();
  1864. record.put("time", day.format(DATE_FMT));
  1865. record.put("className", cls.bjmc);
  1866. record.put("inspectorName", "风纪检查");
  1867. record.put("violationCount", violations);
  1868. record.put("description", rdStr(row.get("ms")));
  1869. List<Map<String, Object>> items = new ArrayList<>();
  1870. if (violations > 0) {
  1871. Map<String, Object> item = new LinkedHashMap<>();
  1872. item.put("itemName", "风纪仪容违纪");
  1873. item.put("deducted", violations);
  1874. item.put("remark", "违纪" + violations + "人次,每人次扣1分");
  1875. items.add(item);
  1876. }
  1877. return traceResult(cls, day, category, SOURCE_REAL,
  1878. "风纪仪容扣分详情", record, items,
  1879. violations == 0 ? "当日无风纪仪容扣分" : "");
  1880. }
  1881. private static Map<String, Object> rdCheckTrace(Db db, ClassInfo cls,
  1882. LocalDate day,
  1883. CategoryDef category,
  1884. long sourceId,
  1885. String type)
  1886. throws Exception {
  1887. String mainSql;
  1888. String itemSql;
  1889. if ("dorm".equals(type)) {
  1890. mainSql = "select s.SSNWJCID ID,s.JCSJ,s.FS,s.MS,s.KFID,"
  1891. + "cd.MC KFMC,b.MC BJMC,jc.XM JCRYXM from SSNWJC s"
  1892. + " left join CD cd on cd.CDID=s.KFID"
  1893. + " left join BJ b on b.BJID=s.BJID"
  1894. + " left join RY jc on jc.RYID=s.JCRYID"
  1895. + " where s.SSNWJCID=:id and s.BJID=:bjid and s."
  1896. + ObjC.JLZT_useStr;
  1897. itemSql = "select x.SSNWJCXMM CODE,x.MC ITEM_NAME,"
  1898. + "m.FS CURRENT_SCORE,x.MFZ MAX_SCORE"
  1899. + " from SSNWJCMX m inner join SSNWJCXM x"
  1900. + " on x.SSNWJCXMM=m.SSNWJCXMM"
  1901. + " where m.SSNWJCID=:id and m." + ObjC.JLZT_useStr
  1902. + " order by x.SSNWJCXMM";
  1903. } else if ("flag".equals(type)) {
  1904. mainSql = "select s.SQLJCID ID,s.JCSJ,s.ZFS FS,s.MS,s.BMID,"
  1905. + "bm.MC BMMC,b.MC BJMC,jc.XM JCRYXM from SQLJC s"
  1906. + " left join BM bm on bm.BMID=s.BMID"
  1907. + " left join BJ b on b.BJID=s.BJID"
  1908. + " left join RY jc on jc.RYID=s.JCRYID"
  1909. + " where s.SQLJCID=:id and s.BJID=:bjid and s."
  1910. + ObjC.JLZT_useStr;
  1911. itemSql = "select x.SQLJCXMM CODE,x.MC ITEM_NAME,"
  1912. + "m.FS CURRENT_SCORE,x.MFZ MAX_SCORE"
  1913. + " from SQLJCMX m inner join SQLJCXM x"
  1914. + " on x.SQLJCXMM=m.SQLJCXMM"
  1915. + " where m.SQLJCID=:id and m." + ObjC.JLZT_useStr
  1916. + " and x.SQLJCXMM in(11,21,22,23,31)"
  1917. + " order by x.SQLJCXMM";
  1918. } else {
  1919. mainSql = "select s.CSWSJCID ID,s.JCSJ,s.FS,s.MS,"
  1920. + "b.MC BJMC,jc.XM JCRYXM from CSWSJC s"
  1921. + " left join BJ b on b.BJID=s.BJID"
  1922. + " left join RY jc on jc.RYID=s.JCRYID"
  1923. + " where s.CSWSJCID=:id and s.BJID=:bjid and s."
  1924. + ObjC.JLZT_useStr;
  1925. itemSql = "select x.MC ITEM_NAME,m.FS CURRENT_SCORE,x.MFZ MAX_SCORE"
  1926. + " from CSWSJCMX m inner join CSWSJCXM x"
  1927. + " on x.CSWSJCXMM=m.CSWSJCXMM"
  1928. + " where m.CSWSJCID=:id and m." + ObjC.JLZT_useStr
  1929. + " order by x.CSWSJCXMM";
  1930. }
  1931. SqlCmd mainCmd = new SqlCmd(mainSql);
  1932. mainCmd.wrLongParm("id", sourceId);
  1933. mainCmd.wrLongParm("bjid", cls.bjid);
  1934. List<Map<String, Object>> mainRows = db.doSelMapListByC(mainCmd);
  1935. if (mainRows == null || mainRows.isEmpty())
  1936. throw new IllegalArgumentException("扣分记录不存在或已不可查看");
  1937. Map<String, Object> main = mainRows.get(0);
  1938. SqlCmd itemCmd = new SqlCmd(itemSql);
  1939. itemCmd.wrLongParm("id", sourceId);
  1940. List<Map<String, Object>> itemRows = db.doSelMapListByC(itemCmd);
  1941. if (itemRows == null)
  1942. itemRows = new ArrayList<>();
  1943. List<Map<String, Object>> items = new ArrayList<>();
  1944. for (Map<String, Object> row : itemRows) {
  1945. int current = rdInt(row.get("current_score"));
  1946. int max = rdInt(row.get("max_score"));
  1947. int rawDeducted = Math.max(0, max - current);
  1948. double deducted = "flag".equals(type)
  1949. ? round2(rawDeducted
  1950. * flagWeightPct(rdInt(row.get("code"))) / 100.0)
  1951. : rawDeducted;
  1952. if (deducted <= 0.0)
  1953. continue;
  1954. Map<String, Object> item = new LinkedHashMap<>();
  1955. item.put("itemName", rdStr(row.get("item_name")));
  1956. item.put("currentScore", current);
  1957. item.put("maxScore", max);
  1958. item.put("deducted", deducted);
  1959. item.put("rawDeducted", rawDeducted);
  1960. item.put("remark", "得分 " + current + " / " + max
  1961. + ("flag".equals(type)
  1962. ? ",折算扣 " + deducted : ""));
  1963. items.add(item);
  1964. }
  1965. Map<String, Object> record = new LinkedHashMap<>();
  1966. record.put("time", formatTimestamp(main.get("jcsj")));
  1967. record.put("className", defaultText(main.get("bjmc"), cls.bjmc));
  1968. record.put("roomName", defaultText(main.get("kfmc"), ""));
  1969. record.put("departmentName", defaultText(main.get("bmmc"), ""));
  1970. record.put("inspectorName", defaultText(main.get("jcryxm"), "未记录"));
  1971. record.put("totalScore", rdDouble(main.get("fs")));
  1972. record.put("description", defaultText(main.get("ms"), ""));
  1973. return traceResult(cls, day, category, SOURCE_REAL,
  1974. category.label + "扣分详情", record, items, "");
  1975. }
  1976. private static Map<String, Object> rdAttendanceTrace(Db db, ClassInfo cls,
  1977. LocalDate day,
  1978. CategoryDef category,
  1979. long sourceId)
  1980. throws Exception {
  1981. SqlCmd cmd = new SqlCmd(
  1982. "select k.KQJLID,k.KQLBM,lb.MC KQLBMC,k.RYID,ry.XM,"
  1983. + "k.MC,k.MS,k.KSSJ,k.JSSJ,k.BJID,b.MC BJMC"
  1984. + " from KQJL k left join KQLB lb on lb.KQLBM=k.KQLBM"
  1985. + " left join RY ry on ry.RYID=k.RYID"
  1986. + " left join BJ b on b.BJID=k.BJID"
  1987. + " where k.KQJLID=:id and k.BJID=:bjid"
  1988. + " and k.KQJLZTM=51 and k." + ObjC.JLZT_useStr);
  1989. cmd.wrLongParm("id", sourceId);
  1990. cmd.wrLongParm("bjid", cls.bjid);
  1991. List<Map<String, Object>> rows = db.doSelMapListByC(cmd);
  1992. if (rows == null || rows.isEmpty())
  1993. throw new IllegalArgumentException("考勤扣分记录不存在或已不可查看");
  1994. Map<String, Object> main = rows.get(0);
  1995. int kqlbm = rdInt(main.get("kqlbm"));
  1996. double deducted = attendancePenalty(kqlbm);
  1997. Map<String, Object> record = new LinkedHashMap<>();
  1998. record.put("time", formatTimestamp(main.get("kssj")));
  1999. record.put("className", defaultText(main.get("bjmc"), cls.bjmc));
  2000. record.put("studentName", defaultText(main.get("xm"), ""));
  2001. record.put("inspectorName", "考勤系统");
  2002. record.put("description", defaultText(main.get("ms"), ""));
  2003. record.put("period", formatTimestamp(main.get("kssj")) + " - "
  2004. + formatTimestamp(main.get("jssj")));
  2005. List<Map<String, Object>> items = new ArrayList<>();
  2006. Map<String, Object> item = new LinkedHashMap<>();
  2007. item.put("itemName", defaultText(main.get("kqlbmc"), "考勤异常"));
  2008. item.put("deducted", deducted);
  2009. item.put("remark", defaultText(main.get("mc"), ""));
  2010. items.add(item);
  2011. return traceResult(cls, day, category, SOURCE_REAL,
  2012. category.label + "扣分详情", record, items, "");
  2013. }
  2014. private static Map<String, Object> rdKtjlTrace(
  2015. Db db, ClassInfo cls, LocalDate day,
  2016. CategoryDef category, long sourceId) throws Exception {
  2017. Timestamp start = Timestamp.valueOf(day.atStartOfDay());
  2018. Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
  2019. SqlCmd mainCmd = new SqlCmd(
  2020. "select j.KTJLID,j.FS,j.MS,j.MSWJ,j.FJID,j.JLSJ,"
  2021. + "k.KSSJ,nvl(kc.MC,k.MC) KCM,b.MC BJMC,ry.XM JLRYXM"
  2022. + " from KTJL j"
  2023. + " inner join KCB k on k.KCBID=j.KCBID"
  2024. + " left join KC kc on kc.KCID=k.KCID"
  2025. + " left join BJ b on b.BJID=j.BJID"
  2026. + " left join RY ry on ry.RYID=j.JLRYID"
  2027. + " where j.KTJLID=:id and j.BJID=:bjid"
  2028. + " and k.KSSJ>=:start and k.KSSJ<:end"
  2029. + " and j." + ObjC.JLZT_useStr
  2030. + " and k." + ObjC.JLZT_useStr);
  2031. mainCmd.wrLongParm("id", sourceId);
  2032. mainCmd.wrLongParm("bjid", cls.bjid);
  2033. mainCmd.wrTimeParm("start", start);
  2034. mainCmd.wrTimeParm("end", end);
  2035. List<Map<String, Object>> mainRows = db.doSelMapListByC(mainCmd);
  2036. if (mainRows == null || mainRows.isEmpty())
  2037. throw new IllegalArgumentException("课堂考核记录不存在或已不可查看");
  2038. Map<String, Object> main = mainRows.get(0);
  2039. SqlCmd itemCmd = new SqlCmd(
  2040. "select x.KTJLXMM,x.MC ITEM_NAME,x.MFZ MAX_SCORE,m.FS"
  2041. + " from KTJLMX m inner join KTJLXM x"
  2042. + " on x.KTJLXMM=m.KTJLXMM"
  2043. + " where m.KTJLID=:id and m." + ObjC.JLZT_useStr
  2044. + " order by x.KTJLXMM");
  2045. itemCmd.wrLongParm("id", sourceId);
  2046. List<Map<String, Object>> itemRows = db.doSelMapListByC(itemCmd);
  2047. if (itemRows == null)
  2048. itemRows = new ArrayList<>();
  2049. List<Map<String, Object>> items = new ArrayList<>();
  2050. for (Map<String, Object> row : itemRows) {
  2051. int current = rdInt(row.get("fs"));
  2052. int max = rdInt(row.get("max_score"));
  2053. int deducted = Math.max(0, max - current);
  2054. if (deducted == 0)
  2055. continue;
  2056. Map<String, Object> item = new LinkedHashMap<>();
  2057. item.put("itemName", rdStr(row.get("item_name")));
  2058. item.put("currentScore", current);
  2059. item.put("maxScore", max);
  2060. item.put("deducted", deducted);
  2061. item.put("remark", "得分 " + current + " / " + max);
  2062. items.add(item);
  2063. }
  2064. Map<String, Object> record = new LinkedHashMap<>();
  2065. record.put("time", formatTimestamp(main.get("kssj")));
  2066. record.put("className", defaultText(main.get("bjmc"), cls.bjmc));
  2067. record.put("courseName", defaultText(main.get("kcm"), ""));
  2068. record.put("inspectorName", defaultText(main.get("jlryxm"), "未记录"));
  2069. record.put("totalScore", rdDouble(main.get("fs")));
  2070. record.put("description", defaultText(main.get("mswj"),
  2071. defaultText(main.get("ms"), "")));
  2072. record.put("attachmentId", main.get("fjid"));
  2073. return traceResult(cls, day, category, SOURCE_REAL,
  2074. category.label + "扣分详情", record, items, "");
  2075. }
  2076. private static Map<String, Object> rdAdjustmentTrace(
  2077. Db db, ClassInfo cls, long ledgerId, YearMonth reportMonth)
  2078. throws Exception {
  2079. SqlCmd ledgerCmd = new SqlCmd(
  2080. "select j.XJB_JFJLID,j.NDY,j.FSSJ,j.JFLX,j.JFZ,j.MC,j.MS,"
  2081. + "j.LYLX,j.LYID,j.LYLB,j.RYID,r.XM RYXM"
  2082. + " from XJB_JFJL j left join RY r on r.RYID=j.RYID"
  2083. + " where j.XJB_JFJLID=:id and j.BJID=:bjid"
  2084. + " and j.JLZTM=51");
  2085. ledgerCmd.wrLongParm("id", ledgerId);
  2086. ledgerCmd.wrLongParm("bjid", cls.bjid);
  2087. List<Map<String, Object>> ledgerRows =
  2088. db.doSelMapListByC(ledgerCmd);
  2089. if (ledgerRows == null || ledgerRows.isEmpty())
  2090. throw new IllegalArgumentException("增扣分记录不存在或已不可查看");
  2091. Map<String, Object> ledger = ledgerRows.get(0);
  2092. if (reportMonth != null) {
  2093. YearMonth ledgerMonth = YearMonth.parse(
  2094. rdStr(ledger.get("ndy")), MONTH_FMT);
  2095. ensureReportMonth(reportMonth, ledgerMonth);
  2096. }
  2097. String sourceType = defaultText(ledger.get("lylx"), "");
  2098. long sourceId = rdLong(ledger.get("lyid"));
  2099. if (XjbJfServ.LYLX_AWARD.equals(sourceType))
  2100. return rdAwardAdjustmentTrace(db, cls, ledger, sourceId);
  2101. if (XjbJfServ.LYLX_SCHOOL_VIOLATION.equals(sourceType))
  2102. return rdViolationAdjustmentTrace(db, cls, ledger, sourceId);
  2103. if (XjbJfServ.LYLX_TEAM_ROLE.equals(sourceType)
  2104. || XjbJfServ.LYLX_TEAM_MEMBER.equals(sourceType))
  2105. return rdTeamAdjustmentTrace(db, cls, ledger, sourceType,
  2106. sourceId);
  2107. if (XjbJfServ.LYLX_MONTH_SAFE.equals(sourceType)
  2108. || XjbJfServ.LYLX_FJ_SAFE.equals(sourceType))
  2109. return rdRuleAdjustmentTrace(cls, ledger, sourceType);
  2110. return rdLedgerOnlyTrace(cls, ledger, sourceType);
  2111. }
  2112. private static Map<String, Object> rdAwardAdjustmentTrace(
  2113. Db db, ClassInfo cls, Map<String, Object> ledger, long sourceId)
  2114. throws Exception {
  2115. SqlCmd sqlc = new SqlCmd(
  2116. "select h.HJJLID,h.HJXZ,h.HJRQ,h.MS,h.MC,h.HJLBM,"
  2117. + "l.MC LBMC,l.BJJF,l.JTBJJF,r.XM RYXM"
  2118. + " from HJJL h inner join HJLB l on l.HJLBM=h.HJLBM"
  2119. + " left join RY r on r.RYID=h.RYID"
  2120. + " where h.HJJLID=:id and h.JLZTM=51");
  2121. sqlc.wrLongParm("id", sourceId);
  2122. List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
  2123. if (rows == null || rows.isEmpty())
  2124. return rdLedgerOnlyTrace(cls, ledger,
  2125. XjbJfServ.LYLX_AWARD);
  2126. Map<String, Object> row = rows.get(0);
  2127. int awardType = rdInt(row.get("hjxz"));
  2128. String awardTypeText = awardType == 2 ? "集体获奖" : "个人获奖";
  2129. Map<String, Object> record = adjustmentRecord(cls, ledger,
  2130. "学校获奖", row.get("ryxm"));
  2131. record.put("awardNature", awardTypeText);
  2132. record.put("awardCategory", rdStr(row.get("lbmc")));
  2133. record.put("description", defaultText(row.get("ms"),
  2134. defaultText(row.get("mc"), "")));
  2135. List<Map<String, Object>> items = new ArrayList<>();
  2136. if (awardType == 2) {
  2137. SqlCmd memberCmd = new SqlCmd(
  2138. "select c.RYID,r.XM,b.MC BJMC from HJJLCY c"
  2139. + " left join RY r on r.RYID=c.RYID"
  2140. + " left join BJ b on b.BJID=c.BJID"
  2141. + " where c.HJJLID=:id and c.JLZTM=51"
  2142. + " order by c.BJID,c.RYID");
  2143. memberCmd.wrLongParm("id", sourceId);
  2144. List<Map<String, Object>> members =
  2145. db.doSelMapListByC(memberCmd);
  2146. for (Map<String, Object> member : members) {
  2147. Map<String, Object> item = new LinkedHashMap<>();
  2148. item.put("itemName", "参与学生");
  2149. item.put("studentName", defaultText(member.get("xm"), ""));
  2150. item.put("className", defaultText(member.get("bjmc"), ""));
  2151. item.put("remark", "集体获奖参与学生");
  2152. items.add(item);
  2153. }
  2154. }
  2155. Map<String, Object> main = adjustmentItem(ledger,
  2156. defaultText(row.get("lbmc"), awardTypeText),
  2157. defaultText(row.get("ms"), ""));
  2158. items.add(0, main);
  2159. return adjustmentTraceResult(cls, ledger, sourceId,
  2160. XjbJfServ.LYLX_AWARD, awardTypeText + "增分详情",
  2161. record, items, "");
  2162. }
  2163. private static Map<String, Object> rdViolationAdjustmentTrace(
  2164. Db db, ClassInfo cls, Map<String, Object> ledger, long sourceId)
  2165. throws Exception {
  2166. SqlCmd sqlc = new SqlCmd(
  2167. "select w.WJJLID,w.WJSJ,w.MS,w.WJLBM,lb.MC WJLBMC,"
  2168. + "lb.BJKF,ry.XM RYXM,cj.XM CJRYXM"
  2169. + " from WJJL w left join WJLB lb on lb.WJLBM=w.WJLBM"
  2170. + " left join RY ry on ry.RYID=w.RYID"
  2171. + " left join RY cj on cj.RYID=w.CJRYID"
  2172. + " where w.WJJLID=:id and w.JLZTM=51");
  2173. sqlc.wrLongParm("id", sourceId);
  2174. List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
  2175. if (rows == null || rows.isEmpty())
  2176. return rdLedgerOnlyTrace(cls, ledger,
  2177. XjbJfServ.LYLX_SCHOOL_VIOLATION);
  2178. Map<String, Object> row = rows.get(0);
  2179. Map<String, Object> record = adjustmentRecord(cls, ledger,
  2180. "学校违纪", row.get("ryxm"));
  2181. record.put("eventTime", formatTimestamp(row.get("wjsj")));
  2182. record.put("inspectorName",
  2183. defaultText(row.get("cjryxm"), "未记录"));
  2184. record.put("businessCategory", rdStr(row.get("wjlbmc")));
  2185. record.put("description", defaultText(row.get("ms"), ""));
  2186. List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
  2187. defaultText(row.get("wjlbmc"), "学校违纪"),
  2188. defaultText(row.get("ms"), "")));
  2189. return adjustmentTraceResult(cls, ledger, sourceId,
  2190. XjbJfServ.LYLX_SCHOOL_VIOLATION,
  2191. "学校违纪减分详情", record, items, "");
  2192. }
  2193. private static Map<String, Object> rdTeamAdjustmentTrace(
  2194. Db db, ClassInfo cls, Map<String, Object> ledger,
  2195. String sourceType, long sourceId) throws Exception {
  2196. String sql;
  2197. if (XjbJfServ.LYLX_TEAM_ROLE.equals(sourceType)) {
  2198. sql = "select w.TTWCYID ID,w.RYID,w.TTWCYLBM,"
  2199. + "t.MC TTMC,wc.MC ROLEMC,wc.BJJF,ry.XM RYXM"
  2200. + " from TTWCY w inner join TT t on t.TTID=w.TTID"
  2201. + " inner join TTWCYLB wc on wc.TTWCYLBM=w.TTWCYLBM"
  2202. + " left join RY ry on ry.RYID=w.RYID"
  2203. + " where w.TTWCYID=:id and w.JLZTM=51";
  2204. } else {
  2205. sql = "select c.TTCYID ID,c.RYID,wc.TTWCYLBM,"
  2206. + "t.MC TTMC,wc.MC ROLEMC,wc.BJJF,ry.XM RYXM"
  2207. + " from TTCY c inner join TT t on t.TTID=c.TTID"
  2208. + " inner join TTWCYLB wc on wc.TTLBM=t.TTLBM"
  2209. + " and wc.TTWCYLBM=(select min(wc2.TTWCYLBM)"
  2210. + " from TTWCYLB wc2 where wc2.TTLBM=t.TTLBM"
  2211. + " and wc2.MC='成员')"
  2212. + " left join RY ry on ry.RYID=c.RYID"
  2213. + " where c.TTCYID=:id and c.JLZTM=51";
  2214. }
  2215. SqlCmd sqlc = new SqlCmd(sql);
  2216. sqlc.wrLongParm("id", sourceId);
  2217. List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
  2218. if (rows == null || rows.isEmpty())
  2219. return rdLedgerOnlyTrace(cls, ledger, sourceType);
  2220. Map<String, Object> row = rows.get(0);
  2221. Map<String, Object> record = adjustmentRecord(cls, ledger,
  2222. "团体成员增分", row.get("ryxm"));
  2223. record.put("teamName", rdStr(row.get("ttmc")));
  2224. record.put("roleName", rdStr(row.get("rolemc")));
  2225. record.put("description", defaultText(ledger.get("ms"), ""));
  2226. List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
  2227. defaultText(row.get("ttmc"), "")
  2228. + "·" + defaultText(row.get("rolemc"), ""),
  2229. defaultText(ledger.get("ms"), "")));
  2230. return adjustmentTraceResult(cls, ledger, sourceId, sourceType,
  2231. "团体成员增分详情", record, items, "");
  2232. }
  2233. private static Map<String, Object> rdRuleAdjustmentTrace(
  2234. ClassInfo cls, Map<String, Object> ledger, String sourceType) {
  2235. Map<String, Object> record = adjustmentRecord(cls, ledger,
  2236. "星级班规则增分", null);
  2237. record.put("ruleName",
  2238. XjbJfServ.LYLX_MONTH_SAFE.equals(sourceType)
  2239. ? "当月无学生处分" : "当月无风纪扣分");
  2240. record.put("description", defaultText(ledger.get("ms"), ""));
  2241. List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
  2242. defaultText(ledger.get("mc"),
  2243. String.valueOf(record.get("ruleName"))),
  2244. defaultText(ledger.get("ms"), "")));
  2245. return adjustmentTraceResult(cls, ledger, rdLong(ledger.get("lyid")),
  2246. sourceType, "星级班规则增分详情", record, items,
  2247. "该记录由月度规则自动生成,无其他原始业务单据");
  2248. }
  2249. private static Map<String, Object> rdLedgerOnlyTrace(
  2250. ClassInfo cls, Map<String, Object> ledger, String sourceType) {
  2251. Map<String, Object> record = adjustmentRecord(cls, ledger,
  2252. adjustmentSourceLabel(sourceType), null);
  2253. record.put("description", defaultText(ledger.get("ms"), ""));
  2254. List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
  2255. defaultText(ledger.get("mc"), "星级班增扣分"),
  2256. defaultText(ledger.get("ms"), "")));
  2257. return adjustmentTraceResult(cls, ledger, rdLong(ledger.get("lyid")),
  2258. sourceType, "星级班增扣分详情", record, items,
  2259. "原业务记录已不可查看,以下内容来自星级班增扣分账本");
  2260. }
  2261. private static Map<String, Object> adjustmentRecord(
  2262. ClassInfo cls, Map<String, Object> ledger, String businessType,
  2263. Object studentName) {
  2264. Map<String, Object> record = new LinkedHashMap<>();
  2265. record.put("time", formatTimestamp(ledger.get("fssj")));
  2266. record.put("className", cls.bjmc);
  2267. record.put("studentName",
  2268. defaultText(studentName, defaultText(ledger.get("ryxm"), "")));
  2269. record.put("businessType", businessType);
  2270. record.put("ledgerId", rdLong(ledger.get("xjb_jfjlid")));
  2271. record.put("score", signedAdjustmentScore(ledger));
  2272. return record;
  2273. }
  2274. private static Map<String, Object> adjustmentItem(
  2275. Map<String, Object> ledger, String itemName, String remark) {
  2276. Map<String, Object> item = new LinkedHashMap<>();
  2277. item.put("itemName", itemName);
  2278. item.put("delta", signedAdjustmentScore(ledger));
  2279. item.put("remark", remark);
  2280. return item;
  2281. }
  2282. private static Map<String, Object> adjustmentTraceResult(
  2283. ClassInfo cls, Map<String, Object> ledger, long sourceId,
  2284. String sourceType, String title, Map<String, Object> record,
  2285. List<Map<String, Object>> items, String notice) {
  2286. Map<String, Object> data = new LinkedHashMap<>();
  2287. data.put("bjid", cls.bjid);
  2288. data.put("bjmc", cls.bjmc);
  2289. data.put("kind", "adjustment");
  2290. data.put("ledgerId", rdLong(ledger.get("xjb_jfjlid")));
  2291. data.put("sourceType", sourceType);
  2292. data.put("sourceId", sourceId);
  2293. data.put("title", title);
  2294. data.put("record", record);
  2295. data.put("items", items);
  2296. data.put("notice", notice);
  2297. return data;
  2298. }
  2299. private static double signedAdjustmentScore(Map<String, Object> ledger) {
  2300. double points = Math.abs(rdDouble(ledger.get("jfz")));
  2301. return rdInt(ledger.get("jflx"))
  2302. == XjbJfServ.JFLX_ADD ? points : -points;
  2303. }
  2304. private static String adjustmentSourceLabel(String sourceType) {
  2305. if (XjbJfServ.LYLX_AWARD.equals(sourceType))
  2306. return "学校获奖";
  2307. if (XjbJfServ.LYLX_SCHOOL_VIOLATION.equals(sourceType))
  2308. return "学校违纪";
  2309. if (XjbJfServ.LYLX_TEAM_ROLE.equals(sourceType))
  2310. return "团体职务";
  2311. if (XjbJfServ.LYLX_TEAM_MEMBER.equals(sourceType))
  2312. return "团体成员";
  2313. if (XjbJfServ.LYLX_MONTH_SAFE.equals(sourceType))
  2314. return "当月无学生处分";
  2315. if (XjbJfServ.LYLX_FJ_SAFE.equals(sourceType))
  2316. return "当月无风纪扣分";
  2317. return StringUtils.defaultIfBlank(sourceType, "星级班增扣分");
  2318. }
  2319. private static Map<String, Object> traceResult(
  2320. ClassInfo cls, LocalDate day, CategoryDef category, String source,
  2321. String title, Map<String, Object> record,
  2322. List<Map<String, Object>> items, String notice) {
  2323. Map<String, Object> data = new LinkedHashMap<>();
  2324. data.put("bjid", cls.bjid);
  2325. data.put("bjmc", cls.bjmc);
  2326. data.put("date", day.format(DATE_FMT));
  2327. data.put("category", category.code);
  2328. data.put("categoryLabel", category.label);
  2329. data.put("source", source);
  2330. data.put("title", title);
  2331. data.put("record", record);
  2332. data.put("items", items);
  2333. data.put("notice", notice);
  2334. return data;
  2335. }
  2336. private static String defaultText(Object value, String defaultValue) {
  2337. String text = rdStr(value);
  2338. return StringUtils.isBlank(text) ? defaultValue : text;
  2339. }
  2340. private static int flagWeightPct(int code) {
  2341. if (code == 11)
  2342. return 20;
  2343. if (code == 21 || code == 22 || code == 23)
  2344. return 40;
  2345. if (code == 31)
  2346. return 15;
  2347. return 0;
  2348. }
  2349. private static List<Map<String, Object>> rdAdjustmentRows(
  2350. List<Adjustment> adjustments) {
  2351. List<Map<String, Object>> rows = new ArrayList<>();
  2352. for (Adjustment item : adjustments) {
  2353. Map<String, Object> row = baseDetail(item.date, SOURCE_REAL);
  2354. row.put("id", item.id);
  2355. row.put("ledgerId", item.id);
  2356. row.put("sourceId", item.sourceRecordId);
  2357. row.put("sourceType", item.sourceType);
  2358. row.put("detailKind", "adjustment");
  2359. row.put("traceable", true);
  2360. row.put("itemName", item.itemName);
  2361. row.put("studentName", item.studentName);
  2362. row.put("title", item.itemName);
  2363. row.put("remark", item.remark);
  2364. row.put("delta", item.score);
  2365. row.put("scoreText", "");
  2366. row.put("sortTime", item.date.format(DATE_FMT));
  2367. rows.add(row);
  2368. }
  2369. return rows;
  2370. }
  2371. private static Map<String, Object> baseDetail(LocalDate day, String source) {
  2372. Map<String, Object> item = new LinkedHashMap<>();
  2373. item.put("date", day.format(DATE_FMT));
  2374. item.put("source", source);
  2375. return item;
  2376. }
  2377. private static CategoryDef requireCategory(String code) {
  2378. for (CategoryDef def : CATEGORY_DEFS) {
  2379. if (def.code.equals(code))
  2380. return def;
  2381. }
  2382. throw new IllegalArgumentException("评分项目参数错误");
  2383. }
  2384. private static Map<Long, AdjustmentTotals> rdAdjustmentTotals(
  2385. Db db, YearMonth month) throws Exception {
  2386. SqlCmd sqlc = new SqlCmd(
  2387. "select BJID,"
  2388. + "sum(case when JFLX=1 and LYLX in('"
  2389. + XjbJfServ.LYLX_TEAM_ROLE + "','"
  2390. + XjbJfServ.LYLX_TEAM_MEMBER
  2391. + "') then JFZ else 0 end) TEAM_BONUS,"
  2392. + "sum(case when JFLX=1 and nvl(LYLX,'#') not in('"
  2393. + XjbJfServ.LYLX_TEAM_ROLE + "','"
  2394. + XjbJfServ.LYLX_TEAM_MEMBER
  2395. + "') then JFZ else 0 end) OTHER_BONUS,"
  2396. + "sum(case when JFLX=2 then JFZ else 0 end) DEDUCTION,"
  2397. + "sum(case when JFLX=1 then 1 else 0 end) BONUS_CNT,"
  2398. + "sum(case when JFLX=2 then 1 else 0 end) DEDUCTION_CNT"
  2399. + " from XJB_JFJL where NDY=:ndy and JLZTM=51"
  2400. + " group by BJID");
  2401. sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
  2402. try {
  2403. Map<Long, AdjustmentTotals> result = new HashMap<>();
  2404. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  2405. AdjustmentTotals total = new AdjustmentTotals();
  2406. total.bonus = XjbJfServ.capBonus(
  2407. rdDouble(row.get("other_bonus")),
  2408. rdDouble(row.get("team_bonus")));
  2409. total.deduction = rdDouble(row.get("deduction"));
  2410. total.bonusEvents = rdInt(row.get("bonus_cnt"));
  2411. total.deductionEvents = rdInt(row.get("deduction_cnt"));
  2412. result.put(rdLong(row.get("bjid")), total);
  2413. }
  2414. return result;
  2415. } catch (SQLException e) {
  2416. if (isMissingTable(e, "XJB_JFJL"))
  2417. return Collections.emptyMap();
  2418. throw e;
  2419. }
  2420. }
  2421. private static PublishedSnapshot rdPublishedSnapshot(
  2422. Db db, long bjid, YearMonth month) throws Exception {
  2423. SqlCmd sqlc = new SqlCmd(
  2424. "select jg.ZF,jg.XJ,jg.ZJF,jg.KJF,jg.ZJFCS,jg.KJFCS,"
  2425. + "jg.SSLY,jg.KTLY,jg.SJLY,jg.CSLY,jg.FJLY,jg.KQLY,"
  2426. + "pm.DWPM,pm.DWCS,pm.XXPM,pm.XXCS from XJB_JG jg"
  2427. + " inner join XJB_JD jd on jd.XJB_JDID=jg.XJB_JDID"
  2428. + " inner join XJB_PM pm on pm.XJB_JDID=jg.XJB_JDID"
  2429. + " and pm.BJID=jg.BJID"
  2430. + " where jg.BJID=:bjid and jg.NDY=:ndy"
  2431. + " and jg.ZT=5 and jd.ZT=5"
  2432. + " and jd.FWLX in('XX','BM')"
  2433. + " order by case when jd.FWLX='XX' then 0 else 1 end,"
  2434. + " jd.BB desc,jd.XJB_JDID desc");
  2435. sqlc.wrLongParm("bjid", bjid);
  2436. sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
  2437. try {
  2438. List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
  2439. if (rows == null || rows.isEmpty())
  2440. return null;
  2441. Map<String, Object> row = rows.get(0);
  2442. PublishedSnapshot snapshot = new PublishedSnapshot();
  2443. snapshot.total = rdDouble(row.get("zf"));
  2444. snapshot.starLevel = rdStr(row.get("xj"));
  2445. snapshot.bonus = rdDouble(row.get("zjf"));
  2446. snapshot.deduction = rdDouble(row.get("kjf"));
  2447. snapshot.bonusCount = rdInt(row.get("zjfcs"));
  2448. snapshot.deductionCount = rdInt(row.get("kjfcs"));
  2449. snapshot.departmentRank = rdInt(row.get("dwpm"));
  2450. snapshot.departmentClassCount = rdInt(row.get("dwcs"));
  2451. snapshot.schoolRank = rdInt(row.get("xxpm"));
  2452. snapshot.schoolClassCount = rdInt(row.get("xxcs"));
  2453. snapshot.sources.put("dorm", rdStr(row.get("ssly")));
  2454. snapshot.sources.put("classroom", rdStr(row.get("ktly")));
  2455. snapshot.sources.put("flag", rdStr(row.get("sjly")));
  2456. snapshot.sources.put("cleaning", rdStr(row.get("csly")));
  2457. snapshot.sources.put("discipline", rdStr(row.get("fjly")));
  2458. snapshot.sources.put("attendance", rdStr(row.get("kqly")));
  2459. return snapshot;
  2460. } catch (SQLException e) {
  2461. if (isMissingTable(e, "XJB_JG"))
  2462. return null;
  2463. throw e;
  2464. }
  2465. }
  2466. private static List<Adjustment> rdAdjustments(
  2467. Db db, long bjid, YearMonth month) throws Exception {
  2468. SqlCmd sqlc = new SqlCmd(
  2469. "select j.XJB_JFJLID ID,j.FSSJ,j.JFLX,j.JFZ,j.MC,j.MS,"
  2470. + "j.LYLX,j.LYID,j.LYLB,r.XM RYXM from XJB_JFJL j"
  2471. + " left join RY r on r.RYID=j.RYID"
  2472. + " where j.BJID=:bjid and j.NDY=:ndy and j.JLZTM=51"
  2473. + " order by j.FSSJ desc,j.XJB_JFJLID desc");
  2474. sqlc.wrLongParm("bjid", bjid);
  2475. sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
  2476. try {
  2477. List<Adjustment> result = new ArrayList<>();
  2478. for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
  2479. int type = rdInt(row.get("jflx"));
  2480. double points = rdDouble(row.get("jfz"));
  2481. result.add(new Adjustment(
  2482. rdLong(row.get("id")),
  2483. rdLocalDate(row.get("fssj")),
  2484. type == 1 ? points : -points,
  2485. defaultText(row.get("mc"), "星级班增扣分"),
  2486. defaultText(row.get("ms"), ""),
  2487. defaultText(row.get("lylx"), ""),
  2488. rdLong(row.get("lyid")),
  2489. defaultText(row.get("ryxm"), "")));
  2490. }
  2491. return result;
  2492. } catch (SQLException e) {
  2493. if (isMissingTable(e, "XJB_JFJL"))
  2494. return Collections.emptyList();
  2495. throw e;
  2496. }
  2497. }
  2498. private static AdjustmentTotals adjustmentTotals(
  2499. List<Adjustment> adjustments) {
  2500. AdjustmentTotals total = new AdjustmentTotals();
  2501. double otherBonus = 0.0;
  2502. double teamBonus = 0.0;
  2503. for (Adjustment item : adjustments) {
  2504. if (item.score > 0) {
  2505. if (XjbJfServ.LYLX_TEAM_ROLE.equals(item.sourceType)
  2506. || XjbJfServ.LYLX_TEAM_MEMBER.equals(
  2507. item.sourceType)) {
  2508. teamBonus += item.score;
  2509. } else {
  2510. otherBonus += item.score;
  2511. }
  2512. total.bonusEvents++;
  2513. } else {
  2514. total.deduction += Math.abs(item.score);
  2515. total.deductionEvents++;
  2516. }
  2517. }
  2518. total.bonus = round2(XjbJfServ.capBonus(otherBonus, teamBonus));
  2519. total.deduction = round2(total.deduction);
  2520. return total;
  2521. }
  2522. private static String starLevel(double score, int schoolRank) {
  2523. if (schoolRank <= 10 && score > 90.0)
  2524. return "五星级";
  2525. if (score > 80.0)
  2526. return "四星级";
  2527. if (score > 75.0)
  2528. return "三星级";
  2529. if (score > 65.0)
  2530. return "二星级";
  2531. if (score > 55.0)
  2532. return "一星级";
  2533. return "无星级";
  2534. }
  2535. private static int attendancePenalty(int kqlbm) {
  2536. return switch (kqlbm) {
  2537. case 1 -> 3;
  2538. case 21 -> 1;
  2539. case 51 -> 1;
  2540. case 52 -> 1;
  2541. case 61 -> 2;
  2542. default -> 0;
  2543. };
  2544. }
  2545. private static boolean isZhixinStarImport(String marker) {
  2546. return StringUtils.startsWith(marker, ZHIXIN_STAR_MARKER_PREFIX);
  2547. }
  2548. private static YearMonth rdMonth(HttpServletRequest request) {
  2549. String value = StringUtils.trimToNull(request.getParameter("month"));
  2550. YearMonth now = YearMonth.now(CN_ZONE);
  2551. YearMonth month = value == null ? now : YearMonth.parse(value, MONTH_FMT);
  2552. if (month.isAfter(now))
  2553. throw new IllegalArgumentException("不能查询未来月份");
  2554. return month;
  2555. }
  2556. private static LocalDate rdDate(HttpServletRequest request, String name) {
  2557. String value = StringUtils.trimToNull(request.getParameter(name));
  2558. if (value == null)
  2559. throw new IllegalArgumentException("缺少参数:" + name);
  2560. return LocalDate.parse(value, DATE_FMT);
  2561. }
  2562. private static long rdLongParam(HttpServletRequest request, String name,
  2563. boolean required) {
  2564. String value = StringUtils.trimToNull(request.getParameter(name));
  2565. if (value == null) {
  2566. if (required)
  2567. throw new IllegalArgumentException("缺少参数:" + name);
  2568. return 0L;
  2569. }
  2570. try {
  2571. return Long.parseLong(value);
  2572. } catch (NumberFormatException e) {
  2573. throw new IllegalArgumentException("参数格式错误:" + name);
  2574. }
  2575. }
  2576. private static int rdIntParam(HttpServletRequest request, String name,
  2577. int defaultValue) {
  2578. String value = StringUtils.trimToNull(request.getParameter(name));
  2579. if (value == null)
  2580. return defaultValue;
  2581. try {
  2582. return Integer.parseInt(value);
  2583. } catch (NumberFormatException e) {
  2584. throw new IllegalArgumentException("参数格式错误:" + name);
  2585. }
  2586. }
  2587. private static int clampPageSize(int value) {
  2588. return Math.max(1, Math.min(100, value));
  2589. }
  2590. private static Map<Long, Double> rdScoreMap(
  2591. List<Map<String, Object>> rows) {
  2592. Map<Long, Double> result = new HashMap<>();
  2593. for (Map<String, Object> row : rows)
  2594. result.put(rdLong(row.get("bjid")), round2(
  2595. rdDouble(row.get("score"))));
  2596. return result;
  2597. }
  2598. private static LocalDate rdLocalDate(Object value) {
  2599. if (value instanceof Date)
  2600. return ((Date) value).toLocalDate();
  2601. if (value instanceof Timestamp)
  2602. return ((Timestamp) value).toLocalDateTime().toLocalDate();
  2603. if (value == null)
  2604. return null;
  2605. String text = String.valueOf(value);
  2606. if (text.length() >= 10)
  2607. return LocalDate.parse(text.substring(0, 10), DATE_FMT);
  2608. return null;
  2609. }
  2610. private static String formatTimestamp(Object value) {
  2611. if (value instanceof Timestamp)
  2612. return ((Timestamp) value).toLocalDateTime().format(DATETIME_FMT);
  2613. return value == null ? "" : String.valueOf(value);
  2614. }
  2615. private static String weekdayCn(LocalDate date) {
  2616. DayOfWeek day = date.getDayOfWeek();
  2617. return switch (day) {
  2618. case MONDAY -> "星期一";
  2619. case TUESDAY -> "星期二";
  2620. case WEDNESDAY -> "星期三";
  2621. case THURSDAY -> "星期四";
  2622. case FRIDAY -> "星期五";
  2623. case SATURDAY -> "星期六";
  2624. case SUNDAY -> "星期日";
  2625. };
  2626. }
  2627. private static long rdLong(Object value) {
  2628. return value == null ? 0L : Long.parseLong(String.valueOf(value));
  2629. }
  2630. private static Long rdLongObj(Object value) {
  2631. return value == null ? null : Long.valueOf(String.valueOf(value));
  2632. }
  2633. private static int rdInt(Object value) {
  2634. return value == null ? 0 : Integer.parseInt(String.valueOf(value));
  2635. }
  2636. private static double rdDouble(Object value) {
  2637. return value == null ? 0.0 : Double.parseDouble(String.valueOf(value));
  2638. }
  2639. private static String rdStr(Object value) {
  2640. return value == null ? null : String.valueOf(value);
  2641. }
  2642. private static double round2(double value) {
  2643. return Math.round(value * 100.0) / 100.0;
  2644. }
  2645. private static boolean isMissingTable(SQLException e, String tableName) {
  2646. String message = StringUtils.defaultString(e.getMessage()).toUpperCase();
  2647. return e.getErrorCode() == 942
  2648. && message.contains(tableName.toUpperCase());
  2649. }
  2650. private static final class MonthPeriod {
  2651. final YearMonth month;
  2652. final Timestamp start;
  2653. final Timestamp end;
  2654. final LocalDate maxDate;
  2655. final int maxDay;
  2656. private MonthPeriod(YearMonth month) {
  2657. this.month = month;
  2658. LocalDate first = month.atDay(1);
  2659. LocalDate today = LocalDate.now(CN_ZONE);
  2660. LocalDate monthEnd = month.atEndOfMonth();
  2661. this.maxDate = month.equals(YearMonth.from(today))
  2662. ? today : monthEnd;
  2663. this.maxDay = maxDate.getDayOfMonth();
  2664. this.start = Timestamp.valueOf(first.atStartOfDay());
  2665. this.end = Timestamp.valueOf(maxDate.plusDays(1).atStartOfDay());
  2666. }
  2667. static MonthPeriod of(YearMonth month) {
  2668. return new MonthPeriod(month);
  2669. }
  2670. }
  2671. private static final class ClassInfo {
  2672. final long bjid;
  2673. final String bjmc;
  2674. final Long dwid;
  2675. final String dwmc;
  2676. ClassInfo(long bjid, String bjmc, Long dwid, String dwmc) {
  2677. this.bjid = bjid;
  2678. this.bjmc = bjmc;
  2679. this.dwid = dwid;
  2680. this.dwmc = dwmc;
  2681. }
  2682. }
  2683. private record CategoryDef(String code, String label, double weight) {
  2684. }
  2685. private static final class DailyPoint {
  2686. final LocalDate date;
  2687. final double score;
  2688. final int count;
  2689. DailyPoint(LocalDate date, double score, int count) {
  2690. this.date = date;
  2691. this.score = score;
  2692. this.count = count;
  2693. }
  2694. }
  2695. private static final class DailyAccumulator {
  2696. final LocalDate date;
  2697. double regularDeduction;
  2698. boolean hasRegular;
  2699. DailyAccumulator(LocalDate date) {
  2700. this.date = date;
  2701. }
  2702. Map<String, Object> toMap() {
  2703. Map<String, Object> row = new LinkedHashMap<>();
  2704. row.put("date", date.format(DATE_FMT));
  2705. row.put("weekday", weekdayCn(date));
  2706. row.put("regularDeduction", round2(regularDeduction));
  2707. row.put("totalDeduction", round2(regularDeduction));
  2708. row.put("hasRegular", hasRegular);
  2709. return row;
  2710. }
  2711. }
  2712. private static final class CategoryDaily {
  2713. final ClassInfo cls;
  2714. final Map<String, Map<LocalDate, DailyPoint>> actual = new HashMap<>();
  2715. final Map<String, String> sources = new HashMap<>();
  2716. CategoryDaily(ClassInfo cls) {
  2717. this.cls = cls;
  2718. }
  2719. Map<String, Object> toMap(CategoryDef def, LocalDate date) {
  2720. String source = sources.getOrDefault(def.code, SOURCE_MISSING);
  2721. DailyPoint point = null;
  2722. if (SOURCE_REAL.equals(source)) {
  2723. Map<LocalDate, DailyPoint> values = actual.get(def.code);
  2724. point = values == null ? null : values.get(date);
  2725. }
  2726. boolean available;
  2727. double score;
  2728. double deduction;
  2729. if (point != null) {
  2730. available = true;
  2731. score = point.score;
  2732. deduction = Math.max(0.0, 100.0 - score);
  2733. } else {
  2734. available = false;
  2735. score = 0.0;
  2736. deduction = 0.0;
  2737. }
  2738. Map<String, Object> row = new LinkedHashMap<>();
  2739. row.put("code", def.code);
  2740. row.put("label", def.label);
  2741. row.put("score", round2(score));
  2742. row.put("deduction", round2(deduction));
  2743. row.put("source", source);
  2744. row.put("available", available);
  2745. row.put("count", point == null ? 0 : point.count);
  2746. return row;
  2747. }
  2748. double regularDeduction(LocalDate date) {
  2749. double total = 0.0;
  2750. for (CategoryDef def : CATEGORY_DEFS) {
  2751. Map<String, Object> row = toMap(def, date);
  2752. total += rdDouble(row.get("deduction"));
  2753. }
  2754. return total;
  2755. }
  2756. }
  2757. private static final class ScoreBook {
  2758. Map<Long, Double> dorm = new HashMap<>();
  2759. Map<Long, Double> dormAttendance = new HashMap<>();
  2760. Map<Long, Double> classroom = new HashMap<>();
  2761. Map<Long, Double> flag = new HashMap<>();
  2762. Map<Long, Double> cleaning = new HashMap<>();
  2763. Map<Long, Double> attendance = new HashMap<>();
  2764. Map<Long, Double> discipline = new HashMap<>();
  2765. Map<Long, AdjustmentTotals> adjustments = new HashMap<>();
  2766. Map<Long, ClassScore> classScores = new HashMap<>();
  2767. Map<String, String> categorySources(long bjid) {
  2768. ClassScore score = classScores.get(bjid);
  2769. return score == null ? Collections.emptyMap() : score.sources;
  2770. }
  2771. }
  2772. private static final class ClassScore {
  2773. final Map<String, Double> values = new LinkedHashMap<>();
  2774. final Map<String, String> sources = new LinkedHashMap<>();
  2775. final List<String> missing = new ArrayList<>();
  2776. AdjustmentTotals adjust = new AdjustmentTotals();
  2777. double total;
  2778. boolean hasMissing;
  2779. }
  2780. private static final class RankBook {
  2781. final Map<Long, Integer> schoolRank = new HashMap<>();
  2782. final Map<Long, Integer> departmentRank = new HashMap<>();
  2783. final Map<Long, Integer> departmentClassCount = new HashMap<>();
  2784. }
  2785. private static final class DisciplinePenalties {
  2786. final Map<Long, Map<LocalDate, Double>> mapped = new HashMap<>();
  2787. final Map<Long, Map<LocalDate, Double>> legacy = new HashMap<>();
  2788. }
  2789. private static final class Adjustment {
  2790. final long id;
  2791. final LocalDate date;
  2792. final double score;
  2793. final String itemName;
  2794. final String remark;
  2795. final String sourceType;
  2796. final long sourceRecordId;
  2797. final String studentName;
  2798. Adjustment(long id, LocalDate date, double score,
  2799. String itemName, String remark, String sourceType,
  2800. long sourceRecordId, String studentName) {
  2801. this.id = id;
  2802. this.date = date;
  2803. this.score = score;
  2804. this.itemName = itemName;
  2805. this.remark = remark;
  2806. this.sourceType = sourceType;
  2807. this.sourceRecordId = sourceRecordId;
  2808. this.studentName = studentName;
  2809. }
  2810. }
  2811. private static final class AdjustmentTotals {
  2812. double bonus;
  2813. double deduction;
  2814. int bonusEvents;
  2815. int deductionEvents;
  2816. }
  2817. private static final class PublishedSnapshot {
  2818. double total;
  2819. String starLevel;
  2820. double bonus;
  2821. double deduction;
  2822. int bonusCount;
  2823. int deductionCount;
  2824. int departmentRank;
  2825. int departmentClassCount;
  2826. int schoolRank;
  2827. int schoolClassCount;
  2828. final Map<String, String> sources = new LinkedHashMap<>();
  2829. }
  2830. }