移动代码

This commit is contained in:
huangzj
2023-05-25 13:52:34 +08:00
parent e169fe55a6
commit 9e0d40b6fa
8 changed files with 404 additions and 0 deletions

View File

@@ -13,6 +13,27 @@
<name>cs-harmonic-api</name> <name>cs-harmonic-api</name>
<dependencies>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-db</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-microservice</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>

View File

@@ -0,0 +1,45 @@
package pojo.param;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
/**
* Description:
* Date: 2023/5/16 16:25【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Data
public class ThdDataQueryParm {
private String devId;
private String statisticalName;
/**
* 开始时间
*/
@ApiModelProperty(value = "开始时间")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@NotNull(message="开始时间不能为空!")
private String startTime;
/**
* 结束时间
*/
@ApiModelProperty(value = "结束时间")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@NotNull(message="结束时间不能为空!")
private String endTime;
}

View File

@@ -0,0 +1,34 @@
package pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
/**
* Description:
* Date: 2023/5/18 9:14【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Data
public class ThdDataVO {
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime time;
private String LineId;
private String position;
private String Phase;
private String StatMethod;
private String statisticalIndex;
private String statisticalName;
private Double statisticalData;
}

View File

@@ -40,6 +40,34 @@
<artifactId>common-db</artifactId> <artifactId>common-db</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>pqs-influx</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.9.0</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>cs-harmonic-api</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>cs-device-api</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.DependsOn;
/** /**
@@ -16,6 +17,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@MapperScan("com.njcn.**.mapper") @MapperScan("com.njcn.**.mapper")
@EnableFeignClients(basePackages = "com.njcn") @EnableFeignClients(basePackages = "com.njcn")
@SpringBootApplication(scanBasePackages = "com.njcn") @SpringBootApplication(scanBasePackages = "com.njcn")
@DependsOn("proxyMapperRegister")
public class CsHarmonicBootApplication { public class CsHarmonicBootApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -0,0 +1,86 @@
package com.njcn.harmonic.controller;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.harmonic.service.StableDataService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import pojo.param.ThdDataQueryParm;
import pojo.vo.ThdDataVO;
import java.util.List;
/**
* Description:
* Date: 2023/5/18 8:51【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Slf4j
@RestController
@RequestMapping("/stable")
@Api(tags = "稳态数据展示")
@AllArgsConstructor
public class StableDataController extends BaseController {
private final StableDataService stableDataService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryFisrtThdData")
@ApiOperation("查询谐波畸变率实时数据")
@ApiImplicitParams({
@ApiImplicitParam(name = "devId", value = "设备id", required = true),
@ApiImplicitParam(name = "statisticalName", value = "统计指标name", required = true)
})
public HttpResult<List<ThdDataVO>> queryFisrtThdData(@RequestParam("devId") String devId, @RequestParam("statisticalName") String statisticalName) {
String methodDescribe = getMethodDescribe("queryThdData");
List<ThdDataVO> list = stableDataService.queryThdData(devId, statisticalName);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryThdDataByTime")
@ApiOperation("查询时间段内谐波畸变率")
@ApiImplicitParam(name = "thdDataQueryParm", value = "查询参数", required = true)
public HttpResult<List<ThdDataVO>> queryThdDataByTime(@RequestBody @Validated ThdDataQueryParm thdDataQueryParm) {
String methodDescribe = getMethodDescribe("queryThdDataByTime");
List<ThdDataVO> list = stableDataService.queryThdDataByTime(thdDataQueryParm);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryFisrtThdContent")
@ApiOperation("查询谐波含量实时数据")
@ApiImplicitParams({
@ApiImplicitParam(name = "devId", value = "设备id", required = true),
@ApiImplicitParam(name = "statisticalName", value = "统计指标name", required = true)
})
public HttpResult<List<ThdDataVO>> queryFisrtThdContent(@RequestParam("devId") String devId, @RequestParam("statisticalName") String statisticalName) {
String methodDescribe = getMethodDescribe("queryFisrtThdContent");
List<ThdDataVO> list = stableDataService.queryFisrtThdContent(devId, statisticalName);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryThdContentByTime")
@ApiOperation("查询时间段内谐波畸变率")
@ApiImplicitParam(name = "thdDataQueryParm", value = "查询参数", required = true)
public HttpResult<List<ThdDataVO>> queryThdContentByTime(@RequestBody @Validated ThdDataQueryParm thdDataQueryParm) {
String methodDescribe = getMethodDescribe("queryThdContentByTime");
List<ThdDataVO> list = stableDataService.queryThdContentByTime(thdDataQueryParm);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
}

View File

@@ -0,0 +1,31 @@
package com.njcn.harmonic.service;
import pojo.param.ThdDataQueryParm;
import pojo.vo.ThdDataVO;
import java.util.List;
/**
* Description:
* Date: 2023/5/18 14:39【需求编号】
*
* @author clam
* @version V1.0.0
*/
public interface StableDataService {
List<ThdDataVO> queryThdData(String devId, String statisticalName);
/**
* @Description: 查询时间段内谐波畸变率
* @Param:
* @return: java.util.List<com.njcn.algorithm.pojo.vo.ThdDataVO>
* @Author: clam
* @Date: 2023/5/23
*/
List<ThdDataVO> queryThdDataByTime(ThdDataQueryParm thdDataQueryParm);
List<ThdDataVO> queryFisrtThdContent(String devId, String statisticalName);
List<ThdDataVO> queryThdContentByTime(ThdDataQueryParm thdDataQueryParm);
}

