12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package com.cdf.controller.api;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.cdf.common.ResultData;
- import com.cdf.entity.Dept;
- import com.cdf.entity.Shop;
- import com.cdf.entity.ShopCategory;
- import com.cdf.entity.Video;
- import com.cdf.service.IDeptService;
- import com.cdf.service.IShopCategoryService;
- import com.cdf.service.IShopService;
- import com.cdf.service.IVideoService;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- 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 java.util.ArrayList;
- import java.util.List;
- import java.util.Set;
- import java.util.stream.Collectors;
- @RestController
- @RequestMapping("/api")
- public class ShopApiController {
- @Autowired
- private IShopCategoryService shopCategoryService;
- @Autowired
- private IShopService shopService;
- @Autowired
- private IDeptService deptService;
- @GetMapping("/getShopCategory")
- public ResultData getShopCategory(@RequestParam(required = false) String sceneNum){
- List<ShopCategory> list = shopCategoryService.list();
- List<ShopCategory> listVo = new ArrayList<>();
- for (ShopCategory category : list) {
- List<Shop> byCategory = shopService.getByCategoryAndSceneNum(category.getId(),sceneNum);
- if(byCategory != null && byCategory.size() >0){
- listVo.add(category);
- }
- }
- return ResultData.ok(listVo);
- }
- @GetMapping("/getShopByCategory")
- public ResultData getShopByCategory(@RequestParam(required = false) Integer categoryId,
- @RequestParam(required = false) String shopName,
- @RequestParam(required = false) String sceneNum,
- @RequestParam(required = false,defaultValue = "22") Integer deptId){
- LambdaQueryWrapper<Shop> wrapper = new LambdaQueryWrapper<>();
- if(categoryId != null){
- wrapper.eq(Shop::getCategoryId,categoryId);
- }
- if(deptId!=null){
- List<Dept> depts = deptService.getDeptSonList(deptId);
- Set<Integer> deptIds = depts.stream().map(Dept::getId).collect(Collectors.toSet());
- wrapper.in(Shop::getDeptId,deptIds);
- }
- if(StringUtils.isNotBlank(shopName)){
- wrapper.like(Shop::getShopName,shopName);
- }
- if(StringUtils.isNotBlank(sceneNum)){
- wrapper.eq(Shop::getSceneUrl,sceneNum);
- }
- wrapper.orderByAsc(Shop::getSort);
- wrapper.orderByDesc(Shop::getCreateTime);
- return ResultData.ok(shopService.list(wrapper));
- }
- }
|