|
|
|
@ -8,7 +8,6 @@ import com.xydl.cac.model.ColumnModel;
|
|
|
|
|
import com.xydl.cac.model.Response;
|
|
|
|
|
import com.xydl.cac.repository.*;
|
|
|
|
|
import com.xydl.cac.service.DataService;
|
|
|
|
|
import com.xydl.cac.service.NSensorService;
|
|
|
|
|
import com.xydl.cac.service.ParamBindService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
@ -36,10 +35,6 @@ public class ParamBindServiceImpl implements ParamBindService {
|
|
|
|
|
@Resource
|
|
|
|
|
NSensorRepository sensorRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
ModevRepository modevRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
ModevTypeRepository modevTypeRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
IcdConfigTypeRepository typeRepository;
|
|
|
|
|
@Resource
|
|
|
|
|
IcdConfigTypeInstRepository instRepository;
|
|
|
|
@ -89,16 +84,11 @@ public class ParamBindServiceImpl implements ParamBindService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Response preview(BindingModel item) throws Exception {
|
|
|
|
|
Optional<Modev> optionalModev = modevRepository.findById(item.getEqmid());
|
|
|
|
|
if (!optionalModev.isPresent()) {
|
|
|
|
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(item.getEqmid());
|
|
|
|
|
if (!optionalNSensor.isPresent()) {
|
|
|
|
|
throw new BusinessException("未找到该监测装置, eqmid=" + item.getEqmid());
|
|
|
|
|
}
|
|
|
|
|
Modev modev = optionalModev.get();
|
|
|
|
|
Optional<ModevType> optionalModevType = modevTypeRepository.findById(modev.getModevtid());
|
|
|
|
|
if (!optionalModevType.isPresent()) {
|
|
|
|
|
throw new BusinessException("该监测装置类型不正确, 请先修正");
|
|
|
|
|
}
|
|
|
|
|
ModevType modevType = optionalModevType.get();
|
|
|
|
|
NSensor sensor = optionalNSensor.get();
|
|
|
|
|
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(item.getIcdid());
|
|
|
|
|
if (!optionalInst.isPresent()) {
|
|
|
|
|
throw new BusinessException("未找到该ICD逻辑设备实例, icdid=" + item.getIcdid());
|
|
|
|
@ -129,8 +119,8 @@ public class ParamBindServiceImpl implements ParamBindService {
|
|
|
|
|
Response resp = Response.success(attList);
|
|
|
|
|
if (StringUtils.isBlank(type.getTableName())) {
|
|
|
|
|
msgList.add("该ICD配置类型还未设置对应的tableName");
|
|
|
|
|
} else if (!type.getTableName().equals(modevType.getTablename())) {
|
|
|
|
|
msgList.add("该ICD配置类型的tableName(" + type.getTableName() + ")和该监测装置类型的tableName(" + modevType.getTablename() + ")不一致");
|
|
|
|
|
} else if (!type.getTableName().equals(sensor.getTableName())) {
|
|
|
|
|
msgList.add("该ICD配置类型的tableName(" + type.getTableName() + ")和该监测装置类型的tableName(" + sensor.getTableName() + ")不一致");
|
|
|
|
|
}
|
|
|
|
|
if (msgList.size() > 0) {
|
|
|
|
|
String message = msgList.stream().collect(Collectors.joining("\n\r"));
|
|
|
|
@ -141,11 +131,11 @@ public class ParamBindServiceImpl implements ParamBindService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void bind(BindingModel item) throws Exception {
|
|
|
|
|
Optional<Modev> optionalModev = modevRepository.findById(item.getEqmid());
|
|
|
|
|
if (!optionalModev.isPresent()) {
|
|
|
|
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(item.getEqmid());
|
|
|
|
|
if (!optionalNSensor.isPresent()) {
|
|
|
|
|
throw new BusinessException("未找到该监测装置, eqmid=" + item.getEqmid());
|
|
|
|
|
}
|
|
|
|
|
Modev modev = optionalModev.get();
|
|
|
|
|
NSensor sensor = optionalNSensor.get();
|
|
|
|
|
|
|
|
|
|
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(item.getIcdid());
|
|
|
|
|
if (!optionalInst.isPresent()) {
|
|
|
|
@ -158,17 +148,15 @@ public class ParamBindServiceImpl implements ParamBindService {
|
|
|
|
|
}
|
|
|
|
|
IcdConfigType type = optionalType.get();
|
|
|
|
|
|
|
|
|
|
List<Modev> list = modevRepository.findByIcdidAndIdIsNot(item.getIcdid(), item.getEqmid());
|
|
|
|
|
List<NSensor> list = sensorRepository.findByIcdIdAndIdIsNot(item.getIcdid(), item.getEqmid());
|
|
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
|
throw new BusinessException("该逻辑设备实例已被" + list.get(0).getName() + "绑定");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<IcdConfigTypeAtt> attList = attRepository.findByIcdConfigTypeId(type.getId());
|
|
|
|
|
Optional<ModevType> optionalModevType = modevTypeRepository.findById(modev.getModevtid());
|
|
|
|
|
if (optionalModevType.isPresent()) {
|
|
|
|
|
ModevType modevType = optionalModevType.get();
|
|
|
|
|
if (StringUtils.isNotBlank(modevType.getTablename())) {
|
|
|
|
|
List<ColumnModel> columnList = dataService.getDataTableColumns(modevType.getTablename());
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(sensor.getTableName())) {
|
|
|
|
|
List<ColumnModel> columnList = dataService.getDataTableColumns(sensor.getTableName());
|
|
|
|
|
for (IcdConfigTypeAtt att : attList) {
|
|
|
|
|
if (StringUtils.isNotBlank(att.getColName())) {
|
|
|
|
|
boolean found = false;
|
|
|
|
@ -179,50 +167,46 @@ public class ParamBindServiceImpl implements ParamBindService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
throw new BusinessException("当前监控设备对应的表" + modevType.getTablename() + "里不存在配置属性"
|
|
|
|
|
throw new BusinessException("当前监控设备对应的表" + sensor.getTableName() + "里不存在配置属性"
|
|
|
|
|
+ att.getDoName() + "绑定的字段" + att.getColName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modev.setIcdid(item.getIcdid());
|
|
|
|
|
modevRepository.save(modev);
|
|
|
|
|
sensor.setIcdId(item.getIcdid());
|
|
|
|
|
sensorRepository.save(sensor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void unbind(Integer eqmid) throws Exception {
|
|
|
|
|
Optional<Modev> optionalModev = modevRepository.findById(eqmid);
|
|
|
|
|
if (!optionalModev.isPresent()) {
|
|
|
|
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(eqmid);
|
|
|
|
|
if (!optionalNSensor.isPresent()) {
|
|
|
|
|
throw new BusinessException("未找到该监测装置, eqmid=" + eqmid);
|
|
|
|
|
}
|
|
|
|
|
Modev modev = optionalModev.get();
|
|
|
|
|
modev.setIcdid(null);
|
|
|
|
|
modevRepository.save(modev);
|
|
|
|
|
NSensor sensor = optionalNSensor.get();
|
|
|
|
|
sensor.setIcdId(null);
|
|
|
|
|
sensorRepository.save(sensor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BindDetail getBind(Integer eqmid) throws Exception {
|
|
|
|
|
Optional<Modev> optionalModev = modevRepository.findById(eqmid);
|
|
|
|
|
if (!optionalModev.isPresent()) {
|
|
|
|
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(eqmid);
|
|
|
|
|
if (!optionalNSensor.isPresent()) {
|
|
|
|
|
throw new BusinessException("未找到该监测装置");
|
|
|
|
|
}
|
|
|
|
|
Modev modev = optionalModev.get();
|
|
|
|
|
NSensor sensor = optionalNSensor.get();
|
|
|
|
|
|
|
|
|
|
BindDetail result = new BindDetail();
|
|
|
|
|
result.setEqmid(eqmid);
|
|
|
|
|
Optional<ModevType> optionalModevType = modevTypeRepository.findById(modev.getModevtid());
|
|
|
|
|
if (optionalModevType.isPresent()) {
|
|
|
|
|
ModevType modevType = optionalModevType.get();
|
|
|
|
|
if (StringUtils.isNotBlank(modevType.getTablename())) {
|
|
|
|
|
List<ColumnModel> columnList = dataService.getDataTableColumns(modevType.getTablename());
|
|
|
|
|
if (StringUtils.isNotBlank(sensor.getTableName())) {
|
|
|
|
|
List<ColumnModel> columnList = dataService.getDataTableColumns(sensor.getTableName());
|
|
|
|
|
result.setColumnList(columnList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (modev.getIcdid() != null) {
|
|
|
|
|
result.setIcdid(modev.getIcdid());
|
|
|
|
|
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(modev.getIcdid());
|
|
|
|
|
|
|
|
|
|
if (sensor.getIcdId() != null) {
|
|
|
|
|
result.setIcdid(sensor.getIcdId());
|
|
|
|
|
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(sensor.getIcdId());
|
|
|
|
|
if (optionalInst.isPresent()) {
|
|
|
|
|
IcdConfigTypeInst inst = optionalInst.get();
|
|
|
|
|
Optional<IcdConfigType> optionalType = typeRepository.findById(inst.getIcdConfigTypeId());
|
|
|
|
@ -241,26 +225,26 @@ public class ParamBindServiceImpl implements ParamBindService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String generateParamindex() throws Exception {
|
|
|
|
|
List<Modev> modevList = modevRepository.findByIcdidIsNotNull();
|
|
|
|
|
if (!CollectionUtils.isEmpty(modevList)) {
|
|
|
|
|
for (Modev item : modevList) {
|
|
|
|
|
List<NSensor> sensorList = sensorRepository.findByIcdIdIsNotNull();
|
|
|
|
|
if (!CollectionUtils.isEmpty(sensorList)) {
|
|
|
|
|
for (NSensor item : sensorList) {
|
|
|
|
|
generateOne(item);
|
|
|
|
|
}
|
|
|
|
|
return "已对" + modevList.size() + "条绑定数据生成对应的61850参引数据";
|
|
|
|
|
return "已对" + sensorList.size() + "条绑定数据生成对应的61850参引数据";
|
|
|
|
|
} else {
|
|
|
|
|
throw new BusinessException("无任何绑定数据");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void generateOne(Modev item) throws Exception {
|
|
|
|
|
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(item.getIcdid());
|
|
|
|
|
private void generateOne(NSensor item) throws Exception {
|
|
|
|
|
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(item.getIcdId());
|
|
|
|
|
if (!optionalInst.isPresent()) {
|
|
|
|
|
throw new BusinessException("未找到该ICD逻辑设备实例, eqmid=" + item.getId() + ", icdid=" + item.getIcdid());
|
|
|
|
|
throw new BusinessException("未找到该ICD逻辑设备实例, eqmid=" + item.getId() + ", icdid=" + item.getIcdId());
|
|
|
|
|
}
|
|
|
|
|
IcdConfigTypeInst inst = optionalInst.get();
|
|
|
|
|
Optional<IcdConfigType> optionalType = typeRepository.findById(inst.getIcdConfigTypeId());
|
|
|
|
|
if (!optionalType.isPresent()) {
|
|
|
|
|
throw new BusinessException("未找到该实例对应的ICD配置类型, icdid=" + item.getIcdid());
|
|
|
|
|
throw new BusinessException("未找到该实例对应的ICD配置类型, icdid=" + item.getIcdId());
|
|
|
|
|
}
|
|
|
|
|
IcdConfigType type = optionalType.get();
|
|
|
|
|
String param = type.getIedName() + type.getLdeviceInst() + "/" + type.getLnClass()
|
|
|
|
|