feat: 排队叫号接口实现

This commit is contained in:
张松
2024-12-10 11:07:22 +08:00
parent c1cbdba2e3
commit 84971187ca
31 changed files with 1141 additions and 49 deletions

View File

@@ -21,7 +21,12 @@
</properties>
<dependencies>
<!-- zxing生成二维码 -->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -0,0 +1,111 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.entity.dto.calltable.*;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.service.TbCallService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
/**
* 叫号
*/
@RestController
@RequestMapping("/callTable")
@AllArgsConstructor
public class TbCallTableController {
private static final Logger log = LoggerFactory.getLogger(TbCallTableController.class);
private final TbCallService tbCallService;
@GetMapping
public Result 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 Result.success(CodeEnum.SUCCESS, tbCallService.get(page, size, shopId, callTableId, state));
}
@PostMapping
public Result add(@Validated @RequestBody CallTableDTO addCallTableDTO) {
return Result.success(CodeEnum.SUCCESS, tbCallService.add(addCallTableDTO));
}
@PutMapping
public Result update(@Validated @RequestBody UpdateCallTableDTO callTableDTO) {
return Result.success(CodeEnum.SUCCESS, tbCallService.update(callTableDTO));
}
@DeleteMapping
public Result delete(@Validated @RequestBody BaseCallTableDTO baseCallTableDTO) {
return Result.success(CodeEnum.SUCCESS, tbCallService.delete(baseCallTableDTO));
}
@PostMapping("takeNumber")
public Result takeNumber(@Validated @RequestBody TakeNumberDTO takeNumberDTO) {
return Result.success(CodeEnum.SUCCESS, tbCallService.takeNumber(takeNumberDTO));
}
@GetMapping("takeNumberCode")
public Result takeNumberCode(@RequestParam Integer shopId, @RequestParam Integer callTableId) {
return Result.success(CodeEnum.SUCCESS, tbCallService.takeNumberCode(shopId, callTableId));
}
@PostMapping("call")
public Result call(@Validated @RequestBody CallQueueDTO callQueueDTO) {
try {
return Result.success(CodeEnum.SUCCESS, tbCallService.call(callQueueDTO));
} catch (MsgException e) {
log.error("异常", e);
return Result.success(CodeEnum.SUCCESS, new HashMap<String, Object>() {{
put("state", "0");
put("message", e.getMessage());
}});
}
}
@PutMapping("updateState")
public Result confirm(@Validated @RequestBody UpdateCallQueueDTO updateCallQueueDTO) {
return Result.success(CodeEnum.SUCCESS, tbCallService.updateInfo(updateCallQueueDTO));
}
@GetMapping("queue")
public Result 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 Result.success(CodeEnum.SUCCESS, tbCallService.getQueue(shopId, callTableId, state, page, size));
}
@GetMapping("callRecord")
public Result getCallRecord(@RequestParam Integer shopId, @RequestParam(required = false) Integer callTableId,
@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
return Result.success(CodeEnum.SUCCESS, tbCallService.getCallRecord(shopId, callTableId, page, size));
}
@GetMapping("config")
public Result getConfig(@RequestParam Integer shopId) {
return Result.success(CodeEnum.SUCCESS, tbCallService.getConfig(shopId));
}
@PutMapping("config")
public Result updateConfig(@RequestBody UpdateConfigDTO configDTO) {
return Result.success(CodeEnum.SUCCESS, tbCallService.updateConfig(configDTO));
}
}

View File

