<?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.VaccineInfoMapper">
    
    <resultMap type="VaccineInfoOperation" id="VaccineInfoResult">
        <result property="id"    column="id"    />
        <result property="villageTowns"    column="village_towns" />
        <result property="village"    column="village"    />
        <result property="villagerGroup"    column="villager_group" />
        <result property="houseType"    column="house_type"  />
        <result property="domicile"    column="domicile"   />
        <result property="province"    column="province"  />
        <result property="city"    column="city"  />
        <result property="region"    column="region"  />
        <result property="userName"    column="user_name"  />
        <result property="gender"    column="gender"  />
        <result property="idCard"    column="id_card"  />
        <result property="phoneNum"    column="phone_num"  />
        <result property="keyIndustries"    column="key_industries" />
        <result property="isVaccination"    column="is_vaccination"  />
        <result property="contraindication"    column="contraindication"    />
        <result property="suspend"    column="suspend"    />
        <result property="death"    column="death"    />
        <result property="lostInMissing"    column="lost_in_missing"    />
        <result property="shouldBe"    column="should_be"    />
        <result property="other"    column="other"    />
        <result property="remark"    column="remark"    />
        <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"    />
        <result property="code"    column="code"    />
        <result property="birthday"    column="birthday"    />
        <result property="workUnit"    column="work_unit"    />
        <result property="crowdClassification"    column="crowd_classification"    />
        <result property="manufacturer"    column="manufacturer"    />
        <result property="nowIn"    column="now_in"    />
        <result property="url"    column="url"    />
        <collection  property="vaccineInfoUserList"   javaType="java.util.List"        resultMap="VaccineInfoUser" />
    </resultMap>

    <resultMap id="VaccineInfoUser" type="com.boman.web.core.domain.VaccineInfoUser">
        <id     property="id"       column="id_user"        />
        <result property="idCard"     column="id_card_user"      />
        <result property="vaccineName"      column="vaccine_name_user"       />
        <result property="jici"     column="jici_user"      />
        <result property="vaccinationTime"    column="vaccination_time_user"    />
        <result property="vaccinationPlace"    column="vaccination_place_user"    />
        <result property="progress"    column="progress_user"    />
        <result property="status"    column="status_user"    />
    </resultMap>

    <sql id="selectVaccineInfoVo">
        select vi.id, vi.village_towns, vi.village, vi.villager_group, vi.house_type, vi.domicile, vi.province, vi.city,
        vi.region, vi.user_name, vi.gender, vi.id_card, vi.phone_num, vi.key_industries, vi.is_vaccination, vi.vaccine_name, vi.jici,
        vi.vaccination_time, vi.vaccination_place, vi.contraindication, vi.suspend, vi.death, vi.lost_in_missing,
        vi.should_be, vi.other, vi.progress, vi.remark, vi.status, vi.create_by, vi.create_time, vi.update_by, vi.update_time,
               vi.is_del,vi.code,vi.birthday,vi.work_unit,vi.crowd_classification,vi.manufacturer,vi.now_in,vi.url,
               viu.id as id_user,viu.id_card as id_card_user,viu.vaccine_name as vaccine_name_user,viu.jici as jici_user,viu.vaccination_time as vaccination_time_user,
               viu.vaccination_place as vaccination_place_user,viu.progress as progress_user,viu.status as status_user
               from vaccine_info vi left join vaccine_info_user viu
               on vi.id_card = viu.id_card and viu.is_del = 'N'
    </sql>

    <select id="selectVaccineInfoList" parameterType="VaccineInfoOperation" resultMap="VaccineInfoResult">
        select vi.id, vi.village_towns, vi.village, vi.villager_group, vi.house_type, vi.domicile, vi.province, vi.city,
        vi.region, vi.user_name, vi.gender, vi.id_card, vi.phone_num, vi.key_industries, vi.is_vaccination, vi.vaccine_name, vi.jici,
        vi.vaccination_time, vi.vaccination_place, vi.contraindication, vi.suspend, vi.death, vi.lost_in_missing,
        vi.should_be, vi.other, vi.progress, vi.remark, vi.status, vi.create_by, vi.create_time, vi.update_by, vi.update_time,
        vi.is_del,vi.code,vi.birthday,vi.work_unit,vi.crowd_classification,vi.manufacturer,vi.now_in,vi.url from vaccine_info vi
        <where>
            vi.is_del = 'N'
            <if test="villageTowns != null  and villageTowns != ''"> and vi.village_towns = #{villageTowns}</if>
            <if test="village != null  and village != ''"> and vi.village = #{village}</if>
            <if test="villagerGroup != null  and villagerGroup != ''"> and vi.villager_group = #{villagerGroup}</if>
            <if test="houseType != null  and houseType != ''"> and vi.house_type = #{houseType}</if>
            <if test="domicile != null  and domicile != ''"> and vi.domicile = #{domicile}</if>
            <if test="province != null  and province != ''"> and vi.province = #{province}</if>
            <if test="city != null  and city != ''"> and vi.city = #{city}</if>
            <if test="region != null  and region != ''"> and vi.region = #{region}</if>
            <if test="userName != null  and userName != ''"> and vi.user_name like concat('%', #{userName}, '%')</if>
            <if test="gender != null  and gender != ''"> and vi.gender = #{gender}</if>
            <if test="idCard != null  and idCard != ''"> and vi.id_card like concat('%', #{idCard}, '%')</if>
            <if test="phoneNum != null  and phoneNum != ''"> and vi.phone_num = #{phoneNum}</if>
            <if test="keyIndustries != null  and keyIndustries != ''"> and vi.key_industries = #{keyIndustries}</if>
            <if test="isVaccination != null  and isVaccination != ''"> and vi.is_vaccination = #{isVaccination}</if>
            <if test="params.startAge != null  and params.startAge != ''"> and vi.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''"> and vi.age &lt;= #{params.endAge}</if>
            <if test="contraindication != null  and contraindication != ''"> and vi.contraindication = #{contraindication}</if>
            <if test="suspend != null  and suspend != ''"> and vi.suspend = #{suspend}</if>
            <if test="death != null  and death != ''"> and vi.death = #{death}</if>
            <if test="lostInMissing != null  and lostInMissing != ''"> and vi.lost_in_missing = #{lostInMissing}</if>
            <if test="shouldBe != null  and shouldBe != ''"> and vi.should_be = #{shouldBe}</if>
            <if test="other != null  and other != ''"> and vi.other = #{other}</if>
            <if test="status != null  and status != ''"> and vi.status = #{status}</if>
            <if test="code != null  and code != ''"> and vi.code = #{code}</if>
            <if test="birthday != null  and birthday != ''"> and vi.birthday = #{birthday}</if>
            <if test="workUnit != null  and workUnit != ''"> and vi.work_unit = #{workUnit}</if>
            <if test="crowdClassification != null  and crowdClassification != ''"> and vi.crowd_classification = #{crowdClassification}</if>
            <if test="manufacturer != null  and manufacturer != ''"> and vi.manufacturer = #{manufacturer}</if>
            <if test="nowIn != null  and nowIn != ''"> and vi.now_in = #{nowIn}</if>
            <if test="idCardS != null  and idCardS.size() > 0">
             and vi.id_card in
            <foreach item="idCard" collection="idCardS" open="(" separator="," close=")">
                #{idCard}
            </foreach>
            </if>
        </where>
        order by vi.create_time DESC
    </select>

    <select id="selectVaccineInfoListByPage" parameterType="Integer" resultMap="VaccineInfoResult">
        select * from vaccine_info limit   #{startNum}, #{endNum}
    </select>


    <select id="selectVaccineInfoById" parameterType="Long" resultMap="VaccineInfoResult">
        <include refid="selectVaccineInfoVo"/>
        where vi.id = #{id} and vi.is_del = 'N'
        order by viu.vaccination_time
    </select>
    <select id="selectVaccineInfoByIds" parameterType="Long" resultMap="VaccineInfoResult">
        <include refid="selectVaccineInfoVo"/>
        where vi.id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
        and vi.is_del = 'N'
    </select>
        
    <insert id="insertVaccineInfo" parameterType="VaccineInfoOperation" useGeneratedKeys="true" keyProperty="id">
        insert into vaccine_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="villageTowns != null">village_towns,</if>
            <if test="village != null">village,</if>
            <if test="villagerGroup != null">villager_group,</if>
            <if test="houseType != null">house_type,</if>
            <if test="domicile != null">domicile,</if>
            <if test="province != null">province,</if>
            <if test="city != null">city,</if>
            <if test="region != null and region != ''">region,</if>
            <if test="userName != null">user_name,</if>
            <if test="gender != null">gender,</if>
            <if test="idCard != null">id_card,</if>
            <if test="phoneNum != null">phone_num,</if>
            <if test="keyIndustries != null">key_industries,</if>
            <if test="isVaccination != null">is_vaccination,</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="contraindication != null">contraindication,</if>
            <if test="suspend != null">suspend,</if>
            <if test="death != null">death,</if>
            <if test="lostInMissing != null">lost_in_missing,</if>
            <if test="shouldBe != null">should_be,</if>
            <if test="other != null">other,</if>
            <if test="progress != null">progress,</if>
            <if test="remark != null">remark,</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>
            <if test="code != null and code != ''">code,</if>
            <if test="birthday != null and birthday != ''">birthday,</if>
            <if test="workUnit != null and workUnit != ''">work_unit,</if>
            <if test="crowdClassification != null and crowdClassification != ''">crowd_classification,</if>
            <if test="manufacturer != null and manufacturer != ''">manufacturer,</if>
            <if test="nowIn != null and nowIn != ''">now_in,</if>
            <if test="url != null and url != ''">url,</if>
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="villageTowns != null">#{villageTowns},</if>
            <if test="village != null">#{village},</if>
            <if test="villagerGroup != null">#{villagerGroup},</if>
            <if test="houseType != null">#{houseType},</if>
            <if test="domicile != null">#{domicile},</if>
            <if test="province != null">#{province},</if>
            <if test="city != null">#{city},</if>
            <if test="region != null and region != ''">#{region},</if>
            <if test="userName != null">#{userName},</if>
            <if test="gender != null">#{gender},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="phoneNum != null">#{phoneNum},</if>
            <if test="keyIndustries != null">#{keyIndustries},</if>
            <if test="isVaccination != null">#{isVaccination},</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="contraindication != null">#{contraindication},</if>
            <if test="suspend != null">#{suspend},</if>
            <if test="death != null">#{death},</if>
            <if test="lostInMissing != null">#{lostInMissing},</if>
            <if test="shouldBe != null">#{shouldBe},</if>
            <if test="other != null">#{other},</if>
            <if test="progress != null">#{progress},</if>
            <if test="remark != null">#{remark},</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>
            <if test="code != null and code != ''">#{code},</if>
            <if test="birthday != null and birthday != ''">#{birthday},</if>
            <if test="workUnit != null and workUnit != ''">#{workUnit},</if>
            <if test="crowdClassification != null and crowdClassification != ''">#{crowdClassification},</if>
            <if test="manufacturer != null and manufacturer != ''">#{manufacturer},</if>
            <if test="nowIn != null and nowIn != ''">#{nowIn},</if>
            <if test="url != null and url != ''">#{url},</if>
            sysdate()
         </trim>
    </insert>

    <update id="updateVaccineInfo" parameterType="VaccineInfoOperation">
        update vaccine_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="villageTowns != null">village_towns = #{villageTowns},</if>
            <if test="village != null">village = #{village},</if>
            <if test="villagerGroup != null">villager_group = #{villagerGroup},</if>
            <if test="houseType != null">house_type = #{houseType},</if>
            <if test="domicile != null">domicile = #{domicile},</if>
            <if test="province != null">province = #{province},</if>
            <if test="city != null">city = #{city},</if>
            <if test="region != null and region != ''">region = #{region},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="phoneNum != null">phone_num = #{phoneNum},</if>
            <if test="keyIndustries != null">key_industries = #{keyIndustries},</if>
            <if test="isVaccination != null">is_vaccination = #{isVaccination},</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="contraindication != null">contraindication = #{contraindication},</if>
            <if test="suspend != null">suspend = #{suspend},</if>
            <if test="death != null">death = #{death},</if>
            <if test="lostInMissing != null">lost_in_missing = #{lostInMissing},</if>
            <if test="shouldBe != null">should_be = #{shouldBe},</if>
            <if test="other != null">other = #{other},</if>
            <if test="progress != null">progress = #{progress},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null and isDel != ''">is_del = #{isDel},</if>
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="birthday != null and birthday != ''">birthday = #{birthday},</if>
            <if test="workUnit != null and workUnit != ''">work_unit = #{workUnit},</if>
            <if test="crowdClassification != null and crowdClassification != ''">crowd_classification = #{crowdClassification},</if>
            <if test="manufacturer != null and manufacturer != ''">manufacturer = #{manufacturer},</if>
            <if test="nowIn != null and nowIn != ''">now_in = #{nowIn},</if>
            <if test="url != null and url != ''">url = #{url},</if>
        </trim>
        where id = #{id}
    </update>

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

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


    <select id="findHjInfo" parameterType="VaccineInfoOperation" resultMap="VaccineInfoResult">
        select xm as user_name,xb as gender,csrq as birthday from hj
        <where>
         <if test="idCard != null and idCard != '' ">zjhm = #{idCard}</if>
        </where>
        limit 1
    </select>

    <select id="selectSysDictDataByDictLabel" parameterType="string" resultType="String">
        select dict_value  from sys_dict_data where dict_label = #{vaccineName} and  status = '0'
    </select>

</mapper>