Browse Source

feat: add BJPB dual-write mirror and compensation

apple 2 weeks ago
parent
commit
bc44d8bade

+ 252 - 0
src/base/po/BjpbPo.java

@@ -0,0 +1,252 @@
+package base.po;
+
+import java.sql.Timestamp;
+import java.util.Map;
+
+import ss.db.DbC;
+import ss.db.Po;
+
+/**
+ * 班级评比主表。
+ */
+public class BjpbPo extends Po {
+    {
+        super.fieldTypeMap = Map.<String, Integer>ofEntries(
+                Map.entry("bjpbid", DbC.PO_longType),
+                Map.entry("bmid", DbC.PO_LongType),
+                Map.entry("jcryid", DbC.PO_longType),
+                Map.entry("bjid", DbC.PO_longType),
+                Map.entry("bjpblbm", DbC.PO_intType),
+                Map.entry("jzwid", DbC.PO_LongType),
+                Map.entry("cdid", DbC.PO_LongType),
+                Map.entry("zfs", DbC.PO_floatType),
+                Map.entry("cql", DbC.PO_floatType),
+                Map.entry("kqfs", DbC.PO_floatType),
+                Map.entry("dlfs", DbC.PO_floatType),
+                Map.entry("fmfs", DbC.PO_floatType),
+                Map.entry("jlfs", DbC.PO_floatType),
+                Map.entry("sfypfj", DbC.PO_booleanType),
+                Map.entry("ms", DbC.PO_StringType),
+                Map.entry("mswj", DbC.PO_StringType),
+                Map.entry("fjid", DbC.PO_LongType),
+                Map.entry("jcsj", DbC.PO_TimestampType),
+                Map.entry("jlztm", DbC.PO_intType),
+                Map.entry("cjryid", DbC.PO_LongType),
+                Map.entry("glryid", DbC.PO_LongType),
+                Map.entry("glbmid", DbC.PO_LongType));
+    }
+
+    private long bjpbid;
+    private Long bmid;
+    private long jcryid;
+    private long bjid;
+    private int bjpblbm;
+    private Long jzwid;
+    private Long cdid;
+    private float zfs;
+    private float cql;
+    private float kqfs;
+    private float dlfs;
+    private float fmfs;
+    private float jlfs;
+    private int sfypfj;
+    private String ms;
+    private String mswj;
+    private Long fjid;
+    private Timestamp jcsj;
+    private int jlztm;
+    private Long cjryid;
+    private Long glryid;
+    private Long glbmid;
+
+    public BjpbPo() {
+        super.tabName = "bjpb";
+        super.idName = "bjpbid";
+    }
+
+    @Override
+    public long rdIdVal() {
+        return bjpbid;
+    }
+
+    @Override
+    public void wrIdVal(long id) {
+        bjpbid = id;
+    }
+
+    public long getBjpbid() {
+        return bjpbid;
+    }
+
+    public void setBjpbid(long v) {
+        bjpbid = v;
+    }
+
+    public Long getBmid() {
+        return bmid;
+    }
+
+    public void setBmid(Long v) {
+        bmid = v;
+    }
+
+    public long getJcryid() {
+        return jcryid;
+    }
+
+    public void setJcryid(long v) {
+        jcryid = v;
+    }
+
+    public long getBjid() {
+        return bjid;
+    }
+
+    public void setBjid(long v) {
+        bjid = v;
+    }
+
+    public int getBjpblbm() {
+        return bjpblbm;
+    }
+
+    public void setBjpblbm(int v) {
+        bjpblbm = v;
+    }
+
+    public Long getJzwid() {
+        return jzwid;
+    }
+
+    public void setJzwid(Long v) {
+        jzwid = v;
+    }
+
+    public Long getCdid() {
+        return cdid;
+    }
+
+    public void setCdid(Long v) {
+        cdid = v;
+    }
+
+    public float getZfs() {
+        return zfs;
+    }
+
+    public void setZfs(float v) {
+        zfs = v;
+    }
+
+    public float getCql() {
+        return cql;
+    }
+
+    public void setCql(float v) {
+        cql = v;
+    }
+
+    public float getKqfs() {
+        return kqfs;
+    }
+
+    public void setKqfs(float v) {
+        kqfs = v;
+    }
+
+    public float getDlfs() {
+        return dlfs;
+    }
+
+    public void setDlfs(float v) {
+        dlfs = v;
+    }
+
+    public float getFmfs() {
+        return fmfs;
+    }
+
+    public void setFmfs(float v) {
+        fmfs = v;
+    }
+
+    public float getJlfs() {
+        return jlfs;
+    }
+
+    public void setJlfs(float v) {
+        jlfs = v;
+    }
+
+    public int getSfypfj() {
+        return sfypfj;
+    }
+
+    public void setSfypfj(int v) {
+        sfypfj = v;
+    }
+
+    public String getMs() {
+        return ms;
+    }
+
+    public void setMs(String v) {
+        ms = v;
+    }
+
+    public String getMswj() {
+        return mswj;
+    }
+
+    public void setMswj(String v) {
+        mswj = v;
+    }
+
+    public Long getFjid() {
+        return fjid;
+    }
+
+    public void setFjid(Long v) {
+        fjid = v;
+    }
+
+    public Timestamp getJcsj() {
+        return jcsj;
+    }
+
+    public void setJcsj(Timestamp v) {
+        jcsj = v;
+    }
+
+    public int getJlztm() {
+        return jlztm;
+    }
+
+    public void setJlztm(int v) {
+        jlztm = v;
+    }
+
+    public Long getCjryid() {
+        return cjryid;
+    }
+
+    public void setCjryid(Long v) {
+        cjryid = v;
+    }
+
+    public Long getGlryid() {
+        return glryid;
+    }
+
+    public void setGlryid(Long v) {
+        glryid = v;
+    }
+
+    public Long getGlbmid() {
+        return glbmid;
+    }
+
+    public void setGlbmid(Long v) {
+        glbmid = v;
+    }
+}

+ 111 - 0
src/base/po/BjpbmxPo.java

