|
|
@@ -56,6 +56,7 @@ public class BzrqjServ extends Serv {
|
|
|
// 增加,去掉 e.printStackTrace(),改用 log4j -- 按 IDEA 规范。Lin
|
|
|
private static final Logger log4j = LogManager.getLogger(BzrqjServ.class);
|
|
|
private static final DateTimeFormatter QJ_TIME_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ private static final DateTimeFormatter QJ_TIME_MIN_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
|
|
|
|
|
|
|
|
// 抄自 BzrdmServ.(String) loadBzrdmByMp() < ZGZ:XyService.(String) xy_dm_bjcy_kcbjz() > (String) dm()。Lin
|
|
|
@@ -372,4 +373,217 @@ public class BzrqjServ extends Serv {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public String initRcXjByMp() {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ HttpServletRequest request = super.req;
|
|
|
+ long rcid = rdReqLongParm(request, "rcid", "ssObjId");
|
|
|
+ if (rcid <= 0) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "缺少有效的请假记录ID");
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+
|
|
|
+ try (Db gdba = Db.makeConn()) {
|
|
|
+ UserRunB user = UserU.rdUserByReq(request);
|
|
|
+ Map<String, Object> rcRow = selRcLeaveRow(gdba, rcid);
|
|
|
+ String errMsg = chkRcXjPerm(rcRow, user);
|
|
|
+ if (StringUtils.isNotBlank(errMsg)) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", errMsg);
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+
|
|
|
+ Timestamp kssj = rdTimestamp(rcRow.get("kssj"));
|
|
|
+ Timestamp oldJssj = rdTimestamp(rcRow.get("jssj"));
|
|
|
+ Timestamp now = new Timestamp(System.currentTimeMillis());
|
|
|
+ if (oldJssj == null || !oldJssj.after(now)) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "当前请假已结束,无需销假");
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+ Timestamp nowMinute = floorMinute(now);
|
|
|
+ Timestamp minJssj = calcRcXjMinJssj(kssj, nowMinute);
|
|
|
+
|
|
|
+ result.put("ok", true);
|
|
|
+ result.put("rcid", rcid);
|
|
|
+ result.put("jssj", fmtMinute(oldJssj));
|
|
|
+ result.put("nowTime", fmtMinute(nowMinute));
|
|
|
+ result.put("defaultJssj", fmtMinute(minJssj));
|
|
|
+ result.put("minJssj", fmtMinute(minJssj));
|
|
|
+ result.put("minJssjMsg", rdRcXjMinJssjMsg(kssj, nowMinute));
|
|
|
+ result.put("maxJssj", fmtMinute(oldJssj));
|
|
|
+ result.put("saveServiceName", "rc_xj_tj");
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("BzrqjServ.initRcXjByMp() 异常", e);
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "销假页面初始化失败");
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public String saveRcXjByMp() {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ HttpServletRequest request = super.req;
|
|
|
+ long rcid = rdReqLongParm(request, "rcid", "ssObjId");
|
|
|
+ Timestamp newJssj = rdReqTime(request, "jssj");
|
|
|
+ if (rcid <= 0) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "缺少有效的请假记录ID");
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+ if (newJssj == null) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "请选择销假时间");
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+
|
|
|
+ try (Db gdba = Db.makeConn()) {
|
|
|
+ UserRunB user = UserU.rdUserByReq(request);
|
|
|
+ Map<String, Object> rcRow = selRcLeaveRow(gdba, rcid);
|
|
|
+ String errMsg = chkRcXjPerm(rcRow, user);
|
|
|
+ if (StringUtils.isNotBlank(errMsg)) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", errMsg);
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+
|
|
|
+ Timestamp kssj = rdTimestamp(rcRow.get("kssj"));
|
|
|
+ Timestamp oldJssj = rdTimestamp(rcRow.get("jssj"));
|
|
|
+ Timestamp now = new Timestamp(System.currentTimeMillis());
|
|
|
+ Timestamp nowMinute = floorMinute(now);
|
|
|
+ if (oldJssj == null || !oldJssj.after(now)) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "当前请假已结束,无需销假");
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+ Timestamp minJssj = calcRcXjMinJssj(kssj, nowMinute);
|
|
|
+ if (newJssj.before(minJssj)) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", rdRcXjMinJssjMsg(kssj, nowMinute));
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+ if (newJssj.after(oldJssj)) {
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "销假时间不能晚于原请假结束时间");
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+
|
|
|
+ RcPo rcPo = new RcPo();
|
|
|
+ rcPo.setRcid(rcid);
|
|
|
+ rcPo.setJssj(newJssj);
|
|
|
+ gdba.doUpdPo(rcPo, Set.of("jssj"));
|
|
|
+ gdba.commit();
|
|
|
+
|
|
|
+ result.put("ok", true);
|
|
|
+ result.put("msg", "销假保存成功");
|
|
|
+ result.put("rcid", rcid);
|
|
|
+ result.put("jssj", fmtMinute(newJssj));
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("BzrqjServ.saveRcXjByMp() 异常", e);
|
|
|
+ result.put("ok", false);
|
|
|
+ result.put("msg", "销假保存失败");
|
|
|
+ super.wrJsonByResp(result);
|
|
|
+ return ServC.SERV_notByA;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> selRcLeaveRow(Db gdba, long rcid) throws SQLException {
|
|
|
+ SqlCmd sqlCmd = new SqlCmd("select RCID rcid,KSSJ kssj,JSSJ jssj,RCLBM rclbm,CJRYID cjryid,JLZTM jlztm from RC where RCID=:rcid");
|
|
|
+ sqlCmd.wrLongParm("rcid", rcid);
|
|
|
+ return gdba.doSelMapByC(sqlCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String chkRcXjPerm(Map<String, Object> rcRow, UserRunB user) {
|
|
|
+ if (rcRow == null || rcRow.isEmpty())
|
|
|
+ return "未找到对应的请假记录";
|
|
|
+ if (user == null)
|
|
|
+ return "当前登录状态已失效,请重新进入";
|
|
|
+
|
|
|
+ Object rclbmObj = rcRow.get("rclbm");
|
|
|
+ int rclbm = (rclbmObj == null) ? 0 : Integer.parseInt(String.valueOf(rclbmObj));
|
|
|
+ if (rclbm != RcC.RCLB_sj && rclbm != RcC.RCLB_bj)
|
|
|
+ return "当前记录不是班主任请假记录";
|
|
|
+
|
|
|
+ Object jlztmObj = rcRow.get("jlztm");
|
|
|
+ int jlztm = (jlztmObj == null) ? 0 : Integer.parseInt(String.valueOf(jlztmObj));
|
|
|
+ if (jlztm != ObjC.JLZT_inUse)
|
|
|
+ return "当前请假记录已失效,不能销假";
|
|
|
+
|
|
|
+ Object cjryidObj = rcRow.get("cjryid");
|
|
|
+ long cjryid = (cjryidObj == null) ? 0L : Long.parseLong(String.valueOf(cjryidObj));
|
|
|
+ if (cjryid != user.ryid)
|
|
|
+ return "只能销假自己发起的请假记录";
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private long rdReqLongParm(HttpServletRequest request, String... fieldNameArr) {
|
|
|
+ for (String fieldName : fieldNameArr) {
|
|
|
+ String valStr = request.getParameter(fieldName);
|
|
|
+ if (StringUtils.isBlank(valStr))
|
|
|
+ continue;
|
|
|
+ try {
|
|
|
+ return Long.parseLong(valStr.trim());
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ // 当前字段不是合法 Long 时继续尝试下一个字段。Lin
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Timestamp rdTimestamp(Object value) {
|
|
|
+ if (value instanceof Timestamp)
|
|
|
+ return (Timestamp) value;
|
|
|
+ if (value == null)
|
|
|
+ return null;
|
|
|
+ try {
|
|
|
+ return StrDate.toTimestamp(String.valueOf(value), "yyyy-MM-dd HH:mm:ss");
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Timestamp calcRcXjMinJssj(Timestamp kssj, Timestamp nowMinute) {
|
|
|
+ Timestamp minJssj = nowMinute;
|
|
|
+ Timestamp kssjMinute = floorMinute(kssj);
|
|
|
+ if (kssjMinute != null && kssjMinute.after(minJssj))
|
|
|
+ minJssj = kssjMinute;
|
|
|
+ return minJssj;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String rdRcXjMinJssjMsg(Timestamp kssj, Timestamp nowMinute) {
|
|
|
+ Timestamp kssjMinute = floorMinute(kssj);
|
|
|
+ if (kssjMinute != null && kssjMinute.after(nowMinute))
|
|
|
+ return "销假时间不能早于请假开始时间";
|
|
|
+ return "销假时间不能早于当前时间";
|
|
|
+ }
|
|
|
+
|
|
|
+ private Timestamp floorMinute(Timestamp time) {
|
|
|
+ if (time == null)
|
|
|
+ return null;
|
|
|
+ return Timestamp.valueOf(time.toLocalDateTime().withSecond(0).withNano(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String fmtMinute(Timestamp time) {
|
|
|
+ if (time == null)
|
|
|
+ return "";
|
|
|
+ return time.toLocalDateTime().format(QJ_TIME_MIN_FMT);
|
|
|
+ }
|
|
|
+
|
|
|
}
|