| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676 |
- package biz.bj;
- import base.po.XjbJfjlPo;
- import com.google.gson.Gson;
- import jakarta.servlet.http.HttpServletRequest;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import ss.db.Db;
- import ss.db.SqlCmd;
- import ss.obj.ObjC;
- import ss.serv.Serv;
- import ss.serv.ServU;
- import ss.user.UserRunB;
- import ss.user.UserU;
- import java.io.Writer;
- import java.sql.Timestamp;
- import java.time.LocalDate;
- import java.time.YearMonth;
- import java.time.ZoneId;
- import java.time.format.DateTimeFormatter;
- import java.util.Arrays;
- import java.util.LinkedHashMap;
- import java.util.LinkedHashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- /**
- * 星级班增分、减分事件账本。
- */
- public class XjbJfServ extends Serv {
- private static final Logger log4j = LogManager.getLogger(XjbJfServ.class);
- private static final ZoneId CN_ZONE = ZoneId.of("Asia/Shanghai");
- private static final DateTimeFormatter MONTH_FMT =
- DateTimeFormatter.ofPattern("yyyy-MM");
- public static final String LYLX_AWARD = "HJ";
- public static final String LYLX_SCHOOL_VIOLATION = "XW";
- public static final String LYLX_TEAM_ROLE = "TT";
- public static final String LYLX_TEAM_MEMBER = "TTCY";
- public static final String LYLX_MONTH_SAFE = "MONTH_SAFE";
- public static final String LYLX_FJ_SAFE = "FJ_SAFE";
- public static final int JFLX_ADD = 1;
- public static final int JFLX_SUB = 2;
- public static final double TEAM_BONUS_CAP = 3.0;
- public static final double TOTAL_BONUS_CAP = 8.0;
- private static final Set<String> RECALC_TYPES = new LinkedHashSet<>(
- Arrays.asList(LYLX_AWARD, LYLX_SCHOOL_VIOLATION,
- LYLX_MONTH_SAFE, LYLX_FJ_SAFE));
- private static final Set<String> TEAM_SNAPSHOT_TYPES = new LinkedHashSet<>(
- Arrays.asList(LYLX_TEAM_ROLE, LYLX_TEAM_MEMBER));
- /**
- * 学生团体先按 3 分封顶,再与其他增分合并并受总增分 8 分限制。
- */
- public static double capBonus(double otherBonus, double teamBonus) {
- double safeTeamBonus = Math.min(
- TEAM_BONUS_CAP, Math.max(0.0, teamBonus));
- double safeOtherBonus = Math.max(0.0, otherBonus);
- return Math.min(TOTAL_BONUS_CAP, safeOtherBonus + safeTeamBonus);
- }
- public static String schoolYearCode(YearMonth month) {
- int startYear = month.getMonthValue() >= 9
- ? month.getYear() : month.getYear() - 1;
- return startYear + "-" + (startYear + 1);
- }
- /**
- * 为当前班主任的指定班级重建一个月的事件账本。
- */
- @SuppressWarnings("unused")
- public void syncByA() throws Exception {
- HttpServletRequest request = super.req;
- super.resp.setCharacterEncoding("UTF-8");
- super.resp.setContentType("application/json;charset=UTF-8");
- Writer writer = super.resp.getWriter();
- Gson gson = new Gson();
- try (Db db = Db.makeConn()) {
- UserRunB user = UserU.rdUserByReq(request);
- if (user == null)
- throw new IllegalArgumentException("登录状态已失效,请重新登录");
- long bjid = rdLong(request.getParameter("bjid"), 0L);
- Map<String, Object> cls = requireTeacherClass(db, user.ryid, bjid);
- bjid = rdLong(cls.get("bjid"), 0L);
- YearMonth month = rdMonth(request.getParameter("month"));
- if (month.isAfter(YearMonth.now(CN_ZONE)))
- throw new IllegalArgumentException("不能同步未来月份");
- SyncCount count = syncClassMonth(db, bjid, month, user);
- db.commit();
- Map<String, Object> data = new LinkedHashMap<>();
- data.put("bjid", bjid);
- data.put("bjmc", cls.get("bjmc"));
- data.put("month", month.format(MONTH_FMT));
- data.put("awardEvents", count.awards);
- data.put("violationEvents", count.violations);
- data.put("teamRoleEvents", count.teamRoles);
- data.put("monthSafeEvents", count.monthSafe);
- data.put("fjSafeEvents", count.fjSafe);
- data.put("totalEvents", count.total());
- ServU.wrOkDataByWriter(data, writer, gson);
- } catch (IllegalArgumentException e) {
- ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
- } catch (Exception e) {
- log4j.error("XjbJfServ.syncByA() 异常", e);
- ServU.wrErrMsgByWriter(null, "星级班增扣分同步失败", writer, gson);
- }
- }
- /**
- * 定时任务入口:同步当前月和上一月。
- * 测试环境不加载 timer.xml,正式发布后再启用。
- */
- @SuppressWarnings("unused")
- public void syncDaily() throws Exception {
- try (Db db = Db.makeConn()) {
- List<Long> classIds = rdActiveClassIds(db);
- YearMonth current = YearMonth.now(CN_ZONE);
- YearMonth previous = current.minusMonths(1);
- for (long bjid : classIds) {
- syncClassMonth(db, bjid, previous, null);
- syncClassMonth(db, bjid, current, null);
- }
- db.commit();
- log4j.info("星级班增扣分定时同步完成,班级数={}", classIds.size());
- } catch (Exception e) {
- log4j.error("XjbJfServ.syncDaily() 异常", e);
- throw e;
- }
- }
- private SyncCount syncClassMonth(Db db, long bjid, YearMonth month,
- UserRunB user) throws Exception {
- String ndy = month.format(MONTH_FMT);
- Set<String> recalcTypes = new LinkedHashSet<>(RECALC_TYPES);
- if (YearMonth.now(CN_ZONE).equals(month)) {
- recalcTypes.add(LYLX_TEAM_ROLE);
- recalcTypes.add(LYLX_TEAM_MEMBER);
- }
- String placeholders = String.join(",",
- recalcTypes.stream().map(type -> ":lylx" + type).toList());
- SqlCmd delete = new SqlCmd(
- "delete from XJB_JFJL where BJID=:bjid and NDY=:ndy"
- + " and LYLX in(" + placeholders + ")");
- delete.wrLongParm("bjid", bjid);
- delete.wrStrParm("ndy", ndy);
- for (String type : recalcTypes)
- delete.wrStrParm("lylx" + type, type);
- db.doModByC(delete);
- SyncCount count = new SyncCount();
- count.awards = insertAwards(db, bjid, month, user);
- count.violations = insertSchoolViolations(db, bjid, month, user);
- if (YearMonth.now(CN_ZONE).equals(month))
- count.teamRoles = insertTeamRoles(db, bjid, month, user);
- if (month.isBefore(YearMonth.now(CN_ZONE))) {
- count.monthSafe = insertMonthSafe(db, bjid, month, user);
- count.fjSafe = insertFjSafe(db, bjid, month, user);
- }
- return count;
- }
- /**
- * 在月结核算时重建该班的团体成员快照。
- * 普通成员和职务成员都按执行核算时的有效班级关系固化。
- */
- public int rebuildTeamSnapshot(Db db, long bjid, YearMonth month,
- UserRunB user) throws Exception {
- String placeholders = String.join(",",
- TEAM_SNAPSHOT_TYPES.stream()
- .map(type -> ":lylx" + type).toList());
- SqlCmd delete = new SqlCmd(
- "delete from XJB_JFJL where BJID=:bjid and NDY=:ndy"
- + " and LYLX in(" + placeholders + ")");
- delete.wrLongParm("bjid", bjid);
- delete.wrStrParm("ndy", month.format(MONTH_FMT));
- for (String type : TEAM_SNAPSHOT_TYPES)
- delete.wrStrParm("lylx" + type, type);
- db.doModByC(delete);
- return insertTeamRoles(db, bjid, month, user);
- }
- private int insertAwards(Db db, long bjid, YearMonth month, UserRunB user)
- throws Exception {
- int count = insertPersonalAwards(db, bjid, month, user);
- count += insertCollectiveAwards(db, bjid, month, user);
- return count;
- }
- private int insertPersonalAwards(Db db, long bjid, YearMonth month,
- UserRunB user) throws Exception {
- Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
- Timestamp end = Timestamp.valueOf(month.plusMonths(1).atDay(1)
- .atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select h.HJJLID ID,h.RYID,h.HJRQ FSSJ,h.HJLBM LYLB,"
- + "l.MC LBMC,l.BJJF JFZ,h.MC TITLE,h.MS DESCRIPTION,"
- + "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.BJID=:bjid and h.JLZTM=51"
- + " and nvl(h.HJXZM,1)=1"
- + " and h.HJRQ>=:start and h.HJRQ<:end"
- + " and h.HJLBM is not null and nvl(l.BJJF,0)>0"
- + " order by h.HJJLID");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- int count = 0;
- for (Map<String, Object> row : rows) {
- count += insertEvent(db, bjid, month, LYLX_AWARD,
- rdLong(row.get("id"), 0L),
- rdLong(row.get("lylb"), 0L),
- rdLongOrNull(row.get("ryid")),
- rdTimestamp(row.get("fssj")),
- JFLX_ADD, rdFloat(row.get("jfz")),
- rdStr(row.get("lbmc")),
- joinText("学校获奖",
- rdStr(row.get("title")),
- rdStr(row.get("description")),
- rdStr(row.get("ryxm"))),
- user);
- }
- return count;
- }
- private int insertCollectiveAwards(Db db, long bjid, YearMonth month,
- UserRunB user) throws Exception {
- Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
- Timestamp end = Timestamp.valueOf(month.plusMonths(1).atDay(1)
- .atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select h.HJJLID ID,h.HJRQ FSSJ,h.HJLBM LYLB,"
- + "l.MC LBMC,l.JTBJJF JFZ,h.MC TITLE,h.MS DESCRIPTION,"
- + "(select count(distinct c.RYID) from HJJLCY c"
- + " where c.HJJLID=h.HJJLID and c.JLZTM=51)"
- + "+case when h.RYID is not null then 1 else 0 end RYCOUNT"
- + " from HJJL h"
- + " inner join HJLB l on l.HJLBM=h.HJLBM"
- + " inner join (select h2.HJJLID,h2.BJID BJID"
- + " from HJJL h2 where h2.BJID is not null"
- + " union select c.HJJLID,nvl(c.BJID,bc.BJID) BJID"
- + " from HJJLCY c left join BJCY bc on bc.RYID=c.RYID"
- + " and bc." + ObjC.JLZT_useStr
- + " and nvl(bc.SFBY,0)=0"
- + " where c.JLZTM=51"
- + " and nvl(c.BJID,bc.BJID) is not null) tc"
- + " on tc.HJJLID=h.HJJLID"
- + " where h.JLZTM=51 and h.HJXZM=5"
- + " and h.HJRQ>=:start and h.HJRQ<:end"
- + " and h.HJLBM is not null and nvl(l.JTBJJF,0)>0"
- + " and tc.BJID=:bjid"
- + " order by h.HJJLID");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- int count = 0;
- for (Map<String, Object> row : rows) {
- count += insertEvent(db, bjid, month, LYLX_AWARD,
- rdLong(row.get("id"), 0L),
- rdLong(row.get("lylb"), 0L),
- null,
- rdTimestamp(row.get("fssj")),
- JFLX_ADD, rdFloat(row.get("jfz")),
- "集体获奖·" + rdStr(row.get("lbmc")),
- joinText("学校集体获奖",
- rdStr(row.get("title")),
- rdStr(row.get("description")),
- "参与学生" + rdInt(row.get("rycount"), 0) + "人"),
- user);
- }
- return count;
- }
- private int insertOrdinaryTeamMembers(Db db, long bjid, YearMonth month,
- UserRunB user, Timestamp syncTime)
- throws Exception {
- Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
- Timestamp end = Timestamp.valueOf(month.plusMonths(1).atDay(1)
- .atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select c.TTCYID ID,c.RYID,wc.TTWCYLBM LYLB,wc.MC LBMC,"
- + "wc.BJJF JFZ,t.MC TTMC,r.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='成员')"
- + " inner join BJCY bc on bc.RYID=c.RYID"
- + " left join RY r on r.RYID=c.RYID"
- + " where bc.BJID=:bjid and bc." + ObjC.JLZT_useStr
- + " and nvl(bc.SFBY,0)=0 and c." + ObjC.JLZT_useStr
- + " and t." + ObjC.JLZT_useStr
- + " and (c.KSRQ is null or c.KSRQ<:cEnd)"
- + " and (c.JSRQ is null or c.JSRQ>=:cStart)"
- + " and (t.KSRQ is null or t.KSRQ<:tEnd)"
- + " and (t.JSRQ is null or t.JSRQ>=:tStart)"
- + " and (c.XNDM is null or c.XNDM=:cXndm)"
- + " and (t.XNDM is null or t.XNDM=:tXndm)"
- + " and nvl(wc.BJJF,0)>0"
- + " and not exists (select 1 from TTWCY w"
- + " where w.TTID=c.TTID and w.RYID=c.RYID"
- + " and w." + ObjC.JLZT_useStr + ")"
- + " order by c.TTCYID");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("cStart", start);
- sqlc.wrTimeParm("cEnd", end);
- sqlc.wrStrParm("cXndm", schoolYearCode(month));
- sqlc.wrTimeParm("tStart", start);
- sqlc.wrTimeParm("tEnd", end);
- sqlc.wrStrParm("tXndm", schoolYearCode(month));
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- int count = 0;
- for (Map<String, Object> row : rows) {
- long sourceId = rdLong(row.get("id"), 0L);
- if (eventExists(db, LYLX_TEAM_MEMBER, sourceId, bjid, month))
- continue;
- String groupName = rdStr(row.get("ttmc"));
- String roleName = rdStr(row.get("lbmc"));
- count += insertEvent(db, bjid, month, LYLX_TEAM_MEMBER,
- sourceId,
- rdLong(row.get("lylb"), 0L),
- rdLongOrNull(row.get("ryid")),
- syncTime, JFLX_ADD, rdFloat(row.get("jfz")),
- groupName + "·" + roleName,
- joinText("团体普通成员班级加分", groupName, roleName,
- rdStr(row.get("ryxm"))),
- user);
- }
- return count;
- }
- private int insertSchoolViolations(Db db, long bjid, YearMonth month,
- UserRunB user) throws Exception {
- Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
- Timestamp end = Timestamp.valueOf(month.plusMonths(1).atDay(1)
- .atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select w.WJJLID ID,w.RYID,w.WJSJ FSSJ,w.WJLBM LYLB,"
- + "l.MC LBMC,l.BJKF JFZ,w.MS DESCRIPTION,r.XM RYXM"
- + " from WJJL w inner join WJLB l on l.WJLBM=w.WJLBM"
- + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
- + " and wm.YTM=" + XjbWjlbC.YTM_SCHOOL
- + " and wm.JLZTM=51"
- + " left join RY r on r.RYID=w.RYID"
- + " where w.BJID=:bjid and w.JLZTM=51"
- + " and w.WJSJ>=:start and w.WJSJ<:end"
- + " and nvl(l.BJKF,0)>0 order by w.WJJLID");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("start", start);
- sqlc.wrTimeParm("end", end);
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- int count = 0;
- for (Map<String, Object> row : rows) {
- count += insertEvent(db, bjid, month, LYLX_SCHOOL_VIOLATION,
- rdLong(row.get("id"), 0L),
- rdLong(row.get("lylb"), 0L),
- rdLongOrNull(row.get("ryid")),
- rdTimestamp(row.get("fssj")),
- JFLX_SUB, rdFloat(row.get("jfz")),
- rdStr(row.get("lbmc")),
- joinText("学校违纪",
- rdStr(row.get("description")),
- rdStr(row.get("ryxm"))),
- user);
- }
- return count;
- }
- private int insertTeamRoles(Db db, long bjid, YearMonth month,
- UserRunB user) throws Exception {
- Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
- Timestamp end = Timestamp.valueOf(month.plusMonths(1).atDay(1)
- .atStartOfDay());
- SqlCmd sqlc = new SqlCmd(
- "select w.TTWCYID ID,w.RYID,w.TTWCYLBM LYLB,"
- + "wc.MC LBMC,wc.BJJF JFZ,t.MC TTMC,r.XM RYXM"
- + " from TTWCY w inner join TT t on t.TTID=w.TTID"
- + " inner join TTWCYLB wc on wc.TTWCYLBM=w.TTWCYLBM"
- + " inner join BJCY bc on bc.RYID=w.RYID"
- + " left join RY r on r.RYID=w.RYID"
- + " where bc.BJID=:bjid and bc." + ObjC.JLZT_useStr
- + " and nvl(bc.SFBY,0)=0 and w." + ObjC.JLZT_useStr
- + " and t." + ObjC.JLZT_useStr
- + " and (w.KSRQ is null or w.KSRQ<:wEnd)"
- + " and (w.JSRQ is null or w.JSRQ>=:wStart)"
- + " and (t.KSRQ is null or t.KSRQ<:tEnd)"
- + " and (t.JSRQ is null or t.JSRQ>=:tStart)"
- + " and (w.XNDM is null or w.XNDM=:wXndm)"
- + " and (t.XNDM is null or t.XNDM=:tXndm)"
- + " and nvl(wc.BJJF,0)>0"
- + " and wc.MC not like '%退休%'"
- + " order by w.TTWCYID");
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrTimeParm("wStart", start);
- sqlc.wrTimeParm("wEnd", end);
- sqlc.wrStrParm("wXndm", schoolYearCode(month));
- sqlc.wrTimeParm("tStart", start);
- sqlc.wrTimeParm("tEnd", end);
- sqlc.wrStrParm("tXndm", schoolYearCode(month));
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- Timestamp syncTime = Timestamp.valueOf(
- LocalDate.now(CN_ZONE).atStartOfDay());
- int count = 0;
- for (Map<String, Object> row : rows) {
- long sourceId = rdLong(row.get("id"), 0L);
- if (eventExists(db, LYLX_TEAM_ROLE, sourceId, bjid, month))
- continue;
- String groupName = rdStr(row.get("ttmc"));
- String roleName = rdStr(row.get("lbmc"));
- count += insertEvent(db, bjid, month, LYLX_TEAM_ROLE,
- sourceId,
- rdLong(row.get("lylb"), 0L),
- rdLongOrNull(row.get("ryid")),
- syncTime, JFLX_ADD, rdFloat(row.get("jfz")),
- groupName + "·" + roleName,
- joinText("团体成员班级加分", groupName, roleName,
- rdStr(row.get("ryxm"))),
- user);
- }
- count += insertOrdinaryTeamMembers(db, bjid, month, user, syncTime);
- return count;
- }
- private boolean eventExists(Db db, String lylx, long lyid,
- long bjid, YearMonth month) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select count(*) CNT from XJB_JFJL where LYLX=:lylx"
- + " and LYID=:lyid and BJID=:bjid and NDY=:ndy"
- + " and JLZTM=51");
- sqlc.wrStrParm("lylx", lylx);
- sqlc.wrLongParm("lyid", lyid);
- sqlc.wrLongParm("bjid", bjid);
- sqlc.wrStrParm("ndy", month.format(MONTH_FMT));
- db.doSelByC(sqlc);
- return db.rowNum > 0 && db.rdIntCol("cnt") > 0;
- }
- private int insertMonthSafe(Db db, long bjid, YearMonth month,
- UserRunB user) throws Exception {
- Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
- Timestamp end = Timestamp.valueOf(month.plusMonths(1).atDay(1)
- .atStartOfDay());
- SqlCmd countCmd = new SqlCmd(
- "select count(*) CNT from WJJL w"
- + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
- + " and wm.YTM in(" + XjbWjlbC.YTM_DISCIPLINE
- + "," + XjbWjlbC.YTM_SCHOOL + ") and wm.JLZTM=51"
- + " where w.BJID=:bjid and w.JLZTM=51"
- + " and w.WJSJ>=:start and w.WJSJ<:end");
- countCmd.wrLongParm("bjid", bjid);
- countCmd.wrTimeParm("start", start);
- countCmd.wrTimeParm("end", end);
- db.doSelByC(countCmd);
- if (db.rowNum > 0 && db.rdIntCol("cnt") > 0)
- return 0;
- SqlCmd legacyCmd = new SqlCmd(
- "select count(*) CNT from XJB_FJRY"
- + " where BJID=:bjid and JCRQ>=:start and JCRQ<:end"
- + " and JLZTM=51 and WJRS>0");
- legacyCmd.wrLongParm("bjid", bjid);
- legacyCmd.wrTimeParm("start", start);
- legacyCmd.wrTimeParm("end", end);
- db.doSelByC(legacyCmd);
- if (db.rowNum > 0 && db.rdIntCol("cnt") > 0)
- return 0;
- long syntheticId = month.getYear() * 100L + month.getMonthValue();
- Timestamp eventTime = Timestamp.valueOf(
- month.atEndOfMonth().atTime(23, 59, 59));
- return insertEvent(db, bjid, month, LYLX_MONTH_SAFE,
- syntheticId, 0L, null, eventTime,
- JFLX_ADD, 1.5F, "当月无学生处分",
- "当月班级无有效学校处分记录,增1.5分", user);
- }
- private int insertFjSafe(Db db, long bjid, YearMonth month,
- UserRunB user) throws Exception {
- Timestamp start = Timestamp.valueOf(month.atDay(1).atStartOfDay());
- Timestamp end = Timestamp.valueOf(month.plusMonths(1).atDay(1)
- .atStartOfDay());
- SqlCmd inspectionCmd = new SqlCmd(
- "select count(*) CNT,nvl(sum(nvl(mx.JFKF,0)),0) JFKF"
- + " from XJB_FJJCMX mx"
- + " inner join XJB_FJJC jc on jc.XJB_FJJCID=mx.XJB_FJJCID"
- + " where mx.BJID=:bjid and mx.JLZTM=51 and jc.JLZTM=51"
- + " and jc.JCRQ>=:start and jc.JCRQ<:end");
- inspectionCmd.wrLongParm("bjid", bjid);
- inspectionCmd.wrTimeParm("start", start);
- inspectionCmd.wrTimeParm("end", end);
- List<Map<String, Object>> inspections =
- db.doSelMapListByC(inspectionCmd);
- Map<String, Object> inspection =
- inspections == null || inspections.isEmpty()
- ? Map.of() : inspections.get(0);
- int inspectionCount = rdInt(inspection.get("cnt"), 0);
- double inspectionPenalty = rdFloat(inspection.get("jfkf"));
- if (inspectionCount == 0 || inspectionPenalty > 0.0)
- return 0;
- SqlCmd countCmd = new SqlCmd(
- "select count(*) CNT from WJJL w"
- + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
- + " and wm.YTM=" + XjbWjlbC.YTM_DISCIPLINE
- + " and wm.JLZTM=51"
- + " where w.BJID=:bjid and w.JLZTM=51"
- + " and w.WJSJ>=:start and w.WJSJ<:end");
- countCmd.wrLongParm("bjid", bjid);
- countCmd.wrTimeParm("start", start);
- countCmd.wrTimeParm("end", end);
- db.doSelByC(countCmd);
- if (db.rowNum > 0 && db.rdIntCol("cnt") > 0)
- return 0;
- SqlCmd legacyCmd = new SqlCmd(
- "select count(*) CNT from XJB_FJRY"
- + " where BJID=:bjid and JCRQ>=:start and JCRQ<:end"
- + " and JLZTM=51 and WJRS>0");
- legacyCmd.wrLongParm("bjid", bjid);
- legacyCmd.wrTimeParm("start", start);
- legacyCmd.wrTimeParm("end", end);
- db.doSelByC(legacyCmd);
- if (db.rowNum > 0 && db.rdIntCol("cnt") > 0)
- return 0;
- long syntheticId = month.getYear() * 100L + month.getMonthValue();
- Timestamp eventTime = Timestamp.valueOf(
- month.atEndOfMonth().atTime(23, 59, 59));
- return insertEvent(db, bjid, month, LYLX_FJ_SAFE,
- syntheticId, 0L, null, eventTime,
- JFLX_ADD, 0.5F, "当月已完成风纪检查且无扣分",
- "当月存在有效风纪检查记录,且无有效风纪扣分,增0.5分", user);
- }
- private int insertEvent(Db db, long bjid, YearMonth month, String lylx,
- long lyid, long lylb, Long ryid, Timestamp fssj,
- int jflx, float jfz, String mc, String ms,
- UserRunB user) throws Exception {
- XjbJfjlPo po = new XjbJfjlPo();
- po.setXjb_jfjlid(db.rdNextSeqVal("XJB_JFJLID"));
- po.setNdy(month.format(MONTH_FMT));
- po.setBjid(bjid);
- po.setLylx(lylx);
- po.setLyid(lyid);
- po.setLylb(lylb);
- po.setRyid(ryid);
- po.setFssj(fssj);
- po.setJflx(jflx);
- po.setJfz(jfz);
- po.setMc(StringUtils.abbreviate(mc, 250));
- po.setMs(StringUtils.abbreviate(ms, 1000));
- po.setJlztm(ObjC.JLZT_inUse);
- po.setJlsj(new Timestamp(System.currentTimeMillis()));
- po.setCjryid(user == null ? null : user.ryid);
- po.setGlryid(user == null ? null : user.ryid);
- po.setGlbmid(user == null ? null : user.bmid);
- Set<String> fields = new LinkedHashSet<>(Arrays.asList(
- "xjb_jfjlid", "ndy", "bjid", "lylx", "lyid", "lylb",
- "ryid", "fssj", "jflx", "jfz", "mc", "ms", "jlztm",
- "jlsj", "cjryid", "glryid", "glbmid"));
- db.doInsPo(po, fields);
- return 1;
- }
- private Map<String, Object> requireTeacherClass(Db db, long ryid,
- long bjid)
- throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select BJID,MC BJMC from BJ where BZRID=:ryid and "
- + ObjC.JLZT_useStr + " and BJZTM!=81"
- + (bjid > 0 ? " and BJID=:bjid" : "")
- + " order by BJID");
- sqlc.wrLongParm("ryid", ryid);
- if (bjid > 0)
- sqlc.wrLongParm("bjid", bjid);
- List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
- if (rows == null || rows.isEmpty())
- throw new IllegalArgumentException(
- bjid > 0 ? "无权同步该班级" : "当前账号未关联班主任班级");
- return rows.get(0);
- }
- private List<Long> rdActiveClassIds(Db db) throws Exception {
- SqlCmd sqlc = new SqlCmd(
- "select BJID from BJ where " + ObjC.JLZT_useStr
- + " and BJZTM!=81 order by BJID");
- List<Long> result = new java.util.ArrayList<>();
- for (Map<String, Object> row : db.doSelMapListByC(sqlc))
- result.add(rdLong(row.get("bjid"), 0L));
- return result;
- }
- private YearMonth rdMonth(String value) {
- String text = StringUtils.trimToNull(value);
- if (text == null)
- return YearMonth.now(CN_ZONE);
- try {
- return YearMonth.parse(text, MONTH_FMT);
- } catch (Exception e) {
- throw new IllegalArgumentException("月份格式错误");
- }
- }
- private static long rdLong(Object value, long defaultValue) {
- if (value == null)
- return defaultValue;
- String text = StringUtils.trimToNull(String.valueOf(value));
- return text == null ? defaultValue : Long.parseLong(text);
- }
- private static int rdInt(Object value, int defaultValue) {
- return (int) rdLong(value, defaultValue);
- }
- private static Long rdLongOrNull(Object value) {
- long result = rdLong(value, 0L);
- return result == 0L ? null : result;
- }
- private static float rdFloat(Object value) {
- if (value == null)
- return 0F;
- String text = StringUtils.trimToNull(String.valueOf(value));
- return text == null ? 0F : Float.parseFloat(text);
- }
- private static Timestamp rdTimestamp(Object value) {
- if (value instanceof Timestamp timestamp)
- return timestamp;
- if (value instanceof java.sql.Date date)
- return new Timestamp(date.getTime());
- if (value instanceof java.util.Date date)
- return new Timestamp(date.getTime());
- String text = StringUtils.trimToNull(
- value == null ? null : String.valueOf(value));
- return text == null ? null : Timestamp.valueOf(text);
- }
- private static String rdStr(Object value) {
- return value == null ? "" : StringUtils.defaultString(
- String.valueOf(value));
- }
- private static String joinText(String... parts) {
- StringBuilder result = new StringBuilder();
- for (String part : parts) {
- String text = StringUtils.trimToNull(part);
- if (text == null)
- continue;
- if (result.length() > 0)
- result.append(";");
- result.append(text);
- }
- return result.toString();
- }
- private static final class SyncCount {
- int awards;
- int violations;
- int teamRoles;
- int monthSafe;
- int fjSafe;
- int total() {
- return awards + violations + teamRoles + monthSafe + fjSafe;
- }
- }
- }
|