Search in sources :

Example 1 with Goods

use of cn.lili.modules.goods.entity.dos.Goods in project lilishop by lilishop.

the class GoodsServiceImpl method editGoods.

@Override
@Transactional(rollbackFor = Exception.class)
public void editGoods(GoodsOperationDTO goodsOperationDTO, String goodsId) {
    Goods goods = new Goods(goodsOperationDTO);
    goods.setId(goodsId);
    // 检查商品信息
    this.checkGoods(goods);
    // 向goods加入图片
    this.setGoodsGalleryParam(goodsOperationDTO.getGoodsGalleryList().get(0), goods);
    // 添加商品参数
    if (goodsOperationDTO.getGoodsParamsDTOList() != null && !goodsOperationDTO.getGoodsParamsDTOList().isEmpty()) {
        goods.setParams(JSONUtil.toJsonStr(goodsOperationDTO.getGoodsParamsDTOList()));
    }
    // 修改商品
    this.updateById(goods);
    // 修改商品sku信息
    this.goodsSkuService.update(goodsOperationDTO.getSkuList(), goods, goodsOperationDTO.getRegeneratorSkuFlag());
    // 添加相册
    if (goodsOperationDTO.getGoodsGalleryList() != null && !goodsOperationDTO.getGoodsGalleryList().isEmpty()) {
        this.goodsGalleryService.add(goodsOperationDTO.getGoodsGalleryList(), goods.getId());
    }
    if (GoodsAuthEnum.TOBEAUDITED.name().equals(goods.getAuthFlag())) {
        this.deleteEsGoods(Collections.singletonList(goodsId));
    }
    cache.remove(CachePrefix.GOODS.getPrefix() + goodsId);
}
Also used : Goods(cn.lili.modules.goods.entity.dos.Goods) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Goods

use of cn.lili.modules.goods.entity.dos.Goods in project lilishop by lilishop.

the class GoodsServiceImpl method getUpdateWrapperByStoreAuthority.

/**
 * 获取UpdateWrapper(检查用户越权)
 *
 * @return updateWrapper
 */
private LambdaUpdateWrapper<Goods> getUpdateWrapperByStoreAuthority() {
    LambdaUpdateWrapper<Goods> updateWrapper = new LambdaUpdateWrapper<>();
    AuthUser authUser = this.checkStoreAuthority();
    if (authUser != null) {
        updateWrapper.eq(Goods::getStoreId, authUser.getStoreId());
    }
    return updateWrapper;
}
Also used : LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) Goods(cn.lili.modules.goods.entity.dos.Goods) AuthUser(cn.lili.common.security.AuthUser)

Example 3 with Goods

use of cn.lili.modules.goods.entity.dos.Goods in project lilishop by lilishop.

the class GoodsServiceImpl method addGoods.

@Override
@Transactional(rollbackFor = Exception.class)
public void addGoods(GoodsOperationDTO goodsOperationDTO) {
    Goods goods = new Goods(goodsOperationDTO);
    // 检查商品
    this.checkGoods(goods);
    // 向goods加入图片
    this.setGoodsGalleryParam(goodsOperationDTO.getGoodsGalleryList().get(0), goods);
    // 添加商品参数
    if (goodsOperationDTO.getGoodsParamsDTOList() != null && !goodsOperationDTO.getGoodsParamsDTOList().isEmpty()) {
        // 给商品参数填充值
        goods.setParams(JSONUtil.toJsonStr(goodsOperationDTO.getGoodsParamsDTOList()));
    }
    // 添加商品
    this.save(goods);
    // 添加商品sku信息
    this.goodsSkuService.add(goodsOperationDTO.getSkuList(), goods);
    // 添加相册
    if (goodsOperationDTO.getGoodsGalleryList() != null && !goodsOperationDTO.getGoodsGalleryList().isEmpty()) {
        this.goodsGalleryService.add(goodsOperationDTO.getGoodsGalleryList(), goods.getId());
    }
}
Also used : Goods(cn.lili.modules.goods.entity.dos.Goods) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Goods

use of cn.lili.modules.goods.entity.dos.Goods in project lilishop by lilishop.

the class GoodsServiceImpl method auditGoods.

@Override
@Transactional(rollbackFor = Exception.class)
public boolean auditGoods(List<String> goodsIds, GoodsAuthEnum goodsAuthEnum) {
    boolean result = false;
    for (String goodsId : goodsIds) {
        Goods goods = this.checkExist(goodsId);
        goods.setAuthFlag(goodsAuthEnum.name());
        result = this.updateById(goods);
        goodsSkuService.updateGoodsSkuStatus(goods);
        // 删除之前的缓存
        cache.remove(CachePrefix.GOODS.getPrefix() + goodsId);
        // 商品审核消息
        String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_AUDIT.name();
        // 发送mq消息
        rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goods), RocketmqSendCallbackBuilder.commonCallback());
    }
    return result;
}
Also used : Goods(cn.lili.modules.goods.entity.dos.Goods) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Goods