@@ -8,7 +8,7 @@ import java.io.Serializable;
import java.util.Date;
/**
*
* 叫号配置表
* @TableName tb_call_config
*/
@TableName(value ="tb_call_config")
@@ -65,14 +65,9 @@ public class TbCallConfig implements Serializable {
private Date updateTime;
/**
* 是否过号顺延
* 临近几桌提醒
*/
private Integer isPostpone;
/**
* 顺延号码数量
*/
private Integer postponeNum;
private Integer nearNum;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@@ -218,31 +213,17 @@ public class TbCallConfig implements Serializable {
}
/**
* 是否过号顺延
* 临近几桌提醒
*/
public Integer getIsPostpone() {
return isPostpone;
public Integer getNearNum() {
return nearNum;
}
/**
* 是否过号顺延
* 临近几桌提醒
*/
public void setIsPostpone(Integer isPostpone) {
this.isPostpone = isPostpone;
}
/**
* 顺延号码数量
*/
public Integer getPostponeNum() {
return postponeNum;
}
/**
* 顺延号码数量
*/
public void setPostponeNum(Integer postponeNum) {
this.postponeNum = postponeNum;
public void setNearNum(Integer nearNum) {
this.nearNum = nearNum;
}
@Override
@@ -267,8 +248,7 @@ public class TbCallConfig implements Serializable {
&& (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getIsPostpone() == null ? other.getIsPostpone() == null : this.getIsPostpone().equals(other.getIsPostpone()))
&& (this.getPostponeNum() == null ? other.getPostponeNum() == null : this.getPostponeNum().equals(other.getPostponeNum()));
&& (this.getNearNum() == null ? other.getNearNum() == null : this.getNearNum().equals(other.getNearNum()));
}
@Override
@@ -285,8 +265,7 @@ public class TbCallConfig implements Serializable {
result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getIsPostpone() == null) ? 0 : getIsPostpone().hashCode());
result = prime * result + ((getPostponeNum() == null) ? 0 : getPostponeNum().hashCode());
result = prime * result + ((getNearNum() == null) ? 0 : getNearNum().hashCode());
return result;
}
@@ -306,8 +285,7 @@ public class TbCallConfig implements Serializable {
sb.append(", shopId=").append(shopId);
sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", isPostpone=").append(isPostpone);
sb.append(", postponeNum=").append(postponeNum);
sb.append(", nearNum=").append(nearNum);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();

View File

@@ -8,7 +8,7 @@ import java.io.Serializable;
import java.util.Date;
/**
*
* 叫号排号表
* @TableName tb_call_queue
*/
@TableName(value ="tb_call_queue")
@@ -109,6 +109,11 @@ public class TbCallQueue implements Serializable {
*/
private String createDay;
/**
* 是否已经顺延 0 未顺延 1已顺延一次 2顺延一次仍然过号
*/
private Integer isPostpone;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@@ -378,6 +383,20 @@ public class TbCallQueue implements Serializable {
this.createDay = createDay;
}
/**
* 是否已经顺延 0 未顺延 1已顺延一次 2顺延一次仍然过号
*/
public Integer getIsPostpone() {
return isPostpone;
}
/**
* 是否已经顺延 0 未顺延 1已顺延一次 2顺延一次仍然过号
*/
public void setIsPostpone(Integer isPostpone) {
this.isPostpone = isPostpone;
}
@Override
public boolean equals(Object that) {
if (this == that) {
@@ -408,7 +427,8 @@ public class TbCallQueue implements Serializable {
&& (this.getSubState() == null ? other.getSubState() == null : this.getSubState().equals(other.getSubState()))
&& (this.getConfirmTime() == null ? other.getConfirmTime() == null : this.getConfirmTime().equals(other.getConfirmTime()))
&& (this.getCallNum() == null ? other.getCallNum() == null : this.getCallNum().equals(other.getCallNum()))
&& (this.getCreateDay() == null ? other.getCreateDay() == null : this.getCreateDay().equals(other.getCreateDay()));
&& (this.getCreateDay() == null ? other.getCreateDay() == null : this.getCreateDay().equals(other.getCreateDay()))
&& (this.getIsPostpone() == null ? other.getIsPostpone() == null : this.getIsPostpone().equals(other.getIsPostpone()));
}
@Override
@@ -434,6 +454,7 @@ public class TbCallQueue implements Serializable {
result = prime * result + ((getConfirmTime() == null) ? 0 : getConfirmTime().hashCode());
result = prime * result + ((getCallNum() == null) ? 0 : getCallNum().hashCode());
result = prime * result + ((getCreateDay() == null) ? 0 : getCreateDay().hashCode());
result = prime * result + ((getIsPostpone() == null) ? 0 : getIsPostpone().hashCode());
return result;
}
@@ -462,6 +483,7 @@ public class TbCallQueue implements Serializable {
sb.append(", confirmTime=").append(confirmTime);
sb.append(", callNum=").append(callNum);
sb.append(", createDay=").append(createDay);
sb.append(", isPostpone=").append(isPostpone);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();

View File

@@ -0,0 +1,13 @@
package com.chaozhanggui.system.cashierservice.entity.dto.calltable;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class BaseCallTableDTO {
@NotNull
private Integer callTableId;
@NotNull
private Integer shopId;
}

View File

@@ -0,0 +1,13 @@
package com.chaozhanggui.system.cashierservice.entity.dto.calltable;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class CallQueueDTO{
@NotNull
private Integer callQueueId;
@NotNull
private Integer shopId;
}

View File

@@ -0,0 +1,29 @@
package com.chaozhanggui.system.cashierservice.entity.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;
private Integer isPostpone;
private Integer postponeNum;
}

View File

@@ -0,0 +1,18 @@
package com.chaozhanggui.system.cashierservice.entity.dto.calltable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
@EqualsAndHashCode(callSuper = true)
@Data
public class TakeNumberDTO extends BaseCallTableDTO{
private Integer userId;
@NotEmpty
@Pattern(regexp = "^1\\d{10}$|^(0\\d{2,3}-?|\\(0\\d{2,3}\\))?[1-9]\\d{4,7}(-\\d{1,8})?$",message = "手机号码格式错误")
private String phone;
private String note;
private String name;
}

View File

@@ -0,0 +1,15 @@
package com.chaozhanggui.system.cashierservice.entity.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 Integer state;
}

View File

@@ -0,0 +1,23 @@
package com.chaozhanggui.system.cashierservice.entity.dto.calltable;
import lombok.Data;
import javax.validation.constraints.Min;
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;
}

View File

@@ -0,0 +1,16 @@
package com.chaozhanggui.system.cashierservice.entity.dto.calltable;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class UpdateConfigDTO {
@NotNull
private Integer shopId;
private Integer isOnline;
private String bgCover;
private Integer isPostpone;
private Integer postponeNum;
private Integer nearNum;
}

View File

@@ -0,0 +1,12 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
import com.chaozhanggui.system.cashierservice.entity.TbCallQueue;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class CallRecordVO extends TbCallQueue {
private String note;
private Long sinceAt;
}

View File

@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author Administrator
* @description 针对表【tb_call_config】的数据库操作Mapper
* @createDate 2024-09-19 14:35:05
* @description 针对表【tb_call_config(叫号配置表)】的数据库操作Mapper
* @createDate 2024-12-10 10:12:45
* @Entity com.chaozhanggui.system.cashierservice.entity.TbCallConfig
*/
public interface TbCallConfigMapper extends BaseMapper<TbCallConfig> {

View File

@@ -1,16 +1,23 @@
package com.chaozhanggui.system.cashierservice.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chaozhanggui.system.cashierservice.entity.TbCallQueue;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chaozhanggui.system.cashierservice.entity.vo.CallRecordVO;
import org.apache.ibatis.annotations.Select;
/**
* @author Administrator
* @description 针对表【tb_call_queue】的数据库操作Mapper
* @createDate 2024-09-19 14:35:05
* @description 针对表【tb_call_queue(叫号排号表)】的数据库操作Mapper
* @createDate 2024-12-10 10:12:45
* @Entity com.chaozhanggui.system.cashierservice.entity.TbCallQueue
*/
public interface TbCallQueueMapper extends BaseMapper<TbCallQueue> {
@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.state in (3, 2, 1) order by a.create_time desc")
Page<CallRecordVO> selectCallRecord(Integer shopId, Integer callTableId, Page<Object> objectPage);
}

View File

@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author Administrator
* @description 针对表【tb_call_table】的数据库操作Mapper
* @createDate 2024-09-19 14:35:05
* @description 针对表【tb_call_table(叫号桌型表)】的数据库操作Mapper
* @createDate 2024-12-10 10:12:45
* @Entity com.chaozhanggui.system.cashierservice.entity.TbCallTable
*/
public interface TbCallTableMapper extends BaseMapper<TbCallTable> {

View File

@@ -0,0 +1,13 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.TbCallConfig;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author Administrator
* @description 针对表【tb_call_config(叫号配置表)】的数据库操作Service
* @createDate 2024-12-10 10:12:45
*/
public interface TbCallConfigService extends IService<TbCallConfig> {
}

View File

@@ -0,0 +1,13 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.TbCallQueue;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author Administrator
* @description 针对表【tb_call_queue(叫号排号表)】的数据库操作Service
* @createDate 2024-12-10 10:12:45
*/
public interface TbCallQueueService extends IService<TbCallQueue> {
}

View File

@@ -0,0 +1,30 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.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);
Object getCallRecord(Integer shopId, Integer callTableId, Integer page, Integer size);
Object getConfig(Integer shopId);
Object updateConfig(UpdateConfigDTO configDTO);
}

View File

@@ -0,0 +1,13 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.TbCallTable;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author Administrator
* @description 针对表【tb_call_table(叫号桌型表)】的数据库操作Service
* @createDate 2024-12-10 10:12:45
*/
public interface TbCallTableService extends IService<TbCallTable> {
}

View File

@@ -0,0 +1,22 @@
package com.chaozhanggui.system.cashierservice.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chaozhanggui.system.cashierservice.entity.TbCallConfig;
import com.chaozhanggui.system.cashierservice.service.TbCallConfigService;
import com.chaozhanggui.system.cashierservice.mapper.TbCallConfigMapper;
import org.springframework.stereotype.Service;
/**
* @author Administrator
* @description 针对表【tb_call_config(叫号配置表)】的数据库操作Service实现
* @createDate 2024-12-10 10:12:45
*/
@Service
public class TbCallConfigServiceImpl extends ServiceImpl<TbCallConfigMapper, TbCallConfig>
implements TbCallConfigService{
}

View File

@@ -0,0 +1,22 @@
package com.chaozhanggui.system.cashierservice.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chaozhanggui.system.cashierservice.entity.TbCallQueue;
import com.chaozhanggui.system.cashierservice.service.TbCallQueueService;
import com.chaozhanggui.system.cashierservice.mapper.TbCallQueueMapper;
import org.springframework.stereotype.Service;
/**
* @author Administrator
* @description 针对表【tb_call_queue(叫号排号表)】的数据库操作Service实现
* @createDate 2024-12-10 10:12:45
*/
@Service
public class TbCallQueueServiceImpl extends ServiceImpl<TbCallQueueMapper, TbCallQueue>
implements TbCallQueueService{
}

View File

@@ -0,0 +1,575 @@
package com.chaozhanggui.system.cashierservice.service.impl;
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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.calltable.*;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mapper.TbCallQueueMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserMapper;
import com.chaozhanggui.system.cashierservice.service.TbCallConfigService;
import com.chaozhanggui.system.cashierservice.service.TbCallQueueService;
import com.chaozhanggui.system.cashierservice.service.TbCallService;
import com.chaozhanggui.system.cashierservice.service.TbCallTableService;
import com.chaozhanggui.system.cashierservice.util.RabbitMsgUtils;
import com.chaozhanggui.system.cashierservice.util.RedisCst;
import com.chaozhanggui.system.cashierservice.util.Utils;
import com.chaozhanggui.system.cashierservice.util.WxAccountUtil;
import org.springframework.beans.factory.annotation.Value;
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
public class TbCallServiceImpl implements TbCallService {
@Value("${wx.mini.page.call}")
private String callPageUrl;
private final TbCallTableService callTableService;
private final TbCallQueueService callQueueService;
private final MpShopUserMapper shopUserMapper;
private final TbShopInfoMapper shopInfoMapper;
private final StringRedisTemplate redisTemplate;
private final TbCallQueueMapper tbCallQueueMapper;
private final WxAccountUtil wxMiniUtils;
private final TbCallConfigService tbCallConfigService;
private final RabbitMsgUtils rabbitMsgUtils;
public TbCallServiceImpl(TbCallTableService callTableService, TbCallQueueService callQueueService,
MpShopUserMapper shopUserMapper, TbShopInfoMapper shopInfoMapper,
StringRedisTemplate redisTemplate, TbCallQueueMapper tbCallQueueMapper,
WxAccountUtil wxMiniUtils, TbCallConfigService tbCallConfigService, RabbitMsgUtils rabbitMsgUtils) {
this.callTableService = callTableService;
this.callQueueService = callQueueService;
this.shopUserMapper = shopUserMapper;
this.shopInfoMapper = shopInfoMapper;
this.redisTemplate = redisTemplate;
this.tbCallQueueMapper = tbCallQueueMapper;
this.wxMiniUtils = wxMiniUtils;
this.tbCallConfigService = tbCallConfigService;
this.rabbitMsgUtils = rabbitMsgUtils;
}
@Override
public Object add(CallTableDTO addCallTableDTO) {
Integer 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 MsgException("名称或前缀已存在");
}
TbCallTable callTable = new TbCallTable();
BeanUtil.copyProperties(addCallTableDTO, callTable);
callTable.setCreateTime(DateUtil.date());
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 MsgException("桌型不存在");
}
TbCallTable newInfo = new TbCallTable();
BeanUtil.copyProperties(callTableDTO, newInfo);
newInfo.setId(callTable.getId());
newInfo.setUpdateTime(DateUtil.date());
return callTableService.updateById(newInfo);
}
@Override
public Object delete(BaseCallTableDTO baseCallTableDTO) {
return callTableService.remove(new LambdaQueryWrapper<TbCallTable>()
.eq(TbCallTable::getId, baseCallTableDTO.getCallTableId())
.eq(TbCallTable::getShopId, baseCallTableDTO.getShopId()));
}
private String getCallNumber(Integer shopId, TbCallTable callTable) {
return Utils.runFunAndCheckKey(() -> {
String callNumKey = RedisCst.getTableCallNumKey(shopId, callTable.getId());
String value = redisTemplate.opsForValue().get(callNumKey);
AtomicReference<String> 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 MsgException("生成排队号码失败");
}
}else {
value = String.valueOf((Integer.parseInt(value) + 1));
redisTemplate.opsForValue().set(callNumKey, value);
return callTable.getPrefix() + value;
}
}, redisTemplate, RedisCst.getLockKey("UPDATE_TABLE", shopId, callTable.getId()));
}
@Override
public Object takeNumber(TakeNumberDTO takeNumberDTO) {
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(takeNumberDTO.getShopId());
if (shopInfo == null) {
throw new MsgException("店铺信息不存在");
}
TbCallTable callTable = callTableService.lambdaQuery()
.eq(TbCallTable::getShopId, takeNumberDTO.getShopId())
.eq(TbCallTable::getId, takeNumberDTO.getCallTableId()).one();
if (callTable == null) {
throw new MsgException("桌型不存在");
}
// 查询当前
// 拿取系统内部用户信息
TbCallQueue callQueue;
if (takeNumberDTO.getUserId() != null) {
TbShopUser shopUser = shopUserMapper.selectOne(new LambdaQueryWrapper<TbShopUser>()
.eq(TbShopUser::getStatus, 1)
.eq(TbShopUser::getShopId, takeNumberDTO.getShopId())
.eq(TbShopUser::getId, takeNumberDTO.getUserId()));
if (shopUser == null) {
throw new MsgException("用户不存在");
}
callQueue = callQueueService.lambdaQuery()
.eq(TbCallQueue::getUserId, shopUser.getId())
.eq(TbCallQueue::getShopId, takeNumberDTO.getShopId())
.in(TbCallQueue::getState, 0, 1)
.eq(TbCallQueue::getCreateDay, DateUtil.today())
.ne(TbCallQueue::getIsPostpone, 2)
.eq(TbCallQueue::getCallTableId, takeNumberDTO.getCallTableId()).one();
if (callQueue != null) {
throw new MsgException("当前用户已取号");
}
callQueue = new TbCallQueue();
BeanUtil.copyProperties(takeNumberDTO, callQueue);
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 MsgException("手机号或openId不能为空");
// }
callQueue = callQueueService.lambdaQuery()
.eq(TbCallQueue::getPhone, takeNumberDTO.getPhone())
.eq(TbCallQueue::getShopId, takeNumberDTO.getShopId())
.eq(TbCallQueue::getCreateDay, DateUtil.today())
.in(TbCallQueue::getState, 0, 1)
.ne(TbCallQueue::getIsPostpone, 2)
.eq(TbCallQueue::getCallTableId, takeNumberDTO.getCallTableId()).one();
if (callQueue != null) {
throw new MsgException("当前用户已取号");
}
callQueue = new TbCallQueue();
BeanUtil.copyProperties(takeNumberDTO, callQueue);
callQueue.setPhone(takeNumberDTO.getPhone());
// callQueue.setOpenId(takeNumberDTO.getOpenId());
callQueue.setSubState(0);
}
callQueue.setCreateDay(DateUtil.today());
callQueue.setCallNum(getCallNumber(takeNumberDTO.getShopId(), callTable));
callQueue.setCreateTime(DateUtil.date());
callQueue.setShopId(shopInfo.getId());
callQueue.setShopName(shopInfo.getShopName());
callQueueService.save(callQueue);
// 打印排号票信息
rabbitMsgUtils.printCallNumTicket(callQueue.getId(), callQueue.getShopId());
HashMap<String, Object> data = new HashMap<>();
data.put("tableName", callTable.getName());
data.put("tableNote", callTable.getNote());
data.put("callNum", callQueue.getCallNum());
return data;
}
@Override
public Object call(CallQueueDTO callQueueDTO) {
TbCallQueue callQueue = callQueueService.lambdaQuery()
.notIn(TbCallQueue::getState, -1, 2)
.eq(TbCallQueue::getCreateDay, DateUtil.today())
.eq(TbCallQueue::getId, callQueueDTO.getCallQueueId())
.eq(TbCallQueue::getShopId, callQueueDTO.getShopId())
.one();
if (callQueue == null) {
throw new MsgException("叫号用户不存在");
}
callQueue.setState(1);
callQueue.setCallCount(callQueue.getCallCount() + 1);
callQueue.setCallTime(DateUtil.date());
callQueueService.updateById(callQueue);
if (callQueue.getSubState().equals(0)) {
return new HashMap<String, Object>(){{
put("state", "-1");
}};
}
// 发送模板消息通知用户
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(callQueue.getShopId());
if (shopInfo == null) {
throw new MsgException("店铺信息不存在");
}
List<TbCallQueue> current = callQueueService.lambdaQuery()
.eq(TbCallQueue::getCallTableId, callQueue.getCallTableId())
.eq(TbCallQueue::getCreateDay, DateUtil.today())
.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())) {
return new HashMap<String, Object>(){{
put("state", "-1");
}};
}
wxMiniUtils.sendCurrentOrNearCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(callQueue.getState())),
callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "排号信息", callQueue.getOpenId(), false);
TbCallConfig config = getConfig(callQueueDTO.getShopId());
// 临近用户提醒
List<TbCallQueue> 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 new HashMap<String, Object>(){{
put("state", "1");
}};
}
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()
.eq(TbCallQueue::getShopId, updateCallQueueDTO.getShopId())
.eq(TbCallQueue::getCreateDay, DateUtil.today())
.eq(TbCallQueue::getId, updateCallQueueDTO.getCallQueueId()).one();
if (callQueue == null) {
throw new MsgException("叫号用户不存在");
}
switch (updateCallQueueDTO.getState()) {
case -1:
callQueue.setCancelTime(DateUtil.date());
break;
case 0:
callQueue.setState(0);
break;
case 1:
if (callQueue.getSubState().equals(0)) {
throw new MsgException("当前用户未订阅微信提醒");
}
callQueue.setState(1);
callQueue.setCallCount(callQueue.getCallCount() + 1);
callQueue.setCallTime(DateUtil.date());
break;
case 2:
callQueue.setConfirmTime(DateUtil.date());
break;
case 3:
callQueue.setPassTime(DateUtil.date());
// 已经顺延
callQueue.setIsPostpone(callQueue.getIsPostpone() == null ? 1 : callQueue.getIsPostpone() == 0 ? 1 : 2);
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(callQueue.getShopId());
if (shopInfo == null) {
throw new MsgException("店铺信息不存在");
}
if(StrUtil.isBlank(callQueue.getOpenId()) && callQueue.getSubState() != 1) {
break;
}
TbCallTable callTable = callTableService.getById(callQueue.getCallTableId());
Integer isPostpone = callTable.getIsPostpone();
Integer postponeNum = callTable.getPostponeNum();
// 判断是否需要顺延, 暂时注释
if (false && callQueue.getIsPostpone() == 0 && isPostpone != null && isPostpone == 1 && postponeNum != null && postponeNum > 0) {
// 查询当前桌以及顺延桌数
List<TbCallQueue> current = callQueueService.lambdaQuery()
.eq(TbCallQueue::getCallTableId, callQueue.getCallTableId())
.eq(TbCallQueue::getCreateDay, DateUtil.today())
.eq(TbCallQueue::getShopId, callTable.getShopId())
.ge(TbCallQueue::getId, callQueue.getId())
.orderByAsc(TbCallQueue::getCreateTime)
.page(new Page<>(1, postponeNum + 1)) // 获取当前桌和顺延的桌数
.getRecords();
// 确保有足够的桌可以顺延
if (current.size() > 1) {
// 获取当前桌以及顺延桌
TbCallQueue currentTable = new TbCallQueue();
BeanUtil.copyProperties(current.get(0), currentTable);
// 顺延替换信息,将每一张顺延桌向前移动
for (int i = 0; i < current.size() - 1; i++) {
exchangeCallQueueInfo(current.get(i), current.get(i + 1)); // 当前桌替换为顺延桌
}
exchangeCallQueueInfo(current.get(current.size() - 1), currentTable);
callQueue = current.get(current.size() - 1);
// 更新数据库中的桌号信息
callQueueService.updateBatchById(current);
}
}
List<TbCallQueue> current = callQueueService.lambdaQuery()
.eq(TbCallQueue::getCallTableId, callQueue.getCallTableId())
.eq(TbCallQueue::getCreateDay, DateUtil.today())
.and(r -> {
r.eq(TbCallQueue::getState, 1)
.or()
.eq(TbCallQueue::getState, 0);
})
.orderByAsc(TbCallQueue::getCreateTime)
.page(new Page<>(1, 1)).getRecords();
wxMiniUtils.sendPassCallMsg(shopInfo.getShopName(), getStrByState(Integer.valueOf(updateCallQueueDTO.getState())),
callQueue.getCallNum(), current.isEmpty() ? "" : current.get(0).getCallNum(), "即将过号", callQueue.getOpenId());
break;
default:
throw new MsgException("错误类型");
}
callQueue.setState(updateCallQueueDTO.getState());
return callQueueService.updateById(callQueue);
}
private void exchangeCallQueueInfo(TbCallQueue setCallQueue, TbCallQueue copyCallQueue) {
setCallQueue.setOpenId(copyCallQueue.getOpenId());
setCallQueue.setState(copyCallQueue.getState());
setCallQueue.setSubState(copyCallQueue.getSubState());
setCallQueue.setCreateTime(copyCallQueue.getCreateTime());
setCallQueue.setName(copyCallQueue.getName());
setCallQueue.setNote(copyCallQueue.getNote());
setCallQueue.setCallNum(copyCallQueue.getCallNum());
setCallQueue.setCallTime(copyCallQueue.getCallTime());
setCallQueue.setCallCount(copyCallQueue.getCallCount());
setCallQueue.setPassTime(copyCallQueue.getPassTime());
setCallQueue.setCancelTime(copyCallQueue.getCancelTime());
setCallQueue.setUserId(copyCallQueue.getUserId());
setCallQueue.setConfirmTime(copyCallQueue.getConfirmTime());
}
@Override
public Object get(Integer page, Integer size, Integer shopId, Integer callTableId, Integer state) {
LambdaQueryWrapper<TbCallTable> query = new LambdaQueryWrapper<TbCallTable>()
.eq(TbCallTable::getShopId, shopId)
.eq(TbCallTable::getState, 1);
if (callTableId != null) {
query.eq(TbCallTable::getId, callTableId);
}
if (state != null) {
query.eq(TbCallTable::getState, state);
}
Page<TbCallTable> pageInfo = callTableService.page(new Page<>(page, size), query);
ArrayList<Map<String, Object>> info = new ArrayList<>();
Long totalCount = 0L;
for (TbCallTable item : pageInfo.getRecords()) {
LambdaQueryChainWrapper<TbCallQueue> q = callQueueService.lambdaQuery()
.eq(TbCallQueue::getCallTableId, item.getId())
.eq(TbCallQueue::getShopId, shopId)
.eq(TbCallQueue::getCreateDay, DateUtil.today())
.in(TbCallQueue::getState, 0, 1);
Integer count = q.count();
totalCount += count;
Map<String, Object> map = BeanUtil.beanToMap(item, false, false);
map.put("totalCount", count);
map.put("isPostpone", item.getIsPostpone() == 1);
info.add(map);
}
Map<String, Object> toMap = BeanUtil.beanToMap(pageInfo);
toMap.put("records", info);
toMap.put("totalCount", totalCount);
return toMap;
}
@Override
public Object takeNumberCode(Integer shopId, Integer callTableId) {
// 创建二维码配置对象设置宽度和高度为400
QrConfig config = new QrConfig(400, 400);
// 使用字节数组输出流来存储二维码图片
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 生成二维码图片,输出到字节数组输出流
QrCodeUtil.generate(StrUtil.format(callPageUrl, shopId, ""), 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<Integer> tableIds;
if (callTableId != null) {
tableIds = Collections.singletonList(callTableId);
}else {
List<TbCallTable> 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<TbCallQueue> query = callQueueService.lambdaQuery()
.eq(TbCallQueue::getShopId, shopId)
.eq(TbCallQueue::getCreateDay, DateUtil.today())
.in(TbCallQueue::getCallTableId, tableIds);
state = null;
if (state != null) {
query.eq(TbCallQueue::getState, state);
}else {
query.in(TbCallQueue::getState, 0, 1);
}
Page<TbCallQueue> pageInfo = query
.orderByAsc(TbCallQueue::getCreateTime)
.orderByDesc(TbCallQueue::getState)
.page(new Page<>(page, size));
List<TbCallQueue> list1 = pageInfo.getRecords();
// 创建返回的结果集
List<Map<String, Object>> 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<String, Object> map = BeanUtil.beanToMap(calling, false, false);
map.put("waitingCount", waitingCount);
// 将该map加入结果集
resultList.add(map);
}
Map<String, Object> toMap = BeanUtil.beanToMap(pageInfo, false, false);
toMap.put("records", resultList);
// 返回结果列表
return toMap;
}
@Override
public Object getCallRecord(Integer shopId, Integer callTableId, Integer page, Integer size) {
return tbCallQueueMapper.selectCallRecord(shopId, callTableId, new Page<>(page, size));
}
@Override
public TbCallConfig getConfig(Integer shopId) {
TbCallConfig config = tbCallConfigService.lambdaQuery().eq(TbCallConfig::getShopId, shopId).one();
if (config == null) {
config = new TbCallConfig();
config.setShopId(shopId);
config.setCreateTime(DateUtil.date());
tbCallConfigService.save(config);
config = tbCallConfigService.lambdaQuery().eq(TbCallConfig::getShopId, shopId).one();
}
return config;
}
@Override
public Object updateConfig(UpdateConfigDTO configDTO) {
TbCallConfig config = tbCallConfigService.lambdaQuery().eq(TbCallConfig::getShopId, configDTO.getShopId()).one();
if (config == null) {
throw new MsgException("未查询到配置信息");
}
TbCallConfig tbCallConfig = new TbCallConfig();
BeanUtil.copyProperties(configDTO, tbCallConfig);
tbCallConfig.setId(config.getId());
tbCallConfig.setUpdateTime(DateUtil.date());
return tbCallConfigService.updateById(tbCallConfig);
}
}

