Преглед изворни кода

1.控制台渠道 导出与列表不一致

wuhp пре 1 година
родитељ
комит
db3ef31426
1 измењених фајлова са 81 додато и 81 уклоњено
  1. 81 81
      src/main/resources/mapper/modules/admin/TaskStatisticsMapper.xml

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

@@ -531,103 +531,103 @@
     </select>
 
     <select id="getBusinessAgentDataExcel"  resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
-        select
+        SELECT
         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",
-        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",
+        su.name AS "userName",
+        sd.id AS "deptId",
+        su.leader_name AS "leaderName",
+        a.sumpremium,
+        a.jqpremium,
+        a.sypremium,
+        a.taxamount,
+        a.jypremium,
+        a.riskCodeJs,
+        a.riskCodeDj,
+        a.riskCodeJshang,
+        a.riskCodeDs,
+        a.riskCodeDsan,
+        sd.management_source AS "managementSource",
+        a.distributionAmount,
+        CASE WHEN a.sumpremium = 0 THEN 0  ELSE a.distributionAmount / a.sumpremium  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(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')
+        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",
+        IFNULL(IFNULL(SUM(IFNULL(ifon.jq_costs_premiums, 0) + IFNULL(ifon.sy_costs_premiums, 0) + IFNULL(ifon.no_costs_premiums, 0)), 0) - IFNULL(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)), 0), 0) AS "distributionAmount"
+        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
+        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)
         <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
-            AND signing_time BETWEEN #{vo.signingTimeStart} 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 createtime BETWEEN #{vo.enterTimeStart} AND #{vo.enterTimeEnd}
+            AND iac.createtime BETWEEN #{vo.enterTimeStart} AND #{vo.enterTimeEnd}
+        </if>
+
+        <if test="vo.leaderName != null and vo.leaderName!='' ">
+            AND iac.leader_name = #{vo.leaderName}
         </if>
         <if test="vo.userIds  !=null  and vo.userIds!=''  and vo.userIds.size()>0">
-            and leader_id in
+            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 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>
-            <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>
-        </where>
-        group by io.userid, io.username, io.deptid, iac.leader_name, sd.management_source
+        GROUP BY
+        io.userid
         ) a
-        order by a.sumpremium desc, a.userId
+        LEFT JOIN sys_user su ON a.userId = su.id
+        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.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>
+        <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>
+        ORDER BY
+        a.sumpremium DESC,
+        a.userId
     </select>
 
     <select id="ordersDetailsExcel" resultType="com.ydtech.modules.admin.model.dto.OrdersDetailsExcel">