桌台统计接口
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.account.entity.ShopTableOrderStatistic;
|
||||
import com.czg.account.service.ShopTableOrderStatisticService;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 桌台订单统计
|
||||
* @author Administrator
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/tableOrderStatistic")
|
||||
public class TableOrderStatisticController {
|
||||
@Resource
|
||||
private ShopTableOrderStatisticService orderStatisticService;
|
||||
|
||||
/**
|
||||
* 桌台统计列表
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 统计信息
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "tableOrderStatistic:list", name = "台桌订单统计列表")
|
||||
@GetMapping
|
||||
public CzgResult<Page<ShopTableOrderStatistic>> list(String startTime, String endTime) {
|
||||
return CzgResult.success(orderStatisticService.summary(StpKit.USER.getShopId(), startTime, endTime));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
|
||||
package com.czg.account.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import java.io.Serial;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopTableOrderStatisticDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private Integer tableId;
|
||||
|
||||
/**
|
||||
* 订单数量
|
||||
*/
|
||||
private Long orderCount;
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
private BigDecimal ordereAmount;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建日期 年月日
|
||||
*/
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createDay;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.czg.account.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_shop_table_order_statistic")
|
||||
public class ShopTableOrderStatistic implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
private Long tableId;
|
||||
|
||||
@Column(ignore = true)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 订单数量
|
||||
*/
|
||||
private Long orderCount;
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建日期 年月日
|
||||
*/
|
||||
private Date createDay;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.czg.account.service;
|
||||
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.account.entity.ShopTableOrderStatistic;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
public interface ShopTableOrderStatisticService extends IService<ShopTableOrderStatistic> {
|
||||
|
||||
Page<ShopTableOrderStatistic> summary(Long shopId, String startTime, String endTime);
|
||||
|
||||
/**
|
||||
* 增加每日统计信息
|
||||
* @param shopId 店铺id
|
||||
* @param tableId 台桌id
|
||||
* @param count 订单数量
|
||||
* @param amount 订单总金额
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean addInfo(long shopId, long tableId, long count, BigDecimal amount);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.ShopTableOrderStatistic;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
public interface ShopTableOrderStatisticMapper extends BaseMapper<ShopTableOrderStatistic> {
|
||||
|
||||
List<ShopTableOrderStatistic> selectSummary(@Param("shopId") Long shopId, @Param("startTime") String startTime, @Param("endTime") String endTime);
|
||||
|
||||
boolean incrInfo(@Param("shopId") long shopId, @Param("tableId") long tableId, @Param("count") long count, @Param("amount") BigDecimal amount, @Param("date") String date);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.service.account.util.FunUtil;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.ShopTableOrderStatistic;
|
||||
import com.czg.account.service.ShopTableOrderStatisticService;
|
||||
import com.czg.service.account.mapper.ShopTableOrderStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
@Service
|
||||
public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrderStatisticMapper, ShopTableOrderStatistic> implements ShopTableOrderStatisticService{
|
||||
@Resource
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@Override
|
||||
public Page<ShopTableOrderStatistic> summary(Long shopId, String startTime, String endTime) {
|
||||
Page<Object> page = PageUtil.buildPage();
|
||||
PageHelper.startPage(Math.toIntExact(page.getPageNumber()),Math.toIntExact(page.getPageSize()));
|
||||
return PageUtil.convert(new PageInfo<>(mapper.selectSummary(shopId, startTime, endTime)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addInfo(long shopId, long tableId, long count, BigDecimal amount) {
|
||||
return FunUtil.runFunAndCheckKey(() -> {
|
||||
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getTableId, tableId)
|
||||
.eq(ShopTableOrderStatistic::getCreateDay, DateUtil.date().toDateStr()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopTableOrderStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setTableId(tableId);
|
||||
statistic.setCreateDay(DateUtil.date().toSqlDate());
|
||||
statistic.setOrderCount(count);
|
||||
statistic.setOrderAmount(amount);
|
||||
save(statistic);
|
||||
}
|
||||
return mapper.incrInfo(shopId, tableId, count, amount, DateUtil.date().toDateStr());
|
||||
}, redisTemplate, RedisCst.getLockKey("add_table_order_statistic", shopId, tableId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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.czg.service.account.mapper.ShopTableOrderStatisticMapper">
|
||||
<update id="incrInfo">
|
||||
update tb_shop_table_order_statistic set order_count=order_count + #{count}, order_amount=order_amount + #{count}
|
||||
where shop_id = #{shopId} and table_id = #{tableId} and create_day=#{date}
|
||||
</update>
|
||||
|
||||
<select id="selectSummary" resultType="com.czg.account.entity.ShopTableOrderStatistic">
|
||||
SELECT
|
||||
a.table_id as tableId, b.name as name, sum(a.order_count) as orderCount, sum(a.order_amount) as orderAmount
|
||||
FROM
|
||||
tb_shop_table_order_statistic as a
|
||||
left join tb_shop_table as b on a.table_id = b.id
|
||||
WHERE
|
||||
a.shop_id = #{shopId}
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND a.create_day >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
and a.create_day <= #{endTime}
|
||||
</if>
|
||||
GROUP BY
|
||||
a.table_id
|
||||
order by a.id desc
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user