@@ -0,0 +1,111 @@
+package base.po;
+
+import java.util.Map;
+
+import ss.db.DbC;
+import ss.db.Po;
+
+/**
+ * 班级评比明细。
+ */
+public class BjpbmxPo extends Po {
+    {
+        super.fieldTypeMap = Map.<String, Integer>ofEntries(
+                Map.entry("bjpbmxid", DbC.PO_longType),
+                Map.entry("bjpbid", DbC.PO_longType),
+                Map.entry("bjpbxmm", DbC.PO_intType),
+                Map.entry("fs", DbC.PO_floatType),
+                Map.entry("jlztm", DbC.PO_intType),
+                Map.entry("cjryid", DbC.PO_LongType),
+                Map.entry("glryid", DbC.PO_LongType),
+                Map.entry("glbmid", DbC.PO_LongType));
+    }
+
+    private long bjpbmxid;
+    private long bjpbid;
+    private int bjpbxmm;
+    private float fs;
+    private int jlztm;
+    private Long cjryid;
+    private Long glryid;
+    private Long glbmid;
+
+    public BjpbmxPo() {
+        super.tabName = "bjpbmx";
+        super.idName = "bjpbmxid";
+    }
+
+    @Override
+    public long rdIdVal() {
+        return bjpbmxid;
+    }
+
+    @Override
+    public void wrIdVal(long id) {
+        bjpbmxid = id;
+    }
+
+    public long getBjpbmxid() {
+        return bjpbmxid;
+    }
+
+    public void setBjpbmxid(long v) {
+        bjpbmxid = v;
+    }
+
+    public long getBjpbid() {
+        return bjpbid;
+    }
+
+    public void setBjpbid(long v) {
+        bjpbid = v;
+    }
+
+    public int getBjpbxmm() {
+        return bjpbxmm;
+    }
+
+    public void setBjpbxmm(int v) {
+        bjpbxmm = v;
+    }
+
+    public float getFs() {
+        return fs;
+    }
+
+    public void setFs(float v) {
+        fs = v;
+    }
+
+    public int getJlztm() {
+        return jlztm;
+    }
+
+    public void setJlztm(int v) {
+        jlztm = v;
+    }
+
+    public Long getCjryid() {
+        return cjryid;
+    }
+
+    public void setCjryid(Long v) {
+        cjryid = v;
+    }
+
+    public Long getGlryid() {
+        return glryid;
+    }
+
+    public void setGlryid(Long v) {
+        glryid = v;
+    }
+
+    public Long getGlbmid() {
+        return glbmid;
+    }
+
+    public void setGlbmid(Long v) {
+        glbmid = v;
+    }
+}

+ 187 - 0
src/biz/bjpj/BjpbMirrorServ.java

@@ -0,0 +1,187 @@
+package biz.bjpj;
+
+import java.io.Writer;
+import java.time.LocalDate;
+import java.time.format.DateTimeParseException;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.google.gson.Gson;
+import jakarta.servlet.http.HttpServletRequest;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import ss.db.Db;
+import ss.db.SqlCmd;
+import ss.serv.Serv;
+import ss.serv.ServU;
+
+/**
+ * 双写补偿入口。
+ *
+ * <p>用于处理旧表已成功保存、但新表镜像暂时失败或缺失的记录。
+ * 该入口按旧主记录重新执行一次完整镜像,依赖同步映射保持幂等。</p>
+ */
+public class BjpbMirrorServ extends Serv {
+
+    private static final Logger log4j =
+            LogManager.getLogger(BjpbMirrorServ.class);
+
+    @SuppressWarnings("unused")
+    public void retryByA() 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 gdba = Db.makeConn()) {
+            String sourceType = request.getParameter("sourceType");
+            String sourceIdText = request.getParameter("sourceId");
+            if (sourceType == null || sourceType.trim().isEmpty()
+                    || sourceIdText == null || sourceIdText.trim().isEmpty())
+                throw new IllegalArgumentException("sourceType和sourceId不能为空");
+
+            sourceType = sourceType.trim().toUpperCase();
+            if (!BjpbMirrorU.SRC_SSNWJC.equals(sourceType)
+                    && !BjpbMirrorU.SRC_CSWSJC.equals(sourceType)
+                    && !BjpbMirrorU.SRC_SQLJC.equals(sourceType))
+                throw new IllegalArgumentException("不支持的检查类型:" + sourceType);
+
+            long sourceId = Long.parseLong(sourceIdText.trim());
+            BjpbMirrorU.retryAll(sourceType, sourceId, gdba);
+            gdba.commit();
+
+            Map<String, Object> data = new LinkedHashMap<>();
+            data.put("sourceType", sourceType);
+            data.put("sourceId", sourceId);
+            data.put("status", "SUCCESS");
+            ServU.wrOkDataByWriter(data, writer, gson);
+        } catch (IllegalArgumentException e) {
+            ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
+        } catch (Exception e) {
+            log4j.error("BjpbMirrorServ.retryByA() 异常", e);
+            ServU.wrErrMsgByWriter(null, "BJPB镜像补偿失败", writer, gson);
+        }
+    }
+
+    /**
+     * 扫描指定日期的旧记录并重新镜像。适用于失败补偿和状态/分数漂移修复。
+     */
+    @SuppressWarnings("unused")
+    public void retryRecentByA() 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 gdba = Db.makeConn()) {
+            String sourceType = request.getParameter("sourceType");
+            if (sourceType == null || sourceType.trim().isEmpty())
+                throw new IllegalArgumentException("sourceType不能为空");
+            sourceType = sourceType.trim().toUpperCase();
+            if (!BjpbMirrorU.SRC_SSNWJC.equals(sourceType)
+                    && !BjpbMirrorU.SRC_CSWSJC.equals(sourceType)
+                    && !BjpbMirrorU.SRC_SQLJC.equals(sourceType))
+                throw new IllegalArgumentException("不支持的检查类型:" + sourceType);
+
+            String fromText = request.getParameter("fromDate");
+            String toText = request.getParameter("toDate");
+            if (fromText == null || fromText.trim().isEmpty())
+                fromText = LocalDate.now().toString();
+            if (toText == null || toText.trim().isEmpty())
+                toText = fromText;
+            LocalDate fromDate = LocalDate.parse(fromText.trim());
+            LocalDate toDate = LocalDate.parse(toText.trim());
+            if (toDate.isBefore(fromDate))
+                throw new IllegalArgumentException("toDate不能早于fromDate");
+
+            List<Long> ids = rdSourceIds(sourceType, fromDate, toDate, gdba);
+            int repaired = 0;
+            for (Long id : ids) {
+                BjpbMirrorU.retryAll(sourceType, id, gdba);
+                repaired++;
+            }
+            gdba.commit();
+
+            Map<String, Object> data = new LinkedHashMap<>();
+            data.put("sourceType", sourceType);
+            data.put("fromDate", fromDate.toString());
+            data.put("toDate", toDate.toString());
+            data.put("repaired", repaired);
+            ServU.wrOkDataByWriter(data, writer, gson);
+        } catch (DateTimeParseException e) {
+            ServU.wrErrMsgByWriter(null, "日期格式应为YYYY-MM-DD", writer, gson);
+        } catch (IllegalArgumentException e) {
+            ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
+        } catch (Exception e) {
+            log4j.error("BjpbMirrorServ.retryRecentByA() 异常", e);
+            ServU.wrErrMsgByWriter(null, "BJPB日期补偿失败", writer, gson);
+        }
+    }
+
+    /**
+     * 定时补偿入口:扫描前一天和当天,测试/正式环境都通过同一套幂等镜像逻辑。
+     */
+    @SuppressWarnings("unused")
+    public void timerRetryByA() throws Exception {
+        LocalDate today = LocalDate.now();
+        LocalDate fromDate = today.minusDays(1);
+        int repaired = 0;
+        int failed = 0;
+        try (Db gdba = Db.makeConn()) {
+            for (String sourceType : List.of(
+                    BjpbMirrorU.SRC_SSNWJC,
+                    BjpbMirrorU.SRC_CSWSJC,
+                    BjpbMirrorU.SRC_SQLJC)) {
+                for (Long id : rdSourceIds(sourceType, fromDate, today, gdba)) {
+                    try {
+                        BjpbMirrorU.retryAll(sourceType, id, gdba);
+                        repaired++;
+                    } catch (Exception e) {
+                        failed++;
+                        log4j.error("BJPB定时补偿失败,source=" + sourceType
+                                + ", id=" + id, e);
+                    }
+                }
+            }
+            gdba.commit();
+            log4j.info("BJPB定时补偿完成,日期={}~{},成功={},失败={}",
+                    fromDate, today, repaired, failed);
+        }
+    }
+
+    private List<Long> rdSourceIds(String sourceType, LocalDate fromDate,
+                                   LocalDate toDate, Db gdba)
+            throws Exception {
+        String sql = switch (sourceType) {
+            case BjpbMirrorU.SRC_SSNWJC ->
+                    "select SSNWJCID from SSNWJC "
+                            + "where JCSJ>=:fromDate and JCSJ<:toDate "
+                            + "and JLZTM in(1,21,22,25,51,81) "
+                            + "order by SSNWJCID";
+            case BjpbMirrorU.SRC_CSWSJC ->
+                    "select CSWSJCID from CSWSJC "
+                            + "where JCSJ>=:fromDate and JCSJ<:toDate "
+                            + "and JLZTM in(1,21,22,25,51,81) "
+                            + "order by CSWSJCID";
+            case BjpbMirrorU.SRC_SQLJC ->
+                    "select SQLJCID from SQLJC "
+                            + "where JCSJ>=:fromDate and JCSJ<:toDate "
+                            + "and JLZTM in(1,21,22,25,51,81) "
+                            + "order by SQLJCID";
+            default -> throw new IllegalArgumentException(
+                    "不支持的检查类型:" + sourceType);
+        };
+        SqlCmd cmd = new SqlCmd(sql);
+        cmd.wrTimeParm("fromDate", java.sql.Timestamp.valueOf(
+                fromDate.atStartOfDay()));
+        cmd.wrTimeParm("toDate", java.sql.Timestamp.valueOf(
+                toDate.plusDays(1).atStartOfDay()));
+        return gdba.doSelListByC(cmd).stream()
+                .map(v -> Long.parseLong(String.valueOf(v)))
+                .collect(java.util.stream.Collectors.toList());
+    }
+}

