1
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.web.controller.jarvis;
|
package com.ruoyi.web.controller.jarvis;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@@ -62,7 +63,28 @@ public class OrderRowsController extends BaseController
|
|||||||
|
|
||||||
startPage();
|
startPage();
|
||||||
List<OrderRows> list = orderRowsService.selectOrderRowsList(orderRows);
|
List<OrderRows> list = orderRowsService.selectOrderRowsList(orderRows);
|
||||||
return getDataTable(list);
|
TableDataInfo dataTable = getDataTable(list);
|
||||||
|
Date beginTime = getDateFromParams(orderRows.getParams(), "beginTime");
|
||||||
|
Date endTime = getDateFromParams(orderRows.getParams(), "endTime");
|
||||||
|
dataTable.setStatistics(buildStatistics(orderRows, beginTime, endTime));
|
||||||
|
return dataTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Date getDateFromParams(Map<String, Object> params, String key) {
|
||||||
|
if (params == null) return null;
|
||||||
|
Object v = params.get(key);
|
||||||
|
if (v == null) return null;
|
||||||
|
if (v instanceof Date) return (Date) v;
|
||||||
|
if (v instanceof String) {
|
||||||
|
String s = ((String) v).trim();
|
||||||
|
if (s.isEmpty()) return null;
|
||||||
|
try {
|
||||||
|
return new SimpleDateFormat("yyyy-MM-dd").parse(s);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,143 +168,131 @@ public class OrderRowsController extends BaseController
|
|||||||
return AjaxResult.success(options);
|
return AjaxResult.success(options);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 根据联盟ID或日期范围统计订单数据,按validCode分组
|
* 根据联盟ID或日期范围统计订单数据,按validCode分组(独立接口,与列表同条件时建议用 list 返回的 statistics)
|
||||||
*/
|
*/
|
||||||
@GetMapping("/statistics")
|
@GetMapping("/statistics")
|
||||||
public AjaxResult getStatistics(OrderRows orderRows, Date beginTime, Date endTime) {
|
public AjaxResult getStatistics(OrderRows orderRows, Date beginTime, Date endTime) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
return AjaxResult.success(buildStatistics(orderRows, beginTime, endTime));
|
||||||
|
|
||||||
// 获取superAdminList,筛选出isCount = 0的unionId
|
|
||||||
List<Long> excludeUnionIds = new ArrayList<>();
|
|
||||||
List<SuperAdmin> superAdminList = superAdminService.selectSuperAdminList(null);
|
|
||||||
logger.info("superAdminList.size: {}", superAdminList.size());
|
|
||||||
for (SuperAdmin superAdmin : superAdminList) {
|
|
||||||
if (superAdmin.getIsCount() != null && superAdmin.getIsCount() == 0 && superAdmin.getUnionId() != null) {
|
|
||||||
try {
|
|
||||||
excludeUnionIds.add(Long.parseLong(superAdmin.getUnionId()));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
// 忽略无法解析的unionId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
logger.info("excludeUnionIds: {}", excludeUnionIds.size());
|
|
||||||
|
|
||||||
// 使用新的查询方法,直接在SQL中完成日期过滤和unionId排除
|
/**
|
||||||
List<OrderRows> filteredList = orderRowsService.selectOrderRowsListWithFilter(orderRows, beginTime, endTime, excludeUnionIds);
|
* 按列表相同条件构建统计数据(与 selectOrderRowsList 同条件:日期、unionId 等,排除 isCount=0)
|
||||||
|
*/
|
||||||
// 定义分组
|
private Map<String, Object> buildStatistics(OrderRows orderRows, Date beginTime, Date endTime) {
|
||||||
Map<String, List<String>> groups = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
groups.put("cancel", Arrays.asList("3"));
|
List<Long> excludeUnionIds = new ArrayList<>();
|
||||||
groups.put("invalid", Arrays.asList("2","4","5","6","7","8","9","10","11","14","19","20","21","22","23","29","30","31","32","33","34"));
|
List<SuperAdmin> superAdminList = superAdminService.selectSuperAdminList(null);
|
||||||
groups.put("pending", Arrays.asList("15"));
|
for (SuperAdmin superAdmin : superAdminList) {
|
||||||
groups.put("paid", Arrays.asList("16"));
|
if (superAdmin.getIsCount() != null && superAdmin.getIsCount() == 0 && superAdmin.getUnionId() != null) {
|
||||||
groups.put("finished", Arrays.asList("17"));
|
try {
|
||||||
groups.put("deposit", Arrays.asList("24"));
|
excludeUnionIds.add(Long.parseLong(superAdmin.getUnionId()));
|
||||||
groups.put("illegal", Arrays.asList("25","26","27","28"));
|
} catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
// 初始化统计结果
|
|
||||||
Map<String, Map<String, Object>> groupStats = new HashMap<>();
|
|
||||||
groupStats.put("cancel", createGroupStat("取消", "cancel"));
|
|
||||||
groupStats.put("invalid", createGroupStat("无效", "invalid"));
|
|
||||||
groupStats.put("pending", createGroupStat("待付款", "pending"));
|
|
||||||
groupStats.put("paid", createGroupStat("已付款", "paid"));
|
|
||||||
groupStats.put("finished", createGroupStat("已完成", "finished"));
|
|
||||||
groupStats.put("deposit", createGroupStat("已付定金", "deposit"));
|
|
||||||
groupStats.put("illegal", createGroupStat("违规", "illegal"));
|
|
||||||
|
|
||||||
// 总统计数据
|
|
||||||
int totalOrders = 0;
|
|
||||||
double totalCommission = 0;
|
|
||||||
double totalActualFee = 0;
|
|
||||||
long totalSkuNum = 0;
|
|
||||||
|
|
||||||
// 违规订单统计
|
|
||||||
long violationOrders = 0;
|
|
||||||
double violationCommission = 0.0;
|
|
||||||
|
|
||||||
// 按分组统计
|
|
||||||
for (OrderRows row : filteredList) {
|
|
||||||
totalOrders++;
|
|
||||||
if (row.getSkuNum() != null) {
|
|
||||||
totalSkuNum += row.getSkuNum();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算佣金金额(对于违规和取消订单使用特殊计算)
|
|
||||||
String validCode = row.getValidCode() != null ? String.valueOf(row.getValidCode()) : null;
|
|
||||||
boolean isCancel = "3".equals(validCode); // 取消订单
|
|
||||||
boolean isIllegal = "25".equals(validCode) || "26".equals(validCode)
|
|
||||||
|| "27".equals(validCode) || "28".equals(validCode); // 违规订单
|
|
||||||
|
|
||||||
double commissionAmount = 0.0;
|
|
||||||
double actualFeeAmount = 0.0;
|
|
||||||
|
|
||||||
// 违规订单:始终使用 estimateCosPrice * commissionRate / 100 计算
|
|
||||||
if (isIllegal) {
|
|
||||||
if (row.getEstimateCosPrice() != null && row.getCommissionRate() != null) {
|
|
||||||
commissionAmount = row.getEstimateCosPrice() * row.getCommissionRate() * 0.01;
|
|
||||||
actualFeeAmount = commissionAmount; // 违规订单的实际费用等于计算的佣金
|
|
||||||
} else if (row.getEstimateFee() != null) {
|
|
||||||
commissionAmount = row.getEstimateFee();
|
|
||||||
actualFeeAmount = commissionAmount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 取消订单:如果actualFee为空或0,则使用公式计算
|
List<OrderRows> filteredList = orderRowsService.selectOrderRowsListWithFilter(orderRows, beginTime, endTime, excludeUnionIds);
|
||||||
else if (isCancel) {
|
|
||||||
if (row.getActualFee() != null && row.getActualFee() > 0) {
|
Map<String, List<String>> groups = new HashMap<>();
|
||||||
actualFeeAmount = row.getActualFee();
|
groups.put("cancel", Arrays.asList("3"));
|
||||||
commissionAmount = row.getEstimateFee() != null ? row.getEstimateFee() : 0;
|
groups.put("invalid", Arrays.asList("2","4","5","6","7","8","9","10","11","14","19","20","21","22","23","29","30","31","32","33","34"));
|
||||||
} else if (row.getEstimateCosPrice() != null && row.getCommissionRate() != null) {
|
groups.put("pending", Arrays.asList("15"));
|
||||||
commissionAmount = row.getEstimateCosPrice() * row.getCommissionRate() * 0.01;
|
groups.put("paid", Arrays.asList("16"));
|
||||||
actualFeeAmount = commissionAmount;
|
groups.put("finished", Arrays.asList("17"));
|
||||||
|
groups.put("deposit", Arrays.asList("24"));
|
||||||
|
groups.put("illegal", Arrays.asList("25","26","27","28"));
|
||||||
|
|
||||||
|
Map<String, Map<String, Object>> groupStats = new HashMap<>();
|
||||||
|
groupStats.put("cancel", createGroupStat("取消", "cancel"));
|
||||||
|
groupStats.put("invalid", createGroupStat("无效", "invalid"));
|
||||||
|
groupStats.put("pending", createGroupStat("待付款", "pending"));
|
||||||
|
groupStats.put("paid", createGroupStat("已付款", "paid"));
|
||||||
|
groupStats.put("finished", createGroupStat("已完成", "finished"));
|
||||||
|
groupStats.put("deposit", createGroupStat("已付定金", "deposit"));
|
||||||
|
groupStats.put("illegal", createGroupStat("违规", "illegal"));
|
||||||
|
|
||||||
|
int totalOrders = 0;
|
||||||
|
double totalCosPrice = 0;
|
||||||
|
double totalCommission = 0;
|
||||||
|
double totalActualFee = 0;
|
||||||
|
long totalSkuNum = 0;
|
||||||
|
long violationOrders = 0;
|
||||||
|
double violationCommission = 0.0;
|
||||||
|
|
||||||
|
for (OrderRows row : filteredList) {
|
||||||
|
totalOrders++;
|
||||||
|
if (row.getEstimateCosPrice() != null) {
|
||||||
|
totalCosPrice += row.getEstimateCosPrice();
|
||||||
|
}
|
||||||
|
if (row.getSkuNum() != null) {
|
||||||
|
totalSkuNum += row.getSkuNum();
|
||||||
|
}
|
||||||
|
|
||||||
|
String validCode = row.getValidCode() != null ? String.valueOf(row.getValidCode()) : null;
|
||||||
|
boolean isCancel = "3".equals(validCode);
|
||||||
|
boolean isIllegal = "25".equals(validCode) || "26".equals(validCode)
|
||||||
|
|| "27".equals(validCode) || "28".equals(validCode);
|
||||||
|
|
||||||
|
double commissionAmount = 0.0;
|
||||||
|
double actualFeeAmount = 0.0;
|
||||||
|
|
||||||
|
if (isIllegal) {
|
||||||
|
if (row.getEstimateCosPrice() != null && row.getCommissionRate() != null) {
|
||||||
|
commissionAmount = row.getEstimateCosPrice() * row.getCommissionRate() * 0.01;
|
||||||
|
actualFeeAmount = commissionAmount;
|
||||||
|
} else if (row.getEstimateFee() != null) {
|
||||||
|
commissionAmount = row.getEstimateFee();
|
||||||
|
actualFeeAmount = commissionAmount;
|
||||||
|
}
|
||||||
|
} else if (isCancel) {
|
||||||
|
if (row.getActualFee() != null && row.getActualFee() > 0) {
|
||||||
|
actualFeeAmount = row.getActualFee();
|
||||||
|
commissionAmount = row.getEstimateFee() != null ? row.getEstimateFee() : 0;
|
||||||
|
} else if (row.getEstimateCosPrice() != null && row.getCommissionRate() != null) {
|
||||||
|
commissionAmount = row.getEstimateCosPrice() * row.getCommissionRate() * 0.01;
|
||||||
|
actualFeeAmount = commissionAmount;
|
||||||
|
} else {
|
||||||
|
commissionAmount = row.getEstimateFee() != null ? row.getEstimateFee() : 0;
|
||||||
|
actualFeeAmount = row.getActualFee() != null ? row.getActualFee() : 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
commissionAmount = row.getEstimateFee() != null ? row.getEstimateFee() : 0;
|
commissionAmount = row.getEstimateFee() != null ? row.getEstimateFee() : 0;
|
||||||
actualFeeAmount = row.getActualFee() != null ? row.getActualFee() : 0;
|
actualFeeAmount = row.getActualFee() != null ? row.getActualFee() : 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// 其他订单:使用原有的字段值
|
|
||||||
else {
|
|
||||||
commissionAmount = row.getEstimateFee() != null ? row.getEstimateFee() : 0;
|
|
||||||
actualFeeAmount = row.getActualFee() != null ? row.getActualFee() : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
totalCommission += commissionAmount;
|
|
||||||
totalActualFee += actualFeeAmount;
|
|
||||||
|
|
||||||
// 按validCode分组统计
|
totalCommission += commissionAmount;
|
||||||
if (validCode != null) {
|
totalActualFee += actualFeeAmount;
|
||||||
for (Map.Entry<String, List<String>> group : groups.entrySet()) {
|
|
||||||
List<String> codes = group.getValue();
|
|
||||||
if (codes.contains(validCode)) {
|
|
||||||
Map<String, Object> stat = groupStats.get(group.getKey());
|
|
||||||
stat.put("count", (Integer) stat.get("count") + 1);
|
|
||||||
stat.put("commission", (Double) stat.get("commission") + commissionAmount);
|
|
||||||
stat.put("actualFee", (Double) stat.get("actualFee") + actualFeeAmount);
|
|
||||||
if (row.getSkuNum() != null) {
|
|
||||||
stat.put("skuNum", (Long) stat.get("skuNum") + row.getSkuNum());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 统计违规订单
|
if (validCode != null) {
|
||||||
if ("illegal".equals(group.getKey())) {
|
for (Map.Entry<String, List<String>> group : groups.entrySet()) {
|
||||||
violationOrders++;
|
if (group.getValue().contains(validCode)) {
|
||||||
violationCommission += commissionAmount;
|
Map<String, Object> stat = groupStats.get(group.getKey());
|
||||||
|
stat.put("count", (Integer) stat.get("count") + 1);
|
||||||
|
stat.put("commission", (Double) stat.get("commission") + commissionAmount);
|
||||||
|
stat.put("actualFee", (Double) stat.get("actualFee") + actualFeeAmount);
|
||||||
|
if (row.getSkuNum() != null) {
|
||||||
|
stat.put("skuNum", (Long) stat.get("skuNum") + row.getSkuNum());
|
||||||
|
}
|
||||||
|
if ("illegal".equals(group.getKey())) {
|
||||||
|
violationOrders++;
|
||||||
|
violationCommission += commissionAmount;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.put("totalOrders", totalOrders);
|
||||||
|
result.put("totalCosPrice", totalCosPrice);
|
||||||
|
result.put("totalCommission", totalCommission);
|
||||||
|
result.put("totalActualFee", totalActualFee);
|
||||||
|
result.put("totalSkuNum", totalSkuNum);
|
||||||
|
result.put("violationOrders", violationOrders);
|
||||||
|
result.put("violationCommission", violationCommission);
|
||||||
|
result.put("groupStats", groupStats);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.put("totalOrders", totalOrders);
|
|
||||||
result.put("totalCommission", totalCommission);
|
|
||||||
result.put("totalActualFee", totalActualFee);
|
|
||||||
result.put("totalSkuNum", totalSkuNum);
|
|
||||||
result.put("violationOrders", violationOrders);
|
|
||||||
result.put("violationCommission", violationCommission);
|
|
||||||
result.put("groupStats", groupStats);
|
|
||||||
|
|
||||||
return AjaxResult.success(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建分组统计对象
|
* 创建分组统计对象
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ public class TableDataInfo implements Serializable
|
|||||||
/** 消息内容 */
|
/** 消息内容 */
|
||||||
private String msg;
|
private String msg;
|
||||||
|
|
||||||
|
/** 扩展数据(如统计信息等,可选) */
|
||||||
|
private Object statistics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表格数据对象
|
* 表格数据对象
|
||||||
*/
|
*/
|
||||||
@@ -82,4 +85,14 @@ public class TableDataInfo implements Serializable
|
|||||||
{
|
{
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getStatistics()
|
||||||
|
{
|
||||||
|
return statistics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatistics(Object statistics)
|
||||||
|
{
|
||||||
|
this.statistics = statistics;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user