<?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.lyms.platform.permission.dao.master.FolviteMapper">
    <resultMap id="folviteResultMap" type="com.lyms.platform.pojo.FolviteRecordModel">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="sex" property="sex"/>
        <result column="birthday" property="birthday"/>
        <result column="nationality" property="nationality"/>
        <result column="nation" property="nation"/>
        <result column="marital_status" property="maritalStatus"/>
        <result column="certificate_type" property="certificateType"/>
        <result column="card_no" property="cardNo"/>
        <result column="census_type" property="censusType"/>
        <result column="live_type" property="liveType"/>
        <result column="education" property="education"/>
        <result column="occupation" property="occupation"/>
        <result column="phone" property="phone"/>
        <result column="work_unit" property="workUnit"/>
        <result column="habitation_province" property="habitationProvince"/>
        <result column="habitation_city" property="habitationCity"/>
        <result column="habitation_area" property="habitationArea"/>
        <result column="habitation_country" property="habitationCountry"/>
        <result column="habitation_address" property="habitationAddress"/>
        <result column="domicile_province" property="domicileProvince"/>
        <result column="domicile_city" property="domicileCity"/>
        <result column="domicile_area" property="domicileArea"/>
        <result column="domicile_country" property="domicileCountry"/>
        <result column="domicile_address" property="domicileAddress"/>
        <result column="woman_id" property="womanId"/>
        <result column="isconceive" property="isconceive"/>
        <result column="lastmenstrual" property="lastmenstrual"/>
        <result column="ispregnancy" property="ispregnancy"/>
        <result column="operation_doctor" property="operationDoctor"/>
        <result column="created" property="created"/>
        <result column="vc_card" property="vcCard"/>
        <result column="hospitalid" property="hospitalId"/>
        <result column="modify" property="modify"/>
        <result column="receivesum" property="receiveSum"/>
        <result column="drawTime" property="drawTime"/>
    </resultMap>
    <select id="queryList" parameterType="com.lyms.platform.permission.model.FolviteQuery" resultMap="folviteResultMap">
        SELECT
        id AS id,
        NAME AS NAME,
        sex AS sex,
        birthday AS birthday,
        nationality AS nationality,
        nation AS nation,
        marital_status AS maritalStatus,
        certificate_type AS certificateType,
        card_no AS cardNo,
        census_type AS censusType,
        live_type AS liveType,
        education AS education,
        occupation AS occupation,
        phone AS phone,
        work_unit AS workUnit,
        habitation_province AS habitationProvince,
        habitation_city AS habitationCity,
        habitation_area AS habitationArea,
        habitation_country AS habitationCountry,
        habitation_address AS habitationAddress,
        domicile_province AS domicileProvince,
        domicile_city AS domicileCity,
        domicile_area AS domicileArea,
        domicile_country AS domicileCountry,
        domicile_address AS domicileAddress,
        woman_id AS womanId,
        isconceive AS isconceive,
        lastmenstrual AS lastmenstrual,
        ispregnancy AS ispregnancy,
        operation_doctor AS operationDoctor,
        created AS created,
        vc_card AS vcCard,
        receivesum as receiveSum,
        hospitalid as hospitalId,
        drawTime as drawTime
        FROM
        lyms_folvite_Info
        <include refid="whereSql"/>
    </select>
    <select id="queryOne" parameterType="java.lang.String" resultMap="folviteResultMap">
        SELECT
        id AS id,
        NAME AS NAME,
        sex AS sex,
        birthday AS birthday,
        nationality AS nationality,
        nation AS nation,
        marital_status AS maritalStatus,
        certificate_type AS certificateType,
        card_no AS cardNo,
        census_type AS censusType,
        live_type AS liveType,
        education AS education,
        occupation AS occupation,
        phone AS phone,
        work_unit AS workUnit,
        habitation_province AS habitationProvince,
        habitation_city AS habitationCity,
        habitation_area AS habitationArea,
        habitation_country AS habitationCountry,
        habitation_address AS habitationAddress,
        domicile_province AS domicileProvince,
        domicile_city AS domicileCity,
        domicile_area AS domicileArea,
        domicile_country AS domicileCountry,
        domicile_address AS domicileAddress,
        woman_id AS womanId,
        isconceive AS isconceive,
        lastmenstrual AS lastmenstrual,
        ispregnancy AS ispregnancy,
        operation_doctor AS operationDoctor,
        created AS created,
        vc_card AS vcCard,
        receivesum as receiveSum,
        hospitalid as hospitalId,
        drawTime as drawTime
        FROM
        lyms_folvite_Info
        where id=#{id}
    </select>
    <select id="queryListMap" parameterType="com.lyms.platform.permission.model.FolviteQuery"
            resultType="map">
        SELECT
        f.`name`,f.card_no,f.phone,p.receive_date,p.receive_number,p.receive_week,p.highrisk,p.provide_unit,f.habitation_address,f.habitation_area,f.habitation_city,
        f.habitation_country,f.habitation_province,p.`issuer`,p.id as id, f.id as folviteId,f.certificate_type
        FROM
        lyms_folvite_provide AS p
        LEFT JOIN
        lyms_folvite_Info f ON p.folvite_id = f.id
        <where>
            1=1
            <if test="yn != null">
              and  p.yn=#{yn}
            </if>
            <if test="queryNo !=null and queryNo != ''">
                and f.name =#{queryNo} or f.card_no=#{queryNo} or f.phone=#{queryNo}
            </if>
            <if test="hospitalId !=null and hospitalId != ''">
                and p.hospitalid =#{hospitalId}
            </if>
            <if test="startReceiveDate != null ">
                AND  <![CDATA[ p.receive_date >= date_format(#{startReceiveDate},'%Y-%m-%d %H:%i:%S')  ]]>
            </if>
            <if test="endReceiveDate != null">
                AND  <![CDATA[ p.receive_date <= date_format(#{endReceiveDate},'%Y-%m-%d %H:%i:%S')  ]]>
            </if>
            <if test="highRisk !=null and highRisk != ''">
                AND p.highrisk=#{highRisk}
            </if>
        </where>
        <include refid="orderAndLimit"/>
    </select>
    <select id="queryListCount" parameterType="com.lyms.platform.permission.model.FolviteQuery"
            resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM
        lyms_folvite_provide AS p
        LEFT JOIN
        lyms_folvite_Info f ON p.folvite_id = f.id
        <where>
            1=1
            <if test="yn != null">
              and   p.yn=#{yn}
            </if>
            <if test="queryNo !=null and queryNo != ''">
                and f.name =#{queryNo} or f.card_no=#{queryNo} or f.phone=#{queryNo}
            </if>
            <if test="hospitalId !=null and hospitalId != ''">
                and p.hospitalid =#{hospitalId}
            </if>
            <if test="startReceiveDate != null ">
                AND  <![CDATA[ p.receive_date >= date_format(#{startReceiveDate},'%Y-%m-%d %H:%i:%S')  ]]>
            </if>
            <if test="endReceiveDate != null">
                AND  <![CDATA[ p.receive_date <= date_format(#{endReceiveDate},'%Y-%m-%d %H:%i:%S')  ]]>
            </if>
            <if test="highRisk !=null and highRisk != ''">
                AND p.highrisk=#{highRisk}
            </if>
        </where>
    </select>
    <select id="queryFolviteListCount" parameterType="com.lyms.platform.permission.model.FolviteQuery"
            resultType="java.lang.Integer">
        select count(id) from lyms_folvite_Info
        <include refid="whereSql"/>
    </select>
    <select id="queryFolviteList" parameterType="com.lyms.platform.permission.model.FolviteQuery"
            resultMap="folviteResultMap">
        SELECT * FROM lyms_folvite_Info
        <include refid="whereSql"/>
        <include refid="orderAndLimit"/>
    </select>
    <insert id="saveFolvite" parameterType="com.lyms.platform.pojo.FolviteRecordModel">
INSERT INTO lyms_folvite_Info(
id,
name,
sex,
birthday,
nationality,
nation,
marital_status,
certificate_type,
card_no,
census_type,
live_type,
education,
occupation,
phone,
work_unit,
habitation_province,
habitation_city,
habitation_area,
habitation_country,
habitation_address,
domicile_province,
domicile_city,
domicile_area,
domicile_country,
domicile_address,
woman_id,
isconceive,
lastmenstrual,
ispregnancy,
operation_doctor,
created,
vc_card,
hospitalid,
receivesum,
modify,
drawTime ) VALUES (
#{id,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR},
#{sex,jdbcType=BIGINT},
#{birthday,jdbcType=TIMESTAMP},
#{nationality,jdbcType=VARCHAR},
#{nation,jdbcType=VARCHAR},
#{maritalStatus,jdbcType=VARCHAR},
#{certificateType,jdbcType=VARCHAR},
#{cardNo,jdbcType=VARCHAR},
#{censusType,jdbcType=VARCHAR},
#{liveType,jdbcType=VARCHAR},
#{education,jdbcType=VARCHAR},
#{occupation,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR},
#{workUnit,jdbcType=VARCHAR},
#{habitationProvince,jdbcType=VARCHAR},
#{habitationCity,jdbcType=VARCHAR},
#{habitationArea,jdbcType=VARCHAR},
#{habitationCountry,jdbcType=VARCHAR},
#{habitationAddress,jdbcType=VARCHAR},
#{domicileProvince,jdbcType=VARCHAR},
#{domicileCity,jdbcType=VARCHAR},
#{domicileArea,jdbcType=VARCHAR},
#{domicileCountry,jdbcType=VARCHAR},
#{domicileAddress,jdbcType=VARCHAR},
#{womanId,jdbcType=VARCHAR},
#{isconceive,jdbcType=BIGINT},
#{lastmenstrual,jdbcType=TIMESTAMP},
#{ispregnancy,jdbcType=BIGINT},
#{operationDoctor,jdbcType=VARCHAR},
#{created,jdbcType=TIMESTAMP},
#{vcCard,jdbcType=VARCHAR},
#{hospitalId,jdbcType=VARCHAR},
#{receiveSum,jdbcType=INTEGER},
#{modify,jdbcType=TIMESTAMP},
#{drawTime,jdbcType=TIMESTAMP})
    </insert>
    <sql id="whereSql">
        <where>
            1=1
            <if test="id != null and id !=''">
                and id=#{id,jdbcType=VARCHAR}
            </if>
            <if test="certificateType != null and certificateType !='' ">
                and certificate_type=#{certificateType,jdbcType=VARCHAR}
            </if>
            <if test="cardNo != null and cardNo!=''">
                and card_no=#{cardNo,jdbcType=VARCHAR}
            </if>
            <if test="vcCard != null and vcCard !=''">
                and vc_card=#{vcCard,jdbcType=VARCHAR}
            </if>
            <if test="hospitalId != null and hospitalId !=''">
                and hospitalid=#{hospitalId,jdbcType=VARCHAR}
            </if>
            <if test="ispregnancy != null">
                and ispregnancy=#{ispregnancy}
            </if>
            <if test="drawTimeStartDate != null">
                and drawTime >= #{drawTimeStartDate}
            </if>
            <if test="drawTimeEndDate != null">
                and drawTime <![CDATA[ <= ]]> #{drawTimeEndDate}
            </if>
        </where>
    </sql>
    <update id="updateFolvite" parameterType="com.lyms.platform.pojo.FolviteRecordModel">
        UPDATE lyms_folvite_Info
        <include refid="columnUpdate"/>
        where id = #{id}
    </update>
    <sql id="columnUpdate">
        <set>
            <if test="name != null">
                name=#{name,jdbcType=VARCHAR},
            </if>
            <if test="sex != null">
                sex=#{sex,jdbcType=BIGINT},
            </if>
            <if test="birthday != null">
                birthday=#{birthday,jdbcType=TIMESTAMP},
            </if>
            <if test="nationality != null">
                nationality=#{nationality,jdbcType=VARCHAR},
            </if>
            <if test="nation != null">
                nation=#{nation,jdbcType=VARCHAR},
            </if>
            <if test="maritalStatus != null">
                marital_status=#{maritalStatus,jdbcType=VARCHAR},
            </if>
            <if test="certificateType != null">
                certificate_type=#{certificateType,jdbcType=VARCHAR},
            </if>
            <if test="cardNo != null">
                card_no=#{cardNo,jdbcType=VARCHAR},
            </if>
            <if test="censusType != null">
                census_type=#{censusType,jdbcType=VARCHAR},
            </if>
            <if test="liveType != null">
                live_type=#{liveType,jdbcType=VARCHAR},
            </if>
            <if test="education != null">
                education=#{education,jdbcType=VARCHAR},
            </if>
            <if test="occupation != null">
                occupation=#{occupation,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                phone=#{phone,jdbcType=VARCHAR},
            </if>
            <if test="workUnit != null">
                work_unit=#{workUnit,jdbcType=VARCHAR},
            </if>
            <if test="habitationProvince != null">
                habitation_province=#{habitationProvince,jdbcType=VARCHAR},
            </if>
            <if test="habitationCity != null">
                habitation_city=#{habitationCity,jdbcType=VARCHAR},
            </if>
            <if test="habitationArea != null">
                habitation_area=#{habitationArea,jdbcType=VARCHAR},
            </if>
            <if test="habitationCountry != null">
                habitation_country=#{habitationCountry,jdbcType=VARCHAR},
            </if>
            <if test="habitationAddress != null">
                habitation_address=#{habitationAddress,jdbcType=VARCHAR},
            </if>
            <if test="domicileProvince != null">
                domicile_province=#{domicileProvince,jdbcType=VARCHAR},
            </if>
            <if test="domicileCity != null">
                domicile_city=#{domicileCity,jdbcType=VARCHAR},
            </if>
            <if test="domicileArea != null">
                domicile_area=#{domicileArea,jdbcType=VARCHAR},
            </if>
            <if test="domicileCountry != null">
                domicile_country=#{domicileCountry,jdbcType=VARCHAR},
            </if>
            <if test="domicileAddress != null">
                domicile_address=#{domicileAddress,jdbcType=VARCHAR},
            </if>
            <if test="womanId != null">
                woman_id=#{womanId,jdbcType=VARCHAR},
            </if>
            <if test="isconceive != null">
                isconceive=#{isconceive,jdbcType=BIGINT},
            </if>
            <if test="lastmenstrual != null">
                lastmenstrual=#{lastmenstrual,jdbcType=TIMESTAMP},
            </if>
            <if test="ispregnancy != null">
                ispregnancy=#{ispregnancy,jdbcType=BIGINT},
            </if>
            <if test="operationDoctor != null">
                operation_doctor=#{operationDoctor,jdbcType=VARCHAR},
            </if>
            <if test="created != null">
                created=#{created,jdbcType=TIMESTAMP},
            </if>
            <if test="vcCard != null">
                vc_card=#{vcCard,jdbcType=VARCHAR},
            </if>
            <if test="hospitalId != null and hospitalId != ''">
                hospitalid=#{hospitalId,jdbcType=VARCHAR},
            </if>
            <if test="receiveSum != null">
                receivesum=#{receiveSum,jdbcType=INTEGER},
            </if>
            <if test="modify != null">
                modify=#{modify,jdbcType=TIMESTAMP},
            </if>
            <if test="drawTime !=null">
                drawTime=#{drawTime,jdbcType=TIMESTAMP}
            </if>
        </set>
    </sql>
    <sql id="orderAndLimit">
        <if test="sort != null and sort != '' ">
            order by ${sort}
            <if test="need != null">
                limit #{offset, jdbcType=INTEGER} , #{limit, jdbcType=INTEGER}
            </if>
        </if>
    </sql>
</mapper>