feat:营养分析

This commit is contained in:
dzc committed 2025-10-14 18:27:35 +08:00
1 parent b525aec4ba
commit 8a08aa79e6
6 files changed
+165 -5

No files matched your search

@@ -2,6 +2,8 @@ package com.bsd.pjcloud.hard.api.dto.order.app;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 个人菜品喜好排行
*/
@@ -10,4 +12,6 @@ public class HardAppProductLikeTopDto {
private Long userId;
private LocalDateTime[] payTimeList;
}
@@ -19,11 +19,26 @@ import java.util.List;
@NoArgsConstructor
public class PanelPorductVo {
/**
* 分类名
*/
private String classifyName;
/**
* 分类ID
*/
private Long classifyId;
/**
* 商品名
*/
private String productName;
/**
* 商品id
*/
private Long productId;
/**
* 商家ID
*/
@@ -39,11 +54,6 @@ public class PanelPorductVo {
*/
private String hourType;
/**
* 商品名
*/
private String productStr;
/**
* 用餐人数
*/
@@ -0,0 +1,51 @@
package com.bsd.pjcloud.hard.controller.panel;
import cn.hutool.core.util.ObjectUtil;
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
import com.bsd.pjcloud.common.core.util.DateRangeTool;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.hard.api.dto.panel.PanelProductDto;
import com.bsd.pjcloud.hard.api.vo.hard.PanelPorductVo;
import com.bsd.pjcloud.hard.service.PanelNutritionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/panel-nutrition")
@Tag(description = "panel-nutrition", name = "营养统计")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PanelNutritionController {
private final PanelNutritionService panelNutritionService;
@PostMapping(value = "/class-count")
@Operation(summary = "食堂用餐分类统计")
public R<List<PanelPorductVo>> classCount(@RequestBody PanelProductDto dto) {
if (ObjectUtil.isNotEmpty(dto.getDateRangeType()) && ObjectUtil.isEmpty(dto.getTotalTimeList())) {
dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType()));
}
dto.setMchTypeCodes(List.of(MerchantTypeEnum.CANTEEN.getType()));
return R.ok(panelNutritionService.classCount(dto));
}
@PostMapping(value = "/cuisine-top")
@Operation(summary = "菜品喜好排行")
public R<List<PanelPorductVo>> cuisineTop(@RequestBody PanelProductDto dto) {
if (ObjectUtil.isNotEmpty(dto.getDateRangeType()) && ObjectUtil.isEmpty(dto.getTotalTimeList())) {
dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType()));
}
dto.setMchTypeCodes(List.of(MerchantTypeEnum.CANTEEN.getType()));
return R.ok(panelNutritionService.cuisineTop(dto));
}
}
@@ -0,0 +1,24 @@
package com.bsd.pjcloud.hard.service;
import com.bsd.pjcloud.hard.api.dto.panel.PanelProductDto;
import com.bsd.pjcloud.hard.api.vo.hard.PanelPorductVo;
import java.util.List;
/**
* @author liusiyang_dxm
* @since 2025/10/14
*/
public interface PanelNutritionService {
/**
* 食堂用餐分类统计
*/
List<PanelPorductVo> classCount(PanelProductDto dto);
/**
* 菜品喜好排行
*/
List<PanelPorductVo> cuisineTop(PanelProductDto dto);
}
@@ -0,0 +1,68 @@
package com.bsd.pjcloud.hard.service.impl.panel;
import com.bsd.pjcloud.hard.api.dto.order.app.HardAppProductByClassifyDto;
import com.bsd.pjcloud.hard.api.dto.order.app.HardAppProductLikeTopDto;
import com.bsd.pjcloud.hard.api.dto.panel.PanelProductDto;
import com.bsd.pjcloud.hard.api.vo.hard.PanelPorductVo;
import com.bsd.pjcloud.hard.api.vo.order.app.HardAppProductByClassifyVo;
import com.bsd.pjcloud.hard.api.vo.order.app.HardAppProductLikeTopVo;
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.service.HardCanteenTotalService;
import com.bsd.pjcloud.hard.service.PanelNutritionService;
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.List;
@Validated
@Slf4j
@RequiredArgsConstructor
@Service
public class PanelNutritionServiceImpl implements PanelNutritionService {
private final HardOrderMapper hardOrderMapper;
private final HardCanteenTotalService canteenTotalService;
private final RemoteMchService remoteMchService;
/**
* 食堂用餐分类统计
*/
@Override
public List<PanelPorductVo> classCount(PanelProductDto dto) {
HardAppProductByClassifyDto classDto = new HardAppProductByClassifyDto();
classDto.setPayTimeList(dto.getTotalTimeList());
List<HardAppProductByClassifyVo> list = canteenTotalService.productByClassify(classDto);
return list.stream().map((item) -> {
PanelPorductVo entity = new PanelPorductVo();
entity.setClassifyId(item.getClassifyId());
entity.setClassifyName(item.getClassifyName());
entity.setBuyCount(item.getPayCount());
entity.setBuyProductCount(item.getTimeCount());
entity.setPersonCount(item.getPayUserCount());
return entity;
}).toList();
}
/**
* 菜品喜好排行
*/
@Override
public List<PanelPorductVo> cuisineTop(PanelProductDto dto) {
HardAppProductLikeTopDto likeQuery = new HardAppProductLikeTopDto();
likeQuery.setPayTimeList(dto.getTotalTimeList());
List<HardAppProductLikeTopVo> list = canteenTotalService.productLikeTop(likeQuery);
return list.stream().map((item) -> {
PanelPorductVo entity = new PanelPorductVo();
entity.setProductName(item.getProductName());
entity.setProductId(item.getProductId());
entity.setBuyProductCount(item.getPayCount());
return entity;
}).toList();
}
}
@@ -375,6 +375,9 @@
<if test="dto.userId != null and dto.userId != '' ">
and o.user_id = #{dto.userId}
</if>
<if test="dto.payTimeList != null and dto.payTimeList.length == 2">
and o.pay_time between #{dto.payTimeList[0]} and #{dto.payTimeList[1]}
</if>
</where>
group by a.product_id
order by SUM(a.product_count) desc