<?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">
<!--suppress ALL -->
<mapper namespace="com.xhpc.card.mapper.XhpcMessageBoardReceiveUserMapper">
    <resultMap id="BaseResultMap" type="com.xhpc.card.pojo.XhpcMessageBoardReceiveUser">
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <result column="tenant_type" jdbcType="INTEGER" property="tenantType"/>
        <result column="sender_account" jdbcType="VARCHAR" property="senderAccount"/>
        <result column="sender_type" jdbcType="INTEGER" property="senderType"/>
        <result column="user_icon" jdbcType="VARCHAR" property="userIcon"/>
        <result column="have_new_info" jdbcType="BOOLEAN" property="haveNewInfo"/>
        <result column="del_flag" jdbcType="BOOLEAN" property="delFlag"/>
    </resultMap>
    <sql id="Base_Column_List">
        tenant_id
        ,
    tenant_type,
    sender_account,
    sender_type,
    user_icon,
    have_new_info,
    del_flag
    </sql>
    <insert id="insert" parameterType="com.xhpc.card.pojo.XhpcMessageBoardReceiveUser">
        insert into xhpc_message_board_receive_user (tenant_id, tenant_type, sender_account,
                                                     sender_type, user_icon, have_new_info,
                                                     del_flag)
        values (#{tenantId,jdbcType=VARCHAR}, #{tenantType,jdbcType=INTEGER}, #{senderAccount,jdbcType=VARCHAR},
                #{senderType,jdbcType=INTEGER}, #{userIcon,jdbcType=VARCHAR}, #{haveNewInfo,jdbcType=BOOLEAN},
                #{delFlag,jdbcType=BOOLEAN})
    </insert>
    <insert id="insertSelective" parameterType="com.xhpc.card.pojo.XhpcMessageBoardReceiveUser">
        insert into xhpc_message_board_receive_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">
                tenant_id,
            </if>
            <if test="tenantType != null">
                tenant_type,
            </if>
            <if test="senderAccount != null">
                sender_account,
            </if>
            <if test="senderType != null">
                sender_type,
            </if>
            <if test="userIcon != null">
                user_icon,
            </if>
            <if test="haveNewInfo != null">
                have_new_info,
            </if>
            <if test="delFlag != null">
                del_flag,
            </if>
                new_info_time,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">
                #{tenantId,jdbcType=VARCHAR},
            </if>
            <if test="tenantType != null">
                #{tenantType,jdbcType=INTEGER},
            </if>
            <if test="senderAccount != null">
                #{senderAccount,jdbcType=VARCHAR},
            </if>
            <if test="senderType != null">
                #{senderType,jdbcType=INTEGER},
            </if>
            <if test="userIcon != null">
                #{userIcon,jdbcType=VARCHAR},
            </if>
            <if test="haveNewInfo != null">
                #{haveNewInfo,jdbcType=BOOLEAN},
            </if>
            <if test="delFlag != null">
                #{delFlag,jdbcType=BOOLEAN},
            </if>
            now(),
        </trim>
    </insert>
    <update id="updateHaveNewInfoFiledByUserCondition">
        UPDATE xhpc_message_board_receive_user
        SET have_new_info = 0,
            new_info_time = now()
        WHERE tenant_type = #{tenantType}
          AND tenant_id = #{tenantId}
          AND sender_account = #{senderAccount}
          AND sender_type = #{senderType}
    </update>
    <update id="updateHaveNewInfoIsNull">
        UPDATE xhpc_message_board_receive_user
        SET have_new_info = null
        WHERE tenant_type = #{tenantType}
          AND tenant_id = #{tenantId}
          AND sender_account = #{senderAccount}
          AND sender_type = #{senderType}
          AND del_flag IS NULL;
    </update>
    <update id="updateDelFlag">
        UPDATE xhpc_message_board_receive_user
        SET del_flag = 0
        WHERE tenant_type = #{tenantType}
          AND tenant_id = #{tenantId}
          AND sender_account = #{senderAccount}
          AND sender_type = #{senderType}
    </update>
    <update id="setDelFlag">
        UPDATE xhpc_message_board_receive_user
        SET del_flag = null
        WHERE tenant_type = #{tenantType}
          AND tenant_id = #{tenantId}
          AND sender_account = #{senderAccount}
          AND sender_type = #{senderType}
    </update>
    <select id="findOneByCondition" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        xhpc_message_board_receive_user
        WHERE
        tenant_id = #{tenantId}
        AND tenant_type = #{tenantType}
        AND sender_account = #{senderAccount}
        AND sender_type = #{senderType}
    </select>
    <select id="findAllBy" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        `xhpc_message_board_receive_user`
        WHERE
        tenant_id = #{tenantId}
        AND tenant_type = #{tenantType}
        AND del_flag IS NULL
        <if test="userType!=null and userType!=''">
            AND sender_type = #{userType}
        </if>
        <if test="senderAccount!=null and senderAccount!=''">
            AND sender_account = #{senderAccount}
        </if>
        ORDER BY new_info_time desc,have_new_info DESC
        LIMIT #{currentPage},#{items}
    </select>
    <select id="totalUserNumber" resultType="java.lang.Long">
        SELECT count(tenant_id)
        FROM `xhpc_message_board_receive_user`
        WHERE tenant_id = #{tenantId}
        AND tenant_type = #{tenantType}
        AND del_flag IS NULL
        <if test="userType!=null and userType!=''">
            AND sender_type = #{userType}
        </if>
        <if test="senderAccount!=null and senderAccount!=''">
            AND sender_account = #{senderAccount}
        </if>
    </select>
</mapper>