<?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.visit.VisitFreePlanMapper">
  <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.visit.VisitFreePlan">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="plan_model_id" jdbcType="VARCHAR" property="planModelId" />
    <result column="plan_title" jdbcType="VARCHAR" property="planTitle" />
    <result column="plan_type" jdbcType="VARCHAR" property="planType" />
    <result column="task_type" jdbcType="VARCHAR" property="taskType" />
    <result column="plan_user_name" jdbcType="VARCHAR" property="planUserName" />
    <result column="useId" jdbcType="VARCHAR" property="useid" />
    <result column="wg_code" jdbcType="VARCHAR" property="wgCode" />
    <result column="start_time" jdbcType="VARCHAR" property="startTime" />
    <result column="end_time" jdbcType="VARCHAR" property="endTime" />
    <result column="unlimited" jdbcType="VARCHAR" property="unlimited" />
    <result column="plan_total" jdbcType="BIGINT" property="planTotal" />
    <result column="plan_com_num" jdbcType="BIGINT" property="planComNum" />
    <result column="plan_shop_num" jdbcType="BIGINT" property="planShopNum" />
    <result column="plan_house_num" jdbcType="BIGINT" property="planHouseNum" />
    <result column="plan_people_num" jdbcType="BIGINT" property="planPeopleNum" />
    <result column="com_num" jdbcType="BIGINT" property="comNum" />
    <result column="shop_num" jdbcType="BIGINT" property="shopNum" />
    <result column="house_num" jdbcType="BIGINT" property="houseNum" />
    <result column="people_num" jdbcType="BIGINT" property="peopleNum" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="is_valid" jdbcType="VARCHAR" property="isValid" />
    <result column="has_done" jdbcType="VARCHAR" property="hasDone" />
    <result column="visit_type" jdbcType="VARCHAR" property="visitType" />
  </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, plan_model_id, plan_title, plan_type, task_type, plan_user_name, useId, wg_code,
    start_time, end_time, unlimited, plan_total, plan_com_num, plan_shop_num, plan_house_num,
    plan_people_num, com_num, shop_num, house_num, people_num, create_time, create_by,
    update_time, update_by, is_valid, has_done, visit_type
  </sql>
  <select id="selectByExample" parameterType="com.ruoyi.system.domain.visit.VisitFreePlanExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from visit_free_plan
    <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 visit_free_plan
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from visit_free_plan
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.ruoyi.system.domain.visit.VisitFreePlanExample">
    delete from visit_free_plan
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.ruoyi.system.domain.visit.VisitFreePlan">
    insert into visit_free_plan (id, plan_model_id, plan_title,
      plan_type, task_type, plan_user_name,
      useId, wg_code, start_time,
      end_time, unlimited, plan_total,
      plan_com_num, plan_shop_num, plan_house_num,
      plan_people_num, com_num, shop_num,
      house_num, people_num, create_time,
      create_by, update_time, update_by,
      is_valid, has_done, visit_type
      )
    values (#{id,jdbcType=VARCHAR}, #{planModelId,jdbcType=VARCHAR}, #{planTitle,jdbcType=VARCHAR},
      #{planType,jdbcType=VARCHAR}, #{taskType,jdbcType=VARCHAR}, #{planUserName,jdbcType=VARCHAR},
      #{useid,jdbcType=VARCHAR}, #{wgCode,jdbcType=VARCHAR}, #{startTime,jdbcType=VARCHAR},
      #{endTime,jdbcType=VARCHAR}, #{unlimited,jdbcType=VARCHAR}, #{planTotal,jdbcType=BIGINT},
      #{planComNum,jdbcType=BIGINT}, #{planShopNum,jdbcType=BIGINT}, #{planHouseNum,jdbcType=BIGINT},
      #{planPeopleNum,jdbcType=BIGINT}, #{comNum,jdbcType=BIGINT}, #{shopNum,jdbcType=BIGINT},
      #{houseNum,jdbcType=BIGINT}, #{peopleNum,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP},
      #{createBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR},
      #{isValid,jdbcType=VARCHAR}, #{hasDone,jdbcType=VARCHAR}, #{visitType,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.ruoyi.system.domain.visit.VisitFreePlan">
    insert into visit_free_plan
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="planModelId != null">
        plan_model_id,
      </if>
      <if test="planTitle != null">
        plan_title,
      </if>
      <if test="planType != null">
        plan_type,
      </if>
      <if test="taskType != null">
        task_type,
      </if>
      <if test="planUserName != null">
        plan_user_name,
      </if>
      <if test="useid != null">
        useId,
      </if>
      <if test="wgCode != null">
        wg_code,
      </if>
      <if test="startTime != null">
        start_time,
      </if>
      <if test="endTime != null">
        end_time,
      </if>
      <if test="unlimited != null">
        unlimited,
      </if>
      <if test="planTotal != null">
        plan_total,
      </if>
      <if test="planComNum != null">
        plan_com_num,
      </if>
      <if test="planShopNum != null">
        plan_shop_num,
      </if>
      <if test="planHouseNum != null">
        plan_house_num,
      </if>
      <if test="planPeopleNum != null">
        plan_people_num,
      </if>
      <if test="comNum != null">
        com_num,
      </if>
      <if test="shopNum != null">
        shop_num,
      </if>
      <if test="houseNum != null">
        house_num,
      </if>
      <if test="peopleNum != null">
        people_num,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="updateBy != null">
        update_by,
      </if>
      <if test="isValid != null">
        is_valid,
      </if>
      <if test="hasDone != null">
        has_done,
      </if>
      <if test="visitType != null">
        visit_type,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="planModelId != null">
        #{planModelId,jdbcType=VARCHAR},
      </if>
      <if test="planTitle != null">
        #{planTitle,jdbcType=VARCHAR},
      </if>
      <if test="planType != null">
        #{planType,jdbcType=VARCHAR},
      </if>
      <if test="taskType != null">
        #{taskType,jdbcType=VARCHAR},
      </if>
      <if test="planUserName != null">
        #{planUserName,jdbcType=VARCHAR},
      </if>
      <if test="useid != null">
        #{useid,jdbcType=VARCHAR},
      </if>
      <if test="wgCode != null">
        #{wgCode,jdbcType=VARCHAR},
      </if>
      <if test="startTime != null">
        #{startTime,jdbcType=VARCHAR},
      </if>
      <if test="endTime != null">
        #{endTime,jdbcType=VARCHAR},
      </if>
      <if test="unlimited != null">
        #{unlimited,jdbcType=VARCHAR},
      </if>
      <if test="planTotal != null">
        #{planTotal,jdbcType=BIGINT},
      </if>
      <if test="planComNum != null">
        #{planComNum,jdbcType=BIGINT},
      </if>
      <if test="planShopNum != null">
        #{planShopNum,jdbcType=BIGINT},
      </if>
      <if test="planHouseNum != null">
        #{planHouseNum,jdbcType=BIGINT},
      </if>
      <if test="planPeopleNum != null">
        #{planPeopleNum,jdbcType=BIGINT},
      </if>
      <if test="comNum != null">
        #{comNum,jdbcType=BIGINT},
      </if>
      <if test="shopNum != null">
        #{shopNum,jdbcType=BIGINT},
      </if>
      <if test="houseNum != null">
        #{houseNum,jdbcType=BIGINT},
      </if>
      <if test="peopleNum != null">
        #{peopleNum,jdbcType=BIGINT},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="isValid != null">
        #{isValid,jdbcType=VARCHAR},
      </if>
      <if test="hasDone != null">
        #{hasDone,jdbcType=VARCHAR},
      </if>
      <if test="visitType != null">
        #{visitType,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.ruoyi.system.domain.visit.VisitFreePlanExample" resultType="java.lang.Long">
    select count(*) from visit_free_plan
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update visit_free_plan
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.planModelId != null">
        plan_model_id = #{record.planModelId,jdbcType=VARCHAR},
      </if>
      <if test="record.planTitle != null">
        plan_title = #{record.planTitle,jdbcType=VARCHAR},
      </if>
      <if test="record.planType != null">
        plan_type = #{record.planType,jdbcType=VARCHAR},
      </if>
      <if test="record.taskType != null">
        task_type = #{record.taskType,jdbcType=VARCHAR},
      </if>
      <if test="record.planUserName != null">
        plan_user_name = #{record.planUserName,jdbcType=VARCHAR},
      </if>
      <if test="record.useid != null">
        useId = #{record.useid,jdbcType=VARCHAR},
      </if>
      <if test="record.wgCode != null">
        wg_code = #{record.wgCode,jdbcType=VARCHAR},
      </if>
      <if test="record.startTime != null">
        start_time = #{record.startTime,jdbcType=VARCHAR},
      </if>
      <if test="record.endTime != null">
        end_time = #{record.endTime,jdbcType=VARCHAR},
      </if>
      <if test="record.unlimited != null">
        unlimited = #{record.unlimited,jdbcType=VARCHAR},
      </if>
      <if test="record.planTotal != null">
        plan_total = #{record.planTotal,jdbcType=BIGINT},
      </if>
      <if test="record.planComNum != null">
        plan_com_num = #{record.planComNum,jdbcType=BIGINT},
      </if>
      <if test="record.planShopNum != null">
        plan_shop_num = #{record.planShopNum,jdbcType=BIGINT},
      </if>
      <if test="record.planHouseNum != null">
        plan_house_num = #{record.planHouseNum,jdbcType=BIGINT},
      </if>
      <if test="record.planPeopleNum != null">
        plan_people_num = #{record.planPeopleNum,jdbcType=BIGINT},
      </if>
      <if test="record.comNum != null">
        com_num = #{record.comNum,jdbcType=BIGINT},
      </if>
      <if test="record.shopNum != null">
        shop_num = #{record.shopNum,jdbcType=BIGINT},
      </if>
      <if test="record.houseNum != null">
        house_num = #{record.houseNum,jdbcType=BIGINT},
      </if>
      <if test="record.peopleNum != null">
        people_num = #{record.peopleNum,jdbcType=BIGINT},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createBy != null">
        create_by = #{record.createBy,jdbcType=VARCHAR},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateBy != null">
        update_by = #{record.updateBy,jdbcType=VARCHAR},
      </if>
      <if test="record.isValid != null">
        is_valid = #{record.isValid,jdbcType=VARCHAR},
      </if>
      <if test="record.hasDone != null">
        has_done = #{record.hasDone,jdbcType=VARCHAR},
      </if>
      <if test="record.visitType != null">
        visit_type = #{record.visitType,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update visit_free_plan
    set id = #{record.id,jdbcType=VARCHAR},
    plan_model_id = #{record.planModelId,jdbcType=VARCHAR},
    plan_title = #{record.planTitle,jdbcType=VARCHAR},
    plan_type = #{record.planType,jdbcType=VARCHAR},
    task_type = #{record.taskType,jdbcType=VARCHAR},
    plan_user_name = #{record.planUserName,jdbcType=VARCHAR},
    useId = #{record.useid,jdbcType=VARCHAR},
    wg_code = #{record.wgCode,jdbcType=VARCHAR},
    start_time = #{record.startTime,jdbcType=VARCHAR},
    end_time = #{record.endTime,jdbcType=VARCHAR},
    unlimited = #{record.unlimited,jdbcType=VARCHAR},
    plan_total = #{record.planTotal,jdbcType=BIGINT},
    plan_com_num = #{record.planComNum,jdbcType=BIGINT},
    plan_shop_num = #{record.planShopNum,jdbcType=BIGINT},
    plan_house_num = #{record.planHouseNum,jdbcType=BIGINT},
    plan_people_num = #{record.planPeopleNum,jdbcType=BIGINT},
    com_num = #{record.comNum,jdbcType=BIGINT},
    shop_num = #{record.shopNum,jdbcType=BIGINT},
    house_num = #{record.houseNum,jdbcType=BIGINT},
    people_num = #{record.peopleNum,jdbcType=BIGINT},
    create_time = #{record.createTime,jdbcType=TIMESTAMP},
    create_by = #{record.createBy,jdbcType=VARCHAR},
    update_time = #{record.updateTime,jdbcType=TIMESTAMP},
    update_by = #{record.updateBy,jdbcType=VARCHAR},
    is_valid = #{record.isValid,jdbcType=VARCHAR},
    has_done = #{record.hasDone,jdbcType=VARCHAR},
    visit_type = #{record.visitType,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.system.domain.visit.VisitFreePlan">
    update visit_free_plan
    <set>
      <if test="planModelId != null">
        plan_model_id = #{planModelId,jdbcType=VARCHAR},
      </if>
      <if test="planTitle != null">
        plan_title = #{planTitle,jdbcType=VARCHAR},
      </if>
      <if test="planType != null">
        plan_type = #{planType,jdbcType=VARCHAR},
      </if>
      <if test="taskType != null">
        task_type = #{taskType,jdbcType=VARCHAR},
      </if>
      <if test="planUserName != null">
        plan_user_name = #{planUserName,jdbcType=VARCHAR},
      </if>
      <if test="useid != null">
        useId = #{useid,jdbcType=VARCHAR},
      </if>
      <if test="wgCode != null">
        wg_code = #{wgCode,jdbcType=VARCHAR},
      </if>
      <if test="startTime != null">
        start_time = #{startTime,jdbcType=VARCHAR},
      </if>
      <if test="endTime != null">
        end_time = #{endTime,jdbcType=VARCHAR},
      </if>
      <if test="unlimited != null">
        unlimited = #{unlimited,jdbcType=VARCHAR},
      </if>
      <if test="planTotal != null">
        plan_total = #{planTotal,jdbcType=BIGINT},
      </if>
      <if test="planComNum != null">
        plan_com_num = #{planComNum,jdbcType=BIGINT},
      </if>
      <if test="planShopNum != null">
        plan_shop_num = #{planShopNum,jdbcType=BIGINT},
      </if>
      <if test="planHouseNum != null">
        plan_house_num = #{planHouseNum,jdbcType=BIGINT},
      </if>
      <if test="planPeopleNum != null">
        plan_people_num = #{planPeopleNum,jdbcType=BIGINT},
      </if>
      <if test="comNum != null">
        com_num = #{comNum,jdbcType=BIGINT},
      </if>
      <if test="shopNum != null">
        shop_num = #{shopNum,jdbcType=BIGINT},
      </if>
      <if test="houseNum != null">
        house_num = #{houseNum,jdbcType=BIGINT},
      </if>
      <if test="peopleNum != null">
        people_num = #{peopleNum,jdbcType=BIGINT},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="isValid != null">
        is_valid = #{isValid,jdbcType=VARCHAR},
      </if>
      <if test="hasDone != null">
        has_done = #{hasDone,jdbcType=VARCHAR},
      </if>
      <if test="visitType != null">
        visit_type = #{visitType,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ruoyi.system.domain.visit.VisitFreePlan">
    update visit_free_plan
    set plan_model_id = #{planModelId,jdbcType=VARCHAR},
      plan_title = #{planTitle,jdbcType=VARCHAR},
      plan_type = #{planType,jdbcType=VARCHAR},
      task_type = #{taskType,jdbcType=VARCHAR},
      plan_user_name = #{planUserName,jdbcType=VARCHAR},
      useId = #{useid,jdbcType=VARCHAR},
      wg_code = #{wgCode,jdbcType=VARCHAR},
      start_time = #{startTime,jdbcType=VARCHAR},
      end_time = #{endTime,jdbcType=VARCHAR},
      unlimited = #{unlimited,jdbcType=VARCHAR},
      plan_total = #{planTotal,jdbcType=BIGINT},
      plan_com_num = #{planComNum,jdbcType=BIGINT},
      plan_shop_num = #{planShopNum,jdbcType=BIGINT},
      plan_house_num = #{planHouseNum,jdbcType=BIGINT},
      plan_people_num = #{planPeopleNum,jdbcType=BIGINT},
      com_num = #{comNum,jdbcType=BIGINT},
      shop_num = #{shopNum,jdbcType=BIGINT},
      house_num = #{houseNum,jdbcType=BIGINT},
      people_num = #{peopleNum,jdbcType=BIGINT},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_by = #{createBy,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      update_by = #{updateBy,jdbcType=VARCHAR},
      is_valid = #{isValid,jdbcType=VARCHAR},
      has_done = #{hasDone,jdbcType=VARCHAR},
    visit_type = #{visitType,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="listByParams" resultType="com.ruoyi.system.domain.visit.VisitFreePlan" parameterType="com.ruoyi.system.domain.visit.vo.VisitPlanSearchParam">
    select * from visit_free_plan where is_valid = '1'
    <if test="visitType != null and visitType != ''">
      and visit_type = #{visitType}
    </if>
    <if test="hasDone != null and hasDone != ''">
      and has_done = #{hasDone}
    </if>
    <if test="planTitle != null and planTitle != ''">
      and plan_title like CONCAT('%', #{planTitle}, '%')
    </if>
    <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="startDate != null and startDate != ''">
      and DATE_FORMAT(start_time,'%Y-%m-%d') &gt;= #{startDate}
    </if>
    <if test="endDate != null and endDate != ''">
      and DATE_FORMAT(end_time,'%Y-%m-%d') &lt;= #{endDate}
    </if>
    <if test="hasDoneList != null and hasDoneList.size()>0 ">
      and has_done in
      <foreach collection="hasDoneList" item="hasDone" open="(" close=")" separator=",">
        #{hasDone}
      </foreach>
    </if>
    order by create_time desc
  </select>
</mapper>