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 666096ed..9e6ecc68 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 @@ -6,7 +6,6 @@ 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.CallNumPrintDTO; import cn.ysk.cashier.dto.calltable.*; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.entity.TbCallConfig; @@ -27,7 +26,6 @@ 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; -import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; @@ -254,14 +252,31 @@ public class TbCallServiceImpl implements TbCallService { .orderByAsc(TbCallQueue::getCreateTime) .page(new Page<>(1, 1)).getRecords(); + if (current.isEmpty()) { + throw new BadRequestException("当前用户未排号"); + } + 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()); + wxMiniUtils.sendCurrentOrNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(callQueue.getState())), + callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", callQueue.getOpenId(), false); + boolean flag = callQueueService.updateById(callQueue); - return callQueueService.updateById(callQueue); + TbCallConfig config = getConfig(callQueueDTO.getShopId()); + // 临近用户提醒 + List nearList = callQueueService.lambdaQuery() + .eq(TbCallQueue::getCallTableId, callQueue.getCallTableId()) + .eq(TbCallQueue::getCreateDay, DateUtil.today()) + .gt(TbCallQueue::getId, current.get(0).getId()) + .page(new Page<>(config.getNearNum(), 1)).getRecords(); + if (!nearList.isEmpty()) { + TbCallQueue nearQueue = nearList.get(0); + wxMiniUtils.sendCurrentOrNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(nearQueue.getState())), + nearQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", nearQueue.getOpenId(), true); + } + return flag; } private String getStrByState(Integer state) { @@ -445,7 +460,7 @@ public class TbCallServiceImpl implements TbCallService { } @Override - public Object getConfig(Integer shopId) { + public TbCallConfig getConfig(Integer shopId) { TbCallConfig config = tbCallConfigService.lambdaQuery().eq(TbCallConfig::getShopId, shopId).one(); if (config == null) { config = new TbCallConfig(); 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..68338a59 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 @@ -25,6 +25,10 @@ public class WxMiniUtils { @Value("${wx.mini.user.msgId.currentCall}") private String currentCallTempId; + @Value("${wx.mini.user.msgId.nearCall}") + private String nearCallTempId; + @Value("${wx.mini.user.msgId.passCall}") + private String passCallTempId; static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); @@ -61,8 +65,8 @@ public class WxMiniUtils { } - public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data) { - log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); + public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map data, String note) { + log.info("开始发送" + note + "模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); JSONObject object= getAccessToken(); String accessToken=object.get("access_token")+""; @@ -85,7 +89,7 @@ public class WxMiniUtils { throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); } - public void sendNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { + public void sendCurrentOrNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId, boolean isNear) { Map data = new HashMap() {{ put("thing1", new HashMap() {{ put("value", shopName); @@ -103,9 +107,33 @@ public class WxMiniUtils { put("value", note); }}); }}; - log.info("开始发送排号到号消息, 接收用户openId: {}, 消息数据: {}", openId, data); try { - sendTempMsg(currentCallTempId, openId, data); + sendTempMsg(isNear ? nearCallTempId : currentCallTempId, openId, data, "排队到号"); + } catch (Exception e) { + log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage()); + } + } + + public void sendPassCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) { + Map data = new HashMap() {{ + put("thing1", new HashMap() {{ + put("value", shopName); + }}); + put("character_string2", new HashMap() {{ + put("value", callNum); + }}); + put("character_string3", new HashMap() {{ + put("value", currentNum); + }}); + put("phrase4", new HashMap() {{ + put("value", state); + }}); + put("thing5", new HashMap() {{ + put("value", note); + }}); + }}; + 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 0b92fa56..cfb6b464 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -97,9 +97,9 @@ wx: appId: wxd88fffa983758a30 secrete: a34a61adc0602118b49400baa8812454 msgId: - nearCall: yxOjWK-KjMEZ_BaHWqDJJpHiUPXN6JWgr7u9y65RIWM - currentCall: 3BgFazRpVlvreh5z9u4cNPVeclXKSQfh-r3x2_bYx4 - passCall: qUhvEfvCtlcBA3DOn3QMgsGOolrEpyr0YBh99i-AUgw + nearCall: yxOjWK-KjMEZ_BaHWqDJJpHiUPXN6JWqr7u9y65RIWM + currentCall: 3BgFazRpVlvreh5z9u4cNP_VeclXKSQfh-r3x2_bYx4 + passCall: qUhvEfvCtIcBA3DOn3QMqsGOolrEpyr0YBh99i-AUqw page: call: https://cashier.sxczgkj.cn/make?shopId={}&queueId={}