Information Security 11 min read

DCheck: Real-time Asset Loss Detection and Prevention System

DCheck is a real‑time asset‑loss detection platform that monitors MySQL binlog and MQ streams, matches upstream and downstream states, and triggers alerts via configurable topics, events, sub‑events and Groovy scripts implementing filter and check logic, while offering rule‑based controls, debugging tips, and proposed enhancements for reliability.

DeWu Technology
DeWu Technology
DeWu Technology
DCheck: Real-time Asset Loss Detection and Prevention System

Asset loss (资损) refers to financial loss in payment scenarios, from both user and company perspectives.

DCheck is a real‑time verification system developed by the Transaction & Stability team to detect and prevent asset loss. It monitors MySQL binlog and MQ streams, matches upstream and downstream states, and triggers alerts when inconsistencies are found.

System Overview

The platform consists of functional layers, architectural logic, and core concepts such as topics, events, sub‑events, script pools, and rules. Topics map to database tables or MQ topics; events correspond to INSERT/UPDATE operations; sub‑events filter the first layer of data; scripts (Groovy) implement filter and check methods; rules combine triggers and execution logic.

Example Groovy Script

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import groovy.util.logging.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * DCheck: Platform customer service cancels order within cooling period – refund buyer
 */
@Slf4j
@Service
class CheckRefundPayForLess30min implements BaseScript {

    @Resource
    private OrderDevOpsApi orderDevOpsApi;

    @Resource
    DCheckApi dCheckApi;

    @Resource
    private PayServiceFeignClient payServiceFeignClient;

    String logTag = "TAG_CheckCrossAndOverSeaRefundPayForLess30min:{}";

    // 1. Order time – payment time < 30 minutes
    @Override
    boolean filter(JSONObject doneCleanData) {
        String unionId = doneCleanData.getString("order_no");
        String payTime = getOrderData(unionId,"payTime", DevOpsSceneEnum.FORWARD_PAY);
        long modifyTime = doneCleanData.getDate("modify_time").getTime();
        long diffTime = modifyTime - Long.valueOf(payTime);
        if (diffTime < 30 * 60 * 1000){
            return true;
        }
        log.info(logTag,"===\u003e有符合数据进入Check");
        return false;
    }

    @Override
    String check(JSONObject doneCleanData) {
        String subOrderNo = doneCleanData.getString("sub_order_no");
        Result
> listResult = dCheckApi.queryPayNoBySubOrderNo(subOrderNo);
        if(listResult == null || listResult.getData() == null){
            return "根据正向查询接口通过子订单号查询支付流水号数据为空";
        }
        if(listResult.getData().size() > 1){
            return "根据正向查询接口通过子订单号查询支付流水号多条数据,请查看是否需要优化逻辑";
        }
        String outPayNo = listResult.getData().get(0);
        RefundQueryRequest refundQueryRequest = new RefundQueryRequest();
        refundQueryRequest.setPayLogNum(outPayNo);
        Result
> resp = payServiceFeignClient.queryRefundsByPayLogNum(refundQueryRequest);
        if (resp == null || resp.getData() == null) {
            return "上游数据为空:支付退款查询(根据支付流水号)";
        } else if (resp.getData().size() != 1) {
            return "上游数据为多条请确认逻辑:支付退款查询(根据支付流水号)";
        }
        if (resp.getData().get(0).getStatus() != 2 ){
            return "校验支付打款状态非2";
        }
        if (resp.getData().get(0).getAmount() != doneCleanData.getLong("amount")) {
            return "校验交易退款金额和支付打款金额不一致";
        }
        return "SUCCESS";
    }

    // Helper to query order data
    String getOrderData(String unionNo,String key,DevOpsSceneEnum devOpsSceneEnum){
        // internal method omitted...
        return value;
    }
}

The rule configuration combines topics, events, sub‑events, and scripts. It also defines degradation strategies such as sampling percentage, initial delay, and timeout limits.

Practical tips include consolidating similar scripts, using Groovy closures for list processing, and employing mock data for local debugging.

Current platform limitations are lack of convenient debugging, script redundancy, missing circuit‑breaker mechanisms, and insufficient on/off switches. Suggested improvements cover adding a debug button, separating filter and check pools, integrating circuit‑breakers, and providing dynamic traffic control.

data consistencyReal-time Monitoringmessage queueAsset Loss PreventionGroovy ScriptsMySQL binlog
DeWu Technology
Written by

DeWu Technology

A platform for sharing and discussing tech knowledge, guiding you toward the cloud of technology.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.