|
@@ -23,6 +23,7 @@ import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.iot.domain.*;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.iot.mapper.DmpDeviceInfoMapper;
|
|
|
+import com.usky.iot.service.BaseFacilityDeviceService;
|
|
|
import com.usky.iot.service.DmpDeviceInfoService;
|
|
|
import com.usky.iot.service.DmpDeviceStatusService;
|
|
|
import com.usky.iot.service.vo.BaseFacilityDeviceVO;
|
|
@@ -54,6 +55,9 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
@Autowired
|
|
|
private DmpDeviceStatusService dmpDeviceStatusService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BaseFacilityDeviceService baseFacilityDeviceService;
|
|
|
+
|
|
|
@Override
|
|
|
public void add(DmpDeviceInfo dmpDeviceInfo) {
|
|
|
if (checkNameUnique(dmpDeviceInfo)){
|
|
@@ -104,6 +108,19 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
return null != one && !Objects.equals(one.getId(), id);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean checkNameUnique1(DmpDeviceInfo dmpDeviceInfo,Integer tenantId) {
|
|
|
+ Integer id = null == dmpDeviceInfo.getId() ? -1 : dmpDeviceInfo.getId();
|
|
|
+ LambdaQueryWrapper<DmpDeviceInfo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper
|
|
|
+ .eq(DmpDeviceInfo::getDeviceId,dmpDeviceInfo.getDeviceId())
|
|
|
+ .eq(DmpDeviceInfo::getProductCode,dmpDeviceInfo.getProductCode())
|
|
|
+ .eq(DmpDeviceInfo::getDeleteFlag,0)
|
|
|
+ .eq(DmpDeviceInfo::getTenantId,tenantId);
|
|
|
+ DmpDeviceInfo one = this.getOne(queryWrapper);
|
|
|
+ return null != one && !Objects.equals(one.getId(), id);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public CommonPage<DmpDeviceInfo> page(DmpDeviceInfoRequest diRequest) {
|
|
|
IPage<DmpDeviceInfo> page = new Page<>(diRequest.getCurrent(), diRequest.getSize());
|
|
@@ -115,6 +132,15 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
public boolean remove(Integer id) {
|
|
|
DmpDeviceInfo dmpDeviceInfo = this.getById(id);
|
|
|
Optional.ofNullable(dmpDeviceInfo).orElseThrow(() -> new BusinessException("设备不存在"));
|
|
|
+
|
|
|
+ //已关联设施的不能删除
|
|
|
+ LambdaQueryWrapper<BaseFacilityDevice> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(BaseFacilityDevice::getDeviceId,dmpDeviceInfo.getDeviceId());
|
|
|
+ int count = baseFacilityDeviceService.count(queryWrapper);
|
|
|
+ if(count > 0){
|
|
|
+ throw new BusinessException("已关联设施的不能删除");
|
|
|
+ }
|
|
|
+
|
|
|
dmpDeviceInfo.setDeleteFlag(1);
|
|
|
return this.updateById(dmpDeviceInfo);
|
|
|
}
|
|
@@ -151,16 +177,18 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
throw new BusinessException("数据不能为空");
|
|
|
}
|
|
|
for(int i=0;i<devList.size();i++){
|
|
|
- if (checkNameUnique(devList.get(i))){
|
|
|
- throw new BusinessException("新增设备信息'" + devList.get(i).getDeviceId() + "'失败,设备信息已存在");
|
|
|
- }
|
|
|
List<DmpProductInfo> list = baseMapper.getProductInfo(devList.get(i).getProductCode());
|
|
|
if(CollectionUtils.isNotEmpty(list)){
|
|
|
+
|
|
|
+ if (checkNameUnique1(devList.get(i),list.get(0).getTenantId())){
|
|
|
+ throw new BusinessException("新增设备信息'" + devList.get(i).getDeviceId() + "'失败,设备信息已存在");
|
|
|
+ }
|
|
|
+
|
|
|
devList.get(i).setDeviceType(list.get(0).getDeviceType());
|
|
|
devList.get(i).setProductId(list.get(0).getId());
|
|
|
devList.get(i).setCreatedBy(SecurityUtils.getUsername());
|
|
|
devList.get(i).setCreatedTime(LocalDateTime.now());
|
|
|
- devList.get(i).setTenantId(SecurityUtils.getTenantId());
|
|
|
+ devList.get(i).setTenantId(list.get(0).getTenantId());
|
|
|
devList.get(i).setServiceStatus(1);
|
|
|
|
|
|
DmpDeviceStatus dmpDeviceStatus = new DmpDeviceStatus();
|