|
|
@@ -1,14 +1,17 @@
|
|
|
package com.gyee.runeconomy.service.auto.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.gyee.runeconomy.init.CacheContext;
|
|
|
import com.gyee.runeconomy.mapper.auto.ProEconEquipmentInfoDay4Mapper;
|
|
|
+import com.gyee.runeconomy.model.auto.ProBasicEquipment;
|
|
|
import com.gyee.runeconomy.model.auto.ProEconEquipmentInfoDay4;
|
|
|
import com.gyee.runeconomy.service.auto.IProEconEquipmentInfoDay4Service;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -22,10 +25,102 @@ import java.util.List;
|
|
|
public class ProEconEquipmentInfoDay4ServiceImpl extends ServiceImpl<ProEconEquipmentInfoDay4Mapper, ProEconEquipmentInfoDay4> implements IProEconEquipmentInfoDay4Service {
|
|
|
|
|
|
@Override
|
|
|
- public List<ProEconEquipmentInfoDay4> getpcllist(String time) {
|
|
|
+ public Map<String, Object> getpcllist(String time) {
|
|
|
QueryWrapper<ProEconEquipmentInfoDay4> qw = new QueryWrapper<>();
|
|
|
qw.eq("to_char(record_date,'yyyy-MM')", time);
|
|
|
- List<ProEconEquipmentInfoDay4> infoDay4s = baseMapper.selectList(qw);
|
|
|
- return infoDay4s;
|
|
|
+
|
|
|
+ // 1. 计算三个字段的平均值(使用聚合查询)
|
|
|
+ qw.select(
|
|
|
+ "AVG(r35mqxpcl) as avg_r35mqxpcl",
|
|
|
+ "AVG(r511mqxpcl) as avg_r511mqxpcl",
|
|
|
+ "AVG(r11mycqxpcl) as avg_r11mycqxpcl"
|
|
|
+ );
|
|
|
+ // 不需要groupBy,因为是整个时间段的聚合
|
|
|
+ Map<String, Object> avgMap = getBaseMapper().selectMaps(qw).get(0); // 返回单条Map
|
|
|
+ return avgMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> pcllist(String time) {
|
|
|
+ List<ProBasicEquipment> wtls = CacheContext.wtls;
|
|
|
+
|
|
|
+ // 创建ID到nem_code的映射,方便快速查找
|
|
|
+ Map<String, String> idToNemCodeMap = wtls.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ ProBasicEquipment::getId,
|
|
|
+ ProBasicEquipment::getNemCode,
|
|
|
+ (existing, replacement) -> existing // 如果有重复,取第一个
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 1. 找出 r35mqxpcl 的最小记录,并获取nem_code
|
|
|
+ QueryWrapper<ProEconEquipmentInfoDay4> minQwR35 = Wrappers.query();
|
|
|
+ minQwR35.select("windturbine_id", "r35mqxpcl") // 只查询需要的字段
|
|
|
+ .eq("to_char(record_date,'yyyy-MM')", time)
|
|
|
+ .orderByAsc("r35mqxpcl")
|
|
|
+ .last("LIMIT 1");
|
|
|
+ ProEconEquipmentInfoDay4 minR35Record = getOne(minQwR35);
|
|
|
+ String minR35NemCode = minR35Record != null && idToNemCodeMap.containsKey(minR35Record.getWindturbineId())
|
|
|
+ ? idToNemCodeMap.get(minR35Record.getWindturbineId()) : null;
|
|
|
+
|
|
|
+ // 2. 找出 r35mqxpcl 的最大记录,并获取nem_code
|
|
|
+ QueryWrapper<ProEconEquipmentInfoDay4> maxQwR35 = Wrappers.query();
|
|
|
+ maxQwR35.select("windturbine_id", "r35mqxpcl")
|
|
|
+ .eq("to_char(record_date,'yyyy-MM')", time)
|
|
|
+ .orderByDesc("r35mqxpcl")
|
|
|
+ .last("LIMIT 1");
|
|
|
+ ProEconEquipmentInfoDay4 maxR35Record = getOne(maxQwR35);
|
|
|
+ String maxR35NemCode = maxR35Record != null && idToNemCodeMap.containsKey(maxR35Record.getWindturbineId())
|
|
|
+ ? idToNemCodeMap.get(maxR35Record.getWindturbineId()) : null;
|
|
|
+
|
|
|
+ // 3. r511mqxpcl 最小记录
|
|
|
+ QueryWrapper<ProEconEquipmentInfoDay4> minQwR511 = Wrappers.query();
|
|
|
+ minQwR511.select("windturbine_id", "r511mqxpcl")
|
|
|
+ .eq("to_char(record_date,'yyyy-MM')", time)
|
|
|
+ .orderByAsc("r511mqxpcl")
|
|
|
+ .last("LIMIT 1");
|
|
|
+ ProEconEquipmentInfoDay4 minR511Record = getOne(minQwR511);
|
|
|
+ String minR511NemCode = minR511Record != null && idToNemCodeMap.containsKey(minR511Record.getWindturbineId())
|
|
|
+ ? idToNemCodeMap.get(minR511Record.getWindturbineId()) : null;
|
|
|
+
|
|
|
+ // 4. r511mqxpcl 最大记录
|
|
|
+ QueryWrapper<ProEconEquipmentInfoDay4> maxQwR511 = Wrappers.query();
|
|
|
+ maxQwR511.select("windturbine_id", "r511mqxpcl")
|
|
|
+ .eq("to_char(record_date,'yyyy-MM')", time)
|
|
|
+ .orderByDesc("r511mqxpcl")
|
|
|
+ .last("LIMIT 1");
|
|
|
+ ProEconEquipmentInfoDay4 maxR511Record = getOne(maxQwR511);
|
|
|
+ String maxR511NemCode = maxR511Record != null && idToNemCodeMap.containsKey(maxR511Record.getWindturbineId())
|
|
|
+ ? idToNemCodeMap.get(maxR511Record.getWindturbineId()) : null;
|
|
|
+
|
|
|
+ // 5. r11mycqxpcl 最小记录
|
|
|
+ QueryWrapper<ProEconEquipmentInfoDay4> minQwR11 = Wrappers.query();
|
|
|
+ minQwR11.select("windturbine_id", "r11mycqxpcl")
|
|
|
+ .eq("to_char(record_date,'yyyy-MM')", time)
|
|
|
+ .orderByAsc("r11mycqxpcl")
|
|
|
+ .last("LIMIT 1");
|
|
|
+ ProEconEquipmentInfoDay4 minR11Record = getOne(minQwR11);
|
|
|
+ String minR11NemCode = minR11Record != null && idToNemCodeMap.containsKey(minR11Record.getWindturbineId())
|
|
|
+ ? idToNemCodeMap.get(minR11Record.getWindturbineId()) : null;
|
|
|
+
|
|
|
+ // 6. r11mycqxpcl 最大记录
|
|
|
+ QueryWrapper<ProEconEquipmentInfoDay4> maxQwR11 = Wrappers.query();
|
|
|
+ maxQwR11.select("windturbine_id", "r11mycqxpcl")
|
|
|
+ .eq("to_char(record_date,'yyyy-MM')", time)
|
|
|
+ .orderByDesc("r11mycqxpcl")
|
|
|
+ .last("LIMIT 1");
|
|
|
+ ProEconEquipmentInfoDay4 maxR11Record = getOne(maxQwR11);
|
|
|
+ String maxR11NemCode = maxR11Record != null && idToNemCodeMap.containsKey(maxR11Record.getWindturbineId())
|
|
|
+ ? idToNemCodeMap.get(maxR11Record.getWindturbineId()) : null;
|
|
|
+
|
|
|
+ // 可以根据需要构建不同的返回格式,这里示例返回所有nem_code
|
|
|
+ Map<String, Object> summary = new HashMap<>();
|
|
|
+ summary.put("min_r35_nem_code", minR35NemCode);
|
|
|
+ summary.put("max_r35_nem_code", maxR35NemCode);
|
|
|
+ summary.put("min_r511_nem_code", minR511NemCode);
|
|
|
+ summary.put("max_r511_nem_code", maxR511NemCode);
|
|
|
+ summary.put("min_r11_nem_code", minR11NemCode);
|
|
|
+ summary.put("max_r11_nem_code", maxR11NemCode);
|
|
|
+
|
|
|
+ return summary;
|
|
|
}
|
|
|
}
|