package com.hwrj.cloud.admin.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.google.gson.Gson;
import com.hwrj.cloud.admin.common.CmsPrefrenceAreaProductRelationInput;
import com.hwrj.cloud.admin.common.CmsSubjectProductRelationInput;
import com.hwrj.cloud.admin.common.PmsProductOutput;
import com.hwrj.cloud.admin.dto.param.*;
import com.hwrj.cloud.admin.service.CmsPrefrenceAreaService;
import com.hwrj.cloud.admin.service.CmsSubjectService;
import com.hwrj.cloud.admin.dao.*;
import com.hwrj.cloud.admin.dto.PmsProductParam;
import com.hwrj.cloud.admin.dto.PmsProductQueryParam;
import com.hwrj.cloud.admin.dto.PmsProductResult;
import com.hwrj.cloud.admin.mapper.*;
import com.hwrj.cloud.admin.model.*;
import com.hwrj.cloud.admin.service.PmsProductService;
import com.hwrj.cloud.admin.util.ChineseCharToEn;
import com.hwrj.cloud.admin.util.CurrUserUtil;
import com.hwrj.cloud.admin.util.EasyExcelUtil;
import com.hwrj.cloud.admin.util.MyStringUtils;
import com.hwrj.cloud.common.exception.GlobalException;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 商品管理Service实现类
 * Created by macro on 2018/4/26.
 */
@Service

public class PmsProductServiceImpl implements PmsProductService {
    private static final Logger LOGGER = LoggerFactory.getLogger(PmsProductServiceImpl.class);
    @Autowired
    private PmsProductMapper productMapper;
    @Autowired
    private PmsMemberPriceDao memberPriceDao;
    @Autowired
    private PmsMemberPriceMapper memberPriceMapper;
    @Autowired
    private PmsProductLadderDao productLadderDao;
    @Autowired
    private PmsProductLadderMapper productLadderMapper;
    @Autowired
    private PmsProductFullReductionDao productFullReductionDao;
    @Autowired
    private PmsProductFullReductionMapper productFullReductionMapper;
    @Autowired
    private PmsSkuStockDao skuStockDao;
    @Autowired
    private PmsSkuStockMapper skuStockMapper;
    @Autowired
    private PmsProductAttributeValueDao productAttributeValueDao;
    @Autowired
    private PmsProductAttributeValueMapper productAttributeValueMapper;


    @Autowired
    private CmsSubjectService subjectService;


    @Autowired
    private PmsProductDao productDao;
    @Autowired
    private PmsProductVertifyRecordDao productVertifyRecordDao;
    @Autowired
    private CmsPrefrenceAreaService prefrenceAreaService;

    @Override
    @Transactional
    public int create(PmsProductParam productParam) {
        int count;
        //创建商品
        PmsProduct product = productParam;
        //检查数据
        checkData(product);
        product.setId(null);
//        long compId = CurrUserUtil.getCompId();
//        if(StringUtils.isEmpty(compId)){
//            throw new RuntimeException("没有绑定供应商无法新增!");
//        }
//        productParam.setCompId(compId);
        productParam.setCompName(CurrUserUtil.getCompName());
        productParam.setCreateId((long) CurrUserUtil.getUserId());
        productParam.setCreateTime(new Date());
        productMapper.insertSelective(product);
        //根据促销类型设置价格：会员价格、阶梯价格、满减价格
        Long productId = product.getId();
        //会员价格
        relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), productId);
        //阶梯价格
        relateAndInsertList(productLadderDao, productParam.getProductLadderList(), productId);
        //满减价格
        relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), productId);
        //处理sku的编码
        handleSkuStockCode(productParam.getSkuStockList(), productId);
        //添加sku库存信息
        relateAndInsertList(skuStockDao, productParam.getSkuStockList(), productId);
        //添加商品参数,添加自定义商品规格
        relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), productId);
        //关联专题
        subjectService.relateAndInsertList(productParam.getSubjectProductRelationList(), productId);
