|  | @@ -0,0 +1,180 @@
 | 
	
		
			
				|  |  | +/*
 | 
	
		
			
				|  |  | + * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * https://www.gz-yami.com/
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * 未经允许,不可做商业用途!
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * 版权所有,侵权必究!
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +package com.yami.shop.service.impl;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  | +import com.yami.shop.bean.model.ChannelProd;
 | 
	
		
			
				|  |  | +import com.yami.shop.common.exception.YamiShopBindException;
 | 
	
		
			
				|  |  | +import com.yami.shop.common.util.PageParam;
 | 
	
		
			
				|  |  | +import com.yami.shop.dao.ChannelProdMapper;
 | 
	
		
			
				|  |  | +import com.yami.shop.service.ChannelProdService;
 | 
	
		
			
				|  |  | +import lombok.AllArgsConstructor;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * 渠道对应商品管理服务实现类
 | 
	
		
			
				|  |  | + * @author lgh on 2024/01/01.
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +@Service
 | 
	
		
			
				|  |  | +@AllArgsConstructor
 | 
	
		
			
				|  |  | +public class ChannelProdServiceImpl extends ServiceImpl<ChannelProdMapper, ChannelProd> implements ChannelProdService {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private final ChannelProdMapper channelProdMapper;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public List<ChannelProd> getChannelProdsByShannerId(Long shannerId) {
 | 
	
		
			
				|  |  | +        if (shannerId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return channelProdMapper.getChannelProdsByShannerId(shannerId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public List<ChannelProd> getChannelProdsBySkuId(Long skuId) {
 | 
	
		
			
				|  |  | +        if (skuId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("SKU ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return channelProdMapper.getChannelProdsBySkuId(skuId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public ChannelProd getChannelProdByShannerIdAndSkuId(Long shannerId, Long skuId) {
 | 
	
		
			
				|  |  | +        if (shannerId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (skuId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("SKU ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return channelProdMapper.getChannelProdByShannerIdAndSkuId(shannerId, skuId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public IPage<ChannelProd> getChannelProdPage(PageParam<ChannelProd> page, ChannelProd channelProd) {
 | 
	
		
			
				|  |  | +        return channelProdMapper.getChannelProdPage(page, channelProd);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public void saveChannelProd(ChannelProd channelProd) {
 | 
	
		
			
				|  |  | +        if (channelProd == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道商品信息不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (channelProd.getShannerId() == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (channelProd.getSkuId() == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("SKU ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (channelProd.getPurchasePrice() == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("进货价不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (channelProd.getDeliveryPrice() == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("出货价不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (channelProd.getShannerProdPrice() == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道商品售价不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        // 检查是否已存在
 | 
	
		
			
				|  |  | +        ChannelProd existing = getChannelProdByShannerIdAndSkuId(channelProd.getShannerId(), channelProd.getSkuId());
 | 
	
		
			
				|  |  | +        if (existing != null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("该渠道下已存在此商品");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        channelProd.setIsDelete(0);
 | 
	
		
			
				|  |  | +        channelProd.setRecTime(new Date());
 | 
	
		
			
				|  |  | +        channelProd.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +        channelProdMapper.insert(channelProd);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public void updateChannelProd(ChannelProd channelProd) {
 | 
	
		
			
				|  |  | +        if (channelProd == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道商品信息不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (channelProd.getId() == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道商品ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        channelProd.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +        channelProdMapper.updateById(channelProd);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public void deleteChannelProdById(Long id) {
 | 
	
		
			
				|  |  | +        if (id == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道商品ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        channelProdMapper.deleteById(id);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public void deleteChannelProdsByShannerId(Long shannerId) {
 | 
	
		
			
				|  |  | +        if (shannerId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        channelProdMapper.deleteByShannerId(shannerId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public void deleteChannelProdsBySkuId(Long skuId) {
 | 
	
		
			
				|  |  | +        if (skuId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("SKU ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        channelProdMapper.deleteBySkuId(skuId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public void updateBatchPrices(List<ChannelProd> channelProds) {
 | 
	
		
			
				|  |  | +        if (channelProds == null || channelProds.isEmpty()) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道商品列表不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        channelProdMapper.updateBatchPrices(channelProds);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Integer countByShannerId(Long shannerId) {
 | 
	
		
			
				|  |  | +        if (shannerId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return channelProdMapper.countByShannerId(shannerId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Integer countBySkuId(Long skuId) {
 | 
	
		
			
				|  |  | +        if (skuId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("SKU ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return channelProdMapper.countBySkuId(skuId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Boolean existsByShannerIdAndSkuId(Long shannerId, Long skuId) {
 | 
	
		
			
				|  |  | +        if (shannerId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("渠道ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (skuId == null) {
 | 
	
		
			
				|  |  | +            throw new YamiShopBindException("SKU ID不能为空");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        ChannelProd channelProd = getChannelProdByShannerIdAndSkuId(shannerId, skuId);
 | 
	
		
			
				|  |  | +        return channelProd != null;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |