圈人机制调整
This commit is contained in:
@@ -412,7 +412,7 @@ public class LbDailyUserTradeReportController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/stats/user-trade-with-team/by-date-range-and-tenant")
|
@GetMapping("/stats/user-trade-with-team/by-date-range-and-tenant")
|
||||||
@Operation(summary = "按日期范围统计本人及递归下级交易金额", description = "根据开始日期、结束日期、租户ID,基于 lb_department_user 上下级(parent_id 为父用户 user_id)与 lb_daily_user_trade_report,对 yestoday_buy_amt、daily_sell_amt、daily_buy_amt、diff_amt 四类分别汇总 own*/team*/total*(team 为全部下级递归,不含本人);不含 data_type=report_sum")
|
@Operation(summary = "按日期范围统计本人及递归下级交易金额", description = "先查 lb_daily_user_trade_report(日期+租户,排除 report_sum)圈定 user_id;再查 lb_department_user(同租户)用 parent_id(父 user_id)建上下级;对 yestoday_buy_amt、daily_sell_amt、daily_buy_amt、diff_amt 分别汇总 own*/team*/total*(team 为递归下级、不含本人)。仅返回报表范围内有数据的用户。")
|
||||||
public ResponseEntity<Map<String, Object>> statsUserTradeWithTeamByDateRangeAndTenant(
|
public ResponseEntity<Map<String, Object>> statsUserTradeWithTeamByDateRangeAndTenant(
|
||||||
@Parameter(description = "开始日期,格式:yyyy-MM-dd", required = true)
|
@Parameter(description = "开始日期,格式:yyyy-MM-dd", required = true)
|
||||||
@RequestParam String startDate,
|
@RequestParam String startDate,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public interface ILbDailyUserTradeReportService extends IService<LbDailyUserTrad
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 按日期范围与租户统计每人四类金额(昨日买入、当日卖出、当日买入、差额):本人汇总与递归下级汇总。
|
* 按日期范围与租户统计每人四类金额(昨日买入、当日卖出、当日买入、差额):本人汇总与递归下级汇总。
|
||||||
|
* 用户范围由 lb_daily_user_trade_report 在条件内出现过的 user_id 圈定;上下级由 lb_department_user 确定。
|
||||||
*/
|
*/
|
||||||
Map<String, Object> listUserTradeAmountWithTeamByDateRangeAndTenant(
|
Map<String, Object> listUserTradeAmountWithTeamByDateRangeAndTenant(
|
||||||
LocalDate startDate, LocalDate endDate, String tenantId);
|
LocalDate startDate, LocalDate endDate, String tenantId);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class LbDailyUserTradeReportServiceImpl extends ServiceImpl<LbDailyUserTr
|
|||||||
implements ILbDailyUserTradeReportService {
|
implements ILbDailyUserTradeReportService {
|
||||||
|
|
||||||
private static final String DATA_TYPE_REPORT_SUM = "report_sum";
|
private static final String DATA_TYPE_REPORT_SUM = "report_sum";
|
||||||
|
private static final String DATA_TYPE_REPORT_DETAIL = "report_detail";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ILbDepartmentUserService lbDepartmentUserService;
|
private ILbDepartmentUserService lbDepartmentUserService;
|
||||||
@@ -121,52 +122,17 @@ public class LbDailyUserTradeReportServiceImpl extends ServiceImpl<LbDailyUserTr
|
|||||||
LocalDateTime rangeStart = startDate.atStartOfDay();
|
LocalDateTime rangeStart = startDate.atStartOfDay();
|
||||||
LocalDateTime rangeEnd = endDate.atTime(23, 59, 59);
|
LocalDateTime rangeEnd = endDate.atTime(23, 59, 59);
|
||||||
|
|
||||||
List<LbDepartmentUser> deptUsers = lbDepartmentUserService.list(
|
// 1) 先查 lb_daily_user_trade_report:圈定日期内有数据的用户,并汇总本人四类金额
|
||||||
new LambdaQueryWrapper<LbDepartmentUser>()
|
LambdaQueryWrapper<LbDailyUserTradeReport> tradeQw = new LambdaQueryWrapper<>();
|
||||||
.eq(LbDepartmentUser::getTenantId, tenantIdTrim));
|
tradeQw.ge(LbDailyUserTradeReport::getReportDate, rangeStart)
|
||||||
if (deptUsers == null || deptUsers.isEmpty()) {
|
.le(LbDailyUserTradeReport::getReportDate, rangeEnd)
|
||||||
result.put("success", true);
|
.eq(LbDailyUserTradeReport::getDataType, DATA_TYPE_REPORT_DETAIL );
|
||||||
result.put("message", "查询成功");
|
|
||||||
result.put("data", List.of());
|
|
||||||
result.put("total", 0);
|
|
||||||
result.put("startDate", startDate);
|
|
||||||
result.put("endDate", endDate);
|
|
||||||
result.put("tenantId", tenantIdTrim);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, String> userIdToName = new HashMap<>();
|
Map<String, String> userIdToName = new HashMap<>();
|
||||||
Set<String> tenantUserIds = new HashSet<>();
|
|
||||||
Map<String, List<String>> childrenByParentUserId = new HashMap<>();
|
|
||||||
for (LbDepartmentUser row : deptUsers) {
|
|
||||||
if (row.getUserId() == null || row.getUserId().trim().isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String uid = row.getUserId().trim();
|
|
||||||
tenantUserIds.add(uid);
|
|
||||||
if (row.getName() != null && !row.getName().trim().isEmpty()) {
|
|
||||||
userIdToName.putIfAbsent(uid, row.getName().trim());
|
|
||||||
}
|
|
||||||
String parentUserId = row.getParentId() == null ? null : row.getParentId().trim();
|
|
||||||
if (parentUserId != null && !parentUserId.isEmpty()) {
|
|
||||||
List<String> ch = childrenByParentUserId.computeIfAbsent(parentUserId, k -> new ArrayList<>());
|
|
||||||
if (!ch.contains(uid)) {
|
|
||||||
ch.add(uid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (List<String> list : childrenByParentUserId.values()) {
|
|
||||||
list.sort(String::compareTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
LambdaQueryWrapper<LbDailyUserTradeReport> tradeQw = new LambdaQueryWrapper<>();
|
|
||||||
tradeQw.eq(LbDailyUserTradeReport::getTenantId, tenantIdTrim)
|
|
||||||
.ge(LbDailyUserTradeReport::getReportDate, rangeStart)
|
|
||||||
.le(LbDailyUserTradeReport::getReportDate, rangeEnd)
|
|
||||||
.ne(LbDailyUserTradeReport::getDataType, DATA_TYPE_REPORT_SUM);
|
|
||||||
|
|
||||||
Map<String, TradeAmtBundle> ownAmtByUserId = new HashMap<>();
|
Map<String, TradeAmtBundle> ownAmtByUserId = new HashMap<>();
|
||||||
for (LbDailyUserTradeReport r : list(tradeQw)) {
|
List<LbDailyUserTradeReport> list1 = list(tradeQw);
|
||||||
|
|
||||||
|
for (LbDailyUserTradeReport r : list1) {
|
||||||
if (r.getUserId() == null || r.getUserId().trim().isEmpty()) {
|
if (r.getUserId() == null || r.getUserId().trim().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -179,13 +145,54 @@ public class LbDailyUserTradeReportServiceImpl extends ServiceImpl<LbDailyUserTr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ownAmtByUserId.isEmpty()) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "查询成功");
|
||||||
|
result.put("data", List.of());
|
||||||
|
result.put("total", 0);
|
||||||
|
result.put("startDate", startDate);
|
||||||
|
result.put("endDate", endDate);
|
||||||
|
result.put("tenantId", tenantIdTrim);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> scopeUserIds = new HashSet<>(ownAmtByUserId.keySet());
|
||||||
|
|
||||||
|
// 2) 再查 lb_department_user:同一租户下的上下级(parent_id 为父用户 user_id),用于递归下级汇总
|
||||||
|
Map<String, List<String>> childrenByParentUserId = new HashMap<>();
|
||||||
|
List<LbDepartmentUser> deptUsers = lbDepartmentUserService.list(
|
||||||
|
new LambdaQueryWrapper<LbDepartmentUser>()
|
||||||
|
.eq(LbDepartmentUser::getTenantId, tenantIdTrim));
|
||||||
|
if (deptUsers != null) {
|
||||||
|
for (LbDepartmentUser row : deptUsers) {
|
||||||
|
if (row.getUserId() == null || row.getUserId().trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String uid = row.getUserId().trim();
|
||||||
|
if (row.getName() != null && !row.getName().trim().isEmpty()) {
|
||||||
|
userIdToName.putIfAbsent(uid, row.getName().trim());
|
||||||
|
}
|
||||||
|
String parentUserId = row.getParentId() == null ? null : row.getParentId().trim();
|
||||||
|
if (parentUserId != null && !parentUserId.isEmpty()) {
|
||||||
|
List<String> ch = childrenByParentUserId.computeIfAbsent(parentUserId, k -> new ArrayList<>());
|
||||||
|
if (!ch.contains(uid)) {
|
||||||
|
ch.add(uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (List<String> list : childrenByParentUserId.values()) {
|
||||||
|
list.sort(String::compareTo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) 仅对报表圈定的用户计算递归下级 team(无部门数据时 team 全为 0)
|
||||||
Map<String, TradeAmtBundle> teamAmtMemo = new HashMap<>();
|
Map<String, TradeAmtBundle> teamAmtMemo = new HashMap<>();
|
||||||
for (String userId : tenantUserIds) {
|
for (String userId : scopeUserIds) {
|
||||||
teamAmtRecursive(userId, childrenByParentUserId, ownAmtByUserId, teamAmtMemo, new HashSet<>());
|
teamAmtRecursive(userId, childrenByParentUserId, ownAmtByUserId, teamAmtMemo, new HashSet<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map<String, Object>> rows = new ArrayList<>();
|
List<Map<String, Object>> rows = new ArrayList<>();
|
||||||
for (String userId : tenantUserIds) {
|
for (String userId : scopeUserIds) {
|
||||||
TradeAmtBundle own = ownAmt(userId, ownAmtByUserId);
|
TradeAmtBundle own = ownAmt(userId, ownAmtByUserId);
|
||||||
TradeAmtBundle team = teamAmt(userId, teamAmtMemo);
|
TradeAmtBundle team = teamAmt(userId, teamAmtMemo);
|
||||||
TradeAmtBundle total = own.addCopy(team);
|
TradeAmtBundle total = own.addCopy(team);
|
||||||
|
|||||||
Reference in New Issue
Block a user