From efd9d7822782b350b732f0ca8b2f29cdba86fdbb Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 10 Sep 2024 15:54:40 +0800 Subject: [PATCH 01/56] =?UTF-8?q?=E9=A6=96=E9=A1=B5=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/shop/SummaryController.java | 16 +- .../java/cn/ysk/cashier/dto/BaseQueryDto.java | 36 +++ .../mybatis/mapper/TbShopUserFlowMapper.java | 29 ++- .../order/TbOrderInfoRepository.java | 17 ++ .../ysk/cashier/service/SummaryService.java | 4 +- .../service/impl/SummaryServiceImpl.java | 234 +++++++++++------- 6 files changed, 243 insertions(+), 93 deletions(-) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/BaseQueryDto.java diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java index e7f09c34..bcdd6f4e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java @@ -2,6 +2,7 @@ package cn.ysk.cashier.controller.shop; import cn.ysk.cashier.annotation.rest.AnonymousGetMapping; import cn.ysk.cashier.annotation.rest.AnonymousPostMapping; +import cn.ysk.cashier.dto.BaseQueryDto; import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto; import cn.ysk.cashier.service.SummaryService; import lombok.RequiredArgsConstructor; @@ -23,11 +24,20 @@ public class SummaryController { @Resource private SummaryService summaryService; - @GetMapping - private Object shopSummary(@RequestParam Integer shopId) { - return summaryService.selectSummary(shopId); + + @PostMapping("/trade") + @AnonymousPostMapping + private Object shopSummaryDate(@RequestBody BaseQueryDto param) { + return summaryService.trade(param); } + + +// @GetMapping +// private Object shopSummary(@RequestParam Integer shopId) { +// return summaryService.selectSummary(shopId); +// } + @GetMapping("/date") private Object shopSummaryDate(@RequestParam Integer shopId, @RequestParam Integer day) { return summaryService.selectSummaryDate(shopId, day); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BaseQueryDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BaseQueryDto.java new file mode 100644 index 00000000..1d8117ff --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BaseQueryDto.java @@ -0,0 +1,36 @@ +package cn.ysk.cashier.dto; + +import org.springframework.format.annotation.DateTimeFormat; +import java.util.Date; + +public class BaseQueryDto { + private Integer shopId; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date startTime; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endTime; + + public Integer getShopId() { + return shopId; + } + + public void setShopId(Integer shopId) { + this.shopId = shopId; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopUserFlowMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopUserFlowMapper.java index 6e80822b..d4053259 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopUserFlowMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopUserFlowMapper.java @@ -5,9 +5,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; -import javax.validation.Valid; import java.math.BigDecimal; import java.util.List; +import java.util.Map; /** * @author GYJ @@ -41,6 +41,33 @@ public interface TbShopUserFlowMapper extends BaseMapper { @Param("startTime") String startTime, @Param("endTime") String endTime); + @Select("") + Map tradeIndexFlow(@Param("shopId") Integer shopId, + @Param("startTime") String startTime, + @Param("endTime") String endTime); + + @Select("") + Integer tradeIndexNewFlow(@Param("shopId") Integer shopId, @Param("startTime") String startTime, @Param("endTime") String endTime); + @Select(value = "select * from tb_shop_user_flow where shop_user_id=#{userId} order by id desc limit #{page},#{size}") List selectByUserId(@Param("userId") Integer userId,@Param("page") Integer page,@Param("size") Integer size); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java index c59da55c..69efbe63 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java @@ -31,6 +31,7 @@ import javax.persistence.Tuple; import java.math.BigDecimal; import java.util.Date; import java.util.List; +import java.util.Map; /** * @website https://eladmin.vip @@ -54,6 +55,22 @@ public interface TbOrderInfoRepository extends JpaRepository:start AND info.createdAt<:end") TbOrderPayCountVo queryTbOrderRefund(@Param("shopId")String shopId, @Param("tableName") String tableName ,@Param("start") Long start, @Param("end") Long end); + @Query(value = "SELECT " + + "COALESCE(SUM( info.order_amount ),0) AS 'saleAmount'," + + "COALESCE(count( 1 ),0) AS 'saleNum'," + + "COALESCE(sum( discount_amount ),0) AS 'saveAmount'," + + "COALESCE(COUNT( CASE WHEN discount_amount IS NOT NULL AND discount_amount > 0.00 THEN 1 ELSE NULL END ),0) AS 'saveNum' " + + "FROM tb_order_info info " + + "WHERE info.shop_id = :shopId " + + "AND info.created_at > :startTime AND info.created_at < :endTime " + + "AND ((info.STATUS = 'closed' ) OR ( info.STATUS = 'refund' AND info.order_type != 'return' ))", nativeQuery = true) + Map tradeIndex(@Param("shopId") Integer shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); + @Query(value = "SELECT COALESCE(SUM(info.order_amount),0) FROM tb_order_info info " + + "WHERE info.shop_id = :shopId AND info.order_type = 'return' " + + "AND info.created_at > :startTime AND info.created_at < :endTime", nativeQuery = true) + BigDecimal tradeIndexRefund(@Param("shopId") Integer shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); + + @Query(value = "SELECT COUNT(1) ,pay_type AS payType FROM tb_order_info Where shop_id = :shopId AND " + " created_at BETWEEN :startTime AND :endTime AND status='closed'AND order_type <>'return' GROUP BY pay_type", nativeQuery = true) List countByShopId(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java index 61615be7..330398a8 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.service; +import cn.ysk.cashier.dto.BaseQueryDto; import cn.ysk.cashier.dto.ShopSummaryDto; import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto; import cn.ysk.cashier.vo.ShopTableSaleInfoVo; @@ -17,8 +18,9 @@ import java.util.Map; * @author lyf */ public interface SummaryService { - SummaryVO selectSummary(Integer shop); + Map trade(BaseQueryDto param); +// SummaryVO selectSummary(Integer shop); Map selectSummaryDate(Integer shopId, Integer day); Map selectSummaryToday(Integer shopId); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index e6c3a59e..ca5294c9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -1,15 +1,19 @@ package cn.ysk.cashier.service.impl; +import cn.hutool.core.util.ObjectUtil; import cn.ysk.cashier.dto.ShopSummaryDto; +import cn.ysk.cashier.dto.BaseQueryDto; import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto; import cn.ysk.cashier.enums.PayTypeEnum; import cn.ysk.cashier.exception.BadRequestException; +import cn.ysk.cashier.mybatis.mapper.TbShopUserFlowMapper; import cn.ysk.cashier.mybatis.service.TbShopUserFlowService; import cn.ysk.cashier.repository.ShopUserDutyDetailRepository; import cn.ysk.cashier.repository.ShopUserDutyRepository; import cn.ysk.cashier.repository.TbTokenRepository; import cn.ysk.cashier.repository.order.TbOrderDetailRepository; import cn.ysk.cashier.repository.order.TbOrderInfoRepository; +import cn.ysk.cashier.repository.shop.TbShopTableRepository; import cn.ysk.cashier.repository.shop.TbShopUserRepository; import cn.ysk.cashier.service.SummaryService; import cn.ysk.cashier.utils.DateUtil; @@ -56,106 +60,160 @@ public class SummaryServiceImpl implements SummaryService { @Resource private TbTokenRepository tbTokenRepository; + @Autowired + private TbShopUserFlowMapper tbShopUserFlowMapper; @Resource private TbShopUserFlowService tbShopUserFlowService; + @Autowired private TbOrderDetailRepository tbOrderDetailRepository; + private final TbShopTableRepository tbShopTableRepository; @Override - public SummaryVO selectSummary(Integer shopId) { - SummaryVO summaryVO = new SummaryVO(); - //支付笔数, - Tuple result = tbOrderInfoRepository.countByShopId(shopId.toString()); - summaryVO.setPaymentsNumber(result.get(0, Long.class) == null ? 0L : result.get(0, Long.class)); - summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null ? new BigDecimal("0") : result.get(1, BigDecimal.class)); - if (summaryVO.getPaymentsNumber() == 0) { - summaryVO.setAverageSales(new BigDecimal("0")); - } else { - summaryVO.setAverageSales(summaryVO.getTotalSales().divide(new BigDecimal(summaryVO.getPaymentsNumber()), 2, RoundingMode.DOWN)); + public Map trade(BaseQueryDto param) { + if (ObjectUtil.isNull(param.getShopId())) { + throw new BadRequestException("参数不合法"); } - //用户数 - Tuple count = tbShopUserRepository.searchByCount(shopId.toString()); - summaryVO.setTotalUser(count == null ? 0L : count.get(0, Long.class)); - //支付笔数柱形图 - List objects = tbOrderInfoRepository.sumByDateOrderNum(shopId.toString(), DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd()); - List countDateList = new ArrayList<>(); - for (Object[] o : objects) { - CountDateVO countDateVO = new CountDateVO(); - BigInteger integers = (BigInteger) o[0]; - countDateVO.setCount(new BigDecimal(integers.toString())); - countDateVO.setTradeDay((String) o[1]); - countDateList.add(countDateVO); + Map result = new HashMap<>(); + Map sale = new HashMap<>(); + Map vip = new HashMap<>(); + Map count = new HashMap<>(); + //订单 销售金额 saleAmount /订单数 saleNum /优惠金额 saveAmount /优惠笔数 saveNum + Map orderMap = tbOrderInfoRepository.tradeIndex(param.getShopId(), param.getStartTime().getTime(), param.getEndTime().getTime()); + //退款金额 + BigDecimal refundAmount = tbOrderInfoRepository.tradeIndexRefund(param.getShopId(), param.getStartTime().getTime(), param.getEndTime().getTime()); + + //会员 充值金额 inAmount /退款金额 outAmount /会员消费金额 useAmount /会员消费笔数 useNum + Map flowMap = tbShopUserFlowMapper.tradeIndexFlow(param.getShopId(), DateUtil.getStrTime(param.getStartTime()), DateUtil.getStrTime(param.getEndTime())); + // 新增会员数 + Integer newFlow = tbShopUserFlowMapper.tradeIndexNewFlow(param.getShopId(), DateUtil.getStrTime(param.getStartTime()), DateUtil.getStrTime(param.getEndTime())); + //台桌数 + int tables = tbShopTableRepository.countAllByShopId(param.getShopId()); + sale.put("totalSaleAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(refundAmount));//总金额 + sale.put("incomeAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(new BigDecimal(flowMap.get("inAmount").toString())));//实收 + sale.put("refundAmount", refundAmount);//销售退款金额 + sale.put("inAmount", flowMap.get("inAmount"));//会员充值金额 + sale.put("outAmount", flowMap.get("outAmount"));//会员退款金额 + result.put("sale",sale); + vip.put("useAmount", flowMap.get("useAmount"));//会员消费金额 + vip.put("newFlow",newFlow);//新增会员数 + vip.put("useNum",flowMap.get("useNum"));//会员消费笔数 + result.put("vip",vip); + BigDecimal saleAmount = new BigDecimal(orderMap.get("saleAmount").toString()).add(refundAmount); + //客单价 + if(saleAmount.compareTo(BigDecimal.ZERO) == 0){ + count.put("unitPrice",BigDecimal.ZERO); + }else { + count.put("unitPrice",saleAmount.divide(new BigDecimal(orderMap.get("saleNum").toString()),2,RoundingMode.DOWN)); } - //填充日期 - Map dataMap = new HashMap<>(); - for (CountDateVO entry : countDateList) { - String tradeDay = entry.getTradeDay(); - BigDecimal countOrder = entry.getCount(); - dataMap.put(tradeDay, new CountDateVO(tradeDay, countOrder)); + BigDecimal saleNum = new BigDecimal(orderMap.get("saleNum").toString()); + if(saleNum.compareTo(BigDecimal.ZERO) == 0){ + count.put("turnoverRate",BigDecimal.ZERO);//翻台率 + }else { + count.put("turnoverRate",saleNum.divide(new BigDecimal(tables),2,RoundingMode.DOWN));//翻台率 } - // 获取今天的日期 - LocalDate today = LocalDate.now(); - // 定义日期格式 - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - // 转换为字符串 - List countDateLists = new ArrayList<>(); - for (int i = 0; i < 30; i++) { - LocalDate tradeDayLocalDate = today.minusDays(i); - String tradeDayString = tradeDayLocalDate.format(formatter); - CountDateVO countDateVO; - // 检查数据Map中是否存在该日期的数据 - if (dataMap.containsKey(tradeDayString)) { - countDateVO = dataMap.get(tradeDayString); - } else { - // 如果不存在,则创建新的SumDateVO对象,amount设为0 - countDateVO = new CountDateVO(tradeDayString, BigDecimal.ZERO); - } - // 将SumDateVO对象添加到列表中 - countDateLists.add(countDateVO); - } - countDateLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay())); - summaryVO.setCountDateList(countDateLists); - //访问量 - Tuple tuple = tbTokenRepository.countByAccountId(shopId); - summaryVO.setTotalVisits(tuple == null ? 0L : tuple.get(0, Long.class)); - //访问量柱状图 - List objectsVisits = tbTokenRepository.countByMonth(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd()); - List visitsList = new ArrayList<>(); - for (Object[] o : objectsVisits) { - CountVisitsVO countDateVO = new CountVisitsVO(); - countDateVO.setCount((BigInteger) o[0]); - countDateVO.setTradeDay((String) o[1]); - visitsList.add(countDateVO); - } - //填充日期 - Map dataVisitsMap = new HashMap<>(); - for (CountVisitsVO entry : visitsList) { - String tradeDay = entry.getTradeDay(); - BigInteger countOrder = entry.getCount(); - dataVisitsMap.put(tradeDay, new CountVisitsVO(tradeDay, countOrder)); - } - // 转换为字符串 - List countVisitsLists = new ArrayList<>(); - for (int i = 0; i < 30; i++) { - LocalDate tradeDayLocalDate = today.minusDays(i); - String tradeDayString = tradeDayLocalDate.format(formatter); - CountVisitsVO countDateVO; - // 检查数据Map中是否存在该日期的数据 - if (dataVisitsMap.containsKey(tradeDayString)) { - countDateVO = dataVisitsMap.get(tradeDayString); - } else { - // 如果不存在,则创建新的SumDateVO对象,amount设为0 - countDateVO = new CountVisitsVO(tradeDayString, BigInteger.ZERO); - } - // 将SumDateVO对象添加到列表中 - countVisitsLists.add(countDateVO); - } - countVisitsLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay())); - summaryVO.setVisitsCountList(countVisitsLists); - return summaryVO; + count.put("saveAmount",orderMap.get("saveAmount"));//优惠金额 + count.put("saveNum",orderMap.get("saveNum"));//优惠单数 + result.put("count",count); + return result; } + +// @Override +// public SummaryVO selectSummary(Integer shopId) { +// SummaryVO summaryVO = new SummaryVO(); +// //支付笔数, +// Tuple result = tbOrderInfoRepository.countByShopId(shopId.toString()); +// summaryVO.setPaymentsNumber(result.get(0, Long.class) == null ? 0L : result.get(0, Long.class)); +// summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null ? new BigDecimal("0") : result.get(1, BigDecimal.class)); +// if (summaryVO.getPaymentsNumber() == 0) { +// summaryVO.setAverageSales(new BigDecimal("0")); +// } else { +// summaryVO.setAverageSales(summaryVO.getTotalSales().divide(new BigDecimal(summaryVO.getPaymentsNumber()), 2, RoundingMode.DOWN)); +// } +// //用户数 +// Tuple count = tbShopUserRepository.searchByCount(shopId.toString()); +// summaryVO.setTotalUser(count == null ? 0L : count.get(0, Long.class)); +// //支付笔数柱形图 +// List objects = tbOrderInfoRepository.sumByDateOrderNum(shopId.toString(), DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd()); +// List countDateList = new ArrayList<>(); +// for (Object[] o : objects) { +// CountDateVO countDateVO = new CountDateVO(); +// BigInteger integers = (BigInteger) o[0]; +// countDateVO.setCount(new BigDecimal(integers.toString())); +// countDateVO.setTradeDay((String) o[1]); +// countDateList.add(countDateVO); +// } +// //填充日期 +// Map dataMap = new HashMap<>(); +// for (CountDateVO entry : countDateList) { +// String tradeDay = entry.getTradeDay(); +// BigDecimal countOrder = entry.getCount(); +// dataMap.put(tradeDay, new CountDateVO(tradeDay, countOrder)); +// } +// // 获取今天的日期 +// LocalDate today = LocalDate.now(); +// // 定义日期格式 +// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); +// // 转换为字符串 +// List countDateLists = new ArrayList<>(); +// for (int i = 0; i < 30; i++) { +// LocalDate tradeDayLocalDate = today.minusDays(i); +// String tradeDayString = tradeDayLocalDate.format(formatter); +// CountDateVO countDateVO; +// // 检查数据Map中是否存在该日期的数据 +// if (dataMap.containsKey(tradeDayString)) { +// countDateVO = dataMap.get(tradeDayString); +// } else { +// // 如果不存在,则创建新的SumDateVO对象,amount设为0 +// countDateVO = new CountDateVO(tradeDayString, BigDecimal.ZERO); +// } +// // 将SumDateVO对象添加到列表中 +// countDateLists.add(countDateVO); +// } +// countDateLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay())); +// summaryVO.setCountDateList(countDateLists); +// //访问量 +// Tuple tuple = tbTokenRepository.countByAccountId(shopId); +// summaryVO.setTotalVisits(tuple == null ? 0L : tuple.get(0, Long.class)); +// //访问量柱状图 +// List objectsVisits = tbTokenRepository.countByMonth(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd()); +// List visitsList = new ArrayList<>(); +// for (Object[] o : objectsVisits) { +// CountVisitsVO countDateVO = new CountVisitsVO(); +// countDateVO.setCount((BigInteger) o[0]); +// countDateVO.setTradeDay((String) o[1]); +// visitsList.add(countDateVO); +// } +// //填充日期 +// Map dataVisitsMap = new HashMap<>(); +// for (CountVisitsVO entry : visitsList) { +// String tradeDay = entry.getTradeDay(); +// BigInteger countOrder = entry.getCount(); +// dataVisitsMap.put(tradeDay, new CountVisitsVO(tradeDay, countOrder)); +// } +// // 转换为字符串 +// List countVisitsLists = new ArrayList<>(); +// for (int i = 0; i < 30; i++) { +// LocalDate tradeDayLocalDate = today.minusDays(i); +// String tradeDayString = tradeDayLocalDate.format(formatter); +// CountVisitsVO countDateVO; +// // 检查数据Map中是否存在该日期的数据 +// if (dataVisitsMap.containsKey(tradeDayString)) { +// countDateVO = dataVisitsMap.get(tradeDayString); +// } else { +// // 如果不存在,则创建新的SumDateVO对象,amount设为0 +// countDateVO = new CountVisitsVO(tradeDayString, BigInteger.ZERO); +// } +// // 将SumDateVO对象添加到列表中 +// countVisitsLists.add(countDateVO); +// } +// countVisitsLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay())); +// summaryVO.setVisitsCountList(countVisitsLists); +// return summaryVO; +// } + @Override public Map selectSummaryDate(Integer shopId, Integer day) { Date startTime = new Date(); From ced7d4bc7d0ad4f2e6423bdcb63a5966c9f4d44c Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 10 Sep 2024 15:54:40 +0800 Subject: [PATCH 02/56] =?UTF-8?q?=E9=A6=96=E9=A1=B5=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/shop/SummaryController.java | 16 +- .../java/cn/ysk/cashier/dto/BaseQueryDto.java | 36 +++ .../mybatis/mapper/TbShopUserFlowMapper.java | 29 ++- .../order/TbOrderInfoRepository.java | 17 ++ .../ysk/cashier/service/SummaryService.java | 4 +- .../service/impl/SummaryServiceImpl.java | 234 +++++++++++------- 6 files changed, 243 insertions(+), 93 deletions(-) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/BaseQueryDto.java diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java index e7f09c34..bcdd6f4e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java @@ -2,6 +2,7 @@ package cn.ysk.cashier.controller.shop; import cn.ysk.cashier.annotation.rest.AnonymousGetMapping; import cn.ysk.cashier.annotation.rest.AnonymousPostMapping; +import cn.ysk.cashier.dto.BaseQueryDto; import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto; import cn.ysk.cashier.service.SummaryService; import lombok.RequiredArgsConstructor; @@ -23,11 +24,20 @@ public class SummaryController { @Resource private SummaryService summaryService; - @GetMapping - private Object shopSummary(@RequestParam Integer shopId) { - return summaryService.selectSummary(shopId); + + @PostMapping("/trade") + @AnonymousPostMapping + private Object shopSummaryDate(@RequestBody BaseQueryDto param) { + return summaryService.trade(param); } + + +// @GetMapping +// private Object shopSummary(@RequestParam Integer shopId) { +// return summaryService.selectSummary(shopId); +// } + @GetMapping("/date") private Object shopSummaryDate(@RequestParam Integer shopId, @RequestParam Integer day) { return summaryService.selectSummaryDate(shopId, day); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/BaseQueryDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BaseQueryDto.java new file mode 100644 index 00000000..1d8117ff --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/BaseQueryDto.java @@ -0,0 +1,36 @@ +package cn.ysk.cashier.dto; + +import org.springframework.format.annotation.DateTimeFormat; +import java.util.Date; + +public class BaseQueryDto { + private Integer shopId; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date startTime; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endTime; + + public Integer getShopId() { + return shopId; + } + + public void setShopId(Integer shopId) { + this.shopId = shopId; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopUserFlowMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopUserFlowMapper.java index 6e80822b..d4053259 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopUserFlowMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopUserFlowMapper.java @@ -5,9 +5,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; -import javax.validation.Valid; import java.math.BigDecimal; import java.util.List; +import java.util.Map; /** * @author GYJ @@ -41,6 +41,33 @@ public interface TbShopUserFlowMapper extends BaseMapper { @Param("startTime") String startTime, @Param("endTime") String endTime); + @Select("") + Map tradeIndexFlow(@Param("shopId") Integer shopId, + @Param("startTime") String startTime, + @Param("endTime") String endTime); + + @Select("") + Integer tradeIndexNewFlow(@Param("shopId") Integer shopId, @Param("startTime") String startTime, @Param("endTime") String endTime); + @Select(value = "select * from tb_shop_user_flow where shop_user_id=#{userId} order by id desc limit #{page},#{size}") List selectByUserId(@Param("userId") Integer userId,@Param("page") Integer page,@Param("size") Integer size); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java index c59da55c..69efbe63 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java @@ -31,6 +31,7 @@ import javax.persistence.Tuple; import java.math.BigDecimal; import java.util.Date; import java.util.List; +import java.util.Map; /** * @website https://eladmin.vip @@ -54,6 +55,22 @@ public interface TbOrderInfoRepository extends JpaRepository:start AND info.createdAt<:end") TbOrderPayCountVo queryTbOrderRefund(@Param("shopId")String shopId, @Param("tableName") String tableName ,@Param("start") Long start, @Param("end") Long end); + @Query(value = "SELECT " + + "COALESCE(SUM( info.order_amount ),0) AS 'saleAmount'," + + "COALESCE(count( 1 ),0) AS 'saleNum'," + + "COALESCE(sum( discount_amount ),0) AS 'saveAmount'," + + "COALESCE(COUNT( CASE WHEN discount_amount IS NOT NULL AND discount_amount > 0.00 THEN 1 ELSE NULL END ),0) AS 'saveNum' " + + "FROM tb_order_info info " + + "WHERE info.shop_id = :shopId " + + "AND info.created_at > :startTime AND info.created_at < :endTime " + + "AND ((info.STATUS = 'closed' ) OR ( info.STATUS = 'refund' AND info.order_type != 'return' ))", nativeQuery = true) + Map tradeIndex(@Param("shopId") Integer shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); + @Query(value = "SELECT COALESCE(SUM(info.order_amount),0) FROM tb_order_info info " + + "WHERE info.shop_id = :shopId AND info.order_type = 'return' " + + "AND info.created_at > :startTime AND info.created_at < :endTime", nativeQuery = true) + BigDecimal tradeIndexRefund(@Param("shopId") Integer shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); + + @Query(value = "SELECT COUNT(1) ,pay_type AS payType FROM tb_order_info Where shop_id = :shopId AND " + " created_at BETWEEN :startTime AND :endTime AND status='closed'AND order_type <>'return' GROUP BY pay_type", nativeQuery = true) List countByShopId(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java index 61615be7..330398a8 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.service; +import cn.ysk.cashier.dto.BaseQueryDto; import cn.ysk.cashier.dto.ShopSummaryDto; import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto; import cn.ysk.cashier.vo.ShopTableSaleInfoVo; @@ -17,8 +18,9 @@ import java.util.Map; * @author lyf */ public interface SummaryService { - SummaryVO selectSummary(Integer shop); + Map trade(BaseQueryDto param); +// SummaryVO selectSummary(Integer shop); Map selectSummaryDate(Integer shopId, Integer day); Map selectSummaryToday(Integer shopId); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index e6c3a59e..ca5294c9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -1,15 +1,19 @@ package cn.ysk.cashier.service.impl; +import cn.hutool.core.util.ObjectUtil; import cn.ysk.cashier.dto.ShopSummaryDto; +import cn.ysk.cashier.dto.BaseQueryDto; import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto; import cn.ysk.cashier.enums.PayTypeEnum; import cn.ysk.cashier.exception.BadRequestException; +import cn.ysk.cashier.mybatis.mapper.TbShopUserFlowMapper; import cn.ysk.cashier.mybatis.service.TbShopUserFlowService; import cn.ysk.cashier.repository.ShopUserDutyDetailRepository; import cn.ysk.cashier.repository.ShopUserDutyRepository; import cn.ysk.cashier.repository.TbTokenRepository; import cn.ysk.cashier.repository.order.TbOrderDetailRepository; import cn.ysk.cashier.repository.order.TbOrderInfoRepository; +import cn.ysk.cashier.repository.shop.TbShopTableRepository; import cn.ysk.cashier.repository.shop.TbShopUserRepository; import cn.ysk.cashier.service.SummaryService; import cn.ysk.cashier.utils.DateUtil; @@ -56,106 +60,160 @@ public class SummaryServiceImpl implements SummaryService { @Resource private TbTokenRepository tbTokenRepository; + @Autowired + private TbShopUserFlowMapper tbShopUserFlowMapper; @Resource private TbShopUserFlowService tbShopUserFlowService; + @Autowired private TbOrderDetailRepository tbOrderDetailRepository; + private final TbShopTableRepository tbShopTableRepository; @Override - public SummaryVO selectSummary(Integer shopId) { - SummaryVO summaryVO = new SummaryVO(); - //支付笔数, - Tuple result = tbOrderInfoRepository.countByShopId(shopId.toString()); - summaryVO.setPaymentsNumber(result.get(0, Long.class) == null ? 0L : result.get(0, Long.class)); - summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null ? new BigDecimal("0") : result.get(1, BigDecimal.class)); - if (summaryVO.getPaymentsNumber() == 0) { - summaryVO.setAverageSales(new BigDecimal("0")); - } else { - summaryVO.setAverageSales(summaryVO.getTotalSales().divide(new BigDecimal(summaryVO.getPaymentsNumber()), 2, RoundingMode.DOWN)); + public Map trade(BaseQueryDto param) { + if (ObjectUtil.isNull(param.getShopId())) { + throw new BadRequestException("参数不合法"); } - //用户数 - Tuple count = tbShopUserRepository.searchByCount(shopId.toString()); - summaryVO.setTotalUser(count == null ? 0L : count.get(0, Long.class)); - //支付笔数柱形图 - List objects = tbOrderInfoRepository.sumByDateOrderNum(shopId.toString(), DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd()); - List countDateList = new ArrayList<>(); - for (Object[] o : objects) { - CountDateVO countDateVO = new CountDateVO(); - BigInteger integers = (BigInteger) o[0]; - countDateVO.setCount(new BigDecimal(integers.toString())); - countDateVO.setTradeDay((String) o[1]); - countDateList.add(countDateVO); + Map result = new HashMap<>(); + Map sale = new HashMap<>(); + Map vip = new HashMap<>(); + Map count = new HashMap<>(); + //订单 销售金额 saleAmount /订单数 saleNum /优惠金额 saveAmount /优惠笔数 saveNum + Map orderMap = tbOrderInfoRepository.tradeIndex(param.getShopId(), param.getStartTime().getTime(), param.getEndTime().getTime()); + //退款金额 + BigDecimal refundAmount = tbOrderInfoRepository.tradeIndexRefund(param.getShopId(), param.getStartTime().getTime(), param.getEndTime().getTime()); + + //会员 充值金额 inAmount /退款金额 outAmount /会员消费金额 useAmount /会员消费笔数 useNum + Map flowMap = tbShopUserFlowMapper.tradeIndexFlow(param.getShopId(), DateUtil.getStrTime(param.getStartTime()), DateUtil.getStrTime(param.getEndTime())); + // 新增会员数 + Integer newFlow = tbShopUserFlowMapper.tradeIndexNewFlow(param.getShopId(), DateUtil.getStrTime(param.getStartTime()), DateUtil.getStrTime(param.getEndTime())); + //台桌数 + int tables = tbShopTableRepository.countAllByShopId(param.getShopId()); + sale.put("totalSaleAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(refundAmount));//总金额 + sale.put("incomeAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(new BigDecimal(flowMap.get("inAmount").toString())));//实收 + sale.put("refundAmount", refundAmount);//销售退款金额 + sale.put("inAmount", flowMap.get("inAmount"));//会员充值金额 + sale.put("outAmount", flowMap.get("outAmount"));//会员退款金额 + result.put("sale",sale); + vip.put("useAmount", flowMap.get("useAmount"));//会员消费金额 + vip.put("newFlow",newFlow);//新增会员数 + vip.put("useNum",flowMap.get("useNum"));//会员消费笔数 + result.put("vip",vip); + BigDecimal saleAmount = new BigDecimal(orderMap.get("saleAmount").toString()).add(refundAmount); + //客单价 + if(saleAmount.compareTo(BigDecimal.ZERO) == 0){ + count.put("unitPrice",BigDecimal.ZERO); + }else { + count.put("unitPrice",saleAmount.divide(new BigDecimal(orderMap.get("saleNum").toString()),2,RoundingMode.DOWN)); } - //填充日期 - Map dataMap = new HashMap<>(); - for (CountDateVO entry : countDateList) { - String tradeDay = entry.getTradeDay(); - BigDecimal countOrder = entry.getCount(); - dataMap.put(tradeDay, new CountDateVO(tradeDay, countOrder)); + BigDecimal saleNum = new BigDecimal(orderMap.get("saleNum").toString()); + if(saleNum.compareTo(BigDecimal.ZERO) == 0){ + count.put("turnoverRate",BigDecimal.ZERO);//翻台率 + }else { + count.put("turnoverRate",saleNum.divide(new BigDecimal(tables),2,RoundingMode.DOWN));//翻台率 } - // 获取今天的日期 - LocalDate today = LocalDate.now(); - // 定义日期格式 - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - // 转换为字符串 - List countDateLists = new ArrayList<>(); - for (int i = 0; i < 30; i++) { - LocalDate tradeDayLocalDate = today.minusDays(i); - String tradeDayString = tradeDayLocalDate.format(formatter); - CountDateVO countDateVO; - // 检查数据Map中是否存在该日期的数据 - if (dataMap.containsKey(tradeDayString)) { - countDateVO = dataMap.get(tradeDayString); - } else { - // 如果不存在,则创建新的SumDateVO对象,amount设为0 - countDateVO = new CountDateVO(tradeDayString, BigDecimal.ZERO); - } - // 将SumDateVO对象添加到列表中 - countDateLists.add(countDateVO); - } - countDateLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay())); - summaryVO.setCountDateList(countDateLists); - //访问量 - Tuple tuple = tbTokenRepository.countByAccountId(shopId); - summaryVO.setTotalVisits(tuple == null ? 0L : tuple.get(0, Long.class)); - //访问量柱状图 - List objectsVisits = tbTokenRepository.countByMonth(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd()); - List visitsList = new ArrayList<>(); - for (Object[] o : objectsVisits) { - CountVisitsVO countDateVO = new CountVisitsVO(); - countDateVO.setCount((BigInteger) o[0]); - countDateVO.setTradeDay((String) o[1]); - visitsList.add(countDateVO); - } - //填充日期 - Map dataVisitsMap = new HashMap<>(); - for (CountVisitsVO entry : visitsList) { - String tradeDay = entry.getTradeDay(); - BigInteger countOrder = entry.getCount(); - dataVisitsMap.put(tradeDay, new CountVisitsVO(tradeDay, countOrder)); - } - // 转换为字符串 - List countVisitsLists = new ArrayList<>(); - for (int i = 0; i < 30; i++) { - LocalDate tradeDayLocalDate = today.minusDays(i); - String tradeDayString = tradeDayLocalDate.format(formatter); - CountVisitsVO countDateVO; - // 检查数据Map中是否存在该日期的数据 - if (dataVisitsMap.containsKey(tradeDayString)) { - countDateVO = dataVisitsMap.get(tradeDayString); - } else { - // 如果不存在,则创建新的SumDateVO对象,amount设为0 - countDateVO = new CountVisitsVO(tradeDayString, BigInteger.ZERO); - } - // 将SumDateVO对象添加到列表中 - countVisitsLists.add(countDateVO); - } - countVisitsLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay())); - summaryVO.setVisitsCountList(countVisitsLists); - return summaryVO; + count.put("saveAmount",orderMap.get("saveAmount"));//优惠金额 + count.put("saveNum",orderMap.get("saveNum"));//优惠单数 + result.put("count",count); + return result; } + +// @Override +// public SummaryVO selectSummary(Integer shopId) { +// SummaryVO summaryVO = new SummaryVO(); +// //支付笔数, +// Tuple result = tbOrderInfoRepository.countByShopId(shopId.toString()); +// summaryVO.setPaymentsNumber(result.get(0, Long.class) == null ? 0L : result.get(0, Long.class)); +// summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null ? new BigDecimal("0") : result.get(1, BigDecimal.class)); +// if (summaryVO.getPaymentsNumber() == 0) { +// summaryVO.setAverageSales(new BigDecimal("0")); +// } else { +// summaryVO.setAverageSales(summaryVO.getTotalSales().divide(new BigDecimal(summaryVO.getPaymentsNumber()), 2, RoundingMode.DOWN)); +// } +// //用户数 +// Tuple count = tbShopUserRepository.searchByCount(shopId.toString()); +// summaryVO.setTotalUser(count == null ? 0L : count.get(0, Long.class)); +// //支付笔数柱形图 +// List objects = tbOrderInfoRepository.sumByDateOrderNum(shopId.toString(), DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd()); +// List countDateList = new ArrayList<>(); +// for (Object[] o : objects) { +// CountDateVO countDateVO = new CountDateVO(); +// BigInteger integers = (BigInteger) o[0]; +// countDateVO.setCount(new BigDecimal(integers.toString())); +// countDateVO.setTradeDay((String) o[1]); +// countDateList.add(countDateVO); +// } +// //填充日期 +// Map dataMap = new HashMap<>(); +// for (CountDateVO entry : countDateList) { +// String tradeDay = entry.getTradeDay(); +// BigDecimal countOrder = entry.getCount(); +// dataMap.put(tradeDay, new CountDateVO(tradeDay, countOrder)); +// } +// // 获取今天的日期 +// LocalDate today = LocalDate.now(); +// // 定义日期格式 +// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); +// // 转换为字符串 +// List countDateLists = new ArrayList<>(); +// for (int i = 0; i < 30; i++) { +// LocalDate tradeDayLocalDate = today.minusDays(i); +// String tradeDayString = tradeDayLocalDate.format(formatter); +// CountDateVO countDateVO; +// // 检查数据Map中是否存在该日期的数据 +// if (dataMap.containsKey(tradeDayString)) { +// countDateVO = dataMap.get(tradeDayString); +// } else { +// // 如果不存在,则创建新的SumDateVO对象,amount设为0 +// countDateVO = new CountDateVO(tradeDayString, BigDecimal.ZERO); +// } +// // 将SumDateVO对象添加到列表中 +// countDateLists.add(countDateVO); +// } +// countDateLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay())); +// summaryVO.setCountDateList(countDateLists); +// //访问量 +// Tuple tuple = tbTokenRepository.countByAccountId(shopId); +// summaryVO.setTotalVisits(tuple == null ? 0L : tuple.get(0, Long.class)); +// //访问量柱状图 +// List objectsVisits = tbTokenRepository.countByMonth(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd()); +// List visitsList = new ArrayList<>(); +// for (Object[] o : objectsVisits) { +// CountVisitsVO countDateVO = new CountVisitsVO(); +// countDateVO.setCount((BigInteger) o[0]); +// countDateVO.setTradeDay((String) o[1]); +// visitsList.add(countDateVO); +// } +// //填充日期 +// Map dataVisitsMap = new HashMap<>(); +// for (CountVisitsVO entry : visitsList) { +// String tradeDay = entry.getTradeDay(); +// BigInteger countOrder = entry.getCount(); +// dataVisitsMap.put(tradeDay, new CountVisitsVO(tradeDay, countOrder)); +// } +// // 转换为字符串 +// List countVisitsLists = new ArrayList<>(); +// for (int i = 0; i < 30; i++) { +// LocalDate tradeDayLocalDate = today.minusDays(i); +// String tradeDayString = tradeDayLocalDate.format(formatter); +// CountVisitsVO countDateVO; +// // 检查数据Map中是否存在该日期的数据 +// if (dataVisitsMap.containsKey(tradeDayString)) { +// countDateVO = dataVisitsMap.get(tradeDayString); +// } else { +// // 如果不存在,则创建新的SumDateVO对象,amount设为0 +// countDateVO = new CountVisitsVO(tradeDayString, BigInteger.ZERO); +// } +// // 将SumDateVO对象添加到列表中 +// countVisitsLists.add(countDateVO); +// } +// countVisitsLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay())); +// summaryVO.setVisitsCountList(countVisitsLists); +// return summaryVO; +// } + @Override public Map selectSummaryDate(Integer shopId, Integer day) { Date startTime = new Date(); From df4886d62cd70f2d4ab2d77c6c842d002ee34a75 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 10 Sep 2024 16:11:36 +0800 Subject: [PATCH 03/56] =?UTF-8?q?=E7=BF=BB=E5=8F=B0=E7=8E=87=20=E7=99=BE?= =?UTF-8?q?=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index ca5294c9..a3659869 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -109,9 +109,9 @@ public class SummaryServiceImpl implements SummaryService { } BigDecimal saleNum = new BigDecimal(orderMap.get("saleNum").toString()); if(saleNum.compareTo(BigDecimal.ZERO) == 0){ - count.put("turnoverRate",BigDecimal.ZERO);//翻台率 + count.put("turnoverRate",BigDecimal.ZERO+"%");//翻台率 }else { - count.put("turnoverRate",saleNum.divide(new BigDecimal(tables),2,RoundingMode.DOWN));//翻台率 + count.put("turnoverRate",saleNum.divide(new BigDecimal(tables),2,RoundingMode.DOWN).subtract(BigDecimal.ONE).multiply(new BigDecimal("100"))+"%");//翻台率 } count.put("saveAmount",orderMap.get("saveAmount"));//优惠金额 count.put("saveNum",orderMap.get("saveNum"));//优惠单数 From 18614278a780071c2a276f015c2d259e1af40dd6 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 10 Sep 2024 16:11:36 +0800 Subject: [PATCH 04/56] =?UTF-8?q?=E7=BF=BB=E5=8F=B0=E7=8E=87=20=E7=99=BE?= =?UTF-8?q?=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index ca5294c9..a3659869 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -109,9 +109,9 @@ public class SummaryServiceImpl implements SummaryService { } BigDecimal saleNum = new BigDecimal(orderMap.get("saleNum").toString()); if(saleNum.compareTo(BigDecimal.ZERO) == 0){ - count.put("turnoverRate",BigDecimal.ZERO);//翻台率 + count.put("turnoverRate",BigDecimal.ZERO+"%");//翻台率 }else { - count.put("turnoverRate",saleNum.divide(new BigDecimal(tables),2,RoundingMode.DOWN));//翻台率 + count.put("turnoverRate",saleNum.divide(new BigDecimal(tables),2,RoundingMode.DOWN).subtract(BigDecimal.ONE).multiply(new BigDecimal("100"))+"%");//翻台率 } count.put("saveAmount",orderMap.get("saveAmount"));//优惠金额 count.put("saveNum",orderMap.get("saveNum"));//优惠单数 From 535079c14decb3cba08254d76da566a5a92c2fde Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 11 Sep 2024 11:02:29 +0800 Subject: [PATCH 05/56] =?UTF-8?q?=E5=BA=97=E9=93=BA=E4=BF=A1=E6=81=AF=20?= =?UTF-8?q?=E6=A1=8C=E4=BD=8D=E8=B4=B9=20=E6=94=B6=E6=AC=BE=E7=A0=81=20?= =?UTF-8?q?=E4=BB=98=E6=AC=BE=E6=A8=A1=E5=BC=8F=20=E5=B0=B1=E9=A4=90?= =?UTF-8?q?=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysk/cashier/dto/shop/TbShopInfoDto.java | 7 +++++++ .../cashier/mapper/shop/TbShopInfoMapper.java | 20 +++++++++++++++++++ .../cn/ysk/cashier/pojo/shop/TbShopInfo.java | 17 +++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopInfoDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopInfoDto.java index 8560fec3..a2b667d8 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopInfoDto.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopInfoDto.java @@ -23,6 +23,7 @@ import javax.persistence.Column; import javax.validation.constraints.NotBlank; import java.math.BigDecimal; import java.io.Serializable; +import java.util.List; /** * @website https://eladmin.vip @@ -192,4 +193,10 @@ public class TbShopInfoDto implements Serializable { private String isReturn; private String isMemberIn; private String isMemberReturn; + private Integer isTableFee; + private BigDecimal tableFee; + private List eatModel; + //程序码(零点八零首页) + private String smallQrcode; + private String paymentQrcode; } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mapper/shop/TbShopInfoMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mapper/shop/TbShopInfoMapper.java index 0749836d..6cc0ada3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mapper/shop/TbShopInfoMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mapper/shop/TbShopInfoMapper.java @@ -18,8 +18,13 @@ package cn.ysk.cashier.mapper.shop; import cn.ysk.cashier.base.BaseMapper; import cn.ysk.cashier.pojo.shop.TbShopInfo; import cn.ysk.cashier.dto.shop.TbShopInfoDto; +import cn.ysk.cashier.utils.ListUtil; import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; +import org.springframework.util.CollectionUtils; + +import java.util.List; +import java.util.stream.Collectors; /** * @website https://eladmin.vip @@ -29,4 +34,19 @@ import org.mapstruct.ReportingPolicy; @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface TbShopInfoMapper extends BaseMapper { + // 自定义的字符串到整数列表的转换方法 + default List map(String value) { + return ListUtil.stringChangeStringList(value); + } + + // 如果需要从DTO转回实体,也可能需要实现反向的映射方法 + default String map(List values) { + if (!CollectionUtils.isEmpty(values)) { + return ""; + } + // 将整数列表转换为由逗号分隔的字符串 + return values.stream() + .map(String::valueOf) + .collect(Collectors.joining(",")); + } } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java index 5f8a7944..6bd14fa1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java @@ -258,13 +258,28 @@ public class TbShopInfo implements Serializable { @ApiModelProperty(value = "是否允许用户自定义金额") private String isMemberIn; - @Column(name = "is_member_return") @ApiModelProperty(value = "是否允许用户自定义金额") private String isMemberReturn; + @Column(name = "is_table_fee") + @ApiModelProperty(value = "是否免除桌位费 0否1是") + private Integer isTableFee; + @Column(name = "tableFee") + @ApiModelProperty(value = "桌位费") + private BigDecimal tableFee; + @Column(name = "eat_model") + @ApiModelProperty(value = "就餐模式 堂食 dine-in 外带 take-out") + private String eatModel; + + @Column(name = "small_qrcode") + @ApiModelProperty(value = "程序码(零点八零首页)") + private String smallQrcode; + @Column(name = "payment_qrcode") + @ApiModelProperty(value = "店铺收款码") + private String paymentQrcode; public void copy(TbShopInfo source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false)); From 10290bd37bb1a48b927210f1bf27180709a85eaa Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 11:17:39 +0800 Subject: [PATCH 06/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E9=80=80=E5=8D=95=E6=8E=A5=E5=8F=A3=20=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=8F=B0=E6=A1=8C=20=E9=80=89=E6=8B=A9=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/cons/rabbit/RabbitConstants.java | 5 + .../controller/product/TbPlaceController.java | 34 +++ .../ysk/cashier/dto/shoptable/AddCartDTO.java | 3 +- .../cashier/dto/shoptable/ChoseCountDTO.java | 20 ++ .../cashier/dto/shoptable/ChoseTableDTO.java | 19 ++ .../cashier/dto/shoptable/ReturnOrderDTO.java | 15 + .../ysk/cashier/pojo/order/TbCashierCart.java | 2 + .../ysk/cashier/pojo/order/TbOrderDetail.java | 6 + .../ysk/cashier/pojo/order/TbOrderInfo.java | 3 + .../cn/ysk/cashier/service/TbPayService.java | 7 +- .../service/impl/TbPayServiceImpl.java | 134 ++------- .../impl/shopimpl/TbShopTableServiceImpl.java | 283 +++++++++++++++--- .../service/shop/TbShopTableService.java | 9 +- .../cn/ysk/cashier/utils/RabbitMsgUtils.java | 8 + 14 files changed, 397 insertions(+), 151 deletions(-) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ChoseCountDTO.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ChoseTableDTO.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ReturnOrderDTO.java diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rabbit/RabbitConstants.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rabbit/RabbitConstants.java index 5f622ddc..51221d37 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rabbit/RabbitConstants.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rabbit/RabbitConstants.java @@ -19,4 +19,9 @@ public interface RabbitConstants { // 售出记录 String EXCHANGE_STOCK_RECORD = "exchange.stock.record"; String ROUTING_STOCK_RECORD_SALE = "routing.stock.record.sale"; + + // 菜品打印 + String EXCHANGE_PRINT = "exchange.print"; + String ROUTING_KEY_PRINT_DISHES = "routing.dishes.print"; + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java index d6b4ef92..a620268a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java @@ -86,6 +86,15 @@ public class TbPlaceController { tbShopTableService.removeCart(removeCartDTO); return new ResponseEntity<>(HttpStatus.OK); } + + @AnonymousAccess + @PutMapping("/returnOrder") + @Log("代客下单 退单") + @ApiOperation("代客下单 清空购物车 /shop/table") + public ResponseEntity returnOrder(@Validated @RequestBody RemoveCartDTO removeCartDTO) { + tbShopTableService.returnCart(removeCartDTO); + return new ResponseEntity<>(HttpStatus.OK); + } @AnonymousAccess @DeleteMapping("/clearCart") @@ -192,6 +201,31 @@ public class TbPlaceController { return ResponseEntity.ok(tbShopTableService.pay(payDTO)); } + @AnonymousAccess + + @PutMapping("/choseTable") + @Log("代客下单 选择台桌") + @ApiOperation("代客下单 选择台桌 /shop/table") + public ResponseEntity choseTable( + @Validated @RequestBody ChoseTableDTO choseTableDTO + ) { + + return ResponseEntity.ok(tbShopTableService.choseTable(choseTableDTO)); + } + @AnonymousAccess + + @PutMapping("/choseCount") + @Log("代客下单 选择用餐人数") + @ApiOperation("代客下单 选择台桌 /shop/table") + public ResponseEntity choseCount( + @Validated @RequestBody ChoseCountDTO choseCountDTO + ) { + + return ResponseEntity.ok(tbShopTableService.choseCount(choseCountDTO)); + } + + + @AnonymousAccess @PutMapping("/updateVip") @Log("代客下单 查询购物车") diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/AddCartDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/AddCartDTO.java index 7508701f..c64b654c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/AddCartDTO.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/AddCartDTO.java @@ -20,9 +20,10 @@ public class AddCartDTO { @NotEmpty private String tableId; @NotNull - @Min(0) + @Min(1) private Integer num; private boolean isPack; private boolean isGift; private Integer cartId; + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ChoseCountDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ChoseCountDTO.java new file mode 100644 index 00000000..795d1525 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ChoseCountDTO.java @@ -0,0 +1,20 @@ +package cn.ysk.cashier.dto.shoptable; + +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Data +public class ChoseCountDTO { + @NotEmpty + private String masterId; + @NotNull + private Integer shopId; + @NotEmpty + private String tableId; + @NotNull + @Min(1) + private Integer num; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ChoseTableDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ChoseTableDTO.java new file mode 100644 index 00000000..2d3728c1 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ChoseTableDTO.java @@ -0,0 +1,19 @@ +package cn.ysk.cashier.dto.shoptable; + +import lombok.Data; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Data +public class ChoseTableDTO { + @NotNull + private Integer shopId; + private Integer orderId; + @NotNull + private String newTableId; + @NotEmpty + private String oldTableId; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ReturnOrderDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ReturnOrderDTO.java new file mode 100644 index 00000000..74e6c3e9 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ReturnOrderDTO.java @@ -0,0 +1,15 @@ +package cn.ysk.cashier.dto.shoptable; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +public class ReturnOrderDTO { + @NotNull + private Integer cartId; + @NotNull + private Integer shopId; + @NotNull + private Long tableId; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java index 0496bf4d..b87e46bf 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java @@ -155,6 +155,8 @@ public class TbCashierCart implements Serializable { private String uuid; @Column(name = "`sku_name`") private String skuName; + @Column(name = "`place_num`") + private Integer placeNum; public void copy(TbCashierCart source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java index 1fbe6c20..60437fcc 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java @@ -15,6 +15,7 @@ */ package cn.ysk.cashier.pojo.order; +import com.baomidou.mybatisplus.annotation.TableField; import lombok.Data; import cn.hutool.core.bean.BeanUtil; import io.swagger.annotations.ApiModelProperty; @@ -101,12 +102,17 @@ public class TbOrderDetail implements Serializable { @Transient @ApiModelProperty(value = "退单数量") + @TableField(exist = false) private Integer refundNumber; @Column(name = "`is_vip`") @ApiModelProperty(value = "isVip") private Integer isVip; + @Column(name = "`place_num`") + @ApiModelProperty(value = "place_num") + private Integer placeNum; + public void copy(TbOrderDetail source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java index 4ac4f9e8..760aa648 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java @@ -228,6 +228,9 @@ public class TbOrderInfo implements Serializable { private String isUseCoupon; @Column(name = "`use_type`") private String useType; + @Column(name = "`place_num`") + @ApiModelProperty(value = "place_num") + private Integer placeNum; public void copy(TbOrderInfo source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/TbPayService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/TbPayService.java index 90ee4cd9..c73da59f 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/TbPayService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/TbPayService.java @@ -7,14 +7,15 @@ import cn.ysk.cashier.pojo.order.TbOrderInfo; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; +import java.math.BigDecimal; public interface TbPayService { - TbOrderInfo scanPay(PayDTO payDTO); + TbOrderInfo scanPay(Integer shopId, String code, Integer merchantId, Integer memberId, BigDecimal payMount, TbOrderInfo orderInfo); - TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId, Double discount, Integer vipUserId); + void vipPay(BigDecimal payMount, Integer vipUserId); TbOrderInfo cashPay(PayDTO payDTO); - TbOrderInfo memberAccountPay(String memberId, String shopId, String accountCode, Integer orderId, Double discount) throws Exception; + TbOrderInfo memberAccountPay(String memberId, String shopId, String accountCode, TbOrderInfo orderInfo, BigDecimal payMount) throws Exception; } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/TbPayServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/TbPayServiceImpl.java index 9b15f6b0..939af193 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/TbPayServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/TbPayServiceImpl.java @@ -106,29 +106,20 @@ public class TbPayServiceImpl implements TbPayService { } @Override - public TbOrderInfo scanPay(PayDTO scanPayDTO) { - if (StrUtil.isBlank(scanPayDTO.getCode())) { + public TbOrderInfo scanPay(Integer shopId, String code, Integer merchantId, Integer memberId, BigDecimal payMount, TbOrderInfo orderInfo) { + if (StrUtil.isBlank(code)) { throw new BadRequestException("无效码"); } - TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaUpdateWrapper() - .in(TbOrderInfo::getStatus, "unpaid", "paying") - .eq(TbOrderInfo::getId, scanPayDTO.getOrderId()) - .eq(TbOrderInfo::getShopId, scanPayDTO.getShopId())); - if (orderInfo == null) { - throw new BadRequestException("订单不存在或已支付"); - } - - - if (ObjectUtil.isNull(orderInfo.getMerchantId()) || ObjectUtil.isEmpty(orderInfo.getMerchantId())) { + if (merchantId == null) { throw new BadRequestException("订单商户id为空"); } List cashierCarts = cashierCartMapper.selectList(new LambdaUpdateWrapper() - .eq(TbCashierCart::getShopId, scanPayDTO.getShopId()) - .eq(TbCashierCart::getOrderId, scanPayDTO.getOrderId())); + .eq(TbCashierCart::getShopId, shopId) + .eq(TbCashierCart::getOrderId, orderInfo.getId())); if (cashierCarts.isEmpty()) { throw new BadRequestException("购物车为空"); } @@ -138,10 +129,8 @@ public class TbPayServiceImpl implements TbPayService { body.append(cashierCart.getName()); } - BigDecimal payMount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(scanPayDTO.getDiscount())).setScale(2, RoundingMode.HALF_UP); - - TbMerchantThirdApply thirdApply = merchantThirdApplyRepository.getById(Integer.valueOf(orderInfo.getMerchantId())); + TbMerchantThirdApply thirdApply = merchantThirdApplyRepository.getById(merchantId); if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { throw new BadRequestException("三方支付信息不存在"); } @@ -149,7 +138,7 @@ public class TbPayServiceImpl implements TbPayService { String payType; String payName; String qpay; - String payTypeCode = scanPayDTO.getCode().substring(0, 2);// 判断收款码 + String payTypeCode = code.substring(0, 2);// 判断收款码 if(Integer.parseInt(payTypeCode) >=25 && Integer.parseInt(payTypeCode) <= 30){ payType = "aliPay"; @@ -168,32 +157,32 @@ public class TbPayServiceImpl implements TbPayService { } long count = shopPayTypeMapper.selectCount(new LambdaUpdateWrapper() - .eq(TbShopPayType::getShopId, scanPayDTO.getShopId()) + .eq(TbShopPayType::getShopId, shopId) .eq(TbShopPayType::getIsDisplay, 1) .eq(TbShopPayType::getPayType, qpay)); if (count < 1) { throw new BadRequestException("未到找支付方式"); } - TbOrderPayment payment = orderPaymentService.getById(scanPayDTO.getOrderId()); + TbOrderPayment payment = orderPaymentService.getById(orderInfo.getId()); if (ObjectUtil.isEmpty(payment) || payment == null) { payment = new TbOrderPayment(); payment.setPayTypeId("ysk"); payment.setAmount(payMount.doubleValue()); - payment.setPaidAmount(orderInfo.getPayAmount().doubleValue()); + payment.setPaidAmount(payMount.doubleValue()); payment.setHasRefundAmount((double) 0); payment.setPayName(payName); payment.setPayType(payType); payment.setReceived(payment.getAmount()); payment.setChangeFee((double) 0); - payment.setMemberId(orderInfo.getMemberId()); - payment.setShopId(orderInfo.getShopId()); - payment.setOrderId(orderInfo.getId().toString()); + payment.setMemberId(String.valueOf(memberId)); + payment.setShopId(String.valueOf(shopId)); + payment.setOrderId(String.valueOf(orderInfo.getId())); payment.setCreatedAt(System.currentTimeMillis()); - payment.setAuthCode(scanPayDTO.getCode()); + payment.setAuthCode(code); orderPaymentService.save(payment); } else { - payment.setAuthCode(scanPayDTO.getCode()); + payment.setAuthCode(code); payment.setUpdatedAt(System.currentTimeMillis()); orderPaymentService.updateById(payment); } @@ -202,15 +191,13 @@ public class TbPayServiceImpl implements TbPayService { orderInfo.setPayAmount(payMount); orderInfo.setPayType(qpay); orderInfo.setUpdatedAt(System.currentTimeMillis()); - orderInfoMapper.update(orderInfo, new LambdaUpdateWrapper() - .eq(TbOrderInfo::getId, scanPayDTO.getOrderId())); if ("ysk".equals(thirdPayType)) { ScanPayReq scanPayReq = new ScanPayReq(); scanPayReq.setAppId(thirdApply.getAppId()); scanPayReq.setTimestamp(System.currentTimeMillis()); - scanPayReq.setAuthCode(scanPayDTO.getCode()); + scanPayReq.setAuthCode(code); scanPayReq.setNotifyUrl(backUrl); scanPayReq.setConsumeFee(BigDecimal.valueOf(payment.getAmount()).setScale(2, RoundingMode.DOWN).toPlainString()); @@ -231,20 +218,20 @@ public class TbPayServiceImpl implements TbPayService { orderInfo.setStatus("closed"); orderInfo.setPayOrderNo(object.getJSONObject("data").get("orderNumber").toString()); orderInfoMapper.update(orderInfo, new LambdaQueryWrapper() - .eq(TbOrderInfo::getId, scanPayDTO.getOrderId())); + .eq(TbOrderInfo::getId, orderInfo.getId())); //更新购物车状态 TbCashierCart cashierCart = new TbCashierCart(); cashierCart.setStatus("final"); int cartCount = cashierCartMapper.update(cashierCart, new LambdaQueryWrapper() - .eq(TbCashierCart::getOrderId, scanPayDTO.getOrderId())); + .eq(TbCashierCart::getOrderId, orderInfo.getId())); log.info("更新购物车:{}", cartCount); //更新子单状态 TbOrderDetail orderDetail = new TbOrderDetail(); orderDetail.setStatus("closed"); orderDetailMapper.update(orderDetail, new LambdaQueryWrapper() - .eq(TbOrderDetail::getOrderId, scanPayDTO.getOrderId())); + .eq(TbOrderDetail::getOrderId, orderInfo.getId())); return orderInfo; @@ -282,7 +269,7 @@ public class TbPayServiceImpl implements TbPayService { reqbody, reqbody, BigDecimal.valueOf(payment.getAmount()).setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), payType.equals("wechatPay") ? thirdApply.getSmallAppid() : null, - scanPayDTO.getCode(), DateUtils.getSsdfTimes(), thirdApply.getStoreId(), callBack, thirdApply.getAppToken()); + code, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), callBack, thirdApply.getAppToken()); log.info("响应信息, {}", publicResp); if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) { if ("000000".equals(publicResp.getCode())) { @@ -331,41 +318,25 @@ public class TbPayServiceImpl implements TbPayService { } @Override - public TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId, Double discount, Integer vipUserId) { - - TbOrderInfo orderInfo = orderInfoMapper.selectById(orderId); - - if (ObjectUtil.isEmpty(orderInfo)) { - throw new BadRequestException("订单不存在"); - } - - if (!"unpaid".equals(orderInfo.getStatus()) && !"pending".equals(orderInfo.getStatus())) { - throw new BadRequestException("订单非未支付状态"); - } - - if (vipUserId != null) { - orderInfo.setUserId(String.valueOf(vipUserId)); - } - + public void vipPay(BigDecimal payMount, Integer vipUserId) { // 扣减会员余额 TbShopUser shopUser = shopUserMapper.selectOne(new LambdaUpdateWrapper() .eq(TbShopUser::getStatus, 1) - .eq(TbShopUser::getId, orderInfo.getUserId())); + .eq(TbShopUser::getId, vipUserId)); if (shopUser == null) { throw new BadRequestException("用户不存在或已被禁用"); } - BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount)).setScale(2, RoundingMode.HALF_UP); - long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), finalAmount); + long flag = shopUserMapper.decrBalance(vipUserId, payMount); if (flag < 1) { throw new BadRequestException("余额不足或扣除余额失败"); } TbShopUserFlow userFlow = new TbShopUserFlow(); - userFlow.setAmount(finalAmount); - userFlow.setBalance(shopUser.getAmount().subtract(finalAmount)); + userFlow.setAmount(payMount); + userFlow.setBalance(shopUser.getAmount().subtract(payMount)); userFlow.setShopUserId(shopUser.getId()); userFlow.setBizCode("vipCardCash"); userFlow.setBizName("余额支付"); @@ -373,22 +344,6 @@ public class TbPayServiceImpl implements TbPayService { userFlow.setType("-"); shopUserFlowMapper.insert(userFlow); - orderInfo.setPayAmount(finalAmount); - orderInfo.setPayType("cash"); - orderInfo.setStatus("closed"); - orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo())); - orderInfo.setDiscountRatio(BigDecimal.valueOf(discount)); - orderInfo.setDiscountAmount(orderInfo.getAmount().subtract(finalAmount)); - orderInfoMapper.updateById(orderInfo); - //更新购物车状态 - int cartCount = cashierCartMapper.update(null, new LambdaUpdateWrapper() - .eq(TbCashierCart::getOrderId, orderId) - .set(TbCashierCart::getStatus, "final")); - - orderDetailMapper.update(null, new LambdaUpdateWrapper() - .eq(TbOrderDetail::getOrderId, orderId) - .set(TbOrderDetail::getStatus, "closed")); - return orderInfo; } @@ -442,33 +397,11 @@ public class TbPayServiceImpl implements TbPayService { return orderInfo; } - public TbOrderInfo memberAccountPay(String memberId, String shopId, String accountCode, Integer orderId, Double discount) { + public TbOrderInfo memberAccountPay(String memberId, String shopId, String accountCode, TbOrderInfo orderInfo, BigDecimal payMount) { if (StrUtil.isBlank(accountCode)) { throw new BadRequestException("无效码"); } - TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaUpdateWrapper() - .eq(TbOrderInfo::getId, orderId) - .eq(TbOrderInfo::getShopId, shopId)); - - if (orderInfo == null) { - throw new BadRequestException("订单不存在或已支付"); - } - - if (!"unpaid".equals(orderInfo.getStatus()) && !"pending".equals(orderInfo.getStatus())) { - throw new BadRequestException("此订单不处于未支付状态"); - } - - BigDecimal payMount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount)).setScale(2, RoundingMode.HALF_UP); - - long count = tbShopPayTypeMapper.selectCount(new LambdaQueryWrapper() - .eq(TbShopPayType::getShopId, shopId) - .eq(TbShopPayType::getIsDisplay, 1) - .eq(TbShopPayType::getPayType, "deposit")); - if (count < 1) { - throw new BadRequestException("未知支付方式"); - } - TbShopUser user = null; @@ -520,22 +453,7 @@ public class TbPayServiceImpl implements TbPayService { orderInfo.setUserId(user.getUserId()); orderInfo.setMemberId(user.getId().toString()); orderInfo.setPayType("deposit"); - orderInfo.setStatus("closed"); orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo())); - orderInfoMapper.updateById(orderInfo); - //更新购物车状态 - int cartCount = cashierCartMapper.update(null, new LambdaUpdateWrapper() - .eq(TbCashierCart::getId, orderId) - .set(TbCashierCart::getStatus, "final")); - - - orderDetailMapper.update(null, new LambdaUpdateWrapper() - .eq(TbOrderDetail::getOrderId, orderId) - .set(TbOrderDetail::getStatus, "closed")); - - log.info("更新购物车:{}", cartCount); - - return orderInfo; } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 4d917b89..611cbc4d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -18,6 +18,7 @@ package cn.ysk.cashier.service.impl.shopimpl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.thread.ThreadUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.ysk.cashier.config.security.security.TokenProvider; import cn.ysk.cashier.cons.RedisConstant; @@ -27,7 +28,9 @@ import cn.ysk.cashier.enums.ShopWxMsgTypeEnum; import cn.ysk.cashier.enums.TableStateEnum; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import cn.ysk.cashier.mybatis.entity.TbShopUserFlow; import cn.ysk.cashier.mybatis.mapper.*; +import cn.ysk.cashier.pojo.TbShopPayType; import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.pojo.order.TbOrderInfo; @@ -66,6 +69,8 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import java.math.BigDecimal; +import java.math.RoundingMode; +import java.sql.Timestamp; import java.time.Instant; import java.util.*; import java.io.IOException; @@ -105,6 +110,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { private final WxMsgUtils wxMsgUtils; private final TbShopPayTypeRepository payTypeRepository; private final MpShopTableMapper mpShopTableMapper; + private final TbShopPayTypeMapper tbShopPayTypeMapper; + /** * 桌码前缀 @@ -322,10 +329,24 @@ public class TbShopTableServiceImpl implements TbShopTableService { return shopTable; } + private int getCurrentPlaceNum(String tableId, String shopId) { + String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, + shopId); + if (StrUtil.isBlank(currentOrderKey)) { + return 1; + } + TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper() + .eq(TbOrderInfo::getUseType, "postPay") + .eq(TbOrderInfo::getId, currentOrderKey).select(TbOrderInfo::getPlaceNum)); + return orderInfo == null ? 1 : orderInfo.getPlaceNum() + 1; + } + @Override public TbCashierCart addCartForUser(AddCartDTO addCartDTO) { checkTableIsOpen(addCartDTO.getTableId()); + int currentPlaceNum = getCurrentPlaceNum(addCartDTO.getShopId().toString(), addCartDTO.getTableId()); + TbProductSku productSku = productMapper.selectSkuByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getSkuId()); TbProduct product = productMapper.selectByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getProductId()); @@ -344,6 +365,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { .eq(TbCashierCart::getSkuId, addCartDTO.getSkuId()) .eq(TbCashierCart::getProductId, addCartDTO.getProductId()) .eq(TbCashierCart::getTableId, addCartDTO.getTableId()) + .eq(TbCashierCart::getPlaceNum, currentPlaceNum) .in(TbCashierCart::getStatus, "create", "refund") // .and(q -> { // q.eq(TbCashierCart::getTradeDay, DateUtils.getDay()) @@ -391,6 +413,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { tbCashierCart.setSalePrice(productSku.getSalePrice()); tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice())); tbCashierCart.setSkuName(productSku.getSpecSnap()); + tbCashierCart.setPlaceNum(currentPlaceNum); if (!addCartDTO.isPack()) { tbCashierCart.setPackFee(BigDecimal.ZERO); } else { @@ -425,11 +448,6 @@ public class TbShopTableServiceImpl implements TbShopTableService { tbCashierCart.setIsGift(String.valueOf(addCartDTO.isGift())); tbCashierCart.setTotalNumber(addCartDTO.getNum()); tbCashierCart.setNumber(addCartDTO.getNum()); - // 数量0删除 - if (tbCashierCart.getNumber() == 0) { - cashierCartRepository.deleteById(tbCashierCart.getId()); - return null; - } tbCashierCart.setUpdatedAt(DateUtil.current()); cashierCartRepository.save(tbCashierCart); } @@ -466,9 +484,11 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public void removeCart(RemoveCartDTO removeCartDTO) { + int currentPlaceNum = getCurrentPlaceNum(removeCartDTO.getTableId().toString(), removeCartDTO.getShopId().toString()); // 会员点单 TbCashierCart cashierCart = cashierCartMapper.selectOne(new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, removeCartDTO.getShopId()) + .eq(TbCashierCart::getPlaceNum, currentPlaceNum) .eq(TbCashierCart::getId, removeCartDTO.getCartId())); if (cashierCart == null) { throw new BadRequestException("购物车商品不存在"); @@ -479,11 +499,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { .eq(TbOrderDetail::getShopId, cashierCart.getShopId()) .eq(TbOrderDetail::getProductId, cashierCart.getProductId()) .eq(TbOrderDetail::getProductSkuId, cashierCart.getSkuId()) + .eq(TbOrderDetail::getPlaceNum, currentPlaceNum) .eq(TbOrderDetail::getOrderId, cashierCart.getOrderId())); } - cashierCartMapper.delete(new LambdaQueryWrapper().eq(TbCashierCart::getShopId, removeCartDTO.getShopId()) - .eq(TbCashierCart::getId, removeCartDTO.getCartId())); - // 清空购物车 出票 long carCount = countCar(cashierCart.getTableId(), cashierCart.getShopId(), cashierCart.getMasterId()); @@ -497,13 +515,55 @@ public class TbShopTableServiceImpl implements TbShopTableService { } + @Override + public void returnCart(RemoveCartDTO removeCartDTO) { + rabbitMsgUtils.printDishesReturnTicket(4450, 9313); + + int currentPlaceNum = getCurrentPlaceNum(removeCartDTO.getTableId().toString(), removeCartDTO.getShopId().toString()); + // 会员点单 + TbCashierCart cashierCart = cashierCartMapper.selectOne(new LambdaQueryWrapper() + .eq(TbCashierCart::getShopId, removeCartDTO.getShopId()) + .in(TbCashierCart::getStatus, "create") + .eq(TbCashierCart::getId, removeCartDTO.getCartId())); + + if (cashierCart == null) { + throw new BadRequestException("购物车商品不存在或已退单"); + } + + TbOrderDetail tbOrderDetail = orderDetailMapper.selectOne(new LambdaQueryWrapper() + .eq(TbOrderDetail::getShopId, removeCartDTO.getShopId()) + .eq(TbOrderDetail::getPlaceNum, cashierCart.getPlaceNum()) + .in(TbOrderDetail::getStatus, "unpaid") + .eq(TbOrderDetail::getOrderId, cashierCart.getOrderId())); + if (tbOrderDetail == null) { + throw new BadRequestException("购物车商品不存在或已退单"); + } + + if (cashierCart.getOrderId() == null) { + throw new BadRequestException("此商品还未下单,无需退单"); + } + + cashierCartMapper.update(null, new LambdaUpdateWrapper() + .eq(TbCashierCart::getId, cashierCart.getId()) + .set(TbCashierCart::getStatus, "return")); + + orderDetailMapper.update(null, new LambdaUpdateWrapper() + .eq(TbOrderDetail::getId, tbOrderDetail.getId()) + .set(TbOrderDetail::getUpdateTime, DateUtil.date()) + .set(TbOrderDetail::getStatus, "return")); + + rabbitMsgUtils.printDishesReturnTicket(tbOrderDetail.getOrderId(), tbOrderDetail.getOrderId()); + } + @Override public void clearCart(ClearCartDTO clearCartDTO) { String orderId = redisTemplate.opsForValue().get(RedisConstant.getCurrentOrderKey(clearCartDTO.getTableId().toString(), clearCartDTO.getShopId())); + int currentPlaceNum = getCurrentPlaceNum(clearCartDTO.getTableId().toString(), clearCartDTO.getShopId()); cashierCartMapper.delete(new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, clearCartDTO.getShopId()) .eq(TbCashierCart::getTableId, clearCartDTO.getTableId()) + .eq(TbCashierCart::getPlaceNum, currentPlaceNum) .and(q -> { q.eq(TbCashierCart::getMasterId, clearCartDTO.getMasterId()) .or() @@ -518,10 +578,13 @@ public class TbShopTableServiceImpl implements TbShopTableService { }) ); + // tbShopTableRepository.deleteByTableIdAndShopId(clearCartDTO.getTableId(), clearCartDTO.getShopId()); if (StrUtil.isNotBlank(orderId)) { - orderDetailMapper.delete(new LambdaQueryWrapper().eq(TbOrderDetail::getShopId, clearCartDTO.getShopId()) + orderDetailMapper.delete(new LambdaQueryWrapper() + .eq(TbOrderDetail::getShopId, clearCartDTO.getShopId()) + .eq(TbOrderDetail::getPlaceNum, currentPlaceNum) .eq(TbOrderDetail::getOrderId, orderId)); rabbitMsgUtils.printTicket(orderId); } @@ -541,7 +604,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { Integer size, Integer shopId, Integer vipUserId, String masterId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .eq(TbCashierCart::getTableId, tableId) - .in(TbCashierCart::getStatus, "create", "refund") + .in(TbCashierCart::getStatus, "create", "refund", "return") .eq(TbCashierCart::getShopId, shopId) .and(query2 -> { query2.or(query3 -> { @@ -835,7 +898,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { private final StringRedisTemplate redisTemplate; @Override - public Object getMasterId(Integer shopId, Long tableId, Integer vipUserId) { + public JSONObject getMasterId(Integer shopId, Long tableId, Integer vipUserId) { String account = tokenProvider.getSubject(); if (account == null) { throw new BadRequestException("token解析失败"); @@ -875,12 +938,32 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public TbOrderInfo createOrder(CreateOrderDTO createOrderDTO, boolean addMaterId, boolean isPrint) { return Utils.runFunAndCheckKey(() -> { + TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() + .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) + .in(TbShopTable::getStatus, "idle", "using")); + + if (tbShopTable == null) { + throw new BadRequestException("台桌未开台或不存在"); + } + + + // 传递orderId直接取否则取当前缓存id String currentOrderKey = RedisConstant.getCurrentOrderKey(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString()); String orderIdValue = redisTemplate.opsForValue().get(currentOrderKey); Integer orderId = orderIdValue == null ? null : Integer.parseInt(orderIdValue); orderId = createOrderDTO.getOrderId() != null ? createOrderDTO.getOrderId() : orderId; + // 查询订单 + TbOrderInfo orderInfo = null; + if (orderId != null) { + orderInfo = orderInfoMapper.selectById(orderId); + + if (orderInfo == null || !"unpaid".equals(orderInfo.getStatus())) { + redisTemplate.delete(currentOrderKey); + } + } + String day = DateUtils.getDay(); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, createOrderDTO.getShopId()) @@ -896,33 +979,26 @@ public class TbShopTableServiceImpl implements TbShopTableService { .isNull(TbCashierCart::getMasterId); })); }); -// if (createOrderDTO.getVipUserId() != null) { -// queryWrapper.eq(TbCashierCart::getUserId, createOrderDTO.getVipUserId()); -// }else { -// queryWrapper.eq(TbCashierCart::getMasterId, createOrderDTO.getMasterId()) -// .isNull(TbCashierCart::getUserId); -// } + List cashierCarts = cashierCartMapper .selectList(queryWrapper); if (cashierCarts.isEmpty()) { throw new BadRequestException("购物车为空,请先添加商品"); } - TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() - .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) - .in(TbShopTable::getStatus, "idle", "using")); - - if (tbShopTable == null) { - throw new BadRequestException("台桌未开台或不存在"); - } - BigDecimal totalAmount = BigDecimal.ZERO; BigDecimal packAMount = BigDecimal.ZERO; BigDecimal feeAmount = BigDecimal.ZERO; BigDecimal saleAmount = BigDecimal.ZERO; + // 当前下单次数 + int placeNum = orderInfo == null ? 1 : orderInfo.getPlaceNum() + 1; List orderDetails = new ArrayList<>(); + boolean mealCost = false; for (TbCashierCart cashierCart : cashierCarts) { + if ("客位费".equals(cashierCart.getName())) { + mealCost = true; + } totalAmount = totalAmount.add(cashierCart.getTotalAmount()); packAMount = packAMount.add(cashierCart.getPackFee()); feeAmount = cashierCart.getPackFee(); @@ -950,15 +1026,11 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderId = cashierCart.getOrderId(); } orderDetail.setOrderId(orderId); + orderDetail.setPlaceNum(placeNum); } - TbOrderInfo orderInfo = null; - if (orderId != null) { - orderInfo = orderInfoMapper.selectById(orderId); - - if (orderInfo == null || !"unpaid".equals(orderInfo.getStatus())) { - redisTemplate.delete(currentOrderKey); - } + if (!mealCost) { + throw new BadRequestException("请选择用餐人数"); } // 修改订单信息 @@ -1236,25 +1308,70 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public Object pay(PayDTO payDTO) { return Utils.runFunAndCheckKey(() -> { - TbOrderInfo orderInfo = null; + long count = tbShopPayTypeMapper.selectCount(new LambdaQueryWrapper() + .eq(TbShopPayType::getShopId, payDTO.getShopId()) + .eq(TbShopPayType::getIsDisplay, 1) + .eq(TbShopPayType::getPayType, "deposit")); + if (count < 1) { + throw new BadRequestException("未知支付方式"); + } + + TbOrderInfo orderInfo = orderInfoMapper.selectById(payDTO.getOrderId()); + + if (ObjectUtil.isEmpty(orderInfo)) { + throw new BadRequestException("订单不存在"); + } + + if (!"unpaid".equals(orderInfo.getStatus()) && !"pending".equals(orderInfo.getStatus())) { + throw new BadRequestException("订单非未支付状态"); + } + + if (payDTO.getDiscount() == null) { + payDTO.setDiscount((double) 1); + } + + BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.HALF_UP); + switch (payDTO.getPayType()) { case "vipPay": - orderInfo = tbPayServiceImpl.vipPay(payDTO.getShopId(), payDTO.getOrderId(), payDTO.getDiscount(), payDTO.getVipUserId()); + if (payDTO.getVipUserId() != null) { + orderInfo.setUserId(String.valueOf(payDTO.getVipUserId())); + } + tbPayServiceImpl.vipPay(finalAmount, Integer.valueOf(orderInfo.getUserId())); + orderInfo.setPayOrderNo("vipPay".concat(SnowFlakeUtil.generateOrderNo())); + orderInfo.setPayType("deposit"); break; case "cash": - orderInfo = tbPayServiceImpl.cashPay(payDTO); + orderInfo.setPayType("cash"); + orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo())); + +// orderInfo = tbPayServiceImpl.cashPay(payDTO); break; case "scanCode": - orderInfo = tbPayServiceImpl.scanPay(payDTO); + orderInfo = tbPayServiceImpl.scanPay(payDTO.getShopId(), payDTO.getCode(), Integer.valueOf(orderInfo.getMerchantId()), Integer.valueOf(orderInfo.getMemberId()), finalAmount, orderInfo); break; case "deposit": - orderInfo = tbPayServiceImpl.memberAccountPay("", String.valueOf(payDTO.getShopId()), payDTO.getCode(), payDTO.getOrderId(), payDTO.getDiscount()); + orderInfo = tbPayServiceImpl.memberAccountPay("", String.valueOf(payDTO.getShopId()), payDTO.getCode(), orderInfo, finalAmount); break; default: throw new BadRequestException("未知支付方式"); } - log.info("更新购物车"); + orderInfo.setPayAmount(finalAmount); + orderInfo.setStatus("closed"); + orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount())); + orderInfo.setDiscountAmount(orderInfo.getAmount().subtract(finalAmount)); + orderInfoMapper.updateById(orderInfo); + + //更新购物车状态 + cashierCartMapper.update(null, new LambdaUpdateWrapper() + .eq(TbCashierCart::getOrderId, orderInfo.getId()) + .set(TbCashierCart::getStatus, "final")); + + orderDetailMapper.update(null, new LambdaUpdateWrapper() + .eq(TbOrderDetail::getOrderId, orderInfo.getId()) + .set(TbOrderDetail::getStatus, "closed")); + JSONObject jsonObject = new JSONObject(); jsonObject.put("token", null); @@ -1327,4 +1444,94 @@ public class TbShopTableServiceImpl implements TbShopTableService { } return cashierCartMapper.update(null, queryWrapper); } + + private String getCurrentOrderId(String tableId, String shopId) { + String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId); + return redisTemplate.opsForValue().get(currentOrderKey); + } + + @Override + public Object choseTable(ChoseTableDTO choseTableDTO) { + String masterId = getMasterId(choseTableDTO.getShopId(), Long.valueOf(choseTableDTO.getNewTableId()), null).getString("masterId"); + String currentOrderId = choseTableDTO.getOrderId() == null ? getCurrentOrderId(choseTableDTO.getOldTableId(), + choseTableDTO.getShopId().toString()) : choseTableDTO.getOrderId().toString(); + + TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() + .eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId()) + .eq(TbShopTable::getStatus, "idle")); + if (shopTable == null) { + throw new BadRequestException("台桌不存在或非空闲状态"); + } + + cashierCartMapper.update(null, new LambdaUpdateWrapper() + .eq(TbCashierCart::getTableId, choseTableDTO.getOldTableId()) + .in(TbCashierCart::getStatus, "create", "return") + .eq(TbCashierCart::getShopId, choseTableDTO.getShopId()) + .and(q -> { + q.isNull(TbCashierCart::getOrderId) + .or() + .eq(TbCashierCart::getOrderId, currentOrderId); + }) + .and(query2 -> { + query2.or(query3 -> { + query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay()) + .isNotNull(TbCashierCart::getMasterId); + }) + .or((query4 -> { + query4.isNull(TbCashierCart::getTradeDay) + .isNull(TbCashierCart::getMasterId); + })); + }) + .set(TbCashierCart::getMasterId, masterId) + .set(TbCashierCart::getTableId, choseTableDTO.getNewTableId())); + + + mpShopTableMapper.update(null, new LambdaUpdateWrapper() + .eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId()) + .set(TbShopTable::getStatus, "using")); + mpShopTableMapper.update(null, new LambdaUpdateWrapper() + .eq(TbShopTable::getQrcode, choseTableDTO.getOldTableId()) + .set(TbShopTable::getStatus, "idle")); + + return orderInfoMapper.update(null, new LambdaUpdateWrapper() + .eq(TbOrderInfo::getId, currentOrderId) + .set(TbOrderInfo::getMasterId, masterId) + .set(TbOrderInfo::getTableId, choseTableDTO.getNewTableId())); + + } + + @Override + public Object choseCount(ChoseCountDTO choseCountDTO) { + LambdaQueryWrapper query = new LambdaQueryWrapper() + .eq(TbCashierCart::getShopId, choseCountDTO.getShopId()) + .eq(TbCashierCart::getMasterId, choseCountDTO.getMasterId()) + .eq(TbCashierCart::getProductId, -999) + .eq(TbCashierCart::getTableId, choseCountDTO.getTableId()); + TbCashierCart tbCashierCart = cashierCartMapper.selectOne(query); + + if (tbCashierCart == null) { + tbCashierCart = new TbCashierCart(); + tbCashierCart.setStatus("create"); + tbCashierCart.setCreatedAt(System.currentTimeMillis()); + tbCashierCart.setTableId(Long.valueOf(choseCountDTO.getTableId())); + tbCashierCart.setName("客座费"); + tbCashierCart.setSalePrice(BigDecimal.ONE); + tbCashierCart.setMasterId(choseCountDTO.getMasterId()); + tbCashierCart.setShopId(String.valueOf(choseCountDTO.getShopId())); + tbCashierCart.setTradeDay(DateUtils.getDay()); + tbCashierCart.setStatus("create"); + tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(BigDecimal.ONE)); + tbCashierCart.setPlaceNum(1); + tbCashierCart.setProductId("-999"); + tbCashierCart.setSkuId("-999"); + tbCashierCartMapper.insert(tbCashierCart); + }else { + tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(BigDecimal.ONE)); + tbCashierCart.setNumber(choseCountDTO.getNum()); + tbCashierCart.setTotalNumber(choseCountDTO.getNum()); + tbCashierCartMapper.updateById(tbCashierCart); + } + + return tbCashierCart; + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java index fb7c7f75..12516322 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java @@ -20,6 +20,7 @@ import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.shop.TbShopTable; import cn.ysk.cashier.dto.shop.TbShopTableDto; import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.data.domain.Pageable; import java.util.Map; @@ -100,6 +101,8 @@ public interface TbShopTableService { void removeCart(RemoveCartDTO removeCartDTO); + void returnCart(RemoveCartDTO removeCartDTO); + void clearCart(ClearCartDTO clearCartDTO); Page getCart(Long tableId, Integer page, Integer size, Integer shopId, Integer vipUserId, String masterId); @@ -110,7 +113,7 @@ public interface TbShopTableService { Object createOrder(CreateOrderDTO createOrderDTO, boolean addMasterId, boolean isPrint); - Object getMasterId(Integer shopId, Long tableId, Integer vipUserId); + JSONObject getMasterId(Integer shopId, Long tableId, Integer vipUserId); Object pending(PendingDTO pendingDTO); @@ -123,4 +126,8 @@ public interface TbShopTableService { Object deleteOrder(DeleteOrderDTO deleteOrderDTO); Object updateVip(UpdateVipDTO updateVipDTO); + + Object choseTable(ChoseTableDTO choseTableDTO); + + Object choseCount(ChoseCountDTO choseCountDTO); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java index 203ba29f..cd22a2dc 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java @@ -46,4 +46,12 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback { // 发送库存记录mq消息 sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData, "库存记录", true); } + + public void printDishesReturnTicket(Integer orderId, Integer... orderIds) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("orderId", orderId); + jsonObject.put("orderDetailIds", orderIds); + jsonObject.put("isReturn", true); + sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品退单", false); + } } From dc0f6eae1e14a4118b315040d550cde9459405a3 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 11:26:58 +0800 Subject: [PATCH 07/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=AE=A2=E4=BD=8D=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 611cbc4d..d6637df4 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -996,7 +996,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { boolean mealCost = false; for (TbCashierCart cashierCart : cashierCarts) { - if ("客位费".equals(cashierCart.getName())) { + if ("-999".equals(cashierCart.getProductId())) { mealCost = true; } totalAmount = totalAmount.add(cashierCart.getTotalAmount()); @@ -1524,6 +1524,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { tbCashierCart.setPlaceNum(1); tbCashierCart.setProductId("-999"); tbCashierCart.setSkuId("-999"); + tbCashierCart.setPackFee(BigDecimal.ZERO); tbCashierCartMapper.insert(tbCashierCart); }else { tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(BigDecimal.ONE)); From f2bfc718c3364bec1560e195859b40356dd75776 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 14:08:41 +0800 Subject: [PATCH 08/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=B7=B2=E4=B8=8B=E5=8D=95=E5=95=86=E5=93=81=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/shopimpl/TbShopTableServiceImpl.java | 58 +++++++++++++++++-- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index d6637df4..a3485840 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -272,6 +272,12 @@ public class TbShopTableServiceImpl implements TbShopTableService { throw new BadRequestException("购物车商品不存在"); } + int currentPlaceNum = getCurrentPlaceNum(tbCashierCart.getTableId().toString(), tbCashierCart.getShopId()); + + if (!tbCashierCart.getPlaceNum().equals(currentPlaceNum)) { + throw new BadRequestException("已下单商品仅支持退单操作"); + } + if (updateCartDTO.getNum() == 0) { cashierCartRepository.deleteById(updateCartDTO.getCartId()); return null; @@ -332,12 +338,13 @@ public class TbShopTableServiceImpl implements TbShopTableService { private int getCurrentPlaceNum(String tableId, String shopId) { String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId); - if (StrUtil.isBlank(currentOrderKey)) { + String orderId = redisTemplate.opsForValue().get(currentOrderKey); + if (StrUtil.isBlank(orderId)) { return 1; } TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper() .eq(TbOrderInfo::getUseType, "postPay") - .eq(TbOrderInfo::getId, currentOrderKey).select(TbOrderInfo::getPlaceNum)); + .eq(TbOrderInfo::getId, orderId).select(TbOrderInfo::getPlaceNum)); return orderInfo == null ? 1 : orderInfo.getPlaceNum() + 1; } @@ -345,7 +352,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { public TbCashierCart addCartForUser(AddCartDTO addCartDTO) { checkTableIsOpen(addCartDTO.getTableId()); - int currentPlaceNum = getCurrentPlaceNum(addCartDTO.getShopId().toString(), addCartDTO.getTableId()); + int currentPlaceNum = getCurrentPlaceNum(addCartDTO.getTableId(), addCartDTO.getShopId().toString()); TbProductSku productSku = productMapper.selectSkuByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getSkuId()); TbProduct product = productMapper.selectByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getProductId()); @@ -488,12 +495,15 @@ public class TbShopTableServiceImpl implements TbShopTableService { // 会员点单 TbCashierCart cashierCart = cashierCartMapper.selectOne(new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, removeCartDTO.getShopId()) - .eq(TbCashierCart::getPlaceNum, currentPlaceNum) .eq(TbCashierCart::getId, removeCartDTO.getCartId())); if (cashierCart == null) { throw new BadRequestException("购物车商品不存在"); } + if (!cashierCart.getPlaceNum().equals(currentPlaceNum)) { + throw new BadRequestException("已下单商品仅支持退单操作"); + } + if (cashierCart.getOrderId() != null) { orderDetailMapper.delete(new LambdaQueryWrapper() .eq(TbOrderDetail::getShopId, cashierCart.getShopId()) @@ -633,6 +643,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { skuIds.add(Integer.valueOf(item.getSkuId())); }); + + if (!skuIds.isEmpty()) { List skuList = productSkuRepository.findAllById(skuIds); HashMap skuMap = new HashMap<>(); @@ -647,9 +659,22 @@ public class TbShopTableServiceImpl implements TbShopTableService { }); com.baomidou.mybatisplus.extension.plugins.pagination.Page copyPage = BeanUtil.copyProperties(cartPage, com.baomidou.mybatisplus.extension.plugins.pagination.Page.class); - copyPage.setRecords(infos); + + // 根据placeNum进行分组 + Map>> groupedByPlaceNum = infos.stream() + .collect(Collectors.groupingBy(info -> info.get("placeNum"))); + + ArrayList> list = new ArrayList<>(); + groupedByPlaceNum.forEach((k, v) -> { + HashMap item = new HashMap<>(); + item.put("placeNum", k); + item.put("info", v); + list.add(item); + }); + copyPage.setRecords(list); return copyPage; } + return cartPage; } @@ -991,7 +1016,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { BigDecimal feeAmount = BigDecimal.ZERO; BigDecimal saleAmount = BigDecimal.ZERO; // 当前下单次数 - int placeNum = orderInfo == null ? 1 : orderInfo.getPlaceNum() + 1; + int placeNum = getCurrentPlaceNum(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString()); List orderDetails = new ArrayList<>(); boolean mealCost = false; @@ -1052,6 +1077,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay"); orderInfo.setUserId(createOrderDTO.getVipUserId() == null ? null : String.valueOf(createOrderDTO.getVipUserId())); orderInfo.setCreatedAt(DateUtil.current()); + orderInfo.setPlaceNum(placeNum); orderInfoMapper.updateById(orderInfo); } else { String orderNo = generateOrderNumber(); @@ -1078,6 +1104,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderInfo.setUserId(createOrderDTO.getVipUserId() == null ? null : String.valueOf(createOrderDTO.getVipUserId())); orderInfo.setCreatedAt(DateUtil.current()); orderInfo.setTableName(tbShopTable.getName()); + orderInfo.setPlaceNum(placeNum); TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper() .eq(TbMerchantAccount::getShopId, createOrderDTO.getShopId()) .eq(TbMerchantAccount::getStatus, 1)); @@ -1102,6 +1129,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { // 是否是第一次添加的商品 boolean isFirst = true; for (TbCashierCart cashierCart : cashierCarts) { + if ("-999".equals(cashierCart.getProductId())) { + continue; + } TbProduct product = productMapper.selectById(cashierCart.getProductId()); TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null); @@ -1450,6 +1480,18 @@ public class TbShopTableServiceImpl implements TbShopTableService { return redisTemplate.opsForValue().get(currentOrderKey); } + private void setCurrentOrderId(String tableId, String shopId, String orderId) { + String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId); + redisTemplate.opsForValue().set(currentOrderKey, orderId); + } + + private String removeCurrentOrderId(String tableId, String shopId) { + String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId); + String orderId = redisTemplate.opsForValue().get(currentOrderKey); + redisTemplate.delete(currentOrderKey); + return orderId; + } + @Override public Object choseTable(ChoseTableDTO choseTableDTO) { String masterId = getMasterId(choseTableDTO.getShopId(), Long.valueOf(choseTableDTO.getNewTableId()), null).getString("masterId"); @@ -1493,6 +1535,10 @@ public class TbShopTableServiceImpl implements TbShopTableService { .eq(TbShopTable::getQrcode, choseTableDTO.getOldTableId()) .set(TbShopTable::getStatus, "idle")); + // 将台桌redis数据迁移 + String orderId = removeCurrentOrderId(choseTableDTO.getOldTableId(), choseTableDTO.getShopId().toString()); + setCurrentOrderId(choseTableDTO.getNewTableId(), choseTableDTO.getShopId().toString(), orderId); + return orderInfoMapper.update(null, new LambdaUpdateWrapper() .eq(TbOrderInfo::getId, currentOrderId) .set(TbOrderInfo::getMasterId, masterId) From 3ebec6f0c5529930364f8beb05c6a3cd7a9ea57a Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 14:49:22 +0800 Subject: [PATCH 09/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=89=8B=E5=8A=A8=E6=B8=85?= =?UTF-8?q?=E5=8F=B0=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=8F=B0=E6=A1=8C=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=8A=B6=E6=80=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/enums/TableStateEnum.java | 2 +- .../cn/ysk/cashier/pojo/shop/TbShopTable.java | 19 ++++++++++ .../impl/shopimpl/TbShopTableServiceImpl.java | 37 +++++++++++++------ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/enums/TableStateEnum.java b/eladmin-system/src/main/java/cn/ysk/cashier/enums/TableStateEnum.java index 3db2ee31..6fb3613b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/enums/TableStateEnum.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/enums/TableStateEnum.java @@ -2,7 +2,7 @@ package cn.ysk.cashier.enums; public enum TableStateEnum { IDLE("idle"), - CLOSED("closed"), PAYING("paying"), PENDING("pending"), USING("using"); + CLOSED("closed"), PAYING("paying"), PENDING("pending"), USING("using"), CLEANING("cleaning"); private String state = "closed"; TableStateEnum(String state) { diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java index 6edb698b..b6471ac9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java @@ -23,6 +23,8 @@ import javax.persistence.*; import javax.validation.constraints.*; import java.math.BigDecimal; import java.io.Serializable; +import java.sql.Date; +import java.sql.Timestamp; /** * @website https://eladmin.vip @@ -104,6 +106,23 @@ public class TbShopTable implements Serializable { @ApiModelProperty(value = "二维码") private String qrcode = ""; + @Column(name = "`auto_clear`") + @ApiModelProperty(value = "自动清台") + private Integer autoClear=1; + + @Column(name = "`use_time`") + private Date useTime; + @Column(name = "`end_time`") + private Date endTime; + + @Column(name = "`product_num`") + private Integer productNum; + @Column(name = "`total_amount`") + private Integer totalAmount; + @Column(name = "`real_amount`") + private Integer realAmount; + + public void copy(TbShopTable source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index a3485840..64143ed1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -154,12 +154,12 @@ public class TbShopTableServiceImpl implements TbShopTableService { } else if (tbCashierCartMapper.selectCount(new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, date.getShopId()) .eq(TbCashierCart::getTableId, date.getQrcode()) - .eq(TbCashierCart::getTradeDay, cn.ysk.cashier.utils.DateUtils.getDay()) + .eq(TbCashierCart::getTradeDay, cn.ysk.cashier.utils.DateUtils.getDay()) .eq(TbCashierCart::getStatus, "create")) < 1 || (orderId != null && tbOrderDetailMapper.selectCount(new LambdaQueryWrapper() .eq(TbOrderDetail::getShopId, date.getShopId()) .eq(TbOrderDetail::getStatus, "unpaid") - .ge(TbOrderDetail::getCreateTime, DateUtil.beginOfDay(new Date())) + .ge(TbOrderDetail::getCreateTime, DateUtil.beginOfDay(new Date())) .eq(TbOrderDetail::getOrderId, orderId)) < 1) ) { date.setStatus("idle"); @@ -343,7 +343,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { return 1; } TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper() - .eq(TbOrderInfo::getUseType, "postPay") + .eq(TbOrderInfo::getUseType, "postPay") .eq(TbOrderInfo::getId, orderId).select(TbOrderInfo::getPlaceNum)); return orderInfo == null ? 1 : orderInfo.getPlaceNum() + 1; } @@ -542,7 +542,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { TbOrderDetail tbOrderDetail = orderDetailMapper.selectOne(new LambdaQueryWrapper() .eq(TbOrderDetail::getShopId, removeCartDTO.getShopId()) - .eq(TbOrderDetail::getPlaceNum, cashierCart.getPlaceNum()) + .eq(TbOrderDetail::getPlaceNum, cashierCart.getPlaceNum()) .in(TbOrderDetail::getStatus, "unpaid") .eq(TbOrderDetail::getOrderId, cashierCart.getOrderId())); if (tbOrderDetail == null) { @@ -644,7 +644,6 @@ public class TbShopTableServiceImpl implements TbShopTableService { }); - if (!skuIds.isEmpty()) { List skuList = productSkuRepository.findAllById(skuIds); HashMap skuMap = new HashMap<>(); @@ -1163,8 +1162,6 @@ public class TbShopTableServiceImpl implements TbShopTableService { // 推送耗材信息 pushConsMsg(orderInfo, cashierCarts); - - if (createOrderDTO.isPostPay() && isPrint) { Long count = orderInfoMapper.selectCount(new LambdaQueryWrapper() .eq(TbOrderInfo::getStatus, "unpaid") @@ -1174,15 +1171,20 @@ public class TbShopTableServiceImpl implements TbShopTableService { } } + // 设置台桌信息 mpShopTableMapper.update(null, new LambdaUpdateWrapper() .eq(TbShopTable::getShopId, createOrderDTO.getShopId()) .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) + .set(TbShopTable::getUseTime, DateUtil.date()) + .set(TbShopTable::getProductNum, cashierCarts.size()) + .set(TbShopTable::getTotalAmount, orderInfo.getOrderAmount()) + .set(TbShopTable::getRealAmount, orderInfo.getOrderAmount()) .set(TbShopTable::getStatus, TableStateEnum.USING.getState())); String tableCartKey = RedisConstant.getTableCartKey(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString()); redisTemplate.delete(tableCartKey); return orderInfo; - }, stringRedisTemplate, RedisConstant.getLockKey(RedisConstant.CREATE_ORDER,createOrderDTO.getShopId(), + }, stringRedisTemplate, RedisConstant.getLockKey(RedisConstant.CREATE_ORDER, createOrderDTO.getShopId(), createOrderDTO.getTableId(), createOrderDTO.getMasterId(), createOrderDTO.isPostPay())); } @@ -1419,9 +1421,20 @@ public class TbShopTableServiceImpl implements TbShopTableService { rabbitTemplate.convertAndSend(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData.toJSONString(), new CorrelationData(UUID.randomUUID().toString())); // 修改台桌状态 - mpShopTableMapper.update(null, new LambdaUpdateWrapper() - .eq(TbShopTable::getQrcode, orderInfo.getTableId()) - .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState())); + TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() + .eq(TbShopTable::getShopId, payDTO.getShopId()) + .eq(TbShopTable::getQrcode, orderInfo.getTableId())); + if (tbShopTable.getAutoClear().equals(1)) { + mpShopTableMapper.update(null, new LambdaUpdateWrapper() + .eq(TbShopTable::getQrcode, orderInfo.getTableId()) + .set(TbShopTable::getEndTime, DateUtil.date()) + .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState())); + } else { + mpShopTableMapper.update(null, new LambdaUpdateWrapper() + .eq(TbShopTable::getQrcode, orderInfo.getTableId()) + .set(TbShopTable::getEndTime, DateUtil.date()) + .set(TbShopTable::getStatus, TableStateEnum.CLEANING.getState())); + } if ("postPay".equals(orderInfo.getUseType())) { String day = DateUtils.getDay(); @@ -1572,7 +1585,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { tbCashierCart.setSkuId("-999"); tbCashierCart.setPackFee(BigDecimal.ZERO); tbCashierCartMapper.insert(tbCashierCart); - }else { + } else { tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(BigDecimal.ONE)); tbCashierCart.setNumber(choseCountDTO.getNum()); tbCashierCart.setTotalNumber(choseCountDTO.getNum()); From 26b3e0bc2cba5352cde181d7d1dec5a7c417f2eb Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 14:53:21 +0800 Subject: [PATCH 10/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=89=8B=E5=8A=A8=E6=B8=85?= =?UTF-8?q?=E5=8F=B0=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=8F=B0=E6=A1=8C=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=8A=B6=E6=80=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java index b6471ac9..73851ee3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java @@ -112,7 +112,7 @@ public class TbShopTable implements Serializable { @Column(name = "`use_time`") private Date useTime; - @Column(name = "`end_time`") + @Column(name = "`end_time`") private Date endTime; @Column(name = "`product_num`") From 2c99b8cd1880a80052cdc0435b878b314d53291c Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 14:55:27 +0800 Subject: [PATCH 11/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=89=8B=E5=8A=A8=E6=B8=85?= =?UTF-8?q?=E5=8F=B0=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=8F=B0=E6=A1=8C=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=8A=B6=E6=80=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java index 73851ee3..936640ce 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java @@ -110,7 +110,7 @@ public class TbShopTable implements Serializable { @ApiModelProperty(value = "自动清台") private Integer autoClear=1; - @Column(name = "`use_time`") + @Column(name = "`use_time`") private Date useTime; @Column(name = "`end_time`") private Date endTime; From 2ef311f887416927decdfd421a4399ed1559499b Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 14:59:57 +0800 Subject: [PATCH 12/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95=E6=9B=B4=E6=96=B0=E5=8F=B0?= =?UTF-8?q?=E6=A1=8C=E4=BD=BF=E7=94=A8=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/shopimpl/TbShopTableServiceImpl.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 64143ed1..e6eb44d5 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1171,15 +1171,18 @@ public class TbShopTableServiceImpl implements TbShopTableService { } } - // 设置台桌信息 - mpShopTableMapper.update(null, new LambdaUpdateWrapper() + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper() .eq(TbShopTable::getShopId, createOrderDTO.getShopId()) .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) - .set(TbShopTable::getUseTime, DateUtil.date()) .set(TbShopTable::getProductNum, cashierCarts.size()) .set(TbShopTable::getTotalAmount, orderInfo.getOrderAmount()) .set(TbShopTable::getRealAmount, orderInfo.getOrderAmount()) - .set(TbShopTable::getStatus, TableStateEnum.USING.getState())); + .set(TbShopTable::getStatus, TableStateEnum.USING.getState()); + if (isFirst) { + wrapper.set(TbShopTable::getUseTime, DateUtil.date()); + } + // 设置台桌信息 + mpShopTableMapper.update(null, wrapper); String tableCartKey = RedisConstant.getTableCartKey(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString()); redisTemplate.delete(tableCartKey); From f03913537185b59ec6dbdc7c75c5d4aee8a4879c Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 11 Sep 2024 16:52:09 +0800 Subject: [PATCH 13/56] =?UTF-8?q?=E8=90=A5=E4=B8=9A=E6=9D=BF=E5=9D=97=20?= =?UTF-8?q?=E9=87=91=E9=A2=9D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/pojo/shop/TbShopInfo.java | 2 +- .../service/impl/SummaryServiceImpl.java | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java index 6bd14fa1..103fc7bb 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java @@ -266,7 +266,7 @@ public class TbShopInfo implements Serializable { @ApiModelProperty(value = "是否免除桌位费 0否1是") private Integer isTableFee; - @Column(name = "tableFee") + @Column(name = "table_fee") @ApiModelProperty(value = "桌位费") private BigDecimal tableFee; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index a3659869..25a34a9b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -90,11 +90,18 @@ public class SummaryServiceImpl implements SummaryService { Integer newFlow = tbShopUserFlowMapper.tradeIndexNewFlow(param.getShopId(), DateUtil.getStrTime(param.getStartTime()), DateUtil.getStrTime(param.getEndTime())); //台桌数 int tables = tbShopTableRepository.countAllByShopId(param.getShopId()); - sale.put("totalSaleAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(refundAmount));//总金额 - sale.put("incomeAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(new BigDecimal(flowMap.get("inAmount").toString())));//实收 - sale.put("refundAmount", refundAmount);//销售退款金额 - sale.put("inAmount", flowMap.get("inAmount"));//会员充值金额 - sale.put("outAmount", flowMap.get("outAmount"));//会员退款金额 + //收款金额 + BigDecimal incomeAmount = new BigDecimal(orderMap.get("saleAmount").toString()).subtract(new BigDecimal(orderMap.get("saveAmount").toString()));//订单金额 - 优惠金额 + sale.put("totalSaleAmount", incomeAmount.add(refundAmount));//总金额 销售收款金额+销售退款金额 + sale.put("incomeAmount", incomeAmount);//销售 收款金额 + sale.put("refundAmount", refundAmount);//销售 退款金额 + + sale.put("totalVipAmount", new BigDecimal(flowMap.get("inAmount").toString()).add(new BigDecimal(flowMap.get("outAmount").toString())));//会员总金额 + sale.put("inAmount", flowMap.get("inAmount")); //会员 充值金额 + sale.put("outAmount", flowMap.get("outAmount"));//会员 退款金额 + + sale.put("incomeAmountAll",incomeAmount.add(new BigDecimal(flowMap.get("inAmount").toString())));//总实收 销售实收+会员实收 + result.put("sale",sale); vip.put("useAmount", flowMap.get("useAmount"));//会员消费金额 vip.put("newFlow",newFlow);//新增会员数 From 1dd8dc4508db573f790a2207d26d34c58ad6ea0a Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 11 Sep 2024 16:52:09 +0800 Subject: [PATCH 14/56] =?UTF-8?q?=E8=90=A5=E4=B8=9A=E6=9D=BF=E5=9D=97=20?= =?UTF-8?q?=E9=87=91=E9=A2=9D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/pojo/shop/TbShopInfo.java | 2 +- .../service/impl/SummaryServiceImpl.java | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java index 6bd14fa1..103fc7bb 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java @@ -266,7 +266,7 @@ public class TbShopInfo implements Serializable { @ApiModelProperty(value = "是否免除桌位费 0否1是") private Integer isTableFee; - @Column(name = "tableFee") + @Column(name = "table_fee") @ApiModelProperty(value = "桌位费") private BigDecimal tableFee; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index a3659869..25a34a9b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -90,11 +90,18 @@ public class SummaryServiceImpl implements SummaryService { Integer newFlow = tbShopUserFlowMapper.tradeIndexNewFlow(param.getShopId(), DateUtil.getStrTime(param.getStartTime()), DateUtil.getStrTime(param.getEndTime())); //台桌数 int tables = tbShopTableRepository.countAllByShopId(param.getShopId()); - sale.put("totalSaleAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(refundAmount));//总金额 - sale.put("incomeAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(new BigDecimal(flowMap.get("inAmount").toString())));//实收 - sale.put("refundAmount", refundAmount);//销售退款金额 - sale.put("inAmount", flowMap.get("inAmount"));//会员充值金额 - sale.put("outAmount", flowMap.get("outAmount"));//会员退款金额 + //收款金额 + BigDecimal incomeAmount = new BigDecimal(orderMap.get("saleAmount").toString()).subtract(new BigDecimal(orderMap.get("saveAmount").toString()));//订单金额 - 优惠金额 + sale.put("totalSaleAmount", incomeAmount.add(refundAmount));//总金额 销售收款金额+销售退款金额 + sale.put("incomeAmount", incomeAmount);//销售 收款金额 + sale.put("refundAmount", refundAmount);//销售 退款金额 + + sale.put("totalVipAmount", new BigDecimal(flowMap.get("inAmount").toString()).add(new BigDecimal(flowMap.get("outAmount").toString())));//会员总金额 + sale.put("inAmount", flowMap.get("inAmount")); //会员 充值金额 + sale.put("outAmount", flowMap.get("outAmount"));//会员 退款金额 + + sale.put("incomeAmountAll",incomeAmount.add(new BigDecimal(flowMap.get("inAmount").toString())));//总实收 销售实收+会员实收 + result.put("sale",sale); vip.put("useAmount", flowMap.get("useAmount"));//会员消费金额 vip.put("newFlow",newFlow);//新增会员数 From 770c8e01f2d74ff4664c24dadf62e58f5d264530 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 16:59:20 +0800 Subject: [PATCH 15/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=89=93=E5=8D=B0=202.=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8F=B0=E6=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/cons/rabbit/RabbitConstants.java | 4 ++ .../controller/product/TbPlaceController.java | 10 +++ .../shop/TbShopTableController.java | 11 +++ .../cashier/dto/shoptable/BaseTableDTO.java | 15 ++++ .../dto/shoptable/TableGenerateDTO.java | 28 ++++++++ .../mybatis/mapper/MpShopAreaMapper.java | 8 +++ .../mybatis/service/MpShopTableService.java | 7 ++ .../service/impl/MpShopTableServiceImpl.java | 15 ++++ .../impl/shopimpl/TbShopTableServiceImpl.java | 68 ++++++++++++++++++- .../service/shop/TbShopTableService.java | 4 ++ .../cn/ysk/cashier/utils/RabbitMsgUtils.java | 8 +++ 11 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/BaseTableDTO.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/TableGenerateDTO.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/MpShopAreaMapper.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpShopTableService.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpShopTableServiceImpl.java diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rabbit/RabbitConstants.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rabbit/RabbitConstants.java index 51221d37..2b3e134e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rabbit/RabbitConstants.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rabbit/RabbitConstants.java @@ -24,4 +24,8 @@ public interface RabbitConstants { String EXCHANGE_PRINT = "exchange.print"; String ROUTING_KEY_PRINT_DISHES = "routing.dishes.print"; + // 订单打印 + String QUEUE_PRINT_PLACE = "queue.place.order.print"; + String ROUTING_KEY_PRINT_PLACE = "routing.place.order.print"; + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java index a620268a..925a74b6 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java @@ -236,6 +236,16 @@ public class TbPlaceController { return ResponseEntity.ok(tbShopTableService.updateVip(updateVipDTO)); } + @AnonymousAccess + @PostMapping("/printOrder") + @Log("代客下单 打印订单") + @ApiOperation("代客下单 查询购物车 /shop/table") + public ResponseEntity printOrder( + @Validated @RequestBody BaseTableDTO baseTableDTO + ) { + return ResponseEntity.ok(tbShopTableService.printOrder(baseTableDTO)); + } + private final RabbitTemplate rabbitTemplate; @AnonymousAccess @GetMapping("/test") diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopTableController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopTableController.java index 70ab3a66..e62f214c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopTableController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopTableController.java @@ -15,10 +15,12 @@ */ package cn.ysk.cashier.controller.shop; +import cn.ysk.cashier.annotation.AnonymousAccess; import cn.ysk.cashier.annotation.Log; import cn.ysk.cashier.dto.shoptable.AddCartDTO; import cn.ysk.cashier.dto.shoptable.ClearCartDTO; import cn.ysk.cashier.dto.shoptable.RemoveCartDTO; +import cn.ysk.cashier.dto.shoptable.TableGenerateDTO; import cn.ysk.cashier.pojo.shop.TbShopTable; import cn.ysk.cashier.service.shop.TbShopTableService; import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria; @@ -87,6 +89,15 @@ public class TbShopTableController { return new ResponseEntity<>(HttpStatus.OK); } + @PostMapping("/generate") + @ApiOperation("查询/shop/table") + public ResponseEntity generate(@Validated @RequestBody TableGenerateDTO generateDTO){ + if (generateDTO.getStart() >= generateDTO.getEnd()){ + return ResponseEntity.badRequest().body("起始数不能大于结束数"); + } + return new ResponseEntity<>(tbShopTableService.generate(generateDTO),HttpStatus.OK); + } + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/BaseTableDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/BaseTableDTO.java new file mode 100644 index 00000000..cafdb4e5 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/BaseTableDTO.java @@ -0,0 +1,15 @@ +package cn.ysk.cashier.dto.shoptable; + +import lombok.Data; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Data +public class BaseTableDTO { + @NotNull + private Integer shopId; + @NotEmpty + private String tableId; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/TableGenerateDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/TableGenerateDTO.java new file mode 100644 index 00000000..9e19f372 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/TableGenerateDTO.java @@ -0,0 +1,28 @@ +package cn.ysk.cashier.dto.shoptable; + +import lombok.Data; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Data +public class TableGenerateDTO { + @NotNull + private Integer shopId; + @NotEmpty + private String sign; + private Integer areaId; + @Min(1) + @NotNull + private Integer start; + @Min(2) + @Max(1000) + @NotNull + private Integer end; + @NotNull + @Min(1) + private Integer capacity; + private Integer autoClear = 1; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/MpShopAreaMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/MpShopAreaMapper.java new file mode 100644 index 00000000..1a64808d --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/MpShopAreaMapper.java @@ -0,0 +1,8 @@ +package cn.ysk.cashier.mybatis.mapper; + +import cn.ysk.cashier.pojo.shop.TbShopArea; +import cn.ysk.cashier.pojo.shop.TbShopTable; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +public interface MpShopAreaMapper extends BaseMapper { +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpShopTableService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpShopTableService.java new file mode 100644 index 00000000..65ee8e88 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpShopTableService.java @@ -0,0 +1,7 @@ +package cn.ysk.cashier.mybatis.service; + +import cn.ysk.cashier.pojo.shop.TbShopTable; +import com.baomidou.mybatisplus.extension.service.IService; + +public interface MpShopTableService extends IService { +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpShopTableServiceImpl.java new file mode 100644 index 00000000..986aa570 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpShopTableServiceImpl.java @@ -0,0 +1,15 @@ +package cn.ysk.cashier.mybatis.service.impl; + +import cn.ysk.cashier.mapper.shop.TbShopTableMapper; +import cn.ysk.cashier.mybatis.entity.TagProductDepts; +import cn.ysk.cashier.mybatis.mapper.MpShopTableMapper; +import cn.ysk.cashier.mybatis.mapper.TagProductDeptsMapper; +import cn.ysk.cashier.mybatis.service.MpShopTableService; +import cn.ysk.cashier.mybatis.service.TagProductDeptsService; +import cn.ysk.cashier.pojo.shop.TbShopTable; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +@Service +public class MpShopTableServiceImpl extends ServiceImpl implements MpShopTableService { +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index e6eb44d5..5e02d17c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -30,6 +30,7 @@ import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.entity.TbShopOpenId; import cn.ysk.cashier.mybatis.entity.TbShopUserFlow; import cn.ysk.cashier.mybatis.mapper.*; +import cn.ysk.cashier.mybatis.service.MpShopTableService; import cn.ysk.cashier.pojo.TbShopPayType; import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.order.TbOrderDetail; @@ -37,6 +38,7 @@ import cn.ysk.cashier.pojo.order.TbOrderInfo; import cn.ysk.cashier.pojo.product.TbProduct; import cn.ysk.cashier.pojo.product.TbProductSku; import cn.ysk.cashier.pojo.shop.TbMerchantAccount; +import cn.ysk.cashier.pojo.shop.TbShopArea; import cn.ysk.cashier.pojo.shop.TbShopInfo; import cn.ysk.cashier.pojo.shop.TbShopTable; import cn.ysk.cashier.repository.TbShopPayTypeRepository; @@ -111,6 +113,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { private final TbShopPayTypeRepository payTypeRepository; private final MpShopTableMapper mpShopTableMapper; private final TbShopPayTypeMapper tbShopPayTypeMapper; + private final MpShopTableService mpShopTableService; /** @@ -122,6 +125,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { private final TbCashierCartMapper tbCashierCartMapper; private final TbOrderDetailMapper tbOrderDetailMapper; private final StringRedisTemplate stringRedisTemplate; + private final MpShopAreaMapper mpShopAreaMapper; @Override public Map queryAll(TbShopTableQueryCriteria criteria, Pageable pageable) { @@ -1567,7 +1571,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { LambdaQueryWrapper query = new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, choseCountDTO.getShopId()) .eq(TbCashierCart::getMasterId, choseCountDTO.getMasterId()) - .eq(TbCashierCart::getProductId, -999) + .eq(TbCashierCart::getProductId, "-999") + .eq(TbCashierCart::getSkuId, "-999") .eq(TbCashierCart::getTableId, choseCountDTO.getTableId()); TbCashierCart tbCashierCart = cashierCartMapper.selectOne(query); @@ -1597,4 +1602,65 @@ public class TbShopTableServiceImpl implements TbShopTableService { return tbCashierCart; } + + @Override + public Object printOrder(BaseTableDTO baseTableDTO) { + TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() + .eq(TbShopTable::getQrcode, baseTableDTO.getTableId()) + .in(TbShopTable::getStatus, TableStateEnum.USING.getState(), TableStateEnum.PAYING.getState(), TableStateEnum.CLEANING.getState())); + if (tbShopTable == null) { + throw new BadRequestException("台桌不存在或当前台桌未开台"); + } + String currentOrderId = getCurrentOrderId(baseTableDTO.getTableId(), baseTableDTO.getShopId().toString()); + if (StrUtil.isBlank(currentOrderId)) { + throw new BadRequestException("当前台桌不存在订单"); + } + TbOrderInfo orderInfo = orderInfoMapper.selectById(currentOrderId); + rabbitMsgUtils.printPlaceTicket(orderInfo.getId(), false); + return true; + } + + @Override + public Object generate(TableGenerateDTO generateDTO) { + TbShopArea shopArea = mpShopAreaMapper.selectOne(new LambdaQueryWrapper() + .eq(TbShopArea::getShopId, generateDTO.getShopId()) + .eq(TbShopArea::getId, generateDTO.getAreaId())); + if (shopArea == null) { + throw new BadRequestException("台桌区域不存在"); + } + + List tbShopTables = mpShopTableMapper.selectList(new LambdaQueryWrapper() + .eq(TbShopTable::getShopId, generateDTO.getShopId()) + .select(TbShopTable::getName)); + + HashMap tableMap = new HashMap<>(); + tbShopTables.forEach(item -> { + tableMap.put(item.getName(), item); + }); + + StringBuilder msg = new StringBuilder(); + ArrayList tableArrayList = new ArrayList<>(); + for (int i = generateDTO.getStart(); i <= generateDTO.getEnd(); i++) { + String name = generateDTO.getSign() + i; + if (tableMap.get(name) != null) { + msg.append(name).append(";"); + continue; + } + TbShopTable shopTable = new TbShopTable(); + shopTable.setShopId(generateDTO.getShopId()); + shopTable.setName(name); + shopTable.setMaxCapacity(generateDTO.getCapacity()); + shopTable.setAreaId(generateDTO.getAreaId()); + shopTable.setCreatedAt(DateUtil.current()); + shopTable.setStatus(TableStateEnum.CLOSED.getState()); + tableArrayList.add(shopTable); + } + + mpShopTableService.saveBatch(tableArrayList); + if (StrUtil.isNotBlank(msg.toString())) { + msg.append("台桌名已存在,未添加"); + throw new BadRequestException(msg.toString()); + } + return true; + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java index 12516322..91c666f0 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java @@ -130,4 +130,8 @@ public interface TbShopTableService { Object choseTable(ChoseTableDTO choseTableDTO); Object choseCount(ChoseCountDTO choseCountDTO); + + Object printOrder(BaseTableDTO baseTableDTO); + + Object generate(TableGenerateDTO generateDTO); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java index cd22a2dc..d3585244 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java @@ -54,4 +54,12 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback { jsonObject.put("isReturn", true); sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品退单", false); } + + public void printPlaceTicket(Integer id, boolean isReturn) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("orderId", id); + jsonObject.put("isReturn", isReturn); + sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_PLACE, jsonObject, "订单打印", false); + + } } From 5d15b3c30977f0373a86848263c16715b5b1dc93 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 11 Sep 2024 17:09:44 +0800 Subject: [PATCH 16/56] =?UTF-8?q?=E7=BF=BB=E5=8F=B0=E7=8E=87=20=E4=B8=8D?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/service/impl/SummaryServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index 25a34a9b..0d7c5596 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -115,10 +115,10 @@ public class SummaryServiceImpl implements SummaryService { count.put("unitPrice",saleAmount.divide(new BigDecimal(orderMap.get("saleNum").toString()),2,RoundingMode.DOWN)); } BigDecimal saleNum = new BigDecimal(orderMap.get("saleNum").toString()); - if(saleNum.compareTo(BigDecimal.ZERO) == 0){ - count.put("turnoverRate",BigDecimal.ZERO+"%");//翻台率 + if(saleNum.compareTo(BigDecimal.ZERO) == 0 || saleNum.compareTo(new BigDecimal(tables)) < 0){ + count.put("turnoverRate","0%");//翻台率 }else { - count.put("turnoverRate",saleNum.divide(new BigDecimal(tables),2,RoundingMode.DOWN).subtract(BigDecimal.ONE).multiply(new BigDecimal("100"))+"%");//翻台率 + count.put("turnoverRate",saleNum.divide(new BigDecimal(tables),0,RoundingMode.DOWN).subtract(BigDecimal.ONE).multiply(new BigDecimal("100"))+"%");//翻台率 } count.put("saveAmount",orderMap.get("saveAmount"));//优惠金额 count.put("saveNum",orderMap.get("saveNum"));//优惠单数 From 2f4fec7631c40756f11351de2fd9b3a752941787 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 17:37:25 +0800 Subject: [PATCH 17/56] =?UTF-8?q?1.=E9=80=80=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/controller/product/TbPlaceController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java index 925a74b6..c231c059 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java @@ -88,7 +88,7 @@ public class TbPlaceController { } @AnonymousAccess - @PutMapping("/returnOrder") + @PutMapping("/returnCart") @Log("代客下单 退单") @ApiOperation("代客下单 清空购物车 /shop/table") public ResponseEntity returnOrder(@Validated @RequestBody RemoveCartDTO removeCartDTO) { From 7921c21295ceeb657471b9fb60722426983f2902 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 17:52:37 +0800 Subject: [PATCH 18/56] =?UTF-8?q?1.=E5=8F=96=E6=B6=88=E6=8C=82=E5=8D=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/controller/product/TbPlaceController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java index c231c059..5caefc37 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java @@ -163,7 +163,6 @@ public class TbPlaceController { public ResponseEntity pending( @RequestBody PendingDTO pendingDTO ) { - pendingDTO.setIsPending(true); return ResponseEntity.ok(tbShopTableService.pending(pendingDTO)); } From 3b9617a03efdf53cf17b2019154d7726070ca53e Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 18:00:46 +0800 Subject: [PATCH 19/56] =?UTF-8?q?1.=E5=B7=B2=E9=80=80=E5=8D=95=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=BF=BD=E7=95=A5=E8=AE=A2=E5=8D=95=E6=80=BB=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/shopimpl/TbShopTableServiceImpl.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 5e02d17c..062be576 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -537,7 +537,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { // 会员点单 TbCashierCart cashierCart = cashierCartMapper.selectOne(new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, removeCartDTO.getShopId()) - .in(TbCashierCart::getStatus, "create") + .in(TbCashierCart::getStatus, "create", "refund") .eq(TbCashierCart::getId, removeCartDTO.getCartId())); if (cashierCart == null) { @@ -1027,9 +1027,12 @@ public class TbShopTableServiceImpl implements TbShopTableService { if ("-999".equals(cashierCart.getProductId())) { mealCost = true; } - totalAmount = totalAmount.add(cashierCart.getTotalAmount()); - packAMount = packAMount.add(cashierCart.getPackFee()); - feeAmount = cashierCart.getPackFee(); + if (!"return".equals(cashierCart.getStatus())) { + totalAmount = totalAmount.add(cashierCart.getTotalAmount()); + packAMount = packAMount.add(cashierCart.getPackFee()); + feeAmount = cashierCart.getPackFee(); + } + TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null); TbOrderDetail orderDetail = new TbOrderDetail(); @@ -1047,7 +1050,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderDetail.setProductName(cashierCart.getName()); orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId())); orderDetail.setPackAmount(cashierCart.getPackFee()); - orderDetail.setStatus("unpaid"); + orderDetail.setStatus("return"); orderDetail.setProductImg(cashierCart.getCoverImg()); orderDetails.add(orderDetail); if (cashierCart.getOrderId() != null) { From 7af4a48dfa44d99bf5ba1c67844ee96b64a4e6cb Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 11 Sep 2024 18:04:06 +0800 Subject: [PATCH 20/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=B0=E6=A1=8C=E5=B0=B1=E9=A4=90=E4=BA=BA?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java | 2 ++ .../service/impl/shopimpl/TbShopTableServiceImpl.java | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java index 936640ce..d34d454d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java @@ -121,6 +121,8 @@ public class TbShopTable implements Serializable { private Integer totalAmount; @Column(name = "`real_amount`") private Integer realAmount; + @Column(name = "`use_num`") + private Integer useNum; public void copy(TbShopTable source){ diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 062be576..75c963c3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1022,10 +1022,10 @@ public class TbShopTableServiceImpl implements TbShopTableService { int placeNum = getCurrentPlaceNum(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString()); List orderDetails = new ArrayList<>(); - boolean mealCost = false; + Integer mealNum = null; for (TbCashierCart cashierCart : cashierCarts) { if ("-999".equals(cashierCart.getProductId())) { - mealCost = true; + mealNum = cashierCart.getNumber(); } if (!"return".equals(cashierCart.getStatus())) { totalAmount = totalAmount.add(cashierCart.getTotalAmount()); @@ -1060,7 +1060,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderDetail.setPlaceNum(placeNum); } - if (!mealCost) { + if (mealNum == null) { throw new BadRequestException("请选择用餐人数"); } @@ -1184,6 +1184,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { .set(TbShopTable::getProductNum, cashierCarts.size()) .set(TbShopTable::getTotalAmount, orderInfo.getOrderAmount()) .set(TbShopTable::getRealAmount, orderInfo.getOrderAmount()) + .set(TbShopTable::getUseNum, mealNum) .set(TbShopTable::getStatus, TableStateEnum.USING.getState()); if (isFirst) { wrapper.set(TbShopTable::getUseTime, DateUtil.date()); From 48078ad2d6c5f6dc00daa9ae38984113675c8d58 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 09:33:16 +0800 Subject: [PATCH 21/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=E4=B8=8D=E8=AE=BE=E7=BD=AEplaceNum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 75c963c3..b23bc7a2 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -424,7 +424,6 @@ public class TbShopTableServiceImpl implements TbShopTableService { tbCashierCart.setSalePrice(productSku.getSalePrice()); tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice())); tbCashierCart.setSkuName(productSku.getSpecSnap()); - tbCashierCart.setPlaceNum(currentPlaceNum); if (!addCartDTO.isPack()) { tbCashierCart.setPackFee(BigDecimal.ZERO); } else { @@ -658,6 +657,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { Map map = BeanUtil.beanToMap(item, false, false); TbProductSku tbProductSku = skuMap.get(item.getSkuId()); map.put("specSnap", tbProductSku != null ? tbProductSku.getSpecSnap() : null); + map.put("placeNum", item.getPlaceNum() == null ? 0 : item.getPlaceNum()); infos.add(map); }); @@ -1149,6 +1149,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { cashierCart.setOrderId(orderId); cashierCart.setUpdatedAt(System.currentTimeMillis()); cashierCart.setStatus("pending".equals(orderInfo.getStatus()) ? "refund" : cashierCart.getStatus()); + cashierCart.setPlaceNum(placeNum); cashierCartMapper.updateById(cashierCart); } if (isFirst) { From c5d92f9ea62fdd9e023b4c2061e15e8e49386cbd Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 09:49:54 +0800 Subject: [PATCH 22/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=E4=B8=8D=E8=AE=BE=E7=BD=AEplaceNum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index b23bc7a2..cbbbba80 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -278,7 +278,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { int currentPlaceNum = getCurrentPlaceNum(tbCashierCart.getTableId().toString(), tbCashierCart.getShopId()); - if (!tbCashierCart.getPlaceNum().equals(currentPlaceNum)) { + if (tbCashierCart.getPlaceNum() != null && !tbCashierCart.getPlaceNum().equals(currentPlaceNum)) { throw new BadRequestException("已下单商品仅支持退单操作"); } From 242427f1ee99d2a94c562f1280d588ff7537caac Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 10:07:53 +0800 Subject: [PATCH 23/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=8F=B0=E6=A1=8C=E7=8A=B6=E6=80=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/shopimpl/TbShopTableServiceImpl.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index cbbbba80..acd273a8 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -159,12 +159,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { .eq(TbCashierCart::getShopId, date.getShopId()) .eq(TbCashierCart::getTableId, date.getQrcode()) .eq(TbCashierCart::getTradeDay, cn.ysk.cashier.utils.DateUtils.getDay()) - .eq(TbCashierCart::getStatus, "create")) < 1 || (orderId != null && - tbOrderDetailMapper.selectCount(new LambdaQueryWrapper() - .eq(TbOrderDetail::getShopId, date.getShopId()) - .eq(TbOrderDetail::getStatus, "unpaid") - .ge(TbOrderDetail::getCreateTime, DateUtil.beginOfDay(new Date())) - .eq(TbOrderDetail::getOrderId, orderId)) < 1) + .eq(TbCashierCart::getStatus, "create")) < 1 ) { date.setStatus("idle"); mpShopTableMapper.update(null, new LambdaUpdateWrapper() From 7e29627bf6033ba66da4be105c17e2fd0da5c5ed Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 10:22:12 +0800 Subject: [PATCH 24/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8A=A5=E9=94=99fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index acd273a8..be9292f9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -498,7 +498,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { throw new BadRequestException("购物车商品不存在"); } - if (!cashierCart.getPlaceNum().equals(currentPlaceNum)) { + if (cashierCart.getPlaceNum() != null && !cashierCart.getPlaceNum().equals(currentPlaceNum)) { throw new BadRequestException("已下单商品仅支持退单操作"); } From 8b099a2ae663f97fb95c7e059ba35b6eb43d17ee Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 12 Sep 2024 10:26:28 +0800 Subject: [PATCH 25/56] =?UTF-8?q?=E5=BA=97=E9=93=BA=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java | 5 ++--- .../cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java index 103fc7bb..fdc8c28b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java @@ -57,8 +57,7 @@ public class TbShopInfo implements Serializable { @ApiModelProperty(value = "商户Id") private String merchantId; - @Column(name = "`shop_name`",nullable = false) - @NotBlank + @Column(name = "`shop_name`") @ApiModelProperty(value = "店铺名称") private String shopName; @@ -282,6 +281,6 @@ public class TbShopInfo implements Serializable { private String paymentQrcode; public void copy(TbShopInfo source){ - BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false)); + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java index 0fad205e..96200030 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java @@ -239,7 +239,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { @Transactional(rollbackFor = Exception.class) public void update(TbShopInfo resources) { TbShopInfo tbShopInfo = tbShopInfoRepository.findById(resources.getId()).orElseGet(TbShopInfo::new); - if (!resources.getShopName().equals(tbShopInfo.getShopName())) { + if (StringUtils.isNotBlank(resources.getShopName()) && !resources.getShopName().equals(tbShopInfo.getShopName())) { shopStaffRepository.updateNameById(resources.getShopName(),resources.getId().toString()); userRepository.updateNickName(resources.getAccount(),resources.getShopName()); } From 0a3b50ef6f3007fba3caf090b04ba8ade0cab593 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 12 Sep 2024 10:26:28 +0800 Subject: [PATCH 26/56] =?UTF-8?q?=E5=BA=97=E9=93=BA=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java | 5 ++--- .../cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java index 103fc7bb..fdc8c28b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java @@ -57,8 +57,7 @@ public class TbShopInfo implements Serializable { @ApiModelProperty(value = "商户Id") private String merchantId; - @Column(name = "`shop_name`",nullable = false) - @NotBlank + @Column(name = "`shop_name`") @ApiModelProperty(value = "店铺名称") private String shopName; @@ -282,6 +281,6 @@ public class TbShopInfo implements Serializable { private String paymentQrcode; public void copy(TbShopInfo source){ - BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false)); + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java index 0fad205e..96200030 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java @@ -239,7 +239,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { @Transactional(rollbackFor = Exception.class) public void update(TbShopInfo resources) { TbShopInfo tbShopInfo = tbShopInfoRepository.findById(resources.getId()).orElseGet(TbShopInfo::new); - if (!resources.getShopName().equals(tbShopInfo.getShopName())) { + if (StringUtils.isNotBlank(resources.getShopName()) && !resources.getShopName().equals(tbShopInfo.getShopName())) { shopStaffRepository.updateNameById(resources.getShopName(),resources.getId().toString()); userRepository.updateNickName(resources.getAccount(),resources.getShopName()); } From baa9c6c2608bb010be8cea5278541dc7b46f49f6 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 12 Sep 2024 10:31:26 +0800 Subject: [PATCH 27/56] =?UTF-8?q?=E5=BA=97=E9=93=BA=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98=20=E9=9D=9E=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java index fdc8c28b..3cb60517 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java @@ -189,8 +189,7 @@ public class TbShopInfo implements Serializable { @ApiModelProperty(value = "到期时间") private Long expireAt; - @Column(name = "`status`",nullable = false) - @NotNull + @Column(name = "`status`") @ApiModelProperty(value = "门店状态") private Integer status; From e08f83ac6ee8190f01bc8d61771e3c41cafdae81 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 10:47:16 +0800 Subject: [PATCH 28/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/pojo/shop/TbShopTable.java | 2 +- .../service/impl/shopimpl/TbShopTableServiceImpl.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java index d34d454d..688570b7 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopTable.java @@ -15,6 +15,7 @@ */ package cn.ysk.cashier.pojo.shop; +import com.baomidou.mybatisplus.annotation.TableField; import lombok.Data; import cn.hutool.core.bean.BeanUtil; import io.swagger.annotations.ApiModelProperty; @@ -124,7 +125,6 @@ public class TbShopTable implements Serializable { @Column(name = "`use_num`") private Integer useNum; - public void copy(TbShopTable source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index be9292f9..eae1b64c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -167,6 +167,11 @@ public class TbShopTableServiceImpl implements TbShopTableService { .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState())); } Map itemMap = BeanUtil.beanToMap(date, false, false); + if ((date.getStatus().equals("using") || date.getStatus().equals("cleaning")) && date.getUseTime() != null) { + itemMap.put("durationTime", DateUtil.current() - date.getUseTime().getTime()); + }else { + itemMap.put("durationTime", 0); + } if (!"".equals(date.getQrcode())) { itemMap.put("qrcode", QRCODE + date.getQrcode().trim()); itemMap.put("tableId", date.getQrcode()); @@ -371,7 +376,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { .eq(TbCashierCart::getSkuId, addCartDTO.getSkuId()) .eq(TbCashierCart::getProductId, addCartDTO.getProductId()) .eq(TbCashierCart::getTableId, addCartDTO.getTableId()) - .eq(TbCashierCart::getPlaceNum, currentPlaceNum) + .isNull(TbCashierCart::getPlaceNum) .in(TbCashierCart::getStatus, "create", "refund") // .and(q -> { // q.eq(TbCashierCart::getTradeDay, DateUtils.getDay()) @@ -507,10 +512,12 @@ public class TbShopTableServiceImpl implements TbShopTableService { .eq(TbOrderDetail::getShopId, cashierCart.getShopId()) .eq(TbOrderDetail::getProductId, cashierCart.getProductId()) .eq(TbOrderDetail::getProductSkuId, cashierCart.getSkuId()) - .eq(TbOrderDetail::getPlaceNum, currentPlaceNum) + .isNull(TbOrderDetail::getPlaceNum) .eq(TbOrderDetail::getOrderId, cashierCart.getOrderId())); } + cashierCartMapper.deleteById(cashierCart.getId()); + // 清空购物车 出票 long carCount = countCar(cashierCart.getTableId(), cashierCart.getShopId(), cashierCart.getMasterId()); From d7bf0f2811202c5019484196f25ad9aceb38986a Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 11:21:06 +0800 Subject: [PATCH 29/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=BD=93=E5=89=8D=E5=8F=B0=E6=A1=8C=E8=8F=9C?= =?UTF-8?q?=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/product/TbPlaceController.java | 10 ++++ .../impl/shopimpl/TbShopTableServiceImpl.java | 53 ++++++++++++++++--- .../service/shop/TbShopTableService.java | 2 + .../cn/ysk/cashier/utils/RabbitMsgUtils.java | 8 +++ 4 files changed, 66 insertions(+), 7 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java index 5caefc37..bce7b7c0 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java @@ -245,6 +245,16 @@ public class TbPlaceController { return ResponseEntity.ok(tbShopTableService.printOrder(baseTableDTO)); } + @AnonymousAccess + @PostMapping("/printDishes") + @Log("代客下单 打印菜品单") + @ApiOperation("代客下单 打印菜品单 /shop/table") + public ResponseEntity printDishes( + @Validated @RequestBody BaseTableDTO baseTableDTO + ) { + return ResponseEntity.ok(tbShopTableService.printDishes(baseTableDTO)); + } + private final RabbitTemplate rabbitTemplate; @AnonymousAccess @GetMapping("/test") diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index eae1b64c..a76a41b3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1052,7 +1052,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderDetail.setProductName(cashierCart.getName()); orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId())); orderDetail.setPackAmount(cashierCart.getPackFee()); - orderDetail.setStatus("return"); + orderDetail.setStatus("unpaid"); orderDetail.setProductImg(cashierCart.getCoverImg()); orderDetails.add(orderDetail); if (cashierCart.getOrderId() != null) { @@ -1612,12 +1612,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public Object printOrder(BaseTableDTO baseTableDTO) { - TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() - .eq(TbShopTable::getQrcode, baseTableDTO.getTableId()) - .in(TbShopTable::getStatus, TableStateEnum.USING.getState(), TableStateEnum.PAYING.getState(), TableStateEnum.CLEANING.getState())); - if (tbShopTable == null) { - throw new BadRequestException("台桌不存在或当前台桌未开台"); - } + checkTableState(baseTableDTO.getTableId()); + String currentOrderId = getCurrentOrderId(baseTableDTO.getTableId(), baseTableDTO.getShopId().toString()); if (StrUtil.isBlank(currentOrderId)) { throw new BadRequestException("当前台桌不存在订单"); @@ -1670,4 +1666,47 @@ public class TbShopTableServiceImpl implements TbShopTableService { } return true; } + + private TbShopTable checkTableState(String tableId) { + TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() + .eq(TbShopTable::getQrcode, tableId) + .in(TbShopTable::getStatus, TableStateEnum.USING.getState(), TableStateEnum.PAYING.getState(), TableStateEnum.CLEANING.getState())); + if (tbShopTable == null) { + throw new BadRequestException("台桌不存在或当前台桌未开台"); + } + return tbShopTable; + } + + private TbOrderInfo getCurrentOrder(String tableId, String shopId) { + String currentOrderId = getCurrentOrderId(tableId, shopId); + if (StrUtil.isBlank(currentOrderId)) { + throw new BadRequestException("当前台桌不存在订单"); + } + TbOrderInfo orderInfo = orderInfoMapper.selectById(currentOrderId); + if (orderInfo == null) { + throw new BadRequestException("当前台桌不存在订单"); + } + return orderInfo; + } + + @Override + public Object printDishes(BaseTableDTO baseTableDTO) { + checkTableState(baseTableDTO.getTableId()); + TbOrderInfo currentOrder = getCurrentOrder(baseTableDTO.getTableId(), baseTableDTO.getShopId().toString()); + List detailList = orderDetailMapper.selectList(new LambdaQueryWrapper() + .eq(TbOrderDetail::getOrderId, currentOrder.getId()) + .eq(TbOrderDetail::getStatus, "unpaid") + .ne(TbOrderDetail::getProductId, -999) + .select(TbOrderDetail::getId)); + if (detailList.isEmpty()) { + throw new BadRequestException("当前台桌还未下单任何菜品, 请先下单"); + } + + Integer[] detailIds = new Integer[detailList.size()]; + for (int i = 0; i < detailList.size(); i++) { + detailIds[i] = detailList.get(i).getId(); + } + rabbitMsgUtils.printDishesTicket(currentOrder.getId(), false, detailIds); + return true; + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java index 91c666f0..64f76194 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java @@ -134,4 +134,6 @@ public interface TbShopTableService { Object printOrder(BaseTableDTO baseTableDTO); Object generate(TableGenerateDTO generateDTO); + + Object printDishes(BaseTableDTO baseTableDTO); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java index d3585244..a51e3d6a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/RabbitMsgUtils.java @@ -55,6 +55,14 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback { sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品退单", false); } + public void printDishesTicket(Integer orderId, boolean isReturn, Integer... detailOrderIds) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("orderId", orderId); + jsonObject.put("orderDetailIds", detailOrderIds); + jsonObject.put("isReturn", isReturn); + sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品打印", false); + } + public void printPlaceTicket(Integer id, boolean isReturn) { JSONObject jsonObject = new JSONObject(); jsonObject.put("orderId", id); From 90d5e3888bada727073bc7b9f15ae7b682d31489 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 14:08:13 +0800 Subject: [PATCH 30/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E9=80=80=E5=8D=95fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index a76a41b3..70fe5630 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -548,6 +548,10 @@ public class TbShopTableServiceImpl implements TbShopTableService { TbOrderDetail tbOrderDetail = orderDetailMapper.selectOne(new LambdaQueryWrapper() .eq(TbOrderDetail::getShopId, removeCartDTO.getShopId()) .eq(TbOrderDetail::getPlaceNum, cashierCart.getPlaceNum()) + .eq(TbOrderDetail::getProductId, cashierCart.getProductId()) + .eq(TbOrderDetail::getProductSkuId, cashierCart.getSkuId()) + .eq(TbOrderDetail::getPlaceNum, cashierCart.getPlaceNum()) + .eq(TbOrderDetail::getNum, cashierCart.getNumber()) .in(TbOrderDetail::getStatus, "unpaid") .eq(TbOrderDetail::getOrderId, cashierCart.getOrderId())); if (tbOrderDetail == null) { From 5c2b995d1fd2ad1f80f70e1454443c77313f1aca Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 14:21:56 +0800 Subject: [PATCH 31/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95placeNum=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/shopimpl/TbShopTableServiceImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 70fe5630..ba90ce14 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -970,7 +970,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override - public TbOrderInfo createOrder(CreateOrderDTO createOrderDTO, boolean addMaterId, boolean isPrint) { + public TbOrderInfo createOrder(CreateOrderDTO createOrderDTO, boolean addMaterId, boolean isPrint) { return Utils.runFunAndCheckKey(() -> { TbShopTable tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) @@ -1029,6 +1029,10 @@ public class TbShopTableServiceImpl implements TbShopTableService { List orderDetails = new ArrayList<>(); Integer mealNum = null; + + if (cashierCarts.stream().noneMatch(item -> item.getPlaceNum() == null)) { + throw new BadRequestException("此次未添加新商品,清先添加商品"); + } for (TbCashierCart cashierCart : cashierCarts) { if ("-999".equals(cashierCart.getProductId())) { mealNum = cashierCart.getNumber(); @@ -1155,7 +1159,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { cashierCart.setOrderId(orderId); cashierCart.setUpdatedAt(System.currentTimeMillis()); cashierCart.setStatus("pending".equals(orderInfo.getStatus()) ? "refund" : cashierCart.getStatus()); - cashierCart.setPlaceNum(placeNum); + if (cashierCart.getPlaceNum() == null) { + cashierCart.setPlaceNum(placeNum); + } cashierCartMapper.updateById(cashierCart); } if (isFirst) { From 0f9c3701181889d03993d79cb7fb5b1229e2f408 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 14:38:45 +0800 Subject: [PATCH 32/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8D=95=E5=93=81=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysk/cashier/dto/shoptable/AddCartDTO.java | 2 +- .../ysk/cashier/pojo/order/TbCashierCart.java | 2 ++ .../ysk/cashier/pojo/order/TbOrderDetail.java | 3 +++ .../impl/shopimpl/TbShopTableServiceImpl.java | 22 +++++++++++++------ .../service/shop/TbShopTableService.java | 3 +-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/AddCartDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/AddCartDTO.java index c64b654c..0107c9aa 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/AddCartDTO.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/AddCartDTO.java @@ -25,5 +25,5 @@ public class AddCartDTO { private boolean isPack; private boolean isGift; private Integer cartId; - + private String note; } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java index b87e46bf..788b041d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbCashierCart.java @@ -157,6 +157,8 @@ public class TbCashierCart implements Serializable { private String skuName; @Column(name = "`place_num`") private Integer placeNum; + @Column(name = "`note`") + private String note; public void copy(TbCashierCart source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java index 60437fcc..379db52a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java @@ -113,6 +113,9 @@ public class TbOrderDetail implements Serializable { @ApiModelProperty(value = "place_num") private Integer placeNum; + @Column(name = "`note`") + private String note; + public void copy(TbOrderDetail source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index ba90ce14..213cb88e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -28,7 +28,6 @@ import cn.ysk.cashier.enums.ShopWxMsgTypeEnum; import cn.ysk.cashier.enums.TableStateEnum; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.entity.TbShopOpenId; -import cn.ysk.cashier.mybatis.entity.TbShopUserFlow; import cn.ysk.cashier.mybatis.mapper.*; import cn.ysk.cashier.mybatis.service.MpShopTableService; import cn.ysk.cashier.pojo.TbShopPayType; @@ -49,7 +48,6 @@ import cn.ysk.cashier.repository.shop.TbShopInfoRepository; import cn.ysk.cashier.service.impl.TbPayServiceImpl; import cn.ysk.cashier.utils.*; import cn.ysk.cashier.vo.PendingCountVO; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -72,12 +70,12 @@ import org.springframework.data.domain.Pageable; import java.math.BigDecimal; import java.math.RoundingMode; -import java.sql.Timestamp; import java.time.Instant; import java.util.*; import java.io.IOException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; @@ -437,9 +435,11 @@ public class TbShopTableServiceImpl implements TbShopTableService { tbCashierCart.setTotalNumber(addCartDTO.getNum()); tbCashierCart.setNumber(addCartDTO.getNum()); tbCashierCart.setCategoryId(product.getCategoryId()); + tbCashierCart.setNote(addCartDTO.getNote()); cashierCartRepository.save(tbCashierCart); } else { + tbCashierCart.setNote(addCartDTO.getNote()); tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice())); if (!addCartDTO.isPack()) { @@ -619,8 +619,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { } @Override - public com.baomidou.mybatisplus.extension.plugins.pagination.Page getCart(Long tableId, Integer page, - Integer size, Integer shopId, Integer vipUserId, String masterId) { + public Map getCart(Long tableId, Integer page, + Integer size, Integer shopId, Integer vipUserId, String masterId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .eq(TbCashierCart::getTableId, tableId) .in(TbCashierCart::getStatus, "create", "refund", "return") @@ -653,6 +653,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { }); + AtomicReference mealCashierCart = new AtomicReference<>(); if (!skuIds.isEmpty()) { List skuList = productSkuRepository.findAllById(skuIds); HashMap skuMap = new HashMap<>(); @@ -660,6 +661,10 @@ public class TbShopTableServiceImpl implements TbShopTableService { ArrayList> infos = new ArrayList<>(); records.forEach(item -> { + if (item.getProductId().equals("-999")) { + mealCashierCart.set(item); + return; + } Map map = BeanUtil.beanToMap(item, false, false); TbProductSku tbProductSku = skuMap.get(item.getSkuId()); map.put("specSnap", tbProductSku != null ? tbProductSku.getSpecSnap() : null); @@ -681,10 +686,12 @@ public class TbShopTableServiceImpl implements TbShopTableService { list.add(item); }); copyPage.setRecords(list); - return copyPage; + Map map = BeanUtil.beanToMap(copyPage, false, false); + map.put("seatFee", mealCashierCart); + return map; } - return cartPage; + return BeanUtil.beanToMap(cartPage); } @Override @@ -1051,6 +1058,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderDetail.setProductSkuName(productSku.getSpecSnap()); } + orderDetail.setNote(cashierCart.getNote()); orderDetail.setCreateTime(DateUtil.date().toTimestamp()); orderDetail.setNum(cashierCart.getNumber()); orderDetail.setPrice(cashierCart.getSalePrice()); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java index 64f76194..5cf3c63e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopTableService.java @@ -21,7 +21,6 @@ import cn.ysk.cashier.pojo.shop.TbShopTable; import cn.ysk.cashier.dto.shop.TbShopTableDto; import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria; import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.data.domain.Pageable; import java.util.Map; import java.util.List; @@ -105,7 +104,7 @@ public interface TbShopTableService { void clearCart(ClearCartDTO clearCartDTO); - Page getCart(Long tableId, Integer page, Integer size, Integer shopId, Integer vipUserId, String masterId); + Map getCart(Long tableId, Integer page, Integer size, Integer shopId, Integer vipUserId, String masterId); TbCashierCart updateCart(UpdateCartDTO updateCartDTO); From a40431fbe7c55e9df94a944b3e4b77f5d50196f1 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 14:43:54 +0800 Subject: [PATCH 33/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8D=95=E5=93=81=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 213cb88e..1b8fc5c1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1037,7 +1037,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { Integer mealNum = null; - if (cashierCarts.stream().noneMatch(item -> item.getPlaceNum() == null)) { + if (addMaterId && cashierCarts.stream().noneMatch(item -> item.getPlaceNum() == null)) { throw new BadRequestException("此次未添加新商品,清先添加商品"); } for (TbCashierCart cashierCart : cashierCarts) { From 7f0056304db2b89a36016df1956100e18bd80f0e Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 14:47:08 +0800 Subject: [PATCH 34/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95=E7=9B=B4=E6=8E=A5=E4=BB=98?= =?UTF-8?q?=E6=AC=BE=E4=B8=8D=E5=A2=9E=E5=8A=A0placeNum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 1b8fc5c1..42be90ec 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1101,7 +1101,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay"); orderInfo.setUserId(createOrderDTO.getVipUserId() == null ? null : String.valueOf(createOrderDTO.getVipUserId())); orderInfo.setCreatedAt(DateUtil.current()); - orderInfo.setPlaceNum(placeNum); + if (addMaterId) { + orderInfo.setPlaceNum(placeNum); + } orderInfoMapper.updateById(orderInfo); } else { String orderNo = generateOrderNumber(); From 7c00d0d9a01901f18679d6a005f9729d74f904bf Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 14:54:53 +0800 Subject: [PATCH 35/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95=E7=9B=B4=E6=8E=A5=E4=BB=98?= =?UTF-8?q?=E6=AC=BE=E4=B8=8D=E5=A2=9E=E5=8A=A0placeNum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/shopimpl/TbShopTableServiceImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 42be90ec..fc6d0f8b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1037,7 +1037,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { Integer mealNum = null; - if (addMaterId && cashierCarts.stream().noneMatch(item -> item.getPlaceNum() == null)) { + boolean unAdd = cashierCarts.stream().noneMatch(item -> item.getPlaceNum() == null); + if (addMaterId && unAdd) { throw new BadRequestException("此次未添加新商品,清先添加商品"); } for (TbCashierCart cashierCart : cashierCarts) { @@ -1101,7 +1102,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay"); orderInfo.setUserId(createOrderDTO.getVipUserId() == null ? null : String.valueOf(createOrderDTO.getVipUserId())); orderInfo.setCreatedAt(DateUtil.current()); - if (addMaterId) { + if (!unAdd) { orderInfo.setPlaceNum(placeNum); } orderInfoMapper.updateById(orderInfo); From ff27101e13209f9f4994349123ac79d6c8ec18cf Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 12 Sep 2024 16:58:35 +0800 Subject: [PATCH 36/56] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?orderDetail=E5=90=8C=E6=AD=A5=E4=BF=9D=E5=AD=98cartid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java | 3 +++ .../service/impl/shopimpl/TbShopTableServiceImpl.java | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java index 379db52a..794d1ad7 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderDetail.java @@ -116,6 +116,9 @@ public class TbOrderDetail implements Serializable { @Column(name = "`note`") private String note; + @Column(name = "`cart_id`") + private Integer cartId; + public void copy(TbOrderDetail source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index fc6d0f8b..883a05f7 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -547,12 +547,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { TbOrderDetail tbOrderDetail = orderDetailMapper.selectOne(new LambdaQueryWrapper() .eq(TbOrderDetail::getShopId, removeCartDTO.getShopId()) - .eq(TbOrderDetail::getPlaceNum, cashierCart.getPlaceNum()) + .eq(TbOrderDetail::getCartId, cashierCart.getId()) .eq(TbOrderDetail::getProductId, cashierCart.getProductId()) .eq(TbOrderDetail::getProductSkuId, cashierCart.getSkuId()) - .eq(TbOrderDetail::getPlaceNum, cashierCart.getPlaceNum()) - .eq(TbOrderDetail::getNum, cashierCart.getNumber()) - .in(TbOrderDetail::getStatus, "unpaid") .eq(TbOrderDetail::getOrderId, cashierCart.getOrderId())); if (tbOrderDetail == null) { throw new BadRequestException("购物车商品不存在或已退单"); @@ -1071,6 +1068,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderDetail.setPackAmount(cashierCart.getPackFee()); orderDetail.setStatus("unpaid"); orderDetail.setProductImg(cashierCart.getCoverImg()); + orderDetail.setCartId(cashierCart.getId()); orderDetails.add(orderDetail); if (cashierCart.getOrderId() != null) { orderId = cashierCart.getOrderId(); From b1e5ae969b0bd690669fcac04ca82d383aa71517 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 13 Sep 2024 10:24:12 +0800 Subject: [PATCH 37/56] =?UTF-8?q?1.=E5=8F=B0=E6=A1=8C=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=B2=BE=E7=A1=AE=E6=90=9C=E7=B4=A2=202.?= =?UTF-8?q?=E5=8F=B0=E6=A1=8C=E9=80=89=E6=8B=A9=E4=BA=BA=E6=95=B0=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E6=9C=80=E5=A4=A7=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysk/cashier/dto/shop/TbShopTableQueryCriteria.java | 5 ++++- .../service/impl/shopimpl/TbShopTableServiceImpl.java | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopTableQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopTableQueryCriteria.java index ce7a0f45..2b3de201 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopTableQueryCriteria.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopTableQueryCriteria.java @@ -36,4 +36,7 @@ public class TbShopTableQueryCriteria{ @Query private Integer areaId; -} \ No newline at end of file + + @Query + private Long qrcode; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 883a05f7..b571f2a2 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1594,6 +1594,15 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public Object choseCount(ChoseCountDTO choseCountDTO) { + TbShopTable shopTable = mpShopTableService.lambdaQuery().eq(TbShopTable::getQrcode, choseCountDTO.getTableId()).one(); + if (shopTable == null) { + throw new BadRequestException("台桌不存在"); + } + + if (shopTable.getMaxCapacity() < choseCountDTO.getNum()) { + throw new BadRequestException("当前台桌最大人数为: " + shopTable.getMaxCapacity()); + } + LambdaQueryWrapper query = new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, choseCountDTO.getShopId()) .eq(TbCashierCart::getMasterId, choseCountDTO.getMasterId()) From 62c28fe2f6c0671c0304d8397c04ab2438a36d88 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 13 Sep 2024 11:49:20 +0800 Subject: [PATCH 38/56] =?UTF-8?q?=E6=89=AB=E7=A0=81=E6=8E=92=E9=98=9F?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TbCallTableController.java | 106 +++++++ .../dto/calltable/UpdateCallQueueDTO.java | 15 + .../dto/calltable/UpdateCallTableDTO.java | 26 ++ .../cashier/mybatis/entity/TbCallQueue.java | 73 +++++ .../cashier/mybatis/entity/TbCallTable.java | 57 ++++ .../mybatis/mapper/TbCallQueueMapper.java | 18 ++ .../mybatis/mapper/TbCallTableMapper.java | 18 ++ .../mybatis/service/TbCallQueueService.java | 13 + .../mybatis/service/TbCallTableService.java | 13 + .../service/impl/TbCallQueueServiceImpl.java | 22 ++ .../service/impl/TbCallTableServiceImpl.java | 22 ++ .../cashier/service/app/TbCallService.java | 23 ++ .../service/impl/app/TbCallServiceImpl.java | 296 ++++++++++++++++++ .../cn/ysk/cashier/utils/WxMiniUtils.java | 103 ++++++ .../resources/mapper/TbCallQueueMapper.xml | 32 ++ .../resources/mapper/TbCallTableMapper.xml | 28 ++ 16 files changed, 865 insertions(+) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/controller/TbCallTableController.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/UpdateCallQueueDTO.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/UpdateCallTableDTO.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallQueue.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallTable.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallTableMapper.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbCallQueueService.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbCallTableService.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbCallQueueServiceImpl.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbCallTableServiceImpl.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/service/app/TbCallService.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java create mode 100644 eladmin-system/src/main/resources/mapper/TbCallQueueMapper.xml create mode 100644 eladmin-system/src/main/resources/mapper/TbCallTableMapper.xml diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbCallTableController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbCallTableController.java new file mode 100644 index 00000000..c11145b9 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbCallTableController.java @@ -0,0 +1,106 @@ +package cn.ysk.cashier.controller; + +import cn.ysk.cashier.annotation.AnonymousAccess; +import cn.ysk.cashier.dto.calltable.*; +import cn.ysk.cashier.exception.BadRequestException; +import cn.ysk.cashier.service.app.TbCallService; +import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; + +/** + * 叫号 + */ +@RestController +@RequestMapping("/callTable") +@AllArgsConstructor +public class TbCallTableController { + + private final TbCallService tbCallService; + + @AnonymousAccess + @GetMapping + public ResponseEntity get( + @RequestParam(required = false) Integer callTableId, + @RequestParam Integer shopId, + @RequestParam(defaultValue = "1") Integer page, + @RequestParam(defaultValue = "10") Integer size, + @RequestParam(required = false) Integer state + ) { + return ResponseEntity.ok(tbCallService.get(page, size, shopId, callTableId, state)); + } + + @AnonymousAccess + @PostMapping + public ResponseEntity add( + @Validated @RequestBody CallTableDTO addCallTableDTO + ) { + return ResponseEntity.ok(tbCallService.add(addCallTableDTO)); + } + + @AnonymousAccess + @PutMapping + public ResponseEntity update( + @Validated @RequestBody UpdateCallTableDTO callTableDTO + ) { + return ResponseEntity.ok(tbCallService.update(callTableDTO)); + } + + @AnonymousAccess + @DeleteMapping + public ResponseEntity delete( + @Validated @RequestBody BaseCallTableDTO baseCallTableDTO + ) { + return ResponseEntity.ok(tbCallService.delete(baseCallTableDTO)); + } + + @AnonymousAccess + @PostMapping("takeNumber") + public ResponseEntity takeNumber( + @Validated @RequestBody TakeNumberDTO takeNumberDTO + ) { + return ResponseEntity.ok(tbCallService.takeNumber(takeNumberDTO)); + } + + @AnonymousAccess + @GetMapping("takeNumberCode") + public ResponseEntity takeNumberCode( + @RequestParam Integer shopId, + @RequestParam Integer callTableId + ) { + return ResponseEntity.ok(tbCallService.takeNumberCode(shopId, callTableId)); + } + + @AnonymousAccess + @PostMapping("call") + public ResponseEntity call( + @Validated @RequestBody CallQueueDTO callQueueDTO + ) { + return ResponseEntity.ok(tbCallService.call(callQueueDTO)); + } + + @AnonymousAccess + @PutMapping("updateState") + public ResponseEntity confirm( + @Validated @RequestBody UpdateCallQueueDTO updateCallQueueDTO + ) { + return ResponseEntity.ok(tbCallService.updateInfo(updateCallQueueDTO)); + } + + @AnonymousAccess + @GetMapping("queue") + public ResponseEntity getQueue( + @RequestParam Integer shopId, + @RequestParam(required = false) Integer callTableId, + @RequestParam(required = false) Integer state, + @RequestParam(defaultValue = "1") Integer page, + @RequestParam(defaultValue = "10") Integer size + ) { + return ResponseEntity.ok(tbCallService.getQueue(shopId, callTableId, state, page, size)); + } + + +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/UpdateCallQueueDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/UpdateCallQueueDTO.java new file mode 100644 index 00000000..6d0fc12b --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/UpdateCallQueueDTO.java @@ -0,0 +1,15 @@ +package cn.ysk.cashier.dto.calltable; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +import javax.validation.constraints.NotNull; + +@EqualsAndHashCode(callSuper = true) +@Data +@Getter +public class UpdateCallQueueDTO extends CallQueueDTO{ + @NotNull + private Byte state; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/UpdateCallTableDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/UpdateCallTableDTO.java new file mode 100644 index 00000000..f45d8c4e --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/UpdateCallTableDTO.java @@ -0,0 +1,26 @@ +package cn.ysk.cashier.dto.calltable; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Data +public class UpdateCallTableDTO{ + @NotNull + private Integer callTableId; + @NotNull + private Integer shopId; + private String name; + private String note; + @Min(1) + private Integer waitTime; + private String prefix; + @Min(1) + private Integer start; + @Min(1) + private Integer nearNum; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallQueue.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallQueue.java new file mode 100644 index 00000000..45b9d55a --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallQueue.java @@ -0,0 +1,73 @@ +package cn.ysk.cashier.mybatis.entity; + +import lombok.Getter; +import lombok.Setter; + +import javax.persistence.*; +import javax.validation.constraints.Size; +import java.time.Instant; + +@Getter +@Setter +@Entity +@Table(name = "tb_call_queue") +public class TbCallQueue { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Integer id; + + @Column(name = "call_table_id") + private Integer callTableId; + + @Size(max = 255) + @Column(name = "phone") + private String phone; + + @Size(max = 255) + @Column(name = "name") + private String name; + + @Size(max = 255) + @Column(name = "shop_name") + private String shopName; + + @Column(name = "shop_id") + private Integer shopId; + + @Column(name = "state") + private Byte state; + + @Column(name = "create_time") + private Instant createTime; + + @Column(name = "call_time") + private Instant callTime; + + @Column(name = "call_count") + private Integer callCount; + + @Column(name = "pass_time") + private Instant passTime; + + @Column(name = "cancel_time") + private Instant cancelTime; + + @Column(name = "confirm_time") + private Instant confirmTime; + + @Size(max = 255) + @Column(name = "note") + private String note; + + @Column(name = "user_id") + private Integer userId; + + @Size(max = 255) + @Column(name = "open_id") + private String openId; + + @Column(name = "sub_state") + private Integer subState; + +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallTable.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallTable.java new file mode 100644 index 00000000..a2b76690 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallTable.java @@ -0,0 +1,57 @@ +package cn.ysk.cashier.mybatis.entity; + +import lombok.Getter; +import lombok.Setter; + +import javax.persistence.*; +import javax.validation.constraints.Size; +import java.time.Instant; + +@Getter +@Setter +@Entity +@Table(name = "tb_call_table") +public class TbCallTable { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Integer id; + + @Size(max = 255) + @Column(name = "name") + private String name; + + @Size(max = 255) + @Column(name = "note") + private String note; + + @Column(name = "wait_time") + private Integer waitTime; + + @Size(max = 255) + @Column(name = "prefix") + private String prefix; + + @Column(name = "start") + private Integer start; + + @Column(name = "near_num") + private Integer nearNum; + + @Column(name = "state") + private Byte state; + + @Column(name = "shop_id") + private Integer shopId; + + @Size(max = 255) + @Column(name = "qrcode") + private String qrcode; + + @Column(name = "create_time") + private Instant createTime; + + @Column(name = "update_time") + private Instant updateTime; + +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java new file mode 100644 index 00000000..2cbb80a3 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java @@ -0,0 +1,18 @@ +package cn.ysk.cashier.mybatis.mapper; + +import cn.ysk.cashier.mybatis.entity.TbCallQueue; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author Administrator +* @description 针对表【tb_call_queue】的数据库操作Mapper +* @createDate 2024-09-12 15:34:30 +* @Entity cn.ysk.cashier.mybatis.entity.TbCallQueue +*/ +public interface TbCallQueueMapper extends BaseMapper { + +} + + + + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallTableMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallTableMapper.java new file mode 100644 index 00000000..038abe1d --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallTableMapper.java @@ -0,0 +1,18 @@ +package cn.ysk.cashier.mybatis.mapper; + +import cn.ysk.cashier.mybatis.entity.TbCallTable; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author Administrator +* @description 针对表【tb_call_table】的数据库操作Mapper +* @createDate 2024-09-12 15:07:15 +* @Entity cn.ysk.cashier.mybatis.entity.TbCallTable +*/ +public interface TbCallTableMapper extends BaseMapper { + +} + + + + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbCallQueueService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbCallQueueService.java new file mode 100644 index 00000000..6ef47753 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbCallQueueService.java @@ -0,0 +1,13 @@ +package cn.ysk.cashier.mybatis.service; + +import cn.ysk.cashier.mybatis.entity.TbCallQueue; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author Administrator +* @description 针对表【tb_call_queue】的数据库操作Service +* @createDate 2024-09-12 15:34:30 +*/ +public interface TbCallQueueService extends IService { + +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbCallTableService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbCallTableService.java new file mode 100644 index 00000000..b329b6fa --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbCallTableService.java @@ -0,0 +1,13 @@ +package cn.ysk.cashier.mybatis.service; + +import cn.ysk.cashier.mybatis.entity.TbCallTable; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author Administrator +* @description 针对表【tb_call_table】的数据库操作Service +* @createDate 2024-09-12 15:07:15 +*/ +public interface TbCallTableService extends IService { + +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbCallQueueServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbCallQueueServiceImpl.java new file mode 100644 index 00000000..1906dfc9 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbCallQueueServiceImpl.java @@ -0,0 +1,22 @@ +package cn.ysk.cashier.mybatis.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import cn.ysk.cashier.mybatis.entity.TbCallQueue; +import cn.ysk.cashier.mybatis.service.TbCallQueueService; +import cn.ysk.cashier.mybatis.mapper.TbCallQueueMapper; +import org.springframework.stereotype.Service; + +/** +* @author Administrator +* @description 针对表【tb_call_queue】的数据库操作Service实现 +* @createDate 2024-09-12 15:34:30 +*/ +@Service +public class TbCallQueueServiceImpl extends ServiceImpl + implements TbCallQueueService{ + +} + + + + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbCallTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbCallTableServiceImpl.java new file mode 100644 index 00000000..ee129a24 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbCallTableServiceImpl.java @@ -0,0 +1,22 @@ +package cn.ysk.cashier.mybatis.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import cn.ysk.cashier.mybatis.entity.TbCallTable; +import cn.ysk.cashier.mybatis.service.TbCallTableService; +import cn.ysk.cashier.mybatis.mapper.TbCallTableMapper; +import org.springframework.stereotype.Service; + +/** +* @author Administrator +* @description 针对表【tb_call_table】的数据库操作Service实现 +* @createDate 2024-09-12 15:07:15 +*/ +@Service +public class TbCallTableServiceImpl extends ServiceImpl + implements TbCallTableService{ + +} + + + + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/app/TbCallService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/app/TbCallService.java new file mode 100644 index 00000000..2ae4d905 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/app/TbCallService.java @@ -0,0 +1,23 @@ +package cn.ysk.cashier.service.app; + +import cn.ysk.cashier.dto.calltable.*; + +public interface TbCallService { + Object add(CallTableDTO addCallTableDTO); + + Object update(UpdateCallTableDTO callTableDTO); + + Object delete(BaseCallTableDTO baseCallTableDTO); + + Object takeNumber(TakeNumberDTO takeNumber); + + Object call(CallQueueDTO callQueueDTO); + + Object updateInfo(UpdateCallQueueDTO updateCallQueueDTO); + + Object get(Integer page, Integer size, Integer shopId, Integer callTableId, Integer state); + + Object takeNumberCode(Integer shopId, Integer callTableId); + + Object getQueue(Integer shopId, Integer callTableId, Integer state, Integer page, Integer size); +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java new file mode 100644 index 00000000..d43e0cfc --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java @@ -0,0 +1,296 @@ +package cn.ysk.cashier.service.impl.app; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.qrcode.QrCodeUtil; +import cn.hutool.extra.qrcode.QrConfig; +import cn.ysk.cashier.dto.calltable.*; +import cn.ysk.cashier.exception.BadRequestException; +import cn.ysk.cashier.mybatis.entity.TbCallQueue; +import cn.ysk.cashier.mybatis.entity.TbCallTable; +import cn.ysk.cashier.mybatis.mapper.TbShopUserMapper; +import cn.ysk.cashier.mybatis.service.TbCallQueueService; +import cn.ysk.cashier.mybatis.service.TbCallTableService; +import cn.ysk.cashier.pojo.shop.TbShopInfo; +import cn.ysk.cashier.pojo.shop.TbShopUser; +import cn.ysk.cashier.repository.shop.TbShopInfoRepository; +import cn.ysk.cashier.service.app.TbCallService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.io.ByteArrayOutputStream; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@AllArgsConstructor +public class TbCallServiceImpl implements TbCallService { + + private final TbCallTableService callTableService; + private final TbCallQueueService callQueueService; + private final TbShopUserMapper shopUserMapper; + private final TbShopInfoRepository shopInfoRepository; + + @Override + public Object add(CallTableDTO addCallTableDTO) { + Long count = callTableService.lambdaQuery() + .eq(TbCallTable::getShopId, addCallTableDTO.getShopId()) + .and(q -> { + q.eq(TbCallTable::getName, addCallTableDTO.getName()) + .or() + .eq(TbCallTable::getPrefix, addCallTableDTO.getPrefix()); + }).count(); + if (count > 0) { + throw new BadRequestException("名称或前缀已存在"); + } + + TbCallTable callTable = BeanUtil.copyProperties(addCallTableDTO, TbCallTable.class); + callTable.setCreateTime(DateUtil.date().toInstant()); + return callTableService.save(callTable); + } + + @Override + public Object update(UpdateCallTableDTO callTableDTO) { + TbCallTable callTable = callTableService.lambdaQuery() + .eq(TbCallTable::getShopId, callTableDTO.getShopId()) + .eq(TbCallTable::getId, callTableDTO.getCallTableId()).one(); + + if (callTable == null) { + throw new BadRequestException("桌型不存在"); + } + TbCallTable newInfo = BeanUtil.copyProperties(callTableDTO, TbCallTable.class); + newInfo.setId(callTable.getId()); + newInfo.setUpdateTime(DateUtil.date().toInstant()); + + return callTableService.updateById(newInfo); + } + + @Override + public Object delete(BaseCallTableDTO baseCallTableDTO) { + return callTableService.remove(new LambdaQueryWrapper() + .eq(TbCallTable::getId, baseCallTableDTO.getCallTableId()) + .eq(TbCallTable::getShopId, baseCallTableDTO.getShopId())); + } + + @Override + public Object takeNumber(TakeNumberDTO takeNumberDTO) { + TbShopInfo shopInfo = shopInfoRepository.findById(takeNumberDTO.getShopId()).orElse(null); + if (shopInfo == null) { + throw new BadRequestException("店铺信息不存在"); + } + + TbCallTable callTable = callTableService.lambdaQuery() + .eq(TbCallTable::getShopId, takeNumberDTO.getShopId()) + .eq(TbCallTable::getId, takeNumberDTO.getCallTableId()).one(); + if (callTable == null) { + throw new BadRequestException("桌型不存在"); + } + + // 拿取系统内部用户信息 + TbCallQueue callQueue; + if (takeNumberDTO.getUserId() != null) { + TbShopUser shopUser = shopUserMapper.selectOne(new LambdaQueryWrapper() + .eq(TbShopUser::getStatus, 1) + .eq(TbShopUser::getShopId, takeNumberDTO.getShopId()) + .eq(TbShopUser::getId, takeNumberDTO.getUserId())); + if (shopUser == null) { + throw new BadRequestException("用户不存在"); + } + + callQueue = callQueueService.lambdaQuery() + .eq(TbCallQueue::getUserId, shopUser.getId()) + .eq(TbCallQueue::getShopId, takeNumberDTO.getShopId()) + .eq(TbCallQueue::getCallTableId, takeNumberDTO.getCallTableId()).one(); + if (callQueue != null) { + throw new BadRequestException("当前用户已取号"); + } + + callQueue = BeanUtil.copyProperties(takeNumberDTO, TbCallQueue.class); + callQueue.setPhone(StrUtil.isBlank(takeNumberDTO.getPhone()) ? shopUser.getTelephone() : takeNumberDTO.getPhone()); + +// callQueue.setOpenId(shopUser.getMiniOpenId()); + + }else { +// if (StrUtil.isBlank(takeNumberDTO.getPhone()) || StrUtil.isBlank(takeNumberDTO.getOpenId())) { +// throw new BadRequestException("手机号或openId不能为空"); +// } + + callQueue = callQueueService.lambdaQuery() + .eq(TbCallQueue::getPhone, takeNumberDTO.getPhone()) + .eq(TbCallQueue::getShopId, takeNumberDTO.getShopId()) + .eq(TbCallQueue::getCallTableId, takeNumberDTO.getCallTableId()).one(); + if (callQueue != null) { + throw new BadRequestException("当前用户已取号"); + } + + callQueue = BeanUtil.copyProperties(takeNumberDTO, TbCallQueue.class); + callQueue.setPhone(takeNumberDTO.getPhone()); +// callQueue.setOpenId(takeNumberDTO.getOpenId()); + callQueue.setSubState(1); + } + + callQueue.setCreateTime(DateUtil.date().toInstant()); + callQueue.setShopId(shopInfo.getId()); + callQueue.setShopName(shopInfo.getShopName()); + + return callQueueService.save(callQueue); + } + + @Override + public Object call(CallQueueDTO callQueueDTO) { + TbCallQueue callQueue = callQueueService.lambdaQuery() + .notIn(TbCallQueue::getState, -1, 2) + .eq(TbCallQueue::getShopId, callQueueDTO.getShopId()) + .one(); + + if (callQueue == null) { + throw new BadRequestException("叫号用户不存在"); + } + + if (callQueue.getSubState().equals(0)) { + throw new BadRequestException("当前用户未订阅微信提醒"); + } + + callQueue.setState((byte) 1); + callQueue.setCallCount(callQueue.getCallCount() + 1); + callQueue.setCallTime(DateUtil.date().toInstant()); + + // 发送模板消息通知用户 + + return callQueueService.updateById(callQueue); + } + + @Override + public Object updateInfo(UpdateCallQueueDTO updateCallQueueDTO) { + TbCallQueue callQueue = callQueueService.lambdaQuery() + .eq(TbCallQueue::getShopId, updateCallQueueDTO.getShopId()) + .eq(TbCallQueue::getId, updateCallQueueDTO.getCallQueueId()).one(); + if (callQueue == null) { + throw new BadRequestException("叫号用户不存在"); + } + + switch (updateCallQueueDTO.getState()) { + case -1: + callQueue.setCancelTime(DateUtil.date().toInstant()); + break; + case 0: + if (callQueue.getSubState().equals(0)) { + throw new BadRequestException("当前用户未订阅微信提醒"); + } + + callQueue.setState((byte) 1); + callQueue.setCallCount(callQueue.getCallCount() + 1); + callQueue.setCallTime(DateUtil.date().toInstant()); + break; + case 2: + callQueue.setConfirmTime(DateUtil.date().toInstant()); + break; + case 3: + callQueue.setPassTime(DateUtil.date().toInstant()); + break; + default: + throw new BadRequestException("错误类型"); + + } + + callQueue.setState(updateCallQueueDTO.getState()); + + return callQueueService.updateById(callQueue); + } + + @Override + public Object get(Integer page, Integer size, Integer shopId, Integer callTableId, Integer state) { + LambdaQueryWrapper query = new LambdaQueryWrapper() + .eq(TbCallTable::getShopId, shopId) + .eq(TbCallTable::getState, 1); + + if (callTableId != null) { + query.eq(TbCallTable::getId, callTableId); + } + + if (state != null) { + query.eq(TbCallTable::getState, state); + } + return callTableService.page(new Page<>(page, size), query); + } + + @Override + public Object takeNumberCode(Integer shopId, Integer callTableId) { + // 创建二维码配置对象,设置宽度和高度为400 + QrConfig config = new QrConfig(400, 400); + + // 使用字节数组输出流来存储二维码图片 + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + + // 生成二维码图片,输出到字节数组输出流 + QrCodeUtil.generate("Your QR Code Content Here", config, "png", outputStream); + + // 将图片转换为 Base64 字符串 + String base64 = Base64.getEncoder().encodeToString(outputStream.toByteArray()); + + // 返回Base64格式的图片字符串 + return "data:image/png;base64," + base64; + } + + @Override + public Object getQueue(Integer shopId, Integer callTableId, Integer state, Integer page, Integer size) { + List tableIds; + if (callTableId != null) { + tableIds = Collections.singletonList(callTableId); + }else { + List list = callTableService.lambdaQuery() + .eq(TbCallTable::getShopId, shopId) + .eq(TbCallTable::getState, 1).list(); + if (list.isEmpty()) { + return new Page<>(); + } + tableIds = list.stream() + .map(TbCallTable::getId) + .collect(Collectors.toList()); + } + + LambdaQueryChainWrapper query = callQueueService.lambdaQuery() + .eq(TbCallQueue::getShopId, shopId) + .in(TbCallQueue::getCallTableId, tableIds); + if (state != null) { + query.eq(TbCallQueue::getState, state); + } + Page pageInfo = query + .orderByAsc(TbCallQueue::getCreateTime) + .orderByDesc(TbCallQueue::getState) + .page(new Page<>(page, size)); + + List list1 = pageInfo.getRecords(); + + // 创建返回的结果集 + List> resultList = new ArrayList<>(); + + // 遍历每一个叫号中的记录,计算前面状态为"0" (排队中) 的人数 + for (TbCallQueue calling : list1) { + // 计算前面等待的人数 (状态为"0"且在叫号记录创建时间之前的) + long waitingCount = 0; + if (calling.getState() == 0) { + waitingCount = list1.stream() + .filter(item -> item.getState() == 0 || item.getState() == 1) // 过滤出状态为"排队中"的 + .filter(item -> item.getCreateTime().compareTo(calling.getCreateTime()) < 0 ) // 时间在当前叫号之前 + .count(); + } + + // 创建一个Map来保存叫号中的记录及其前面排队的人数 + Map map = BeanUtil.beanToMap(calling, false, false); + map.put("waitingCount", waitingCount); + // 将该map加入结果集 + resultList.add(map); + } + + Map toMap = BeanUtil.beanToMap(pageInfo, false, false); + toMap.put("records", resultList); + + // 返回结果列表 + return toMap; + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java new file mode 100644 index 00000000..f01cae4c --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java @@ -0,0 +1,103 @@ +package cn.ysk.cashier.utils; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +@Component +public class WxMiniUtils { + +// @Value("${wx.msg.appId}") +// private String appId; +// +// @Value("${wx.msg.secrete}") +// private String secrete; +// +// @Value("${wx.msg.warnMsgTmpId}") +// private String msgTmpId; +// +// static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); +// +// static { +// +// linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); +// linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); +// linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); +// linkedHashMap.put("40037","不合法的 template_id"); +// linkedHashMap.put("43101","用户未订阅消息"); +// linkedHashMap.put("43107","订阅消息能力封禁"); +// linkedHashMap.put("43108","并发下发消息给同一个粉丝"); +// linkedHashMap.put("45168","命中敏感词"); +// linkedHashMap.put("47003","参数错误"); +// +// } +// +// public JSONObject getAccessToken(){ +// String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; +// Map requestUrlParam = new HashMap<>(); +// //小程序appId +// requestUrlParam.put("appid", appId); +// //小程序secret +// requestUrlParam.put("secret", secrete); +// //默认参数 +// requestUrlParam.put("grant_type", "client_credential"); +// JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doGet(requestUrl,requestUrlParam)); +// return jsonObject; +// } +// +// public static void main(String[] args) { +// String id ="kSxJL9TR4s_UmOmNLE"; +//// sendStockWarnMsg("123", "1231", "1231", "23321", id); +// } +// +// public JSONObject sendStockWarnMsg(String shopName, String productName, String stock, String note, String toUserOpenId) { +// Map data = new HashMap() {{ +// put("thing1", new HashMap(){{ +// put("value", shopName); +// }}); +// put("thing6", new HashMap(){{ +// put("value", productName); +// }}); +// put("number7", new HashMap(){{ +// put("value", stock); +// }}); +// put("thing5", new HashMap(){{ +// put("value", note); +// }}); +// }}; +// log.info("开始发送库存预警消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); +// return sendTempMsg(msgTmpId, toUserOpenId, data); +// } +// +// +// public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { +// log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); +// JSONObject object= getAccessToken(); +// String accessToken=object.get("access_token")+""; +// +// JSONObject object1=new JSONObject(); +// +// object1.put("template_id", tempId); +// object1.put("touser", toUserOpenId); +// object1.put("data",data); +// +// object1.put("miniprogram_state","trial"); +// object1.put("lang","zh_CN"); +// +// String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); +// log.info("微信模板消息发送成功,相应内容:{}",response); +// JSONObject resObj=JSONObject.parseObject(response); +// if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ +// return resObj; +// } +// +// throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); +// } +} diff --git a/eladmin-system/src/main/resources/mapper/TbCallQueueMapper.xml b/eladmin-system/src/main/resources/mapper/TbCallQueueMapper.xml new file mode 100644 index 00000000..cac92993 --- /dev/null +++ b/eladmin-system/src/main/resources/mapper/TbCallQueueMapper.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + id,call_table_id,phone, + name,shop_name,shop_id, + state,create_time,call_time, + call_count,pass_time,cancel_time, + note,user_id,open_id + + diff --git a/eladmin-system/src/main/resources/mapper/TbCallTableMapper.xml b/eladmin-system/src/main/resources/mapper/TbCallTableMapper.xml new file mode 100644 index 00000000..003abc47 --- /dev/null +++ b/eladmin-system/src/main/resources/mapper/TbCallTableMapper.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + id,name,note, + wait_time,prefix,start, + near_num,state,shop_id, + qrcode,create_time,update_time + + From 69053261e01970236231ed5a78a031d456b6ba94 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 13 Sep 2024 11:49:51 +0800 Subject: [PATCH 39/56] =?UTF-8?q?=E6=89=AB=E7=A0=81=E6=8E=92=E9=98=9F?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/calltable/BaseCallTableDTO.java | 13 +++++++++ .../cashier/dto/calltable/CallQueueDTO.java | 13 +++++++++ .../cashier/dto/calltable/CallTableDTO.java | 27 +++++++++++++++++++ .../cashier/dto/calltable/TakeNumberDTO.java | 15 +++++++++++ 4 files changed, 68 insertions(+) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/BaseCallTableDTO.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/CallQueueDTO.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/CallTableDTO.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/TakeNumberDTO.java diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/BaseCallTableDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/BaseCallTableDTO.java new file mode 100644 index 00000000..6d79ea24 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/BaseCallTableDTO.java @@ -0,0 +1,13 @@ +package cn.ysk.cashier.dto.calltable; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +public class BaseCallTableDTO { + @NotNull + private Integer callTableId; + @NotNull + private Integer shopId; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/CallQueueDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/CallQueueDTO.java new file mode 100644 index 00000000..37d26627 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/CallQueueDTO.java @@ -0,0 +1,13 @@ +package cn.ysk.cashier.dto.calltable; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +public class CallQueueDTO{ + @NotNull + private Integer callQueueId; + @NotNull + private Integer shopId; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/CallTableDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/CallTableDTO.java new file mode 100644 index 00000000..92448269 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/CallTableDTO.java @@ -0,0 +1,27 @@ +package cn.ysk.cashier.dto.calltable; + +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Data +public class CallTableDTO { + @NotNull + private Integer shopId; + @NotEmpty + private String name; + private String note; + @NotNull + @Min(1) + private Integer waitTime; + @NotBlank + private String prefix; + @NotNull + @Min(1) + private Integer start; + @Min(1) + private Integer nearNum; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/TakeNumberDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/TakeNumberDTO.java new file mode 100644 index 00000000..7d774145 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/calltable/TakeNumberDTO.java @@ -0,0 +1,15 @@ +package cn.ysk.cashier.dto.calltable; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotNull; + +@EqualsAndHashCode(callSuper = true) +@Data +public class TakeNumberDTO extends BaseCallTableDTO{ + private Integer userId; + private String phone; + private String note; + private String name; +} From 5e8601745b360346d13f2d9b226df5eadf00bd73 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 13 Sep 2024 15:13:39 +0800 Subject: [PATCH 40/56] =?UTF-8?q?=E5=AE=A2=E5=BA=A7=E8=B4=B9=E4=BF=AE?= =?UTF-8?q?=E6=94=B9fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index b571f2a2..0b0321dd 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1608,6 +1608,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { .eq(TbCashierCart::getMasterId, choseCountDTO.getMasterId()) .eq(TbCashierCart::getProductId, "-999") .eq(TbCashierCart::getSkuId, "-999") + .eq(TbCashierCart::getTradeDay, cn.ysk.cashier.utils.DateUtils.getDay()) .eq(TbCashierCart::getTableId, choseCountDTO.getTableId()); TbCashierCart tbCashierCart = cashierCartMapper.selectOne(query); From a73530df84cb7273c5aab8553350564466e52134 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 13 Sep 2024 15:14:03 +0800 Subject: [PATCH 41/56] =?UTF-8?q?=E6=8E=92=E9=98=9F=E5=8F=96=E5=8F=B7?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=8F=B7=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/cons/RedisConstant.java | 6 +++ .../cashier/mybatis/entity/TbCallQueue.java | 3 ++ .../service/impl/app/TbCallServiceImpl.java | 37 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/RedisConstant.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/RedisConstant.java index f36e3cf8..9a6eb659 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/RedisConstant.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/RedisConstant.java @@ -21,6 +21,8 @@ public interface RedisConstant { String LOCK_KEY = "LOCK:"; String CREATE_ORDER = "CREATE_ORDER"; + // 排队取号全局号码 + String TABLE_CALL_NUMBER = "TABLE_CALL_NUMBER:"; static String getCurrentOrderKey(String tableId, String shopId) { return CURRENT_TABLE_ORDER + shopId + ":" + tableId; @@ -37,4 +39,8 @@ public interface RedisConstant { } return key.toString(); } + + static String getTableCallNumKey(Integer shopId, Integer callTableId) { + return TABLE_CALL_NUMBER + shopId + ":" + callTableId; + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallQueue.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallQueue.java index 45b9d55a..7482973d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallQueue.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbCallQueue.java @@ -70,4 +70,7 @@ public class TbCallQueue { @Column(name = "sub_state") private Integer subState; + @Column(name = "call_num") + private String callNum; + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java index d43e0cfc..e585e07a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrConfig; +import cn.ysk.cashier.cons.RedisConstant; import cn.ysk.cashier.dto.calltable.*; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.entity.TbCallQueue; @@ -16,14 +17,17 @@ import cn.ysk.cashier.pojo.shop.TbShopInfo; import cn.ysk.cashier.pojo.shop.TbShopUser; import cn.ysk.cashier.repository.shop.TbShopInfoRepository; import cn.ysk.cashier.service.app.TbCallService; +import cn.ysk.cashier.utils.Utils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.AllArgsConstructor; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.io.ByteArrayOutputStream; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @Service @@ -34,6 +38,7 @@ public class TbCallServiceImpl implements TbCallService { private final TbCallQueueService callQueueService; private final TbShopUserMapper shopUserMapper; private final TbShopInfoRepository shopInfoRepository; + private final StringRedisTemplate redisTemplate; @Override public Object add(CallTableDTO addCallTableDTO) { @@ -76,6 +81,35 @@ public class TbCallServiceImpl implements TbCallService { .eq(TbCallTable::getShopId, baseCallTableDTO.getShopId())); } + private String getCallNumber(Integer shopId, TbCallTable callTable) { + return Utils.runFunAndCheckKey(() -> { + String callNumKey = RedisConstant.getTableCallNumKey(shopId, callTable.getId()); + String value = redisTemplate.opsForValue().get(callNumKey); + AtomicReference newVal = new AtomicReference<>(""); + // 初始化 + if (StrUtil.isBlank(value)) { + Boolean setFlag = Utils.runFunAndRetry(() -> redisTemplate.opsForValue().setIfAbsent(callNumKey, callTable.getStart().toString()), flag -> !flag, + r -> newVal.set(redisTemplate.opsForValue().get(callNumKey))); + + if (setFlag) { + return callTable.getPrefix() + callTable.getStart(); + }else if (StrUtil.isNotBlank(newVal.get())){ + value = String.valueOf((Integer.parseInt(newVal.get()) + 1)); + redisTemplate.opsForValue().set(callNumKey, value); + return callTable.getPrefix() + value; + }else { + throw new BadRequestException("生成排队号码失败"); + } + + }else { + value = String.valueOf((Integer.parseInt(value) + 1)); + redisTemplate.opsForValue().set(callNumKey, value); + return callTable.getPrefix() + value; + } + }, redisTemplate, RedisConstant.getLockKey("UPDATE_TABLE", shopId, callTable.getId())); + + } + @Override public Object takeNumber(TakeNumberDTO takeNumberDTO) { TbShopInfo shopInfo = shopInfoRepository.findById(takeNumberDTO.getShopId()).orElse(null); @@ -90,6 +124,8 @@ public class TbCallServiceImpl implements TbCallService { throw new BadRequestException("桌型不存在"); } + // 查询当前 + // 拿取系统内部用户信息 TbCallQueue callQueue; if (takeNumberDTO.getUserId() != null) { @@ -133,6 +169,7 @@ public class TbCallServiceImpl implements TbCallService { callQueue.setSubState(1); } + callQueue.setCallNum(getCallNumber(takeNumberDTO.getShopId(), callTable)); callQueue.setCreateTime(DateUtil.date().toInstant()); callQueue.setShopId(shopInfo.getId()); callQueue.setShopName(shopInfo.getShopName()); From 67af4f14638e77bf2a960474409902d24c264c19 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 13 Sep 2024 15:24:11 +0800 Subject: [PATCH 42/56] =?UTF-8?q?=E6=8E=92=E9=98=9F=E5=8F=96=E5=8F=B7?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=8F=B7=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java index e585e07a..68629d57 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java @@ -140,6 +140,7 @@ public class TbCallServiceImpl implements TbCallService { callQueue = callQueueService.lambdaQuery() .eq(TbCallQueue::getUserId, shopUser.getId()) .eq(TbCallQueue::getShopId, takeNumberDTO.getShopId()) + .in(TbCallQueue::getState, 0, 1) .eq(TbCallQueue::getCallTableId, takeNumberDTO.getCallTableId()).one(); if (callQueue != null) { throw new BadRequestException("当前用户已取号"); From 78ed984ef8aacd4eb2a52660eefff56a3ed7ad18 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 13 Sep 2024 15:45:14 +0800 Subject: [PATCH 43/56] =?UTF-8?q?=E5=8F=B0=E6=A1=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=B8=85=E9=99=A4=E7=94=A8=E9=A4=90=E4=BA=BA?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 0b0321dd..6679fc18 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -233,6 +233,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { TbShopTable tbShopTable = tbShopTableRepository.findById(resources.getId()).orElseGet(TbShopTable::new); ValidationUtil.isNull(tbShopTable.getId(), "TbShopTable", "id", resources.getId()); tbShopTable.copy(resources); + if ("idle".equals(resources.getStatus())) { + tbShopTable.setUseNum(0); + } tbShopTableRepository.save(tbShopTable); } @@ -1461,6 +1464,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { mpShopTableMapper.update(null, new LambdaUpdateWrapper() .eq(TbShopTable::getQrcode, orderInfo.getTableId()) .set(TbShopTable::getEndTime, DateUtil.date()) + .set(TbShopTable::getUseNum, 0) .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState())); } else { mpShopTableMapper.update(null, new LambdaUpdateWrapper() From 116852ce307ad5fed43c202a6fd04b78116d0830 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 14 Sep 2024 09:14:19 +0800 Subject: [PATCH 44/56] =?UTF-8?q?=E5=BA=97=E9=93=BA=E5=8F=82=E6=95=B0=20?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/rest/StorageController.java | 57 ++----------- .../cn/ysk/cashier/service/WxService.java | 10 +++ .../cashier/service/impl/WxServiceImpl.java | 80 +++++++++++++++++++ .../impl/shopimpl/TbShopInfoServiceImpl.java | 7 ++ 4 files changed, 105 insertions(+), 49 deletions(-) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/service/WxService.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/service/impl/WxServiceImpl.java diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/rest/StorageController.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/rest/StorageController.java index d42421ca..09d2d775 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/rest/StorageController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/rest/StorageController.java @@ -1,29 +1,22 @@ package cn.ysk.cashier.mybatis.rest; -import cn.hutool.core.io.IoUtil; -import cn.hutool.http.HttpUtil; import cn.ysk.cashier.annotation.Log; -import cn.ysk.cashier.domain.QiniuContent; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.entity.Activate; import cn.ysk.cashier.mybatis.service.ShopService; -import cn.ysk.cashier.service.QiNiuService; +import cn.ysk.cashier.service.WxService; import cn.ysk.cashier.utils.CacheKey; import cn.ysk.cashier.utils.RedisUtils; import cn.ysk.cashier.utils.SecurityUtils; -import com.alibaba.fastjson.JSONObject; -import com.google.gson.JsonObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.io.InputStream; import java.util.Map; @Slf4j @@ -32,15 +25,9 @@ import java.util.Map; @Api(tags = "/shop/storage") @RequestMapping("/shop/storage") public class StorageController { - @Autowired - private ShopService shopService; + private final ShopService shopService; private final RedisUtils redisUtils; - - private final QiNiuService qiNiuService; - private static final String APP_ID = "wxd88fffa983758a30"; - private static final String APP_SECRET = "a34a61adc0602118b49400baa8812454"; - private static final String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token"; - private static final String QR_CODE_URL = "https://api.weixin.qq.com/wxa/getwxacode"; + private final WxService wxService; @GetMapping("/findActivate") public ResponseEntity findActivate(@RequestParam String shopId){ @@ -72,38 +59,10 @@ public class StorageController { */ @PostMapping("/getwxacode") public ResponseEntity getwxacode(@RequestBody Map params) { - if (CollectionUtils.isEmpty(params) || !params.containsKey("shopId")) throw new BadRequestException("参数错误"); - if (redisUtils.hasKey(CacheKey.VIPCODE + params.get("shopId"))) return new ResponseEntity<>(redisUtils.get(CacheKey.VIPCODE + params.get("shopId")),HttpStatus.OK); - try { - InputStream qrCodeStream = fetchQRCode(params); - QiniuContent qiniuContent = qiNiuService.uploadByte(IoUtil.readBytes(qrCodeStream),qiNiuService.findCloud()); - redisUtils.set(CacheKey.VIPCODE + params.get("shopId"),qiniuContent.getUrl()); - return new ResponseEntity<>(qiniuContent.getUrl(),HttpStatus.OK); - } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body("Failed to generate QR code: " + e.getMessage()); - } - } - - private String getAccessToken() { - String url = String.format("%s?grant_type=client_credential&appid=%s&secret=%s", TOKEN_URL, APP_ID, APP_SECRET); - String response = HttpUtil.get(url); - JSONObject jsonResponse = JSONObject.parseObject(response); - if (!jsonResponse.containsKey("access_token")) { - throw new RuntimeException("Failed to retrieve access token: " + response); - } - return jsonResponse.getString("access_token"); - } - private InputStream fetchQRCode(Map params) { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("path", "pages/member/index?shopId="+params.get("shopId"));//路径 - jsonObject.addProperty("is_hyaline", true);//是否需要透明底色,为 true 时,生成透明底色的小程序码 - if (params.containsKey("env_version")) jsonObject.addProperty("env_version", "trial");//正式版为 release,体验版为 trial,开发版为 develop - String accessToken = getAccessToken(); - String url = String.format("%s?access_token=%s", QR_CODE_URL, accessToken); - return HttpUtil.createPost(url) - .body(jsonObject.toString(), "application/json") - .execute() - .bodyStream(); + if (CollectionUtils.isEmpty(params) || !params.containsKey("shopId")) + throw new BadRequestException("参数错误"); + if (redisUtils.hasKey(CacheKey.VIPCODE + params.get("shopId"))) + return new ResponseEntity<>(redisUtils.get(CacheKey.VIPCODE + params.get("shopId")), HttpStatus.OK); + return new ResponseEntity<>(wxService.getFetchQRCode(params), HttpStatus.OK); } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/WxService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/WxService.java new file mode 100644 index 00000000..e486007f --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/WxService.java @@ -0,0 +1,10 @@ +package cn.ysk.cashier.service; + +import java.util.Map; + +public interface WxService { + + String getFetchQRCode(Map params); + + String getSmallQrcode(String shopId); +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/WxServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/WxServiceImpl.java new file mode 100644 index 00000000..e1f760ed --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/WxServiceImpl.java @@ -0,0 +1,80 @@ +package cn.ysk.cashier.service.impl; + +import cn.hutool.core.io.IoUtil; +import cn.hutool.http.HttpUtil; +import cn.ysk.cashier.domain.QiniuContent; +import cn.ysk.cashier.service.QiNiuService; +import cn.ysk.cashier.service.WxService; +import cn.ysk.cashier.utils.CacheKey; +import cn.ysk.cashier.utils.RedisUtils; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.JsonObject; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.io.InputStream; +import java.util.Map; + +@Service +@RequiredArgsConstructor +public class WxServiceImpl implements WxService { + + private final QiNiuService qiNiuService; + + private final RedisUtils redisUtils; + private static final String APP_ID = "wxd88fffa983758a30"; + private static final String APP_SECRET = "a34a61adc0602118b49400baa8812454"; + private static final String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token"; + private static final String QR_CODE_URL = "https://api.weixin.qq.com/wxa/getwxacode"; + + @Override + public String getFetchQRCode(Map params) { + InputStream qrCodeStream = fetchQRCode(params); + QiniuContent qiniuContent = qiNiuService.uploadByte(IoUtil.readBytes(qrCodeStream),qiNiuService.findCloud()); + redisUtils.set(CacheKey.VIPCODE + params.get("shopId"),qiniuContent.getUrl()); + return qiniuContent.getUrl(); + } + + @Override + public String getSmallQrcode(String shopId) { + InputStream shopQRCodeStream = smallQrcode(shopId); + QiniuContent qiniuContent = qiNiuService.uploadByte(IoUtil.readBytes(shopQRCodeStream),qiNiuService.findCloud()); + return qiniuContent.getUrl(); + } + + + public InputStream fetchQRCode(Map params) { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("path", "pages/member/index?shopId="+params.get("shopId"));//路径 + jsonObject.addProperty("is_hyaline", true);//是否需要透明底色,为 true 时,生成透明底色的小程序码 + if (params.containsKey("env_version")) jsonObject.addProperty("env_version", "trial");//正式版为 release,体验版为 trial,开发版为 develop + String accessToken = getAccessToken(); + String url = String.format("%s?access_token=%s", QR_CODE_URL, accessToken); + return HttpUtil.createPost(url) + .body(jsonObject.toString(), "application/json") + .execute() + .bodyStream(); + } + + public InputStream smallQrcode(String shopId) { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("path", "pages/index/index?shopId="+shopId);//路径 + jsonObject.addProperty("is_hyaline", true);//是否需要透明底色,为 true 时,生成透明底色的小程序码 + String accessToken = getAccessToken(); + String url = String.format("%s?access_token=%s", QR_CODE_URL, accessToken); + return HttpUtil.createPost(url) + .body(jsonObject.toString(), "application/json") + .execute() + .bodyStream(); + } + + private String getAccessToken() { + String url = String.format("%s?grant_type=client_credential&appid=%s&secret=%s", TOKEN_URL, APP_ID, APP_SECRET); + String response = HttpUtil.get(url); + JSONObject jsonResponse = JSONObject.parseObject(response); + if (!jsonResponse.containsKey("access_token")) { + throw new RuntimeException("Failed to retrieve access token: " + response); + } + return jsonResponse.getString("access_token"); + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java index 96200030..a112ff6e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java @@ -28,6 +28,7 @@ import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; import cn.ysk.cashier.pojo.shop.TbShopInfo; import cn.ysk.cashier.repository.TbShopPayTypeRepository; import cn.ysk.cashier.repository.shop.*; +import cn.ysk.cashier.service.WxService; import cn.ysk.cashier.service.shop.TbShopInfoService; import cn.ysk.cashier.system.domain.Dept; import cn.ysk.cashier.system.domain.Job; @@ -84,6 +85,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { private final RedisUtils redisUtils; private final TbShopPayTypeRepository tbShopPayTypeRepository; + private final WxService wxService; @Override public Map queryAll(TbShopInfoQueryCriteria criteria){ @@ -102,6 +104,11 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { @Transactional public TbShopInfoDto findById(Integer id) { TbShopInfo tbShopInfo = tbShopInfoRepository.findById(id).orElseGet(TbShopInfo::new); + if(StringUtils.isBlank(tbShopInfo.getSmallQrcode())){ + String smallQrcode = wxService.getSmallQrcode(id.toString()); + tbShopInfo.setSmallQrcode(smallQrcode); + tbShopInfoRepository.save(tbShopInfo); + } ValidationUtil.isNull(tbShopInfo.getId(),"TbShopInfo","id",id); return tbShopInfoMapper.toDto(tbShopInfo); } From f9b5dbad58a8a5750d3dcde58f1dd69ff5449a05 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 11:47:03 +0800 Subject: [PATCH 45/56] =?UTF-8?q?=E5=8F=B0=E6=A1=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=B8=85=E9=99=A4=E7=94=A8=E9=A4=90=E4=BA=BA?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 6679fc18..bf94cd29 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1580,10 +1580,10 @@ public class TbShopTableServiceImpl implements TbShopTableService { mpShopTableMapper.update(null, new LambdaUpdateWrapper() .eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId()) - .set(TbShopTable::getStatus, "using")); + .set(TbShopTable::getStatus, TableStateEnum.USING.getState())); mpShopTableMapper.update(null, new LambdaUpdateWrapper() .eq(TbShopTable::getQrcode, choseTableDTO.getOldTableId()) - .set(TbShopTable::getStatus, "idle")); + .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState())); // 将台桌redis数据迁移 String orderId = removeCurrentOrderId(choseTableDTO.getOldTableId(), choseTableDTO.getShopId().toString()); From 8f2303d1bfa7d5b61790e69b724ad0436e88e90e Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 14:50:22 +0800 Subject: [PATCH 46/56] =?UTF-8?q?=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95?= =?UTF-8?q?=E4=BA=BA=E6=95=B0=E6=9C=AA=E4=BF=9D=E5=AD=98fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/shopimpl/TbShopTableServiceImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index bf94cd29..e9165a08 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -1632,6 +1632,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { tbCashierCart.setProductId("-999"); tbCashierCart.setSkuId("-999"); tbCashierCart.setPackFee(BigDecimal.ZERO); + tbCashierCart.setNumber(choseCountDTO.getNum()); + tbCashierCart.setTotalNumber(choseCountDTO.getNum()); tbCashierCartMapper.insert(tbCashierCart); } else { tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(BigDecimal.ONE)); From 077222c9b7bb11591c51ce2d6c086d8fc1c52f36 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 15:01:34 +0800 Subject: [PATCH 47/56] =?UTF-8?q?=E6=8E=92=E5=8F=B7=E6=A1=8C=E5=9E=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E6=80=BB=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/app/TbCallServiceImpl.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java index 68629d57..5b9900b9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java @@ -253,7 +253,22 @@ public class TbCallServiceImpl implements TbCallService { if (state != null) { query.eq(TbCallTable::getState, state); } - return callTableService.page(new Page<>(page, size), query); + Page pageInfo = callTableService.page(new Page<>(page, size), query); + ArrayList> info = new ArrayList<>(); + pageInfo.getRecords().forEach(item -> { + Long count = callQueueService.lambdaQuery() + .eq(TbCallQueue::getCallTableId, item.getId()) + .in(TbCallQueue::getState, 0, 1) + .count(); + + Map map = BeanUtil.beanToMap(item, false, false); + map.put("totalCount", count); + info.add(map); + }); + + Map toMap = BeanUtil.beanToMap(pageInfo); + toMap.put("records", info); + return toMap; } @Override From 675569c19ea95c8a0f7d635deb9669270e0186f7 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 15:16:49 +0800 Subject: [PATCH 48/56] =?UTF-8?q?=E6=8E=92=E5=8F=B7=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E8=AE=B0=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/controller/TbCallTableController.java | 11 +++++++++++ .../cashier/mybatis/mapper/TbCallQueueMapper.java | 7 +++++++ .../cn/ysk/cashier/mybatis/vo/CallRecordVO.java | 14 ++++++++++++++ .../cn/ysk/cashier/service/app/TbCallService.java | 2 ++ .../service/impl/app/TbCallServiceImpl.java | 7 +++++++ 5 files changed, 41 insertions(+) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/CallRecordVO.java diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbCallTableController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbCallTableController.java index c11145b9..268dff3f 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbCallTableController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbCallTableController.java @@ -102,5 +102,16 @@ public class TbCallTableController { return ResponseEntity.ok(tbCallService.getQueue(shopId, callTableId, state, page, size)); } + @AnonymousAccess + @GetMapping("callRecord") + public ResponseEntity getCallRecord( + @RequestParam Integer shopId, + @RequestParam(required = false) Integer callTableId, + @RequestParam(defaultValue = "1") Integer page, + @RequestParam(defaultValue = "10") Integer size + ) { + return ResponseEntity.ok(tbCallService.getCallRecord(shopId, callTableId, page, size)); + } + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java index 2cbb80a3..f30242e5 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java @@ -1,7 +1,10 @@ package cn.ysk.cashier.mybatis.mapper; import cn.ysk.cashier.mybatis.entity.TbCallQueue; +import cn.ysk.cashier.mybatis.vo.CallRecordVO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.ibatis.annotations.Select; /** * @author Administrator @@ -11,6 +14,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; */ public interface TbCallQueueMapper extends BaseMapper { + @Select("select * from tb_call_queue a " + + "left join tb_call_table b on a.call_table_id=b.id " + + "where a.shop_id=#{shopId} and a.call_table_id=#{callTableId}") + Page selectCallRecord(Integer shopId, Integer callTableId, Page objectPage); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/CallRecordVO.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/CallRecordVO.java new file mode 100644 index 00000000..f408dd60 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/CallRecordVO.java @@ -0,0 +1,14 @@ +package cn.ysk.cashier.mybatis.vo; + +import cn.ysk.cashier.mybatis.entity.TbCallQueue; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.sql.Date; +import java.time.Instant; + +@EqualsAndHashCode(callSuper = true) +@Data +public class CallRecordVO extends TbCallQueue { + private String note; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/app/TbCallService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/app/TbCallService.java index 2ae4d905..b12eeed2 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/app/TbCallService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/app/TbCallService.java @@ -20,4 +20,6 @@ public interface TbCallService { Object takeNumberCode(Integer shopId, Integer callTableId); Object getQueue(Integer shopId, Integer callTableId, Integer state, Integer page, Integer size); + + Object getCallRecord(Integer shopId, Integer callTableId, Integer page, Integer size); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java index 5b9900b9..ec1470a3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java @@ -10,6 +10,7 @@ import cn.ysk.cashier.dto.calltable.*; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.entity.TbCallQueue; import cn.ysk.cashier.mybatis.entity.TbCallTable; +import cn.ysk.cashier.mybatis.mapper.TbCallQueueMapper; import cn.ysk.cashier.mybatis.mapper.TbShopUserMapper; import cn.ysk.cashier.mybatis.service.TbCallQueueService; import cn.ysk.cashier.mybatis.service.TbCallTableService; @@ -39,6 +40,7 @@ public class TbCallServiceImpl implements TbCallService { private final TbShopUserMapper shopUserMapper; private final TbShopInfoRepository shopInfoRepository; private final StringRedisTemplate redisTemplate; + private final TbCallQueueMapper tbCallQueueMapper; @Override public Object add(CallTableDTO addCallTableDTO) { @@ -346,4 +348,9 @@ public class TbCallServiceImpl implements TbCallService { // 返回结果列表 return toMap; } + + @Override + public Object getCallRecord(Integer shopId, Integer callTableId, Integer page, Integer size) { + return tbCallQueueMapper.selectCallRecord(shopId, callTableId, new Page<>(page, size)); + } } From 6b9d48874978d2d8152c033f8880269fd48d1e2d Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 15:45:55 +0800 Subject: [PATCH 49/56] =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=A8=A1=E6=9D=BF=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/app/TbCallServiceImpl.java | 43 +++++ .../cn/ysk/cashier/utils/WxAccountUtil.java | 3 + .../cn/ysk/cashier/utils/WxMiniUtils.java | 182 +++++++++--------- 3 files changed, 142 insertions(+), 86 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java index ec1470a3..69bb7cb9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java @@ -19,6 +19,7 @@ import cn.ysk.cashier.pojo.shop.TbShopUser; import cn.ysk.cashier.repository.shop.TbShopInfoRepository; import cn.ysk.cashier.service.app.TbCallService; import cn.ysk.cashier.utils.Utils; +import cn.ysk.cashier.utils.WxMiniUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -41,6 +42,7 @@ public class TbCallServiceImpl implements TbCallService { private final TbShopInfoRepository shopInfoRepository; private final StringRedisTemplate redisTemplate; private final TbCallQueueMapper tbCallQueueMapper; + private final WxMiniUtils wxMiniUtils; @Override public Object add(CallTableDTO addCallTableDTO) { @@ -201,9 +203,50 @@ public class TbCallServiceImpl implements TbCallService { // 发送模板消息通知用户 + TbShopInfo shopInfo = shopInfoRepository.findById(callQueue.getShopId()).orElse(null); + if (shopInfo == null) { + throw new BadRequestException("店铺信息不存在"); + } + + List current = callQueueService.lambdaQuery() + .eq(TbCallQueue::getCallTableId, callQueue.getCallTableId()) + .and(r -> { + r.eq(TbCallQueue::getState, 1) + .or() + .eq(TbCallQueue::getState, 0); + }) + .orderByAsc(TbCallQueue::getCreateTime) + .page(new Page<>(1, 1)).getRecords(); + + if (StrUtil.isBlank(callQueue.getOpenId())) { + throw new BadRequestException("此用户未订阅微信小程序消息"); + } + + wxMiniUtils.sendNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(callQueue.getState())), + callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", callQueue.getOpenId()); + return callQueueService.updateById(callQueue); } + private String getStrByState(Integer state) { + String msg = ""; + switch (state) { + case -1: + msg = "已取消"; + break; + case 0: + msg = "排队中"; + break; + case 1: + msg = "已到号"; + break; + case 3: + msg = "已过号"; + } + + return msg; + } + @Override public Object updateInfo(UpdateCallQueueDTO updateCallQueueDTO) { TbCallQueue callQueue = callQueueService.lambdaQuery() diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java index f870f5a1..4d5cd717 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java @@ -156,4 +156,7 @@ public class WxAccountUtil { } } + + + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java index f01cae4c..1b7b8421 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java @@ -2,8 +2,10 @@ package cn.ysk.cashier.utils; import cn.hutool.core.util.ObjectUtil; import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -12,92 +14,100 @@ import java.util.LinkedHashMap; import java.util.Map; @Component +@Slf4j public class WxMiniUtils { -// @Value("${wx.msg.appId}") -// private String appId; -// -// @Value("${wx.msg.secrete}") -// private String secrete; -// -// @Value("${wx.msg.warnMsgTmpId}") -// private String msgTmpId; -// -// static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); -// -// static { -// -// linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); -// linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); -// linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); -// linkedHashMap.put("40037","不合法的 template_id"); -// linkedHashMap.put("43101","用户未订阅消息"); -// linkedHashMap.put("43107","订阅消息能力封禁"); -// linkedHashMap.put("43108","并发下发消息给同一个粉丝"); -// linkedHashMap.put("45168","命中敏感词"); -// linkedHashMap.put("47003","参数错误"); -// -// } -// -// public JSONObject getAccessToken(){ -// String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; -// Map requestUrlParam = new HashMap<>(); -// //小程序appId -// requestUrlParam.put("appid", appId); -// //小程序secret -// requestUrlParam.put("secret", secrete); -// //默认参数 -// requestUrlParam.put("grant_type", "client_credential"); -// JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doGet(requestUrl,requestUrlParam)); -// return jsonObject; -// } -// -// public static void main(String[] args) { -// String id ="kSxJL9TR4s_UmOmNLE"; -//// sendStockWarnMsg("123", "1231", "1231", "23321", id); -// } -// -// public JSONObject sendStockWarnMsg(String shopName, String productName, String stock, String note, String toUserOpenId) { -// Map data = new HashMap() {{ -// put("thing1", new HashMap(){{ -// put("value", shopName); -// }}); -// put("thing6", new HashMap(){{ -// put("value", productName); -// }}); -// put("number7", new HashMap(){{ -// put("value", stock); -// }}); -// put("thing5", new HashMap(){{ -// put("value", note); -// }}); -// }}; -// log.info("开始发送库存预警消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); -// return sendTempMsg(msgTmpId, toUserOpenId, data); -// } -// -// -// public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { -// log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); -// JSONObject object= getAccessToken(); -// String accessToken=object.get("access_token")+""; -// -// JSONObject object1=new JSONObject(); -// -// object1.put("template_id", tempId); -// object1.put("touser", toUserOpenId); -// object1.put("data",data); -// -// object1.put("miniprogram_state","trial"); -// object1.put("lang","zh_CN"); -// -// String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); -// log.info("微信模板消息发送成功,相应内容:{}",response); -// JSONObject resObj=JSONObject.parseObject(response); -// if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ -// return resObj; -// } -// -// throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); -// } + @Value("${wx.mini.user.appId}") + private String appId; + + @Value("${wx.mini.user.secrete}") + private String secrete; + + @Value("${wx.mini.user.msgId.currentCall}") + private String currentCallTempId; + + + static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); + + static { + + linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); + linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40037","不合法的 template_id"); + linkedHashMap.put("43101","用户未订阅消息"); + linkedHashMap.put("43107","订阅消息能力封禁"); + linkedHashMap.put("43108","并发下发消息给同一个粉丝"); + linkedHashMap.put("45168","命中敏感词"); + linkedHashMap.put("47003","参数错误"); + + } + + public JSONObject getAccessToken(){ + String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; + Map requestUrlParam = new HashMap<>(); + //小程序appId + requestUrlParam.put("appid", appId); + //小程序secret + requestUrlParam.put("secret", secrete); + //默认参数 + requestUrlParam.put("grant_type", "client_credential"); + return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); + } + + public static void main(String[] args) { + String id ="kSxJL9TR4s_UmOmNLE"; +// sendStockWarnMsg("123", "1231", "1231", "23321", id); + } + + + public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { + log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); + JSONObject object= getAccessToken(); + String accessToken=object.get("access_token")+""; + + JSONObject object1=new JSONObject(); + + object1.put("template_id", tempId); + object1.put("touser", toUserOpenId); + object1.put("data",data); + + object1.put("miniprogram_state","trial"); + object1.put("lang","zh_CN"); + + String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); + log.info("微信模板消息发送成功,相应内容:{}",response); + JSONObject resObj=JSONObject.parseObject(response); + if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ + return resObj; + } + + throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); + } + + public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { + Map data = new HashMap() {{ + put("thing1", new HashMap() {{ + put("value", shopName); + }}); + put("phrase2", new HashMap() {{ + put("value", state); + }}); + put("character_string3", new HashMap() {{ + put("value", callNum); + }}); + put("character_string4", new HashMap() {{ + put("value", currentNum); + }}); + put("thing5", new HashMap() {{ + put("value", note); + }}); + }}; + log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); + try { + sendTempMsg(currentCallTempId, openId, data); + } catch (Exception e) { + log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); + } + } } From 90e8e4944ea34a64bc93ddfa31146863dd4442d5 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 15:50:06 +0800 Subject: [PATCH 50/56] =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java | 2 +- .../src/main/java/cn/ysk/cashier/mybatis/vo/CallRecordVO.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java index f30242e5..77381657 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCallQueueMapper.java @@ -14,7 +14,7 @@ import org.apache.ibatis.annotations.Select; */ public interface TbCallQueueMapper extends BaseMapper { - @Select("select * from tb_call_queue a " + + @Select("select a.*, b.note, TIMESTAMPDIFF(SECOND, a.create_time, NOW()) as since_at from tb_call_queue a " + "left join tb_call_table b on a.call_table_id=b.id " + "where a.shop_id=#{shopId} and a.call_table_id=#{callTableId}") Page selectCallRecord(Integer shopId, Integer callTableId, Page objectPage); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/CallRecordVO.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/CallRecordVO.java index f408dd60..d25aef19 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/CallRecordVO.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/CallRecordVO.java @@ -11,4 +11,5 @@ import java.time.Instant; @Data public class CallRecordVO extends TbCallQueue { private String note; + private Long sinceAt; } From a956e7b76461aea51a0583bef29d0ee7a627b377 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 15:52:13 +0800 Subject: [PATCH 51/56] =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/utils/WxMiniUtils.java | 226 +++++++++--------- 1 file changed, 113 insertions(+), 113 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java index 1b7b8421..aae056fc 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java @@ -1,113 +1,113 @@ -package cn.ysk.cashier.utils; - -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -@Component -@Slf4j -public class WxMiniUtils { - - @Value("${wx.mini.user.appId}") - private String appId; - - @Value("${wx.mini.user.secrete}") - private String secrete; - - @Value("${wx.mini.user.msgId.currentCall}") - private String currentCallTempId; - - - static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); - - static { - - linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); - linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); - linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); - linkedHashMap.put("40037","不合法的 template_id"); - linkedHashMap.put("43101","用户未订阅消息"); - linkedHashMap.put("43107","订阅消息能力封禁"); - linkedHashMap.put("43108","并发下发消息给同一个粉丝"); - linkedHashMap.put("45168","命中敏感词"); - linkedHashMap.put("47003","参数错误"); - - } - - public JSONObject getAccessToken(){ - String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; - Map requestUrlParam = new HashMap<>(); - //小程序appId - requestUrlParam.put("appid", appId); - //小程序secret - requestUrlParam.put("secret", secrete); - //默认参数 - requestUrlParam.put("grant_type", "client_credential"); - return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); - } - - public static void main(String[] args) { - String id ="kSxJL9TR4s_UmOmNLE"; -// sendStockWarnMsg("123", "1231", "1231", "23321", id); - } - - - public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { - log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); - JSONObject object= getAccessToken(); - String accessToken=object.get("access_token")+""; - - JSONObject object1=new JSONObject(); - - object1.put("template_id", tempId); - object1.put("touser", toUserOpenId); - object1.put("data",data); - - object1.put("miniprogram_state","trial"); - object1.put("lang","zh_CN"); - - String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); - log.info("微信模板消息发送成功,相应内容:{}",response); - JSONObject resObj=JSONObject.parseObject(response); - if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ - return resObj; - } - - throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); - } - - public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { - Map data = new HashMap() {{ - put("thing1", new HashMap() {{ - put("value", shopName); - }}); - put("phrase2", new HashMap() {{ - put("value", state); - }}); - put("character_string3", new HashMap() {{ - put("value", callNum); - }}); - put("character_string4", new HashMap() {{ - put("value", currentNum); - }}); - put("thing5", new HashMap() {{ - put("value", note); - }}); - }}; - log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); - try { - sendTempMsg(currentCallTempId, openId, data); - } catch (Exception e) { - log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); - } - } -} +//package cn.ysk.cashier.utils; +// +//import cn.hutool.core.util.ObjectUtil; +//import cn.hutool.http.HttpRequest; +//import cn.hutool.http.HttpUtil; +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.JSONObject; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.stereotype.Component; +// +//import java.util.HashMap; +//import java.util.LinkedHashMap; +//import java.util.Map; +// +//@Component +//@Slf4j +//public class WxMiniUtils { +// +// @Value("${wx.mini.user.appId}") +// private String appId; +// +// @Value("${wx.mini.user.secrete}") +// private String secrete; +// +// @Value("${wx.mini.user.msgId.currentCall}") +// private String currentCallTempId; +// +// +// static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); +// +// static { +// +// linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); +// linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); +// linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); +// linkedHashMap.put("40037","不合法的 template_id"); +// linkedHashMap.put("43101","用户未订阅消息"); +// linkedHashMap.put("43107","订阅消息能力封禁"); +// linkedHashMap.put("43108","并发下发消息给同一个粉丝"); +// linkedHashMap.put("45168","命中敏感词"); +// linkedHashMap.put("47003","参数错误"); +// +// } +// +// public JSONObject getAccessToken(){ +// String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; +// Map requestUrlParam = new HashMap<>(); +// //小程序appId +// requestUrlParam.put("appid", appId); +// //小程序secret +// requestUrlParam.put("secret", secrete); +// //默认参数 +// requestUrlParam.put("grant_type", "client_credential"); +// return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); +// } +// +// public static void main(String[] args) { +// String id ="kSxJL9TR4s_UmOmNLE"; +//// sendStockWarnMsg("123", "1231", "1231", "23321", id); +// } +// +// +// public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { +// log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); +// JSONObject object= getAccessToken(); +// String accessToken=object.get("access_token")+""; +// +// JSONObject object1=new JSONObject(); +// +// object1.put("template_id", tempId); +// object1.put("touser", toUserOpenId); +// object1.put("data",data); +// +// object1.put("miniprogram_state","trial"); +// object1.put("lang","zh_CN"); +// +// String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); +// log.info("微信模板消息发送成功,相应内容:{}",response); +// JSONObject resObj=JSONObject.parseObject(response); +// if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ +// return resObj; +// } +// +// throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); +// } +// +// public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { +// Map data = new HashMap() {{ +// put("thing1", new HashMap() {{ +// put("value", shopName); +// }}); +// put("phrase2", new HashMap() {{ +// put("value", state); +// }}); +// put("character_string3", new HashMap() {{ +// put("value", callNum); +// }}); +// put("character_string4", new HashMap() {{ +// put("value", currentNum); +// }}); +// put("thing5", new HashMap() {{ +// put("value", note); +// }}); +// }}; +// log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); +// try { +// sendTempMsg(currentCallTempId, openId, data); +// } catch (Exception e) { +// log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); +// } +// } +//} From 99e7cdf5a9281148bda6e382bbe5193538d3bb1f Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 15:55:22 +0800 Subject: [PATCH 52/56] =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/utils/WxMiniUtils.java | 226 +++++++++--------- .../src/main/resources/config/application.yml | 10 + 2 files changed, 123 insertions(+), 113 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java index aae056fc..1b7b8421 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java @@ -1,113 +1,113 @@ -//package cn.ysk.cashier.utils; -// -//import cn.hutool.core.util.ObjectUtil; -//import cn.hutool.http.HttpRequest; -//import cn.hutool.http.HttpUtil; -//import com.alibaba.fastjson.JSON; -//import com.alibaba.fastjson.JSONObject; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.beans.factory.annotation.Value; -//import org.springframework.stereotype.Component; -// -//import java.util.HashMap; -//import java.util.LinkedHashMap; -//import java.util.Map; -// -//@Component -//@Slf4j -//public class WxMiniUtils { -// -// @Value("${wx.mini.user.appId}") -// private String appId; -// -// @Value("${wx.mini.user.secrete}") -// private String secrete; -// -// @Value("${wx.mini.user.msgId.currentCall}") -// private String currentCallTempId; -// -// -// static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); -// -// static { -// -// linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); -// linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); -// linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); -// linkedHashMap.put("40037","不合法的 template_id"); -// linkedHashMap.put("43101","用户未订阅消息"); -// linkedHashMap.put("43107","订阅消息能力封禁"); -// linkedHashMap.put("43108","并发下发消息给同一个粉丝"); -// linkedHashMap.put("45168","命中敏感词"); -// linkedHashMap.put("47003","参数错误"); -// -// } -// -// public JSONObject getAccessToken(){ -// String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; -// Map requestUrlParam = new HashMap<>(); -// //小程序appId -// requestUrlParam.put("appid", appId); -// //小程序secret -// requestUrlParam.put("secret", secrete); -// //默认参数 -// requestUrlParam.put("grant_type", "client_credential"); -// return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); -// } -// -// public static void main(String[] args) { -// String id ="kSxJL9TR4s_UmOmNLE"; -//// sendStockWarnMsg("123", "1231", "1231", "23321", id); -// } -// -// -// public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { -// log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); -// JSONObject object= getAccessToken(); -// String accessToken=object.get("access_token")+""; -// -// JSONObject object1=new JSONObject(); -// -// object1.put("template_id", tempId); -// object1.put("touser", toUserOpenId); -// object1.put("data",data); -// -// object1.put("miniprogram_state","trial"); -// object1.put("lang","zh_CN"); -// -// String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); -// log.info("微信模板消息发送成功,相应内容:{}",response); -// JSONObject resObj=JSONObject.parseObject(response); -// if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ -// return resObj; -// } -// -// throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); -// } -// -// public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { -// Map data = new HashMap() {{ -// put("thing1", new HashMap() {{ -// put("value", shopName); -// }}); -// put("phrase2", new HashMap() {{ -// put("value", state); -// }}); -// put("character_string3", new HashMap() {{ -// put("value", callNum); -// }}); -// put("character_string4", new HashMap() {{ -// put("value", currentNum); -// }}); -// put("thing5", new HashMap() {{ -// put("value", note); -// }}); -// }}; -// log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); -// try { -// sendTempMsg(currentCallTempId, openId, data); -// } catch (Exception e) { -// log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); -// } -// } -//} +package cn.ysk.cashier.utils; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +@Component +@Slf4j +public class WxMiniUtils { + + @Value("${wx.mini.user.appId}") + private String appId; + + @Value("${wx.mini.user.secrete}") + private String secrete; + + @Value("${wx.mini.user.msgId.currentCall}") + private String currentCallTempId; + + + static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); + + static { + + linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); + linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40037","不合法的 template_id"); + linkedHashMap.put("43101","用户未订阅消息"); + linkedHashMap.put("43107","订阅消息能力封禁"); + linkedHashMap.put("43108","并发下发消息给同一个粉丝"); + linkedHashMap.put("45168","命中敏感词"); + linkedHashMap.put("47003","参数错误"); + + } + + public JSONObject getAccessToken(){ + String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; + Map requestUrlParam = new HashMap<>(); + //小程序appId + requestUrlParam.put("appid", appId); + //小程序secret + requestUrlParam.put("secret", secrete); + //默认参数 + requestUrlParam.put("grant_type", "client_credential"); + return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); + } + + public static void main(String[] args) { + String id ="kSxJL9TR4s_UmOmNLE"; +// sendStockWarnMsg("123", "1231", "1231", "23321", id); + } + + + public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { + log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); + JSONObject object= getAccessToken(); + String accessToken=object.get("access_token")+""; + + JSONObject object1=new JSONObject(); + + object1.put("template_id", tempId); + object1.put("touser", toUserOpenId); + object1.put("data",data); + + object1.put("miniprogram_state","trial"); + object1.put("lang","zh_CN"); + + String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); + log.info("微信模板消息发送成功,相应内容:{}",response); + JSONObject resObj=JSONObject.parseObject(response); + if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ + return resObj; + } + + throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); + } + + public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { + Map data = new HashMap() {{ + put("thing1", new HashMap() {{ + put("value", shopName); + }}); + put("phrase2", new HashMap() {{ + put("value", state); + }}); + put("character_string3", new HashMap() {{ + put("value", callNum); + }}); + put("character_string4", new HashMap() {{ + put("value", currentNum); + }}); + put("thing5", new HashMap() {{ + put("value", note); + }}); + }}; + log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); + try { + sendTempMsg(currentCallTempId, openId, data); + } catch (Exception e) { + log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); + } + } +} diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index 27f66d89..2cf03921 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -88,8 +88,18 @@ wx: operationMsgTmpId: wFdoUG-dUT7bDRHq8bMJD9CF5TjyH9x_uJQgQByZqHg warnMsgTmpId: C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0 + mini: + user: + appId: wxd88fffa983758a30 + secrete: a34a61adc0602118b49400baa8812454 + msgId: + nearCall: yxOjWK-KjMEZ BaHWgDJJpHiUPXN6JWgr7u9y65RIWM + currentCall: 3BgFazRpVlvreh5z9u4cNPVeclXKSQfh-r3x2 bYx4 gateway: url: https://gateway.api.sxczgkj.cn/gate-service/ client: backUrl: https://cashierclient.sxczgkj.cn/cashier-client/notify/notifyPay +logging: + level: + root: error From a9589edca5df5c2c4f64ee9248a0a4ae506ae00d Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 15:59:46 +0800 Subject: [PATCH 53/56] =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java index 1b7b8421..85f8d83e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java @@ -18,13 +18,13 @@ import java.util.Map; public class WxMiniUtils { @Value("${wx.mini.user.appId}") - private String appId; + private String appId = ""; @Value("${wx.mini.user.secrete}") - private String secrete; + private String secrete =""; @Value("${wx.mini.user.msgId.currentCall}") - private String currentCallTempId; + private String currentCallTempId =""; static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); From e35da7f608843d88a1095ea572ad50f99ece4318 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 16:02:35 +0800 Subject: [PATCH 54/56] =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java index 85f8d83e..d728f626 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java @@ -17,13 +17,13 @@ import java.util.Map; @Slf4j public class WxMiniUtils { - @Value("${wx.mini.user.appId}") +// @Value("${wx.mini.user.appId}") private String appId = ""; - @Value("${wx.mini.user.secrete}") +// @Value("${wx.mini.user.secrete}") private String secrete =""; - @Value("${wx.mini.user.msgId.currentCall}") +// @Value("${wx.mini.user.msgId.currentCall}") private String currentCallTempId =""; From f516dae0daa5df5fec6ddd834860a23141f68ff2 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 16:05:08 +0800 Subject: [PATCH 55/56] =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/app/TbCallServiceImpl.java | 6 +- .../cn/ysk/cashier/utils/WxMiniUtils.java | 220 +++++++++--------- 2 files changed, 112 insertions(+), 114 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java index 69bb7cb9..36c62df1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java @@ -19,7 +19,6 @@ import cn.ysk.cashier.pojo.shop.TbShopUser; import cn.ysk.cashier.repository.shop.TbShopInfoRepository; import cn.ysk.cashier.service.app.TbCallService; import cn.ysk.cashier.utils.Utils; -import cn.ysk.cashier.utils.WxMiniUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -42,7 +41,6 @@ public class TbCallServiceImpl implements TbCallService { private final TbShopInfoRepository shopInfoRepository; private final StringRedisTemplate redisTemplate; private final TbCallQueueMapper tbCallQueueMapper; - private final WxMiniUtils wxMiniUtils; @Override public Object add(CallTableDTO addCallTableDTO) { @@ -222,8 +220,8 @@ public class TbCallServiceImpl implements TbCallService { throw new BadRequestException("此用户未订阅微信小程序消息"); } - wxMiniUtils.sendNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(callQueue.getState())), - callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", callQueue.getOpenId()); +// wxMiniUtils.sendNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(callQueue.getState())), +// callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", callQueue.getOpenId()); return callQueueService.updateById(callQueue); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java index d728f626..aae056fc 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java @@ -1,113 +1,113 @@ -package cn.ysk.cashier.utils; - -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -@Component -@Slf4j -public class WxMiniUtils { - +//package cn.ysk.cashier.utils; +// +//import cn.hutool.core.util.ObjectUtil; +//import cn.hutool.http.HttpRequest; +//import cn.hutool.http.HttpUtil; +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.JSONObject; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.stereotype.Component; +// +//import java.util.HashMap; +//import java.util.LinkedHashMap; +//import java.util.Map; +// +//@Component +//@Slf4j +//public class WxMiniUtils { +// // @Value("${wx.mini.user.appId}") - private String appId = ""; - +// private String appId; +// // @Value("${wx.mini.user.secrete}") - private String secrete =""; - +// private String secrete; +// // @Value("${wx.mini.user.msgId.currentCall}") - private String currentCallTempId =""; - - - static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); - - static { - - linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); - linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); - linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); - linkedHashMap.put("40037","不合法的 template_id"); - linkedHashMap.put("43101","用户未订阅消息"); - linkedHashMap.put("43107","订阅消息能力封禁"); - linkedHashMap.put("43108","并发下发消息给同一个粉丝"); - linkedHashMap.put("45168","命中敏感词"); - linkedHashMap.put("47003","参数错误"); - - } - - public JSONObject getAccessToken(){ - String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; - Map requestUrlParam = new HashMap<>(); - //小程序appId - requestUrlParam.put("appid", appId); - //小程序secret - requestUrlParam.put("secret", secrete); - //默认参数 - requestUrlParam.put("grant_type", "client_credential"); - return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); - } - - public static void main(String[] args) { - String id ="kSxJL9TR4s_UmOmNLE"; -// sendStockWarnMsg("123", "1231", "1231", "23321", id); - } - - - public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { - log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); - JSONObject object= getAccessToken(); - String accessToken=object.get("access_token")+""; - - JSONObject object1=new JSONObject(); - - object1.put("template_id", tempId); - object1.put("touser", toUserOpenId); - object1.put("data",data); - - object1.put("miniprogram_state","trial"); - object1.put("lang","zh_CN"); - - String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); - log.info("微信模板消息发送成功,相应内容:{}",response); - JSONObject resObj=JSONObject.parseObject(response); - if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ - return resObj; - } - - throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); - } - - public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { - Map data = new HashMap() {{ - put("thing1", new HashMap() {{ - put("value", shopName); - }}); - put("phrase2", new HashMap() {{ - put("value", state); - }}); - put("character_string3", new HashMap() {{ - put("value", callNum); - }}); - put("character_string4", new HashMap() {{ - put("value", currentNum); - }}); - put("thing5", new HashMap() {{ - put("value", note); - }}); - }}; - log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); - try { - sendTempMsg(currentCallTempId, openId, data); - } catch (Exception e) { - log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); - } - } -} +// private String currentCallTempId; +// +// +// static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); +// +// static { +// +// linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); +// linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); +// linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); +// linkedHashMap.put("40037","不合法的 template_id"); +// linkedHashMap.put("43101","用户未订阅消息"); +// linkedHashMap.put("43107","订阅消息能力封禁"); +// linkedHashMap.put("43108","并发下发消息给同一个粉丝"); +// linkedHashMap.put("45168","命中敏感词"); +// linkedHashMap.put("47003","参数错误"); +// +// } +// +// public JSONObject getAccessToken(){ +// String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; +// Map requestUrlParam = new HashMap<>(); +// //小程序appId +// requestUrlParam.put("appid", appId); +// //小程序secret +// requestUrlParam.put("secret", secrete); +// //默认参数 +// requestUrlParam.put("grant_type", "client_credential"); +// return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); +// } +// +// public static void main(String[] args) { +// String id ="kSxJL9TR4s_UmOmNLE"; +//// sendStockWarnMsg("123", "1231", "1231", "23321", id); +// } +// +// +// public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { +// log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); +// JSONObject object= getAccessToken(); +// String accessToken=object.get("access_token")+""; +// +// JSONObject object1=new JSONObject(); +// +// object1.put("template_id", tempId); +// object1.put("touser", toUserOpenId); +// object1.put("data",data); +// +// object1.put("miniprogram_state","trial"); +// object1.put("lang","zh_CN"); +// +// String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); +// log.info("微信模板消息发送成功,相应内容:{}",response); +// JSONObject resObj=JSONObject.parseObject(response); +// if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ +// return resObj; +// } +// +// throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); +// } +// +// public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { +// Map data = new HashMap() {{ +// put("thing1", new HashMap() {{ +// put("value", shopName); +// }}); +// put("phrase2", new HashMap() {{ +// put("value", state); +// }}); +// put("character_string3", new HashMap() {{ +// put("value", callNum); +// }}); +// put("character_string4", new HashMap() {{ +// put("value", currentNum); +// }}); +// put("thing5", new HashMap() {{ +// put("value", note); +// }}); +// }}; +// log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); +// try { +// sendTempMsg(currentCallTempId, openId, data); +// } catch (Exception e) { +// log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); +// } +// } +//} From 48f82895e733a162c345eacee87ed42cbb7d0492 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 14 Sep 2024 16:07:46 +0800 Subject: [PATCH 56/56] =?UTF-8?q?=E5=8F=AB=E5=8F=B7=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/app/TbCallServiceImpl.java | 6 +- .../cn/ysk/cashier/utils/WxMiniUtils.java | 226 +++++++++--------- 2 files changed, 117 insertions(+), 115 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java index 36c62df1..69bb7cb9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/app/TbCallServiceImpl.java @@ -19,6 +19,7 @@ import cn.ysk.cashier.pojo.shop.TbShopUser; import cn.ysk.cashier.repository.shop.TbShopInfoRepository; import cn.ysk.cashier.service.app.TbCallService; import cn.ysk.cashier.utils.Utils; +import cn.ysk.cashier.utils.WxMiniUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -41,6 +42,7 @@ public class TbCallServiceImpl implements TbCallService { private final TbShopInfoRepository shopInfoRepository; private final StringRedisTemplate redisTemplate; private final TbCallQueueMapper tbCallQueueMapper; + private final WxMiniUtils wxMiniUtils; @Override public Object add(CallTableDTO addCallTableDTO) { @@ -220,8 +222,8 @@ public class TbCallServiceImpl implements TbCallService { throw new BadRequestException("此用户未订阅微信小程序消息"); } -// wxMiniUtils.sendNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(callQueue.getState())), -// callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", callQueue.getOpenId()); + wxMiniUtils.sendNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(callQueue.getState())), + callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", callQueue.getOpenId()); return callQueueService.updateById(callQueue); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java index aae056fc..1b7b8421 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMiniUtils.java @@ -1,113 +1,113 @@ -//package cn.ysk.cashier.utils; -// -//import cn.hutool.core.util.ObjectUtil; -//import cn.hutool.http.HttpRequest; -//import cn.hutool.http.HttpUtil; -//import com.alibaba.fastjson.JSON; -//import com.alibaba.fastjson.JSONObject; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.beans.factory.annotation.Value; -//import org.springframework.stereotype.Component; -// -//import java.util.HashMap; -//import java.util.LinkedHashMap; -//import java.util.Map; -// -//@Component -//@Slf4j -//public class WxMiniUtils { -// -// @Value("${wx.mini.user.appId}") -// private String appId; -// -// @Value("${wx.mini.user.secrete}") -// private String secrete; -// -// @Value("${wx.mini.user.msgId.currentCall}") -// private String currentCallTempId; -// -// -// static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); -// -// static { -// -// linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); -// linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); -// linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); -// linkedHashMap.put("40037","不合法的 template_id"); -// linkedHashMap.put("43101","用户未订阅消息"); -// linkedHashMap.put("43107","订阅消息能力封禁"); -// linkedHashMap.put("43108","并发下发消息给同一个粉丝"); -// linkedHashMap.put("45168","命中敏感词"); -// linkedHashMap.put("47003","参数错误"); -// -// } -// -// public JSONObject getAccessToken(){ -// String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; -// Map requestUrlParam = new HashMap<>(); -// //小程序appId -// requestUrlParam.put("appid", appId); -// //小程序secret -// requestUrlParam.put("secret", secrete); -// //默认参数 -// requestUrlParam.put("grant_type", "client_credential"); -// return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); -// } -// -// public static void main(String[] args) { -// String id ="kSxJL9TR4s_UmOmNLE"; -//// sendStockWarnMsg("123", "1231", "1231", "23321", id); -// } -// -// -// public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { -// log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); -// JSONObject object= getAccessToken(); -// String accessToken=object.get("access_token")+""; -// -// JSONObject object1=new JSONObject(); -// -// object1.put("template_id", tempId); -// object1.put("touser", toUserOpenId); -// object1.put("data",data); -// -// object1.put("miniprogram_state","trial"); -// object1.put("lang","zh_CN"); -// -// String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); -// log.info("微信模板消息发送成功,相应内容:{}",response); -// JSONObject resObj=JSONObject.parseObject(response); -// if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ -// return resObj; -// } -// -// throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); -// } -// -// public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { -// Map data = new HashMap() {{ -// put("thing1", new HashMap() {{ -// put("value", shopName); -// }}); -// put("phrase2", new HashMap() {{ -// put("value", state); -// }}); -// put("character_string3", new HashMap() {{ -// put("value", callNum); -// }}); -// put("character_string4", new HashMap() {{ -// put("value", currentNum); -// }}); -// put("thing5", new HashMap() {{ -// put("value", note); -// }}); -// }}; -// log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); -// try { -// sendTempMsg(currentCallTempId, openId, data); -// } catch (Exception e) { -// log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); -// } -// } -//} +package cn.ysk.cashier.utils; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +@Component +@Slf4j +public class WxMiniUtils { + + @Value("${wx.mini.user.appId}") + private String appId; + + @Value("${wx.mini.user.secrete}") + private String secrete; + + @Value("${wx.mini.user.msgId.currentCall}") + private String currentCallTempId; + + + static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); + + static { + + linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); + linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40037","不合法的 template_id"); + linkedHashMap.put("43101","用户未订阅消息"); + linkedHashMap.put("43107","订阅消息能力封禁"); + linkedHashMap.put("43108","并发下发消息给同一个粉丝"); + linkedHashMap.put("45168","命中敏感词"); + linkedHashMap.put("47003","参数错误"); + + } + + public JSONObject getAccessToken(){ + String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; + Map requestUrlParam = new HashMap<>(); + //小程序appId + requestUrlParam.put("appid", appId); + //小程序secret + requestUrlParam.put("secret", secrete); + //默认参数 + requestUrlParam.put("grant_type", "client_credential"); + return JSON.parseObject(HttpUtil.get(requestUrl,requestUrlParam)); + } + + public static void main(String[] args) { + String id ="kSxJL9TR4s_UmOmNLE"; +// sendStockWarnMsg("123", "1231", "1231", "23321", id); + } + + + public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { + log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); + JSONObject object= getAccessToken(); + String accessToken=object.get("access_token")+""; + + JSONObject object1=new JSONObject(); + + object1.put("template_id", tempId); + object1.put("touser", toUserOpenId); + object1.put("data",data); + + object1.put("miniprogram_state","trial"); + object1.put("lang","zh_CN"); + + String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); + log.info("微信模板消息发送成功,相应内容:{}",response); + JSONObject resObj=JSONObject.parseObject(response); + if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ + return resObj; + } + + throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); + } + + public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { + Map data = new HashMap() {{ + put("thing1", new HashMap() {{ + put("value", shopName); + }}); + put("phrase2", new HashMap() {{ + put("value", state); + }}); + put("character_string3", new HashMap() {{ + put("value", callNum); + }}); + put("character_string4", new HashMap() {{ + put("value", currentNum); + }}); + put("thing5", new HashMap() {{ + put("value", note); + }}); + }}; + log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); + try { + sendTempMsg(currentCallTempId, openId, data); + } catch (Exception e) { + log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); + } + } +}