Browse Source

# 设备管理设备保存代码优化

zhongwei
haungxing 2 years ago
parent
commit
3807b9ed7b
  1. 4
      hzims-service/equipment/pom.xml
  2. 15
      hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java
  3. 47
      hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java
  4. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java

4
hzims-service/equipment/pom.xml

@ -94,6 +94,10 @@
<artifactId>hzims-operational-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
</dependencies>

15
hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java

@ -117,21 +117,6 @@ public class EmInfoController extends BladeController {
@ApiOperationSupport(order = 4)
@ApiOperation(value = "新增", notes = "传入em_info")
public R save(@Valid @RequestBody EmInfoAddVo em_info) {
List<EmInfoEntity> name = em_infoService.list(new QueryWrapper<EmInfoEntity>() {{
eq("NAME", em_info.getInfo().getName());
}});
if (CollectionUtil.isNotEmpty(name)) {
return R.fail("设备名称已存在");
}
if(Func.isNotEmpty(em_info.getInfo().getEmIndex())) {
List<EmInfoEntity> exist = em_infoService.list(Wrappers.<EmInfoEntity>lambdaQuery()
.eq(EmInfoEntity::getCreateDept, AuthUtil.getDeptId())
.eq(EmInfoEntity::getEmIndex, em_info.getInfo().getEmIndex())
);
Assert.isTrue(CollectionUtil.isEmpty(exist),() -> {
throw new ServiceException("该设备序号已存在,设备新增失败");
});
}
return em_infoService.saveInfo(em_info);
}

47
hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java

@ -23,6 +23,7 @@ import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient;
import org.apache.commons.collections4.MapUtils;
import org.springblade.core.log.exception.ServiceException;
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.utils.*;
import org.springblade.system.vo.CreateTableVO;
@ -103,17 +104,11 @@ public class EmInfoServiceImpl extends BaseServiceImpl<EmInfoMapper, EmInfoEntit
@Override
@Transactional
public R saveInfo(@Valid EmInfoAddVo em_info) {
// 查询设备编码设备实例是否已存在
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());
if (ObjectUtil.isNotEmpty(emInfoEntity)) {
return R.fail("设备编号已存在");
}
if (this.save(em_info.getInfo())) {
// 验证设备信息
this.validEmInfo(em_info);
EmInfoEntity infoEntity = em_info.getInfo();
//infoEntity.setNumber(Func.);
if (this.save(infoEntity)) {
this.getStationCodeStoreRedis();
Long infoId = em_info.getInfo().getId();
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())));
}
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("设备编号已存在");
});
}
}

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java

@ -641,7 +641,7 @@ public class StationServiceImpl extends BaseServiceImpl<StationMapper, StationEn
if(CollectionUtil.isNotEmpty(list) && list.size() > 1) {
throw new ServiceException("获取站点数量超过一条");
}
return Optional.ofNullable(list).map(l -> l.get(0)).orElse(null);
return list.size() > 0 ? list.get(0) : null;
}
/**

Loading…
Cancel
Save