feat(shop): 添加统计功能以获取商店、商品、订单等数据

新增统计功能,用于获取商店数量、商品数量、订单数量、柜子数量、格口数量、已关联格口数量、未管理格口数量、网关数量等数据,并支持获取热门商品和今日最新订单商品信息。
This commit is contained in:
dzq 2025-05-20 11:00:08 +08:00
parent 97bf45987f
commit ca858ba62b
28 changed files with 294 additions and 4 deletions

View File

@ -5,12 +5,19 @@ import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import com.agileboot.domain.cabinet.cell.CabinetCellApplicationService;
import com.agileboot.domain.cabinet.smartCabinet.SmartCabinetApplicationService;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.mqtt.MqttService;
import com.agileboot.domain.shop.goods.GoodsApplicationService;
import com.agileboot.domain.shop.order.OrderApplicationService;
import com.agileboot.domain.shop.order.db.TodayLatestOrderGoodsDTO;
import com.agileboot.domain.shop.shop.ShopApplicationService;
import com.agileboot.domain.shop.shop.command.AddShopCommand;
import com.agileboot.domain.shop.shop.command.UpdateShopCommand;
import com.agileboot.domain.shop.shop.db.ShopEntity;
import com.agileboot.domain.shop.shop.dto.ShopDTO;
import com.agileboot.domain.shop.shop.dto.StatsDTO;
import com.agileboot.domain.shop.shop.query.SearchShopQuery;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
@ -33,6 +40,34 @@ import org.springframework.web.bind.annotation.RestController;
public class ShopController extends BaseController {
private final ShopApplicationService shopApplicationService;
private final GoodsApplicationService goodsApplicationService;
private final OrderApplicationService orderApplicationService;
private final SmartCabinetApplicationService smartCabinetApplicationService;
private final CabinetCellApplicationService cabinetCellApplicationService;
private final MqttService mqttService;
@Operation(summary = "首页数据")
@GetMapping("/Stats")
public ResponseDTO<StatsDTO> stats() {
StatsDTO statsDTO = new StatsDTO();
statsDTO.setShopCount(shopApplicationService.countAllRecord());
statsDTO.setGoodsCount(goodsApplicationService.countAllRecord());
statsDTO.setOrderCount(orderApplicationService.countAllRecord());
statsDTO.setCabinetCount(smartCabinetApplicationService.countAllRecord());
statsDTO.setCellCount(cabinetCellApplicationService.countAllRecord());
statsDTO.setLinkedCellCount(cabinetCellApplicationService.countLinkedRecord());
statsDTO.setUnmanagedCellCount(statsDTO.getCellCount() - statsDTO.getLinkedCellCount());
statsDTO.setGatewayCount(mqttService.getGatewayCount());
statsDTO.setTopGoods(orderApplicationService.selectTopGoodsByOccurrence());
List<TodayLatestOrderGoodsDTO> todayLatestOrderGoodsDTOS = orderApplicationService.selectTodayLatestOrderGoods();
todayLatestOrderGoodsDTOS.forEach(dto -> {
if (dto.getCreateTime() != null) {
dto.setCreateTimeStr(cn.hutool.core.date.DateUtil.format(dto.getCreateTime(), "HH:mm:ss"));
}
});
statsDTO.setTodayLatestOrderGoods(todayLatestOrderGoodsDTOS);
return ResponseDTO.ok(statsDTO);
}
@Operation(summary = "商店列表")
@GetMapping

View File

@ -104,4 +104,12 @@ public class CabinetCellApplicationService {
public void clearGoodsCells(Long cellId) {
cabinetCellService.clearGoodsIdAndFreeCell(cellId);
}
public Long countAllRecord() {
return cabinetCellService.countAllRecord();
}
public Long countLinkedRecord() {
return cabinetCellService.countLinkedRecord();
}
}

View File

@ -61,4 +61,9 @@ public interface CabinetCellMapper extends BaseMapper<CabinetCellEntity> {
@Param(Constants.WRAPPER) Wrapper<CabinetCellEntity> queryWrapper
);
@Select("SELECT COUNT(1) FROM cabinet_cell WHERE deleted = 0")
Long countAllRecord();
@Select("SELECT COUNT(1) FROM cabinet_cell WHERE deleted = 0 AND goods_id IS NOT NULL")
Long countLinkedRecord();
}

