综合销售情况表 月度分组调整

This commit is contained in:
king
2026-03-20 14:28:48 +08:00
parent a3a49394aa
commit 1b86125114
5 changed files with 46 additions and 42 deletions

View File

@@ -130,8 +130,8 @@ public class NewGrBiSaAggMonthCount implements Serializable
private BigDecimal lastMonthCost;
@TableField(value = "yoy_last_month_cost")
private BigDecimal yoyLastMonthCost;
@TableField(value = "yoy_month_cost")
private BigDecimal yoyMonthCost;
@TableField(value = "this_month_profit_rate")

View File

@@ -38,12 +38,14 @@ public interface NewGrBiSaAggMapper extends BaseMapper<NewGrBiSaAgg>
// void updateThisYearData();
//
void updateLastYearData();
// void updateLastYearData();
void updateLastMonthSamoney();
void updateYoyMonthData();
void updateComplexCalculateMonth1();
void updateComplexCalculateMonth2();
//
// void updateComplexCalculate1();
// void updateComplexCalculate2();
// void updateComplexCalculateYear();
// void updateComplexCalculate3();
// void updateComplexCalculate4();
// void updateComplexCalculate5();

View File

@@ -76,12 +76,14 @@ public class NewGrBiSaAggServiceImpl extends ServiceImpl<NewGrBiSaAggMapper, New
}
//保存数据
removeAndSaveBatch(pastYear, pastMonth, currentYear, currentMonth, grBiSaSetdtlList);
this.baseMapper.updateYoyMonthData();
this.baseMapper.updateLastMonthSamoney();
this.baseMapper.updateComplexCalculateMonth1();
this.baseMapper.updateComplexCalculateMonth2();
// this.baseMapper.updateThisYearData();
// this.baseMapper.updateYoyMonthData();
this.baseMapper.updateLastYearData();
// this.baseMapper.updateLastMonthSamoney();
// this.baseMapper.updateComplexCalculate1();
// this.baseMapper.updateComplexCalculate2();
// this.baseMapper.updateLastYearData();
// this.baseMapper.updateComplexCalculateYear();
// this.baseMapper.updateComplexCalculate3();
// this.baseMapper.updateComplexCalculate4();
// this.baseMapper.updateComplexCalculate5();

View File

