|
|
@@ -0,0 +1,746 @@
|
|
|
+package biz.bjpj;
|
|
|
+
|
|
|
+import base.po.XjbFjjcPo;
|
|
|
+import base.po.XjbFjjcmxPo;
|
|
|
+import base.po.XjbFjjcWjjlPo;
|
|
|
+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.AppB;
|
|
|
+import ss.bpm.Bpm;
|
|
|
+import ss.bpm.BpmAddRunB;
|
|
|
+import ss.bpm.BpmU;
|
|
|
+import ss.db.Db;
|
|
|
+import ss.db.SqlCmd;
|
|
|
+import ss.db.impl.SqPo;
|
|
|
+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.Date;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 星级班风纪仪容检查批次。
|
|
|
+ *
|
|
|
+ * <p>每个班级都会生成一条检查结果,无违纪班级也保留结果记录。具体违纪仍写入
|
|
|
+ * WJJL/WJJLCY,本服务只通过 XJB_FJJC_WJJL 建立关联,不修改违纪和处分结构。</p>
|
|
|
+ */
|
|
|
+public class XjbFjjcServ extends Serv {
|
|
|
+
|
|
|
+ private static final Logger log4j =
|
|
|
+ LogManager.getLogger(XjbFjjcServ.class);
|
|
|
+ private static final ZoneId CN_ZONE = ZoneId.of("Asia/Shanghai");
|
|
|
+ private static final DateTimeFormatter DATE_FMT =
|
|
|
+ DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ private static final String OBJECT_NAME = "fjjc";
|
|
|
+ private static final String BPM_NAME = "fjjc_zj";
|
|
|
+ private static final int RESULT_NO_VIOLATION = 1;
|
|
|
+ private static final int RESULT_HAS_VIOLATION = 2;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化页面需要的检查类型和可检查班级。
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public void initByA() 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 = requireUser(request);
|
|
|
+ long bmid = rdLong(request.getParameter("bmid"), 0L);
|
|
|
+ if (bmid == 0L && user.bmid != null)
|
|
|
+ bmid = user.bmid;
|
|
|
+ Map<Long, Map<String, Object>> classes =
|
|
|
+ loadAllowedClasses(db, user, bmid);
|
|
|
+ Map<String, Object> data = new LinkedHashMap<>();
|
|
|
+ data.put("bmid", bmid);
|
|
|
+ data.put("classes", new ArrayList<>(classes.values()));
|
|
|
+ data.put("types", inspectionTypes());
|
|
|
+ ServU.wrOkDataByWriter(data, writer, gson);
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("XjbFjjcServ.initByA() 异常", e);
|
|
|
+ ServU.wrErrMsgByWriter(null, "风纪检查初始化失败", writer, gson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询本次检查可关联的风纪违纪记录。
|
|
|
+ *
|
|
|
+ * <p>只返回检查日期、责任部门范围内的有效记录。页面用于勾选关联,不能通过
|
|
|
+ * 手工输入主键绕过班级和日期校验。</p>
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public void violationsByA() 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 = requireUser(request);
|
|
|
+ LocalDate inspectionDate = rdDate(request.getParameter("jcrq"));
|
|
|
+ long bmid = rdLong(request.getParameter("bmid"), 0L);
|
|
|
+ if (bmid == 0L && user.bmid != null)
|
|
|
+ bmid = user.bmid;
|
|
|
+ if (bmid == 0L)
|
|
|
+ throw new IllegalArgumentException("请选择责任部门");
|
|
|
+ Map<Long, Map<String, Object>> allowed =
|
|
|
+ loadAllowedClasses(db, user, bmid);
|
|
|
+ Set<Long> requestedClassIds = parseIds(
|
|
|
+ firstNotBlank(request.getParameter("bjidStr"),
|
|
|
+ request.getParameter("bjid")));
|
|
|
+ if (requestedClassIds.isEmpty())
|
|
|
+ requestedClassIds.addAll(allowed.keySet());
|
|
|
+ for (Long classId : requestedClassIds) {
|
|
|
+ if (!allowed.containsKey(classId))
|
|
|
+ throw new IllegalArgumentException("无权查询所选班级的风纪记录");
|
|
|
+ }
|
|
|
+
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select w.WJJLID,w.BJID,b.MC BJMC,w.WJLBM,lb.MC WJLBMC,"
|
|
|
+ + "w.WJSJ,nvl(lb.BJKF,0) BJKF,nvl(w.MS,'') MS,"
|
|
|
+ + "nvl(ry.XM,'') XM"
|
|
|
+ + " from WJJL w"
|
|
|
+ + " inner join WJLB lb on lb.WJLBM=w.WJLBM"
|
|
|
+ + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
|
|
|
+ + " and wm.YTM=:ytm and wm.JLZTM=51"
|
|
|
+ + " inner join BJ b on b.BJID=w.BJID"
|
|
|
+ + " left join RY ry on ry.RYID=nvl(w.RYID,w.FZRYID)"
|
|
|
+ + " where w.JLZTM=51 and w.WJSJ>=:start and w.WJSJ<:end"
|
|
|
+ + " and w.BJID in(" + placeholders(requestedClassIds.size()) + ")"
|
|
|
+ + " order by w.WJSJ desc,w.WJJLID desc");
|
|
|
+ sqlc.wrIntParm("ytm", biz.bj.XjbWjlbC.YTM_DISCIPLINE);
|
|
|
+ sqlc.wrTimeParm("start", Timestamp.valueOf(
|
|
|
+ inspectionDate.atStartOfDay()));
|
|
|
+ sqlc.wrTimeParm("end", Timestamp.valueOf(
|
|
|
+ inspectionDate.plusDays(1).atStartOfDay()));
|
|
|
+ int index = 0;
|
|
|
+ for (Long classId : requestedClassIds)
|
|
|
+ sqlc.wrLongParm("bjid" + (index++), classId);
|
|
|
+ List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (Map<String, Object> row : rows) {
|
|
|
+ Map<String, Object> item = new LinkedHashMap<>();
|
|
|
+ item.put("wjjlid", rdLong(row.get("wjjlid"), 0L));
|
|
|
+ item.put("bjid", rdLong(row.get("bjid"), 0L));
|
|
|
+ item.put("bjmc", String.valueOf(row.get("bjmc")));
|
|
|
+ item.put("wjlbm", rdInt(row.get("wjlbm"), 0));
|
|
|
+ item.put("wjlbmc", String.valueOf(row.get("wjlbmc")));
|
|
|
+ item.put("wjsj", String.valueOf(row.get("wjsj")));
|
|
|
+ item.put("bjfk", rdDouble(row.get("bjfk"), 0.0));
|
|
|
+ item.put("ms", String.valueOf(row.get("ms")));
|
|
|
+ item.put("xm", String.valueOf(row.get("xm")));
|
|
|
+ result.add(item);
|
|
|
+ }
|
|
|
+ Map<String, Object> data = new LinkedHashMap<>();
|
|
|
+ data.put("jcrq", inspectionDate.format(DATE_FMT));
|
|
|
+ data.put("list", result);
|
|
|
+ ServU.wrOkDataByWriter(data, writer, gson);
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("XjbFjjcServ.violationsByA() 异常", e);
|
|
|
+ ServU.wrErrMsgByWriter(null, "可关联风纪记录加载失败", writer, gson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存并提交一次风纪检查。
|
|
|
+ *
|
|
|
+ * <p>参数 bjidStr 为本次检查覆盖的班级,必填;wjjlidStr 为可选的具体违纪
|
|
|
+ * 记录主键列表。未被 wjjlidStr 命中的班级一律保存为“已检查且无违纪”。</p>
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public void saveByA() 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 = requireUser(request);
|
|
|
+ LocalDate inspectionDate = rdDate(request.getParameter("jcrq"));
|
|
|
+ if (inspectionDate.isAfter(LocalDate.now(CN_ZONE)))
|
|
|
+ throw new IllegalArgumentException("不能登记未来日期的风纪检查");
|
|
|
+ int inspectionType = rdInt(request.getParameter("fjlx"), 1);
|
|
|
+ validateInspectionType(inspectionType);
|
|
|
+ long bmid = rdLong(request.getParameter("bmid"), 0L);
|
|
|
+ if (bmid == 0L && user.bmid != null)
|
|
|
+ bmid = user.bmid;
|
|
|
+ if (bmid == 0L)
|
|
|
+ throw new IllegalArgumentException("请选择责任部门");
|
|
|
+
|
|
|
+ Set<Long> requestedClassIds = parseIds(
|
|
|
+ firstNotBlank(request.getParameter("bjidStr"),
|
|
|
+ request.getParameter("bjid")));
|
|
|
+ if (requestedClassIds.isEmpty())
|
|
|
+ throw new IllegalArgumentException("请选择检查班级");
|
|
|
+ Map<Long, Map<String, Object>> allowed =
|
|
|
+ loadAllowedClasses(db, user, bmid);
|
|
|
+ for (Long classId : requestedClassIds) {
|
|
|
+ if (!allowed.containsKey(classId))
|
|
|
+ throw new IllegalArgumentException("无权登记所选班级的风纪检查");
|
|
|
+ }
|
|
|
+ Set<Long> violationIds = parseIds(firstNotBlank(
|
|
|
+ request.getParameter("wjjlidStr"),
|
|
|
+ request.getParameter("wjjlid")));
|
|
|
+ validateViolations(db, bmid, inspectionDate,
|
|
|
+ requestedClassIds, violationIds);
|
|
|
+
|
|
|
+ Timestamp inspectionTime = rdInspectionTime(
|
|
|
+ request.getParameter("jcsj"));
|
|
|
+ String memo = StringUtils.abbreviate(
|
|
|
+ StringUtils.trimToEmpty(request.getParameter("ms")), 1000);
|
|
|
+ Long attachmentId = rdLongOrNull(request.getParameter("fjid"));
|
|
|
+ Map<String, Object> existingHeader = findHeader(db,
|
|
|
+ inspectionDate, inspectionType, bmid);
|
|
|
+ Long existingHeaderId = existingHeader == null ? null
|
|
|
+ : rdLongOrNull(existingHeader.get("xjb_fjjcid"));
|
|
|
+ if (existingHeaderId != null
|
|
|
+ && rdInt(existingHeader.get("jlztm"), 0)
|
|
|
+ == ObjC.JLZT_inUse) {
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "该日期和检查类型的风纪检查已生效,不能重复修改");
|
|
|
+ }
|
|
|
+ boolean newHeader = existingHeaderId == null;
|
|
|
+ long headerId = newHeader
|
|
|
+ ? insertHeader(db, inspectionDate, inspectionTime,
|
|
|
+ inspectionType, user.ryid, bmid, memo,
|
|
|
+ attachmentId, user)
|
|
|
+ : existingHeaderId;
|
|
|
+ if (!newHeader)
|
|
|
+ updateHeader(db, headerId, inspectionTime, memo,
|
|
|
+ attachmentId, user);
|
|
|
+
|
|
|
+ replaceBatchMembership(db, headerId, requestedClassIds);
|
|
|
+ Map<Long, Long> resultIds = new LinkedHashMap<>();
|
|
|
+ for (Long classId : requestedClassIds) {
|
|
|
+ resultIds.put(classId, upsertClassResult(
|
|
|
+ db, headerId, classId, inspectionDate, user));
|
|
|
+ }
|
|
|
+ for (Long violationId : violationIds) {
|
|
|
+ Map<String, Object> violation = rdViolation(db, violationId);
|
|
|
+ long classId = rdLong(violation.get("bjid"), 0L);
|
|
|
+ linkViolation(db, headerId, resultIds.get(classId),
|
|
|
+ violationId);
|
|
|
+ }
|
|
|
+ for (Long classId : requestedClassIds) {
|
|
|
+ recalcClassResult(db, resultIds.get(classId), user);
|
|
|
+ }
|
|
|
+ recalcHeader(db, headerId, user);
|
|
|
+ db.commit();
|
|
|
+
|
|
|
+ boolean processRequired = needsProcessStart(db, headerId);
|
|
|
+ boolean bpmStarted = !processRequired;
|
|
|
+ String warnMsg = null;
|
|
|
+ if (processRequired) {
|
|
|
+ try {
|
|
|
+ startShortProcess(request, headerId, user);
|
|
|
+ bpmStarted = true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ warnMsg = "检查记录已保存,但审批流程启动失败";
|
|
|
+ log4j.error("XjbFjjcServ.saveByA() 启动流程失败,xjb_fjjcid="
|
|
|
+ + headerId, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> data = new LinkedHashMap<>();
|
|
|
+ data.put("xjb_fjjcid", headerId);
|
|
|
+ data.put("jcrq", inspectionDate.format(DATE_FMT));
|
|
|
+ data.put("classCount", requestedClassIds.size());
|
|
|
+ data.put("violationCount", violationIds.size());
|
|
|
+ data.put("newHeader", newHeader);
|
|
|
+ data.put("bpmStarted", bpmStarted);
|
|
|
+ if (warnMsg != null)
|
|
|
+ data.put("warnMsg", warnMsg);
|
|
|
+ ServU.wrOkDataByWriter(data, writer, gson);
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("XjbFjjcServ.saveByA() 异常", e);
|
|
|
+ ServU.wrErrMsgByWriter(null, "风纪检查保存失败", writer, gson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static UserRunB requireUser(HttpServletRequest request) {
|
|
|
+ UserRunB user = UserU.rdUserByReq(request);
|
|
|
+ if (user == null)
|
|
|
+ throw new IllegalArgumentException("登录状态已失效,请重新登录");
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<Map<String, Object>> inspectionTypes() {
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ result.add(type(1, "校门上午"));
|
|
|
+ result.add(type(2, "校门下午"));
|
|
|
+ result.add(type(3, "集队"));
|
|
|
+ result.add(type(4, "政教月检"));
|
|
|
+ result.add(type(5, "其他"));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, Object> type(int code, String name) {
|
|
|
+ Map<String, Object> item = new LinkedHashMap<>();
|
|
|
+ item.put("code", code);
|
|
|
+ item.put("name", name);
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void validateInspectionType(int value) {
|
|
|
+ if (value < 1 || value > 5)
|
|
|
+ throw new IllegalArgumentException("检查类型不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<Long, Map<String, Object>> loadAllowedClasses(
|
|
|
+ Db db, UserRunB user, long bmid) throws Exception {
|
|
|
+ String classFilter = bmid > 0
|
|
|
+ ? "(z.FZBMID=:bmid or b.BZRID=:ryid)"
|
|
|
+ : "b.BZRID=:ryid";
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select b.BJID,b.MC BJMC,nvl(z.FZBMID,:bmid) BMID,"
|
|
|
+ + "nvl(bm.MC,'') BMMC"
|
|
|
+ + " from BJ b left join ZY z on z.ZYID=b.ZYID"
|
|
|
+ + " left join BM bm on bm.BMID=z.FZBMID"
|
|
|
+ + " where b." + ObjC.JLZT_useStr + " and b.BJZTM!=81"
|
|
|
+ + " and " + classFilter + " order by b.MC,b.BJID");
|
|
|
+ if (bmid > 0)
|
|
|
+ sqlc.wrLongParm("bmid", bmid);
|
|
|
+ sqlc.wrLongParm("ryid", user.ryid);
|
|
|
+ Map<Long, Map<String, Object>> result = new LinkedHashMap<>();
|
|
|
+ for (Map<String, Object> row : db.doSelMapListByC(sqlc)) {
|
|
|
+ long classId = rdLong(row.get("bjid"), 0L);
|
|
|
+ if (classId > 0)
|
|
|
+ result.put(classId, row);
|
|
|
+ }
|
|
|
+ if (result.isEmpty())
|
|
|
+ throw new IllegalArgumentException("当前账号没有可检查的班级");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static long insertHeader(Db db, LocalDate inspectionDate,
|
|
|
+ Timestamp inspectionTime,
|
|
|
+ int inspectionType, long inspectorId,
|
|
|
+ long bmid, String memo,
|
|
|
+ Long attachmentId, UserRunB user)
|
|
|
+ throws Exception {
|
|
|
+ long id = db.rdNextSeqVal("XJB_FJJCID");
|
|
|
+ XjbFjjcPo po = new XjbFjjcPo();
|
|
|
+ po.setXjb_fjjcid(id);
|
|
|
+ po.setJcrq(Date.valueOf(inspectionDate));
|
|
|
+ po.setJcsj(inspectionTime);
|
|
|
+ po.setFjlx(inspectionType);
|
|
|
+ po.setJcryid(inspectorId);
|
|
|
+ po.setBmid(bmid);
|
|
|
+ po.setFjfs(100.0);
|
|
|
+ po.setJfkf(0.0);
|
|
|
+ po.setMs(memo);
|
|
|
+ po.setFjid(attachmentId);
|
|
|
+ po.setJlztm(ObjC.JLZT_inAddChk);
|
|
|
+ po.setCjryid(user.ryid);
|
|
|
+ po.setCjsj(new Timestamp(System.currentTimeMillis()));
|
|
|
+ po.setGlryid(user.ryid);
|
|
|
+ po.setGlbmid(bmid);
|
|
|
+ db.doInsPo(po, fields("xjb_fjjcid", "jcrq", "jcsj", "fjlx",
|
|
|
+ "jcryid", "bmid", "fjfs", "jfkf", "ms", "fjid", "jlztm",
|
|
|
+ "cjryid", "cjsj", "glryid", "glbmid"));
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean needsProcessStart(Db db, long headerId)
|
|
|
+ throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select JLZTM,nvl(SHID,'') SHID from XJB_FJJC"
|
|
|
+ + " where XJB_FJJCID=:id");
|
|
|
+ sqlc.wrLongParm("id", headerId);
|
|
|
+ List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
|
|
|
+ if (rows == null || rows.isEmpty())
|
|
|
+ throw new IllegalStateException("风纪检查批次不存在");
|
|
|
+ Map<String, Object> row = rows.get(0);
|
|
|
+ int status = rdInt(row.get("jlztm"), 0);
|
|
|
+ Object processValue = row.get("shid");
|
|
|
+ String processId = processValue == null ? "" : StringUtils.trimToEmpty(
|
|
|
+ String.valueOf(processValue));
|
|
|
+ return status == ObjC.JLZT_inAddChk && processId.isEmpty();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, Object> findHeader(Db db,
|
|
|
+ LocalDate inspectionDate,
|
|
|
+ int inspectionType,
|
|
|
+ long bmid)
|
|
|
+ throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select XJB_FJJCID,JLZTM from XJB_FJJC where JCRQ=:jcrq"
|
|
|
+ + " and FJLX=:fjlx and BMID=:bmid and JLZTM in(21,51)"
|
|
|
+ + " order by case when JLZTM=51 then 0 else 1 end,"
|
|
|
+ + " XJB_FJJCID desc");
|
|
|
+ sqlc.wrTimeParm("jcrq", Timestamp.valueOf(
|
|
|
+ inspectionDate.atStartOfDay()));
|
|
|
+ sqlc.wrIntParm("fjlx", inspectionType);
|
|
|
+ sqlc.wrLongParm("bmid", bmid);
|
|
|
+ List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
|
|
|
+ return rows == null || rows.isEmpty() ? null : rows.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void updateHeader(Db db, long headerId,
|
|
|
+ Timestamp inspectionTime, String memo,
|
|
|
+ Long attachmentId, UserRunB user)
|
|
|
+ throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "update XJB_FJJC set JCSJ=:jcsj,MS=:ms,FJID=:fjid,"
|
|
|
+ + "GLRYID=:glryid,GLBMID=:glbmid"
|
|
|
+ + " where XJB_FJJCID=:id and JLZTM in(21,51)");
|
|
|
+ sqlc.wrTimeParm("jcsj", inspectionTime);
|
|
|
+ sqlc.wrStrParm("ms", memo);
|
|
|
+ sqlc.wrLongParm("fjid", attachmentId);
|
|
|
+ sqlc.wrLongParm("glryid", user.ryid);
|
|
|
+ sqlc.wrLongParm("glbmid", user.bmid);
|
|
|
+ sqlc.wrLongParm("id", headerId);
|
|
|
+ if (db.doModByC(sqlc) != 1)
|
|
|
+ throw new IllegalStateException("风纪检查批次更新失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static long upsertClassResult(Db db, long headerId, long classId,
|
|
|
+ LocalDate inspectionDate,
|
|
|
+ UserRunB user) throws Exception {
|
|
|
+ Long existingId = findClassResultId(db, headerId, classId);
|
|
|
+ if (existingId != null) {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "update XJB_FJJCMX set MS=null,GLRYID=:glryid,"
|
|
|
+ + "GLBMID=:glbmid where XJB_FJJCMXID=:id"
|
|
|
+ + " and JLZTM=51");
|
|
|
+ sqlc.wrLongParm("glryid", user.ryid);
|
|
|
+ sqlc.wrLongParm("glbmid", user.bmid);
|
|
|
+ sqlc.wrLongParm("id", existingId);
|
|
|
+ db.doModByC(sqlc);
|
|
|
+ return existingId;
|
|
|
+ }
|
|
|
+ long id = db.rdNextSeqVal("XJB_FJJCMXID");
|
|
|
+ XjbFjjcmxPo po = new XjbFjjcmxPo();
|
|
|
+ po.setXjb_fjjcmxid(id);
|
|
|
+ po.setXjb_fjjcid(headerId);
|
|
|
+ po.setBjid(classId);
|
|
|
+ po.setJcjg(RESULT_NO_VIOLATION);
|
|
|
+ po.setFjfs(100.0);
|
|
|
+ po.setJfkf(0.0);
|
|
|
+ po.setWjrs(0);
|
|
|
+ po.setJlztm(ObjC.JLZT_inUse);
|
|
|
+ po.setCjrq(Date.valueOf(inspectionDate));
|
|
|
+ po.setCjryid(user.ryid);
|
|
|
+ po.setCjsj(new Timestamp(System.currentTimeMillis()));
|
|
|
+ po.setGlryid(user.ryid);
|
|
|
+ po.setGlbmid(user.bmid);
|
|
|
+ db.doInsPo(po, fields("xjb_fjjcmxid", "xjb_fjjcid", "bjid",
|
|
|
+ "jcjg", "fjfs", "jfkf", "wjrs", "jlztm", "cjrq",
|
|
|
+ "cjryid", "cjsj", "glryid", "glbmid"));
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同一日期、检查类型和责任部门再次保存时,以本次提交作为完整批次。
|
|
|
+ *
|
|
|
+ * <p>先解除旧违纪关联,再删除本次未勾选的旧班级结果,防止已取消的违纪
|
|
|
+ * 或班级继续参与统计。删除范围仅限当前批次,不影响其他检查记录。</p>
|
|
|
+ */
|
|
|
+ private static void replaceBatchMembership(Db db, long headerId,
|
|
|
+ Set<Long> classIds)
|
|
|
+ throws Exception {
|
|
|
+ SqlCmd deleteLinks = new SqlCmd(
|
|
|
+ "delete from XJB_FJJC_WJJL where XJB_FJJCID=:header");
|
|
|
+ deleteLinks.wrLongParm("header", headerId);
|
|
|
+ db.doModByC(deleteLinks);
|
|
|
+
|
|
|
+ SqlCmd deleteClasses = new SqlCmd(
|
|
|
+ "delete from XJB_FJJCMX where XJB_FJJCID=:header"
|
|
|
+ + " and BJID not in(" + placeholders(classIds.size())
|
|
|
+ + ")");
|
|
|
+ deleteClasses.wrLongParm("header", headerId);
|
|
|
+ int index = 0;
|
|
|
+ for (Long classId : classIds)
|
|
|
+ deleteClasses.wrLongParm("bjid" + (index++), classId);
|
|
|
+ db.doModByC(deleteClasses);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Long findClassResultId(Db db, long headerId,
|
|
|
+ long classId) throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select XJB_FJJCMXID from XJB_FJJCMX where XJB_FJJCID=:header"
|
|
|
+ + " and BJID=:bjid and JLZTM=51");
|
|
|
+ sqlc.wrLongParm("header", headerId);
|
|
|
+ sqlc.wrLongParm("bjid", classId);
|
|
|
+ List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
|
|
|
+ return rows == null || rows.isEmpty()
|
|
|
+ ? null : rdLongOrNull(rows.get(0).get("xjb_fjjcmxid"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void validateViolations(Db db, long bmid,
|
|
|
+ LocalDate inspectionDate,
|
|
|
+ Set<Long> classIds,
|
|
|
+ Set<Long> violationIds)
|
|
|
+ throws Exception {
|
|
|
+ for (Long violationId : violationIds) {
|
|
|
+ Map<String, Object> violation = rdViolation(db, violationId);
|
|
|
+ long classId = rdLong(violation.get("bjid"), 0L);
|
|
|
+ if (!classIds.contains(classId))
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "违纪记录 " + violationId + " 不属于本次检查班级");
|
|
|
+ LocalDate violationDate = rdLocalDate(violation.get("wjsj"));
|
|
|
+ if (violationDate == null
|
|
|
+ || !inspectionDate.equals(violationDate))
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "违纪记录 " + violationId + " 的日期与检查日期不一致");
|
|
|
+ if (bmid > 0 && !classBelongsToDepartment(db, classId, bmid))
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "违纪记录 " + violationId + " 不属于当前责任部门");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, Object> rdViolation(Db db, long violationId)
|
|
|
+ throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select w.WJJLID,w.BJID,w.WJSJ,nvl(lb.BJKF,0) BJKF"
|
|
|
+ + " from WJJL w"
|
|
|
+ + " inner join WJLB lb on lb.WJLBM=w.WJLBM"
|
|
|
+ + " inner join XJB_WJLBMAP wm on wm.WJLBM=w.WJLBM"
|
|
|
+ + " and wm.YTM=:ytm and wm.JLZTM=51"
|
|
|
+ + " where w.WJJLID=:id and w.JLZTM=51");
|
|
|
+ sqlc.wrIntParm("ytm", biz.bj.XjbWjlbC.YTM_DISCIPLINE);
|
|
|
+ sqlc.wrLongParm("id", violationId);
|
|
|
+ List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
|
|
|
+ if (rows == null || rows.isEmpty())
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "违纪记录不存在或不属于风纪仪容类别:" + violationId);
|
|
|
+ return rows.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean classBelongsToDepartment(Db db, long classId,
|
|
|
+ long bmid)
|
|
|
+ throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select count(*) CNT from BJ b inner join ZY z on z.ZYID=b.ZYID"
|
|
|
+ + " where b.BJID=:bjid and z.FZBMID=:bmid and b."
|
|
|
+ + ObjC.JLZT_useStr);
|
|
|
+ sqlc.wrLongParm("bjid", classId);
|
|
|
+ sqlc.wrLongParm("bmid", bmid);
|
|
|
+ db.doSelByC(sqlc);
|
|
|
+ return db.rowNum > 0 && db.rdIntCol("cnt") > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void linkViolation(Db db, long headerId, long resultId,
|
|
|
+ long violationId) throws Exception {
|
|
|
+ SqlCmd existing = new SqlCmd(
|
|
|
+ "select XJB_FJJCID,XJB_FJJCMXID from XJB_FJJC_WJJL"
|
|
|
+ + " where WJJLID=:wjjlid");
|
|
|
+ existing.wrLongParm("wjjlid", violationId);
|
|
|
+ List<Map<String, Object>> rows =
|
|
|
+ db.doSelMapListByC(existing);
|
|
|
+ if (rows != null && !rows.isEmpty()) {
|
|
|
+ long linkedHeader = rdLong(rows.get(0).get("xjb_fjjcid"), 0L);
|
|
|
+ long linkedResult = rdLong(
|
|
|
+ rows.get(0).get("xjb_fjjcmxid"), 0L);
|
|
|
+ if (linkedHeader == headerId && linkedResult == resultId)
|
|
|
+ return;
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "违纪记录已关联其他风纪检查:" + violationId);
|
|
|
+ }
|
|
|
+ XjbFjjcWjjlPo po = new XjbFjjcWjjlPo();
|
|
|
+ po.setXjb_fjjc_wjjlid(db.rdNextSeqVal("XJB_FJJC_WJJLID"));
|
|
|
+ po.setXjb_fjjcid(headerId);
|
|
|
+ po.setXjb_fjjcmxid(resultId);
|
|
|
+ po.setWjjlid(violationId);
|
|
|
+ po.setCjsj(new Timestamp(System.currentTimeMillis()));
|
|
|
+ db.doInsPo(po, fields("xjb_fjjc_wjjlid", "xjb_fjjcid",
|
|
|
+ "xjb_fjjcmxid", "wjjlid", "cjsj"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void recalcClassResult(Db db, long resultId,
|
|
|
+ UserRunB user) throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select count(*) WJRS,nvl(sum(nvl(lb.BJKF,0)),0) JFKF"
|
|
|
+ + " from XJB_FJJC_WJJL x"
|
|
|
+ + " inner join WJJL w on w.WJJLID=x.WJJLID"
|
|
|
+ + " inner join WJLB lb on lb.WJLBM=w.WJLBM"
|
|
|
+ + " where x.XJB_FJJCMXID=:id and w.JLZTM=51");
|
|
|
+ sqlc.wrLongParm("id", resultId);
|
|
|
+ List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
|
|
|
+ Map<String, Object> row = rows == null || rows.isEmpty()
|
|
|
+ ? Map.of() : rows.get(0);
|
|
|
+ int violations = rdInt(row.get("wjrs"), 0);
|
|
|
+ double penalty = rdDouble(row.get("jfkf"), 0.0);
|
|
|
+ int result = violations > 0 || penalty > 0.0
|
|
|
+ ? RESULT_HAS_VIOLATION : RESULT_NO_VIOLATION;
|
|
|
+ SqlCmd update = new SqlCmd(
|
|
|
+ "update XJB_FJJCMX set JCJG=:jcjg,FJFS=:fjfs,JFKF=:jfkf,"
|
|
|
+ + "WJRS=:wjrs,GLRYID=:glryid,GLBMID=:glbmid"
|
|
|
+ + " where XJB_FJJCMXID=:id and JLZTM=51");
|
|
|
+ update.wrIntParm("jcjg", result);
|
|
|
+ update.wrDblParm("fjfs", Math.max(0.0, 100.0 - penalty));
|
|
|
+ update.wrDblParm("jfkf", penalty);
|
|
|
+ update.wrIntParm("wjrs", violations);
|
|
|
+ update.wrLongParm("glryid", user.ryid);
|
|
|
+ update.wrLongParm("glbmid", user.bmid);
|
|
|
+ update.wrLongParm("id", resultId);
|
|
|
+ if (db.doModByC(update) != 1)
|
|
|
+ throw new IllegalStateException("风纪检查班级结果更新失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void recalcHeader(Db db, long headerId, UserRunB user)
|
|
|
+ throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select nvl(sum(nvl(JFKF,0)),0) JFKF from XJB_FJJCMX"
|
|
|
+ + " where XJB_FJJCID=:id and JLZTM=51");
|
|
|
+ sqlc.wrLongParm("id", headerId);
|
|
|
+ List<Map<String, Object>> rows = db.doSelMapListByC(sqlc);
|
|
|
+ double penalty = rows == null || rows.isEmpty()
|
|
|
+ ? 0.0 : rdDouble(rows.get(0).get("jfkf"), 0.0);
|
|
|
+ SqlCmd update = new SqlCmd(
|
|
|
+ "update XJB_FJJC set FJFS=:fjfs,JFKF=:jfkf,"
|
|
|
+ + "GLRYID=:glryid,GLBMID=:glbmid"
|
|
|
+ + " where XJB_FJJCID=:id and JLZTM in(21,51)");
|
|
|
+ update.wrDblParm("fjfs", Math.max(0.0, 100.0 - penalty));
|
|
|
+ update.wrDblParm("jfkf", penalty);
|
|
|
+ update.wrLongParm("glryid", user.ryid);
|
|
|
+ update.wrLongParm("glbmid", user.bmid);
|
|
|
+ update.wrLongParm("id", headerId);
|
|
|
+ if (db.doModByC(update) != 1)
|
|
|
+ throw new IllegalStateException("风纪检查批次汇总更新失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startShortProcess(HttpServletRequest request, long headerId,
|
|
|
+ UserRunB user) throws Exception {
|
|
|
+ XjbFjjcPo po = new XjbFjjcPo();
|
|
|
+ po.setXjb_fjjcid(headerId);
|
|
|
+ SqPo sq = new SqPo();
|
|
|
+ sq.setDxm(OBJECT_NAME);
|
|
|
+ sq.setMc("提交风纪仪容检查");
|
|
|
+ BpmU.saveSq(null, po, AppB.objMap.get(OBJECT_NAME),
|
|
|
+ ss.bpm.BpmC.CHG_addType, null, user.ryid, null,
|
|
|
+ OBJECT_NAME, headerId, null, request);
|
|
|
+ Bpm.doStartBpm(BPM_NAME, po, sq, new LinkedHashMap<>(),
|
|
|
+ new BpmAddRunB(), user.ryid, request, super.resp);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Set<String> fields(String... names) {
|
|
|
+ return new LinkedHashSet<>(Arrays.asList(names));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String placeholders(int count) {
|
|
|
+ if (count <= 0)
|
|
|
+ throw new IllegalArgumentException("请选择检查班级");
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
+ for (int i = 0; i < count; i++) {
|
|
|
+ if (i > 0)
|
|
|
+ result.append(',');
|
|
|
+ result.append(":bjid").append(i);
|
|
|
+ }
|
|
|
+ return result.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Set<Long> parseIds(String value) {
|
|
|
+ Set<Long> result = new LinkedHashSet<>();
|
|
|
+ String text = StringUtils.trimToEmpty(value);
|
|
|
+ if (text.isEmpty())
|
|
|
+ return result;
|
|
|
+ for (String part : text.split("[,|]")) {
|
|
|
+ String item = StringUtils.trimToNull(part);
|
|
|
+ if (item == null)
|
|
|
+ continue;
|
|
|
+ try {
|
|
|
+ long id = Long.parseLong(item);
|
|
|
+ if (id > 0)
|
|
|
+ result.add(id);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new IllegalArgumentException("编号格式错误:" + item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static LocalDate rdDate(String value) {
|
|
|
+ String text = StringUtils.trimToNull(value);
|
|
|
+ if (text == null)
|
|
|
+ return LocalDate.now(CN_ZONE);
|
|
|
+ try {
|
|
|
+ return LocalDate.parse(text, DATE_FMT);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IllegalArgumentException("检查日期格式错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Timestamp rdInspectionTime(String value) {
|
|
|
+ String text = StringUtils.trimToNull(value);
|
|
|
+ if (text == null)
|
|
|
+ return new Timestamp(System.currentTimeMillis());
|
|
|
+ try {
|
|
|
+ if (text.length() == 10)
|
|
|
+ return Timestamp.valueOf(LocalDate.parse(text, DATE_FMT)
|
|
|
+ .atTime(LocalDateTime.now(CN_ZONE).toLocalTime()));
|
|
|
+ return Timestamp.valueOf(text.replace('T', ' '));
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IllegalArgumentException("检查时间格式错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static LocalDate rdLocalDate(Object value) {
|
|
|
+ if (value instanceof Timestamp timestamp)
|
|
|
+ return timestamp.toLocalDateTime().toLocalDate();
|
|
|
+ if (value instanceof Date date)
|
|
|
+ return date.toLocalDate();
|
|
|
+ if (value instanceof java.util.Date date)
|
|
|
+ return new Timestamp(date.getTime()).toLocalDateTime().toLocalDate();
|
|
|
+ String text = StringUtils.trimToNull(
|
|
|
+ value == null ? null : String.valueOf(value));
|
|
|
+ if (text == null)
|
|
|
+ return null;
|
|
|
+ return LocalDate.parse(text.substring(0, Math.min(10, text.length())),
|
|
|
+ DATE_FMT);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 Long rdLongOrNull(Object value) {
|
|
|
+ long parsed = rdLong(value, 0L);
|
|
|
+ return parsed == 0L ? null : parsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int rdInt(Object value, int defaultValue) {
|
|
|
+ return (int) rdLong(value, defaultValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static double rdDouble(Object value, double defaultValue) {
|
|
|
+ if (value == null)
|
|
|
+ return defaultValue;
|
|
|
+ String text = StringUtils.trimToNull(String.valueOf(value));
|
|
|
+ return text == null ? defaultValue : Double.parseDouble(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String firstNotBlank(String value, String fallback) {
|
|
|
+ return StringUtils.defaultIfBlank(value, fallback);
|
|
|
+ }
|
|
|
+}
|