| | |
| | | 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.CheckoutDTO; |
| | | import com.ruoyi.system.dto.TOrderSaleDTO; |
| | | import com.ruoyi.system.importExcel.TOrderMealExportExcel; |
| | | import com.ruoyi.system.importExcel.TOrderSaleExportExcel; |
| | | import com.ruoyi.system.export.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.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @PostMapping(value = "/pageList") |
| | | public AjaxResult<PageInfo<TOrderSaleVO>> pageList(@RequestBody TOrderSaleQuery query) { |
| | | query.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | query.setIsCover(1); |
| | | return AjaxResult.success(orderSaleService.pageList(query)); |
| | | } |
| | | |
| | |
| | | */ |
| | | @ApiOperation( value = "查询销售金额统计") |
| | | @PostMapping(value = "/amountSum") |
| | | public AjaxResult<AmountSumVO> amountSum(@RequestBody TOrderMealQuery query) { |
| | | public AjaxResult<AmountSumVO> amountSum(@RequestBody TOrderSaleQuery query) { |
| | | query.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | return AjaxResult.success(orderSaleService.amountSum(query)); |
| | | } |
| | |
| | | @GetMapping(value = "/getDetailById") |
| | | public AjaxResult<TOrderSaleVO> getDetailById(@RequestParam(value = "id") Long id) { |
| | | TOrderSale orderSale = orderSaleService.getById(id); |
| | | if(Objects.isNull(orderSale)){ |
| | | return AjaxResult.error("未查询到销售单"); |
| | | } |
| | | 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); |
| | | BigDecimal sum = BigDecimal.ZERO; |
| | | Integer count = 0; |
| | | for (TOrderSaleGoods tOrderSaleGoods : list) { |
| | | sum = sum.add(tOrderSaleGoods.getThisSalePrice().multiply(new BigDecimal(tOrderSaleGoods.getGoodsCount()))); |
| | | count = count + tOrderSaleGoods.getGoodsCount(); |
| | | } |
| | | orderSaleVO.setGoodsAmount(sum); |
| | | orderSaleVO.setGoodsCount(count); |
| | | return AjaxResult.success(orderSaleVO); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 销售下单接口 |
| | | */ |
| | | @ApiOperation( value = "销售单修改接口") |
| | | @PostMapping(value = "/edit") |
| | | public AjaxResult<String> edit(@RequestBody TOrderSaleDTO dto) { |
| | | orderSaleService.edit(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @ApiOperation( value = "结账接口") |
| | | @PostMapping(value = "/checkout") |
| | | public AjaxResult<String> checkout(@Validated @RequestBody CheckoutDTO dto) { |
| | | orderSaleService.checkout(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 导出销售列表 |
| | | */ |
| | | @ApiOperation(value = "导出销售列表") |
| | | @PostMapping("/exportOrderSale") |
| | | public void exportOrderSale(@RequestBody TOrderMealQuery query) |
| | | { |
| | | query.setShopId(tokenService.getLoginUser().getObjectId()); |
| | | List<TOrderSaleVO> list = orderSaleService.exportOrderSale(query); |
| | | List<TOrderMealExportExcel> orderMeals = new ArrayList<>(); |
| | | List<TOrderSaleExportExcel> 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()); |
| | | orderSaleExportExcel.setGoodsAmount(orderSaleVO.getGoodsAmount()); |
| | | orderSaleExportExcel.setGoodsCount(orderSaleVO.getGoodsCount()); |
| | | orderMeals.add(orderSaleExportExcel); |
| | | } |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TOrderMealExportExcel.class, orderMeals); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TOrderSaleExportExcel.class, orderMeals); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |