四、核心代码
4.1 查询菜品类型
@RequestMapping(value = "/getByPage", method = RequestMethod.GET) @ApiOperation(value = "查询菜品类型") public Result<IPage<DishType>> getByPage(@ModelAttribute DishType dishType ,@ModelAttribute PageVo page){ QueryWrapper<DishType> qw = new QueryWrapper<>(); if(!ZwzNullUtils.isNull(dishType.getTitle())) { qw.like("title",dishType.getTitle()); } if(!ZwzNullUtils.isNull(dishType.getStatus())) { qw.eq("status",dishType.getStatus()); } IPage<DishType> data = iDishTypeService.page(PageUtil.initMpPage(page),qw); return new ResultUtil<IPage<DishType>>().setData(data); }
4.2 查询菜品
@RequestMapping(value = "/getByPage", method = RequestMethod.GET) @ApiOperation(value = "查询菜品") public Result<IPage<DishVariety>> getByPage(@ModelAttribute DishVariety dishVariety ,@ModelAttribute PageVo page){ QueryWrapper<DishVariety> qw = new QueryWrapper<>(); if(!ZwzNullUtils.isNull(dishVariety.getTitle())) { qw.like("title",dishVariety.getTitle()); } if(!ZwzNullUtils.isNull(dishVariety.getType())) { qw.eq("type",dishVariety.getType()); } if(!ZwzNullUtils.isNull(dishVariety.getContent())) { qw.like("content",dishVariety.getContent()); } IPage<DishVariety> data = iDishVarietyService.page(PageUtil.initMpPage(page),qw); User currUser = securityUtil.getCurrUser(); for (DishVariety vo : data.getRecords()) { QueryWrapper<DishCollect> collQw = new QueryWrapper<>(); collQw.eq("collect_id",currUser.getId()); collQw.eq("dish_id",vo.getId()); vo.setCollectFlag(iDishCollectService.count(collQw)); QueryWrapper<DishOrder> orderQw = new QueryWrapper<>(); orderQw.eq("dish_id",vo.getId()); orderQw.eq("status","已加购"); orderQw.last("limit 1"); DishOrder order = iDishOrderService.getOne(orderQw); vo.setBuyNumber(order == null ? BigDecimal.ZERO : order.getNumber()); } return new ResultUtil<IPage<DishVariety>>().setData(data); }
4.3 加购菜品
@RequestMapping(value = "/addOne", method = RequestMethod.GET) @ApiOperation(value = "加购") public Result<DishOrder> addOne(@RequestParam String id, @RequestParam BigDecimal number){ DishVariety dish = iDishVarietyService.getById(id); if(dish == null) { return ResultUtil.error("菜品不存在"); } User currUser = securityUtil.getCurrUser(); QueryWrapper<DishOrder> qw = new QueryWrapper<>(); qw.eq("dish_id",dish.getId()); qw.eq("status","已加购"); qw.eq("order_id",currUser.getId()); qw.last("limit 1"); DishOrder order = iDishOrderService.getOne(qw); if(order != null) { order.setNumber(order.getNumber().add(number)); iDishOrderService.saveOrUpdate(order); return ResultUtil.success(); } DishOrder o = new DishOrder(); o.setDishId(dish.getId()); o.setTitle(dish.getTitle()); o.setType(dish.getType()); o.setContent(dish.getContent()); o.setImage(dish.getImage()); o.setPrice(dish.getPrice()); o.setStatus("已加购"); o.setNumber(number); o.setOrderId(currUser.getId()); o.setOrderName(currUser.getNickname()); o.setOrderTime(DateUtil.now()); iDishOrderService.saveOrUpdate(o); return ResultUtil.success(); }
4.4 新增菜品收藏
@RequestMapping(value = "/addOne", method = RequestMethod.GET) @ApiOperation(value = "新增收藏") public Result<DishCollect> addOne(@RequestParam String id){ DishVariety dish = iDishVarietyService.getById(id); if(dish == null) { return ResultUtil.error("菜品不存在"); } User currUser = securityUtil.getCurrUser(); QueryWrapper<DishCollect> qw = new QueryWrapper<>(); qw.eq("dish_id",id); qw.eq("collect_id",currUser.getId()); if(iDishCollectService.count(qw) > 0L) { return ResultUtil.success(); } DishCollect dishCollect = new DishCollect(); dishCollect.setDishId(dish.getId()); dishCollect.setTitle(dish.getTitle()); dishCollect.setType(dish.getType()); dishCollect.setContent(dish.getContent()); dishCollect.setImage(dish.getImage()); dishCollect.setPrice(dish.getPrice()); dishCollect.setCollectId(currUser.getId()); dishCollect.setCollectName(currUser.getNickname()); dishCollect.setCollectTime(DateUtil.now()); iDishCollectService.saveOrUpdate(dishCollect); return ResultUtil.success(); }
4.5 新增菜品留言
@RequestMapping(value = "/insert", method = RequestMethod.POST) @ApiOperation(value = "新增菜品留言") public Result<Message> insert(Message message){ User currUser = securityUtil.getCurrUser(); message.setUserId(currUser.getId()); message.setUserName(currUser.getNickname()); message.setUserTime(DateUtil.now()); message.setReplyContent(""); message.setReplyName(""); message.setReplyTime(""); message.setReplyId(""); iMessageService.saveOrUpdate(message); return new ResultUtil<Message>().setData(message); }
五、免责说明
- 本项目仅供个人学习使用,商用授权请联系博主,否则后果自负。
- 博主拥有本软件构建后的应用系统全部内容所有权及独立的知识产权,拥有最终解释权。
- 如有问题,欢迎在仓库 Issue 留言,看到后会第一时间回复,相关意见会酌情考虑,但没有一定被采纳的承诺或保证。
下载本系统代码或使用本系统的用户,必须同意以下内容,否则请勿下载!
- 出于自愿而使用/开发本软件,了解使用本软件的风险,且同意自己承担使用本软件的风险。
- 利用本软件构建的网站的任何信息内容以及导致的任何版权纠纷和法律争议及后果和博主无关,博主对此不承担任何责任。
- 在任何情况下,对于因使用或无法使用本软件而导致的任何难以合理预估的损失(包括但不仅限于商业利润损失、业务中断与业务信息丢失),博主概不承担任何责任。
- 必须了解使用本软件的风险,博主不承诺提供一对一的技术支持、使用担保,也不承担任何因本软件而产生的难以预料的问题的相关责任。