主要产品前10销售收入与占比 调整,新增插件

This commit is contained in:
king
2026-05-07 17:10:23 +08:00
parent 4596642603
commit 35c66d27af
6 changed files with 171 additions and 17 deletions

View File

@@ -0,0 +1,64 @@
package com.lideeyunji.core.framework.enhance.example.report.xtsy;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
import com.lideeyunji.core.framework.config.aspect.enhancereport.plugin.ReportAroundAdvicePlugin;
import com.lideeyunji.core.framework.entity.NewGrBiSaAggMonthCount;
import com.lideeyunji.core.framework.service.INewGrBiSaAggMonthCountService;
import com.lideeyunji.tool.framework.yunji.model.ResultDataModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 报表-主要产品前10销售收入与占比-插件
*/
@Slf4j
@Component("stgoodTop10Plugin")
public class stgoodTop10Plugin implements ReportAroundAdvicePlugin {
@Resource
INewGrBiSaAggMonthCountService newGrBiSaAggMonthCountService;
@Override
public ResultDataModel executeAround(EnhanceReportContext enhanceContext) {
log.info("进入=======>stgoodTop10Plugin=======>execute");
Map<String, Object> params = enhanceContext.getParam().getParams();
if(!params.containsKey("useYearStart")){
params.put("useYearStart", "2026");
params.put("useMonthStart", "1");
}
if(!params.containsKey("useYearEnd")){
params.put("useYearEnd", "2026");
params.put("useMonthEnd", "4");
}
Page<Object> page = PageHelper.startPage(Integer.parseInt(params.get("pageNo").toString()), Integer.parseInt(params.get("pageSize").toString()));
if (params.containsKey("column")) {
String orderBy = params.get("column") + " " + params.get("order");
// if ("thisYearSaQty".equals(params.get("column"))) {
// orderBy = "this_year_sa_qty " + params.get("order").toString();
// }
// if ("saqty_yoy".equals(params.get("column"))) {
// orderBy = "CAST(TRIM(REGEXP_SUBSTR(saqty_yoy, '-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)')) AS DECIMAL(10,2)) " + params.get("order").toString();
// }
// if ("thisYearSaMoney".equals(params.get("column"))) {
// orderBy = "this_year_sa_money " + params.get("order").toString();
// }
page.setUnsafeOrderBy(orderBy);
}
List<NewGrBiSaAggMonthCount> newGrBiSaAggList = newGrBiSaAggMonthCountService.stgoodTop10(params);
PageInfo<NewGrBiSaAggMonthCount> pageInfo = new PageInfo<>(newGrBiSaAggList);
List<Map<String, Object>> list = newGrBiSaAggList.stream().map(BeanUtil::beanToMap).collect(Collectors.toList());
return ResultDataModel.fomat(pageInfo.getTotal(), list);
}
}

View File

@@ -85,6 +85,9 @@ public class NewGrBiSaAggMonthCount implements Serializable
@TableField(value = "std_goods_name")
private String stdGoodsName;
@TableField(value = "goods_id")
private String goodsId;
@TableField(value = "province_id")
private String provinceId;
@@ -190,4 +193,13 @@ public class NewGrBiSaAggMonthCount implements Serializable
@TableField(value = "monthprofit_yoy")
private String monthprofit_yoy;
@TableField(value = "yoy_money_sub")
private String yoyMoneySub;
@TableField(value = "money")
private String money;
@TableField(value = "money_share")
private String moneyShare;
}

View File

@@ -1,16 +1,15 @@
package com.lideeyunji.core.framework.mapper;
import java.util.List;
import java.util.Map;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.lideeyunji.core.framework.entity.NewGrBiSaAgg;
import com.lideeyunji.core.framework.entity.NewGrBiSaAggMonthCount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lideeyunji.core.framework.entity.NewGrBiSaAggMonthCount;
import com.lideeyunji.core.framework.params.SaAggParam;
import com.lideeyunji.tool.framework.permission.core.annotation.DataPermission;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 综合销售情况月维度Mapper接口
*
@@ -100,4 +99,14 @@ public interface NewGrBiSaAggMonthCountMapper extends BaseMapper<NewGrBiSaAggMon
@DS(value = "#dataSourceType")
public List<NewGrBiSaAggMonthCount> selectNewGrBiSaAggGroupNoMonthNoYearList(@Param("dataSourceType") String dataSourceType, @Param("saAggParam") SaAggParam saAggParam, @Param("params") Map<String, Object> params, @Param("groupFieldList")List<String> groupFieldList);
/**
* 主要产品前10销售收入与占比 -月度
*
* @param params 综合销售情况明细参数
* @return 综合销售情况明细集合
*/
@DataPermission(enable = false)
@DS(value = "#dataSourceType")
public List<NewGrBiSaAggMonthCount> stgoodTop10(@Param("dataSourceType") String dataSourceType, @Param("params") Map<String, Object> params);
}

View File

