<?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.willalp.yiqing.mapper.HsYiqingUserMapper">

    <resultMap type="com.willalp.yiqing.domain.HsYiqingUser" id="HsYiqingUserResult">
        <result property="id" column="id"/>
        <result property="userNo" column="user_no"/>
        <result property="userName" column="user_name"/>
        <result property="orgNo" column="org_no"/>
        <result property="orgName" column="org_name"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectHsYiqingUserVo">
        select id, user_no, user_name, org_no, org_name, is_delete, create_by, create_time, update_by, update_time, remark        from hs_yiqing_user
    </sql>


    <select id="selectHsYiqingUserList" parameterType="HsYiqingUser" resultMap="HsYiqingUserResult">
        <include refid="selectHsYiqingUserVo"/>
        <where>
            is_delete = 0
            <if test="userNo != null  and userNo != ''">
                and user_no = #{userNo}
            </if>
            <if test="userName != null  and userName != ''">
                and user_name like concat('%', #{userName}, '%')
            </if>
            <if test="orgNo != null  and orgNo != ''">
                and org_no = #{orgNo}
            </if>
            <if test="orgName != null  and orgName != ''">
                and org_name like concat('%', #{orgName}, '%')
            </if>
            <if test="isDelete != null ">
                and is_delete = #{isDelete}
            </if>
        </where>
    </select>

    <select id="selectQueResultList" resultType="com.willalp.yiqing.domain.vo.QueResultVo">
        SELECT * from user_que_result_view
        where yqUserNo = #{userNo}
    </select>

    <update id="updateRegistrationInformationView">
        DROP VIEW user_que_result_view;
        CREATE VIEW user_que_result_view AS SELECT
            hyq.id id,
        	hyq.que_result_no queResultNo,
        	hyq.que_text_or_pid queText,
        	hyuqr.que_result_text queResultText,
        	hyu.user_no yqUserNo
        FROM
        	hs_yiqing_user_que_result AS hyuqr,
        	hs_yiqing_user AS hyu,
        	hs_yiqing_question AS hyq
        WHERE
        	hyuqr.yq_user_id = hyu.id
        AND hyuqr.yq_que_id = hyq.id
        AND hyuqr.is_delete = 0;
    </update>

</mapper>
