<?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.yinet.xcqh.mapper.XcqhMapper">

    <resultMap type="Xcqh" id="XcqhResult">
        <result property="xcqhId" column="xcqh_id"/>
        <result property="openid" column="openid"/>
        <result property="guidanceId" column="guidance_id"/>
        <result property="applyForName" column="apply_for_name"/>
        <result property="idNum" column="id_num"/>
        <result property="phongNum" column="phong_num"/>
        <result property="serNum" column="ser_num"/>
        <result property="status" column="status"/>
        <result property="submitTime" column="submit_time"/>
        <result property="windowNum" column="window_num"/>
        <result property="guidanceName" column="guidance_name"/>
    </resultMap>

    <sql id="selectXcqhVo">
        select x.xcqh_id,x.openid,x.guidance_id,x.apply_for_name,x.id_num,x.phong_num,x.ser_num,x.status,x.submit_time,x.window_num,yg.guidance_name from xcqh x LEFT JOIN yyqh_guidance yg on x.guidance_id=yg.yyqh_guidance_id
    </sql>

    <select id="selectXcqhList" parameterType="RegisterUser" resultMap="XcqhResult">
        <include refid="selectXcqhVo"/>
        <where>
            <if test="idNum != null  and idNum != ''">and id_num = #{idNum}</if>
            <if test="phongNum != null  and phongNum != ''">and phong_num = #{phongNum}</if>
            <if test="applyForName != null  and applyForName != ''">and apply_for_name like concat('%',
                #{applyForName},'%')
            </if>
            <if test="serNum != null and serNum != ''">and ser_num like concat('%',
                #{serNum},'%')
            </if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="submitTime != null ">and submit_time = #{submitTime}</if>
        </where>
    </select>

    <insert id="insertXcqh" parameterType="RegisterUser">
        INSERT INTO xcqh (
        xcqh_id,
        openid,
        guidance_id,
        id_num,
        phong_num,
        apply_for_name,
        window_num,
        ser_num,
        status,
        submit_time
        )VALUES(
        #{xcqh.xcqhId},
        #{xcqh.openid},
        #{xcqh.guidanceId},
        #{xcqh.idNum},
        #{xcqh.phongNum},
        #{xcqh.applyForName},
        #{xcqh.windowNum},
        #{xcqh.serNum},
        #{xcqh.status},
        #{xcqh.submitTime}
        );
    </insert>

    <delete id="deleteXcqhByIds" parameterType="String">
        delete from xcqh where xcqh_id in
        <foreach item="xcqhId" collection="array" open="(" separator="," close=")">
            #{xcqhId}
        </foreach>
    </delete>
    <select id="selectXcqhListByIdNum" resultMap="XcqhResult">
        <include refid="selectXcqhVo"/>
        <where>
            id_num = #{idNum} and status = 1
        </where>
        order by submit_time desc
    </select>
</mapper>