| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.system.domain.TGoodsType; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.WebUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.domain.TOrderMeal; |
| | | import com.ruoyi.system.domain.TOrderMealGoods; |
| | | import com.ruoyi.system.dto.AddDishDTO; |
| | | import com.ruoyi.system.dto.CheckoutDTO; |
| | | import com.ruoyi.system.dto.OrderMealGeneratorDTO; |
| | | import com.ruoyi.system.dto.TOrderMealDTO; |
| | | import com.ruoyi.system.service.TGoodsTypeService; |
| | | import com.ruoyi.system.importExcel.TOrderMealExportExcel; |
| | | import com.ruoyi.system.query.SysUserQuery; |
| | | import com.ruoyi.system.query.TOrderMealQuery; |
| | | import com.ruoyi.system.service.TOrderMealGoodsService; |
| | | import com.ruoyi.system.service.TOrderMealService; |
| | | import com.ruoyi.system.vo.AmountSumVO; |
| | | import com.ruoyi.system.vo.SysUserVO; |
| | | import com.ruoyi.system.vo.TOrderMealVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | public class TOrderMealController { |
| | | |
| | | private final TOrderMealService orderMealService; |
| | | private final TOrderMealGoodsService orderMealGoodsService; |
| | | private final TokenService tokenService; |
| | | |
| | | @Autowired |
| | | public TOrderMealController(TOrderMealService orderMealService) { |
| | | public TOrderMealController(TOrderMealService orderMealService, TOrderMealGoodsService orderMealGoodsService, TokenService tokenService) { |
| | | this.orderMealService = orderMealService; |
| | | this.orderMealGoodsService = orderMealGoodsService; |
| | | this.tokenService = tokenService; |
| | | } |
| | | |
| | | /** |
| | | * 查询餐饮列表 |
| | | */ |
| | | // @ApiOperation( value = "查询餐饮列表") |
| | | // @PostMapping(value = "/list") |
| | | // public AjaxResult<List<TOrderMeal>> list() { |
| | | // return AjaxResult.success(orderMealService.list()); |
| | | // } |
| | | @ApiOperation( value = "查询餐饮分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public AjaxResult<PageInfo<TOrderMealVO>> pageList(@RequestBody TOrderMealQuery query) { |
| | | query.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | return AjaxResult.success(orderMealService.pageList(query)); |
| | | } |
| | | |
| | | /** |
| | | * 查询餐饮金额统计 |
| | | */ |
| | | @ApiOperation( value = "查询餐饮金额统计") |
| | | @PostMapping(value = "/amountSum") |
| | | public AjaxResult<AmountSumVO> amountSum(@RequestBody TOrderMealQuery query) { |
| | | query.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | return AjaxResult.success(orderMealService.amountSum(query)); |
| | | } |
| | | |
| | | @ApiOperation( value = "查询餐饮详情") |
| | | @GetMapping(value = "/getDetailById") |
| | | public AjaxResult<TOrderMealVO> getDetailById(@RequestParam(value = "id") Long id) { |
| | | TOrderMeal orderMeal = orderMealService.getById(id); |
| | | TOrderMealVO orderMealVO = new TOrderMealVO(); |
| | | BeanUtils.copyProperties(orderMeal, orderMealVO); |
| | | List<TOrderMealGoods> list = orderMealGoodsService.list(Wrappers.lambdaQuery(TOrderMealGoods.class) |
| | | .eq(TOrderMealGoods::getOrderId, orderMeal.getId())); |
| | | orderMealVO.setOrderMealGoods(list); |
| | | return AjaxResult.success(orderMealVO); |
| | | } |
| | | |
| | | @ApiOperation( value = "删除餐饮订单") |
| | | @GetMapping(value = "/deleteById") |
| | | public AjaxResult<Boolean> deleteById(@RequestParam(value = "id") Long id) { |
| | | orderMealGoodsService.remove(Wrappers.lambdaQuery(TOrderMealGoods.class) |
| | | .eq(TOrderMealGoods::getOrderId, id)); |
| | | return AjaxResult.success(orderMealService.removeById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 添加餐饮管理 |
| | |
| | | @ApiOperation( value = "开台-点菜接口") |
| | | @PostMapping(value = "/add") |
| | | public AjaxResult<Integer> add(@RequestBody TOrderMealDTO dto) { |
| | | dto.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | orderMealService.add(dto); |
| | | return AjaxResult.success(dto.getId()); |
| | | } |
| | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 导出餐饮列表 |
| | | */ |
| | | @ApiOperation(value = "导出餐饮列表") |
| | | @PostMapping("/exportOrderMeal") |
| | | public void exportOrderMeal(@RequestBody TOrderMealQuery query) |
| | | { |
| | | List<TOrderMealVO> list = orderMealService.exportOrderMeal(query); |
| | | List<TOrderMealExportExcel> orderMeals = new ArrayList<>(); |
| | | for (TOrderMealVO orderMealVO : list) { |
| | | TOrderMealExportExcel tOrderMealExportExcel = new TOrderMealExportExcel(); |
| | | BeanUtils.copyProperties(orderMealVO, tOrderMealExportExcel); |
| | | tOrderMealExportExcel.setCreateStrTime(DateUtils.localDateTimeToString(orderMealVO.getCreateTime())); |
| | | tOrderMealExportExcel.setGoodsList(orderMealVO.getGoodsList().stream().collect(Collectors.joining("\n"))); |
| | | } |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TOrderMealExportExcel.class, orderMeals); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("餐饮列表.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |