| | |
| | | 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.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.system.dto.TOrderMealDTO; |
| | | 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.domain.TOrderSale; |
| | | import com.ruoyi.system.domain.TOrderSaleGoods; |
| | | import com.ruoyi.system.dto.TOrderSaleDTO; |
| | | import com.ruoyi.system.service.TOrderMealService; |
| | | import com.ruoyi.system.importExcel.TOrderMealExportExcel; |
| | | import com.ruoyi.system.importExcel.TOrderSaleExportExcel; |
| | | import com.ruoyi.system.query.TOrderMealQuery; |
| | | import com.ruoyi.system.query.TOrderSaleQuery; |
| | | import com.ruoyi.system.service.TOrderSaleGoodsService; |
| | | import com.ruoyi.system.service.TOrderSaleService; |
| | | import com.ruoyi.system.vo.AmountSumVO; |
| | | import com.ruoyi.system.vo.TOrderMealVO; |
| | | import com.ruoyi.system.vo.TOrderSaleVO; |
| | | 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.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.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RequestMapping("/t-order-sale") |
| | | public class TOrderSaleController { |
| | | private final TOrderSaleService orderSaleService; |
| | | private final TOrderSaleGoodsService orderSaleGoodsService; |
| | | private final TokenService tokenService; |
| | | |
| | | @Autowired |
| | | public TOrderSaleController(TOrderSaleService orderSaleService) { |
| | | public TOrderSaleController(TOrderSaleService orderSaleService, TOrderSaleGoodsService orderSaleGoodsService, TokenService tokenService) { |
| | | this.orderSaleService = orderSaleService; |
| | | this.orderSaleGoodsService = orderSaleGoodsService; |
| | | this.tokenService = tokenService; |
| | | } |
| | | |
| | | /** |
| | | * 查询销售列表 |
| | | */ |
| | | @ApiOperation( value = "查询销售分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public AjaxResult<PageInfo<TOrderSaleVO>> pageList(@RequestBody TOrderSaleQuery query) { |
| | | query.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | return AjaxResult.success(orderSaleService.pageList(query)); |
| | | } |
| | | |
| | | /** |
| | | * 查询销售金额统计 |
| | | */ |
| | | @ApiOperation( value = "查询销售金额统计") |
| | | @PostMapping(value = "/amountSum") |
| | | public AjaxResult<AmountSumVO> amountSum(@RequestBody TOrderMealQuery query) { |
| | | query.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | return AjaxResult.success(orderSaleService.amountSum(query)); |
| | | } |
| | | |
| | | @ApiOperation( value = "查询销售详情") |
| | | @GetMapping(value = "/getDetailById") |
| | | public AjaxResult<TOrderSaleVO> getDetailById(@RequestParam(value = "id") Long id) { |
| | | TOrderSale orderSale = orderSaleService.getById(id); |
| | | TOrderSaleVO orderSaleVO = new TOrderSaleVO(); |
| | | BeanUtils.copyProperties(orderSale, orderSaleVO); |
| | | List<TOrderSaleGoods> list = orderSaleGoodsService.list(Wrappers.lambdaQuery(TOrderSaleGoods.class) |
| | | .eq(TOrderSaleGoods::getOrderId, orderSale.getId())); |
| | | orderSaleVO.setOrderSaleGoods(list); |
| | | return AjaxResult.success(orderSaleVO); |
| | | } |
| | | |
| | | @ApiOperation( value = "删除销售订单") |
| | | @DeleteMapping(value = "/deleteById") |
| | | public AjaxResult<Boolean> deleteById(@RequestParam(value = "id") Long id) { |
| | | orderSaleGoodsService.remove(Wrappers.lambdaQuery(TOrderSaleGoods.class) |
| | | .eq(TOrderSaleGoods::getOrderId,id)); |
| | | return AjaxResult.success(orderSaleService.removeById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 销售下单接口 |
| | | */ |
| | | @ApiOperation( value = "销售下单接口") |
| | | @PostMapping(value = "/add") |
| | | public AjaxResult<String> add(@RequestBody TOrderSaleDTO dto) { |
| | | dto.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | orderSaleService.add(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 导出销售列表 |
| | | */ |
| | | @ApiOperation(value = "导出销售列表") |
| | | @PostMapping("/exportOrderSale") |
| | | public void exportOrderSale(@RequestBody TOrderMealQuery query) |
| | | { |
| | | List<TOrderSaleVO> list = orderSaleService.exportOrderSale(query); |
| | | List<TOrderMealExportExcel> orderMeals = new ArrayList<>(); |
| | | for (TOrderSaleVO orderSaleVO : list) { |
| | | TOrderSaleExportExcel orderSaleExportExcel = new TOrderSaleExportExcel(); |
| | | BeanUtils.copyProperties(orderSaleVO, orderSaleExportExcel); |
| | | orderSaleExportExcel.setCreateStrTime(DateUtils.localDateTimeToString(orderSaleVO.getCreateTime())); |
| | | orderSaleExportExcel.setGoodsAmount(orderSaleVO.getOrderSaleGoods().stream().map(TOrderSaleGoods::getSalePrice).reduce(BigDecimal::add).get()); |
| | | orderSaleExportExcel.setGoodsCount(orderSaleVO.getOrderSaleGoods().size()); |
| | | } |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |