| | |
| | | @Autowired |
| | | private TFoundationConfigService foundationConfigService; |
| | | @Autowired |
| | | private TFoundationPersonService foundationPersonService; |
| | | @Autowired |
| | | private TGoodsService goodsService; |
| | | @Autowired |
| | | private TOrderMealService orderMealService; |
| | |
| | | dataGenerator.setOtherPay(dto.getOtherProportion()); |
| | | this.save(dataGenerator); |
| | | long start = System.currentTimeMillis(); |
| | | // 查询所有的人数用餐标准 |
| | | List<TFoundationConfigVO> foundationConfigs = foundationConfigService.getList(dto.getShopId()); |
| | | TShop shop = shopService.getById(dto.getShopId()); |
| | | List<TFoundationConfigVO> foundationConfigs = foundationConfigService.getList(shop.getMealType()); |
| | | if(CollectionUtils.isEmpty(foundationConfigs)){ |
| | | throw new ServiceException("请先添加该店铺用餐标准"); |
| | | throw new ServiceException("请先添加中餐或火锅用餐标准"); |
| | | } |
| | | // 查询所有桌子 |
| | | List<TBoard> boards = boardService.list(Wrappers.lambdaQuery(TBoard.class) |
| | |
| | | List<OrderMealGeneratorCountDTO> orderMealGeneratorCountDTOS = dto.getOrderMealGeneratorCountDTOS(); |
| | | List<TOrderMeal> orderMeals = new ArrayList<>(); |
| | | for (OrderMealGeneratorCountDTO orderMealGeneratorCountDTO : orderMealGeneratorCountDTOS) { |
| | | TBoard board = boards.stream().filter(e -> e.getId().equals(orderMealGeneratorCountDTO.getBoardId())).findFirst().get(); |
| | | TBoard board = boards.stream().filter(e -> e.getId().equals(orderMealGeneratorCountDTO.getBoardId())).findFirst().orElse(null); |
| | | if(Objects.isNull(board)){ |
| | | throw new ServiceException("该桌台信息不存在"); |
| | | } |
| | | Integer orderCount = orderMealGeneratorCountDTO.getOrderCount(); |
| | | if(orderCount == 0){ |
| | | continue; |
| | | } |
| | | // 查询当前桌的用餐人数 |
| | | for (int i = 1; i <= orderCount; i++) { |
| | | int random = getRandom(board.getMinPerson(), board.getMaxPerson()); |
| | |
| | | orderMeal.setMealType(1); |
| | | orderMeal.setMealPerson(random); |
| | | orderMeal.setMealTime(orderMealGeneratorCountDTO.getTime()); |
| | | orderMeal.setOrderNum(OrderNumConstants.MEAL + CodeGenerateUtils.generateVolumeSn()); |
| | | String num = OrderNumConstants.MEAL + CodeGenerateUtils.generateVolumeSn(); |
| | | // long count1 = orderMealService.count(Wrappers.lambdaQuery(TOrderMeal.class) |
| | | // .eq(TOrderMeal::getOrderNum, num)); |
| | | // if(count1>0){ |
| | | // num = CodeGenerateUtils.generateVolumeSn(); |
| | | // } |
| | | orderMeal.setOrderNum(num); |
| | | orderMeal.setStatus(2); |
| | | List<TOrderMealGoods> orderMealGoods = new ArrayList<>(); |
| | | // 获取当前桌的菜品 |
| | | List<TFoundationConfigVO> foundationConfigVOS = foundationConfigs.stream().filter(e -> e.getMealCount().equals(random)).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(foundationConfigVOS)){ |
| | | throw new ServiceException("桌台"+random+"人餐,人数配置不存在"); |
| | | } |
| | | // 每种菜品分类需要几个菜的生成 |
| | | foundationConfigVOS.forEach(e -> { |
| | | int random1 = getRandom(e.getMinCount(), e.getMaxCount()); |
| | | List<TGoods> typeGoods = goods.stream().filter(m -> e.getTypeId().equals(m.getTypeId())).collect(Collectors.toList()); |
| | | typeGoods = randomSelection(typeGoods, random1); |
| | | List<TGoods> typeGoodsList = goods.stream().filter(m -> e.getTypeId().equals(m.getTypeId())).collect(Collectors.toList()); |
| | | List<TGoods> typeGoods = randomSelection(typeGoodsList, random1); |
| | | if(typeGoods.size() != random1){ |
| | | List<TGoods> goods1 = randomSelection(typeGoodsList, random1 - typeGoods.size()); |
| | | typeGoods.addAll(goods1); |
| | | } |
| | | for (TGoods typeGood : typeGoods) { |
| | | int count = 0; |
| | | for (TOrderMealGoods good : orderMealGoods) { |
| | | if (good.getGoodsNum().equals(typeGood.getGoodsNum())) { |
| | | count+=1; |
| | | good.setGoodsCount(good.getGoodsCount() + 1); |
| | | good.setGoodsSalePrice(good.getGoodsSalePrice().add(typeGood.getSalePrice())); |
| | | // good.setGoodsSalePrice(good.getGoodsSalePrice().add(typeGood.getSalePrice())); |
| | | break; // 找到后直接跳出循环 |
| | | } |
| | | } |
| | |
| | | // 查询上一次开始之后的订单数据 |
| | | List<TOrderSale> orderSales1 = orderSaleService.list(new LambdaQueryWrapper<TOrderSale>().gt(TOrderSale::getOrderTime, startTime1)); |
| | | List<Long> saleIds1 = orderSales1.stream().map(TOrderSale::getId).collect(Collectors.toList()); |
| | | // 查询上一次的商品 |
| | | List<TOrderSaleGoods> list = orderSaleGoodsService.list(new LambdaQueryWrapper<TOrderSaleGoods>().in(TOrderSaleGoods::getOrderId, saleIds1)); |
| | | // 结合上次最后一次的数据 |
| | | list.addAll(orderSaleGoodsList); |
| | | List<TOrderSaleGoods> list; |
| | | if(CollectionUtils.isEmpty(saleIds1)){ |
| | | // 查询上一次的商品 |
| | | list = orderSaleGoodsService.list(new LambdaQueryWrapper<TOrderSaleGoods>().in(TOrderSaleGoods::getOrderId, saleIds1)); |
| | | // 结合上次最后一次的数据 |
| | | list.addAll(orderSaleGoodsList); |
| | | }else { |
| | | list = orderSaleGoodsList; |
| | | } |
| | | // 删除上一次的数据生成 新生成一条数据 |
| | | TOrderStock orderStock = new TOrderStock(); |
| | | orderStock.setStockNum(OrderNumConstants.STOCK + CodeGenerateUtils.generateVolumeSn()); |
| | |
| | | return; |
| | | } |
| | | // 删除上一次的数据生成 |
| | | if(Objects.nonNull(orderStockLast)){ |
| | | if(Objects.nonNull(orderStockLast) && Objects.nonNull(stockDataSet) && stockDataSets.size() > 1){ |
| | | orderStockService.removeById(orderStockLast); |
| | | } |
| | | orderSaleService.saveBatch(orderSales); |
| | |
| | | // BigDecimal money = orderSaleGoods.stream().filter(e -> collect.contains(e.getOrderId())) |
| | | // .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getGoodsCostPrice().multiply(new BigDecimal(y.getGoodsCount()))), BigDecimal::add); |
| | | if(!CollectionUtils.isEmpty(orderSales)){ |
| | | BigDecimal money = orderSales.stream().map(TOrderSale::getPayMoney).reduce(BigDecimal::add).get(); |
| | | List<TOrderSale> collect = orderSales.stream().filter(e -> e.getGeneratorId().equals(tDataGeneratorVO.getId())).collect(Collectors.toList()); |
| | | BigDecimal money = BigDecimal.ZERO; |
| | | if(!CollectionUtils.isEmpty(collect)){ |
| | | money = collect.stream().map(TOrderSale::getPayMoney).reduce(BigDecimal::add).get(); |
| | | } |
| | | tDataGeneratorVO.setTotalRevenue(money); |
| | | } |
| | | } |
| | |
| | | // 统计支付金额 |
| | | Map<String, Object> map = orderStockService.getDataGeneratorStockDetail(query); |
| | | Integer totalStock = Integer.parseInt(map.get("totalStock").toString()); |
| | | BigDecimal stockAmountSum = new BigDecimal(map.get("stockAmountSum").toString()); |
| | | // BigDecimal stockAmountSum = new BigDecimal(map.get("stockAmountSum").toString()); |
| | | data.setTotalStock(totalStock); |
| | | data.setStockAmountSum(stockAmountSum); |
| | | List<TOrderStock> list = orderStockService.list(Wrappers.lambdaQuery(TOrderStock.class) |
| | | .eq(TOrderStock::getGeneratorId, query.getGeneratorId())); |
| | | if(CollectionUtils.isEmpty(list)){ |
| | | data.setStockAmountSum(BigDecimal.ZERO); |
| | | }else { |
| | | data.setStockAmountSum(list.stream().filter(e->Objects.nonNull(e.getStockTotalPrice())).map(TOrderStock::getStockTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | } |
| | | return data; |
| | | } |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByShopId(Long shopId) { |
| | | this.baseMapper.deleteByShopId(shopId); |
| | | } |
| | | |
| | | private int getRandomPayType(Integer size,BigDecimal count) { |
| | | BigDecimal bigDecimal = new BigDecimal(size).multiply(count.divide(new BigDecimal(100))).setScale(0, BigDecimal.ROUND_FLOOR); |
| | | return Integer.parseInt(bigDecimal.toString()); |