Search in sources :

Example 1 with VanTreeSelectVo

use of com.wayn.common.core.domain.vo.VanTreeSelectVo in project waynboot-mall by wayn111.

the class CategoryController method index.

@GetMapping("index")
public R index(@RequestParam(required = false) Long id) {
    R success = R.success();
    List<VanTreeSelectVo> categoryList = iCategoryService.selectL1Category();
    Callable<Category> currentCategoryCallable;
    Callable<List<VanTreeSelectVo>> subCategoryListCallable;
    if (Objects.isNull(id) && CollectionUtils.isNotEmpty(categoryList)) {
        currentCategoryCallable = () -> iCategoryService.getById(categoryList.get(0).getId());
        subCategoryListCallable = () -> iCategoryService.selectCategoryByPid(categoryList.get(0).getId());
    } else {
        currentCategoryCallable = () -> iCategoryService.getById(id);
        subCategoryListCallable = () -> iCategoryService.selectCategoryByPid(id);
    }
    FutureTask<Category> currentCategoryTask = new FutureTask<>(currentCategoryCallable);
    FutureTask<List<VanTreeSelectVo>> subCategoryListTask = new FutureTask<>(subCategoryListCallable);
    categoryThreadPoolTaskExecutor.submit(currentCategoryTask);
    categoryThreadPoolTaskExecutor.submit(subCategoryListTask);
    try {
        success.add("categoryList", categoryList);
        success.add("currentCategory", currentCategoryTask.get());
        success.add("subCategoryList", subCategoryListTask.get());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return success;
}
Also used : VanTreeSelectVo(com.wayn.common.core.domain.vo.VanTreeSelectVo) R(com.wayn.common.util.R) Category(com.wayn.common.core.domain.shop.Category) FutureTask(java.util.concurrent.FutureTask) List(java.util.List) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Category (com.wayn.common.core.domain.shop.Category)1 VanTreeSelectVo (com.wayn.common.core.domain.vo.VanTreeSelectVo)1 R (com.wayn.common.util.R)1 List (java.util.List)1 FutureTask (java.util.concurrent.FutureTask)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1