<?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="com.kmall.api.dao.mk.ApiMkStoreCampMinusLevelMapper">

	<resultMap type="com.kmall.api.entity.mk.MkStoreCampMinusLevelVo" id="mkStoreCampMinusLevelMap">
		<result property="campMinusLevelId" column="camp_minus_level_id"/>
		<result property="campMinusType" column="camp_minus_type"/>
		<result property="campMinusId" column="camp_minus_id"/>
		<result property="minusMode" column="minus_mode"/>
		<result property="yuanMinusCond" column="yuan_minus_cond"/>
		<result property="yuanMinusPref" column="yuan_minus_pref"/>
		<result property="pieceMinusConf" column="piece_minus_conf"/>
		<result property="pieceMinusPref" column="piece_minus_pref"/>
		<result property="pieceMinusEachDisc" column="piece_minus_each_disc"/>
		<result property="yuanDiscCond" column="yuan_disc_cond"/>
		<result property="yuanDiscPref" column="yuan_disc_pref"/>
		<result property="pieceDiscConf" column="piece_disc_conf"/>
		<result property="pieceDiscPref" column="piece_disc_pref"/>
		<result property="isValid" column="is_valid"/>
		<result property="note" column="note"/>
		<result property="createrSn" column="creater_sn"/>
		<result property="createTime" column="create_time"/>
		<result property="moderSn" column="moder_sn"/>
		<result property="modTime" column="mod_time"/>
		<result property="tstm" column="tstm"/>
	</resultMap>

	<select id="queryObject" resultType="com.kmall.api.entity.mk.MkStoreCampMinusLevelVo">
		select
		`camp_minus_level_id`,
		`camp_minus_type`,
		`camp_minus_id`,
		`minus_mode`,
		`yuan_minus_cond`,
		`yuan_minus_pref`,
		`piece_minus_conf`,
		`piece_minus_pref`,
		`piece_minus_each_disc`,
		`yuan_disc_cond`,
		`yuan_disc_pref`,
		`piece_disc_conf`,
		`piece_disc_pref`,
		`is_valid`,
		`note`,
		`creater_sn`,
		`create_time`,
		`moder_sn`,
		`mod_time`,
		`tstm`
		from mk_store_camp_minus_level
		where camp_minus_level_id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.api.entity.mk.MkStoreCampMinusLevelVo">
		select
		`camp_minus_level_id`,
		`camp_minus_type`,
		`camp_minus_id`,
		`minus_mode`,
		`yuan_minus_cond`,
		`yuan_minus_pref`,
		`piece_minus_conf`,
		`piece_minus_pref`,
		`piece_minus_each_disc`,
		`yuan_disc_cond`,
		`yuan_disc_pref`,
		`piece_disc_conf`,
		`piece_disc_pref`,
		`is_valid`,
		`note`,
		`creater_sn`,
		`create_time`,
		`moder_sn`,
		`mod_time`,
		`tstm`
		from mk_store_camp_minus_level
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
		<choose>
			<when test="sidx != null and sidx.trim() != ''">
				order by ${sidx} ${order}
			</when>
			<otherwise>
				order by camp_minus_level_id desc
			</otherwise>
		</choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>

	<select id="queryTotal" resultType="int">
		select count(*) from mk_store_camp_minus_level
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
	</select>

	<select id="queryObjectByCampMinusId" resultType="com.kmall.api.entity.mk.MkStoreCampMinusLevelVo">
		select
		`camp_minus_level_id`,
		`camp_minus_type`,
		`camp_minus_id`,
		`minus_mode`,
		`yuan_minus_cond`,
		`yuan_minus_pref`,
		`piece_minus_conf`,
		`piece_minus_pref`,
		`piece_minus_each_disc`,
		`yuan_disc_cond`,
		`yuan_disc_pref`,
		`piece_disc_conf`,
		`piece_disc_pref`,
		`is_valid`,
		`note`,
		`creater_sn`,
		`create_time`,
		`moder_sn`,
		`mod_time`,
		`tstm`
		from mk_store_camp_minus_level
		where camp_minus_id = #{campMinusId}
	</select>

	<select id="queryYuanCondByCampMinusId" resultType="com.kmall.api.entity.mk.MkStoreCampMinusLevelVo">
		SELECT
		`camp_minus_level_id`,
		`camp_minus_type`,
		`camp_minus_id`,
		`minus_mode`,
		`yuan_minus_cond`,
		`yuan_minus_pref`,
		piece_minus_each_disc,
		`is_valid`
		FROM mk_store_camp_minus_level
		WHERE
		camp_minus_id = #{campMinusId} AND camp_minus_type = #{campMinusType}
		AND minus_mode = #{minusMode} ORDER BY yuan_minus_cond DESC LIMIT 1
	</select>

	<select id="queryPieceConfByCampMinusId" resultType="com.kmall.api.entity.mk.MkStoreCampMinusLevelVo">
		SELECT
		`camp_minus_level_id`,
		`camp_minus_type`,
		`camp_minus_id`,
		`minus_mode`,
		`piece_minus_conf`,
		`piece_minus_pref`,
		piece_minus_each_disc,
		`is_valid`
		FROM mk_store_camp_minus_level
		WHERE
		camp_minus_id = #{campMinusId}  AND camp_minus_type = #{campMinusType}
		AND minus_mode = #{minusMode} ORDER BY piece_minus_conf DESC LIMIT 1
	</select>

	<select id="queryDiscCondByCampMinusId" resultType="com.kmall.api.entity.mk.MkStoreCampMinusLevelVo">
		SELECT
		`camp_minus_level_id`,
		`camp_minus_type`,
		`camp_minus_id`,
		`minus_mode`,
		`yuan_disc_cond`,
		`yuan_disc_pref`,
		`is_valid`
		FROM mk_store_camp_minus_level
		WHERE
		camp_minus_id = #{campMinusId}  AND camp_minus_type = '10' ORDER BY yuan_disc_cond DESC LIMIT 1
	</select>

	<select id="queryDiscConfByCampMinusId" resultType="com.kmall.api.entity.mk.MkStoreCampMinusLevelVo">
		SELECT
		`camp_minus_level_id`,
		`camp_minus_type`,
		`camp_minus_id`,
		`minus_mode`,
		`piece_disc_conf`,
		`piece_disc_pref`,
		`is_valid`
		FROM mk_store_camp_minus_level
		WHERE
		camp_minus_id = #{campMinusId}  AND camp_minus_type = '11' ORDER BY piece_disc_conf DESC LIMIT 1
	</select>
</mapper>