Search in sources :

Example 1 with UpdateAttachmentDto

use of com.paascloud.provider.model.dto.UpdateAttachmentDto in project paascloud-master by paascloud.

the class MdcTopicConsumer method handlerSendSmsTopic.

/**
 * Handler send sms topic.
 *
 * @param body      the body
 * @param topicName the topic name
 * @param tags      the tags
 * @param keys      the keys
 */
@Transactional(rollbackFor = Exception.class)
public void handlerSendSmsTopic(String body, String topicName, String tags, String keys) throws QiniuException {
    MqMessage.checkMessage(body, keys, topicName);
    if (StringUtils.equals(tags, AliyunMqTopicConstants.MqTagEnum.DELETE_ATTACHMENT.getTag())) {
        List<Long> idList = opcAttachmentService.queryAttachmentByRefNo(body);
        for (final Long id : idList) {
            opcAttachmentService.deleteFile(id);
        }
    } else {
        UpdateAttachmentDto attachmentDto;
        try {
            attachmentDto = JacksonUtil.parseJson(body, UpdateAttachmentDto.class);
        } catch (Exception e) {
            log.error("发送短信MQ出现异常={}", e.getMessage(), e);
            throw new IllegalArgumentException("JSON转换异常", e);
        }
        opcAttachmentService.updateAttachment(attachmentDto);
    }
}
Also used : UpdateAttachmentDto(com.paascloud.provider.model.dto.UpdateAttachmentDto) QiniuException(com.qiniu.common.QiniuException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UpdateAttachmentDto

use of com.paascloud.provider.model.dto.UpdateAttachmentDto 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)

Aggregations

UpdateAttachmentDto (com.paascloud.provider.model.dto.UpdateAttachmentDto)2 MdcProduct (com.paascloud.provider.model.domain.MdcProduct)1 MqMessageData (com.paascloud.provider.model.domain.MqMessageData)1 QiniuException (com.qiniu.common.QiniuException)1 Transactional (org.springframework.transaction.annotation.Transactional)1