<?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.VisitPlanTaskExtMapper">
  <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.visit.VisitPlanTask">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="plan_id" jdbcType="VARCHAR" property="planId" />
    <result column="urser_id" jdbcType="VARCHAR" property="urserId" />
    <result column="wgy_name" jdbcType="VARCHAR" property="wgyName" />
    <result column="wgy_code" jdbcType="VARCHAR" property="wgyCode" />
    <result column="obj_wg_code" jdbcType="VARCHAR" property="objWgCode" />
    <result column="visit_plan_user_id" jdbcType="VARCHAR" property="visitPlanUserId" />
    <result column="visit_plan_obj_id" jdbcType="VARCHAR" property="visitPlanObjId" />
    <result column="obj_name" jdbcType="VARCHAR" property="objName" />
    <result column="obj_id" jdbcType="VARCHAR" property="objId" />
    <result column="obj_type" jdbcType="VARCHAR" property="objType" />
    <result column="obj_number" jdbcType="VARCHAR" property="objNumber" />
    <result column="obj_user_name" jdbcType="VARCHAR" property="objUserName" />
    <result column="plan_task_status" jdbcType="VARCHAR" property="planTaskStatus" />
    <result column="task_id" jdbcType="VARCHAR" property="taskId" />
    <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="ylzd1" jdbcType="VARCHAR" property="ylzd1" />
    <result column="ylzd2" jdbcType="VARCHAR" property="ylzd2" />
    <result column="ylzd3" jdbcType="VARCHAR" property="ylzd3" />
    <result column="ylzd4" jdbcType="VARCHAR" property="ylzd4" />
    <result column="ylzd5" jdbcType="VARCHAR" property="ylzd5" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.ruoyi.system.domain.visit.VisitPlanTask">
    <result column="plan_task_feedback" jdbcType="LONGVARCHAR" property="planTaskFeedback" />
  </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_id,urser_id, wgy_name, wgy_code, obj_wg_code, visit_plan_user_id,
    visit_plan_obj_id, obj_name, obj_id, obj_type, obj_number, obj_user_name, plan_task_status,
    task_id, create_time, create_by, update_time, update_by, is_valid, ylzd1, ylzd2,
    ylzd3, ylzd4, ylzd5
  </sql>
  <sql id="Blob_Column_List">
    plan_task_feedback
  </sql>

  <insert id="insertForList" parameterType="java.util.List">
    insert into visit_plan_task
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <include refid="Base_Column_List" />
      ,
      <include refid="Blob_Column_List" />
    </trim>
    values
    <foreach collection="list" item="obj" index="index" separator="," >
      (#{obj.id,jdbcType=VARCHAR}, #{obj.planId,jdbcType=VARCHAR},
      #{obj.urserId,jdbcType=VARCHAR}, #{obj.wgyName,jdbcType=VARCHAR}, #{obj.wgyCode,jdbcType=VARCHAR},
      #{obj.objWgCode,jdbcType=VARCHAR}, #{obj.visitPlanUserId,jdbcType=VARCHAR}, #{obj.visitPlanObjId,jdbcType=VARCHAR},
      #{obj.objName,jdbcType=VARCHAR}, #{obj.objId,jdbcType=VARCHAR}, #{obj.objType,jdbcType=VARCHAR},
      #{obj.objNumber,jdbcType=VARCHAR}, #{obj.objUserName,jdbcType=VARCHAR}, #{obj.planTaskStatus,jdbcType=VARCHAR},
      #{obj.taskId,jdbcType=VARCHAR}, #{obj.createTime,jdbcType=TIMESTAMP}, #{obj.createBy,jdbcType=VARCHAR},
      #{obj.updateTime,jdbcType=TIMESTAMP}, #{obj.updateBy,jdbcType=VARCHAR}, #{obj.isValid,jdbcType=VARCHAR},
      #{obj.ylzd1,jdbcType=VARCHAR}, #{obj.ylzd2,jdbcType=VARCHAR}, #{obj.ylzd3,jdbcType=VARCHAR},
      #{obj.ylzd4,jdbcType=VARCHAR}, #{obj.ylzd5,jdbcType=VARCHAR}, #{obj.planTaskFeedback,jdbcType=LONGVARCHAR}
      )
    </foreach>
  </insert>
  <select id="selectAqzfTj" resultType="java.util.Map">
    SELECT
      wpt.obj_wg_code,count(wpt.id) as count,bs.wg_parent_id as parentCode
    FROM
      visit_plan_task wpt
      LEFT JOIN grid_region bs on bs.wg_code = obj_wg_code
    WHERE
    (
      wpt.is_valid = 1 and bs.wg_parent_id is not null
    AND <![CDATA[ wpt.create_time >=  DATE_FORMAT(#{startTime,jdbcType=DATE}, '%Y-%m-%d %H:%i:%s') ]]>
    AND <![CDATA[ wpt.create_time <=  DATE_FORMAT(#{endTime,jdbcType=DATE}, '%Y-%m-%d %H:%i:%s') ]]>
    AND wpt.obj_type IN ("1","2")
    )
    GROUP BY wpt.obj_wg_code
    ORDER BY count
  </select>
  <select id="listByParams" resultType="com.ruoyi.system.domain.visit.VisitPlanTask" parameterType="com.ruoyi.system.domain.visit.vo.VisitPlanTaskSearchParam">
    select * from visit_plan_task where is_valid = '1'
    <if test="objType != null and objType != ''">
      and obj_type = #{objType}
    </if>
    <if test="planTaskStatus != null and planTaskStatus != ''">
      and plan_task_status = #{planTaskStatus}
    </if>
    <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
      and (
      <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
        wgy_code like CONCAT(#{wgCode}, '%')
      </foreach>
      )
    </if>
    <if test="startDate != null and startDate != ''">
      and DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= #{startDate}
    </if>
    <if test="endDate != null and endDate != ''">
      and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= #{endDate}
    </if>
  </select>
  <select id="countByParam" resultType="java.lang.Integer" parameterType="com.ruoyi.system.domain.visit.vo.VisitPlanTaskSearchParam">
    select count(1) from visit_plan_task where is_valid = '1'
    <if test="objType != null and objType != ''">
      and obj_type = #{objType}
    </if>
    <if test="planTaskStatus != null and planTaskStatus != ''">
      and plan_task_status = #{planTaskStatus}
    </if>
    <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
      and (
      <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
        wgy_code like CONCAT(#{wgCode}, '%')
      </foreach>
      )
    </if>
    <if test="startDate != null and startDate != ''">
      and DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= #{startDate}
    </if>
    <if test="endDate != null and endDate != ''">
      and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= #{endDate}
    </if>
  </select>

</mapper>
