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 list = shopCategoryService.list(); List listVo = new ArrayList<>(); for (ShopCategory category : list) { List 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 wrapper = new LambdaQueryWrapper<>(); if(categoryId != null){ wrapper.eq(Shop::getCategoryId,categoryId); } if(deptId!=null){ List depts = deptService.getDeptSonList(deptId); Set 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)); } }