按步长检索数据,放缓有问题数据的处理

示例:捞取符合条件的数据

SELECT * FROM tbDebtTransfer where nDebtState in (0, 4, 5, 8)
                AND lLastTimeMillis < ({currentTimeMillis}-{lTimeMillisInterval|0} * nStep);

【说明】:

lLastTimeMillis :上次操作数据表的时间戳;

currentTimeMillis:当前时间戳

lTimeMillisInterval:步长的基数(例如,基数 lTimeMillisInterval 为 5*60*1000 = 300,000,2次捞取,数据仍未处理,第3次捞取的时间间隔为:lTimeMillisInterval * nStep = 300,000 * 3)

调节数据捞取的节奏:

if (nState == Success) {
    DebtTransferServiceUtil.updateDebtTransfer(lId,
            "nDebtState", DebtEnum.Info_Success.getCode(),
            "strMsg", DebtEnum.Info_Success.getMsg(),
            "nStep",0
    );
}else{
    log.error("代偿失败!req=" + cdoRequest);
    DebtTransferServiceUtil.updateDebtTransfer(lId,
            "nDebtState", DebtEnum.Info_Failure.getCode(),
            "strMsg", DebtEnum.Info_Failure.getMsg(),
            "nStep",1
    );
}

数据结构(部分字段):

CREATE TABLE `tbDebtTransfer` (
  `lId` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `nDebtState` int(11) NOT NULL DEFAULT '0' COMMENT '代偿状态 0-初始值,1-代偿中,2-代偿成功',
  `dtCreateTime` datetime NOT NULL COMMENT '创建时间',
  `dtModifyTime` datetime NOT NULL COMMENT '最后修改时间',
  `strMsg` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT '状态信息',
  `nStep` int(11) NOT NULL DEFAULT '0' COMMENT '步长 每访问一次,加1',
  PRIMARY KEY (`lId`),
  KEY `nDebtState` (`nDebtState`)
) ENGINE=InnoDB AUTO_INCREMENT=335 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='代偿表';
原文地址:https://www.cnblogs.com/bridgestone29-08/p/9204358.html