View File

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@ -30,4 +31,8 @@ public interface CabinetCellService extends IService<CabinetCellEntity> {
void clearGoodsIdAndFreeCell(Long cellId);
Page<CabinetCellWithOrderCountDTO> getCellListWithOrders(AbstractPageQuery<CabinetCellEntity> query);
Long countAllRecord();
Long countLinkedRecord();
}

View File

@ -46,4 +46,14 @@ public class CabinetCellServiceImpl extends ServiceImpl<CabinetCellMapper, Cabin
public Page<CabinetCellWithOrderCountDTO> getCellListWithOrders(AbstractPageQuery<CabinetCellEntity> query) {
return baseMapper.getCellListWithOrders(query.toPage(), query.toQueryWrapper());
}
@Override
public Long countAllRecord() {
return baseMapper.countAllRecord();
}
@Override
public Long countLinkedRecord() {
return baseMapper.countLinkedRecord();
}
}

View File

@ -218,4 +218,8 @@ public class SmartCabinetApplicationService {
}
return result;
}
public Long countAllRecord() {
return smartCabinetService.countAllRecord();
}
}

View File

@ -48,4 +48,7 @@ public interface SmartCabinetMapper extends BaseMapper<SmartCabinetEntity> {
// 新增根据柜体ID查询的方法
@Select("SELECT * FROM smart_cabinet WHERE cabinet_id = #{cabinetId} LIMIT 1")
SmartCabinetEntity selectByCabinetId(Long cabinetId);
@Select("SELECT COUNT(1) FROM smart_cabinet WHERE deleted = 0")
Long countAllRecord();
}

View File

@ -23,4 +23,5 @@ public interface SmartCabinetService extends IService<SmartCabinetEntity> {
SmartCabinetEntity getByCabinetId(Long cabinetId);
Long countAllRecord();
}

View File

@ -40,4 +40,9 @@ public class SmartCabinetServiceImpl extends ServiceImpl<SmartCabinetMapper, Sma
return baseMapper.selectByCabinetId(cabinetId);
}
@Override
public Long countAllRecord() {
return baseMapper.countAllRecord();
}
}

View File

