✨ 新增毛利分析报表及提成设置

This commit is contained in:
caojia
2026-10-14 16:57:44 +08:00
parent c0c9c798b3
commit 0087aa3712
17 changed files with 1671 additions and 0 deletions
@@ -0,0 +1,44 @@
<?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.bms.price.mapper.PrcProfitCommissionRateMapper">
<resultMap type="PrcProfitCommissionRate" id="PrcProfitCommissionRateResult">
<id property="rateId" column="rate_id"/>
<result property="belongSalerCode" column="belong_saler_code"/>
<result property="belongSaler" column="belong_saler"/>
<result property="commissionRate" column="commission_rate"/>
<result property="status" column="status"/>
<result property="remark" column="remark"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="selectAll" resultMap="PrcProfitCommissionRateResult">
select rate_id, belong_saler_code, belong_saler, commission_rate, status,
remark, create_by, create_time, update_by, update_time
from prc_profit_commission_rate
order by belong_saler_code
</select>
<insert id="upsert" parameterType="PrcProfitCommissionRate">
insert into prc_profit_commission_rate (
belong_saler_code, belong_saler, commission_rate, status, remark, create_by, create_time
) values (
#{belongSalerCode}, #{belongSaler}, #{commissionRate}, #{status}, #{remark}, #{createBy}, sysdate()
)
on duplicate key update
belong_saler = values(belong_saler),
commission_rate = values(commission_rate),
status = values(status),
remark = values(remark),
update_by = values(create_by),
update_time = sysdate()
</insert>
<delete id="deleteById" parameterType="Long">
delete from prc_profit_commission_rate where rate_id = #{rateId}
</delete>
</mapper>
@@ -0,0 +1,276 @@
<?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.bms.price.mapper.PrcProfitReportMapper">
<resultMap type="PrcProfitReportOrderRow" id="PrcProfitReportOrderResult">
<result property="orderNo" column="order_no"/>
<result property="customerCode" column="customer_code"/>
<result property="customerName" column="customer_name"/>
<result property="belongSaler" column="belong_saler"/>
<result property="belongSalerCode" column="belong_saler_code"/>
<result property="productCode" column="product_code"/>
<result property="productName" column="product_name"/>
<result property="countryCode" column="country_code"/>
<result property="countryName" column="country_name"/>
<result property="currency" column="currency"/>
<result property="bizDate" column="biz_date"/>
<result property="costAmount" column="cost_amount"/>
<result property="redlineAmount" column="redline_amount"/>
<result property="redlineGrossProfit" column="redline_gross_profit"/>
<result property="redlineGrossMarginRate" column="redline_gross_margin_rate"/>
<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>
<resultMap type="PrcProfitReportProductRow" id="PrcProfitReportProductResult">
<result property="productCode" column="product_code"/>
<result property="productName" column="product_name"/>
<result property="countryCode" column="country_code"/>
<result property="countryName" column="country_name"/>
<result property="currency" column="currency"/>
<result property="orderCount" column="order_count"/>
<result property="costAmount" column="cost_amount"/>
<result property="redlineAmount" column="redline_amount"/>
<result property="redlineGrossProfit" column="redline_gross_profit"/>
<result property="redlineGrossMarginRate" column="redline_gross_margin_rate"/>
<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>
<resultMap type="PrcProfitReportSummary" id="PrcProfitReportSummaryResult">
<result property="orderCount" column="order_count"/>
<result property="incompleteOrderCount" column="incomplete_order_count"/>
<result property="currency" column="currency"/>
<result property="costAmount" column="cost_amount"/>
<result property="redlineAmount" column="redline_amount"/>
<result property="redlineGrossProfit" column="redline_gross_profit"/>
<result property="redlineGrossMarginRate" column="redline_gross_margin_rate"/>
<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>
<if test="beginBizDate != null">
and p.biz_date &gt;= #{beginBizDate}
</if>
<if test="endBizDate != null">
and p.biz_date &lt;= #{endBizDate}
</if>
<choose>
<when test="orderNos != null and orderNos.size() > 0">
and (
<foreach collection="orderNos" item="orderValue" separator=" or ">
p.order_no like concat('%', #{orderValue}, '%')
</foreach>
)
</when>
<when test="orderNo != null and orderNo != ''">
and p.order_no like concat('%', #{orderNo}, '%')
</when>
</choose>
<choose>
<when test="customerCodes != null and customerCodes.size() > 0">
and p.customer_code in
<foreach collection="customerCodes" item="customerValue" open="(" separator="," close=")">
#{customerValue}
</foreach>
</when>
<when test="customerCode != null and customerCode != ''">
and p.customer_code = #{customerCode}
</when>
</choose>
<choose>
<when test="customerNames != null and customerNames.size() > 0">
and (
<foreach collection="customerNames" item="customerValue" separator=" or ">
p.customer_name like concat('%', #{customerValue}, '%')
</foreach>
)
</when>
<when test="customerName != null and customerName != ''">
and p.customer_name like concat('%', #{customerName}, '%')
</when>
</choose>
<choose>
<when test="productDrilldown != null and productDrilldown">
and p.product_code &lt;=&gt; #{productCode}
and p.country_code &lt;=&gt; #{countryCode}
and i.currency &lt;=&gt; #{currency}
<if test="belongSalerCode != null and belongSalerCode != ''">
and i.belong_saler_code = #{belongSalerCode}
</if>
</when>
<otherwise>
<if test="belongSalerCode != null and belongSalerCode != ''">
and i.belong_saler_code = #{belongSalerCode}
</if>
<if test="productCode != null and productCode != ''">
and p.product_code = #{productCode}
</if>
<if test="countryCode != null and countryCode != ''">
and p.country_code = #{countryCode}
</if>
<if test="currency != null and currency != ''">
and i.currency = #{currency}
</if>
</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>
</choose>
<if test="params != null and params.dataScope != null and params.dataScope != ''">
and exists (
select 1
from sys_user su
where su.del_flag = '0'
and (
(p.belong_saler_code is not null and p.belong_saler_code != ''
and (su.user_name = p.belong_saler_code collate utf8mb4_general_ci
or su.user_id = p.belong_saler_code + 0))
or
(p.settlement_man_code is not null and p.settlement_man_code != ''
and (su.user_name = p.settlement_man_code collate utf8mb4_general_ci
or su.user_id = p.settlement_man_code + 0))
)
${params.dataScope}
)
</if>
</where>
</sql>
<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,
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,
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,
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">
select p.order_no, p.customer_code, p.customer_name,
i.belong_saler, i.belong_saler_code,
p.product_code, p.product_name, p.country_code, p.country_name,
i.currency, p.biz_date,
<include refid="profitExpressions"/>,
p.ar_bill_status
<include refid="profitReportFromAndWhere"/>
order by p.biz_date desc, p.bill_id desc
</select>
<select id="selectProductRows" resultMap="PrcProfitReportProductResult">
select p.product_code, p.product_name, p.country_code, p.country_name,
i.currency, count(*) as order_count,
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,
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
then i.redline_amount else null end) = 0
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 /
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,
sum(i.sales_amount) as sales_amount,
sum(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 sum(case when i.product_amount is not null and i.sales_amount is not null
then i.sales_amount else null end) is null
or sum(case when i.product_amount is not null and i.sales_amount is not null
then i.sales_amount else null end) = 0
then null
else round(
sum(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) * 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
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"/>
group by p.product_code, p.product_name, p.country_code, p.country_name, i.currency
order by p.product_code, p.country_code, i.currency
</select>
<select id="selectSummary" resultMap="PrcProfitReportSummaryResult">
select i.currency, count(*) as 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,
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,
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
then i.redline_amount else null end) = 0
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 /
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,
sum(i.sales_amount) as sales_amount,
sum(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 sum(case when i.product_amount is not null and i.sales_amount is not null
then i.sales_amount else null end) is null
or sum(case when i.product_amount is not null and i.sales_amount is not null
then i.sales_amount else null end) = 0
then null
else round(
sum(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) * 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
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"/>
group by i.currency
order by i.currency
</select>
</mapper>