✨ 完善毛利分析筛选与导出日志
This commit is contained in:
@@ -4,6 +4,56 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bms.price.mapper.PrcProfitReportMapper">
|
||||
|
||||
<resultMap type="PrcProfitReportExport" id="PrcProfitReportExportResult">
|
||||
<id property="exportId" column="export_id"/>
|
||||
<result property="dimension" column="dimension"/>
|
||||
<result property="fileName" column="file_name"/>
|
||||
<result property="storageKey" column="storage_key"/>
|
||||
<result property="rowCount" column="row_count"/>
|
||||
<result property="exportStatus" column="export_status"/>
|
||||
<result property="exportBy" column="export_by"/>
|
||||
<result property="exportTime" column="export_time"/>
|
||||
<result property="remark" column="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="profitReportExportColumns">
|
||||
select export_id, dimension, file_name, storage_key, row_count,
|
||||
export_status, export_by, export_time, remark
|
||||
from prc_profit_report_export
|
||||
</sql>
|
||||
|
||||
<insert id="insertExport" parameterType="PrcProfitReportExport" useGeneratedKeys="true" keyProperty="exportId">
|
||||
insert into prc_profit_report_export (
|
||||
dimension, file_name, storage_key, row_count, export_status, export_by, export_time, remark
|
||||
) values (
|
||||
#{dimension}, #{fileName}, #{storageKey}, #{rowCount}, #{exportStatus}, #{exportBy}, sysdate(), #{remark}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="markExportSuccess" parameterType="PrcProfitReportExport">
|
||||
update prc_profit_report_export
|
||||
set file_name = #{fileName}, storage_key = #{storageKey}, row_count = #{rowCount},
|
||||
export_status = 'SUCCESS', remark = null
|
||||
where export_id = #{exportId} and export_status = 'PROCESSING'
|
||||
</update>
|
||||
|
||||
<update id="markExportFailed">
|
||||
update prc_profit_report_export
|
||||
set export_status = 'FAILED', remark = #{remark}
|
||||
where export_id = #{exportId} and export_status = 'PROCESSING'
|
||||
</update>
|
||||
|
||||
<select id="selectExportsByUser" resultMap="PrcProfitReportExportResult">
|
||||
<include refid="profitReportExportColumns"/>
|
||||
where export_by = #{exportBy}
|
||||
order by export_time desc, export_id desc
|
||||
</select>
|
||||
|
||||
<select id="selectExportByIdAndUser" resultMap="PrcProfitReportExportResult">
|
||||
<include refid="profitReportExportColumns"/>
|
||||
where export_id = #{exportId} and export_by = #{exportBy}
|
||||
</select>
|
||||
|
||||
<resultMap type="PrcProfitReportOrderRow" id="PrcProfitReportOrderResult">
|
||||
<result property="orderNo" column="order_no"/>
|
||||
<result property="customerCode" column="customer_code"/>
|
||||
@@ -23,8 +73,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="salesAmount" column="sales_amount"/>
|
||||
<result property="salesGrossProfit" column="sales_gross_profit"/>
|
||||
<result property="salesGrossMarginRate" column="sales_gross_margin_rate"/>
|
||||
<!-- 提成结果字段暂停使用。
|
||||
<result property="commissionRate" column="commission_rate"/>
|
||||
<result property="commissionAmount" column="commission_amount"/>
|
||||
-->
|
||||
<result property="arBillStatus" column="ar_bill_status"/>
|
||||
</resultMap>
|
||||
|
||||
@@ -42,8 +94,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="salesAmount" column="sales_amount"/>
|
||||
<result property="salesGrossProfit" column="sales_gross_profit"/>
|
||||
<result property="salesGrossMarginRate" column="sales_gross_margin_rate"/>
|
||||
<!-- 提成结果字段暂停使用。
|
||||
<result property="commissionAmount" column="commission_amount"/>
|
||||
<result property="commissionMissingOrderCount" column="commission_missing_order_count"/>
|
||||
-->
|
||||
<result property="incompleteOrderCount" column="incomplete_order_count"/>
|
||||
</resultMap>
|
||||
|
||||
@@ -58,16 +112,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="salesAmount" column="sales_amount"/>
|
||||
<result property="salesGrossProfit" column="sales_gross_profit"/>
|
||||
<result property="salesGrossMarginRate" column="sales_gross_margin_rate"/>
|
||||
<!-- 提成汇总字段暂停使用。
|
||||
<result property="commissionAmount" column="commission_amount"/>
|
||||
<result property="commissionMissingOrderCount" column="commission_missing_order_count"/>
|
||||
-->
|
||||
</resultMap>
|
||||
|
||||
<sql id="profitReportFromAndWhere">
|
||||
from prc_income_bill i
|
||||
inner join prc_order_bill p on p.bill_id = i.bill_id
|
||||
<!-- 提成表关联暂停使用,毛利报表不再依赖提成配置。
|
||||
left join prc_profit_commission_rate cr
|
||||
on cr.belong_saler_code = i.belong_saler_code and cr.status = '0'
|
||||
-->
|
||||
<where>
|
||||
<!-- 不将未匹配产品、国家或重量段的计费失败订单纳入毛利报表;保留历史空值(按成功处理)。 -->
|
||||
and (p.billing_fail_status is null or p.billing_fail_status not in (1, 2, 3))
|
||||
<if test="beginBizDate != null">
|
||||
and p.biz_date >= #{beginBizDate}
|
||||
</if>
|
||||
@@ -134,9 +194,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</otherwise>
|
||||
</choose>
|
||||
<choose>
|
||||
<!-- 提成未计算订单下钻暂停使用。
|
||||
<when test="detailType == 'COMMISSION_MISSING'">
|
||||
and (cr.commission_rate is null or i.product_amount is null or i.sales_amount is null)
|
||||
</when>
|
||||
-->
|
||||
<when test="detailType == 'INCOMPLETE'">
|
||||
and (i.product_amount is null or i.redline_amount is null or i.sales_amount is null)
|
||||
</when>
|
||||
@@ -161,21 +223,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 红线毛利 = 产品价 - 红线价;红线毛利率 = 红线毛利 / 红线价 * 100%。汇总先逐单计算再求和。 -->
|
||||
<sql id="profitExpressions">
|
||||
i.product_amount as cost_amount,
|
||||
i.redline_amount,
|
||||
case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount - i.product_amount else null end as redline_gross_profit,
|
||||
then i.product_amount - i.redline_amount else null end as redline_gross_profit,
|
||||
case when i.product_amount is not null and i.redline_amount is not null and i.redline_amount != 0
|
||||
then round((i.redline_amount - i.product_amount) * 100 / i.redline_amount, 4) else null end as redline_gross_margin_rate,
|
||||
then round((i.product_amount - i.redline_amount) * 100 / i.redline_amount, 4) else null end as redline_gross_margin_rate,
|
||||
i.sales_amount,
|
||||
case when i.product_amount is not null and i.sales_amount is not null
|
||||
then i.sales_amount - i.product_amount else null end as sales_gross_profit,
|
||||
case when i.product_amount is not null and i.sales_amount is not null and i.sales_amount != 0
|
||||
then round((i.sales_amount - i.product_amount) * 100 / i.sales_amount, 4) else null end as sales_gross_margin_rate,
|
||||
cr.commission_rate,
|
||||
then round((i.sales_amount - i.product_amount) * 100 / i.sales_amount, 4) else null end as sales_gross_margin_rate
|
||||
<!-- 提成比例与金额计算暂停使用;恢复时包含前置逗号。
|
||||
, cr.commission_rate,
|
||||
case when cr.commission_rate is not null and i.product_amount is not null and i.sales_amount is not null
|
||||
then round((i.sales_amount - i.product_amount) * cr.commission_rate / 100, 4) else null end as commission_amount
|
||||
-->
|
||||
</sql>
|
||||
|
||||
<select id="selectOrderRows" resultMap="PrcProfitReportOrderResult">
|
||||
@@ -186,6 +251,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="profitExpressions"/>,
|
||||
p.ar_bill_status
|
||||
<include refid="profitReportFromAndWhere"/>
|
||||
<if test="arBillStatus != null and arBillStatus != '' and productDrilldown != true">
|
||||
and p.ar_bill_status = #{arBillStatus}
|
||||
</if>
|
||||
order by p.biz_date desc, p.bill_id desc
|
||||
</select>
|
||||
|
||||
@@ -195,7 +263,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
sum(i.product_amount) as cost_amount,
|
||||
sum(i.redline_amount) as redline_amount,
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount - i.product_amount else null end) as redline_gross_profit,
|
||||
then i.product_amount - i.redline_amount else null end) as redline_gross_profit,
|
||||
case when sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount else null end) is null
|
||||
or sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
@@ -203,7 +271,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
then null
|
||||
else round(
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount - i.product_amount else null end) * 100 /
|
||||
then i.product_amount - i.redline_amount else null end) * 100 /
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount else null end), 4)
|
||||
end as redline_gross_margin_rate,
|
||||
@@ -221,10 +289,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
sum(case when i.product_amount is not null and i.sales_amount is not null
|
||||
then i.sales_amount else null end), 4)
|
||||
end as sales_gross_margin_rate,
|
||||
<!-- 提成金额与未计算订单数暂停使用。
|
||||
sum(case when cr.commission_rate is not null and i.product_amount is not null and i.sales_amount is not null
|
||||
then (i.sales_amount - i.product_amount) * cr.commission_rate / 100 else null end) as commission_amount,
|
||||
sum(case when cr.commission_rate is null or i.product_amount is null or i.sales_amount is null
|
||||
then 1 else 0 end) as commission_missing_order_count,
|
||||
-->
|
||||
sum(case when i.product_amount is null or i.redline_amount is null or i.sales_amount is null
|
||||
then 1 else 0 end) as incomplete_order_count
|
||||
<include refid="profitReportFromAndWhere"/>
|
||||
@@ -239,7 +309,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
sum(i.product_amount) as cost_amount,
|
||||
sum(i.redline_amount) as redline_amount,
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount - i.product_amount else null end) as redline_gross_profit,
|
||||
then i.product_amount - i.redline_amount else null end) as redline_gross_profit,
|
||||
case when sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount else null end) is null
|
||||
or sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
@@ -247,7 +317,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
then null
|
||||
else round(
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount - i.product_amount else null end) * 100 /
|
||||
then i.product_amount - i.redline_amount else null end) * 100 /
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount else null end), 4)
|
||||
end as redline_gross_margin_rate,
|
||||
@@ -264,12 +334,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
then i.sales_amount - i.product_amount else null end) * 100 /
|
||||
sum(case when i.product_amount is not null and i.sales_amount is not null
|
||||
then i.sales_amount else null end), 4)
|
||||
end as sales_gross_margin_rate,
|
||||
sum(case when cr.commission_rate is not null and i.product_amount is not null and i.sales_amount is not null
|
||||
end as sales_gross_margin_rate
|
||||
<!-- 提成汇总计算暂停使用;恢复时包含前置逗号。
|
||||
, sum(case when cr.commission_rate is not null and i.product_amount is not null and i.sales_amount is not null
|
||||
then (i.sales_amount - i.product_amount) * cr.commission_rate / 100 else null end) as commission_amount,
|
||||
sum(case when cr.commission_rate is null or i.product_amount is null or i.sales_amount is null
|
||||
then 1 else 0 end) as commission_missing_order_count
|
||||
-->
|
||||
<include refid="profitReportFromAndWhere"/>
|
||||
<if test="arBillStatus != null and arBillStatus != ''">
|
||||
and p.ar_bill_status = #{arBillStatus}
|
||||
</if>
|
||||
group by i.currency
|
||||
order by i.currency
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user