<?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.jeeplus.modules.pushinfo.dao.PushinfoDao">
    
	<sql id="pushinfoColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.title AS "title",
		a.content AS "content",
		a.type AS "type",
		a.status AS "status",
		a.push_id AS "pushId",
		a.user_id AS "userId",
		a.push_user_id AS "pushUserId",
		a.parent_type AS "parentType",
		a.addcontent AS "addcontent",
		a.mobile AS "mobile",
		a.company_id AS "companyId"
	</sql>
	
	<sql id="pushinfoJoins">
	</sql>
	
    
	<select id="get" resultType="Pushinfo" >
		SELECT 
			<include refid="pushinfoColumns"/>
		FROM sys_push_info a
		<include refid="pushinfoJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="getByPushId" resultType="Pushinfo" >
		SELECT
			<include refid="pushinfoColumns"/>
		FROM sys_push_info a
		<include refid="pushinfoJoins"/>
        WHERE 1=1
          <if test="pushId != null and pushId != ''">
            AND a.push_id = #{pushId}
          </if>
	</select>

	<select id="findList" resultType="Pushinfo" >
		SELECT 
			<include refid="pushinfoColumns"/>
		FROM sys_push_info a
		<include refid="pushinfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
            <if test="type != null and type != ''">
                AND a.type = #{type}
            </if>
            <if test="status != null and status != ''">
                AND a.status = #{status}
            </if>
            <if test="pushId != null and pushId != ''">
                AND a.push_id = #{pushId}
            </if>
            <if test="userId != null and userId != ''">
                AND a.user_id = #{userId}
            </if>
            <if test="companyId != null and companyId != ''">
                AND a.company_id = #{companyId}
            </if>
            <if test="parentType != null and parentType != ''">
                AND a.parent_type like
                <if test="dbName == 'oracle'">'%'||#{parentType}||'%'</if>
                <if test="dbName == 'mysql'">CONCAT('%', #{parentType}, '%')</if>
            </if>
            <if test="pushUserId != null and pushUserId != ''">
                AND a.push_user_id like
                <if test="dbName == 'oracle'">'%'||#{pushUserId}||'%'</if>
                <if test="dbName == 'mysql'">CONCAT('%', #{pushUserId}, '%')</if>
            </if>
            <if test="addcontent != null and addcontent != ''">
                AND a.addcontent like
                <if test="dbName == 'oracle'">'%'||#{addcontent}||'%'</if>
                <if test="dbName == 'mysql'">CONCAT('%', #{addcontent}, '%')</if>
            </if>
            <if test="mobile != null and mobile != ''">
                AND a.mobile like
                <if test="dbName == 'oracle'">'%'||#{mobile}||'%'</if>
                <if test="dbName == 'mysql'">CONCAT('%', #{mobile}, '%')</if>
            </if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<update id="updateDelflagByPushId">
		UPDATE sys_push_info
		SET del_flag = #{delFlag}
		WHERE push_id = #{pushId}
	</update>
	<update id="updateStatusByPushId">
		UPDATE sys_push_info
		SET status = #{status}
		WHERE push_id = #{pushId}
	</update>

	<!-- start 查新推送信息  -->
	<select id="findPushList" resultType="Pushinfo" >
		SELECT
		<include refid="pushinfoColumns"/>
		FROM sys_push_info a
		<include refid="pushinfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="type != null and type != ''">
				AND a.type = #{type}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
			<if test="pushId != null and pushId != ''">
				AND a.push_id = #{pushId}
			</if>
			<if test="userId != null and userId != ''">
				AND a.user_id = #{userId}
			</if>
			<if test="companyId != null and companyId != ''">
				AND a.company_id = #{companyId}
			</if>
			<if test="parentType != null and parentType != ''">
				AND a.parent_type like
				<if test="dbName == 'oracle'">'%'||#{parentType}||'%'</if>
				<if test="dbName == 'mysql'">CONCAT('%', #{parentType}, '%')</if>
			</if>
			<if test="pushUserId != null and pushUserId != ''">
				AND a.push_user_id like
				<if test="dbName == 'oracle'">'%'||#{pushUserId}||'%'</if>
				<if test="dbName == 'mysql'">CONCAT('%', #{pushUserId}, '%')</if>
			</if>
			<if test="addcontent != null and addcontent != ''">
				AND a.addcontent like
				<if test="dbName == 'oracle'">'%'||#{addcontent}||'%'</if>
				<if test="dbName == 'mysql'">CONCAT('%', #{addcontent}, '%')</if>
			</if>
			<if test="mobile != null and mobile != ''">
				AND a.mobile like
				<if test="dbName == 'oracle'">'%'||#{mobile}||'%'</if>
				<if test="dbName == 'mysql'">CONCAT('%', #{mobile}, '%')</if>
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.create_date DESC
			</otherwise>
		</choose>
	</select>
	<!--查新推送信息 end -->


	<select id="findAllList" resultType="Pushinfo" >
		SELECT 
			<include refid="pushinfoColumns"/>
		FROM sys_push_info a
		<include refid="pushinfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO sys_push_info(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			title,
			content,
			type,
			push_id,
			user_id,
			push_user_id,
			status,
			addcontent,
			company_id,
			mobile,
			parent_type
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{title},
			#{content},
			#{type},
			#{pushId},
			#{userId},
			#{pushUserId},
			#{status},
			#{addcontent},
			#{companyId},
			#{mobile},
			#{parentType}
		)
	</insert>
	
	<update id="update">
		UPDATE sys_push_info SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			title = #{title},
			content = #{content},
			type = #{type},
			push_id = #{pushId},
			user_id = #{userId},
			push_user_id = #{pushUserId},
			status = #{status},
			addcontent = #{addcontent},
			company_id = #{companyId},
			mobile = #{mobile},
			parent_type = #{parentType}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM sys_push_info
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE sys_push_info SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="Pushinfo" statementType="STATEMENT">
		select * FROM sys_push_info  where ${propertyName} = '${value}'
	</select>
	
</mapper>