| | |
| | | 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.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.domain.*; |
| | | import com.ruoyi.system.dto.CheckoutDTO; |
| | | import com.ruoyi.system.dto.TOrderMealDTO; |
| | | import com.ruoyi.system.importExcel.TOrderMealExportExcel; |
| | | import com.ruoyi.system.query.SysUserQuery; |
| | | import com.ruoyi.system.export.TOrderMealExportExcel; |
| | | import com.ruoyi.system.query.TOrderMealQuery; |
| | | import com.ruoyi.system.service.TOrderMealGoodsService; |
| | | import com.ruoyi.system.service.TOrderMealService; |
| | | import com.ruoyi.system.service.*; |
| | | 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.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | 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; |
| | | |
| | | /** |
| | |
| | | |
| | | private final TOrderMealService orderMealService; |
| | | private final TOrderMealGoodsService orderMealGoodsService; |
| | | private final TGoodsTypeService goodsTypeService; |
| | | private final TGoodsService goodsService; |
| | | private final TBoardService boardService; |
| | | private final TokenService tokenService; |
| | | |
| | | @Autowired |
| | | public TOrderMealController(TOrderMealService orderMealService, TOrderMealGoodsService orderMealGoodsService, TokenService tokenService) { |
| | | public TOrderMealController(TOrderMealService orderMealService, TOrderMealGoodsService orderMealGoodsService, TGoodsTypeService goodsTypeService, TGoodsService goodsService, TBoardService boardService, TokenService tokenService) { |
| | | this.orderMealService = orderMealService; |
| | | this.orderMealGoodsService = orderMealGoodsService; |
| | | this.goodsTypeService = goodsTypeService; |
| | | this.goodsService = goodsService; |
| | | this.boardService = boardService; |
| | | this.tokenService = tokenService; |
| | | } |
| | | |
| | |
| | | BeanUtils.copyProperties(orderMeal, orderMealVO); |
| | | List<TOrderMealGoods> list = orderMealGoodsService.list(Wrappers.lambdaQuery(TOrderMealGoods.class) |
| | | .eq(TOrderMealGoods::getOrderId, orderMeal.getId())); |
| | | if(!CollectionUtils.isEmpty(list)){ |
| | | Map<String, List<TOrderMealGoods>> map = list.stream().collect(Collectors.groupingBy(TOrderMealGoods::getTypeName)); |
| | | List<String> goodsList = new ArrayList<>(); |
| | | map.forEach((k,v)->{ |
| | | goodsList.add(k+":"+v.stream().map(item->item.getGoodsName()+" "+(item.getGoodsSalePrice().multiply(new BigDecimal(item.getGoodsCount())))).collect(Collectors.joining(","))); |
| | | }); |
| | | orderMealVO.setGoodsList(goodsList); |
| | | } |
| | | orderMealVO.setOrderMealGoods(list); |
| | | // 查询用餐人数 |
| | | TBoard board = boardService.getById(orderMeal.getBoardId()); |
| | | orderMealVO.setMaxPerson(board.getMaxPerson()); |
| | | orderMealVO.setMinPerson(board.getMinPerson()); |
| | | return AjaxResult.success(orderMealVO); |
| | | } |
| | | |
| | | @ApiOperation( value = "修改") |
| | | @PostMapping(value = "/update") |
| | | public AjaxResult<String> update(@RequestBody TOrderMealDTO dto) { |
| | | // 删除所有菜品 |
| | | orderMealGoodsService.remove(Wrappers.lambdaQuery(TOrderMealGoods.class) |
| | | .eq(TOrderMealGoods::getOrderId, dto.getId())); |
| | | orderMealService.updateById(dto); |
| | | for (TOrderMealGoods mealOrderGood : dto.getMealOrderGoods()) { |
| | | // 设置商品类型和类型id |
| | | TGoodsType goodsType = goodsTypeService.getById(mealOrderGood.getTypeId()); |
| | | mealOrderGood.setId(null); |
| | | mealOrderGood.setOrderId(dto.getId()); |
| | | mealOrderGood.setTypeId(goodsType.getId()); |
| | | mealOrderGood.setTypeName(goodsType.getTypeName()); |
| | | } |
| | | orderMealGoodsService.saveBatch(dto.getMealOrderGoods()); |
| | | return AjaxResult.success(); |
| | | } |
| | | @ApiOperation( value = "列表详情结账") |
| | | @PostMapping(value = "/detailUpdate") |
| | | public AjaxResult<String> detailUpdate(@RequestBody TOrderMealDTO dto) { |
| | | // 删除所有菜品 |
| | | orderMealGoodsService.remove(Wrappers.lambdaQuery(TOrderMealGoods.class) |
| | | .eq(TOrderMealGoods::getOrderId, dto.getId())); |
| | | orderMealService.updateById(dto); |
| | | // 查询餐桌 |
| | | List<TOrderMealGoods> mealOrderGoods = dto.getMealOrderGoods(); |
| | | if (!CollectionUtils.isEmpty(mealOrderGoods)) { |
| | | for (TOrderMealGoods mealOrderGood : mealOrderGoods) { |
| | | // 设置商品类型和类型id |
| | | mealOrderGood.setId(null); |
| | | } |
| | | orderMealGoodsService.saveBatch(mealOrderGoods); |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @ApiOperation( value = "删除餐饮订单") |
| | |
| | | /** |
| | | * 添加餐饮管理 |
| | | */ |
| | | @ApiOperation( value = "开台-点菜接口") |
| | | @ApiOperation( value = "开台") |
| | | @PostMapping(value = "/startMeal") |
| | | public AjaxResult<Integer> startMeal(@RequestBody TOrderMeal dto) { |
| | | dto.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | orderMealService.startMeal(dto); |
| | | return AjaxResult.success(dto.getId()); |
| | | } |
| | | |
| | | /** |
| | | * 添加餐饮管理 |
| | | */ |
| | | @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()); |
| | | } |
| | | |
| | | @ApiOperation( value = "加菜接口") |
| | | @PostMapping(value = "/addDish") |
| | | public AjaxResult<String> addDish(@Validated @RequestBody AddDishDTO dto) { |
| | | orderMealService.addDish(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | // @ApiOperation( value = "加菜接口") |
| | | // @PostMapping(value = "/addDish") |
| | | // public AjaxResult<String> addDish(@Validated @RequestBody AddDishDTO dto) { |
| | | // orderMealService.addDish(dto); |
| | | // return AjaxResult.success(); |
| | | // } |
| | | |
| | | @ApiOperation( value = "结账接口") |
| | | @PostMapping(value = "/checkout") |
| | |
| | | @PostMapping("/exportOrderMeal") |
| | | public void exportOrderMeal(@RequestBody TOrderMealQuery query) |
| | | { |
| | | query.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | List<TOrderMealVO> list = orderMealService.exportOrderMeal(query); |
| | | List<TOrderMealExportExcel> orderMeals = new ArrayList<>(); |
| | | for (TOrderMealVO orderMealVO : list) { |
| | |
| | | BeanUtils.copyProperties(orderMealVO, tOrderMealExportExcel); |
| | | tOrderMealExportExcel.setCreateStrTime(DateUtils.localDateTimeToString(orderMealVO.getCreateTime())); |
| | | tOrderMealExportExcel.setGoodsList(orderMealVO.getGoodsList().stream().collect(Collectors.joining("\n"))); |
| | | orderMeals.add(tOrderMealExportExcel); |
| | | } |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TOrderMealExportExcel.class, orderMeals); |
| | | HttpServletResponse response = WebUtils.response(); |