代码提交

This commit is contained in:
wr
2023-06-19 20:25:56 +08:00
parent 190380610e
commit e007c94976
4 changed files with 256 additions and 183 deletions

View File

@@ -130,6 +130,12 @@
<version>3.0.10</version>
</dependency>
<dependency>
<groupId>org.joda.time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-db</artifactId>

View File

@@ -1,17 +1,22 @@
package com.njcn.syncdata.controller;
import com.alibaba.fastjson.JSONArray;
import com.njcn.syncdata.pojo.po.AdsAstXbjcptGetFctgDi;
import com.njcn.syncdata.pojo.po.PWFeederLinePSR;
import com.njcn.syncdata.pojo.po.PWOPTransformerPSR;
import com.njcn.syncdata.pojo.po.Substation;
import com.njcn.syncdata.service.IPowerDistributionareaService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.*;
@RestController
@Slf4j
@RequestMapping("/dataImport")
@RequiredArgsConstructor
public class DataImportController {
@@ -20,52 +25,78 @@ public class DataImportController {
/**
* 登录获取token
*
* @return
*/
@GetMapping("/token")
public String token(){
public String token() {
return service.LoginToken();
}
/**
* 获取数据中台数据
*
* @return
*/
@GetMapping("/getAdsList")
public String adsList(){
public List<AdsAstXbjcptGetFctgDi> adsList() {
return service.adsList();
}
/**
* 获取数据中台返回体
* @param token
* 获取业务中台返回体
*
* @param psrType
* @param fieldName
* @param fieldValue
* @return
*/
@GetMapping("/getResource")
public Map getResource(String token,String psrType, String fieldName,String fieldValue){
return service.getResourceData(token,psrType,100,fieldName,fieldValue);
public Map getResource(String psrType, String fieldName, String fieldValue) {
return service.getResourceData(service.LoginToken(), psrType, 100, fieldName, fieldValue);
}
/**
* 获取数据中台返回数据
* @param token
* 获取业务中台返回数据
*
* @param psrType
* @param fieldName
* @param fieldValue
* @return
*/
@GetMapping("/getResourceData")
public List getResourceData(String token,String psrType, String fieldName,String fieldValue){
Map map = service.getResourceData(token, psrType,100, fieldName, fieldValue);
public List getResourceData(String psrType, String fieldName, String fieldValue) {
Map map = service.getResourceData(service.LoginToken(), psrType, 100, fieldName, fieldValue);
List<PWOPTransformerPSR> data = JSONArray.parseArray(JSONArray.toJSONString(map.get("result")), PWOPTransformerPSR.class);
return data;
}
@GetMapping("/insertData")
public String getResourceData(){
String s = service.insertData();
@GetMapping("/getResourceTest")
public List getResourceTest(Integer type, String fieldValue) {
List<?> aas = new ArrayList<>();
if (type == 1) {
Map transformerData = service.getResourceData(service.LoginToken(), "PWOPTransformerPSR", 100, "ACCOUNT_ID", fieldValue);
aas = JSONArray.parseArray(JSONArray.toJSONString(transformerData.get("result")), PWOPTransformerPSR.class);
} else if (type == 2) {
Map feederLineData = service.getResourceData(service.LoginToken(), "PWFeederLinePSR", 100, "ID", fieldValue);
aas = JSONArray.parseArray(JSONArray.toJSONString(feederLineData.get("result")), PWFeederLinePSR.class);
//查询变电站
} else {
Map substationData = service.getResourceData(service.LoginToken(), "Substation", 100, "ID", fieldValue);
aas = JSONArray.parseArray(JSONArray.toJSONString(substationData.get("result")), Substation.class);
}
return aas;
}
@PostMapping("/insertData")
public String insertData() {
String s = service.insertData(1);
return s;
}
@PostMapping("/insertDataTest")
public String insertDataTest() {
String s = service.insertData(0);
return s;
}
}

View File

@@ -1,8 +1,10 @@
package com.njcn.syncdata.service;
import com.njcn.db.service.IReplenishMybatisService;
import com.njcn.syncdata.pojo.po.AdsAstXbjcptGetFctgDi;
import com.njcn.syncdata.pojo.po.PowerDistributionarea;
import java.util.List;
import java.util.Map;
/**
@@ -25,7 +27,7 @@ public interface IPowerDistributionareaService extends IReplenishMybatisService<
* 获取数据中台数据
* @return
*/
String adsList();
List<AdsAstXbjcptGetFctgDi> adsList();
/**
* 通用资源数据中台数据查询
@@ -37,5 +39,5 @@ public interface IPowerDistributionareaService extends IReplenishMybatisService<
*/
Map getResourceData(String token,String psrType,Integer num, String fieldName,String fieldValue);
String insertData();
String insertData(Integer type);
}

View File

@@ -2,6 +2,9 @@ package com.njcn.syncdata.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -17,6 +20,7 @@ import com.njcn.syncdata.pojo.po.*;
import com.njcn.syncdata.service.IPowerDistributionareaService;
import com.njcn.syncdata.utils.RestTemplateUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -24,8 +28,6 @@ import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.util.UriComponentsBuilder;
@@ -46,10 +48,10 @@ import java.util.stream.Collectors;
* @since 2022-10-14
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImpl<PowerDistributionareaMapper, PowerDistributionarea> implements IPowerDistributionareaService {
private static Logger logger = LoggerFactory.getLogger(PowerDistributionareaServiceImpl.class);
private final DictDataMapper dictDataMapper;
@Override
@@ -71,7 +73,7 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
ResponseEntity<Map> userEntity = RestTemplateUtil.post(uri, Map.class);
if (userEntity.getStatusCodeValue() == 200) {
logger.debug(Thread.currentThread().getName() + "数据:" + userEntity.getBody() + "结束----");
log.info(Thread.currentThread().getName() + "数据:" + userEntity.getBody() + "结束----");
//获取返回体
Map body = userEntity.getBody();
Map data = (Map) body.get("result");
@@ -81,8 +83,8 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
}
@Override
public String adsList() {
String s = null;
public List<AdsAstXbjcptGetFctgDi> adsList() {
List<AdsAstXbjcptGetFctgDi> aas = new ArrayList<>();
String key = "0e3bac160fd246f181ad4fd47da6929a";
String secret = "383b4b2536234d84ac909cd605762061";
String url = "http://0f92aaf3da9b4dd2ab80a337495ccf09.apigw.he-region-2.sgic.sgcc.com.cn/ast/yxywyyxt/dws/get_e_mp_fctg_zl";
@@ -106,7 +108,7 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
//API中 Body体参数
//request.setBody("demo");
} catch (Exception e) {
logger.error(Thread.currentThread().getName() + "链接" + apiName + "失败");
log.error(Thread.currentThread().getName() + "链接" + apiName + "失败");
e.printStackTrace();
}
try {
@@ -119,26 +121,25 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
HttpResponse response = client.execute(signedRequest);
//Print the status line of the response.
logger.debug(response.getStatusLine().toString());
log.info(response.getStatusLine().toString());
//Print the header fields of the response.
Header[] resHeaders = response.getAllHeaders();
for (Header h : resHeaders) {
logger.debug(h.getName() + ":" + h.getValue());
log.info(h.getName() + ":" + h.getValue());
}
//Print the body of the response.
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
s = EntityUtils.toString(resEntity, "UTF-8");
logger.debug(System.getProperty("line.separator") + s);
// JSONObject jsonObject = JSON.parseObject(s);
// JSONArray data = jsonObject.getJSONArray("data");
// logger.debug(System.getProperty("line.separator") + data);
// List<AdsAstXbjcptGetFctgDi> aas = JSONArray.parseArray(s, AdsAstXbjcptGetFctgDi.class);
String s = EntityUtils.toString(resEntity, "UTF-8");
log.info(System.getProperty("line.separator") + s);
JSONObject jsonObject = JSON.parseObject(s);
Map data = jsonObject.getObject("data", Map.class);
aas = JSONArray.parseArray(data.get("data").toString(), AdsAstXbjcptGetFctgDi.class);
}
} catch (Exception e) {
logger.error(Thread.currentThread().getName() + "链接" + apiName + "失败");
log.error(Thread.currentThread().getName() + "链接" + apiName + "失败");
e.printStackTrace();
} finally {
try {
@@ -149,12 +150,12 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
e.printStackTrace();
}
}
return s;
return aas;
}
@Override
public Map getResourceData(String token, String psrType,Integer num, String fieldName, String fieldValue) {
Map body=new HashMap();
public Map getResourceData(String token, String psrType, Integer num, String fieldName, String fieldValue) {
Map body = new HashMap();
String userUrl = "http://dwzyywzt.com/PSRCenter/queryServices/commonQuery";
Map<String, String> mapHeader = new HashMap<>();
@@ -178,161 +179,191 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
mapSubset.put("filters", info);
map1.put("params", mapSubset);
ResponseEntity<Map> userEntity = RestTemplateUtil.post(userUrl, mapHeader, map1, Map.class, new ArrayList<>());
if (userEntity.getStatusCodeValue() == 200) {
logger.debug(Thread.currentThread().getName() + "数据:" + userEntity.getBody() + "结束----");
//获取返回体
body = userEntity.getBody();
body = userEntity.getBody();
log.info(Thread.currentThread().getName() + "获取返回体 getResourceData" + body + "结束----");
}
return body;
}
@Override
public String insertData() {
//初始化集合
List<PowerDistributionarea> info = new ArrayList<>();
public String insertData(Integer type) {
String message = "数据导入成功!";
try {
//初始化集合
List<PowerDistributionarea> info = new ArrayList<>();
List<String> orgID = new ArrayList<>();
String token = null;
//1.获取数据台账信息
String token= LoginToken();
//1.获取数据台账信息
String s1 = adsList();
JSONObject jsonObject = JSON.parseObject(s1);
JSONArray data = jsonObject.getJSONArray("result");
List<AdsAstXbjcptGetFctgDi> aas = JSONArray.parseArray(String.valueOf(data), AdsAstXbjcptGetFctgDi.class);
//获取数据中台数据
List<AdsAstXbjcptGetFctgDi> aas = adsList();
// String s = "[{\"tg_id\":\"824843\",\"trans_pms_id\":\"73a32eea908afa989256723aa9015673a323181105\",\"id\":\"1415129064\",\"tg_name\":\"【混全】10kV722协神线东安香村南1号160公用配变\",\"tg_no\":\"0010034073\",\"pub_priv_flag\":\"01\",\"org_no\":\"134011910\",\"org_name\":\"行唐县安香供电所\",\"org_type\":\"06\",\"p_org_no\":\"1340119\",\"run_status_code\":\"01\",\"tg_cap\":160.0,\"fc_num\":2,\"fc_sum_cap\":44.8},\n" +
// " {\"tg_id\":\"825000\",\"trans_pms_id\":\"bc82f8391f8afa9890505facdb0150bc820b995f08\",\"id\":\"1411391450\",\"tg_name\":\"【混全】10kV722协神线东安香社厂100公用配变\",\"tg_no\":\"0010034337\",\"pub_priv_flag\":\"01\",\"org_no\":\"134011910\",\"org_name\":\"行唐县安香供电所\",\"org_type\":\"06\",\"p_org_no\":\"1340119\",\"run_status_code\":\"01\",\"tg_cap\":100.0,\"fc_num\":2,\"fc_sum_cap\":52.0}," +
// "{\"tg_id\":\"825000\",\"trans_pms_id\":\"bc82f8391f8afa9890505facdb0150bc820b995f08\",\"id\":\"1411391450\",\"tg_name\":\"【混全】10kV722协神线东安香社厂100公用配变\",\"tg_no\":\"0010034337\",\"pub_priv_flag\":\"01\",\"org_no\":\"134011910\",\"org_name\":\"行唐县安香供电所\",\"org_type\":\"06\",\"p_org_no\":\"1340119\",\"run_status_code\":\"01\",\"tg_cap\":100.0,\"fc_num\":2,\"fc_sum_cap\":52.0}," +
// "{\"tg_id\":\"825001\",\"trans_pms_id\":\"c06e78c12c8afa98904fb5b289014fc06e636c1f90\",\"id\":\"1411391450\",\"tg_name\":\"【混全】10kV722协神线东安香社厂100公用配变\",\"tg_no\":\"0010034337\",\"pub_priv_flag\":\"01\",\"org_no\":\"134011910\",\"org_name\":\"行唐县安香供电所\",\"org_type\":\"06\",\"p_org_no\":\"1340119\",\"run_status_code\":\"01\",\"tg_cap\":100.0,\"fc_num\":2,\"fc_sum_cap\":52.0}]";
// List<AdsAstXbjcptGetFctgDi> aas = JSONArray.parseArray(s, AdsAstXbjcptGetFctgDi.class);
Assert.isTrue(CollUtil.isNotEmpty(aas), "获取中台数据为空!");
//进行数据拆分查询
ArrayList<AdsAstXbjcptGetFctgDi> dome = aas.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(AdsAstXbjcptGetFctgDi::getTg_id))), ArrayList::new));
//2.1.1获取电压字典
List<DictData> devVoltage = dictDataMapper.selectList(DicDataTypeEnum.DEV_VOLTAGE.getCode());
//2.1.2运行状态
DictData state = dictDataMapper.selectByCode(DicDataEnum.RUN.getCode(), DicDataTypeEnum.LINE_STATE.getCode());
//2.1.3分布式光伏字典
DictData photovoltaics = dictDataMapper.selectByCode(DicDataEnum.DISTRIBUTED_PHOTOVOLTAICS.getCode(), DicDataTypeEnum.MONITORING_LABELS.getCode());
//2.1.4地区特征
List<DictData> regional = dictDataMapper.selectList(DicDataTypeEnum.DEVICE_REGIONLYPE.getCode());
//2.1.5使用性质
List<DictData> userNature = dictDataMapper.selectList(DicDataTypeEnum.DEVICE_USERNATURE.getCode());
//2.1.6获取部门字典
List<Dept> depts = dictDataMapper.selectUserList();
//3.设置需要进行的分片数据
Integer num = 1000;
int totalCount = dome.size();
List<List<AdsAstXbjcptGetFctgDi>> pageList = ListUtil.split(dome, num);
//进行数据拆分查询
Set<AdsAstXbjcptGetFctgDi> aa = new HashSet<>(aas);
List<AdsAstXbjcptGetFctgDi> dome = new ArrayList<>(aa);
//2.1.1获取电压字典
List<DictData> devVoltage = dictDataMapper.selectList(DicDataTypeEnum.DEV_VOLTAGE.getCode());
//2.1.2运行状态
DictData state = dictDataMapper.selectByCode(DicDataEnum.RUN.getCode(),DicDataTypeEnum.LINE_STATE.getCode());
//2.1.3分布式光伏字典
DictData photovoltaics = dictDataMapper.selectByCode(DicDataEnum.DISTRIBUTED_PHOTOVOLTAICS.getCode(),DicDataTypeEnum.MONITORING_LABELS.getCode());
//2.1.4地区特征
List<DictData> regional = dictDataMapper.selectList(DicDataTypeEnum.DEVICE_REGIONLYPE.getCode());
//2.1.5使用性质
List<DictData> userNature = dictDataMapper.selectList(DicDataTypeEnum.DEVICE_USERNATURE.getCode());
//2.1.6获取部门字典
List<Dept> depts = dictDataMapper.selectUserList();
//3.设置需要进行的分片数据
Integer num = 1000;
int totalCount = dome.size();
List<List<AdsAstXbjcptGetFctgDi>> pageList = ListUtil.split(dome, num);
Integer forNum = totalCount % num == 0 ? (totalCount / num) : (totalCount / num + 1);
for (Integer i = 0; i < forNum; i++) {
List<AdsAstXbjcptGetFctgDi> temList = pageList.get(i);
List<String> trans_pms_id = temList.stream().map(AdsAstXbjcptGetFctgDi::getTrans_pms_id).distinct().collect(Collectors.toList());
//1.需要查询的户外变id
String transPmsIds = String.join(",", trans_pms_id);
List<PWOPTransformerPSR> transformer = resourceMethod(1, token, num, transPmsIds, PWOPTransformerPSR.class);
List<String> root_id = transformer.stream().map(PWOPTransformerPSR::getROOT_ID).distinct().collect(Collectors.toList());
if(CollUtil.isEmpty(root_id)){
continue;
}
//2.查询配网馈线id
String rootIds = String.join(",", root_id);
List<PWFeederLinePSR> line = resourceMethod(2, token, num, rootIds, PWFeederLinePSR.class);
List<String> start_station_id = line.stream().map(PWFeederLinePSR::getStart_station_id).distinct().collect(Collectors.toList());
if(CollUtil.isEmpty(start_station_id)){
continue;
}
//3.查询变电站id
String substationIds = String.join(",", start_station_id);
List<Substation> substation = resourceMethod(3, token, num, substationIds, Substation.class);
if(CollUtil.isEmpty(substation)){
continue;
}
// List<PWOPTransformerPSR> transformer =this.staticMethod(1,PWOPTransformerPSR.class);
// List<PWFeederLinePSR> line =this.staticMethod(2,PWFeederLinePSR.class);
// List<Substation> substation =this.staticMethod(3,Substation.class);
Map<String, PWOPTransformerPSR> transformerMap = transformer.stream().collect(Collectors.toMap(PWOPTransformerPSR::getACCOUNT_ID, Function.identity(), (key1, kye2) -> key1));
Map<String, PWFeederLinePSR> lineMap = line.stream().collect(Collectors.toMap(PWFeederLinePSR::getID, Function.identity(), (key1, kye2) -> key1));
Map<String, Substation> substationMap = substation.stream().collect(Collectors.toMap(Substation::getID, Function.identity(), (key1, kye2) -> key1));
for (AdsAstXbjcptGetFctgDi fctgDi : temList) {
PowerDistributionarea area = new PowerDistributionarea();
area.setId(fctgDi.getTg_id());
area.setName(fctgDi.getTg_name());
//从户外变查询数据查询数据是否存在
if (transformerMap.containsKey(fctgDi.getTrans_pms_id())) {
PWOPTransformerPSR pwopTransformerPSR = transformerMap.get(fctgDi.getTrans_pms_id());
if (lineMap.containsKey(pwopTransformerPSR.getROOT_ID())) {
PWFeederLinePSR pwFeederLinePSR = lineMap.get(pwopTransformerPSR.getROOT_ID());
if (substationMap.containsKey(pwFeederLinePSR.getStart_station_id())) {
Substation sub = substationMap.get(pwFeederLinePSR.getStart_station_id());
//名称暂时不知道
area.setOrgName(getDeptName(pwFeederLinePSR.getDEPART(),depts));
area.setOrgId(pwFeederLinePSR.getDEPART());
area.setOperationName(getDeptName(pwFeederLinePSR.getMAINTENANCE_TEAM(),depts));
area.setOperationId(pwFeederLinePSR.getMAINTENANCE_TEAM());
area.setPowerrName(sub.getNAME());
area.setPowerStationId(sub.getID());
area.setLineName(pwFeederLinePSR.getName());
area.setLineId(pwFeederLinePSR.getID());
//todo 要做处理(处理)
area.setVoltageLevel(getAlgoDescribe(pwopTransformerPSR.getVOLTAGELEVEL_ID(),devVoltage));
area.setPCapacity(fctgDi.getTg_cap().floatValue());
//todo 要做处理(未处理)
area.setRegionalism(getAlgoDescribe(pwopTransformerPSR.getREGION_TYPE(),regional));
area.setIfRuralPowerGrid(pwopTransformerPSR.getIS_RURAL_GRID());
//todo 要做处理(未处理)
area.setNatureOfUse(getAlgoDescribe(pwopTransformerPSR.getUse_nature(),userNature));
area.setPowerSupplyRadius(pwFeederLinePSR.getSUPPLY_RADIUS().floatValue());
area.setLineLength(pwFeederLinePSR.getLENGTH().floatValue());
//todo 要做处理(处理)
area.setState(state.getId());
area.setDistributedPhotovoltaicNum(fctgDi.getFc_num());
area.setPhotovoltaicCapacity(fctgDi.getFc_sum_cap().floatValue());
area.setIfBevAp(0);
area.setApLoadType(photovoltaics.getId());
area.setIsUpToGrid(1);
area.setStatus(1);
area.setCreateTime(LocalDateTime.now());
area.setUpdateTime(LocalDateTime.now());
area.setInputStatus(1);
info.add(area);
}
}
} else {
Integer forNum = totalCount % num == 0 ? (totalCount / num) : (totalCount / num) + 1;
for (Integer i = 0; i < forNum; i++) {
List<AdsAstXbjcptGetFctgDi> temList = pageList.get(i);
List<String> trans_pms_id = temList.stream().map(AdsAstXbjcptGetFctgDi::getTrans_pms_id).distinct().collect(Collectors.toList());
//1.需要查询的户外变id
String transPmsIds = String.join(",", trans_pms_id);
List<PWOPTransformerPSR> transformer = resourceMethod(1, token, num, transPmsIds, PWOPTransformerPSR.class);
log.info(Thread.currentThread().getName() + "1.数据添加 transformerID" + trans_pms_id.size() + "条数" + transPmsIds + "结束----");
log.info(Thread.currentThread().getName() + "1.数据添加 transformer" + transformer.size() + "条数" + transformer + "结束----");
if (CollUtil.isEmpty(transformer)) {
continue;
}
List<String> root_id = transformer.stream().map(PWOPTransformerPSR::getROOT_ID).distinct().collect(Collectors.toList());
//2.查询配网馈线id
String rootIds = String.join(",", root_id);
List<PWFeederLinePSR> line = resourceMethod(2, token, num, rootIds, PWFeederLinePSR.class);
log.info(Thread.currentThread().getName() + "2.数据添加 lineID" + root_id.size() + "条数" + rootIds + "结束----");
log.info(Thread.currentThread().getName() + "2.数据添加 line" + line.size() + "条数" + line + "结束----");
if (CollUtil.isEmpty(line)) {
continue;
}
List<String> start_station_id = line.stream().map(PWFeederLinePSR::getStart_station_id).distinct().collect(Collectors.toList());
//3.查询变电站id
String substationIds = String.join(",", start_station_id);
List<Substation> substation = resourceMethod(3, token, num, substationIds, Substation.class);
log.info(Thread.currentThread().getName() + "3.数据添加 substationID" + start_station_id.size() + "条数" + substationIds + "结束----");
log.info(Thread.currentThread().getName() + "3.数据添加 substation" + substation.size() + "条数" + substation + "结束----");
if (CollUtil.isEmpty(substation)) {
continue;
}
Map<String, PWOPTransformerPSR> transformerMap = transformer.stream().collect(Collectors.toMap(PWOPTransformerPSR::getACCOUNT_ID, Function.identity(), (key1, kye2) -> key1));
Map<String, PWFeederLinePSR> lineMap = line.stream().collect(Collectors.toMap(PWFeederLinePSR::getID, Function.identity(), (key1, kye2) -> key1));
Map<String, Substation> substationMap = substation.stream().collect(Collectors.toMap(Substation::getID, Function.identity(), (key1, kye2) -> key1));
for (AdsAstXbjcptGetFctgDi fctgDi : temList) {
PowerDistributionarea area = new PowerDistributionarea();
area.setId(fctgDi.getTg_id());
area.setName(fctgDi.getTg_name());
//从户外变查询数据查询数据是否存在
if (transformerMap.containsKey(fctgDi.getTrans_pms_id())) {
PWOPTransformerPSR pwopTransformerPSR = transformerMap.get(fctgDi.getTrans_pms_id());
if (lineMap.containsKey(pwopTransformerPSR.getROOT_ID())) {
PWFeederLinePSR pwFeederLinePSR = lineMap.get(pwopTransformerPSR.getROOT_ID());
if (substationMap.containsKey(pwFeederLinePSR.getStart_station_id())) {
Substation sub = substationMap.get(pwFeederLinePSR.getStart_station_id());
//名称暂时不知道
area.setOrgName(getDeptName(pwFeederLinePSR.getDEPART(), depts));
area.setOrgId(pwFeederLinePSR.getDEPART());
area.setOperationName(getDeptName(pwFeederLinePSR.getMAINTENANCE_TEAM(), depts));
area.setOperationId(pwFeederLinePSR.getMAINTENANCE_TEAM());
area.setPowerrName(sub.getNAME());
area.setPowerStationId(sub.getID());
area.setLineName(pwFeederLinePSR.getName());
area.setLineId(pwFeederLinePSR.getID());
if (StrUtil.isBlank(area.getOrgName())) {
orgID.add(area.getOrgId());
continue;
}
if (StrUtil.isBlank(area.getOperationName())) {
orgID.add(area.getOperationId());
continue;
}
//判断传入的电压等级,台区区域,使用性质是否为空
if(StrUtil.hasBlank(pwopTransformerPSR.getVOLTAGELEVEL_ID(),
pwopTransformerPSR.getREGION_TYPE(),
pwopTransformerPSR.getUse_nature())
){
continue;
}
if(StrUtil.hasBlank(pwopTransformerPSR.getVOLTAGELEVEL_ID(),
pwopTransformerPSR.getREGION_TYPE(),
pwopTransformerPSR.getUse_nature())
){
continue;
}
//todo 要做处理(处理)
area.setVoltageLevel(getAlgoDescribe(pwopTransformerPSR.getVOLTAGELEVEL_ID(), devVoltage));
//todo 要做处理(处理)
area.setRegionalism(getAlgoDescribe(pwopTransformerPSR.getREGION_TYPE(), regional));
//todo 要做处理(处理)
area.setNatureOfUse(getAlgoDescribe(pwopTransformerPSR.getUse_nature(), userNature));
//判断数据是否为空
if(ObjectUtil.hasNull(fctgDi.getTg_cap(),
pwFeederLinePSR.getSUPPLY_RADIUS(),
pwFeederLinePSR.getLENGTH(),
fctgDi.getFc_sum_cap())
){
continue;
}
area.setPCapacity(fctgDi.getTg_cap().floatValue());
area.setIfRuralPowerGrid(pwopTransformerPSR.getIS_RURAL_GRID());
area.setPowerSupplyRadius(pwFeederLinePSR.getSUPPLY_RADIUS().floatValue());
area.setLineLength(pwFeederLinePSR.getLENGTH().floatValue());
//todo 要做处理(处理)
area.setState(state.getId());
area.setDistributedPhotovoltaicNum(fctgDi.getFc_num());
area.setPhotovoltaicCapacity(fctgDi.getFc_sum_cap().floatValue());
area.setIfBevAp(0);
area.setApLoadType(photovoltaics.getId());
area.setIsUpToGrid(1);
area.setStatus(1);
area.setCreateTime(LocalDateTime.now());
area.setUpdateTime(LocalDateTime.now());
area.setInputStatus(1);
info.add(area);
}
}
}
}
}
if (CollUtil.isNotEmpty(info)) {
log.info(Thread.currentThread().getName() + "4.数据添加 info" + info + "结束----");
LambdaQueryWrapper<PowerDistributionarea> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(PowerDistributionarea::getInputStatus, 1);
this.remove(lambdaQueryWrapper);
this.insertBatchBySlice(info, 1000);
}
if (CollUtil.isNotEmpty(orgID)) {
log.info(Thread.currentThread().getName() + "5.数据添加 orgID" + orgID + "结束----");
return message + "数据存在未知部门:" + String.join(",", orgID);
}
} catch (Exception e) {
log.error(Thread.currentThread().getName() + "链接" + e + "失败");
return e.toString();
}
if(CollUtil.isNotEmpty(info)){
LambdaQueryWrapper<PowerDistributionarea> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(PowerDistributionarea::getInputStatus,1);
this.remove(lambdaQueryWrapper);
this.insertBatchBySlice(info,1000);
}
return "数据导入成功";
return message;
}
public static <T> List<T> staticMethod(Integer a,Class<T> t){
List<T> aas=new ArrayList<>();
String s=null;
switch (a){
public static <T> List<T> staticMethod(Integer a, Class<T> t) {
List<T> aas = new ArrayList<>();
String s = null;
switch (a) {
case 1:
s="[{\n" +
s = "[{\n" +
" \"RUN_DATE\":\"2014-10-19 00:00:00\",\n" +
" \"ACCOUNT_ID\":\"c06e78c12c8afa98904fb5b289014fc06e636c1f90\",\n" +
" \"BELONG_TYPE\":\"1\",\n" +
@@ -393,7 +424,7 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
aas = JSONArray.parseArray(s, t);
break;
case 2:
s="[\n" +
s = "[\n" +
" {\n" +
" \"DISPATCH_DEPART\": null,\n" +
" \"RUN_DATE\": \"2017-07-18 00:00:00\",\n" +
@@ -476,7 +507,7 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
aas = JSONArray.parseArray(s, t);
break;
case 3:
s="[\n" +
s = "[\n" +
" {\n" +
" \"RUN_DATE\": \"2004-11-30 00:00:00\",\n" +
" \"BELONG_TYPE\": \"1\",\n" +
@@ -552,9 +583,10 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
}
return aas;
}
public <T> List<T> resourceMethod(Integer a,String token,Integer num,String ids,Class<T> t){
List<T> aas=new ArrayList<>();
switch (a){
public <T> List<T> resourceMethod(Integer a, String token, Integer num, String ids, Class<T> t) {
List<T> aas = new ArrayList<>();
switch (a) {
case 1:
//查询户外变
Map transformerData = getResourceData(token, "PWOPTransformerPSR", num, "ACCOUNT_ID", ids);
@@ -573,16 +605,18 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
}
return aas;
}
public String getAlgoDescribe(String name,List<DictData> voltageLevel){
Map<Integer, String> voltageMap = voltageLevel.stream().filter(x -> x.getAlgoDescribe() != null).collect(Collectors.toMap(DictData::getAlgoDescribe, DictData::getId,(key1, key2) -> key1));
if(voltageMap.containsKey(Integer.valueOf(name))){
public String getAlgoDescribe(String name, List<DictData> voltageLevel) {
Map<Integer, String> voltageMap = voltageLevel.stream().filter(x -> x.getAlgoDescribe() != null).collect(Collectors.toMap(DictData::getAlgoDescribe, DictData::getId, (key1, key2) -> key1));
if (voltageMap.containsKey(Integer.valueOf(name))) {
return voltageMap.get(Integer.valueOf(name));
}
return "";
}
public String getDeptName(String name,List<Dept> depts){
public String getDeptName(String name, List<Dept> depts) {
Map<String, String> deptMap = depts.stream().collect(Collectors.toMap(Dept::getCode, Dept::getName, (key1, key2) -> key1));
if(deptMap.containsKey(name)){
if (deptMap.containsKey(name)) {
return deptMap.get(name);
}
return "";