xuhy
2024-09-05 b7fc2805e29fbe44013179204541513893afb7c3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDataStatisticsController.java
@@ -6,8 +6,11 @@
import com.ruoyi.system.query.TDataStatisticsQuery;
import com.ruoyi.system.service.TOrderMealService;
import com.ruoyi.system.service.TOrderSaleService;
import com.ruoyi.system.vo.OrderTrendsVO;
import com.ruoyi.system.vo.PersonnelStatisticsVO;
import com.ruoyi.system.vo.SalesRankingVO;
import com.ruoyi.system.vo.SalesVolumeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -24,6 +27,7 @@
 * @author xiaochen
 * @since 2024-08-27
 */
@Api(tags = "营业数据统计")
@RestController
@RequestMapping("/t-data-statistics")
public class TDataStatisticsController {
@@ -129,7 +133,7 @@
    @ApiOperation( value = "下单趋势")
    @PostMapping(value = "/orderingTrends")
    public AjaxResult<List<SalesRankingVO>> orderingTrends(@RequestBody TDataStatisticsQuery query) {
    public AjaxResult<List<OrderTrendsVO>> orderingTrends(@RequestBody TDataStatisticsQuery query) {
        Integer roleType = tokenService.getLoginUser().getRoleType();
        Long objectId = tokenService.getLoginUser().getObjectId();
        query.setShopId(objectId);
@@ -162,13 +166,50 @@
        }
        query.setStartTime(startTime);
        query.setEndTime(endTime);
        List<SalesRankingVO> salesRankingVOS;
        List<OrderTrendsVO> orderTrendsVOS;
        if(roleType == 2){
            salesRankingVOS = orderMealService.salesRanking(query);
            orderTrendsVOS = orderMealService.orderingTrends(query);
        }else{
            salesRankingVOS = orderSaleService.salesRanking(query);
            orderTrendsVOS = orderSaleService.orderingTrends(query);
        }
        return AjaxResult.success(salesRankingVOS);
        return AjaxResult.success(orderTrendsVOS);
    }
    @ApiOperation( value = "接待人数统计")
    @PostMapping(value = "/personnelStatistics")
    public AjaxResult<List<PersonnelStatisticsVO>> personnelStatistics(@RequestBody TDataStatisticsQuery query) {
        Long objectId = tokenService.getLoginUser().getObjectId();
        query.setShopId(objectId);
        if(Objects.isNull(query.getTimeType())){
            query.setTimeType(1);
        }
        LocalDateTime startTime = null;
        LocalDateTime endTime = null;
        switch (query.getTimeType()){
            case 1:
                // 今日
                startTime = LocalDateTime.MIN;
                endTime = LocalDateTime.MAX;
                break;
            case 2:
                // 昨日
                startTime = LocalDateTime.now().minusDays(1);
                endTime = LocalDateTime.now().minusDays(1);
                break;
            case 3:
                // 近7天
                startTime = LocalDateTime.now().minusDays(7);
                endTime = LocalDateTime.now();
                break;
            case 4:
                // 近30天
                startTime = LocalDateTime.now().minusDays(30);
                endTime = LocalDateTime.now();
                break;
        }
        query.setStartTime(startTime);
        query.setEndTime(endTime);
        return AjaxResult.success(orderMealService.personnelStatistics(query));
    }