@ -135,6 +135,10 @@ public class MqttService implements MqttCallback {
@Override
public void deliveryComplete(IMqttDeliveryToken token) {}
public Long getGatewayCount() {
return (long) clientConfigs.size();
}
/******************************************************
*函数名称: lockCmd
* : 指令地址码通道号指令参数

View File

@ -69,4 +69,8 @@ public class GoodsApplicationService {
public ShopGoodsDTO getGoodsInfo(Long goodsId) {
return new ShopGoodsDTO(shopGoodsService.getGoodsInfo(goodsId));
}
public Long countAllRecord() {
return shopGoodsService.countAllRecord();
}
}

View File

@ -91,4 +91,7 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
"LEFT JOIN smart_cabinet sc ON cc.cabinet_id = sc.cabinet_id AND sc.deleted = 0 " +
"WHERE g.goods_id = #{goodsId} ")
SearchGoodsDO getGoodsInfo(@Param("goodsId") Long goodsId);
@Select("SELECT COUNT(1) FROM shop_goods WHERE deleted = 0")
Long countAllRecord();
}

View File

@ -22,4 +22,6 @@ public interface ShopGoodsService extends IService<ShopGoodsEntity> {
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(Long shopId);
SearchGoodsDO getGoodsInfo(Long goodsId);
Long countAllRecord();
}

View File

@ -45,4 +45,9 @@ public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoods
public SearchGoodsDO getGoodsInfo(Long goodsId) {
return baseMapper.getGoodsInfo(goodsId);
}
@Override
public Long countAllRecord() {
return baseMapper.countAllRecord();
}
}

View File

@ -25,14 +25,12 @@ import com.agileboot.domain.qywx.user.model.QyUserModelFactory;
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
import com.agileboot.domain.shop.goods.db.ShopGoodsService;
import com.agileboot.domain.shop.order.command.SubmitOrderCommand;
import com.agileboot.domain.shop.order.db.ShopOrderEntity;
import com.agileboot.domain.shop.order.db.ShopOrderService;
import com.agileboot.domain.shop.order.db.ShopOrderGoodsEntity;
import com.agileboot.domain.shop.order.db.ShopOrderGoodsService;
import com.agileboot.domain.shop.order.db.*;
import com.agileboot.domain.shop.order.db.dto.OrderWithGoodsDTO;
import com.agileboot.domain.shop.order.dto.CreateOrderResult;
import com.agileboot.domain.shop.order.dto.GetOrdersByOpenIdDTO;
import com.agileboot.domain.shop.order.dto.ShopOrderDTO;
import com.agileboot.domain.shop.order.dto.TopGoodsDTO;
import com.agileboot.domain.shop.order.model.OrderModel;
import com.agileboot.domain.shop.order.model.OrderModelFactory;
import com.agileboot.domain.shop.order.model.OrderGoodsModel;
@ -339,4 +337,16 @@ public class OrderApplicationService {
public OrderModel loadById(Long orderId) {
return orderModelFactory.loadById(orderId);
}
public Long countAllRecord() {
return orderService.countAllRecord();
}
public List<TopGoodsDTO> selectTopGoodsByOccurrence(){
return orderGoodsService.selectTopGoodsByOccurrence();
}
public List<TodayLatestOrderGoodsDTO> selectTodayLatestOrderGoods(){
return orderGoodsService.selectTodayLatestOrderGoods();
}
}

View File

@ -1,5 +1,6 @@
package com.agileboot.domain.shop.order.db;
import com.agileboot.domain.shop.order.dto.TopGoodsDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@ -22,4 +23,22 @@ public interface ShopOrderGoodsMapper extends BaseMapper<ShopOrderGoodsEntity> {
@Select("SELECT * FROM shop_order_goods WHERE order_id = #{orderId} AND deleted = 0")
List<ShopOrderGoodsEntity> selectByOrderId(@Param("orderId") Long orderId);
@Select("SELECT sog.goods_id, sg.goods_name, sg.cover_img, COUNT(*) AS occurrence_count " +
"FROM shop_order_goods sog " +
"JOIN shop_goods sg ON sog.goods_id = sg.goods_id " +
"WHERE sog.deleted = 0 AND sg.deleted = 0 AND sog.goods_id != 6 " +
"GROUP BY sog.goods_id, sg.goods_name, sg.cover_img " +
"ORDER BY occurrence_count DESC " +
"LIMIT 10")
List<TopGoodsDTO> selectTopGoodsByOccurrence();
@Select("SELECT sog.*, so.name AS buyer_name " +
"FROM shop_order_goods sog " +
"JOIN shop_order so ON sog.order_id = so.order_id " +
"WHERE sog.deleted = 0 AND so.deleted = 0 " +
"AND DATE(sog.create_time) = CURRENT_DATE " +
"ORDER BY sog.create_time DESC " +
"LIMIT 10")
List<TodayLatestOrderGoodsDTO> selectTodayLatestOrderGoods();
}

View File

@ -1,6 +1,8 @@
package com.agileboot.domain.shop.order.db;
import com.agileboot.domain.shop.order.dto.TopGoodsDTO;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@ -16,4 +18,8 @@ public interface ShopOrderGoodsService extends IService<ShopOrderGoodsEntity> {
ShopOrderGoodsEntity getByOrderIdAndGoodsId(Long orderId, Long goodsId);
List<ShopOrderGoodsEntity> selectByOrderId(Long orderId);
List<TopGoodsDTO> selectTopGoodsByOccurrence();
List<TodayLatestOrderGoodsDTO> selectTodayLatestOrderGoods();
}

View File

@ -1,5 +1,6 @@
package com.agileboot.domain.shop.order.db;
import com.agileboot.domain.shop.order.dto.TopGoodsDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@ -26,4 +27,14 @@ public class ShopOrderGoodsServiceImpl extends ServiceImpl<ShopOrderGoodsMapper,
return baseMapper.selectByOrderId(orderId);
}
@Override
public List<TopGoodsDTO> selectTopGoodsByOccurrence() {
return baseMapper.selectTopGoodsByOccurrence();
}
@Override
public List<TodayLatestOrderGoodsDTO> selectTodayLatestOrderGoods() {
return baseMapper.selectTodayLatestOrderGoods();
}
}

View File

@ -29,4 +29,7 @@ public interface ShopOrderMapper extends BaseMapper<ShopOrderEntity> {
Page<OrderWithGoodsDTO> page,
@Param(Constants.WRAPPER) Wrapper<OrderWithGoodsDTO> queryWrapper
);
@Select("SELECT COUNT(1) FROM shop_order WHERE deleted = 0")
Long countAllRecord();
}

View File

@ -16,4 +16,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface ShopOrderService extends IService<ShopOrderEntity> {
Page<OrderWithGoodsDTO> getOrderList(SearchShopOrderQuery<OrderWithGoodsDTO> query);
Long countAllRecord();
}

View File

@ -23,4 +23,9 @@ public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrder
public Page<OrderWithGoodsDTO> getOrderList(SearchShopOrderQuery<OrderWithGoodsDTO> query) {
return baseMapper.getOrderList(query.toPage(), query.toQueryWrapper());
}
@Override
public Long countAllRecord() {
return baseMapper.countAllRecord();
}
}

View File

@ -0,0 +1,63 @@
package com.agileboot.domain.shop.order.db;
import com.agileboot.common.core.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
import java.util.Date;
/**
* <p>
* 今日最新订单商品DTO
* </p>
*
* @author valarchie
* @since 2025-03-10
*/
@Getter
@Setter
@ApiModel(value = "TodayLatestOrderGoodsDTO对象", description = "今日最新订单商品DTO")
public class TodayLatestOrderGoodsDTO extends BaseEntity<TodayLatestOrderGoodsDTO> {
@ApiModelProperty("订单商品唯一ID")
private Long orderGoodsId;
@ApiModelProperty("关联订单ID")
private Long orderId;
@ApiModelProperty("关联商品ID")
private Long goodsId;
@ApiModelProperty("关联格口ID")
private Long cellId;
@ApiModelProperty("购买数量")
private Integer quantity;
@ApiModelProperty("购买时单价")
private BigDecimal price;
@ApiModelProperty("商品总金额")
private BigDecimal totalAmount;
@ApiModelProperty("商品名称")
private String goodsName;
@ApiModelProperty("封面图URL")
private String coverImg;
@ApiModelProperty("商品状态1正常 2已退货 3已换货 4已完成 5审核中 6退货未通过")
private Integer status;
@ApiModelProperty("买家姓名")
private String buyerName;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("创建时间")
private String createTimeStr;
}

View File

@ -0,0 +1,22 @@
package com.agileboot.domain.shop.order.dto;
import com.agileboot.common.annotation.ExcelColumn;
import com.agileboot.common.annotation.ExcelSheet;
import lombok.Data;
@ExcelSheet(name = "热门商品统计")
@Data
public class TopGoodsDTO {
@ExcelColumn(name = "商品ID")
private Long goodsId;
@ExcelColumn(name = "商品名称")
private String goodsName;
@ExcelColumn(name = "封面图片")
private String coverImg;
@ExcelColumn(name = "出现次数")
private Integer occurrenceCount;
}

View File

@ -50,4 +50,8 @@ public class ShopApplicationService {
model.deleteById();
}
}
public Long countAllRecord() {
return shopService.countAllRecord();
}
}

