package com.njcn.device.pms.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.device.pq.pojo.po.DeptLine;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author denghuajun
 * @since 2022-01-12 18:04
 */
public interface DeptLineMapper extends BaseMapper<DeptLine> {
    /**
     * 换绑监测点
     * @param id 部门id
     * @param lineId 监测点id
     * @return
     */
    int deptChangeBindLine(@Param("id")String id,@Param("lineId")String lineId);


    /**
     * 查询所有绑定的监测点
     */
    List<String> getAllBindLine();

    /**
     * 查询其他绑定的监测点
     * @param deptId
     * @return
     */
    List<String> getOtherBindLine(@Param("deptId")String deptId);

    /**
     * 查询自己绑定的监测点
     * @param deptId
     * @return
     */
    List<String> getMyselfBindLine(@Param("deptId")String deptId);

    @Select ("SELECT\n" +
            "\tpq_dept_line.Id,\n" +
            "\tpq_dept_line.Line_Id\n" +
            "FROM\n" +
            "\tpq_dept_line\n" +
            "WHERE\n" +
            "\tEXISTS (\n" +
            "\t\tSELECT\n" +
            "\t\t\t1\n" +
            "\t\tFROM\n" +
            "\t\t\tpq_device,\n" +
            "\t\t\tpq_line\n" +
            "\t\tWHERE\n" +
            "\t\t\tSUBSTRING_INDEX(\n" +
            "\t\t\t\tSUBSTRING_INDEX(pq_line.Pids, ',', 5),\n" +
            "\t\t\t\t',',\n" +
            "\t\t\t\t- 1\n" +
            "\t\t\t) = pq_device.Id\n" +
            "\t\tAND pq_line.Id = pq_dept_line.Line_Id and (pq_device.Dev_Data_Type= 2 or pq_device.Dev_Data_Type = #{devDataType})\n" +
            "\t)")
    List<DeptLine> getLineByDeptRelation(@Param("devDataType")Integer devDataType);
}
