<?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.boman.web.core.mapper.VaccineInfoUserMapper">


    <resultMap id="VaccineInfoUser" type="com.boman.domain.VaccineInfoUser">
        <id     property="id"       column="id"        />
        <result property="idCard"     column="id_card"      />
        <result property="vaccineName"      column="vaccine_name"       />
        <result property="jici"     column="jici"      />
        <result property="vaccinationTime"    column="vaccination_time"    />
        <result property="vaccinationPlace"    column="vaccination_place"    />
        <result property="progress"    column="progress"    />
        <result property="url"    column="url"    />
        <result property="status"    column="status"    />
        <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="isDel"    column="is_del"    />
    </resultMap>


    <select id="selectVaccineInfoUserByIdCard" resultMap="VaccineInfoUser">
               select id,id_card,vaccine_name,jici,vaccination_time,vaccination_place,progress,url,status from vaccine_info_user  where id_card = #{idCard} and is_del = 'N'
    </select>

    <select id="selectIdCardList"  resultType="java.lang.String">
        SELECT DISTINCT id_card FROM vaccine_info_user
        <where>
            is_del = 'N'
            <if test="jici != null  and jici != ''"> and jici = #{jici}</if>
            <if test="vaccinationTime != null "> and DATE_FORMAT(vaccination_time,'%Y-%m-%d') = DATE_FORMAT(#{vaccinationTime},'%Y-%m-%d')</if>
            <if test="vaccinationPlace != null  and vaccinationPlace != ''"> and vaccination_place = #{vaccinationPlace}</if>
        </where>
    </select>

    <insert id="insertVaccineInfoUser"  useGeneratedKeys="true" keyProperty="id">
        insert into vaccine_info_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="idCard != null">id_card,</if>
            <if test="vaccineName != null">vaccine_name,</if>
            <if test="jici != null">jici,</if>
            <if test="vaccinationTime != null">vaccination_time,</if>
            <if test="vaccinationPlace != null">vaccination_place,</if>
            <if test="progress != null">progress,</if>
            <if test="url != null and url != ''">url,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null and isDel != ''">is_del,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="idCard != null">#{idCard},</if>
            <if test="vaccineName != null">#{vaccineName},</if>
            <if test="jici != null">#{jici},</if>
            <if test="vaccinationTime != null">#{vaccinationTime},</if>
            <if test="vaccinationPlace != null">#{vaccinationPlace},</if>
            <if test="progress != null">#{progress},</if>
            <if test="url != null and url != ''">#{url},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null and isDel != ''">#{isDel},</if>
            sysdate()
        </trim>
    </insert>

    <update id="updateVaccineInfoUser" >
        update vaccine_info_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="vaccineName != null">vaccine_name = #{vaccineName},</if>
            <if test="jici != null">jici = #{jici},</if>
            <if test="vaccinationTime != null">vaccination_time = #{vaccinationTime},</if>
            <if test="vaccinationPlace != null">vaccination_place = #{vaccinationPlace},</if>
            <if test="progress != null">progress = #{progress},</if>
            <if test="url != null and url != ''">url = #{url},</if>
            <if test="status != null">status = #{status},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="isDel != null and isDel != ''">is_del = #{isDel},</if>
            update_time = sysdate()
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteVaccineInfoUserById" parameterType="Long">
        update vaccine_info_user set is_del = 'Y'  where id = #{id}
    </delete>

    <delete id="deleteVaccineInfoUserByIds" parameterType="String">
        update vaccine_info_user set is_del = 'Y' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="listBy1jici" resultType="int">
        SELECT count(1) FROM vaccine_info_user where is_del = 'N' and jici = '1';
    </select>

    <select id="countByIdCardAndJici" resultType="int">
        SELECT count(1) FROM vaccine_info_user where id_card = #{sfz} and jici = #{jzjc};
    </select>


    <select id="todayCnt" resultType="com.alibaba.fastjson.JSONObject">
        SELECT count(1) one FROM vaccine_info_user WHERE is_del = 'N' AND jici = '1'
            AND vaccination_time &gt;= #{todayStart}
            AND vaccination_time &lt;= #{todayEnd}

        UNION ALL

        SELECT count(1) FROM vaccine_info_user WHERE is_del = 'N' AND jici = '2'
            AND vaccination_time &gt;= #{todayStart}
            AND vaccination_time &lt;= #{todayEnd}

        UNION ALL

        SELECT count(1) FROM vaccine_info_user WHERE is_del = 'N'
            AND vaccination_time &gt;= #{todayStart}
            AND vaccination_time &lt;= #{todayEnd}
    </select>

</mapper>