@@ -281,7 +281,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- </update>-->
<update id="updateYoyMonthData">
UPDATE new_gr_bi_sa_agg_month_count a
UPDATE new_gr_bi_sa_agg a
LEFT JOIN (
SELECT
use_year,
@@ -325,7 +325,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<update id="updateLastMonthSamoney">
UPDATE new_gr_bi_sa_agg_month_count AS current_month
UPDATE new_gr_bi_sa_agg AS current_month
LEFT JOIN (
SELECT
-- 当前记录的维度和年月
@@ -340,8 +340,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
custom_id,
saler_id,
-- 计算上个月的年月
YEAR(DATE_SUB(CONCAT(use_year, '-', use_month, '-01'), INTERVAL 1 MONTH)) AS LAST_YEAR,
MONTH(DATE_SUB(CONCAT(use_year, '-', use_month, '-01'), INTERVAL 1 MONTH)) AS LAST_MONTH,
use_year AS LAST_YEAR,
use_month AS LAST_MONTH,
SUM(this_month_sa_qty) AS current_month_sa_qty,
-- 当前月的销售金额,将作为上个月的金额赋给别的记录
SUM(this_month_sa_money) AS current_month_sa_money,
@@ -366,13 +366,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND current_month.dosage_id = last_month_data.dosage_id
AND current_month.custom_id = last_month_data.custom_id
AND current_month.saler_id = last_month_data.saler_id
AND current_month.use_year = last_month_data.use_year
AND current_month.use_month = last_month_data.use_month
AND last_month_data.use_year = current_month.use_year - (current_month.use_month = 1)
AND last_month_data.use_month = IF(current_month.use_month = 1, 12, current_month.use_month - 1)
SET
current_month.last_month_sa_qty = last_month_data.current_month_sa_qty, -- 上月销量
current_month.last_month_sa_money = last_month_data.current_month_sa_money, -- 上月销售金额
current_month.last_month_sa_cost = last_month_data.current_month_cost, -- 上月销售成本
current_month.last_month_sa_profit = last_month_data.current_month_profit; -- 上月毛利额
current_month.last_month_cost = last_month_data.current_month_cost, -- 上月销售成本
current_month.last_month_profit = last_month_data.current_month_profit; -- 上月毛利额
</update>
<update id="updateLastYearData">
UPDATE new_gr_bi_sa_agg_year_count a
@@ -416,32 +416,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<update id="updateComplexCalculate0">
<update id="updateComplexCalculateMonth1">
-- 本月毛利率 MONTHPROFITRATE 本月销售毛利/本月销售收入×100%
UPDATE new_gr_bi_sa_agg_month_count
UPDATE new_gr_bi_sa_agg
SET
this_month_profit_rate = CASE WHEN last_month_sa_money = 0 or last_month_sa_money is null THEN
IF(MONTHPROFIT > 0, 100, 0) ELSE MONTHPROFIT/ last_month_sa_money * 100 END;
IF(this_month_profit > 0, 100, 0) ELSE this_month_profit/ last_month_sa_money * 100 END;
</update>
<update id="updateComplexCalculate1">
-- 本年毛利率 THISPROFITRATE 本年销售毛利/本年销售收入×100%
-- 上年毛利率 LASTPROFITRATE 上年销售毛利/上年销售收入×100%
UPDATE new_gr_bi_sa_agg_year_count
SET
this_year_profit_rate = CASE WHEN this_year_sa_money = 0 or this_year_sa_money is null THEN
IF(this_year_profit > 0, 100, 0) ELSE this_year_profit/ this_year_sa_money * 100 END,
last_year_profit_rate =CASE WHEN last_year_sa_money = 0 or last_year_sa_money is null THEN
IF(last_year_profit > 0, 100, 0) ELSE last_year_profit/ last_year_sa_money * 100 END;
</update>
<update id="updateComplexCalculate2">
<update id="updateComplexCalculateMonth2">
-- 本月销售金额占比 MONTHSAMONEYSHARE 当前行本月销售额/本月销售额总和*100%
-- 本月毛利额占比 MONTHPROFITSHARE 当前行本月毛利额/本月毛利额总和*100%
UPDATE new_gr_bi_sa_agg_month_count a
UPDATE new_gr_bi_sa_agg a
LEFT JOIN (
SELECT
use_year,
@@ -458,6 +445,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SET a.this_month_sa_money_share = COALESCE (ROUND( a.this_month_sa_money/b.this_month_sa_money_sum * 100, 2), 0 ),
a.this_month_profit_share = COALESCE (ROUND( a.this_month_profit/b.this_month_profit_sum * 100, 2), 0 );
</update>
<update id="updateComplexCalculateYear">
-- 本年毛利率 THISPROFITRATE 本年销售毛利/本年销售收入×100%
-- 上年毛利率 LASTPROFITRATE 上年销售毛利/上年销售收入×100%
UPDATE new_gr_bi_sa_agg_year_count
SET
this_year_profit_rate = CASE WHEN this_year_sa_money = 0 or this_year_sa_money is null THEN
IF(this_year_profit > 0, 100, 0) ELSE this_year_profit/ this_year_sa_money * 100 END,
last_year_profit_rate =CASE WHEN last_year_sa_money = 0 or last_year_sa_money is null THEN
IF(last_year_profit > 0, 100, 0) ELSE last_year_profit/ last_year_sa_money * 100 END;
</update>
<update id="updateComplexCalculate3">
-- 本年销售金额占比 this_year_sa_money_share当前行本年销售额/本年销售额总和*100%

View File

@@ -33,7 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="yoyMonthProfit" column="yoy_month_profit" />
<result property="thisMonthCost" column="this_month_cost" />
<result property="lastMonthCost" column="last_month_cost" />
<result property="yoyLastMonthCost" column="yoy_last_month_cost" />
<result property="yoyMonthCost" column="yoy_month_cost" />
<result property="thisMonthProfitRate" column="this_month_profit_rate" />
<result property="lastMonthProfitRate" column="last_month_profit_rate" />
<result property="lastMonthProfitShare" column="last_month_profit_share" />
@@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectNewGrBiSaAggMonthCountVo">
select id, use_year, use_month, zone_id, zone_name, sale_type_id, sale_type_name, custom_id, custom_name, dosage_id, dosage_name, goods_id, goods_name, province_id, province_name, saler_id, saler_name, this_month_sa_qty, last_month_sa_qty, yoy_month_sa_qty, this_month_sa_money, last_month_sa_money, yoy_month_sa_money, this_month_profit, last_month_profit, yoy_month_profit, this_month_cost, last_month_cost, yoy_last_month_cost, this_month_profit_rate, last_month_profit_rate, last_month_profit_share, this_month_sa_money_share, this_month_profit_share from new_gr_bi_sa_agg_month_count
select id, use_year, use_month, zone_id, zone_name, sale_type_id, sale_type_name, custom_id, custom_name, dosage_id, dosage_name, goods_id, goods_name, province_id, province_name, saler_id, saler_name, this_month_sa_qty, last_month_sa_qty, yoy_month_sa_qty, this_month_sa_money, last_month_sa_money, yoy_month_sa_money, this_month_profit, last_month_profit, yoy_month_profit, this_month_cost, last_month_cost, yoy_month_cost, this_month_profit_rate, last_month_profit_rate, last_month_profit_share, this_month_sa_money_share, this_month_profit_share from new_gr_bi_sa_agg_month_count
</sql>
<select id="selectNewGrBiSaAggMonthCountList" parameterType="com.lideeyunji.core.framework.entity.NewGrBiSaAggMonthCount" resultMap="NewGrBiSaAggMonthCountResult">
@@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="yoyMonthProfit != null "> and yoy_month_profit = #{yoyMonthProfit}</if>
<if test="thisMonthCost != null "> and this_month_cost = #{thisMonthCost}</if>
<if test="lastMonthCost != null "> and last_month_cost = #{lastMonthCost}</if>
<if test="yoyLastMonthCost != null "> and yoy_last_month_cost = #{yoyLastMonthCost}</if>
<if test="yoyMonthCost != null "> and yoy_month_cost = #{yoyMonthCost}</if>
<if test="thisMonthProfitRate != null "> and this_month_profit_rate = #{thisMonthProfitRate}</if>
<if test="lastMonthProfitRate != null "> and last_month_profit_rate = #{lastMonthProfitRate}</if>
<if test="lastMonthProfitShare != null "> and last_month_profit_share = #{lastMonthProfitShare}</if>
@@ -119,7 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="yoyMonthProfit != null">yoy_month_profit,</if>
<if test="thisMonthCost != null">this_month_cost,</if>
<if test="lastMonthCost != null">last_month_cost,</if>
<if test="yoyLastMonthCost != null">yoy_last_month_cost,</if>
<if test="yoyMonthCost != null">yoy_month_cost,</if>
<if test="thisMonthProfitRate != null">this_month_profit_rate,</if>
<if test="lastMonthProfitRate != null">last_month_profit_rate,</if>
<if test="lastMonthProfitShare != null">last_month_profit_share,</if>
@@ -154,7 +154,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="yoyMonthProfit != null">#{yoyMonthProfit},</if>
<if test="thisMonthCost != null">#{thisMonthCost},</if>
<if test="lastMonthCost != null">#{lastMonthCost},</if>
<if test="yoyLastMonthCost != null">#{yoyLastMonthCost},</if>
<if test="yoyMonthCost != null">#{yoyMonthCost},</if>
<if test="thisMonthProfitRate != null">#{thisMonthProfitRate},</if>
<if test="lastMonthProfitRate != null">#{lastMonthProfitRate},</if>
<if test="lastMonthProfitShare != null">#{lastMonthProfitShare},</if>
@@ -193,7 +193,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="yoyMonthProfit != null">yoy_month_profit = #{yoyMonthProfit},</if>
<if test="thisMonthCost != null">this_month_cost = #{thisMonthCost},</if>
<if test="lastMonthCost != null">last_month_cost = #{lastMonthCost},</if>
<if test="yoyLastMonthCost != null">yoy_last_month_cost = #{yoyLastMonthCost},</if>
<if test="yoyMonthCost != null">yoy_month_cost = #{yoyMonthCost},</if>
<if test="thisMonthProfitRate != null">this_month_profit_rate = #{thisMonthProfitRate},</if>
<if test="lastMonthProfitRate != null">last_month_profit_rate = #{lastMonthProfitRate},</if>
<if test="lastMonthProfitShare != null">last_month_profit_share = #{lastMonthProfitShare},</if>