<?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.fjs.scenic.mapper.user.UserMapper">
	<resultMap id="BaseResultMap" type="com.fjs.scenic.entity.user.User">
		<id column="id" jdbcType="INTEGER" property="id" javaType="java.lang.Integer" />
		<result column="nick_name" jdbcType="VARCHAR" property="nickName" javaType="java.lang.String" />
		<result column="phone" jdbcType="VARCHAR" property="phone" javaType="java.lang.String" />
		<result column="head_pic" jdbcType="VARCHAR" property="headPic" javaType="java.lang.String" />
		<result column="sex" jdbcType="TINYINT" property="sex" javaType="java.lang.String"  />
		<result column="status" jdbcType="TINYINT" property="status" javaType="java.lang.String" />
		<result column="create_time" jdbcType="TIMESTAMP" property="createTime" javaType="java.util.Date" />
		<result column="uodate_time" jdbcType="TIMESTAMP" property="uodateTime" javaType="java.util.Date" />
		<result column="openid" jdbcType="VARCHAR" property="openid" javaType="java.lang.String" />
	</resultMap>
	<sql id="Base_Column_List">
		id, nick_name, phone, head_pic, sex, status, create_time, uodate_time,
		openid
	</sql>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap"
		parameterType="java.lang.Integer">
		select
		<include refid="Base_Column_List" />
		from user
		where id = #{id,jdbcType=INTEGER}
	</select>
	
	<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
		delete from user
		where id = #{id,jdbcType=INTEGER}
	</delete>
	<insert id="insert" parameterType="com.fjs.scenic.entity.user.User">
		insert into user (id, nick_name, phone,
		head_pic, sex, status,
		create_time, uodate_time, openid
		)
		values (#{id,jdbcType=INTEGER}, #{nickName,jdbcType=VARCHAR},
		#{phone,jdbcType=VARCHAR},
		#{headPic,jdbcType=VARCHAR}, #{sex,jdbcType=TINYINT}, #{status,jdbcType=TINYINT},
		#{createTime,jdbcType=TIMESTAMP}, #{uodateTime,jdbcType=TIMESTAMP},
		#{openid,jdbcType=VARCHAR}
		)
	</insert>
	<insert id="insertSelective" parameterType="com.fjs.scenic.entity.user.User" useGeneratedKeys="true" keyProperty="id">
		insert into user
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="id != null">
				id,
			</if>
			<if test="nickName != null">
				nick_name,
			</if>
			<if test="phone != null">
				phone,
			</if>
			<if test="headPic != null">
				head_pic,
			</if>
			<if test="sex != null">
				sex,
			</if>
			<if test="status != null">
				status,
			</if>
			<if test="createTime != null">
				create_time,
			</if>
			<if test="uodateTime != null">
				uodate_time,
			</if>
			<if test="openid != null">
				openid,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="id != null">
				#{id,jdbcType=INTEGER},
			</if>
			<if test="nickName != null">
				#{nickName,jdbcType=VARCHAR},
			</if>
			<if test="phone != null">
				#{phone,jdbcType=VARCHAR},
			</if>
			<if test="headPic != null">
				#{headPic,jdbcType=VARCHAR},
			</if>
			<if test="sex != null">
				#{sex,jdbcType=TINYINT},
			</if>
			<if test="status != null">
				#{status,jdbcType=TINYINT},
			</if>
			<if test="createTime != null">
				#{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="uodateTime != null">
				#{uodateTime,jdbcType=TIMESTAMP},
			</if>
			<if test="openid != null">
				#{openid,jdbcType=VARCHAR},
			</if>
		</trim>
	</insert>
	<update id="updateByPrimaryKeySelective" parameterType="com.fjs.scenic.entity.user.User">
		update user
		<set>
			<if test="nickName != null">
				nick_name = #{nickName,jdbcType=VARCHAR},
			</if>
			<if test="phone != null">
				phone = #{phone,jdbcType=VARCHAR},
			</if>
			<if test="headPic != null">
				head_pic = #{headPic,jdbcType=VARCHAR},
			</if>
			<if test="sex != null">
				sex = #{sex,jdbcType=TINYINT},
			</if>
			<if test="status != null">
				status = #{status,jdbcType=TINYINT},
			</if>
			<if test="createTime != null">
				create_time = #{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="uodateTime != null">
				uodate_time = #{uodateTime,jdbcType=TIMESTAMP},
			</if>
			<if test="openid != null">
				openid = #{openid,jdbcType=VARCHAR},
			</if>
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>

	<delete id="delete" parameterType="com.fjs.scenic.entity.user.User">
		delete from user where 1=1
		<if test="id != null"> and id = #{id}</if>
		<if test="nickName != null">
			and nick_name = #{nickName,jdbcType=VARCHAR}
		</if>
		<if test="phone != null">
			and phone = #{phone,jdbcType=VARCHAR}
		</if>
		<if test="headPic != null">
			and head_pic = #{headPic,jdbcType=VARCHAR}
		</if>
		<if test="sex != null">
			and sex = #{sex,jdbcType=TINYINT}
		</if>
		<if test="status != null">
			and status = #{status,jdbcType=TINYINT}
		</if>
		<if test="createTime != null">
			and create_time = #{createTime,jdbcType=TIMESTAMP}
		</if>
		<if test="uodateTime != null">
			and uodate_time = #{uodateTime,jdbcType=TIMESTAMP}
		</if>
		<if test="openid != null">
			and openid = #{openid,jdbcType=VARCHAR}
		</if>
	</delete>

	<select id="select" resultMap="BaseResultMap" parameterType="com.fjs.scenic.entity.user.User">
		select * from user where 1 = 1
		<if test="id != null"> and id = #{id}</if>
		<if test="nickName != null">
			and nick_name like CONCAT(CONCAT('%', #{nickName,jdbcType=VARCHAR}),
			'%')
		</if>
		<if test="phone != null">
			and phone like CONCAT(CONCAT('%', #{phone,jdbcType=VARCHAR}), '%')
		</if>
		<if test="headPic != null">
			and head_pic = #{headPic,jdbcType=VARCHAR}
		</if>
		<if test="sex != null">
			and sex = #{sex,jdbcType=TINYINT}
		</if>
		<if test="status != null">
			and status = #{status,jdbcType=TINYINT}
		</if>
		<if test="createTime != null">
			and create_time = #{createTime,jdbcType=TIMESTAMP}
		</if>
		<if test="uodateTime != null">
			and uodate_time = #{uodateTime,jdbcType=TIMESTAMP}
		</if>
		<if test="openid != null">
			and openid = #{openid,jdbcType=VARCHAR}
		</if>
	</select>

	<select id="selectByParam" resultMap="BaseResultMap"
		parameterType="java.util.Map">
		select
		<if test="field != null and field != ''"> ${field}</if>
		<if test="field == null or field == ''"> * </if>
		from user
		<if test="param != null and param != ''">where ${param}</if>
	</select>

	<delete id="deleteByParam" parameterType="java.util.Map">
		delete from user
		<if test="param != null and param != ''">where ${param}</if>
	</delete>

	<update id="updateByParam" parameterType="java.util.Map">
		<if test="param != null and param !=''">update user set ${param}</if>
	</update>

	<update id="updateByPrimaryKey" parameterType="com.fjs.scenic.entity.user.User">
		update user
		set nick_name = #{nickName,jdbcType=VARCHAR},
		phone = #{phone,jdbcType=VARCHAR},
		head_pic = #{headPic,jdbcType=VARCHAR},
		sex = #{sex,jdbcType=TINYINT},
		status = #{status,jdbcType=TINYINT},
		create_time = #{createTime,jdbcType=TIMESTAMP},
		uodate_time = #{uodateTime,jdbcType=TIMESTAMP},
		openid = #{openid,jdbcType=VARCHAR}
		where id = #{id,jdbcType=INTEGER}
	</update>

	<!--自定义sql -->
	<select id="selectAll" resultMap="BaseResultMap" parameterType="java.lang.Integer">
		select
		<include refid="Base_Column_List" />
		from user
		<where>
			<if test="nickName != null">
				AND nick_name like CONCAT('%',#{nickName},'%')
			</if>
		</where>
	</select>
	
	<select id="getUserByOpenId" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from user where openid = #{openid,jdbcType=VARCHAR}
	</select>
	
	<select id="getOpenIdByOrderNo" resultType="java.lang.String">
	SELECT openid FROM `user` WHERE id = (SELECT user_id FROM orders WHERE order_no=#{orderNo,jdbcType=VARCHAR})
	</select>
	
</mapper>