//        //关联优选
//        prefrenceAreaService.relateAndInsertList(productParam.getPrefrenceAreaProductRelationList(), productId);
        count = 1;
        return count;
    }

    private void handleSkuStockCode(List<PmsSkuStock> skuStockList, Long productId) {
        if (CollectionUtils.isEmpty(skuStockList)) return;
        for (int i = 0; i < skuStockList.size(); i++) {
            PmsSkuStock skuStock = skuStockList.get(i);
            if (StringUtils.isEmpty(skuStock.getSkuCode())) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                StringBuilder sb = new StringBuilder();
                //日期
                sb.append(sdf.format(new Date()));
                //四位商品id
                sb.append(String.format("%04d", productId));
                //三位索引id
                sb.append(String.format("%03d", i + 1));
                skuStock.setSkuCode(sb.toString());
            }
        }
    }

    @Override
    public PmsProductResult getUpdateInfo(Long id) {
        PmsProductResult updateInfo = productDao.getUpdateInfo(id);

        List<CmsSubjectProductRelationInput> relationInputList = subjectService.relationByProductId(id);
        // 关联主题
//        if (listCommonResult.getCode() == ResultCode.SUCCESS.getCode()) {
//            List<CmsSubjectProductRelationInput> relationInputList = gson.fromJson(JSON.toJSONString(listCommonResult.getData()) ,
//                    new TypeToken<List<CmsSubjectProductRelationInput>>() {
//                    }.getType());
//            updateInfo.setSubjectProductRelationList(relationInputList);
//        }
        if (relationInputList != null && relationInputList.size() > 0) {
            updateInfo.setSubjectProductRelationList(relationInputList);
        }
        // 关联优选
//        CommonResult<List<CmsPrefrenceAreaProductRelationInput>> commonResult = cmsPrefrenceAreaProductRelationClient.relationByProductId(id);
//        if (commonResult.getCode() == ResultCode.SUCCESS.getCode()) {
//            List<CmsPrefrenceAreaProductRelationInput> areaProductRelationInputs = gson.fromJson(JSON.toJSONString(commonResult.getData()),
//                    new TypeToken<List<CmsPrefrenceAreaProductRelationInput>>() {
//                    }.getType());
//            updateInfo.setPrefrenceAreaProductRelationList(areaProductRelationInputs);
//        }
        List<CmsPrefrenceAreaProductRelationInput> relationInputs = prefrenceAreaService.relationByProductId(id);
        updateInfo.setPrefrenceAreaProductRelationList(relationInputs);
        return updateInfo;
    }

    public void check(PmsProductParam productParam) {
        long compId = CurrUserUtil.getCompId();
        if (StringUtils.isEmpty(compId)) {
            throw new RuntimeException("没有绑定供应商无法修改!");
        }
        Long productcompId = productParam.getCompId();
        if (!productcompId.equals(compId)) {
            throw new RuntimeException("你不能修改别的供应商数据!");
        }
    }

    @Override
    @Transactional
    public int update(Long id, PmsProductParam productParam) {
        //检验供应商
        //check(productParam);
        int count;
        //更新商品信息
        PmsProduct product = productParam;
        //检查数据
        checkData(product);

        product.setId(id);
//        product.setCompId(CurrUserUtil.getCompId());
        productMapper.updateByPrimaryKeySelective(product);
        //会员价格
        PmsMemberPriceExample pmsMemberPriceExample = new PmsMemberPriceExample();
        pmsMemberPriceExample.createCriteria().andProductIdEqualTo(id);
        memberPriceMapper.deleteByExample(pmsMemberPriceExample);
        relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), id);
        //阶梯价格
        PmsProductLadderExample ladderExample = new PmsProductLadderExample();
        ladderExample.createCriteria().andProductIdEqualTo(id);
        productLadderMapper.deleteByExample(ladderExample);
        relateAndInsertList(productLadderDao, productParam.getProductLadderList(), id);
        //满减价格
        PmsProductFullReductionExample fullReductionExample = new PmsProductFullReductionExample();
        fullReductionExample.createCriteria().andProductIdEqualTo(id);
        productFullReductionMapper.deleteByExample(fullReductionExample);
        relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), id);
        //修改sku库存信息
        handleUpdateSkuStockList(id, productParam);
        //修改商品参数,添加自定义商品规格
        PmsProductAttributeValueExample productAttributeValueExample = new PmsProductAttributeValueExample();
        productAttributeValueExample.createCriteria().andProductIdEqualTo(id);
        productAttributeValueMapper.deleteByExample(productAttributeValueExample);
        relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), id);
        //关联专题
        List<CmsSubjectProductRelationInput> subjectProductRelationList = productParam.getSubjectProductRelationList();
        subjectService.relateAndUpdateList(productParam.getSubjectProductRelationList(), id);
