rev:解决项目启动opc或plc数据源不存在及驱动配置报错

This commit is contained in:
2024-01-05 11:08:46 +08:00
parent ad27f45e62
commit fe6c081c87
2 changed files with 25 additions and 14 deletions

View File

@@ -1414,15 +1414,19 @@ public class DeviceServiceImpl extends CommonServiceImpl<DeviceMapper, Device> i
String opc_id = dto.getOpc_server_id();
if (StrUtil.isNotEmpty(opc_id)) {
OpcDto opcDto = opcService.findById(opc_id);
String opc_code = opcDto.getOpc_code();
json.put("opc_code", opc_code);
if (opcDto != null) {
String opc_code = opcDto.getOpc_code();
json.put("opc_code", opc_code);
}
}
String plc_id = dto.getOpc_plc_id();
if (StrUtil.isNotEmpty(opc_id)) {
OpcPlcDto opcPlcDto = opcPlcService.findById(plc_id);
String plc_code = opcPlcDto.getPlc_code();
json.put("plc_code", plc_code);
if (opcPlcDto != null) {
String plc_code = opcPlcDto.getPlc_code();
json.put("plc_code", plc_code);
}
}
String address = dto.getAddress();

View File

@@ -7,12 +7,14 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.domain.Device;
import org.nl.acs.device.domain.DeviceExtra;
import org.nl.acs.device.service.mapper.DeviceExtraMapper;
import org.nl.acs.device.service.mapper.DeviceMapper;
import org.nl.acs.device.service.mapper.DeviceRunpointMapper;
import org.nl.acs.opc.domain.Opc;
import org.nl.acs.opc.domain.OpcPlc;
import org.nl.acs.opc.service.mapper.OpcMapper;
import org.nl.acs.opc.service.mapper.OpcPlcMapper;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,10 +23,12 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author 20220102CG\noblelift
*/
@Service
@Slf4j
public class DeviceManageServiceImpl implements DeviceManageService {
@Autowired
@@ -65,20 +69,23 @@ public class DeviceManageServiceImpl implements DeviceManageService {
String opc_plc_id = json.getString("opc_plc_id");
if (StrUtil.isNotEmpty(opc_plc_id) && StrUtil.isNotEmpty(opc_server_id)) {
//OPC表【acs_opc】
String opc_code = new LambdaQueryChainWrapper<>(opcMapper).apply("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'")
.one().getOpc_code();
/*Opc opc = opcMapper.selectOne(Wrappers.lambdaQuery(Opc.class).eq(Opc::getIs_delete, "0").eq(Opc::getIs_active, CommonFinalParam.ONE).eq(Opc::getOpc_id, opc_server_id));
String opc_code = "";
if(ObjectUtil.isNotNull(opc)){
opc_code = opc.getOpc_code();
}*/
device.setOpc_server_code(opc_code);
Opc opc = new LambdaQueryChainWrapper<>(opcMapper).apply("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'")
.one();
if (opc == null) {
log.info("设备:{},配置的OPC数据源不存在,opc_id:{}", json.getString("device_code"), opc_server_id);
continue;
}
device.setOpc_server_code(opc.getOpc_code());
if (ObjectUtil.isEmpty(new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one())) {
System.out.println(device.getDevice_code());
continue;
}
String plc_code = new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one().getPlc_code();
device.setOpc_plc_code(plc_code);
OpcPlc opcPlc = new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one();
if (opcPlc == null) {
log.info("设备:{},配置的PLC数据源不存在,plc_id:{}", json.getString("device_code"), opc_plc_id);
continue;
}
device.setOpc_plc_code(opcPlc.getPlc_code());
}
devices.add(device);
}