package com.hzs.sale.product.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.constant.RabbitMqConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.domain.sale.classify.BdClassify;
import com.hzs.common.domain.sale.classify.BdSpecsType;
import com.hzs.common.domain.sale.ext.BdProductExt;
import com.hzs.common.domain.sale.product.*;
import com.hzs.common.domain.sale.wares.BdWaresExtend;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.sale.product.controller.manage.params.ProductParams;
import com.hzs.sale.product.mapper.BdProductMapper;
import com.hzs.sale.product.param.SupplierProductCensusParam;
import com.hzs.sale.product.service.*;
import com.hzs.sale.product.vo.ProductVo;
import com.hzs.sale.product.vo.SupplierProductCensusVo;
import com.hzs.sale.product.vo.WaresDetailVo;
import com.hzs.sale.wares.service.IBdWaresDetailService;
import com.hzs.sale.wares.service.IBdWaresExtendService;
import com.hzs.system.base.ITransactionServiceApi;
import com.hzs.system.sys.ICubasdocApi;
import com.hzs.system.sys.dto.BusinessLogDTO;
import com.hzs.system.sys.dto.CubasdocDTO;
import com.hzs.system.sys.dto.LoginUser;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 产品 服务实现类
 */
@Service
public class BdProductServiceImpl extends ServiceImpl<BdProductMapper, BdProduct> implements IBdProductService {

    @Autowired
    private IBdWaresExtendService waresExtendService;
    @Autowired
    private IBdClassifyService classifyService;
    @Autowired
    private IBdProductExtendService productExtendService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private IBdProductSpecsService productSpecsService;
    @Autowired
    private IBdSpecsTypeService specsTypeService;
    @Autowired
    private IBdWaresDetailService waresDetailService;

    @DubboReference
    ICubasdocApi cubasdocApi;
    @DubboReference
    ITransactionServiceApi transactionServiceApi;

    @Override
    public BdProduct getProduct(Integer pkProduct) {
        return baseMapper.selectById(pkProduct);
    }