View File

@@ -0,0 +1,22 @@
package com.chaozhanggui.system.cashierservice.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chaozhanggui.system.cashierservice.entity.TbCallTable;
import com.chaozhanggui.system.cashierservice.service.TbCallTableService;
import com.chaozhanggui.system.cashierservice.mapper.TbCallTableMapper;
import org.springframework.stereotype.Service;
/**
* @author Administrator
* @description 针对表【tb_call_table(叫号桌型表)】的数据库操作Service实现
* @createDate 2024-12-10 10:12:45
*/
@Service
public class TbCallTableServiceImpl extends ServiceImpl<TbCallTableMapper, TbCallTable>
implements TbCallTableService{
}

View File

@@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.util;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
@@ -80,4 +81,20 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
public void updateCons(JSONObject jsonObject1) {
sendMsg(RabbitConstants.EXCHANGE_CONS, RabbitConstants.ROUTING_KEY_CONS, jsonObject1, "储值卡记录", true);
}
public void printCallNumTicket(Integer callQueueId, Integer shopId) {
CallNumPrintDTO printDTO = new CallNumPrintDTO();
printDTO.setCallQueueId(callQueueId);
printDTO.setShopId(shopId);
try {
JSONObject currentUserInfo = TokenUtil.getCurrentUserInfo();
log.info("用户信息: {}", currentUserInfo);
printDTO.setCurrentUserId(currentUserInfo.getLong("accountId"));
printDTO.setCurrentUserName(currentUserInfo.getString("name"));
printDTO.setCurrentUserNickName(currentUserInfo.getString("nickname"));
} catch (Exception e) {
log.error("获取当前用户信息失败", e);
}
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_CALL_TABLE, printDTO, "排号小票打印", true);
}
}

