ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDataStatisticsController.java
@@ -6,6 +6,7 @@ import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.WebUtils; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.export.SaleGeneratorListExport; @@ -28,6 +29,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URLEncoder; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -63,6 +65,7 @@ Integer roleType = tokenService.getLoginUser().getRoleType(); Long objectId = tokenService.getLoginUser().getObjectId(); query.setShopId(objectId); if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ if(Objects.isNull(query.getTimeType())){ query.setTimeType(1); } @@ -92,6 +95,7 @@ } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } SalesVolumeVO salesVolumeVO; if(roleType == 2){ salesVolumeVO = orderMealService.salesVolume(query); @@ -106,6 +110,7 @@ public AjaxResult<ProfitDetailsVO> profitDetails(@RequestBody ProfitDetailsQuery query) { Long objectId = tokenService.getLoginUser().getObjectId(); query.setShopId(objectId); if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ if(Objects.nonNull(query.getTimeType())){ LocalDateTime startTime = null; LocalDateTime endTime = null; @@ -133,6 +138,7 @@ } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } } return AjaxResult.success(orderMealService.profitDetails(query)); } @@ -142,6 +148,8 @@ public void profitDetailsExport(@RequestBody ProfitDetailsQuery query) { Long objectId = tokenService.getLoginUser().getObjectId(); query.setShopId(objectId); if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ if(Objects.nonNull(query.getTimeType())){ LocalDateTime startTime = null; LocalDateTime endTime = null; @@ -169,6 +177,7 @@ } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } } List<GoodsProfitVO> list = orderMealService.profitDetailsExport(query); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), GoodsProfitVO.class, list); @@ -201,6 +210,7 @@ Integer roleType = tokenService.getLoginUser().getRoleType(); Long objectId = tokenService.getLoginUser().getObjectId(); query.setShopId(objectId); if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ if(Objects.isNull(query.getTimeType())){ query.setTimeType(1); } @@ -230,6 +240,7 @@ } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } PageInfo<SalesRankingVO> salesRankingVOS; if(roleType == 2){ salesRankingVOS = orderMealService.salesRanking(query); @@ -245,6 +256,8 @@ Integer roleType = tokenService.getLoginUser().getRoleType(); Long objectId = tokenService.getLoginUser().getObjectId(); query.setShopId(objectId); if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ if(Objects.isNull(query.getTimeType())){ query.setTimeType(3); } @@ -274,11 +287,15 @@ } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } List<OrderTrendsVO> orderTrendsVOS; if(roleType == 2){ orderTrendsVOS = orderMealService.orderingTrends(query); }else{ orderTrendsVOS = orderSaleService.orderingTrends(query); } if (!CollectionUtils.isEmpty(orderTrendsVOS) && Objects.isNull(orderTrendsVOS.get(0).getDayTime())){ orderTrendsVOS.get(0).setDayTime(LocalDate.now().toString()); } return AjaxResult.success(orderTrendsVOS); } @@ -288,6 +305,8 @@ public AjaxResult<PersonnelStatisticsAndSumVO> personnelStatistics(@RequestBody TDataStatisticsQuery query) { Long objectId = tokenService.getLoginUser().getObjectId(); query.setShopId(objectId); if(StringUtils.isEmpty(query.getStartTime()) && StringUtils.isEmpty(query.getEndTime())){ if(Objects.isNull(query.getTimeType())){ query.setTimeType(1); } @@ -317,6 +336,7 @@ } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); query.setEndTime(DateUtils.localDateTimeToDate(endTime)); } PersonnelStatisticsAndSumVO personnelStatisticsAndSumVO = new PersonnelStatisticsAndSumVO(); List<PersonnelStatisticsVO> personnelStatisticsVOS = orderMealService.personnelStatistics(query); ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java
@@ -91,17 +91,20 @@ long start = System.currentTimeMillis(); // 查询所有的人数用餐标准 List<TFoundationConfigVO> foundationConfigs = foundationConfigService.getList(dto.getShopId()); if(CollectionUtils.isEmpty(foundationConfigs)){ throw new ServiceException("请先添加该店铺用餐标准"); } // 查询所有桌子 List<TBoard> boards = boardService.list(Wrappers.lambdaQuery(TBoard.class) .eq(TBoard::getShopId,dto.getShopId())); if(CollectionUtils.isEmpty(boards)){ throw new ServiceException("请先添加桌台信息"); throw new ServiceException("请先添加该店铺桌台信息"); } // 查询所有菜品 List<TGoods> goods = goodsService.list(Wrappers.lambdaQuery(TGoods.class) .eq(TGoods::getShopId,dto.getShopId())); if(CollectionUtils.isEmpty(goods)){ throw new ServiceException("请先添加菜品信息"); throw new ServiceException("请先添加该店铺菜品信息"); } // 循环待生成订单列表,添加到集合中,批量插入 List<OrderMealGeneratorCountDTO> orderMealGeneratorCountDTOS = dto.getOrderMealGeneratorCountDTOS(); @@ -151,8 +154,8 @@ }); if(!CollectionUtils.isEmpty(orderMealGoods)){ orderMeal.setMealOrderGoods(orderMealGoods); orderMeal.setOrderMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get()); orderMeal.setPayMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get()); orderMeal.setOrderMoney(orderMealGoods.stream().map(good->good.getGoodsSalePrice().multiply(new BigDecimal(good.getGoodsCount()))).reduce(BigDecimal::add).get()); orderMeal.setPayMoney(orderMealGoods.stream().map(good->good.getGoodsSalePrice().multiply(new BigDecimal(good.getGoodsCount()))).reduce(BigDecimal::add).get()); orderMeals.add(orderMeal); } } @@ -492,15 +495,15 @@ if(dataGenerator.getOrderType() == 1){ // 删除时间段的数据 orderMealService.remove(Wrappers.lambdaQuery(TOrderMeal.class) .gt(TOrderMeal::getCreateTime, dataGenerator.getStartTime()) .lt(TOrderMeal::getCreateTime, dataGenerator.getEndTime())); .gt(TOrderMeal::getMealTime, dataGenerator.getStartTime()) .lt(TOrderMeal::getMealTime, dataGenerator.getEndTime())); // 修改覆盖类型为已覆盖 orderMealService.update(Wrappers.lambdaUpdate(TOrderMeal.class).set(TOrderMeal::getIsCover, 1).eq(TOrderMeal::getGeneratorId, id)); }else { // 删除时间段的数据 orderStockService.remove(Wrappers.lambdaQuery(TOrderStock.class) .gt(TOrderStock::getCreateTime, dataGenerator.getStartTime()) .lt(TOrderStock::getCreateTime, dataGenerator.getEndTime())); .gt(TOrderStock::getStockTime, dataGenerator.getStartTime()) .lt(TOrderStock::getStockTime, dataGenerator.getEndTime())); // 修改覆盖类型为已覆盖 orderStockService.update(Wrappers.lambdaUpdate(TOrderStock.class).set(TOrderStock::getIsCover, 1).eq(TOrderStock::getGeneratorId, id)); } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOrderMealServiceImpl.java
@@ -234,7 +234,7 @@ PageInfo<SalesRankingVO> pageInfo = new PageInfo<>(query.getPageNum(),query.getPageSize()); List<TOrderMeal> list = this.list(Wrappers.lambdaQuery(TOrderMeal.class) .eq(TOrderMeal::getShopId, query.getShopId()) .between(TOrderMeal::getCreateTime, query.getStartTime(), query.getEndTime())); .between(TOrderMeal::getMealTime, query.getStartTime(), query.getEndTime())); List<Long> ids = list.stream().map(TOrderMeal::getId).collect(Collectors.toList()); if(CollectionUtils.isEmpty(ids)){ return new PageInfo<>(); ruoyi-system/src/main/resources/mapper/system/TOrderMealGoodsMapper.xml
@@ -33,17 +33,19 @@ </where> </select> <select id="salesRanking" resultType="com.ruoyi.system.vo.SalesRankingVO"> SELECT typeName,SUM(goodsSalePrice*goodsCount) AS salesVolume from t_order_meal_goods SELECT tomg.typeName,SUM(tomg.goodsSalePrice*goodsCount) AS salesVolume from t_order_meal_goods tomg left join t_order_meal tom on tomg.orderId=tom.id <where> <if test="ids != null and ids.size()>0"> AND orderId IN AND tomg.orderId IN <foreach collection="ids" item="id" open="(" separator="," close=")"> #{id} </foreach> </if> AND tom.isCover = 1 </where> GROUP BY typeName GROUP BY tomg.typeName </select> </mapper> ruoyi-system/src/main/resources/mapper/system/TOrderMealMapper.xml
@@ -107,6 +107,7 @@ AND (mealTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND isCover = 1 </where> </select> <select id="exportOrderMeal" resultType="com.ruoyi.system.vo.TOrderMealVO"> @@ -140,7 +141,7 @@ </select> <select id="orderingTrends" resultType="com.ruoyi.system.vo.OrderTrendsVO"> select DATE_FORMAT(createTime, '%Y-%m-%d') AS dayTime, DATE_FORMAT(mealTime, '%Y-%m-%d') AS dayTime, COUNT(id) AS orderCount from t_order_meal <where> @@ -148,14 +149,15 @@ AND shopId = #{query.shopId} </if> <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''"> AND (createTime BETWEEN #{query.startTime} AND #{query.endTime}) AND (mealTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND isCover = 1 </where> </select> <select id="personnelStatistics" resultType="com.ruoyi.system.vo.PersonnelStatisticsVO"> select tb.boardName,tom.mealPerson, (tom.payMoney/tom.mealPerson) AS avgAmount tb.boardName,tom.mealPerson AS personCount, ROUND((tom.payMoney/tom.mealPerson),2) AS avgAmount from t_order_meal tom left join t_board tb on tb.id = tom.boardId <where> @@ -163,9 +165,10 @@ AND tom.shopId = #{query.shopId} </if> <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''"> AND (tom.createTime BETWEEN #{query.startTime} AND #{query.endTime}) AND (tom.mealTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} AND tom.isCover = 1 </where> </select> <select id="pageListGenerator" resultType="com.ruoyi.system.vo.TOrderMealVO"> ruoyi-system/src/main/resources/mapper/system/TOrderSaleMapper.xml
@@ -90,7 +90,7 @@ and shopId = #{query.shopId} </if> <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''"> AND (createTime BETWEEN #{query.startTime} AND #{query.endTime}) AND (orderTime BETWEEN #{query.startTime} AND #{query.endTime}) </if> AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} </where>