<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="MdeVipPackageMapper">
    
	<sql id="mdeVipPackageColumns">
		a.pkg_id AS "pkgId",
		a.pkg_type AS "pkgType",
		a.pkg_title AS "pkgTitle",
		a.pkg_introduction AS "pkgIntroduction",
		a.pkg_detail AS "pkgDetail",
		a.RECOMMENDED as recommended,
		a.pkg_title_en AS "pkgTitleEn",
		a.pkg_introduction_en AS "pkgIntroductionEn",
		a.pkg_detail_en AS "pkgDetailEn",
		a.sort AS "sort",
		a.VIP_FLAG as "vipFlag",
		a.pkg_status AS "pkgStatus",
		a.version_no AS "versionNo",
		a.create_by AS "createBy",
		a.create_date AS "createDate",
		a.update_by AS "updateBy",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag"
	</sql>
	
	<sql id="mdeVipPackageJoins"> 
	</sql>
	
	<resultMap type="com.wechat.model.dbEntity.MdeVipPackage" id="mdeVipPackageMap">
		<result column="pkgId" property="pkgId" />
		<result column="pkgType" property="pkgType"/>
		<result column="pkgTitle" property="pkgTitle" />
		<result column="recommended" property="recommended" />
		<result column="vipFlag" property="vipFlag" />
		<result column="pkgIntroduction" property="pkgIntroduction"/>
		<result column="pkgDetail" property="pkgDetail" />
		<result column="pkgTitleEn" property="pkgTitleEn" />
		<result column="pkgIntroductionEn" property="pkgIntroductionEn"/>
		<result column="pkgDetailEn" property="pkgDetailEn" />
		<result column="pkgStatus" property="pkgStatus"/> 
		<collection column="pkgId" property="pkgDetails" ofType="com.wechat.model.dto.VipPackagePriceDto" >
			<result column="priceId" property="priceId"/>
			<result column="pkgId" property="pkgId"/>  
            <result column="validityPeriod" property="validityPeriod"/>
            <result column="skuCn" property="skuCn"/>
            <result column="skuEn" property="skuEn"/>
            <result column="price" property="price"/>
            <result column="marketPrice" property="marketPrice"/>
		</collection>
	</resultMap>
	
	<resultMap type="com.wechat.model.dto.VipPackageDto" id="vipPackageDtoMap">
		<id column="pkgId" property="pkgId" />
		<result column="pkgType" property="pkgType"/>
		<result column="pkgTitle" property="pkgTitle" />
		<result column="RECOMMENDED" property="recommended" />
		<result column="vipFlag" property="vipFlag" />
		<result column="pkgIntroduction" property="pkgIntroduction"/>
		<result column="pkgTitleEn" property="pkgTitleEn" />
		<result column="pkgIntroductionEn" property="pkgIntroductionEn"/>
		<result column="pkgStatus" property="pkgStatus"/>

		<collection column="pkgId" property="pkgPrice" ofType="com.wechat.model.dto.VipPackagePriceDto" >
			<result column="priceId" property="priceId"/>
			<result column="pkgId" property="pkgId"/>    
            <result column="validityPeriod" property="validityPeriod"/>
            <result column="skuCn" property="skuCn"/>
            <result column="skuEn" property="skuEn"/>
            <result column="price" property="price"/> 
            <result column="marketPrice" property="marketPrice"/>
		</collection>
		<collection javaType="list" column="pkgServiceType" property="pkgDetailGroup" ofType="com.wechat.model.dto.VipPackageDetailGroupDto" >
			<result column="pkgServiceType" property="pkgServiceType"/>    
			<collection javaType="list" resultMap="pkgDetail" property="pkgDetail"/>
		</collection>	
	</resultMap>
	
	<resultMap type="com.wechat.model.dto.VipPackageDetailDto" id="pkgDetail">
		<id column="pkgDtlId" property="pkgDtlId"/> 
		<result column="pkgId" property="pkgId"/>    
        <result column="pkgType" property="pkgType"/>
        <result column="pkgServiceType" property="pkgServiceType"/> 
        <result column="sort" property="sort"/>
        <result column="pkgDetail" property="pkgDetail"/>
        <result column="pkgDetailEn" property="pkgDetailEn"/>
	</resultMap>
			
	<select id="getPkgInfoById" resultMap="mdeVipPackageMap">
  		SELECT 
			a.pkg_id AS "pkgId",
			a.VIP_FLAG as "vipFlag",
			a.pkg_type AS "pkgType",
			<choose>
				<when test=" lang == 'en'.toString() ">
					a.pkg_title_en AS "pkgTitle",
					a.pkg_introduction_en AS "pkgIntroduction",
					a.pkg_detail_en AS "pkgDetail",
				</when>
				<otherwise>
					a.pkg_title AS "pkgTitle",
					a.pkg_introduction AS "pkgIntroduction",
					a.pkg_detail AS "pkgDetail",
				</otherwise>
			</choose>
			a.pkg_status AS "pkgStatus",
			b.price_id as priceId,
			b.validity_period AS "validityPeriod",
			b.SKU_CN as skuCn,
			b.SKU_EN as skuEn,
			b.MARKET_PRICE AS marketPrice,
			b.price AS "price"
		FROM mde_vip_package a
		left join MDE_VIP_PACKAGE_PRICE b on a.PKG_ID = b.PKG_ID and b.DEL_FLAG =0
		WHERE a.PKG_STATUS =3 and a.DEL_FLAG =0 
		and a.pkg_id = #{pkgId}
	</select>
	
	
	<select id="getPackagesByIdentityFlag" resultMap="vipPackageDtoMap">
  		SELECT 
			a.pkg_id AS pkgId,
			a.pkg_type AS pkgType,
			a.pkg_title_en AS pkgTitleEn,
			a.pkg_introduction_en AS pkgIntroductionEn,
			a.pkg_title AS pkgTitle,
			a.pkg_introduction AS pkgIntroduction,
			a.pkg_status AS pkgStatus,
			a.recommended as recommended,
			a.VIP_FLAG as vipFlag,
			b.PRICE_ID AS priceId,
			b.validity_period AS validityPeriod,
			b.SKU_CN as skuCn,
			b.SKU_EN as skuEn,
			b.price AS price,
			b.MARKET_PRICE AS marketPrice,
			c.PKG_DTL_ID as pkgDtlId,
			c.PKG_SERVICE_TYPE as pkgServiceType,
			c.PKG_DETAIL as pkgDetail,
			c.PKG_DETAIL_EN as pkgDetailEn
		FROM 
			mde_vip_package a
		left join 
			MDE_VIP_PACKAGE_PRICE b 
		 on a.PKG_ID = b.PKG_ID and b.DEL_FLAG =0
		inner join 
			MDE_VIP_PACKAGE_DETAIL c 
		 on a.PKG_ID = c.PKG_ID and c.DEL_FLAG =0
		WHERE 
			a.PKG_STATUS =3 and a.DEL_FLAG =0 
		and a.pkg_type =#{identityFlag}
		order by 
			a.sort asc , c.sort ,c.PKG_DTL_ID 
	</select>
	
	<select id="getPkgInfoContainPrice" resultMap="mdeVipPackageMap">
  		SELECT 
		a.pkg_id AS "pkgId",
		a.pkg_type AS "pkgType",
		a.VIP_FLAG as vipFlag,
		a.pkg_title AS "pkgTitle",
		a.pkg_introduction AS "pkgIntroduction",
		a.pkg_detail AS "pkgDetail",
		
		a.pkg_title_en AS "pkgTitleEn",
		a.pkg_introduction_en AS "pkgIntroductionEn",
		a.pkg_detail_en AS "pkgDetailEn", 
		
		a.pkg_status AS "pkgStatus",
		b.PRICE_ID AS priceId,
		b.validity_period AS "validityPeriod",
		b.sku_cn AS "skuCn",
		b.sku_en AS "skuEn",
		b.price AS "price" 
		FROM mde_vip_package a
		left join MDE_VIP_PACKAGE_PRICE b on a.PKG_ID = b.PKG_ID and b.DEL_FLAG =0 and b.PRICE_ID=#{priceId}
		WHERE a.PKG_STATUS =3 and a.DEL_FLAG =0 and a.PKG_ID =#{pkgId}  
	</select>
    
	
	
</mapper>