package org.springblade.dataextraction.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Select;
import org.springblade.dataextraction.enity.DimCTypeSmall;
import org.springblade.dataextraction.enity.DimProductCategory;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Desc
 * @Author William
 * @DateTime 2022 下午4:30:42
 */
public interface DimProductCategoryMapper extends BaseMapper<DimProductCategory> {
	@Select("SELECT\r\n"
			+ "	cptype,\r\n"
			+ "	FULL_CPTYPE,\r\n"
			+ "	categoryname2\r\n"
			+ "FROM\r\n"
			+ "	(\r\n"
			+ "	SELECT DISTINCT * FROM\r\n"
			+ "		(\r\n"
			+ "		SELECT\r\n"
			+ "			cptype,\r\n"
			+ "			FULL_CPTYPE,\r\n"
			+ "			categoryname2,\r\n"
			+ "			cptype2\r\n"
			+ "		FROM\r\n"
			+ "			DIM_PRODUCT_CATEGORY\r\n"
			+ "		WHERE\r\n"
			+ "			cptype = #{cptype}\r\n"
			+ "		)\r\n"
			+ "	)\r\n"
			+ "ORDER BY cptype2")
	public List<DimCTypeSmall> listSmallCate(String cptype);
	
	@Select("SELECT\r\n"
			+ "	DISTINCT FULL_CPTYPE,\r\n"
			+ "	spid,\r\n"
			+ "	shortname\r\n"
			+ "FROM\r\n"
			+ "	DIM_PRODUCT_CATEGORY\r\n"
			+ "WHERE\r\n"
			+ "	isprm = 1\r\n"
			+ "	AND full_cptype  = #{fullCptype}\r\n"
			+ "UNION ALL\r\n"
			+ "SELECT\r\n"
			+ "	DISTINCT FULL_CPTYPE,\r\n"
			+ "	spid,\r\n"
			+ "	shortname\r\n"
			+ "FROM\r\n"
			+ "	DIM_PRODUCT_CATEGORY\r\n"
			+ "WHERE\r\n"
			+ "	( isprm != 1\r\n"
			+ "		OR isprm IS NULL )\r\n"
			+ "	AND full_cptype = #{fullCptype}")
	public List<DimProductCategory> listProduct(String fullCptype);
}
