diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductLikeTopDto.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductLikeTopDto.java index 1eb28df7c..f0b7a983a 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductLikeTopDto.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/app/HardAppProductLikeTopDto.java @@ -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; + } diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/hard/PanelPorductVo.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/hard/PanelPorductVo.java index 8cddbf723..ae6172905 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/hard/PanelPorductVo.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/hard/PanelPorductVo.java @@ -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; - /** * 用餐人数 */ diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelNutritionController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelNutritionController.java new file mode 100644 index 000000000..5e353c9b9 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/panel/PanelNutritionController.java @@ -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> 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> 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)); + } + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelNutritionService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelNutritionService.java new file mode 100644 index 000000000..4404892bb --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/PanelNutritionService.java @@ -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 classCount(PanelProductDto dto); + + /** + * 菜品喜好排行 + */ + List cuisineTop(PanelProductDto dto); + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelNutritionServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelNutritionServiceImpl.java new file mode 100644 index 000000000..1ad037046 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/panel/PanelNutritionServiceImpl.java @@ -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 classCount(PanelProductDto dto) { + HardAppProductByClassifyDto classDto = new HardAppProductByClassifyDto(); + classDto.setPayTimeList(dto.getTotalTimeList()); + List 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 cuisineTop(PanelProductDto dto) { + HardAppProductLikeTopDto likeQuery = new HardAppProductLikeTopDto(); + likeQuery.setPayTimeList(dto.getTotalTimeList()); + List 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(); + } + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml index 84a3b8377..2b1de7195 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml @@ -375,6 +375,9 @@ and o.user_id = #{dto.userId} + + and o.pay_time between #{dto.payTimeList[0]} and #{dto.payTimeList[1]} + group by a.product_id order by SUM(a.product_count) desc