<?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="MdeVipPackagePriceMapper">
    
	<sql id="mdeVipPackagePriceColumns">
		a.pkg_id AS "pkgId",
		a.validity_period AS "validityPeriod",
		a.price AS "price",
		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="mdeVipPackagePriceJoins">
	</sql>
    
	<select id="get" resultType="com.wechat.model.dbEntity.MdeVipPackagePrice">
		SELECT 
			<include refid="mdeVipPackagePriceColumns"/>
		FROM mde_vip_package_price a
		<include refid="mdeVipPackagePriceJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="com.wechat.model.dbEntity.MdeVipPackagePrice">
		SELECT 
			<include refid="mdeVipPackagePriceColumns"/>
		FROM mde_vip_package_price a
		<include refid="mdeVipPackagePriceJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY #{page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="com.wechat.model.dbEntity.MdeVipPackagePrice">
		SELECT 
			<include refid="mdeVipPackagePriceColumns"/>
		FROM mde_vip_package_price a
		<include refid="mdeVipPackagePriceJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY #{page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO mde_vip_package_price(
			validity_period,
			price,
			version_no,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{validityPeriod},
			#{price},
			#{versionNo},
			#{createBy},
			#{createDate},
			#{updateBy},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE mde_vip_package_price SET 	
			validity_period = #{validityPeriod},
			price = #{price},
			version_no = version_no+1,
			update_by = #{updateBy},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id} version_no = #{versionNo}
	</update>
	
	<update id="delete">
		UPDATE mde_vip_package_price SET 
		version_no = version_no+1,
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id} version_no = #{versionNo}
	</update>
	
</mapper>