View File

@@ -0,0 +1,157 @@
package com.njcn.harmonic.service.impl;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.constant.DataParam;
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.utils.ReflectUtils;
import com.njcn.harmonic.service.StableDataService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import pojo.param.ThdDataQueryParm;
import pojo.vo.ThdDataVO;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Description:
* Date: 2023/5/18 14:39【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Service
@RequiredArgsConstructor
public class StableDataServiceImpl implements StableDataService {
private final CsLinePOService csLinePOService;
private final PowerQualityService powerQualityService;
private final HarmonicRatioService harmonicRatioService;
@Override
public List<ThdDataVO> queryThdData(String devId, String statisticalName) {
List<ThdDataVO> thdDataVOList = new ArrayList<>();
List<CsLinePO> csLinePOList = csLinePOService.queryByDevId(devId);
Optional.ofNullable(csLinePOList).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR));
List<String> collect = csLinePOList.stream().map(CsLinePO::getLineId).collect(Collectors.toList());
List<PowerQualityData> firstPowerQuality = powerQualityService.getFirstPowerQuality(collect, statisticalName);
csLinePOList.forEach(temp->{
DataParam.phases.forEach(phase->{
DataParam.statMethods.forEach(method -> {
ThdDataVO thdDataVO = new ThdDataVO();
thdDataVO.setLineId(temp.getLineId());
thdDataVO.setPosition(temp.getPosition());
thdDataVO.setStatisticalName(statisticalName);
thdDataVO.setPhase(phase);
thdDataVO.setStatMethod(method);
Double statisticalValue = 0.00;
List<PowerQualityData> collect1 = firstPowerQuality.stream().filter(powerQualityData -> Objects.equals(powerQualityData.getPhase(), phase) &&
Objects.equals(powerQualityData.getStatMethod(), method)
).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(collect1)){
statisticalValue= (Double) ReflectUtils.getValue(collect1.get(0), statisticalName);
}
thdDataVO.setStatisticalData(statisticalValue);
thdDataVOList.add(thdDataVO);
});
});
});
return thdDataVOList;
}
@Override
public List<ThdDataVO> queryThdDataByTime(ThdDataQueryParm thdDataQueryParm) {
List<ThdDataVO> thdDataVOList = new ArrayList<>();
List<CsLinePO> csLinePOList = csLinePOService.queryByDevId(thdDataQueryParm.getDevId());
Optional.ofNullable(csLinePOList).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR));
List<String> collect = csLinePOList.stream().map(CsLinePO::getLineId).collect(Collectors.toList());
List<PowerQualityData> firstPowerQuality = powerQualityService.getPowerQuality(collect, thdDataQueryParm.getStatisticalName(), thdDataQueryParm.getStartTime(), thdDataQueryParm.getEndTime());
csLinePOList.forEach(temp->{
DataParam.phases.forEach(phase->{
DataParam.statMethods.forEach(method -> {
ThdDataVO thdDataVO = new ThdDataVO();
thdDataVO.setLineId(temp.getLineId());
thdDataVO.setPosition(temp.getPosition());
thdDataVO.setStatisticalName(thdDataQueryParm.getStatisticalName());
thdDataVO.setPhase(phase);
thdDataVO.setStatMethod(method);
Double statisticalValue = 0.00;
List<PowerQualityData> collect1 = firstPowerQuality.stream().filter(powerQualityData -> Objects.equals(powerQualityData.getPhase(), phase) &&
Objects.equals(powerQualityData.getStatMethod(), method)
).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(collect1)){
statisticalValue= (Double) ReflectUtils.getValue(collect1.get(0), thdDataQueryParm.getStatisticalName());
}
thdDataVO.setStatisticalData(statisticalValue);
thdDataVOList.add(thdDataVO);
});
});
});
return thdDataVOList;
}
@Override
public List<ThdDataVO> queryFisrtThdContent(String devId, String statisticalName) {
List<ThdDataVO> thdDataVOList = new ArrayList<>();
List<CsLinePO> csLinePOList = csLinePOService.queryByDevId(devId);
Optional.ofNullable(csLinePOList).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR));
List<String> collect = csLinePOList.stream().map(CsLinePO::getLineId).collect(Collectors.toList());
List<HarmonicRatioData> harmonicRatioList = haronicRatioService.getFirstHaronicRatio(collect, statisticalName);
harmonicRatioList.forEach(temp->{
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(temp,thdDataVO);
thdDataVO.setStatisticalName(statisticalName);
thdDataVO.setTime(temp.getTime().atZone(ZoneId.systemDefault()).toLocalDateTime());
String position = csLinePOList.stream().filter(csLinePO -> Objects.equals(csLinePO.getLineId(), thdDataVO.getLineId())).collect(Collectors.toList()).get(0).getPosition();
thdDataVO.setPosition(position);
Double statisticalValue = 0.00;
statisticalValue= (Double) ReflectUtils.getValue(temp, statisticalName);
thdDataVO.setStatisticalData(statisticalValue);
thdDataVOList.add(thdDataVO);
});
return thdDataVOList;
}
@Override
public List<ThdDataVO> queryThdContentByTime(ThdDataQueryParm thdDataQueryParm) {
List<ThdDataVO> thdDataVOList = new ArrayList<>();
List<CsLinePO> csLinePOList = csLinePOService.queryByDevId(thdDataQueryParm.getDevId());
Optional.ofNullable(csLinePOList).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR));
List<String> collect = csLinePOList.stream().map(CsLinePO::getLineId).collect(Collectors.toList());
List<HarmonicRatioData> harmonicRatioList = haronicRatioService.getHaronicRatio(collect, thdDataQueryParm.getStatisticalName(),thdDataQueryParm.getStartTime(), thdDataQueryParm.getEndTime());
harmonicRatioList.forEach(temp->{
ThdDataVO thdDataVO = new ThdDataVO();
BeanUtils.copyProperties(temp,thdDataVO);
thdDataVO.setStatisticalName(thdDataQueryParm.getStatisticalName());
thdDataVO.setTime(temp.getTime().atZone(ZoneId.systemDefault()).toLocalDateTime());
String position = csLinePOList.stream().filter(csLinePO -> Objects.equals(csLinePO.getLineId(), thdDataVO.getLineId())).collect(Collectors.toList()).get(0).getPosition();
thdDataVO.setPosition(position);
Double statisticalValue = 0.00;
statisticalValue= (Double) ReflectUtils.getValue(temp, thdDataQueryParm.getStatisticalName());
thdDataVO.setStatisticalData(statisticalValue);
thdDataVOList.add(thdDataVO);
});
return thdDataVOList;
}
}