1、销售BI汇总sql
This commit is contained in:
parent
4cefda4987
commit
f85d62d394
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -81,7 +81,7 @@ public class PurchaseDataSummaryServiceImpl implements DataSummaryService {
|
||||
String startDate = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-mm-dd"));
|
||||
// 1. 计算并保存各板块物料采购总额、总量、单价(按月存储)
|
||||
// monthlyMaterialSummaryBySegment(year, month, yearMonth, yearLastMonth, lastYearMonth, bkgs, distinctList);
|
||||
newmonthlyMaterialSummaryBySegment(startDate, bkgs, distinctList);
|
||||
// newmonthlyMaterialSummaryBySegment(startDate, bkgs, distinctList);
|
||||
|
||||
// 2. 根据年月汇总板块、基地、年月、当期、上期、同期数据
|
||||
// monthlyBaseSummaryBySegment(year, month, yearMonth, yearLastMonth, lastYearMonth, bkgs, distinctList);
|
||||
@ -98,7 +98,7 @@ public class PurchaseDataSummaryServiceImpl implements DataSummaryService {
|
||||
dateRange.getStartDate(), dateRange.getEndDate());
|
||||
String startDate = DATE_FORMAT.format(dateRange.getStartDate());
|
||||
//计算并保存各板块物料采购总额、总量、单价(按月存储)
|
||||
newmonthlyMaterialSummaryBySegment(startDate, bkgs, distinctList);
|
||||
// newmonthlyMaterialSummaryBySegment(startDate, bkgs, distinctList);
|
||||
// 计算月度维度数据(按月遍历)
|
||||
calculateMonthlyData(dateRange, bkgs, distinctList);
|
||||
|
||||
@ -287,7 +287,7 @@ public class PurchaseDataSummaryServiceImpl implements DataSummaryService {
|
||||
Date currentDate = new Date(System.currentTimeMillis());
|
||||
|
||||
// 1. 计算并保存各板块物料采购总额、总量、单价(按月存储)
|
||||
// monthlyMaterialSummaryBySegment(year, month, yearMonth, yearLastMonth, lastYearMonth, bkgs, distinctList);
|
||||
monthlyMaterialSummaryBySegment(year, month, yearMonth, yearLastMonth, lastYearMonth, bkgs, distinctList);
|
||||
|
||||
// 2. 根据年月汇总板块、基地、年月、当期、上期、同期数据
|
||||
monthlyBaseSummaryBySegment(year, month, yearMonth, yearLastMonth, lastYearMonth, bkgs, distinctList);
|
||||
|
||||
@ -17,6 +17,8 @@ import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -134,8 +136,10 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
throw e;
|
||||
}
|
||||
|
||||
String sql = "SELECT t.RQ,t.QYGS,t.XSZZ,t.SHENGQU,t.SHIQU,t.QX,t.QCYE,t.LJXS,t.LJHK,t.YSYE," +
|
||||
" t.ZLFX0_60,t.ZLFX60_1,t.ZLFX1_2,t.ZLFX2_3,t.ZLFX3_4,t.ZLFX4_5,t.ZLFX5" +
|
||||
String sql = "SELECT t.RQ AS RQ,t.QYGS AS QYGS,t.XSZZ AS XSZZ,t.SHENGQU AS SHENGQU,t.SHIQU AS SHIQU," +
|
||||
" t.QX AS QX,t.QCYE AS QCYE,t.LJXS AS LJXS,t.LJHK AS LJHK,t.YSYE AS YSYE," +
|
||||
" t.ZLFX0_60 AS ZLFX0_60,t.ZLFX60_1 AS ZLFX60_1,t.ZLFX1_2 AS ZLFX1_2,t.ZLFX2_3 AS ZLFX2_3," +
|
||||
" t.ZLFX3_4 AS ZLFX3_4,t.ZLFX4_5 AS ZLFX4_5,t.ZLFX5 AS ZLFX5" +
|
||||
" FROM BO_EU_BNBM_DATALINKUP_XS_YSL t" +
|
||||
" INNER JOIN (" +
|
||||
" SELECT QYGS,SHIQU,MAX(RQ) AS MaxRQ,YEAR(RQ) AS Year,MONTH(RQ) AS Month" +
|
||||
@ -171,10 +175,11 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
for (RowMap map : maps) {
|
||||
String xszz = map.getString("XSZZ");
|
||||
String rq = map.getString("RQ");
|
||||
String qygs = map.getString("QYGS");
|
||||
BO bo = new BO();
|
||||
bo.set("YEARMONTH", rq.substring(0, 7));
|
||||
bo.set("BKGS", bkgs);
|
||||
bo.set("QYGS", map.getString("QYGS"));
|
||||
bo.set("QYGS", qygs);
|
||||
bo.set("GC", xszz);
|
||||
bo.set("SQ", map.getString("SHENGQU"));
|
||||
bo.set("CITY", map.getString("SHIQU"));
|
||||
@ -195,6 +200,15 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
bo.set("ZL3_4", map.getDouble("ZLFX3_4"));
|
||||
bo.set("ZL4_5", map.getDouble("ZLFX4_5"));
|
||||
bo.set("ZL5", map.getDouble("ZLFX5"));
|
||||
|
||||
// LocalDate parse = LocalDate.parse(rq,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss .S"));
|
||||
// YearMonth yearMonth = YearMonth.of(parse.getYear(), parse.getMonthValue());
|
||||
// LocalDate lastYear = yearMonth.atEndOfMonth();
|
||||
// RowMap map1 = DBSql.getMap("SELECT YSYE FROM BO_EU_BNBM_DATALINKUP_XS_YSL WHERE RQ = '" + lastYear.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "'" +
|
||||
// " WHERE QYGS = '" + qygs + "' AND BKGS = '" + bkgs + "' AND XSZZ = '" + xszz + "'");
|
||||
// if (map1!=null) {
|
||||
// bo.set("QNTQYSZE", map.getDouble("QNTQYSZE"));
|
||||
// }
|
||||
bos.add(bo);
|
||||
}
|
||||
|
||||
@ -235,8 +249,8 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
|
||||
try {
|
||||
// 第一个SQL:查询应收账款数据
|
||||
String receivableSql = "SELECT t1.XSZZ AS XSZZ, t1.QYGS AS QYGS, t1.BKGS AS BKGS," +
|
||||
" DATE_FORMAT( t1.RQ, '%Y-%m' ) ASyear_month, t1.RQ AS max_rq, SUM( t1.YSYE ) AS YSZK," +
|
||||
String receivableSql = "SELECT t1.RQ AS RQ, t1.XSZZ AS XSZZ, t1.QYGS AS QYGS, t1.BKGS AS BKGS," +
|
||||
" DATE_FORMAT( t1.RQ, '%Y-%m' ) ASyear_month, t1.RQ AS max_rq, (SUM( t1.YSYE )/1000) AS YSZK," +
|
||||
" SUM(t1.LJHK) AS LJHK,SUM(t1.LJXS) AS LJXS," +
|
||||
" CASE " +
|
||||
" WHEN SUM(t1.LJXS) != 0 THEN SUM(t1.LJHK) / SUM(t1.LJXS)" +
|
||||
@ -252,7 +266,6 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
" WHERE t1.RQ >= ? AND t1.RQ < ? AND t1.BKGS = ?" +
|
||||
" GROUP BY t1.QYGS,t1.BKGS,DATE_FORMAT ( t1.RQ, '%Y-%m' ),t1.RQ";
|
||||
|
||||
|
||||
String startDate = DATE_FORMAT.format(dateRange.getStartDate());
|
||||
String endDate = DATE_FORMAT.format(dateRange.getEndDate());
|
||||
|
||||
@ -292,7 +305,7 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
String inClause = xszzList.stream()
|
||||
.map(s -> "'" + s.replace("'", "''") + "'") // 转义单引号防止SQL注入
|
||||
.collect(Collectors.joining(","));
|
||||
String inventorySql = "SELECT STOCKORGNAME, SUM(BALANCE_AMOUNT) as KCJE " +
|
||||
String inventorySql = "SELECT STOCKORGNAME, (SUM(BALANCE_AMOUNT)/10000) as KCJE " +
|
||||
" FROM " + BO_EU_DWD_ORDER_KC_HZ + " " +
|
||||
" WHERE STOCKORGNAME IN (" + inClause + ") " +
|
||||
" AND CATEGORY = '产成品' " +
|
||||
@ -313,9 +326,11 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
}
|
||||
|
||||
BO bo = new BO();
|
||||
String qygs = receivable.getString("QYGS");
|
||||
String rq = receivable.getString("RQ");
|
||||
bo.set("YEARMONTH", year_month);
|
||||
bo.set("BKGS", bkgs);
|
||||
bo.set("QYGS", receivable.getString("QYGS"));
|
||||
bo.set("QYGS", qygs);
|
||||
bo.set("YSZK", yszk);
|
||||
bo.set("CCJE", kcje);
|
||||
bo.set("LJHK", receivable.getString("LJHK"));
|
||||
@ -323,6 +338,14 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
bo.set("HKL", receivable.getString("HKL"));
|
||||
//增加额度使用率情况
|
||||
bo.set("EDSYL", SaleUtil.calculateResult(sxedList,bkgs,receivable.getString("QYGS"),yszk));
|
||||
// LocalDate parse = LocalDate.parse(rq,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"));
|
||||
// YearMonth yearMonth = YearMonth.of(parse.getYear(), parse.getMonthValue());
|
||||
// LocalDate lastYear = yearMonth.atEndOfMonth();
|
||||
// RowMap map = DBSql.getMap("SELECT (SUM( t1.YSYE )/1000) AS YSZK FROM BO_EU_BNBM_DATALINKUP_XS_YSL" +
|
||||
// " WHERE QYGS = '" + qygs + "' AND BKGS = '" + bkgs + "' AND RQ = '" + lastYear.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "'");
|
||||
// if (map!=null) {
|
||||
// bo.set("QYTQYSZK", map.getString("YSZK"));
|
||||
// }
|
||||
bos.add(bo);
|
||||
}
|
||||
|
||||
@ -374,7 +397,7 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
|
||||
String querySql = "SELECT QYGS, KCZZ, LB_1, LB_2, LB_3, SQ, CS, QY, SUM(ZSSL) AS XL," +
|
||||
String querySql = "SELECT DZRQ,QYGS, KCZZ, LB_1, LB_2, LB_3, SQ, CS, QY, SUM(ZSSL) AS XL," +
|
||||
" SUM(SSJERMB) AS XE, SUM(XSSL) AS TSXL, NMNY ,YEARMONTH" +
|
||||
" FROM " + SALES_DETAIL_TABLE +
|
||||
" WHERE DZRQ >= ? AND DZRQ < ? AND BKGS = ?" +
|
||||
@ -391,14 +414,17 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
// 循环外先获取下公装家装、基材面材类别
|
||||
List<BO> gzjzList = SDK.getBOAPI().query("BO_EU_DATALINKUP_CPJZGZJCMC").orderBy("CPLB_L2").desc().list();
|
||||
for (RowMap map : maps) {
|
||||
String dzrq = map.getString("DZRQ");
|
||||
String gc = map.getString("KCZZ");
|
||||
String yearmonth = map.getString("YEARMONTH");
|
||||
String qygs = map.getString("QYGS");
|
||||
String lb_1 = map.getString("LB_1");
|
||||
BO bo = new BO();
|
||||
bo.set("YEARMONTH", yearmonth.substring(0, 4) + "-" + yearmonth.substring(4));
|
||||
bo.set("BKGS", bkgs);
|
||||
bo.set("QYGS", map.getString("QYGS"));
|
||||
bo.set("QYGS", qygs);
|
||||
bo.set("GC", gc);
|
||||
bo.set("LB_1", map.getString("LB_1"));
|
||||
bo.set("LB_1",lb_1 );
|
||||
bo.set("LB_2", map.getString("LB_2"));
|
||||
bo.set("LB_3", map.getString("LB_3"));
|
||||
bo.set("SQ", map.getString("SQ"));
|
||||
@ -409,14 +435,28 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
bo.set("JD", location.getLongitude());
|
||||
bo.set("WD", location.getLatitude());
|
||||
}
|
||||
String querySql2 = "SELECT SUM(ZSSL) AS XL,SUM(SSJERMB) AS XE, SUM(XSSL) AS TSXL" +
|
||||
" FROM " + SALES_DETAIL_TABLE +
|
||||
" WHERE DZRQ = ? AND BKGS = ? AND QYGS = ? AND KCZZ = ? AND LB_1 = ?";
|
||||
// LocalDate parse = LocalDate.parse(dzrq,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"));
|
||||
// YearMonth yearMonth = YearMonth.of(parse.getYear(), parse.getMonthValue());
|
||||
// LocalDate lastYear = yearMonth.atEndOfMonth();
|
||||
// RowMap map1 = DBSql.getMap(querySql2, lastYear.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), bkgs, qygs, gc, lb_1);
|
||||
if ("石膏板".equals(map.getString("LB_1"))){
|
||||
bo.set("XL", map.getDouble("TSXL"));
|
||||
// if (map1!=null) {
|
||||
// bo.set("SNTQXL", map1.getString("TSXL"));
|
||||
// }
|
||||
}else {
|
||||
bo.set("XL", map.getDouble("XL"));
|
||||
// if (map1!=null) {
|
||||
// bo.set("SNTQXL", map1.getString("XL"));
|
||||
// }
|
||||
}
|
||||
Double ssjermb = map.getDouble("SSJERMB");
|
||||
Double xe = map.getDouble("XE");
|
||||
bo.set("XE", ssjermb!=null?ssjermb:xe!=null?(xe*0.13):0.00);
|
||||
// bo.set("SNTQXE", map1.getString("XE"));
|
||||
// 匹配公装家装类别,如果未匹配到,则默认未其他
|
||||
String[] gzjzStrings = SaleUtil.matchSingleField(bkgs, map.getString("LB_1"), map.getString("LB_2"), gzjzList, "其他", "其他","其他");
|
||||
bo.set("JZ_GZ", gzjzStrings[0]);
|
||||
@ -471,7 +511,7 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
|
||||
String querySql = "SELECT QYGS, KCZZ, LB_1, LB_2, LB_3, SQ, CS, QY, SUM(NMNY) as BHSYYSR, SUM(SSJERMB) AS YYSR, YEARMONTH" +
|
||||
String querySql = "SELECT DZRQ, QYGS, KCZZ, LB_1, LB_2, LB_3, SQ, CS, QY, SUM(NMNY) as BHSYYSR, SUM(SSJERMB) AS YYSR, YEARMONTH" +
|
||||
" FROM " + SALES_DETAIL_TABLE +
|
||||
" WHERE DZRQ >= ? AND DZRQ < ? AND BKGS = ?" +
|
||||
" GROUP BY QYGS, KCZZ, LB_1, LB_2, LB_3, SQ, CS, QY, YEARMONTH";
|
||||
@ -487,6 +527,9 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
for (RowMap map : maps) {
|
||||
String gc = map.getString("KCZZ");
|
||||
String yearmonth = map.getString("YEARMONTH");
|
||||
String dzrq = map.getString("DZRQ");
|
||||
String qygs = map.getString("QYGS");
|
||||
String sq = map.getString("SQ");
|
||||
BO bo = new BO();
|
||||
bo.set("YEARMONTH", yearmonth.substring(0, 4) + "-" + yearmonth.substring(4));
|
||||
bo.set("BKGS", bkgs);
|
||||
@ -495,7 +538,7 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
bo.set("LB_1", map.getString("LB_1"));
|
||||
bo.set("LB_2", map.getString("LB_2"));
|
||||
bo.set("LB_3", map.getString("LB_3"));
|
||||
bo.set("SQ", map.getString("SQ"));
|
||||
bo.set("SQ", sq);
|
||||
bo.set("CITY", map.getString("CS"));
|
||||
bo.set("QX", map.getString("QY"));
|
||||
if (resultMap.containsKey(gc)) {
|
||||
@ -505,6 +548,17 @@ public class SaleCountDimensionImpl implements DataSummaryService {
|
||||
}
|
||||
bo.set("YYSR", map.getDouble("YYSR"));
|
||||
bo.set("BHSYYSR", map.getDouble("BHSYYSR"));
|
||||
String querySql2 = "SELECT SUM(NMNY) as BHSYYSR, SUM(SSJERMB) AS YYSR" +
|
||||
" FROM " + SALES_DETAIL_TABLE +
|
||||
" WHERE DZRQ = ? AND BKGS = ? AND QYGS = ? AND KCZZ = ? AND SQ = ?";
|
||||
// LocalDate parse = LocalDate.parse(dzrq,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S")).minusYears(1);
|
||||
// YearMonth yearMonth = YearMonth.of(parse.getYear(), parse.getMonthValue());
|
||||
// LocalDate lastYear = yearMonth.atEndOfMonth();
|
||||
// RowMap map1 = DBSql.getMap(querySql2, lastYear.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), bkgs, qygs, gc, sq);
|
||||
// if (map1!=null) {
|
||||
// bo.set("QNTQYYSR", map1.getDouble("YYSR"));
|
||||
// bo.set("QNTQBHSYYSR", map1.getDouble("BHSYYSR"));
|
||||
// }
|
||||
bos.add(bo);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user