package com.tofly.xrtygis.custom.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.xrtygis.entity.Tablelinkpipe;
import com.tofly.xrtygis.entity.Tablelinkuser;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * 综合展示线上核对
 *
 * @author 泡泡
 */
public interface TheOnlineCheckMapper {

    /**
     * 是否为总表
     */
    @Select("select count(*) from TF_YWPN_WATERMETER_W where ID = #{code} and ISSUM = 1 and STATUS = 1")
    Long isSumTable(@Param("code") Long code);

    /**
     * 查询总表信息
     *
     * @return list
     */
    @Select("select id,sid,address,x,y from TF_YWPN_WATERMETER_W where ISSUM = 1")
    List<Map<String, Object>> selectSumTableInfo();

    /**
     * 管线客户总表显示
     *
     * @param type 确认状态：0未确认、1已确认、2自动匹配
     * @param page page
     * @return pages
     */
    Page<Map> viewTablePipe(Page page,@Param("type") Short type);

    /**
     *
     * 查询未关联客户信息
     *
     * @param page page
     * @param str  str
     * @return page
     */
    Page<Map> unaffiliatedCustomer(Page page, @Param("str") String str);

    Page<Map<String,Object>> unaffiliatedCustomer2(Page page);

    @Select("select u.KHBH,\n" +
            "       u.ID, \n" +
            "       u.SID,\n" +
            "       q.YHDZ,\n" +
            "       q.YHXM,\n" +
            "       m.X,\n" +
            "       m.Y,\n" +
            "       decode(STATE,'0','未确认','1','确认','2','自动匹配') state,\n" +
            "       VILLAGE\n" +
            "from TF_YWPN_TABLELINKUSER_W u\n" +
            "         left join TF_YWPN_QFKHJBXX_W q on u.KHBH = q.YHBH\n" +
            "         left join TF_YWPN_WATERMETER_W m on u.SID = m.SID\n" +
            "       where table_id = #{tableId}")
    Page<Map> affiliatedCustomer(Page page, @Param("tableId") Integer tableId);

    @Select("select u.KHBH,\n" +
            "       u.ID, \n" +
            "       u.SID,\n" +
            "       q.YHDZ,\n" +
            "       q.YHXM,\n" +
            "       m.X,\n" +
            "       m.Y,\n" +
            "       decode(STATE,'0','未确认','1','确认','2','自动匹配') state,\n" +
            "       VILLAGE\n" +
            "from TF_YWPN_TABLELINKUSER_W u\n" +
            "         left join TF_YWPN_QFKHJBXX_W q on u.KHBH = q.YHBH\n" +
            "         left join TF_YWPN_WATERMETER_W m on u.SID = m.SID\n" +
            "       where table_id = #{tableId}")
    List<Map<String, Object>> affiliatedCustomer(@Param("tableId") Integer tableId);

    boolean insertUserToTable(@Param("t") List<Tablelinkuser> t);

    boolean updatePlotName(@Param("name") String name,@Param("codes") List<String> codes);

    @Select("select count(*) from TF_YWPN_TABLELINKUSER_W")
    Double getNowNum();

    List<Map<String, Object>> getCustomerInfo(@Param("list")List<String> list);

    Map<String,Object> getWateMeter(@Param("tableId") Long tableId);

    boolean insertPipeTable(@Param("list") List<Tablelinkpipe> list);
}
