Commit ca4b85cb authored by tianchao's avatar tianchao

1.年预测

parent 62730c67
......@@ -17,7 +17,7 @@ public class BaseProjectInfoPredictedDataEnt implements Serializable {
@XText("项目名称")
@TableField
private String projectId;
private Integer projectId;
@TableField
private String particularYear;
......@@ -51,11 +51,11 @@ public class BaseProjectInfoPredictedDataEnt implements Serializable {
this.id = id;
}
public String getProjectId() {
public Integer getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
......
......@@ -252,7 +252,7 @@ public class BaseDataService {
returnMap = XJsonUtils.toMap(ret.toString());
return returnMap;
}catch (Exception e) {
throw new RuntimeException(e);
throw new RuntimeException("调用预测接口失败");
}
}
......
......@@ -10,9 +10,11 @@ import pps.cloud.system.service.data.QuerySysDictionaryViewInput;
import pps.cloud.system.service.data.QuerySysDictionaryViewOutput;
import pps.core.base.entity.*;
import pps.core.base.mapper.*;
import pps.core.base.service.data.base_data.CalcBaseDataInput;
import pps.core.base.service.data.base_line.*;
import pps.core.base.service.data.base_line_attenuation_rate.CreateBaseLineAttenuationRateInput;
import pps.core.base.service.data.base_project_info.*;
import pps.core.base.utils.HttpUtils;
import pps.core.common.session.PpsUserSession;
import pps.core.system.entity.SysAreaEnt;
import pps.core.system.mapper.SysAreaMapper;
......@@ -20,7 +22,10 @@ import xstartup.annotation.XService;
import xstartup.base.XContext;
import xstartup.base.data.CustomQueryInput;
import xstartup.base.util.XCopyUtils;
import xstartup.base.util.XDateUtils;
import xstartup.base.util.XJsonUtils;
import xstartup.base.util.XStringUtils;
import xstartup.core.base.helper.XThreadHelper;
import xstartup.data.XListResult;
import xstartup.data.XPageResult;
import xstartup.data.XServiceResult;
......@@ -31,9 +36,9 @@ import xstartup.feature.api.annotation.XApiGet;
import xstartup.feature.api.annotation.XApiPost;
import xstartup.feature.mybatis.helper.XMapperHelper;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@XService
public class BaseProjectInfoService {
......@@ -50,9 +55,9 @@ public class BaseProjectInfoService {
entity.setCreateTime(now);
entity.setIsDeleted(0);
mapper.insert(entity);
List<BaseLineAttenuationRateView> list = new ArrayList<>();
if(!CollectionUtils.isEmpty(input.getList())){
BaseLineAttenuationRateViewMapper rateMapper = context.getBean(BaseLineAttenuationRateViewMapper.class);
List<BaseLineAttenuationRateView> list = new ArrayList<>();
for(CreateBaseLineAttenuationRateInput rateInput : input.getList()){
BaseLineAttenuationRateView ent = XCopyUtils.copyNewObject(rateInput , BaseLineAttenuationRateView.class);
ent.setCreateById(session.getId());
......@@ -64,6 +69,13 @@ public class BaseProjectInfoService {
}
rateMapper.batchInsert(list);
}
//开始预测
XThreadHelper.async(new Runnable() {
@Override
public void run() {
predictedData(context , entity , list);
}
});
return XServiceResult.OK;
}
......@@ -90,9 +102,9 @@ public class BaseProjectInfoService {
queryRateWrapper.lambda().eq(BaseLineAttenuationRateEnt::getLineId , entity.getId());
queryRateWrapper.lambda().eq(BaseLineAttenuationRateEnt::getType , 1);
rateMapper.delete(queryRateWrapper);
List<BaseLineAttenuationRateView> list = new ArrayList<>();
if(!CollectionUtils.isEmpty(input.getList())){
BaseLineAttenuationRateViewMapper rateViewMapper = context.getBean(BaseLineAttenuationRateViewMapper.class);
List<BaseLineAttenuationRateView> list = new ArrayList<>();
for(CreateBaseLineAttenuationRateInput rateInput : input.getList()){
BaseLineAttenuationRateView ent = XCopyUtils.copyNewObject(rateInput , BaseLineAttenuationRateView.class);
ent.setCreateById(session.getId());
......@@ -104,6 +116,13 @@ public class BaseProjectInfoService {
}
rateViewMapper.batchInsert(list);
}
//开始预测
XThreadHelper.async(new Runnable() {
@Override
public void run() {
predictedData(context , entity , list);
}
});
return XServiceResult.OK;
}
......@@ -202,4 +221,48 @@ public class BaseProjectInfoService {
List<GetProjectInfoPredictedDataOutput> outputs = XCopyUtils.copyNewList(pageInfo.getList(), GetProjectInfoPredictedDataOutput.class);
return XListResult.success(outputs);
}
private void predictedData(XContext context , BaseProjectInfoEnt entity , List<BaseLineAttenuationRateView> list){
CalcProjectInfoPredictedDataInput input = new CalcProjectInfoPredictedDataInput();
input.setLat(entity.getLatitude());
input.setLon(entity.getLongitude());
input.setAngle(entity.getArrayIncidence());
input.setDirection(entity.getArrayToward());
input.setCapacity(entity.getInstallCapacity());
input.setEfficiency(new BigDecimal(0.35));
input.setWeather(new BigDecimal(0.7));
List<BaseLineAttenuationRateView> sortList = list.stream().sorted(Comparator.comparing(BaseLineAttenuationRateView::getSort)).collect(Collectors.toList());
List<BigDecimal> decimals = sortList.stream().map(BaseLineAttenuationRateView::getAttenuationRate).collect(Collectors.toList());
input.setDecline(decimals);
Map<String , Object> map = getPredictedData(context , input);
//插入数据
BaseProjectInfoPredictedDataMapper mapper = context.getBean(BaseProjectInfoPredictedDataMapper.class);
QueryWrapper<BaseProjectInfoPredictedDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(BaseProjectInfoPredictedDataEnt::getProjectId , entity.getId());
mapper.delete(queryWrapper);
List<Double> powers = (List<Double>)map.get("power");
Integer particularYear = Integer.valueOf(entity.getProductionYear());
for(Double decimal : powers){
BaseProjectInfoPredictedDataEnt ent = new BaseProjectInfoPredictedDataEnt();
ent.setProjectId(entity.getId());
ent.setParticularYear(particularYear + "");
ent.setPredictedPower(BigDecimal.valueOf(decimal.doubleValue()));
particularYear ++;
mapper.insert(ent);
}
}
public Map<String , Object> getPredictedData(XContext context, CalcProjectInfoPredictedDataInput calcProjectInfoPredictedDataInput ){
Map<String , Object> returnMap = new HashMap<>();
try {
String jsonString = XJsonUtils.toJson(calcProjectInfoPredictedDataInput);
context.getLogger().info(jsonString);
Object ret = HttpUtils.send2("http://121.36.43.217:8098/model/yearmodel",
jsonString);
returnMap = XJsonUtils.toMap(ret.toString());
return returnMap;
}catch (Exception e) {
throw new RuntimeException("调用预测接口失败");
}
}
}
package pps.core.base.service.data.base_project_info;
import java.math.BigDecimal;
import java.util.List;
public class CalcProjectInfoPredictedDataInput {
private String liner_id;// 组织机构
private BigDecimal lat;// 纬度
private BigDecimal lon; // 经度
private BigDecimal angle; // 光伏仰角
private BigDecimal direction; // # 朝向# pvlib uses 0=North, 90=East, 180=South, 270=West convention
private BigDecimal capacity; // 安装功率KW
private BigDecimal efficiency; //转换效率
private List<BigDecimal> decline; //25年逐年衰减
private BigDecimal weather;
public String getLiner_id() {
return liner_id;
}
public void setLiner_id(String liner_id) {
this.liner_id = liner_id;
}
public BigDecimal getLat() {
return lat;
}
public void setLat(BigDecimal lat) {
this.lat = lat;
}
public BigDecimal getLon() {
return lon;
}
public void setLon(BigDecimal lon) {
this.lon = lon;
}
public BigDecimal getAngle() {
return angle;
}
public void setAngle(BigDecimal angle) {
this.angle = angle;
}
public BigDecimal getDirection() {
return direction;
}
public void setDirection(BigDecimal direction) {
this.direction = direction;
}
public BigDecimal getCapacity() {
return capacity;
}
public void setCapacity(BigDecimal capacity) {
this.capacity = capacity;
}
public BigDecimal getEfficiency() {
return efficiency;
}
public void setEfficiency(BigDecimal efficiency) {
this.efficiency = efficiency;
}
public List<BigDecimal> getDecline() {
return decline;
}
public void setDecline(List<BigDecimal> decline) {
this.decline = decline;
}
public BigDecimal getWeather() {
return weather;
}
public void setWeather(BigDecimal weather) {
this.weather = weather;
}
}
......@@ -14,7 +14,7 @@ public class GetProjectInfoPredictedDataOutput {
private Integer id;
@XText("项目名称")
private String projectId;
private Integer projectId;
private String particularYear;
......@@ -41,11 +41,11 @@ public class GetProjectInfoPredictedDataOutput {
this.id = id;
}
public String getProjectId() {
public Integer getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment