xuhy
2024-09-19 45403c689e2e0d6e69d32e1833faabc116f859e2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDataStatisticsController.java
@@ -3,6 +3,7 @@
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.WebUtils;
@@ -19,6 +20,7 @@
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -195,7 +197,7 @@
    @ApiOperation( value = "商品分类销售排行")
    @PostMapping(value = "/salesRanking")
    public AjaxResult<List<SalesRankingVO>> salesRanking(@RequestBody TDataStatisticsQuery query) {
    public AjaxResult<PageInfo<SalesRankingVO>> salesRanking(@RequestBody TDataStatisticsQuery query) {
        Integer roleType = tokenService.getLoginUser().getRoleType();
        Long objectId = tokenService.getLoginUser().getObjectId();
        query.setShopId(objectId);
@@ -228,7 +230,7 @@
        }
        query.setStartTime(DateUtils.localDateTimeToDate(startTime));
        query.setEndTime(DateUtils.localDateTimeToDate(endTime));
        List<SalesRankingVO> salesRankingVOS;
        PageInfo<SalesRankingVO> salesRankingVOS;
        if(roleType == 2){
            salesRankingVOS = orderMealService.salesRanking(query);
        }else{
@@ -283,7 +285,7 @@
    @ApiOperation( value = "接待人数统计")
    @PostMapping(value = "/personnelStatistics")
    public AjaxResult<List<PersonnelStatisticsVO>> personnelStatistics(@RequestBody TDataStatisticsQuery query) {
    public AjaxResult<PersonnelStatisticsAndSumVO> personnelStatistics(@RequestBody TDataStatisticsQuery query) {
        Long objectId = tokenService.getLoginUser().getObjectId();
        query.setShopId(objectId);
        if(Objects.isNull(query.getTimeType())){
@@ -315,7 +317,16 @@
        }
        query.setStartTime(DateUtils.localDateTimeToDate(startTime));
        query.setEndTime(DateUtils.localDateTimeToDate(endTime));
        return AjaxResult.success(orderMealService.personnelStatistics(query));
        PersonnelStatisticsAndSumVO personnelStatisticsAndSumVO = new PersonnelStatisticsAndSumVO();
        List<PersonnelStatisticsVO> personnelStatisticsVOS = orderMealService.personnelStatistics(query);
        personnelStatisticsAndSumVO.setPersonnelStatisticsVOS(personnelStatisticsVOS);
        if(!CollectionUtils.isEmpty(personnelStatisticsVOS)){
            personnelStatisticsAndSumVO.setPersonCountSum(personnelStatisticsVOS.stream().filter(e->e.getPersonCount() != null).mapToInt(PersonnelStatisticsVO::getPersonCount).sum());
            // 计算列表中平均金额乘以人数的总和
            personnelStatisticsAndSumVO.setTotalMoney(personnelStatisticsVOS.stream().filter(e->e.getPersonCount() != null).mapToDouble(personnelStatisticsVO -> personnelStatisticsVO.getAvgAmount().doubleValue() * personnelStatisticsVO.getPersonCount()).sum());
        }
        return AjaxResult.success(personnelStatisticsAndSumVO);
    }