feat:营养分析趋势

This commit is contained in:
dzc committed 2025-10-16 09:55:01 +08:00
1 parent 966d78b41b
commit 47e7e97075
4 files changed
+103 -10

No files matched your search

@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.List;
@RestController
@@ -68,4 +69,25 @@ public class PanelNutritionController {
return R.ok(panelNutritionService.nutritionTotal(dto));
}
@PostMapping(value = "/nutrition/trend")
@Operation(summary = "营养分析(趋势)")
public R<PanelPorductVo.NutritionTypeVo> nutritionTrend(@RequestBody PanelProductDto dto) {
dto.setTotalTimeList(new LocalDateTime[]{
LocalDateTime.now().minusDays(8).withHour(0).withMinute(0).withSecond(0),
LocalDateTime.now().withHour(23).withMinute(59).withSecond(59)
});
dto.setMchTypeCodes(List.of(MerchantTypeEnum.CANTEEN.getType()));
return R.ok(panelNutritionService.nutritionByTime(dto));
}
@PostMapping(value = "/repurchase")
@Operation(summary = "复购排行榜")
public R<List<PanelPorductVo>> repurchase(@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.repurchase(dto));
}
}
@@ -30,4 +30,9 @@ public interface PanelNutritionService {
* 营养分析(总数统计)
*/
List<PanelPorductVo> nutritionTotal(PanelProductDto dto);
/**
* 复购排行榜
*/
List<PanelPorductVo> repurchase(PanelProductDto dto);
}
@@ -23,6 +23,8 @@ import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@@ -179,12 +181,36 @@ public class PanelNutritionServiceImpl implements PanelNutritionService {
return null;
}
/**
* 复购排行榜
*/
@Override
public List<PanelPorductVo> repurchase(PanelProductDto dto) {
PanelPorductVo panelPorductVo = hardOrderMapper.groupCount(dto);
return List.of();
}
private List<Map<String, Object>> nutritionSetting() {
return List.of(
Map.of("key", "hc", "name", "荤菜", "classify", new ArrayList<Long>(), "order", 0),
Map.of("key", "sc", "name", "素菜", "classify", new ArrayList<Long>(), "order", 1),
Map.of("key", "zs", "name", "主食", "classify", new ArrayList<Long>(), "order", 2)
);
Map<String, Object> hcMap = new HashMap<>();
hcMap.put("key", "hc");
hcMap.put("name", "荤菜");
hcMap.put("classify", new ArrayList<Long>());
hcMap.put("order", 0);
Map<String, Object> scMap = new HashMap<>();
scMap.put("key", "sc");
scMap.put("name", "素菜");
scMap.put("classify", new ArrayList<Long>());
scMap.put("order", 1);
Map<String, Object> zsMap = new HashMap<>();
zsMap.put("key", "zs");
zsMap.put("name", "主食");
zsMap.put("classify", new ArrayList<Long>());
zsMap.put("order", 2);
return Arrays.asList(hcMap, scMap, zsMap);
}
}
@@ -554,7 +554,8 @@
select SUM(a.product_count) as buyProductCount,
SUM(a.total_price) as totalPrice,
count(distinct o.id) as buyCount,
count(distinct o.user_id) as personCount
count(distinct o.user_id) as personCount,
s.category_id as classifyId
from hard_car a
inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0'
inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0' and o.hour_type is not null and
@@ -562,6 +563,7 @@
<if test="dto.hourTypeIsNull == null">
and o.hour_type is not null and o.hour_type not in ('-1', 'null')
</if>
left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id
<where>
a.del_flag = '0'
<if test="dto.totalTimeList != null and dto.totalTimeList.length == 2">
@@ -576,6 +578,12 @@
#{v}
</foreach>
</if>
<if test="dto.classifyIds != null and dto.classifyIds.size() != 0">
and s.category_id in
<foreach collection="dto.classifyIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
</select>
@@ -586,13 +594,15 @@
SUM(a.product_count) as buyProductCount,
SUM(a.total_price) as totalPrice,
count(distinct o.id) as buyCount,
count(distinct o.user_id) as personCount
count(distinct o.user_id) as personCount,
s.category_id as classifyId
from hard_car a
inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0'
inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0'
<if test="dto.hourTypeIsNull == null">
and o.hour_type is not null and o.hour_type not in ('-1', 'null')
</if>
left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id
<where>
a.del_flag = '0'
<if test="dto.totalTimeList != null and dto.totalTimeList.length == 2">
@@ -607,6 +617,12 @@
#{v}
</foreach>
</if>
<if test="dto.classifyIds != null and dto.classifyIds.size() != 0">
and s.category_id in
<foreach collection="dto.classifyIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by date(o.create_time)
order by date(o.create_time) desc
@@ -622,13 +638,15 @@
SUM(a.product_count) as buyProductCount,
SUM(a.total_price) as totalPrice,
count(distinct o.id) as buyCount,
count(distinct o.user_id) as personCount
count(distinct o.user_id) as personCount,
s.category_id as classifyId
from hard_car a
inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0'
inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0'
<if test="dto.hourTypeIsNull == null">
and o.hour_type is not null and o.hour_type not in ('-1', 'null')
</if>
left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id
<where>
a.del_flag = '0'
<if test="dto.totalTimeList != null and dto.totalTimeList.length == 2">
@@ -643,6 +661,12 @@
#{v}
</foreach>
</if>
<if test="dto.classifyIds != null and dto.classifyIds.size() != 0">
and s.category_id in
<foreach collection="dto.classifyIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by date(o.create_time), o.hour_type
order by date(o.create_time) desc
@@ -658,13 +682,15 @@
SUM(a.product_count) as buyProductCount,
SUM(a.total_price) as totalPrice,
count(distinct o.id) as buyCount,
count(distinct o.user_id) as personCount
count(distinct o.user_id) as personCount,
s.category_id as classifyId
from hard_car a
inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0'
inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0'
<if test="dto.hourTypeIsNull == null">
and o.hour_type is not null and o.hour_type not in ('-1', 'null')
</if>
left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id
<where>
a.del_flag = '0'
<if test="dto.totalTimeList != null and dto.totalTimeList.length == 2">
@@ -679,6 +705,12 @@
#{v}
</foreach>
</if>
<if test="dto.classifyIds != null and dto.classifyIds.size() != 0">
and s.category_id in
<foreach collection="dto.classifyIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by date_format(o.create_time, '%Y-%m'), o.hour_type
order by date_format(o.create_time, '%Y-%m') desc
@@ -692,13 +724,15 @@
sum(a.product_count) as buyProductCount,
SUM(a.total_price) as totalPrice,
count(distinct o.id) as buyCount,
count(distinct o.user_id) as personCount
count(distinct o.user_id) as personCount,
s.category_id as classifyId
from hard_car a
inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0'
inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0'
<if test="dto.hourTypeIsNull == null">
and o.hour_type is not null and o.hour_type not in ('-1', 'null')
</if>
left join pjcloudx_canteen.canteen_spu s on a.product_id = s.id
<where>
a.del_flag = '0'
<if test="dto.totalTimeList != null and dto.totalTimeList.length == 2">
@@ -713,6 +747,12 @@
#{v}
</foreach>
</if>
<if test="dto.classifyIds != null and dto.classifyIds.size() != 0">
and s.category_id in
<foreach collection="dto.classifyIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by o.merchant_id
order by sum(a.product_count) desc