<?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="cn.pluss.platform.mapper.QrCodeMapper">

	   	<insert id="saveQrCode" parameterType="cn.pluss.platform.entity.QrCode">
        	insert into tb_pluss_qr_code (
			createTime
			<if test="qrNo != null and qrNo != ''">
				,qrNo
			</if>
			<if test="orderNo != null and orderNo != ''">
				,orderNo
			</if>
			<if test="buyMercName != null and buyMercName != ''">
				,buyMercName
			</if>
			<if test="buyMercId != null">
				,buyMercId
			</if>
			<if test="actMercName != null and actMercName != ''">
				,actMercName
			</if>
			<if test="actMercId != null">
				,actMercId
			</if>
			<if test="status != null and status != ''">
				,status
			</if>
			<if test="createBy != null and createBy != ''">
				,createBy
			</if>
			<if test="remarks != null and remarks != ''">
				,remarks
			</if>
			)
			VALUES(
				now()
			<if test="qrNo != null and qrNo != ''">
				,#{qrNo}
			</if>
			<if test="orderNo != null and orderNo != ''">
				,#{orderNo}
			</if>
			<if test="buyMercName != null and buyMercName != ''">
				,#{buyMercName}
			</if>
			<if test="buyMercId != null">
				,#{buyMercId}
			</if>
			<if test="actMercName != null and actMercName != ''">
				,#{actMercName}
			</if>
			<if test="actMercId != null">
				,#{actMercId}
			</if>
			<if test="status != null and status != ''">
				,#{status}
			</if>
			<if test="createBy != null and createBy != ''">
				,#{createBy}
			</if>
			<if test="remarks != null and remarks != ''">
				,#{remarks}
			</if>
			)
    	</insert>

	   	<insert id="batchSaveQrCode">
        	insert into tb_pluss_qr_code(
			qrNo,orderNo,buyMercName,buyMercId,actMercName,actMercId,createTime,createBy,remarks
			) VALUES
    			<foreach collection="list" item="item" index="index" separator=",">
					(#{item.qrNo},#{item.orderNo},
					#{item.buyMercName},
					#{item.buyMercId},
					#{item.actMercName},
					#{item.actMercId},
					now(),#{item.createBy},#{item.remarks})
				</foreach>
    	</insert>

		<select id="getQrCode" parameterType="cn.pluss.platform.entity.QrCode" resultType="cn.pluss.platform.entity.QrCode">
			SELECT * from tb_pluss_qr_code
				<where>
					delFlag = '1'
					<if test="id!= null"> 
					 	and id = #{id}
					 </if> 
					<if test="qrNo!= null and qrNo != ''">
					 	and qrNo = #{qrNo}
					 </if> 
					<if test="orderNo!= null and orderNo != ''">
					 	and orderNo = #{orderNo}
					 </if> 
					<if test="buyMercName!= null and buyMercName != ''">
					 	and buyMercName = #{buyMercName}
					 </if>
					<if test="buyMercId!= null">
						and buyMercId = #{buyMercId}
					</if>
					<if test="actMercName!= null and actMercName != ''">
						and actMercName = #{actMercName}
					</if>
					<if test="actMercId!= null">
						and actMercId = #{actMercId}
					</if>
					<if test="status!= null and status != ''">
					 	and status = #{status}
					 </if> 
				 </where>
		</select>

		<select id="queryQrCodeList" parameterType="cn.pluss.platform.entity.QrCode" resultType="cn.pluss.platform.entity.QrCode">
			SELECT * from tb_pluss_qr_code
				<where>
					delFlag = '1'
					<if test="id!= null"> 
					 	and id = #{id}
					 </if>
					<if test="qrNo!= null and qrNo != ''">
						and qrNo = #{qrNo}
					</if>
					<if test="orderNo!= null and orderNo != ''">
						and orderNo = #{orderNo}
					</if>
					<if test="buyMercName!= null and buyMercName != ''">
						and buyMercName = #{buyMercName}
					</if>
					<if test="buyMercId!= null">
						and buyMercId = #{buyMercId}
					</if>
					<if test="actMercName!= null and actMercName != ''">
						and actMercName = #{actMercName}
					</if>
					<if test="actMercId!= null">
						and actMercId = #{actMercId}
					</if>
					<if test="status!= null and status != ''">
						and status = #{status}
					</if>
					<if test="createTime!= null">
						and createTime = #{createTime}
					</if>
				</where>
		</select>

		<select id="getQrCodeByQrNo" parameterType="java.lang.String" resultType="cn.pluss.platform.entity.QrCode">
			SELECT * from tb_pluss_qr_code where delFlag = '1' and qrNo = #{qrNo}
		</select>

		<update id="updateQrCode" parameterType="cn.pluss.platform.entity.QrCode" >
			update tb_pluss_qr_code
				  <set> 
					<if test="qrNo!= null and qrNo != ''">
						qrNo = #{qrNo},
					 </if>
					  <if test="orderNo!= null and orderNo !=''">
						  orderNo = #{orderNo},
					  </if>
					  <if test="buyMercName!= null and buyMercName != ''">
						  buyMercName = #{buyMercName},
					 </if>
					  <if test="buyMercId!= null">
						  buyMercId = #{buyMercId},
					  </if>
					  <if test="actMercName!= null and actMercName != ''">
						  actMercName = #{actMercName},
					  </if>
					  <if test="actMercId!= null">
						  actMercId = #{actMercId},
					  </if>

					  <if test="status!= null and status != ''">
						  status = #{status}
					  </if>
				</set>
			where id=#{id} 
		</update>

		<delete id="deleteQrCode" parameterType="cn.pluss.platform.entity.QrCode" >
			DELETE FROM tb_pluss_qr_code where id=#{id}
		</delete>

		<select id="queryQrCodePage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.QrCode">
			SELECT * from tb_pluss_qr_code
				<where>
					delFlag = '1'
					<if test="id!= null">
						and id = #{id}
					</if>
					<if test="qrNo!= null and qrNo != ''">
						and qrNo = #{qrNo}
					</if>
					<if test="orderNo!= null and orderNo != ''">
						and orderNo = #{orderNo}
					</if>
					<if test="buyMercName!= null and buyMercName != ''">
						and buyMercName = #{buyMercName}
					</if>
					<if test="buyMercId!= null">
						and buyMercId = #{buyMercId}
					</if>
					<if test="actMercName!= null and actMercName != ''">
						and actMercName = #{actMercName}
					</if>
					<if test="actMercId!= null">
						and actMercId = #{actMercId}
					</if>
					<if test="status!= null and status != ''">
						and status = #{status}
					</if>
					<if test="createTime!= null">
						and createTime = #{createTime}
					</if>
				 </where>
			order by id desc  limit #{pageSize}  offset  #{offset}  
		</select>

		<select id="queryQrCodePageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
			SELECT count(*) from tb_pluss_qr_code
			<where>
				delFlag = '1'
				<if test="id!= null">
					and id = #{id}
				</if>
				<if test="qrNo!= null and qrNo != ''">
					and qrNo = #{qrNo}
				</if>
				<if test="orderNo!= null and orderNo != ''">
					and orderNo = #{orderNo}
				</if>
				<if test="buyMercName!= null and buyMercName != ''">
					and buyMercName = #{buyMercName}
				</if>
				<if test="buyMercId!= null">
					and buyMercId = #{buyMercId}
				</if>
				<if test="actMercName!= null and actMercName != ''">
					and actMercName = #{actMercName}
				</if>
				<if test="actMercId!= null">
					and actMercId = #{actMercId}
				</if>
				<if test="status!= null and status != ''">
					and status = #{status}
				</if>
				<if test="createTime!= null">
					and createTime = #{createTime}
				</if>
			</where>
		</select>

	<delete id="deleteQrCodeByIds">
		delete from tb_pluss_qr_code where id in
		<foreach collection="array" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
	</delete>

	<select id="checkQrNo" parameterType="java.util.List" resultType="java.lang.Integer">
		select count(1) from tb_pluss_qr_code where qrNo in
		<foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
			#{item}
		</foreach>
	</select>
</mapper>
