|  | @@ -1,15 +1,14 @@
 | 
	
		
			
				|  |  |  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.BigDataListInfoVo;
 | 
	
		
			
				|  |  | -import com.hwrj.cloud.admin.dto.param.BigDataListParam;
 | 
	
		
			
				|  |  | -import com.hwrj.cloud.admin.dto.param.BigDataListVo;
 | 
	
		
			
				|  |  | -import com.hwrj.cloud.admin.dto.param.SelectVo;
 | 
	
		
			
				|  |  | +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.*;
 | 
	
	
		
			
				|  | @@ -19,8 +18,12 @@ 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;
 | 
	
	
		
			
				|  | @@ -29,12 +32,15 @@ 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 java.io.IOException;
 | 
	
		
			
				|  |  |  import java.lang.reflect.Method;
 | 
	
		
			
				|  |  | +import java.math.BigDecimal;
 | 
	
		
			
				|  |  |  import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | -import java.util.ArrayList;
 | 
	
		
			
				|  |  | -import java.util.Date;
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  | +import java.util.regex.Matcher;
 | 
	
		
			
				|  |  | +import java.util.regex.Pattern;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -42,6 +48,7 @@ import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |   * Created by macro on 2018/4/26.
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  public class PmsProductServiceImpl implements PmsProductService {
 | 
	
		
			
				|  |  |      private static final Logger LOGGER = LoggerFactory.getLogger(PmsProductServiceImpl.class);
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
	
		
			
				|  | @@ -458,4 +465,147 @@ public class PmsProductServiceImpl implements PmsProductService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @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(), 3, 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;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |