| | |
| | | LambdaQueryWrapper<T> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.orderByDesc(timeField).last("LIMIT 1"); |
| | | T lastRecord = service.getOne(queryWrapper); |
| | | |
| | | if (lastRecord == null) { |
| | | return null; |
| | | } |
| | | try { |
| | | Method writeReplace = timeField.getClass().getDeclaredMethod("writeReplace"); |
| | | writeReplace.setAccessible(true); |
| | | SerializedLambda lambda = (SerializedLambda) writeReplace.invoke(timeField); |
| | | // 获取方法名 |
| | | String methodName = lambda.getImplMethodName(); |
| | | // 转字段名 |
| | | String fieldName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4); |
| | | Field field = lastRecord.getClass().getDeclaredField(fieldName); |
| | | field.setAccessible(true); |
| | | return (LocalDateTime) field.get(lastRecord); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("获取最后同步时间失败", e); |
| | | Object value = timeField.apply(lastRecord); |
| | | |
| | | if (value instanceof LocalDateTime) { |
| | | return (LocalDateTime) value; |
| | | } |
| | | return null; |
| | | } |
| | | } |