<?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.HsYiqingRegisterMapper">

    <resultMap type="com.willalp.yiqing.domain.HsYiqingRegister" id="HsYiqingRegisterResult">
        <result property="id" column="id"/>
        <result property="userDataId" column="user_data_id"/>
        <result property="registerType" column="register_type"/>
        <result property="sort" column="sort"/>
        <result property="status" column="status"/>
        <result property="isolatedPlace" column="isolated_place"/>
        <result property="rnaResult" column="rna_result"/>
        <result property="antigenResult" column="antigen_result"/>
        <result property="estimatedValue" column="estimated_value"/>
        <result property="registerExplain" column="register_explain"/>
        <result property="belongName" column="belong_name"/>
        <result property="belongPhone" column="belong_phone"/>
        <result property="sendOrdersEnd" column="send_orders_end"/>
        <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>

    <resultMap type="com.willalp.yiqing.domain.vo.RegisterVo" id="RegisterResultVo">
        <result property="id" column="id"/>
        <result property="userName" column="userName"/>
        <result property="userNo" column="userNo"/>
        <result property="attestNo" column="attestNo"/>
        <result property="userDataId" column="user_data_id"/>
        <result property="registerType" column="register_type"/>
        <result property="sort" column="sort"/>
        <result property="status" column="status"/>
        <result property="isolatedPlace" column="isolated_place"/>
        <result property="rnaResult" column="rna_result"/>
        <result property="antigenResult" column="antigen_result"/>
        <result property="estimatedValue" column="estimated_value"/>
        <result property="registerExplain" column="register_explain"/>
        <result property="belongName" column="belong_name"/>
        <result property="belongPhone" column="belong_phone"/>
        <result property="sendOrdersEnd" column="send_orders_end"/>
        <result property="createTime" column="create_time"/>
        <result property="remark" column="remark"/>
    </resultMap>
    <resultMap type="com.willalp.yiqing.domain.vo.RegisterVo2" id="RegisterResultVo2">
        <result property="id" column="id"/>
        <result property="userName" column="userName"/>
        <result property="userNo" column="userNo"/>
        <result property="attestNo" column="attestNo"/>
        <result property="userDataId" column="user_data_id"/>
        <result property="registerType" column="register_type"/>
        <result property="sort" column="sort"/>
        <result property="status" column="status"/>
        <result property="isolatedPlace" column="isolated_place"/>
        <result property="rnaResult" column="rna_result"/>
        <result property="antigenResult" column="antigen_result"/>
        <result property="estimatedValue" column="estimated_value"/>
        <result property="registerExplain" column="register_explain"/>
        <result property="belongName" column="belong_name"/>
        <result property="belongPhone" column="belong_phone"/>
        <result property="sendOrdersEnd" column="send_orders_end"/>
        <result property="createTime" column="create_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectHsYiqingRegisterVo">
        select id,
               user_data_id,
               register_type,
               sort,
               status,
               isolated_place,
               rna_result,
               antigen_result,
               estimated_value,
               register_explain,
               belong_name,
               belong_phone,
               send_orders_end,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from hs_yiqing_register
    </sql>

    <sql id="selectRegisterAndUserVo">
        select id,
               hypcu.user_name as userName,
               hypcu.user_no   as userNo,
               hypcu.attest_no as attestNo,
               register_type,
               sort,
               status,
               isolated_place,
               rna_result,
               antigen_result,
               estimated_value,
               register_explain,
               belong_name,
               belong_phone,
               send_orders_end,
               hyr.create_time,
               hyr.remark
        from hs_yiqing_register hyr,
             hs_yiqing_positive_contiguity_user hypcu
    </sql>
    <sql id="selectNewRegisterAndUserVo">
        select id,
               hypcu.user_name as userName,
               hypcu.user_no   as userNo,
               hypcu.attest_no as attestNo,
               hypcu.other_attest as otherAttest,
               hypcu.phone as phone,
               hypcu.address as address,
               hypcu.house_no as houseNo,
               hypcu.area_name as areaName,
               register_type,
               user_data_id,
               sort,
               status,
               isolated_place,
               rna_result,
               antigen_result,
               estimated_value,
               register_explain,
               belong_name,
               belong_phone,
               send_orders_end,
               max(hyr.create_time) as create_time,
               hyr.remark
        from hs_yiqing_register hyr,
             hs_yiqing_positive_contiguity_user hypcu
    </sql>

    <select id="selectHsYiqingRegisterList" parameterType="RegisterVo2" resultMap="RegisterResultVo2">
        <include refid="selectRegisterAndUserVo"/>
        <where>
            hyr.is_delete = 0 and hypcu.is_delete = 0 and
            hyr.user_data_id = hypcu.data_id
            <if test="userNo != null  and userNo != ''">
                #{userNo}, '%')
            </if>
            <if test="userName != null  and userName != ''">
                and hypcu.user_name like concat('%', #{userName}, '%')
            </if>
            <if test="attestNo != null  and attestNo != ''">
                and hypcu.attest_no like concat('%', #{attestNo}, '%')
            </if>
            <if test="userDataId != null  and userDataId != ''">
                and user_data_id = #{userDataId}
            </if>
            <if test="registerType != null  and registerType != ''">
                and register_type = #{registerType}
            </if>
            <if test="sort != null  and sort != ''">
                and sort = #{sort}
            </if>
            <if test="status != null  and status != ''">
                and status = #{status}
            </if>
            <if test="isolatedPlace != null  and isolatedPlace != ''">
                and isolated_place = #{isolatedPlace}
            </if>
            <if test="rnaResult != null  and rnaResult != ''">
                and rna_result = #{rnaResult}
            </if>
            <if test="antigenResult != null  and antigenResult != ''">
                and antigen_result = #{antigenResult}
            </if>
            <if test="estimatedValue != null  and estimatedValue != ''">
                and estimated_value
            </if>
            <if test="registerExplain != null  and registerExplain != ''">
                and register_explain = #{registerExplain}
            </if>
            <if test="sendOrdersEnd != null ">
                and datediff(send_orders_end, #{sendOrdersEnd})= 0
            </if>
        </where>
    </select>
    <select id="selectNewHsYiqingRegisterList" resultMap="RegisterResultVo">
    <include refid="selectNewRegisterAndUserVo"/>
    <where>
        hyr.is_delete = 0 and
        hyr.user_data_id = hypcu.data_id
        <if test="userNo != null  and userNo != ''">
            and hypcu.user_no like concat('%', #{userNo}, '%')
        </if>
        <if test="userName != null  and userName != ''">
            and hypcu.user_name like concat('%', #{userName}, '%')
        </if>
        <if test="attestNo != null  and attestNo != ''">
            and hypcu.attest_no like concat('%', #{attestNo}, '%')
        </if>
        <if test="userDataId != null  and userDataId != ''">
            and user_data_id = #{userDataId}
        </if>
        <if test="registerType != null  and registerType != ''">
            and register_type = #{registerType}
        </if>
        <if test="sort != null  and sort != ''">
            and sort = #{sort}
        </if>
        <if test="status != null  and status != ''">
            and status = #{status}
        </if>
        <if test="isolatedPlace != null  and isolatedPlace != ''">
            and isolated_place = #{isolatedPlace}
        </if>
        <if test="rnaResult != null  and rnaResult != ''">
            and rna_result = #{rnaResult}
        </if>
        <if test="antigenResult != null  and antigenResult != ''">
            and antigen_result = #{antigenResult}
        </if>
        <if test="estimatedValue != null  and estimatedValue != ''">
            and estimated_value like concat('%', #{estimatedValue}, '%')
        </if>
        <if test="registerExplain != null  and registerExplain != ''">
            and register_explain = #{registerExplain}
        </if>
        <if test="sendOrdersEnd != null ">
            and datediff(send_orders_end, #{sendOrdersEnd})= 0
        </if>
    </where>
        group by user_data_id
    </select>
</mapper>
