|
|
@@ -24,7 +24,11 @@ import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.course.domain.FsUserCompanyUser;
|
|
|
import com.fs.course.mapper.FsUserCompanyUserMapper;
|
|
|
import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
+import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStoreOrderItemScrmMapper;
|
|
|
+import com.fs.hisStore.vo.FsStoreOrderItemVO;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
|
|
@@ -92,7 +96,9 @@ public class LiveDataServiceImpl implements ILiveDataService {
|
|
|
@Autowired
|
|
|
private CompanyUserMapper companyUserMapper;
|
|
|
@Autowired
|
|
|
- private LiveOrderMapper liveOrderMapper;
|
|
|
+ private FsStoreOrderScrmMapper fsStoreOrderScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsStoreOrderItemScrmMapper fsStoreOrderItemScrmMapper;
|
|
|
|
|
|
/* 直播大屏展示 数据接口 */
|
|
|
@Override
|
|
|
@@ -1139,36 +1145,29 @@ public class LiveDataServiceImpl implements ILiveDataService {
|
|
|
detailVo.setLivePeak(liveData.getPeakConcurrentViewers());
|
|
|
}
|
|
|
|
|
|
- // 查询订单数据
|
|
|
- LiveOrderMapper liveOrderMapper = SpringUtils.getBean(LiveOrderMapper.class);
|
|
|
- LiveOrder orderQuery = new LiveOrder();
|
|
|
- orderQuery.setLiveId(liveId);
|
|
|
- List<LiveOrder> orders = liveOrderMapper.selectLiveOrderList(orderQuery);
|
|
|
+ // 查询订单数据(fs_store_order_scrm,order_type=2,remark=liveId)
|
|
|
+ FsStoreOrderScrm orderQuery = new FsStoreOrderScrm();
|
|
|
+ orderQuery.setOrderType(2);
|
|
|
+ orderQuery.setRemark(String.valueOf(liveId));
|
|
|
+ List<FsStoreOrderScrm> orders = fsStoreOrderScrmMapper.selectFsStoreOrderList(orderQuery);
|
|
|
|
|
|
BigDecimal gmv = orders.stream()
|
|
|
- .filter(o -> "1".equals(o.getIsPay()))
|
|
|
- .map(LiveOrder::getPayPrice)
|
|
|
+ .filter(o -> o.getPaid() != null && (o.getPaid() == 1 || "1".equals(String.valueOf(o.getPaid()))))
|
|
|
+ .map(FsStoreOrderScrm::getPayPrice)
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
detailVo.setGmv(gmv);
|
|
|
|
|
|
long paidUsers = orders.stream()
|
|
|
- .filter(o -> "1".equals(o.getIsPay()))
|
|
|
- .filter(o -> o.getUserId() != null && !o.getUserId().isEmpty())
|
|
|
- .map(o -> {
|
|
|
- try {
|
|
|
- return Long.parseLong(o.getUserId());
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- })
|
|
|
- .filter(Objects::nonNull)
|
|
|
+ .filter(o -> o.getPaid() != null && (o.getPaid() == 1 || "1".equals(String.valueOf(o.getPaid()))))
|
|
|
+ .filter(o -> o.getUserId() != null)
|
|
|
+ .map(FsStoreOrderScrm::getUserId)
|
|
|
.distinct()
|
|
|
.count();
|
|
|
detailVo.setPaidUsers(paidUsers);
|
|
|
|
|
|
long paidOrders = orders.stream()
|
|
|
- .filter(o -> "1".equals(o.getIsPay()))
|
|
|
+ .filter(o -> o.getPaid() != null && (o.getPaid() == 1 || "1".equals(String.valueOf(o.getPaid()))))
|
|
|
.count();
|
|
|
detailVo.setPaidOrders(paidOrders);
|
|
|
|
|
|
@@ -1200,9 +1199,11 @@ public class LiveDataServiceImpl implements ILiveDataService {
|
|
|
// 查询观看用户
|
|
|
List<LiveWatchUser> watchUsers = liveWatchUserMapper.selectLiveWatchUserListByLiveId(liveId);
|
|
|
|
|
|
- LiveOrder orderQuery = new LiveOrder();
|
|
|
- orderQuery.setLiveId(liveId);
|
|
|
- List<LiveOrder> orders = liveOrderMapper.selectLiveOrderList(orderQuery);
|
|
|
+ // 查询订单数据(fs_store_order_scrm,order_type=2,remark=liveId)
|
|
|
+ FsStoreOrderScrm orderQuery = new FsStoreOrderScrm();
|
|
|
+ orderQuery.setOrderType(2);
|
|
|
+ orderQuery.setRemark(String.valueOf(liveId));
|
|
|
+ List<FsStoreOrderScrm> orders = fsStoreOrderScrmMapper.selectFsStoreOrderList(orderQuery);
|
|
|
|
|
|
|
|
|
// 按用户ID分组统计
|
|
|
@@ -1254,28 +1255,15 @@ public class LiveDataServiceImpl implements ILiveDataService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 统计订单数据
|
|
|
- Map<Long, List<LiveOrder>> userOrdersMap = orders.stream()
|
|
|
- .filter(o -> o.getUserId() != null && !o.getUserId().isEmpty())
|
|
|
- .filter(o -> {
|
|
|
- try {
|
|
|
- Long.parseLong(o.getUserId());
|
|
|
- return true;
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- })
|
|
|
- .collect(Collectors.groupingBy(o -> {
|
|
|
- try {
|
|
|
- return Long.parseLong(o.getUserId());
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- return 0L;
|
|
|
- }
|
|
|
- }));
|
|
|
+ // 统计订单数据(仅已支付订单)
|
|
|
+ Map<Long, List<FsStoreOrderScrm>> userOrdersMap = orders.stream()
|
|
|
+ .filter(o -> o.getUserId() != null)
|
|
|
+ .filter(o -> o.getPaid() != null && (o.getPaid() == 1 || "1".equals(String.valueOf(o.getPaid()))))
|
|
|
+ .collect(Collectors.groupingBy(FsStoreOrderScrm::getUserId));
|
|
|
|
|
|
- for (Map.Entry<Long, List<LiveOrder>> entry : userOrdersMap.entrySet()) {
|
|
|
+ for (Map.Entry<Long, List<FsStoreOrderScrm>> entry : userOrdersMap.entrySet()) {
|
|
|
Long userId = entry.getKey();
|
|
|
- List<LiveOrder> userOrders = entry.getValue();
|
|
|
+ List<FsStoreOrderScrm> userOrders = entry.getValue();
|
|
|
|
|
|
LiveUserDetailVo userDetail = userDetailMap.computeIfAbsent(userId, k -> {
|
|
|
LiveUserDetailVo vo = new LiveUserDetailVo();
|
|
|
@@ -1310,8 +1298,7 @@ public class LiveDataServiceImpl implements ILiveDataService {
|
|
|
|
|
|
userDetail.setOrderCount((long) userOrders.size());
|
|
|
BigDecimal orderAmount = userOrders.stream()
|
|
|
- .filter(o -> "1".equals(o.getIsPay()))
|
|
|
- .map(LiveOrder::getPayPrice)
|
|
|
+ .map(FsStoreOrderScrm::getPayPrice)
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
userDetail.setOrderAmount(orderAmount);
|
|
|
@@ -1329,37 +1316,50 @@ public class LiveDataServiceImpl implements ILiveDataService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查询单品销量统计
|
|
|
+ * 查询单品销量统计(从 fs_store_order_scrm,order_type=2,remark=liveId,按订单明细汇总)
|
|
|
*/
|
|
|
private List<ProductSalesVo> getProductSalesList(Long liveId) {
|
|
|
-
|
|
|
- List<LiveOrder> orders = liveOrderMapper.selectOrderByLiveId(liveId);
|
|
|
+ FsStoreOrderScrm orderQuery = new FsStoreOrderScrm();
|
|
|
+ orderQuery.setOrderType(2);
|
|
|
+ orderQuery.setRemark(String.valueOf(liveId));
|
|
|
+ List<FsStoreOrderScrm> orders = fsStoreOrderScrmMapper.selectFsStoreOrderList(orderQuery);
|
|
|
|
|
|
// 按商品ID分组统计
|
|
|
Map<Long, ProductSalesVo> productSalesMap = new HashMap<>();
|
|
|
|
|
|
- for (LiveOrder order : orders) {
|
|
|
- if (!"1".equals(order.getIsPay()) || order.getProductId() == null) {
|
|
|
+ for (FsStoreOrderScrm order : orders) {
|
|
|
+ if (order.getPaid() == null || (order.getPaid() != 1 && !"1".equals(String.valueOf(order.getPaid())))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<FsStoreOrderItemVO> items = fsStoreOrderItemScrmMapper.selectFsStoreOrderItemListByOrderId(order.getId());
|
|
|
+ if (items == null || items.isEmpty()) {
|
|
|
continue;
|
|
|
}
|
|
|
+ long totalNum = order.getTotalNum() != null && order.getTotalNum() > 0 ? order.getTotalNum() : 1;
|
|
|
+ BigDecimal orderPayPrice = order.getPayPrice() != null ? order.getPayPrice() : BigDecimal.ZERO;
|
|
|
|
|
|
- ProductSalesVo productSales = productSalesMap.computeIfAbsent(order.getProductId(), k -> {
|
|
|
- ProductSalesVo vo = new ProductSalesVo();
|
|
|
- vo.setProductId(order.getProductId());
|
|
|
- // 查询商品名称
|
|
|
- FsStoreProductScrmMapper productMapper = SpringUtils.getBean(FsStoreProductScrmMapper.class);
|
|
|
- FsStoreProductScrm product = productMapper.selectFsStoreProductById(order.getProductId());
|
|
|
- if (product != null) {
|
|
|
- vo.setProductName(product.getProductName());
|
|
|
- } else {
|
|
|
- vo.setProductName("未知商品");
|
|
|
+ for (FsStoreOrderItemVO item : items) {
|
|
|
+ if (item.getProductId() == null) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- return vo;
|
|
|
- });
|
|
|
+ long itemNum = item.getNum() != null ? item.getNum() : 0;
|
|
|
+ BigDecimal itemAmount = totalNum > 0 ? orderPayPrice.multiply(BigDecimal.valueOf(itemNum)).divide(BigDecimal.valueOf(totalNum), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
|
|
+
|
|
|
+ ProductSalesVo productSales = productSalesMap.computeIfAbsent(item.getProductId(), k -> {
|
|
|
+ ProductSalesVo vo = new ProductSalesVo();
|
|
|
+ vo.setProductId(item.getProductId());
|
|
|
+ FsStoreProductScrmMapper productMapper = SpringUtils.getBean(FsStoreProductScrmMapper.class);
|
|
|
+ FsStoreProductScrm product = productMapper.selectFsStoreProductById(item.getProductId());
|
|
|
+ if (product != null) {
|
|
|
+ vo.setProductName(product.getProductName());
|
|
|
+ } else {
|
|
|
+ vo.setProductName("未知商品");
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ });
|
|
|
|
|
|
- productSales.setSalesCount(productSales.getSalesCount() + 1);
|
|
|
- if (order.getPayPrice() != null) {
|
|
|
- productSales.setSalesAmount(productSales.getSalesAmount().add(order.getPayPrice()));
|
|
|
+ productSales.setSalesCount(productSales.getSalesCount() + itemNum);
|
|
|
+ productSales.setSalesAmount(productSales.getSalesAmount().add(itemAmount));
|
|
|
}
|
|
|
}
|
|
|
|