goods-config-mapper.xml 4.27 KB
<?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">

<!-- @author kongmingke -->
<mapper namespace="com.cjs.cms.dao.user.point.GoodsConfigDao">
	<sql id="goods_config_field">
	id, otc_code, otc_name, otc_account, image, price, point, goods_amount,
	goods_remain, goods_status, buy_max, lottery, lottery_probability, lottery_start,
	lottery_end, lottery_point, lottery_expire, buy_expire, create_at, create_by
	</sql>
	
	<sql id="searchCondition">
		where 1=1 
		<if test="otcCode != null and otcCode != ''">
			and otc_code = #{otcCode}
		</if>
		<if test="otcName != null and otcName != ''">
		    and otc_name = #{otcName}
		</if>
		<if test="goodsStatus != null and goodsStatus != ''">
			and goods_status = #{goodsStatus} 
		</if>
		<if test="startDate != null and startDate != ''"> <![CDATA[ and create_at >= #{startDate}]]> </if>
		<if test="endDate != null and endDate != ''">  <![CDATA[ and create_at <= DATE_ADD(#{endDate}, INTERVAL 1 day)]]> </if>
	</sql>
	
	<insert id="insert" parameterType="GoodsConfigInfo">
		insert into goods_config(otc_code, otc_name, otc_account, image, price, point, goods_amount,
	    goods_remain, goods_status, buy_max, lottery, lottery_probability, lottery_start, lottery_end, lottery_point,
	    lottery_expire, buy_expire, create_at, create_by) 
		values(#{otcCode}, #{otcName}, #{otcAccount}, #{image}, #{price}, #{point}, #{goodsAmount},
		#{goodsAmount}, '0', #{buyMax},#{lottery}, #{lotteryProbability},
		<choose>
	       <when test="lotteryStart != null and lotteryStart != ''">
	        #{lotteryStart},
	       </when>
	       <otherwise>
	        null,
	       </otherwise>
	    </choose>
	     <choose>
	       <when test="lotteryEnd != null and lotteryEnd != ''">
	       #{lotteryEnd},
	       </when>
	       <otherwise>
	        null,
	       </otherwise>
	    </choose>
		#{lotteryPoint}, #{lotteryExpire}, #{buyExpire}, CURRENT_TIMESTAMP, #{createBy}) 
	</insert>
	
	<update id="updateAll" parameterType="GoodsConfigInfo">
	    update goods_config set
	    price =#{price}, point =#{point}, goods_amount =#{goodsAmount}, goods_remain=#{goodsRemain},
	    buy_max=#{buyMax}, lottery=#{lottery}, lottery_probability=#{lotteryProbability}, lottery_point=#{lotteryPoint}, lottery_expire=#{lotteryExpire}, buy_expire=#{lotteryExpire}, 
	    create_by =#{createBy}
	    <choose>
	       <when test="lotteryStart != null and lotteryStart != ''">
	        ,lottery_start=#{lotteryStart}
	       </when>
	       <otherwise>
	        ,lottery_start = null
	       </otherwise>
	    </choose>
	     <choose>
	       <when test="lotteryEnd != null and lotteryEnd != ''">
	       ,lottery_end=#{lotteryEnd}
	       </when>
	       <otherwise>
	       ,lottery_end  = null
	       </otherwise>
	    </choose>
	    <if test="image != null and image != ''">
		,image =#{image}
		</if>
	    where id=#{id}
	</update>                                                        
	
	<!-- 修改藏品状态 -->
	<update id="updateStatus" parameterType="GoodsConfigInfo">
	    update goods_config set goods_status=#{goodsStatus} 
	    where id = #{id}
	</update>
	
	
	<select id="search" parameterType="map" resultType="GoodsConfigInfo">
		select <include refid="goods_config_field" /> 
		from goods_config 
		<include refid="searchCondition" />
		order by id desc 
		<include refid="common.pageLimit" />
	</select>
	
	<select id="searchTotal" parameterType="map" resultType="int">
		select count(*) from goods_config 
		<include refid="searchCondition" />
	</select>
	
	<select id="queryOne" parameterType="int" resultType="GoodsConfigInfo">
	    select <include refid="goods_config_field" /> 
	    from goods_config 
	    where id=#{id}
	</select>
	
	<select id="searchByTime" parameterType="GoodsConfigInfo" resultType="GoodsConfigInfo">
	     select <include refid="goods_config_field" /> 
	     from goods_config 
	     where  <![CDATA[ lottery_start<#{lotteryEnd}]]> <![CDATA[and lottery_end>#{lotteryStart}]]>
	     and lottery=1
	     and goods_status!=2
	     and otc_code != #{otcCode}
	</select>
	
	<select id="queryByOtcCode" parameterType="String" resultType="GoodsConfigInfo">
	     select <include refid="goods_config_field" /> 
	     from goods_config 
	     where otc_code=#{otcCode} and goods_status !=2
	</select>
</mapper>