+ 514 - 0
src/biz/bjpj/BjpbMirrorU.java

@@ -0,0 +1,514 @@
+package biz.bjpj;
+
+import java.sql.Timestamp;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import base.po.BjpbPo;
+import base.po.BjpbmxPo;
+import ss.db.Db;
+import ss.db.Po;
+import ss.db.SqlCmd;
+
+/**
+ * 将旧的三套班级检查记录镜像到 BJPB/BJPBMX。
+ *
+ * <p>旧表仍是业务事实来源。该类只负责附加写入新模型,供双写过渡期对账。</p>
+ */
+public final class BjpbMirrorU {
+
+    public static final String SRC_SSNWJC = "SSNWJC";
+    public static final String SRC_CSWSJC = "CSWSJC";
+    public static final String SRC_SQLJC = "SQLJC";
+
+    private static final int CATEGORY_DORM = 1;
+    private static final int CATEGORY_ROOM = 11;
+    private static final int CATEGORY_FLAG = 51;
+
+    private static final Logger log4j = LogManager.getLogger(BjpbMirrorU.class);
+
+    private BjpbMirrorU() {
+    }
+
+    /**
+     * 通用 PC 保存钩子。未识别的对象直接忽略。
+     */
+    public static void mirrorByObjectQuietly(String objName, Po po, Db db) {
+        if (objName == null || po == null || po.rdIdVal() <= 0)
+            return;
+
+        try {
+            String batchId = newBatchId(objName);
+            if ("ssnwjc".equals(objName))
+                mirrorParent(SRC_SSNWJC, po.rdIdVal(), batchId, db);
+            else if ("cswsjc".equals(objName))
+                mirrorParent(SRC_CSWSJC, po.rdIdVal(), batchId, db);
+            else if ("sqljc".equals(objName))
+                mirrorParent(SRC_SQLJC, po.rdIdVal(), batchId, db);
+            else if ("ssnwjcmx".equals(objName))
+                mirrorChild(SRC_SSNWJC, po.rdIdVal(), batchId, db);
+            else if ("cswsjcmx".equals(objName))
+                mirrorChild(SRC_CSWSJC, po.rdIdVal(), batchId, db);
+            else if ("sqljcmx".equals(objName))
+                mirrorChild(SRC_SQLJC, po.rdIdVal(), batchId, db);
+        } catch (Exception e) {
+            log4j.error("BJPB 镜像失败,object=" + objName + ", id="
+                    + po.rdIdVal(), e);
+        }
+    }
+
+    /**
+     * Excel/小程序在旧主从记录全部落库后调用,按旧主表同步主表和全部明细。
+     */
+    public static void mirrorAllQuietly(String sourceType, long sourceId,
+                                        Db db) {
+        mirrorAllQuietly(sourceType, sourceId, newBatchId(sourceType), db);
+    }
+
+    /**
+     * 同一次多班级提交传入同一个批次号,供后续整批追踪和补偿。
+     */
+    public static void mirrorAllQuietly(String sourceType, long sourceId,
+                                        String batchId, Db db) {
+        try {
+            mirrorAll(sourceType, sourceId, batchId, db);
+        } catch (Exception e) {
+            log4j.error("BJPB 全量镜像失败,source=" + sourceType
+                    + ", id=" + sourceId, e);
+        }
+    }
+
+    /**
+     * 补偿服务使用的严格模式:失败时抛出,由调用方决定是否回滚。
+     */
+    public static void retryAll(String sourceType, long sourceId, Db db)
+            throws Exception {
+        String batchId = rdParentBatchId(sourceType, sourceId, db);
+        if (batchId == null)
+            batchId = newBatchId(sourceType);
+        mirrorAll(sourceType, sourceId, batchId, db);
+    }
+
+    private static void mirrorAll(String sourceType, long sourceId,
+                                  String batchId, Db db) throws Exception {
+        mirrorParent(sourceType, sourceId, batchId, db);
+        for (Long sourceMxId : rdChildIds(sourceType, sourceId, db))
+            mirrorChild(sourceType, sourceMxId, batchId, db);
+        if (SRC_SQLJC.equals(sourceType))
+            syncFlagMaster(sourceId, db);
+    }
+
+    /**
+     * 生成批次号。批次只用于同一次业务提交,不参与主键。
+     */
+    public static String newBatchId(String sourceType) {
+        String prefix = sourceType == null ? "BJPB" : sourceType;
+        return prefix + "-" + UUID.randomUUID().toString().replace("-", "")
+                .substring(0, 20);
+    }
+
+    /**
+     * 通用 PC 删除钩子。必须在新表中断开主从关系,再删除同步映射。
+     */
+    public static void deleteByObjectQuietly(String objName, long sourceId,
+                                             Db db) {
+        if (sourceId <= 0)
+            return;
+        try {
+            if ("ssnwjc".equals(objName))
+                deleteParent(SRC_SSNWJC, sourceId, db);
+            else if ("cswsjc".equals(objName))
+                deleteParent(SRC_CSWSJC, sourceId, db);
+            else if ("sqljc".equals(objName))
+                deleteParent(SRC_SQLJC, sourceId, db);
+            else if ("ssnwjcmx".equals(objName))
+                deleteChild(SRC_SSNWJC, sourceId, db);
+            else if ("cswsjcmx".equals(objName))
+                deleteChild(SRC_CSWSJC, sourceId, db);
+            else if ("sqljcmx".equals(objName))
+                deleteChild(SRC_SQLJC, sourceId, db);
+        } catch (Exception e) {
+            log4j.error("BJPB 删除镜像失败,object=" + objName
+                    + ", id=" + sourceId, e);
+        }
+    }
+
+    private static long mirrorParent(String sourceType, long sourceId,
+                                     String batchId, Db db)
+            throws Exception {
+        Map<String, Object> old = rdOldParent(sourceType, sourceId, db);
+        if (old == null)
+            throw new IllegalStateException("旧检查记录不存在:" + sourceType
+                    + "/" + sourceId);
+
+        BjpbPo po = toBjpbPo(sourceType, old);
+        Long bjpbId = rdParentTargetId(sourceType, sourceId, db);
+        if (bjpbId == null) {
+            po.setBjpbid(0L);
+            Set<String> fields = new LinkedHashSet<>(List.of(
+                    "bmid", "jcryid", "bjid", "bjpblbm", "jzwid", "cdid",
+                    "zfs", "cql", "kqfs", "dlfs", "fmfs", "jlfs",
+                    "sfypfj", "ms", "mswj", "fjid", "jcsj", "jlztm",
+                    "cjryid", "glryid", "glbmid"));
+            bjpbId = db.doInsPo(po, fields);
+            upsertSyncMap(sourceType, sourceId, 0L, bjpbId, null,
+                    batchId, "SUCCESS", null, db);
+        } else {
+            po.setBjpbid(bjpbId);
+            Set<String> fields = new LinkedHashSet<>(List.of(
+                    "bmid", "jcryid", "bjid", "bjpblbm", "jzwid", "cdid",
+                    "zfs", "cql", "kqfs", "dlfs", "fmfs", "jlfs",
+                    "sfypfj", "ms", "mswj", "fjid", "jcsj", "jlztm",
+                    "cjryid", "glryid", "glbmid"));
+            db.doUpdPo(po, fields);
+            upsertSyncMap(sourceType, sourceId, 0L, bjpbId, null,
+                    batchId, "SUCCESS", null, db);
+        }
+        return bjpbId;
+    }
+
+    private static void mirrorChild(String sourceType, long sourceMxId,
+                                    String batchId, Db db)
+            throws Exception {
+        Map<String, Object> itemMap = rdItemMap(sourceType, sourceMxId, db);
+        if (itemMap == null)
+            throw new IllegalStateException("旧检查明细不存在:" + sourceType
+                    + "/" + sourceMxId);
+
+        String mapStatus = str(itemMap.get("mapping_status"));
+        if ("IGNORE".equals(mapStatus)) {
+            Long sourceId = longObj(itemMap.get("source_id"));
+            if (sourceId != null) {
+                upsertSyncMap(sourceType, sourceId, sourceMxId, null, null,
+                        batchId, "IGNORED", str(itemMap.get("mapping_msg")), db);
+            }
+            return;
+        }
+
+        Integer targetXmm = intObj(itemMap.get("bjpbxmm"));
+        if (targetXmm == null) {
+            throw new IllegalStateException("检查项目未配置 BJPB 映射:"
+                    + sourceType + "/" + str(itemMap.get("source_xmm")));
+        }
+
+        long sourceId = longValue(itemMap.get("source_id"));
+        long bjpbId = mirrorParent(sourceType, sourceId, batchId, db);
+        Long bjpbmxId = rdChildTargetId(sourceType, sourceMxId, db);
+
+        BjpbmxPo po = new BjpbmxPo();
+        po.setBjpbid(bjpbId);
+        po.setBjpbxmm(targetXmm);
+        po.setFs(floatValue(itemMap.get("fs")));
+        po.setJlztm(intValue(itemMap.get("jlztm"), 51));
+        po.setCjryid(longObj(itemMap.get("cjryid")));
+        po.setGlryid(longObj(itemMap.get("glryid")));
+        po.setGlbmid(longObj(itemMap.get("glbmid")));
+
+        if (bjpbmxId == null) {
+            po.setBjpbmxid(0L);
+            Set<String> fields = new LinkedHashSet<>(List.of(
+                    "bjpbid", "bjpbxmm", "fs", "jlztm",
+                    "cjryid", "glryid", "glbmid"));
+            bjpbmxId = db.doInsPo(po, fields);
+        } else {
+            po.setBjpbmxid(bjpbmxId);
+            Set<String> fields = new LinkedHashSet<>(List.of(
+                    "bjpbid", "bjpbxmm", "fs", "jlztm",
+                    "cjryid", "glryid", "glbmid"));
+            db.doUpdPo(po, fields);
+        }
+
+        upsertSyncMap(sourceType, sourceId, sourceMxId, bjpbId, bjpbmxId,
+                batchId, "SUCCESS", null, db);
+        if (SRC_SQLJC.equals(sourceType))
+            syncFlagMaster(sourceId, db);
+    }
+
+    private static BjpbPo toBjpbPo(String sourceType, Map<String, Object> old) {
+        BjpbPo po = new BjpbPo();
+        po.setBmid(longObj(old.get("bmid")));
+        po.setJcryid(longValue(old.get("jcryid")));
+        po.setBjid(longValue(old.get("bjid")));
+        po.setJzwid(longObj(old.get("jzwid")));
+        po.setCdid(longObj(old.get("cdid")));
+        po.setZfs(floatValue(old.get("zfs")));
+        po.setCql(floatValue(old.get("cql")));
+        po.setKqfs(floatValue(old.get("kqfs")));
+        po.setDlfs(floatValue(old.get("dlfs")));
+        po.setFmfs(floatValue(old.get("fmfs")));
+        po.setJlfs(floatValue(old.get("jlfs")));
+        po.setSfypfj(0);
+        po.setMs(strObj(old.get("ms")));
+        po.setMswj(strObj(old.get("mswj")));
+        po.setFjid(longObj(old.get("fjid")));
+        po.setJcsj((Timestamp) old.get("jcsj"));
+        po.setJlztm(intValue(old.get("jlztm"), 51));
+        po.setCjryid(longObj(old.get("cjryid")));
+        po.setGlryid(longObj(old.get("glryid")));
+        po.setGlbmid(longObj(old.get("glbmid")));
+
+        if (SRC_SSNWJC.equals(sourceType))
+            po.setBjpblbm(CATEGORY_DORM);
+        else if (SRC_CSWSJC.equals(sourceType))
+            po.setBjpblbm(CATEGORY_ROOM);
+        else if (SRC_SQLJC.equals(sourceType))
+            po.setBjpblbm(CATEGORY_FLAG);
+        else
+            throw new IllegalArgumentException("未知检查类型:" + sourceType);
+        return po;
+    }
+
+    private static Map<String, Object> rdOldParent(String sourceType,
+                                                   long sourceId, Db db)
+            throws Exception {
+        String sql;
+        if (SRC_SSNWJC.equals(sourceType)) {
+            sql = "select JCRYID,BJID,JCSJ,JLZTM,CJRYID,GLRYID,GLBMID,"
+                    + " JZWID,KFID CDID,FS ZFS,MS,MSWJ,FJID"
+                    + " from SSNWJC where SSNWJCID=:sourceId";
+        } else if (SRC_CSWSJC.equals(sourceType)) {
+            sql = "select JCRYID,BJID,JCSJ,JLZTM,CJRYID,GLRYID,GLBMID,"
+                    + " JZWID,CDID,FS ZFS,MS,MSWJ,FJID"
+                    + " from CSWSJC where CSWSJCID=:sourceId";
+        } else if (SRC_SQLJC.equals(sourceType)) {
+            sql = "select BMID,JCRYID,BJID,JCSJ,JLZTM,CJRYID,GLRYID,"
+                    + " GLBMID,ZFS,CQL,KQFS,DLFS,FMFS,JLFS,MS,MSWJ,FJID"
+                    + " from SQLJC where SQLJCID=:sourceId";
+        } else {
+            throw new IllegalArgumentException("未知检查类型:" + sourceType);
+        }
+        SqlCmd cmd = new SqlCmd(sql);
+        cmd.wrLongParm("sourceId", sourceId);
+        return db.doSelMapByC(cmd);
+    }
+
+    private static Map<String, Object> rdItemMap(String sourceType,
+                                                 long sourceMxId, Db db)
+            throws Exception {
+        String sql;
+        if (SRC_SSNWJC.equals(sourceType)) {
+            sql = "select x.SSNWJCID source_id,x.SSNWJCXMM source_xmm,"
+                    + " x.FS,x.JLZTM,x.CJRYID,x.GLRYID,x.GLBMID,"
+                    + " m.BJPBXMM,m.MAPPING_STATUS,m.MS mapping_msg"
+                    + " from SSNWJCMX x"
+                    + " left join XJB_BJPB_XM_MAP m"
+                    + " on m.SOURCE_TYPE='SSNWJC' and m.SOURCE_XMM=x.SSNWJCXMM"
+                    + " where x.SSNWJCMXID=:sourceMxId";
+        } else if (SRC_CSWSJC.equals(sourceType)) {
+            sql = "select x.CSWSJCID source_id,x.CSWSJCXMM source_xmm,"
+                    + " x.FS,x.JLZTM,x.CJRYID,x.GLRYID,x.GLBMID,"
+                    + " m.BJPBXMM,m.MAPPING_STATUS,m.MS mapping_msg"
+                    + " from CSWSJCMX x"
+                    + " left join XJB_BJPB_XM_MAP m"
+                    + " on m.SOURCE_TYPE='CSWSJC' and m.SOURCE_XMM=x.CSWSJCXMM"
+                    + " where x.CSWSJCMXID=:sourceMxId";
+        } else if (SRC_SQLJC.equals(sourceType)) {
+            sql = "select x.SQLJCID source_id,x.SQLJCXMM source_xmm,"
+                    + " x.FS,x.JLZTM,x.CJRYID,x.GLRYID,x.GLBMID,"
+                    + " m.BJPBXMM,m.MAPPING_STATUS,m.MS mapping_msg"
+                    + " from SQLJCMX x"
+                    + " left join XJB_BJPB_XM_MAP m"
+                    + " on m.SOURCE_TYPE='SQLJC' and m.SOURCE_XMM=x.SQLJCXMM"
+                    + " where x.SQLJCMXID=:sourceMxId";
+        } else {
+            throw new IllegalArgumentException("未知检查类型:" + sourceType);
+        }
+        SqlCmd cmd = new SqlCmd(sql);
+        cmd.wrLongParm("sourceMxId", sourceMxId);
+        return db.doSelMapByC(cmd);
+    }
+
+    private static List<Long> rdChildIds(String sourceType, long sourceId,
+                                         Db db) throws Exception {
+        String sql;
+        if (SRC_SSNWJC.equals(sourceType)) {
+            sql = "select SSNWJCMXID from SSNWJCMX where SSNWJCID=:sourceId";
+        } else if (SRC_CSWSJC.equals(sourceType)) {
+            sql = "select CSWSJCMXID from CSWSJCMX where CSWSJCID=:sourceId";
+        } else if (SRC_SQLJC.equals(sourceType)) {
+            sql = "select SQLJCMXID from SQLJCMX where SQLJCID=:sourceId";
+        } else {
+            throw new IllegalArgumentException("未知检查类型:" + sourceType);
+        }
+        SqlCmd cmd = new SqlCmd(sql);
+        cmd.wrLongParm("sourceId", sourceId);
+        List<Object> values = db.doSelListByC(cmd);
+        return values.stream().map(v -> Long.parseLong(String.valueOf(v)))
+                .collect(Collectors.toList());
+    }
+
+    private static Long rdParentTargetId(String sourceType, long sourceId,
+                                         Db db) throws Exception {
+        SqlCmd cmd = new SqlCmd(
+                "select BJPBID from XJB_BJPB_SYNC_MAP"
+                        + " where SOURCE_TYPE=:sourceType and SOURCE_ID=:sourceId"
+                        + " and SOURCE_MX_ID=0");
+        cmd.wrStrParm("sourceType", sourceType);
+        cmd.wrLongParm("sourceId", sourceId);
+        return longObj(db.doSelFieldByC(cmd));
+    }
+
+    private static String rdParentBatchId(String sourceType, long sourceId,
+                                          Db db) throws Exception {
+        SqlCmd cmd = new SqlCmd(
+                "select SOURCE_BATCH_ID from XJB_BJPB_SYNC_MAP"
+                        + " where SOURCE_TYPE=:sourceType and SOURCE_ID=:sourceId"
+                        + " and SOURCE_MX_ID=0");
+        cmd.wrStrParm("sourceType", sourceType);
+        cmd.wrLongParm("sourceId", sourceId);
+        return strObj(db.doSelFieldByC(cmd));
+    }
+
+    private static Long rdChildTargetId(String sourceType, long sourceMxId,
+                                        Db db) throws Exception {
+        SqlCmd cmd = new SqlCmd(
+                "select BJPBMXID from XJB_BJPB_SYNC_MAP"
+                        + " where SOURCE_TYPE=:sourceType"
+                        + " and SOURCE_MX_ID=:sourceMxId");
+        cmd.wrStrParm("sourceType", sourceType);
+        cmd.wrLongParm("sourceMxId", sourceMxId);
+        return longObj(db.doSelFieldByC(cmd));
+    }
+
+    private static void upsertSyncMap(String sourceType, long sourceId,
+                                      long sourceMxId, Long bjpbId,
+                                      Long bjpbmxId, String batchId,
+                                      String status,
+                                      String errorMsg, Db db) throws Exception {
+        SqlCmd update = new SqlCmd(
+                "update XJB_BJPB_SYNC_MAP"
+                        + " set BJPBID=:bjpbId,BJPBMXID=:bjpbmxId,"
+                        + " SOURCE_BATCH_ID=coalesce(:batchId,SOURCE_BATCH_ID),"
+                        + " SYNC_STATUS=:status,ERROR_MSG=:errorMsg,"
+                        + " SYNC_TIME=systimestamp"
+                        + " where SOURCE_TYPE=:sourceType and SOURCE_ID=:sourceId"
+                        + " and SOURCE_MX_ID=:sourceMxId");
+        update.wrLongParm("bjpbId", bjpbId);
+        update.wrLongParm("bjpbmxId", bjpbmxId);
+        update.wrStrParm("batchId", batchId);
+        update.wrStrParm("status", status);
+        update.wrStrParm("errorMsg", errorMsg);
+        update.wrStrParm("sourceType", sourceType);
+        update.wrLongParm("sourceId", sourceId);
+        update.wrLongParm("sourceMxId", sourceMxId);
+        if (db.doModByC(update) > 0)
+            return;
+
+        SqlCmd insert = new SqlCmd(
+                "insert into XJB_BJPB_SYNC_MAP"
+                        + " (SOURCE_TYPE,SOURCE_ID,SOURCE_MX_ID,SOURCE_BATCH_ID,"
+                        + " BJPBID,BJPBMXID,SYNC_STATUS,ERROR_MSG,SYNC_TIME)"
+                        + " values"
+                        + " (:sourceType,:sourceId,:sourceMxId,:batchId,"
+                        + " :bjpbId,:bjpbmxId,:status,:errorMsg,systimestamp)");
+        insert.wrStrParm("sourceType", sourceType);
+        insert.wrLongParm("sourceId", sourceId);
+        insert.wrLongParm("sourceMxId", sourceMxId);
+        insert.wrStrParm("batchId", batchId);
+        insert.wrLongParm("bjpbId", bjpbId);
+        insert.wrLongParm("bjpbmxId", bjpbmxId);
+        insert.wrStrParm("status", status);
+        insert.wrStrParm("errorMsg", errorMsg);
+        db.doModByC(insert);
+    }
+
+    /**
+     * 升旗礼主表字段以明细为准,避免历史 DLFS/FMFS/JLFS 与明细不一致。
+     */
+    private static void syncFlagMaster(long sourceId, Db db) throws Exception {
+        Long bjpbId = rdParentTargetId(SRC_SQLJC, sourceId, db);
+        if (bjpbId == null)
+            return;
+
+        SqlCmd cmd = new SqlCmd(
+                "update BJPB p"
+                        + " set DLFS=nvl((select max(case when BJPBXMM=5151 then FS end)"
+                        + "              from BJPBMX where BJPBID=p.BJPBID),p.DLFS),"
+                        + "     FMFS=(select nvl(sum(case when BJPBXMM in"
+                        + "              (5161,5162,5163) then FS else 0 end),0)"
+                        + "              from BJPBMX where BJPBID=p.BJPBID),"
+                        + "     JLFS=nvl((select max(case when BJPBXMM=5171 then FS end)"
+                        + "              from BJPBMX where BJPBID=p.BJPBID),p.JLFS)"
+                        + " where p.BJPBID=:bjpbId");
+        cmd.wrLongParm("bjpbId", bjpbId);
+        db.doModByC(cmd);
+    }
+
+    private static void deleteParent(String sourceType, long sourceId, Db db)
+            throws Exception {
+        Long bjpbId = rdParentTargetId(sourceType, sourceId, db);
+        if (bjpbId != null) {
+            SqlCmd delMx = new SqlCmd(
+                    "delete from BJPBMX where BJPBID=:bjpbId");
+            delMx.wrLongParm("bjpbId", bjpbId);
+            db.doModByC(delMx);
+
+            SqlCmd del = new SqlCmd("delete from BJPB where BJPBID=:bjpbId");
+            del.wrLongParm("bjpbId", bjpbId);
+            db.doModByC(del);
+        }
+
+        SqlCmd map = new SqlCmd(
+                "delete from XJB_BJPB_SYNC_MAP"
+                        + " where SOURCE_TYPE=:sourceType and SOURCE_ID=:sourceId");
+        map.wrStrParm("sourceType", sourceType);
+        map.wrLongParm("sourceId", sourceId);
+        db.doModByC(map);
+    }
+
+    private static void deleteChild(String sourceType, long sourceMxId, Db db)
+            throws Exception {
+        Long bjpbmxId = rdChildTargetId(sourceType, sourceMxId, db);
+        if (bjpbmxId != null) {
+            SqlCmd del = new SqlCmd(
+                    "delete from BJPBMX where BJPBMXID=:bjpbmxId");
+            del.wrLongParm("bjpbmxId", bjpbmxId);
+            db.doModByC(del);
+        }
+
+        SqlCmd map = new SqlCmd(
+                "delete from XJB_BJPB_SYNC_MAP"
+                        + " where SOURCE_TYPE=:sourceType"
+                        + " and SOURCE_MX_ID=:sourceMxId");
+        map.wrStrParm("sourceType", sourceType);
+        map.wrLongParm("sourceMxId", sourceMxId);
+        db.doModByC(map);
+    }
+
+    private static Long longObj(Object value) {
+        return value == null ? null : Long.valueOf(String.valueOf(value));
+    }
+
+    private static long longValue(Object value) {
+        Long result = longObj(value);
+        return result == null ? 0L : result;
+    }
+
+    private static Integer intObj(Object value) {
+        return value == null ? null : Integer.valueOf(String.valueOf(value));
+    }
+
+    private static int intValue(Object value, int defaultValue) {
+        Integer result = intObj(value);
+        return result == null ? defaultValue : result;
+    }
+
+    private static float floatValue(Object value) {
+        return value == null ? 0F : Float.parseFloat(String.valueOf(value));
+    }
+
+    private static String str(Object value) {
+        return value == null ? "" : String.valueOf(value);
+    }
+
+    private static String strObj(Object value) {
+        return value == null ? null : String.valueOf(value);
+    }
+}

