4 Commits

7 changed files with 248 additions and 37 deletions

View File

@@ -60,6 +60,17 @@ public class ZhxsqkPlugin implements ReportAroundAdvicePlugin {
Page<Object> page = PageHelper.startPage(Integer.parseInt(params.get("pageNo").toString()), Integer.parseInt(params.get("pageSize").toString()));
if(!groupFieldList.contains("useMonth") && !groupFieldList.contains("useYear")){
setMonthOrderBy(params, page);
if(!params.containsKey("column")){
page.setUnsafeOrderBy(params.get("Group by").toString()
.replace("useYear", "use_year desc")
.replace("useMonth", "use_month desc")
.replace("stdGoodsName", "std_goods_name")
.replace("customName", "custom_name")
.replace("zoneName", "zone_name")
.replace("salerName", "saler_name")
.replace("dosageName", "dosage_name")
.replace("saleTypeName", "sale_type_name"));
}
if(params.get("useYearStart").toString() .equals(params.get("useYearEnd").toString())){
params.put("isOneYear", true);
}else{
@@ -72,6 +83,17 @@ public class ZhxsqkPlugin implements ReportAroundAdvicePlugin {
}
if(groupFieldList.contains("useMonth") || params.containsKey("useMonth")){
setMonthOrderBy(params, page);
if(!params.containsKey("column")){
page.setUnsafeOrderBy(params.get("Group by").toString()
.replace("useYear", "use_year desc")
.replace("useMonth", "use_month desc")
.replace("stdGoodsName", "std_goods_name")
.replace("customName", "custom_name")
.replace("zoneName", "zone_name")
.replace("salerName", "saler_name")
.replace("dosageName", "dosage_name")
.replace("saleTypeName", "sale_type_name"));
}
List<NewGrBiSaAggMonthCount> newGrBiSaAggList = newGrBiSaAggMonthCountService.selectNewGrBiSaAggGroupMonthList(params, groupFieldList);
PageInfo<NewGrBiSaAggMonthCount> pageInfo = new PageInfo<>(newGrBiSaAggList);
List<Map<String, Object>> list = newGrBiSaAggList.stream().map(BeanUtil::beanToMap).collect(Collectors.toList());
@@ -109,16 +131,17 @@ public class ZhxsqkPlugin implements ReportAroundAdvicePlugin {
if ("thisYearSaMoneyGrowth".equals(params.get("column"))) {
orderBy = "CAST(TRIM(REGEXP_SUBSTR(this_year_sa_money_growth, '-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)')) AS DECIMAL(10,2)) " + params.get("order").toString();
}
if("stdGoodsName".equals(params.get("column"))){
orderBy = "std_goods_name " + params.get("order").toString();
}
if("customName".equals(params.get("column"))){
orderBy = "custom_name " + params.get("order").toString();
}
if("salerName".equals(params.get("column"))){
orderBy = "saler_name " + params.get("order").toString();
}
page.setUnsafeOrderBy(orderBy);
commonOrder(params, page, orderBy);
}else{
page.setUnsafeOrderBy(params.get("Group by").toString()
.replace("useYear", "use_year desc")
.replace("useMonth", "use_month desc")
.replace("stdGoodsName", "std_goods_name")
.replace("customName", "custom_name")
.replace("zoneName", "zone_name")
.replace("salerName", "saler_name")
.replace("dosageName", "dosage_name")
.replace("saleTypeName", "sale_type_name"));
}
List<NewGrBiSaAggYearCount> newGrBiSaAggList = newGrBiSaAggYearCountService.selectNewGrBiSaAggGroupYearList(params, groupFieldList);
PageInfo<NewGrBiSaAggYearCount> pageInfo = new PageInfo<>(newGrBiSaAggList);
@@ -169,16 +192,45 @@ public class ZhxsqkPlugin implements ReportAroundAdvicePlugin {
if ("lastMonthSaMoney_yoy".equals(params.get("column"))) {
orderBy = "CAST(TRIM(REGEXP_SUBSTR(lastMonthSaMoney_yoy, '-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)')) AS DECIMAL(10,2)) " + params.get("order").toString();
}
if("stdGoodsName".equals(params.get("column"))){
orderBy = "std_goods_name " + params.get("order").toString();
}
if("customName".equals(params.get("column"))){
orderBy = "custom_name " + params.get("order").toString();
}
if("salerName".equals(params.get("column"))){
orderBy = "saler_name " + params.get("order").toString();
}
page.setUnsafeOrderBy(orderBy);
commonOrder(params, page, orderBy);
}
}
private static void commonOrder(Map<String, Object> params, Page<Object> page, String orderBy) {
if("stdGoodsName".equals(params.get("column"))){
orderBy = "std_goods_name " + params.get("order").toString();
}
if("customName".equals(params.get("column"))){
orderBy = "custom_name " + params.get("order").toString();
}
if("salerName".equals(params.get("column"))){
orderBy = "saler_name " + params.get("order").toString();
}
if("useYear".equals(params.get("column"))){
orderBy = "use_year " + params.get("order").toString();
}
if("useMonth".equals(params.get("column"))){
orderBy = "use_month " + params.get("order").toString();
}
if("stdGoodsName".equals(params.get("column"))){
orderBy = "std_goods_name " + params.get("order").toString();
}
if("customName".equals(params.get("column"))){
orderBy = "custom_name " + params.get("order").toString();
}
if("zoneName".equals(params.get("column"))){
orderBy = "zone_name " + params.get("order").toString();
}
if("salerName".equals(params.get("column"))){
orderBy = "saler_name " + params.get("order").toString();
}
if("dosageName".equals(params.get("column"))){
orderBy = "dosage_name " + params.get("order").toString();
}
if("saleTypeName".equals(params.get("column"))){
orderBy = "sale_type_name " + params.get("order").toString();
}
page.setUnsafeOrderBy(orderBy);
}
}

View File

@@ -0,0 +1,69 @@
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.time.LocalDateTime;
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();
// 获取一个月前的时间和年月
LocalDateTime lastNow = LocalDateTime.now().minusMonths(1);
int lastYear = lastNow.getYear();
int lastMonth = lastNow.getMonthValue();
if(!params.containsKey("useYearStart")){
params.put("useYearStart", lastYear);
params.put("useMonthStart", "1");
}
if(!params.containsKey("useYearEnd")){
params.put("useYearEnd", lastYear);
params.put("useMonthEnd", lastMonth);
}
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>