Browse Source

设备在线率时间修改

develop
王兴琳 4 weeks ago
parent
commit
897261afb3
  1. 8
      zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java
  2. 5
      zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java
  3. 5
      zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java
  4. 5
      zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java
  5. 2
      zc-business/src/main/java/com/zc/business/task/DeviceOnlineTask.java

8
zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java

@ -146,7 +146,7 @@ public class DcDeviceOnlineController extends BaseController {
Map<String, Map<String, String>> maps = new HashMap<>();
LocalDateTime start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDateTime end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
List<OnlineSum> onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start.toLocalDate(), end.toLocalDate(), direction);
List<OnlineSum> onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start, end, direction);
Map<String, List<OnlineSum>> stringListMap = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType));
for (String type : types) {
Map<String, String> map = new HashMap<>();
@ -183,7 +183,7 @@ public class DcDeviceOnlineController extends BaseController {
}
// 查询数据
List<OnlineSum> onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start.toLocalDate(), end.toLocalDate(), direction);
List<OnlineSum> onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start, end, direction);
// 按设备类型分组
Map<String, List<OnlineSum>> stringListMap = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType));
@ -208,9 +208,9 @@ public class DcDeviceOnlineController extends BaseController {
LocalDateTime startHour = LocalDateTime.of(date, LocalTime.of(hour, 0));
LocalDateTime endHour = startHour.plusHours(1);
List<OnlineSum> hourList = dayList.stream()
.filter(os -> os.getStatisticalDate().toLocalDate().isAfter(ChronoLocalDate.from(startHour)) && os.getStatisticalDate().toLocalDate().isBefore(ChronoLocalDate.from(endHour)))
.filter(os -> os.getStatisticalDate().isAfter(startHour) &&
os.getStatisticalDate().isBefore(endHour))
.collect(Collectors.toList());
double averageRate = hourList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0);
hourlyMap.put(startHour.toString(), MathUtil.doubleTwoDecimalStr(averageRate) + "%");
}

5
zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java

@ -4,6 +4,7 @@ import com.zc.business.controller.queryParams.OnlineQueryParams;
import com.zc.business.domain.OnlineSum;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
public interface OnlineSumMapper {
@ -13,8 +14,8 @@ public interface OnlineSumMapper {
@Param("endDate") LocalDate endDate);
List<OnlineSum> queryByDeviceTypeAndDate(
@Param("types") String[] types,
@Param("startDate") LocalDate startDate,
@Param("endDate") LocalDate endDate,
@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate,
@Param("direction") String direction
);
List<OnlineSum> queryByDateOfDeviceType(@Param("queryDate") LocalDate queryDate);

5
zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java

@ -4,6 +4,7 @@ import com.zc.business.controller.queryParams.OnlineQueryParams;
import com.zc.business.domain.OnlineSum;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
public interface IOnlineSumService {
@ -13,8 +14,8 @@ public interface IOnlineSumService {
List<OnlineSum> queryByDeviceTypeAndDate(
String[] deviceType,
LocalDate startDate,
LocalDate endDate,
LocalDateTime startDate,
LocalDateTime endDate,
String direction
);
List<OnlineSum> queryByDateOfDeviceType(LocalDate queryDate);

5
zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java

@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Service
@ -29,8 +30,8 @@ public class OnlineSumServiceImpl implements IOnlineSumService {
@Override
public List<OnlineSum> queryByDeviceTypeAndDate(
String[] deviceType,
LocalDate startDate,
LocalDate endDate,
LocalDateTime startDate,
LocalDateTime endDate,
String direction) {
return onlineSumMapper.queryByDeviceTypeAndDate(deviceType, startDate, endDate, direction);
}

2
zc-business/src/main/java/com/zc/business/task/DeviceOnlineTask.java

@ -236,7 +236,7 @@ public class DeviceOnlineTask {
*/
private void incrementSummary(OnlineLog onlineLog) {
// 获取当天日期
String date = LocalDate.now().toString();
String date = LocalDateTime.now().toString();
long deviceId = onlineLog.getDeviceId();
OnlineSum onlineSum = redisCache.getCacheMapValue(RedisKeyConstants.DEVICE_ONLINE , date+":"+deviceId);
if (ObjectUtils.isEmpty(onlineSum)){

Loading…
Cancel
Save