| | |
| | | import com.ruoyi.system.dto.*; |
| | | import com.ruoyi.system.mapper.TOrderMealGoodsMapper; |
| | | import com.ruoyi.system.mapper.TOrderMealMapper; |
| | | import com.ruoyi.system.query.TDataGeneratorMealQuery; |
| | | import com.ruoyi.system.query.TDataStatisticsQuery; |
| | | import com.ruoyi.system.query.TOrderMealQuery; |
| | | import com.ruoyi.system.query.*; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | switch (query.getTimeType()){ |
| | | case 1: |
| | | // 今日 |
| | | startTime = LocalDateTime.MIN; |
| | | endTime = LocalDateTime.MAX; |
| | | startTime = DateUtils.getDayStart(LocalDateTime.now()); |
| | | endTime = DateUtils.getDayEnd(LocalDateTime.now()); |
| | | break; |
| | | case 2: |
| | | // 昨日 |
| | | startTime = LocalDateTime.now().minusDays(1); |
| | | endTime = LocalDateTime.now().minusDays(1); |
| | | startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); |
| | | endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); |
| | | break; |
| | | case 3: |
| | | // 近7天 |
| | | startTime = LocalDateTime.now().minusDays(7); |
| | | endTime = LocalDateTime.now(); |
| | | startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); |
| | | endTime = DateUtils.getDayEnd(LocalDateTime.now()); |
| | | break; |
| | | case 4: |
| | | // 近30天 |
| | | startTime = LocalDateTime.now().minusDays(30); |
| | | endTime = LocalDateTime.now(); |
| | | startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); |
| | | endTime = DateUtils.getDayEnd(LocalDateTime.now()); |
| | | break; |
| | | } |
| | | query.setStartTime(DateUtils.localDateTimeToDate(startTime)); |
| | |
| | | switch (query.getTimeType()){ |
| | | case 1: |
| | | // 今日 |
| | | startTime = LocalDateTime.MIN; |
| | | endTime = LocalDateTime.MAX; |
| | | startTime = DateUtils.getDayStart(LocalDateTime.now()); |
| | | endTime = DateUtils.getDayEnd(LocalDateTime.now()); |
| | | break; |
| | | case 2: |
| | | // 昨日 |
| | | startTime = LocalDateTime.now().minusDays(1); |
| | | endTime = LocalDateTime.now().minusDays(1); |
| | | startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); |
| | | endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); |
| | | break; |
| | | case 3: |
| | | // 近7天 |
| | | startTime = LocalDateTime.now().minusDays(7); |
| | | endTime = LocalDateTime.now(); |
| | | startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); |
| | | endTime = DateUtils.getDayEnd(LocalDateTime.now()); |
| | | break; |
| | | case 4: |
| | | // 近30天 |
| | | startTime = LocalDateTime.now().minusDays(30); |
| | | endTime = LocalDateTime.now(); |
| | | startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); |
| | | endTime = DateUtils.getDayEnd(LocalDateTime.now()); |
| | | break; |
| | | } |
| | | query.setStartTime(DateUtils.localDateTimeToDate(startTime)); |
| | |
| | | this.save(dto); |
| | | } |
| | | |
| | | @Override |
| | | public List<TDataGeneratorVO> mealGeneratorListExport(TDataGeneratorQuery query) { |
| | | List<TDataGeneratorVO> list = this.baseMapper.mealGeneratorListExport(query); |
| | | List<Long> ids = list.stream().map(TDataGeneratorVO::getId).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(ids)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<TOrderMeal> orderMeals = this.list(Wrappers.lambdaQuery(TOrderMeal.class) |
| | | .in(TOrderMeal::getGeneratorId, ids)); |
| | | List<Long> mealIds = orderMeals.stream().map(TOrderMeal::getId).collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(mealIds)){ |
| | | List<TOrderMealGoods> mealGoods = orderMealGoodsService.list(Wrappers.lambdaQuery(TOrderMealGoods.class) |
| | | .in(TOrderMealGoods::getOrderId, mealIds)); |
| | | for (TDataGeneratorVO tDataGeneratorVO : list) { |
| | | List<Long> collect = orderMeals.stream().filter(e -> e.getGeneratorId().equals(tDataGeneratorVO.getId())).map(TOrderMeal::getId).collect(Collectors.toList()); |
| | | BigDecimal money = mealGoods.stream().filter(e -> collect.contains(e.getOrderId())) |
| | | .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getGoodsSalePrice().multiply(new BigDecimal(y.getGoodsCount()))), BigDecimal::add); |
| | | tDataGeneratorVO.setTotalRevenue(money); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public ProfitDetailsVO profitDetails(ProfitDetailsQuery query) { |
| | | |
| | | ProfitDetailsVO profitDetailsVO = new ProfitDetailsVO(); |
| | | // 查询商品盈利明细 |
| | | PageInfo<GoodsProfitVO> pageInfo = new PageInfo<>(query.getPageNum(),query.getPageSize()); |
| | | List<GoodsProfitVO> list = this.baseMapper.profitDetails(query,pageInfo); |
| | | pageInfo.setRecords(list); |
| | | profitDetailsVO.setGoodsProfitVOS(pageInfo); |
| | | |
| | | // 统计商品金额 |
| | | Map<String,BigDecimal> map = this.baseMapper.profitDetailsStatistics(query); |
| | | profitDetailsVO.setTotalProfits(new BigDecimal(map.get("totalProfits").toString())); |
| | | profitDetailsVO.setTotalCosts(new BigDecimal(map.get("totalCosts").toString())); |
| | | profitDetailsVO.setTotalSales(new BigDecimal(map.get("totalSales").toString())); |
| | | return profitDetailsVO; |
| | | } |
| | | |
| | | @Override |
| | | public List<GoodsProfitVO> profitDetailsExport(ProfitDetailsQuery query) { |
| | | return this.baseMapper.profitDetailsExport(query); |
| | | } |
| | | |
| | | } |