package org.nl.acs.device.service.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.nl.acs.device.domain.DeviceExtra;
import org.nl.acs.common.base.CommonMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @author jiaolm
* @date 2023-05-09
*/
@Repository
public interface DeviceExtraMapper extends CommonMapper<DeviceExtra> {
    String queryDeviceProtocolSql = "SELECT " +
            "d.device_id AS device_id,"+
            "d.device_code AS device_code," +
            "d.driver_code AS driver_code," +
            "d.device_type AS device_type," +
            "e.extra_code AS id," +
            "e.extra_code AS extra_code," +
            "e.extra_name AS extra_name," +
            "opc.opc_code AS opc_code," +
            "plc.plc_code AS plc_code " +
            "FROM " +
            "acs_device_extra e " +
            "LEFT JOIN acs_device d ON e.device_id = d.device_id " +
            "LEFT JOIN acs_opc opc ON d.opc_server_id = opc.opc_id " +
            "LEFT JOIN acs_opc_plc plc ON d.opc_plc_id = plc.plc_id ";
    String wrapperDeviceProtocolSql =  queryDeviceProtocolSql + " ${ew.customSqlSegment} " + "ORDER BY d.device_code,e.extra_name";
    /**
     * 设备协议分页查询
     */
    @Select(wrapperDeviceProtocolSql)
    <P extends IPage<DeviceExtra>> P queryDeviceProtocolPage(P page, @Param("ew") Wrapper<DeviceExtra> queryWrapper);

    @Select(wrapperDeviceProtocolSql)
    List<DeviceExtra> selectDeviceProtocolList(@Param("ew") Wrapper<DeviceExtra> queryWrapper);
}
