|
@@ -1,11 +1,15 @@
|
|
|
package com.bizmatics.mhfire.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
import com.bizmatics.mhfire.model.DeviceInfo;
|
|
|
import com.bizmatics.mhfire.persistence.mapper.DeviceInfoMapper;
|
|
|
import com.bizmatics.mhfire.service.DeviceInfoService;
|
|
|
-import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 设备心跳 服务实现类
|
|
@@ -17,4 +21,36 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class DeviceInfoServiceImpl extends AbstractCrudService<DeviceInfoMapper, DeviceInfo> implements DeviceInfoService {
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> elIco(String deviceCode, Date startTime, Date endTime) {
|
|
|
+ QueryWrapper<DeviceInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.select("HOUR(lasj) createTime","sum(electric) as elCount")
|
|
|
+ .between("create_time",startTime,endTime)
|
|
|
+ .eq("device_code",deviceCode)
|
|
|
+ .groupBy("createTime");
|
|
|
+ List<Map<String, Object>> list = this.listMaps(queryWrapper);
|
|
|
+ perfectDate(list,24,0);
|
|
|
+ list = list.stream()
|
|
|
+ .sorted(Comparator.comparing(map -> Integer.valueOf(map.get("createTime").toString())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void perfectDate(List<Map<String,Object>> list,Integer times,Integer defaultTime){
|
|
|
+ for (int i = defaultTime; i < times; i++) {
|
|
|
+ int finalI = i;
|
|
|
+ list.stream()
|
|
|
+ .filter(parkDTO -> Integer.parseInt(parkDTO.get("createTime").toString()) == finalI)
|
|
|
+ .findFirst()
|
|
|
+ .orElseGet(() -> {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("elCount",0);
|
|
|
+ map.put("createTime",finalI);
|
|
|
+ list.add(map);
|
|
|
+ return map;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|