指标通用查询
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.njcn.influx.imapper;
|
||||
|
||||
import com.njcn.influx.base.InfluxDbBaseMapper;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
import com.njcn.influx.pojo.po.PowerQualityData;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/5/5 14:39
|
||||
*/
|
||||
|
||||
public interface CommonMapper extends InfluxDbBaseMapper<PowerQualityData> {
|
||||
|
||||
List<StatisticalDataDTO> getStatistical(InfluxQueryWrapper influxQueryWrapper);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.influx.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.influxdb.annotation.Column;
|
||||
import org.influxdb.annotation.Measurement;
|
||||
import retrofit2.http.Field;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2023/6/5 10:23【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
|
||||
|
||||
@Data
|
||||
public class StatisticalDataDTO {
|
||||
private String LineId;
|
||||
private String Phase;
|
||||
@Column(name = "Stat_Method")
|
||||
private String statMethod;
|
||||
private String statisticalName;
|
||||
private Double statisticalData;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.influx.service;
|
||||
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2023/6/2 16:00【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public interface CommonService {
|
||||
List<StatisticalDataDTO> commonquery(String lineId, String tableName, String columnName);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.influx.service.impl;
|
||||
|
||||
import com.njcn.influx.imapper.CommonMapper;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
import com.njcn.influx.pojo.po.HarmonicRatioData;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
import com.njcn.influx.service.CommonService;
|
||||
import com.njcn.influx.utils.ReflectUitl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2023/6/2 16:04【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CommonServiceImpl implements CommonService {
|
||||
private final CommonMapper commonMapper;
|
||||
|
||||
@Override
|
||||
public List<StatisticalDataDTO> commonquery(String lineId ,String tableName, String columnName) {
|
||||
HashMap<String, Class<?>> entityClassesByAnnotation = ReflectUitl.getEntityClassesByAnnotation();
|
||||
Class<?> aClass = entityClassesByAnnotation.get(tableName);
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(aClass,StatisticalDataDTO.class);
|
||||
influxQueryWrapper.eq("LineId",lineId).
|
||||
last(columnName,"statisticalData").
|
||||
groupBy(StatisticalDataDTO::getLineId, StatisticalDataDTO::getStatMethod, StatisticalDataDTO::getPhase);
|
||||
|
||||
List<StatisticalDataDTO> statistical = commonMapper.getStatistical(influxQueryWrapper);
|
||||
|
||||
return statistical;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.njcn.influx.utils;
|
||||
|
||||
import org.influxdb.annotation.Measurement;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2023/6/2 15:08【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public class ReflectUitl {
|
||||
|
||||
|
||||
/*
|
||||
* 获取po报下,所有有@Measurement注解的实体类;
|
||||
*/
|
||||
public static HashMap<String,Class<?>> getEntityClassesByAnnotation() {
|
||||
HashMap<String,Class<?>> result = new HashMap<>();
|
||||
List<Class<?>> classes = ReflectUitl.getClasses("com.njcn.influx.pojo.po");
|
||||
for (Class<?> clazz : classes) {
|
||||
if (clazz.isAnnotationPresent(Measurement.class)) {
|
||||
Measurement annotation = (Measurement) clazz.getAnnotation(Measurement.class);
|
||||
result.put(annotation.name(),clazz) ;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<Class<?>> getClasses(String packageName) {
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
try {
|
||||
String path = packageName.replace(".", "/");
|
||||
Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(path);
|
||||
while (resources.hasMoreElements()) {
|
||||
URL resource = resources.nextElement();
|
||||
if (resource.getProtocol().equals("file")) {
|
||||
String filePath = URLDecoder.decode(resource.getFile(), "UTF-8");
|
||||
findClassesInPackage(packageName, filePath, classes);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static void findClassesInPackage(String packageName, String packagePath, List<Class<?>> classes) {
|
||||
File packageDir = new File(packagePath);
|
||||
if (!packageDir.exists() || !packageDir.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
File[] files = packageDir.listFiles();
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
findClassesInPackage(packageName + "." + file.getName(), file.getAbsolutePath(), classes);
|
||||
} else if (file.getName().endsWith(".class")) {
|
||||
String className = packageName + "." + file.getName().substring(0, file.getName().length() - 6);
|
||||
try {
|
||||
Class<?> clazz = Class.forName(className);
|
||||
classes.add(clazz);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user