<?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.goafanti.common.dao.OrganizationManagementMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.OrganizationManagement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="create_id" jdbcType="VARCHAR" property="createId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="deleted_sign" jdbcType="VARCHAR" property="deletedSign" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="manager_id" jdbcType="VARCHAR" property="managerId" />
    <result column="dep_no" jdbcType="VARCHAR" property="depNo" />
    <result column="super_id" jdbcType="VARCHAR" property="superId" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="status" jdbcType="VARCHAR" property="status" />
    <result column="abbreviation" jdbcType="VARCHAR" property="abbreviation" />
    <result column="finance_id" jdbcType="VARCHAR" property="financeId" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    <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.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    <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.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    id, create_id, create_time, update_time, deleted_sign, name, type, manager_id, dep_no, 
    super_id, remarks, status,abbreviation,finance_id
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.OrganizationManagementExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from department
    <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">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    select 
    <include refid="Base_Column_List" />
    from department
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    delete from department
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.OrganizationManagementExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    delete from department
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.OrganizationManagement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    insert into department (id, create_id, create_time, 
      update_time, deleted_sign, name, 
      type, manager_id, dep_no, 
      super_id, remarks, status
      )
    values (#{id,jdbcType=VARCHAR}, #{createId,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{deletedSign,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{type,jdbcType=VARCHAR}, #{managerId,jdbcType=VARCHAR}, #{depNo,jdbcType=VARCHAR}, 
      #{superId,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.OrganizationManagement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    insert into department
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="createId != null">
        create_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="deletedSign != null">
        deleted_sign,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="managerId != null">
        manager_id,
      </if>
      <if test="depNo != null">
        dep_no,
      </if>
      <if test="superId != null">
        super_id,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="status != null">
        status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="createId != null">
        #{createId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedSign != null">
        #{deletedSign,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="managerId != null">
        #{managerId,jdbcType=VARCHAR},
      </if>
      <if test="depNo != null">
        #{depNo,jdbcType=VARCHAR},
      </if>
      <if test="superId != null">
        #{superId,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.OrganizationManagementExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    select count(*) from department
    <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.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    update department
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.createId != null">
        create_id = #{record.createId,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deletedSign != null">
        deleted_sign = #{record.deletedSign,jdbcType=VARCHAR},
      </if>
      <if test="record.name != null">
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.type != null">
        type = #{record.type,jdbcType=VARCHAR},
      </if>
      <if test="record.managerId != null">
        manager_id = #{record.managerId,jdbcType=VARCHAR},
      </if>
      <if test="record.depNo != null">
        dep_no = #{record.depNo,jdbcType=VARCHAR},
      </if>
      <if test="record.superId != null">
        super_id = #{record.superId,jdbcType=VARCHAR},
      </if>
      <if test="record.remarks != null">
        remarks = #{record.remarks,jdbcType=VARCHAR},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=VARCHAR},
      </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.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    update department
    set id = #{record.id,jdbcType=VARCHAR},
      create_id = #{record.createId,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      deleted_sign = #{record.deletedSign,jdbcType=VARCHAR},
      name = #{record.name,jdbcType=VARCHAR},
      type = #{record.type,jdbcType=VARCHAR},
      manager_id = #{record.managerId,jdbcType=VARCHAR},
      dep_no = #{record.depNo,jdbcType=VARCHAR},
      super_id = #{record.superId,jdbcType=VARCHAR},
      remarks = #{record.remarks,jdbcType=VARCHAR},
      status = #{record.status,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.OrganizationManagement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    update department
    <set>
      <if test="createId != null">
        create_id = #{createId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedSign != null">
        deleted_sign = #{deletedSign,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=VARCHAR},
      </if>
      <if test="managerId != null">
        manager_id = #{managerId,jdbcType=VARCHAR},
      </if>
      <if test="depNo != null">
        dep_no = #{depNo,jdbcType=VARCHAR},
      </if>
      <if test="superId != null">
        super_id = #{superId,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=VARCHAR},
      </if>
      <if test="abbreviation != null">
        abbreviation = #{abbreviation,jdbcType=VARCHAR},
      </if>
      <if test="financeId != null">
        finance_id = #{financeId,jdbcType=VARCHAR},
      </if>
      <if test="province != null">
        province = #{province,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.OrganizationManagement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 11:09:29 CST 2017.
    -->
    update department
    set create_id = #{createId,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      deleted_sign = #{deletedSign,jdbcType=VARCHAR},
      name = #{name,jdbcType=VARCHAR},
      type = #{type,jdbcType=VARCHAR},
      manager_id = #{managerId,jdbcType=VARCHAR},
      dep_no = #{depNo,jdbcType=VARCHAR},
      super_id = #{superId,jdbcType=VARCHAR},
      remarks = #{remarks,jdbcType=VARCHAR},
      status = #{status,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
	<select id="selectOrganizationList" parameterType="String" resultType="com.goafanti.organization.bo.OrganizationListOut">
		select
			om.id,om.create_id as createId,om.create_time as createTime,
			om.update_time as updateTime,om.deleted_sign as deletedSign,
			om.name,om.type,
			om.dep_no as depNo,
			om.remarks,
			om.status,
			dm.name as superName,
			x.name as managerName
		from department om 
		left join department dm on om.super_id = dm.id
		left join admin x on om.manager_id = x.id
		where
			om.deleted_sign = '0'
			and
			om.name != '平台超管中心'
		<if test="name !=null">
			AND om.name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
		</if>
		<if test="superId !=null">
			AND om.super_id=#{superId,jdbcType=VARCHAR}
		</if>
		<if test="type !=null">
			AND om.type=#{type,jdbcType=VARCHAR}
		</if>
		<if test="depNo !=null">
			AND om.dep_no=#{depNo,jdbcType=VARCHAR}
		</if>
		<if test="page_sql != null">
    		${page_sql}
   		</if>
	</select>
	<select id="selectOrganizationCount" resultType="java.lang.Integer">
		select
			count(0)
		from department om
		left join department dm on om.super_id = dm.id
		left join admin x on om.manager_id = x.id
		where
			om.deleted_sign='0'
		<if test="name !=null">
			AND om.name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
		</if>
		<if test="superId !=null">
			AND om.super_id=#{superId,jdbcType=VARCHAR}
		</if>
		<if test="type !=null">
			AND om.type=#{type,jdbcType=VARCHAR}
		</if>
		<if test="depNo !=null">
			AND om.dep_no=#{depNo,jdbcType=VARCHAR}
		</if>	
	</select>
	<select id="selectSuperId"  resultType="com.goafanti.organization.bo.OrganizationListOut">
		select
		id,name,dep_no as depNo
		from department
		where
		status ='0'
		order by CONVERT (name USING gbk)
		<if test="sort ==1" >
		limit 10	
		</if>
	</select>
	<insert id="insert1" parameterType="com.goafanti.organization.bo.OrganizationListOut">
		insert into department(
		id,create_id,create_time,update_time,deleted_sign,
		name,type,manager_id,dep_no,super_id,desc,status)
		values(#{id,jdbcType=VARCHAR},#{createId,jdbcType=VARCHAR},
		#{createTime,jdbcType=VARCHAR},#{updateTime,jdbcType=VARCHAR},
		#{deletedSign,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},
		#{type,jdbcType=VARCHAR},#{managerId,jdbcType=VARCHAR},
		#{depNo,jdbcType=VARCHAR},#{superId,jdbcType=VARCHAR},
		#{desc,jdbcType=VARCHAR},#{status,jdbcType=VARCHAR})	
	</insert>
	<!-- 得到上级 -->
	<select id="selectDepNo" resultType="String">
	select
	dep_no as depNo
		from department
		where
		id=#{superId,jdbcType=VARCHAR}
	</select>
	
	<select id="selectDepNoByName" resultType="String">
		select
		dep_no as depNo
		from department
		where
		name=#{name,jdbcType=VARCHAR}
	</select>
	<select id="selectDepNoCount" parameterType="String" resultType="java.lang.Integer">
		select
		count(0)
		from department
		where
		<!-- dep_no like concat(#{depNo,jdbcType=VARCHAR},'%') -->
		super_id=#{superId,jdbcType=VARCHAR}
	</select>
	<select id="selectName" resultType="com.goafanti.admin.bo.AdminListBo">
		select
		name,id
		from admin
		where status='正常'
		and name  like concat('%',#{name,jdbcType=VARCHAR},'%')
	</select>
	<select id="selectAllById" resultType="com.goafanti.organization.bo.OrganizationListOut">
	select
		a.id,
		a.create_id as createId,
		a.create_time as createTime,
		a.update_time as updateTime,
		a.deleted_sign as deletedSign,
		a.name,
		a.type,
		a.manager_id as managerId,
		a.dep_no as depNo,
		a.super_id as superId,
		a.remarks,
		a.status,
		a.abbreviation,
		a.finance_id financeId,
		a.province,
		c.name financeName,
		b.name as managerName
	from department a 
	left join admin b on a.manager_id = b.id
	left join admin c on a.finance_id = c.id
	where 
		a.id=#{id,jdbcType=VARCHAR}
	</select>
	<delete id="deleteById" parameterType="java.lang.String">
	    delete from department
	    where id = #{id,jdbcType=VARCHAR}
  	</delete>
  	<select id="selectAdminNameById" parameterType="java.lang.String" resultType="java.lang.String">
  		select 
  		name
  		from admin
  		where 
  		id=#{id,jdbcType=VARCHAR}
  	</select>
  	<select id="selectIdByDepNo" parameterType="java.lang.String" resultType="java.lang.String">
  		select
  		id
  		from department
  		where
  		dep_no=#{depNo,jdbcType=VARCHAR}
  	</select>
  	<select id="selectIDNBySuperId" parameterType="java.lang.String" resultType="com.goafanti.organization.bo.OrganizationListOut">
  		select
  		id,create_id as createId,create_time as createTime,
		update_time as updateTime,deleted_sign as deletedSign,
		name,type,manager_id as managerId,
		dep_no as depNo,
		super_id as superId,
		remarks,status
  		from department 		
  		where
  		super_id=#{id,jdbcType=VARCHAR}
  		order by dep_no
  	</select>
  	<update id="updateByNumber" parameterType="com.goafanti.organization.bo.OrganizationListOut">
  		update department
	    <set>
	    	dep_no = #{depNo,jdbcType=VARCHAR}
	    </set>
	    where
	    id=#{id,jdbcType=VARCHAR}
  	</update>
  	<select id="selectCountBySuperId" parameterType="String" resultType="java.lang.Integer">
  		select
		count(0)
		from department
		where
		super_id=#{superId,jdbcType=VARCHAR}
  	</select>
  	<select id="selectIdByName" parameterType="java.lang.String" resultType="java.lang.String">
  		select
  		id
  		from department 		
  		where
  		name=#{name,jdbcType=VARCHAR} 		
  	</select>
  	<select id="selectNameById" parameterType="java.lang.String" resultType="java.lang.String">
  		select
  		name
  		from department 		
  		where
  		id=#{id,jdbcType=VARCHAR} 		
  	</select>
  	<select id="selectDepNoById" resultType="String">
		select
		dep_no as depNo
		from department
		where
		id=#{id,jdbcType=VARCHAR}
	</select>
	<select id="selectUserById" parameterType="java.lang.String" resultType="java.lang.Integer">
		select
		count(0)
		from admin
		where
		department_id=#{id,jdbcType=VARCHAR}
	</select>
	<!-- 查询当前层级 -->
	<select id="selectCurrentDeps" parameterType="java.lang.String" resultMap="BaseResultMap">
		select id,name,dep_no,super_id from department where manager_id = #{aid,jdbcType=VARCHAR}
			union all
		select id,name,dep_no,super_id from department where id = (select department_id from admin where id = #{aid,jdbcType=VARCHAR})
	</select>
	<!-- 查询下一层级  -->
	<select id="selectSubDeps"  parameterType="java.lang.String" resultMap="BaseResultMap">
		select id,name,dep_no from department where super_id in (#{superIds,jdbcType=VARCHAR})
	</select>
	
	<select id="selectBysuperName"  resultType="com.goafanti.admin.bo.depCountBo">
		select a.id ,a.name ,0 userCount,0 inputCount,0 receiveCount, 0 completeCount, 0 interviewCount
		from department a left join department b on a.super_id=b.id where b.name= #{superName,jdbcType=VARCHAR}
	</select>
	
	<select id="selectAll" resultType="com.goafanti.admin.bo.depCountBo">
		select a.id ,a.name ,0 userCount,0 inputCount,0 receiveCount, 0 completeCount, 0 interviewCount
		from department a left join department b on a.super_id=b.id
	</select>
	
	<!-- 查询所有 -->
	<select id="selectAllDeps" resultMap="BaseResultMap">
		select id,name,dep_no from department
	</select>
	<select id="getMaxAbbreviation"  parameterType="java.lang.String" resultType="java.lang.String">
	select max(contract_no) as maxNo from t_order_new
	where create_time > '2019-5-31'
	and contract_no like  concat(#{abbreviation,jdbcType=VARCHAR},'%') 
	</select>
	
	<select id="getDepAll" resultType="com.goafanti.admin.bo.AdminCustomerBo">
	select a.id as aid,a.name as aName,d.id depId,d.name as depName,ifnull(b.userCount,0) as userCount,ifnull(c.timeCount,0) as inputCount,
  	ifnull(d.timeCount,0) as receiveCount, ifnull(e.completeCount,0)completeCount,ifnull(f.interviewCount,0)interviewCount
  	from admin a 
	left join (select aid,count(aid) as userCount from user where aid is not null  
	and  share_type=0 and source !=0 and type=1
	group by aid) b on a.id=b.aid
	left join (select aid,count(aid) as timeCount from `user` where aid is not null  
	and  share_type=0 and source =1 and type=1
	<if test="startTime != null and endTime != null"> 
    and  create_time  between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
    </if>
	group by aid) c on a.id=c.aid
	left join (select aid,count(aid) as timeCount from `user` where aid is not null  
	and  share_type=0 and source =2 and type=1
	<if test="startTime != null and endTime != null"> 
    and  transfer_time  between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
    </if>
	group by aid) d on a.id=d.aid
	left join (select x.aid,count(uid) completeCount from (select a.aid,a.uid from user_business a left join `user` b on a.uid=b.id where a.follow_situation=5
	  <if test="startTime != null and endTime != null"> 
    and  a.update_time  between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
    </if>
	and b.`type`=1 group by aid,uid)x group by aid)e on a.id=e.aid 
	left join (select x.aid,count(uid) interviewCount from (select a.aid,a.uid from user_business a left join `user` b on a.uid=b.id where a.follow_situation=1
	  <if test="startTime != null and endTime != null"> 
    and  a.update_time  between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
    </if>
	and b.`type`=1 group by aid,uid)x group by aid)f on a.id=f.aid
	left join department d on a.department_id=d.id
	left join user_role e on a.id=e.uid
	left join `role` f on e.rid=f.id
	where f.role_name in ('营销员','营销经理')	
	and	 a.status='正常' 
	<if test="depName !=null">
	and d.name= #{depName}
	</if>
	<if test="adminName !=null">
	and a.name  like concat('%',#{adminName},'%')  
	</if>
	<if test="depId !=null">
	and d.id= #{depId}
	</if>
	</select>
</mapper>