赵冬冬 4 gadi atpakaļ
vecāks
revīzija
5cd17b9993

+ 2 - 16
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/controller/PmsProductController.java

@@ -187,25 +187,11 @@ public class PmsProductController {
         return CommonResult.success(pmsProduct);
     }
 
-    @Autowired
-    private PmsProductExcelDao productExcelDao;
 
     @PostMapping(value = "/import")
     public CommonResult importBasic(MultipartFile file, HttpServletResponse response) throws IOException {
-        PmsProductExcelListener basicExcelListener = new PmsProductExcelListener(productExcelDao,response);
-        ExcelReader excelReader = null;
-        try {
-            excelReader = EasyExcel.read(file.getInputStream()).build();
-            ReadSheet readSheet3 =
-                    EasyExcel.readSheet(2).head(PmsProductExcel.class).registerReadListener(basicExcelListener).headRowNumber(2).build();
-            // 这里注意 一定要把sheet1 sheet2 一起传进去,不然有个问题就是03版的excel 会读取多次,浪费性能
-            excelReader.read(readSheet3);
-        } finally {
-            if (excelReader != null) {
-                // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
-                excelReader.finish();
-            }
-        }
+
+        productService.importBasic(file);
         return CommonResult.success();
     }
 }

+ 34 - 34
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/controller/UploadCompanyInfoAndProductController.java

@@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.hwrj.cloud.admin.dao.PmsProductExcelDao;
 import com.hwrj.cloud.admin.dto.param.ForestPath;
 import com.hwrj.cloud.admin.dto.param.PmsProductExcel;
-import com.hwrj.cloud.admin.dto.param.PmsProductParam;
+import com.hwrj.cloud.admin.dto.param.PmsProductExcelParam;
 import com.hwrj.cloud.admin.dto.utilEntity.LagLatEntity;
 import com.hwrj.cloud.admin.excelEntity.UmsCompanyInfoExcel;
 import com.hwrj.cloud.admin.excelEntity.UmsMemberOriginExcel;
