parent
684bf26ee5
commit
aada1a3649
@ -0,0 +1,67 @@
|
|||||||
|
package com.cyl.manager.statistics.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.cyl.manager.statistics.pojo.GoodsStatisticsQueryParam;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.MemberAndCartStatisticsVO;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.OrderAndAftersaleStatisticsVO;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.OrderStatisticsVO;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.ProductTopVO;
|
||||||
|
import com.cyl.manager.statistics.service.IndexStatisticsService;
|
||||||
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理端,首页统计数据接口
|
||||||
|
*
|
||||||
|
* @author zhangcheng
|
||||||
|
* @since 2023/05/15 13:53
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "管理端,首页统计数据接口")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/dev/statistics/index")
|
||||||
|
public class IndexStatisticsManagerController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首页统计
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private IndexStatisticsService indexStatisticsService;
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取首页查询热卖商品TOP10")
|
||||||
|
@GetMapping("/goodsStatistics")
|
||||||
|
public ResponseEntity<List<ProductTopVO>> goodsStatistics(@Validated GoodsStatisticsQueryParam goodsStatisticsQueryParam) {
|
||||||
|
|
||||||
|
return ResponseEntity.ok(indexStatisticsService.goodsStatistics(goodsStatisticsQueryParam));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "订单信息")
|
||||||
|
@GetMapping("/orderStatistics")
|
||||||
|
public ResponseEntity<List<OrderStatisticsVO>> orderStatistics() {
|
||||||
|
|
||||||
|
return ResponseEntity.ok(indexStatisticsService.orderStatistics());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "会员数,加购数")
|
||||||
|
@GetMapping("/memberAndCart/statistics")
|
||||||
|
public ResponseEntity<MemberAndCartStatisticsVO> statMemberAndCart(){
|
||||||
|
return ResponseEntity.ok(indexStatisticsService.statMemberAndCart());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "订单与售后单统计")
|
||||||
|
@GetMapping("/order/aftersale/statistics")
|
||||||
|
public ResponseEntity<OrderAndAftersaleStatisticsVO> orderAndAftersaleStatistics(){
|
||||||
|
return ResponseEntity.ok(indexStatisticsService.orderAndAftersaleStatistics());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.cyl.manager.statistics.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.cyl.manager.statistics.pojo.GoodsStatisticsQueryParam;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.OrderStatisticsVO;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.ProductTopVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IndexStatisticsMapper {
|
||||||
|
List<ProductTopVO> goodsSkuStatistics(GoodsStatisticsQueryParam goodsStatisticsQueryParam);
|
||||||
|
|
||||||
|
List<ProductTopVO> goodsStatistics(GoodsStatisticsQueryParam goodsStatisticsQueryParam);
|
||||||
|
List<OrderStatisticsVO> orderStatistics();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.cyl.manager.statistics.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MemberAndCartStatisticsVO {
|
||||||
|
private Integer memberCount;
|
||||||
|
private Integer cartCount;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package com.cyl.manager.statistics.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class OrderAndAftersaleStatisticsVO {
|
||||||
|
/** 待处理售后 */
|
||||||
|
private Integer pendingAftersaleCount;
|
||||||
|
/** 处理中售后 */
|
||||||
|
private Integer processingAftersaleCount;
|
||||||
|
/** 待发货 */
|
||||||
|
private Integer waitDeliveredCount;
|
||||||
|
/** 已发货 */
|
||||||
|
private Integer todayHasDeliveredCount;
|
||||||
|
/** 订单数 */
|
||||||
|
private Integer todayOrderCount;
|
||||||
|
/** 成交额 */
|
||||||
|
private BigDecimal todayTransactionAmount;
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.cyl.manager.statistics.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class OrderStatisticsVO {
|
||||||
|
|
||||||
|
private String date;
|
||||||
|
//订单笔数
|
||||||
|
private Double orderCount;
|
||||||
|
//订单金额
|
||||||
|
private Double orderAmount;
|
||||||
|
private Double numPaidOrders;
|
||||||
|
private Double numPendingOrders;
|
||||||
|
private Double numRefundOrders;
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package com.cyl.manager.statistics.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ProductTopVO {
|
||||||
|
|
||||||
|
private String productName;
|
||||||
|
private int totalSales;
|
||||||
|
private String pic;
|
||||||
|
private String spData;
|
||||||
|
}
|
||||||
@ -0,0 +1,79 @@
|
|||||||
|
package com.cyl.manager.statistics.service;
|
||||||
|
|
||||||
|
import com.cyl.manager.oms.mapper.AftersaleMapper;
|
||||||
|
import com.cyl.manager.oms.mapper.OrderMapper;
|
||||||
|
import com.cyl.manager.oms.service.AftersaleService;
|
||||||
|
import com.cyl.manager.oms.service.OrderDeliveryHistoryService;
|
||||||
|
import com.cyl.manager.oms.service.OrderService;
|
||||||
|
import com.cyl.manager.statistics.mapper.IndexStatisticsMapper;
|
||||||
|
import com.cyl.manager.statistics.pojo.GoodsStatisticsQueryParam;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.MemberAndCartStatisticsVO;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.OrderAndAftersaleStatisticsVO;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.OrderStatisticsVO;
|
||||||
|
import com.cyl.manager.statistics.pojo.vo.ProductTopVO;
|
||||||
|
import com.cyl.manager.ums.mapper.MemberCartMapper;
|
||||||
|
import com.cyl.manager.ums.mapper.MemberMapper;
|
||||||
|
import com.cyl.manager.ums.service.MemberService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理端,首页统计数据Service业务层处理
|
||||||
|
*
|
||||||
|
* @author zhangcheng
|
||||||
|
* @since 2023/05/15 13:53
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class IndexStatisticsService {
|
||||||
|
@Autowired
|
||||||
|
private IndexStatisticsMapper indexStatisticsMapper;
|
||||||
|
@Autowired
|
||||||
|
private MemberMapper memberMapper;
|
||||||
|
@Autowired
|
||||||
|
private MemberCartMapper memberCartMapper;
|
||||||
|
@Autowired
|
||||||
|
private AftersaleMapper aftersaleMapper;
|
||||||
|
@Autowired
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
|
|
||||||
|
public List<ProductTopVO> goodsStatistics(GoodsStatisticsQueryParam goodsStatisticsQueryParam) {
|
||||||
|
if (goodsStatisticsQueryParam.getStatType() == 1){
|
||||||
|
return indexStatisticsMapper.goodsSkuStatistics(goodsStatisticsQueryParam);
|
||||||
|
}else {
|
||||||
|
return indexStatisticsMapper.goodsStatistics(goodsStatisticsQueryParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderStatisticsVO> orderStatistics() {
|
||||||
|
return indexStatisticsMapper.orderStatistics();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberAndCartStatisticsVO statMemberAndCart() {
|
||||||
|
MemberAndCartStatisticsVO vo = new MemberAndCartStatisticsVO();
|
||||||
|
vo.setMemberCount(memberMapper.selectCount(null));
|
||||||
|
vo.setCartCount(memberCartMapper.selectCount(null));
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderAndAftersaleStatisticsVO orderAndAftersaleStatistics() {
|
||||||
|
//统计售后
|
||||||
|
OrderAndAftersaleStatisticsVO vo = aftersaleMapper.statPendingAndProcessing();
|
||||||
|
//统计未发货数
|
||||||
|
vo.setWaitDeliveredCount(orderMapper.statWaitDelivered());
|
||||||
|
//统计今日订单数,成交金额,发货数
|
||||||
|
LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
|
||||||
|
LocalDateTime endTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
|
||||||
|
OrderAndAftersaleStatisticsVO todayData = orderMapper.statTodayData(startTime, endTime);
|
||||||
|
vo.setTodayOrderCount(todayData.getTodayOrderCount());
|
||||||
|
vo.setTodayHasDeliveredCount(todayData.getTodayHasDeliveredCount());
|
||||||
|
vo.setTodayTransactionAmount(todayData.getTodayTransactionAmount());
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.cyl.manager.statistics.mapper.IndexStatisticsMapper">
|
||||||
|
<sql id="dateRange">
|
||||||
|
SELECT
|
||||||
|
curdate( ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 1 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 2 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 3 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 4 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 5 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 6 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 7 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 8 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 9 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 10 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 11 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 12 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 13 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 14 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 15 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 16 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 17 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 18 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 19 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 20 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 21 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 22 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 23 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 24 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 25 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 26 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 27 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 28 DAY ) AS date UNION ALL
|
||||||
|
SELECT date_sub( curdate( ), INTERVAL 29 DAY ) AS date
|
||||||
|
</sql>
|
||||||
|
<resultMap id="topSalesResultMap" type="com.cyl.manager.statistics.pojo.vo.ProductTopVO">
|
||||||
|
<result property="productName" column="product_name"/>
|
||||||
|
<result property="totalSales" column="total_sales"/>
|
||||||
|
<result property="pic" column="pic"/>
|
||||||
|
<result property="spData" column="sp_data"/>
|
||||||
|
</resultMap>
|
||||||
|
<select id="goodsStatistics" parameterType="com.cyl.manager.statistics.pojo.GoodsStatisticsQueryParam" resultMap="topSalesResultMap">
|
||||||
|
SELECT product_id ,
|
||||||
|
product_name,
|
||||||
|
pic,
|
||||||
|
SUM(quantity) as total_sales
|
||||||
|
FROM oms_order_item item right join oms_order o on o.id=item.order_id
|
||||||
|
WHERE DATE(item.create_time) between DATE(#{startDate}) AND DATE(#{endDate}) AND o.status in(1,2,3)
|
||||||
|
GROUP BY product_id, product_name
|
||||||
|
ORDER BY total_sales DESC
|
||||||
|
LIMIT #{size}
|
||||||
|
</select>
|
||||||
|
<select id="orderStatistics" resultType="com.cyl.manager.statistics.pojo.vo.OrderStatisticsVO">
|
||||||
|
select a.date,
|
||||||
|
IFNULL(b.order_count,0) orderCount,
|
||||||
|
IFNULL(b.order_amount,0) orderAmount
|
||||||
|
from
|
||||||
|
(
|
||||||
|
<include refid="dateRange"></include>
|
||||||
|
) a
|
||||||
|
left join (
|
||||||
|
SELECT DATE_FORMAT(create_time, '%Y-%m-%d') as date,
|
||||||
|
COUNT(*) as order_count,
|
||||||
|
SUM(total_amount) as order_amount
|
||||||
|
FROM oms_order
|
||||||
|
WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND status in(1,2,3)
|
||||||
|
GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')
|
||||||
|
) b
|
||||||
|
on a.date=b.date
|
||||||
|
order by a.date asc
|
||||||
|
</select>
|
||||||
|
<select id="goodsSkuStatistics" resultMap="topSalesResultMap">
|
||||||
|
SELECT product_id ,
|
||||||
|
product_name,
|
||||||
|
pic,
|
||||||
|
sp_data,
|
||||||
|
SUM(quantity) as total_sales
|
||||||
|
FROM oms_order_item item right join oms_order o on o.id=item.order_id
|
||||||
|
WHERE DATE(item.create_time) between DATE(#{startDate}) AND DATE(#{endDate}) AND o.status in(1,2,3)
|
||||||
|
GROUP BY sku_id
|
||||||
|
ORDER BY total_sales DESC
|
||||||
|
LIMIT #{size}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in new issue