Search in sources :

Example 6 with MdcProduct

use of com.paascloud.provider.model.domain.MdcProduct in project paascloud-master by paascloud.

the class MdcProductServiceImpl method saveProduct.

@Override
public void saveProduct(final MdcEditProductDto mdcEditProductDto, final LoginAuthDto loginAuthDto) {
    String productCode = mdcEditProductDto.getProductCode();
    MdcProduct product = new MdcProduct();
    BeanUtils.copyProperties(mdcEditProductDto, product);
    List<Long> categoryIdList = mdcEditProductDto.getCategoryIdList();
    Long categoryId = categoryIdList.get(categoryIdList.size() - 1);
    product.setCategoryId(categoryId);
    List<Long> attachmentIdList = mdcEditProductDto.getAttachmentIdList();
    product.setUpdateInfo(loginAuthDto);
    if (PublicUtil.isNotEmpty(attachmentIdList)) {
        product.setMainImage(String.valueOf(attachmentIdList.get(0)));
        product.setSubImages(Joiner.on(GlobalConstant.Symbol.COMMA).join(attachmentIdList));
    }
    MqMessageData mqMessageData;
    if (product.isNew()) {
        productCode = String.valueOf(generateId());
    } else {
        Preconditions.checkArgument(StringUtils.isNotEmpty(productCode), ErrorCodeEnum.MDC10021024.msg());
    }
    product.setProductCode(productCode);
    UpdateAttachmentDto updateAttachmentDto = new UpdateAttachmentDto(productCode, attachmentIdList, loginAuthDto);
    String body = JSON.toJSONString(updateAttachmentDto);
    String topic = AliyunMqTopicConstants.MqTagEnum.UPDATE_ATTACHMENT.getTopic();
    String tag = AliyunMqTopicConstants.MqTagEnum.UPDATE_ATTACHMENT.getTag();
    String key = RedisKeyUtil.createMqKey(topic, tag, product.getProductCode(), body);
    if (product.isNew() && PublicUtil.isNotEmpty(attachmentIdList)) {
        product.setId(generateId());
        mqMessageData = new MqMessageData(body, topic, tag, key);
        mdcProductManager.saveProduct(mqMessageData, product, true);
    } else if (product.isNew() && PublicUtil.isEmpty(attachmentIdList)) {
        product.setId(generateId());
        mdcProductMapper.insertSelective(product);
    } else {
        mqMessageData = new MqMessageData(body, topic, tag, key);
        mdcProductManager.saveProduct(mqMessageData, product, false);
    }
}
Also used : UpdateAttachmentDto(com.paascloud.provider.model.dto.UpdateAttachmentDto) MqMessageData(com.paascloud.provider.model.domain.MqMessageData) MdcProduct(com.paascloud.provider.model.domain.MdcProduct)

Example 7 with MdcProduct

use of com.paascloud.provider.model.domain.MdcProduct in project paascloud-master by paascloud.

the class MdcProductServiceImpl method getProductVo.

@Override
public ProductVo getProductVo(final Long id) {
    MdcProduct mdcProduct = mdcProductMapper.selectByPrimaryKey(id);
    ProductVo productVo = new ModelMapper().map(mdcProduct, ProductVo.class);
    List<Long> categoryIdList = Lists.newArrayList();
    buildCategoryIdList(categoryIdList, mdcProduct.getCategoryId());
    // 获取分类节点集合
    Collections.reverse(categoryIdList);
    productVo.setCategoryIdList(categoryIdList);
    // 获取图片集合
    final OptBatchGetUrlRequest request = new OptBatchGetUrlRequest(mdcProduct.getProductCode());
    request.setEncrypt(true);
    List<ElementImgUrlDto> imgUrlList = opcRpcService.listFileUrl(request);
    productVo.setImgUrlList(imgUrlList);
    return productVo;
}
Also used : OptBatchGetUrlRequest(com.paascloud.provider.model.dto.oss.OptBatchGetUrlRequest) ProductVo(com.paascloud.provider.model.vo.ProductVo) MdcProduct(com.paascloud.provider.model.domain.MdcProduct) ModelMapper(org.modelmapper.ModelMapper) ElementImgUrlDto(com.paascloud.provider.model.dto.oss.ElementImgUrlDto)

Aggregations

MdcProduct (com.paascloud.provider.model.domain.MdcProduct)7 MqMessageData (com.paascloud.provider.model.domain.MqMessageData)2 ProductDto (com.paascloud.provider.model.dto.ProductDto)2 ApiOperation (io.swagger.annotations.ApiOperation)2 PageInfo (com.github.pagehelper.PageInfo)1 MdcBizException (com.paascloud.provider.exceptions.MdcBizException)1 MdcProductCategory (com.paascloud.provider.model.domain.MdcProductCategory)1 UpdateAttachmentDto (com.paascloud.provider.model.dto.UpdateAttachmentDto)1 ElementImgUrlDto (com.paascloud.provider.model.dto.oss.ElementImgUrlDto)1 OptBatchGetUrlRequest (com.paascloud.provider.model.dto.oss.OptBatchGetUrlRequest)1 OptGetUrlRequest (com.paascloud.provider.model.dto.oss.OptGetUrlRequest)1 ProductVo (com.paascloud.provider.model.vo.ProductVo)1 ModelMapper (org.modelmapper.ModelMapper)1