HotGoodController.java
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.sl.ms.oms.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sl.ms.oms.dto.OrderCargoDTO;
import com.sl.ms.oms.entity.HotGoodEntity;
import com.sl.ms.oms.service.HotGoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* 热门货物
*/
@RestController
@RequestMapping("/good")
@Slf4j
public class HotGoodController {
@Resource
private HotGoodService hotGoodService;
/**
* 批量查询货物信息表
*
* @param name 热门货品名称
* @return 货品信息
*/
@GetMapping("/hot")
List<OrderCargoDTO> list(@RequestParam(name = "name", required = false) String name) {
return hotGoodService.list(Wrappers.<HotGoodEntity>lambdaQuery()
.like(ObjectUtil.isNotEmpty(name), HotGoodEntity::getName, name)
// 没有名称查询条件 则按照类型分组返回
.groupBy(ObjectUtil.isEmpty(name), HotGoodEntity::getGoodsTypeId)
.last("limit 20")
)
.stream()
.map(hotGoodEntity -> BeanUtil.toBean(hotGoodEntity, OrderCargoDTO.class))
.collect(Collectors.toList());
}
}