37 lines
1.2 KiB
Java
37 lines
1.2 KiB
Java
package com.guwan.backend.mongodb;
|
|
|
|
import com.mongoplus.conditions.query.LambdaQueryChainWrapper;
|
|
import com.mongoplus.service.impl.ServiceImpl;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.time.Duration;
|
|
import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Service
|
|
public class EveryReadDetailOfMongodbServiceImpl extends ServiceImpl<EveryReadDetailOfMongodb> implements EveryReadDetailOfMongodbService {
|
|
|
|
@Override
|
|
public Long getUserOneTotalTime(Long userId) {
|
|
List<EveryReadDetailOfMongodb> list = this.list(new LambdaQueryChainWrapper<>(this.getBaseMapper(), EveryReadDetailOfMongodb.class)
|
|
.eq(EveryReadDetailOfMongodb::getUserId, userId));
|
|
|
|
log.info("list: {}", list);
|
|
|
|
Long total = 0L;
|
|
for (EveryReadDetailOfMongodb everyReadDetailOfMongodb : list) {
|
|
LocalDateTime startTime = everyReadDetailOfMongodb.getStartTime();
|
|
LocalDateTime endTime = everyReadDetailOfMongodb.getEndTime();
|
|
Duration duration = Duration.between(startTime, endTime);
|
|
total += duration.getSeconds();
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
} |