<?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.UserMidMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.UserMid">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="uid" jdbcType="VARCHAR" property="uid" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="last_follow_time" jdbcType="TIMESTAMP" property="lastFollowTime" />
    <result column="last_sign_time" jdbcType="TIMESTAMP" property="lastSignTime" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="big_customer" jdbcType="INTEGER" property="bigCustomer" />
    <result column="update_aid" jdbcType="VARCHAR" property="updateAid" />
    <result column="update_name" jdbcType="VARCHAR" property="updateName" />
    <result column="date_update_time" jdbcType="TIMESTAMP" property="dateUpdateTime" />
    <result column="channel_type" jdbcType="INTEGER" property="channelType" />
    <result column="chargeback" jdbcType="INTEGER" property="chargeback" />
    <result column="member" jdbcType="INTEGER" property="member" />
    <result column="last_sales_type" jdbcType="INTEGER" property="lastSalesType" />
    <result column="last_follow_type" jdbcType="INTEGER" property="lastFollowType" />
    <result column="follow_number" jdbcType="INTEGER" property="followNumber" />
    <result column="task_names" jdbcType="VARCHAR" property="taskNames" />
    <result column="sign_number" jdbcType="INTEGER" property="signNumber" />
    <result column="sign_amount" jdbcType="DECIMAL" property="signAmount" />
    <result column="last_signing_time" jdbcType="DATE" property="lastSigningTime" />
    <result column="first_signing_time" jdbcType="DATE" property="firstSigningTime" />
    <result column="follow_dep" jdbcType="VARCHAR" property="followDep" />
    <result column="follow_explain" jdbcType="VARCHAR" property="followExplain" />
    <result column="follow_aname" jdbcType="VARCHAR" property="followAname" />
    <result column="follow_aid" jdbcType="VARCHAR" property="followAid" />
  </resultMap>
  <sql id="Base_Column_List">
    id, `uid`, aid, last_follow_time, last_sign_time, create_time, big_customer, update_aid,
    update_name, date_update_time, channel_type, chargeback, `member`, last_sales_type,
    last_follow_type, follow_number, task_names, sign_number, sign_amount, last_signing_time,
    first_signing_time, follow_dep, follow_explain, follow_aname, follow_aid
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from user_mid
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from user_mid
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.UserMid" useGeneratedKeys="true">
    insert into user_mid (`uid`, aid, last_follow_time,
      last_sign_time, create_time, big_customer,
      update_aid, update_name, date_update_time,
      channel_type, chargeback, `member`,
      last_sales_type, last_follow_type, follow_number,
      task_names, sign_number, sign_amount,
      last_signing_time, first_signing_time, follow_dep,
      follow_explain, follow_aname, follow_aid
      )
    values (#{uid,jdbcType=VARCHAR}, #{aid,jdbcType=VARCHAR}, #{lastFollowTime,jdbcType=TIMESTAMP},
      #{lastSignTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{bigCustomer,jdbcType=INTEGER},
      #{updateAid,jdbcType=VARCHAR}, #{updateName,jdbcType=VARCHAR}, #{dateUpdateTime,jdbcType=TIMESTAMP},
      #{channelType,jdbcType=INTEGER}, #{chargeback,jdbcType=INTEGER}, #{member,jdbcType=INTEGER},
      #{lastSalesType,jdbcType=INTEGER}, #{lastFollowType,jdbcType=INTEGER}, #{followNumber,jdbcType=INTEGER},
      #{taskNames,jdbcType=VARCHAR}, #{signNumber,jdbcType=INTEGER}, #{signAmount,jdbcType=DECIMAL},
      #{lastSigningTime,jdbcType=DATE}, #{firstSigningTime,jdbcType=DATE}, #{followDep,jdbcType=VARCHAR},
      #{followExplain,jdbcType=VARCHAR}, #{followAname,jdbcType=VARCHAR}, #{followAid,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.UserMid" useGeneratedKeys="true">
    insert into user_mid
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="uid != null">
        `uid`,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="lastFollowTime != null">
        last_follow_time,
      </if>
      <if test="lastSignTime != null">
        last_sign_time,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="bigCustomer != null">
        big_customer,
      </if>
      <if test="updateAid != null">
        update_aid,
      </if>
      <if test="updateName != null">
        update_name,
      </if>
      <if test="dateUpdateTime != null">
        date_update_time,
      </if>
      <if test="channelType != null">
        channel_type,
      </if>
      <if test="chargeback != null">
        chargeback,
      </if>
      <if test="member != null">
        `member`,
      </if>
      <if test="lastSalesType != null">
        last_sales_type,
      </if>
      <if test="lastFollowType != null">
        last_follow_type,
      </if>
      <if test="followNumber != null">
        follow_number,
      </if>
      <if test="taskNames != null">
        task_names,
      </if>
      <if test="signNumber != null">
        sign_number,
      </if>
      <if test="signAmount != null">
        sign_amount,
      </if>
      <if test="lastSigningTime != null">
        last_signing_time,
      </if>
      <if test="firstSigningTime != null">
        first_signing_time,
      </if>
      <if test="followDep != null">
        follow_dep,
      </if>
      <if test="followExplain != null">
        follow_explain,
      </if>
      <if test="followAname != null">
        follow_aname,
      </if>
      <if test="followAid != null">
        follow_aid,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="uid != null">
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="lastFollowTime != null">
        #{lastFollowTime,jdbcType=TIMESTAMP},
      </if>
      <if test="lastSignTime != null">
        #{lastSignTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="bigCustomer != null">
        #{bigCustomer,jdbcType=INTEGER},
      </if>
      <if test="updateAid != null">
        #{updateAid,jdbcType=VARCHAR},
      </if>
      <if test="updateName != null">
        #{updateName,jdbcType=VARCHAR},
      </if>
      <if test="dateUpdateTime != null">
        #{dateUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="channelType != null">
        #{channelType,jdbcType=INTEGER},
      </if>
      <if test="chargeback != null">
        #{chargeback,jdbcType=INTEGER},
      </if>
      <if test="member != null">
        #{member,jdbcType=INTEGER},
      </if>
      <if test="lastSalesType != null">
        #{lastSalesType,jdbcType=INTEGER},
      </if>
      <if test="lastFollowType != null">
        #{lastFollowType,jdbcType=INTEGER},
      </if>
      <if test="followNumber != null">
        #{followNumber,jdbcType=INTEGER},
      </if>
      <if test="taskNames != null">
        #{taskNames,jdbcType=VARCHAR},
      </if>
      <if test="signNumber != null">
        #{signNumber,jdbcType=INTEGER},
      </if>
      <if test="signAmount != null">
        #{signAmount,jdbcType=DECIMAL},
      </if>
      <if test="lastSigningTime != null">
        #{lastSigningTime,jdbcType=DATE},
      </if>
      <if test="firstSigningTime != null">
        #{firstSigningTime,jdbcType=DATE},
      </if>
      <if test="followDep != null">
        #{followDep,jdbcType=VARCHAR},
      </if>
      <if test="followExplain != null">
        #{followExplain,jdbcType=VARCHAR},
      </if>
      <if test="followAname != null">
        #{followAname,jdbcType=VARCHAR},
      </if>
      <if test="followAid != null">
        #{followAid,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.UserMid">
    update user_mid
    <set>
      <if test="uid != null">
        `uid` = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="lastFollowTime != null">
        last_follow_time = #{lastFollowTime,jdbcType=TIMESTAMP},
      </if>
      <if test="lastSignTime != null">
        last_sign_time = #{lastSignTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="bigCustomer != null">
        big_customer = #{bigCustomer,jdbcType=INTEGER},
      </if>
      <if test="updateAid != null">
        update_aid = #{updateAid,jdbcType=VARCHAR},
      </if>
      <if test="updateName != null">
        update_name = #{updateName,jdbcType=VARCHAR},
      </if>
      <if test="dateUpdateTime != null">
        date_update_time = #{dateUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="channelType != null">
        channel_type = #{channelType,jdbcType=INTEGER},
      </if>
      <if test="chargeback != null">
        chargeback = #{chargeback,jdbcType=INTEGER},
      </if>
      <if test="member != null">
        `member` = #{member,jdbcType=INTEGER},
      </if>
      <if test="lastSalesType != null">
        last_sales_type = #{lastSalesType,jdbcType=INTEGER},
      </if>
      <if test="lastFollowType != null">
        last_follow_type = #{lastFollowType,jdbcType=INTEGER},
      </if>
      <if test="followNumber != null">
        follow_number = #{followNumber,jdbcType=INTEGER},
      </if>
      <if test="taskNames != null">
        task_names = #{taskNames,jdbcType=VARCHAR},
      </if>
      <if test="signNumber != null">
        sign_number = #{signNumber,jdbcType=INTEGER},
      </if>
      <if test="signAmount != null">
        sign_amount = #{signAmount,jdbcType=DECIMAL},
      </if>
      <if test="lastSigningTime != null">
        last_signing_time = #{lastSigningTime,jdbcType=DATE},
      </if>
      <if test="firstSigningTime != null">
        first_signing_time = #{firstSigningTime,jdbcType=DATE},
      </if>
      <if test="followDep != null">
        follow_dep = #{followDep,jdbcType=VARCHAR},
      </if>
      <if test="followExplain != null">
        follow_explain = #{followExplain,jdbcType=VARCHAR},
      </if>
      <if test="followAname != null">
        follow_aname = #{followAname,jdbcType=VARCHAR},
      </if>
      <if test="followAid != null">
        follow_aid = #{followAid,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.UserMid">
    update user_mid
    set `uid` = #{uid,jdbcType=VARCHAR},
      aid = #{aid,jdbcType=VARCHAR},
      last_follow_time = #{lastFollowTime,jdbcType=TIMESTAMP},
      last_sign_time = #{lastSignTime,jdbcType=TIMESTAMP},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      big_customer = #{bigCustomer,jdbcType=INTEGER},
      update_aid = #{updateAid,jdbcType=VARCHAR},
      update_name = #{updateName,jdbcType=VARCHAR},
      date_update_time = #{dateUpdateTime,jdbcType=TIMESTAMP},
      channel_type = #{channelType,jdbcType=INTEGER},
      chargeback = #{chargeback,jdbcType=INTEGER},
      `member` = #{member,jdbcType=INTEGER},
      last_sales_type = #{lastSalesType,jdbcType=INTEGER},
      last_follow_type = #{lastFollowType,jdbcType=INTEGER},
      follow_number = #{followNumber,jdbcType=INTEGER},
      task_names = #{taskNames,jdbcType=VARCHAR},
      sign_number = #{signNumber,jdbcType=INTEGER},
      sign_amount = #{signAmount,jdbcType=DECIMAL},
      last_signing_time = #{lastSigningTime,jdbcType=DATE},
      first_signing_time = #{firstSigningTime,jdbcType=DATE},
      follow_dep = #{followDep,jdbcType=VARCHAR},
      follow_explain = #{followExplain,jdbcType=VARCHAR},
      follow_aname = #{followAname,jdbcType=VARCHAR},
      follow_aid = #{followAid,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>


  <update id="updateByUid" parameterType="com.goafanti.common.model.UserMid">
    update user_mid
    <set>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="lastFollowTime != null">
        last_follow_time = #{lastFollowTime,jdbcType=TIMESTAMP},
      </if>
      <if test="lastSignTime != null">
        last_sign_time = #{lastSignTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="bigCustomer != null">
        big_customer = #{bigCustomer,jdbcType=INTEGER},
      </if>
      <if test="updateAid != null">
        update_aid = #{updateAid,jdbcType=VARCHAR},
      </if>
      <if test="updateName != null">
        update_name = #{updateName,jdbcType=VARCHAR},
      </if>
      <if test="dateUpdateTime != null">
        date_update_time = #{dateUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="channelType != null">
        channel_type = #{channelType,jdbcType=INTEGER},
      </if>
      <if test="chargeback != null">
        chargeback = #{chargeback,jdbcType=INTEGER},
      </if>
      <if test="member != null">
        `member` = #{member,jdbcType=INTEGER},
      </if>
      <if test="lastSalesType != null">
        last_sales_type = #{lastSalesType,jdbcType=INTEGER},
      </if>
      <if test="lastFollowType != null">
        last_follow_type = #{lastFollowType,jdbcType=INTEGER},
      </if>
      <if test="followNumber != null">
        follow_number = #{followNumber,jdbcType=INTEGER},
      </if>
      <if test="taskNames != null">
        task_names = #{taskNames,jdbcType=VARCHAR},
      </if>
      <if test="signNumber != null">
        sign_number = #{signNumber,jdbcType=INTEGER},
      </if>
      <if test="signAmount != null">
        sign_amount = #{signAmount,jdbcType=DECIMAL},
      </if>
      <if test="lastSigningTime != null">
        last_signing_time = #{lastSigningTime,jdbcType=DATE},
      </if>
      <if test="firstSigningTime != null">
        first_signing_time = #{firstSigningTime,jdbcType=DATE},
      </if>
      <if test="followDep != null">
        follow_dep = #{followDep,jdbcType=VARCHAR},
      </if>
      <if test="followExplain != null">
        follow_explain = #{followExplain,jdbcType=VARCHAR},
      </if>
      <if test="followAname != null">
        follow_aname = #{followAname,jdbcType=VARCHAR},
      </if>
      <if test="followAid != null">
        follow_aid = #{followAid,jdbcType=VARCHAR},
      </if>
    </set>
    where `uid` = #{uid,jdbcType=VARCHAR}
  </update>


  <update id="updateListByUid" parameterType="com.goafanti.common.model.UserMid">
    update user_mid
    <set>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="updateFollow ==1">
        last_follow_time = null,
      </if>
      <if test="lastSignTime != null">
        last_sign_time = #{lastSignTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="bigCustomer != null">
        big_customer = #{bigCustomer,jdbcType=INTEGER},
      </if>
      <if test="updateAid != null">
        update_aid = #{updateAid,jdbcType=VARCHAR},
      </if>
      <if test="updateName != null">
        update_name = #{updateName,jdbcType=VARCHAR},
      </if>
      <if test="dateUpdateTime != null">
        date_update_time = #{dateUpdateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where `uid` in
    <foreach item="item" collection="list" separator="," open="(" close=")" index="">
      #{item}
    </foreach>
  </update>

  <select id="getUserTaskNames" resultType="java.lang.String">
    select group_concat(distinct b.commodity_name)task_names from t_order_new a
                                                                    left join t_order_task b on a.order_no =b.order_no
    where a.buyer_id = #{uid}
    group by  a.buyer_id
  </select>
  <select id="getUserDtails" resultType="com.goafanti.common.model.UserMid">
    select a.buyer_id uid,min(a.sign_time)firstSigningTime,max(a.sign_time)lastSigningTime,
           sum(a.total_amount)signAmount,count(*)signNumber
    from t_order_new a
    where a.delete_sign in (0,2) and a.process_status >4
      and a.buyer_id= #{uid}
    group by a.buyer_id
  </select>

  <select id="selectSignSummaryList" resultType="com.goafanti.order.bo.OutSignSummary">
    select a.id ,a.nickname ,b.sign_number signNumber,b.sign_amount signAmount,
    date_format(b.first_signing_time ,'%Y-%m-%d') firstSigningTime,
    date_format(b.last_signing_time  ,'%Y-%m-%d') lastSigningTime ,
    b.last_sales_type  lastSalesType,c.name,d.name depName,
    b.last_follow_type lastFollowType,b.follow_explain followExplain ,b.follow_number followNumber ,
    date_format(b.last_follow_time ,'%Y-%m-%d %H:%i:%S') lastFollowTime ,b.task_names taskNames ,
    b.`member` ,b.chargeback ,b.big_customer bigCustomer,b.follow_aname followAname
    from user a left join user_mid b on a.id=b.uid  left join admin c on a.aid=c.id
    left join department d on c.department_id =d.id
    where a.share_type =2
    <if test="userName != null">
      and a.nickname like concat('%',#{userName},'%')
    </if>
    <if test="aid != null">
      and c.id =#{aid}
    </if>
    <if test="followAid != null">
      and b.follow_aid =#{followAid}
    </if>
    <if test="member != null">
      and b.`member` = #{member}
    </if>
    <if test="chargeback != null">
      and b.chargeback = #{chargeback}
    </if>
    <if test="bigCustomer != null">
      and b.big_customer = #{bigCustomer}
    </if>
    <if test="lastFollowType != null">
      and b.last_follow_type = #{lastFollowType}
    </if>
    <if test="depId != null">
      and c.department_id  = #{depId}
    </if>
    <if test="lastFollowTimeStart != null and lastFollowTimeEnd !=null">
      and b.last_follow_time BETWEEN #{lastFollowTimeStart} and #{lastFollowTimeEnd}
    </if>
    <if test="firstSigningTimeStart != null and firstSigningTimeEnd !=null">
      and b.first_signing_time BETWEEN #{firstSigningTimeStart} and #{firstSigningTimeEnd}
    </if>
    <if test="lastSigningTimeStart != null and lastSigningTimeStart !=null">
      and b.last_signing_time BETWEEN #{lastSigningTimeStart} and #{lastSigningTimeEnd}
    </if>
    <if test="signNumber != null">
      and b.sign_number = #{signNumber}
    </if>
    <if test="lastSalesType != null">
      and b.last_sales_type = #{lastSalesType}
    </if>
    <if test="page_sql!=null">
      ${page_sql}
    </if>
  </select>
  <select id="selectSignSummaryCount" resultType="integer">
    select count(*)
    from user a left join user_mid b on a.id=b.uid  left join admin c on a.aid=c.id
    where a.share_type = 2
    <if test="userName != null">
      and a.nickname like concat('%',#{userName},'%')
    </if>
    <if test="aid != null">
      and c.id =#{aid}
    </if>
    <if test="followAid != null">
      and b.follow_aid =#{followAid}
    </if>
    <if test="member != null">
      and b.`member` = #{member}
    </if>
    <if test="chargeback != null">
      and b.chargeback = #{chargeback}
    </if>
    <if test="bigCustomer != null">
      and b.big_customer = #{bigCustomer}
    </if>
    <if test="lastFollowType != null">
      and b.last_follow_type = #{lastFollowType}
    </if>
    <if test="depId != null">
      and c.department_id  = #{depId}
    </if>
    <if test="lastFollowTimeStart != null and lastFollowTimeEnd !=null">
      and b.last_follow_time BETWEEN #{lastFollowTimeStart} and #{lastFollowTimeEnd}
    </if>
    <if test="firstSigningTimeStart != null and firstSigningTimeEnd !=null">
      and b.first_signing_time BETWEEN #{firstSigningTimeStart} and #{firstSigningTimeEnd}
    </if>
    <if test="lastSigningTimeStart != null and lastSigningTimeStart !=null">
      and b.last_signing_time BETWEEN #{lastSigningTimeStart} and #{lastSigningTimeEnd}
    </if>
    <if test="signNumber != null">
      and b.sign_number = #{signNumber}
    </if>
    <if test="lastSalesType != null">
      and b.last_sales_type = #{lastSalesType}
    </if>
  </select>

  <select id="selectsignStatisticsList" resultType="com.goafanti.order.bo.OutSignStatistics">
    select a.id, a.name,  userCount, orderCount, totalAmount, newSignNumber, repeatSignNumber, channelSignNumber,
    (newSignNumber/orderCount)newRatio,(repeatSignNumber/orderCount)repeatRatio,(channelSignNumber/orderCount)channelRatio
    from  admin a
    left join user_role ur on ur.uid =a.id left join `role` r on r.id=ur.rid
    left join ( select x.aid,count(id) userCount, sum(x.orderCount)orderCount,sum(x.totalAmount)totalAmount,
    sum(x.newSignNumber)newSignNumber,sum(x.repeatSignNumber)repeatSignNumber,
    sum(x.channelSignNumber)channelSignNumber
    from ( select b.aid,b.id,count(*)orderCount ,sum(a.total_amount) totalAmount ,
    sum(if(a.sales_type &lt; 3 || (a.sales_type &gt; 3 &amp;&amp; a.sales_type &lt; 6),1,0 ))newSignNumber,
    sum(if(a.sales_type=3,1,0 ))channelSignNumber,sum(if(a.sales_type &gt; 5,1,0 ))repeatSignNumber
    from t_order_new a left join user b on b.id=a.buyer_id
    where a.process_status &gt;4 and b.share_type =2 and a.delete_sign in(0,2)
    <if test="signTimeStart != null and signTimeEnd!=null">
      and a.sign_time BETWEEN #{signTimeStart} and #{signTimeEnd}
    </if>
    group by b.aid,b.id)x group by x.aid)y on y.aid=a.id
    where a.status= 0 and r.role_type in (96,996)
    <if test="aid != null">
      and a.id= #{aid}
    </if>
    <if test="deps != null">
      and a.department_id in
      <foreach close=")" collection="deps" item="depId" open="(" separator=",">
        #{depId}
      </foreach>
    </if>
    <if test="amountType != null">
      <if test="amountType == 1">
        and  ( totalAmount &lt; 10 or totalAmount is null)
      </if>
      <if test="amountType == 2">
        and  totalAmount BETWEEN 10 and 20
      </if>
      <if test="amountType == 3">
        and  totalAmount BETWEEN 20 and 30
      </if>
      <if test="amountType == 4">
        and  totalAmount &gt; 30
      </if>
    </if>
    <if test="page_sql!=null">
      ${page_sql}
    </if>
  </select>

  <select id="selectsignStatisticsCount" resultType="integer">
    select count(*)
    from  admin a left join user_role ur on ur.uid =a.id left join `role` r on r.id=ur.rid
    left join (select b.aid,sum(a.total_amount) totalAmount
    from t_order_new a left join user b on b.id=a.buyer_id
    where a.process_status >4 and b.share_type =2 and a.delete_sign in(0,2)
    group by b.aid)x on a.id=x.aid
    where a.status= 0 and r.role_type in (96,996)
    <if test="aid != null">
      and a.id= #{aid}
    </if>
    <if test="deps != null">
      and a.department_id in
      <foreach close=")" collection="deps" item="depId" open="(" separator=",">
        #{depId}
      </foreach>
    </if>
    <if test="amountType != null">
      <if test="amountType == 1">
        and ( totalAmount &lt; 10 or totalAmount is null)
      </if>
      <if test="amountType == 2">
        and  totalAmount BETWEEN 10 and 20
      </if>
      <if test="amountType == 3">
        and  totalAmount BETWEEN 20 and 30
      </if>
      <if test="amountType == 4">
        and  totalAmount &gt; 30
      </if>
    </if>
  </select>

  <select id="selectsignStatisticsOrderList" resultType="com.goafanti.order.bo.TOrderNewBo">
    select a.order_no as orderNo,a.create_time as createTime, date_format(a.sign_time,'%Y-%m-%d' ) as signDate,a.delete_sign deleteSign,
    a.contract_no as contractNo, b.nickname as userName ,a.process_status as processStatus,a.total_amount as totalAmount,
    a.order_status as orderStatus, a.liquidation_status as liquidationStatus,a.approval,c.salesman_name as salesmanName,c.project_type projectType,
    dep.name as depName,c.finance_name as financeName,c.invoice_amount invoiceAmount,a.settlement_amount settlementAmount,
    a.sales_type salesType, a.channel_id channelId ,a.other
    from t_order_new a  left join `user` b on a.buyer_id=b.id left join t_order_mid c on a.order_no=c.order_no
    left join department dep on a.order_dep=dep.id
    where a.process_status &gt;4 and b.share_type =2 and a.delete_sign in(0,2)
    <if test="amountType != null">
      <if test="amountType == 1">
        and  a.total_amount &lt; 10
      </if>
      <if test="amountType == 2">
        and  a.total_amount BETWEEN 10 and 20
      </if>
      <if test="amountType == 3">
        and  a.total_amount BETWEEN 20 and 30
      </if>
      <if test="amountType == 4">
        and  a.total_amount &gt; 30
      </if>
    </if>
    <if test="signTimeStart != null and signTimeEnd!=null">
      and a.sign_time BETWEEN #{signTimeStart} and #{signTimeEnd}
    </if>
    <if test="aid !=null">
      and  b.aid= #{aid}
    </if>

    <if test="uid !=null">
      and  b.id= #{uid}
    </if>
    <if test="orderType !=null">
      <if test="orderType ==1">
        and(a.sales_type &lt; 3 or (a.sales_type &gt; 3 and a.sales_type &lt; 6))
      </if>
      <if test="orderType ==2">
        and a.sales_type &gt; 5
      </if>
      <if test="orderType ==3">
        and a.sales_type=3
      </if>
    </if>
    order by a.create_time desc
    <if test="page_sql!=null">
      ${page_sql}
    </if>
  </select>

  <select id="selectsignStatisticsOrderCount" resultType="integer">
    select count(*)
    from t_order_new a  left join `user` b on a.buyer_id=b.id left join t_order_mid c on a.order_no=c.order_no
    left join department dep on a.order_dep=dep.id
    where a.process_status &gt;4 and b.share_type =2 and a.delete_sign in(0,2)
    <if test="amountType != null">
      <if test="amountType == 1">
        and  a.total_amount &lt; 10
      </if>
      <if test="amountType == 2">
        and  a.total_amount BETWEEN 10 and 20
      </if>
      <if test="amountType == 3">
        and  a.total_amount BETWEEN 20 and 30
      </if>
      <if test="amountType == 4">
        and  a.total_amount &gt; 30
      </if>
    </if>
    <if test="signTimeStart != null and signTimeEnd!=null">
      and a.sign_time BETWEEN #{signTimeStart} and #{signTimeEnd}
    </if>
    <if test="aid !=null">
      and  b.aid= #{aid}
    </if>
    <if test="uid !=null">
      and  b.id= #{uid}
    </if>
    <if test="orderType !=null">
      <if test="orderType ==1">
        and(a.sales_type &lt; 3 or (a.sales_type &gt; 3 and a.sales_type &lt; 6))
      </if>
      <if test="orderType ==2">
        and a.sales_type &gt; 5
      </if>
      <if test="orderType ==3">
        and a.sales_type=3
      </if>
    </if>
  </select>
</mapper>
