package com.sandu.ximon.admin.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.sandu.common.execption.BusinessException;
|
import com.sandu.common.service.impl.BaseServiceImpl;
|
import com.sandu.ximon.admin.param.PoleBindingParam;
|
import com.sandu.ximon.dao.domain.PoleBinding;
|
import com.sandu.ximon.dao.mapper.PoleBindingMapper;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
/**
|
* @author chenjiantian
|
* @date 2021/12/14 11:48
|
*/
|
@Service
|
@AllArgsConstructor
|
public class PoleBindingService extends BaseServiceImpl<PoleBindingMapper, PoleBinding> {
|
|
private final LightReportDataService lightReportDataService;
|
|
/**
|
* 灯杆绑定设备
|
*
|
* @param poleId
|
* @param param
|
* @return
|
*/
|
public boolean bindPole(Long poleId, PoleBindingParam param) {
|
Integer deviceType = param.getDeviceType();
|
// if (PoleBindingEnums.LIGHT.getCode().equals(deviceType)) {
|
// }
|
LambdaQueryWrapper<PoleBinding> eq = Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, poleId);
|
List<PoleBinding> list = list(eq);
|
if (list.size() != 0){
|
for (PoleBinding poleBinding : list) {
|
if (poleBinding.getDeviceType().equals(deviceType)) {
|
throw new BusinessException("该灯杆已绑定过相同类型设备");
|
}
|
}
|
}
|
|
PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, param.getDeviceCode()));
|
if (one == null) {
|
PoleBinding poleBinding = new PoleBinding();
|
poleBinding.setPoleId(poleId);
|
poleBinding.setDeviceType(deviceType);
|
poleBinding.setDeviceName(param.getDeviceName());
|
poleBinding.setDeviceCode(param.getDeviceCode());
|
return save(poleBinding);
|
} else {
|
throw new BusinessException("该设备已绑定过");
|
}
|
}
|
|
/**
|
* 灯杆解绑设备,删除设备前需要解绑
|
*
|
* @param deviceCode
|
*/
|
public boolean unBindPole(Long poleId, String deviceCode) {
|
if (deviceCode == null) {
|
throw new BusinessException("设备编号不能为空");
|
}
|
PoleBinding one;
|
//直接删除设备不需要灯杆ID
|
if (poleId == null) {
|
one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
|
} else {
|
one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode).eq(PoleBinding::getPoleId, poleId));
|
}
|
if (one != null) {
|
return removeById(one.getId());
|
} else {
|
throw new BusinessException("设备不存在绑定情况或灯杆ID不正确");
|
}
|
}
|
|
/**
|
* 设备删除,直接解绑设备相关绑定数据
|
*
|
* @param deviceCode
|
*/
|
public boolean unBindPole(String deviceCode) {
|
if (deviceCode == null) {
|
throw new BusinessException("设备编号不能为空");
|
}
|
//直接删除设备不需要灯杆ID
|
PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
|
|
if (one != null) {
|
return removeById(one.getId());
|
} else {
|
return false;
|
}
|
}
|
|
public PoleBinding getPoleIdByMac(String deviceCode) {
|
return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
|
}
|
}
|