<?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.ruoyi.back.mapper.BCustomerQuestionErrorMapper">

    <resultMap type="BCustomerQuestionError" id="BCustomerQuestionErrorResult">
        <result property="id"    column="id"    />
        <result property="customercode"    column="customerCode"    />
        <result property="questionid"    column="questionId"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="createTime"    />
        <result property="status"    column="status"    />
        <association property="user"    column="customerCode" javaType="SysUser" resultMap="SysUserResult" />
    </resultMap>

    <resultMap type="SysUser" id="SysUserResult">
        <id     property="userId"       column="user_id"      />
        <result property="userName"     column="user_name"    />
        <result property="nickName"     column="nick_name"    />
        <result property="phonenumber"  column="phonenumber"  />
    </resultMap>

    <sql id="selectBCustomerQuestionErrorVo">
        select bcqe.id, bcqe.customerCode, bcqe.questionId, bcqe.remark, bcqe.createTime, bcqe.status
             ,u.user_id,u.user_name,u.nick_name,u.phonenumber
        from b_customer_question_error bcqe
        LEFT JOIN sys_user u on bcqe.customerCode=u.user_id
    </sql>

    <select id="selectBCustomerQuestionErrorList" parameterType="BCustomerQuestionError" resultMap="BCustomerQuestionErrorResult">
        <include refid="selectBCustomerQuestionErrorVo"/>
        where 1=1
            <if test="customercode != null  and customercode != ''"> and bcqe.customerCode = #{customercode}</if>
            <if test="questionid != null  and questionid != ''"> and bcqe.questionId like concat('%', #{questionid}, '%')</if>
            <if test="createTime != null "> and bcqe.createTime = #{createTime}</if>
            <if test="status != null "> and bcqe.status = #{status}</if>
        order by id desc
    </select>

    <select id="selectBCustomerQuestionErrorById" parameterType="Long" resultMap="BCustomerQuestionErrorResult">
        <include refid="selectBCustomerQuestionErrorVo"/>
        where id = #{id}
    </select>

    <insert id="insertBCustomerQuestionError" parameterType="BCustomerQuestionError" useGeneratedKeys="true" keyProperty="id">
        insert into b_customer_question_error
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="customercode != null">customerCode,</if>
            <if test="questionid != null">questionId,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="createTime != null">createTime,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="customercode != null">#{customercode},</if>
            <if test="questionid != null">#{questionid},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateBCustomerQuestionError" parameterType="BCustomerQuestionError">
        update b_customer_question_error
        <trim prefix="SET" suffixOverrides=",">
            <if test="customercode != null">customerCode = #{customercode},</if>
            <if test="questionid != null">questionId = #{questionid},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBCustomerQuestionErrorById" parameterType="Long">
        delete from b_customer_question_error where id = #{id}
    </delete>

    <delete id="deleteBCustomerQuestionErrorByIds" parameterType="String">
        delete from b_customer_question_error where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
