Browse Source

优化

master
dimengzhe 1 year ago
parent
commit
9fe50de2de
  1. 12
      anrui-reportcenter/anrui-reportcenter-biz/src/main/java/com/yxt/anrui/reportcenter/biz/dailyreport/DailyReportMapper.xml
  2. 86
      anrui-reportcenter/anrui-reportcenter-biz/src/main/java/com/yxt/anrui/reportcenter/biz/dailyreport/DailyReportService.java

12
anrui-reportcenter/anrui-reportcenter-biz/src/main/java/com/yxt/anrui/reportcenter/biz/dailyreport/DailyReportMapper.xml

@ -132,7 +132,7 @@
</select>
<select id="selectReport" resultType="com.yxt.anrui.reportcenter.api.dailyreport.DailyReportVo">
select ifnull(sum(dr.saleOfStockRatio), 0) as saleOfStockRatio,
select ifnull(sum(SUBSTRING_INDEX(dr.saleOfStockRatio, ':', 1)/SUBSTRING_INDEX(dr.saleOfStockRatio, ':', -1)), 0) as saleOfStockRatio,
ifnull(sum(dr.stock_total), 0) as stock_total,
ifnull(sum(dr.stock_unreserve), 0) as stock_unreserve,
ifnull(sum(dr.stock_reserve), 0) as stock_reserve,
@ -198,7 +198,7 @@
<select id="pageList1" resultType="com.yxt.anrui.reportcenter.api.dailyreport.DailyReportListVo">
select DATE_FORMAT(createTime, '%Y-%m-%d') as date,
sum(saleOfStockRatio) as saleOfStockRatio,
sum(SUBSTRING_INDEX(saleOfStockRatio, ':', 1)/SUBSTRING_INDEX(saleOfStockRatio, ':', -1)) as saleOfStockRatio,
sum(stock_subtotal) as stock_subtotal,
sum(pcOrder_subtotal) as pcOrder_subtotal,
sum(saleOrder_subtotal_day) as saleOrder_subtotal_day,
@ -217,7 +217,7 @@
<select id="getReport" resultType="com.yxt.anrui.reportcenter.api.dailyreport.ReportVo">
select DATE_FORMAT(createTime, '%Y-%m-%d') as date,
ifnull(sum(saleOfStockRatio), 0) as saleOfStockRatio,
ifnull(sum(SUBSTRING_INDEX(saleOfStockRatio, ':', 1)/SUBSTRING_INDEX(saleOfStockRatio, ':', -1)), 0) as saleOfStockRatio,
ifnull(sum(stock_total), 0) as stock_total,
ifnull(sum(stock_subtotal), 0) as stock_subtotal,
ifnull(sum(stock_unreserve), 0) as stock_unreserve,
@ -272,7 +272,7 @@
</select>
<select id="selectReport2" resultType="com.yxt.anrui.reportcenter.api.dailyreport.DailyReportVo">
select ifnull(sum(saleOfStockRatio), 0) as saleOfStockRatio,
select ifnull(sum(SUBSTRING_INDEX(saleOfStockRatio, ':', 1)/SUBSTRING_INDEX(saleOfStockRatio, ':', -1)), 0) as saleOfStockRatio,
ifnull(sum(stock_subtotal), 0) as stock_subtotal,
ifnull(sum(stock_total), 0) as stock_total,
ifnull(sum(stock_unreserve), 0) as stock_unreserve,
@ -344,7 +344,7 @@
</select>
<select id="selectReport3" resultType="com.yxt.anrui.reportcenter.api.dailyreport.DailyReportVo">
select ifnull(sum(saleOfStockRatio), 0) as saleOfStockRatio,
select ifnull(sum(SUBSTRING_INDEX(saleOfStockRatio, ':', 1)/SUBSTRING_INDEX(saleOfStockRatio, ':', -1)), 0) as saleOfStockRatio,
ifnull(sum(stock_subtotal), 0) as stock_subtotal,
ifnull(sum(stock_unreserve), 0) as stock_unreserve,
ifnull(sum(stock_total), 0) as stock_total,
@ -475,7 +475,7 @@
ifnull(dr.deliver_loan_year, 0) as deliver_loan_year,
ifnull(dr.deliver_full_year, 0) as deliver_full_year,
ifnull(dr.deliver_subtotal_year, 0) as deliver_subtotal_year-->
ifnull(sum(dr.saleOfStockRatio), 0) as saleOfStockRatio,
ifnull(sum(SUBSTRING_INDEX(dr.saleOfStockRatio, ':', 1)/SUBSTRING_INDEX(dr.saleOfStockRatio, ':', -1)), 0) as saleOfStockRatio,
ifnull(sum(dr.stock_total), 0) as stock_total,
ifnull(sum(dr.stock_unreserve), 0) as stock_unreserve,
ifnull(sum(dr.stock_reserve), 0) as stock_reserve,

