2021与蓝度共同重构项目,服务端
fix
zhanzhiqin
2022-04-22 1a8340a0bb7dd7cd72bb6ca5fb5a3e3accda2924
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java
@@ -1,13 +1,19 @@
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.common.util.SpringContextHolder;
import com.sandu.ximon.admin.param.PoleBindingParam;
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;
/**
 * @author chenjiantian
@@ -30,6 +36,16 @@
        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) && deviceType != 2) {
                    throw new BusinessException("该灯杆已绑定过相同类型设备");
                }
            }
        }
        PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, param.getDeviceCode()));
        if (one == null) {
@@ -40,7 +56,22 @@
            poleBinding.setDeviceCode(param.getDeviceCode());
            return save(poleBinding);
        } else {
            throw new BusinessException("该设备已绑定过");
            //修改单灯的绑定关系的时候要额外处理的事务
            // 删除灯杆的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);
            one.setDeviceType(param.getDeviceType());
            one.setDeviceName(param.getDeviceName());
            one.setDeviceCode(param.getDeviceCode());
            return updateById(one);
        }
    }
@@ -86,7 +117,7 @@
        }
    }
    public PoleBinding getPoleIdByMac(String deviceCode){
       return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
    public PoleBinding getPoleIdByMac(String deviceCode) {
        return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
    }
}