View File

@ -40,4 +40,7 @@ public interface ShopMapper extends BaseMapper<ShopEntity> {
@Select("SELECT * FROM shop WHERE shop_name = #{shopName} LIMIT 1")
ShopEntity selectByShopName(String shopName);
@Select("SELECT COUNT(1) FROM shop WHERE deleted = 0")
Long countAllRecord();
}

View File

@ -25,4 +25,6 @@ public interface ShopService extends IService<ShopEntity> {
ShopEntity selectByShopId(Long shopId);
ShopEntity selectByShopName(String shopName);
Long countAllRecord();
}

View File

@ -42,4 +42,9 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopEntity> impleme
public ShopEntity selectByShopName(String shopName) {
return baseMapper.selectByShopName(shopName);
}
@Override
public Long countAllRecord() {
return baseMapper.countAllRecord();
}
}

View File

@ -0,0 +1,42 @@
package com.agileboot.domain.shop.shop.dto;
import com.agileboot.common.annotation.ExcelColumn;
import com.agileboot.common.annotation.ExcelSheet;
import com.agileboot.domain.shop.order.db.TodayLatestOrderGoodsDTO;
import com.agileboot.domain.shop.order.dto.TopGoodsDTO;
import lombok.Data;
import java.util.List;
@ExcelSheet(name = "统计数据")
@Data
public class StatsDTO {
@ExcelColumn(name = "商店数量")
private Long shopCount;
@ExcelColumn(name = "商品数量")
private Long goodsCount;
@ExcelColumn(name = "订单数量")
private Long orderCount;
@ExcelColumn(name = "总柜子数量")
private Long cabinetCount;
@ExcelColumn(name = "总格口数量")
private Long cellCount;
@ExcelColumn(name = "已关联格口数量")
private Long linkedCellCount;
@ExcelColumn(name = "未管理格口数量")
private Long unmanagedCellCount;
@ExcelColumn(name = "网关数量")
private Long gatewayCount;
private List<TopGoodsDTO> topGoods;
private List<TodayLatestOrderGoodsDTO> todayLatestOrderGoods;
}