移动代码

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

@@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
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")
@EnableFeignClients(basePackages = "com.njcn")
@SpringBootApplication(scanBasePackages = "com.njcn")
@DependsOn("proxyMapperRegister")
public class CsHarmonicBootApplication {
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;
}
}