文章目录
- 一、项目介绍
- 二、项目介绍
- 三、运行截图
- 四、主要代码
一、项目介绍
项目演示地址:视频地址
二、项目介绍
项目描述:这是一个基于SpringBoot+微信小程序框架开发的酒店预订小程序系统。首先,这是一个前后端分离的项目,代码简洁规范,注释说明详细,易于理解和学习。其次,这项目功能丰富,具有一个酒店预订小程序系统该有的所有功能。
项目功能:此项目分为两个角色:普通用户和管理员。普通用户有微信授权登录、浏览房间信息、提交房间预订订单、浏览酒店图集和配套设施信息、浏览公告信息、管理个人基本信息、查看个人订单信息、管理个人评价信息、发布评价信息等等功能。管理员有管理所有房间信息、管理所有订单信息、管理所有用户信息、管理所有评价信息、管理所有公告信息、管理所有图集信息、浏览收益图表数据等等功能。
应用技术:SpringBoot + 微信小程序 + MySQL + MyBatis + Redis + ElementUI + Vue + Vant Weapp
运行环境:IntelliJ IDEA2019.3.5 + 微信开发者工具(项目压缩包中自带)+ MySQL5.7(项目压缩包中自带) + Redis5.0.5(项目压缩包中自带) + JDK1.8 + Maven3.6.3(项目压缩包中自带)+ Node14.16.1(项目压缩包中自带)
三、运行截图
四、主要代码
1.提交预订房间订单代码:
/*** 提交订单操作* @param orderDTO* @return*/
@Override
public ResponseDTO<Boolean> submitOrder(OrderDTO orderDTO) {ResponseDTO<UserDTO> loginUserResponse = userService.getLoginUser(orderDTO.getToken());if(!CodeMsg.SUCCESS.getCode().equals(loginUserResponse.getCode())) {return ResponseDTO.errorByMsg(CodeMsg.USER_SESSION_EXPIRED);}UserDTO loginUserDTO = loginUserResponse.getData();// 进行统一表单验证CodeMsg validate = ValidateEntityUtil.validate(orderDTO);if(!validate.getCode().equals(CodeMsg.SUCCESS.getCode())){return ResponseDTO.errorByMsg(validate);}Room room = roomMapper.selectByPrimaryKey(orderDTO.getRoomId());if(room == null) {return ResponseDTO.errorByMsg(CodeMsg.ROOM_NOT_EXIST);}Order order = CopyUtil.copy(orderDTO, Order.class);if(order.getNum() > room.getNum()) {return ResponseDTO.errorByMsg(CodeMsg.ROOM_NOT_ENOUGH);}RoomExample roomExample = new RoomExample();// 乐观锁控制更新房间余量 防止超卖roomExample.createCriteria().andIdEqualTo(room.getId()).andVersionEqualTo(room.getVersion());// 版本号 + 1room.setVersion(room.getVersion() + 1);room.setNum(room.getNum() - order.getNum());if(roomMapper.updateByExampleSelective(room, roomExample) == 0) {return ResponseDTO.errorByMsg(CodeMsg.ORDER_BUSY);}order.setId(UuidUtil.getShortUuid());order.setCreateTime(new Date());order.setRoomType(room.getType());order.setRoomPhoto(room.getPhoto());order.setUserId(loginUserDTO.getId());order.setRoomPrice(room.getPrice());order.setTotalPrice(room.getPrice().multiply(new BigDecimal(order.getNum())));// 入队操作,队列已满则阻塞等待try {blockingQueue.put(order);} catch (InterruptedException e) {e.printStackTrace();return ResponseDTO.errorByMsg(CodeMsg.ORDER_BUSY);}return ResponseDTO.successByMsg(true, "预订成功!");
}
2.小程序微信授权登录代码:
/*** 小程序授权登录验证* @param userDTO* @return*/@Overridepublic ResponseDTO<UserDTO> appWxLogin(UserDTO userDTO) {String url = LOGIN_URL + "?appid=" + APP_ID + "&secret="+ APP_SECRET + "&grant_type=authorization_code&js_code=" + userDTO.getCode();HttpClient client = HttpClients.createDefault(); // 创建默认http连接HttpGet getRequest = new HttpGet(url);// 创建一个post请求LoginDTO loginDTO = new LoginDTO();try {// 用http连接去执行get请求并且获得http响应HttpResponse response = client.execute(getRequest);// 从response中取到响实体HttpEntity entity = response.getEntity();// 把响应实体转成文本String html = EntityUtils.toString(entity);loginDTO = JSON.parseObject(html, LoginDTO.class);if(null == loginDTO.getErrcode()) {userDTO.setWxId(loginDTO.getOpenid());} else {return ResponseDTO.errorByMsg(CodeMsg.USER_WX_LOGIN_ERROR);}} catch (Exception e) {e.printStackTrace();return ResponseDTO.errorByMsg(CodeMsg.USER_WX_LOGIN_ERROR);}// 使用微信openId查询是否有此用户UserExample userExample = new UserExample();userExample.createCriteria().andWxIdEqualTo(userDTO.getWxId());List<User> userList = userMapper.selectByExample(userExample);if(null != userList && userList.size() > 0) {// 已经存在用户信息,读取数据库中用户信息User user = userList.get(0);userDTO = CopyUtil.copy(user, UserDTO.class);} else {// 数据库中不存在,注册用户信息User user = CopyUtil.copy(userDTO, User.class);user.setId(UuidUtil.getShortUuid());user.setUsername(user.getWxUsername());user.setHeadPic(user.getWxHeadPic());user.setRoleId(RoleEnum.USER.getCode());if(userMapper.insertSelective(user) == 0) {return ResponseDTO.errorByMsg(CodeMsg.USER_REGISTER_ERROR);}userDTO = CopyUtil.copy(user, UserDTO.class);}userDTO.setToken(UuidUtil.getShortUuid());stringRedisTemplate.opsForValue().set("USER_" + userDTO.getToken(), JSON.toJSONString(userMapper.selectByPrimaryKey(userDTO.getId())), 3600, TimeUnit.SECONDS);return ResponseDTO.successByMsg(userDTO, "登录成功!");}
3.提交评价信息代码:
/*** 提交评价信息* @param commentDTO* @return*/@Overridepublic ResponseDTO<Boolean> submitComment(CommentDTO commentDTO) {ResponseDTO<UserDTO> loginUserResponse = userService.getLoginUser(commentDTO.getToken());if(!CodeMsg.SUCCESS.getCode().equals(loginUserResponse.getCode())) {return ResponseDTO.errorByMsg(CodeMsg.USER_SESSION_EXPIRED);}UserDTO loginUserDTO = loginUserResponse.getData();// 进行统一表单验证CodeMsg validate = ValidateEntityUtil.validate(commentDTO);if(!validate.getCode().equals(CodeMsg.SUCCESS.getCode())){return ResponseDTO.errorByMsg(validate);}Comment comment = CopyUtil.copy(commentDTO, Comment.class);comment.setId(UuidUtil.getShortUuid());comment.setCreateTime(new Date());comment.setUserId(loginUserDTO.getId());if(commentMapper.insertSelective(comment) == 0) {return ResponseDTO.errorByMsg(CodeMsg.COMMENT_ADD_ERROR);}return ResponseDTO.successByMsg(true, "评价成功!");}