package com.imdroid.secapi.dto;

import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


@Mapper
public interface GnssStatusMapper extends MPJBaseMapper<GnssStatus> {

    // 不需要关联设备类型
    @Select({"select * from gnssstatus where deviceid = #{deviceId} limit 1"})
    GnssStatus getByDeviceId(String deviceId);

    @Update({"update gnssstatus set state=0,warning=#{warning},warningcode=#{warningcode} where deviceid=#{deviceid}"})
    int setOfflineByDeviceId(GnssStatusJoin status);

    @Select({"select s.*, d.devicetype, d.group_id, d.name from gnssstatus s ,gnssdevices d where s.deviceid=d.deviceid and s.state <> 0"})
    List<GnssStatusJoin> queryOnline();

    @Select({"select s.*, d.devicetype, d.group_id, d.name from gnssstatus s ,gnssdevices d where " +
            "s.deviceid=d.deviceid and d.tenantid<>0 and d.opmode<>2"})
    List<GnssStatusJoin> queryDeployed();

    @Select({"select s.*, d.devicetype, d.group_id, d.name from gnssstatus s ,gnssdevices d where " +
            "s.deviceid=d.deviceid and d.tenantid = #{tenantid} and d.opmode<>2"})
    List<GnssStatusJoin> queryDeployedByTenant(int tenantid);

    // 需要关联设备类型
    @Select({"select s.*, d.devicetype from gnssstatus s ,gnssdevices d where s.deviceid=d.deviceid and s.deviceid = #{deviceId}"})
    GnssStatusJoin queryByDeviceId(String deviceId);

    @Select({"select s.*, d.devicetype from gnssstatus s ,gnssdevices d where s.deviceid=d.deviceid"})
    GnssStatusJoin queryAll();
}
