Browse Source

2024-06-21

master
qiezi 2 years ago
parent
commit
274b5ecd3f
  1. 4
      src/main/java/com/spring/modules/cdc/utils/CollectUtils.java
  2. 44
      src/main/java/com/spring/modules/sys/service/impl/DictDataServiceImpl.java

4
src/main/java/com/spring/modules/cdc/utils/CollectUtils.java

@ -99,6 +99,8 @@ public class CollectUtils {
} }
public static List<DeviceVo> getReadS7XMZValueList(List<DeviceVo> deviceList,String IP,BigDecimal defaultValue){ public static List<DeviceVo> getReadS7XMZValueList(List<DeviceVo> deviceList,String IP,BigDecimal defaultValue){
List<DeviceVo> deviceVoList = new ArrayList<>();
try {
S7Connector s7Connector = S7ConnectorFactory S7Connector s7Connector = S7ConnectorFactory
.buildTCPConnector() .buildTCPConnector()
.withHost(IP) .withHost(IP)
@ -106,8 +108,6 @@ public class CollectUtils {
.withRack(0) .withRack(0)
.withSlot(1) .withSlot(1)
.build(); .build();
List<DeviceVo> deviceVoList = new ArrayList<>();
try {
log.info("IP:{} 连接成功!!!", IP); log.info("IP:{} 连接成功!!!", IP);
for (DeviceVo device : deviceList) { for (DeviceVo device : deviceList) {
int i = readS7XMZValue(s7Connector, device.getDeviceIp()); int i = readS7XMZValue(s7Connector, device.getDeviceIp());

44
src/main/java/com/spring/modules/sys/service/impl/DictDataServiceImpl.java

@ -25,23 +25,7 @@ public class DictDataServiceImpl extends ServiceImpl<DictDataDao, DictData> impl
throw new RuntimeException("字典数据为空"); throw new RuntimeException("字典数据为空");
} }
// 设置为默认值 // 设置为默认值
if (StringUtils.hasText(dictData.getIsDefault()) && dictData.getIsDefault().equals("Y")){
// List<DictData> list = list(new LambdaQueryWrapper<DictData>().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<DictData> list = list(new LambdaQueryWrapper<DictData>().eq(DictData::getDictValue, dictData.getDictValue()).eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite()));
List<DictData> list =isDefault(dictData);
if (null != list && !list.isEmpty()){ if (null != list && !list.isEmpty()){
throw new RuntimeException("字典键值重复"); throw new RuntimeException("字典键值重复");
} }
@ -53,7 +37,20 @@ public class DictDataServiceImpl extends ServiceImpl<DictDataDao, DictData> impl
if (Objects.isNull(dictData)||Objects.isNull(dictData.getDictCode())){ if (Objects.isNull(dictData)||Objects.isNull(dictData.getDictCode())){
throw new RuntimeException("字典数据为空"); throw new RuntimeException("字典数据为空");
} }
if (StringUtils.hasText(dictData.getIsDefault()) && dictData.getIsDefault().equals("Y")){
List<DictData> 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<DictData> isDefault(DictData dictData) {
if (StringUtils.hasText(dictData.getIsDefault()) && dictData.getIsDefault().equals(Constant.SYSTEM_ACTIVE_YES)){
// List<DictData> list = list(new LambdaQueryWrapper<DictData>().eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite()).eq(DictData::getIsDefault,"Y")); // List<DictData> list = list(new LambdaQueryWrapper<DictData>().eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite()).eq(DictData::getIsDefault,"Y"));
// if (null != list && !list.isEmpty()){ // if (null != list && !list.isEmpty()){
// if (list.size() > 1){ // if (list.size() > 1){
@ -74,15 +71,6 @@ public class DictDataServiceImpl extends ServiceImpl<DictDataDao, DictData> impl
if (!StringUtils.hasText(dictData.getSite())){ if (!StringUtils.hasText(dictData.getSite())){
throw new RuntimeException("工厂编码为空"); throw new RuntimeException("工厂编码为空");
} }
List<DictData> list = list(new LambdaQueryWrapper<DictData>().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<DictData>().eq(DictData::getDictValue, dictData.getDictValue()).eq(DictData::getDictType, dictData.getDictType()).eq(DictData::getSite, dictData.getSite()));
} }
} }
Loading…
Cancel
Save