|
|
@@ -0,0 +1,195 @@
|
|
|
+package biz.xy;
|
|
|
+
|
|
|
+import base.po.XyvPo;
|
|
|
+import biz.ry.RyC;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
|
+import ss.AppB;
|
|
|
+import ss.bpm.BpmC;
|
|
|
+import ss.bpm.BpmRunB;
|
|
|
+import ss.bpm.BpmU;
|
|
|
+import ss.db.Db;
|
|
|
+import ss.db.SqlCmd;
|
|
|
+import ss.obj.ObjC;
|
|
|
+import ss.serv.Serv;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 学员休学流程执行节点。
|
|
|
+ *
|
|
|
+ * <p>休学只把 {@code RY.RYZTM} 从 101 受控改为 151。保留人员启用状态、班级关系、
|
|
|
+ * 住宿事实和海康组织/权限,使未退宿学生仍可按原宿舍权限进出校门;考勤侧继续按
|
|
|
+ * {@code RYZTM=101} 排除休学学生。</p>
|
|
|
+ */
|
|
|
+public class XySuspendServ extends Serv {
|
|
|
+
|
|
|
+ private static final Logger log4j = LogManager.getLogger(XySuspendServ.class);
|
|
|
+ private static final int JLZTM_USE = 51;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 休学 BPM 执行入口,由 {@code xy_sh_xx_run} 挂载。
|
|
|
+ *
|
|
|
+ * @return {@link BpmC#FWD_runAgr} 表示流程继续,{@link BpmC#FWD_runRej} 表示退回申请人。
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public String syncSuspendByBpm() throws Exception {
|
|
|
+ BpmRunB bpmParam = AppB.bpmRunMap.get(Thread.currentThread().getId());
|
|
|
+ if (bpmParam == null || bpmParam.dba == null)
|
|
|
+ throw new IllegalStateException("未找到学员休学 BPM 上下文。");
|
|
|
+
|
|
|
+ Db gdba = bpmParam.dba;
|
|
|
+ String mountErr = checkNodeMount(bpmParam);
|
|
|
+ if (mountErr != null)
|
|
|
+ return finishBpm(bpmParam, BpmC.FWD_runRej, mountErr);
|
|
|
+
|
|
|
+ long ryid = rdRyid(bpmParam);
|
|
|
+ if (ryid <= 0)
|
|
|
+ return finishBpm(bpmParam, BpmC.FWD_runRej, "未找到学员对象,无法执行休学。");
|
|
|
+
|
|
|
+ String message;
|
|
|
+ try {
|
|
|
+ Map<String, Object> person = selectPerson(gdba, ryid);
|
|
|
+ if (person == null)
|
|
|
+ return finishBpm(bpmParam, BpmC.FWD_runRej,
|
|
|
+ "未找到人员档案(ryid=" + ryid + "),无法执行休学。");
|
|
|
+
|
|
|
+ message = applyLocalSuspend(gdba, person);
|
|
|
+ gdba.commit();
|
|
|
+ } catch (Exception e) {
|
|
|
+ try {
|
|
|
+ gdba.rollback();
|
|
|
+ } catch (Exception rollbackEx) {
|
|
|
+ e.addSuppressed(rollbackEx);
|
|
|
+ }
|
|
|
+ log4j.error("XySuspendServ.syncSuspendByBpm() 异常, ryid=" + ryid, e);
|
|
|
+ return finishBpm(bpmParam, BpmC.FWD_runRej, "休学本地处理异常:" + rdErrMsg(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ log4j.info("学员休学状态处理成功, ryid={}, result={}", ryid, message);
|
|
|
+ return finishBpm(bpmParam, BpmC.FWD_runAgr, message);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行受控的本地状态写入。这里不触碰 JLZTM、SFQY、BJCY、CDSY、床位或海康。
|
|
|
+ */
|
|
|
+ private String applyLocalSuspend(Db gdba, Map<String, Object> person) throws Exception {
|
|
|
+ long ryid = rdLongVal(person, "ryid");
|
|
|
+ int rylbm = rdInt(person, "rylbm", -1);
|
|
|
+ int ryztm = rdInt(person, "ryztm", -1);
|
|
|
+ int jlztm = rdInt(person, "jlztm", -1);
|
|
|
+ int sfqy = rdInt(person, "sfqy", -1);
|
|
|
+
|
|
|
+ if (rylbm != RyC.RYLB_xy)
|
|
|
+ throw new IllegalStateException("人员不是学员(RYLBM=" + rylbm + "),已停止休学操作。");
|
|
|
+
|
|
|
+ int activeBjcy = countActiveBjcy(gdba, ryid);
|
|
|
+ if (activeBjcy != 1)
|
|
|
+ throw new IllegalStateException("有效班级成员记录数量不是 1(实际 " + activeBjcy + "),请先处理班级关系。");
|
|
|
+
|
|
|
+ if (ryztm == RyC.RYZT_xx && jlztm == JLZTM_USE && sfqy == 1)
|
|
|
+ return "本地休学状态已生效,跳过重复写入。";
|
|
|
+
|
|
|
+ if (ryztm != RyC.RYZT_zd || jlztm != JLZTM_USE || sfqy != 1)
|
|
|
+ throw new IllegalStateException("人员状态不是预期的 101/51/启用(实际 "
|
|
|
+ + ryztm + "/" + jlztm + "/" + sfqy + "),已停止休学操作。");
|
|
|
+
|
|
|
+ SqlCmd cmd = new SqlCmd("update RY set RYZTM=" + RyC.RYZT_xx +
|
|
|
+ " where RYID=:ryid and RYZTM=" + RyC.RYZT_zd +
|
|
|
+ " and JLZTM=" + JLZTM_USE + " and SFQY=1");
|
|
|
+ cmd.wrLongParm("ryid", ryid);
|
|
|
+ if (gdba.doModByC(cmd) != 1)
|
|
|
+ throw new IllegalStateException("人员休学状态更新行数不是 1,已停止操作。");
|
|
|
+
|
|
|
+ return "本地休学状态已写入(RYZTM 101 -> 151;JLZTM/SFQY/BJCY/CDSY/床位/海康权限未修改)。";
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> selectPerson(Db gdba, long ryid) throws Exception {
|
|
|
+ SqlCmd cmd = new SqlCmd("select ry.RYID,ry.RYH,ry.XM,ry.RYLBM,ry.RYZTM,ry.JLZTM,ry.SFQY" +
|
|
|
+ " from RY ry where ry.RYID=:ryid");
|
|
|
+ cmd.wrLongParm("ryid", ryid);
|
|
|
+ Map<String, Object> row = gdba.doSelMapByC(cmd);
|
|
|
+ return row == null || row.isEmpty() ? null : row;
|
|
|
+ }
|
|
|
+
|
|
|
+ private int countActiveBjcy(Db gdba, long ryid) throws Exception {
|
|
|
+ SqlCmd cmd = new SqlCmd("select count(*) CNT from BJCY where RYID=:ryid and SFBY=0 and "
|
|
|
+ + ObjC.JLZT_useStr);
|
|
|
+ cmd.wrLongParm("ryid", ryid);
|
|
|
+ gdba.doSelByC(cmd);
|
|
|
+ return gdba.rdIntCol("cnt");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 防止节点误挂到增加、停用或启用流程。 */
|
|
|
+ private String checkNodeMount(BpmRunB bpmParam) {
|
|
|
+ String dxm = bpmParam.sq == null ? null : StringUtils.trimToNull(bpmParam.sq.getDxm());
|
|
|
+ if (dxm != null && !"xy".equalsIgnoreCase(dxm))
|
|
|
+ return "【休学】节点挂载对象不匹配:只允许挂在“xy”对象的变动流程,实际对象=" + dxm + "。";
|
|
|
+
|
|
|
+ int lbm = bpmParam.sq == null ? 0 : bpmParam.sq.getLbm();
|
|
|
+ if (lbm != BpmC.CHG_chgType)
|
|
|
+ return "【休学】节点只允许挂在“变动”流程(lbm=" + BpmC.CHG_chgType
|
|
|
+ + "),当前流程类别 lbm=" + lbm + ",请检查流程节点配置。";
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private long rdRyid(BpmRunB bpmParam) {
|
|
|
+ if (bpmParam.objPo instanceof XyvPo) {
|
|
|
+ XyvPo xy = (XyvPo) bpmParam.objPo;
|
|
|
+ if (xy.getRyid() > 0)
|
|
|
+ return xy.getRyid();
|
|
|
+ }
|
|
|
+ Long dxid = bpmParam.sq == null ? null : bpmParam.sq.getDxid();
|
|
|
+ return dxid == null ? 0L : dxid;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String finishBpm(BpmRunB bpmParam, String fwd, String message) throws Exception {
|
|
|
+ if (bpmParam.sh != null)
|
|
|
+ BpmU.updShByRun(fwd, message, bpmParam.sh.getShid(), bpmParam.dba);
|
|
|
+ return fwd;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Object rdVal(Map<String, Object> row, String key) {
|
|
|
+ if (row == null || key == null)
|
|
|
+ return null;
|
|
|
+ if (row.containsKey(key))
|
|
|
+ return row.get(key);
|
|
|
+ if (row.containsKey(StringUtils.lowerCase(key)))
|
|
|
+ return row.get(StringUtils.lowerCase(key));
|
|
|
+ return row.get(StringUtils.upperCase(key));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int rdInt(Map<String, Object> row, String key, int defaultValue) {
|
|
|
+ Object value = rdVal(row, key);
|
|
|
+ if (value == null)
|
|
|
+ return defaultValue;
|
|
|
+ if (value instanceof Number)
|
|
|
+ return ((Number) value).intValue();
|
|
|
+ try {
|
|
|
+ return Integer.parseInt(StringUtils.trim(String.valueOf(value)));
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static long rdLongVal(Map<String, Object> row, String key) {
|
|
|
+ Object value = rdVal(row, key);
|
|
|
+ if (value == null)
|
|
|
+ return 0L;
|
|
|
+ if (value instanceof Number)
|
|
|
+ return ((Number) value).longValue();
|
|
|
+ try {
|
|
|
+ return Long.parseLong(StringUtils.trim(String.valueOf(value)));
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String rdErrMsg(Exception e) {
|
|
|
+ Throwable current = e;
|
|
|
+ while (current.getCause() != null && current.getCause() != current)
|
|
|
+ current = current.getCause();
|
|
|
+ return StringUtils.defaultIfBlank(current.getMessage(), current.getClass().getSimpleName());
|
|
|
+ }
|
|
|
+}
|