Search in sources :

Example 1 with ProductColumnSpu

use of com.whoiszxl.entity.ProductColumnSpu in project shopzz by whoiszxl.

the class ProductColumnServiceImpl method detail.

@Override
public ColumnDetailApiResponse detail(Long id) {
    String redisKey = RedisKeyPrefixConstants.COLUMN_DETAIL + id;
    String columnDetailJson = redisUtils.get(redisKey);
    if (StringUtils.isBlank(columnDetailJson)) {
        synchronized (ProductColumnServiceImpl.class) {
            columnDetailJson = redisUtils.get(redisKey);
            if (StringUtils.isBlank(columnDetailJson)) {
                ColumnDetailApiResponse response = new ColumnDetailApiResponse();
                // 从DB获取
                ProductColumn productColumn = super.getById(id);
                dozerUtils.map(productColumn, response);
                List<ProductColumnSpu> productColumnSpuList = productColumnSpuService.list(Wrappers.<ProductColumnSpu>lambdaQuery().eq(ProductColumnSpu::getColumnId, id));
                if (ObjectUtils.isEmpty(productColumnSpuList)) {
                    ExceptionCatcher.catchValidateEx(ResponseResult.buildError("专栏下无商品"));
                }
                List<Long> spuIds = productColumnSpuList.stream().map(ProductColumnSpu::getSpuId).collect(Collectors.toList());
                String feignParams = ParamUtils.array2Str(spuIds);
                ResponseResult<List<SpuFeignDTO>> feignResponse = productFeignClient.getSpuListBySpuIdList(feignParams);
                if (!feignResponse.isOk()) {
                    ExceptionCatcher.catchValidateEx(ResponseResult.buildError(feignResponse.getMessage()));
                }
                List<SpuFeignDTO> spuFeignDTOList = feignResponse.getData();
                List<ColumnSpuApiResponse> columnSpuApiResponses = dozerUtils.mapList(spuFeignDTOList, ColumnSpuApiResponse.class);
                response.setSpuList(columnSpuApiResponses);
                columnDetailJson = JsonUtil.toJson(response);
                redisUtils.set(redisKey, columnDetailJson);
            }
        }
    }
    return JsonUtil.fromJson(columnDetailJson, ColumnDetailApiResponse.class);
}
Also used : ProductColumnSpu(com.whoiszxl.entity.ProductColumnSpu) ColumnDetailApiResponse(com.whoiszxl.cqrs.response.ColumnDetailApiResponse) SpuFeignDTO(com.whoiszxl.dto.SpuFeignDTO) ColumnSpuApiResponse(com.whoiszxl.cqrs.response.ColumnSpuApiResponse) List(java.util.List) ProductColumn(com.whoiszxl.entity.ProductColumn)

Example 2 with ProductColumnSpu

use of com.whoiszxl.entity.ProductColumnSpu in project shopzz by whoiszxl.

the class ColumnAdminController method saveColumnSpu.

@SaCheckLogin
@PostMapping("/spu")
@ApiOperation(value = "新增专栏SPU", notes = "新增专栏SPU", response = ResponseResult.class)
public ResponseResult<Boolean> saveColumnSpu(@RequestBody ProductColumnSpuSaveCommand saveCommand) {
    ProductColumnSpu columnSpu = dozerUtils.map(saveCommand, ProductColumnSpu.class);
    boolean saveFlag = productColumnSpuService.save(columnSpu);
    return ResponseResult.buildByFlag(saveFlag);
}
Also used : ProductColumnSpu(com.whoiszxl.entity.ProductColumnSpu) SaCheckLogin(cn.dev33.satoken.annotation.SaCheckLogin) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ProductColumnSpu (com.whoiszxl.entity.ProductColumnSpu)2 SaCheckLogin (cn.dev33.satoken.annotation.SaCheckLogin)1 ColumnDetailApiResponse (com.whoiszxl.cqrs.response.ColumnDetailApiResponse)1 ColumnSpuApiResponse (com.whoiszxl.cqrs.response.ColumnSpuApiResponse)1 SpuFeignDTO (com.whoiszxl.dto.SpuFeignDTO)1 ProductColumn (com.whoiszxl.entity.ProductColumn)1 ApiOperation (io.swagger.annotations.ApiOperation)1 List (java.util.List)1