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

    <resultMap type="com.boman.domain.Czrk" id="CzrkResult">
        <result property="id" column="id"/>
        <result property="czrkJzdzId" column="czrk_jzdz_id"/>
        <result property="userName" column="user_name"/>
        <result property="gender" column="gender"/>
        <result property="age" column="age"/>
        <result property="birthday" column="birthday"/>
        <result property="deptId" column="dept_id"/>
        <result property="idCard" column="id_card"/>
        <result property="phoneNum" column="phone_num"/>
        <result property="code" column="code"/>
        <result property="houseType" column="house_type"/>
        <result property="rlr" column="rlr"/>
        <result property="rlrNike" column="rlr_nike"/>
        <result property="rlTime" column="rl_time"/>
        <result property="keyIndustries" column="key_industries"/>
        <result property="keyCategory" column="key_category"/>
        <result property="yhzgx" column="yhzgx"/>
        <result property="workUnit" column="work_unit"/>
        <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="isRl" column="is_rl"/>
        <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="villagerGroupId" column="villager_group_id"/>
        <result property="villagerGroup" column="villager_group"/>
        <result property="nowIn" column="now_in"/>
        <result property="remark" column="remark"/>
        <result property="gridId" column="grid_id"/>
        <result property="gridName" column="grid_name"/>
        <result property="status" column="status"/>
        <result property="changUser" column="chang_user"/>
        <result property="changNikeUser" column="chang_nike_user"/>
        <result property="changUserTime" column="chang_user_time"/>
        <result property="isConfirm" column="is_confirm"/>
        <result property="confirmInfoUser" column="confirm_info_user"/>
        <result property="confirmInfoNikeUser" column="confirm_info_nike_user"/>
        <result property="confirmInfoUserTime" column="confirm_info_user_time"/>
        <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="deleteReason" column="delete_reason"/>
        <result property="isNucleicAcid" column="is_nucleicAcid"/>
        <result property="nucleicAcidTime" column="nucleicAcid_time"/>

        <result property="toAppropriatePhone" column="to_appropriate_phone"/>
        <result property="toAppropriateTime" column="to_appropriate_time"/>


        <result property="provinceIdXjd" column="provinceIdXjd"/>
        <result property="cityIdXjd" column="cityIdXjd"/>
        <result property="regionIdXjd" column="regionIdXjd"/>
        <result property="villageTownsIdXjd" column="villageTownsIdXjd"/>
        <result property="villageIdXjd" column="villageIdXjd"/>

        <result property="provinceXjd" column="provinceXjd"/>
        <result property="cityXjd" column="cityXjd"/>
        <result property="regionXjd" column="regionXjd"/>
        <result property="villageTownsXjd" column="villageTownsXjd"/>
        <result property="villageXjd" column="villageXjd"/>
        <result property="nowXjd" column="nowXjd"/>


        <result property="villagerGroupIdJz" column="villagerGroupIdJz"/>
        <result property="gridIdJz" column="gridIdJz"/>
        <result property="villagerGroupJz" column="villagerGroupJz"/>
        <result property="gridNameJz" column="gridNameJz"/>

        <collection property="czrkJzdzList" javaType="java.util.List" resultMap="CzrkJzdzResult"/>


    </resultMap>

    <resultMap type="com.boman.domain.CzrkJzdz" id="CzrkJzdzResult">
        <result property="provinceId" column="province_id_jzdz"/>
        <result property="province" column="province_jzdz"/>
        <result property="cityId" column="city_id_jzdz"/>
        <result property="city" column="city_jzdz"/>
        <result property="regionId" column="region_id_jzdz"/>
        <result property="region" column="region_jzdz"/>
        <result property="townId" column="town_id_jzdz"/>
        <result property="town" column="town_jzdz"/>
        <result property="villageId" column="village_id_jzdz"/>
        <result property="village" column="village_jzdz"/>
        <result property="nowIn" column="now_in_jzdz"/>
    </resultMap>


    <resultMap type="com.boman.domain.SysDept" id="SysDeptResult">
        <id property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="ancestors" column="ancestors"/>
        <result property="deptName" column="dept_name"/>
        <result property="orderNum" column="order_num"/>
        <result property="leader" column="leader"/>
        <result property="phone" column="phone"/>
        <result property="email" column="email"/>
        <result property="status" column="status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="parentName" column="parent_name"/>
        <result property="num" column="num"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <resultMap type="com.boman.web.core.domain.ConfirmInfoUser" id="ConfrimInforUserResult">
        <result property="confirmInfoUser" column="confirm_info_user"/>
        <result property="confirmInfoNikeUser" column="confirm_info_nike_user"/>
        <result property="czrkId" column="czrk_id"/>
    </resultMap>
    <sql id="selectCzrkVo">
        select id, user_name, gender, age, birthday,dept_id, id_card, phone_num, code, house_type, rlr,rlr_nike, rl_time, yhzgx
             , work_unit, province_id, province, city_id, city, region_id, region, village_towns_id, village_towns
             , village_id, village, villager_group_id, villager_group, now_in, remark,grid_id,grid_name, status,is_confirm,confirm_info_user,confirm_info_nike_user,confirm_info_user_time, create_by, create_time
             , update_by, update_time, is_del, delete_reason,  is_rl, key_industries,key_category from czrk
    </sql>

    <select id="listByCzrk" resultMap="CzrkResult">
        select id, user_name, phone_num, id_card, gender, province, city, region, village_towns, village,
        villager_group,villager_group_id, house_type, code,is_rl,grid_name,grid_id,
        rlr,rlr_nike,now_in,is_confirm,confirm_info_user,confirm_info_nike_user,confirm_info_user_time,is_nucleicAcid,nucleicAcid_time,to_appropriate_phone,key_category
        from czrk
        <where>
            is_del = 'N'
            and status = '1'
            <!-- 已认领 -->
            <if test="isRl != null and isRl != ''">and is_rl = #{isRl}</if>
            <if test="isNucleicAcid != null and isNucleicAcid != ''">and is_nucleicAcid = #{isNucleicAcid}</if>
            <if test="userName != null  and userName != ''">
                and user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and age &lt;= #{params.endAge}</if>
            <if test="gender != null  and gender != ''">and gender = #{gender}</if>
            <if test="age != null ">and age = #{age}</if>
            <if test="birthday != null ">and birthday = #{birthday}</if>
            <if test="idCard != null  and idCard != ''">and id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and phone_num = #{phoneNum}</if>
            <if test="houseType != null  and houseType != ''">and house_type = #{houseType}</if>
            <if test="provinceId != null  and provinceId != ''">and province_id = #{provinceId}</if>
            <if test="province != null  and province != ''">and province = #{province}</if>
            <if test="cityId != null  and cityId != ''">and city_id = #{cityId}</if>
            <if test="city != null  and city != ''">and city = #{city}</if>
            <if test="regionId != null  and regionId != ''">and region_id = #{regionId}</if>
            <if test="region != null  and region != ''">and region = #{region}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and village_towns_id = #{villageTownsId}</if>
            <if test="villageTowns != null  and villageTowns != ''">and village_towns = #{villageTowns}</if>
            <if test="villageId != null  and villageId != ''">and village_id = #{villageId}</if>
            <if test="village != null  and village != ''">and village = #{village}</if>

            <if test="villagerGroupId != null  and villagerGroupId != ''">and villager_group_id = #{villagerGroupId}</if>
            <if test="villagerGroup != null  and villagerGroup != ''">and villager_group = #{villagerGroup}</if>

            <if test="isConfirm != null  and isConfirm != ''">and is_confirm = #{isConfirm}</if>
            <if test="gridId != null  and gridId != ''">and grid_id = #{gridId}</if>

            <if test="keyCategoryList != null  and keyCategoryList.size() > 0">
                <foreach item="KeyCategory" collection="keyCategoryList">
                and  find_in_set(#{KeyCategory}, key_category)
                </foreach>
            </if>


        </where>
        order by create_time DESC
    </select>


    <select id="listCzrkByJzdz" resultMap="CzrkResult">
        select c.id, c.user_name, c.phone_num,c.dept_id, c.id_card,
        c.province, c.city ,c.region , c.village_towns, c.village ,c.now_in,c.grid_name,c.grid_id,c.villager_group_id,c.villager_group,
        c.gender, c.house_type, c.update_by, c.code,c.is_rl, c.rlr,c.rlr_nike,
        c.is_confirm,c.confirm_info_user,c.confirm_info_nike_user,c.confirm_info_user_time,c.key_category
        from czrk c left join czrk_jzdz z on c.id =z.czrk_id
        <where>
            c.is_del = 'N'
            and c.status = '1'
            <if test="isRl != null and isRl != ''">and c.is_rl = #{isRl}</if>
            <if test="userName != null  and userName != ''">
                and c.user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and c.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and c.age &lt;= #{params.endAge}</if>
            <if test="idCard != null  and idCard != ''">and c.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and c.phone_num = #{phoneNum}</if>
            <if test="houseType != null  and houseType != ''">and c.house_type = #{houseType}</if>
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            <if test="villageId != null  and villageId != ''">and c.village_id = #{villageId}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="provinceIdXjd != null and provinceIdXjd != ''">and z.province_id = #{provinceIdXjd}</if>
            <if test="cityIdXjd != null and cityIdXjd != ''">and z.city_id = #{cityIdXjd}</if>
            <if test="regionIdXjd != null and regionIdXjd != ''">and z.region_id = #{regionIdXjd}</if>
            <if test="villageTownsIdXjd != null and villageTownsIdXjd != ''">and z.town_id = #{villageTownsIdXjd}</if>
            <if test="villageIdXjd != null and villageIdXjd != ''">and z.village_id = #{villageIdXjd}</if>

            <if test="villagerGroupIdJz != null and villagerGroupIdJz != ''">and z.villager_group_id = #{villagerGroupIdJz}</if>
            <if test="gridIdJz != null and gridIdJz != ''">and z.grid_id = #{gridIdJz}</if>

            <if test="keyCategoryList != null  and keyCategoryList.size() > 0">
                <foreach item="KeyCategory" collection="keyCategoryList">
                    and  find_in_set(#{KeyCategory}, key_category)
                </foreach>
            </if>
        </where>
        order by c.create_time DESC
    </select>
    <select id="listByRlryRel" resultType="com.boman.domain.Czrk">
        SELECT
        czrk.id,
        ANY_VALUE(czrk.user_name) userName,
        ANY_VALUE(czrk.phone_num) phoneNum,
        ANY_VALUE(czrk.id_card) idCard,
        ANY_VALUE(czrk.gender) gender,
        ANY_VALUE(czrk.province) province,
        ANY_VALUE(czrk.is_rl) isRl,
        ANY_VALUE(czrk.city) city,
        ANY_VALUE(czrk.region) region,
        ANY_VALUE(czrk.house_type) houseType,
        ANY_VALUE(czrk.update_by) updateBy,
        ANY_VALUE(czrk. CODE) CODE,
        ANY_VALUE(czrk.rlr) rlr,
        ANY_VALUE(czrk.update_time) updateTime,
        ANY_VALUE(czrk.delete_reason) deleteReason,
        ANY_VALUE(czrk.now_in) nowIn,
        ANY_VALUE(jzdz.province) provinceXjd,
        ANY_VALUE(jzdz.city) cityXjd,
        ANY_VALUE(jzdz.region) regionXjd,
        ANY_VALUE(jzdz.town) villageTownsXjd,
        ANY_VALUE(jzdz.village) villageXjd,
        ANY_VALUE(jzdz.now_in) domicile
        from czrk
        left join czrk_jzdz jzdz on czrk.id = jzdz.czrk_id
        <where>
            jzdz.status = 'Y'
            <!-- 已认领 -->
            <if test="isRl != null and isRl != ''">and czrk.is_rl = #{isRl}</if>

            <if test="userName != null  and userName != ''">
                and (czrk.user_name like concat(#{userName}, '%') or czrk.id_card like concat( #{userName}, '%'))
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and czrk.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and czrk.age &lt;= #{params.endAge}</if>
            <if test="gender != null  and gender != ''">and czrk.gender = #{gender}</if>
            <if test="age != null ">and czrk.age = #{age}</if>
            <if test="birthday != null ">and czrk.birthday = #{birthday}</if>
            <if test="idCard != null  and idCard != ''">and czrk.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and czrk.phone_num = #{phoneNum}</if>
            <if test="code != null  and code != ''">and czrk.code = #{code}</if>
            <if test="houseType != null  and houseType != ''">and czrk.house_type = #{houseType}</if>
            <if test="rlr != null  and rlr != ''">and czrk.rlr = #{rlr}</if>
            <if test="rlTime != null ">and czrk.rl_time = #{rlTime}</if>
            <if test="yhzgx != null  and yhzgx != ''">and czrk.yhzgx = #{yhzgx}</if>
            <if test="workUnit != null  and workUnit != ''">and czrk.work_unit = #{workUnit}</if>
            <if test="provinceId != null  and provinceId != ''">and czrk.province_id = #{provinceId}</if>

            <if test="provinceIdXjd != null  and provinceIdXjd != ''">and jzdz.province_id = #{provinceId}</if>
            <if test="cityIdXjd != null  and cityIdXjd != ''">and jzdz.city_id = #{cityIdXjd}</if>
            <if test="regionIdXjd != null  and regionIdXjd != ''">and jzdz.region_id = #{regionIdXjd}</if>
            <if test="villageTownsIdXjd != null  and villageTownsIdXjd != ''">and jzdz.town_id = #{villageTownsIdXjd}
            </if>
            <if test="villageIdXjd != null  and villageIdXjd != ''">and jzdz.village_id = #{villageIdXjd}</if>

            <if test="province != null  and province != ''">and czrk.province = #{province}</if>
            <if test="cityId != null  and cityId != ''">and czrk.city_id = #{cityId}</if>
            <if test="city != null  and city != ''">and czrk.city = #{city}</if>
            <if test="regionId != null  and regionId != ''">and czrk.region_id = #{regionId}</if>
            <if test="region != null  and region != ''">and czrk.region = #{region}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and czrk.village_towns_id = #{villageTownsId}
            </if>
            <if test="villageTowns != null  and villageTowns != ''">and czrk.village_towns = #{villageTowns}</if>
            <if test="villageId != null  and villageId != ''">and czrk.village_id = #{villageId}</if>
            <if test="village != null  and village != ''">and czrk.village = #{village}</if>
            <if test="villagerGroupId != null  and villagerGroupId != ''">and czrk.villager_group_id =
                #{villagerGroupId}
            </if>
            <if test="villagerGroup != null  and villagerGroup != ''">and czrk.villager_group = #{villagerGroup}</if>
            <if test="nowIn != null  and nowIn != ''">and czrk.now_in = #{nowIn}</if>
            <if test="status != null  and status != ''">and czrk.status = #{status}</if>
            <if test="isDel != null  and isDel != ''">and czrk.is_del = #{isDel}</if>
            <if test="deleteReason != null  and deleteReason != ''">and czrk.delete_reason = #{deleteReason}</if>
            <if test="gridId != null  and gridId != ''">and czrk.grid_id = #{gridId}</if>

            <if test="deptIdList != null and deptIdList.size() > 0">
                and czrk.dept_id in
                <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
            <if test="keyCategory != null  and keyCategory != ''">and  find_in_set(#{keyCategory}, czrk.key_category)</if>

        </where>
        GROUP BY czrk.id ORDER BY czrk.update_time DESC
    </select>

    <select id="listByXz" resultMap="CzrkResult">
        select vi.id, vi.create_time, vi.update_time, vi.is_del, vi.update_by, vi.user_name, vi.phone_num, vi.id_card
        , vi.gender, vi.province, vi.city, vi.region, vi.now_in, vi.house_type, vi.update_by, vi.code,vi.yhzgx
        from czrk vi
        where vi.status = '1' and is_del = 'N' and vi.update_time &gt;= #{startTime} and vi.update_time &lt;= #{endTime}
        <if test="userName != null  and userName != ''">
            and vi.user_name like concat( #{userName}, '%')
        </if>
        <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="province != null  and province != ''">and vi.province = #{province}</if>
        <if test="city != null  and city != ''">and vi.city = #{city}</if>
        <if test="regionId != null  and regionId != ''">and vi.region_id = #{regionId}</if>
        <if test="region != null  and region != ''">and vi.region = #{region}</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="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="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="nowIn != null  and nowIn != ''">and vi.now_in = #{nowIn}</if>
        <if test="gridId != null  and gridId != ''">and vi.grid_id = #{gridId}</if>
        <if test="keyCategory != null  and keyCategory != ''">and  find_in_set(#{keyCategory}, key_category)</if>

    </select>

    <select id="countByCzXz" resultType="int">
        select count(1)
        from czrk vi
        where vi.is_del = 'N' and vi.create_time &gt;= #{startTime} and vi.create_time &lt;= #{endTime}
        <choose>
            <when test="type == 1">and vi.province_id = #{areaId}</when>
            <when test="type == 2">and vi.city_id = #{areaId}</when>
            <when test="type == 3">and vi.region_id = #{areaId}</when>
            <when test="type == 4">and vi.village_towns_id = #{areaId}</when>
            <when test="type == 5">and vi.village_id = #{areaId}</when>
        </choose>
    </select>

    <select id="listByCzXz" resultMap="CzrkResult">
        select vi.id, vi.create_time
        from czrk vi
        where vi.is_del = 'N' and vi.create_time &gt;= #{startTime} and vi.create_time &lt;= #{endTime}
        <choose>
            <when test="type == 1">and vi.province_id = #{areaId}</when>
            <when test="type == 2">and vi.city_id = #{areaId}</when>
            <when test="type == 3">and vi.region_id = #{areaId}</when>
            <when test="type == 4">and vi.village_towns_id = #{areaId}</when>
            <when test="type == 5">and vi.village_id = #{areaId}</when>
        </choose>
    </select>

    <select id="listByJs" resultMap="CzrkResult">
        select vi.id, vi.create_time, vi.update_time, vi.is_del, vi.update_by, vi.user_name, vi.phone_num, vi.id_card
        , vi.gender, vi.province, vi.city, vi.region, vi.now_in, vi.house_type, vi.update_by, vi.code,vi.yhzgx
        from czrk vi
        where vi.status in ('2','3','4') and vi.update_time &gt;= #{startTime} and vi.update_time &lt;= #{endTime}
        <if test="userName != null  and userName != ''">
            and vi.user_name like concat(#{userName}, '%')
        </if>
        <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="province != null  and province != ''">and vi.province = #{province}</if>
        <if test="city != null  and city != ''">and vi.city = #{city}</if>
        <if test="regionId != null  and regionId != ''">and vi.region_id = #{regionId}</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="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="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="nowIn != null  and nowIn != ''">and vi.now_in = #{nowIn}</if>
        <if test="gridId != null  and gridId != ''">and vi.grid_id = #{gridId}</if>
    </select>

    <select id="countByCzJs" resultType="int">
        select count(1)
        from czrk vi
        where vi.is_del = 'Y' and vi.update_time &gt;= #{startTime} and vi.update_time &lt;= #{endTime}
        <choose>
            <when test="type == 1">and vi.province_id = #{areaId}</when>
            <when test="type == 2">and vi.city_id = #{areaId}</when>
            <when test="type == 3">and vi.region_id = #{areaId}</when>
            <when test="type == 4">and vi.village_towns_id = #{areaId}</when>
            <when test="type == 5">and vi.village_id = #{areaId}</when>
        </choose>
    </select>

    <select id="listByCzJs" resultMap="CzrkResult">
        select vi.id, vi.update_time
        from czrk vi
        where vi.is_del = 'Y' and vi.update_time &gt;= #{startTime} and vi.update_time &lt;= #{endTime}
        <choose>
            <when test="type == 1">and vi.province_id = #{areaId}</when>
            <when test="type == 2">and vi.city_id = #{areaId}</when>
            <when test="type == 3">and vi.region_id = #{areaId}</when>
            <when test="type == 4">and vi.village_towns_id = #{areaId}</when>
            <when test="type == 5">and vi.village_id = #{areaId}</when>
        </choose>
    </select>

    <select id="listByCode" resultMap="CzrkResult">
        select vi.id, vi.user_name, vi.phone_num, vi.id_card, vi.gender, vi.province, vi.city,
        vi.region,vi.village_towns,vi.village,vi.villager_group, vi.now_in
        , vi.house_type, vi.update_by, vi.code, vi.rlr, vi.yhzgx
        from czrk vi
        <!--把户主放第一位-->
        where vi.is_del = 'N' and vi.code = #{code} and vi.status = '1' order by house_type desc
    </select>

    <select id="listByCodeSynchronization" resultMap="CzrkResult">
        select vi.id, vi.user_name, vi.phone_num, vi.id_card, vi.gender,
        vi.province_id,vi.province, vi.city_id, vi.city,vi.region_id, vi.region,
        vi.village_towns_id, vi.village_towns, vi.village_id, vi.village, vi.villager_group_id, vi.villager_group,
        vi.now_in, vi.code
        from czrk vi
        <!--把户主放第一位-->
        where vi.is_del = 'N' and vi.code = #{code} and vi.status = '1' order by house_type desc
    </select>


    <select id="countCzrk" resultType="int">
        select count(vi.id)
        from czrk vi
        where vi.is_del = 'N'
        <choose>
            <when test="type == 1">and vi.province_id = #{areaId}</when>
            <when test="type == 2">and vi.city_id = #{areaId}</when>
            <when test="type == 3">and vi.region_id = #{areaId}</when>
            <when test="type == 4">and vi.village_towns_id = #{areaId}</when>
            <when test="type == 5">and vi.village_id = #{areaId}</when>
        </choose>
    </select>

    <select id="countHj1" resultType="int">
        select count(vi.id)
        from czrk vi
        where vi.is_del = 'N'
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and vi.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </select>

    <select id="countCz1" resultType="int">
        SELECT COUNT(DISTINCT(jzdz.id_card)) from czrk_jzdz jzdz
        where jzdz.status = 'Y'
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and jzdz.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </select>

    <select id="countByCzXz1" resultType="int">
        SELECT COUNT(DISTINCT(jzdz.id_card)) from czrk_jzdz jzdz
        where jzdz.status = 'Y' and jzdz.create_time &gt;= #{startTime} and jzdz.create_time &lt;= #{endTime}
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and jzdz.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </select>

    <select id="listByCzXz1" resultType="com.boman.domain.Czrk">
        SELECT ANY_VALUE(jzdz.id_card) idCard,
        ANY_VALUE(jzdz.create_time) createTime from czrk_jzdz jzdz
        where jzdz.status = 'Y' and jzdz.create_time &gt;= #{startTime} and jzdz.create_time &lt;= #{endTime}
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and jzdz.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
        group by jzdz.id_card
    </select>

    <select id="countByCzJs1" resultType="int">
        SELECT count(DISTINCT(jzdz.id_card)) from czrk_jzdz jzdz
        where jzdz.status = 'N' and jzdz.create_time &gt;= #{startTime} and jzdz.create_time &lt;= #{endTime}
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and jzdz.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </select>

    <select id="listByCzJs1" resultType="com.boman.domain.Czrk">
        SELECT ANY_VALUE(id_card) idCard,
        ANY_VALUE(update_time) updateTime from czrk_jzdz jzdz
        where jzdz.status = 'N' and jzdz.update_time &gt;= #{startTime} and jzdz.update_time &lt;= #{endTime}
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and jzdz.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
        group by jzdz.id_card
    </select>

    <select id="countByHjXz1" resultType="int">
        select count(vi.id)
        from czrk vi
        where vi.is_del = 'N' and vi.create_time &gt;= #{startTime} and vi.create_time &lt;= #{endTime}
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and vi.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </select>

    <select id="listByHjXz1" resultMap="CzrkResult">
        select create_time
        from czrk vi
        where vi.is_del = 'N' and vi.create_time &gt;= #{startTime} and vi.create_time &lt;= #{endTime}
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and vi.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </select>

    <select id="countByHjJs1" resultType="int">
        select count(vi.id)
        from czrk vi
        where vi.is_del = 'Y' and vi.update_time &gt;= #{startTime} and vi.update_time &lt;= #{endTime}
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and vi.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </select>

    <select id="listByHjJs1" resultMap="CzrkResult">
        select vi.update_time
        from czrk vi
        where vi.is_del = 'Y' and vi.update_time &gt;= #{startTime} and vi.update_time &lt;= #{endTime}
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and vi.dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </select>

    <select id="selectCzrkById" parameterType="Long" resultMap="CzrkResult">
        <include refid="selectCzrkVo"/>
        where id = #{id} and is_del = 'N' limit 1
    </select>


    <select id="selectCzrkByIds" parameterType="list" resultMap="CzrkResult">
        <include refid="selectCzrkVo"/>
        <if test="ids != null  and ids.size() > 0">
            where id in
            <foreach item="id" collection="ids" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>

    <select id="countIdCard" resultType="int">
        select count(vi.id) from czrk vi where vi.is_del = 'N' and id_card = #{idCard}
    </select>

    <select id="stsByYrl" resultType="int">
        select count(1)
        from czrk c left join czrk_jzdz z on c.id =z.czrk_id
        <where>
            c.is_del = 'N'
            and c.status = '1'
            and c.is_rl = '是'
            <if test="userName != null  and userName != ''">
                and c.user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and c.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and c.age &lt;= #{params.endAge}</if>
            <if test="idCard != null  and idCard != ''">and c.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and c.phone_num = #{phoneNum}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="houseType != null  and houseType != ''">and c.house_type = #{houseType}</if>
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            <if test="villageId != null  and villageId != ''">and c.village_id = #{villageId}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="provinceIdXjd != null and provinceIdXjd != ''">and z.province_id = #{provinceIdXjd}</if>
            <if test="cityIdXjd != null and cityIdXjd != ''">and z.city_id = #{cityIdXjd}</if>
            <if test="regionIdXjd != null and regionIdXjd != ''">and z.region_id = #{regionIdXjd}</if>
            <if test="villageTownsIdXjd != null and villageTownsIdXjd != ''">and z.town_id = #{villageTownsIdXjd}</if>
            <if test="villageIdXjd != null and villageIdXjd != ''">and z.village_id = #{villageIdXjd}</if>
        </where>
    </select>

    <select id="listIsRl" resultMap="CzrkResult">
        SELECT id, is_rl
        from czrk
        where is_del = 'N'
        <if test="idCard != null  and idCard != ''">
            and id_card like concat(#{idCard}, '%')
        </if>
        <choose>
            <when test="type == 1">and province_id = #{areaId}</when>
            <when test="type == 2">and city_id = #{areaId}</when>
            <when test="type == 3">and region_id = #{areaId}</when>
            <when test="type == 4">and village_towns_id = #{areaId}</when>
            <when test="type == 5">and village_id = #{areaId}</when>
        </choose>
    </select>

    <select id="getHzByCode" resultMap="CzrkResult">
        SELECT user_name, id_card
        from czrk
        where house_type = '是' and code = #{code} and is_del = 'N' limit 1;
    </select>

    <select id="getColumnNamesByIdCard" resultType="com.alibaba.fastjson.JSONObject">
        SELECT id, ${columnNames}
        from czrk
        where id_card = #{idCard} limit 1;
    </select>

    <select id="stsByWrl" resultType="int">
        select count(1)
        from czrk c  left join czrk_jzdz z on c.id = z.czrk_id
        <where>
            c.is_del = 'N'
            and c.is_rl = '否'
            and c.status = '1'
            <if test="userName != null  and userName != ''">
                and c.user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and c.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and c.age &lt;= #{params.endAge}</if>
            <if test="idCard != null  and idCard != ''">and c.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and c.phone_num = #{phoneNum}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            <if test="villageId != null  and villageId != ''">and c.village_id = #{villageId}</if>
            <if test="provinceIdXjd != null and provinceIdXjd != ''">and z.province_id = #{provinceIdXjd}</if>
            <if test="cityIdXjd != null and cityIdXjd != ''">and z.city_id = #{cityIdXjd}</if>
            <if test="regionIdXjd != null and regionIdXjd != ''">and z.region_id = #{regionIdXjd}</if>
            <if test="villageTownsIdXjd != null and villageTownsIdXjd != ''">and z.town_id = #{villageTownsIdXjd}</if>
            <if test="villageIdXjd != null and villageIdXjd != ''">and z.village_id = #{villageIdXjd}</if>
        </where>
    </select>
    <select id="stsByAll" resultType="int">
        select count(1)
        from czrk c left join czrk_jzdz z on c.id =z.czrk_id
        <where>
            c.is_del = 'N'
            and c.status = '1'
            <if test="isRl != null and isRl != ''">and c.is_rl = #{isRl}</if>
            <if test="userName != null  and userName != ''">
                and c.user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and c.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and c.age &lt;= #{params.endAge}</if>
            <if test="idCard != null  and idCard != ''">and c.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and c.phone_num = #{phoneNum}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="houseType != null  and houseType != ''">and c.house_type = #{houseType}</if>
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            <if test="villageId != null  and villageId != ''">and c.village_id = #{villageId}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="provinceIdXjd != null and provinceIdXjd != ''">and z.province_id = #{provinceIdXjd}</if>
            <if test="cityIdXjd != null and cityIdXjd != ''">and z.city_id = #{cityIdXjd}</if>
            <if test="regionIdXjd != null and regionIdXjd != ''">and z.region_id = #{regionIdXjd}</if>
            <if test="villageTownsIdXjd != null and villageTownsIdXjd != ''">and z.town_id = #{villageTownsIdXjd}</if>
            <if test="villageIdXjd != null and villageIdXjd != ''">and z.village_id = #{villageIdXjd}</if>
        </where>
    </select>


    <insert id="insertCzrk" useGeneratedKeys="true" keyProperty="id">
        insert into czrk
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userName != null">user_name,</if>
            <if test="gender != null">gender,</if>
            <if test="age != null">age,</if>
            <if test="birthday != null">birthday,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="idCard != null">id_card,</if>
            <if test="phoneNum != null">phone_num,</if>
            <if test="code != null">code,</if>
            <if test="keyIndustries != null">key_Industries,</if>
            <if test="keyCategory != null and keyCategory != ''">key_category,</if>
            <if test="houseType != null">house_type,</if>
            <if test="rlr != null">rlr,</if>
            <if test="isRl != null">is_rl,</if>
            <if test="rlTime != null">rl_time,</if>
            <if test="yhzgx != null">yhzgx,</if>
            <if test="workUnit != null">work_unit,</if>
            <if test="provinceId != null">province_id,</if>
            <if test="province != null">province,</if>
            <if test="cityId != null">city_id,</if>
            <if test="city != null">city,</if>
            <if test="regionId != null">region_id,</if>
            <if test="region != null">region,</if>
            <if test="villageTownsId != null">village_towns_id,</if>
            <if test="villageTowns != null">village_towns,</if>
            <if test="villageId != null">village_id,</if>
            <if test="village != null">village,</if>
            <if test="villagerGroupId != null">villager_group_id,</if>
            <if test="villagerGroup != null">villager_group,</if>
            <if test="nowIn != null">now_in,</if>
            <if test="remark != null">remark,</if>
            <if test="gridId != null">grid_id,</if>
            <if test="gridName != null">grid_name,</if>
            <if test="status != null">status,</if>
            <if test="isConfirm != null">is_confirm,</if>
            <if test="confirmInfoUser != null and confirmInfoUser != ''">confirm_info_user,</if>
            <if test="confirmInfoUserTime != null ">confirm_info_user_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="isDel != null and isDel != ''">is_del,</if>
            <if test="deleteReason != null">delete_reason,</if>
            create_time, update_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userName != null">#{userName},</if>
            <if test="gender != null">#{gender},</if>
            <if test="age != null">#{age},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="phoneNum != null">#{phoneNum},</if>
            <if test="code != null">#{code},</if>
            <if test="keyIndustries != null">#{keyIndustries},</if>
            <if test="keyCategory != null and keyCategory != ''">#{keyCategory},</if>
            <if test="houseType != null">#{houseType},</if>
            <if test="rlr != null">#{rlr},</if>
            <if test="isRl != null">#{isRl},</if>
            <if test="rlTime != null">#{rlTime},</if>
            <if test="yhzgx != null">#{yhzgx},</if>
            <if test="workUnit != null">#{workUnit},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="province != null">#{province},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="city != null">#{city},</if>
            <if test="regionId != null">#{regionId},</if>
            <if test="region != null">#{region},</if>
            <if test="villageTownsId != null">#{villageTownsId},</if>
            <if test="villageTowns != null">#{villageTowns},</if>
            <if test="villageId != null">#{villageId},</if>
            <if test="village != null">#{village},</if>
            <if test="villagerGroupId != null">#{villagerGroupId},</if>
            <if test="villagerGroup != null">#{villagerGroup},</if>
            <if test="nowIn != null">#{nowIn},</if>
            <if test="remark != null">#{remark},</if>
            <if test="gridId != null">#{gridId},</if>
            <if test="gridName != null">#{gridName},</if>
            <if test="status != null">#{status},</if>
            <if test="isConfirm != null">#{isConfirm},</if>
            <if test="confirmInfoUser != null and confirmInfoUser != ''">#{confirmInfoUser},</if>
            <if test="confirmInfoUserTime != null ">#{confirmInfoUserTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="isDel != null and isDel != ''">#{isDel},</if>
            <if test="deleteReason != null">#{deleteReason},</if>
            sysdate(), sysdate()
        </trim>
    </insert>

    <update id="updateCzrk">
        update czrk
        <trim prefix="SET" suffixOverrides=",">
            <if test="userName != null">user_name = #{userName},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="age != null">age = #{age},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="phoneNum != null">phone_num = #{phoneNum},</if>
            <if test="code != null">code = #{code},</if>
            <if test="keyIndustries != null">key_industries = #{keyIndustries},</if>
            <if test="keyCategory != null and keyCategory != ''">key_category = #{keyCategory},</if>
            <if test="houseType != null">house_type = #{houseType},</if>
            <if test="rlr != null">rlr = #{rlr},</if>
            <if test="rlrNike != null">rlr_nike = #{rlrNike},</if>
            <if test="isRl != null">is_rl = #{isRl},</if>
            <if test="rlTime != null">rl_time = #{rlTime},</if>
            <if test="yhzgx != null">yhzgx = #{yhzgx},</if>
            <if test="workUnit != null">work_unit = #{workUnit},</if>
            <if test="provinceId != ''">province_id = #{provinceId},</if>
            <if test="province != ''">province = #{province},</if>
            <if test="cityId != ''">city_id = #{cityId},</if>
            <if test="city != ''">city = #{city},</if>
            <if test="regionId != ''">region_id = #{regionId},</if>
            <if test="region != ''">region = #{region},</if>
            <if test="villageTownsId != ''">village_towns_id = #{villageTownsId},</if>
            <if test="villageTowns != ''">village_towns = #{villageTowns},</if>
            <if test="villageId != ''">village_id = #{villageId},</if>
            <if test="village != ''">village = #{village},</if>
            <if test="villagerGroupId != ''">villager_group_id = #{villagerGroupId},</if>
            <if test="villagerGroup != ''">villager_group = #{villagerGroup},</if>
            <if test="nowIn != null">now_in = #{nowIn},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="gridId != null">grid_id = #{gridId},</if>
            <if test="gridName != null">grid_name = #{gridName},</if>
            <if test="changUser != null">chang_user = #{changUser},</if>
            <if test="changNikeUser != null">chang_nike_user = #{changNikeUser},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isConfirm != null">is_confirm = #{isConfirm},</if>
            <if test="confirmInfoUser != null ">confirm_info_user = #{confirmInfoUser},</if>
            <if test="confirmInfoNikeUser != null">confirm_info_nike_user =
                #{confirmInfoNikeUser},
            </if>
            <if test="confirmInfoUserTime != null ">confirm_info_user_time = #{confirmInfoUserTime},</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="isDel != null and isDel != ''">is_del = #{isDel},</if>
            <if test="deleteReason != null">delete_reason = #{deleteReason},</if>
            update_time = sysdate(),
            chang_user_time = #{changUserTime}
        </trim>
        where id = #{id}
    </update>

    <update id="updateCzrkByNucleicAcid">
        update czrk
        set is_nucleicAcid = 'Y',nucleicAcid_time = #{nucleicAcidTime}
        where id_card = #{idCard}
    </update>

    <delete id="deleteCzrkById" parameterType="Long">
        delete from czrk where id = #{id}
    </delete>

    <update id="reduction">
        update czrk
        set is_del        = 'N'
          , update_by     = #{updateBy}
          , update_time   = sysdate()
          ,delete_reason = ''
        where id = #{id}
    </update>

    <!--    <delete id="deleteCzrk" parameterType="String">-->
    <!--        delete from czrk where id in -->
    <!--        <foreach item="id" collection="array" open="(" separator="," close=")">-->
    <!--            #{id}-->
    <!--        </foreach>-->
    <!--    </delete>-->

    <update id="deleteCzrk">
        update czrk
        set is_del        = 'Y'
          , delete_reason = #{deleteReason}
          , update_by     = #{updateBy}
          , update_time   = sysdate()
        where id = #{id}
    </update>

    <update id="updateHouseholdRegister">
        update czrk
        set province_id = #{czrk.provinceId},
            province = #{czrk.province},
            city_id = #{czrk.cityId},
            city = #{czrk.city},
            region_id = #{czrk.regionId},
            region = #{czrk.region},
            village_towns_id = #{czrk.villageTownsId},
            village_towns = #{czrk.villageTowns},
            village_id = #{czrk.villageId},
            village = #{czrk.village},
            villager_group_id = #{czrk.villagerGroupId},
            villager_group = #{czrk.villagerGroup},
            now_in = #{czrk.nowIn}
        where is_del = 'N' and code = #{czrk.code};
    </update>

    <select id="findHjInfo" resultMap="CzrkResult">
        select c.id, c.user_name ,c.gender,
        c.birthday,c.age,c.code,c.phone_num,c.key_industries,c.key_category,c.province_id,c.province,c.city_id,c.city,c.region_id,c.region,c.village_towns_id,c.village_towns,c.village_id,c.village,c.villager_group_id,c.villager_group,
        c.now_in,c.house_type,c.code,c.yhzgx,c.remark,
        cj.province_id as province_id_jzdz,cj.province as province_jzdz,cj.city_id as city_id_jzdz,cj.city as
        city_jzdz,cj.region_id as region_id_jzdz,cj.region as region_jzdz,cj.town_id as town_id_jzdz,cj.town as
        town_jzdz,cj.village_id as village_id_jzdz,cj.village as village_jzdz,cj.now_in as now_in_jzdz
        from czrk c left join czrk_jzdz cj on c.id_card = cj.id_card
        <where>
            c.is_del = 'N'
            and cj.status = 'Y'
            <if test="idCard != null and idCard != '' ">and c.id_card = #{idCard}</if>
        </where>
    </select>

    <select id="stsByAppletCz" resultMap="CzrkResult">
        SELECT
        czrk.id,
        czrk.is_rl
        from czrk
        left join czrk_jzdz jzdz on czrk.id = jzdz.czrk_id
        <where>
            czrk.is_del = 'N' and jzdz.status = 'Y'
            <if test="idCard != null  and idCard != ''">
                and czrk.id_card = #{idCard}
            </if>
            <if test="houseType != null  and houseType != ''">
                and czrk.house_type = #{houseType}
            </if>
            <if test="isConfirm != null  and isConfirm != ''">
                and czrk.is_confirm = #{isConfirm}
            </if>
            <if test="userName != null  and userName != ''">
                and czrk.user_name like concat(#{userName}, '%')
            </if>
            <choose>
                <when test="type == 1">and jzdz.province_id = #{areaId}</when>
                <when test="type == 2">and jzdz.city_id = #{areaId}</when>
                <when test="type == 3">and jzdz.region_id = #{areaId}</when>
                <when test="type == 4">and jzdz.town_id = #{areaId}</when>
                <when test="type == 5">and jzdz.village_id = #{areaId}</when>
            </choose>

            <!-- <if test="provinceIdXjd != null  and provinceIdXjd != ''"> and jzdz.province_id = #{areaId}</if>
             <if test="cityIdXjd != null  and cityIdXjd != ''"> and jzdz.city_id = #{areaId}</if>
             <if test="regionIdXjd != null  and regionIdXjd != ''"> and jzdz.region_id = #{areaId}</if>
             <if test="villageTownsIdXjd != null  and villageTownsIdXjd != ''"> and jzdz.town_id = #{areaId}</if>
             <if test="villageIdXjd != null  and villageIdXjd != ''"> and jzdz.village_id = #{areaId}</if>-->

            <!-- <if test="provinceId != null  and provinceId != ''"> and czrk.province_id = #{areaId}</if>
             <if test="cityId != null  and cityId != ''"> and czrk.city_id = #{areaId}</if>
             <if test="regionId != null  and regionId != ''"> and czrk.region_id = #{areaId}</if>
             <if test="villageTownsId != null  and villageTownsId != ''"> and czrk.village_towns_id = #{areaId}</if>
             <if test="villageId != null  and villageId != ''"> and czrk.village_id = #{areaId}</if>
             <if test="villagerGroupId != null  and villagerGroupId != ''"> and czrk.villager_group_id = #{villagerGroupId}</if>-->
        </where>
        GROUP BY czrk.id
    </select>

    <select id="countByHjXz" resultType="int">
        SELECT COUNT(DISTINCT(jzdz.id_card)) from czrk_jzdz jzdz
        where jzdz.status = 'Y' and jzdz.create_time &gt;= #{startTime} and jzdz.create_time &lt;= #{endTime}
        <!--SELECT czrk.id, czrk.create_time
        from czrk
        left join czrk_jzdz jzdz on czrk.id = jzdz.czrk_id
        where czrk.is_del = 'N'
        <if test="userName != null  and userName != ''">
            and (czrk.user_name like concat('%', #{userName}, '%') or czrk.id_card like concat('%', #{userName}, '%'))
        </if>-->

        <choose>
            <when test="type == 1">and jzdz.province_id = #{areaId}</when>
            <when test="type == 2">and jzdz.city_id = #{areaId}</when>
            <when test="type == 3">and jzdz.region_id = #{areaId}</when>
            <when test="type == 4">and jzdz.town_id = #{areaId}</when>
            <when test="type == 5">and jzdz.village_id = #{areaId}</when>
        </choose>
        <!--GROUP BY czrk.id-->
    </select>

    <select id="listByHjXz" resultMap="CzrkResult">
        SELECT czrk.id, czrk.create_time
        where czrk.is_del = 'N' and czrk.create_time &gt;= #{startTime} and czrk.create_time &lt;= #{endTime}
        <!-- <if test="userName != null  and userName != ''">
            and (czrk.user_name like concat('%', #{userName}, '%') or czrk.id_card like concat('%', #{userName}, '%'))
        </if>-->

        <choose>
            <when test="type == 1">and jzdz.province_id = #{areaId}</when>
            <when test="type == 2">and jzdz.city_id = #{areaId}</when>
            <when test="type == 3">and jzdz.region_id = #{areaId}</when>
            <when test="type == 4">and jzdz.town_id = #{areaId}</when>
            <when test="type == 5">and jzdz.village_id = #{areaId}</when>
        </choose>
        GROUP BY czrk.id
    </select>

    <select id="countByHjJs" resultType="int">
        SELECT COUNT(DISTINCT(jzdz.id_card)) from czrk_jzdz jzdz
        where jzdz.status = 'N' and jzdz.update_time &gt;= #{startTime} and jzdz.update_time &lt;= #{endTime}
        <!-- SELECT czrk.id, czrk.update_time
         from czrk
         left join czrk_jzdz jzdz on czrk.id = jzdz.czrk_id
         where czrk.is_del = 'Y' and czrk.update_time &gt;= #{startTime} and czrk.update_time &lt;= #{endTime}
         <if test="userName != null  and userName != ''">
             and (czrk.user_name like concat('%', #{userName}, '%') or czrk.id_card like concat('%', #{userName}, '%'))
         </if>-->

        <choose>
            <when test="type == 1">and jzdz.province_id = #{areaId}</when>
            <when test="type == 2">and jzdz.city_id = #{areaId}</when>
            <when test="type == 3">and jzdz.region_id = #{areaId}</when>
            <when test="type == 4">and jzdz.town_id = #{areaId}</when>
            <when test="type == 5">and jzdz.village_id = #{areaId}</when>
        </choose>
        <!--GROUP BY czrk.id-->
    </select>

    <select id="listByHjJs" resultMap="CzrkResult">
        SELECT czrk.id, czrk.update_time
        from czrk
        left join czrk_jzdz jzdz on czrk.id = jzdz.czrk_id
        where czrk.is_del = 'Y' and czrk.update_time &gt;= #{startTime} and czrk.update_time &lt;= #{endTime}
        <!-- <if test="userName != null  and userName != ''">
             and (czrk.user_name like concat('%', #{userName}, '%') or czrk.id_card like concat('%', #{userName}, '%'))
         </if>-->
        <choose>
            <when test="type == 1">and jzdz.province_id = #{areaId}</when>
            <when test="type == 2">and jzdz.city_id = #{areaId}</when>
            <when test="type == 3">and jzdz.region_id = #{areaId}</when>
            <when test="type == 4">and jzdz.town_id = #{areaId}</when>
            <when test="type == 5">and jzdz.village_id = #{areaId}</when>
        </choose>
        GROUP BY czrk.id
    </select>

    <select id="countHj" resultType="int">
        SELECT COUNT(DISTINCT(jzdz.id_card)) from czrk_jzdz jzdz where jzdz.status = 'Y'
        <!-- SELECT czrk.id
         from czrk
         left join czrk_jzdz jzdz on czrk.id = jzdz.czrk_id
         where czrk.is_del = 'N'
         <if test="userName != null  and userName != ''">
             and (czrk.user_name like concat('%', #{userName}, '%') or czrk.id_card like concat('%', #{userName}, '%'))
         </if>-->

        <choose>
            <when test="type == 1">and jzdz.province_id = #{areaId}</when>
            <when test="type == 2">and jzdz.city_id = #{areaId}</when>
            <when test="type == 3">and jzdz.region_id = #{areaId}</when>
            <when test="type == 4">and jzdz.town_id = #{areaId}</when>
            <when test="type == 5">and jzdz.village_id = #{areaId}</when>
        </choose>
        <!--GROUP BY czrk.id-->
    </select>

    <select id="countAll" resultType="int">
        select count(1) from czrk where is_del = 'N';
    </select>

    <select id="selectCzrkListByPage" parameterType="Integer" resultMap="CzrkResult">
        select * from czrk where village_id = '' and  village_towns_id != '' and dept_id != 1 limit   #{startNum}, #{endNum}
    </select>


    <select id="selectDeptNameById" parameterType="Long" resultMap="SysDeptResult">
        select *  from sys_dept where id = #{id} limit 1;
    </select>

    <update id="confirmInfoByIds">
        update czrk
        <trim prefix="SET" suffixOverrides=",">
            is_confirm = 'Y'
        </trim>
        where id in
        <foreach collection="czrkList" item="czrk" open="(" separator="," close=")">
            #{czrk.id}
        </foreach>
    </update>


    <update id="updateCzrkHs">
        <foreach collection="czrkList" item="czrk" index="index" open="" close="" separator=";">
            update czrk
            <set>
                is_nucleicAcid= 'Y',
                nucleicAcid_time = ${czrk.nucleicAcidTime}
            </set>
            where id_card = ${czrk.idCard}
        </foreach>
    </update>


    <insert id="insertConfirmInfoUser" useGeneratedKeys="true" keyProperty="id">
        insert into confim_info_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="confirmInfoUser != null">confirm_info_user,</if>
            <if test="confirmInfoNikeUser != null">confirm_info_nike_user,</if>
            <if test="czrkId != null">czrk_id,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="confirmInfoUser != null">#{confirmInfoUser},</if>
            <if test="confirmInfoNikeUser != null">#{confirmInfoNikeUser},</if>
            <if test="czrkId != null">#{czrkId},</if>
            sysdate()
        </trim>
    </insert>


    <select id="selectCzrkByCode" resultType="java.lang.Integer" resultMap="CzrkResult">
       select id_card from czrk where is_del = 'N' and code = #{code} and house_type = '是' limit 1
    </select>


    <update id="changeCzrk" parameterType="com.boman.domain.Czrk">
                update czrk
        set status = #{status},
            chang_user = #{changUser},
            house_type = #{houseType},
            chang_nike_user = #{changNikeUser},
            chang_user_time = sysdate(),
            update_time = sysdate()
        where  id = #{id};
    </update>

    <select id="selectCzrkByIdCard" resultType="java.lang.String" resultMap="CzrkResult">
        <include refid="selectCzrkVo"/>
        where is_del = 'N' and id_card = #{idCard} limit 1
    </select>

    <select id="selectLost" resultMap="CzrkResult">
        <include refid="selectCzrkVo"/>
        where is_confirm = 'Y' and (village_towns is null or village_towns = '') and is_del ='N'
    </select>

    <select id="unusualList" resultMap="CzrkResult">
        select id, user_name, phone_num,dept_id, id_card, province, city, region, village_towns, village,
        villager_group,status, house_type,chang_user,chang_nike_user,chang_user_time from czrk
        <where>
            <if test="userName != null  and userName != ''">
                and user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and age &lt;= #{params.endAge}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="age != null ">and age = #{age}</if>
            <if test="idCard != null  and idCard != ''">and id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and phone_num = #{phoneNum}</if>
            <if test="provinceId != null  and provinceId != ''">and province_id = #{provinceId}</if>
            <if test="province != null  and province != ''">and province = #{province}</if>
            <if test="cityId != null  and cityId != ''">and city_id = #{cityId}</if>
            <if test="city != null  and city != ''">and city = #{city}</if>
            <if test="regionId != null  and regionId != ''">and region_id = #{regionId}</if>
            <if test="region != null  and region != ''">and region = #{region}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and village_towns_id = #{villageTownsId}</if>
            <if test="villageTowns != null  and villageTowns != ''">and village_towns = #{villageTowns}</if>
            <if test="villageId != null  and villageId != ''">and village_id = #{villageId}</if>
            <if test="village != null  and village != ''">and village = #{village}</if>
            <if test="isConfirm != null  and isConfirm != ''">and is_confirm = #{isConfirm}</if>
            <if test="isDel != null  and isDel != ''">and is_del = #{isDel}</if>
        </where>
        order by chang_user_time DESC
    </select>
    <select id="selectCzrkListByDeptId" resultMap="CzrkResult">
        select id, dept_id, create_time, is_del from czrk
        where 1=1
        <if test="deptIdList != null  and deptIdList.size() > 0">
            and dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </select>

    <select id="getAllCzrkRegionIdHj" resultMap="CzrkResult">
        select c.id, c.dept_id, c.region_id, c.region, c.village_towns_id, c.village_towns
                , c.village_id, c.village, c.create_time, c.update_time, c.is_del,c.status, c.is_nucleicAcid
        from czrk c
        where c.region_id = #{regionId} and c.is_del = 'N';
    </select>

    <select id="getAllCzrkRegionId" resultMap="CzrkResult">
        select c.id, c.dept_id, cj.region_id as regionIdXjd, cj.region as regionXjd, cj.town_id as villageTownsIdXjd, cj.town as villageTownsXjd
             , cj.village_id as villageIdXjd, cj.village as villageXjd, c.create_time, c.update_time, c.is_del,c.status, c.is_nucleicAcid
        from czrk c
        left join czrk_jzdz cj on c.id =cj.czrk_id
        where cj.region_id = #{regionId} and c.is_del = 'N';
    </select>


    <select id="getAllCzrkVillageTownsId" resultMap="CzrkResult">
        select c.id, c.dept_id, c.region_id, c.region, c.village_towns_id, c.village_towns
             , c.village_id, c.village, c.create_time, c.update_time, c.is_del,c.status, c.is_nucleicAcid
        from czrk c
        left join czrk_jzdz cj on c.id =cj.czrk_id
        where cj.town_id = #{areaId} and c.is_del = 'N';
    </select>


    <select id="getAllCzrkVillageId" resultMap="CzrkResult">
        select id, dept_id, region_id, region, village_towns_id, village_towns
             , village_id, village, create_time, update_time, is_del,status, is_nucleicAcid from czrk
        where village_id = #{areaId} and is_del = 'N';
    </select>


    <select id="getAllCzrk" resultMap="CzrkResult">
        select
        ANY_VALUE(c.user_name) as user_name,
        ANY_VALUE(c.is_nucleicAcid) as is_nucleicAcid,
        ANY_VALUE(c.nucleicAcid_time) as nucleicAcid_time,
        ANY_VALUE(c.age) as age,
        <!--ANY_VALUE(STUFF (c.id_card, 7, 8, '********')) AS id_card,-->
        ANY_VALUE(c.id_card) AS id_card,
        ANY_VALUE(c.province) as province,
        ANY_VALUE(c.city) as city,
        ANY_VALUE(c.region) as region,
        ANY_VALUE(c.village_towns) as village_towns,
        ANY_VALUE(c.village) as village,
        ANY_VALUE(c.villager_group) as villager_group,
        ANY_VALUE(REPLACE (c.now_in, '/', '')) AS now_in,
        ANY_VALUE(c.key_industries) as key_industries,
        ANY_VALUE(c.gender) as gender,
        ANY_VALUE(c.phone_num) as phone_num,
        ANY_VALUE(c.CODE) as CODE,
        ANY_VALUE(c.house_type) as house_type,
        ANY_VALUE(c.yhzgx) as yhzgx,
        ANY_VALUE(cj.province) AS provinceXjd,
        ANY_VALUE(cj.city) AS cityXjd,
        ANY_VALUE(cj.region) AS regionXjd,
        ANY_VALUE(cj.town) AS villageTownsXjd,
        ANY_VALUE(cj.village) AS villageXjd,
        ANY_VALUE(REPLACE (cj.now_in, '/', '')) AS nowXjd
        from czrk c
        left join czrk_jzdz cj on c.id =cj.czrk_id
        <where>
            c.is_del = 'N'
            and c.status = '1'
            <!-- 已认领 -->
            <if test="isRl != null and isRl != ''">and c.is_rl = #{isRl}</if>

            <if test="userName != null  and userName != ''">
                and c.user_name like concat(#{userName}, '%')
            </if>
            <if test="isNucleicAcid != null and isNucleicAcid != ''">and c.is_nucleicAcid = #{isNucleicAcid}</if>
            <if test="params.startAge != null  and params.startAge != ''">and c.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and c.age &lt;= #{params.endAge}</if>
            <if test="gender != null  and gender != ''">and c.gender = #{gender}</if>
            <if test="birthday != null ">and c.birthday = #{birthday}</if>
            <if test="idCard != null  and idCard != ''">and c.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and c.phone_num = #{phoneNum}</if>
            <if test="code != null  and code != ''">and c.code = #{code}</if>
            <if test="houseType != null  and houseType != ''">and c.house_type = #{houseType}</if>
            <if test="rlr != null  and rlr != ''">and c.rlr = #{rlr}</if>
            <if test="rlTime != null ">and c.rl_time = #{rlTime}</if>
            <if test="yhzgx != null  and yhzgx != ''">and c.yhzgx = #{yhzgx}</if>
            <if test="workUnit != null  and workUnit != ''">and c.work_unit = #{workUnit}</if>
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="province != null  and province != ''">and c.province = #{province}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="city != null  and city != ''">and c.city = #{city}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="region != null  and region != ''">and c.region = #{region}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            <if test="villageTowns != null  and villageTowns != ''">and c.village_towns = #{villageTowns}</if>
            <if test="villageId != null  and villageId != ''">and c.village_id = #{villageId}</if>
            <if test="village != null  and village != ''">and c.village = #{village}</if>
            <!--    <if test="villagerGroupId != null  and villagerGroupId != ''"> and villager_group_id = #{villagerGroupId}</if>
                <if test="villagerGroup != null  and villagerGroup != ''"> and villager_group = #{villagerGroup}</if>-->
            <if test="nowIn != null  and nowIn != ''">and c.now_in = #{nowIn}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="deleteReason != null  and deleteReason != ''">and c.delete_reason = #{deleteReason}</if>
            <if test="gridId != null  and gridId != ''">and c.grid_id = #{gridId}</if>
            <if test="deptIdList != null and deptIdList.size() > 0">
                and c.dept_id in
                <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
            <if test="idCardList != null and idCardList.size() > 0">
                and c.id_card in
                <foreach item="idCard" collection="idCardList" open="(" separator="," close=")">
                    #{idCard}
                </foreach>
            </if>
            <if test="provinceIdXjd != null">and cj.province_id = #{provinceIdXjd}</if>
            <if test="cityIdXjd != null">and cj.city_id = #{cityIdXjd}</if>
            <if test="regionIdXjd != null">and cj.region_id = #{regionIdXjd}</if>
            <if test="villageTownsIdXjd != null">and cj.town_id = #{villageTownsIdXjd}</if>
            <if test="villageIdXjd != null">and cj.village_id = #{villageIdXjd}</if>
        </where>
        order by c.code ,c.house_type desc,c.id_card;
    </select>




    <select id="getAllCzrkHjVillage" resultMap="CzrkResult">
        select
        ANY_VALUE(c.user_name) as user_name,
        ANY_VALUE(c.is_nucleicAcid) as is_nucleicAcid,
        ANY_VALUE(c.nucleicAcid_time) as nucleicAcid_time,
        ANY_VALUE(c.age) as age,
        <!--ANY_VALUE(STUFF (c.id_card, 7, 8, '********')) AS id_card,-->
        ANY_VALUE(c.id_card) AS id_card,
        ANY_VALUE(c.province) as province,
        ANY_VALUE(c.city) as city,
        ANY_VALUE(c.region) as region,
        ANY_VALUE(c.village_towns) as village_towns,
        ANY_VALUE(c.village) as village,
        ANY_VALUE(c.villager_group) as villager_group,
        ANY_VALUE(REPLACE (c.now_in, '/', '')) AS now_in,
        ANY_VALUE(c.key_industries) as key_industries,
        ANY_VALUE(c.gender) as gender,
        ANY_VALUE(c.phone_num) as phone_num,
        ANY_VALUE(c.CODE) as CODE,
        ANY_VALUE(c.house_type) as house_type,
        ANY_VALUE(c.yhzgx) as yhzgx,
        ANY_VALUE(cj.province) AS provinceXjd,
        ANY_VALUE(cj.city) AS cityXjd,
        ANY_VALUE(cj.region) AS regionXjd,
        ANY_VALUE(cj.town) AS villageTownsXjd,
        ANY_VALUE(cj.village) AS villageXjd,
        ANY_VALUE(REPLACE (cj.now_in, '/', '')) AS nowXjd
        from czrk c
        left join czrk_jzdz cj on c.id =cj.czrk_id
        <where>
            c.is_del = 'N'
            and c.status = '1'
            <!-- 已认领 -->
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            and (c.village_id = '' or c.village_id = '0' or c.village_id is null)
        </where>
        order by c.code ,c.house_type desc,c.id_card;
    </select>


    <select id="getAllCzrkNoTownCz" resultMap="CzrkResult">
        select
        ANY_VALUE(c.user_name) as user_name,
        ANY_VALUE(c.is_nucleicAcid) as is_nucleicAcid,
        ANY_VALUE(c.nucleicAcid_time) as nucleicAcid_time,
        ANY_VALUE(c.age) as age,
        <!--ANY_VALUE(STUFF (c.id_card, 7, 8, '********')) AS id_card,-->
        ANY_VALUE(c.id_card) AS id_card,
        ANY_VALUE(c.province) as province,
        ANY_VALUE(c.city) as city,
        ANY_VALUE(c.region) as region,
        ANY_VALUE(c.village_towns) as village_towns,
        ANY_VALUE(c.village) as village,
        ANY_VALUE(c.villager_group) as villager_group,
        ANY_VALUE(REPLACE (c.now_in, '/', '')) AS now_in,
        ANY_VALUE(c.key_industries) as key_industries,
        ANY_VALUE(c.gender) as gender,
        ANY_VALUE(c.phone_num) as phone_num,
        ANY_VALUE(c.CODE) as CODE,
        ANY_VALUE(c.house_type) as house_type,
        ANY_VALUE(c.yhzgx) as yhzgx,
        ANY_VALUE(cj.province) AS provinceXjd,
        ANY_VALUE(cj.city) AS cityXjd,
        ANY_VALUE(cj.region) AS regionXjd,
        ANY_VALUE(cj.town) AS villageTownsXjd,
        ANY_VALUE(cj.village) AS villageXjd,
        ANY_VALUE(REPLACE (cj.now_in, '/', '')) AS nowXjd
        from czrk c
        left join czrk_jzdz cj on c.id =cj.czrk_id
        <where>
            c.is_del = 'N'
            and c.status = '1'
            <!-- 已认领 -->
            and cj.region_id = '340882000000'
            and (cj.town_id = '' or cj.town_id = '0')
        </where>
        order by c.code ,c.house_type desc,c.id_card;
    </select>


    <select id="getAllCzrkNoTown" resultMap="CzrkResult">
        select
        ANY_VALUE(c.user_name) as user_name,
        ANY_VALUE(c.is_nucleicAcid) as is_nucleicAcid,
        ANY_VALUE(c.nucleicAcid_time) as nucleicAcid_time,
        ANY_VALUE(c.age) as age,
        <!--ANY_VALUE(STUFF (c.id_card, 7, 8, '********')) AS id_card,-->
        ANY_VALUE(c.id_card) AS id_card,
        ANY_VALUE(c.province) as province,
        ANY_VALUE(c.city) as city,
        ANY_VALUE(c.region) as region,
        ANY_VALUE(c.village_towns) as village_towns,
        ANY_VALUE(c.village) as village,
        ANY_VALUE(c.villager_group) as villager_group,
        ANY_VALUE(REPLACE (c.now_in, '/', '')) AS now_in,
        ANY_VALUE(c.key_industries) as key_industries,
        ANY_VALUE(c.gender) as gender,
        ANY_VALUE(c.phone_num) as phone_num,
        ANY_VALUE(c.CODE) as CODE,
        ANY_VALUE(c.house_type) as house_type,
        ANY_VALUE(c.yhzgx) as yhzgx,
        ANY_VALUE(cj.province) AS provinceXjd,
        ANY_VALUE(cj.city) AS cityXjd,
        ANY_VALUE(cj.region) AS regionXjd,
        ANY_VALUE(cj.town) AS villageTownsXjd,
        ANY_VALUE(cj.village) AS villageXjd,
        ANY_VALUE(REPLACE (cj.now_in, '/', '')) AS nowXjd
        from czrk c
        left join czrk_jzdz cj on c.id =cj.czrk_id
        <where>
            c.is_del = 'N'
            and c.status = '1'
            <!-- 已认领 -->
            and c.region_id = '340882000000'
            and (c.village_towns_id = '' or c.village_towns_id = '0')
        </where>
        order by c.code ,c.house_type desc,c.id_card;
    </select>




    <select id="listByCzrkJzdz" resultMap="CzrkResult">
        select c.id, c.user_name, c.phone_num,c.dept_id, c.id_card,
        z.province as provinceXjd, z.city as cityXjd,z.region as regionXjd, z.town as villageTownsXjd, z.village as
        villageXjd,z.now_in,z.villager_group_id as villagerGroupIdJz,z.villager_group as villagerGroupJz,z.grid_id as gridIdJz,z.grid_name as gridNameJz,
        c.gender, c.grid_id, c.house_type, c.update_by, c.code, c.rlr,c.rlr_nike,
        c.is_confirm,c.confirm_info_user,c.confirm_info_nike_user,c.confirm_info_user_time,c.is_nucleicAcid,c.nucleicAcid_time,c.to_appropriate_phone
        from czrk c left join czrk_jzdz z on c.id =z.czrk_id
        <where>
            c.is_del = 'N'
            and c.status = '1'
            <if test="isRl != null and isRl != ''">and c.is_rl = #{isRl}</if>
            <if test="userName != null  and userName != ''">
                and c.user_name like concat(#{userName}, '%')
            </if>
            <if test="isNucleicAcid != null and isNucleicAcid != ''">and c.is_nucleicAcid = #{isNucleicAcid}</if>
            <if test="params.startAge != null  and params.startAge != ''">and c.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and c.age &lt;= #{params.endAge}</if>
            <if test="idCard != null  and idCard != ''">and c.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and c.phone_num = #{phoneNum}</if>
            <if test="houseType != null  and houseType != ''">and c.house_type = #{houseType}</if>
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            <if test="villageId != null  and villageId != ''">and c.village_id = #{villageId}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="provinceIdXjd != null and provinceIdXjd != ''">and z.province_id = #{provinceIdXjd}</if>
            <if test="cityIdXjd != null and cityIdXjd != ''">and z.city_id = #{cityIdXjd}</if>
            <if test="regionIdXjd != null and regionIdXjd != ''">and z.region_id = #{regionIdXjd}</if>
            <if test="villageTownsIdXjd != null and villageTownsIdXjd != ''">and z.town_id = #{villageTownsIdXjd}</if>
            <if test="villageIdXjd != null and villageIdXjd != ''">and z.village_id = #{villageIdXjd}</if>
        </where>
        order by c.create_time DESC
    </select>


    <select id="selectCzrkByNotRl" resultMap="CzrkResult">
        select c.id, c.user_name, c.phone_num,c.dept_id, c.id_card, c.gender, c.province, c.city, c.region,
        c.village_towns, c.village, c.villager_group, c.grid_id
        , c.house_type, c.update_by, c.code, c.rlr,c.rlr_nike, c.update_time, c.delete_reason,
        c.now_in,c.is_confirm,c.confirm_info_user,c.confirm_info_nike_user,c.confirm_info_user_time
        from czrk c
        <where>
            c.is_del = 'N'
            and c.is_rl = '否'
            and c.is_confirm = 'N'
            and c.status in ('1','2')
            <if test="userName != null  and userName != ''">
                and c.user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and c.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and c.age &lt;= #{params.endAge}</if>
            <if test="idCard != null  and idCard != ''">and c.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and c.phone_num = #{phoneNum}</if>
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            <if test="villageId != null  and villageId != ''">and c.village_id = #{villageId}</if>
        </where>
        order by c.update_time DESC
    </select>

    <select id="selectCzrkByNotRlCz" resultMap="CzrkResult">
        select c.id, c.user_name, c.phone_num, c.id_card, c.gender,
        z.province as provinceXjd, z.city as cityXjd,z.region as regionXjd, z.town as villageTownsXjd, z.village as
        villageXjd,z.now_in,c.grid_id
        , c.house_type, c.update_by, c.code, c.rlr,c.rlr_nike, c.update_time, c.delete_reason,
        c.now_in,c.is_confirm,c.confirm_info_user,c.confirm_info_nike_user,c.confirm_info_user_time,c.key_category
        from czrk c  left join czrk_jzdz z on c.id = z.czrk_id
        <where>
            c.is_del = 'N'
            and c.is_rl = '否'
            and c.is_confirm = 'N'
            and c.status in ('1','2')
            <if test="userName != null  and userName != ''">
                and c.user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and c.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and c.age &lt;= #{params.endAge}</if>
            <if test="idCard != null  and idCard != ''">and c.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and c.phone_num = #{phoneNum}</if>
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            <if test="villageId != null  and villageId != ''">and c.village_id = #{villageId}</if>
            <if test="provinceIdXjd != null and provinceIdXjd != ''">and z.province_id = #{provinceIdXjd}</if>
            <if test="cityIdXjd != null and cityIdXjd != ''">and z.city_id = #{cityIdXjd}</if>
            <if test="regionIdXjd != null and regionIdXjd != ''">and z.region_id = #{regionIdXjd}</if>
            <if test="villageTownsIdXjd != null and villageTownsIdXjd != ''">and z.town_id = #{villageTownsIdXjd}</if>
            <if test="villageIdXjd != null and villageIdXjd != ''">and z.village_id = #{villageIdXjd}</if>
            <if test="keyCategory != null and keyCategory != ''">and c.key_category = #{keyCategory}</if>
        </where>
        order by c.update_time DESC
    </select>
    <select id="listByIdCard" resultMap="CzrkResult">
        select vi.id, vi.create_time, vi.update_time, vi.is_del, vi.update_by, vi.user_name, vi.phone_num, vi.id_card
             , vi.gender, vi.province, vi.city, vi.region, vi.now_in, vi.house_type, vi.update_by, vi.code,vi.key_category
        from czrk vi
        where vi.id_card in
        <foreach item="idCard" collection="czrkIdCardList" open="(" separator="," close=")">
            #{idCard}
        </foreach>
    </select>


    <select id="selectCzrkCount" resultType="long">
        select ifnull(count(1),0)
        from czrk
        <where>
            is_del = 'N'
            and status = '1'
            <!-- 已认领 -->
            <if test="isRl != null and isRl != ''">and is_rl = #{isRl}</if>
            <if test="userName != null  and userName != ''">
                and user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and age &lt;= #{params.endAge}</if>
            <if test="gender != null  and gender != ''">and gender = #{gender}</if>
            <if test="age != null ">and age = #{age}</if>
            <if test="birthday != null ">and birthday = #{birthday}</if>
            <if test="idCard != null  and idCard != ''">and id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and phone_num = #{phoneNum}</if>
            <if test="isConfirm != null  and isConfirm != ''">and is_confirm = #{isConfirm}</if>
            <if test="houseType != null  and houseType != ''">and house_type = #{houseType}</if>
            <if test="provinceId != null  and provinceId != ''">and province_id = #{provinceId}</if>
            <if test="province != null  and province != ''">and province = #{province}</if>
            <if test="cityId != null  and cityId != ''">and city_id = #{cityId}</if>
            <if test="city != null  and city != ''">and city = #{city}</if>
            <if test="regionId != null  and regionId != ''">and region_id = #{regionId}</if>
            <if test="region != null  and region != ''">and region = #{region}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and village_towns_id = #{villageTownsId}</if>
            <if test="villageTowns != null  and villageTowns != ''">and village_towns = #{villageTowns}</if>
            <if test="villageId != null  and villageId != ''">and village_id = #{villageId}</if>
            <if test="village != null  and village != ''">and village = #{village}</if>
            <if test="isConfirm != null  and isConfirm != ''">and is_confirm = #{isConfirm}</if>
            <if test="gridId != null  and gridId != ''">and grid_id = #{gridId}</if>
        </where>
        order by create_time DESC
    </select>

    <select id="selectCzrkJzdzCount" resultType="long">
        select ifnull(count(1),0)
        from czrk c left join czrk_jzdz z on c.id =z.czrk_id
        <where>
            c.is_del = 'N'
            and c.status = '1'
            <if test="isRl != null and isRl != ''">and c.is_rl = #{isRl}</if>
            <if test="userName != null  and userName != ''">
                and c.user_name like concat(#{userName}, '%')
            </if>
            <if test="params.startAge != null  and params.startAge != ''">and c.age &gt;= #{params.startAge}</if>
            <if test="params.endAge != null  and params.endAge != ''">and c.age &lt;= #{params.endAge}</if>
            <if test="idCard != null  and idCard != ''">and c.id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''">and c.phone_num = #{phoneNum}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="houseType != null  and houseType != ''">and c.house_type = #{houseType}</if>
            <if test="provinceId != null  and provinceId != ''">and c.province_id = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''">and c.city_id = #{cityId}</if>
            <if test="regionId != null  and regionId != ''">and c.region_id = #{regionId}</if>
            <if test="villageTownsId != null  and villageTownsId != ''">and c.village_towns_id = #{villageTownsId}</if>
            <if test="villageId != null  and villageId != ''">and c.village_id = #{villageId}</if>
            <if test="isConfirm != null  and isConfirm != ''">and c.is_confirm = #{isConfirm}</if>
            <if test="provinceIdXjd != null and provinceIdXjd != ''">and z.province_id = #{provinceIdXjd}</if>
            <if test="cityIdXjd != null and cityIdXjd != ''">and z.city_id = #{cityIdXjd}</if>
            <if test="regionIdXjd != null and regionIdXjd != ''">and z.region_id = #{regionIdXjd}</if>
            <if test="villageTownsIdXjd != null and villageTownsIdXjd != ''">and z.town_id = #{villageTownsIdXjd}</if>
            <if test="villageIdXjd != null and villageIdXjd != ''">and z.village_id = #{villageIdXjd}</if>
        </where>
        order by c.create_time DESC
    </select>
    <select id="getCzrkByIdCard" resultMap="CzrkResult">
        select id,id_card,house_type from czrk where is_del = 'N' and id_card = #{idCard}
    </select>
    <update id="setNoRl" parameterType="com.boman.domain.Czrk">
        update czrk set is_rl = '否',is_confirm = 'N'
        <where>
            (village_id = '' or village_id is null or village_id = '0')
            and is_del = 'N'
            and  `status` = '1'
            <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>
        </where>
    </update>

    <update id="updateCzrkByToQianshanPersonner">
        update czrk
        set to_appropriate_phone = #{toAppropriatePhone},to_appropriate_time = #{toAppropriateTime}
        where id_card = #{idCard}
    </update>
</mapper>