|
|
@ -23,6 +23,7 @@ import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.utils.*; |
|
|
|
import org.springblade.core.tool.utils.*; |
|
|
|
import org.springblade.system.vo.CreateTableVO; |
|
|
|
import org.springblade.system.vo.CreateTableVO; |
|
|
@ -103,17 +104,11 @@ public class EmInfoServiceImpl extends BaseServiceImpl<EmInfoMapper, EmInfoEntit |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public R saveInfo(@Valid EmInfoAddVo em_info) { |
|
|
|
public R saveInfo(@Valid EmInfoAddVo em_info) { |
|
|
|
// 查询设备编码设备实例是否已存在
|
|
|
|
// 验证设备信息
|
|
|
|
R<Boolean> existResult = deviceClient.isDeviceCodeExist(em_info.getInfo().getNumber()); |
|
|
|
this.validEmInfo(em_info); |
|
|
|
Assert.isTrue(existResult.isSuccess() && !existResult.getData(),() -> { |
|
|
|
EmInfoEntity infoEntity = em_info.getInfo(); |
|
|
|
throw new ServiceException("该设备编码在设备实例中找到对应记录,保存失败!"); |
|
|
|
//infoEntity.setNumber(Func.);
|
|
|
|
}); |
|
|
|
if (this.save(infoEntity)) { |
|
|
|
EmInfoEntity emInfoEntity = this.baseMapper.selectEmInfoByCode(em_info.getInfo().getNumber()); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(emInfoEntity)) { |
|
|
|
|
|
|
|
return R.fail("设备编号已存在"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.save(em_info.getInfo())) { |
|
|
|
|
|
|
|
this.getStationCodeStoreRedis(); |
|
|
|
this.getStationCodeStoreRedis(); |
|
|
|
Long infoId = em_info.getInfo().getId(); |
|
|
|
Long infoId = em_info.getInfo().getId(); |
|
|
|
if (em_info.getAttach() != null) { |
|
|
|
if (em_info.getAttach() != null) { |
|
|
@ -469,4 +464,34 @@ public class EmInfoServiceImpl extends BaseServiceImpl<EmInfoMapper, EmInfoEntit |
|
|
|
// 设置缓存
|
|
|
|
// 设置缓存
|
|
|
|
redisTemplate.opsForValue().set(em_info_list_path, JSONObject.toJSONString(list.stream().filter(o-> Math.abs(o.getInstalledCapacity()) > 0 || MapUtils.isNotEmpty(o.getPoint())).collect(Collectors.toList()))); |
|
|
|
redisTemplate.opsForValue().set(em_info_list_path, JSONObject.toJSONString(list.stream().filter(o-> Math.abs(o.getInstalledCapacity()) > 0 || MapUtils.isNotEmpty(o.getPoint())).collect(Collectors.toList()))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void validEmInfo(EmInfoAddVo em_info) { |
|
|
|
|
|
|
|
// 验证设备名称
|
|
|
|
|
|
|
|
List<EmInfoEntity> existName = this.list( |
|
|
|
|
|
|
|
Wrappers.<EmInfoEntity>lambdaQuery().eq(EmInfoEntity::getName, em_info.getInfo().getName()) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
Assert.isTrue(CollectionUtil.isEmpty(existName),()-> { |
|
|
|
|
|
|
|
throw new ServiceException("设备名称已存在"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
// 验证设备序号
|
|
|
|
|
|
|
|
if(Func.isNotEmpty(em_info.getInfo().getEmIndex())) { |
|
|
|
|
|
|
|
List<EmInfoEntity> exist = super.list(Wrappers.<EmInfoEntity>lambdaQuery() |
|
|
|
|
|
|
|
.eq(EmInfoEntity::getCreateDept, AuthUtil.getDeptId()) |
|
|
|
|
|
|
|
.eq(EmInfoEntity::getEmIndex, em_info.getInfo().getEmIndex()) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
Assert.isTrue(CollectionUtil.isEmpty(exist),() -> { |
|
|
|
|
|
|
|
throw new ServiceException("该设备序号已存在,设备新增失败"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 查询设备编码设备实例是否已存在
|
|
|
|
|
|
|
|
R<Boolean> existResult = deviceClient.isDeviceCodeExist(em_info.getInfo().getNumber()); |
|
|
|
|
|
|
|
Assert.isTrue(existResult.isSuccess() && !existResult.getData(),() -> { |
|
|
|
|
|
|
|
throw new ServiceException("该设备编码在设备实例中找到对应记录,保存失败!"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
// 验证设备编号是否已存在
|
|
|
|
|
|
|
|
EmInfoEntity emInfoEntity = this.baseMapper.selectEmInfoByCode(em_info.getInfo().getNumber()); |
|
|
|
|
|
|
|
Assert.isTrue(ObjectUtil.isEmpty(emInfoEntity),() -> { |
|
|
|
|
|
|
|
throw new ServiceException("设备编号已存在"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|