package com.common.mapper;

import com.common.entity.DeviceInterlocking;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface DeviceInterlockingMapper {

    /**
     * 根据ID查询
     */
    @Select("SELECT * FROM device_interlocking WHERE id = #{id}")
    DeviceInterlocking selectById(Long id);

    /**
     * 根据部门ID查询联动设备
     */
    @Select("SELECT * FROM device_interlocking WHERE dept_id = #{deptId}")
    List<DeviceInterlocking> selectByDeptId(@Param("deptId") String deptId);

    /**
     * 根据厂商查询
     */
    @Select("SELECT * FROM device_interlocking WHERE vendor = #{vendor}")
    List<DeviceInterlocking> selectByVendor(@Param("vendor") String vendor);

    /**
     * 插入记录
     */
    @Insert("INSERT INTO device_interlocking (device_name, vendor, dept_id, ban_limit, ip, api_url, " +
            "tenant_id, create_dept, create_by, create_time, update_time, remark, auth_username, auth_password) " +
            "VALUES (#{deviceName}, #{vendor}, #{deptId}, #{banLimit}, #{ip}, #{apiUrl}, " +
            "#{tenantId}, #{createDept}, #{createBy}, NOW(), NOW(), #{remark}, #{authUsername}, #{authPassword})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(DeviceInterlocking device);

    /**
     * 更新记录
     */
    @Update("UPDATE device_interlocking SET device_name = #{deviceName}, vendor = #{vendor}, " +
            "dept_id = #{deptId}, ban_limit = #{banLimit}, ip = #{ip}, api_url = #{apiUrl}, " +
            "update_time = NOW(), remark = #{remark}, auth_username = #{authUsername}, " +
            "auth_password = #{authPassword} WHERE id = #{id}")
    int update(DeviceInterlocking device);

    /**
     * 查询所有记录
     */
    @Select("SELECT * FROM device_interlocking ORDER BY create_time DESC")
    List<DeviceInterlocking> selectAll();
}
