package com.hdkj.lt.bf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdkj.lt.bf.entity.FhzgDistCustomer;
import com.hdkj.lt.core.bizms.modle.dto.FhzgDistCustomerDTO;
import com.hdkj.lt.core.bizms.modle.dto.FhzgFaultDistCustomerDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 配电用户信息表 Mapper接口
 *
 * @author zhousc
 * @since 2025-05-07
 */
@Mapper
public interface FhzgDistCustomerMapper extends BaseMapper<FhzgDistCustomer> {

    @Select("select distinct pvu.id,dc.cust_id as customer_id, dc.cust_no, dc.cust_name, dc.cust_voltage, dc.zone_no, dc.zone_name,dc.user_type" +
            " from fhzg_plan_power_cut_pv_users pvu left join fhzg_dist_pv_customer dc on dc.cust_id = pvu.cust_id" +
            " where pvu.plan_id = #{dto.planId} ")
    List<FhzgDistCustomer> selectCustomerList(Page<FhzgDistCustomer> page, @Param("dto") FhzgDistCustomerDTO dto);

    @Select("select distinct pvu.id,dc.cust_id as customer_id,  dc.cust_no, dc.cust_name, dc.cust_voltage, dc.zone_no, dc.zone_name,dc.user_type" +
            " from fhzg_fault_power_cut_pv_users pvu left join fhzg_dist_pv_customer dc on dc.cust_id = pvu.cust_id" +
            " left join fhzg_fault_power_cut pc on pvu.fault_id = pc.fault_no" +
            " where pc.id = #{dto.faultId} ")
    List<FhzgDistCustomer> selectCustomerListByFaultId(Page<FhzgDistCustomer> page, FhzgFaultDistCustomerDTO dto);

    @Select("SELECT cpv.user_type userType, count(1) count " +
            "FROM fhzg_plan_power_cut_pv_users cpv where cpv.plan_id= #{dto.planId}  GROUP BY cpv.user_type")
    List<FhzgDistCustomer> getDistCustomerCount(@Param("dto") FhzgDistCustomerDTO dto);

    @Select("SELECT cpv.user_type userType, count(1) count " +
            "FROM fhzg_fault_power_cut_pv_users cpv " +
            "LEFT JOIN fhzg_fault_power_cut pc on cpv.fault_id = pc.fault_no " +
            "where pc.id= #{dto.faultId}  GROUP BY cpv.user_type ")
    List<FhzgDistCustomer> getDistCustomerCountByFaultId(@Param("dto") FhzgFaultDistCustomerDTO dto);


}