//        //关联优选
//        prefrenceAreaService.relateAndUpdateList(productParam.getPrefrenceAreaProductRelationList(), id);
        count = 1;
        return count;
    }

    private void checkData(PmsProduct product) {
        //商品价格
        BigDecimal price = product.getPrice();
        if (StringUtils.isEmpty(price)) {
            throw new RuntimeException("商品价格不能空!");
        }
        if (price.compareTo(BigDecimal.ZERO) == -1) {
            throw new RuntimeException("商品价格不能小于0!");
        }
        BigDecimal originalPrice = product.getOriginalPrice();
        if (StringUtils.isEmpty(originalPrice)) {
            throw new RuntimeException("市场价格不能空!");
        }
        if (originalPrice.compareTo(BigDecimal.ZERO) == -1) {
            throw new RuntimeException("市场价格不能小于0!");
        }
        Integer stock = product.getStock();
        if (StringUtils.isEmpty(stock)) {
            throw new RuntimeException("库存不能不能空!");
        }
        if (stock.intValue() < 0) {
            throw new RuntimeException("库存不能小于0!");
        }
        //库存预警为0
        product.setLowStock(0);
        //设置不是新品
        product.setNewStatus(0);
        //设置为不推荐
        product.setRecommandStatus(0);
        //活动限制数量
        product.setPromotionPerLimit(0);
        //设置为原价购买
        product.setPromotionType(0);
        //设置批发价
        product.setTradePrice(product.getPrice());
        //设置促销价格
        product.setPromotionPrice(product.getPrice());
        //限制使用的积分数
        product.setUsePointLimit(0);
        //是否为预告商品：0->不是；1->是
        product.setPreviewStatus(0);
    }

    private void handleUpdateSkuStockList(Long id, PmsProductParam productParam) {
        //当前的sku信息
        List<PmsSkuStock> currSkuList = productParam.getSkuStockList();
        //当前没有sku直接删除
        if (CollUtil.isEmpty(currSkuList)) {
            PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
            skuStockExample.createCriteria().andProductIdEqualTo(id);
            skuStockMapper.deleteByExample(skuStockExample);
            return;
        }
        //获取初始sku信息
        PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
        skuStockExample.createCriteria().andProductIdEqualTo(id);
        List<PmsSkuStock> oriStuList = skuStockMapper.selectByExample(skuStockExample);
        //获取新增sku信息
        List<PmsSkuStock> insertSkuList = currSkuList.stream().filter(item -> item.getId() == null).collect(Collectors.toList());
        //获取需要更新的sku信息
        List<PmsSkuStock> updateSkuList = currSkuList.stream().filter(item -> item.getId() != null).collect(Collectors.toList());
        List<Long> updateSkuIds = updateSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
        //获取需要删除的sku信息
        List<PmsSkuStock> removeSkuList = oriStuList.stream().filter(item -> !updateSkuIds.contains(item.getId())).collect(Collectors.toList());
        handleSkuStockCode(insertSkuList, id);
        handleSkuStockCode(updateSkuList, id);
        //新增sku
        if (CollUtil.isNotEmpty(insertSkuList)) {
            relateAndInsertList(skuStockDao, insertSkuList, id);
        }
        //删除sku
        if (CollUtil.isNotEmpty(removeSkuList)) {
            List<Long> removeSkuIds = removeSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
            PmsSkuStockExample removeExample = new PmsSkuStockExample();
            removeExample.createCriteria().andIdIn(removeSkuIds);
            skuStockMapper.deleteByExample(removeExample);
        }
        //修改sku
        if (CollUtil.isNotEmpty(updateSkuList)) {
            for (PmsSkuStock pmsSkuStock : updateSkuList) {
                skuStockMapper.updateByPrimaryKeySelective(pmsSkuStock);
            }
        }

    }

    @Override
    public List<PmsProduct> list(PmsProductQueryParam productQueryParam, Integer pageSize, Integer pageNum) {
        Long compId = CurrUserUtil.getCompIdInfo();
        PageHelper.startPage(pageNum, pageSize);
        PmsProductExample productExample = new PmsProductExample();
        PmsProductExample.Criteria criteria = productExample.createCriteria();
        productExample.setOrderByClause("create_time desc");
        criteria.andDeleteStatusEqualTo(0);
        if (!StringUtils.isEmpty(compId)) {
            criteria.andCompIdEqualTo(compId);
        } else {
            if (!StringUtils.isEmpty(productQueryParam.getCompId())) {
                criteria.andCompIdEqualTo(productQueryParam.getCompId());
            }
        }
        if (productQueryParam.getPublishStatus() != null) {
            criteria.andPublishStatusEqualTo(productQueryParam.getPublishStatus());
        }
        if (productQueryParam.getVerifyStatus() != null) {
            criteria.andVerifyStatusEqualTo(productQueryParam.getVerifyStatus());
        }
        if (!StringUtils.isEmpty(productQueryParam.getKeyword())) {
            criteria.andNameLike("%" + productQueryParam.getKeyword() + "%");
        }
        if (!StringUtils.isEmpty(productQueryParam.getProductSn())) {
            criteria.andProductSnEqualTo(productQueryParam.getProductSn());
        }
        if (productQueryParam.getBrandId() != null) {
            criteria.andBrandIdEqualTo(productQueryParam.getBrandId());
        }
        if (productQueryParam.getProductCategoryId() != null) {
            criteria.andProductCategoryIdEqualTo(productQueryParam.getProductCategoryId());
        }
        if (productQueryParam.getStartTime() != null) {
            criteria.andCreateTimeGreaterThanOrEqualTo(productQueryParam.getStartTime());
        }
        if (productQueryParam.getEndTime() != null) {
            criteria.andCreateTimeLessThanOrEqualTo(productQueryParam.getEndTime());
        }
        return productMapper.selectByExample(productExample);
    }

    @Override
    public int updateVerifyStatus(List<Long> ids, Integer verifyStatus, String detail) {
        PmsProduct product = new PmsProduct();
        product.setVerifyStatus(verifyStatus);
        PmsProductExample example = new PmsProductExample();
        example.createCriteria().andIdIn(ids);
        List<PmsProductVertifyRecord> list = new ArrayList<>();
        int count = productMapper.updateByExampleSelective(product, example);
        //修改完审核状态后插入审核记录
        for (Long id : ids) {
            PmsProductVertifyRecord record = new PmsProductVertifyRecord();
            record.setProductId(id);
            record.setCreateTime(new Date());
            record.setDetail(detail);
            record.setStatus(verifyStatus);
            record.setVertifyMan("test");
            list.add(record);
        }
        productVertifyRecordDao.insertList(list);
        return count;
    }

    @Override
    public int updatePublishStatus(List<Long> ids, Integer publishStatus) {
        PmsProduct record = new PmsProduct();
        record.setPublishStatus(publishStatus);
        PmsProductExample example = new PmsProductExample();
        example.createCriteria().andIdIn(ids);
        return productMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateRecommendStatus(List<Long> ids, Integer recommendStatus) {
        PmsProduct record = new PmsProduct();
        record.setRecommandStatus(recommendStatus);
        PmsProductExample example = new PmsProductExample();
        example.createCriteria().andIdIn(ids);
        return productMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateNewStatus(List<Long> ids, Integer newStatus) {
        PmsProduct record = new PmsProduct();
        record.setNewStatus(newStatus);
        PmsProductExample example = new PmsProductExample();
        example.createCriteria().andIdIn(ids);
        return productMapper.updateByExampleSelective(record, example);
    }

    @Autowired
    private PmsProductDao pmsProductDao;

    @Override
    public int updateDeleteStatus(List<Long> ids, Integer deleteStatus) {
        if (deleteStatus.intValue() == 1) {
            long i = pmsProductDao.check(ids);
            if (i > 0) {
                throw new GlobalException("你删除的商品存在未完成的订单,无法删除!");
            }
        }
        PmsProduct record = new PmsProduct();
        record.setDeleteStatus(deleteStatus);
        //释放商品
        record.setLockDel(0);
        PmsProductExample example = new PmsProductExample();
        example.createCriteria().andIdIn(ids);
        subjectService.relateAndDeleteByProductId(ids);
        return productMapper.updateByExampleSelective(record, example);
    }

    @Override
    public List<PmsProduct> list(String keyword) {
        PmsProductExample productExample = new PmsProductExample();
        PmsProductExample.Criteria criteria = productExample.createCriteria();
        criteria.andDeleteStatusEqualTo(0);
        if (!StringUtils.isEmpty(keyword)) {
            criteria.andNameLike("%" + keyword + "%");
            productExample.or().andDeleteStatusEqualTo(0).andProductSnLike("%" + keyword + "%");
        }
        return productMapper.selectByExample(productExample);
    }

    /**
     * 根据 商品 id 过去商品信息
     *
     * @param productId
     * @return
     */
    @Override
    public PmsProductOutput getProductByProductId(Long productId) {
        PmsProduct pmsProduct = productMapper.selectByPrimaryKey(productId);
        PmsProductOutput pmsProductOutput = new PmsProductOutput();
        BeanUtils.copyProperties(pmsProduct, pmsProductOutput);
        return pmsProductOutput;
    }


    /**
     * 建立和插入关系表操作
     *
     * @param dao       可以操作的dao
     * @param dataList  要插入的数据
     * @param productId 建立关系的id
     */
    private void relateAndInsertList(Object dao, List dataList, Long productId) {
        try {
            if (CollectionUtils.isEmpty(dataList)) return;
            for (Object item : dataList) {
                Method setId = item.getClass().getMethod("setId", Long.class);
                setId.invoke(item, (Long) null);
                Method setProductId = item.getClass().getMethod("setProductId", Long.class);
                setProductId.invoke(item, productId);
            }
            Method insertList = dao.getClass().getMethod("insertList", List.class);
            insertList.invoke(dao, dataList);
        } catch (Exception e) {
            LOGGER.warn("创建产品出错:{}", e.getMessage());
            throw new RuntimeException(e.getMessage());
        }
    }

    @Autowired
    private PmsProductExcelDao productExcelDao;

    @Override
    public List<BigDataListInfoVo> bigDataList(BigDataListParam bigDataListParam) {
        PageHelper.startPage(bigDataListParam.getPageNum(), bigDataListParam.getPageSize());
        return productExcelDao.bigDataList(bigDataListParam);
    }

    @Override
    public BigDataListInfoVo bigDatainfo(Long id) {
        return productExcelDao.bigDatainfo(id);
    }

    @Override
    public List<SelectVo> bigDataType() {
        return productExcelDao.bigDataType();
    }

    @Override
    public List<SelectVo> plOfProSelect(Long compId) {
        return productExcelDao.plOfProSelect(compId);
    }

    @Override
    public int verify(Long id) {
        int count = 0;
        PmsProduct pmsProduct = productMapper.selectByPrimaryKey(id);
        if (!StringUtils.isEmpty(pmsProduct)) {
            PmsProduct product = new PmsProduct();
            product.setVerifyStatus(1);
            PmsProductExample example = new PmsProductExample();
            example.createCriteria().andIdEqualTo(id);
            List<PmsProductVertifyRecord> list = new ArrayList<>();
            return count = productMapper.updateByExampleSelective(product, example);
        } else {
            throw new GlobalException("商品不存在无法审核！");
        }
    }

    @Override
    @Transactional
    public void importBasic(MultipartFile file) {
        List<PmsProductExcelParam> listAll = new ArrayList();

        Set<String> companyList = new HashSet<>();

        Set<String> bandlist = new HashSet<>();

        if (file != null) {
            List<Object> list = null;
            try {
                list = EasyExcelUtil.readExcel(file, new PmsProductExcel(), 1, 2);
            } catch (IOException e) {
                //e.printStackTrace();
                throw new RuntimeException("上传文件错误!");
            }
            if (list != null && list.size() > 0) {
                for (Object obj : list) {
                    LOGGER.info("解析到一条数据:{}", JSONArray.toJSONString(obj));
                    PmsProductExcel excel = (PmsProductExcel) obj;
                    PmsProductExcelParam pmsProductParam = addData(excel);
                    listAll.add(pmsProductParam);
                }
            }
            if (listAll.size() > 0) {
                LOGGER.info("插入数据:{}", JSONObject.toJSONString(listAll));
                productExcelDao.saveData(listAll);
                //获取品牌
                List<String> bandNameNew = listAll.stream().map(PmsProductExcelParam::getBrandName).distinct().collect(Collectors.toList());
                bandlist.addAll(bandNameNew);
                //获取供应商
                List<String> companyNameNew = listAll.stream().map(PmsProductExcelParam::getUmsCompanyInfo).distinct().collect(Collectors.toList());
                companyList.addAll(companyNameNew);
                updateProduct(bandlist, companyList, listAll);
            }
        }

    }

    private void updateProduct(Set<String> bandlist, Set<String> companyList, List<PmsProductExcelParam> listAll) {
        //插入品牌数据
        insertBandList(bandlist, listAll);
        //更新大小类以及品牌生产地
        updateProductType(companyList, listAll);
    }

    private void insertBandList(Set<String> bandlist, List<PmsProductExcelParam> listAll) {
        //更新商品品牌
        if (bandlist.size() > 0) {
            //获取所有的品牌
            List<PmsBrand> allBrand = new ArrayList<>();
            for (String bandName : bandlist) {
                PmsBrand pmsBrand = new PmsBrand();
                //去除空格
                pmsBrand.setName(MyStringUtils.replaceBlank(bandName));
                //获取首字母大写
                pmsBrand.setFirstLetter(ChineseCharToEn.getAllFirstLetter(bandName));
                pmsBrand.setShowStatus(1);
                pmsBrand.setSort(1);
                pmsBrand.setFactoryStatus(1);
                pmsBrand.setProductCount(listAll.size());
                pmsBrand.setCreateId((long) 1);
                pmsBrand.setCreateTime(new Date());
                allBrand.add(pmsBrand);
            }
            //插入品牌数据
            if (allBrand.size() > 0) {
                productExcelDao.saveBrandData(allBrand);
            }
            LOGGER.info("存储数据库成功！");

        }
    }

    //更新大小类
    public void updateProductType(Set<String> companyList, List<PmsProductExcelParam> listAll) {
        if (companyList.size() > 0) {
            List<Long> ids = listAll.stream().map(PmsProductExcelParam::getId).distinct().collect(Collectors.toList());
            //更新大小类以及品牌生产地
            List<String> companyNameList = new ArrayList<>(companyList);
            productExcelDao.updateBrand(companyNameList, ids);
            productExcelDao.updateBigType(companyNameList, ids);
            productExcelDao.updateSimType(companyNameList, ids);
            productExcelDao.updateMemberOrigin(companyNameList, ids);
            productExcelDao.updateComp(companyNameList, ids);
        }

    }

    private PmsProductExcelParam addData(PmsProductExcel pmsProductExcel) {

        PmsProductExcelParam pmsProductParam = new PmsProductExcelParam();

        BeanUtils.copyProperties(pmsProductExcel, pmsProductParam);
        //名称
        String name = pmsProductExcel.getName();
        //价格
        BigDecimal price = pmsProductExcel.getPrice();
        //标题
        pmsProductParam.setDetailTitle(name);
        //笔记
        pmsProductParam.setNote(name);
        //关键字
        pmsProductParam.setKeywords(name);

        String description = replaceBlank(pmsProductExcel.getDescription());

        //商品描述
        pmsProductParam.setDescription(description);
        //简述
        pmsProductParam.setSubTitle(description);
        //使用说明
        String instructions = replaceBlank(pmsProductExcel.getInstructions());
        //默认文本
        pmsProductParam.setDetailDesc(instructions);
        //web网页显示
        pmsProductParam.setDetailHtml(instructions);
        //手机网页显示
        pmsProductParam.setDetailMobileHtml(instructions);
        //市场价
        pmsProductParam.setOriginalPrice(price);
        //创建人 admin 1
        pmsProductParam.setCreateUser((long) 1);
        //创建时间
        pmsProductParam.setCreateTime(new Date());
        //未上架
        pmsProductParam.setPublishStatus(0);
        //未审核
        pmsProductParam.setVerifyStatus(0);
        return pmsProductParam;
    }

    public static String replaceBlank(String str) {
        String dest = "";
        if (str != null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }


}