@@ -64,7 +64,7 @@ public class UploadCompanyInfoAndProductController {
     @Autowired
     private CompanyLatLagGet companyLatLagGet;
 
-    List<PmsProductParam> listAll = new ArrayList<>();
+    List<PmsProductExcelParam> listAll = new ArrayList<>();
 
 
     @ApiOperation("上传文件")
@@ -338,7 +338,7 @@ public class UploadCompanyInfoAndProductController {
         if (listAll != null || listAll.size() < 1) {
             log.info("好像没有数据哦");
         }
-        for (PmsProductParam pms : listAll) {
+        for (PmsProductExcelParam pms : listAll) {
             if (directory.contains(pms.getProductNo())) {
                 updateFile(forestPath.getPath(), pms.getId(), pms.getProductNo());
             }
@@ -478,7 +478,7 @@ public class UploadCompanyInfoAndProductController {
                 umsCompanyInfoExcel.setCreateId(0l);
                 companyId = umsCompanyInfoExcel.getCompName();
                 LagLatEntity lagLat = companyLatLagGet.getLagLat(umsCompanyInfoExcel.getCityId(), umsCompanyInfoExcel.getCountyId(), umsCompanyInfoExcel.getDetailAddress());
-                if (lagLat != null ){
+                if (lagLat != null) {
                     umsCompanyInfoExcel.setLatitude(new BigDecimal(lagLat.getLat()));
                     umsCompanyInfoExcel.setLongitude(new BigDecimal(lagLat.getLag()));
                 }
@@ -519,7 +519,7 @@ public class UploadCompanyInfoAndProductController {
                     excel.setCreateId(1);
                     excel.setState(0);
                     LagLatEntity lagLat = companyLatLagGet.getLagLat(excel.getCityName(), excel.getCountyName(), excel.getDetailAddress());
-                    if (lagLat != null ){
+                    if (lagLat != null) {
                         excel.setLatitude(lagLat.getLat());
                         excel.setLongitude(lagLat.getLag());
                     }
@@ -554,7 +554,6 @@ public class UploadCompanyInfoAndProductController {
     public void importBasic(MultipartFile file) throws IOException {
 
 
-
         listAll = new ArrayList<>();
         if (file != null) {
             List<Object> list = null;
@@ -567,19 +566,19 @@ public class UploadCompanyInfoAndProductController {
             if (list != null && list.size() > 0) {
                 for (Object obj : list) {
                     PmsProductExcel excel = (PmsProductExcel) obj;
-                    PmsProductParam pmsProductParam = addData(excel);
-                    listAll.add(pmsProductParam);
+                    PmsProductExcelParam pmsProductExcelParam = addData(excel);
+                    listAll.add(pmsProductExcelParam);
                 }
             }
         }
         List<PmsBrand> bandlist = new ArrayList<>();
         //去除品牌里面的空格以及空字符
-        for(PmsProductParam  pmsProductParam:listAll){
-            String brandName = pmsProductParam.getBrandName();
-            pmsProductParam.setBrandName(MyStringUtils.replaceBlank(brandName));
+        for (PmsProductExcelParam pmsProductExcelParam : listAll) {
+            String brandName = pmsProductExcelParam.getBrandName();
+            pmsProductExcelParam.setBrandName(MyStringUtils.replaceBlank(brandName));
         }
         log.info("开始插入品牌数据");
-        List<String> BandNames = listAll.stream().map(PmsProductParam::getBrandName).distinct().collect(Collectors.toList());
+        List<String> BandNames = listAll.stream().map(PmsProductExcelParam::getBrandName).distinct().collect(Collectors.toList());
         for (String bandName : BandNames) {
             PmsBrand pmsBrand = new PmsBrand();
             pmsBrand.setName(bandName);
@@ -600,7 +599,7 @@ public class UploadCompanyInfoAndProductController {
             log.info(JSONObject.toJSONString(listAll));
             productExcelDao.saveData(listAll);
         }
-        List<String> compNames = listAll.stream().map(PmsProductParam::getUmsCompanyInfo).distinct().collect(Collectors.toList());
+        List<String> compNames = listAll.stream().map(PmsProductExcelParam::getUmsCompanyInfo).distinct().collect(Collectors.toList());
         if (compNames.size() > 0) {
             //更新大小类以及品牌生产地
             updateProductType(compNames);
@@ -610,52 +609,53 @@ public class UploadCompanyInfoAndProductController {
 
     //更新大小类
     public void updateProductType(List<String> compName) {
-        productExcelDao.updateBrand(compName);
-        productExcelDao.updateBigType(compName);
-        productExcelDao.updateSimType(compName);
-        productExcelDao.updateMemberOrigin(compName);
-        productExcelDao.updateBrandComp(compName);
+        List<Long> ids = listAll.stream().map(PmsProductExcelParam::getId).distinct().collect(Collectors.toList());
+        productExcelDao.updateBrand(compName, ids);
+        productExcelDao.updateBigType(compName, ids);
+        productExcelDao.updateSimType(compName, ids);
+        productExcelDao.updateMemberOrigin(compName, ids);
+        productExcelDao.updateBrandComp(compName, ids);
     }
 
 
-    private PmsProductParam addData(PmsProductExcel pmsProductExcel) {
+    private PmsProductExcelParam addData(PmsProductExcel pmsProductExcel) {
 
-        PmsProductParam pmsProductParam = new PmsProductParam();
-        BeanUtils.copyProperties(pmsProductExcel, pmsProductParam);
+        PmsProductExcelParam pmsProductExcelParam = new PmsProductExcelParam();
+        BeanUtils.copyProperties(pmsProductExcel, pmsProductExcelParam);
         //名称
         String name = pmsProductExcel.getName();
         //价格
         BigDecimal price = pmsProductExcel.getPrice();
         //标题
-        pmsProductParam.setDetailTitle(name);
+        pmsProductExcelParam.setDetailTitle(name);
         //笔记
-        pmsProductParam.setNote(name);
+        pmsProductExcelParam.setNote(name);
         //关键字
-        pmsProductParam.setKeywords(name);
+        pmsProductExcelParam.setKeywords(name);
 
         String description = replaceBlank(pmsProductExcel.getDescription());
 
-        pmsProductParam.setUmsCompanyInfoId(companyId(pmsProductExcel.getUmsCompanyInfo()));
+        pmsProductExcelParam.setUmsCompanyInfoId(companyId(pmsProductExcel.getUmsCompanyInfo()));
 
         //商品描述
-        pmsProductParam.setDescription(description);
+        pmsProductExcelParam.setDescription(description);
         //简述
-        pmsProductParam.setSubTitle(description);
+        pmsProductExcelParam.setSubTitle(description);
         //使用说明
         String instructions = replaceBlank(pmsProductExcel.getInstructions());
         //默认文本
-        pmsProductParam.setDetailDesc(instructions);
+        pmsProductExcelParam.setDetailDesc(instructions);
         //web网页显示
-        pmsProductParam.setDetailHtml(instructions);
+        pmsProductExcelParam.setDetailHtml(instructions);
         //手机网页显示
-        pmsProductParam.setDetailMobileHtml(instructions);
+        pmsProductExcelParam.setDetailMobileHtml(instructions);
         //市场价
-        pmsProductParam.setOriginalPrice(price);
+        pmsProductExcelParam.setOriginalPrice(price);
         //创建人 admin 1
-        pmsProductParam.setCreateUser((long) 1);
+        pmsProductExcelParam.setCreateUser((long) 1);
         //创建时间
-        pmsProductParam.setCreateTime(new Date());
-        return pmsProductParam;
+        pmsProductExcelParam.setCreateTime(new Date());
+        return pmsProductExcelParam;
     }
 
     public static String replaceBlank(String str) {

+ 7 - 6
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/dao/PmsProductExcelDao.java

@@ -8,7 +8,7 @@ import org.apache.ibatis.annotations.Param;
 import java.util.List;
 @Mapper
 public interface PmsProductExcelDao {
-    void saveData(@Param("list") List<PmsProductParam> list);
+    void saveData(@Param("list") List<PmsProductExcelParam> list);
 
     void saveBrandData(@Param("list") List<PmsBrand> list);
 
@@ -22,14 +22,15 @@ public interface PmsProductExcelDao {
 
     List<SelectVo> plOfProSelect(@Param("compId")Long compId);
 
-    void updateBrand(List<String> list);
+    void updateBrand(@Param("list")List<String> list,@Param("ids") List<Long> ids);
 
-    void updateBigType(List<String> list);
+    void updateBigType(@Param("list")List<String> list,@Param("ids") List<Long> ids);
 
-    void updateSimType(List<String> list);
+    void updateSimType(@Param("list")List<String> list,@Param("ids") List<Long> ids);
 
-    void updateMemberOrigin(List<String> list);
+    void updateMemberOrigin(@Param("list")List<String> list,@Param("ids") List<Long> ids);
 
+    void updateBrandComp(@Param("list")List<String> list,@Param("ids") List<Long> ids);
 
-    void updateBrandComp(List<String> list);
+    void updateComp(@Param("list")List<String> list,@Param("ids") List<Long> ids );
 }

+ 1 - 1
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/dto/param/PmsProductParam.java → forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/dto/param/PmsProductExcelParam.java

@@ -8,7 +8,7 @@ import java.math.BigDecimal;
 import java.util.Date;
 
 @Data
-public class PmsProductParam {
+public class PmsProductExcelParam {
     @ExcelIgnore
     private Long id;
     private String productNo;

+ 93 - 28
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/listener/PmsProductExcelListener.java

@@ -1,34 +1,35 @@
 package com.hwrj.cloud.admin.listener;
 
-import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.event.AnalysisEventListener;
 import com.alibaba.fastjson.JSONArray;
 import com.hwrj.cloud.admin.dao.PmsProductExcelDao;
 import com.hwrj.cloud.admin.dto.param.PmsProductExcel;
-import com.hwrj.cloud.admin.dto.param.PmsProductParam;
-import com.hwrj.cloud.admin.util.CurrUserUtil;
+import com.hwrj.cloud.admin.dto.param.PmsProductExcelParam;
+import com.hwrj.cloud.admin.model.PmsBrand;
+import com.hwrj.cloud.admin.util.ChineseCharToEn;
+import com.hwrj.cloud.admin.util.MyStringUtils;
 import lombok.SneakyThrows;
+import org.jetbrains.annotations.NotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Component;
-import org.springframework.util.StringUtils;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
-import java.net.URLEncoder;
 import java.text.DecimalFormat;
-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;
 
 /*
  * 监听器批处理数据
  * */
 @Component
+@Transactional
 public class PmsProductExcelListener extends AnalysisEventListener<PmsProductExcel> {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PmsProductExcelListener.class);
@@ -52,7 +53,11 @@ public class PmsProductExcelListener extends AnalysisEventListener<PmsProductExc
      */
     private static final int BATCH_COUNT = 2000;
 
-    List<PmsProductParam> list = new ArrayList();
+    List<PmsProductExcelParam> list = new ArrayList();
+
+    Set<String> companyList = new HashSet<>();
+
+    Set<String> bandlist = new HashSet<>();
 
     List<PmsProductExcel> erroList = new ArrayList<>();
 
@@ -107,44 +112,95 @@ public class PmsProductExcelListener extends AnalysisEventListener<PmsProductExc
     private void addData(PmsProductExcel pmsProductExcel, AnalysisContext analysisContext) {
         //获取对应的行数
         int num = analysisContext.readRowHolder().getRowIndex();
-        PmsProductParam pmsProductParam = new PmsProductParam();
-        BeanUtils.copyProperties(pmsProductExcel, pmsProductParam);
+        PmsProductExcelParam pmsProductExcelParam = getPmsProductParam(pmsProductExcel);
+        list.add(pmsProductExcelParam);
+        if (list.size() >= BATCH_COUNT) {
+            saveData();
+            list.clear();
+        }
+    }
+
+    private void updateProduct() {
+        //更新商品品牌
+        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(list.size());
+                pmsBrand.setCreateId((long) 1);
+                pmsBrand.setCreateTime(new Date());
+                allBrand.add(pmsBrand);
+            }
+            //插入品牌数据
+            if (allBrand.size() > 0) {
+                productExcelDao.saveBrandData(allBrand);
+            }
+            LOGGER.info("存储数据库成功!");
+            if (companyList.size() > 0) {
+                //更新大小类以及品牌生产地
+                List<String> companyNameList = new ArrayList<>(companyList);
+                updateProductType(companyNameList);
+            }
+        }
+    }
+
+    @NotNull
+    private PmsProductExcelParam getPmsProductParam(PmsProductExcel pmsProductExcel) {
+        PmsProductExcelParam pmsProductExcelParam = new PmsProductExcelParam();
+        BeanUtils.copyProperties(pmsProductExcel, pmsProductExcelParam);
         //名称
         String name = pmsProductExcel.getName();
         //价格
         BigDecimal price = pmsProductExcel.getPrice();
         //标题
-        pmsProductParam.setDetailTitle(name);
+        pmsProductExcelParam.setDetailTitle(name);
         //笔记
-        pmsProductParam.setNote(name);
+        pmsProductExcelParam.setNote(name);
         //关键字
-        pmsProductParam.setKeywords(name);
+        pmsProductExcelParam.setKeywords(name);
 
         String description = replaceBlank(pmsProductExcel.getDescription());
 
         //商品描述
-        pmsProductParam.setDescription(description);
+        pmsProductExcelParam.setDescription(description);
         //简述
-        pmsProductParam.setSubTitle(description);
+        pmsProductExcelParam.setSubTitle(description);
         //使用说明
         String instructions = replaceBlank(pmsProductExcel.getInstructions());
         //默认文本
-        pmsProductParam.setDetailDesc(instructions);
+        pmsProductExcelParam.setDetailDesc(instructions);
         //web网页显示
-        pmsProductParam.setDetailHtml(instructions);
+        pmsProductExcelParam.setDetailHtml(instructions);
         //手机网页显示
-        pmsProductParam.setDetailMobileHtml(instructions);
+        pmsProductExcelParam.setDetailMobileHtml(instructions);
         //市场价
-        pmsProductParam.setOriginalPrice(price);
+        pmsProductExcelParam.setOriginalPrice(price);
         //创建人 admin 1
-        pmsProductParam.setCreateUser((long) CurrUserUtil.getUserId());
+        pmsProductExcelParam.setCreateUser((long) 1);
         //创建时间
-        pmsProductParam.setCreateTime(new Date());
-        list.add(pmsProductParam);
-        if (list.size() >= BATCH_COUNT) {
-            saveData();
-            list.clear();
-        }
+        pmsProductExcelParam.setCreateTime(new Date());
+        //未上架
+        pmsProductExcelParam.setPublishStatus(0);
+        //未审核
+        pmsProductExcelParam.setVerifyStatus(0);
+        return pmsProductExcelParam;
+    }
+
+
+    //更新大小类
+    public void updateProductType(List<String> compName) {
+        productExcelDao.updateBrand(compName);
+        productExcelDao.updateBigType(compName);
+        productExcelDao.updateSimType(compName);
+        productExcelDao.updateMemberOrigin(compName);
     }
 
     @SneakyThrows
@@ -163,14 +219,23 @@ public class PmsProductExcelListener extends AnalysisEventListener<PmsProductExc
 //            EasyExcel.write(response.getOutputStream(), PmsProductExcel.class).sheet("Sheet").doWrite(erroList);
 //        }
 
+        updateProduct();
+
+
     }
 
     private void saveData() {
         LOGGER.info("{}条数据,开始存储数据库!", list.size());
         //调用saveData()方法
         if (list.size() > 0) {
+            LOGGER.info("开始插入商品数据");
             productExcelDao.saveData(list);
-            LOGGER.info("存储数据库成功!");
+            //获取品牌
+            List<String> bandNameNew= list.stream().map(PmsProductExcelParam::getBrandName).distinct().collect(Collectors.toList());
+            bandlist.addAll(bandNameNew);
+            //获取供应商
+            List<String>CompanyNameNew= list.stream().map(PmsProductExcelParam::getUmsCompanyInfo).distinct().collect(Collectors.toList());
+            companyList.addAll(CompanyNameNew);
         }
 
     }

+ 3 - 0
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/service/PmsProductService.java

@@ -12,6 +12,7 @@ import com.hwrj.cloud.admin.model.PmsProduct;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -92,4 +93,6 @@ public interface PmsProductService {
     List<SelectVo> plOfProSelect(Long compId);
 
     int verify(Long id);
+
+    void importBasic(MultipartFile file);
 }

+ 157 - 7
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/service/impl/PmsProductServiceImpl.java

@@ -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;
+    }
+
 }

+ 39 - 2
forest-admin/admin-server/src/main/resources/dao/ProductExcelDao.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.hwrj.cloud.admin.dao.PmsProductExcelDao">
     <insert id="saveData" useGeneratedKeys="true" keyProperty="id"
-            parameterType="com.hwrj.cloud.admin.dto.param.PmsProductParam">
+            parameterType="com.hwrj.cloud.admin.dto.param.PmsProductExcelParam">
         INSERT INTO pms_product
         (
         brand_id,
@@ -275,9 +275,13 @@
     <update id="updateBrand">
         UPDATE pms_product a
         LEFT JOIN pms_brand f ON a.brand_name = f.`name`
-        SET a.brand_id = f.id,a.
+        SET a.brand_id = f.id
         WHERE
         1 = 1
+        AND a.id IN
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
         AND a.comp_name in
         <foreach collection="list" item="compName" open="(" separator="," close=")">
             #{compName}
@@ -291,6 +295,10 @@
         WHERE
         b.parent_id = 0
         AND a.comp_name in
+        AND a.id IN
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
         <foreach collection="list" item="compName" open="(" separator="," close=")">
             #{compName}
         </foreach>
@@ -303,6 +311,10 @@
         WHERE
         c.parent_id != 0
         AND a.product_big_category_id = c.parent_id
+        AND a.id IN
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
         AND a.comp_name in
         <foreach collection="list" item="compName" open="(" separator="," close=")">
             #{compName}
@@ -315,6 +327,10 @@
         SET a.place_of_production_id = e.id
         WHERE
         1 = 1
+        AND a.id IN
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
         AND a.comp_name in
         <foreach collection="list" item="compName" open="(" separator="," close=")">
             #{compName}
@@ -326,10 +342,31 @@
         SET a.comp_id = b.comp_id,
          a.comp_name = b.comp_name
         WHERE 1=1
+
+        AND b.id IN
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
         AND b.comp_name in
         <foreach collection="list" item="compName" open="(" separator="," close=")">
             #{compName}
         </foreach>
     </update>
 
+    <update id="updateComp">
+        UPDATE pms_product a
+        LEFT JOIN ums_company_info b ON a.comp_name = b.comp_name
+        SET a.comp_id = b.id
+        WHERE
+        1 = 1
+        AND a.id IN
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        AND a.comp_name IN
+        <foreach collection="list" item="compName" open="(" separator="," close=")">
+            #{compName}
+        </foreach>
+    </update>
+
 </mapper>