Pārlūkot izejas kodu

1.控制台业务数据渠道调整

wuhp 1 gadu atpakaļ
vecāks
revīzija
af67f75b8e

+ 207 - 219
src/main/resources/mapper/modules/admin/TaskStatisticsMapper.xml

@@ -6,169 +6,166 @@
 
     <select id="getBusinessAgentData" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
         select
-        su.id as "userId",
-        su.name as "userName",
-        sd.id as "deptId",
-        su.leader_name as "leaderName",
-        IFNULL(a.sumpremium,0) as "sumpremium",
-        IFNULL(a.jqpremium,0) as "jqpremium",
-        IFNULL(a.sypremium,0) as "sypremium",
-        IFNULL(a.taxamount,0) as "taxamount",
-        IFNULL(a.jypremium,0) as "jypremium",
-        IFNULL(a.riskCodeJs,0) as "riskCodeJs",
-        IFNULL(a.riskCodeDj,0) as "riskCodeDj" ,
-        IFNULL(a.riskCodeJshang,0) as "riskCodeJshang",
-        IFNULL(a.riskCodeDs,0) as "riskCodeDs",
-        IFNULL(a.riskCodeDsan,0) as "riskCodeDsan",
-        sd.management_source as "managementSource",
-        IFNULL(IFNULL(a.entranceAllFee,0) -IFNULL(a.exportAllFee,0),0)  as  "distributionAmount",
-        (IFNULL(IFNULL(a.entranceAllFee,0) -IFNULL(a.exportAllFee,0),0)) / a.sumpremium as "distributionAmountRate"
-        from sys_user su
-        left join sys_dept sd on sd.id =su.dept_id
-        LEFT JOIN sys_user_role sur ON sur.user_id = su.id
-        left join (
+        a.userId as "userId",
+        a.userName as "userName",
+        a.deptId as "deptId",
+        a.leaderName as "leaderName",
+        COALESCE(a.sumpremium, 0) as "sumpremium",
+        COALESCE(a.jqpremium, 0) as "jqpremium",
+        COALESCE(a.sypremium, 0) as "sypremium",
+        COALESCE(a.taxamount, 0) as "taxamount",
+        COALESCE(a.jypremium, 0) as "jypremium",
+        COALESCE(a.riskCodeJs, 0) as "riskCodeJs",
+        COALESCE(a.riskCodeDj, 0) as "riskCodeDj",
+        COALESCE(a.riskCodeJshang, 0) as "riskCodeJshang",
+        COALESCE(a.riskCodeDs, 0) as "riskCodeDs",
+        COALESCE(a.riskCodeDsan, 0) as "riskCodeDsan",
+        a.managementSource as "managementSource",
+        COALESCE(a.entranceAllFee - a.exportAllFee, 0) as "distributionAmount",
+        CASE WHEN a.sumpremium > 0 THEN (COALESCE(a.entranceAllFee - a.exportAllFee, 0) / a.sumpremium) ELSE 0 END as "distributionAmountRate"
+        from (
         select
         io.userid as "userId",
-        sum(IFNULL(jqpremium, 0) + IFNULL(sypremium, 0)+ IFNULL(jypremium, 0)) as "sumpremium",
-        IFNULL(sum(jqpremium),0) as "jqpremium",
-        IFNULL(sum(sypremium),0) as "sypremium",
-        IFNULL(sum(taxamount),0) as "taxamount",
-        IFNULL(sum(jypremium),0) as "jypremium",
-        COUNT( CASE WHEN iac.product = '交三'  THEN 1 END ) AS "riskCodeJs",
-        COUNT( CASE WHEN iac.product = '单交'  THEN 1 END ) AS "riskCodeDj",
-        COUNT( CASE WHEN iac.product = '交商'  THEN 1 END ) AS "riskCodeJshang",
-        COUNT( CASE WHEN iac.product = '单商'  THEN 1 END ) AS "riskCodeDs",
-        COUNT( CASE WHEN iac.product = '单三'  THEN 1 END ) AS "riskCodeDsan",
-        ROUND(sum(IFNULL(ifon.jq_costs_premiums,0) + IFNULL(ifon.sy_costs_premiums,0) + IFNULL
-        (ifon.no_costs_premiums,0)),2) as "entranceAllFee",
-        ROUND(sum(IFNULL(jq_export_other_costs_premiums,0) + IFNULL(jq_export_supervise_costs_premiums,0)
-        +IFNULL(sy_export_other_costs_premiums,0) +IFNULL(sy_export_supervise_costs_premiums,0)
-        +IFNULL(no_export_other_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0) ),2) as "exportAllFee"
-        from ins_area_company iac
-        left join ins_orders io on io.orderno =iac.orderno
-        left join  sys_user  su  on su.id =io.userid
+        io.username as "userName",
+        sd.id as "deptId",
+        sd.management_source as "managementSource",
+        iac.leader_name as "leaderName",
+        sum(COALESCE(jqpremium, 0) + COALESCE(sypremium, 0) + COALESCE(jypremium, 0)) as "sumpremium",
+        sum(COALESCE(jqpremium, 0)) as "jqpremium",
+        sum(COALESCE(sypremium, 0)) as "sypremium",
+        sum(COALESCE(taxamount, 0)) as "taxamount",
+        sum(COALESCE(jypremium, 0)) as "jypremium",
+        COUNT(CASE WHEN iac.product = '交三' THEN 1 END) AS "riskCodeJs",
+        COUNT(CASE WHEN iac.product = '单交' THEN 1 END) AS "riskCodeDj",
+        COUNT(CASE WHEN iac.product = '交商' THEN 1 END) AS "riskCodeJshang",
+        COUNT(CASE WHEN iac.product = '单商' THEN 1 END) AS "riskCodeDs",
+        COUNT(CASE WHEN iac.product = '单三' THEN 1 END) AS "riskCodeDsan",
+        ROUND(sum(COALESCE(ifon.jq_costs_premiums, 0) + COALESCE(ifon.sy_costs_premiums, 0) + COALESCE(ifon.no_costs_premiums, 0)), 2) as "entranceAllFee",
+        ROUND(sum(COALESCE(jq_export_other_costs_premiums, 0) + COALESCE(jq_export_supervise_costs_premiums, 0)
+        + COALESCE(sy_export_other_costs_premiums, 0) + COALESCE(sy_export_supervise_costs_premiums, 0)
+        + COALESCE(no_export_other_costs_premiums, 0) + COALESCE(no_export_supervise_costs_premiums, 0)), 2) as "exportAllFee"
+        from (
+        select *
+        from ins_area_company
+        where orderstatus = '3'
+        and (del_flag = '1')
+        <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
+            AND DATE_FORMAT(signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
+        </if>
+        <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
+            AND DATE_FORMAT(createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
+        </if>
+        <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
+            and leader_id in
+            <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="vo.leaderName !=null  and vo.leaderName!=''">
+            and leader_name=#{vo.leaderName}
+        </if>
+        ) iac
+        left join ins_orders io on io.orderno = iac.orderno
         LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
+        left join sys_dept sd on sd.id = io.deptid
+        LEFT JOIN sys_user_role sur ON sur.user_id = io.userid
         <where>
-            iac.orderstatus = '3'
-            and  (iac.del_flag = '1' or io.del_flag IS NULL or io.del_flag = 1)
-            <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
-                AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
-            </if>
-            <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
-                AND DATE_FORMAT(iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
-            </if>
-
-            <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
-                and su.leader_id in
-                <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </if>
-
-        </where>
-        group by io.userid
-        ) a  on  a.userId  =su.id
-        <where>
-            1=1
             <if test="vo.userId !=null  and vo.userId!=''">
-                and su.id=#{vo.userId}
+                and io.userid=#{vo.userId}
             </if>
-
             <if test="vo.userName !=null  and vo.userName!=''">
-                and su.name=#{vo.userName}
+                and io.username=#{vo.userName}
             </if>
-
             <if test="vo.managementSource !=null  and vo.managementSource!=''">
                 and sd.management_source=#{vo.managementSource}
             </if>
-
-            <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
-                and su.leader_id in
-                <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </if>
-
-
-            <if test="vo.leaderName !=null  and vo.leaderName!=''">
-                and su.leader_name=#{vo.leaderName}
-            </if>
-
             <choose>
-                <when  test='vo.managementSource == "2"'>
-                    and (sur.role_id = 20  or  sur.role_id = 21)
+                <when test='vo.managementSource == "2"'>
+                    and (sur.role_id = 20 or sur.role_id = 21)
                 </when>
-                <when  test='vo.managementSource == "1"'>
-                    and (sur.role_id = 19  or  sur.role_id = 21)
+                <when test='vo.managementSource == "1"'>
+                    and (sur.role_id = 19 or sur.role_id = 21)
                 </when>
                 <otherwise>
                 </otherwise>
             </choose>
-
             <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
                 AND sd.id in
                 <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
                     #{item}
                 </foreach>
             </if>
-
             <if test="vo.deptId !=null  and vo.deptId!=''">
-                and sd.id like concat('%',#{vo.deptId},'%')
+                and sd.id like concat('%', #{vo.deptId}, '%')
             </if>
         </where>
-        order by  a.sumpremium  desc ,su.id
+        group by io.userid, io.username, io.deptid, iac.leader_name, sd.management_source
+        ) a
+        order by a.sumpremium desc, a.userId
     </select>
 
     <select id="getBusinessAgentDataTotal" resultType="java.lang.Long">
-        select
+        SELECT
         COUNT(0)
-        from sys_user su
-        left join sys_dept sd on sd.id =su.dept_id
-        LEFT JOIN sys_user_role sur ON sur.user_id = su.id
-        <where>
-            1=1
-            <if test="vo.userId !=null  and vo.userId!=''">
-                and su.id=#{vo.userId}
-            </if>
-            <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
-                and su.leader_id in
-                <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </if>
-            <if test="vo.userName !=null  and vo.userName!=''">
-                and su.name=#{vo.userName}
-            </if>
-
-            <if test="vo.managementSource !=null  and vo.managementSource!=''">
-                and sd.management_source=#{vo.managementSource}
-            </if>
-
-            <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
-                AND sd.id in
-                <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </if>
-
-            <if test="vo.leaderName !=null  and vo.leaderName!=''">
-                and su.leader_name=#{vo.leaderName}
-            </if>
+        FROM (
+        SELECT
+        io.userid AS "userId"
 
-            <if test="vo.deptId !=null  and vo.deptId!=''">
-                and sd.id like concat('%',#{vo.deptId},'%')
-            </if>
-            <choose>
-                <when  test='vo.managementSource == "2"'>
-                    and (sur.role_id = 20  or  sur.role_id = 21)
-                </when>
-                <when  test='vo.managementSource == "1"'>
-                    and (sur.role_id = 19  or  sur.role_id = 21)
-                </when>
-                <otherwise>
-                </otherwise>
-            </choose>
-        </where>
+        FROM
+        ins_area_company iac
+        LEFT JOIN ins_orders io ON io.orderno = iac.orderno
+        LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
+        LEFT JOIN sys_dept sd ON sd.id = io.deptid
+        LEFT JOIN sys_user_role sur ON sur.user_id = io.userid
+        WHERE
+        iac.orderstatus = '3'
+        AND iac.del_flag = '1'
+        <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
+            AND iac.signing_time BETWEEN #{vo.signingTimeStart} AND #{vo.signingTimeEnd}
+        </if>
+        <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
+            AND iac.createtime BETWEEN #{vo.enterTimeStart} AND #{vo.enterTimeEnd}
+        </if>
+        <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
+            AND iac.leader_id IN
+            <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="vo.leaderName !=null  and vo.leaderName!=''">
+            AND iac.leader_name = #{vo.leaderName}
+        </if>
+        <if test="vo.userId !=null  and vo.userId!=''">
+            AND io.userid = #{vo.userId}
+        </if>
+        <if test="vo.userName !=null  and vo.userName!=''">
+            AND io.username = #{vo.userName}
+        </if>
+        <if test="vo.managementSource !=null  and vo.managementSource!=''">
+            AND sd.management_source = #{vo.managementSource}
+        </if>
+        <choose>
+            <when test='vo.managementSource == "2"'>
+                AND (sur.role_id = 20 OR sur.role_id = 21)
+            </when>
+            <when test='vo.managementSource == "1"'>
+                AND (sur.role_id = 19 OR sur.role_id = 21)
+            </when>
+            <otherwise>
+            </otherwise>
+        </choose>
+        <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
+            AND sd.id IN
+            <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="vo.deptId !=null  and vo.deptId!=''">
+            AND sd.id LIKE CONCAT('%', #{vo.deptId}, '%')
+        </if>
+        GROUP BY
+        io.userid
+        ) a;
     </select>
 
     <select id="getBusinessAgentDataTotalAdd" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
@@ -185,12 +182,11 @@
             +IFNULL(no_export_other_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0) ),2) as "exportAllFee"
         from ins_area_company iac
                  left join ins_orders io on io.orderno =iac.orderno
-                 left join sys_user su on io.userid =su.id
-                 left join sys_dept sd on sd.id =su.dept_id
+                 left join sys_dept sd on sd.id =io.deptid
                  LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
         <where>
         iac.orderstatus = '3'
-            and  (iac.del_flag = '1' or io.del_flag IS NULL or io.del_flag = 1)
+            and  (iac.del_flag = '1' )
             <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
                 AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
             </if>
@@ -203,15 +199,16 @@
             </if>
 
             <if test="vo.userName !=null  and vo.userName!=''">
-                and su.name=#{vo.userName}
+                and io.userName=#{vo.userName}
             </if>
 
-            <if test="vo.userId !=null  and vo.userId!=''">
-                and su.id=#{vo.userId}
+            <if test="vo.userId !=null  and vo.
+            !=''">
+                and io.userid=#{vo.userId}
             </if>
 
             <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
-                and su.leader_id in
+                and iac.leader_id in
                 <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
                     #{item}
                 </foreach>
@@ -231,7 +228,7 @@
                 </foreach>
             </if>
             <if test="vo.leaderName !=null  and vo.leaderName!=''">
-                and su.leader_name=#{vo.leaderName}
+                and iac.leader_name=#{vo.leaderName}
             </if>
         </where>
     </select>
@@ -530,111 +527,102 @@
 
     <select id="getBusinessAgentDataExcel"  resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
         select
-        su.id as "userId",
-        su.name as "userName",
-        sd.id as "deptId",
-        su.leader_name as "leaderName",
-        IFNULL(a.sumpremium,0) as "sumpremium",
-        IFNULL(a.jqpremium,0) as "jqpremium",
-        IFNULL(a.sypremium,0) as "sypremium",
-        IFNULL(a.taxamount,0) as "taxamount",
-        IFNULL(a.jypremium,0) as "jypremium",
-        IFNULL(a.riskCodeJs,0) as "riskCodeJs",
-        IFNULL(a.riskCodeDj,0) as "riskCodeDj" ,
-        IFNULL(a.riskCodeJshang,0) as "riskCodeJshang",
-        IFNULL(a.riskCodeDs,0) as "riskCodeDs",
-        IFNULL(a.riskCodeDsan,0) as "riskCodeDsan",
-        sd.management_source as "managementSource",
-        IFNULL(IFNULL(a.entranceAllFee,0) -IFNULL(a.exportAllFee,0),0)  as  "distributionAmount",
-        (IFNULL(IFNULL(a.entranceAllFee,0) -IFNULL(a.exportAllFee,0),0)) / a.sumpremium as "distributionAmountRate"
-        from sys_user su
-        left join sys_dept sd on sd.id =su.dept_id
-        LEFT JOIN sys_user_role sur ON sur.user_id = su.id
-        left join (
+        a.userId as "userId",
+        a.userName as "userName",
+        a.deptId as "deptId",
+        a.leaderName as "leaderName",
+        COALESCE(a.sumpremium, 0) as "sumpremium",
+        COALESCE(a.jqpremium, 0) as "jqpremium",
+        COALESCE(a.sypremium, 0) as "sypremium",
+        COALESCE(a.taxamount, 0) as "taxamount",
+        COALESCE(a.jypremium, 0) as "jypremium",
+        COALESCE(a.riskCodeJs, 0) as "riskCodeJs",
+        COALESCE(a.riskCodeDj, 0) as "riskCodeDj",
+        COALESCE(a.riskCodeJshang, 0) as "riskCodeJshang",
+        COALESCE(a.riskCodeDs, 0) as "riskCodeDs",
+        COALESCE(a.riskCodeDsan, 0) as "riskCodeDsan",
+        a.managementSource as "managementSource",
+        COALESCE(a.entranceAllFee - a.exportAllFee, 0) as "distributionAmount",
+        CASE WHEN a.sumpremium > 0 THEN (COALESCE(a.entranceAllFee - a.exportAllFee, 0) / a.sumpremium) ELSE 0 END as "distributionAmountRate"
+        from (
         select
         io.userid as "userId",
-        sum(IFNULL(jqpremium, 0) + IFNULL(sypremium, 0)+ IFNULL(jypremium, 0)) as "sumpremium",
-        IFNULL(sum(jqpremium),0) as "jqpremium",
-        IFNULL(sum(sypremium),0) as "sypremium",
-        IFNULL(sum(taxamount),0) as "taxamount",
-        IFNULL(sum(jypremium),0) as "jypremium",
-        COUNT( CASE WHEN iac.product = '交三'  THEN 1 END ) AS "riskCodeJs",
-        COUNT( CASE WHEN iac.product = '单交'  THEN 1 END ) AS "riskCodeDj",
-        COUNT( CASE WHEN iac.product = '交商'  THEN 1 END ) AS "riskCodeJshang",
-        COUNT( CASE WHEN iac.product = '单商'  THEN 1 END ) AS "riskCodeDs",
-        COUNT( CASE WHEN iac.product = '单三'  THEN 1 END ) AS "riskCodeDsan",
-        ROUND(sum(IFNULL(ifon.jq_costs_premiums,0) + IFNULL(ifon.sy_costs_premiums,0) + IFNULL
-        (ifon.no_costs_premiums,0)),2) as "entranceAllFee",
-        ROUND(sum(IFNULL(jq_export_other_costs_premiums,0) + IFNULL(jq_export_supervise_costs_premiums,0)
-        +IFNULL(sy_export_other_costs_premiums,0) +IFNULL(sy_export_supervise_costs_premiums,0)
-        +IFNULL(no_export_other_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0) ),2) as "exportAllFee"
-        from ins_area_company iac
-        left join ins_orders io on io.orderno =iac.orderno
-        left join  sys_user  su  on su.id =io.userid
+        io.username as "userName",
+        sd.id as "deptId",
+        sd.management_source as "managementSource",
+        iac.leader_name as "leaderName",
+        sum(COALESCE(jqpremium, 0) + COALESCE(sypremium, 0) + COALESCE(jypremium, 0)) as "sumpremium",
+        sum(COALESCE(jqpremium, 0)) as "jqpremium",
+        sum(COALESCE(sypremium, 0)) as "sypremium",
+        sum(COALESCE(taxamount, 0)) as "taxamount",
+        sum(COALESCE(jypremium, 0)) as "jypremium",
+        COUNT(CASE WHEN iac.product = '交三' THEN 1 END) AS "riskCodeJs",
+        COUNT(CASE WHEN iac.product = '单交' THEN 1 END) AS "riskCodeDj",
+        COUNT(CASE WHEN iac.product = '交商' THEN 1 END) AS "riskCodeJshang",
+        COUNT(CASE WHEN iac.product = '单商' THEN 1 END) AS "riskCodeDs",
+        COUNT(CASE WHEN iac.product = '单三' THEN 1 END) AS "riskCodeDsan",
+        ROUND(sum(COALESCE(ifon.jq_costs_premiums, 0) + COALESCE(ifon.sy_costs_premiums, 0) + COALESCE(ifon.no_costs_premiums, 0)), 2) as "entranceAllFee",
+        ROUND(sum(COALESCE(jq_export_other_costs_premiums, 0) + COALESCE(jq_export_supervise_costs_premiums, 0)
+        + COALESCE(sy_export_other_costs_premiums, 0) + COALESCE(sy_export_supervise_costs_premiums, 0)
+        + COALESCE(no_export_other_costs_premiums, 0) + COALESCE(no_export_supervise_costs_premiums, 0)), 2) as "exportAllFee"
+        from (
+        select *
+        from ins_area_company
+        where orderstatus = '3'
+        and (del_flag = '1')
+        <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
+            AND DATE_FORMAT(signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
+        </if>
+        <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
+            AND DATE_FORMAT(createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
+        </if>
+        <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
+            and leader_id in
+            <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="vo.leaderName !=null  and vo.leaderName!=''">
+            and leader_name=#{vo.leaderName}
+        </if>
+        ) iac
+        left join ins_orders io on io.orderno = iac.orderno
         LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
+        left join sys_dept sd on sd.id = io.deptid
+        LEFT JOIN sys_user_role sur ON sur.user_id = io.userid
         <where>
-            iac.orderstatus = '3'
-            <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
-                AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
-            </if>
-            <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
-                AND DATE_FORMAT(iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
-            </if>
-
-            <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
-                and su.leader_id in
-                <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </if>
-
-        </where>
-        group by io.userid
-        ) a  on  a.userId  =su.id
-        <where>
-            1=1
             <if test="vo.userId !=null  and vo.userId!=''">
-                and su.id=#{vo.userId}
+                and io.userid=#{vo.userId}
             </if>
-
             <if test="vo.userName !=null  and vo.userName!=''">
-                and su.name=#{vo.userName}
+                and io.username=#{vo.userName}
             </if>
-
             <if test="vo.managementSource !=null  and vo.managementSource!=''">
                 and sd.management_source=#{vo.managementSource}
             </if>
-
-            <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
-                and su.leader_id in
-                <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </if>
-
             <choose>
-                <when  test='vo.managementSource == "2"'>
-                    and (sur.role_id = 20  or  sur.role_id = 21)
+                <when test='vo.managementSource == "2"'>
+                    and (sur.role_id = 20 or sur.role_id = 21)
                 </when>
-                <when  test='vo.managementSource == "1"'>
-                    and (sur.role_id = 19  or  sur.role_id = 21)
+                <when test='vo.managementSource == "1"'>
+                    and (sur.role_id = 19 or sur.role_id = 21)
                 </when>
                 <otherwise>
                 </otherwise>
             </choose>
-
             <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
                 AND sd.id in
                 <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
                     #{item}
                 </foreach>
             </if>
-
             <if test="vo.deptId !=null  and vo.deptId!=''">
-                and sd.id like concat('%',#{vo.deptId},'%')
+                and sd.id like concat('%', #{vo.deptId}, '%')
             </if>
         </where>
-        order by  a.sumpremium  desc ,su.id
+        group by io.userid, io.username, io.deptid, iac.leader_name, sd.management_source
+        ) a
+        order by a.sumpremium desc, a.userId
     </select>
 
     <select id="ordersDetailsExcel" resultType="com.ydtech.modules.admin.model.dto.OrdersDetailsExcel">