综合销售情况表 调整月度,年度 报表数据
This commit is contained in:
@@ -11,10 +11,7 @@ import com.lideeyunji.core.framework.config.aspect.enhancereport.enums.RefreshPl
|
|||||||
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.BuildEnhanceReportContext;
|
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.BuildEnhanceReportContext;
|
||||||
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
||||||
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportParam;
|
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportParam;
|
||||||
import com.lideeyunji.core.framework.config.aspect.enhancereport.plugin.ReportAfterAdvicePlugin;
|
import com.lideeyunji.core.framework.config.aspect.enhancereport.plugin.*;
|
||||||
import com.lideeyunji.core.framework.config.aspect.enhancereport.plugin.ReportBaseAdvicePlugin;
|
|
||||||
import com.lideeyunji.core.framework.config.aspect.enhancereport.plugin.ReportBeforeAdvicePlugin;
|
|
||||||
import com.lideeyunji.core.framework.config.aspect.enhancereport.plugin.ReportPluginManager;
|
|
||||||
import com.lideeyunji.core.framework.entity.ReportEntity;
|
import com.lideeyunji.core.framework.entity.ReportEntity;
|
||||||
import com.lideeyunji.core.framework.service.IReportService;
|
import com.lideeyunji.core.framework.service.IReportService;
|
||||||
import com.lideeyunji.core.framework.utils.Func;
|
import com.lideeyunji.core.framework.utils.Func;
|
||||||
@@ -24,7 +21,9 @@ import com.lideeyunji.tool.framework.yunji.tool.spring.SpringUtils;
|
|||||||
import com.lideeyunji.tool.framework.yunji.utils.FuncBase;
|
import com.lideeyunji.tool.framework.yunji.utils.FuncBase;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -140,6 +139,30 @@ public class LideeYunJiReportEnhance extends LideeYunJiBaseEnhance {
|
|||||||
ReportPluginManager.executePlugin(javaClass, context);
|
ReportPluginManager.executePlugin(javaClass, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Around("@annotation(lideeyunJiReportEnhance)")
|
||||||
|
public Object around(ProceedingJoinPoint joinPoint, LideeyunJiReportEnhance lideeyunJiReportEnhance) throws Throwable {
|
||||||
|
//获取参数
|
||||||
|
BuildEnhanceReportContext buildEnhanceContext = this.getContextAndPlugins(joinPoint);
|
||||||
|
if (FuncBase.isEmpty(buildEnhanceContext)) {//没有增强
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
//增强列表
|
||||||
|
String javaClass = buildEnhanceContext.getJavaClass();
|
||||||
|
if (Func.isEmpty(javaClass)) {//无增强
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
//有增强,但是增强不是报表增强,直接返回原值
|
||||||
|
ReportBaseAdvicePlugin plugin = ReportPluginManager.getPlugin(javaClass);
|
||||||
|
if (!(plugin instanceof ReportAroundAdvicePlugin)) {
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
EnhanceReportContext context = buildEnhanceContext.getContext();
|
||||||
|
//执行增强
|
||||||
|
return ReportPluginManager.executeAroundPlugin(javaClass, context);
|
||||||
|
}
|
||||||
|
|
||||||
private BuildEnhanceReportContext getContextAndPlugins(JoinPoint joinPoint) {
|
private BuildEnhanceReportContext getContextAndPlugins(JoinPoint joinPoint) {
|
||||||
Map<String, Object> paramMap = super.getJoinPointParam(joinPoint);
|
Map<String, Object> paramMap = super.getJoinPointParam(joinPoint);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.lideeyunji.core.framework.config.aspect.enhancereport.plugin;
|
||||||
|
|
||||||
|
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
||||||
|
import com.lideeyunji.tool.framework.yunji.model.ResultDataModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表统计 环绕增强(报表统计专属)
|
||||||
|
*/
|
||||||
|
public interface ReportAroundAdvicePlugin extends ReportBaseAdvicePlugin {
|
||||||
|
|
||||||
|
ResultDataModel executeAround(EnhanceReportContext enhanceContext);
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
package com.lideeyunji.core.framework.config.aspect.enhancereport.plugin;
|
package com.lideeyunji.core.framework.config.aspect.enhancereport.plugin;
|
||||||
|
|
||||||
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
||||||
|
import com.lideeyunji.tool.framework.yunji.model.ResultDataModel;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -39,4 +40,8 @@ public class ReportPluginManager {
|
|||||||
plugin.execute(enhanceContext);
|
plugin.execute(enhanceContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ResultDataModel executeAroundPlugin(String name, EnhanceReportContext enhanceContext) {
|
||||||
|
ReportAroundAdvicePlugin plugin = (ReportAroundAdvicePlugin)plugins.get(name);
|
||||||
|
return plugin.executeAround(enhanceContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -74,6 +74,12 @@ public class NewGrBiSaAggMonthCountController extends BaseController
|
|||||||
if (params.containsKey("stdGoodsName")){
|
if (params.containsKey("stdGoodsName")){
|
||||||
saAggParam.setStdGoodsName(Arrays.asList(params.get("stdGoodsName").toString().split( ",")));
|
saAggParam.setStdGoodsName(Arrays.asList(params.get("stdGoodsName").toString().split( ",")));
|
||||||
}
|
}
|
||||||
|
if (params.containsKey("goodsName")){
|
||||||
|
saAggParam.setGoodsName(Arrays.asList(params.get("goodsName").toString().split( ",")));
|
||||||
|
}
|
||||||
|
if (params.containsKey("provinceName")){
|
||||||
|
saAggParam.setProvinceName(Arrays.asList(params.get("provinceName").toString().split( ",")));
|
||||||
|
}
|
||||||
if (params.containsKey("usemonth") || groupField.contains("usemonth")){
|
if (params.containsKey("usemonth") || groupField.contains("usemonth")){
|
||||||
List<NewGrBiSaAggMonthCount> list = newGrBiSaAggMonthCountService.getTotalDetail(saAggParam);
|
List<NewGrBiSaAggMonthCount> list = newGrBiSaAggMonthCountService.getTotalDetail(saAggParam);
|
||||||
return BaseWebResult.success(list);
|
return BaseWebResult.success(list);
|
||||||
|
|||||||
@@ -2,20 +2,45 @@
|
|||||||
package com.lideeyunji.core.framework.enhance.example.report.xtsy;
|
package com.lideeyunji.core.framework.enhance.example.report.xtsy;
|
||||||
|
|
||||||
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
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.config.aspect.enhancereport.plugin.ReportBeforeAdvicePlugin;
|
import com.lideeyunji.core.framework.config.aspect.enhancereport.plugin.ReportBeforeAdvicePlugin;
|
||||||
|
import com.lideeyunji.core.framework.entity.NewGrBiSaAgg;
|
||||||
|
import com.lideeyunji.core.framework.service.INewGrBiSaAggService;
|
||||||
|
import com.lideeyunji.tool.framework.exception.lideeYunJiException;
|
||||||
|
import com.lideeyunji.tool.framework.yunji.model.ResultDataModel;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报表-系统首页-单表
|
* 报表-系统首页-单表
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component("zhxsqkPlugin")
|
@Component("zhxsqkPlugin")
|
||||||
public class zhxsqkPlugin implements ReportBeforeAdvicePlugin {
|
public class zhxsqkPlugin implements ReportAroundAdvicePlugin {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
INewGrBiSaAggService newGrBiSaAggService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(EnhanceReportContext enhanceContext) {
|
public ResultDataModel executeAround(EnhanceReportContext enhanceContext) {
|
||||||
|
log.info("进入=======>zhxsqkLineReportEnhance=======>execute");
|
||||||
|
Map<String, Object> params = enhanceContext.getParam().getParams();
|
||||||
|
|
||||||
|
if (params.containsKey("Group by")) {
|
||||||
|
if (params.containsKey("goodsname")) {
|
||||||
|
throw new lideeYunJiException("在选择维度时,“货品名称”不能有值!");
|
||||||
|
}
|
||||||
|
List<String> groupFieldList = Arrays.asList(params.get("Group by").toString().split(","));
|
||||||
|
List<NewGrBiSaAgg> newGrBiSaAggList = newGrBiSaAggService.selectNewGrBiSaAggGroupMonthList(params, groupFieldList);
|
||||||
|
// return ResultDataModel.fomatList(newGrBiSaAggList);
|
||||||
|
}else {
|
||||||
|
newGrBiSaAggService.selectNewGrBiSaAggList(params);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package com.lideeyunji.core.framework.mapper;
|
package com.lideeyunji.core.framework.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.lideeyunji.core.framework.entity.GrBiSaAgg;
|
import com.lideeyunji.core.framework.entity.GrBiSaAgg;
|
||||||
import com.lideeyunji.core.framework.entity.NewGrBiSaAgg;
|
import com.lideeyunji.core.framework.entity.NewGrBiSaAgg;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.lideeyunji.core.framework.params.SaAggParam;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,10 +63,17 @@ public interface NewGrBiSaAggMapper extends BaseMapper<NewGrBiSaAgg>
|
|||||||
/**
|
/**
|
||||||
* 查询综合销售情况明细列表
|
* 查询综合销售情况明细列表
|
||||||
*
|
*
|
||||||
* @param newGrBiSaAgg 综合销售情况明细
|
* @param saAggParam 综合销售情况明细参数
|
||||||
* @return 综合销售情况明细集合
|
* @return 综合销售情况明细集合
|
||||||
*/
|
*/
|
||||||
public List<NewGrBiSaAgg> selectNewGrBiSaAggList(NewGrBiSaAgg newGrBiSaAgg);
|
public List<NewGrBiSaAgg> selectNewGrBiSaAggList(@Param("saAggParam")SaAggParam saAggParam);
|
||||||
|
/**
|
||||||
|
* 批量查询综合销售情况明细列表 -月度
|
||||||
|
*
|
||||||
|
* @param saAggParam 综合销售情况明细参数
|
||||||
|
* @return 综合销售情况明细集合
|
||||||
|
*/
|
||||||
|
public List<NewGrBiSaAgg> selectNewGrBiSaAggGroupMonthList(@Param("saAggParam") SaAggParam saAggParam, @Param("params") Map<String, Object> params, @Param("groupFieldList")List<String> groupFieldList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增综合销售情况明细
|
* 新增综合销售情况明细
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ public class SaAggParam {
|
|||||||
private List<String> salerName;
|
private List<String> salerName;
|
||||||
private List<String> dosageName;
|
private List<String> dosageName;
|
||||||
private List<String> stdGoodsName;
|
private List<String> stdGoodsName;
|
||||||
|
private List<String> goodsName;
|
||||||
|
private List<String> provinceName;
|
||||||
|
|
||||||
private List<String> groupFieldList;
|
private List<String> groupFieldList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.lideeyunji.core.framework.service;
|
package com.lideeyunji.core.framework.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.lideeyunji.core.framework.entity.NewGrBiSaAgg;
|
import com.lideeyunji.core.framework.entity.NewGrBiSaAgg;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
@@ -28,7 +30,9 @@ public interface INewGrBiSaAggService
|
|||||||
* @param newGrBiSaAgg 综合销售情况明细
|
* @param newGrBiSaAgg 综合销售情况明细
|
||||||
* @return 综合销售情况明细集合
|
* @return 综合销售情况明细集合
|
||||||
*/
|
*/
|
||||||
public List<NewGrBiSaAgg> selectNewGrBiSaAggList(NewGrBiSaAgg newGrBiSaAgg);
|
public List<NewGrBiSaAgg> selectNewGrBiSaAggList(Map<String, Object> params);
|
||||||
|
|
||||||
|
public List<NewGrBiSaAgg> selectNewGrBiSaAggGroupMonthList(Map<String, Object> params, List<String> groupFieldList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增综合销售情况明细
|
* 新增综合销售情况明细
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.lideeyunji.core.framework.service.impl;
|
package com.lideeyunji.core.framework.service.impl;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
@@ -9,6 +11,7 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.lideeyunji.core.framework.entity.GrBiSaAgg;
|
import com.lideeyunji.core.framework.entity.GrBiSaAgg;
|
||||||
|
import com.lideeyunji.core.framework.params.SaAggParam;
|
||||||
import com.lideeyunji.core.framework.service.INewGrBiSaAggMonthCountService;
|
import com.lideeyunji.core.framework.service.INewGrBiSaAggMonthCountService;
|
||||||
import com.lideeyunji.core.framework.service.INewGrBiSaAggYearCountService;
|
import com.lideeyunji.core.framework.service.INewGrBiSaAggYearCountService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -128,14 +131,48 @@ public class NewGrBiSaAggServiceImpl extends ServiceImpl<NewGrBiSaAggMapper, New
|
|||||||
/**
|
/**
|
||||||
* 查询综合销售情况明细列表
|
* 查询综合销售情况明细列表
|
||||||
*
|
*
|
||||||
* @param newGrBiSaAgg 综合销售情况明细
|
* @param params 综合销售情况明细
|
||||||
* @return 综合销售情况明细
|
* @return 综合销售情况明细
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<NewGrBiSaAgg> selectNewGrBiSaAggList(NewGrBiSaAgg newGrBiSaAgg)
|
public List<NewGrBiSaAgg> selectNewGrBiSaAggList(Map<String, Object> params)
|
||||||
{
|
{
|
||||||
|
SaAggParam saAggParam = createParam(params);
|
||||||
|
return this.baseMapper.selectNewGrBiSaAggList(saAggParam);
|
||||||
|
}
|
||||||
|
|
||||||
return this.baseMapper.selectNewGrBiSaAggList(newGrBiSaAgg);
|
public List<NewGrBiSaAgg> selectNewGrBiSaAggGroupMonthList(Map<String, Object> params, List<String> groupFieldList){
|
||||||
|
SaAggParam saAggParam = createParam(params);
|
||||||
|
return this.baseMapper.selectNewGrBiSaAggGroupMonthList(saAggParam,params, groupFieldList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SaAggParam createParam(Map<String, Object> params) {
|
||||||
|
SaAggParam saAggParam = new SaAggParam();
|
||||||
|
if (params.containsKey("useyear")) {
|
||||||
|
saAggParam.setUseYear(params.get("useyear").toString());
|
||||||
|
}
|
||||||
|
if (params.containsKey("usemonth")) {
|
||||||
|
saAggParam.setUseMonth(params.get("usemonth").toString());
|
||||||
|
}
|
||||||
|
if (params.containsKey("customname")) {
|
||||||
|
saAggParam.setCustomName(Arrays.asList(params.get("customname").toString().split( ",")));
|
||||||
|
}
|
||||||
|
if (params.containsKey("stdGoodsName")) {
|
||||||
|
saAggParam.setStdGoodsName(Arrays.asList(params.get("stdGoodsName").toString().split( ",")));
|
||||||
|
}
|
||||||
|
if (params.containsKey("zonename")) {
|
||||||
|
saAggParam.setZoneName(Arrays.asList(params.get("zonename").toString().split( ",")));
|
||||||
|
}
|
||||||
|
if (params.containsKey("saletypename")) {
|
||||||
|
saAggParam.setSaleTypeName(Arrays.asList(params.get("saletypename").toString().split( ",")));
|
||||||
|
}
|
||||||
|
if (params.containsKey("dosagename")) {
|
||||||
|
saAggParam.setDosageName(Arrays.asList(params.get("dosagename").toString().split( ",")));
|
||||||
|
}
|
||||||
|
if (params.containsKey("salername")) {
|
||||||
|
saAggParam.setSalerName(Arrays.asList(params.get("salername").toString().split( ",")));
|
||||||
|
}
|
||||||
|
return saAggParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -511,29 +511,629 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
END,
|
END,
|
||||||
this_year_profit_change = ( this_year_profit - last_year_profit);
|
this_year_profit_change = ( this_year_profit - last_year_profit);
|
||||||
</update>
|
</update>
|
||||||
<select id="selectNewGrBiSaAggList" parameterType="com.lideeyunji.core.framework.entity.NewGrBiSaAgg" resultMap="NewGrBiSaAggResult">
|
<select id="selectNewGrBiSaAggList" parameterType="com.lideeyunji.core.framework.params.SaAggParam" resultMap="NewGrBiSaAggResult">
|
||||||
<include refid="selectNewGrBiSaAggVo"/>
|
SELECT
|
||||||
|
ANY_VALUE (tbl_lgbsa.id) id,
|
||||||
|
tbl_lgbsa.use_year,
|
||||||
|
tbl_lgbsa.use_month,
|
||||||
|
CONCAT(tbl_lgbsa.use_year, LPAD(tbl_lgbsa.use_month, 2, '0')) AS ny,
|
||||||
|
tbl_lgbsa.zone_id,
|
||||||
|
tbl_lgbsa.zone_name,
|
||||||
|
tbl_lgbsa.sale_type_id,
|
||||||
|
tbl_lgbsa.sale_type_name,
|
||||||
|
tbl_lgbsa.custom_id,
|
||||||
|
tbl_lgbsa.custom_name,
|
||||||
|
tbl_lgbsa.dosage_id,
|
||||||
|
tbl_lgbsa.dosage_name,
|
||||||
|
tbl_lgbsa.goods_id,
|
||||||
|
tbl_lgbsa.goods_name,
|
||||||
|
tbl_lgbsa.std_goods_name,
|
||||||
|
tbl_lgbsa.province_id,
|
||||||
|
tbl_lgbsa.province_name,
|
||||||
|
tbl_lgbsa.saler_id,
|
||||||
|
tbl_lgbsa.saler_name,
|
||||||
|
tbl_lgbsa.this_month_sa_qty AS thisMonthSaQty,
|
||||||
|
ROUND(tbl_lgbsa.this_month_sa_money / 10000, 2) AS this_month_sa_money, -- 本月销售金额(元)
|
||||||
|
ROUND(tbl_lgbsa.this_month_cost / 10000, 2) AS this_month_cost,
|
||||||
|
ROUND(tbl_lgbsa.this_month_profit / 10000, 2) AS this_month_profit,
|
||||||
|
tbl_lgbsa.last_month_sa_qty as last_month_sa_qty,
|
||||||
|
ROUND(tbl_lgbsa.last_month_sa_money / 10000, 2) as last_month_sa_money,
|
||||||
|
ROUND(tbl_lgbsa.last_month_profit / 10000, 2) as last_month_profit,
|
||||||
|
ROUND(tbl_lgbsa.last_month_cost / 10000, 2) as last_month_cost,
|
||||||
|
ROUND(tbl_lgbsa.yoy_month_sa_qty/ 10000, 2) as yoy_month_sa_qty,
|
||||||
|
ROUND(tbl_lgbsa.yoy_month_sa_money / 10000, 2) as yoy_month_sa_money,
|
||||||
|
ROUND(tbl_lgbsa.yoy_month_profit / 10000, 2) as yoy_month_profit,
|
||||||
|
ROUND(tbl_lgbsa.yoy_month_cost / 10000, 2) as yoy_month_cost,
|
||||||
|
CONCAT(ROUND((SELECT SUM(MONTHSAQTY) FROM yunji_gr_bi_sa_agg)/100000000 ,2), '亿') AS monthsaqty_s,
|
||||||
|
CONCAT(ROUND((SELECT SUM(THISSAQTY) FROM yunji_gr_bi_sa_agg)/100000000 ,2), '亿') AS thissaqty_s,
|
||||||
|
CONCAT(ROUND((SELECT SUM(LASTSAQTY) FROM yunji_gr_bi_sa_agg)/100000000 ,2), '亿') AS lastsaqty_s,
|
||||||
|
-- 原本带CAST的字段,简化写法(CONCAT会自动转为字符串)
|
||||||
|
CONCAT(ROUND((SELECT SUM(MONTHSAMONEY) FROM yunji_gr_bi_sa_agg)/100000000 ,2), '亿') AS monthsamoney_s,
|
||||||
|
CONCAT(ROUND((SELECT SUM(THISSAMONEY) FROM yunji_gr_bi_sa_agg)/100000000,2), '亿') AS thissamoney_s,
|
||||||
|
CONCAT(ROUND((SELECT SUM(LASTSAMONEY) FROM yunji_gr_bi_sa_agg)/100000000,2), '亿') AS lastsamoney_s,
|
||||||
|
CASE
|
||||||
|
WHEN (CASE WHEN tbl_lgbsa.yoy_month_sa_qty = 0 THEN IF(tbl_lgbsa.this_month_sa_qty > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_qty - tbl_lgbsa.yoy_month_sa_qty) / tbl_lgbsa.yoy_month_sa_qty * 100 END) > 0 THEN
|
||||||
|
CONCAT('🟢 ', ROUND((CASE WHEN tbl_lgbsa.yoy_month_sa_qty = 0 THEN IF(tbl_lgbsa.this_month_sa_qty > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_qty - tbl_lgbsa.yoy_month_sa_qty) / tbl_lgbsa.yoy_month_sa_qty * 100 END), 2))
|
||||||
|
WHEN (CASE WHEN tbl_lgbsa.yoy_month_sa_qty = 0 THEN IF(tbl_lgbsa.this_month_sa_qty > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_qty - tbl_lgbsa.yoy_month_sa_qty) / tbl_lgbsa.yoy_month_sa_qty * 100 END)<0 THEN
|
||||||
|
CONCAT('🔴 ', ROUND((CASE WHEN tbl_lgbsa.yoy_month_sa_qty = 0 THEN IF(tbl_lgbsa.this_month_sa_qty > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_qty - tbl_lgbsa.yoy_month_sa_qty) / tbl_lgbsa.yoy_month_sa_qty * 100 END), 2))
|
||||||
|
ELSE '0.00'
|
||||||
|
END AS monthsaqty_yoy,
|
||||||
|
|
||||||
|
-- 数量同比(原有)
|
||||||
|
CASE
|
||||||
|
WHEN (CASE WHEN tbl_lgbsa.yoy_month_sa_money = 0 THEN IF(tbl_lgbsa.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_money - tbl_lgbsa.yoy_month_sa_money) / tbl_lgbsa.yoy_month_sa_money * 100 END) > 0 THEN
|
||||||
|
CONCAT('🟢 ', ROUND((CASE WHEN tbl_lgbsa.yoy_month_sa_money = 0 THEN IF(tbl_lgbsa.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_money - tbl_lgbsa.yoy_month_sa_money) / tbl_lgbsa.yoy_month_sa_money * 100 END), 2))
|
||||||
|
WHEN (CASE WHEN tbl_lgbsa.yoy_month_sa_money = 0 THEN IF(tbl_lgbsa.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_money - tbl_lgbsa.yoy_month_sa_money) / tbl_lgbsa.yoy_month_sa_money * 100 END)<0 THEN
|
||||||
|
CONCAT('🔴 ', ROUND((CASE WHEN tbl_lgbsa.yoy_month_sa_money = 0 THEN IF(tbl_lgbsa.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_money - tbl_lgbsa.yoy_month_sa_money) / tbl_lgbsa.yoy_month_sa_money * 100 END), 2))
|
||||||
|
ELSE '0.00'
|
||||||
|
END AS monthsamoney_yoy,
|
||||||
|
CASE WHEN (CASE WHEN tbl_lgbsa.yoy_month_profit = 0 THEN IF(tbl_lgbsa.yoy_month_profit > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.yoy_month_profit - tbl_lgbsa.yoy_month_profit) / tbl_lgbsa.yoy_month_profit * 100 END) > 0 THEN
|
||||||
|
CONCAT('🟢 ', ROUND((CASE WHEN tbl_lgbsa.yoy_month_profit = 0 THEN IF(tbl_lgbsa.yoy_month_profit > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.yoy_month_profit - tbl_lgbsa.yoy_month_profit) / tbl_lgbsa.yoy_month_profit * 100 END), 2))
|
||||||
|
WHEN (CASE WHEN tbl_lgbsa.yoy_month_profit = 0 THEN IF(tbl_lgbsa.yoy_month_profit > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.yoy_month_profit - tbl_lgbsa.yoy_month_profit) / tbl_lgbsa.yoy_month_profit * 100 END)<0 THEN
|
||||||
|
CONCAT('🔴 ', ROUND((CASE WHEN tbl_lgbsa.yoy_month_profit = 0 THEN IF(tbl_lgbsa.yoy_month_profit > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.yoy_month_profit - tbl_lgbsa.yoy_month_profit) / tbl_lgbsa.yoy_month_profit * 100 END), 2))
|
||||||
|
ELSE '0.00'
|
||||||
|
END AS monthprofit_yoy,
|
||||||
|
CASE
|
||||||
|
WHEN (CASE WHEN tbl_lgbsa.last_month_sa_money = 0 THEN IF(tbl_lgbsa.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_money - tbl_lgbsa.last_month_sa_money) / tbl_lgbsa.last_month_sa_money * 100 END) > 0 THEN
|
||||||
|
CONCAT('🟢 ', ROUND((CASE WHEN tbl_lgbsa.last_month_sa_money = 0 THEN IF(tbl_lgbsa.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_money - tbl_lgbsa.last_month_sa_money) / tbl_lgbsa.last_month_sa_money * 100 END), 2))
|
||||||
|
WHEN (CASE WHEN tbl_lgbsa.last_month_sa_money = 0 THEN IF(tbl_lgbsa.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_money - tbl_lgbsa.last_month_sa_money) / tbl_lgbsa.last_month_sa_money * 100 END)<0 THEN
|
||||||
|
CONCAT('🔴 ', ROUND((CASE WHEN tbl_lgbsa.last_month_sa_money = 0 THEN IF(tbl_lgbsa.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (tbl_lgbsa.this_month_sa_money - tbl_lgbsa.last_month_sa_money) / tbl_lgbsa.last_month_sa_money * 100 END), 2))
|
||||||
|
ELSE '0.00'
|
||||||
|
END AS lastMonthSaMoney_yoy, -- 本月销售金额增长率
|
||||||
|
ROUND(tbl_lgbsa.this_month_profit_rate * 100, 2) AS this_month_sa_money_share,
|
||||||
|
ROUND(tbl_lgbsa.this_month_sa_money_share * 100, 2) AS this_month_profit_share
|
||||||
|
FROM
|
||||||
|
new_gr_bi_sa_agg tbl_lgbsa
|
||||||
<where>
|
<where>
|
||||||
<if test="useYear != null and useYear != ''"> and use_year = #{useYear}</if>
|
<if test="useYear != null and useYear != ''"> and use_year = #{useYear}</if>
|
||||||
<if test="useMonth != null "> and use_month = #{useMonth}</if>
|
<if test="useMonth != null "> and use_month = #{useMonth}</if>
|
||||||
<if test="zoneId != null "> and zone_id = #{zoneId}</if>
|
<!--<if test="zoneId != null "> and zone_id = #{zoneId}</if>-->
|
||||||
<if test="zoneName != null and zoneName != ''"> and zone_name like concat('%', #{zoneName}, '%')</if>
|
<if test="zoneName != null and zoneName != ''"> and zone_name in
|
||||||
<if test="saleTypeId != null "> and sale_type_id = #{saleTypeId}</if>
|
<foreach collection="zoneName" item="name" open="(" separator="," close=")">
|
||||||
<if test="saleTypeName != null and saleTypeName != ''"> and sale_type_name like concat('%', #{saleTypeName}, '%')</if>
|
#{name}
|
||||||
<if test="customId != null "> and custom_id = #{customId}</if>
|
</foreach>
|
||||||
<if test="customName != null and customName != ''"> and custom_name like concat('%', #{customName}, '%')</if>
|
</if>
|
||||||
<if test="dosageId != null "> and dosage_id = #{dosageId}</if>
|
<!-- <if test="saleTypeId != null "> and sale_type_id = #{saleTypeId}</if>-->
|
||||||
<if test="dosageName != null and dosageName != ''"> and dosage_name like concat('%', #{dosageName}, '%')</if>
|
<if test="saleTypeName != null and saleTypeName != ''"> and sale_type_name in
|
||||||
<if test="goodsId != null "> and goods_id = #{goodsId}</if>
|
<foreach collection="saleTypeName" item="name" open="(" separator="," close=")">
|
||||||
<if test="goodsName != null and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
|
#{name}
|
||||||
<if test="provinceId != null "> and province_id = #{provinceId}</if>
|
</foreach>
|
||||||
<if test="provinceName != null and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
|
</if>
|
||||||
<if test="salerId != null "> and saler_id = #{salerId}</if>
|
<!--<if test="customId != null "> and custom_id = #{customId}</if>-->
|
||||||
<if test="salerName != null and salerName != ''"> and saler_name like concat('%', #{salerName}, '%')</if>
|
<if test="customName != null and customName != ''"> and custom_name in
|
||||||
<if test="thisMonthSaQty != null "> and this_month_sa_qty = #{thisMonthSaQty}</if>
|
<foreach collection="customName" item="name" open="(" separator="," close=")">
|
||||||
<if test="thisMonthSaMoney != null "> and this_month_sa_money = #{thisMonthSaMoney}</if>
|
#{name}
|
||||||
<if test="thisMonthCost != null "> and this_month_cost = #{thisMonthCost}</if>
|
</foreach>
|
||||||
<if test="thisMonthProfit != null "> and this_month_profit = #{thisMonthProfit}</if>
|
</if>
|
||||||
|
<!--<if test="dosageId != null "> and dosage_id = #{dosageId}</if>-->
|
||||||
|
<if test="dosageName != null and dosageName != ''"> and dosage_name in
|
||||||
|
<foreach collection="dosageName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<!--<if test="goodsId != null "> and goods_id = #{goodsId}</if>-->
|
||||||
|
<if test="goodsName != null and goodsName != ''"> and goods_name in
|
||||||
|
<foreach collection="goodsName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<!--<if test="provinceId != null "> and province_id = #{provinceId}</if>-->
|
||||||
|
<if test="provinceName != null and provinceName != ''"> and province_name in
|
||||||
|
<foreach collection="provinceName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<!--<if test="salerId != null "> and saler_id = #{salerId}</if>-->
|
||||||
|
<if test="salerName != null and salerName != ''"> and saler_name in
|
||||||
|
<foreach collection="salerName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="stdGoodsName != null and stdGoodsName != ''"> and std_goods_name in
|
||||||
|
<foreach collection="stdGoodsName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectNewGrBiSaAggGroupMonthList" resultMap="NewGrBiSaAggResult">
|
||||||
|
select
|
||||||
|
<if test="groupFieldList.contains('useyear') || params.containsKey('usemonth')">
|
||||||
|
current_month.use_month as usemonth,
|
||||||
|
<choose>
|
||||||
|
<when test="groupFieldList.contains('useyear') || params.containsKey('useyear')">
|
||||||
|
current_month.use_year as useyear,
|
||||||
|
current_month.use_year as ny, #年月
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
LPAD(current_month.use_month, 2, '0') as ny,
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('customname') || params.containsKey('customname')">
|
||||||
|
current_month.custom_id as customid,
|
||||||
|
current_month.custom_name as customname, #客户名称
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('zonename') || params.containsKey('zonename')">
|
||||||
|
current_month.zone_id,
|
||||||
|
current_month.zone_name as zonename,
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('saletypename') || params.containsKey('saletypename')">
|
||||||
|
current_month.sale_type_id,
|
||||||
|
current_month.sale_type_name as saletypename,
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('salername') || params.containsKey('salername')">
|
||||||
|
current_month.saler_id,
|
||||||
|
current_month.saler_name as salername, #业务员
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('dosagename') || params.containsKey('dosagename')">
|
||||||
|
current_month.dosage_id,
|
||||||
|
current_month.dosage_name as dosagename, #剂型
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('stdGoodsName') || params.containsKey('stdGoodsName')">
|
||||||
|
current_month.std_goods_name as stdGoodsName,
|
||||||
|
</if>
|
||||||
|
current_month.this_month_sa_qty AS thisMonthSaQty, #本月销售数量(件)
|
||||||
|
ROUND(current_month.this_month_sa_money / 10000, 2) AS thisMonthSaMoney, #本月销售金额(元)
|
||||||
|
ROUND(current_month.this_month_profit / 10000, 2) AS thisMonthProfit, #本月毛利额(元)
|
||||||
|
ROUND(current_month.this_month_cost / 10000, 2) AS thisMonthCost, #本月成本(元)
|
||||||
|
last_month_data.last_month_sa_qty AS lastMonthSaQty, #上月销售数量(件)
|
||||||
|
ROUND(last_month_data.last_month_sa_money / 10000, 2) AS lastMonthSaMoney, #上月销售金额(元)
|
||||||
|
ROUND(last_month_data.last_month_profit / 10000, 2) AS lastMonthProfit, #上月毛利额(元)
|
||||||
|
ROUND(last_month_data.last_month_cost / 10000, 2) AS lastMonthCost, #上月成本(元)
|
||||||
|
ROUND(yoy_month.yoy_month_sa_qty / 10000, 2) AS yoyMonthSaQty, #同比月销售数量(件)
|
||||||
|
ROUND(yoy_month.yoy_month_sa_money / 10000, 2) AS yoyMonthSaMoney, #同比月销售金额(元)
|
||||||
|
ROUND(yoy_month.yoy_month_profit / 10000, 2) AS yoyMonthProfit, #同比月毛利额(元)
|
||||||
|
ROUND(yoy_month.yoy_month_cost / 10000, 2) AS yoyMonthCost, #同比月成本(元)
|
||||||
|
current_month.province_id AS province_id, #行政区域ID
|
||||||
|
current_month.province_name AS province_name, #行政区域名称
|
||||||
|
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, #本月销量同比
|
||||||
|
|
||||||
|
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 last_month_data.last_month_sa_money = 0 THEN IF(current_month.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (current_month.this_month_sa_money - last_month_data.last_month_sa_money) / last_month_data.last_month_sa_money * 100 END) > 0 THEN
|
||||||
|
CONCAT('🟢 ', ROUND((CASE WHEN last_month_data.last_month_sa_money = 0 THEN IF(current_month.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (current_month.this_month_sa_money - last_month_data.last_month_sa_money) / last_month_data.last_month_sa_money * 100 END), 2))
|
||||||
|
WHEN (CASE WHEN last_month_data.last_month_sa_money = 0 THEN IF(current_month.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (current_month.this_month_sa_money - last_month_data.last_month_sa_money) / last_month_data.last_month_sa_money * 100 END)<0 THEN
|
||||||
|
CONCAT('🔴 ', ROUND((CASE WHEN last_month_data.last_month_sa_money = 0 THEN IF(current_month.this_month_sa_money > 0, 100, 0)
|
||||||
|
ELSE (current_month.this_month_sa_money - last_month_data.last_month_sa_money) / last_month_data.last_month_sa_money * 100 END), 2))
|
||||||
|
ELSE '0.00'
|
||||||
|
END AS lastMonthSaMoney_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, #本月毛利同比
|
||||||
|
|
||||||
|
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('useyear') || params.containsKey('useyear')">
|
||||||
|
use_year,
|
||||||
|
</if>
|
||||||
|
use_month,
|
||||||
|
<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,
|
||||||
|
saler_name,
|
||||||
|
</if>
|
||||||
|
CONCAT(MAX(use_year), LPAD(MAX(use_month), 2, '0')) AS ny,
|
||||||
|
GROUP_CONCAT(DISTINCT province_id ORDER BY province_id SEPARATOR ',') AS province_id,
|
||||||
|
GROUP_CONCAT(DISTINCT province_name ORDER BY province_name SEPARATOR ',') AS province_name,
|
||||||
|
sum(this_month_sa_qty) AS this_month_sa_qty,
|
||||||
|
sum(this_month_sa_money) AS this_month_sa_money,
|
||||||
|
sum(this_month_cost) AS this_month_cost,
|
||||||
|
sum(this_month_profit) AS this_month_profit
|
||||||
|
FROM
|
||||||
|
new_gr_bi_sa_agg_month_count
|
||||||
|
<where>
|
||||||
|
<if test="saAggParam.useYear != null and saAggParam.useYear != ''"> and use_year = #{saAggParam.useYear}</if>
|
||||||
|
<if test="saAggParam.useMonth != null "> and use_month = #{saAggParam.useMonth}</if>
|
||||||
|
<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('useyear') || params.containsKey('useyear')">
|
||||||
|
use_year,
|
||||||
|
</if>
|
||||||
|
use_month,
|
||||||
|
<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,
|
||||||
|
saler_name,
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
) AS current_month # current_month 本月数据
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
<if test="groupFieldList.contains('useyear') || params.containsKey('useyear')">
|
||||||
|
use_year,
|
||||||
|
</if>
|
||||||
|
use_month,
|
||||||
|
<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>
|
||||||
|
SUM(this_month_sa_qty) AS last_month_sa_qty,
|
||||||
|
SUM(this_month_sa_money) AS last_month_sa_money,
|
||||||
|
SUM(this_month_cost) AS last_month_cost,
|
||||||
|
SUM(this_month_profit) AS last_month_profit
|
||||||
|
FROM new_gr_bi_sa_agg_month_count
|
||||||
|
GROUP BY
|
||||||
|
<trim suffixOverrides=",">
|
||||||
|
<if test="groupFieldList.contains('useyear') || params.containsKey('useyear')">
|
||||||
|
use_year,
|
||||||
|
</if>
|
||||||
|
use_month,
|
||||||
|
<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>
|
||||||
|
) AS last_month_data # last_month_data 上月数据
|
||||||
|
ON last_month_data.use_month = IF(current_month.use_month = 1, 12, current_month.use_month - 1)
|
||||||
|
<if test="groupFieldList.contains('useyear') || params.containsKey('useyear')">
|
||||||
|
AND last_month_data.use_year = current_month.use_year - (current_month.use_month = 1)
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('customname') || params.containsKey('customname')"># 客户名称
|
||||||
|
AND current_month.custom_id = last_month_data.custom_id
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('stdGoodsName') || params.containsKey('stdGoodsName')"># 标准品名
|
||||||
|
AND current_month.std_goods_name = last_month_data.std_goods_name
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('zonename') || params.containsKey('zonename')">#业务区域
|
||||||
|
AND current_month.zone_id = last_month_data.zone_id
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('saletypename') || params.containsKey('saletypename')">#销售类型
|
||||||
|
AND current_month.sale_type_id = last_month_data.sale_type_id
|
||||||
|
</if>
|
||||||
|
<if test="groupFieldList.contains('dosagename') || params.containsKey('dosagename')">#剂型
|
||||||
|
AND current_month.dosage_id = last_month_data.dosage_id
|
||||||
|
</if>
|
||||||
|
# if (groupFieldList.contains('salername') || params.containsKey('salername')) {
|
||||||
|
<if test="groupFieldList.contains('salername') || params.containsKey('salername')">#业务员
|
||||||
|
AND current_month.saler_id = last_month_data.saler_id
|
||||||
|
</if>
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
<if test="groupFieldList.contains('useyear') || params.containsKey('useyear')">
|
||||||
|
use_year,
|
||||||
|
</if>
|
||||||
|
use_month,
|
||||||
|
<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>
|
||||||
|
SUM(this_month_sa_qty) AS yoy_month_sa_qty, # 同比月销量
|
||||||
|
SUM(this_month_sa_money) AS yoy_month_sa_money, # 同比月销售金额
|
||||||
|
SUM(this_month_cost) as yoy_month_cost, # 同比月销售成本
|
||||||
|
SUM(this_month_profit) AS yoy_month_profit # 同比月毛利额
|
||||||
|
FROM new_gr_bi_sa_agg_month_count
|
||||||
|
<where>
|
||||||
|
<if test="saAggParam.useYear != null and saAggParam.useYear != ''"> and use_year = #{saAggParam.useYear}</if>
|
||||||
|
<if test="saAggParam.useMonth != null "> and use_month = #{saAggParam.useMonth}</if>
|
||||||
|
<if test="saAggParam.zoneName != null and 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('useyear') || params.containsKey('useyear')">
|
||||||
|
use_year,
|
||||||
|
</if>
|
||||||
|
use_month,
|
||||||
|
<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('useyear') || params.containsKey('useyear')">
|
||||||
|
and yoy_month.use_year = current_month.use_year - 1 # 同比月数据
|
||||||
|
</if>
|
||||||
|
and yoy_month.use_month = current_month.use_month
|
||||||
|
<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>
|
||||||
|
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
use_year,
|
||||||
|
SUM( this_month_sa_money ) AS this_month_sa_money_sum,
|
||||||
|
SUM(this_month_profit) AS this_month_profit_sum
|
||||||
|
FROM new_gr_bi_sa_agg
|
||||||
|
GROUP BY
|
||||||
|
use_year
|
||||||
|
) total_month_data ON total_month_data.use_year = current_month.use_year
|
||||||
|
<where>
|
||||||
|
<if test="saAggParam.useYear != null and saAggParam.useYear != ''"> and current_month.use_year = #{saAggParam.useYear}</if>
|
||||||
|
<if test="saAggParam.useMonth != null "> and current_month.use_month = #{saAggParam.useMonth}</if>
|
||||||
|
<if test="saAggParam.zoneName != null and saAggParam.zoneName != ''"> and current_month.zone_name in
|
||||||
|
<foreach collection="saAggParam.zoneName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="saAggParam.saleTypeName != null and saAggParam.saleTypeName != ''"> and current_month.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 current_month.custom_name in
|
||||||
|
<foreach collection="saAggParam.customName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="saAggParam.dosageName != null and saAggParam.dosageName != ''"> and current_month.dosage_name in
|
||||||
|
<foreach collection="saAggParam.dosageName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="saAggParam.goodsName != null and saAggParam.goodsName != ''"> and current_month.goods_name in
|
||||||
|
<foreach collection="saAggParam.goodsName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="saAggParam.provinceName != null and saAggParam.provinceName != ''"> and current_month.province_name in
|
||||||
|
<foreach collection="saAggParam.provinceName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="saAggParam.salerName != null and saAggParam.salerName != ''"> and current_month.saler_name in
|
||||||
|
<foreach collection="saAggParam.salerName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="saAggParam.stdGoodsName != null and saAggParam.stdGoodsName != ''"> and current_month.std_goods_name in
|
||||||
|
<foreach collection="saAggParam.stdGoodsName" item="name" open="(" separator="," close=")">
|
||||||
|
#{name}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user