+ 4 - 0
src/biz/bjpj/CswsjcMpServ.java

@@ -2,6 +2,7 @@ package biz.bjpj;
 
 import base.po.CswsjcPo;
 import base.po.CswsjcmxPo;
+import biz.bjpj.BjpbMirrorU;
 import com.google.gson.Gson;
 import jakarta.servlet.http.HttpServletRequest;
 import org.apache.commons.lang3.StringUtils;
@@ -252,6 +253,7 @@ public class CswsjcMpServ extends Serv {
                             cswsjcid, gdba, request);
                 }
             }
+            BjpbMirrorU.mirrorAllQuietly(BjpbMirrorU.SRC_CSWSJC, cswsjcid, gdba);
             gdba.commit();
 
             boolean bpmStarted = true;
@@ -269,6 +271,8 @@ public class CswsjcMpServ extends Serv {
                 log4j.error("CswsjcMpServ.submAddByA() 启动流程失败,cswsjcid="
                         + cswsjcid, e);
             }
+            BjpbMirrorU.mirrorAllQuietly(BjpbMirrorU.SRC_CSWSJC, cswsjcid, gdba);
+            gdba.commit();
 
             Map<String, Object> data = new LinkedHashMap<>();
             data.put("cswsjcid", cswsjcid);

+ 3 - 0
src/biz/bjpj/CswsjcServ.java

