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

    <resultMap type="com.boman.domain.ThirdPartInfo" id="ThirdPartInfoResult">
        <result property="id"    column="id"    />
        <result property="cremationCertificate"    column="cremation_certificate"    />
        <result property="cremationTime"    column="cremation_time"    />
        <result property="userName"    column="user_name"    />
        <result property="idCard"    column="id_card"    />
        <result property="age"    column="age"    />
        <result property="gender"    column="gender"    />
        <result property="nation"    column="nation"    />
        <result property="township"    column="township"    />
        <result property="villageGroup"    column="village_group"    />
        <result property="homePhone"    column="home_phone"    />
        <result property="isDeposit"    column="is_deposit"    />
        <result property="isColdStorage"    column="is_cold_storage"    />
        <result property="causeOfDeath"    column="cause_of_death"    />
        <result property="isHmbz"    column="is_hmbz"    />
        <result property="sjgm"    column="sjgm"    />
        <result property="jzdx"    column="jzdx"    />
        <result property="remarks"    column="remarks"    />
        <result property="isLocalAccount"    column="is_local_account"    />
        <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="provinceId" column="province_id"/>
        <result property="province" column="province"/>
        <result property="cityId" column="city_id"/>
        <result property="city" column="city"/>
        <result property="regionId" column="region_id"/>
        <result property="region" column="region"/>
        <result property="villageTownsId" column="village_towns_id"/>
        <result property="villageTowns" column="village_towns"/>
        <result property="villageId" column="village_id"/>
        <result property="village" column="village"/>
        <result property="isLocal" column="is_local"/>
        <result property="source" column="source"/>

    </resultMap>


    <insert id="insertThirdPartInfoList" useGeneratedKeys="true" keyProperty="id">
        insert into third_part_info(cremation_certificate,
            cremation_time,
            user_name,
            id_card,
            age,
            gender,
            nation,
            township,
            village_group,
            home_phone,
            is_deposit,
            is_cold_storage,
            cause_of_death,
            is_hmbz,
            sjgm,
            jzdx,
            remarks,
            is_local_account,
            status,
            create_by,
            update_by,
            is_del,
            province_id,
            province,
            city_id,
            city,
            region_id,
            region,
            village_towns_id,
            village_towns,
            village_id,
            village,
            is_local,source,create_time,update_time)
        values
        <foreach item="thirdPartInfo" index="index" collection="thirdPartInfoList" separator=",">
            (#{thirdPartInfo.cremationCertificate},
            #{thirdPartInfo.cremationTime},
            #{thirdPartInfo.userName},
            #{thirdPartInfo.idCard},
            #{thirdPartInfo.age},
            #{thirdPartInfo.gender},
            #{thirdPartInfo.nation},
            #{thirdPartInfo.township},
            #{thirdPartInfo.villageGroup},
            #{thirdPartInfo.homePhone},
            #{thirdPartInfo.isDeposit},
            #{thirdPartInfo.isColdStorage},
            #{thirdPartInfo.causeOfDeath},
            #{thirdPartInfo.isHmbz},
            #{thirdPartInfo.sjgm},
            #{thirdPartInfo.jzdx},
            #{thirdPartInfo.remarks},
            #{thirdPartInfo.isLocalAccount},
            #{thirdPartInfo.status},
            #{thirdPartInfo.createBy},
            #{thirdPartInfo.updateBy},
            #{thirdPartInfo.isDel},
            #{thirdPartInfo.provinceId},
            #{thirdPartInfo.province},
            #{thirdPartInfo.cityId},
            #{thirdPartInfo.city},
            #{thirdPartInfo.regionId},
            #{thirdPartInfo.region},
            #{thirdPartInfo.villageTownsId},
            #{thirdPartInfo.villageTowns},
            #{thirdPartInfo.villageId},
            #{thirdPartInfo.village},
            #{thirdPartInfo.isLocal},
            #{thirdPartInfo.source},
            sysdate(),sysdate())
        </foreach>
    </insert>

    <update id="delecteDie" parameterType="java.lang.String">
        update third_part_info set is_del='Y' where id_card = #{idCard}
    </update>

    <select id="queryList" resultMap="ThirdPartInfoResult">
        select id, cremation_certificate, cremation_time, user_name, id_card, age, gender, nation, township, village_group,
               home_phone, is_deposit, is_cold_storage,cause_of_death,status,
               is_hmbz,sjgm,jzdx,remarks,is_local_account,is_local,create_time,source
        from third_part_info
        <where>
            is_del = 'N'
            and status = '4'
            <if test="userName != null  and userName != ''">
                and user_name like concat(#{userName}, '%')
            </if>
            <if test="gender != null  and gender != ''">and gender = #{gender}</if>
            <if test="age != null ">and age = #{age}</if>
            <if test="cremationCertificate != null  and cremationCertificate != ''">and cremation_certificate = #{cremationCertificate}</if>
            <if test="nation != null  and nation != ''">and nation = #{nation}</if>
            <if test="idCard != null  and idCard != ''">and id_card = #{idCard}</if>
            <if test="township != null  and township != ''">and township = #{township}</if>
            <if test="homePhone != null  and homePhone != ''">and home_phone = #{homePhone}</if>
            <if test="isDeposit != null  and isDeposit != ''">and is_deposit = #{isDeposit}</if>
            <if test="isColdStorage != null  and isColdStorage != ''">and is_cold_storage = #{isColdStorage}</if>
            <if test="causeOfDeath != null  and causeOfDeath != ''">and cause_of_death = #{causeOfDeath}</if>
            <if test="isHmbz != null  and isHmbz != ''">and is_hmbz = #{isHmbz}</if>
            <if test="sjgm != null  and sjgm != ''">and sjgm = #{sjgm}</if>
            <if test="jzdx != null  and jzdx != ''">and jzdx = #{jzdx}</if>
            <if test="isLocalAccount != null  and isLocalAccount != ''">and is_local_account = #{isLocalAccount}</if>
            <if test="provinceId != null  and provinceId != ''">and province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and village_towns_id = #{villageTownsId}</if>
            <if test="villageId != null  and villageId != ''">and village_id = #{villageId}</if>
            <if test="isLocal != null  and isLocal != ''">and is_local = #{isLocal}</if>
        </where>
        order by create_time DESC
    </select>


</mapper>