|
|
@@ -13,6 +13,9 @@ import ss.serv.ServC;
|
|
|
import ss.user.UserRunB;
|
|
|
import ss.user.UserU;
|
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 社团(st)直改状态服务。
|
|
|
@@ -32,45 +35,110 @@ public class StServ extends Serv {
|
|
|
/** 停用:在用(51) -> 停用(55),不走流程。 */
|
|
|
@SuppressWarnings("unused")
|
|
|
public String susByA() throws Exception {
|
|
|
- return chgJlztm(ObjC.JLZT_inSus, "停用");
|
|
|
+ return chgJlztm(ObjC.JLZT_inUse, ObjC.JLZT_inSus, "停用");
|
|
|
}
|
|
|
|
|
|
|
|
|
/** 启用:停用(55) -> 在用(51),不走流程。 */
|
|
|
@SuppressWarnings("unused")
|
|
|
public String resByA() throws Exception {
|
|
|
- return chgJlztm(ObjC.JLZT_inUse, "启用");
|
|
|
+ return chgJlztm(ObjC.JLZT_inSus, ObjC.JLZT_inUse, "启用");
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 直接改 社团.记录状态码;顺带写管理人员、管理部门。
|
|
|
- * 记录 ID 参数名:对象主键名 stid(停用/启用确认页按 ssObjIdName 传参),
|
|
|
- * 兜底再取 ssObjId。
|
|
|
+ * 变动:按页面提交的字段直接更新社团基本情况(保持记录状态不变、不走流程)。
|
|
|
+ * 只更新本次真正提交上来的字段,避免把没提交的字段写成 NULL。
|
|
|
*/
|
|
|
- private String chgJlztm(int jlztm, String actMc) throws Exception {
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public String updByA() throws Exception {
|
|
|
HttpServletRequest request = super.req;
|
|
|
|
|
|
try (Db gdba = Db.makeConn()) {
|
|
|
- String idStr = StringUtils.trimToNull(request.getParameter("stid"));
|
|
|
- if (idStr == null)
|
|
|
- idStr = StringUtils.trimToNull(request.getParameter("ssObjId"));
|
|
|
- if (idStr == null)
|
|
|
- throw new IllegalArgumentException("缺少社团ID,无法" + actMc);
|
|
|
+ long stid = rdStid(request, "变动");
|
|
|
+ UserRunB user = UserU.rdUserByReq(request);
|
|
|
+
|
|
|
+ Map<String, Object> sets = new LinkedHashMap<>();
|
|
|
+ String mc = StringUtils.trimToNull(request.getParameter("mc"));
|
|
|
+ if (mc != null)
|
|
|
+ sets.put("MC", mc);
|
|
|
+ Object stlbm = StringUtils.trimToNull(request.getParameter("stlbm"));
|
|
|
+ if (stlbm != null)
|
|
|
+ sets.put("STLBM", stlbm);
|
|
|
+ Object fzryid = StringUtils.trimToNull(request.getParameter("fzryid"));
|
|
|
+ if (fzryid != null)
|
|
|
+ sets.put("FZRYID", fzryid);
|
|
|
+ if (request.getParameter("ms") != null) // 说明允许清空。
|
|
|
+ sets.put("MS", StringUtils.trimToEmpty(request.getParameter("ms")));
|
|
|
+ Object fjid = StringUtils.trimToNull(request.getParameter("fjid"));
|
|
|
+ if (fjid != null)
|
|
|
+ sets.put("FJID", fjid);
|
|
|
+ if (user != null) {
|
|
|
+ sets.put("GLRYID", user.ryid);
|
|
|
+ if (user.bmid != null)
|
|
|
+ sets.put("GLBMID", user.bmid);
|
|
|
+ }
|
|
|
+ if (sets.isEmpty())
|
|
|
+ throw new IllegalArgumentException("没有可更新的内容");
|
|
|
+
|
|
|
+ StringBuilder sqlStr = new StringBuilder("update ST set ");
|
|
|
+ int i = 0;
|
|
|
+ for (String colName : sets.keySet()) {
|
|
|
+ if (i++ > 0)
|
|
|
+ sqlStr.append(", ");
|
|
|
+ sqlStr.append(colName).append("=:").append(colName);
|
|
|
+ }
|
|
|
+ sqlStr.append(" where STID=:stid");
|
|
|
+
|
|
|
+ SqlCmd sqlc = new SqlCmd(sqlStr.toString());
|
|
|
+ for (Map.Entry<String, Object> entry : sets.entrySet()) {
|
|
|
+ if ("MC".equals(entry.getKey()) || "MS".equals(entry.getKey()))
|
|
|
+ sqlc.wrStrParm(entry.getKey(), entry.getValue());
|
|
|
+ else
|
|
|
+ sqlc.wrLongParm(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ sqlc.wrLongParm("stid", stid);
|
|
|
+ gdba.doModByC(sqlc);
|
|
|
+ gdba.commit();
|
|
|
+
|
|
|
+ request.setAttribute(ServC.REQ_msg, "变动成功");
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ request.setAttribute(ServC.REQ_msg, e.getMessage());
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("StServ.updByA() 异常", e);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
|
|
|
- long stid = Long.parseLong(idStr);
|
|
|
+ return WebC.FWD_info; // 回到信息页。
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 直接改 社团.记录状态码;顺带写管理人员、管理部门。
|
|
|
+ * 只在“当前状态 = 期望的源状态”时才更新,避免重复点或状态不符时改错。
|
|
|
+ */
|
|
|
+ private String chgJlztm(int fromJlztm, int toJlztm, String actMc) throws Exception {
|
|
|
+ HttpServletRequest request = super.req;
|
|
|
+
|
|
|
+ try (Db gdba = Db.makeConn()) {
|
|
|
+ long stid = rdStid(request, actMc);
|
|
|
UserRunB user = UserU.rdUserByReq(request);
|
|
|
|
|
|
SqlCmd sqlc = new SqlCmd("update ST set JLZTM=:jlztm, GLRYID=:glryid, GLBMID=:glbmid"
|
|
|
- + " where STID=:stid");
|
|
|
- sqlc.wrIntParm("jlztm", jlztm);
|
|
|
+ + " where STID=:stid and JLZTM=:fromJlztm");
|
|
|
+ sqlc.wrIntParm("jlztm", toJlztm);
|
|
|
sqlc.wrLongParm("glryid", user == null ? null : user.ryid);
|
|
|
sqlc.wrLongParm("glbmid", user == null ? null : user.bmid);
|
|
|
sqlc.wrLongParm("stid", stid);
|
|
|
- gdba.doModByC(sqlc);
|
|
|
+ sqlc.wrIntParm("fromJlztm", fromJlztm);
|
|
|
+ int rowNum = gdba.doModByC(sqlc);
|
|
|
gdba.commit();
|
|
|
|
|
|
- request.setAttribute(ServC.REQ_msg, actMc + "成功");
|
|
|
+ if (rowNum > 0)
|
|
|
+ request.setAttribute(ServC.REQ_msg, actMc + "成功");
|
|
|
+ else
|
|
|
+ throw new IllegalArgumentException("该社团当前状态不允许" + actMc + ",请刷新后重试");
|
|
|
} catch (Exception e) {
|
|
|
log4j.error("StServ.chgJlztm() 异常,actMc=" + actMc, e);
|
|
|
throw e;
|
|
|
@@ -78,4 +146,15 @@ public class StServ extends Serv {
|
|
|
|
|
|
return WebC.FWD_info; // 回到信息页。
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /** 记录 ID 参数名:对象主键名 stid,兜底取 ssObjId。 */
|
|
|
+ private long rdStid(HttpServletRequest request, String actMc) {
|
|
|
+ String idStr = StringUtils.trimToNull(request.getParameter("stid"));
|
|
|
+ if (idStr == null)
|
|
|
+ idStr = StringUtils.trimToNull(request.getParameter("ssObjId"));
|
|
|
+ if (idStr == null)
|
|
|
+ throw new IllegalArgumentException("缺少社团ID,无法" + actMc);
|
|
|
+ return Long.parseLong(idStr);
|
|
|
+ }
|
|
|
}
|