@@ -108,12 +108,15 @@ public class CswsjcServ extends Serv {
 					BpmU.saveSq(null, cswsjcmx, vo, BpmC.CHG_addType, null, user.ryid, null, CswsjcC.OBJ_cswsjcName, cswsjcid, gdba, request);
 							// null = sqParm,null = wdObject,null = wblp。Lin
 				}
+				BjpbMirrorU.mirrorAllQuietly(BjpbMirrorU.SRC_CSWSJC, cswsjcid, gdba);
 				gdba.commit();
 
 				SqPo sq = new SqPo();
 				sq.setDxm(CswsjcC.OBJ_cswsjcName);
 				sq.setMc("excel 提交场室卫生检查("+ cswsjc.getJcsj() +")");
 				Bpm.doStartBpm(CswsjcC.BPM_cswsjcBoxAddName, cswsjc, sq, new HashMap<>(), new BpmAddRunB(), user.ryid, request, super.resp);
+				BjpbMirrorU.mirrorAllQuietly(BjpbMirrorU.SRC_CSWSJC, cswsjcid, gdba);
+				gdba.commit();
 //			}	// 去掉,只有一个班级。Lin
 		} catch (Exception e) {
 			request.setAttribute(ServC.REQ_msg, "提交失败");

+ 2 - 0
src/biz/bjpj/SqljcMpServ.java

@@ -2,6 +2,7 @@ package biz.bjpj;
 
 import base.po.SqljcPo;
 import base.po.SqljcmxPo;
+import biz.bjpj.BjpbMirrorU;
 import com.google.gson.Gson;
 import jakarta.servlet.http.HttpServletRequest;
 import org.apache.commons.lang3.StringUtils;
@@ -193,6 +194,7 @@ public class SqljcMpServ extends Serv {
             gdba.doSelByC(cntSql);
             int recordsToday = gdba.rowNum > 0 ? gdba.rdIntCol("cnt") : 0;
 
+            BjpbMirrorU.mirrorAllQuietly(BjpbMirrorU.SRC_SQLJC, sqljcid, gdba);
             gdba.commit();
 
             Map<String, Object> data = new LinkedHashMap<>();

+ 7 - 3
src/biz/bjpj/SqljcServ.java

@@ -187,10 +187,11 @@ public class SqljcServ extends Serv {
                 }
             }
 
+            String mirrorBatchId = BjpbMirrorU.newBatchId(BjpbMirrorU.SRC_SQLJC);
             for (Map<String, Object> cls : classes) {
                 long bjid = rdLongValue(cls.get("bjid"));
                 saveDeptSqljc(gdba, bmid, bjid, jcsj, totals,
-                        fsMap, ms, fjid, user, existing.get(bjid));
+                        fsMap, ms, fjid, user, existing.get(bjid), mirrorBatchId);
             }
 
             gdba.commit();
