| | |
| | | import com.mzl.flower.dto.request.flower.FlowerQueryDTO; |
| | | import com.mzl.flower.dto.request.payment.OrderItemSalesQueryDTO; |
| | | import com.mzl.flower.dto.request.payment.OrderQueryDTO; |
| | | import com.mzl.flower.dto.response.flower.FlowerListDTO; |
| | | import com.mzl.flower.dto.response.statistics.FlowerStatisticsDTO; |
| | | import com.mzl.flower.dto.response.statistics.OrderStatisticsDTO; |
| | | import com.mzl.flower.dto.response.statistics.RateStatisticsDTO; |
| | | import com.mzl.flower.dto.response.statistics.SaleStatisticsDTO; |
| | | import com.mzl.flower.entity.customer.Customer; |
| | | import com.mzl.flower.entity.payment.Order; |
| | | import com.mzl.flower.entity.supplier.Supplier; |
| | | import com.mzl.flower.mapper.customer.CustomerMapper; |
| | | import com.mzl.flower.mapper.flower.FlowerMapper; |
| | | import com.mzl.flower.mapper.payment.*; |
| | | import com.mzl.flower.mapper.supplier.SupplierMapper; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | |
| | | @Autowired |
| | | private OrderItemSalesMapper orderItemSalesMapper; |
| | | |
| | | @Autowired |
| | | private CustomerMapper customerMapper; |
| | | |
| | | public SaleStatisticsDTO getSaleStatistics(String date){ |
| | | if(StringUtils.isEmpty(date)){ |
| | | throw new ValidationException("日期不能为空"); |
| | |
| | | LocalDateTime begin = end.plusDays(-1); |
| | | |
| | | SaleStatisticsDTO dto = new SaleStatisticsDTO(); |
| | | BigDecimal a = orderMapper.getOrderSaleAmount(begin, end); |
| | | Integer c = orderItemMapper.getFlowerSaleNum(begin, end); |
| | | BigDecimal a = orderMapper.getOrderSaleAmount(begin, end);//今日销售额:今日全部的实际支付金额合计 |
| | | Integer c = orderItemMapper.getFlowerSaleNum(begin, end);//今日销售扎数:今日成功交易的订单的成交数量 |
| | | |
| | | dto.setSaleAmount(a); |
| | | dto.setSaleFlowerCount(c == null ? 0 : c.longValue()); |
| | |
| | | statusList.add(Constants.FLOWER_STATUS.FORCE_OFF.name()); |
| | | q.setStatusList(statusList); |
| | | flowerMapper.selectFlowerList(page, q); |
| | | dto.setFlowerCount(page.getTotal()); |
| | | dto.setFlowerCount(page.getTotal());//商品管理:待审核+上架+下架(点击跳转到商品列表) |
| | | |
| | | Integer sc = supplierMapper.selectCount(new QueryWrapper<Supplier>() |
| | | .eq("is_enabled", 1) |
| | | .eq("status", "P") |
| | | .eq("deleted", 0)); |
| | | dto.setSupplierCount(sc.longValue()); |
| | | dto.setSupplierCount(sc.longValue());//用户管理:统计商户列表已启用的全部用户(点击跳转到商户列表) |
| | | |
| | | Integer oc = orderMapper.selectCount(new QueryWrapper<Order>() |
| | | .eq("deleted", 0) |
| | | .isNotNull("payment_time") |
| | | .isNull("cancel_time") |
| | | .isNull("refund_time")); |
| | | dto.setOrderCount(oc.longValue()); |
| | | dto.setOrderCount(oc.longValue());//订单管理:全部订单数量-待付款-已取消-已退款(点击跳转到订单列表) |
| | | |
| | | page = new Page(1, 1); |
| | | OrderQueryDTO oq = new OrderQueryDTO(); |
| | | oq.setStatusBackend(Constants.ORDER_STATUS_BACKEND.SEND.name()); |
| | | orderMapper.selectOrderList(page, oq); |
| | | dto.setOrderSendCount(page.getTotal()); |
| | | dto.setOrderSendCount(page.getTotal());//待发货:统计订单列表待发货的数量(点击跳转到订单列表-待发货页面) |
| | | |
| | | page = new Page(1, 1); |
| | | q = new FlowerQueryDTO(); |
| | |
| | | statusList.add(Constants.FLOWER_STATUS.UP.name()); |
| | | q.setStatusList(statusList); |
| | | flowerMapper.selectFlowerList(page, q); |
| | | dto.setFlowerUpCount(page.getTotal()); |
| | | dto.setFlowerUpCount(page.getTotal());//在售商品:统计商品列表上架的商品数量(点击跳转到商品列表-上架页面) |
| | | |
| | | page = new Page(1, 1); |
| | | q = new FlowerQueryDTO(); |
| | |
| | | statusList.add(Constants.FLOWER_STATUS.PENDING.name()); |
| | | q.setStatusList(statusList); |
| | | flowerMapper.selectFlowerList(page, q); |
| | | dto.setFlowerPendingCount(page.getTotal()); |
| | | dto.setFlowerPendingCount(page.getTotal());//待审核商品:跳转到商品列表-待审核页面 |
| | | |
| | | page = new Page(1, 1); |
| | | OrderItemSalesQueryDTO sq = new OrderItemSalesQueryDTO(); |
| | | sq.setStatus(Constants.ORDER_SALES_STATUS.PENDING.name()); |
| | | sq.setStatusList(splitParam(sq.getStatus())); |
| | | orderItemSalesMapper.selectItemSalesList(page, sq); |
| | | dto.setOrderSalesCount(page.getTotal()); |
| | | dto.setOrderSalesCount(page.getTotal());//待售后处理:统计售后理赔-待审核的数量(跳转到售后理赔-待审核页面) |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | public OrderStatisticsDTO getOrderStatistics(){ |
| | | OrderStatisticsDTO dto = new OrderStatisticsDTO(); |
| | | BigDecimal a = orderMapper.getOrderSaleAmount(null, null); |
| | | Integer c = orderItemMapper.getFlowerSaleNum(null, null); |
| | | BigDecimal a = orderMapper.getOrderSaleAmount(null, null);//总销售金额:全部有效订单的实际支付金额合计 |
| | | Integer c = orderItemMapper.getFlowerSaleNum(null, null);//总销售扎数:成功交易订单的成交数量 |
| | | dto.setTotalSaleAmount(a); |
| | | dto.setTotalSaleFlowerCount(c == null ? 0 : c.longValue()); |
| | | |
| | |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | public RateStatisticsDTO getOrderRateStatistics(String date){ |
| | | if(StringUtils.isEmpty(date)){ |
| | | throw new ValidationException("日期不能为空"); |
| | | } |
| | | LocalDate localDate = parseLocalDate(date); |
| | | if(localDate == null){ |
| | | throw new ValidationException("日期无效"); |
| | | } |
| | | |
| | | LocalDateTime end = localDate.atTime(17, 0, 0); |
| | | LocalDateTime begin = end.plusDays(-1); |
| | | |
| | | LocalDateTime endY = begin; |
| | | LocalDateTime beginY = endY.plusDays(-1); |
| | | |
| | | RateStatisticsDTO dto = new RateStatisticsDTO(); |
| | | |
| | | //订单量:与订单管理一致(并计算新增量,计算日环比) |
| | | Integer oc = orderMapper.selectCount(new QueryWrapper<Order>() |
| | | .eq("deleted", 0) |
| | | .isNotNull("payment_time") |
| | | .isNull("cancel_time") |
| | | .isNull("refund_time")); |
| | | dto.setCount(oc.longValue()); |
| | | |
| | | Integer ocToday = orderMapper.selectCount(new QueryWrapper<Order>() |
| | | .eq("deleted", 0) |
| | | .isNotNull("payment_time") |
| | | .isNull("cancel_time") |
| | | .isNull("refund_time") |
| | | .gt("create_time", begin) |
| | | .le("create_time", end) |
| | | ); |
| | | dto.setCountToday(ocToday.longValue()); |
| | | |
| | | Integer ocY = orderMapper.selectCount(new QueryWrapper<Order>() |
| | | .eq("deleted", 0) |
| | | .isNotNull("payment_time") |
| | | .isNull("cancel_time") |
| | | .isNull("refund_time") |
| | | .gt("create_time", beginY) |
| | | .le("create_time", endY) |
| | | ); |
| | | dto.setCountRate(getRate(ocToday, ocY)); |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | public RateStatisticsDTO getSupplierRateStatistics(String date) { |
| | | if (StringUtils.isEmpty(date)) { |
| | | throw new ValidationException("日期不能为空"); |
| | | } |
| | | LocalDate localDate = parseLocalDate(date); |
| | | if (localDate == null) { |
| | | throw new ValidationException("日期无效"); |
| | | } |
| | | |
| | | LocalDateTime end = localDate.atTime(23, 59, 59); |
| | | LocalDateTime begin = localDate.atTime(0, 0, 0); |
| | | |
| | | LocalDateTime endY = end.plusDays(-1); |
| | | LocalDateTime beginY = begin.plusDays(-1); |
| | | |
| | | RateStatisticsDTO dto = new RateStatisticsDTO(); |
| | | |
| | | //供应商数量:已启用的供应商数量(并计算新增量,计算日环比) |
| | | Integer sc = supplierMapper.selectCount(new QueryWrapper<Supplier>() |
| | | .eq("is_enabled", 1) |
| | | .eq("status", "P") |
| | | .eq("deleted", 0)); |
| | | dto.setCount(sc.longValue()); |
| | | |
| | | Integer scT = supplierMapper.selectCount(new QueryWrapper<Supplier>() |
| | | .eq("is_enabled", 1) |
| | | .eq("status", "P") |
| | | .eq("deleted", 0) |
| | | .gt("create_time", begin) |
| | | .le("create_time", end) |
| | | ); |
| | | dto.setCountToday(scT.longValue()); |
| | | |
| | | Integer scY = supplierMapper.selectCount(new QueryWrapper<Supplier>() |
| | | .eq("is_enabled", 1) |
| | | .eq("status", "P") |
| | | .eq("deleted", 0) |
| | | .gt("create_time", beginY) |
| | | .le("create_time", endY) |
| | | ); |
| | | dto.setCountRate(getRate(scT, scY)); |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | public RateStatisticsDTO getCustomerRateStatistics(String date) { |
| | | if (StringUtils.isEmpty(date)) { |
| | | throw new ValidationException("日期不能为空"); |
| | | } |
| | | LocalDate localDate = parseLocalDate(date); |
| | | if (localDate == null) { |
| | | throw new ValidationException("日期无效"); |
| | | } |
| | | |
| | | LocalDateTime end = localDate.atTime(23, 59, 59); |
| | | LocalDateTime begin = localDate.atTime(0, 0, 0); |
| | | |
| | | LocalDateTime endY = end.plusDays(-1); |
| | | LocalDateTime beginY = begin.plusDays(-1); |
| | | |
| | | RateStatisticsDTO dto = new RateStatisticsDTO(); |
| | | //全部用户量:已启用的用户数量合计(并计算新增量,计算日环比) |
| | | |
| | | Integer c = customerMapper.selectCount(new QueryWrapper<Customer>() |
| | | .eq("deleted", 0)); |
| | | dto.setCount(c.longValue()); |
| | | |
| | | Integer cT = customerMapper.selectCount(new QueryWrapper<Customer>() |
| | | .eq("deleted", 0) |
| | | .gt("create_time", begin) |
| | | .le("create_time", end) |
| | | ); |
| | | dto.setCountToday(cT.longValue()); |
| | | |
| | | Integer cY = customerMapper.selectCount(new QueryWrapper<Customer>() |
| | | .eq("deleted", 0) |
| | | .gt("create_time", beginY) |
| | | .le("create_time", endY) |
| | | ); |
| | | dto.setCountRate(getRate(cT, cY)); |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | public RateStatisticsDTO getCustomerVisitRateStatistics(String date) { |
| | | if (StringUtils.isEmpty(date)) { |
| | | throw new ValidationException("日期不能为空"); |
| | | } |
| | | LocalDate localDate = parseLocalDate(date); |
| | | if (localDate == null) { |
| | | throw new ValidationException("日期无效"); |
| | | } |
| | | |
| | | LocalDateTime end = localDate.atTime(23, 59, 59); |
| | | LocalDateTime begin = localDate.atTime(0, 0, 0); |
| | | |
| | | LocalDateTime endY = end.plusDays(-1); |
| | | LocalDateTime beginY = begin.plusDays(-1); |
| | | |
| | | RateStatisticsDTO dto = new RateStatisticsDTO(); |
| | | //TODO 用户访问量:点击到交易大厅或者商品详情页面计算,同一个用户,每天只计算一次(包含游客)(并计算新增量,计算日环比) |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | public RateStatisticsDTO getSalesRateStatistics(String date) { |
| | | if (StringUtils.isEmpty(date)) { |
| | | throw new ValidationException("日期不能为空"); |
| | | } |
| | | LocalDate localDate = parseLocalDate(date); |
| | | if (localDate == null) { |
| | | throw new ValidationException("日期无效"); |
| | | } |
| | | |
| | | LocalDateTime end = localDate.atTime(23, 59, 59); |
| | | LocalDateTime begin = localDate.atTime(0, 0, 0); |
| | | |
| | | LocalDateTime endY = end.plusDays(-1); |
| | | LocalDateTime beginY = begin.plusDays(-1); |
| | | |
| | | RateStatisticsDTO dto = new RateStatisticsDTO(); |
| | | //售后订单数量:统计待审核+已通过(并计算新增量,计算日环比) |
| | | |
| | | List<String> statusList = new ArrayList<>(); |
| | | statusList.add(Constants.ORDER_SALES_STATUS.PENDING.name()); |
| | | statusList.add(Constants.ORDER_SALES_STATUS.AGREED.name()); |
| | | |
| | | Page page = new Page(1, 1); |
| | | OrderItemSalesQueryDTO sq = new OrderItemSalesQueryDTO(); |
| | | sq.setStatusList(statusList); |
| | | orderItemSalesMapper.selectItemSalesList(page, sq); |
| | | dto.setCount(page.getTotal()); |
| | | |
| | | page = new Page(1, 1); |
| | | sq = new OrderItemSalesQueryDTO(); |
| | | sq.setStatusList(statusList); |
| | | sq.setSalesStartDate(begin); |
| | | sq.setSalesStartDate(end); |
| | | orderItemSalesMapper.selectItemSalesList(page, sq); |
| | | dto.setCountToday(page.getTotal()); |
| | | |
| | | page = new Page(1, 1); |
| | | sq = new OrderItemSalesQueryDTO(); |
| | | sq.setStatusList(statusList); |
| | | sq.setSalesStartDate(beginY); |
| | | sq.setSalesStartDate(endY); |
| | | orderItemSalesMapper.selectItemSalesList(page, sq); |
| | | dto.setCountRate(getRate(dto.getCountToday().intValue(), (int)page.getTotal())); |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | private Double getRate(Integer today, Integer yesterday){ |
| | | if(yesterday > 0){ |
| | | Integer ty = today - yesterday; |
| | | BigDecimal ttyy = BigDecimal.valueOf(ty); |
| | | BigDecimal yy = BigDecimal.valueOf(yesterday); |
| | | BigDecimal rate = ttyy.divide(yy, 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); |
| | | return rate.doubleValue(); |
| | | } |
| | | |
| | | return 100D; |
| | | } |
| | | } |