| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093 |
- package biz.bj;
- import com.google.gson.Gson;
- import jakarta.servlet.http.HttpServletRequest;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import ss.db.Db;
- import ss.db.SqlCmd;
- import ss.obj.ObjC;
- import ss.serv.Serv;
- import ss.serv.ServU;
- import ss.user.UserRunB;
- import ss.user.UserU;
- import java.io.Writer;
- import java.sql.Date;
- import java.sql.SQLException;
- import java.sql.Timestamp;
- import java.time.DayOfWeek;
- import java.time.LocalDate;
- import java.time.YearMonth;
- import java.time.ZoneId;
- import java.time.format.DateTimeFormatter;
- import java.time.format.DateTimeParseException;
- import java.time.temporal.TemporalAdjusters;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- import java.util.LinkedHashSet;
- import java.util.List;
- import java.util.Locale;
- import java.util.Map;
- import java.util.Set;
- /**
- * 班主任星级班移动报表。
- */
- public class BjStarClassMpServ extends Serv {
- private static final Logger log4j = LogManager.getLogger(BjStarClassMpServ.class);
- private static final ZoneId CN_ZONE = ZoneId.of("Asia/Shanghai");
- private static final DateTimeFormatter MONTH_FMT = DateTimeFormatter.ofPattern("yyyy-MM");
- private static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- private static final DateTimeFormatter DATETIME_FMT =
- DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
- private static final String SOURCE_REAL = "real";
- private static final String SOURCE_MISSING = "missing";
- private static final String ZHIXIN_STAR_MARKER_PREFIX = "ZHIXIN_STAR_";
- private static final int DEFAULT_PAGE_SIZE = 20;
- private static final int DETAIL_PAGE_SIZE = 30;
- private static final List<CategoryDef> CATEGORY_DEFS = List.of(
- new CategoryDef("dorm", "宿舍评分", 0.20),
- new CategoryDef("classroom", "课堂考核", 0.05),
- new CategoryDef("flag", "升旗礼", 0.14),
- new CategoryDef("cleaning", "清洁卫生", 0.18),
- new CategoryDef("discipline", "风纪仪容", 0.20),
- new CategoryDef("attendance", "考勤", 0.15)
- );
- /**
- * 班主任、本人班级和默认月份。
- */
- @SuppressWarnings("unused")
- public void initByA() throws Exception {
- HttpServletRequest request = super.req;
- prepareJson();
- Writer writer = super.resp.getWriter();
- Gson gson = new Gson();
- try (Db db = Db.makeConn()) {
- UserRunB user = requireUser(request);
- List<ClassInfo> classes = rdTeacherClasses(db, user.ryid);
- if (classes.isEmpty())
- throw new IllegalArgumentException("当前账号未关联班主任班级");
- List<Map<String, Object>> classList = new ArrayList<>();
- for (ClassInfo item : classes) {
- Map<String, Object> classRow = new LinkedHashMap<>();
- classRow.put("bjid", item.bjid);
- classRow.put("bjmc", item.bjmc);
- classRow.put("dwid", item.dwid);
- classRow.put("dwmc", item.dwmc);
- classList.add(classRow);
- }
- Map<String, Object> data = new LinkedHashMap<>();
- data.put("teacherName", user.xm);
- data.put("defaultBjid", classes.get(0).bjid);
- data.put("defaultMonth", YearMonth.now(CN_ZONE).format(MONTH_FMT));
- data.put("classes", classList);
- ServU.wrOkDataByWriter(data, writer, gson);
- } catch (IllegalArgumentException e) {
- ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
- } catch (Exception e) {
- log4j.error("BjStarClassMpServ.initByA() 异常", e);
- ServU.wrErrMsgByWriter(null, "星级班信息加载失败", writer, gson);
- }
- }
- /**
- * 月度汇总和每日列表。
- */
- @SuppressWarnings("unused")
- public void summaryByA() throws Exception {
- HttpServletRequest request = super.req;
- prepareJson();
- Writer writer = super.resp.getWriter();
- Gson gson = new Gson();
- try (Db db = Db.makeConn()) {
- UserRunB user = requireUser(request);
- ClassInfo selected = requireTeacherClass(db, user.ryid,
- rdLongParam(request, "bjid", false));
- YearMonth month = rdMonth(request);
- MonthPeriod period = MonthPeriod.of(month);
- List<ClassInfo> classes = rdActiveClasses(db);
- ScoreBook scores = rdScoreBook(db, classes, period);
- RankBook ranks = rdRanks(classes, scores);
- ClassScore classScore = scores.classScores.get(selected.bjid);
- if (classScore == null)
- throw new IllegalStateException("班级评分未生成");
- PublishedSnapshot snapshot = rdPublishedSnapshot(
- db, selected.bjid, month);
- int pageNo = Math.max(1, rdIntParam(request, "pageNo", 1));
- int pageSize = clampPageSize(rdIntParam(request, "pageSize",
- DEFAULT_PAGE_SIZE));
- List<DailyAccumulator> allDays = rdDailyList(db, selected, period,
- scores.categorySources(selected.bjid));
- int from = Math.min(allDays.size(), (pageNo - 1) * pageSize);
- int to = Math.min(allDays.size(), from + pageSize);
- List<Map<String, Object>> dayRows = new ArrayList<>();
- for (int i = from; i < to; i++) {
- dayRows.add(allDays.get(i).toMap());
- }
- Map<String, Object> data = new LinkedHashMap<>();
- data.put("bjid", selected.bjid);
- data.put("bjmc", selected.bjmc);
- data.put("dwid", selected.dwid);
- data.put("dwmc", selected.dwmc);
- data.put("month", month.format(MONTH_FMT));
- if (snapshot != null) {
- data.put("score", snapshot.total);
- data.put("starLevel", snapshot.starLevel);
- data.put("departmentRank", snapshot.departmentRank);
- data.put("departmentClassCount", snapshot.departmentClassCount);
- data.put("schoolRank", snapshot.schoolRank);
- data.put("schoolClassCount", snapshot.schoolClassCount);
- data.put("bonusTotal", snapshot.bonus);
- data.put("deductionTotal", snapshot.deduction);
- data.put("bonusCount", snapshot.bonusCount);
- data.put("deductionCount", snapshot.deductionCount);
- data.put("rankingPreview", false);
- data.put("snapshotPublished", true);
- data.put("categorySources", snapshot.sources);
- } else {
- data.put("score", classScore.hasMissing
- ? null : round2(classScore.total));
- data.put("starLevel", classScore.hasMissing
- ? "待评分" : starLevel(classScore.total,
- ranks.schoolRank.getOrDefault(selected.bjid, 0)));
- data.put("departmentRank", classScore.hasMissing
- ? null : ranks.departmentRank.get(selected.bjid));
- data.put("departmentClassCount",
- ranks.departmentClassCount.getOrDefault(
- selected.dwid, 0));
- data.put("schoolRank", classScore.hasMissing
- ? null : ranks.schoolRank.get(selected.bjid));
- data.put("schoolClassCount", classes.size());
- data.put("bonusTotal", round2(classScore.adjust.bonus));
- data.put("deductionTotal",
- round2(classScore.adjust.deduction));
- data.put("bonusCount", classScore.adjust.bonusEvents);
- data.put("deductionCount", classScore.adjust.deductionEvents);
- data.put("rankingPreview", classScore.hasMissing);
- data.put("snapshotPublished", false);
- data.put("categorySources",
- scores.categorySources(selected.bjid));
- data.put("missingItems", classScore.missing);
- }
- data.put("pageNo", pageNo);
- data.put("pageSize", pageSize);
- data.put("total", allDays.size());
- data.put("hasMore", to < allDays.size());
- data.put("days", dayRows);
- ServU.wrOkDataByWriter(data, writer, gson);
- } catch (IllegalArgumentException e) {
- ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
- } catch (Exception e) {
- log4j.error("BjStarClassMpServ.summaryByA() 异常", e);
- ServU.wrErrMsgByWriter(null, "星级班月度数据加载失败", writer, gson);
- }
- }
- /**
- * 指定日期的六项得分。
- */
- @SuppressWarnings("unused")
- public void dayByA() throws Exception {
- HttpServletRequest request = super.req;
- prepareJson();
- Writer writer = super.resp.getWriter();
- Gson gson = new Gson();
- try (Db db = Db.makeConn()) {
- UserRunB user = requireUser(request);
- ClassInfo selected = requireTeacherClass(db, user.ryid,
- rdLongParam(request, "bjid", false));
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- YearMonth month = YearMonth.from(day);
- MonthPeriod period = MonthPeriod.of(month);
- CategoryDaily daily = rdCategoryDaily(db, selected, day, period);
- List<Map<String, Object>> categories = new ArrayList<>();
- for (CategoryDef def : CATEGORY_DEFS)
- categories.add(daily.toMap(def, day));
- Map<String, Object> data = new LinkedHashMap<>();
- data.put("bjid", selected.bjid);
- data.put("bjmc", selected.bjmc);
- data.put("date", day.format(DATE_FMT));
- data.put("weekday", weekdayCn(day));
- data.put("categories", categories);
- data.put("regularDeduction", round2(daily.regularDeduction(day)));
- ServU.wrOkDataByWriter(data, writer, gson);
- } catch (DateTimeParseException e) {
- ServU.wrErrMsgByWriter(null, "日期格式错误", writer, gson);
- } catch (IllegalArgumentException e) {
- ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
- } catch (Exception e) {
- log4j.error("BjStarClassMpServ.dayByA() 异常", e);
- ServU.wrErrMsgByWriter(null, "单日星级班数据加载失败", writer, gson);
- }
- }
- /**
- * 项目扣分明细,或月度增分/减分明细。
- */
- @SuppressWarnings("unused")
- public void detailByA() throws Exception {
- writeDetailResponse(false);
- }
- /**
- * PC 已发布月结报表的明细下钻入口。
- */
- @SuppressWarnings("unused")
- public void pcDetailByA() throws Exception {
- writeDetailResponse(true);
- }
- private void writeDetailResponse(boolean pcReport) throws Exception {
- HttpServletRequest request = super.req;
- prepareJson();
- Writer writer = super.resp.getWriter();
- Gson gson = new Gson();
- try (Db db = Db.makeConn()) {
- UserRunB user = requireUser(request);
- ClassInfo selected;
- YearMonth reportMonth = null;
- if (pcReport) {
- long bjid = rdLongParam(request, "bjid", true);
- long jdid = rdLongParam(request, "jdid", true);
- selected = requireReportClass(db, bjid, jdid);
- reportMonth = rdReportBatchMonth(db, jdid);
- } else {
- selected = requireTeacherClass(db, user.ryid,
- rdLongParam(request, "bjid", false));
- }
- Map<String, Object> data = buildDetailData(db, selected,
- request, reportMonth);
- ServU.wrOkDataByWriter(data, writer, gson);
- } catch (DateTimeParseException e) {
- ServU.wrErrMsgByWriter(null, "日期格式错误", writer, gson);
- } catch (IllegalArgumentException e) {
- ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
- } catch (Exception e) {
- log4j.error("BjStarClassMpServ.writeDetailResponse() 异常,"
- + "pcReport=" + pcReport, e);
- ServU.wrErrMsgByWriter(null, "星级班明细加载失败", writer, gson);
- }
- }
- private static Map<String, Object> buildDetailData(
- Db db, ClassInfo selected, HttpServletRequest request,
- YearMonth reportMonth)
- throws Exception {
- String mode = StringUtils.defaultIfBlank(
- request.getParameter("mode"), "dayItem");
- if ("trace".equals(mode)) {
- String kind = StringUtils.defaultIfBlank(
- request.getParameter("kind"), "regular");
- long recordId = rdLongParam(request, "id", true);
- if ("adjustment".equals(kind))
- return rdAdjustmentTrace(db, selected, recordId,
- reportMonth);
- if ("dormManagement".equals(kind))
- return rdDormManagementTrace(db, selected,
- rdDate(request, "date"), reportMonth);
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- ensureReportMonth(reportMonth, YearMonth.from(day));
- CategoryDef category = requireCategory(StringUtils.trimToNull(
- request.getParameter("category")));
- String source = StringUtils.defaultIfBlank(
- request.getParameter("source"), SOURCE_REAL);
- return rdTraceDetail(db, selected, day, category, recordId,
- source);
- }
- int pageNo = Math.max(1, rdIntParam(request, "pageNo", 1));
- int pageSize = clampPageSize(rdIntParam(request, "pageSize",
- DETAIL_PAGE_SIZE));
- List<Map<String, Object>> rows;
- String title;
- String monthText = null;
- String dateText = null;
- String categoryCode = null;
- String displayType = null;
- List<String> columns = null;
- if ("dormDaySummary".equals(mode)) {
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- ensureReportMonth(reportMonth, YearMonth.from(day));
- rows = rdDormDaySummary(db, selected, day);
- title = "宿舍评分 · " + day.format(DATE_FMT);
- dateText = day.format(DATE_FMT);
- categoryCode = "dorm";
- } else if ("dormAttendanceDetail".equals(mode)) {
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- ensureReportMonth(reportMonth, YearMonth.from(day));
- CategoryDef category = requireCategory("dorm");
- rows = rdAttendanceDetail(db, selected.bjid, day,
- XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
- for (Map<String, Object> row : rows) {
- row.put("detailKind", "regular");
- row.put("sourceType", "dormAttendance");
- }
- title = "住宿生考勤 · " + day.format(DATE_FMT);
- dateText = day.format(DATE_FMT);
- categoryCode = category.code;
- } else if ("flagDaySummary".equals(mode)) {
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- ensureReportMonth(reportMonth, YearMonth.from(day));
- rows = rdFlagDaySummary(db, selected.bjid, day);
- title = "升旗礼 · " + day.format(DATE_FMT);
- dateText = day.format(DATE_FMT);
- categoryCode = "flag";
- displayType = "deduction";
- columns = List.of("项目", "扣分");
- } else if ("flagAttendanceDetail".equals(mode)) {
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- ensureReportMonth(reportMonth, YearMonth.from(day));
- rows = rdFlagAttendanceDetail(db, selected.bjid, day);
- title = "考勤 · " + day.format(DATE_FMT);
- dateText = day.format(DATE_FMT);
- categoryCode = "flag";
- displayType = "value";
- columns = List.of("项目", "数值");
- } else if ("flagDemeanorDetail".equals(mode)) {
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- ensureReportMonth(reportMonth, YearMonth.from(day));
- rows = rdFlagDemeanorDetail(db, selected.bjid, day);
- title = "风貌 · " + day.format(DATE_FMT);
- dateText = day.format(DATE_FMT);
- categoryCode = "flag";
- displayType = "score";
- columns = List.of("项目", "得分");
- } else if ("dormInternalDetail".equals(mode)) {
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- ensureReportMonth(reportMonth, YearMonth.from(day));
- rows = rdDormInternalDetail(db, selected.bjid, day);
- title = "宿舍内务 · " + day.format(DATE_FMT);
- dateText = day.format(DATE_FMT);
- categoryCode = "dorm";
- } else if ("dormViolationDetail".equals(mode)) {
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- ensureReportMonth(reportMonth, YearMonth.from(day));
- rows = rdDormViolationDetail(db, selected.bjid, day);
- title = "宿舍违纪扣分 · " + day.format(DATE_FMT);
- dateText = day.format(DATE_FMT);
- categoryCode = "dorm";
- } else if ("bonus".equals(mode) || "deduction".equals(mode)) {
- YearMonth month = rdMonth(request);
- ensureReportMonth(reportMonth, month);
- List<Adjustment> adjustments = rdAdjustments(
- db, selected.bjid, month);
- List<Adjustment> selectedAdjustments = new ArrayList<>();
- for (Adjustment item : adjustments) {
- if ((("bonus".equals(mode) && item.score > 0)
- || ("deduction".equals(mode) && item.score < 0)))
- selectedAdjustments.add(item);
- }
- selectedAdjustments.sort(Comparator
- .comparing((Adjustment item) -> item.date).reversed()
- .thenComparingLong(item -> item.id).reversed());
- rows = rdAdjustmentRows(selectedAdjustments);
- title = "bonus".equals(mode) ? "当月增分明细" : "当月减分明细";
- monthText = month.format(MONTH_FMT);
- } else if ("monthCategory".equals(mode)) {
- YearMonth month = rdMonth(request);
- ensureReportMonth(reportMonth, month);
- categoryCode = StringUtils.trimToNull(
- request.getParameter("category"));
- CategoryDef category = requireCategory(categoryCode);
- MonthPeriod period = MonthPeriod.of(month);
- rows = rdMonthCategoryRows(db, selected, period, category);
- title = category.label + " · " + month.format(MONTH_FMT);
- monthText = month.format(MONTH_FMT);
- } else if ("dayItem".equals(mode)) {
- LocalDate day = rdDate(request, "date");
- if (day.isAfter(LocalDate.now(CN_ZONE)))
- throw new IllegalArgumentException("不能查询未来日期");
- ensureReportMonth(reportMonth, YearMonth.from(day));
- categoryCode = StringUtils.trimToNull(
- request.getParameter("category"));
- CategoryDef category = requireCategory(categoryCode);
- YearMonth month = YearMonth.from(day);
- MonthPeriod period = MonthPeriod.of(month);
- rows = rdDayDetail(db, selected, day, period, category);
- for (Map<String, Object> row : rows) {
- row.put("detailKind", "regular");
- if (!row.containsKey("sourceType"))
- row.put("sourceType", category.code);
- }
- title = category.label + " · " + day.format(DATE_FMT);
- dateText = day.format(DATE_FMT);
- } else {
- throw new IllegalArgumentException("明细模式参数错误");
- }
- int from = Math.min(rows.size(), (pageNo - 1) * pageSize);
- int to = Math.min(rows.size(), from + pageSize);
- List<Map<String, Object>> pageRows = rows.subList(from, to);
- Map<String, Object> data = new LinkedHashMap<>();
- data.put("bjid", selected.bjid);
- data.put("bjmc", selected.bjmc);
- data.put("mode", mode);
- data.put("title", title);
- data.put("month", monthText);
- data.put("date", dateText);
- data.put("category", categoryCode);
- data.put("displayType", displayType);
- data.put("columns", columns);
- data.put("pageNo", pageNo);
- data.put("pageSize", pageSize);
- data.put("total", rows.size());
- data.put("hasMore", to < rows.size());
- data.put("list", pageRows);
- return data;
- }
- private void prepareJson() throws Exception {
- super.resp.setCharacterEncoding("UTF-8");
- super.resp.setContentType("application/json;charset=UTF-8");
- }
- private static UserRunB requireUser(HttpServletRequest request) {
- UserRunB user = UserU.rdUserByReq(request);
- if (user == null)
- throw new IllegalArgumentException("登录状态已失效,请重新进入");
- return user;
- }
- private static List<ClassInfo> rdTeacherClasses(Db db, long ryid)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select b.BJID,b.MC,z.FZBMID DWID,nvl(bm.MC,'') DWMC"
- + " from BJ b inner join ZY z on z.ZYID=b.ZYID"
- + " left join BM bm on bm.BMID=z.FZBMID"
- + " where b.BZRID=:ryid and b." + ObjC.JLZT_useStr
- + " and b.BJZTM!=81 order by b.MC,b.BJID");
- sqlc.wrLongParm("ryid", ryid);
- return rdClasses(db.doSelMapListByC(sqlc));
- }
- private static List<ClassInfo> rdActiveClasses(Db db) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select b.BJID,b.MC,z.FZBMID DWID,nvl(bm.MC,'') DWMC"
- + " from BJ b inner join ZY z on z.ZYID=b.ZYID"
- + " left join BM bm on bm.BMID=z.FZBMID"
- + " where b." + ObjC.JLZT_useStr
- + " and b.BJZTM!=81 order by b.BJID");
- return rdClasses(db.doSelMapListByC(sqlc));
- }
- private static List<ClassInfo> rdClasses(List<Map<String, Object>> rows) {
- List<ClassInfo> list = new ArrayList<>();
- for (Map<String, Object> row : rows)
- list.add(new ClassInfo(rdLong(row.get("bjid")),
- rdStr(row.get("mc")), rdLongObj(row.get("dwid")),
- rdStr(row.get("dwmc"))));
- return list;
- }
- private static ClassInfo requireTeacherClass(Db db, long ryid, long bjid)
- throws Exception {
- List<ClassInfo> classes = rdTeacherClasses(db, ryid);
- if (classes.isEmpty())
- throw new IllegalArgumentException("当前账号未关联班主任班级");
- if (bjid <= 0)
- return classes.get(0);
- for (ClassInfo item : classes) {
- if (item.bjid == bjid)
- return item;
- }
- throw new IllegalArgumentException("无权查看该班级");
- }
- private static ClassInfo requireReportClass(Db db, long bjid, long jdid)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select b.BJID,b.MC,z.FZBMID DWID,nvl(bm.MC,'') DWMC"
- + " from BJ b inner join ZY z on z.ZYID=b.ZYID"
- + " left join BM bm on bm.BMID=z.FZBMID"
- + " where b.BJID=:bjid and b." + ObjC.JLZT_useStr
- + " and b.BJZTM!=81");
- sqlc.wrLongParm("bjid", bjid);
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- if (rows == null || rows.isEmpty())
- throw new IllegalArgumentException("班级不存在或已停用");
- if (jdid > 0) {
- SqlCmd check = new SqlCmd(
- "select count(*) CNT from XJB_JG g"
- + " inner join XJB_JD d on d.XJB_JDID=g.XJB_JDID"
- + " where g.XJB_JDID=:jdid and g.BJID=:bjid"
- + " and g.ZT=5 and d.ZT=5");
- check.wrLongParm("jdid", jdid);
- check.wrLongParm("bjid", bjid);
- db.doSelByC(check);
- if (db.rowNum == 0 || db.rdIntCol("cnt") == 0)
- throw new IllegalArgumentException("该班级不属于当前已发布月结");
- }
- return rdClasses(rows).get(0);
- }
- private static YearMonth rdReportBatchMonth(Db db, long jdid)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select NDY from XJB_JD where XJB_JDID=:jdid and ZT=5");
- sqlc.wrLongParm("jdid", jdid);
- db.doSelByC(sqlc);
- if (db.rowNum == 0)
- throw new IllegalArgumentException("月结批次不存在或未发布");
- return YearMonth.parse(db.rdStrCol("ndy"), MONTH_FMT);
- }
- private static void ensureReportMonth(YearMonth reportMonth,
- YearMonth requestedMonth) {
- if (reportMonth != null && !reportMonth.equals(requestedMonth))
- throw new IllegalArgumentException("明细月份不属于当前月结批次");
- }
- private static ScoreBook rdScoreBook(Db db, List<ClassInfo> classes,
- MonthPeriod period) throws Exception {
- ScoreBook book = new ScoreBook();
- book.cleaning = rdAvgScoreByClass(db, "CSWSJC", period);
- book.flag = rdFlagScoreByClass(db, period);
- book.classroom = rdAvgKtjlScoreByClass(db, period);
- Set<LocalDate> schoolDays = rdSchoolDays(db, period);
- Map<Long, Map<LocalDate, Double>> attendancePenalty =
- rdAttendancePenalty(db, period,
- XjbDormScoreU.AttendanceScope.DAY_STUDENT);
- book.attendance = computeAttendanceScores(
- classes, schoolDays, attendancePenalty);
- Map<Long, Map<LocalDate, Double>> dormAttendancePenalty =
- rdAttendancePenalty(db, period,
- XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
- book.dormAttendance = computeAttendanceScores(
- classes, schoolDays, dormAttendancePenalty);
- book.dorm = rdDormScores(db, classes, period, book.dormAttendance);
- book.discipline = rdDisciplineScores(db, classes, schoolDays, period);
- book.adjustments = rdAdjustmentTotals(db, period.month);
- for (ClassInfo cls : classes) {
- ClassScore score = new ClassScore();
- putScore(score, "dorm", "宿舍评分", book.dorm.get(cls.bjid));
- putScore(score, "classroom", "课堂考核",
- book.classroom.get(cls.bjid));
- putScore(score, "flag", "升旗礼", book.flag.get(cls.bjid));
- putScore(score, "cleaning", "清洁卫生",
- book.cleaning.get(cls.bjid));
- putScore(score, "discipline", "风纪仪容",
- book.discipline.get(cls.bjid));
- putScore(score, "attendance", "考勤",
- book.attendance.get(cls.bjid));
- score.adjust = book.adjustments.getOrDefault(
- cls.bjid, new AdjustmentTotals());
- if (score.missing.isEmpty()) {
- double weighted = 0.0;
- for (CategoryDef def : CATEGORY_DEFS)
- weighted += score.values.get(def.code) * def.weight;
- score.total = round2(weighted
- + Math.min(8.0, score.adjust.bonus)
- - score.adjust.deduction);
- }
- score.hasMissing = !score.missing.isEmpty();
- book.classScores.put(cls.bjid, score);
- }
- return book;
- }
- private static void putScore(ClassScore score, String code, String label,
- Double value) {
- if (value == null) {
- score.values.put(code, 0.0);
- score.sources.put(code, SOURCE_MISSING);
- score.missing.add(label);
- return;
- }
- score.values.put(code, round2(value));
- score.sources.put(code, SOURCE_REAL);
- }
- private static Map<Long, Double> rdAvgScoreByClass(Db db, String table,
- MonthPeriod period)
- throws Exception {
- if (!"SSNWJC".equals(table) && !"CSWSJC".equals(table))
- throw new IllegalArgumentException("评分表参数错误");
- SqlCmd sqlc = new SqlCmd(
- "select BJID,avg(FS) SCORE from " + table
- + " where JCSJ>=:start and JCSJ<:end and "
- + ObjC.JLZT_useStr + " group by BJID");
- sqlc.wrTimeParm("start", period.start);
- sqlc.wrTimeParm("end", period.end);
- return rdScoreMap(db.doSelMapListByC(sqlc));
- }
- private static Map<Long, Double> rdDormScores(
- Db db, List<ClassInfo> classes, MonthPeriod period,
- Map<Long, Double> attendanceScores) throws Exception {
- // 学校确认:宿舍内务不再要求上午、下午各有一条,所有有效检查取平均。
- SqlCmd internalCmd = new SqlCmd(
- "select BJID,avg(FS) SCORE from SSNWJC"
- + " where JCSJ>=:start and JCSJ<:end"
- + " and " + ObjC.JLZT_useStr + " group by BJID");
- internalCmd.wrTimeParm("start", period.start);
- internalCmd.wrTimeParm("end", period.end);
- Map<Long, Double> internal = new HashMap<>();
- for (Map<String, Object> row : db.doSelMapListByC(internalCmd))
- internal.put(rdLong(row.get("bjid")), rdDouble(row.get("score")));
- SqlCmd violationCmd = new SqlCmd(
- "select BJID,sum(PENALTY) PENALTY from ("
- + XjbWjjlU.dedupEventSql()
- + " where WJSJ>=:start and WJSJ<:end)"
- + " where RN=1 group by BJID");
- violationCmd.wrTimeParm("start", period.start);
- violationCmd.wrTimeParm("end", period.end);
- Map<Long, Double> violations = new HashMap<>();
- for (Map<String, Object> row : db.doSelMapListByC(violationCmd))
- violations.put(rdLong(row.get("bjid")),
- rdDouble(row.get("penalty")));
- Map<Long, Double> result = new HashMap<>();
- for (ClassInfo cls : classes) {
- Double internalScore = internal.get(cls.bjid);
- Double attendance = attendanceScores.get(cls.bjid);
- if (internalScore == null || attendance == null)
- continue;
- // 学校确认:宿舍评分允许出现负数。
- double violationScore =
- 100.0 - violations.getOrDefault(cls.bjid, 0.0);
- double base = internalScore * 0.35 + attendance * 0.15
- + violationScore * 0.35;
- XjbDormScoreU.ManagementSummary management =
- XjbDormScoreU.rdManagementSummary(
- db, cls.bjid, period.start, period.end);
- result.put(cls.bjid, round2(base + base / 85.0 * 10.0
- + management.bonus));
- }
- return result;
- }
- private static Map<Long, Double> rdDisciplineScores(
- Db db, List<ClassInfo> classes, Set<LocalDate> schoolDays,
- MonthPeriod period) throws Exception {
- Map<Long, Double> result = new HashMap<>();
- if (schoolDays.isEmpty())
- return result;
- DisciplinePenalties penalties = rdDisciplinePenalties(
- db, null, period.start, period.end);
- for (ClassInfo cls : classes) {
- Map<LocalDate, Double> mapped = penalties.mapped.getOrDefault(
- cls.bjid, Collections.emptyMap());
- Map<LocalDate, Double> legacy = penalties.legacy.getOrDefault(
- cls.bjid, Collections.emptyMap());
- double total = 0.0;
- for (LocalDate day : schoolDays)
- total += Math.max(0.0, 100.0
- - disciplinePenalty(mapped, legacy, day));
- result.put(cls.bjid, round2(total / schoolDays.size()));
- }
- return result;
- }
- private static DisciplinePenalties rdDisciplinePenalties(
- Db db, Long bjid, Timestamp start, Timestamp end) throws Exception {
- DisciplinePenalties result = new DisciplinePenalties();
- String bjFilter = bjid == null ? "" : " and w.BJID=:bjid";
- SqlCmd current = new SqlCmd(
- "select w.BJID,trunc(w.WJSJ) D,sum(nvl(lb.BJKF,0)) PENALTY"
- + " from WJJL w"
- + " inner join WJLB lb on lb.WJLBM=w.WJLBM"
- + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
- + " and wm.YTM=" + XjbWjlbC.YTM_DISCIPLINE
- + " and wm.JLZTM=51"
- + " where w.WJSJ>=:start and w.WJSJ<:end"
- + " and w.JLZTM=51" + bjFilter
- + " group by w.BJID,trunc(w.WJSJ)");
- current.wrTimeParm("start", start);
- current.wrTimeParm("end", end);
- if (bjid != null)
- current.wrLongParm("bjid", bjid);
- for (Map<String, Object> row : db.doSelMapListByC(current)) {
- long classId = rdLong(row.get("bjid"));
- LocalDate day = rdLocalDate(row.get("d"));
- if (day != null)
- result.mapped.computeIfAbsent(classId, key -> new HashMap<>())
- .put(day, rdDouble(row.get("penalty")));
- }
- SqlCmd legacy = new SqlCmd(
- "select BJID,JCRQ D,sum(case when MS like :importMarker"
- + " then nvl(WJRS,0)/10 else nvl(WJRS,0) end) PENALTY"
- + " from XJB_FJRY"
- + " where JCRQ>=:start and JCRQ<:end and JLZTM=51"
- + (bjid == null ? "" : " and BJID=:bjid")
- + " group by BJID,JCRQ");
- legacy.wrStrParm("importMarker", ZHIXIN_STAR_MARKER_PREFIX + "%");
- legacy.wrTimeParm("start", start);
- legacy.wrTimeParm("end", end);
- if (bjid != null)
- legacy.wrLongParm("bjid", bjid);
- for (Map<String, Object> row : db.doSelMapListByC(legacy)) {
- long classId = rdLong(row.get("bjid"));
- LocalDate day = rdLocalDate(row.get("d"));
- if (day != null)
- result.legacy.computeIfAbsent(classId, key -> new HashMap<>())
- .put(day, rdDouble(row.get("penalty")));
- }
- return result;
- }
- private static double disciplinePenalty(
- Map<LocalDate, Double> mapped, Map<LocalDate, Double> legacy,
- LocalDate day) {
- Double penalty = mapped.get(day);
- if (penalty == null)
- penalty = legacy.get(day);
- return penalty == null ? 0.0 : penalty;
- }
- private static Map<Long, Double> rdFlagScoreByClass(Db db,
- MonthPeriod period)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select s.BJID,avg(s.ZFS) SCORE from SQLJC s"
- + " where s.JCSJ>=:start and s.JCSJ<:end"
- + " and s.ZFS between 0 and 100 and s."
- + ObjC.JLZT_useStr + " group by s.BJID");
- sqlc.wrTimeParm("start", period.start);
- sqlc.wrTimeParm("end", period.end);
- return rdScoreMap(db.doSelMapListByC(sqlc));
- }
- private static Map<Long, Double> rdAvgKtjlScoreByClass(
- Db db, MonthPeriod period) throws Exception {
- try {
- SqlCmd sqlc = new SqlCmd(
- "select j.BJID,avg(j.FS) SCORE from KTJL j"
- + " inner join KCB k on k.KCBID=j.KCBID"
- + " where k.KSSJ>=:start and k.KSSJ<:end"
- + " and j." + ObjC.JLZT_useStr
- + " and k." + ObjC.JLZT_useStr
- + " group by j.BJID");
- sqlc.wrTimeParm("start", period.start);
- sqlc.wrTimeParm("end", period.end);
- return rdScoreMap(db.doSelMapListByC(sqlc));
- } catch (SQLException e) {
- if (isMissingTable(e, "KTJL"))
- return Collections.emptyMap();
- throw e;
- }
- }
- private static Set<LocalDate> rdSchoolDays(Db db, MonthPeriod period)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select distinct trunc(KSSJ) D from KQJL"
- + " where KSSJ>=:start and KSSJ<:end"
- + " and KQJLZTM=51 and " + ObjC.JLZT_useStr);
- sqlc.wrTimeParm("start", period.start);
- sqlc.wrTimeParm("end", period.end);
- Set<LocalDate> days = new LinkedHashSet<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- LocalDate day = rdLocalDate(row.get("d"));
- if (day != null && !day.isAfter(period.maxDate))
- days.add(day);
- }
- return days;
- }
- private static Map<Long, Map<LocalDate, Double>> rdAttendancePenalty(
- Db db, MonthPeriod period,
- XjbDormScoreU.AttendanceScope scope) throws Exception {
- Map<Long, Map<LocalDate, Double>> result =
- XjbDormScoreU.rdAttendancePenalty(
- db, period.start, period.end, scope);
- for (Map<LocalDate, Double> values : result.values())
- values.keySet().removeIf(day -> day.isAfter(period.maxDate));
- return result;
- }
- private static Map<Long, Double> computeAttendanceScores(
- List<ClassInfo> classes, Set<LocalDate> schoolDays,
- Map<Long, Map<LocalDate, Double>> penalties) {
- Map<Long, Double> result = new HashMap<>();
- if (schoolDays.isEmpty())
- return result;
- List<LocalDate> days = new ArrayList<>(schoolDays);
- for (ClassInfo cls : classes) {
- Map<LocalDate, Double> classPenalties = penalties.getOrDefault(
- cls.bjid, Collections.emptyMap());
- double total = 0.0;
- for (LocalDate day : days) {
- double penalty = classPenalties.getOrDefault(day, 0.0);
- total += Math.max(0.0, 100.0 - penalty);
- }
- result.put(cls.bjid, round2(total / days.size()));
- }
- return result;
- }
- private static RankBook rdRanks(List<ClassInfo> classes, ScoreBook book) {
- RankBook ranks = new RankBook();
- List<ClassInfo> school = new ArrayList<>();
- for (ClassInfo cls : classes) {
- ClassScore score = book.classScores.get(cls.bjid);
- if (score != null && !score.hasMissing)
- school.add(cls);
- }
- school.sort(Comparator
- .comparingDouble((ClassInfo cls) ->
- -book.classScores.get(cls.bjid).total)
- .thenComparingLong(cls -> cls.bjid));
- assignRanks(school, book, ranks.schoolRank, "school");
- Map<Long, List<ClassInfo>> departments = new LinkedHashMap<>();
- for (ClassInfo cls : school)
- departments.computeIfAbsent(cls.dwid, key -> new ArrayList<>()).add(cls);
- for (Map.Entry<Long, List<ClassInfo>> entry : departments.entrySet()) {
- entry.getValue().sort(Comparator
- .comparingDouble((ClassInfo cls) ->
- -book.classScores.get(cls.bjid).total)
- .thenComparingLong(cls -> cls.bjid));
- assignRanks(entry.getValue(), book, ranks.departmentRank, "department");
- ranks.departmentClassCount.put(entry.getKey(), entry.getValue().size());
- }
- return ranks;
- }
- private static void assignRanks(List<ClassInfo> sorted, ScoreBook book,
- Map<Long, Integer> rankMap, String type) {
- double prev = Double.NaN;
- int rank = 0;
- for (int i = 0; i < sorted.size(); i++) {
- ClassInfo cls = sorted.get(i);
- double score = book.classScores.get(cls.bjid).total;
- if (i == 0 || Double.compare(prev, score) != 0)
- rank = i + 1;
- rankMap.put(cls.bjid, rank);
- prev = score;
- }
- }
- private static List<DailyAccumulator> rdDailyList(
- Db db, ClassInfo cls, MonthPeriod period,
- Map<String, String> sources) throws Exception {
- CategoryDaily daily = rdCategoryDaily(db, cls, null, period);
- Map<LocalDate, DailyAccumulator> days = new HashMap<>();
- for (CategoryDef def : CATEGORY_DEFS) {
- String source = sources.getOrDefault(def.code, SOURCE_MISSING);
- Map<LocalDate, DailyPoint> actual = daily.actual.get(def.code);
- for (LocalDate date = period.month.atDay(1);
- !date.isAfter(period.maxDate);
- date = date.plusDays(1)) {
- DailyPoint point = null;
- if (SOURCE_REAL.equals(source)) {
- point = actual == null ? null : actual.get(date);
- }
- if (point == null)
- continue;
- DailyAccumulator acc = days.computeIfAbsent(date,
- DailyAccumulator::new);
- acc.regularDeduction += Math.max(0.0, 100.0 - point.score);
- acc.hasRegular = true;
- }
- }
- List<DailyAccumulator> result = new ArrayList<>(days.values());
- result.sort(Comparator.comparing(
- (DailyAccumulator item) -> item.date).reversed());
- return result;
- }
- private static CategoryDaily rdCategoryDaily(Db db, ClassInfo cls,
- LocalDate onlyDay,
- MonthPeriod period)
- throws Exception {
- CategoryDaily result = new CategoryDaily(cls);
- Timestamp start = onlyDay == null ? period.start
- : Timestamp.valueOf(onlyDay.atStartOfDay());
- Timestamp end = onlyDay == null ? period.end
- : Timestamp.valueOf(onlyDay.plusDays(1).atStartOfDay());
- result.actual.put("dorm", rdDailyDormScore(db, cls,
- onlyDay, period));
- result.actual.put("cleaning", rdDailyAvgScore(db, "CSWSJC",
- cls.bjid, start, end));
- result.actual.put("flag", rdDailyFlagScore(db, cls.bjid, start, end));
- result.actual.put("classroom", rdDailyKtjlScore(
- db, cls.bjid, start, end));
- result.actual.put("attendance", rdDailyAttendanceScore(db,
- cls.bjid, start, end,
- XjbDormScoreU.AttendanceScope.DAY_STUDENT));
- result.actual.put("discipline", rdDailyDisciplineScore(
- db, cls.bjid, start, end));
- MonthPeriod fullMonth = MonthPeriod.of(period.month);
- Map<Long, Double> monthClean = rdAvgScoreByClass(db, "CSWSJC", fullMonth);
- Map<Long, Double> monthFlag = rdFlagScoreByClass(db, fullMonth);
- Set<LocalDate> monthSchoolDays = rdSchoolDays(db, fullMonth);
- Map<Long, Double> monthAttendance = computeAttendanceScores(
- List.of(cls), monthSchoolDays,
- rdAttendancePenalty(db, fullMonth,
- XjbDormScoreU.AttendanceScope.DAY_STUDENT));
- Map<Long, Double> monthDormAttendance = computeAttendanceScores(
- List.of(cls), monthSchoolDays,
- rdAttendancePenalty(db, fullMonth,
- XjbDormScoreU.AttendanceScope.BOARDING_STUDENT));
- Map<Long, Double> monthDorm = rdDormScores(db, List.of(cls),
- fullMonth, monthDormAttendance);
- Map<Long, Double> monthClassroom =
- rdAvgKtjlScoreByClass(db, fullMonth);
- Map<Long, Double> monthDiscipline =
- rdDisciplineScores(db, List.of(cls), monthSchoolDays,
- fullMonth);
- result.sources.put("dorm", monthDorm.containsKey(cls.bjid)
- ? SOURCE_REAL : SOURCE_MISSING);
- result.sources.put("classroom",
- monthClassroom.containsKey(cls.bjid)
- ? SOURCE_REAL : SOURCE_MISSING);
- result.sources.put("flag", monthFlag.containsKey(cls.bjid)
- ? SOURCE_REAL : SOURCE_MISSING);
- result.sources.put("cleaning", monthClean.containsKey(cls.bjid)
- ? SOURCE_REAL : SOURCE_MISSING);
- result.sources.put("discipline",
- monthDiscipline.containsKey(cls.bjid)
- ? SOURCE_REAL : SOURCE_MISSING);
- result.sources.put("attendance", monthAttendance.containsKey(cls.bjid)
- ? SOURCE_REAL : SOURCE_MISSING);
- return result;
- }
- private static Map<LocalDate, DailyPoint> rdDailyAvgScore(
- Db db, String table, long bjid, Timestamp start, Timestamp end)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select trunc(JCSJ) D,avg(FS) SCORE,count(*) CNT from "
- + table + " where BJID=:bjid and JCSJ>=:start"
- + " and JCSJ<:end and " + ObjC.JLZT_useStr
- + " group by trunc(JCSJ)");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- return rdDailyPoints(db.doSelMapListByC(sqlc));
- }
- private static Map<LocalDate, DailyPoint> rdDailyDormScore(
- Db db, ClassInfo cls, LocalDate onlyDay, MonthPeriod period)
- throws Exception {
- Timestamp start = onlyDay == null ? period.start
- : Timestamp.valueOf(onlyDay.atStartOfDay());
- Timestamp end = onlyDay == null ? period.end
- : Timestamp.valueOf(onlyDay.plusDays(1).atStartOfDay());
- // 学校确认:单日宿舍内务按当天所有有效记录取平均,不区分上午/下午。
- SqlCmd itemCmd = new SqlCmd(
- "select trunc(JCSJ) D,avg(FS) SCORE,count(*) CNT"
- + " from SSNWJC where BJID=:bjid and JCSJ>=:start"
- + " and JCSJ<:end and " + ObjC.JLZT_useStr
- + " group by trunc(JCSJ)");
- itemCmd.wrLongParm("bjid", cls.bjid);
- itemCmd.wrTimeParm("start", start);
- itemCmd.wrTimeParm("end", end);
- Map<LocalDate, DailyPoint> internal = rdDailyPoints(
- db.doSelMapListByC(itemCmd));
- Map<LocalDate, Double> violations =
- rdDormViolationPenalties(db, cls.bjid, start, end);
- Map<Long, Map<LocalDate, Double>> attendancePenalties =
- XjbDormScoreU.rdAttendancePenalty(
- db, start, end,
- XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
- Map<LocalDate, Double> classAttendancePenalty =
- attendancePenalties.getOrDefault(
- cls.bjid, Collections.emptyMap());
- Map<LocalDate, DailyPoint> result = new HashMap<>();
- for (Map.Entry<LocalDate, DailyPoint> entry : internal.entrySet()) {
- DailyPoint internalPoint = entry.getValue();
- double attendanceScore = Math.max(0.0, 100.0
- - classAttendancePenalty.getOrDefault(
- entry.getKey(), 0.0));
- double violationScore =
- 100.0 - violations.getOrDefault(entry.getKey(), 0.0);
- double base = internalPoint.score * 0.35
- + attendanceScore * 0.15
- + violationScore * 0.35;
- result.put(entry.getKey(), new DailyPoint(entry.getKey(),
- round2(base + base / 85.0 * 10.0),
- internalPoint.count));
- }
- return result;
- }
- private static List<Map<String, Object>> rdDormDaySummary(
- Db db, ClassInfo cls, LocalDate day) throws Exception {
- Timestamp start = Timestamp.valueOf(day.atStartOfDay());
- Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
- MonthPeriod month = MonthPeriod.of(YearMonth.from(day));
- Map<LocalDate, DailyPoint> internal =
- rdDailyAvgScore(db, "SSNWJC", cls.bjid, start, end);
- DailyPoint internalPoint = internal.get(day);
- Map<Long, Map<LocalDate, Double>> attendancePenalties =
- XjbDormScoreU.rdAttendancePenalty(
- db, start, end,
- XjbDormScoreU.AttendanceScope.BOARDING_STUDENT);
- double attendancePenalty = attendancePenalties
- .getOrDefault(cls.bjid, Collections.emptyMap())
- .getOrDefault(day, 0.0);
- double attendanceScore = Math.max(0.0, 100.0 - attendancePenalty);
- double violationPenalty = rdDormViolationPenalties(
- db, cls.bjid, start, end).getOrDefault(day, 0.0);
- XjbDormScoreU.ManagementSummary management =
- XjbDormScoreU.rdManagementSummary(
- db, cls.bjid, month.start, month.end);
- List<Map<String, Object>> rows = new ArrayList<>();
- rows.add(dormSummaryRow(day, "attendance", "考勤",
- round2(attendanceScore), "实", "住宿生当日考勤",
- true, "attendance"));
- if (internalPoint == null) {
- rows.add(dormSummaryRow(day, "internal", "内务",
- null, "缺", "当日暂无有效内务检查", false, "internal"));
- } else {
- rows.add(dormSummaryRow(day, "internal", "内务",
- round2(internalPoint.score), "实",
- "共" + internalPoint.count + "条内务检查",
- true, "internal"));
- }
- rows.add(dormSummaryRow(day, "violation", "违纪扣分",
- violationPenalty > 0.0 ? -round2(violationPenalty) : 0.0,
- "实",
- violationPenalty > 0
- ? "宿舍违纪已在基础分中扣减"
- : "当日无宿舍违纪扣分",
- violationPenalty > 0, "violation"));
- double managementScore = management.available
- ? management.bonus : 0.0;
- rows.add(dormSummaryRow(day, "management", "增分",
- managementScore, "实", "",
- management.available, "management"));
- rows.add(dormSummaryRow(day, "deduction", "减分",
- 0.0, "停", "宿舍减分规则暂未启用",
- false, "deduction"));
- return rows;
- }
- private static Map<String, Object> dormSummaryRow(
- LocalDate day, String key, String itemName, Double score,
- String state, String meta, boolean traceable, String detailType) {
- Map<String, Object> row = baseDetail(day, SOURCE_REAL);
- row.put("id", key);
- row.put("sourceId", key);
- row.put("sourceType", "dormDaySummary");
- row.put("detailKind", "dormSummary");
- row.put("category", "dorm");
- row.put("key", key);
- row.put("itemName", itemName);
- row.put("title", itemName);
- row.put("score", score);
- row.put("scoreText", score == null ? "-"
- : String.format(Locale.ROOT, "%.2f", score));
- row.put("state", state);
- row.put("remark", meta);
- row.put("traceable", traceable);
- row.put("detailType", detailType);
- row.put("sortTime", key);
- return row;
- }
- private static Map<LocalDate, Double> rdDormViolationPenalties(
- Db db, long bjid, Timestamp start, Timestamp end)
- throws Exception {
- SqlCmd violationCmd = new SqlCmd(
- "select trunc(WJSJ) D,sum(PENALTY) PENALTY from ("
- + XjbWjjlU.dedupEventSql()
- + " where TARGET_BJID=:bjid"
- + " and WJSJ>=:start and WJSJ<:end)"
- + " where RN=1 group by trunc(WJSJ)");
- violationCmd.wrLongParm("bjid", bjid);
- violationCmd.wrTimeParm("start", start);
- violationCmd.wrTimeParm("end", end);
- Map<LocalDate, Double> result = new HashMap<>();
- for (Map<String, Object> row : db.doSelMapListByC(violationCmd)) {
- LocalDate day = rdLocalDate(row.get("d"));
- if (day != null)
- result.put(day, rdDouble(row.get("penalty")));
- }
- return result;
- }
- private static Map<String, Object> rdDormManagementTrace(
- Db db, ClassInfo cls, LocalDate day, YearMonth reportMonth)
- throws Exception {
- YearMonth month = reportMonth == null
- ? YearMonth.from(day) : reportMonth;
- MonthPeriod period = MonthPeriod.of(month);
- XjbDormScoreU.ManagementSummary summary =
- XjbDormScoreU.rdManagementSummary(
- db, cls.bjid, period.start, period.end);
- Map<String, Object> record = new LinkedHashMap<>();
- record.put("time", day.format(DATE_FMT));
- record.put("className", cls.bjmc);
- record.put("teacherName", summary.teacherName);
- record.put("visitCount", summary.visitCount);
- record.put("bonus", summary.bonus);
- record.put("description", summary.message);
- record.put("source", summary.source);
- List<Map<String, Object>> items = new ArrayList<>();
- for (XjbDormScoreU.Visit visit : summary.visits) {
- Map<String, Object> item = new LinkedHashMap<>();
- item.put("itemName", "有效参与");
- item.put("remark", XjbDormScoreU.formatMinute(visit.enterTime)
- + " 至 " + XjbDormScoreU.formatMinute(visit.leaveTime)
- + ",共" + visit.minutes + "分钟"
- + (StringUtils.isBlank(visit.mjdName)
- ? "" : "," + visit.mjdName));
- item.put("deducted", 0.0);
- items.add(item);
- }
- CategoryDef category = requireCategory("dorm");
- return traceResult(cls, day, category, SOURCE_REAL,
- "班主任宿舍管理参与详情", record, items,
- summary.available ? "" : summary.message);
- }
- private static List<Map<String, Object>> rdDormInternalDetail(
- Db db, long bjid, LocalDate day) throws Exception {
- Timestamp start = Timestamp.valueOf(day.atStartOfDay());
- Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select s.SSNWJCID,s.FS,s.MS,s.JCSJ,cd.MC KFMC,"
- + "jc.XM JCRYXM from SSNWJC s"
- + " left join CD cd on cd.CDID=s.KFID"
- + " left join RY jc on jc.RYID=s.JCRYID"
- + " where s.BJID=:bjid and s.JCSJ>=:start"
- + " and s.JCSJ<:end and s." + ObjC.JLZT_useStr
- + " order by s.JCSJ desc,s.SSNWJCID desc");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- List<Map<String, Object>> result = new ArrayList<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- long id = rdLong(row.get("ssnwjcid"));
- double score = rdDouble(row.get("fs"));
- item.put("id", id);
- item.put("sourceId", id);
- item.put("category", "dorm");
- item.put("traceable", true);
- item.put("itemName", "内务检查");
- item.put("roomName", rdStr(row.get("kfmc")));
- item.put("title", rdStr(row.get("kfmc")));
- item.put("remark", rdStr(row.get("ms")));
- item.put("scoreText", score + "/100");
- item.put("delta", round2(score - 100.0));
- item.put("sortTime", formatTimestamp(row.get("jcsj")));
- result.add(item);
- }
- return result;
- }
- private static List<Map<String, Object>> rdImportedCleaningSummary(
- Db db, long bjid, LocalDate day) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select CSWSJCID,FS,JCSJ from CSWSJC"
- + " where BJID=:bjid"
- + " and trunc(JCSJ)=to_date(:day,'YYYY-MM-DD')"
- + " and MS like :marker and JLZTM=51");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrStrParm("day", day.format(DATE_FMT));
- sqlc.wrStrParm("marker", ZHIXIN_STAR_MARKER_PREFIX + "%");
- List<Map<String, Object>> result = new ArrayList<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- double score = rdDouble(row.get("fs"));
- double deduction = round2(Math.max(0.0, 100.0 - score));
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- item.put("id", rdLong(row.get("cswsjcid")));
- item.put("sourceId", rdLong(row.get("cswsjcid")));
- item.put("category", "cleaning");
- item.put("traceable", false);
- item.put("itemName", "清洁卫生日总分");
- item.put("title", "清洁卫生日总分");
- item.put("remark", "");
- item.put("delta", -deduction);
- item.put("scoreText", plainNumber(score) + "/100");
- item.put("sortTime", formatTimestamp(row.get("jcsj")));
- result.add(item);
- }
- return result;
- }
- private static List<Map<String, Object>> rdDormViolationDetail(
- Db db, long bjid, LocalDate day) throws Exception {
- Timestamp start = Timestamp.valueOf(day.atStartOfDay());
- Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select WJJLID,D,RYXM,WJLBMC,BJKF,WJSJ,MS from ("
- + "select w.WJJLID,trunc(w.WJSJ) D,ry.XM RYXM,"
- + "lb.MC WJLBMC,nvl(lb.BJKF,0) BJKF,w.WJSJ,w.MS,"
- + "row_number() over(partition by w.BJID,w.WJLXM,"
- + "case when w.WJLXM=5 then w.WJLBM end,"
- + "case when w.WJLXM=5 then w.WJSJ end,"
- + "case when w.WJLXM=5 then w.JZWID end,"
- + "case when w.WJLXM=5 then w.KFID end,"
- + "case when w.WJLXM=5 then nvl(w.MS,' ') end,"
- + "case when w.WJLXM=5 then nvl(w.FJID,0) end,"
- + "case when w.WJLXM=5 then 0 else w.WJJLID end"
- + " order by w.WJJLID) RN"
- + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
- + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
- + " and wm.YTM=" + XjbWjlbC.YTM_DORM
- + " and wm.JLZTM=51"
- + " left join RY ry on ry.RYID=w.RYID"
- + " where w.BJID=:bjid and w.WJSJ>=:start"
- + " and w.WJSJ<:end and w.JLZTM=51)"
- + " where RN=1 order by WJSJ desc,WJJLID desc");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- List<Map<String, Object>> result = new ArrayList<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- item.put("id", rdLong(row.get("wjjlid")));
- item.put("sourceId", rdLong(row.get("wjjlid")));
- item.put("category", "dorm");
- item.put("traceable", false);
- item.put("itemName", rdStr(row.get("wjlbmc")));
- item.put("studentName", rdStr(row.get("ryxm")));
- item.put("title", rdStr(row.get("wjlbmc")));
- item.put("remark", rdStr(row.get("ms")));
- item.put("delta", -rdDouble(row.get("bjkf")));
- item.put("scoreText", "");
- item.put("sortTime", formatTimestamp(row.get("wjsj")));
- result.add(item);
- }
- return result;
- }
- private static Map<LocalDate, DailyPoint> rdDailyDisciplineScore(
- Db db, long bjid, Timestamp start, Timestamp end)
- throws Exception {
- DisciplinePenalties penalties = rdDisciplinePenalties(
- db, bjid, start, end);
- Map<LocalDate, Double> mapped = penalties.mapped.getOrDefault(
- bjid, Collections.emptyMap());
- Map<LocalDate, Double> legacy = penalties.legacy.getOrDefault(
- bjid, Collections.emptyMap());
- Set<LocalDate> dates = new LinkedHashSet<>(mapped.keySet());
- dates.addAll(legacy.keySet());
- Map<LocalDate, DailyPoint> result = new HashMap<>();
- for (LocalDate day : dates) {
- double penalty = disciplinePenalty(mapped, legacy, day);
- result.put(day, new DailyPoint(day,
- Math.max(0.0, 100.0 - penalty), 1));
- }
- return result;
- }
- private static Map<LocalDate, DailyPoint> rdDailyFlagScore(
- Db db, long bjid, Timestamp start, Timestamp end) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select trunc(s.JCSJ) D,avg(s.ZFS) SCORE,count(*) CNT"
- + " from SQLJC s where s.BJID=:bjid and s.JCSJ>=:start"
- + " and s.JCSJ<:end and s.ZFS between 0 and 100"
- + " and s." + ObjC.JLZT_useStr
- + " group by trunc(s.JCSJ)");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- return rdDailyPoints(db.doSelMapListByC(sqlc));
- }
- private static Map<LocalDate, DailyPoint> rdDailyKtjlScore(
- Db db, long bjid, Timestamp start, Timestamp end) throws Exception {
- try {
- SqlCmd sqlc = new SqlCmd(
- "select trunc(k.KSSJ) D,avg(j.FS) SCORE,count(*) CNT"
- + " from KTJL j inner join KCB k on k.KCBID=j.KCBID"
- + " where j.BJID=:bjid and k.KSSJ>=:start"
- + " and k.KSSJ<:end and j." + ObjC.JLZT_useStr
- + " and k." + ObjC.JLZT_useStr
- + " group by trunc(k.KSSJ)");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- return rdDailyPoints(db.doSelMapListByC(sqlc));
- } catch (SQLException e) {
- if (isMissingTable(e, "KTJL"))
- return Collections.emptyMap();
- throw e;
- }
- }
- private static Map<LocalDate, DailyPoint> rdDailyAttendanceScore(
- Db db, long bjid, Timestamp start, Timestamp end,
- XjbDormScoreU.AttendanceScope scope) throws Exception {
- Map<Long, Map<LocalDate, Double>> penalties =
- XjbDormScoreU.rdAttendancePenalty(db, start, end, scope);
- Map<LocalDate, Double> classPenalties =
- penalties.getOrDefault(bjid, Collections.emptyMap());
- Map<LocalDate, DailyPoint> points = new HashMap<>();
- for (Map.Entry<LocalDate, Double> entry : classPenalties.entrySet()) {
- points.put(entry.getKey(), new DailyPoint(entry.getKey(),
- Math.max(0.0, 100.0 - entry.getValue()), 1));
- }
- return points;
- }
- private static Map<LocalDate, DailyPoint> rdDailyPoints(
- List<Map<String, Object>> rows) {
- Map<LocalDate, DailyPoint> points = new HashMap<>();
- for (Map<String, Object> row : rows) {
- LocalDate day = rdLocalDate(row.get("d"));
- if (day != null)
- points.put(day, new DailyPoint(day,
- rdDouble(row.get("score")), rdInt(row.get("cnt"))));
- }
- return points;
- }
- private static List<Map<String, Object>> rdMonthCategoryRows(
- Db db, ClassInfo cls, MonthPeriod period, CategoryDef category)
- throws Exception {
- CategoryDaily monthly = rdCategoryDaily(db, cls, null, period);
- String source = monthly.sources.getOrDefault(
- category.code, SOURCE_MISSING);
- Map<LocalDate, DailyPoint> points = monthly.actual.get(category.code);
- List<Map<String, Object>> rows = new ArrayList<>();
- if (SOURCE_REAL.equals(source) && points != null) {
- for (DailyPoint point : points.values()) {
- double deduction = round2(
- Math.max(0.0, 100.0 - point.score));
- Map<String, Object> row = baseDetail(point.date, SOURCE_REAL);
- row.put("id", point.date.format(DATE_FMT));
- row.put("sourceId", point.date.format(DATE_FMT));
- row.put("sourceType", category.code);
- row.put("detailKind", "regular");
- row.put("category", category.code);
- row.put("itemName", category.label);
- row.put("weekday", weekdayCn(point.date));
- row.put("score", round2(point.score));
- row.put("deduction", deduction);
- row.put("delta", -deduction);
- row.put("count", point.count);
- row.put("traceable", true);
- row.put("sortTime", point.date.format(DATE_FMT));
- rows.add(row);
- }
- }
- rows.sort(Comparator.comparing(
- (Map<String, Object> row) -> String.valueOf(
- row.getOrDefault("sortTime", ""))).reversed());
- return rows;
- }
- private static List<Map<String, Object>> rdDayDetail(
- Db db, ClassInfo cls, LocalDate day, MonthPeriod period,
- CategoryDef category) throws Exception {
- CategoryDaily monthly = rdCategoryDaily(db, cls, day, period);
- String source = monthly.sources.getOrDefault(
- category.code, SOURCE_MISSING);
- List<Map<String, Object>> rows;
- if (SOURCE_REAL.equals(source)) {
- if ("attendance".equals(category.code))
- rows = rdAttendanceDetail(db, cls.bjid, day,
- XjbDormScoreU.AttendanceScope.DAY_STUDENT);
- else if ("dorm".equals(category.code))
- rows = rdItemDetail(db, cls.bjid, day, "dorm");
- else if ("flag".equals(category.code))
- rows = rdItemDetail(db, cls.bjid, day, "flag");
- else if ("cleaning".equals(category.code))
- rows = rdItemDetail(db, cls.bjid, day, "cleaning");
- else if ("classroom".equals(category.code))
- rows = rdKtjlDetail(db, cls.bjid, day);
- else if ("discipline".equals(category.code))
- rows = rdDisciplineDetail(db, cls.bjid, day);
- else
- rows = new ArrayList<>();
- } else {
- rows = new ArrayList<>();
- }
- rows.sort(Comparator.comparing(
- (Map<String, Object> row) -> String.valueOf(
- row.getOrDefault("sortTime", ""))).reversed());
- return rows;
- }
- private static List<Map<String, Object>> rdAttendanceDetail(
- Db db, long bjid, LocalDate day,
- XjbDormScoreU.AttendanceScope scope) throws Exception {
- Timestamp start = Timestamp.valueOf(day.atStartOfDay());
- Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select * from (select k.KQJLID,k.KQLBM,lb.MC KQLBMC,"
- + "k.RYID,ry.XM,k.MC,k.MS,k.KSSJ,bjcy.SFZS,"
- + "case k.KQLBM when 1 then 3 when 21 then 1"
- + " when 51 then 1 when 52 then 1 when 61 then 2"
- + " else 0 end PENALTY,"
- + "row_number() over(partition by NVL(k.RYID,-k.KQJLID)"
- + " order by case k.KQLBM when 1 then 3 when 21 then 1"
- + " when 51 then 1 when 52 then 1 when 61 then 2"
- + " else 0 end desc,k.KSSJ desc,k.KQJLID desc) RN"
- + " from KQJL k"
- + " inner join BJCY bjcy on bjcy.RYID=k.RYID"
- + " and bjcy.BJID=k.BJID and bjcy.SFBY=0"
- + " and bjcy." + ObjC.JLZT_useStr
- + " left join KQLB lb on lb.KQLBM=k.KQLBM"
- + " left join RY ry on ry.RYID=k.RYID"
- + " where k.BJID=:bjid and k.KSSJ>=:start"
- + " and k.KSSJ<:end and k.KQJLZTM=51 and k."
- + ObjC.JLZT_useStr
- + " and bjcy.SFZS=:sfzs"
- + " and k.KQLBM in(" + scope.codes + ")) where RN=1"
- + " order by KSSJ desc,KQJLID desc");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- sqlc.wrIntParm("sfzs", scope.sfzs);
- List<Map<String, Object>> result = new ArrayList<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- item.put("id", rdLong(row.get("kqjlid")));
- item.put("sourceId", rdLong(row.get("kqjlid")));
- item.put("category", "attendance");
- item.put("traceable", true);
- item.put("itemName", rdStr(row.get("kqlbmc")));
- item.put("studentType",
- scope == XjbDormScoreU.AttendanceScope.DAY_STUDENT
- ? "走读生" : "住校生");
- item.put("studentName", rdStr(row.get("xm")));
- item.put("title", rdStr(row.get("mc")));
- item.put("remark", rdStr(row.get("ms")));
- item.put("delta", -rdDouble(row.get("penalty")));
- item.put("scoreText", "");
- item.put("sortTime", formatTimestamp(row.get("kssj")));
- result.add(item);
- }
- return result;
- }
- private static List<Map<String, Object>> rdDisciplineDetail(
- Db db, long bjid, LocalDate day) throws Exception {
- Timestamp start = Timestamp.valueOf(day.atStartOfDay());
- Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select w.WJJLID,w.RYID,ry.XM,lb.WJLBM,lb.MC WJLBMC,"
- + "lb.BJKF,w.WJSJ,w.MS,w.WJLXM"
- + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
- + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
- + " and wm.YTM=" + XjbWjlbC.YTM_DISCIPLINE
- + " and wm.JLZTM=51"
- + " left join RY ry on ry.RYID=w.RYID"
- + " where w.BJID=:bjid and w.WJSJ>=:start"
- + " and w.WJSJ<:end and w.JLZTM=51"
- + " order by w.WJSJ,w.WJJLID");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- List<Map<String, Object>> result = new ArrayList<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- item.put("id", rdLong(row.get("wjjlid")));
- item.put("sourceId", rdLong(row.get("wjjlid")));
- item.put("category", "discipline");
- item.put("traceable", true);
- item.put("itemName", rdStr(row.get("wjlbmc")));
- item.put("studentName", rdStr(row.get("xm")));
- item.put("title", rdStr(row.get("wjlbmc")));
- item.put("remark", rdStr(row.get("ms")));
- item.put("delta", -rdDouble(row.get("bjkf")));
- item.put("scoreText", "");
- item.put("sortTime", formatTimestamp(row.get("wjsj")));
- result.add(item);
- }
- if (result.isEmpty())
- result.addAll(rdLegacyDisciplineDetail(db, bjid, day));
- return result;
- }
- private static List<Map<String, Object>> rdLegacyDisciplineDetail(
- Db db, long bjid, LocalDate day) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select XJB_FJRYID,WJRS,MS from XJB_FJRY"
- + " where BJID=:bjid and JCRQ=:jcrq and JLZTM=51");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("jcrq", Timestamp.valueOf(day.atStartOfDay()));
- List<Map<String, Object>> result = new ArrayList<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- boolean imported = isZhixinStarImport(rdStr(row.get("ms")));
- double count = imported
- ? rdDouble(row.get("wjrs")) / 10.0
- : rdInt(row.get("wjrs"));
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- item.put("id", rdLong(row.get("xjb_fjryid")));
- item.put("sourceId", rdLong(row.get("xjb_fjryid")));
- item.put("category", "discipline");
- item.put("traceable", true);
- item.put("itemName", imported ? "风纪仪容扣分" : "风纪仪容违纪");
- item.put("studentName", "");
- item.put("title", imported
- ? "风纪仪容扣分 " + plainNumber(count)
- : "风纪仪容违纪 " + (int) count + "人次");
- item.put("remark", imported ? "" : rdStr(row.get("ms")));
- item.put("delta", -count);
- item.put("scoreText",
- plainNumber(Math.max(0, 100 - count)) + "/100");
- item.put("sortTime", day.format(DATE_FMT));
- result.add(item);
- }
- return result;
- }
- private static List<Map<String, Object>> rdItemDetail(
- Db db, long bjid, LocalDate day, String category) throws Exception {
- Timestamp start = Timestamp.valueOf(day.atStartOfDay());
- Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
- String sql;
- if ("dorm".equals(category)) {
- sql = "select s.SSNWJCID ID,s.KFID,cd.MC KFMC,"
- + "m.SSNWJCXMM XMM,m.FS,x.MFZ,x.MC XMMC,s.JCSJ"
- + " from SSNWJC s inner join SSNWJCMX m"
- + " on m.SSNWJCID=s.SSNWJCID"
- + " inner join SSNWJCXM x on x.SSNWJCXMM=m.SSNWJCXMM"
- + " left join CD cd on cd.CDID=s.KFID"
- + " where s.BJID=:bjid and s.JCSJ>=:start"
- + " and s.JCSJ<:end and s." + ObjC.JLZT_useStr
- + " and m." + ObjC.JLZT_useStr
- + " and m.FS<x.MFZ"
- + " order by s.JCSJ desc,m.SSNWJCMXID";
- } else if ("flag".equals(category)) {
- sql = "select s.SQLJCID ID,m.SQLJCXMM XMM,m.FS,x.MFZ,"
- + "x.MC XMMC,s.JCSJ from SQLJC s"
- + " inner join SQLJCMX m on m.SQLJCID=s.SQLJCID"
- + " inner join SQLJCXM x on x.SQLJCXMM=m.SQLJCXMM"
- + " where s.BJID=:bjid and s.JCSJ>=:start"
- + " and s.JCSJ<:end and s." + ObjC.JLZT_useStr
- + " and m." + ObjC.JLZT_useStr
- + " and x.SQLJCXMM in(11,21,22,23,31)"
- + " and x.MFZ is not null and m.FS is not null"
- + " and m.FS<x.MFZ order by s.JCSJ desc,m.SQLJCMXID";
- } else if ("cleaning".equals(category)) {
- sql = "select s.CSWSJCID ID,m.CSWSJCXMM XMM,m.FS,x.MFZ,"
- + "x.MC XMMC,s.JCSJ from CSWSJC s"
- + " inner join CSWSJCMX m on m.CSWSJCID=s.CSWSJCID"
- + " inner join CSWSJCXM x on x.CSWSJCXMM=m.CSWSJCXMM"
- + " where s.BJID=:bjid and s.JCSJ>=:start"
- + " and s.JCSJ<:end and s." + ObjC.JLZT_useStr
- + " and m." + ObjC.JLZT_useStr
- + " and m.FS<x.MFZ order by s.JCSJ desc,m.CSWSJCMXID";
- } else {
- throw new IllegalArgumentException("明细类型参数错误");
- }
- SqlCmd sqlc = new SqlCmd(sql);
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- List<Map<String, Object>> result = new ArrayList<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- int score = rdInt(row.get("fs"));
- int maxScore = rdInt(row.get("mfz"));
- int rawDeducted = Math.max(0, maxScore - score);
- int code = rdInt(row.get("xmm"));
- double deducted = "flag".equals(category)
- ? round2(rawDeducted * flagWeightPct(code) / 100.0)
- : rawDeducted;
- if (deducted <= 0.0)
- continue;
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- item.put("id", rdLong(row.get("id")));
- item.put("sourceId", rdLong(row.get("id")));
- item.put("category", category);
- item.put("traceable", true);
- item.put("itemName", rdStr(row.get("xmmc")));
- item.put("studentName", "");
- item.put("roomName", rdStr(row.get("kfmc")));
- item.put("title", rdStr(row.get("xmmc")));
- item.put("remark", "得分 " + score + " / " + maxScore
- + ("flag".equals(category)
- ? ",折算扣 " + deducted : ""));
- item.put("deducted", deducted);
- item.put("rawDeducted", rawDeducted);
- item.put("delta", -deducted);
- item.put("scoreText", score + "/" + maxScore);
- item.put("sortTime", formatTimestamp(row.get("jcsj")));
- result.add(item);
- }
- if (result.isEmpty() && "cleaning".equals(category))
- result.addAll(rdImportedCleaningSummary(db, bjid, day));
- return result;
- }
- private static List<Map<String, Object>> rdFlagDaySummary(
- Db db, long bjid, LocalDate day) throws Exception {
- Map<String, Object> record = rdFlagRecord(db, bjid, day);
- if (record == null)
- return new ArrayList<>();
- if (isZhixinStarImport(rdStr(record.get("ms")))) {
- double score = flagRate(record.get("zfs"));
- List<Map<String, Object>> rows = new ArrayList<>();
- rows.add(flagSummaryRow(day, record, "aggregate", "升旗礼",
- round2(100.0 - score), score, false, ""));
- return rows;
- }
- double attendanceRate = flagRate(record.get("cql"));
- double queueScore = flagRate(record.get("dlfs"));
- double demeanorScore = flagRate(record.get("fmfs"));
- double disciplineScore = flagRate(record.get("jlfs"));
- List<Map<String, Object>> rows = new ArrayList<>();
- rows.add(flagSummaryRow(day, record, "attendance", "考勤",
- round2((100.0 - attendanceRate) * 0.25),
- attendanceRate, true, "flagAttendanceDetail"));
- rows.add(flagSummaryRow(day, record, "queue", "队列",
- round2((100.0 - queueScore) * 0.20),
- queueScore, false, ""));
- rows.add(flagSummaryRow(day, record, "demeanor", "风貌",
- round2((100.0 - demeanorScore) * 0.40),
- demeanorScore, true, "flagDemeanorDetail"));
- rows.add(flagSummaryRow(day, record, "discipline", "纪律",
- round2((100.0 - disciplineScore) * 0.15),
- disciplineScore, false, ""));
- return rows;
- }
- private static List<Map<String, Object>> rdFlagAttendanceDetail(
- Db db, long bjid, LocalDate day) throws Exception {
- Map<String, Object> record = rdFlagRecord(db, bjid, day);
- if (record == null)
- return new ArrayList<>();
- Map<Integer, Integer> values = rdFlagItemValues(
- db, rdLong(record.get("sqljcid")));
- String[] labels = {
- "总人数",
- "队列人数",
- "本部学生会值日人数",
- "学校学生会值日人数",
- "国旗队人数",
- "公假人数",
- "参与宿管人数",
- "升旗礼前请假人数"
- };
- List<Map<String, Object>> rows = new ArrayList<>();
- for (int i = 0; i < labels.length; i++) {
- int code = i + 1;
- int value = values.getOrDefault(code, 0);
- rows.add(flagValueRow(day, labels[i], value, String.valueOf(value)));
- }
- double attendanceRate = flagRate(record.get("cql"));
- double attendanceScore = flagRate(record.get("kqfs"));
- rows.add(flagValueRow(day, "出勤率", attendanceRate,
- plainNumber(attendanceRate) + "%"));
- rows.add(flagValueRow(day, "考勤分", attendanceScore,
- plainNumber(attendanceScore)));
- return rows;
- }
- private static List<Map<String, Object>> rdFlagDemeanorDetail(
- Db db, long bjid, LocalDate day) throws Exception {
- Map<String, Object> record = rdFlagRecord(db, bjid, day);
- if (record == null)
- return new ArrayList<>();
- Map<Integer, Integer> values = rdFlagItemValues(
- db, rdLong(record.get("sqljcid")));
- List<Map<String, Object>> rows = new ArrayList<>();
- rows.add(flagValueRow(day, "国歌",
- values.getOrDefault(21, 0),
- String.valueOf(values.getOrDefault(21, 0))));
- rows.add(flagValueRow(day, "校歌",
- values.getOrDefault(22, 0),
- String.valueOf(values.getOrDefault(22, 0))));
- rows.add(flagValueRow(day, "服装",
- values.getOrDefault(23, 0),
- String.valueOf(values.getOrDefault(23, 0))));
- return rows;
- }
- private static Map<String, Object> rdFlagRecord(
- Db db, long bjid, LocalDate day) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select SQLJCID,CQL,KQFS,DLFS,FMFS,JLFS,ZFS,JCSJ,MS"
- + " from SQLJC where BJID=:bjid"
- + " and trunc(JCSJ)=to_date(:day,'YYYY-MM-DD')"
- + " and JLZTM in(22,25,51)"
- + " order by SQLJCID desc");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrStrParm("day", day.format(DATE_FMT));
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- return rows == null || rows.isEmpty() ? null : rows.get(0);
- }
- private static Map<Integer, Integer> rdFlagItemValues(
- Db db, long sqljcid) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select SQLJCXMM,FS from SQLJCMX where SQLJCID=:sqljcid"
- + " and JLZTM=51 and SQLJCXMM in(1,2,3,4,5,6,7,8,"
- + "21,22,23)");
- sqlc.wrLongParm("sqljcid", sqljcid);
- Map<Integer, Integer> result = new HashMap<>();
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- if (rows == null)
- return result;
- for (Map<String, Object> row : rows)
- result.put(rdInt(row.get("sqljcxmm")), rdInt(row.get("fs")));
- return result;
- }
- private static Map<String, Object> flagSummaryRow(
- LocalDate day, Map<String, Object> record, String code,
- String name, double deduction, double rawScore,
- boolean traceable, String detailMode) {
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- item.put("id", rdLong(record.get("sqljcid")));
- item.put("sourceId", rdLong(record.get("sqljcid")));
- item.put("category", "flag");
- item.put("code", code);
- item.put("itemName", name);
- item.put("title", name);
- item.put("deduction", deduction);
- item.put("delta", -deduction);
- item.put("rawScore", round2(rawScore));
- item.put("traceable", traceable);
- item.put("detailMode", detailMode);
- item.put("sortTime", formatTimestamp(record.get("jcsj")));
- return item;
- }
- private static Map<String, Object> flagValueRow(
- LocalDate day, String name, double value, String displayValue) {
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- item.put("itemName", name);
- item.put("title", name);
- item.put("value", round2(value));
- item.put("displayValue", displayValue);
- item.put("traceable", false);
- item.put("sortTime", day.format(DATE_FMT));
- return item;
- }
- private static double flagRate(Object value) {
- return Math.max(0.0, Math.min(100.0, rdDouble(value)));
- }
- private static String plainNumber(double value) {
- String text = String.format(Locale.CHINA, "%.2f", round2(value));
- return text.replaceAll("0+$", "").replaceAll("\\.$", "");
- }
- private static List<Map<String, Object>> rdKtjlDetail(
- Db db, long bjid, LocalDate day) throws Exception {
- Timestamp start = Timestamp.valueOf(day.atStartOfDay());
- Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select j.KTJLID,j.FS,j.MS,j.MSWJ,j.JLSJ,k.KSSJ,"
- + "k.KCBID,nvl(kc.MC,k.MC) KCM,ry.XM JLRYXM"
- + " from KTJL j"
- + " inner join KCB k on k.KCBID=j.KCBID"
- + " left join KC kc on kc.KCID=k.KCID"
- + " left join RY ry on ry.RYID=j.JLRYID"
- + " where j.BJID=:bjid and k.KSSJ>=:start"
- + " and k.KSSJ<:end and j." + ObjC.JLZT_useStr
- + " and k." + ObjC.JLZT_useStr
- + " order by k.KSSJ desc,j.KTJLID desc");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- List<Map<String, Object>> result = new ArrayList<>();
- List<Map<String, Object>> rows;
- try {
- rows = db.doSelMapListByC(sqlc);
- } catch (SQLException e) {
- if (isMissingTable(e, "KTJL"))
- return result;
- throw e;
- }
- if (rows == null)
- return result;
- for (Map<String, Object> row : rows) {
- int score = rdInt(row.get("fs"));
- if (score >= 100)
- continue;
- Map<String, Object> item = baseDetail(day, SOURCE_REAL);
- long id = rdLong(row.get("ktjlid"));
- item.put("id", id);
- item.put("sourceId", id);
- item.put("category", "classroom");
- item.put("traceable", true);
- item.put("itemName", "课堂考核");
- item.put("studentName", "");
- item.put("title", rdStr(row.get("kcm")));
- item.put("remark", defaultText(row.get("ms"),
- defaultText(row.get("mswj"), "课堂考核扣分")));
- item.put("delta", -(100 - score));
- item.put("scoreText", score + "/100");
- item.put("sortTime", formatTimestamp(row.get("kssj")));
- result.add(item);
- }
- return result;
- }
- private static Map<String, Object> rdTraceDetail(Db db, ClassInfo cls,
- LocalDate day,
- CategoryDef category,
- long sourceId,
- String source)
- throws Exception {
- if (!SOURCE_REAL.equals(source))
- throw new IllegalArgumentException("扣分来源参数错误");
- if ("attendance".equals(category.code))
- return rdAttendanceTrace(db, cls, day, category, sourceId);
- if ("dorm".equals(category.code))
- return rdCheckTrace(db, cls, day, category, sourceId, "dorm");
- if ("flag".equals(category.code))
- return rdCheckTrace(db, cls, day, category, sourceId, "flag");
- if ("cleaning".equals(category.code))
- return rdCheckTrace(db, cls, day, category, sourceId, "cleaning");
- if ("classroom".equals(category.code))
- return rdKtjlTrace(db, cls, day, category, sourceId);
- if ("discipline".equals(category.code))
- return rdDisciplineTrace(db, cls, day, category, sourceId);
- throw new IllegalArgumentException("评分项目暂无可追踪明细");
- }
- private static Map<String, Object> rdDisciplineTrace(
- Db db, ClassInfo cls, LocalDate day,
- CategoryDef category, long sourceId) throws Exception {
- SqlCmd current = new SqlCmd(
- "select w.WJJLID,w.WJSJ,w.MS,w.WJLBM,lb.MC WJLBMC,"
- + "lb.BJKF,ry.XM RYXM,cj.XM CJRYXM"
- + " from WJJL w inner join WJLB lb on lb.WJLBM=w.WJLBM"
- + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
- + " and wm.YTM=" + XjbWjlbC.YTM_DISCIPLINE
- + " and wm.JLZTM=51"
- + " left join RY ry on ry.RYID=w.RYID"
- + " left join RY cj on cj.RYID=w.CJRYID"
- + " where w.WJJLID=:id and w.BJID=:bjid"
- + " and w.JLZTM=51");
- current.wrLongParm("id", sourceId);
- current.wrLongParm("bjid", cls.bjid);
- List<Map<String, Object>> currentRows =
- db.doSelMapListByC(current);
- if (currentRows != null && !currentRows.isEmpty()) {
- Map<String, Object> row = currentRows.get(0);
- double deducted = rdDouble(row.get("bjkf"));
- Map<String, Object> record = new LinkedHashMap<>();
- record.put("time", formatTimestamp(row.get("wjsj")));
- record.put("className", cls.bjmc);
- record.put("inspectorName", rdStr(row.get("cjryxm")));
- record.put("studentName", rdStr(row.get("ryxm")));
- record.put("description", rdStr(row.get("ms")));
- List<Map<String, Object>> items = new ArrayList<>();
- Map<String, Object> item = new LinkedHashMap<>();
- item.put("itemName", rdStr(row.get("wjlbmc")));
- item.put("deducted", deducted);
- item.put("remark", rdStr(row.get("ms")));
- items.add(item);
- return traceResult(cls, day, category, SOURCE_REAL,
- "风纪仪容扣分详情", record, items, "");
- }
- return rdLegacyDisciplineTrace(db, cls, day, category, sourceId);
- }
- private static Map<String, Object> rdLegacyDisciplineTrace(
- Db db, ClassInfo cls, LocalDate day,
- CategoryDef category, long sourceId) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select XJB_FJRYID,JCRQ,WJRS,MS from XJB_FJRY"
- + " where XJB_FJRYID=:id and BJID=:bjid and JLZTM=51");
- sqlc.wrLongParm("id", sourceId);
- sqlc.wrLongParm("bjid", cls.bjid);
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- if (rows == null || rows.isEmpty())
- throw new IllegalArgumentException("风纪仪容记录不存在或已不可查看");
- Map<String, Object> row = rows.get(0);
- int violations = rdInt(row.get("wjrs"));
- Map<String, Object> record = new LinkedHashMap<>();
- record.put("time", day.format(DATE_FMT));
- record.put("className", cls.bjmc);
- record.put("inspectorName", "风纪检查");
- record.put("violationCount", violations);
- record.put("description", rdStr(row.get("ms")));
- List<Map<String, Object>> items = new ArrayList<>();
- if (violations > 0) {
- Map<String, Object> item = new LinkedHashMap<>();
- item.put("itemName", "风纪仪容违纪");
- item.put("deducted", violations);
- item.put("remark", "违纪" + violations + "人次,每人次扣1分");
- items.add(item);
- }
- return traceResult(cls, day, category, SOURCE_REAL,
- "风纪仪容扣分详情", record, items,
- violations == 0 ? "当日无风纪仪容扣分" : "");
- }
- private static Map<String, Object> rdCheckTrace(Db db, ClassInfo cls,
- LocalDate day,
- CategoryDef category,
- long sourceId,
- String type)
- throws Exception {
- String mainSql;
- String itemSql;
- if ("dorm".equals(type)) {
- mainSql = "select s.SSNWJCID ID,s.JCSJ,s.FS,s.MS,s.KFID,"
- + "cd.MC KFMC,b.MC BJMC,jc.XM JCRYXM from SSNWJC s"
- + " left join CD cd on cd.CDID=s.KFID"
- + " left join BJ b on b.BJID=s.BJID"
- + " left join RY jc on jc.RYID=s.JCRYID"
- + " where s.SSNWJCID=:id and s.BJID=:bjid and s."
- + ObjC.JLZT_useStr;
- itemSql = "select x.SSNWJCXMM CODE,x.MC ITEM_NAME,"
- + "m.FS CURRENT_SCORE,x.MFZ MAX_SCORE"
- + " from SSNWJCMX m inner join SSNWJCXM x"
- + " on x.SSNWJCXMM=m.SSNWJCXMM"
- + " where m.SSNWJCID=:id and m." + ObjC.JLZT_useStr
- + " order by x.SSNWJCXMM";
- } else if ("flag".equals(type)) {
- mainSql = "select s.SQLJCID ID,s.JCSJ,s.ZFS FS,s.MS,s.BMID,"
- + "bm.MC BMMC,b.MC BJMC,jc.XM JCRYXM from SQLJC s"
- + " left join BM bm on bm.BMID=s.BMID"
- + " left join BJ b on b.BJID=s.BJID"
- + " left join RY jc on jc.RYID=s.JCRYID"
- + " where s.SQLJCID=:id and s.BJID=:bjid and s."
- + ObjC.JLZT_useStr;
- itemSql = "select x.SQLJCXMM CODE,x.MC ITEM_NAME,"
- + "m.FS CURRENT_SCORE,x.MFZ MAX_SCORE"
- + " from SQLJCMX m inner join SQLJCXM x"
- + " on x.SQLJCXMM=m.SQLJCXMM"
- + " where m.SQLJCID=:id and m." + ObjC.JLZT_useStr
- + " and x.SQLJCXMM in(11,21,22,23,31)"
- + " order by x.SQLJCXMM";
- } else {
- mainSql = "select s.CSWSJCID ID,s.JCSJ,s.FS,s.MS,"
- + "b.MC BJMC,jc.XM JCRYXM from CSWSJC s"
- + " left join BJ b on b.BJID=s.BJID"
- + " left join RY jc on jc.RYID=s.JCRYID"
- + " where s.CSWSJCID=:id and s.BJID=:bjid and s."
- + ObjC.JLZT_useStr;
- itemSql = "select x.MC ITEM_NAME,m.FS CURRENT_SCORE,x.MFZ MAX_SCORE"
- + " from CSWSJCMX m inner join CSWSJCXM x"
- + " on x.CSWSJCXMM=m.CSWSJCXMM"
- + " where m.CSWSJCID=:id and m." + ObjC.JLZT_useStr
- + " order by x.CSWSJCXMM";
- }
- SqlCmd mainCmd = new SqlCmd(mainSql);
- mainCmd.wrLongParm("id", sourceId);
- mainCmd.wrLongParm("bjid", cls.bjid);
- List<Map<String, Object>> mainRows = db.doSelMapListByC(mainCmd);
- if (mainRows == null || mainRows.isEmpty())
- throw new IllegalArgumentException("扣分记录不存在或已不可查看");
- Map<String, Object> main = mainRows.get(0);
- SqlCmd itemCmd = new SqlCmd(itemSql);
- itemCmd.wrLongParm("id", sourceId);
- List<Map<String, Object>> itemRows = db.doSelMapListByC(itemCmd);
- if (itemRows == null)
- itemRows = new ArrayList<>();
- List<Map<String, Object>> items = new ArrayList<>();
- for (Map<String, Object> row : itemRows) {
- int current = rdInt(row.get("current_score"));
- int max = rdInt(row.get("max_score"));
- int rawDeducted = Math.max(0, max - current);
- double deducted = "flag".equals(type)
- ? round2(rawDeducted
- * flagWeightPct(rdInt(row.get("code"))) / 100.0)
- : rawDeducted;
- if (deducted <= 0.0)
- continue;
- Map<String, Object> item = new LinkedHashMap<>();
- item.put("itemName", rdStr(row.get("item_name")));
- item.put("currentScore", current);
- item.put("maxScore", max);
- item.put("deducted", deducted);
- item.put("rawDeducted", rawDeducted);
- item.put("remark", "得分 " + current + " / " + max
- + ("flag".equals(type)
- ? ",折算扣 " + deducted : ""));
- items.add(item);
- }
- Map<String, Object> record = new LinkedHashMap<>();
- record.put("time", formatTimestamp(main.get("jcsj")));
- record.put("className", defaultText(main.get("bjmc"), cls.bjmc));
- record.put("roomName", defaultText(main.get("kfmc"), ""));
- record.put("departmentName", defaultText(main.get("bmmc"), ""));
- record.put("inspectorName", defaultText(main.get("jcryxm"), "未记录"));
- record.put("totalScore", rdDouble(main.get("fs")));
- record.put("description", defaultText(main.get("ms"), ""));
- return traceResult(cls, day, category, SOURCE_REAL,
- category.label + "扣分详情", record, items, "");
- }
- private static Map<String, Object> rdAttendanceTrace(Db db, ClassInfo cls,
- LocalDate day,
- CategoryDef category,
- long sourceId)
- throws Exception {
- SqlCmd cmd = new SqlCmd(
- "select k.KQJLID,k.KQLBM,lb.MC KQLBMC,k.RYID,ry.XM,"
- + "k.MC,k.MS,k.KSSJ,k.JSSJ,k.BJID,b.MC BJMC"
- + " from KQJL k left join KQLB lb on lb.KQLBM=k.KQLBM"
- + " left join RY ry on ry.RYID=k.RYID"
- + " left join BJ b on b.BJID=k.BJID"
- + " where k.KQJLID=:id and k.BJID=:bjid"
- + " and k.KQJLZTM=51 and k." + ObjC.JLZT_useStr);
- cmd.wrLongParm("id", sourceId);
- cmd.wrLongParm("bjid", cls.bjid);
- List<Map<String, Object>> rows = db.doSelMapListByC(cmd);
- if (rows == null || rows.isEmpty())
- throw new IllegalArgumentException("考勤扣分记录不存在或已不可查看");
- Map<String, Object> main = rows.get(0);
- int kqlbm = rdInt(main.get("kqlbm"));
- double deducted = attendancePenalty(kqlbm);
- Map<String, Object> record = new LinkedHashMap<>();
- record.put("time", formatTimestamp(main.get("kssj")));
- record.put("className", defaultText(main.get("bjmc"), cls.bjmc));
- record.put("studentName", defaultText(main.get("xm"), ""));
- record.put("inspectorName", "考勤系统");
- record.put("description", defaultText(main.get("ms"), ""));
- record.put("period", formatTimestamp(main.get("kssj")) + " - "
- + formatTimestamp(main.get("jssj")));
- List<Map<String, Object>> items = new ArrayList<>();
- Map<String, Object> item = new LinkedHashMap<>();
- item.put("itemName", defaultText(main.get("kqlbmc"), "考勤异常"));
- item.put("deducted", deducted);
- item.put("remark", defaultText(main.get("mc"), ""));
- items.add(item);
- return traceResult(cls, day, category, SOURCE_REAL,
- category.label + "扣分详情", record, items, "");
- }
- private static Map<String, Object> rdKtjlTrace(
- Db db, ClassInfo cls, LocalDate day,
- CategoryDef category, long sourceId) throws Exception {
- Timestamp start = Timestamp.valueOf(day.atStartOfDay());
- Timestamp end = Timestamp.valueOf(day.plusDays(1).atStartOfDay());
- SqlCmd mainCmd = new SqlCmd(
- "select j.KTJLID,j.FS,j.MS,j.MSWJ,j.FJID,j.JLSJ,"
- + "k.KSSJ,nvl(kc.MC,k.MC) KCM,b.MC BJMC,ry.XM JLRYXM"
- + " from KTJL j"
- + " inner join KCB k on k.KCBID=j.KCBID"
- + " left join KC kc on kc.KCID=k.KCID"
- + " left join BJ b on b.BJID=j.BJID"
- + " left join RY ry on ry.RYID=j.JLRYID"
- + " where j.KTJLID=:id and j.BJID=:bjid"
- + " and k.KSSJ>=:start and k.KSSJ<:end"
- + " and j." + ObjC.JLZT_useStr
- + " and k." + ObjC.JLZT_useStr);
- mainCmd.wrLongParm("id", sourceId);
- mainCmd.wrLongParm("bjid", cls.bjid);
- mainCmd.wrTimeParm("start", start);
- mainCmd.wrTimeParm("end", end);
- List<Map<String, Object>> mainRows = db.doSelMapListByC(mainCmd);
- if (mainRows == null || mainRows.isEmpty())
- throw new IllegalArgumentException("课堂考核记录不存在或已不可查看");
- Map<String, Object> main = mainRows.get(0);
- SqlCmd itemCmd = new SqlCmd(
- "select x.KTJLXMM,x.MC ITEM_NAME,x.MFZ MAX_SCORE,m.FS"
- + " from KTJLMX m inner join KTJLXM x"
- + " on x.KTJLXMM=m.KTJLXMM"
- + " where m.KTJLID=:id and m." + ObjC.JLZT_useStr
- + " order by x.KTJLXMM");
- itemCmd.wrLongParm("id", sourceId);
- List<Map<String, Object>> itemRows = db.doSelMapListByC(itemCmd);
- if (itemRows == null)
- itemRows = new ArrayList<>();
- List<Map<String, Object>> items = new ArrayList<>();
- for (Map<String, Object> row : itemRows) {
- int current = rdInt(row.get("fs"));
- int max = rdInt(row.get("max_score"));
- int deducted = Math.max(0, max - current);
- if (deducted == 0)
- continue;
- Map<String, Object> item = new LinkedHashMap<>();
- item.put("itemName", rdStr(row.get("item_name")));
- item.put("currentScore", current);
- item.put("maxScore", max);
- item.put("deducted", deducted);
- item.put("remark", "得分 " + current + " / " + max);
- items.add(item);
- }
- Map<String, Object> record = new LinkedHashMap<>();
- record.put("time", formatTimestamp(main.get("kssj")));
- record.put("className", defaultText(main.get("bjmc"), cls.bjmc));
- record.put("courseName", defaultText(main.get("kcm"), ""));
- record.put("inspectorName", defaultText(main.get("jlryxm"), "未记录"));
- record.put("totalScore", rdDouble(main.get("fs")));
- record.put("description", defaultText(main.get("mswj"),
- defaultText(main.get("ms"), "")));
- record.put("attachmentId", main.get("fjid"));
- return traceResult(cls, day, category, SOURCE_REAL,
- category.label + "扣分详情", record, items, "");
- }
- private static Map<String, Object> rdAdjustmentTrace(
- Db db, ClassInfo cls, long ledgerId, YearMonth reportMonth)
- throws Exception {
- SqlCmd ledgerCmd = new SqlCmd(
- "select j.XJB_JFJLID,j.NDY,j.FSSJ,j.JFLX,j.JFZ,j.MC,j.MS,"
- + "j.LYLX,j.LYID,j.LYLB,j.RYID,r.XM RYXM"
- + " from XJB_JFJL j left join RY r on r.RYID=j.RYID"
- + " where j.XJB_JFJLID=:id and j.BJID=:bjid"
- + " and j.JLZTM=51");
- ledgerCmd.wrLongParm("id", ledgerId);
- ledgerCmd.wrLongParm("bjid", cls.bjid);
- List<Map<String, Object>> ledgerRows =
- db.doSelMapListByC(ledgerCmd);
- if (ledgerRows == null || ledgerRows.isEmpty())
- throw new IllegalArgumentException("增扣分记录不存在或已不可查看");
- Map<String, Object> ledger = ledgerRows.get(0);
- if (reportMonth != null) {
- YearMonth ledgerMonth = YearMonth.parse(
- rdStr(ledger.get("ndy")), MONTH_FMT);
- ensureReportMonth(reportMonth, ledgerMonth);
- }
- String sourceType = defaultText(ledger.get("lylx"), "");
- long sourceId = rdLong(ledger.get("lyid"));
- if (XjbJfServ.LYLX_AWARD.equals(sourceType))
- return rdAwardAdjustmentTrace(db, cls, ledger, sourceId);
- if (XjbJfServ.LYLX_SCHOOL_VIOLATION.equals(sourceType))
- return rdViolationAdjustmentTrace(db, cls, ledger, sourceId);
- if (XjbJfServ.LYLX_TEAM_ROLE.equals(sourceType)
- || XjbJfServ.LYLX_TEAM_MEMBER.equals(sourceType))
- return rdTeamAdjustmentTrace(db, cls, ledger, sourceType,
- sourceId);
- if (XjbJfServ.LYLX_MONTH_SAFE.equals(sourceType)
- || XjbJfServ.LYLX_FJ_SAFE.equals(sourceType))
- return rdRuleAdjustmentTrace(cls, ledger, sourceType);
- return rdLedgerOnlyTrace(cls, ledger, sourceType);
- }
- private static Map<String, Object> rdAwardAdjustmentTrace(
- Db db, ClassInfo cls, Map<String, Object> ledger, long sourceId)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select h.HJJLID,h.HJXZ,h.HJRQ,h.MS,h.MC,h.HJLBM,"
- + "l.MC LBMC,l.BJJF,l.JTBJJF,r.XM RYXM"
- + " from HJJL h inner join HJLB l on l.HJLBM=h.HJLBM"
- + " left join RY r on r.RYID=h.RYID"
- + " where h.HJJLID=:id and h.JLZTM=51");
- sqlc.wrLongParm("id", sourceId);
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- if (rows == null || rows.isEmpty())
- return rdLedgerOnlyTrace(cls, ledger,
- XjbJfServ.LYLX_AWARD);
- Map<String, Object> row = rows.get(0);
- int awardType = rdInt(row.get("hjxz"));
- String awardTypeText = awardType == 2 ? "集体获奖" : "个人获奖";
- Map<String, Object> record = adjustmentRecord(cls, ledger,
- "学校获奖", row.get("ryxm"));
- record.put("awardNature", awardTypeText);
- record.put("awardCategory", rdStr(row.get("lbmc")));
- record.put("description", defaultText(row.get("ms"),
- defaultText(row.get("mc"), "")));
- List<Map<String, Object>> items = new ArrayList<>();
- if (awardType == 2) {
- SqlCmd memberCmd = new SqlCmd(
- "select c.RYID,r.XM,b.MC BJMC from HJJLCY c"
- + " left join RY r on r.RYID=c.RYID"
- + " left join BJ b on b.BJID=c.BJID"
- + " where c.HJJLID=:id and c.JLZTM=51"
- + " order by c.BJID,c.RYID");
- memberCmd.wrLongParm("id", sourceId);
- List<Map<String, Object>> members =
- db.doSelMapListByC(memberCmd);
- for (Map<String, Object> member : members) {
- Map<String, Object> item = new LinkedHashMap<>();
- item.put("itemName", "参与学生");
- item.put("studentName", defaultText(member.get("xm"), ""));
- item.put("className", defaultText(member.get("bjmc"), ""));
- item.put("remark", "集体获奖参与学生");
- items.add(item);
- }
- }
- Map<String, Object> main = adjustmentItem(ledger,
- defaultText(row.get("lbmc"), awardTypeText),
- defaultText(row.get("ms"), ""));
- items.add(0, main);
- return adjustmentTraceResult(cls, ledger, sourceId,
- XjbJfServ.LYLX_AWARD, awardTypeText + "增分详情",
- record, items, "");
- }
- private static Map<String, Object> rdViolationAdjustmentTrace(
- Db db, ClassInfo cls, Map<String, Object> ledger, long sourceId)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select w.WJJLID,w.WJSJ,w.MS,w.WJLBM,lb.MC WJLBMC,"
- + "lb.BJKF,ry.XM RYXM,cj.XM CJRYXM"
- + " from WJJL w left join WJLB lb on lb.WJLBM=w.WJLBM"
- + " left join RY ry on ry.RYID=w.RYID"
- + " left join RY cj on cj.RYID=w.CJRYID"
- + " where w.WJJLID=:id and w.JLZTM=51");
- sqlc.wrLongParm("id", sourceId);
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- if (rows == null || rows.isEmpty())
- return rdLedgerOnlyTrace(cls, ledger,
- XjbJfServ.LYLX_SCHOOL_VIOLATION);
- Map<String, Object> row = rows.get(0);
- Map<String, Object> record = adjustmentRecord(cls, ledger,
- "学校违纪", row.get("ryxm"));
- record.put("eventTime", formatTimestamp(row.get("wjsj")));
- record.put("inspectorName",
- defaultText(row.get("cjryxm"), "未记录"));
- record.put("businessCategory", rdStr(row.get("wjlbmc")));
- record.put("description", defaultText(row.get("ms"), ""));
- List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
- defaultText(row.get("wjlbmc"), "学校违纪"),
- defaultText(row.get("ms"), "")));
- return adjustmentTraceResult(cls, ledger, sourceId,
- XjbJfServ.LYLX_SCHOOL_VIOLATION,
- "学校违纪减分详情", record, items, "");
- }
- private static Map<String, Object> rdTeamAdjustmentTrace(
- Db db, ClassInfo cls, Map<String, Object> ledger,
- String sourceType, long sourceId) throws Exception {
- String sql;
- if (XjbJfServ.LYLX_TEAM_ROLE.equals(sourceType)) {
- sql = "select w.TTWCYID ID,w.RYID,w.TTWCYLBM,"
- + "t.MC TTMC,wc.MC ROLEMC,wc.BJJF,ry.XM RYXM"
- + " from TTWCY w inner join TT t on t.TTID=w.TTID"
- + " inner join TTWCYLB wc on wc.TTWCYLBM=w.TTWCYLBM"
- + " left join RY ry on ry.RYID=w.RYID"
- + " where w.TTWCYID=:id and w.JLZTM=51";
- } else {
- sql = "select c.TTCYID ID,c.RYID,wc.TTWCYLBM,"
- + "t.MC TTMC,wc.MC ROLEMC,wc.BJJF,ry.XM RYXM"
- + " from TTCY c inner join TT t on t.TTID=c.TTID"
- + " inner join TTWCYLB wc on wc.TTLBM=t.TTLBM"
- + " and wc.TTWCYLBM=(select min(wc2.TTWCYLBM)"
- + " from TTWCYLB wc2 where wc2.TTLBM=t.TTLBM"
- + " and wc2.MC='成员')"
- + " left join RY ry on ry.RYID=c.RYID"
- + " where c.TTCYID=:id and c.JLZTM=51";
- }
- SqlCmd sqlc = new SqlCmd(sql);
- sqlc.wrLongParm("id", sourceId);
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- if (rows == null || rows.isEmpty())
- return rdLedgerOnlyTrace(cls, ledger, sourceType);
- Map<String, Object> row = rows.get(0);
- Map<String, Object> record = adjustmentRecord(cls, ledger,
- "团体成员增分", row.get("ryxm"));
- record.put("teamName", rdStr(row.get("ttmc")));
- record.put("roleName", rdStr(row.get("rolemc")));
- record.put("description", defaultText(ledger.get("ms"), ""));
- List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
- defaultText(row.get("ttmc"), "")
- + "·" + defaultText(row.get("rolemc"), ""),
- defaultText(ledger.get("ms"), "")));
- return adjustmentTraceResult(cls, ledger, sourceId, sourceType,
- "团体成员增分详情", record, items, "");
- }
- private static Map<String, Object> rdRuleAdjustmentTrace(
- ClassInfo cls, Map<String, Object> ledger, String sourceType) {
- Map<String, Object> record = adjustmentRecord(cls, ledger,
- "星级班规则增分", null);
- record.put("ruleName",
- XjbJfServ.LYLX_MONTH_SAFE.equals(sourceType)
- ? "当月无学生处分" : "当月无风纪扣分");
- record.put("description", defaultText(ledger.get("ms"), ""));
- List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
- defaultText(ledger.get("mc"),
- String.valueOf(record.get("ruleName"))),
- defaultText(ledger.get("ms"), "")));
- return adjustmentTraceResult(cls, ledger, rdLong(ledger.get("lyid")),
- sourceType, "星级班规则增分详情", record, items,
- "该记录由月度规则自动生成,无其他原始业务单据");
- }
- private static Map<String, Object> rdLedgerOnlyTrace(
- ClassInfo cls, Map<String, Object> ledger, String sourceType) {
- Map<String, Object> record = adjustmentRecord(cls, ledger,
- adjustmentSourceLabel(sourceType), null);
- record.put("description", defaultText(ledger.get("ms"), ""));
- List<Map<String, Object>> items = List.of(adjustmentItem(ledger,
- defaultText(ledger.get("mc"), "星级班增扣分"),
- defaultText(ledger.get("ms"), "")));
- return adjustmentTraceResult(cls, ledger, rdLong(ledger.get("lyid")),
- sourceType, "星级班增扣分详情", record, items,
- "原业务记录已不可查看,以下内容来自星级班增扣分账本");
- }
- private static Map<String, Object> adjustmentRecord(
- ClassInfo cls, Map<String, Object> ledger, String businessType,
- Object studentName) {
- Map<String, Object> record = new LinkedHashMap<>();
- record.put("time", formatTimestamp(ledger.get("fssj")));
- record.put("className", cls.bjmc);
- record.put("studentName",
- defaultText(studentName, defaultText(ledger.get("ryxm"), "")));
- record.put("businessType", businessType);
- record.put("ledgerId", rdLong(ledger.get("xjb_jfjlid")));
- record.put("score", signedAdjustmentScore(ledger));
- return record;
- }
- private static Map<String, Object> adjustmentItem(
- Map<String, Object> ledger, String itemName, String remark) {
- Map<String, Object> item = new LinkedHashMap<>();
- item.put("itemName", itemName);
- item.put("delta", signedAdjustmentScore(ledger));
- item.put("remark", remark);
- return item;
- }
- private static Map<String, Object> adjustmentTraceResult(
- ClassInfo cls, Map<String, Object> ledger, long sourceId,
- String sourceType, String title, Map<String, Object> record,
- List<Map<String, Object>> items, String notice) {
- Map<String, Object> data = new LinkedHashMap<>();
- data.put("bjid", cls.bjid);
- data.put("bjmc", cls.bjmc);
- data.put("kind", "adjustment");
- data.put("ledgerId", rdLong(ledger.get("xjb_jfjlid")));
- data.put("sourceType", sourceType);
- data.put("sourceId", sourceId);
- data.put("title", title);
- data.put("record", record);
- data.put("items", items);
- data.put("notice", notice);
- return data;
- }
- private static double signedAdjustmentScore(Map<String, Object> ledger) {
- double points = Math.abs(rdDouble(ledger.get("jfz")));
- return rdInt(ledger.get("jflx"))
- == XjbJfServ.JFLX_ADD ? points : -points;
- }
- private static String adjustmentSourceLabel(String sourceType) {
- if (XjbJfServ.LYLX_AWARD.equals(sourceType))
- return "学校获奖";
- if (XjbJfServ.LYLX_SCHOOL_VIOLATION.equals(sourceType))
- return "学校违纪";
- if (XjbJfServ.LYLX_TEAM_ROLE.equals(sourceType))
- return "团体职务";
- if (XjbJfServ.LYLX_TEAM_MEMBER.equals(sourceType))
- return "团体成员";
- if (XjbJfServ.LYLX_MONTH_SAFE.equals(sourceType))
- return "当月无学生处分";
- if (XjbJfServ.LYLX_FJ_SAFE.equals(sourceType))
- return "当月无风纪扣分";
- return StringUtils.defaultIfBlank(sourceType, "星级班增扣分");
- }
- private static Map<String, Object> traceResult(
- ClassInfo cls, LocalDate day, CategoryDef category, String source,
- String title, Map<String, Object> record,
- List<Map<String, Object>> items, String notice) {
- Map<String, Object> data = new LinkedHashMap<>();
- data.put("bjid", cls.bjid);
- data.put("bjmc", cls.bjmc);
- data.put("date", day.format(DATE_FMT));
- data.put("category", category.code);
- data.put("categoryLabel", category.label);
- data.put("source", source);
- data.put("title", title);
- data.put("record", record);
- data.put("items", items);
- data.put("notice", notice);
- return data;
- }
- private static String defaultText(Object value, String defaultValue) {
- String text = rdStr(value);
- return StringUtils.isBlank(text) ? defaultValue : text;
- }
- private static int flagWeightPct(int code) {
- if (code == 11)
- return 20;
- if (code == 21 || code == 22 || code == 23)
- return 40;
- if (code == 31)
- return 15;
- return 0;
- }
- private static List<Map<String, Object>> rdAdjustmentRows(
- List<Adjustment> adjustments) {
- List<Map<String, Object>> rows = new ArrayList<>();
- for (Adjustment item : adjustments) {
- Map<String, Object> row = baseDetail(item.date, SOURCE_REAL);
- row.put("id", item.id);
- row.put("ledgerId", item.id);
- row.put("sourceId", item.sourceRecordId);
- row.put("sourceType", item.sourceType);
- row.put("detailKind", "adjustment");
- row.put("traceable", true);
- row.put("itemName", item.itemName);
- row.put("studentName", item.studentName);
- row.put("title", item.itemName);
- row.put("remark", item.remark);
- row.put("delta", item.score);
- row.put("scoreText", "");
- row.put("sortTime", item.date.format(DATE_FMT));
- rows.add(row);
- }
- return rows;
- }
- private static Map<String, Object> baseDetail(LocalDate day, String source) {
- Map<String, Object> item = new LinkedHashMap<>();
- item.put("date", day.format(DATE_FMT));
- item.put("source", source);
- return item;
- }
- private static CategoryDef requireCategory(String code) {
- for (CategoryDef def : CATEGORY_DEFS) {
- if (def.code.equals(code))
- return def;
- }
- throw new IllegalArgumentException("评分项目参数错误");
- }
- private static Map<Long, AdjustmentTotals> rdAdjustmentTotals(
- Db db, YearMonth month) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select BJID,"
- + "sum(case when JFLX=1 and LYLX in('"
- + XjbJfServ.LYLX_TEAM_ROLE + "','"
- + XjbJfServ.LYLX_TEAM_MEMBER
- + "') then JFZ else 0 end) TEAM_BONUS,"
- + "sum(case when JFLX=1 and nvl(LYLX,'#') not in('"
- + XjbJfServ.LYLX_TEAM_ROLE + "','"
- + XjbJfServ.LYLX_TEAM_MEMBER
- + "') then JFZ else 0 end) OTHER_BONUS,"
- + "sum(case when JFLX=2 then JFZ else 0 end) DEDUCTION,"
- + "sum(case when JFLX=1 then 1 else 0 end) BONUS_CNT,"
- + "sum(case when JFLX=2 then 1 else 0 end) DEDUCTION_CNT"
- + " from XJB_JFJL where NDY=:ndy and JLZTM=51"
- + " group by BJID");
- sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
- try {
- Map<Long, AdjustmentTotals> result = new HashMap<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- AdjustmentTotals total = new AdjustmentTotals();
- total.bonus = XjbJfServ.capBonus(
- rdDouble(row.get("other_bonus")),
- rdDouble(row.get("team_bonus")));
- total.deduction = rdDouble(row.get("deduction"));
- total.bonusEvents = rdInt(row.get("bonus_cnt"));
- total.deductionEvents = rdInt(row.get("deduction_cnt"));
- result.put(rdLong(row.get("bjid")), total);
- }
- return result;
- } catch (SQLException e) {
- if (isMissingTable(e, "XJB_JFJL"))
- return Collections.emptyMap();
- throw e;
- }
- }
- private static PublishedSnapshot rdPublishedSnapshot(
- Db db, long bjid, YearMonth month) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select jg.ZF,jg.XJ,jg.ZJF,jg.KJF,jg.ZJFCS,jg.KJFCS,"
- + "jg.SSLY,jg.KTLY,jg.SJLY,jg.CSLY,jg.FJLY,jg.KQLY,"
- + "pm.DWPM,pm.DWCS,pm.XXPM,pm.XXCS from XJB_JG jg"
- + " inner join XJB_JD jd on jd.XJB_JDID=jg.XJB_JDID"
- + " inner join XJB_PM pm on pm.XJB_JDID=jg.XJB_JDID"
- + " and pm.BJID=jg.BJID"
- + " where jg.BJID=:bjid and jg.NDY=:ndy"
- + " and jg.ZT=5 and jd.ZT=5"
- + " and jd.FWLX in('XX','BM')"
- + " order by case when jd.FWLX='XX' then 0 else 1 end,"
- + " jd.BB desc,jd.XJB_JDID desc");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
- try {
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- if (rows == null || rows.isEmpty())
- return null;
- Map<String, Object> row = rows.get(0);
- PublishedSnapshot snapshot = new PublishedSnapshot();
- snapshot.total = rdDouble(row.get("zf"));
- snapshot.starLevel = rdStr(row.get("xj"));
- snapshot.bonus = rdDouble(row.get("zjf"));
- snapshot.deduction = rdDouble(row.get("kjf"));
- snapshot.bonusCount = rdInt(row.get("zjfcs"));
- snapshot.deductionCount = rdInt(row.get("kjfcs"));
- snapshot.departmentRank = rdInt(row.get("dwpm"));
- snapshot.departmentClassCount = rdInt(row.get("dwcs"));
- snapshot.schoolRank = rdInt(row.get("xxpm"));
- snapshot.schoolClassCount = rdInt(row.get("xxcs"));
- snapshot.sources.put("dorm", rdStr(row.get("ssly")));
- snapshot.sources.put("classroom", rdStr(row.get("ktly")));
- snapshot.sources.put("flag", rdStr(row.get("sjly")));
- snapshot.sources.put("cleaning", rdStr(row.get("csly")));
- snapshot.sources.put("discipline", rdStr(row.get("fjly")));
- snapshot.sources.put("attendance", rdStr(row.get("kqly")));
- return snapshot;
- } catch (SQLException e) {
- if (isMissingTable(e, "XJB_JG"))
- return null;
- throw e;
- }
- }
- private static List<Adjustment> rdAdjustments(
- Db db, long bjid, YearMonth month) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select j.XJB_JFJLID ID,j.FSSJ,j.JFLX,j.JFZ,j.MC,j.MS,"
- + "j.LYLX,j.LYID,j.LYLB,r.XM RYXM from XJB_JFJL j"
- + " left join RY r on r.RYID=j.RYID"
- + " where j.BJID=:bjid and j.NDY=:ndy and j.JLZTM=51"
- + " order by j.FSSJ desc,j.XJB_JFJLID desc");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
- try {
- List<Adjustment> result = new ArrayList<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
- int type = rdInt(row.get("jflx"));
- double points = rdDouble(row.get("jfz"));
- result.add(new Adjustment(
- rdLong(row.get("id")),
- rdLocalDate(row.get("fssj")),
- type == 1 ? points : -points,
- defaultText(row.get("mc"), "星级班增扣分"),
- defaultText(row.get("ms"), ""),
- defaultText(row.get("lylx"), ""),
- rdLong(row.get("lyid")),
- defaultText(row.get("ryxm"), "")));
- }
- return result;
- } catch (SQLException e) {
- if (isMissingTable(e, "XJB_JFJL"))
- return Collections.emptyList();
- throw e;
- }
- }
- private static AdjustmentTotals adjustmentTotals(
- List<Adjustment> adjustments) {
- AdjustmentTotals total = new AdjustmentTotals();
- double otherBonus = 0.0;
- double teamBonus = 0.0;
- for (Adjustment item : adjustments) {
- if (item.score > 0) {
- if (XjbJfServ.LYLX_TEAM_ROLE.equals(item.sourceType)
- || XjbJfServ.LYLX_TEAM_MEMBER.equals(
- item.sourceType)) {
- teamBonus += item.score;
- } else {
- otherBonus += item.score;
- }
- total.bonusEvents++;
- } else {
- total.deduction += Math.abs(item.score);
- total.deductionEvents++;
- }
- }
- total.bonus = round2(XjbJfServ.capBonus(otherBonus, teamBonus));
- total.deduction = round2(total.deduction);
- return total;
- }
- private static String starLevel(double score, int schoolRank) {
- if (schoolRank <= 10 && score > 90.0)
- return "五星级";
- if (score > 80.0)
- return "四星级";
- if (score > 75.0)
- return "三星级";
- if (score > 65.0)
- return "二星级";
- if (score > 55.0)
- return "一星级";
- return "无星级";
- }
- private static int attendancePenalty(int kqlbm) {
- return switch (kqlbm) {
- case 1 -> 3;
- case 21 -> 1;
- case 51 -> 1;
- case 52 -> 1;
- case 61 -> 2;
- default -> 0;
- };
- }
- private static boolean isZhixinStarImport(String marker) {
- return StringUtils.startsWith(marker, ZHIXIN_STAR_MARKER_PREFIX);
- }
- private static YearMonth rdMonth(HttpServletRequest request) {
- String value = StringUtils.trimToNull(request.getParameter("month"));
- YearMonth now = YearMonth.now(CN_ZONE);
- YearMonth month = value == null ? now : YearMonth.parse(value, MONTH_FMT);
- if (month.isAfter(now))
- throw new IllegalArgumentException("不能查询未来月份");
- return month;
- }
- private static LocalDate rdDate(HttpServletRequest request, String name) {
- String value = StringUtils.trimToNull(request.getParameter(name));
- if (value == null)
- throw new IllegalArgumentException("缺少参数:" + name);
- return LocalDate.parse(value, DATE_FMT);
- }
- private static long rdLongParam(HttpServletRequest request, String name,
- boolean required) {
- String value = StringUtils.trimToNull(request.getParameter(name));
- if (value == null) {
- if (required)
- throw new IllegalArgumentException("缺少参数:" + name);
- return 0L;
- }
- try {
- return Long.parseLong(value);
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("参数格式错误:" + name);
- }
- }
- private static int rdIntParam(HttpServletRequest request, String name,
- int defaultValue) {
- String value = StringUtils.trimToNull(request.getParameter(name));
- if (value == null)
- return defaultValue;
- try {
- return Integer.parseInt(value);
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("参数格式错误:" + name);
- }
- }
- private static int clampPageSize(int value) {
- return Math.max(1, Math.min(100, value));
- }
- private static Map<Long, Double> rdScoreMap(
- List<Map<String, Object>> rows) {
- Map<Long, Double> result = new HashMap<>();
- for (Map<String, Object> row : rows)
- result.put(rdLong(row.get("bjid")), round2(
- rdDouble(row.get("score"))));
- return result;
- }
- private static LocalDate rdLocalDate(Object value) {
- if (value instanceof Date)
- return ((Date) value).toLocalDate();
- if (value instanceof Timestamp)
- return ((Timestamp) value).toLocalDateTime().toLocalDate();
- if (value == null)
- return null;
- String text = String.valueOf(value);
- if (text.length() >= 10)
- return LocalDate.parse(text.substring(0, 10), DATE_FMT);
- return null;
- }
- private static String formatTimestamp(Object value) {
- if (value instanceof Timestamp)
- return ((Timestamp) value).toLocalDateTime().format(DATETIME_FMT);
- return value == null ? "" : String.valueOf(value);
- }
- private static String weekdayCn(LocalDate date) {
- DayOfWeek day = date.getDayOfWeek();
- return switch (day) {
- case MONDAY -> "星期一";
- case TUESDAY -> "星期二";
- case WEDNESDAY -> "星期三";
- case THURSDAY -> "星期四";
- case FRIDAY -> "星期五";
- case SATURDAY -> "星期六";
- case SUNDAY -> "星期日";
- };
- }
- private static long rdLong(Object value) {
- return value == null ? 0L : Long.parseLong(String.valueOf(value));
- }
- private static Long rdLongObj(Object value) {
- return value == null ? null : Long.valueOf(String.valueOf(value));
- }
- private static int rdInt(Object value) {
- return value == null ? 0 : Integer.parseInt(String.valueOf(value));
- }
- private static double rdDouble(Object value) {
- return value == null ? 0.0 : Double.parseDouble(String.valueOf(value));
- }
- private static String rdStr(Object value) {
- return value == null ? null : String.valueOf(value);
- }
- private static double round2(double value) {
- return Math.round(value * 100.0) / 100.0;
- }
- private static boolean isMissingTable(SQLException e, String tableName) {
- String message = StringUtils.defaultString(e.getMessage()).toUpperCase();
- return e.getErrorCode() == 942
- && message.contains(tableName.toUpperCase());
- }
- private static final class MonthPeriod {
- final YearMonth month;
- final Timestamp start;
- final Timestamp end;
- final LocalDate maxDate;
- final int maxDay;
- private MonthPeriod(YearMonth month) {
- this.month = month;
- LocalDate first = month.atDay(1);
- LocalDate today = LocalDate.now(CN_ZONE);
- LocalDate monthEnd = month.atEndOfMonth();
- this.maxDate = month.equals(YearMonth.from(today))
- ? today : monthEnd;
- this.maxDay = maxDate.getDayOfMonth();
- this.start = Timestamp.valueOf(first.atStartOfDay());
- this.end = Timestamp.valueOf(maxDate.plusDays(1).atStartOfDay());
- }
- static MonthPeriod of(YearMonth month) {
- return new MonthPeriod(month);
- }
- }
- private static final class ClassInfo {
- final long bjid;
- final String bjmc;
- final Long dwid;
- final String dwmc;
- ClassInfo(long bjid, String bjmc, Long dwid, String dwmc) {
- this.bjid = bjid;
- this.bjmc = bjmc;
- this.dwid = dwid;
- this.dwmc = dwmc;
- }
- }
- private record CategoryDef(String code, String label, double weight) {
- }
- private static final class DailyPoint {
- final LocalDate date;
- final double score;
- final int count;
- DailyPoint(LocalDate date, double score, int count) {
- this.date = date;
- this.score = score;
- this.count = count;
- }
- }
- private static final class DailyAccumulator {
- final LocalDate date;
- double regularDeduction;
- boolean hasRegular;
- DailyAccumulator(LocalDate date) {
- this.date = date;
- }
- Map<String, Object> toMap() {
- Map<String, Object> row = new LinkedHashMap<>();
- row.put("date", date.format(DATE_FMT));
- row.put("weekday", weekdayCn(date));
- row.put("regularDeduction", round2(regularDeduction));
- row.put("totalDeduction", round2(regularDeduction));
- row.put("hasRegular", hasRegular);
- return row;
- }
- }
- private static final class CategoryDaily {
- final ClassInfo cls;
- final Map<String, Map<LocalDate, DailyPoint>> actual = new HashMap<>();
- final Map<String, String> sources = new HashMap<>();
- CategoryDaily(ClassInfo cls) {
- this.cls = cls;
- }
- Map<String, Object> toMap(CategoryDef def, LocalDate date) {
- String source = sources.getOrDefault(def.code, SOURCE_MISSING);
- DailyPoint point = null;
- if (SOURCE_REAL.equals(source)) {
- Map<LocalDate, DailyPoint> values = actual.get(def.code);
- point = values == null ? null : values.get(date);
- }
- boolean available;
- double score;
- double deduction;
- if (point != null) {
- available = true;
- score = point.score;
- deduction = Math.max(0.0, 100.0 - score);
- } else {
- available = false;
- score = 0.0;
- deduction = 0.0;
- }
- Map<String, Object> row = new LinkedHashMap<>();
- row.put("code", def.code);
- row.put("label", def.label);
- row.put("score", round2(score));
- row.put("deduction", round2(deduction));
- row.put("source", source);
- row.put("available", available);
- row.put("count", point == null ? 0 : point.count);
- return row;
- }
- double regularDeduction(LocalDate date) {
- double total = 0.0;
- for (CategoryDef def : CATEGORY_DEFS) {
- Map<String, Object> row = toMap(def, date);
- total += rdDouble(row.get("deduction"));
- }
- return total;
- }
- }
- private static final class ScoreBook {
- Map<Long, Double> dorm = new HashMap<>();
- Map<Long, Double> dormAttendance = new HashMap<>();
- Map<Long, Double> classroom = new HashMap<>();
- Map<Long, Double> flag = new HashMap<>();
- Map<Long, Double> cleaning = new HashMap<>();
- Map<Long, Double> attendance = new HashMap<>();
- Map<Long, Double> discipline = new HashMap<>();
- Map<Long, AdjustmentTotals> adjustments = new HashMap<>();
- Map<Long, ClassScore> classScores = new HashMap<>();
- Map<String, String> categorySources(long bjid) {
- ClassScore score = classScores.get(bjid);
- return score == null ? Collections.emptyMap() : score.sources;
- }
- }
- private static final class ClassScore {
- final Map<String, Double> values = new LinkedHashMap<>();
- final Map<String, String> sources = new LinkedHashMap<>();
- final List<String> missing = new ArrayList<>();
- AdjustmentTotals adjust = new AdjustmentTotals();
- double total;
- boolean hasMissing;
- }
- private static final class RankBook {
- final Map<Long, Integer> schoolRank = new HashMap<>();
- final Map<Long, Integer> departmentRank = new HashMap<>();
- final Map<Long, Integer> departmentClassCount = new HashMap<>();
- }
- private static final class DisciplinePenalties {
- final Map<Long, Map<LocalDate, Double>> mapped = new HashMap<>();
- final Map<Long, Map<LocalDate, Double>> legacy = new HashMap<>();
- }
- private static final class Adjustment {
- final long id;
- final LocalDate date;
- final double score;
- final String itemName;
- final String remark;
- final String sourceType;
- final long sourceRecordId;
- final String studentName;
- Adjustment(long id, LocalDate date, double score,
- String itemName, String remark, String sourceType,
- long sourceRecordId, String studentName) {
- this.id = id;
- this.date = date;
- this.score = score;
- this.itemName = itemName;
- this.remark = remark;
- this.sourceType = sourceType;
- this.sourceRecordId = sourceRecordId;
- this.studentName = studentName;
- }
- }
- private static final class AdjustmentTotals {
- double bonus;
- double deduction;
- int bonusEvents;
- int deductionEvents;
- }
- private static final class PublishedSnapshot {
- double total;
- String starLevel;
- double bonus;
- double deduction;
- int bonusCount;
- int deductionCount;
- int departmentRank;
- int departmentClassCount;
- int schoolRank;
- int schoolClassCount;
- final Map<String, String> sources = new LinkedHashMap<>();
- }
- }
|