@@ -302,10 +303,11 @@ public class SqljcServ extends Serv {
                 }
             }
 
+            String mirrorBatchId = BjpbMirrorU.newBatchId(BjpbMirrorU.SRC_SQLJC);
             for (Map<String, Object> cls : classes) {
                 long bjid = rdLongValue(cls.get("bjid"));
                 saveDeptSqljc(gdba, bmid, bjid, jcsj, totals,
-                        itemValues, ms, fjid, user, existing.get(bjid));
+                        itemValues, ms, fjid, user, existing.get(bjid), mirrorBatchId);
             }
             gdba.commit();
 
@@ -548,7 +550,8 @@ public class SqljcServ extends Serv {
                                Timestamp jcsj, SqljcC.Totals totals,
                                Map<Integer, Integer> itemValues,
                                String ms, Long fjid, UserRunB user,
-                               Map<String, Object> existing) throws Exception {
+                               Map<String, Object> existing,
+                               String mirrorBatchId) throws Exception {
         long sqljcid;
         if (existing == null) {
             Set<String> fields = new LinkedHashSet<>(Arrays.asList(
@@ -599,6 +602,7 @@ public class SqljcServ extends Serv {
                 throw new IllegalStateException("升旗礼记录更新失败");
         }
         replaceSqljcItems(gdba, sqljcid, itemValues, user);
+        BjpbMirrorU.mirrorAllQuietly(BjpbMirrorU.SRC_SQLJC, sqljcid, mirrorBatchId, gdba);
     }
 
     private void replaceSqljcItems(Db gdba, long sqljcid,

+ 5 - 0
src/biz/xyss/SsnwjcMpServ.java

@@ -2,6 +2,7 @@ package biz.xyss;
 
 import base.po.SsnwjcPo;
 import base.po.SsnwjcmxPo;
+import biz.bjpj.BjpbMirrorU;
 import com.google.gson.Gson;
 import jakarta.servlet.http.HttpServletRequest;
 import org.apache.commons.lang3.StringUtils;
@@ -368,6 +369,7 @@ public class SsnwjcMpServ extends Serv {
             List<String> warnMsgList = new ArrayList<>();
             Long firstKfid = kfid;
             long roomId = kfid;
+            String mirrorBatchId = BjpbMirrorU.newBatchId(BjpbMirrorU.SRC_SSNWJC);
             for (long bjid : bjidList) {
                 SsnwjcPo ssnwjc = new SsnwjcPo();
                 ssnwjc.setSsnwjcid(gdba.rdNextSeqVal("SSNWJCID"));
@@ -399,6 +401,7 @@ public class SsnwjcMpServ extends Serv {
 
                 SsnwjcU.saveRosterSnapshot(gdba, ssnwjcid, roomId, jcsj,
                         user.ryid, user.bmid);
+                BjpbMirrorU.mirrorAllQuietly(BjpbMirrorU.SRC_SSNWJC, ssnwjcid, mirrorBatchId, gdba);
                 gdba.commit();
 
                 try {
@@ -414,6 +417,8 @@ public class SsnwjcMpServ extends Serv {
                     log4j.error("SsnwjcMpServ.submAddByA() 启动流程失败,ssnwjcid="
                             + ssnwjcid, e);
                 }
+                BjpbMirrorU.mirrorAllQuietly(BjpbMirrorU.SRC_SSNWJC, ssnwjcid, mirrorBatchId, gdba);
+                gdba.commit();
             }
 
             Map<String, Object> data = new LinkedHashMap<>();

File diff suppressed because it is too large
+ 0 - 0
src/biz/xyss/SsnwjcServ.java


+ 4 - 3
src/biz/xyss/SsnwjcU.java

@@ -88,14 +88,15 @@ public final class SsnwjcU {
                 + "left join CD cd on cd.CDID=d.CDID "
                 + "left join NBCD nb on nb.NBCDID=d.NBCDID "
                 + "where d.CDID=:roomId "
-                + "and d.KSSJ<=:jcsj "
-                + "and (d.JSSJ is null or d.JSSJ>=:jcsj) "
+                + "and d.KSSJ<=:jcsj1 "
+                + "and (d.JSSJ is null or d.JSSJ>=:jcsj2) "
                 + "and d.SYRYID is not null "
                 + "and d." + ObjC.JLZT_useStr + " "
                 + "order by d.NBCDID, d.SYRYID";
         SqlCmd sqlc = new SqlCmd(sql);
         sqlc.wrLongParm("roomId", roomId);
-        sqlc.wrTimeParm("jcsj", jcsj);
+        sqlc.wrTimeParm("jcsj1", jcsj);
+        sqlc.wrTimeParm("jcsj2", jcsj);
         return gdba.doSelMapListByC(sqlc);
     }
 

+ 30 - 1
src/ss/db/DbServ.java

@@ -20,6 +20,7 @@ import org.apache.logging.log4j.Logger;
 import ss.cmn.str.StrBool;
 import ss.db.impl.ShPo;
 import ss.db.impl.SqPo;
+import biz.bjpj.BjpbMirrorU;
 
 import ss.AppB;
 import ss.WebC;
@@ -180,6 +181,13 @@ public class DbServ extends Serv {
 */
 			long pkValue = bean.rdIdVal();	// .getDbObjectId()。Lin
 			if (pkValue == 0L) {
+				String legacySeqName = legacySequenceName(vo.name);
+				if (legacySeqName != null) {
+					pkValue = gdba.rdNextSeqVal(legacySeqName);
+					bean.wrIdVal(pkValue);
+					fieldNameSet.add(vo.idName);
+					fieldNameSet.add("jlztm");
+				}
 
 /* 再去掉,移到上层 -- 只剩 gdba.doInsPo(bb, fieldNameSet) 了。Lin
  * 增加 pkValue =,获得主键值 -- 下面还用到
@@ -330,7 +338,8 @@ if (vo.isBox) {	// 再增加,支持 Box。Lin
 
 /* 再改用 Db.commit(),不用 Serv.commit() -- 改用 Db.makeConn() 了 -- 方法内有 commit(),不能用 Serv.fetchDba()。Lin
 			super.commit();
-*/			gdba.commit();
+*/			BjpbMirrorU.mirrorByObjectQuietly(vo.name, bean, gdba);
+			gdba.commit();
 
 			if (vo.titleField != null) {
 /* tt.util.BeanUtils.getFieldValue() 归入了 ObjU.rdClazzAtr(),但这里用 DbU.rdPoField() -- bean 是 Po。Lin
@@ -370,6 +379,25 @@ if (vo.isBox) {	// 再增加,支持 Box。Lin
 		return forward;
 	}
 
+	/**
+	 * 三套旧检查表在部分环境没有数据库 ID 触发器,由通用保存层显式取序列。
+	 */
+	private String legacySequenceName(String objName) {
+		if ("ssnwjc".equals(objName))
+			return "SSNWJCID";
+		if ("ssnwjcmx".equals(objName))
+			return "SSNWJCMXID";
+		if ("cswsjc".equals(objName))
+			return "CSWSJCID";
+		if ("cswsjcmx".equals(objName))
+			return "CSWSJCMXID";
+		if ("sqljc".equals(objName))
+			return "SQLJCID";
+		if ("sqljcmx".equals(objName))
+			return "SQLJCMXID";
+		return null;
+	}
+
 	
 	// 来自 DbService.saveAndCommit()。Lin
 	@SuppressWarnings("unused")
@@ -1411,6 +1439,7 @@ if (vo.isBox) {	// 再增加,支持 Box。Lin
 /* 再改用 Db.doDelById( -- DbU.rdPoByReqField(vo.poClazz, request) 改为 request.getParameter("???id") 了。Lin
 			gdba.doDelByPo(bb);
 */			gdba.doDelById(bbid, vo.poClazz);
+			BjpbMirrorU.deleteByObjectQuietly(vo.name, bbid, gdba);
 
 			// gdba.makeSureModify(true);
 /* 再改用 Db.commit(),不用 Serv.commit() -- 改用 Db.makeConn() 了 -- 方法内有 commit(),不能用 Serv.fetchDba()。Lin

+ 10 - 0
web/cfg/biz/bjpj/bjpb.timer.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE xml>
+
+<timers biz="bjpj">
+    <timer
+        name="bjpbMirrorRecentPlan"
+        desc="BJPB双写镜像定时补偿:扫描前一天和当天"
+        trigger="0 10/10 * * * ?"
+        serv="sqljc_mirrorTimerRetry"/>
+</timers>

+ 3 - 0
web/cfg/biz/bjpj/sqljc.serv.xml

@@ -4,6 +4,9 @@
 <servs biz="bjpj">
 	<serv name="sqljc" desc="升旗礼检查" obj="sqljc" auth="true">
 		<serv def="parent"/>
+		<serv name="sqljc_mirrorRetry" desc="补写BJPB镜像" clazz="biz.bjpj.BjpbMirrorServ" func="retryByA"/>
+		<serv name="sqljc_mirrorRetryRecent" desc="按日期补写BJPB镜像" clazz="biz.bjpj.BjpbMirrorServ" func="retryRecentByA"/>
+		<serv name="sqljc_mirrorTimerRetry" desc="定时补写BJPB镜像" clazz="biz.bjpj.BjpbMirrorServ" func="timerRetryByA"/>
 		<!-- 0904 合并:dev 原把这些 box 审批挂 excelAdd 组内;现提到对象根,暂无人触发(待接线)。
 		     不引任何自写 clazz。Excel 批量(SqljcServ)待 dev 修复后再接。 -->
 		<serv name="sqljc_sh_boxAdd_ks" desc="开始" def="ss.begBpm"/>

Some files were not shown because too many files changed in this diff