修复统计查询问题
This commit is contained in:
@@ -128,125 +128,116 @@ public class LaborStatsAdminService extends BaseService {
|
||||
while (DateTimeUtil.compareTime(endTime, dateTime) >= 0) {
|
||||
for (String erBanNo : erBanNoArray) {
|
||||
String dateStr = DateTimeUtil.convertDate(dateTime, DateTimeUtil.DEFAULT_DATE_PATTERN);
|
||||
String value = jedisService.hget(RedisKey.labor_stats_cache.getKey(erBanNo), dateStr);
|
||||
if (StrUtil.isEmpty(value)) {
|
||||
Long erBanNoToLong = Long.valueOf(erBanNoStr);
|
||||
Long roomUid = erBanNoMap.get(erBanNoToLong);
|
||||
if (roomUid == null) {
|
||||
continue;
|
||||
}
|
||||
Room room = roomService.getRoomByUid(roomUid);
|
||||
if (room == null) {
|
||||
throw new ServiceException("厅不存在,厅号:" + erBanNo);
|
||||
}
|
||||
String roomTitle = room.getTitle();
|
||||
List<LaborStatsDto> firstInRoomDtos = firstInRoomUserMap.get(dateStr);
|
||||
//首次进房用户
|
||||
List<LaborStatsDto> firstInRoomUsers = new ArrayList<>();
|
||||
if (CollectionUtil.isNotEmpty(firstInRoomDtos)) {
|
||||
firstInRoomUsers = firstInRoomDtos.stream().filter(v -> v.getRoomUid().equals(roomUid)).collect(Collectors.toList());
|
||||
}
|
||||
//用户ID
|
||||
List<Long> firstInRoomUidList = firstInRoomUsers.stream().map(LaborStatsDto::getUid).collect(Collectors.toList());
|
||||
Date currentEndTime = DateTimeUtil.addDays(dateTime, 1);
|
||||
LaborStatsVo stats = new LaborStatsVo();
|
||||
stats.setDate(dateStr);
|
||||
stats.setErbanNo(erBanNoToLong);
|
||||
stats.setRoomTitle(roomTitle);
|
||||
stats.setFirstInRoom(firstInRoomUsers.size());
|
||||
//次日日活用户
|
||||
List<Long> activeUidList = usersService.getDailyActiveUsers(currentEndTime);
|
||||
activeUidList.retainAll(firstInRoomUidList);
|
||||
stats.setFirstInRoomRetained(activeUidList.size());
|
||||
//获取总进房数
|
||||
int totalInRoom = 0;
|
||||
List<LaborStatsDto> totalInRooms = totalInRoomUserMap.get(dateStr);
|
||||
if (totalInRooms != null) {
|
||||
Optional<LaborStatsDto> any = totalInRooms.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
totalInRoom = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setTotalInRoom(totalInRoom);
|
||||
//首次进房用户送礼人数
|
||||
int firstInRoomGiftUser = 0;
|
||||
List<LaborStatsDto> firstInRoomGiftUsers = firstInRoomGiftUserMap.get(dateStr);
|
||||
if (firstInRoomGiftUsers != null) {
|
||||
Optional<LaborStatsDto> any = firstInRoomGiftUsers.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
firstInRoomGiftUser = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setFirstInRoomGiftUser(firstInRoomGiftUser);
|
||||
//送礼人数
|
||||
int giftUser = 0;
|
||||
List<LaborStatsDto> giftUsers = giftUserMap.get(dateStr);
|
||||
if (giftUsers != null) {
|
||||
Optional<LaborStatsDto> any = giftUsers.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
giftUser = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setGiftUser(giftUser);
|
||||
//房间流水
|
||||
int roomRevenue = 0;
|
||||
List<LaborStatsDto> roomRevenues = roomRevenueMap.get(dateStr);
|
||||
if (roomRevenues != null) {
|
||||
Optional<LaborStatsDto> any = roomRevenues.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
roomRevenue = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setRoomRevenue(roomRevenue);
|
||||
//非背包流水
|
||||
int roomNormalRevenue = 0;
|
||||
List<LaborStatsDto> roomNormalRevenues = roomNormalRevenueMap.get(dateStr);
|
||||
if (roomNormalRevenues != null) {
|
||||
Optional<LaborStatsDto> any = roomNormalRevenues.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
roomNormalRevenue = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setRoomNormalRevenue(roomNormalRevenue);
|
||||
//背包流水
|
||||
int roomBackpackRevenue = 0;
|
||||
List<LaborStatsDto> roomBackpackRevenues = roomBackpackRevenueMap.get(dateStr);
|
||||
if (roomBackpackRevenues != null) {
|
||||
Optional<LaborStatsDto> any = roomBackpackRevenues.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
roomBackpackRevenue = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setRoomBackpackRevenue(roomBackpackRevenue);
|
||||
stats.setFirstInRoomGiftRate(stats.getFirstInRoomGiftUser().doubleValue() / (stats.getFirstInRoom() > 0 ? stats.getFirstInRoom() : 1));
|
||||
//新用户进房人数
|
||||
int newUserInRoom = 0;
|
||||
List<LaborStatsDto> newUserInRooms = newUserInRoomMap.get(dateStr);
|
||||
if (newUserInRooms != null) {
|
||||
Optional<LaborStatsDto> any = newUserInRooms.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
newUserInRoom = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setNewUserInRoom(newUserInRoom);
|
||||
//新用户送礼人数
|
||||
int newUserSendGift = 0;
|
||||
List<LaborStatsDto> newUserSendGifts = newUserSendGiftMap.get(dateStr);
|
||||
if (newUserSendGifts != null) {
|
||||
Optional<LaborStatsDto> any = newUserSendGifts.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
newUserSendGift = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setNewUserSendGift(newUserSendGift);
|
||||
data.add(stats);
|
||||
// 缓存1天前的数据
|
||||
if (DateTimeUtil.compareDay(new Date(), dateTime) > 1) {
|
||||
jedisService.hset(RedisKey.labor_stats_cache.getKey(erBanNoStr), dateStr, GsonUtil.getDefGson().toJson(stats));
|
||||
}
|
||||
} else {
|
||||
data.add(GsonUtil.getDefGson().fromJson(value, LaborStatsVo.class));
|
||||
Long erBanNoToLong = Long.valueOf(erBanNoStr);
|
||||
Long roomUid = erBanNoMap.get(erBanNoToLong);
|
||||
if (roomUid == null) {
|
||||
continue;
|
||||
}
|
||||
Room room = roomService.getRoomByUid(roomUid);
|
||||
if (room == null) {
|
||||
throw new ServiceException("厅不存在,厅号:" + erBanNo);
|
||||
}
|
||||
String roomTitle = room.getTitle();
|
||||
List<LaborStatsDto> firstInRoomDtos = firstInRoomUserMap.get(dateStr);
|
||||
//首次进房用户
|
||||
List<LaborStatsDto> firstInRoomUsers = new ArrayList<>();
|
||||
if (CollectionUtil.isNotEmpty(firstInRoomDtos)) {
|
||||
firstInRoomUsers = firstInRoomDtos.stream().filter(v -> v.getRoomUid().equals(roomUid)).collect(Collectors.toList());
|
||||
}
|
||||
//用户ID
|
||||
List<Long> firstInRoomUidList = firstInRoomUsers.stream().map(LaborStatsDto::getUid).collect(Collectors.toList());
|
||||
Date currentEndTime = DateTimeUtil.addDays(dateTime, 1);
|
||||
LaborStatsVo stats = new LaborStatsVo();
|
||||
stats.setDate(dateStr);
|
||||
stats.setErbanNo(erBanNoToLong);
|
||||
stats.setRoomTitle(roomTitle);
|
||||
stats.setFirstInRoom(firstInRoomUsers.size());
|
||||
//次日日活用户
|
||||
List<Long> activeUidList = usersService.getDailyActiveUsers(currentEndTime);
|
||||
activeUidList.retainAll(firstInRoomUidList);
|
||||
stats.setFirstInRoomRetained(activeUidList.size());
|
||||
//获取总进房数
|
||||
int totalInRoom = 0;
|
||||
List<LaborStatsDto> totalInRooms = totalInRoomUserMap.get(dateStr);
|
||||
if (totalInRooms != null) {
|
||||
Optional<LaborStatsDto> any = totalInRooms.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
totalInRoom = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setTotalInRoom(totalInRoom);
|
||||
//首次进房用户送礼人数
|
||||
int firstInRoomGiftUser = 0;
|
||||
List<LaborStatsDto> firstInRoomGiftUsers = firstInRoomGiftUserMap.get(dateStr);
|
||||
if (firstInRoomGiftUsers != null) {
|
||||
Optional<LaborStatsDto> any = firstInRoomGiftUsers.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
firstInRoomGiftUser = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setFirstInRoomGiftUser(firstInRoomGiftUser);
|
||||
//送礼人数
|
||||
int giftUser = 0;
|
||||
List<LaborStatsDto> giftUsers = giftUserMap.get(dateStr);
|
||||
if (giftUsers != null) {
|
||||
Optional<LaborStatsDto> any = giftUsers.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
giftUser = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setGiftUser(giftUser);
|
||||
//房间流水
|
||||
int roomRevenue = 0;
|
||||
List<LaborStatsDto> roomRevenues = roomRevenueMap.get(dateStr);
|
||||
if (roomRevenues != null) {
|
||||
Optional<LaborStatsDto> any = roomRevenues.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
roomRevenue = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setRoomRevenue(roomRevenue);
|
||||
//非背包流水
|
||||
int roomNormalRevenue = 0;
|
||||
List<LaborStatsDto> roomNormalRevenues = roomNormalRevenueMap.get(dateStr);
|
||||
if (roomNormalRevenues != null) {
|
||||
Optional<LaborStatsDto> any = roomNormalRevenues.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
roomNormalRevenue = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setRoomNormalRevenue(roomNormalRevenue);
|
||||
//背包流水
|
||||
int roomBackpackRevenue = 0;
|
||||
List<LaborStatsDto> roomBackpackRevenues = roomBackpackRevenueMap.get(dateStr);
|
||||
if (roomBackpackRevenues != null) {
|
||||
Optional<LaborStatsDto> any = roomBackpackRevenues.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
roomBackpackRevenue = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setRoomBackpackRevenue(roomBackpackRevenue);
|
||||
stats.setFirstInRoomGiftRate(stats.getFirstInRoomGiftUser().doubleValue() / (stats.getFirstInRoom() > 0 ? stats.getFirstInRoom() : 1));
|
||||
//新用户进房人数
|
||||
int newUserInRoom = 0;
|
||||
List<LaborStatsDto> newUserInRooms = newUserInRoomMap.get(dateStr);
|
||||
if (newUserInRooms != null) {
|
||||
Optional<LaborStatsDto> any = newUserInRooms.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
newUserInRoom = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setNewUserInRoom(newUserInRoom);
|
||||
//新用户送礼人数
|
||||
int newUserSendGift = 0;
|
||||
List<LaborStatsDto> newUserSendGifts = newUserSendGiftMap.get(dateStr);
|
||||
if (newUserSendGifts != null) {
|
||||
Optional<LaborStatsDto> any = newUserSendGifts.stream().filter(v -> v.getRoomUid().equals(roomUid)).findAny();
|
||||
if (any.isPresent()) {
|
||||
newUserSendGift = any.get().getStatsCount();
|
||||
}
|
||||
}
|
||||
stats.setNewUserSendGift(newUserSendGift);
|
||||
data.add(stats);
|
||||
}
|
||||
dateTime = DateTimeUtil.addDays(dateTime, 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user