diff --git a/pqs-influx/src/main/java/com/njcn/influx/imapper/CommonMapper.java b/pqs-influx/src/main/java/com/njcn/influx/imapper/CommonMapper.java new file mode 100644 index 000000000..0e89ea005 --- /dev/null +++ b/pqs-influx/src/main/java/com/njcn/influx/imapper/CommonMapper.java @@ -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 { + + List getStatistical(InfluxQueryWrapper influxQueryWrapper); + +} diff --git a/pqs-influx/src/main/java/com/njcn/influx/pojo/dto/StatisticalDataDTO.java b/pqs-influx/src/main/java/com/njcn/influx/pojo/dto/StatisticalDataDTO.java new file mode 100644 index 000000000..ea4a5c7e1 --- /dev/null +++ b/pqs-influx/src/main/java/com/njcn/influx/pojo/dto/StatisticalDataDTO.java @@ -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; +} diff --git a/pqs-influx/src/main/java/com/njcn/influx/service/CommonService.java b/pqs-influx/src/main/java/com/njcn/influx/service/CommonService.java new file mode 100644 index 000000000..05111013f --- /dev/null +++ b/pqs-influx/src/main/java/com/njcn/influx/service/CommonService.java @@ -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 commonquery(String lineId, String tableName, String columnName); +} diff --git a/pqs-influx/src/main/java/com/njcn/influx/service/impl/CommonServiceImpl.java b/pqs-influx/src/main/java/com/njcn/influx/service/impl/CommonServiceImpl.java new file mode 100644 index 000000000..726cf94de --- /dev/null +++ b/pqs-influx/src/main/java/com/njcn/influx/service/impl/CommonServiceImpl.java @@ -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 commonquery(String lineId ,String tableName, String columnName) { + HashMap> 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 statistical = commonMapper.getStatistical(influxQueryWrapper); + + return statistical; + + } +} diff --git a/pqs-influx/src/main/java/com/njcn/influx/utils/ReflectUitl.java b/pqs-influx/src/main/java/com/njcn/influx/utils/ReflectUitl.java new file mode 100644 index 000000000..aff77985d --- /dev/null +++ b/pqs-influx/src/main/java/com/njcn/influx/utils/ReflectUitl.java @@ -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> getEntityClassesByAnnotation() { + HashMap> result = new HashMap<>(); + List> 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> getClasses(String packageName) { + List> classes = new ArrayList>(); + try { + String path = packageName.replace(".", "/"); + Enumeration 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> 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(); + } + } + } + } + + + + +}