View File

@@ -30,7 +30,8 @@ public class RedisCst {
// 选择人数锁
public static final String CHOSE_TABLE_COUNT = "CHOSE_TABLE_COUNT";
// 排队取号全局号码
static String TABLE_CALL_NUMBER = "TABLE_CALL_NUMBER:";
public static String getCurrentOrderKey(String tableId, String shopId) {
@@ -50,4 +51,8 @@ public class RedisCst {
}
return key.toString();
}
public static String getTableCallNumKey(Integer shopId, Integer callTableId) {
return TABLE_CALL_NUMBER + shopId + ":" + callTableId;
}
}

View File

@@ -7,7 +7,10 @@ import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -106,4 +109,11 @@ public class TokenUtil {
public static void main(String[] args) {
parseParamFromToken("eyJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50SWQiOiI2IiwiY2xpZW50VHlwZSI6InBjIiwic2hvcElkIjoiMTUiLCJleHAiOjE3MTA1ODc3NjAsImlhdCI6MTcwOTExNjUzMSwibG9naW5OYW1lIjoiMTg4MjE3Nzc4OCJ9.RXfyRgkfC13JGVypd9TQvbNNl_-btyQ-7xnvlj3ej0M");
}
public static JSONObject getCurrentUserInfo() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String token = request.getHeader("token");
return parseParamFromToken(token);
}
}