86
anrui-reportcenter/anrui-reportcenter-biz/src/main/java/com/yxt/anrui/reportcenter/biz/dailyreport/DailyReportService.java

@ -1062,15 +1062,15 @@ public class DailyReportService extends MybatisBaseService<DailyReportMapper, Da
QueryWrapper<DailyReport> qw = new QueryWrapper<>();
DailyReportAppVo dailyReportAppVo = new DailyReportAppVo();
dailyReportAppVo.setTitle("分公司" + date + "日报");
qw.like("ddr.createTime",date);
qw.eq("ddr.useOrgSid",useOrgSid);
qw.like("ddr.createTime", date);
qw.eq("ddr.useOrgSid", useOrgSid);
qw.groupBy("ddr.brandSid");
qw.groupBy("bm.fuelTypeValue");
qw.groupBy("bm.emissionStandardValue");
List<DailyParameterVo> parameterVoList = baseMapper.selectByParameters(useOrgSid);
parameterVoList.removeAll(Collections.singleton(null));
qw = getCommon(parameterVoList,qw);
List<BrandVo> rows1 = baseMapper.selectByBrand2(useOrgSid, date,qw);
qw = getCommon(parameterVoList, qw);
List<BrandVo> rows1 = baseMapper.selectByBrand2(useOrgSid, date, qw);
rows1.removeAll(Collections.singleton(null));
dailyReportAppVo.setRow1(rows1);
List<String> brandList = rows1.stream().map(v -> v.getLinkSid()).collect(Collectors.toList());
@ -1079,15 +1079,15 @@ public class DailyReportService extends MybatisBaseService<DailyReportMapper, Da
return rb.success();
}
qw = new QueryWrapper<>();
qw.eq("dr.useOrgSid",useOrgSid);
qw.like("dr.createTime",date);
qw.in("dr.brandSid",brandList);
qw.eq("dr.useOrgSid", useOrgSid);
qw.like("dr.createTime", date);
qw.in("dr.brandSid", brandList);
qw.orderByDesc("dr.brandSid");
qw.groupBy("dr.brandSid");
qw.groupBy("bm.fuelTypeValue");
qw.groupBy("bm.emissionStandardValue");
qw = getCommon(parameterVoList,qw);
List<DailyReportVo> dailyReportVoList = baseMapper.selectReport4(brandList, useOrgSid, date,qw);
qw = getCommon(parameterVoList, qw);
List<DailyReportVo> dailyReportVoList = baseMapper.selectReport4(brandList, useOrgSid, date, qw);
//燃料
List<String> row2 = dailyReportVoList.stream().map(v -> v.getFuelTypeValue()).collect(Collectors.toList());
dailyReportAppVo.setRow2(row2);
@ -1095,10 +1095,15 @@ public class DailyReportService extends MybatisBaseService<DailyReportMapper, Da
List<String> row3 = dailyReportVoList.stream().map(v -> v.getEmissionStandardValue()).collect(Collectors.toList());
dailyReportAppVo.setRow3(row3);
//存销比
List<String> row4 = dailyReportVoList.stream().map(v -> v.getSaleOfStockRatio()).collect(Collectors.toList());
List<String> row4 = dailyReportVoList.stream().map(v ->
v.getSaleOfStockRatio().contains(".") ?dicimalToFraction(Double.valueOf(v.getSaleOfStockRatio())):(v.getSaleOfStockRatio()+":1")
).collect(Collectors.toList());
//合计
BigDecimal row4All = row4.stream().map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
row4.add(row4All.toString());
BigDecimal row4All = dailyReportVoList.stream().map(v ->
v.getSaleOfStockRatio()
).collect(Collectors.toList()).stream().map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
String row4alll = row4All.toString().contains(".")?dicimalToFraction(Double.valueOf(row4All.toString())):(row4All.toString()+":1");
row4.add(row4alll);
dailyReportAppVo.setRow4(row4);
//库存总计
List<String> row5 = dailyReportVoList.stream().map(v -> String.valueOf(v.getStock_total())).collect(Collectors.toList());
@ -1420,8 +1425,8 @@ public class DailyReportService extends MybatisBaseService<DailyReportMapper, Da
}
public QueryWrapper<DailyReport> getCommon(List<DailyParameterVo> parameterVoList,QueryWrapper<DailyReport> qw){
if(!parameterVoList.isEmpty()){
public QueryWrapper<DailyReport> getCommon(List<DailyParameterVo> parameterVoList, QueryWrapper<DailyReport> qw) {
if (!parameterVoList.isEmpty()) {
for (int i = 0; i < parameterVoList.size(); i++) {
DailyParameterVo dailyParameterVo = parameterVoList.get(i);
String tableName = Arrays.asList(dailyParameterVo.getTableNameKey().split("\\.")).get(1);
@ -1432,77 +1437,77 @@ public class DailyReportService extends MybatisBaseService<DailyReportMapper, Da
case 0:
if ("base_model_config".equals(tableName)) {
// qw.groupBy("bmc." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bmc."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bmc." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bmc." + dailyParameterVo.getColName());
} else if ("base_vehicle_model".equals(tableName)) {
// qw.groupBy("bm." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bm."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bm." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bm." + dailyParameterVo.getColName());
}
break;
case 1:
if ("base_model_config".equals(tableName)) {
// qw.groupBy("bmc." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bmc."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bmc." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bmc." + dailyParameterVo.getColName());
} else if ("base_vehicle_model".equals(tableName)) {
// qw.groupBy("bm." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bm."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bm." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bm." + dailyParameterVo.getColName());
}
break;
case 2:
if ("base_model_config".equals(tableName)) {
// qw.groupBy("bmc." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bmc."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bmc." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bmc." + dailyParameterVo.getColName());
} else if ("base_vehicle_model".equals(tableName)) {
// qw.groupBy("bm." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bm."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bm." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bm." + dailyParameterVo.getColName());
}
break;
case 3:
if ("base_model_config".equals(tableName)) {
// qw.groupBy("bmc." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bmc."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bmc." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bmc." + dailyParameterVo.getColName());
} else if ("base_vehicle_model".equals(tableName)) {
// qw.groupBy("bm." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bm."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bm." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bm." + dailyParameterVo.getColName());
}
break;
case 4:
if ("base_model_config".equals(tableName)) {
// qw.groupBy("bmc." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bmc."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bmc." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bmc." + dailyParameterVo.getColName());
} else if ("base_vehicle_model".equals(tableName)) {
// qw.groupBy("bm." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bm."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bm." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bm." + dailyParameterVo.getColName());
}
break;
case 5:
if ("base_model_config".equals(tableName)) {
// qw.groupBy("bmc." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bmc."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bmc." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bmc." + dailyParameterVo.getColName());
} else if ("base_vehicle_model".equals(tableName)) {
// qw.groupBy("bm." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bm."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bm." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bm." + dailyParameterVo.getColName());
}
break;
case 6:
if ("base_model_config".equals(tableName)) {
// qw.groupBy("bmc." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bmc."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bmc." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bmc." + dailyParameterVo.getColName());
} else if ("base_vehicle_model".equals(tableName)) {
// qw.groupBy("bm." + dailyParameterVo.getColName());
qw.groupBy("IFNULL(bm."+dailyParameterVo.getColName()+",'')");
qw.groupBy("IFNULL(bm." + dailyParameterVo.getColName() + ",'')");
qw.orderByDesc("bm." + dailyParameterVo.getColName());
}
break;
@ -1515,4 +1520,29 @@ public class DailyReportService extends MybatisBaseService<DailyReportMapper, Da
return qw;
}
public String dicimalToFraction(double num) {
int count = 0;
int base = 10;
while (num != Math.floor(num)) {
num *= base;
count++;
}
base = (int) Math.pow(base, count);
int nor = (int) num;
int gcd = findGCD(nor, base);
return String.valueOf(nor / gcd) + "/" + String.valueOf(base / gcd);
}
//求最大公约数
private int findGCD(int a, int b) {
if (a == 0) {
return b;
}
return findGCD(b % a, a);
}
}

Loading…
Cancel
Save