<?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.wsyy.mapper.WsyyMapper">

    <resultMap type="Wsyy" id="WsyyResult">
        <result property="wsyyId" column="wsyy_id"/>
        <result property="type" column="type"/>
        <result property="site" column="site"/>
        <result property="address" column="address"/>
        <result property="entName" column="ent_name"/>
        <result property="businessType" column="business_type"/>
        <result property="applyType" column="apply_type"/>
        <result property="idNum" column="id_num"/>
        <result property="phongNum" column="phong_num"/>
        <result property="agcy" column="agcy"/>
        <result property="bookedDay" column="booked_day"/>
        <result property="bookedTime" column="booked_time"/>
        <result property="applyForName" column="apply_for_name"/>
        <result property="businessBelongs" column="business_belongs"/>
        <result property="submitTime" column="submit_time"/>
    </resultMap>

    <sql id="selectWsyyVo">
        select wsyy_id, type, site, address, ent_name, business_type, apply_type, id_num, phong_num, agcy, booked_day,booked_time, apply_for_name, business_belongs, submit_time from wsyy
    </sql>

    <select id="selectWsyyList" parameterType="Wsyy" resultMap="WsyyResult">
        <include refid="selectWsyyVo"/>
        <where>
            <if test="type != null ">and type = #{type}</if>
            <if test="site != null  and site != ''">and site = #{site}</if>
            <if test="address != null  and address != ''">and address = #{address}</if>
            <if test="entName != null  and entName != ''">and ent_name like concat('%', #{entName}, '%')</if>
            <if test="businessType != null ">and business_type = #{businessType}</if>
            <if test="applyType != null ">and apply_type = #{applyType}</if>
            <if test="idNum != null  and idNum != ''">and id_num = #{idNum}</if>
            <if test="phongNum != null  and phongNum != ''">and phong_num = #{phongNum}</if>
            <if test="agcy != null  and agcy != ''">and agcy like concat('%', #{agcy}, '%')</if>
            <if test="bookedDay != null">and booked_day = #{bookedDay}</if>
            <if test="bookedTime != null  and bookedTime != ''">and booked_time = #{bookedTime}</if>
            <if test="applyForName != null  and applyForName != ''">and apply_for_name like concat('%',
                #{applyForName},'%')
            </if>
            <if test="businessBelongs != null  and businessBelongs != ''">and business_belongs = #{businessBelongs}</if>
            <if test="submitTime != null ">and submit_time = #{submitTime}</if>
        </where>
    </select>

    <select id="selectWsyyListExcel" parameterType="Wsyy" resultMap="WsyyResult">
        select wsyy_id, type, site, address, ent_name, business_type, apply_type, id_num, phong_num, agcy,
        booked_day,(select time_quantum from wsyy_quantum where wsyy_quantum_id = booked_time) as booked_time,
        apply_for_name, business_belongs, submit_time from wsyy
        <where>
            <if test="type != null ">and type = #{type}</if>
            <if test="site != null  and site != ''">and site = #{site}</if>
            <if test="address != null  and address != ''">and address = #{address}</if>
            <if test="entName != null  and entName != ''">and ent_name like concat('%', #{entName}, '%')</if>
            <if test="businessType != null ">and business_type = #{businessType}</if>
            <if test="applyType != null ">and apply_type = #{applyType}</if>
            <if test="idNum != null  and idNum != ''">and id_num = #{idNum}</if>
            <if test="phongNum != null  and phongNum != ''">and phong_num = #{phongNum}</if>
            <if test="agcy != null  and agcy != ''">and agcy like concat('%', #{agcy}, '%')</if>
            <if test="bookedDay != null">and booked_day = #{bookedDay}</if>
            <if test="bookedTime != null  and bookedTime != ''">and booked_time = #{bookedTime}</if>
            <if test="applyForName != null  and applyForName != ''">and apply_for_name like concat('%',
                #{applyForName},'%')
            </if>
            <if test="businessBelongs != null  and businessBelongs != ''">and business_belongs = #{businessBelongs}</if>
            <if test="submitTime != null ">and submit_time = #{submitTime}</if>
        </where>
    </select>

    <insert id="insertWsyy" parameterType="Wsyy">
        INSERT INTO wsyy (
        wsyy_id,
        type,
        site,
        address,
        ent_name,
        business_type,
        apply_type,
        id_num,
        phong_num,
        agcy,
        booked_day,
        booked_time,
        apply_for_name,
        business_belongs,
        submit_time
        )VALUES(
        #{wsyy.wsyyId},
        #{wsyy.type},
        #{wsyy.site},
        #{wsyy.address},
        #{wsyy.entName},
        #{wsyy.businessType},
        #{wsyy.applyType},
        #{wsyy.idNum},
        #{wsyy.phongNum},
        #{wsyy.agcy},
        #{wsyy.bookedDay},
        #{wsyy.bookedTime},
        #{wsyy.applyForName},
        #{wsyy.businessBelongs},
        #{wsyy.submitTime}
        );
    </insert>

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