需求:查询按照指定时间的前一天的数据,举个例子:传入2023/2/27 ,需要获取到2023/2/26 的数据,如果这一天没有数据,那就需要往前找,直到找不到为止;
分析:因为是从数据库根据时间查找的,就按照数据库中每条数据的时间倒叙排序一下,将符合条件的数据返回即可,奉上代码:
@Override
public R<ChronicChatLog> queryReferralTime(Date incomeTime, String referralId) {
DateTime offsetDay = DateUtil.offsetDay(incomeTime, -1);
ChronicChatLog one = this.getOne(new LambdaQueryWrapper<ChronicChatLog>()
.eq(ChronicChatLog::getSignId,referralId)
.le(ChronicChatLog::getChatTime, offsetDay)
.orderByDesc(ChronicChatLog::getChatTime)
.last("limit 1"));
return R.ok(one);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)