diff --git a/src/main/java/com/spring/modules/cdc/utils/CollectUtils.java b/src/main/java/com/spring/modules/cdc/utils/CollectUtils.java index ac1dd933..3883f4c1 100644 --- a/src/main/java/com/spring/modules/cdc/utils/CollectUtils.java +++ b/src/main/java/com/spring/modules/cdc/utils/CollectUtils.java @@ -99,15 +99,15 @@ public class CollectUtils { } public static List getReadS7XMZValueList(List deviceList,String IP,BigDecimal defaultValue){ - S7Connector s7Connector = S7ConnectorFactory - .buildTCPConnector() - .withHost(IP) - .withPort(102) - .withRack(0) - .withSlot(1) - .build(); List deviceVoList = new ArrayList<>(); try { + S7Connector s7Connector = S7ConnectorFactory + .buildTCPConnector() + .withHost(IP) + .withPort(102) + .withRack(0) + .withSlot(1) + .build(); log.info("IP:{} 连接成功!!!", IP); for (DeviceVo device : deviceList) { int i = readS7XMZValue(s7Connector, device.getDeviceIp()); diff --git a/src/main/java/com/spring/modules/sys/service/impl/DictDataServiceImpl.java b/src/main/java/com/spring/modules/sys/service/impl/DictDataServiceImpl.java index f527eab9..a6362eaa 100644 --- a/src/main/java/com/spring/modules/sys/service/impl/DictDataServiceImpl.java +++ b/src/main/java/com/spring/modules/sys/service/impl/DictDataServiceImpl.java @@ -25,23 +25,7 @@ public class DictDataServiceImpl extends ServiceImpl impl throw new RuntimeException("字典数据为空"); } // 设置为默认值 - if (StringUtils.hasText(dictData.getIsDefault()) && dictData.getIsDefault().equals("Y")){ -// List list = list(new LambdaQueryWrapper().eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite()).eq(DictData::getIsDefault,"Y")); -// if (null != list && !list.isEmpty()){ -// throw new RuntimeException("当前字典已存在默认值"); -// } - lambdaUpdate().set(DictData::getIsDefault,Constant.SYSTEM_ACTIVE_YES).eq(DictData::getDictType,dictData.getDictType()).eq(DictData::getSite,dictData.getSite()).update(); - } - if (!StringUtils.hasText(dictData.getDictType())){ - throw new RuntimeException("字典类型为空"); - } - if (!StringUtils.hasText(dictData.getDictValue())){ - throw new RuntimeException("字典键值为空"); - } - if (!StringUtils.hasText(dictData.getSite())){ - throw new RuntimeException("工厂编码为空"); - } - List list = list(new LambdaQueryWrapper().eq(DictData::getDictValue, dictData.getDictValue()).eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite())); + List list =isDefault(dictData); if (null != list && !list.isEmpty()){ throw new RuntimeException("字典键值重复"); } @@ -53,7 +37,20 @@ public class DictDataServiceImpl extends ServiceImpl impl if (Objects.isNull(dictData)||Objects.isNull(dictData.getDictCode())){ throw new RuntimeException("字典数据为空"); } - if (StringUtils.hasText(dictData.getIsDefault()) && dictData.getIsDefault().equals("Y")){ + List list = isDefault(dictData);; + if (null != list && !list.isEmpty()){ + if (list.size() > 1){ + throw new RuntimeException("字典键值重复"); + } + if (!list.get(0).getDictCode().equals(dictData.getDictCode())){ + throw new RuntimeException("字典键值重复"); + } + } + return updateById(dictData); + } + + private List isDefault(DictData dictData) { + if (StringUtils.hasText(dictData.getIsDefault()) && dictData.getIsDefault().equals(Constant.SYSTEM_ACTIVE_YES)){ // List list = list(new LambdaQueryWrapper().eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite()).eq(DictData::getIsDefault,"Y")); // if (null != list && !list.isEmpty()){ // if (list.size() > 1){ @@ -74,15 +71,6 @@ public class DictDataServiceImpl extends ServiceImpl impl if (!StringUtils.hasText(dictData.getSite())){ throw new RuntimeException("工厂编码为空"); } - List list = list(new LambdaQueryWrapper().eq(DictData::getDictValue, dictData.getDictValue()).eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite())); - if (null != list && !list.isEmpty()){ - if (list.size() > 1){ - throw new RuntimeException("字典键值重复"); - } - if (!list.get(0).getDictCode().equals(dictData.getDictCode())){ - throw new RuntimeException("字典键值重复"); - } - } - return updateById(dictData); + return list(new LambdaQueryWrapper().eq(DictData::getDictValue, dictData.getDictValue()).eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite())); } }