1.mysql台账同步oracle

This commit is contained in:
wr
2024-10-16 17:09:07 +08:00
parent bd153dc7b9
commit 59522c66d9
5 changed files with 114 additions and 70 deletions

View File

@@ -11,7 +11,6 @@ import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -55,10 +54,8 @@ import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.Area;
import com.njcn.system.pojo.po.DictData;
import com.njcn.web.utils.HttpServletUtil;
import com.njcn.web.utils.RequestUtil;
import com.njcn.web.utils.RestTemplateUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@@ -118,6 +115,9 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
@Value("${oracle.syncLedgerUpdateLine}")
private String updateUrl;
@Value("${oracle.syncLedgerDeleteLine}")
private String urlDelete;
/**
* 终端新增操作
*
@@ -503,8 +503,8 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateTerminal(UpdateTerminalParam updateTerminalParam) {
String oldSubName="";
String gbName="";
String oldSubName = "";
String gbName = "";
LambdaQueryWrapper<Line> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//项目
if (Objects.nonNull(updateTerminalParam.getProjectUpdateParam())) {
@@ -535,7 +535,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
//供电公司
if (Objects.nonNull(updateTerminalParam.getGdInformationUpdateParam())) {
Line gdRes = this.getById(updateTerminalParam.getGdInformationUpdateParam().getGdIndex());
gbName=gdRes.getName();
gbName = gdRes.getName();
if (Objects.isNull(gdRes)) {
throw new BusinessException(DeviceResponseEnum.GD_NO);
}
@@ -553,7 +553,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
if (Objects.isNull(subStationRes)) {
throw new BusinessException(DeviceResponseEnum.SUB_NO);
}
oldSubName=subStationRes.getName();
oldSubName = subStationRes.getName();
Line subStation = new Line();
subStation.setId(updateTerminalParam.getSubStationUpdateParam().getSubIndex());
subStation.setName(updateTerminalParam.getSubStationUpdateParam().getName());
@@ -798,8 +798,8 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
/***
* oracle http远程调用接口
*/
SyncLedgerUpdate syncLedger = oracleSyncLedgerUpdate(updateTerminalParam,oldSubName,gbName);
ResponseEntity<Map> userEntity = RestTemplateUtil.post(updateUrl, syncLedger, Map.class);
SyncLedgerUpdate syncLedger = oracleSyncLedgerUpdate(updateTerminalParam, oldSubName, gbName);
ResponseEntity<String> userEntity = RestTemplateUtil.post(updateUrl, syncLedger, String.class);
}
return true;
}
@@ -1360,6 +1360,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
List<Line> deviceList = this.list(lambdaQueryWrapper);
if (CollectionUtil.isNotEmpty(deviceList)) {
List<String> devIndexList = deviceList.stream().map(Line::getId).collect(Collectors.toList());
this.removeByIds(devIndexList);
deviceMapper.deleteBatchIds(devIndexList);
devFuctionMapper.deleteBatchIds(devIndexList);
@@ -1455,6 +1456,10 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
} else {
throw new BusinessException(CommonResponseEnum.FAIL);
}
if (isSync) {
SyncLedgerDelete delete = oracleSyncLedgerDelete(obj);
ResponseEntity<String> userEntity = RestTemplateUtil.post(urlDelete, delete, String.class);
}
return true;
}
@@ -1843,6 +1848,21 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
@Override
@Transactional(rollbackFor = Exception.class)
public String terminalSync(SyncTerminalParam syncTerminalParam) {
if (isSync) {
/***
* oracle http远程调用接口
*/
SyncLedger syncLedger = oracleSyncLedger(syncTerminalParam);
ResponseEntity<Map> userEntity = RestTemplateUtil.post(url, syncLedger, Map.class);
if (HttpURLConnection.HTTP_OK == userEntity.getStatusCodeValue()) {
//获取返回体
Map body = userEntity.getBody();
Integer oracleLineId = Integer.valueOf(body.get("oracleLineId").toString());
Integer oracleDevId = Integer.valueOf(body.get("oracleDevId").toString());
syncTerminalParam.setOracleLineId(oracleLineId);
syncTerminalParam.setOracleDevId(oracleDevId);
}
}
String projectIndex = null;
String provinceIndex = null;
String gdIndex = null;
@@ -2024,21 +2044,6 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
deptLine.setId(syncTerminalParam.getDeptId());
deptLine.setLineId(line.getId());
deptLineMapper.insert(deptLine);
if (isSync) {
/***
* oracle http远程调用接口
*/
SyncLedger syncLedger = oracleSyncLedger(syncTerminalParam);
ResponseEntity<Map> userEntity = RestTemplateUtil.post(url, syncLedger, Map.class);
if (HttpURLConnection.HTTP_OK == userEntity.getStatusCodeValue()) {
//获取返回体
Map body = userEntity.getBody();
Integer oracleLineId = Integer.valueOf(body.get("oracleLineId").toString());
Integer oracleDevId = Integer.valueOf(body.get("oracleDevId").toString());
syncTerminalParam.setOracleLineId(oracleLineId);
syncTerminalParam.setOracleDevId(oracleDevId);
}
}
return subIndex;
}
@@ -3085,41 +3090,85 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
terminalVO.setSubStationVO(subStationVO);
}
private SyncLedgerUpdate oracleSyncLedgerUpdate(UpdateTerminalParam param,String oldSubName,String gdName) {
SyncLedgerUpdate update=new SyncLedgerUpdate();
private SyncLedgerDelete oracleSyncLedgerDelete(Line obj) {
SyncLedgerDelete delete = new SyncLedgerDelete();
delete.setLevel(obj.getLevel());
/**
* 3-变电站4-终端5-母线6-监测点
*/
switch (obj.getLevel()) {
case 3:
Line byId = this.getById(obj.getPid());
if (Objects.isNull(byId)) {
throw new BusinessException(CommonResponseEnum.NO_DATA);
}
delete.setSuperName(byId.getName());
delete.setName(obj.getName());
break;
case 4:
DeviceBak deviceBak = deviceBakService.getById(obj.getId());
delete.setId(deviceBak.getDevId());
delete.setName(obj.getName());
break;
case 5:
DeviceBak bak = deviceBakService.getById(obj.getPid());
delete.setName(obj.getName());
delete.setSuperId(bak.getDevId());
break;
case 6:
LineBak lineBak = lineBakService.getById(obj.getId());
delete.setId(lineBak.getLineId());
delete.setName(obj.getName());
break;
}
return delete;
}
private SyncLedgerUpdate oracleSyncLedgerUpdate(UpdateTerminalParam param, String oldSubName, String gdName) {
SyncLedgerUpdate update = new SyncLedgerUpdate();
/**
* 先更新变电站信息,然后根据变电站信息查询终端信息
*/
//变电站信息
SubStationParam.SubStationUpdateParam sub = param.getSubStationUpdateParam();
List<DeviceParam> deviceUpdateParamList = param.getDeviceUpdateParamList();
PqSubstation substation=new PqSubstation();
PqSubstation substation = new PqSubstation();
if (ObjectUtil.isNull(sub)) {
//因为查出来的数据电压等级是转换过的所有不需要替换
Line byId = this.getById(deviceUpdateParamList.get(0).getDevIndex());
PollutionSubstationDTO substationInfo = lineMapper.getSubstationInfo(byId.getPid());
sub=new SubStationParam.SubStationUpdateParam();
sub = new SubStationParam.SubStationUpdateParam();
sub.setName(substationInfo.getName());
oldSubName=substationInfo.getName();
oldSubName = substationInfo.getName();
sub.setLng(substationInfo.getLng());
sub.setLat(substationInfo.getLat());
substation.setScale(sub.getScale());
}else{
sub.setSubIndex(substationInfo.getId());
substation.setScale(substationInfo.getVoltageLevel());
} else {
substation.setScale(dictName(sub.getScale()));
}
substation.setName(sub.getName());
substation.setOldName(oldSubName);
substation.setGdName(gdName);
if (StrUtil.isNotBlank(gdName)) {
substation.setGdName(gdName);
} else {
Line byId = this.getById(sub.getSubIndex());
Line byId1 = this.getById(byId.getPid());
if(ObjectUtil.isNull(byId1)){
throw new BusinessException(PvDeviceResponseEnum.GD_OR_NOT);
}
substation.setGdName(byId1.getName());
}
update.setPqSubstation(substation);
PqsMap pqsMap=new PqsMap();
PqsMap pqsMap = new PqsMap();
pqsMap.setLongitude(sub.getLng().doubleValue());
pqsMap.setLatitude(sub.getLat().doubleValue());
update.setPqsMap(pqsMap);
//修改终端信息
List<PqDevice> deviceList=new ArrayList<>();
List<PqDevicedetail> deviceDetailList=new ArrayList<>();
List<PqLinedetail> lineDeatailList=new ArrayList<>();
List<PqDevice> deviceList = new ArrayList<>();
List<PqDevicedetail> deviceDetailList = new ArrayList<>();
List<PqLinedetail> lineDeatailList = new ArrayList<>();
List<String> devMysqlIds = deviceUpdateParamList.stream().map(DeviceParam::getDevIndex).collect(Collectors.toList());
List<DeviceBak> deviceBaks = deviceBakService.listByIds(devMysqlIds);
@@ -3128,10 +3177,10 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
for (DeviceParam device : deviceUpdateParamList) {
String devIndex = device.getDevIndex();
if(deviceBakMap.containsKey(devIndex)){
if (deviceBakMap.containsKey(devIndex)) {
Integer devOracleId = deviceBakMap.get(devIndex);
//终端
PqDevice pqDevice=new PqDevice();
PqDevice pqDevice = new PqDevice();
pqDevice.setDevIndex(devOracleId);
pqDevice.setName(device.getName());
pqDevice.setStatus(1);
@@ -3167,8 +3216,8 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
deviceDetailList.add(pqDevicedetail);
//处理母线信息
List<PqSubvoltage> pqSubVoltages=new ArrayList<>();
for (SubVoltageParam subVoltage : device.getSubVoltageParam()) {
List<PqSubvoltage> pqSubVoltages = new ArrayList<>();
for (SubVoltageParam subVoltage : device.getSubVoltageParam()) {
//母线
PqSubvoltage pqSubvoltage = new PqSubvoltage();
pqSubvoltage.setName(subVoltage.getName());
@@ -3178,10 +3227,10 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
pqSubvoltage.setSubvmodel(subVoltage.getModel());
pqSubVoltages.add(pqSubvoltage);
//监测点
List<PqLine> pqLines=new ArrayList<>();
List<PqLine> pqLines = new ArrayList<>();
for (LineParam line : subVoltage.getLineParam()) {
LineBak byId = lineBakService.getById(line.getLineIndex());
if(ObjectUtil.isNotNull(byId)){
if (ObjectUtil.isNotNull(byId)) {
//监测点
PqLine pqLine = new PqLine();
pqLine.setLineIndex(byId.getLineId());
@@ -3195,7 +3244,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
pqLine.setJzcmp(line.getStandardCapacity().doubleValue());
pqLine.setXycmp(line.getDealCapacity().doubleValue());
pqLine.setScale(dictName(subVoltage.getScale()));
pqLine.setStatus(1);
pqLine.setStatus(0);
pqLines.add(pqLine);
PqLinedetail pqLinedetail = new PqLinedetail();
@@ -3235,6 +3284,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
update.setPqLinedetail(lineDeatailList);
return update;
}
/**
* oracle远程台账同步
*
@@ -3365,7 +3415,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
pqLine.setJzcmp(line.getStandardCapacity().doubleValue());
pqLine.setXycmp(line.getDealCapacity().doubleValue());
pqLine.setScale(dictName(subVoltage.getScale()));
pqLine.setStatus(1);
pqLine.setStatus(0);
ledger.setPqLine(pqLine);
PqLinedetail pqLinedetail = new PqLinedetail();
pqLinedetail.setLineName(line.getName());