|
|
@@ -2,11 +2,14 @@ package biz.xygz;
|
|
|
|
|
|
import base.po.RcPo;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import jakarta.servlet.http.HttpSession;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
import ss.bpm.Bpm;
|
|
|
import ss.bpm.BpmAddRunB;
|
|
|
+import ss.bpm.BpmC;
|
|
|
+import ss.bpm.ChgFieldB;
|
|
|
import ss.AppB;
|
|
|
import ss.WebC;
|
|
|
import ss.cmn.str.StrDate;
|
|
|
@@ -19,10 +22,14 @@ import ss.serv.ServC;
|
|
|
import ss.user.UserRunB;
|
|
|
import ss.user.UserU;
|
|
|
|
|
|
+import java.io.Serializable;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -36,6 +43,9 @@ public class TtZbServ extends Serv {
|
|
|
private static final Logger log4j = LogManager.getLogger(TtZbServ.class);
|
|
|
private static final String BPM_XYTTZB_ZJ = "xyttZb_zj";
|
|
|
private static final String BPM_XYTTZB_BD = "xyttZb_bd";
|
|
|
+ private static final String SESS_DUTY_PENDING_CHANGE =
|
|
|
+ TtZbServ.class.getName() + ".dutyPendingChange";
|
|
|
+ private static final long DUTY_PENDING_TTL_MILLIS = 30L * 60L * 1000L;
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
private String obj;
|
|
|
@@ -145,7 +155,70 @@ public class TtZbServ extends Serv {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * “保存并提交”才正式同步值班人员并启动变动流程。
|
|
|
+ * 第一次点击“保存并提交”只生成变动预览,不修改 RC/RCCY,也不启动流程。
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public String previewChgByA() throws Exception {
|
|
|
+ HttpServletRequest request = super.req;
|
|
|
+
|
|
|
+ try (Db gdba = Db.makeConn()) {
|
|
|
+ long rcid = rdRcid(request, "预览变动");
|
|
|
+ UserRunB user = requireUser(request);
|
|
|
+ Map<String, Object> vals = rdBaseVals(request);
|
|
|
+ DutyMainState current = validateBaseInfoChange(gdba, rcid, user, vals);
|
|
|
+ TtZbMemberServ memberServ = new TtZbMemberServ();
|
|
|
+ TtZbMemberServ.DutyMemberSnapshot members =
|
|
|
+ memberServ.previewMembers(gdba, rcid, user);
|
|
|
+
|
|
|
+ boolean baseChanged = hasBaseChanges(current, vals);
|
|
|
+ if (!baseChanged && !members.changed()) {
|
|
|
+ clearPendingChange(request);
|
|
|
+ request.setAttribute(ServC.REQ_msg, "值班信息未发生变化,无需重复提交");
|
|
|
+ return WebC.FWD_info;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ChgFieldB> bdList = new ArrayList<>();
|
|
|
+ addBaseChanges(bdList, gdba, current, vals);
|
|
|
+ if (members.changed())
|
|
|
+ bdList.add(memberChangeField(members));
|
|
|
+
|
|
|
+ DutyPendingChange pending = new DutyPendingChange();
|
|
|
+ pending.createdAt = System.currentTimeMillis();
|
|
|
+ pending.rcid = rcid;
|
|
|
+ pending.userId = user.ryid;
|
|
|
+ pending.oldTtid = current.ttid;
|
|
|
+ pending.oldName = current.name;
|
|
|
+ pending.oldStart = current.startTime;
|
|
|
+ pending.oldEnd = current.endTime;
|
|
|
+ pending.newTtid = (Long) vals.getOrDefault("DXID", current.ttid);
|
|
|
+ pending.newName = (String) vals.getOrDefault("MC", current.name);
|
|
|
+ pending.newStart = (Timestamp) vals.getOrDefault("KSSJ", current.startTime);
|
|
|
+ pending.newEnd = (Timestamp) vals.getOrDefault("JSSJ", current.endTime);
|
|
|
+ pending.oldMemberIds = new ArrayList<>(members.originalIds);
|
|
|
+ pending.newMemberIds = new ArrayList<>(members.selectedIds);
|
|
|
+ pending.hasMemberDraft = members.hasDraft;
|
|
|
+ pending.memberChanged = members.changed();
|
|
|
+ request.getSession().setAttribute(SESS_DUTY_PENDING_CHANGE, pending);
|
|
|
+
|
|
|
+ request.setAttribute("bdList", bdList);
|
|
|
+ request.setAttribute(WebC.REQ_objName, "xyttZb");
|
|
|
+ request.setAttribute(WebC.REQ_objId, String.valueOf(rcid));
|
|
|
+ request.setAttribute(WebC.REQ_objIdName, "rcid");
|
|
|
+ request.setAttribute("rcid", rcid);
|
|
|
+ request.setAttribute(BpmC.REQ_bpmDesc, "值班变动确认");
|
|
|
+ return WebC.FWD_def;
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ request.setAttribute(ServC.REQ_msg, e.getMessage());
|
|
|
+ return WebC.FWD_info;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("TtZbServ.previewChgByA() 异常", e);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 变动确认页点击“确定”后,才正式同步值班人员并启动变动流程。
|
|
|
*/
|
|
|
@SuppressWarnings("unused")
|
|
|
public String submChgByA() throws Exception {
|
|
|
@@ -153,24 +226,43 @@ public class TtZbServ extends Serv {
|
|
|
|
|
|
try (Db gdba = Db.makeConn()) {
|
|
|
long rcid = rdRcid(request, "提交变动");
|
|
|
- UserRunB user = UserU.rdUserByReq(request);
|
|
|
+ UserRunB user = requireUser(request);
|
|
|
+ DutyPendingChange pending = rdPendingChange(request, user, rcid);
|
|
|
+ Map<String, Object> vals = pending.toBaseVals();
|
|
|
+ DutyMainState current = validateBaseInfoChange(gdba, rcid, user, vals);
|
|
|
+ if (!matchesPending(current, pending)) {
|
|
|
+ clearPendingChange(request);
|
|
|
+ throw new IllegalArgumentException("值班记录已被修改,请返回重新提交");
|
|
|
+ }
|
|
|
+
|
|
|
TtZbMemberServ memberServ = new TtZbMemberServ();
|
|
|
- boolean hasMemberDraft = memberServ.hasDraft(gdba, rcid, user);
|
|
|
- if (!hasMemberDraft && !hasBaseChanges(gdba, rcid, request)) {
|
|
|
+ TtZbMemberServ.DutyMemberSnapshot members =
|
|
|
+ memberServ.previewMembers(gdba, rcid, user);
|
|
|
+ if (!members.originalIds.equals(pending.oldMemberIds)
|
|
|
+ || !members.selectedIds.equals(pending.newMemberIds)) {
|
|
|
+ clearPendingChange(request);
|
|
|
+ throw new IllegalArgumentException("值班人员已发生变化,请返回重新提交");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean baseChanged = hasBaseChanges(current, vals);
|
|
|
+ if (!baseChanged && !pending.memberChanged) {
|
|
|
+ clearPendingChange(request);
|
|
|
request.setAttribute(ServC.REQ_msg, "值班信息未发生变化,无需重复提交");
|
|
|
return WebC.FWD_info;
|
|
|
}
|
|
|
|
|
|
- updateBaseInfo(gdba, rcid, user, request);
|
|
|
+ writeBaseInfo(gdba, rcid, user, vals);
|
|
|
|
|
|
// 没有人员草稿时保持现有 RCCY 和值班主任顺序,避免仅修改基本信息时重排人员。
|
|
|
- if (hasMemberDraft)
|
|
|
+ if (pending.hasMemberDraft)
|
|
|
memberServ.syncDraftToMembers(gdba, rcid, user);
|
|
|
gdba.commit();
|
|
|
|
|
|
startFlow(gdba, rcid, false, user, request);
|
|
|
- memberServ.clearDraft(gdba, rcid, user);
|
|
|
+ if (pending.hasMemberDraft)
|
|
|
+ memberServ.clearDraft(gdba, rcid, user);
|
|
|
gdba.commit();
|
|
|
+ clearPendingChange(request);
|
|
|
request.setAttribute(ServC.REQ_msg, "提交成功");
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
request.setAttribute(ServC.REQ_msg, e.getMessage());
|
|
|
@@ -186,10 +278,19 @@ public class TtZbServ extends Serv {
|
|
|
|
|
|
private void updateBaseInfo(Db gdba, long rcid, UserRunB user,
|
|
|
HttpServletRequest request) throws Exception {
|
|
|
+ Map<String, Object> vals = rdBaseVals(request);
|
|
|
+ validateBaseInfoChange(gdba, rcid, user, vals);
|
|
|
+ writeBaseInfo(gdba, rcid, user, vals);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private DutyMainState validateBaseInfoChange(Db gdba, long rcid,
|
|
|
+ UserRunB user,
|
|
|
+ Map<String, Object> vals)
|
|
|
+ throws Exception {
|
|
|
if (user == null)
|
|
|
throw new IllegalArgumentException("登录状态已失效,请重新登录");
|
|
|
|
|
|
- Map<String, Object> vals = rdBaseVals(request);
|
|
|
DutyMainState current = loadDutyMain(gdba, rcid);
|
|
|
boolean ended = current.endTime != null
|
|
|
&& !current.endTime.after(new Timestamp(System.currentTimeMillis()));
|
|
|
@@ -220,6 +321,15 @@ public class TtZbServ extends Serv {
|
|
|
throw new IllegalArgumentException("值班已结束,不能修改结束时间");
|
|
|
}
|
|
|
|
|
|
+ return current;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void writeBaseInfo(Db gdba, long rcid, UserRunB user,
|
|
|
+ Map<String, Object> vals) throws Exception {
|
|
|
+ if (user == null)
|
|
|
+ throw new IllegalArgumentException("登录状态已失效,请重新登录");
|
|
|
+
|
|
|
vals.put("DXM", "xshZb");
|
|
|
vals.put("RCLBM", 75);
|
|
|
vals.put("GLRYID", user.ryid);
|
|
|
@@ -263,6 +373,15 @@ public class TtZbServ extends Serv {
|
|
|
SqPo sq = new SqPo();
|
|
|
sq.setDxm("xyttZb");
|
|
|
sq.setMc((isNew ? "增加" : "变动") + "值班(" + rc.getMc() + ")");
|
|
|
+ String sqMc = StringUtils.trimToNull(request.getParameter(BpmC.REQ_sqMc));
|
|
|
+ if (sqMc != null)
|
|
|
+ sq.setMc(sqMc);
|
|
|
+ String sqMswj = StringUtils.trimToNull(request.getParameter(BpmC.REQ_sqMswj));
|
|
|
+ if (sqMswj != null)
|
|
|
+ sq.setMswj(sqMswj);
|
|
|
+ String sqFjid = StringUtils.trimToNull(request.getParameter(BpmC.REQ_sqFjid));
|
|
|
+ if (sqFjid != null)
|
|
|
+ sq.setFjid(Long.parseLong(sqFjid));
|
|
|
String bpmName = isNew ? BPM_XYTTZB_ZJ : BPM_XYTTZB_BD;
|
|
|
if (AppB.bpmMap.get(bpmName) == null)
|
|
|
throw new IllegalStateException("值班流程未配置:" + bpmName);
|
|
|
@@ -407,14 +526,21 @@ public class TtZbServ extends Serv {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private boolean hasBaseChanges(Db gdba, long rcid, HttpServletRequest request)
|
|
|
- throws Exception {
|
|
|
- Map<String, Object> vals = rdBaseVals(request);
|
|
|
- DutyMainState current = loadDutyMain(gdba, rcid);
|
|
|
+ private UserRunB requireUser(HttpServletRequest request) {
|
|
|
+ UserRunB user = UserU.rdUserByReq(request);
|
|
|
+ if (user == null)
|
|
|
+ throw new IllegalArgumentException("登录状态已失效,请重新登录");
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- if (vals.containsKey("DXID") && !vals.get("DXID").equals(current.ttid))
|
|
|
+ private boolean hasBaseChanges(DutyMainState current,
|
|
|
+ Map<String, Object> vals) {
|
|
|
+ if (vals.containsKey("DXID")
|
|
|
+ && !Objects.equals(vals.get("DXID"), current.ttid))
|
|
|
return true;
|
|
|
- if (vals.containsKey("MC") && !vals.get("MC").equals(current.name))
|
|
|
+ if (vals.containsKey("MC")
|
|
|
+ && !Objects.equals(vals.get("MC"), current.name))
|
|
|
return true;
|
|
|
if (vals.containsKey("KSSJ")
|
|
|
&& !sameTime((Timestamp) vals.get("KSSJ"), current.startTime))
|
|
|
@@ -424,6 +550,112 @@ public class TtZbServ extends Serv {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private void addBaseChanges(List<ChgFieldB> bdList, Db gdba,
|
|
|
+ DutyMainState current,
|
|
|
+ Map<String, Object> vals) throws Exception {
|
|
|
+ Long newTtid = (Long) vals.getOrDefault("DXID", current.ttid);
|
|
|
+ if (!Objects.equals(newTtid, current.ttid)) {
|
|
|
+ addChange(bdList, "dxid", "所属团体",
|
|
|
+ loadTtName(gdba, current.ttid), loadTtName(gdba, newTtid),
|
|
|
+ ObjC.FIELD_txtType, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ String newName = (String) vals.getOrDefault("MC", current.name);
|
|
|
+ if (!Objects.equals(newName, current.name)) {
|
|
|
+ addChange(bdList, "mc", "值班名称", current.name, newName,
|
|
|
+ ObjC.FIELD_txtType, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ Timestamp newStart = (Timestamp) vals.getOrDefault("KSSJ", current.startTime);
|
|
|
+ if (!sameTime(newStart, current.startTime)) {
|
|
|
+ addChange(bdList, "kssj", "开始时间",
|
|
|
+ current.startTime, newStart, ObjC.FIELD_timeType,
|
|
|
+ "yyyy-MM-dd HH:mm");
|
|
|
+ }
|
|
|
+
|
|
|
+ Timestamp newEnd = (Timestamp) vals.getOrDefault("JSSJ", current.endTime);
|
|
|
+ if (!sameTime(newEnd, current.endTime)) {
|
|
|
+ addChange(bdList, "jssj", "结束时间",
|
|
|
+ current.endTime, newEnd, ObjC.FIELD_timeType,
|
|
|
+ "yyyy-MM-dd HH:mm");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private ChgFieldB memberChangeField(TtZbMemberServ.DutyMemberSnapshot members) {
|
|
|
+ ChgFieldB field = new ChgFieldB();
|
|
|
+ field.name = "rccyMembers";
|
|
|
+ field.desc = "值班人员";
|
|
|
+ field.type = ObjC.FIELD_txtType;
|
|
|
+ field.origVal = members.originalNames;
|
|
|
+ field.newVal = members.selectedNames;
|
|
|
+ return field;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void addChange(List<ChgFieldB> bdList, String name, String desc,
|
|
|
+ Object origVal, Object newVal, int type, String fmt) {
|
|
|
+ ChgFieldB field = new ChgFieldB();
|
|
|
+ field.name = name;
|
|
|
+ field.desc = desc;
|
|
|
+ field.type = type;
|
|
|
+ field.origVal = displayValue(origVal);
|
|
|
+ field.newVal = displayValue(newVal);
|
|
|
+ field.fmt = fmt;
|
|
|
+ bdList.add(field);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String displayValue(Object value) {
|
|
|
+ if (value == null || StringUtils.isBlank(String.valueOf(value)))
|
|
|
+ return "(无)";
|
|
|
+ return String.valueOf(value);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String loadTtName(Db gdba, Long ttid) throws Exception {
|
|
|
+ if (ttid == null)
|
|
|
+ return "(无)";
|
|
|
+ SqlCmd cmd = new SqlCmd("select MC from TT where TTID=:ttid");
|
|
|
+ cmd.wrLongParm("ttid", ttid);
|
|
|
+ gdba.doSelByC(cmd);
|
|
|
+ return gdba.rowNum == 0 ? String.valueOf(ttid) : gdba.rdStrCol("mc");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private boolean matchesPending(DutyMainState current,
|
|
|
+ DutyPendingChange pending) {
|
|
|
+ return Objects.equals(current.ttid, pending.oldTtid)
|
|
|
+ && Objects.equals(current.name, pending.oldName)
|
|
|
+ && sameTime(current.startTime, pending.oldStart)
|
|
|
+ && sameTime(current.endTime, pending.oldEnd);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private DutyPendingChange rdPendingChange(HttpServletRequest request,
|
|
|
+ UserRunB user, long rcid) {
|
|
|
+ HttpSession session = request.getSession(false);
|
|
|
+ Object value = session == null ? null
|
|
|
+ : session.getAttribute(SESS_DUTY_PENDING_CHANGE);
|
|
|
+ if (!(value instanceof DutyPendingChange pending))
|
|
|
+ throw new IllegalArgumentException("变动确认信息已失效,请返回重新提交");
|
|
|
+ if (pending.userId != user.ryid || pending.rcid != rcid)
|
|
|
+ throw new IllegalArgumentException("变动确认信息与当前用户或值班记录不一致,请返回重新提交");
|
|
|
+ if (System.currentTimeMillis() - pending.createdAt > DUTY_PENDING_TTL_MILLIS) {
|
|
|
+ clearPendingChange(request);
|
|
|
+ throw new IllegalArgumentException("变动确认信息已过期,请返回重新提交");
|
|
|
+ }
|
|
|
+ return pending;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void clearPendingChange(HttpServletRequest request) {
|
|
|
+ HttpSession session = request.getSession(false);
|
|
|
+ if (session != null)
|
|
|
+ session.removeAttribute(SESS_DUTY_PENDING_CHANGE);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private boolean sameTime(Timestamp left, Timestamp right) {
|
|
|
return left == null ? right == null : left.equals(right);
|
|
|
}
|
|
|
@@ -513,6 +745,36 @@ public class TtZbServ extends Serv {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private static final class DutyPendingChange implements Serializable {
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+
|
|
|
+ long rcid;
|
|
|
+ long userId;
|
|
|
+ long createdAt;
|
|
|
+ Long oldTtid;
|
|
|
+ String oldName;
|
|
|
+ Timestamp oldStart;
|
|
|
+ Timestamp oldEnd;
|
|
|
+ Long newTtid;
|
|
|
+ String newName;
|
|
|
+ Timestamp newStart;
|
|
|
+ Timestamp newEnd;
|
|
|
+ List<Long> oldMemberIds;
|
|
|
+ List<Long> newMemberIds;
|
|
|
+ boolean hasMemberDraft;
|
|
|
+ boolean memberChanged;
|
|
|
+
|
|
|
+ Map<String, Object> toBaseVals() {
|
|
|
+ Map<String, Object> vals = new LinkedHashMap<>();
|
|
|
+ vals.put("DXID", newTtid);
|
|
|
+ vals.put("MC", newName);
|
|
|
+ vals.put("KSSJ", newStart);
|
|
|
+ vals.put("JSSJ", newEnd);
|
|
|
+ return vals;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private static final class DutyMainState {
|
|
|
Long ttid;
|
|
|
String name;
|