use of cn.lili.modules.goods.entity.dos.Goods in project lilishop by lilishop.

the class ParametersServiceImpl method updateParameter.

/**
 * 更新参数组信息
 *
 * @param parameters 参数组信息
 * @return 是否更新成功
 */
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateParameter(Parameters parameters) {
    Parameters origin = this.getById(parameters.getId());
    if (origin == null) {
        throw new ServiceException(ResultCode.CATEGORY_NOT_EXIST);
    }
    List<String> goodsIds = new ArrayList<>();
    LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.select(Goods::getId, Goods::getParams);
    queryWrapper.like(Goods::getParams, parameters.getGroupId());
    List<Map<String, Object>> goodsList = this.goodsService.listMaps(queryWrapper);
    if (!goodsList.isEmpty()) {
        for (Map<String, Object> goods : goodsList) {
            String params = (String) goods.get("params");
            List<GoodsParamsDTO> goodsParamsDTOS = JSONUtil.toList(params, GoodsParamsDTO.class);
            List<GoodsParamsDTO> goodsParamsDTOList = goodsParamsDTOS.stream().filter(i -> i.getGroupId() != null && i.getGroupId().equals(parameters.getGroupId())).collect(Collectors.toList());
            this.setGoodsItemDTOList(goodsParamsDTOList, parameters);
            this.goodsService.updateGoodsParams(goods.get("id").toString(), JSONUtil.toJsonStr(goodsParamsDTOS));
            goodsIds.add(goods.get("id").toString());
        }
        String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX.name();
        // 发送mq消息
        rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIds), RocketmqSendCallbackBuilder.commonCallback());
    }
    return this.updateById(parameters);
}
Also used : GoodsParamsDTO(cn.lili.modules.goods.entity.dto.GoodsParamsDTO) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Parameters(cn.lili.modules.goods.entity.dos.Parameters) RocketmqCustomProperties(cn.lili.common.properties.RocketmqCustomProperties) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Collectors(java.util.stream.Collectors) ParametersMapper(cn.lili.modules.goods.mapper.ParametersMapper) RocketmqSendCallbackBuilder(cn.lili.rocketmq.RocketmqSendCallbackBuilder) ArrayList(java.util.ArrayList) JSONUtil(cn.hutool.json.JSONUtil) GoodsParamsItemDTO(cn.lili.modules.goods.entity.dto.GoodsParamsItemDTO) List(java.util.List) Goods(cn.lili.modules.goods.entity.dos.Goods) GoodsParamsDTO(cn.lili.modules.goods.entity.dto.GoodsParamsDTO) GoodsService(cn.lili.modules.goods.service.GoodsService) Service(org.springframework.stereotype.Service) Map(java.util.Map) RocketMQTemplate(org.apache.rocketmq.spring.core.RocketMQTemplate) CharSequenceUtil(cn.hutool.core.text.CharSequenceUtil) ParametersService(cn.lili.modules.goods.service.ParametersService) ResultCode(cn.lili.common.enums.ResultCode) ServiceException(cn.lili.common.exception.ServiceException) GoodsTagsEnum(cn.lili.rocketmq.tags.GoodsTagsEnum) Transactional(org.springframework.transaction.annotation.Transactional) Parameters(cn.lili.modules.goods.entity.dos.Parameters) ArrayList(java.util.ArrayList) Goods(cn.lili.modules.goods.entity.dos.Goods) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) ServiceException(cn.lili.common.exception.ServiceException) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Goods (cn.lili.modules.goods.entity.dos.Goods)14 Transactional (org.springframework.transaction.annotation.Transactional)9 ServiceException (cn.lili.common.exception.ServiceException)6 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)5 AuthUser (cn.lili.common.security.AuthUser)4 GoodsParamsDTO (cn.lili.modules.goods.entity.dto.GoodsParamsDTO)3 JSONUtil (cn.hutool.json.JSONUtil)2 ResultCode (cn.lili.common.enums.ResultCode)2 Parameters (cn.lili.modules.goods.entity.dos.Parameters)2 Studio (cn.lili.modules.goods.entity.dos.Studio)2 StudioCommodity (cn.lili.modules.goods.entity.dos.StudioCommodity)2 GoodsService (cn.lili.modules.goods.service.GoodsService)2 ParametersService (cn.lili.modules.goods.service.ParametersService)2 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)2 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2