diff --git a/lidee-core/src/main/java/com/lideeyunji/core/framework/entity/NewGrBiSaAggMonthCount.java b/lidee-core/src/main/java/com/lideeyunji/core/framework/entity/NewGrBiSaAggMonthCount.java index b81b501..0f872dc 100644 --- a/lidee-core/src/main/java/com/lideeyunji/core/framework/entity/NewGrBiSaAggMonthCount.java +++ b/lidee-core/src/main/java/com/lideeyunji/core/framework/entity/NewGrBiSaAggMonthCount.java @@ -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") diff --git a/lidee-core/src/main/java/com/lideeyunji/core/framework/mapper/NewGrBiSaAggMapper.java b/lidee-core/src/main/java/com/lideeyunji/core/framework/mapper/NewGrBiSaAggMapper.java index 46c3730..76f5419 100644 --- a/lidee-core/src/main/java/com/lideeyunji/core/framework/mapper/NewGrBiSaAggMapper.java +++ b/lidee-core/src/main/java/com/lideeyunji/core/framework/mapper/NewGrBiSaAggMapper.java @@ -38,12 +38,14 @@ public interface NewGrBiSaAggMapper extends BaseMapper // 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(); diff --git a/lidee-core/src/main/java/com/lideeyunji/core/framework/service/impl/NewGrBiSaAggServiceImpl.java b/lidee-core/src/main/java/com/lideeyunji/core/framework/service/impl/NewGrBiSaAggServiceImpl.java index 105e6f4..b0c8739 100644 --- a/lidee-core/src/main/java/com/lideeyunji/core/framework/service/impl/NewGrBiSaAggServiceImpl.java +++ b/lidee-core/src/main/java/com/lideeyunji/core/framework/service/impl/NewGrBiSaAggServiceImpl.java @@ -76,12 +76,14 @@ public class NewGrBiSaAggServiceImpl extends ServiceImpl--> - 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 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 new_gr_bi_sa_agg_year_count a @@ -416,32 +416,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + -- 本月毛利率 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; - - - -- 本年毛利率 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; - - - - + -- 本月销售金额占比 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 ); + + + -- 本年毛利率 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; + + + -- 本年销售金额占比 this_year_sa_money_share当前行本年销售额/本年销售额总和*100% diff --git a/lidee-core/src/main/resources/mapper/framework/NewGrBiSaAggMonthCountMapper.xml b/lidee-core/src/main/resources/mapper/framework/NewGrBiSaAggMonthCountMapper.xml index fc21b50..9eaa732 100644 --- a/lidee-core/src/main/resources/mapper/framework/NewGrBiSaAggMonthCountMapper.xml +++ b/lidee-core/src/main/resources/mapper/framework/NewGrBiSaAggMonthCountMapper.xml @@ -33,7 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - 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