    @Override
    public List<BdProductExt> queryProductExtById(List<BdProductSpecs> productSpecsList, Integer pkCountry) {
        return baseMapper.queryProductExtBySpecsId(productSpecsList, pkCountry);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String saveProduct(ProductParams productParams, LoginUser loginUser) {
        String productCode = productParams.getProductCode();
        BdProduct bdProduct = BeanUtil.copyProperties(productParams, BdProduct.class);
        R<Integer> transaction = transactionServiceApi.createTransaction(loginUser.getDataCountry(), ETransactionKey.PRODUCT, productParams.getProductName(), EYesNo.NO, EYesNo.NO);
        bdProduct.setProductCode(productCode);
        bdProduct.setPkTransaction(transaction.getData());
        bdProduct.setPkCreator(loginUser.getUserId());
        bdProduct.setCreationTime(new Date());
        bdProduct.setPkCreator(loginUser.getUserId());
        bdProduct.setPkCountry(loginUser.getDataCountry());
        bdProduct.setSystemType(loginUser.getSystemType());
        // 删除状态 审核完毕 修改为未删除状态
        bdProduct.setDelFlag(EDelFlag.UN_DELETE.getValue());
        if (productParams.getIsPutOn().equals(EYesNo.YES.getIntValue())) {
            bdProduct.setListingTime(DateUtils.currentDateTime());
        }
        if (productParams.getIsPutOn().equals(EYesNo.NO.getIntValue())) {
            bdProduct.setRemovalTime(DateUtils.currentDateTime());
        }

        if (productParams.getPkCubasdoc() != null) {
            R<CubasdocDTO> cubasdocDTO = cubasdocApi.getCubasdoc(productParams.getPkCubasdoc());
            CubasdocDTO cubasdoc = cubasdocDTO.getData();
            if (cubasdoc != null) {
                bdProduct.setPkCubasdoc(productParams.getPkCubasdoc());
                bdProduct.setPkSupplier(cubasdoc.getPkSupplier());
            }
        }
        if (StringUtils.isEmpty(bdProduct.getWmsCode())) {
            // 仓储产品编号为空，则默认使用产品编号
            bdProduct.setWmsCode(bdProduct.getProductCode());
        }
        this.save(bdProduct);
        // 生成拓展表
        BdProductExtend productExtend = BeanUtil.copyProperties(productParams, BdProductExtend.class);
        productExtend.setPkProduct(bdProduct.getPkId());
        productExtend.setPkCreator(loginUser.getUserId());
        productExtend.setCreationTime(new Date());
        productExtend.setPkCountry(loginUser.getDataCountry());
        productExtend.setDelFlag(EDelFlag.UN_DELETE.getValue());
        productExtend.setIsPutOn(productParams.getIsPutOn());
        productExtendService.save(productExtend);
        // 生成规格明细
        if (productParams.getPkSpecsType() != null) {
            for (Integer id : productParams.getPkSpecsType()) {
                BdProductSpecs productSpecs = new BdProductSpecs();
                productSpecs.setPkProduct(bdProduct.getPkId());
                productSpecs.setPkSpecsType(id);
                productSpecs.setPkCountry(loginUser.getDataCountry());
                productSpecs.setPkCreator(loginUser.getUserId());
                productSpecs.setCreationTime(new Date());
                productSpecsService.save(productSpecs);
            }
        }
        productParams.setProductCode(productCode);
        productParams.setPkId(bdProduct.getPkId());
        createProductSaveLog(productParams, loginUser, EApprovalBusiness.PRODUCT_SAVE.getValue());
        return productCode;
    }

    /**
     * 产品生成日志记录
     */
    private void createProductSaveLog(ProductParams productParams, LoginUser loginUser, Integer businessType) {
        try {
            // 字符拼接
            StringBuilder str = new StringBuilder();
            str.append("产品编号:").append(productParams.getProductCode());
            str.append("产品名称:").append(productParams.getProductName());
            if (productParams.getPkClassify() != null) {
                BdClassify classify = classifyService.getClassify(productParams.getPkClassify());
                str.append("所属分类名称:").append(classify.getName());
                str.append("所属分类主键:").append(productParams.getPkClassify());
            }
            // 单位
            if (productParams.getUnit() != null) {
                str.append("单位:").append(EUnit.getEnumByValue(productParams.getUnit()).getLabel());
            }
            // 重量
            str.append("重量:").append(productParams.getWeight());
            // 长
            str.append("长:").append(productParams.getLength());
            str.append("宽:").append(productParams.getWidth());
            str.append("高:").append(productParams.getHeight());
            str.append("邮费重量:").append(productParams.getPostageWeight());
            str.append("划线价:").append(productParams.getRetailPrice());
            str.append("产品主图:").append(productParams.getCover());
            str.append("保质期:").append(productParams.getShelfLife());
            if (productParams.getIsFresh() != null) {
                str.append("是否冷链运输:").append(EYesNo.getLabelByIntValue(productParams.getIsFresh()));
            }
            if (productParams.getIsPickUp() != null) {
                str.append("是否提货商品:").append(EYesNo.getLabelByIntValue(productParams.getIsPickUp()));
            }
            if (productParams.getIsPrize() != null) {
                str.append("是否抽奖礼品:").append(EYesNo.getLabelByIntValue(productParams.getIsPickUp()));
            }
            if (productParams.getIsBarCode() != null) {
                str.append("是否条码运输:").append(EYesNo.getLabelByIntValue(productParams.getIsBarCode()));
            }
            if (productParams.getIsMerge() != null) {
                str.append("是否合并发货:").append(EYesNo.getLabelByIntValue(productParams.getIsMerge()));
            }
            if (productParams.getIsLandTrans() != null) {
                str.append("是否陆运:").append(EYesNo.getLabelByIntValue(productParams.getIsLandTrans()));
            }
            if (productParams.getIsAirTrans() != null) {
                str.append("是否空运:").append(EYesNo.getLabelByIntValue(productParams.getIsAirTrans()));
            }
            if (productParams.getIsOceanTrans() != null) {
                str.append("是否海运:").append(EYesNo.getLabelByIntValue(productParams.getIsOceanTrans()));
            }
            if (productParams.getSort() != null) {
                str.append("排序:").append(productParams.getSort());
            }
            if (productParams.getShippingChannel() != null) {
                str.append("发货渠道:").append(EShippingChannel.getEnumByValue(productParams.getShippingChannel()).getLabel());
            }
            // 产品规格类型
            if (productParams.getPkSpecsType() != null && productParams.getPkSpecsType().size() > 0) {
                List<BdSpecsType> specsTypeList = specsTypeService.list(new LambdaQueryWrapper<BdSpecsType>().in(BdSpecsType::getPkId, productParams.getPkSpecsType()));
                List<String> list = specsTypeList.stream().map(BdSpecsType::getTypeName).collect(Collectors.toList());
                str.append("规格明细:").append(StringUtils.join(list, ","));
            }
            // 拼装发送mq
            BusinessLogDTO log = BusinessLogDTO.builder()
                    .businessType(businessType)
                    .businessCode(productParams.getProductCode())
                    .businessId(productParams.getPkId().longValue())
                    .pkMember(null)
                    .content(str.toString())
                    .pkCreator(loginUser.getUserId())
                    .pkCountry(loginUser.getDataCountry())
                    .freeSignFlag(true)
                    .build();
            rabbitTemplate.convertAndSend(RabbitMqConstants.BUSINESS_LOG_EXCHANGE, RabbitMqConstants.BUSINESS_LOG_KEY, log);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("产品日志生成异常,日志mq发送失败");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateProduct(ProductParams productParams, LoginUser loginUser) {
        BdProduct bdProduct = BeanUtil.copyProperties(productParams, BdProduct.class);
        R<Integer> transaction = transactionServiceApi.createTransaction(loginUser.getDataCountry(), ETransactionKey.PRODUCT, productParams.getProductName(), EYesNo.NO, EYesNo.NO);
        bdProduct.setPkId(productParams.getPkId());
        bdProduct.setPkTransaction(transaction.getData());
        bdProduct.setPkModified(loginUser.getUserId());
        bdProduct.setModifiedTime(new Date());
        if (productParams.getIsPutOn().equals(EYesNo.YES.getIntValue())) {
            bdProduct.setListingTime(DateUtils.currentDateTime());
        }
        if (productParams.getIsPutOn().equals(EYesNo.NO.getIntValue())) {
            bdProduct.setRemovalTime(DateUtils.currentDateTime());
        }
        if (StringUtils.isEmpty(bdProduct.getWmsCode())) {
            // 仓储产品编号为空，则默认使用产品编号
            bdProduct.setWmsCode(bdProduct.getProductCode());
        }
        this.updateById(bdProduct);
        // 生成拓展表
        BdProductExtend productExtend = BeanUtil.copyProperties(productParams, BdProductExtend.class);
        productExtend.setPkProduct(bdProduct.getPkId());
        LambdaQueryWrapper<BdProductExtend> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BdProductExtend::getPkProduct, productParams.getPkId());
        productExtendService.update(productExtend, queryWrapper);
        // 生成规格明细
        if (productParams.getPkSpecsType() != null) {
            LambdaQueryWrapper<BdProductSpecs> removeWrapper = new LambdaQueryWrapper<>();
            removeWrapper.eq(BdProductSpecs::getPkProduct, bdProduct.getPkId());
            productSpecsService.remove(removeWrapper);
            for (Integer id : productParams.getPkSpecsType()) {
                BdProductSpecs productSpecs = new BdProductSpecs();
                productSpecs.setPkProduct(bdProduct.getPkId());
                productSpecs.setPkSpecsType(id);
                productSpecs.setPkCountry(loginUser.getDataCountry());
                productSpecs.setPkCreator(loginUser.getUserId());
                productSpecs.setCreationTime(new Date());

                productSpecsService.save(productSpecs);
            }
        }
        productParams.setProductCode(productParams.getProductCode());
        productParams.setPkId(bdProduct.getPkId());
        createProductSaveLog(productParams, loginUser, EApprovalBusiness.PRODUCT_UPDATE.getValue());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeProduct(Integer pkId, LoginUser loginUser) {
        BdProduct product = this.getProduct(pkId);
        LambdaUpdateWrapper<BdProduct> productWrapper = new LambdaUpdateWrapper<>();
        productWrapper.eq(BdProduct::getPkId, pkId);
        productWrapper.set(BdProduct::getPkModified, SecurityUtils.getUserId());
        productWrapper.set(BdProduct::getModifiedTime, new Date());
        productWrapper.set(BdProduct::getDelFlag, EDelFlag.DELETE.getValue());
        this.update(productWrapper);
        // 更新商品拓展表
        LambdaUpdateWrapper<BdProductExtend> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(BdProductExtend::getPkProduct, pkId);
        updateWrapper.set(BdProductExtend::getPkModified, SecurityUtils.getUserId());
        updateWrapper.set(BdProductExtend::getModifiedTime, new Date());
        updateWrapper.set(BdProductExtend::getDelFlag, EDelFlag.DELETE.getValue());
        productExtendService.update(updateWrapper);
        // 逻辑删除规格明细表
        BdProductSpecs bdProductSpecs = new BdProductSpecs();
        bdProductSpecs.setDelFlag(EDelFlag.DELETE.getValue());
        bdProductSpecs.setModifiedTime(new Date());
        bdProductSpecs.setPkModified(SecurityUtils.getUserId());
        LambdaQueryWrapper<BdProductSpecs> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BdProductSpecs::getPkProduct, pkId);
        productSpecsService.update(bdProductSpecs, wrapper);
        // 创建删除产品日志
        if (product != null) {
            createRemoveProductLog(product, loginUser, EApprovalBusiness.PRODUCT_REMOVE.getValue());
        }
    }

    /**
     * 删除产品日志
     *
     * @param product
     */
    private void createRemoveProductLog(BdProduct product, LoginUser loginUser, Integer businessType) {
        // 拼装发送mq
        String str = "删除产品名称:" + product.getProductName() +
                "删除产品ID:" + product.getPkId();
        BusinessLogDTO log = BusinessLogDTO.builder()
                .businessType(businessType)
                .businessCode(product.getProductCode())
                .businessId(product.getPkId().longValue())
                .pkMember(null)
                .content(str)
                .pkCreator(loginUser.getUserId())
                .pkCountry(loginUser.getDataCountry())
                .freeSignFlag(true)
                .build();
        rabbitTemplate.convertAndSend(RabbitMqConstants.BUSINESS_LOG_EXCHANGE, RabbitMqConstants.BUSINESS_LOG_KEY, log);
    }

    @Override
    public String getLastProductCode() {
        return baseMapper.getLastProductCode();
    }

    @Override
    public List<ProductVo> selectByQueryList(ProductParams productParams) {
        return baseMapper.selectByQueryList(productParams);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void productMove(Integer productId, Integer productMoveType, LoginUser loginUser) {
        BdProduct bdProduct = baseMapper.selectById(productId);
        // 产品上移
        if (productMoveType == EProductMoveType.MOVEUP.getIntValue()) {
            // 产品上移  根据当前商品查找当前商品排序之前一个序号  如是15 则查找 16 存不存在 如果存在 则 16 之前的全部+1
            Integer sort = productExtendService.selectByMoveUpSort(productId);
            if (sort != null) {
                Integer maxSort = sort + 1;
                // 查询该排序号码是否重复
                LambdaQueryWrapper<BdProductExtend> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(BdProductExtend::getSort, maxSort);
                int count = productExtendService.count(queryWrapper);
                if (count > 0) {
                    // 表示该号码已存在 将该号码之前的全都上移一位 并且将产品修改为该号码
                    productExtendService.updateMoveUpBySort(maxSort);
                    LambdaUpdateWrapper<BdProductExtend> updateWrapper = new LambdaUpdateWrapper<>();
                    updateWrapper.eq(BdProductExtend::getPkProduct, productId);
                    updateWrapper.set(BdProductExtend::getSort, maxSort);
                    productExtendService.update(updateWrapper);
                } else {
                    LambdaUpdateWrapper<BdProductExtend> updateWrapper = new LambdaUpdateWrapper<>();
                    updateWrapper.eq(BdProductExtend::getPkProduct, productId);
                    updateWrapper.set(BdProductExtend::getSort, maxSort);
                    productExtendService.update(updateWrapper);
                }
            }
            if (bdProduct != null) {
                createProductMoveLog(bdProduct, productMoveType, loginUser, EApprovalBusiness.PRODUCT_MOVEUP.getValue());
            }
        } else if (productMoveType == EProductMoveType.MOVEDOWN.getIntValue()) {
            // 产品下移
            // 产品下移  根据当前商品查找当前商品排序之后一个序号  如是15 则查找 14 存不存在 如果存在 则 14 之前的全部-1
            Integer sort = productExtendService.selectByMoveDownSort(productId);
            if (sort != null) {
                Integer minSort = sort - 1;
                // 查询该排序号码是否重复
                LambdaQueryWrapper<BdProductExtend> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(BdProductExtend::getSort, minSort);
                int count = productExtendService.count(queryWrapper);
                if (count > 0) {
                    // 表示该号码已存在 将该号码之下的全都下移一位 并且将产品修改为该号码
                    productExtendService.updateMoveDownBySort(minSort);
                    LambdaUpdateWrapper<BdProductExtend> updateWrapper = new LambdaUpdateWrapper<>();
                    updateWrapper.eq(BdProductExtend::getPkProduct, productId);
                    updateWrapper.set(BdProductExtend::getSort, minSort);
                    productExtendService.update(updateWrapper);
                } else {
                    LambdaUpdateWrapper<BdProductExtend> updateWrapper = new LambdaUpdateWrapper<>();
                    updateWrapper.eq(BdProductExtend::getPkProduct, productId);
                    updateWrapper.set(BdProductExtend::getSort, minSort);
                    productExtendService.update(updateWrapper);
                }
            }
            if (bdProduct != null) {
                // 产品下移
                createProductMoveLog(bdProduct, productMoveType, loginUser, EApprovalBusiness.PRODUCT_MOVEDOWN.getValue());
            }
        }
    }

    /**
     * 产品上下移 生成日志
     */
    public void createProductMoveLog(BdProduct bdProduct, Integer productMoveType, LoginUser loginUser, Integer businessType) {
        StringBuilder str = new StringBuilder();
        if (productMoveType == EProductMoveType.MOVEUP.getIntValue()) {
            // 产品上移
            str.append("产品上移: 产品编号").append(bdProduct.getProductCode());
        } else if (productMoveType == EProductMoveType.MOVEDOWN.getIntValue()) {
            str.append("产品下移: 产品编号").append(bdProduct.getProductCode());
        }
        str.append("产品名称:").append(bdProduct.getProductName());
        str.append("产品主键:").append(bdProduct.getPkId());
        // 拼装发送mq
        BusinessLogDTO log = BusinessLogDTO.builder()
                .businessType(businessType)
                .businessCode(bdProduct.getProductCode())
                .businessId(bdProduct.getPkId().longValue())
                .pkMember(null)
                .content(str.toString())
                .pkCreator(loginUser.getUserId())
                .pkCountry(loginUser.getDataCountry())
                .freeSignFlag(true)
                .build();
        rabbitTemplate.convertAndSend(RabbitMqConstants.BUSINESS_LOG_EXCHANGE, RabbitMqConstants.BUSINESS_LOG_KEY, log);
    }

    @Override
    public void floatingRoof(Integer productId, LoginUser loginUser) {
        BdProduct product = this.getProduct(productId);
        // 查询当前排序最大值
        Integer sort = productExtendService.getMaxProductSort();
        LambdaUpdateWrapper<BdProductExtend> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(BdProductExtend::getPkProduct, productId);
        updateWrapper.set(BdProductExtend::getSort, sort + 1);
        productExtendService.update(updateWrapper);
        if (product != null) {
            createFloatingRoofLog(product, loginUser, EApprovalBusiness.PRODUCT_TOP.getValue());
        }
    }

    /**
     * 产品置顶 生成日志
     */
    public void createFloatingRoofLog(BdProduct product, LoginUser loginUser, Integer businessType) {
        // 拼装发送mq
        String str = "产品:" + product.getProductName() + " 置顶" +
                "产品主键:" + product.getPkId();
        BusinessLogDTO log = BusinessLogDTO.builder()
                .businessType(businessType)
                .businessCode(product.getProductCode())
                .businessId(product.getPkId().longValue())
                .pkMember(null)
                .content(str)
                .pkCreator(loginUser.getUserId())
                .pkCountry(loginUser.getDataCountry())
                .freeSignFlag(true)
                .build();
        rabbitTemplate.convertAndSend(RabbitMqConstants.BUSINESS_LOG_EXCHANGE, RabbitMqConstants.BUSINESS_LOG_KEY, log);
    }

    @Override
    public Map<Integer, BdProduct> queryProductMap(Collection<Integer> pkProductList, Integer pkCountry) {
        Map<Integer, BdProduct> resultMap = new HashMap<>();

        LambdaQueryWrapper<BdProduct> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(BdProduct::getPkId, pkProductList);
        if (null != pkCountry) {
            queryWrapper.eq(BdProduct::getPkCountry, pkCountry);
        }
        List<BdProduct> productList = this.list(queryWrapper);

        if (CollectionUtil.isNotEmpty(productList)) {
            for (BdProduct bdProduct : productList) {
                resultMap.put(bdProduct.getPkId(), bdProduct);
            }
        }
        return resultMap;
    }

    @Override
    public List<BdProductExt> queryProductExistSpecs(Integer pkCountry, Integer systemType) {
        return baseMapper.queryProductExistSpecs(pkCountry, systemType);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateWaresPreSaleStatus(List<BdProduct> productList) {
        List<Integer> list = productList.stream().map(BdProduct::getPkId).collect(Collectors.toList());

        try {
            List<WaresDetailVo> waresDetailVoList = waresDetailService.listByPkProduct(list);
            // 缺货状态
            List<Integer> waresOutStockList = new ArrayList<>();
            //预售状态
            List<Integer> warespreSaleList = new ArrayList<>();
            for (WaresDetailVo waresDetailVo : waresDetailVoList) {
                if (waresDetailVo.getIsPreSale() == null || waresDetailVo.getIsPreSale().equals(EYesNo.NO.getIntValue())) {
                    // 缺货状态
                    waresOutStockList.add(waresDetailVo.getPkWares());
                } else if (waresDetailVo.getIsPreSale().equals(EYesNo.YES.getIntValue())) {
                    // 是预售 修改为预售状态
                    warespreSaleList.add(waresDetailVo.getPkWares());
                }

            }
            // 更新缺货状态
            if (waresOutStockList.size() > 0) {
                LambdaUpdateWrapper<BdWaresExtend> updateWrapper = new LambdaUpdateWrapper<>();
                updateWrapper.in(BdWaresExtend::getPkWares, waresOutStockList);
                updateWrapper.set(BdWaresExtend::getPreSaleStatus, EPresaleStatus.OUT_STOCK.getValue());
                waresExtendService.update(updateWrapper);
            }
            // 更新预售状态
            if (warespreSaleList.size() > 0) {
                LambdaUpdateWrapper<BdWaresExtend> updateWrapper = new LambdaUpdateWrapper<>();
                updateWrapper.in(BdWaresExtend::getPkWares, warespreSaleList);
                updateWrapper.set(BdWaresExtend::getPreSaleStatus, EPresaleStatus.PRESALE.getValue());
                waresExtendService.update(updateWrapper);
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    @Override
    public List<SupplierProductCensusVo> getSupplierProductCensus(SupplierProductCensusParam supplierProductCensusParam) {
        return baseMapper.getSupplierProductCensus(supplierProductCensusParam);
    }

    @Override
    public ProductVo getByProductId(Integer productId) {
        return baseMapper.getByProductId(productId);
    }

}
