},
onShow: function () {
this.getNum()
},
//取号
quhao(event) {
let type = event.currentTarget.dataset.type
let that = this;
//如果openid不存在,就重新请求接口获取openid
var openid = app.globalData.openid;
if (openid === null || openid === undefined) {
app.getOpenid();
wx.showToast({ //这里提示失败原因
title: 'openid为空!',
duration: 1500
})
return;
}
wx.request({
url: app.globalData.baseUrl + '/paihao/quhao',
method: "POST",
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
data: {
openid: openid,
type: type,
},
success(res) {
if (res && res.data && res.data.data) {
wx.showToast({
title: '排号成功',
})
console.log(res)
that.setData({
type: res.data.data.type,
num: res.data.data.num
})
}
},
fail(res) {
console.log("排号失败", res)
}
})
},
//查询我的排号
getNum() {
let that = this;
//如果openid不存在,就重新请求接口获取openid
var openid = app.globalData.openid;
if (openid === null || openid === undefined) {
app.getOpenid();
wx.showToast({ //这里提示失败原因
title: 'openid为空!',
duration: 1500
})
return;
}
wx.request({
url: app.globalData.baseUrl + '/paihao/getNum',
data: {
openid: openid
},
success: function (res) {
if (res && res.data && res.data.data) {
let dataList = res.data.data;
console.log("请求到的排号情况", dataList)
that.setData({
type: dataList.type,
num: dataList.num,
smallOkNum: dataList.smallOkNum,
bigOkNum: dataList.bigOkNum,
})
} else {
that.setData({
num: -1
})
}
},
fail(res) {
console.log("查询排号失败", res)
}
})
}
})
这里需要注意一点,就是一定要先获取用户的openid,因为openid是用户的唯一标识。每人每天只能排一次号。买我点餐系统这门课的同学,都知道如何获取openid,我课程配套的视频也有讲。
[]( )二,Java后台代码讲解
--------------------------------------------------------------------------
如果有仔细看上面第一步小程序端代码,应该可以看到wx.request网络请求部分,其实这个网络请求就是请求的我们Java后台。下面先把Java后台源码贴出来。
/**
- 小程序端排号相关接口
*/
@RestController
@RequestMapping(“/paihao”)
@Slf4j
public class WxPaihaoController {
@Autowired
PaihaoRepository repository;
/*
* 取号
* */
@PostMapping("/quhao")
public ResultVO quhao(@RequestParam(value = "type") Integer type,
@RequestParam("openid") String openid) {
int size = repository.findByDayAndType(TimeUtils.getYMD(), type).size();
log.info("当前排号数={}", size);
Paihao paihao = new Paihao();
paihao.setDay(TimeUtils.getYMD());
paihao.setNum(size + 1);
paihao.setType(type);
paihao.setOpenid(openid);
paihao.setRuzuo(false);
return ApiUtil.success(repository.save(paihao));
}
/*
* 查询当前排号
* */
@GetMapping("/getNum")
public ResultVO getNum(@RequestParam("openid") String openid) {
//获取当前小桌入座情况
List<Paihao> listSmall = repository.findByDayAndRuzuoAndTypeOrderByNum(TimeUtils.getYMD(), true, 0);
//获取当前大桌入座情况
List<Paihao> listBig = repository.findByDayAndRuzuoAndTypeOrderByNum(TimeUtils.getYMD(), true, 1);
//查询当前客户的排号情况
List<Paihao> listKeHu = repository.findByOpenidAndDay(openid,TimeUtils.getYMD());
//组装数据返回给小程序端
PaihaoVO paihao = new PaihaoVO();
if (listSmall != null && listSmall.size() > 0) {
paihao.setSmallOkNum(listSmall.get(listSmall.size() - 1).getNum());
} else {
paihao.setSmallOkNum(0);
}
if (listBig != null && listBig.size() > 0) {
paihao.setBigOkNum(listBig.get(listBig.size() - 1).getNum());
} else {
paihao.setBigOkNum(0);
}
if (listKeHu != null && listKeHu.size() > 0) {
paihao.setNum(listKeHu.get(listKeHu.size() - 1).getNum());
paihao.setType(listKeHu.get(listKeHu.size() - 1).getType());
} else {
paihao.setNum(0);
paihao.setType(0);
}
return ApiUtil.success(paihao);
}
}
可以看到我们一共给小程序前端提供两个接口,一个是取号,一个是查询当前排号状态。
### []( )1,先给大家讲讲取号
/*
* 取号
* */
@PostMapping("/quhao")
public ResultVO quhao(@RequestParam(value = "type") Integer type,
@RequestParam("openid") String openid) {
int size = repository.findByDayAndType(TimeUtils.getYMD(), type).size();
log.info("当前排号数={}", size);
Paihao paihao = new Paihao();
paihao.setDay(TimeUtils.getYMD());
paihao.setNum(size + 1);
paihao.setType(type);
paihao.setOpenid(openid);
paihao.setRuzuo(false);
return ApiUtil.success(repository.save(paihao));
}
取号其实很简单,就是先查询当前已经排到第几号,然后新排号的客户号码再前面排号的基础上加一。然后数据入库就可以了。
### []( )2,再给大家讲下排号状态查询。
@GetMapping("/getNum")
public ResultVO getNum(@RequestParam("openid") String openid) {
//获取当前小桌入座情况
List<Paihao> listSmall = repository.findByDayAndRuzuoAndTypeOrderByNum(TimeUtils.getYMD(), true, 0);
//获取当前大桌入座情况
List<Paihao> listBig = repository.findByDayAndRuzuoAndTypeOrderByNum(TimeUtils.getYMD(), true, 1);
//查询当前客户的排号情况
List<Paihao> listKeHu = repository.findByOpenidAndDay(openid,TimeUtils.getYMD());
//组装数据返回给小程序端
PaihaoVO paihao = new PaihaoVO();
if (listSmall != null && listSmall.size() > 0) {
paihao.setSmallOkNum(listSmall.get(listSmall.size() - 1).getNum());
} else {
paihao.setSmallOkNum(0);
}
if (listBig != null && listBig.size() > 0) {
paihao.setBigOkNum(listBig.get(listBig.size() - 1).getNum());
} else {
paihao.setBigOkNum(0);
}
if (listKeHu != null && listKeHu.size() > 0) {
paihao.setNum(listKeHu.get(listKeHu.size() - 1).getNum());
paihao.setType(listKeHu.get(listKeHu.size() - 1).getType());
} else {
paihao.setNum(0);
paihao.setType(0);
}
return ApiUtil.success(paihao);
}
这一步稍微复杂一点。这一步的主要就是给小程序端返回所需的数据,比如当前大桌排到了第几号,小桌排到了第几号,当前用户的排号,当前用户是否被叫到。代码里注释都很清楚了,感兴趣的同学仔细看下上面代码即可。
### []( )3,管理员端
管理员就是用来操作谁可以入座的。
![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly91cGxvYWQtaW1hZ2VzLmppYW5zaHUuaW8vdXBsb2FkX2ltYWdlcy82MjczNzEzLWJkN2E2NmIwOWM4MGE5N2YucG5n?x-oss-process=image/format,png)
这
[video(video-8PGqMbZO-1716354551447)(type-bilibili)(url-https://player.bilibili.com/player.html?aid=1804892953)(image-https://img-blog.csdnimg.cn/img_convert/d03a705143646f4f3f6ea879d59b2788.png)(title-必看视频!获取2024年最新Java开发全套学习资料 备注Java)]
个页面主要是用freemarker写的前端页面。代码如下图。
![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly91cGxvYWQtaW1hZ2VzLmppYW5zaHUuaW8vdXBsb2FkX2ltYWdlcy82MjczNzEzLWQyMTk0NmI1ZDhhOTg1NDgucG5n?x-oss-process=image/format,png)
对应的后台接口。
分享
这次面试我也做了一些总结,确实还有很多要学的东西。相关面试题也做了整理,可以分享给大家,了解一下面试真题,想进大厂的或者想跳槽的小伙伴不妨好好利用时间来学习。学习的脚步一定不能停止!
Spring Cloud实战
Spring Boot实战
面试题整理(性能优化+微服务+并发编程+开源框架+分布式)
convert.csdnimg.cn/aHR0cHM6Ly91cGxvYWQtaW1hZ2VzLmppYW5zaHUuaW8vdXBsb2FkX2ltYWdlcy82MjczNzEzLWQyMTk0NmI1ZDhhOTg1NDgucG5n?x-oss-process=image/format,png)
对应的后台接口。
# 分享
这次面试我也做了一些总结,确实还有很多要学的东西。相关面试题也做了整理,可以分享给大家,了解一下面试真题,想进大厂的或者想跳槽的小伙伴不妨好好利用时间来学习。学习的脚步一定不能停止!
[外链图片转存中...(img-Q9NSZSKR-1716463172927)]
Spring Cloud实战
[外链图片转存中...(img-zfAlsk0s-1716463172928)]
Spring Boot实战
[外链图片转存中...(img-8OV8Bm9F-1716463172929)]
面试题整理(性能优化+微服务+并发编程+开源框架+分布式)