2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-13 0d2e4e6b8954d77dd34664f861135ae41f7eb828
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java
@@ -6,13 +6,13 @@
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.param.PoleBindingParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.domain.Pole;
import com.sandu.ximon.dao.domain.PoleBinding;
import com.sandu.ximon.dao.mapper.PoleBindingMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import javax.swing.*;
import java.util.List;
/**
@@ -56,12 +56,15 @@
            poleBinding.setDeviceCode(param.getDeviceCode());
            return save(poleBinding);
        } else {
            //删除灯杆的devicescode
            PoleService poleService = SpringContextHolder.getBean(PoleService.class);
            Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, one.getPoleId()));
            if (pole != null) {
                pole.setDeviceCode(null);
                poleService.updateById(pole);
            //修改单灯的绑定关系的时候要额外处理的事务
            // 删除灯杆的devicescode
            if (param.getDeviceType() == 0) {
                PoleService poleService = SpringContextHolder.getBean(PoleService.class);
                Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, one.getPoleId()));
                if (pole != null) {
                    pole.setDeviceCode(null);
                    poleService.updateById(pole);
                }
            }
            one.setPoleId(poleId);
@@ -87,16 +90,6 @@
            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));
            //删除灯杆的devicescode
            PoleService poleService = SpringContextHolder.getBean(PoleService.class);
            Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, poleId));
            if (pole != null) {
                pole.setDeviceCode(null);
                poleService.updateById(pole);
            }
        }
        if (one != null) {
            return removeById(one.getId());
@@ -127,4 +120,25 @@
    public PoleBinding getPoleIdByMac(String deviceCode) {
        return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
    }
    /**
     * 判断设备归属
     *
     * @param deviceCode 设备编号
     * @param type       设备类型
     * @return 已绑定返回true,未绑定返回false
     */
    public boolean isBelong(String deviceCode, String type) {
        if (type.isEmpty() || deviceCode.isEmpty()) {
            throw new BusinessException("设备编号或类型不能为空");
        }
        Long userId = SecurityUtils.getClientId();
        Pole binding = baseMapper.getPoleByBinding(type, deviceCode, userId);
        if (binding != null) {
            return true;
        } else {
            return false;
        }
    }
}