package cn.pluss.platform.mapper;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import cn.pluss.platform.dto.MercActiveDataDTO;
import cn.pluss.platform.dto.MercOrderDataDTO;
import cn.pluss.platform.dto.MercTradeDataDTO;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.vo.StoreInfoVO;
import cn.pluss.platform.vo.UserNumVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import cn.pluss.platform.entity.MerchantBaseInfo;
import cn.pluss.platform.vo.MerchantBaseNewVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface MerchantBaseInfoMapper extends BaseMapper<MerchantBaseInfo> {


	@Select("SELECT * FROM tb_pluss_merchant_base_info WHERE merchantCode = #{merchantCode}")
	MerchantBaseInfo queryByMerchantCode(@Param("merchantCode") String merchantCode);

	@Select("SELECT * FROM tb_pluss_merchant_base_info WHERE userId = #{userId}")
	List<MerchantBaseInfo> selectListByUserId(@Param("userId") Serializable userId);

    default MerchantBaseInfo queryMerchantBaseInfo(MerchantBaseInfo merchantBaseInfo) {
    	return selectOne(new QueryWrapper<>(merchantBaseInfo));
	}

	default List<MerchantBaseInfo> queryMerchantBaseInfoList(MerchantBaseInfo merchantBaseInfo) {
		return selectList(new QueryWrapper<>(merchantBaseInfo));
	}

    default void saveMerchantBaseInfo(MerchantBaseInfo merchantBaseInfo) {
    	insert(merchantBaseInfo);
	}

	default void updateMerchantBaseInfo(MerchantBaseInfo merchantBaseInfo) {
    	updateById(merchantBaseInfo);
	}

    default void deleteMerchantBaseInfo(MerchantBaseInfo merchantBaseInfo) {
    	deleteById(merchantBaseInfo.getId());
	}

    List<MerchantBaseInfo> queryMerchantBaseInfoPage(Map map);

    Integer queryMerchantBaseInfoPageCount(Map map);

	Integer queryMerchantBaseInfoPageCountBySignDt(Map map);
	
	/**
	 * 
	 * queryMerchantBaseNewPage:(查询商户管理列表的). <br/> 
	 * 
	 * @author Administrator 
	 * @param map
	 * @return 
	 * @since JDK 1.8
	 */
	List<MerchantBaseNewVO> queryMerchantBaseNewPage(Map<String, Object> map);
	
	//统计商户列表个数,admin
	Integer queryMerchantBaseNewPageCount(Map<String, Object> map);
	//统计商户列表个数,商户
	Integer queryMerchantNoBaseNewPageCount(Map<String, Object> map);
	/**
	 * 统计粉丝总数
	 * @param map
	 * @return
	 */
	Integer queryMerchantFansCount(Map map);

	Integer queryTodayFanCount(Map<String, Object> fansMap);

	/**
	 * 获取指定用户所有的店铺
	 * @return	店铺列表
	 */
	List<MerchantBaseInfo> queryMerchantListByUserId(@Param("userId") String userId);

    StoreInfoVO selectParticulars(Integer id);

	/**
	 * 查询商户 ，商户
	 * @param map
	 * @return
	 */
	List<MerchantBaseNewVO> queryMerchantNoBaseNewPage(Map<String, Object> map);

	/**
	 * 关联查询分页信息
	 * @param merchantPage
	 * @param userApp
	 * @return
	 */
    Page<MerchantBaseInfo> pageJoinData(@Param("page")Page<MerchantBaseInfo> merchantPage,
										@Param("userApp")UserApp userApp);

    /**
     * @description:
     * @date: 2021/12/30 17:52
     * @param page:
     * @param dto:
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<cn.pluss.platform.dto.MercOrderDataDTO>
     */
    Page<MercOrderDataDTO> pageData(@Param("page")Page<MercOrderDataDTO> page, @Param("dto")MercOrderDataDTO dto);

    Page<MercTradeDataDTO> pageTradeData(@Param("page")Page<MercTradeDataDTO> page, @Param("dto")MercTradeDataDTO dto);

	/**
	 * 该查询只查询商户信息，不做交易数据统计
	 *
	 * @return
	 */
	List<MercTradeDataDTO> listMercData(@Param("userId") Long userId, @Param("merchantCodeList") List<String> merchantCodeList);

	Page<MercTradeDataDTO> pageTradeDataHistory(@Param("page")Page<MercTradeDataDTO> page, @Param("dto")MercTradeDataDTO dto);

    Page<MercActiveDataDTO> pageActiveData(@Param("page") Page<MercActiveDataDTO> page, @Param("dto")MercActiveDataDTO dto);

	/**
	 * 根据区域和角色查询商户信息
	 * @date: 2022/3/1 16:51
	 * @param areaList:
	 * @param roleCode:
	 * @return java.util.List<java.lang.String>
	 */
    List<String> getAreaAndRoleList(@Param("areaList") List<String> areaList, @Param("roleCode") String roleCode);


	@Select("SELECT mbi.merchantCode FROM tb_pluss_merchant_base_info mbi LEFT JOIN tb_pluss_user_app ua ON mbi.merchantCode = ua.merchantCode AND ua.userType = 'promoter' WHERE ua.parentId = #{userId}")
	List<String> queryNextMercCodeByUserId(Serializable userId);
}

