yeg
2026-09-28 9c93934b70ccfca081102944a47f3baafad3c218
battery-device-neware/src/test/java/com/battery/device/neware/FakeVendorDatabase.java
@@ -33,10 +33,16 @@
            String stepType, long testTimeMillis, int voltage, int current, int capacityCharge, int energyCharge,
            int capacityDischarge, int energyDischarge, String testAtime) { }
    /** 工步层一行:工步层不随采样分表滚动,所以没有表名。 */
    record CapStepRow(long testId, long devUid, int unitId, int chlId, long seqId, int cycle, int stepId,
            String stepType, long testTimeMillis, int voltage, int current, int capacityCharge, int energyCharge,
            int capacityDischarge, int energyDischarge, int middleVoltage, String testAtime) { }
    private final List<String> statements = new java.util.concurrent.CopyOnWriteArrayList<>();
    private final List<ChannelRow> channels = new ArrayList<>();
    private final List<TestRow> tests = new ArrayList<>();
    private final List<SampleRow> samples = new ArrayList<>();
    private final List<CapStepRow> capSteps = new ArrayList<>();
    FakeVendorDatabase registeredChannel(long devUid, int unitId, int chlId)
    {
@@ -53,6 +59,12 @@
    FakeVendorDatabase sample(SampleRow row)
    {
        samples.add(row);
        return this;
    }
    FakeVendorDatabase capStep(CapStepRow row)
    {
        capSteps.add(row);
        return this;
    }
@@ -186,6 +198,9 @@
            return latestTests(longValue(parameters, 0));
        if (normalized.contains("from test"))
            return latestTestForChannel(longValue(parameters, 0), intValue(parameters, 1), intValue(parameters, 2));
        if (normalized.contains("from cap_step"))
            return capStepRows(longValue(parameters, 0), longValue(parameters, 1), intValue(parameters, 2),
                    intValue(parameters, 3));
        if (normalized.contains("order by test_atime, seq_id limit"))
            return samplesAfter(tableOf(sql), parameters);
        return lastSampleOfTest(tableOf(sql), intValue(parameters, 0), intValue(parameters, 1),
@@ -231,6 +246,32 @@
                .map(this::sampleColumns).toList();
    }
    private List<Map<String, Object>> capStepRows(long testId, long devUid, int unitId, int chlId)
    {
        return capSteps.stream().filter(row -> row.testId() == testId && row.devUid() == devUid
                        && row.unitId() == unitId && row.chlId() == chlId)
                .sorted(Comparator.comparingLong(CapStepRow::seqId)).map(this::capStepColumns).toList();
    }
    private Map<String, Object> capStepColumns(CapStepRow row)
    {
        Map<String, Object> value = new LinkedHashMap<>();
        value.put("seq_id", row.seqId());
        value.put("cycle", row.cycle());
        value.put("step_id", row.stepId());
        value.put("step_type", row.stepType());
        value.put("test_time", row.testTimeMillis());
        value.put("test_vol", row.voltage());
        value.put("test_cur", row.current());
        value.put("test_capchg", row.capacityCharge());
        value.put("test_engchg", row.energyCharge());
        value.put("test_capdchg", row.capacityDischarge());
        value.put("test_engdchg", row.energyDischarge());
        value.put("middle_vol", row.middleVoltage());
        value.put("test_atime", row.testAtime());
        return value;
    }
    private static boolean after(String atime, long seqId, String watermark, long watermarkSeq)
    {
        int time = atime.compareTo(watermark);