<?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="org.linlinjava.jz.db.dao.JzBuiltListMapper">
  <resultMap id="BaseResultMap" type="org.linlinjava.jz.db.domain.JzBuiltList">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="user_id" jdbcType="INTEGER" property="userId" />
    <result column="campaign_id" jdbcType="INTEGER" property="campaignId" />
    <result column="customer_id" jdbcType="INTEGER" property="customerId" />
    <result column="ticket_id" jdbcType="INTEGER" property="ticketId" />
    <result column="call_source" jdbcType="VARCHAR" property="callSource" />
    <result column="call_result" jdbcType="SMALLINT" property="callResult" />
    <result column="is_callback" jdbcType="BIT" property="isCallback" />
    <result column="contact_times" jdbcType="INTEGER" property="contactTimes" />
    <result column="last_call_time" jdbcType="TIMESTAMP" property="lastCallTime" />
    <result column="next_call_time" jdbcType="TIMESTAMP" property="nextCallTime" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_user" jdbcType="INTEGER" property="createUser" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="assigned_time" jdbcType="TIMESTAMP" property="assignedTime" />
    <result column="shop_id" jdbcType="INTEGER" property="shopId" />
    <association property="customer" column="customer_id" javaType="org.linlinjava.jz.db.domain.CustomerClient" select="getCustomer"/>

  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <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">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <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">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    id, user_id, campaign_id, customer_id, ticket_id, call_source, call_result, is_callback, 
    contact_times, last_call_time, next_call_time, create_time, create_user, remark, 
    assigned_time, shop_id
  </sql>
  <select id="selectByExample" parameterType="org.linlinjava.jz.db.domain.JzBuiltListExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from jz_built_list
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExampleSelective" parameterType="map" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="example != null and example.distinct">
      distinct
    </if>
    <choose>
      <when test="selective != null and selective.length &gt; 0">
        <foreach collection="selective" item="column" separator=",">
          ${column.aliasedEscapedColumnName}
        </foreach>
      </when>
      <otherwise>
        <include refid="Base_Column_List" />
      </otherwise>
    </choose>
    from jz_built_list
    <if test="example != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
    <if test="example != null and example.orderByClause != null">
      order by ${example.orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from jz_built_list
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectByPrimaryKeySelective" parameterType="map" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <choose>
      <when test="selective != null and selective.length &gt; 0">
        <foreach collection="selective" item="column" separator=",">
          ${column.aliasedEscapedColumnName}
        </foreach>
      </when>
      <otherwise>
        <include refid="Base_Column_List" />
      </otherwise>
    </choose>
    from jz_built_list
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from jz_built_list
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="org.linlinjava.jz.db.domain.JzBuiltListExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from jz_built_list
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="org.linlinjava.jz.db.domain.JzBuiltList">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into jz_built_list (user_id, campaign_id, customer_id, 
      ticket_id, call_source, call_result, 
      is_callback, contact_times, last_call_time, 
      next_call_time, create_time, create_user, 
      remark, assigned_time, shop_id
      )
    values (#{userId,jdbcType=INTEGER}, #{campaignId,jdbcType=INTEGER}, #{customerId,jdbcType=INTEGER}, 
      #{ticketId,jdbcType=INTEGER}, #{callSource,jdbcType=VARCHAR}, #{callResult,jdbcType=SMALLINT}, 
      #{isCallback,jdbcType=BIT}, #{contactTimes,jdbcType=INTEGER}, #{lastCallTime,jdbcType=TIMESTAMP}, 
      #{nextCallTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{createUser,jdbcType=INTEGER}, 
      #{remark,jdbcType=VARCHAR}, #{assignedTime,jdbcType=TIMESTAMP}, #{shopId,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="org.linlinjava.jz.db.domain.JzBuiltList">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into jz_built_list
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="userId != null">
        user_id,
      </if>
      <if test="campaignId != null">
        campaign_id,
      </if>
      <if test="customerId != null">
        customer_id,
      </if>
      <if test="ticketId != null">
        ticket_id,
      </if>
      <if test="callSource != null">
        call_source,
      </if>
      <if test="callResult != null">
        call_result,
      </if>
      <if test="isCallback != null">
        is_callback,
      </if>
      <if test="contactTimes != null">
        contact_times,
      </if>
      <if test="lastCallTime != null">
        last_call_time,
      </if>
      <if test="nextCallTime != null">
        next_call_time,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createUser != null">
        create_user,
      </if>
      <if test="remark != null">
        remark,
      </if>
      <if test="assignedTime != null">
        assigned_time,
      </if>
      <if test="shopId != null">
        shop_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="userId != null">
        #{userId,jdbcType=INTEGER},
      </if>
      <if test="campaignId != null">
        #{campaignId,jdbcType=INTEGER},
      </if>
      <if test="customerId != null">
        #{customerId,jdbcType=INTEGER},
      </if>
      <if test="ticketId != null">
        #{ticketId,jdbcType=INTEGER},
      </if>
      <if test="callSource != null">
        #{callSource,jdbcType=VARCHAR},
      </if>
      <if test="callResult != null">
        #{callResult,jdbcType=SMALLINT},
      </if>
      <if test="isCallback != null">
        #{isCallback,jdbcType=BIT},
      </if>
      <if test="contactTimes != null">
        #{contactTimes,jdbcType=INTEGER},
      </if>
      <if test="lastCallTime != null">
        #{lastCallTime,jdbcType=TIMESTAMP},
      </if>
      <if test="nextCallTime != null">
        #{nextCallTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null">
        #{createUser,jdbcType=INTEGER},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="assignedTime != null">
        #{assignedTime,jdbcType=TIMESTAMP},
      </if>
      <if test="shopId != null">
        #{shopId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="org.linlinjava.jz.db.domain.JzBuiltListExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from jz_built_list
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update jz_built_list
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.userId != null">
        user_id = #{record.userId,jdbcType=INTEGER},
      </if>
      <if test="record.campaignId != null">
        campaign_id = #{record.campaignId,jdbcType=INTEGER},
      </if>
      <if test="record.customerId != null">
        customer_id = #{record.customerId,jdbcType=INTEGER},
      </if>
      <if test="record.ticketId != null">
        ticket_id = #{record.ticketId,jdbcType=INTEGER},
      </if>
      <if test="record.callSource != null">
        call_source = #{record.callSource,jdbcType=VARCHAR},
      </if>
      <if test="record.callResult != null">
        call_result = #{record.callResult,jdbcType=SMALLINT},
      </if>
      <if test="record.isCallback != null">
        is_callback = #{record.isCallback,jdbcType=BIT},
      </if>
      <if test="record.contactTimes != null">
        contact_times = #{record.contactTimes,jdbcType=INTEGER},
      </if>
      <if test="record.lastCallTime != null">
        last_call_time = #{record.lastCallTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.nextCallTime != null">
        next_call_time = #{record.nextCallTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createUser != null">
        create_user = #{record.createUser,jdbcType=INTEGER},
      </if>
      <if test="record.remark != null">
        remark = #{record.remark,jdbcType=VARCHAR},
      </if>
      <if test="record.assignedTime != null">
        assigned_time = #{record.assignedTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.shopId != null">
        shop_id = #{record.shopId,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update jz_built_list
    set id = #{record.id,jdbcType=INTEGER},
      user_id = #{record.userId,jdbcType=INTEGER},
      campaign_id = #{record.campaignId,jdbcType=INTEGER},
      customer_id = #{record.customerId,jdbcType=INTEGER},
      ticket_id = #{record.ticketId,jdbcType=INTEGER},
      call_source = #{record.callSource,jdbcType=VARCHAR},
      call_result = #{record.callResult,jdbcType=SMALLINT},
      is_callback = #{record.isCallback,jdbcType=BIT},
      contact_times = #{record.contactTimes,jdbcType=INTEGER},
      last_call_time = #{record.lastCallTime,jdbcType=TIMESTAMP},
      next_call_time = #{record.nextCallTime,jdbcType=TIMESTAMP},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      create_user = #{record.createUser,jdbcType=INTEGER},
      remark = #{record.remark,jdbcType=VARCHAR},
      assigned_time = #{record.assignedTime,jdbcType=TIMESTAMP},
      shop_id = #{record.shopId,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="org.linlinjava.jz.db.domain.JzBuiltList">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update jz_built_list
    <set>
      <if test="userId != null">
        user_id = #{userId,jdbcType=INTEGER},
      </if>
      <if test="campaignId != null">
        campaign_id = #{campaignId,jdbcType=INTEGER},
      </if>
      <if test="customerId != null">
        customer_id = #{customerId,jdbcType=INTEGER},
      </if>
      <if test="ticketId != null">
        ticket_id = #{ticketId,jdbcType=INTEGER},
      </if>
      <if test="callSource != null">
        call_source = #{callSource,jdbcType=VARCHAR},
      </if>
      <if test="callResult != null">
        call_result = #{callResult,jdbcType=SMALLINT},
      </if>
      <if test="isCallback != null">
        is_callback = #{isCallback,jdbcType=BIT},
      </if>
      <if test="contactTimes != null">
        contact_times = #{contactTimes,jdbcType=INTEGER},
      </if>
      <if test="lastCallTime != null">
        last_call_time = #{lastCallTime,jdbcType=TIMESTAMP},
      </if>
      <if test="nextCallTime != null">
        next_call_time = #{nextCallTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null">
        create_user = #{createUser,jdbcType=INTEGER},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="assignedTime != null">
        assigned_time = #{assignedTime,jdbcType=TIMESTAMP},
      </if>
      <if test="shopId != null">
        shop_id = #{shopId,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="org.linlinjava.jz.db.domain.JzBuiltList">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update jz_built_list
    set user_id = #{userId,jdbcType=INTEGER},
      campaign_id = #{campaignId,jdbcType=INTEGER},
      customer_id = #{customerId,jdbcType=INTEGER},
      ticket_id = #{ticketId,jdbcType=INTEGER},
      call_source = #{callSource,jdbcType=VARCHAR},
      call_result = #{callResult,jdbcType=SMALLINT},
      is_callback = #{isCallback,jdbcType=BIT},
      contact_times = #{contactTimes,jdbcType=INTEGER},
      last_call_time = #{lastCallTime,jdbcType=TIMESTAMP},
      next_call_time = #{nextCallTime,jdbcType=TIMESTAMP},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_user = #{createUser,jdbcType=INTEGER},
      remark = #{remark,jdbcType=VARCHAR},
      assigned_time = #{assignedTime,jdbcType=TIMESTAMP},
      shop_id = #{shopId,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="selectOneByExample" parameterType="org.linlinjava.jz.db.domain.JzBuiltListExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <include refid="Base_Column_List" />
    from jz_built_list
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    limit 1
  </select>
  <select id="selectOneByExampleSelective" parameterType="map" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <choose>
      <when test="selective != null and selective.length &gt; 0">
        <foreach collection="selective" item="column" separator=",">
          ${column.aliasedEscapedColumnName}
        </foreach>
      </when>
      <otherwise>
        <include refid="Base_Column_List" />
      </otherwise>
    </choose>
    from jz_built_list
    <if test="example != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
    <if test="example != null and example.orderByClause != null">
      order by ${example.orderByClause}
    </if>
    limit 1
  </select>

  <!--管理客户信息-->
  <select id="getCustomer" parameterType="java.lang.Integer" resultMap="BaseResultMap2">
    select id,customer_name,tel   from customer_client   where id = #{customer_id,jdbcType=INTEGER}
  </select>

  <resultMap id="BaseResultMap2" type="org.linlinjava.jz.db.domain.CustomerClient">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="customer_name" jdbcType="VARCHAR" property="customerName" />
    <result column="tel" jdbcType="VARCHAR" property="tel" />
  </resultMap>
  
   <select id="getGroupCampaignCount" parameterType="java.lang.Integer" resultType="java.util.Map">
    select campaign_id as  campaignId,count(*) as campaignSum,jc.`name` 
	from jz_built_list jbl 
	left join jz_campaign jc on jbl.campaign_id=jc.id
     where user_id=#{userId} and call_result='0'
      group by campaign_id
  </select>
</mapper>