钱德旺系统适配
This commit is contained in:
@@ -169,7 +169,7 @@ public class LbDepartmentUserController {
|
||||
|
||||
@PostMapping("/exportUsers")
|
||||
@Operation(summary = "导出指定用户Excel",
|
||||
description = "按租户ID与用户ID列表导出:用户ID、用户名、手机号、加入时间、最早/最晚buy_time、累计交易金额")
|
||||
description = "按租户ID与用户ID列表导出:用户ID、用户名、手机号、加入时间、抢单数量、当天买单量、最早/最晚buy_time、累计交易金额")
|
||||
public void exportUsers(
|
||||
@Parameter(description = "租户ID", required = true) @RequestParam String tenantId,
|
||||
@Parameter(description = "用户ID列表", required = true) @RequestBody List<String> userIds,
|
||||
|
||||
@@ -41,4 +41,12 @@ public interface LbOrderRowMapper extends BaseMapper<LbOrderRow> {
|
||||
@Param("buyerIds") List<String> buyerIds,
|
||||
@Param("buyStartTime") String buyStartTime,
|
||||
@Param("buyEndTime") String buyEndTime);
|
||||
|
||||
/**
|
||||
* 按租户、买家ID列表和日期查询每个买家的当天订单数。
|
||||
*/
|
||||
List<Map<String, Object>> selectTodayOrderCountByBuyerIds(@Param("tenantId") String tenantId,
|
||||
@Param("buyerIds") List<Long> buyerIds,
|
||||
@Param("startTime") String startTime,
|
||||
@Param("endTime") String endTime);
|
||||
}
|
||||
|
||||
@@ -711,6 +711,30 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
||||
? includeAncestorUserIds(matchedUserIds, userById)
|
||||
: new HashSet<>(userById.keySet());
|
||||
|
||||
// 计算每个用户当天买单数
|
||||
Map<String, Integer> todayBuyCountByUserId = new HashMap<>();
|
||||
if (!visibleUserIds.isEmpty()) {
|
||||
List<Long> buyerIds = new ArrayList<>(visibleUserIds.size());
|
||||
for (String userId : visibleUserIds) {
|
||||
try {
|
||||
buyerIds.add(Long.parseLong(userId));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
if (!buyerIds.isEmpty()) {
|
||||
// buy_time 是字符串,可能为 "yyyy-MM-dd" 或 "yyyy-MM-dd HH:mm:ss"
|
||||
String todayStart = LocalDate.now().format(ORDER_DAY_FMT);
|
||||
String todayEnd = LocalDate.now().atTime(23, 59, 59).format(ORDER_DAY_TIME_FMT);
|
||||
List<Map<String, Object>> countResults = lbOrderRowMapper.selectTodayOrderCountByBuyerIds(
|
||||
tenantIdTrim, buyerIds, todayStart, todayEnd);
|
||||
for (Map<String, Object> row : countResults) {
|
||||
Long buyerId = ((Number) row.get("buyerId")).longValue();
|
||||
int orderCount = ((Number) row.get("orderCount")).intValue();
|
||||
todayBuyCountByUserId.put(String.valueOf(buyerId), orderCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Map<String, Object>> nodeByUserId = new LinkedHashMap<>();
|
||||
Map<String, String> parentByUserId = new HashMap<>();
|
||||
for (String userId : visibleUserIds) {
|
||||
@@ -718,12 +742,14 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
||||
if (lbUser == null) {
|
||||
continue;
|
||||
}
|
||||
nodeByUserId.put(userId, toLbUserTreeNode(
|
||||
Map<String, Object> node = toLbUserTreeNode(
|
||||
lbUser,
|
||||
joinDateByUserId.get(userId),
|
||||
lastTradeDateByUserId.get(userId),
|
||||
lastBuyAmtByUserId.get(userId),
|
||||
isActiveByUserId.getOrDefault(userId, 0)));
|
||||
isActiveByUserId.getOrDefault(userId, 0));
|
||||
node.put("todayBuyCount", todayBuyCountByUserId.getOrDefault(userId, 0));
|
||||
nodeByUserId.put(userId, node);
|
||||
|
||||
String parentUserId = resolveLbUserParentId(lbUser, userById);
|
||||
if (parentUserId != null && visibleUserIds.contains(parentUserId)) {
|
||||
@@ -1036,6 +1062,7 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
||||
Long pid = user.getPid();
|
||||
node.put("parentId", pid == null || pid <= 0 ? null : String.valueOf(pid));
|
||||
node.put("parentName", trimToNull(user.getPname()));
|
||||
node.put("maxOrder", user.getMaxOrder());
|
||||
node.put("joinDate", joinDate);
|
||||
node.put("lastTradeDate", lastTradeDate);
|
||||
node.put("lastBuyAmt", lastBuyAmt);
|
||||
@@ -1239,6 +1266,30 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Integer> todayOrderCountByUserId = new HashMap<>();
|
||||
if (!buyerIds.isEmpty()) {
|
||||
// buy_time 是字符串,可能为 "yyyy-MM-dd" 或 "yyyy-MM-dd HH:mm:ss"。
|
||||
// 起始用日期格式,兼容两种存储:datetime 在前缀相同时更长更大,仍满足 >=。
|
||||
String todayStart = LocalDate.now().format(ORDER_DAY_FMT);
|
||||
String todayEnd = LocalDate.now().atTime(23, 59, 59).format(ORDER_DAY_TIME_FMT);
|
||||
List<Map<String, Object>> todayOrderCountResults = lbOrderRowMapper.selectTodayOrderCountByBuyerIds(
|
||||
tenantIdTrim, buyerIds, todayStart, todayEnd);
|
||||
|
||||
Map<Long, String> userIdByBuyerId = new HashMap<>();
|
||||
for (Map.Entry<String, Long> entry : buyerIdByUserId.entrySet()) {
|
||||
userIdByBuyerId.put(entry.getValue(), entry.getKey());
|
||||
}
|
||||
|
||||
for (Map<String, Object> row : todayOrderCountResults) {
|
||||
Long buyerId = ((Number) row.get("buyerId")).longValue();
|
||||
int orderCount = ((Number) row.get("orderCount")).intValue();
|
||||
String userId = userIdByBuyerId.get(buyerId);
|
||||
if (userId != null) {
|
||||
todayOrderCountByUserId.put(userId, orderCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
Sheet sheet = workbook.createSheet("部门用户");
|
||||
|
||||
@@ -1246,7 +1297,7 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
||||
CellStyle dataStyle = createExportDataStyle(workbook);
|
||||
|
||||
String[] headers = {
|
||||
"用户ID", "用户名", "手机号", "加入时间",
|
||||
"用户ID", "用户名", "手机号", "加入时间", "抢单数量", "当天买单量",
|
||||
"最早buy_time", "最晚buy_time", "累计交易金额buy_amt"
|
||||
};
|
||||
Row headerRow = sheet.createRow(0);
|
||||
@@ -1266,9 +1317,11 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
||||
createExportCell(row, 1, lbUser == null ? "" : nullToEmpty(lbUser.getNickname()), dataStyle);
|
||||
createExportCell(row, 2, lbUser == null ? "" : nullToEmpty(lbUser.getMobile()), dataStyle);
|
||||
createExportCell(row, 3, formatJoinDate(lbUser == null || lbUser.getJoinTime() == null ? null : lbUser.getJoinTime().toLocalDate()), dataStyle);
|
||||
createExportCell(row, 4, stats == null ? "" : nullToEmpty(stats.earliestBuyTime), dataStyle);
|
||||
createExportCell(row, 5, stats == null ? "" : nullToEmpty(stats.latestBuyTime), dataStyle);
|
||||
createExportCell(row, 6, stats == null ? "" : formatAmount(stats.totalBuyAmt), dataStyle);
|
||||
createExportCell(row, 4, lbUser == null || lbUser.getMaxOrder() == null ? "" : String.valueOf(lbUser.getMaxOrder()), dataStyle);
|
||||
createExportCell(row, 5, String.valueOf(todayOrderCountByUserId.getOrDefault(userId, 0)), dataStyle);
|
||||
createExportCell(row, 6, stats == null ? "" : nullToEmpty(stats.earliestBuyTime), dataStyle);
|
||||
createExportCell(row, 7, stats == null ? "" : nullToEmpty(stats.latestBuyTime), dataStyle);
|
||||
createExportCell(row, 8, stats == null ? "" : formatAmount(stats.totalBuyAmt), dataStyle);
|
||||
}
|
||||
|
||||
adjustExportColumnWidths(sheet, headers);
|
||||
|
||||
Reference in New Issue
Block a user