|
@@ -1,6 +1,8 @@
|
|
|
package com.hfln.portal.infrastructure.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.hfln.portal.common.request.web.OnoffRecordParams;
|
|
@@ -10,7 +12,10 @@ import com.hfln.portal.infrastructure.service.DevOnOffInfoService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Objects;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -34,4 +39,46 @@ public class DevOnOffInfoServiceImpl extends ServiceImpl<DevOnOffInfoMapper, Dev
|
|
|
queryWrapper.orderByDesc(DevOnOffInfo::getCreateTime);
|
|
|
return this.baseMapper.selectPage(page, queryWrapper);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long devOfflineCount(Long devId) {
|
|
|
+ //定义时间范围
|
|
|
+ LocalDateTime start = LocalDate.now().atStartOfDay();
|
|
|
+ LocalDateTime end = start.plusDays(1);
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ LambdaQueryWrapper<DevOnOffInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(DevOnOffInfo::getDevId, devId);
|
|
|
+ queryWrapper.eq(DevOnOffInfo::getType, "off");
|
|
|
+ queryWrapper.between(DevOnOffInfo::getCreateTime, start, end);
|
|
|
+
|
|
|
+ return this.baseMapper.selectCount(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<Long, Integer> batchDevOfflineCount(Set<Long> devIds) {
|
|
|
+ if (CollectionUtils.isEmpty(devIds)) {
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime start = LocalDate.now().atStartOfDay();
|
|
|
+ LocalDateTime end = start.plusDays(1);
|
|
|
+
|
|
|
+ // 批量统计 SQL
|
|
|
+ List<Map<String, Object>> countList = this.baseMapper.selectMaps(
|
|
|
+ new QueryWrapper<DevOnOffInfo>()
|
|
|
+ .select("dev_id, COUNT(*) AS cnt")
|
|
|
+ .in("dev_id", devIds)
|
|
|
+ .eq("type", "off")
|
|
|
+ .between("create_time", start, end)
|
|
|
+ .groupBy("dev_id")
|
|
|
+ );
|
|
|
+
|
|
|
+ // 转成 Map<devId, count>
|
|
|
+ return countList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ m -> (Long) m.get("dev_id"),
|
|
|
+ m -> ((Long) m.get("cnt")).intValue()
|
|
|
+ ));
|
|
|
+ }
|
|
|
}
|