@@ -1,12 +1,11 @@
package com.lideeyunji.core.framework.service;
import com.lideeyunji.core.framework.entity.NewGrBiSaAggMonthCount;
import com.lideeyunji.core.framework.params.SaAggParam;
import java.util.List;
import java.util.Map;
import com.lideeyunji.core.framework.entity.NewGrBiSaAgg;
import com.lideeyunji.core.framework.entity.NewGrBiSaAggMonthCount;
import com.lideeyunji.core.framework.params.SaAggParam;
/**
* 综合销售情况月维度Service接口
*
@@ -72,4 +71,5 @@ public interface INewGrBiSaAggMonthCountService
public List<NewGrBiSaAggMonthCount> selectNewGrBiSaAggGroupNoMonthNoYearList(Map<String, Object> params, List<String> groupFieldList);
List<NewGrBiSaAggMonthCount> stgoodTop10(Map<String, Object> params);
}

View File

@@ -1,17 +1,15 @@
package com.lideeyunji.core.framework.service.impl;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lideeyunji.core.framework.entity.NewGrBiSaAgg;
import com.lideeyunji.core.framework.entity.NewGrBiSaAggMonthCount;
import com.lideeyunji.core.framework.mapper.NewGrBiSaAggMonthCountMapper;
import com.lideeyunji.core.framework.params.SaAggParam;
import com.lideeyunji.core.framework.service.INewGrBiSaAggMonthCountService;
import com.lideeyunji.tool.framework.common.constant.lideeYunJiBaseConstant;
import org.springframework.stereotype.Service;
import com.lideeyunji.core.framework.mapper.NewGrBiSaAggMonthCountMapper;
import com.lideeyunji.core.framework.entity.NewGrBiSaAggMonthCount;
import com.lideeyunji.core.framework.service.INewGrBiSaAggMonthCountService;
import java.util.List;
import java.util.Map;
/**
* 综合销售情况月维度Service业务层处理
@@ -116,4 +114,9 @@ public class NewGrBiSaAggMonthCountServiceImpl extends ServiceImpl<NewGrBiSaAggM
SaAggParam saAggParam = NewGrBiSaAggServiceImpl.createParam(params);
return this.baseMapper.selectNewGrBiSaAggGroupNoMonthNoYearList(lideeYunJiBaseConstant.DS_ERP_BI_DATA, saAggParam,params, groupFieldList);
}
@Override
public List<NewGrBiSaAggMonthCount> stgoodTop10(Map<String, Object> params) {
return this.baseMapper.stgoodTop10(lideeYunJiBaseConstant.DS_ERP_BI_DATA, params);
}
}

View File

@@ -1319,4 +1319,70 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
use_year = YEAR(CURDATE()) and sale_type_name in ( '代理品种','其他收入','自营品种','公司出口','委托加工','外贸品种')
</select>
<select id="stgoodTop10" resultType="com.lideeyunji.core.framework.entity.NewGrBiSaAggMonthCount">
WITH
total_year_data(use_year,this_month_sa_money_total) AS (
SELECT
use_year,
SUM(this_month_sa_money) AS this_month_sa_money_total
FROM
erp_bi_data.new_gr_bi_sa_agg_month_count
<where>
<if test="params.useYearStart != null">
AND (use_year * 100 + use_month) &gt;= (#{params.useYearStart} * 100 + #{params.useMonthStart})
</if>
<if test="params.useYearEnd != null">
AND (use_year * 100 + use_month) &lt;= (#{params.useYearEnd} * 100 + #{params.useMonthEnd})
</if>
</where>
GROUP BY use_year
)
SELECT
CONCAT(#{params.useYearStart}, '-', #{params.useMonthStart}, ' ~ ' , #{params.useYearEnd}, '-', #{params.useMonthEnd}) as ny,
top10.use_year,
CONCAT(#{params.useMonthStart},'~', #{params.useMonthEnd}) use_month,
CONCAT(top10.std_goods_name,',',top10.goods_id) as std_goods_name,
ROUND(top10.money/10000, 2) as money,
ROUND((top10.money - yoy_data.money)/10000, 2) as yoy_money_sub,
COALESCE(ROUND(top10.money / total_year_data.this_month_sa_money_total * 100, 2), 0) AS money_share
FROM
(SELECT
use_year,
std_goods_name,
GROUP_CONCAT(DISTINCT goods_id ORDER BY goods_id SEPARATOR ',') AS goods_id,
sum(this_month_sa_money) AS money
FROM new_gr_bi_sa_agg
<where>
<if test="params.useYearStart != null">
AND (use_year * 100 + use_month) &gt;= (#{params.useYearStart} * 100 + #{params.useMonthStart})
</if>
<if test="params.useYearEnd != null">
AND (use_year * 100 + use_month) &lt;= (#{params.useYearEnd} * 100 + #{params.useMonthEnd})
</if>
</where>
GROUP BY use_year,std_goods_name
ORDER BY money DESC
LIMIT 10
) AS top10
left join
(SELECT
use_year,
std_goods_name,
sum(this_month_sa_money) AS money
FROM new_gr_bi_sa_agg_month_count
<where>
<if test="params.useYearStart != null">
((use_year+1) * 100 + use_month) &gt;= (#{params.useYearStart} * 100 + #{params.useMonthStart})
</if>
<if test="params.useYearEnd != null">
AND ((use_year+1) * 100 + use_month) &lt;= (#{params.useYearEnd} * 100 + #{params.useMonthEnd})
</if>
</where>
GROUP BY use_year,std_goods_name
) AS yoy_data on top10.std_goods_name = yoy_data.std_goods_name
,total_year_data
ORDER BY
money DESC
</select>
</mapper>