View File

@@ -31,6 +31,12 @@ public class WxAccountUtil {
private final TbShopMsgStateMapper shopMsgStateMapper;
static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
@Value("${wx.mini.user.msgId.currentCall}")
private String currentCallTempId;
@Value("${wx.mini.user.msgId.nearCall}")
private String nearCallTempId;
static {
linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口");
@@ -132,4 +138,76 @@ public class WxAccountUtil {
return null;
}
}
public void sendCurrentOrNearCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId, boolean isNear) {
Map<String, Object> data = new HashMap<String, Object>() {{
put("thing1", new HashMap<String, Object>() {{
put("value", shopName);
}});
put("phrase2", new HashMap<String, Object>() {{
put("value", state);
}});
put("character_string3", new HashMap<String, Object>() {{
put("value", callNum);
}});
put("character_string4", new HashMap<String, Object>() {{
put("value", currentNum);
}});
put("thing5", new HashMap<String, Object>() {{
put("value", note);
}});
}};
try {
sendTempMsg(isNear ? nearCallTempId : currentCallTempId, openId, data, "排队到号");
} catch (Exception e) {
log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage());
}
}
public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map<String, Object> data, String note) {
log.info("开始发送" + note + "模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
String accessToken= getAccessToken();
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 sendPassCallMsg(String shopName, String state, String callNum, String currentNum, String note, String openId) {
Map<String, Object> data = new HashMap<String, Object>() {{
put("thing1", new HashMap<String, Object>() {{
put("value", shopName);
}});
put("character_string2", new HashMap<String, Object>() {{
put("value", callNum);
}});
put("character_string3", new HashMap<String, Object>() {{
put("value", currentNum);
}});
put("phrase4", new HashMap<String, Object>() {{
put("value", state);
}});
put("thing5", new HashMap<String, Object>() {{
put("value", note);
}});
}};
try {
sendTempMsg(currentCallTempId, openId, data, "过号");
} catch (Exception e) {
log.error("发送失败, openId:{}, msg: {}", openId, e.getMessage());
}
}
}

View File

@@ -60,6 +60,13 @@ wx:
secrete: a34a61adc0602118b49400baa8812454
warnMsgTmpId: AV-KybUHaK3KtFVLqpy6PHccHBS7XeX__mOM4RbufnQ
mini:
user:
appId: wxd88fffa983758a30
secrete: a34a61adc0602118b49400baa8812454
msgId:
nearCall: yxOjWK-KjMEZ_BaHWqDJJpHiUPXN6JWqr7u9y65RIWM
currentCall: 3BgFazRpVlvreh5z9u4cNP_VeclXKSQfh-r3x2_bYx4
passCall: qUhvEfvCtIcBA3DOn3QMqsGOolrEpyr0YBh99i-AUqw
page:
call: https://cashier.sxczgkj.cn/make?shopId={}&queueId={}
ali:

View File

@@ -15,14 +15,13 @@
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="isPostpone" column="is_postpone" jdbcType="TINYINT"/>
<result property="postponeNum" column="postpone_num" jdbcType="INTEGER"/>
<result property="nearNum" column="near_num" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id,page_address,is_online,
bg_cover,success_msg,near_msg,
calling_msg,shop_id,create_time,
update_time,is_postpone,postpone_num
update_time,near_num
</sql>
</mapper>

View File

@@ -24,6 +24,7 @@
<result property="confirmTime" column="confirm_time" jdbcType="TIMESTAMP"/>
<result property="callNum" column="call_num" jdbcType="VARCHAR"/>
<result property="createDay" column="create_day" jdbcType="VARCHAR"/>
<result property="isPostpone" column="is_postpone" jdbcType="TINYINT"/>
</resultMap>
<sql id="Base_Column_List">
@@ -33,6 +34,6 @@
call_count,pass_time,cancel_time,
note,user_id,open_id,
sub_state,confirm_time,call_num,
create_day
create_day,is_postpone
</sql>
</mapper>

View File

@@ -17,12 +17,15 @@
<result property="qrcode" column="qrcode" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="isPostpone" column="is_postpone" jdbcType="TINYINT"/>
<result property="postponeNum" column="postpone_num" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id,name,note,
wait_time,prefix,start,
near_num,state,shop_id,
qrcode,create_time,update_time
qrcode,create_time,update_time,
is_postpone,postpone_num
</sql>
</mapper>