<?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.ruoyi.system.mapper.grid.GridPeopleMapper">
  <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.grid.GridPeople">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="avatar" jdbcType="VARCHAR" property="avatar" />
    <result column="person_name" jdbcType="VARCHAR" property="personName" />
    <result column="id_card" jdbcType="VARCHAR" property="idCard" />
    <result column="sex" jdbcType="VARCHAR" property="sex" />
    <result column="native_place" jdbcType="VARCHAR" property="nativePlace" />
    <result column="birthday" jdbcType="VARCHAR" property="birthday" />
    <result column="registered_address" jdbcType="VARCHAR" property="registeredAddress" />
    <result column="mz_code" jdbcType="VARCHAR" property="mzCode" />
    <result column="hyzk_code" jdbcType="VARCHAR" property="hyzkCode" />
    <result column="whcd_code" jdbcType="VARCHAR" property="whcdCode" />
    <result column="zzmm_code" jdbcType="VARCHAR" property="zzmmCode" />
    <result column="wg_code" jdbcType="VARCHAR" property="wgCode" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="address" jdbcType="VARCHAR" property="address" />
    <result column="rklx_code" jdbcType="VARCHAR" property="rklxCode" />
    <result column="rkbq_code" jdbcType="VARCHAR" property="rkbqCode" />
    <result column="open_id" jdbcType="VARCHAR" property="openId" />
    <result column="create_time" jdbcType="VARCHAR" property="createTime" />
    <result column="update_time" jdbcType="VARCHAR" property="updateTime" />
    <result column="create_id" jdbcType="VARCHAR" property="createId" />
    <result column="update_id" jdbcType="VARCHAR" property="updateId" />
    <result column="is_valid" jdbcType="TINYINT" property="isValid" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, avatar, person_name, id_card, sex, native_place, birthday, registered_address,
    mz_code, hyzk_code, whcd_code, zzmm_code, wg_code, phone, address, rklx_code, rkbq_code,
    open_id, create_time, update_time, create_id, update_id, is_valid
  </sql>
  <select id="selectByExample" parameterType="com.ruoyi.system.domain.grid.GridPeopleExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from grid_people
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from grid_people
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from grid_people
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.ruoyi.system.domain.grid.GridPeopleExample">
    delete from grid_people
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.ruoyi.system.domain.grid.GridPeople">
    insert into grid_people (id, avatar, person_name,
      id_card, sex, native_place,
      birthday, registered_address, mz_code,
      hyzk_code, whcd_code, zzmm_code,
      wg_code, phone, address,
      rklx_code, rkbq_code, open_id,
      create_time, update_time, create_id,
      update_id, is_valid
      )
    values (#{id,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR}, #{personName,jdbcType=VARCHAR},
      #{idCard,jdbcType=VARCHAR}, #{sex,jdbcType=VARCHAR}, #{nativePlace,jdbcType=VARCHAR},
      #{birthday,jdbcType=VARCHAR}, #{registeredAddress,jdbcType=VARCHAR}, #{mzCode,jdbcType=VARCHAR},
      #{hyzkCode,jdbcType=VARCHAR}, #{whcdCode,jdbcType=VARCHAR}, #{zzmmCode,jdbcType=VARCHAR},
      #{wgCode,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
      #{rklxCode,jdbcType=VARCHAR}, #{rkbqCode,jdbcType=VARCHAR}, #{openId,jdbcType=VARCHAR},
      #{createTime,jdbcType=VARCHAR}, #{updateTime,jdbcType=VARCHAR}, #{createId,jdbcType=VARCHAR},
      #{updateId,jdbcType=VARCHAR}, #{isValid,jdbcType=TINYINT}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.ruoyi.system.domain.grid.GridPeople" keyProperty="id" useGeneratedKeys="true">
    insert into grid_people
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="avatar != null">
        avatar,
      </if>
      <if test="personName != null">
        person_name,
      </if>
      <if test="idCard != null">
        id_card,
      </if>
      <if test="sex != null">
        sex,
      </if>
      <if test="nativePlace != null">
        native_place,
      </if>
      <if test="birthday != null">
        birthday,
      </if>
      <if test="registeredAddress != null">
        registered_address,
      </if>
      <if test="mzCode != null">
        mz_code,
      </if>
      <if test="hyzkCode != null">
        hyzk_code,
      </if>
      <if test="whcdCode != null">
        whcd_code,
      </if>
      <if test="zzmmCode != null">
        zzmm_code,
      </if>
      <if test="wgCode != null">
        wg_code,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="address != null">
        address,
      </if>
      <if test="rklxCode != null">
        rklx_code,
      </if>
      <if test="rkbqCode != null">
        rkbq_code,
      </if>
      <if test="openId != null">
        open_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="createId != null">
        create_id,
      </if>
      <if test="updateId != null">
        update_id,
      </if>
      <if test="isValid != null">
        is_valid,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="avatar != null">
        #{avatar,jdbcType=VARCHAR},
      </if>
      <if test="personName != null">
        #{personName,jdbcType=VARCHAR},
      </if>
      <if test="idCard != null">
        #{idCard,jdbcType=VARCHAR},
      </if>
      <if test="sex != null">
        #{sex,jdbcType=VARCHAR},
      </if>
      <if test="nativePlace != null">
        #{nativePlace,jdbcType=VARCHAR},
      </if>
      <if test="birthday != null">
        #{birthday,jdbcType=VARCHAR},
      </if>
      <if test="registeredAddress != null">
        #{registeredAddress,jdbcType=VARCHAR},
      </if>
      <if test="mzCode != null">
        #{mzCode,jdbcType=VARCHAR},
      </if>
      <if test="hyzkCode != null">
        #{hyzkCode,jdbcType=VARCHAR},
      </if>
      <if test="whcdCode != null">
        #{whcdCode,jdbcType=VARCHAR},
      </if>
      <if test="zzmmCode != null">
        #{zzmmCode,jdbcType=VARCHAR},
      </if>
      <if test="wgCode != null">
        #{wgCode,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="rklxCode != null">
        #{rklxCode,jdbcType=VARCHAR},
      </if>
      <if test="rkbqCode != null">
        #{rkbqCode,jdbcType=VARCHAR},
      </if>
      <if test="openId != null">
        #{openId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=VARCHAR},
      </if>
      <if test="createId != null">
        #{createId,jdbcType=VARCHAR},
      </if>
      <if test="updateId != null">
        #{updateId,jdbcType=VARCHAR},
      </if>
      <if test="isValid != null">
        #{isValid,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.ruoyi.system.domain.grid.GridPeopleExample" resultType="java.lang.Long">
    select count(*) from grid_people
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update grid_people
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.avatar != null">
        avatar = #{record.avatar,jdbcType=VARCHAR},
      </if>
      <if test="record.personName != null">
        person_name = #{record.personName,jdbcType=VARCHAR},
      </if>
      <if test="record.idCard != null">
        id_card = #{record.idCard,jdbcType=VARCHAR},
      </if>
      <if test="record.sex != null">
        sex = #{record.sex,jdbcType=VARCHAR},
      </if>
      <if test="record.nativePlace != null">
        native_place = #{record.nativePlace,jdbcType=VARCHAR},
      </if>
      <if test="record.birthday != null">
        birthday = #{record.birthday,jdbcType=VARCHAR},
      </if>
      <if test="record.registeredAddress != null">
        registered_address = #{record.registeredAddress,jdbcType=VARCHAR},
      </if>
      <if test="record.mzCode != null">
        mz_code = #{record.mzCode,jdbcType=VARCHAR},
      </if>
      <if test="record.hyzkCode != null">
        hyzk_code = #{record.hyzkCode,jdbcType=VARCHAR},
      </if>
      <if test="record.whcdCode != null">
        whcd_code = #{record.whcdCode,jdbcType=VARCHAR},
      </if>
      <if test="record.zzmmCode != null">
        zzmm_code = #{record.zzmmCode,jdbcType=VARCHAR},
      </if>
      <if test="record.wgCode != null">
        wg_code = #{record.wgCode,jdbcType=VARCHAR},
      </if>
      <if test="record.phone != null">
        phone = #{record.phone,jdbcType=VARCHAR},
      </if>
      <if test="record.address != null">
        address = #{record.address,jdbcType=VARCHAR},
      </if>
      <if test="record.rklxCode != null">
        rklx_code = #{record.rklxCode,jdbcType=VARCHAR},
      </if>
      <if test="record.rkbqCode != null">
        rkbq_code = #{record.rkbqCode,jdbcType=VARCHAR},
      </if>
      <if test="record.openId != null">
        open_id = #{record.openId,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=VARCHAR},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=VARCHAR},
      </if>
      <if test="record.createId != null">
        create_id = #{record.createId,jdbcType=VARCHAR},
      </if>
      <if test="record.updateId != null">
        update_id = #{record.updateId,jdbcType=VARCHAR},
      </if>
      <if test="record.isValid != null">
        is_valid = #{record.isValid,jdbcType=TINYINT},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update grid_people
    set id = #{record.id,jdbcType=VARCHAR},
      avatar = #{record.avatar,jdbcType=VARCHAR},
      person_name = #{record.personName,jdbcType=VARCHAR},
      id_card = #{record.idCard,jdbcType=VARCHAR},
      sex = #{record.sex,jdbcType=VARCHAR},
      native_place = #{record.nativePlace,jdbcType=VARCHAR},
      birthday = #{record.birthday,jdbcType=VARCHAR},
      registered_address = #{record.registeredAddress,jdbcType=VARCHAR},
      mz_code = #{record.mzCode,jdbcType=VARCHAR},
      hyzk_code = #{record.hyzkCode,jdbcType=VARCHAR},
      whcd_code = #{record.whcdCode,jdbcType=VARCHAR},
      zzmm_code = #{record.zzmmCode,jdbcType=VARCHAR},
      wg_code = #{record.wgCode,jdbcType=VARCHAR},
      phone = #{record.phone,jdbcType=VARCHAR},
      address = #{record.address,jdbcType=VARCHAR},
      rklx_code = #{record.rklxCode,jdbcType=VARCHAR},
      rkbq_code = #{record.rkbqCode,jdbcType=VARCHAR},
      open_id = #{record.openId,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=VARCHAR},
      update_time = #{record.updateTime,jdbcType=VARCHAR},
      create_id = #{record.createId,jdbcType=VARCHAR},
      update_id = #{record.updateId,jdbcType=VARCHAR},
      is_valid = #{record.isValid,jdbcType=TINYINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.system.domain.grid.GridPeople">
    update grid_people
    <set>
      <if test="avatar != null">
        avatar = #{avatar,jdbcType=VARCHAR},
      </if>
      <if test="personName != null">
        person_name = #{personName,jdbcType=VARCHAR},
      </if>
      <if test="idCard != null">
        id_card = #{idCard,jdbcType=VARCHAR},
      </if>
      <if test="sex != null">
        sex = #{sex,jdbcType=VARCHAR},
      </if>
      <if test="nativePlace != null">
        native_place = #{nativePlace,jdbcType=VARCHAR},
      </if>
      <if test="birthday != null">
        birthday = #{birthday,jdbcType=VARCHAR},
      </if>
      <if test="registeredAddress != null">
        registered_address = #{registeredAddress,jdbcType=VARCHAR},
      </if>
      <if test="mzCode != null">
        mz_code = #{mzCode,jdbcType=VARCHAR},
      </if>
      <if test="hyzkCode != null">
        hyzk_code = #{hyzkCode,jdbcType=VARCHAR},
      </if>
      <if test="whcdCode != null">
        whcd_code = #{whcdCode,jdbcType=VARCHAR},
      </if>
      <if test="zzmmCode != null">
        zzmm_code = #{zzmmCode,jdbcType=VARCHAR},
      </if>
      <if test="wgCode != null">
        wg_code = #{wgCode,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="rklxCode != null">
        rklx_code = #{rklxCode,jdbcType=VARCHAR},
      </if>
      <if test="rkbqCode != null">
        rkbq_code = #{rkbqCode,jdbcType=VARCHAR},
      </if>
      <if test="openId != null">
        open_id = #{openId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=VARCHAR},
      </if>
      <if test="createId != null">
        create_id = #{createId,jdbcType=VARCHAR},
      </if>
      <if test="updateId != null">
        update_id = #{updateId,jdbcType=VARCHAR},
      </if>
      <if test="isValid != null">
        is_valid = #{isValid,jdbcType=TINYINT},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ruoyi.system.domain.grid.GridPeople">
    update grid_people
    set avatar = #{avatar,jdbcType=VARCHAR},
      person_name = #{personName,jdbcType=VARCHAR},
      id_card = #{idCard,jdbcType=VARCHAR},
      sex = #{sex,jdbcType=VARCHAR},
      native_place = #{nativePlace,jdbcType=VARCHAR},
      birthday = #{birthday,jdbcType=VARCHAR},
      registered_address = #{registeredAddress,jdbcType=VARCHAR},
      mz_code = #{mzCode,jdbcType=VARCHAR},
      hyzk_code = #{hyzkCode,jdbcType=VARCHAR},
      whcd_code = #{whcdCode,jdbcType=VARCHAR},
      zzmm_code = #{zzmmCode,jdbcType=VARCHAR},
      wg_code = #{wgCode,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      address = #{address,jdbcType=VARCHAR},
      rklx_code = #{rklxCode,jdbcType=VARCHAR},
      rkbq_code = #{rkbqCode,jdbcType=VARCHAR},
      open_id = #{openId,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=VARCHAR},
      create_id = #{createId,jdbcType=VARCHAR},
      update_id = #{updateId,jdbcType=VARCHAR},
      is_valid = #{isValid,jdbcType=TINYINT}
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="countGridPeople" parameterType="list" resultType="map">
    select a.name, count(b.id) as number from bs_common as a LEFT JOIN grid_people as b on a.code = b.rklx_code and b.is_valid = 1
    <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
      and (
      <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
        b.wg_code like CONCAT(#{wgCode}, '%')
      </foreach>
      )
    </if>
    where a.parent_id = (select id from bs_common where code = 'rklx') and a.is_valid = '1' GROUP BY a.code ORDER BY a.sort desc
  </select>

  <select id="countGridPeopleByGrid" parameterType="java.lang.String" resultType="map">
    select a.wg_name as name, count(b.id) as number from grid_region as a LEFT JOIN grid_people as b on b.wg_code like concat(a.wg_code, '%')
    and b.is_valid = 1
    where a.level = '2' and a.is_valid = '1' GROUP BY a.wg_code ORDER BY number desc, a.wg_code
  </select>

  <select id="countGridPeopleByRkbq" parameterType="java.lang.String" resultType="map">
    select a.name, count(b.id) as number from bs_common as a LEFT JOIN grid_people as b on b.rkbq_code like CONCAT('%', a.code, '%') and b.is_valid = 1
    <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
      and (
      <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
        b.wg_code like CONCAT(#{wgCode}, '%')
      </foreach>
      )
    </if>
    where a.parent_id = (select id from bs_common where code = 'rkbq') and a.is_valid = '1' and a.name != '无' GROUP BY a.code ORDER BY a.sort
  </select>

  <select id="countWsSpecialPeople" parameterType="java.lang.String" resultType="Integer">
    select count(b.id) as number from bs_common as a LEFT JOIN grid_people as b on b.rkbq_code like CONCAT('%', a.code, '%') and b.is_valid = 1
    <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
      and (
      <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
        b.wg_code like CONCAT(#{wgCode}, '%')
      </foreach>
      )
    </if>
    where a.name like '%特殊%' and a.is_valid = '1' GROUP BY a.code ORDER BY number desc, a.sort
  </select>

  <select id="countGridPeopleRklxByGrid" parameterType="java.lang.String" resultType="map">
    select a.wg_name as name, c.name as type, count(b.rklx_code) as number from grid_region as a LEFT JOIN grid_people as b
    on b.wg_code like concat(a.wg_code, '%') and b.is_valid = 1
	RIGHT JOIN bs_common as c on b.rklx_code = c.code
    where a.is_valid = '1'
      <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
        and a.wg_parent_id in
        <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator=",">
          #{wgCode}
        </foreach>
      </if>
      <if test="wgCodeLikes == null or wgCodeLikes.size() == 0">
        and a.level = '2'
      </if>
    GROUP BY a.wg_code, b.rklx_code ORDER BY a.wg_code, c.code desc;
  </select>
    <select id="countByParam" resultType="java.lang.Integer" parameterType="com.ruoyi.system.domain.grid.vo.GridPeopleSearchParam">
      select count(1) from grid_people where is_valid = '1'
      <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
        and (
        <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
          wg_code like CONCAT(#{wgCode}, '%')
        </foreach>
        )
      </if>
    </select>
    <select id="listByParam" resultType="com.ruoyi.system.domain.grid.GridPeople" parameterType="com.ruoyi.system.domain.grid.vo.GridPeopleSearchParam">
      select * from grid_people where is_valid = '1'
      <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
        and (
        <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
          wg_code like CONCAT(#{wgCode}, '%')
        </foreach>
        )
      </if>
      <if test="rklxCode != null and rklxCode != ''">
        and rklx_code = #{rklxCode}
      </if>
      <if test="rkbqCode != null and rkbqCode != ''">
        and find_in_set(#{rkbqCode}, rkbq_code)
      </if>
      <if test="sex != null and sex != ''">
        and sex = #{sex}
      </if>
      <if test="value != null and value != ''">
        and(id_card like CONCAT('%', #{value}, '%') or person_name like CONCAT('%', #{value}, '%'))
      </if>
      order by create_time desc, person_name
    </select>

</mapper>
