DeviceService.java 1.58 KB
package cn.com.glsx.admin.modules.service;

import cn.com.glsx.admin.common.constants.ConstantsDevice;
import cn.com.glsx.admin.modules.entity.Device;
import cn.com.glsx.admin.modules.entity.VehicleDevice;
import cn.com.glsx.admin.modules.mapper.DeviceMapper;
import cn.com.glsx.admin.modules.mapper.VehicleDeviceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Desc:设备service
 * @Author huangxc
 * @Date 2021/5/23
 */
@Service
public class DeviceService {
    @Autowired
    private DeviceMapper deviceMapper;
    @Autowired
    private VehicleDeviceMapper vdMapper;

    public void insertDevice(Device device) {
        deviceMapper.insert(device);
    }

    Device getDeviceBySn(String sn) {
        return deviceMapper.getDeviceBySn(sn);
    }

    /**
     * 检查设备号是否存在 false 不存在
     * @param sn
     */
    public boolean checkSnExist(String sn) {
        Device device = deviceMapper.getDeviceBySn(sn);
        if (device == null) {
            return false;
        }
        return true;
    }

    /**
     * 检查设备号是否绑定 false 没有绑定
     * @param sn
     */
    public boolean checkSnBind(String sn) {
        VehicleDevice vehicleDeviceParam = new VehicleDevice();
        vehicleDeviceParam.setSn(sn);
        VehicleDevice vehicleDevice = vdMapper.getVehicleDeviceBySnStatus(vehicleDeviceParam);
        if (vehicleDevice != null && vehicleDevice.getBindStatus() == ConstantsDevice.BIND_VEHICLE_STATUS) {
            return true;
        }
        return false;
    }

}