|
|
@@ -0,0 +1,162 @@
|
|
|
+<?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.jzg.console.mapper.ReportMeetDataMapper">
|
|
|
+
|
|
|
+ <!-- 应付统计结果映射 -->
|
|
|
+ <resultMap id="PayableStatisticsResultMap" type="com.jzg.commons.entity.report.dto.ReportMeetDataDto">
|
|
|
+ <result column="year_and_month_time" property="yearAndMonthTime"/>
|
|
|
+ <result column="sum_premium" property="sumPremium"/>
|
|
|
+ <result column="payable_commission_money" property="payableCommissionMoney"/>
|
|
|
+ <result column="unwithdrawn_money" property="unwithdrawnMoney"/>
|
|
|
+ <result column="withdrawing_money" property="withdrawingMoney"/>
|
|
|
+ <result column="paid_money" property="paidMoney"/>
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <!-- 应付统计明细结果映射 -->
|
|
|
+ <resultMap id="PayableStatisticsDetailResultMap" type="com.jzg.commons.entity.report.dto.ReportMeetDataDetailDto">
|
|
|
+ <result column="salesman_name" property="salesmanName"/>
|
|
|
+ <result column="salesman_phone" property="salesmanPhone"/>
|
|
|
+ <result column="bank_card_number" property="bankCardNumber"/>
|
|
|
+ <result column="bank_name" property="bankName"/>
|
|
|
+ <result column="status_name" property="statusName"/>
|
|
|
+ <result column="withdrawal_money" property="withdrawalMoney"/>
|
|
|
+ <result column="paid_person_name" property="paidPersonName"/>
|
|
|
+ <result column="pay_account_name" property="payAccountName"/>
|
|
|
+ <result column="paid_time" property="paidTime"/>
|
|
|
+ <result column="reject_person" property="rejectPerson"/>
|
|
|
+ <result column="reject_time" property="rejectTime"/>
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <!--
|
|
|
+ 按月份汇总应付统计数据
|
|
|
+ 说明:
|
|
|
+ 1. 保费:ins_fee_orders.total_premium 按签单时间(signing_time)月份汇总(含补录订单)
|
|
|
+ 2. 应付佣金/未提现/已付款:sys_user_account_change_log 按创建时间(create_time)月份汇总
|
|
|
+ - amount 字段带符号,正数=新增(应付佣金),负数=提现(已付款)
|
|
|
+ - amount 等价于 amount_after - amount_before,且更可靠(amount_after 可能因并发不准)
|
|
|
+ - 应付佣金 = 所有新增(正数)求和
|
|
|
+ - 未提现 = 新增 - 提现 = 所有 amount 求和
|
|
|
+ - 已付款 = 所有提现(负数)取绝对值求和
|
|
|
+ 3. 提现中:sys_amount_auditing 中 auditing_status=0(待付款)的提现金额按创建时间月份汇总
|
|
|
+ 4. sys_amount_auditing 与 sys_user_account_change_log 可通过
|
|
|
+ sys_amount_auditing.id = sys_user_account_change_log.related_amount_auditing_id 关联
|
|
|
+ -->
|
|
|
+ <select id="getPayableStatisticsByMonth" resultMap="PayableStatisticsResultMap">
|
|
|
+ SELECT
|
|
|
+ m.year_and_month_time,
|
|
|
+ COALESCE(p.sum_premium, 0) AS sum_premium,
|
|
|
+ COALESCE(c.payable_commission, 0) AS payable_commission_money,
|
|
|
+ COALESCE(c.unwithdrawn, 0) AS unwithdrawn_money,
|
|
|
+ COALESCE(w.withdrawing, 0) AS withdrawing_money,
|
|
|
+ COALESCE(c.paid, 0) AS paid_money
|
|
|
+ FROM (
|
|
|
+ <!-- 汇总所有涉及到的年月集合:保费按签单时间,佣金/提现按创建时间 -->
|
|
|
+ SELECT CONCAT(YEAR(ifo.signing_time), '-', LPAD(MONTH(ifo.signing_time), 2, '0')) AS year_and_month_time
|
|
|
+ FROM ins_fee_orders ifo
|
|
|
+ WHERE ifo.is_delete = 0
|
|
|
+ AND ifo.system_code = #{systemCode}
|
|
|
+ AND YEAR(ifo.signing_time) IN
|
|
|
+ <foreach collection="param.year" item="y" open="(" separator="," close=")">#{y}</foreach>
|
|
|
+ GROUP BY CONCAT(YEAR(ifo.signing_time), '-', LPAD(MONTH(ifo.signing_time), 2, '0'))
|
|
|
+ UNION
|
|
|
+ SELECT CONCAT(YEAR(suacl.create_time), '-', LPAD(MONTH(suacl.create_time), 2, '0')) AS year_and_month_time
|
|
|
+ FROM sys_user_account_change_log suacl
|
|
|
+ WHERE suacl.is_delete = 0
|
|
|
+ AND suacl.status = 10
|
|
|
+ AND suacl.system_code = #{systemCode}
|
|
|
+ AND YEAR(suacl.create_time) IN
|
|
|
+ <foreach collection="param.year" item="y" open="(" separator="," close=")">#{y}</foreach>
|
|
|
+ GROUP BY CONCAT(YEAR(suacl.create_time), '-', LPAD(MONTH(suacl.create_time), 2, '0'))
|
|
|
+ UNION
|
|
|
+ SELECT CONCAT(YEAR(saa.create_time), '-', LPAD(MONTH(saa.create_time), 2, '0')) AS year_and_month_time
|
|
|
+ FROM sys_amount_auditing saa
|
|
|
+ WHERE saa.is_delete = 0
|
|
|
+ AND saa.system_code = #{systemCode}
|
|
|
+ AND saa.auditing_status = 0
|
|
|
+ AND YEAR(saa.create_time) IN
|
|
|
+ <foreach collection="param.year" item="y" open="(" separator="," close=")">#{y}</foreach>
|
|
|
+ GROUP BY CONCAT(YEAR(saa.create_time), '-', LPAD(MONTH(saa.create_time), 2, '0'))
|
|
|
+ ) m
|
|
|
+ LEFT JOIN (
|
|
|
+ <!-- 保费:按签单时间月份汇总订单总保费(含补录订单) -->
|
|
|
+ SELECT
|
|
|
+ CONCAT(YEAR(ifo.signing_time), '-', LPAD(MONTH(ifo.signing_time), 2, '0')) AS year_and_month_time,
|
|
|
+ SUM(COALESCE(ifo.total_premium, 0)) AS sum_premium
|
|
|
+ FROM ins_fee_orders ifo
|
|
|
+ WHERE ifo.is_delete = 0
|
|
|
+ AND ifo.system_code = #{systemCode}
|
|
|
+ AND YEAR(ifo.signing_time) IN
|
|
|
+ <foreach collection="param.year" item="y" open="(" separator="," close=")">#{y}</foreach>
|
|
|
+ GROUP BY CONCAT(YEAR(ifo.signing_time), '-', LPAD(MONTH(ifo.signing_time), 2, '0'))
|
|
|
+ ) p ON m.year_and_month_time = p.year_and_month_time
|
|
|
+ LEFT JOIN (
|
|
|
+ <!-- 应付佣金/未提现/已付款:按账户变更记录创建时间月份汇总 -->
|
|
|
+ SELECT
|
|
|
+ CONCAT(YEAR(suacl.create_time), '-', LPAD(MONTH(suacl.create_time), 2, '0')) AS year_and_month_time,
|
|
|
+ SUM(CASE WHEN suacl.amount > 0 THEN suacl.amount ELSE 0 END) AS payable_commission,
|
|
|
+ SUM(suacl.amount) AS unwithdrawn,
|
|
|
+ SUM(CASE WHEN suacl.amount < 0 THEN ABS(suacl.amount) ELSE 0 END) AS paid
|
|
|
+ FROM sys_user_account_change_log suacl
|
|
|
+ WHERE suacl.is_delete = 0
|
|
|
+ AND suacl.status = 10
|
|
|
+ AND suacl.system_code = #{systemCode}
|
|
|
+ AND YEAR(suacl.create_time) IN
|
|
|
+ <foreach collection="param.year" item="y" open="(" separator="," close=")">#{y}</foreach>
|
|
|
+ GROUP BY CONCAT(YEAR(suacl.create_time), '-', LPAD(MONTH(suacl.create_time), 2, '0'))
|
|
|
+ ) c ON m.year_and_month_time = c.year_and_month_time
|
|
|
+ LEFT JOIN (
|
|
|
+ <!-- 提现中:按提现申请创建时间月份汇总未付款(auditing_status=0)的提现金额 -->
|
|
|
+ SELECT
|
|
|
+ CONCAT(YEAR(saa.create_time), '-', LPAD(MONTH(saa.create_time), 2, '0')) AS year_and_month_time,
|
|
|
+ SUM(COALESCE(saa.amount, 0)) AS withdrawing
|
|
|
+ FROM sys_amount_auditing saa
|
|
|
+ WHERE saa.is_delete = 0
|
|
|
+ AND saa.system_code = #{systemCode}
|
|
|
+ AND saa.auditing_status = 0
|
|
|
+ AND YEAR(saa.create_time) IN
|
|
|
+ <foreach collection="param.year" item="y" open="(" separator="," close=")">#{y}</foreach>
|
|
|
+ GROUP BY CONCAT(YEAR(saa.create_time), '-', LPAD(MONTH(saa.create_time), 2, '0'))
|
|
|
+ ) w ON m.year_and_month_time = w.year_and_month_time
|
|
|
+ ORDER BY m.year_and_month_time ASC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!--
|
|
|
+ 查询指定年月的应付统计明细
|
|
|
+ 说明:
|
|
|
+ 1. 以 sys_amount_auditing.create_time 作为年月筛选条件
|
|
|
+ 2. 业务员名称/手机号:通过 user_id 关联 sys_user_jzg_info 获取 name,关联 sys_user 获取 mobile
|
|
|
+ 3. 状态:auditing_status 转换为中文(0-待付款、1-已付款、2-拒绝付款)
|
|
|
+ 4. 付款账户:关联 inv_account_card 根据 account_id 获取 card_name
|
|
|
+ -->
|
|
|
+ <select id="getPayableStatisticsDetail" resultMap="PayableStatisticsDetailResultMap">
|
|
|
+ SELECT
|
|
|
+ suji.name AS salesman_name,
|
|
|
+ su.mobile AS salesman_phone,
|
|
|
+ saa.bank_card_num AS bank_card_number,
|
|
|
+ saa.bank_name,
|
|
|
+ CASE saa.auditing_status
|
|
|
+ WHEN 0 THEN '待付款'
|
|
|
+ WHEN 1 THEN '已付款'
|
|
|
+ WHEN 2 THEN '拒绝付款'
|
|
|
+ ELSE CAST(saa.auditing_status AS CHAR)
|
|
|
+ END AS status_name,
|
|
|
+ saa.amount AS withdrawal_money,
|
|
|
+ saa.receive_user AS paid_person_name,
|
|
|
+ iac.card_name AS pay_account_name,
|
|
|
+ saa.payment_time AS paid_time,
|
|
|
+ saa.reject_person,
|
|
|
+ saa.reject_time
|
|
|
+ FROM sys_amount_auditing saa
|
|
|
+ LEFT JOIN sys_user_jzg_info suji ON suji.user_id = saa.user_id AND suji.is_delete = 0
|
|
|
+ LEFT JOIN sys_user su ON su.id = saa.user_id AND su.is_delete = 0
|
|
|
+ LEFT JOIN inv_account_card iac ON iac.id = saa.account_id AND iac.is_delete = 0
|
|
|
+ <where>
|
|
|
+ saa.is_delete = 0
|
|
|
+ AND saa.system_code = #{systemCode}
|
|
|
+ <if test="param.yearAndMonthTime != null and param.yearAndMonthTime != ''">
|
|
|
+ AND DATE_FORMAT(saa.create_time, '%Y-%m') = #{param.yearAndMonthTime}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ ORDER BY saa.create_time DESC
|
|
|
+ </select>
|
|
|
+</mapper>
|