|
|
|
|
@@ -264,62 +264,113 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
|
|
|
|
|
<select id="selectNewGrBiSaAggGroupNoMonthNoYearList" resultMap="NewGrBiSaAggMonthCountResult">
|
|
|
|
|
select
|
|
|
|
|
CONCAT (#{params.useYearMonthStart} , '~' , #{params.useYearMonthEnd}) as ny,
|
|
|
|
|
#{saAggParam.useYearStart} as useYearStart,
|
|
|
|
|
#{saAggParam.useYearEnd} as useYearEnd,
|
|
|
|
|
#{saAggParam.useMonthStart} as useMonthStart,
|
|
|
|
|
#{saAggParam.useMonthEnd} as useMonthEnd,
|
|
|
|
|
<if test="groupFieldList.contains('customName') || params.containsKey('customName')">
|
|
|
|
|
current_month.custom_id,
|
|
|
|
|
current_month.custom_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('zoneName') || params.containsKey('zoneName')">
|
|
|
|
|
current_month.zone_id,
|
|
|
|
|
current_month.zone_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('saleTypeName') || params.containsKey('saleTypeName')">
|
|
|
|
|
current_month.sale_type_id,
|
|
|
|
|
current_month.sale_type_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('salerName') || params.containsKey('salerName')">
|
|
|
|
|
current_month.saler_id,
|
|
|
|
|
current_month.saler_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('dosageName') || params.containsKey('dosageName')">
|
|
|
|
|
current_month.dosage_id,
|
|
|
|
|
current_month.dosage_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('stdGoodsName') || params.containsKey('stdGoodsName')">
|
|
|
|
|
current_month.std_goods_name,
|
|
|
|
|
</if>
|
|
|
|
|
current_month.this_month_sa_qty AS this_month_sa_qty,
|
|
|
|
|
ROUND(current_month.this_month_sa_money / 10000, 2) AS this_month_sa_money,
|
|
|
|
|
ROUND(current_month.this_month_profit / 10000, 2) AS this_month_profit,
|
|
|
|
|
ROUND(current_month.this_month_cost / 10000, 2) AS this_month_cost,
|
|
|
|
|
COALESCE (ROUND( current_month.this_month_sa_money/total_month_data.this_month_sa_money_sum * 100, 2), 0 ) as this_month_sa_money_share,
|
|
|
|
|
COALESCE (ROUND( current_month.this_month_profit/total_month_data.this_month_profit_sum * 100, 2), 0 ) as this_month_profit_share
|
|
|
|
|
FROM ( SELECT
|
|
|
|
|
<if test="groupFieldList.contains('customName') || params.containsKey('customName')">
|
|
|
|
|
custom_id,
|
|
|
|
|
custom_name ,
|
|
|
|
|
</if>
|
|
|
|
|
<trim suffixOverrides=",">
|
|
|
|
|
CONCAT (#{params.useYearMonthStart} , '~' , #{params.useYearMonthEnd}) as ny,
|
|
|
|
|
#{saAggParam.useYearStart} as useYearStart,
|
|
|
|
|
#{saAggParam.useYearEnd} as useYearEnd,
|
|
|
|
|
#{saAggParam.useMonthStart} as useMonthStart,
|
|
|
|
|
#{saAggParam.useMonthEnd} as useMonthEnd,
|
|
|
|
|
<if test="groupFieldList.contains('customName') || params.containsKey('customName')">
|
|
|
|
|
current_month.custom_id,
|
|
|
|
|
current_month.custom_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('zoneName') || params.containsKey('zoneName')">
|
|
|
|
|
current_month.zone_id,
|
|
|
|
|
current_month.zone_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('saleTypeName') || params.containsKey('saleTypeName')">
|
|
|
|
|
current_month.sale_type_id,
|
|
|
|
|
current_month.sale_type_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('salerName') || params.containsKey('salerName')">
|
|
|
|
|
current_month.saler_id,
|
|
|
|
|
current_month.saler_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('dosageName') || params.containsKey('dosageName')">
|
|
|
|
|
current_month.dosage_id,
|
|
|
|
|
current_month.dosage_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('stdGoodsName') || params.containsKey('stdGoodsName')">
|
|
|
|
|
current_month.std_goods_name,
|
|
|
|
|
</if>
|
|
|
|
|
current_month.this_month_sa_qty AS this_month_sa_qty,
|
|
|
|
|
ROUND(current_month.this_month_sa_money / 10000, 2) AS this_month_sa_money,
|
|
|
|
|
ROUND(current_month.this_month_profit / 10000, 2) AS this_month_profit,
|
|
|
|
|
ROUND(current_month.this_month_cost / 10000, 2) AS this_month_cost,
|
|
|
|
|
COALESCE (ROUND( current_month.this_month_sa_money/total_month_data.this_month_sa_money_sum * 100, 2), 0 ) as this_month_sa_money_share,
|
|
|
|
|
COALESCE (ROUND( current_month.this_month_profit/total_month_data.this_month_profit_sum * 100, 2), 0 ) as this_month_profit_share,
|
|
|
|
|
|
|
|
|
|
<if test="groupFieldList.contains('stdGoodsName') || params.containsKey('stdGoodsName')">
|
|
|
|
|
std_goods_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="params.isOneYear" >
|
|
|
|
|
ROUND(yoy_month.yoy_month_sa_qty / 10000, 2) AS yoy_month_sa_qty,
|
|
|
|
|
ROUND(yoy_month.yoy_month_sa_money / 10000, 2) AS yoy_month_sa_money,
|
|
|
|
|
ROUND(yoy_month.yoy_month_profit / 10000, 2) AS yoy_month_profit,
|
|
|
|
|
ROUND(yoy_month.yoy_month_cost / 10000, 2) AS yoy_month_cost,
|
|
|
|
|
CASE WHEN (CASE WHEN yoy_month.yoy_month_sa_qty = 0 THEN IF(current_month.this_month_sa_qty > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_sa_qty - yoy_month.yoy_month_sa_qty) / yoy_month.yoy_month_sa_qty * 100 END) > 0 THEN
|
|
|
|
|
CONCAT('🟢 ', ROUND((CASE WHEN yoy_month.yoy_month_sa_qty = 0 THEN IF(current_month.this_month_sa_qty > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_sa_qty - yoy_month.yoy_month_sa_qty) / yoy_month.yoy_month_sa_qty * 100 END), 2))
|
|
|
|
|
WHEN (CASE WHEN yoy_month.yoy_month_sa_qty = 0 THEN IF(current_month.this_month_sa_qty > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_sa_qty - yoy_month.yoy_month_sa_qty) / yoy_month.yoy_month_sa_qty * 100 END)<0 THEN
|
|
|
|
|
CONCAT('🔴 ', ROUND((CASE WHEN yoy_month.yoy_month_sa_qty = 0 THEN IF(current_month.this_month_sa_qty > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_sa_qty - yoy_month.yoy_month_sa_qty) / yoy_month.yoy_month_sa_qty * 100 END), 2))
|
|
|
|
|
END AS monthsaqty_yoy,
|
|
|
|
|
|
|
|
|
|
<if test="groupFieldList.contains('zoneName') || params.containsKey('zoneName')">
|
|
|
|
|
zone_id,
|
|
|
|
|
zone_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('saleTypeName') || params.containsKey('saleTypeName')">
|
|
|
|
|
sale_type_id,
|
|
|
|
|
sale_type_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('dosageName') || params.containsKey('dosageName')">
|
|
|
|
|
dosage_id,
|
|
|
|
|
dosage_name,
|
|
|
|
|
</if>
|
|
|
|
|
CASE WHEN (CASE WHEN yoy_month.yoy_month_sa_money = 0 THEN IF(current_month.this_month_sa_money > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_sa_money - yoy_month.yoy_month_sa_money) / yoy_month.yoy_month_sa_money * 100 END) > 0 THEN
|
|
|
|
|
CONCAT('🟢 ', ROUND((CASE WHEN yoy_month.yoy_month_sa_money = 0 THEN IF(current_month.this_month_sa_money > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_sa_money - yoy_month.yoy_month_sa_money) / yoy_month.yoy_month_sa_money * 100 END), 2))
|
|
|
|
|
WHEN (CASE WHEN yoy_month.yoy_month_sa_money = 0 THEN IF(current_month.this_month_sa_money > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_sa_money - yoy_month.yoy_month_sa_money) / yoy_month.yoy_month_sa_money * 100 END)<0 THEN
|
|
|
|
|
CONCAT('🔴 ', ROUND((CASE WHEN yoy_month.yoy_month_sa_money = 0 THEN IF(current_month.this_month_sa_money > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_sa_money - yoy_month.yoy_month_sa_money) / yoy_month.yoy_month_sa_money * 100 END), 2))
|
|
|
|
|
ELSE '0.00'
|
|
|
|
|
END AS monthsamoney_yoy,
|
|
|
|
|
|
|
|
|
|
CASE WHEN (CASE WHEN yoy_month.yoy_month_cost = 0 THEN IF(current_month.this_month_cost > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_cost - yoy_month.yoy_month_cost) / yoy_month.yoy_month_cost * 100 END) > 0 THEN
|
|
|
|
|
CONCAT('🟢 ', ROUND((CASE WHEN yoy_month.yoy_month_cost = 0 THEN IF(current_month.this_month_cost > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_cost - yoy_month.yoy_month_cost) / yoy_month.yoy_month_cost * 100 END), 2))
|
|
|
|
|
WHEN (CASE WHEN yoy_month.yoy_month_cost = 0 THEN IF(current_month.this_month_cost > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_cost - yoy_month.yoy_month_cost) / yoy_month.yoy_month_cost * 100 END)<0 THEN
|
|
|
|
|
CONCAT('🔴 ', ROUND((CASE WHEN yoy_month.yoy_month_cost = 0 THEN IF(current_month.this_month_cost > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_cost - yoy_month.yoy_month_cost) / yoy_month.yoy_month_cost * 100 END), 2))
|
|
|
|
|
ELSE '0.00'
|
|
|
|
|
END AS this_month_cost_yoy,
|
|
|
|
|
|
|
|
|
|
CASE WHEN (CASE WHEN yoy_month.yoy_month_profit = 0 THEN IF(current_month.this_month_profit > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_profit - yoy_month.yoy_month_profit) / yoy_month.yoy_month_profit * 100 END) > 0 THEN
|
|
|
|
|
CONCAT('🟢 ', ROUND((CASE WHEN yoy_month.yoy_month_profit = 0 THEN IF(current_month.this_month_profit > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_profit - yoy_month.yoy_month_profit) / yoy_month.yoy_month_profit * 100 END), 2))
|
|
|
|
|
WHEN (CASE WHEN yoy_month.yoy_month_profit = 0 THEN IF(current_month.this_month_profit > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_profit - yoy_month.yoy_month_profit) / yoy_month.yoy_month_profit * 100 END)<0 THEN
|
|
|
|
|
CONCAT('🔴 ', ROUND((CASE WHEN yoy_month.yoy_month_profit = 0 THEN IF(current_month.this_month_profit > 0, 100, 0)
|
|
|
|
|
ELSE (current_month.this_month_profit - yoy_month.yoy_month_profit) / yoy_month.yoy_month_profit * 100 END), 2))
|
|
|
|
|
ELSE '0.00'
|
|
|
|
|
END AS monthprofit_yoy,
|
|
|
|
|
</if>
|
|
|
|
|
</trim>
|
|
|
|
|
FROM ( SELECT
|
|
|
|
|
<if test="groupFieldList.contains('customName') || params.containsKey('customName')">
|
|
|
|
|
custom_id,
|
|
|
|
|
custom_name ,
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
|
|
<if test="groupFieldList.contains('stdGoodsName') || params.containsKey('stdGoodsName')">
|
|
|
|
|
std_goods_name,
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
|
|
<if test="groupFieldList.contains('zoneName') || params.containsKey('zoneName')">
|
|
|
|
|
zone_id,
|
|
|
|
|
zone_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('saleTypeName') || params.containsKey('saleTypeName')">
|
|
|
|
|
sale_type_id,
|
|
|
|
|
sale_type_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('dosageName') || params.containsKey('dosageName')">
|
|
|
|
|
dosage_id,
|
|
|
|
|
dosage_name,
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
|
|
<if test="groupFieldList.contains('salerName') || params.containsKey('salerName')">
|
|
|
|
|
saler_id,
|
|
|
|
|
@@ -403,6 +454,121 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
</if>
|
|
|
|
|
</trim>
|
|
|
|
|
) AS current_month
|
|
|
|
|
<if test="params.isOneYear" >
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
<if test="groupFieldList.contains('customName') || params.containsKey('customName')">
|
|
|
|
|
custom_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('stdGoodsName') || params.containsKey('stdGoodsName')">
|
|
|
|
|
std_goods_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('zoneName') || params.containsKey('zoneName')">
|
|
|
|
|
zone_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('saleTypeName') || params.containsKey('saleTypeName')">
|
|
|
|
|
sale_type_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('dosageName') || params.containsKey('dosageName')">
|
|
|
|
|
dosage_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('salerName') || params.containsKey('salerName')">
|
|
|
|
|
saler_id,
|
|
|
|
|
</if>
|
|
|
|
|
ifnull(SUM(this_month_sa_qty), 0) AS yoy_month_sa_qty,
|
|
|
|
|
ifnull(SUM(this_month_sa_money), 0) AS yoy_month_sa_money,
|
|
|
|
|
ifnull(SUM(this_month_cost), 0) as yoy_month_cost,
|
|
|
|
|
ifnull(SUM(this_month_profit), 0) AS yoy_month_profit
|
|
|
|
|
FROM new_gr_bi_sa_agg_month_count
|
|
|
|
|
<where>
|
|
|
|
|
((use_year+1) * 100 + use_month) >= (#{saAggParam.useYearStart} * 100 + #{saAggParam.useMonthStart})
|
|
|
|
|
AND ((use_year+1) * 100 + use_month) <= (#{saAggParam.useYearEnd} * 100 + #{saAggParam.useMonthEnd})
|
|
|
|
|
<if test="saAggParam.zoneName != null and saAggParam.zoneName != ''"> and zone_name in
|
|
|
|
|
<foreach collection="saAggParam.zoneName" item="name" open="(" separator="," close=")">
|
|
|
|
|
#{name}
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
<if test="saAggParam.saleTypeName != null and saAggParam.saleTypeName != ''"> and sale_type_name in
|
|
|
|
|
<foreach collection="saAggParam.saleTypeName" item="name" open="(" separator="," close=")">
|
|
|
|
|
#{name}
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
<if test="saAggParam.customName != null and saAggParam.customName != ''"> and custom_name in
|
|
|
|
|
<foreach collection="saAggParam.customName" item="name" open="(" separator="," close=")">
|
|
|
|
|
#{name}
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
<if test="saAggParam.dosageName != null and saAggParam.dosageName != ''"> and dosage_name in
|
|
|
|
|
<foreach collection="saAggParam.dosageName" item="name" open="(" separator="," close=")">
|
|
|
|
|
#{name}
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
<if test="saAggParam.goodsName != null and saAggParam.goodsName != ''"> and goods_name in
|
|
|
|
|
<foreach collection="saAggParam.goodsName" item="name" open="(" separator="," close=")">
|
|
|
|
|
#{name}
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
<if test="saAggParam.provinceName != null and saAggParam.provinceName != ''"> and province_name in
|
|
|
|
|
<foreach collection="saAggParam.provinceName" item="name" open="(" separator="," close=")">
|
|
|
|
|
#{name}
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
<if test="saAggParam.salerName != null and saAggParam.salerName != ''"> and saler_name in
|
|
|
|
|
<foreach collection="saAggParam.salerName" item="name" open="(" separator="," close=")">
|
|
|
|
|
#{name}
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
|
|
<if test="saAggParam.stdGoodsName != null and saAggParam.stdGoodsName != ''"> and std_goods_name in
|
|
|
|
|
<foreach collection="saAggParam.stdGoodsName" item="name" open="(" separator="," close=")">
|
|
|
|
|
#{name}
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
</where>
|
|
|
|
|
GROUP BY
|
|
|
|
|
<trim suffixOverrides=",">
|
|
|
|
|
<if test="groupFieldList.contains('customName') || params.containsKey('customName')">
|
|
|
|
|
custom_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('stdGoodsName') || params.containsKey('stdGoodsName')">
|
|
|
|
|
std_goods_name,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('zoneName') || params.containsKey('zoneName')">
|
|
|
|
|
zone_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('saleTypeName') || params.containsKey('saleTypeName')">
|
|
|
|
|
sale_type_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('dosageName') || params.containsKey('dosageName')">
|
|
|
|
|
dosage_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('salerName') || params.containsKey('salerName')">
|
|
|
|
|
saler_id,
|
|
|
|
|
</if>
|
|
|
|
|
</trim>
|
|
|
|
|
) yoy_month ON
|
|
|
|
|
<trim prefixOverrides="and">
|
|
|
|
|
<if test="groupFieldList.contains('customName') || params.containsKey('customName')">
|
|
|
|
|
AND yoy_month.custom_id = current_month.custom_id
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('stdGoodsName') || params.containsKey('stdGoodsName')">
|
|
|
|
|
AND yoy_month.std_goods_name = current_month.std_goods_name
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('zoneName') || params.containsKey('zoneName')">
|
|
|
|
|
AND yoy_month.zone_id = current_month.zone_id
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('saleTypeName') || params.containsKey('saleTypeName')">
|
|
|
|
|
AND yoy_month.sale_type_id = current_month.sale_type_id
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('dosageName') || params.containsKey('dosageName')">
|
|
|
|
|
AND yoy_month.dosage_id = current_month.dosage_id
|
|
|
|
|
</if>
|
|
|
|
|
<if test="groupFieldList.contains('salerName') || params.containsKey('salerName')">
|
|
|
|
|
AND yoy_month.saler_id = current_month.saler_id
|
|
|
|
|
</if>
|
|
|
|
|
</trim>
|
|
|
|
|
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
|
|
, (
|
|
|
|
|
SELECT
|
|
|
|
|
|