package com.ruoyi.ibs.grid.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.ibs.grid.domain.dto.GridCustListDTO;
import com.ruoyi.ibs.grid.domain.dto.RegionGridListDTO;
import com.ruoyi.ibs.grid.domain.entity.RegionGrid;
import com.ruoyi.ibs.grid.domain.vo.RegionGridCustVO;
import com.ruoyi.ibs.grid.domain.vo.RegionGridGroupVO;
import com.ruoyi.ibs.grid.domain.vo.RegionGridListVO;
import com.ruoyi.ibs.grid.domain.vo.RegionUnbindVo;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @Author 吴凯程
 * @Date 2024/9/18
 **/

public interface RegionGridMapper extends BaseMapper<RegionGrid> {

    List<String> getSelectedRegionCodes(@Param("deptId") Long deptId,
                                        @Param("opsDept") String opsDept,
                                        @Param("gridLevel") String gridLevel,
                                        @Param("gridId") Long gridId);

    RegionGrid getSecGridIdByCode(@Param("gridId") Long gridId, @Param("code") String code);

    List<Long> getDeptListByRegionCode(@Param("regionCode") String regionCode, @Param("opsDept") String opsDept);

    List<String> getUserListByRegionCode(@Param("regionCode") String regionCode, @Param("opsDept") String opsDept);

    List<RegionUnbindVo> getUserUnbindList(@Param("gridId") Long gridId, @Param("custId") String custId);

    List<RegionGridCustVO> getRetailCust(GridCustListDTO gridCustListDTO);

    List<RegionGridCustVO> getMerchantCust(GridCustListDTO gridCustListDTO);

    List<RegionGridCustVO> getBusinessCust(GridCustListDTO gridCustListDTO);

    List<RegionGridCustVO> getRetailCustFromTopByManager(GridCustListDTO gridCustListDTO);

    List<RegionGridCustVO> getRetailCustFromSecByManager(GridCustListDTO gridCustListDTO);

    List<RegionGridCustVO> getMerchantCustFromTopByManager(GridCustListDTO gridCustListDTO);

    List<RegionGridCustVO> getMerchantCustFromSecByManager(GridCustListDTO gridCustListDTO);

    List<RegionGridCustVO> getBusinessCustFromTopByManager(GridCustListDTO gridCustListDTO);

    List<RegionGridCustVO> getBusinessCustFromSecByManager(GridCustListDTO gridCustListDTO);

    List<RegionGridListVO> getTopGridList(RegionGridListDTO regionGridListDTO);

    List<RegionGridListVO> getSecGridList(RegionGridListDTO regionGridListDTO);

    List<RegionGridListVO> getSecGridListByManager(RegionGridListDTO regionGridListDTO);

    Long getGridCountByDeptId(@Param("deptId") Long deptId, @Param("opsDept") String opsDept, @Param("gridLevel") String gridLevel);

    Long getSecGridCountByUserName(@Param("userName") String userName);

    List<String> getCodeByDeptId(@Param("deptId") Long deptId, @Param("opsDept") String opsDept);

    List<String> getCodeByOutletId(@Param("deptId") Long deptId);

    RegionGrid selectTopGridByName(@Param("gridName") String gridName, @Param("deptId") Long deptId);

    List<String> getRegionNamesByGridId(@Param("gridId") Long gridId);

    List<Long> getSecGridIdByTopGridId(@Param("gridId") Long gridId);

    /**
     * 查询地理网格列表（简化版）- 专用于客群创建
     * 只返回gridId和gridName，避免N+1查询问题
     */
    List<RegionGridGroupVO> getRegionGridListForGroup(RegionGridListDTO regionGridListDTO);

}
