小程序主页接口
This commit is contained in:
parent
9ff72f171e
commit
d148aafb48
|
|
@ -1,35 +0,0 @@
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|||
import com.czg.CzgPayUtils;
|
||||
import com.czg.entity.CzgBaseRespParams;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.task.StatisticTask;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -24,6 +25,9 @@ public class NotifyController {
|
|||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@Resource
|
||||
private StatisticTask statisticTask;
|
||||
|
||||
|
||||
@RequestMapping("/payCallBack")
|
||||
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams){
|
||||
|
|
@ -42,4 +46,9 @@ public class NotifyController {
|
|||
orderInfoService.refundCallBackOrder(czg.getString("mchOrderNo"), czg);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@RequestMapping("/test")
|
||||
public void test() {
|
||||
statisticTask.run();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.czg.task;
|
||||
|
||||
import com.czg.order.service.ShopOrderStatisticService;
|
||||
import com.czg.order.service.ShopProdStatisticService;
|
||||
import com.czg.order.service.ShopTableOrderStatisticService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Component
|
||||
public class StatisticTask {
|
||||
@Resource
|
||||
private ShopTableOrderStatisticService shopTableOrderStatisticService;
|
||||
@Resource
|
||||
private ShopProdStatisticService shopProdStatisticService;
|
||||
@Resource
|
||||
private ShopOrderStatisticService shopOrderStatisticService;
|
||||
|
||||
public void run() {
|
||||
shopOrderStatisticService.statistic();
|
||||
}
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
|||
// 重置根路径,防止satoken切割根路径导致匹配不到路径
|
||||
ApplicationInfo.routePrefix = "";
|
||||
|
||||
SaRouter.match("/user/**").notMatch("/user/login", "/user/test", "/user/geo/**", "/user/home/**", "/user/home/**", "/user/dict/**")
|
||||
SaRouter.match("/user/**").notMatch("/user/login", "/user/test", "/user/geo/**", "/user/home/**", "/user/home/**", "/user/dict/**", "/user/openId")
|
||||
.notMatch("/pay/**")
|
||||
.notMatch("/notify/**")
|
||||
.check(r -> MyStpLogic.CLIENT_LOGIC.checkLogin())
|
||||
|
|
|
|||
|
|
@ -49,6 +49,14 @@ public class ShopTableOrderStatistic implements Serializable {
|
|||
* 订单金额
|
||||
*/
|
||||
private BigDecimal orderAmount;
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private Long refundCount;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
|
|
|
|||
|
|
@ -0,0 +1,120 @@
|
|||
|
||||
package com.czg.order.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.io.Serial;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopOrderStatisticDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 销售额
|
||||
*/
|
||||
private BigDecimal saleAmount;
|
||||
|
||||
/**
|
||||
* 销售数量
|
||||
*/
|
||||
private Long saleCount;
|
||||
|
||||
/**
|
||||
* 优惠金额
|
||||
*/
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
/**
|
||||
* 优惠笔数
|
||||
*/
|
||||
private Long discountCount;
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 退款笔数
|
||||
*/
|
||||
private Long refundCount;
|
||||
|
||||
/**
|
||||
* 微信支付笔数
|
||||
*/
|
||||
private Long wechatPayCount;
|
||||
|
||||
/**
|
||||
* 位置支付金额
|
||||
*/
|
||||
private BigDecimal wechatPayAmount;
|
||||
|
||||
/**
|
||||
* 支付宝支付笔数
|
||||
*/
|
||||
private Long aliPayCount;
|
||||
|
||||
/**
|
||||
* 支付宝支付金额
|
||||
*/
|
||||
private BigDecimal aliPayAmount;
|
||||
|
||||
/**
|
||||
* 挂账支付笔数
|
||||
*/
|
||||
private Long creditPayCount;
|
||||
|
||||
/**
|
||||
* 挂账支付金额
|
||||
*/
|
||||
private BigDecimal creditPayAmount;
|
||||
|
||||
/**
|
||||
* 会员支付笔数
|
||||
*/
|
||||
private Long memberPayCount;
|
||||
|
||||
/**
|
||||
* 会员支付金额
|
||||
*/
|
||||
private BigDecimal memberPayAmount;
|
||||
|
||||
/**
|
||||
* 主扫支付笔数
|
||||
*/
|
||||
private Long scanPayCount;
|
||||
|
||||
/**
|
||||
* 主扫支付金额
|
||||
*/
|
||||
private BigDecimal scanPayAmount;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createDay;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
package com.czg.order.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.io.Serial;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopProdStatisticDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long prodId;
|
||||
|
||||
/**
|
||||
* 销售数量
|
||||
*/
|
||||
private Long saleNum;
|
||||
|
||||
/**
|
||||
* 销售金额
|
||||
*/
|
||||
private BigDecimal saleAmount;
|
||||
|
||||
/**
|
||||
* 退单量
|
||||
*/
|
||||
private Long refundNum;
|
||||
|
||||
/**
|
||||
* 退单金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createDay;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
package com.czg.order.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.io.Serial;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopTableOrderStatisticDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long tableId;
|
||||
|
||||
/**
|
||||
* 订单数量
|
||||
*/
|
||||
private Long orderCount;
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建日期 年月日
|
||||
*/
|
||||
private Date createDay;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
package com.czg.order.entity;
|
||||
|
||||
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.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_shop_order_statistic")
|
||||
public class ShopOrderStatistic implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 销售额
|
||||
*/
|
||||
private BigDecimal saleAmount;
|
||||
|
||||
/**
|
||||
* 销售数量
|
||||
*/
|
||||
private Long saleCount;
|
||||
|
||||
/**
|
||||
* 优惠金额
|
||||
*/
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
/**
|
||||
* 优惠笔数
|
||||
*/
|
||||
private Long discountCount;
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 退款笔数
|
||||
*/
|
||||
private Long refundCount;
|
||||
|
||||
/**
|
||||
* 微信支付笔数
|
||||
*/
|
||||
private Long wechatPayCount;
|
||||
|
||||
/**
|
||||
* 位置支付金额
|
||||
*/
|
||||
private BigDecimal wechatPayAmount;
|
||||
|
||||
/**
|
||||
* 支付宝支付笔数
|
||||
*/
|
||||
private Long aliPayCount;
|
||||
|
||||
/**
|
||||
* 支付宝支付金额
|
||||
*/
|
||||
private BigDecimal aliPayAmount;
|
||||
|
||||
/**
|
||||
* 挂账支付笔数
|
||||
*/
|
||||
private Long creditPayCount;
|
||||
|
||||
/**
|
||||
* 挂账支付金额
|
||||
*/
|
||||
private BigDecimal creditPayAmount;
|
||||
|
||||
/**
|
||||
* 会员支付笔数
|
||||
*/
|
||||
private Long memberPayCount;
|
||||
|
||||
/**
|
||||
* 会员支付金额
|
||||
*/
|
||||
private BigDecimal memberPayAmount;
|
||||
|
||||
/**
|
||||
* 主扫支付笔数
|
||||
*/
|
||||
private Long scanPayCount;
|
||||
|
||||
/**
|
||||
* 主扫支付金额
|
||||
*/
|
||||
private BigDecimal scanPayAmount;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createDay;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package com.czg.order.entity;
|
||||
|
||||
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.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_shop_prod_statistic")
|
||||
public class ShopProdStatistic implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long prodId;
|
||||
|
||||
/**
|
||||
* 销售数量
|
||||
*/
|
||||
private BigDecimal saleCount;
|
||||
|
||||
/**
|
||||
* 销售金额
|
||||
*/
|
||||
private BigDecimal saleAmount;
|
||||
|
||||
/**
|
||||
* 退单量
|
||||
*/
|
||||
private BigDecimal refundCount;
|
||||
|
||||
/**
|
||||
* 退单金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createDay;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package com.czg.order.entity;
|
||||
|
||||
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.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@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;
|
||||
|
||||
/**
|
||||
* 订单数量
|
||||
*/
|
||||
private Long orderCount;
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 创建日期 年月日
|
||||
*/
|
||||
private Date createDay;
|
||||
/**
|
||||
* 退款数量
|
||||
*/
|
||||
private long refundCount;
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.czg.order.service;
|
||||
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.order.entity.ShopOrderStatistic;
|
||||
|
||||
/**
|
||||
* 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
public interface ShopOrderStatisticService extends IService<ShopOrderStatistic> {
|
||||
|
||||
void statistic();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.czg.order.service;
|
||||
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.order.entity.ShopProdStatistic;
|
||||
|
||||
/**
|
||||
* 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
public interface ShopProdStatisticService extends IService<ShopProdStatistic> {
|
||||
|
||||
void statistic();
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package com.czg.account.service;
|
||||
package com.czg.order.service;
|
||||
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.account.entity.ShopTableOrderStatistic;
|
||||
import com.czg.order.entity.ShopTableOrderStatistic;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
|
@ -10,10 +10,9 @@ import java.math.BigDecimal;
|
|||
* 台桌订单统计表 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-03
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
public interface ShopTableOrderStatisticService extends IService<ShopTableOrderStatistic> {
|
||||
|
||||
Page<ShopTableOrderStatistic> summary(Long shopId, String startTime, String endTime);
|
||||
|
||||
/**
|
||||
|
|
@ -25,4 +24,6 @@ public interface ShopTableOrderStatisticService extends IService<ShopTableOrderS
|
|||
* @return 是否成功
|
||||
*/
|
||||
boolean addInfo(long shopId, long tableId, long count, BigDecimal amount);
|
||||
|
||||
void statistic();
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
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 FunUtil funUtil;
|
||||
|
||||
@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());
|
||||
}, RedisCst.getLockKey("add_table_order_statistic", shopId, tableId));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.ShopOrderStatistic;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.ShopProdStatistic;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
public interface ShopProdStatisticMapper extends BaseMapper<ShopProdStatistic> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.ShopTableOrderStatistic;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
public interface ShopTableOrderStatisticMapper extends BaseMapper<ShopTableOrderStatistic> {
|
||||
|
||||
List<ShopTableOrderStatistic> selectSummary(Long shopId, String startTime, String endTime);
|
||||
|
||||
boolean incrInfo(long shopId, long tableId, long count, BigDecimal amount, String dateStr);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopOrderStatistic;
|
||||
import com.czg.order.service.ShopOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService{
|
||||
@Override
|
||||
public void statistic() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopProdStatistic;
|
||||
import com.czg.order.service.ShopProdStatisticService;
|
||||
import com.czg.service.order.mapper.ShopProdStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.Data;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticMapper, ShopProdStatistic> implements ShopProdStatisticService{
|
||||
@Resource
|
||||
private OrderDetailService orderDetailService;
|
||||
@Data
|
||||
private static class StatisticTask{
|
||||
private BigDecimal successCount = BigDecimal.ZERO;
|
||||
private BigDecimal successAmount = BigDecimal.ZERO;
|
||||
private BigDecimal refundCount = BigDecimal.ZERO;
|
||||
private BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
|
||||
List<OrderDetail> orderDetails = orderDetailService.list(new QueryWrapper()
|
||||
.ge(OrderDetail::getCreateTime, startOfDay)
|
||||
.le(OrderDetail::getCreateTime, endOfDay)
|
||||
.ne(OrderDetail::getStatus, "wait-pay"));
|
||||
|
||||
|
||||
HashMap<Long, Map<Long, StatisticTask>> countInfo = new HashMap<>();
|
||||
for (OrderDetail item : orderDetails) {
|
||||
Map<Long, StatisticTask> map = countInfo.computeIfAbsent(item.getShopId(), k -> new HashMap<>());
|
||||
StatisticTask statisticTask = map.get(item.getProductId());
|
||||
if (statisticTask == null) {
|
||||
map.put(item.getProductId(), statisticTask = new StatisticTask());
|
||||
}
|
||||
if ("refunding".equals(item.getStatus()) || "refund".equals(item.getStatus()) || "part-refund".equals(item.getStatus())) {
|
||||
statisticTask.setRefundAmount(statisticTask.getRefundAmount().add(item.getReturnAmount()));
|
||||
statisticTask.setRefundCount(statisticTask.getRefundCount().add(item.getRefundNum()));
|
||||
if (item.getReturnNum().compareTo(item.getNum()) < 0) {
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount().subtract(item.getReturnAmount())));
|
||||
statisticTask.setSuccessCount(statisticTask.getSuccessCount().add(item.getNum().subtract(item.getReturnAmount())));
|
||||
}
|
||||
}else {
|
||||
statisticTask.setSuccessCount(statisticTask.getSuccessCount().add(item.getNum()));
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount()));
|
||||
}
|
||||
}
|
||||
|
||||
countInfo.forEach((shopId, map) -> map.forEach((productId, statisticTask) -> {
|
||||
ShopProdStatistic statistic = getOne(new QueryWrapper().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, yesterday.toSqlDate()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopProdStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setCreateDay(yesterday.toSqlDate());
|
||||
}
|
||||
statistic.setProdId(productId);
|
||||
statistic.setSaleCount(statisticTask.getSuccessCount());
|
||||
statistic.setSaleAmount(statisticTask.getSuccessAmount());
|
||||
statistic.setRefundCount(statisticTask.getRefundCount());
|
||||
statistic.setRefundAmount(statisticTask.getRefundAmount());
|
||||
saveOrUpdate(statistic);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
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.order.entity.ShopTableOrderStatistic;
|
||||
import com.czg.order.service.ShopTableOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.Data;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 台桌订单统计表 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrderStatisticMapper, ShopTableOrderStatistic> implements ShopTableOrderStatisticService{
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@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) {
|
||||
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());
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class StatisticTask{
|
||||
private long successCount = 0;
|
||||
private BigDecimal successAmount = BigDecimal.ZERO;
|
||||
private long refundCount = 0;
|
||||
private BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
List<OrderInfo> orderInfos = orderInfoService.list(new QueryWrapper()
|
||||
.ge(OrderInfo::getCreateTime, startOfDay)
|
||||
.le(OrderInfo::getCreateTime, endOfDay)
|
||||
.ne(OrderInfo::getStatus, "unpaid").ne(OrderInfo::getStatus, "cancelled"));
|
||||
|
||||
HashMap<Long, StatisticTask> countInfo = new HashMap<>();
|
||||
for (OrderInfo item : orderInfos) {
|
||||
StatisticTask statisticTask = countInfo.get(item.getShopId());
|
||||
if (statisticTask == null) {
|
||||
countInfo.put(item.getShopId(), statisticTask = new StatisticTask());
|
||||
}
|
||||
if ("refunding".equals(item.getStatus()) || "refund".equals(item.getStatus()) || "part-refund".equals(item.getStatus())) {
|
||||
statisticTask.setRefundAmount(statisticTask.getRefundAmount().add(item.getRefundAmount()));
|
||||
statisticTask.setRefundCount(statisticTask.getRefundCount() + 1);
|
||||
if (item.getRefundAmount().compareTo(item.getPayAmount()) < 0) {
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount().subtract(item.getRefundAmount())));
|
||||
}
|
||||
}else {
|
||||
statisticTask.setSuccessCount(statisticTask.getSuccessCount() + 1);
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount()));
|
||||
}
|
||||
}
|
||||
|
||||
countInfo.forEach((shopId, statisticTask) -> {
|
||||
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getCreateDay, yesterday.toSqlDate()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopTableOrderStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setTableId(0L);
|
||||
statistic.setCreateDay(yesterday.toSqlDate());
|
||||
}
|
||||
statistic.setOrderCount(statisticTask.getSuccessCount());
|
||||
statistic.setOrderAmount(statisticTask.getSuccessAmount());
|
||||
statistic.setRefundCount(statisticTask.getRefundCount());
|
||||
statistic.setRefundAmount(statisticTask.getRefundAmount());
|
||||
saveOrUpdate(statistic);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?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.order.mapper.ShopOrderStatisticMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?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.order.mapper.ShopProdStatisticMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -2,13 +2,13 @@
|
|||
<!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">
|
||||
<mapper namespace="com.czg.service.order.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 id="selectSummary" resultType="com.czg.order.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
|
||||
Loading…
Reference in New Issue