<?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.lymsh.yimiao.main.data.dao.YmPushMessagesMapper">

<resultMap id="YmPushMessagesResultMap" type="com.lymsh.yimiao.main.data.model.YmPushMessages">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="content" property="content" jdbcType="VARCHAR" />
<result column="created" property="created" jdbcType="TIMESTAMP" />
<result column="reception_id" property="receptionId" jdbcType="INTEGER" />
<result column="YN" property="yn" jdbcType="INTEGER" />
</resultMap>



<insert id="addYmPushMessages" keyProperty="id" useGeneratedKeys="false" parameterType="com.lymsh.yimiao.main.data.model.YmPushMessages">
 <selectKey resultType="int" keyProperty="id" order="BEFORE">
  SELECT MESSAGE_SEQ.nextval AS id
  FROM dual
 </selectKey>
insert into YM_PUSH_MESSAGES (id,content,created,reception_id,yn) values (#{id,jdbcType=INTEGER},#{content,jdbcType=VARCHAR},#{created,jdbcType=TIMESTAMP},#{receptionId,jdbcType=INTEGER}
 ,#{yn,jdbcType=INTEGER})
</insert>



<update id="updateYmPushMessages" parameterType="com.lymsh.yimiao.main.data.model.YmPushMessages">
update ym_push_messages <set><if test="content != null and content != ''">
 content = #{content,jdbcType=VARCHAR},
</if>
<if test="created != null">
 created = #{created,jdbcType=TIMESTAMP},
</if>
<if test="receptionId != null and receptionId >= 0">
 reception_id = #{receptionId,jdbcType=INTEGER},
</if>
 <if test="yn != null and yn >= 0">
  yn = #{yn,jdbcType=INTEGER},
 </if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>


<delete id="deleteYmPushMessages" parameterType="java.lang.Integer">
delete from ym_push_messages where id = #{id,jdbcType=INTEGER}
</delete>



<select id="getYmPushMessages" resultMap="YmPushMessagesResultMap" parameterType="java.lang.Integer">
select id,content,created,reception_id,yn
 from ym_push_messages where id = #{id,jdbcType=INTEGER}
</select>


<sql id="orderAndLimit">
<if test="sort != null and sort != '' ">
order by ${sort} 
<if test="need != null">
limit #{offset, jdbcType=INTEGER} , #{limit, jdbcType=INTEGER}
</if>
</if>
</sql>



<sql id="YmPushMessagesCondition">
<where>
 1 = 1 
<if test="id != null and id >= 0">
and id = #{id,jdbcType=INTEGER}
</if>
<if test="content != null and content != ''">
and content = #{content,jdbcType=VARCHAR}
</if>
<if test="created != null">
and created = #{created,jdbcType=TIMESTAMP}
</if>
<if test="receptionId != null and receptionId >= 0">
and reception_id = #{receptionId,jdbcType=INTEGER}
</if>
 <if test="yn != null and yn >= 0">
  and yn = #{yn,jdbcType=INTEGER}
 </if>
</where>
</sql>



<select id="queryYmPushMessages" resultMap="YmPushMessagesResultMap" parameterType="com.lymsh.yimiao.main.data.model.YmPushMessagesQuery">
select id,content,created,reception_id,yn
 from ym_push_messages 
<include refid="YmPushMessagesCondition" />
<include refid="orderAndLimit" />
</select>



<select id="queryYmPushMessagesCount" resultType="int" parameterType="com.lymsh.yimiao.main.data.model.YmPushMessagesQuery">
select count(1) from ym_push_messages
<include refid="YmPushMessagesCondition" />
</select>



</mapper>