<?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.MerchantAddressMapper">

	   	<insert id="saveMerchantAddress" parameterType="cn.pluss.platform.entity.MerchantAddress">
        	insert into tb_pluss_merchant_address(userId,merchantCode,provinces,address,linkPhone,linkName,isDefault,createDt)VALUES(#{userId},#{merchantCode},#{provinces},#{address},#{linkPhone},#{linkName},#{isDefault},now())
    	</insert>

	   	<insert id="saveMerchantAddressBatch">
        	insert into tb_pluss_merchant_address(userId,merchantCode,provinces,address,linkPhone,linkName,isDefault,createDt) VALUES 
    			<foreach collection="list" item="item" index="index" separator=",">
			(#{userId},#{merchantCode},#{provinces},#{address},#{linkPhone},#{linkName},#{isDefault},#{createDt}		)
				</foreach>
    	</insert>

		<select id="queryMerchantAddress" parameterType="cn.pluss.platform.entity.MerchantAddress" resultType="cn.pluss.platform.entity.MerchantAddress">
			SELECT * from tb_pluss_merchant_address 
				<where> 
					<if test="id!= null"> 
					 	and id = #{id}
					 </if> 
					<if test="userId!= null"> 
					 	and userId = #{userId}
					 </if> 
					<if test="merchantCode!= null"> 
					 	and merchantCode = #{merchantCode}
					 </if> 
					<if test="provinces!= null"> 
					 	and provinces = #{provinces}
					 </if> 
					<if test="address!= null"> 
					 	and address = #{address}
					 </if> 
					<if test="linkPhone!= null"> 
					 	and linkPhone = #{linkPhone}
					 </if> 
					<if test="linkName!= null"> 
					 	and linkName = #{linkName}
					 </if> 
					<if test="isDefault!= null"> 
					 	and isDefault = #{isDefault}
					 </if> 
					<if test="createDt!= null"> 
					 	and createDt = #{createDt}
					 </if> 
				 </where> 
		</select>

		<select id="queryMerchantAddressList" parameterType="cn.pluss.platform.entity.MerchantAddress" resultType="cn.pluss.platform.entity.MerchantAddress">
			SELECT * from tb_pluss_merchant_address 
				<where> 
					<if test="id!= null"> 
					 and 	id = #{id}
					 </if> 
					<if test="userId!= null"> 
					 and 	userId = #{userId}
					 </if> 
					<if test="merchantCode!= null"> 
					 and 	merchantCode = #{merchantCode}
					 </if> 
					<if test="provinces!= null"> 
					 and 	provinces = #{provinces}
					 </if> 
					<if test="address!= null"> 
					 and 	address = #{address}
					 </if> 
					<if test="linkPhone!= null"> 
					 and 	linkPhone = #{linkPhone}
					 </if> 
					<if test="linkName!= null"> 
					 and 	linkName = #{linkName}
					 </if> 
					<if test="isDefault!= null"> 
					 and 	isDefault = #{isDefault}
					 </if> 
					<if test="createDt!= null"> 
					 and 	createDt = #{createDt}
					 </if> 
				 </where> 
		</select>

		<update id="updateMerchantAddress" parameterType="cn.pluss.platform.entity.MerchantAddress" >
			update tb_pluss_merchant_address 
				  <set> 
					<if test="userId!= null"> 
					 	userId = #{userId},
					 </if> 
					<if test="merchantCode!= null"> 
					 	merchantCode = #{merchantCode},
					 </if> 
					<if test="provinces!= null"> 
					 	provinces = #{provinces},
					 </if> 
					<if test="address!= null"> 
					 	address = #{address},
					 </if> 
					<if test="linkPhone!= null"> 
					 	linkPhone = #{linkPhone},
					 </if> 
					<if test="linkName!= null"> 
					 	linkName = #{linkName},
					 </if> 
					<if test="isDefault!= null"> 
					 	isDefault = #{isDefault},
					 </if> 
					<if test="createDt!= null"> 
					 	createDt = #{createDt}
					 </if> 
				</set>
			where id=#{id} 
		</update>

		<delete id="deleteMerchantAddress" parameterType="cn.pluss.platform.entity.MerchantAddress" >
			DELETE FROM tb_pluss_merchant_address where id=#{id}
		</delete>

		<select id="queryMerchantAddressPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.MerchantAddress">
			SELECT * from tb_pluss_merchant_address 
				<where> 
					<if test="id!= null"> 
					and id = #{id}
					 </if> 
					<if test="userId!= null"> 
					and userId = #{userId}
					 </if> 
					<if test="merchantCode!= null"> 
					and merchantCode = #{merchantCode}
					 </if> 
					<if test="provinces!= null"> 
					and provinces = #{provinces}
					 </if> 
					<if test="address!= null"> 
					and address = #{address}
					 </if> 
					<if test="linkPhone!= null"> 
					and linkPhone = #{linkPhone}
					 </if> 
					<if test="linkName!= null"> 
					and linkName = #{linkName}
					 </if> 
					<if test="isDefault!= null"> 
					and isDefault = #{isDefault}
					 </if> 
					<if test="createDt!= null"> 
					and createDt = #{createDt}
					 </if> 
				 </where> 
			order by id desc  limit #{pageSize}  offset  #{offset}  
		</select>

		<select id="queryMerchantAddressPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
			SELECT count(*) from tb_pluss_merchant_address 
					<where> 
					<if test="id!= null"> 
					 and id = #{id}
					 </if> 
					<if test="userId!= null"> 
					 and userId = #{userId}
					 </if> 
					<if test="merchantCode!= null"> 
					 and merchantCode = #{merchantCode}
					 </if> 
					<if test="provinces!= null"> 
					 and provinces = #{provinces}
					 </if> 
					<if test="address!= null"> 
					 and address = #{address}
					 </if> 
					<if test="linkPhone!= null"> 
					 and linkPhone = #{linkPhone}
					 </if> 
					<if test="linkName!= null"> 
					 and linkName = #{linkName}
					 </if> 
					<if test="isDefault!= null"> 
					 and isDefault = #{isDefault}
					 </if> 
					<if test="createDt!= null"> 
					 and createDt = #{createDt}
					 </if> 
				</where>
		</select>

</mapper>
