lyhzzz 1 år sedan
förälder
incheckning
6beca70120

+ 2 - 0
src/main/java/com/cdf/common/ResultCode.java

@@ -36,6 +36,8 @@ public enum ResultCode {
     PRODUCT_SOURCE_NOT_DEL(9003,"店铺存在关联数据,不能删除。"),
 
     DOWN_TEMPLATE_ERROR(10001,"下载模版出错"),
+    UPLOAD_EXCEL_ERROR(10002,"上传excel文件出错"),
+    UPLOAD_EXCEL_CHECK_ERROR(10003,"上传文件未校验"),
     ;
 
     public int code;

+ 10 - 1
src/main/java/com/cdf/controller/back/BrandController.java

@@ -34,7 +34,16 @@ public class BrandController {
 
     @GetMapping("updateBrandInfo")
     public ResultData updateBrandInfo() throws Exception {
-        brandService.updateBrandInfo();
+        new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    brandService.updateBrandInfo();
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }.run();
         return ResultData.ok();
     }
 }

+ 2 - 2
src/main/java/com/cdf/entity/Brand.java

@@ -71,10 +71,10 @@ public class Brand implements Serializable {
     private Integer tbStatus;
 
     @TableField("create_time")
-    private Date createTime;
+    private String createTime;
 
     @TableField("update_time")
-    private Date updateTime;
+    private String updateTime;
 
 
 }

+ 2 - 2
src/main/java/com/cdf/entity/HotOutline.java

@@ -47,10 +47,10 @@ public class HotOutline implements Serializable {
     private Integer tbStatus;
 
     @TableField("create_time")
-    private Date createTime;
+    private String createTime;
 
     @TableField("update_time")
-    private Date updateTime;
+    private String updateTime;
 
 
 }

+ 5 - 0
src/main/java/com/cdf/service/IBrandService.java

@@ -6,6 +6,7 @@ import com.cdf.request.BrandApiParam;
 import com.cdf.response.BrandApiVo;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -23,4 +24,8 @@ public interface IBrandService extends IService<Brand> {
     Object pageList(BrandApiParam param);
 
     HashMap<Integer, BrandApiVo> getMapByIds(Set<Integer> brandIds);
+
+    List<Brand> getByCdfBrandIds(List<String> brandIds);
+
+    void updateBrandOutline(String brandId, String outlineId);
 }

+ 19 - 0
src/main/java/com/cdf/service/impl/BrandServiceImpl.java

@@ -2,6 +2,7 @@ package com.cdf.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.cdf.common.PageInfo;
 import com.cdf.entity.Brand;
@@ -146,6 +147,16 @@ public class BrandServiceImpl extends ServiceImpl<IBrandMapper, Brand> implement
         return map;
     }
 
+    @Override
+    public List<Brand> getByCdfBrandIds(List<String> brandIds) {
+        if(brandIds != null && brandIds.size() >0){
+            LambdaQueryWrapper<Brand> wrapper = new LambdaQueryWrapper<>();
+            wrapper.in(Brand::getCdfBrandId,brandIds);
+            return this.list(wrapper);
+        }
+        return null;
+    }
+
     public static void main(String[] args) {
         Long pageNum = 1L;
         Long pageSize = 100L;
@@ -167,4 +178,12 @@ public class BrandServiceImpl extends ServiceImpl<IBrandMapper, Brand> implement
         }
         System.out.println(allBrand.size());
     }
+
+    @Override
+    public void updateBrandOutline(String brandId, String outlineId) {
+        LambdaUpdateWrapper<Brand> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.eq(Brand::getCdfBrandId,brandId);
+        wrapper.set(Brand::getOutlineId,outlineId);
+        this.update(wrapper);
+    }
 }

+ 241 - 21
src/main/java/com/cdf/service/impl/ExcelService.java

@@ -6,14 +6,28 @@ import com.alibaba.excel.ExcelWriter;
 import com.alibaba.excel.write.metadata.WriteSheet;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.amazonaws.services.ecs.model.Tmpfs;
 import com.cdf.common.CacheUtil;
 import com.cdf.common.ResultCode;
+import com.cdf.entity.Brand;
+import com.cdf.entity.HotOutline;
+import com.cdf.entity.HotRelation;
+import com.cdf.entity.ProductSource;
+import com.cdf.httpClient.client.CdfClient;
+import com.cdf.httpClient.client.CdfHKClient;
+import com.cdf.httpClient.response.cdf.CdfProduct;
+import com.cdf.httpClient.response.cdf.CdfProductListByIdsRequest;
+import com.cdf.httpClient.response.cdf.CdfProductListByIdsVo;
 import com.cdf.request.UploadHotsParam;
 import com.cdf.response.HotExcelVo;
 import com.cdf.exception.BusinessException;
 import com.cdf.response.HotUploadTemplate;
 import com.cdf.response.OutlineUploadTemplate;
 import com.cdf.response.ProductUploadTemplate;
+import com.cdf.service.IBrandService;
+import com.cdf.service.IHotOutlineService;
+import com.cdf.service.IHotRelationService;
+import com.cdf.service.IProductSourceService;
 import com.cdf.util.ExcelUtil;
 import com.cdf.util.UploadToCdfOssUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -29,6 +43,7 @@ import java.io.File;
 import java.io.InputStream;
 import java.net.URLEncoder;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -44,22 +59,43 @@ public class ExcelService {
     private String filePath;
     @Value("${upload.query-path}")
     private String queryPath;
-
     @Autowired
     private FdkkSceneEditService fdkkSceneEditService;
+    @Autowired
+    CdfHKClient cdfHKClient;
+    @Autowired
+    IProductSourceService productSourceService;
+    @Autowired
+    private IHotOutlineService hotOutlineService;
+    @Autowired
+    private IBrandService brandService;
+    @Autowired
+    private IHotRelationService hotRelationService;
+
+
     // 0 外框设置 ,1 瀑布流, 2,精选推荐设置 ,3 品牌推荐设置
     public void  downTemplate(Integer type,String sceneNum,HttpServletRequest req,HttpServletResponse response)  {
-        if(type == null || StringUtils.isBlank(sceneNum)){
+        if(type == null ){
             throw new BusinessException(ResultCode.PARAM_MISS);
         }
         try {
-            List<HotUploadTemplate> list = getHotsList(sceneNum,req.getHeader("token"));
+            List<HotUploadTemplate> list = new ArrayList<>();
+            if(type != 0 && StringUtils.isNotBlank(sceneNum)){
+                list = getHotsList(sceneNum);
+            }
 
             String fileName = "";
             switch (type){
                 case 0 :
                     fileName ="导入外框模版";
-                    this.commonExport(req,response,fileName,list, OutlineUploadTemplate.class);
+                    List<Brand> list1 = brandService.list();
+                    List<OutlineUploadTemplate> OutlineUploadTemplateList = new ArrayList<>();
+                    for (Brand brand : list1) {
+                        OutlineUploadTemplate template = new OutlineUploadTemplate(brand.getOutlineId().toString(),brand.getCdfBrandId());
+                        OutlineUploadTemplateList.add(template);
+                    }
+
+                    this.commonExport(req,response,fileName,OutlineUploadTemplateList, OutlineUploadTemplate.class);
                     break;
                 case 1 :
                     fileName ="导入商品瀑布流模版";
@@ -108,55 +144,182 @@ public class ExcelService {
             file.getParentFile().mkdirs();
         }
         uploadToCdfOssUtil.download(awsKey,localFile);
+        List<String> errorList = new ArrayList<>();
+        String resultError = null;
+        switch (param.getType()){
+            case 0:
+                checkUploadOutline(file,errorList);
+                break;
+            case 1:
+                checkUploadProduct(file,errorList);
+                break;
+            case 2 :case 3 :
+                checkHot(file,errorList);
+                break;
+            default:  throw new BusinessException(ResultCode.PARAM_MISS);
+        }
+
+        if(!errorList.isEmpty()){
+            resultError = String.join(",", errorList);
+            throw new BusinessException(ResultCode.UPLOAD_EXCEL_ERROR.code,resultError);
+        }
+    }
 
+
+
+    private void checkUploadOutline(File file, List<String> errorList) {
+        List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
+        Integer colum = 0;
+        List<String> outlineIds = new ArrayList<>();
+        List<String> outlineIdsDb = new ArrayList<>();
+        List<String> brandIds = new ArrayList<>();
+        List<String> brandIdsDb = new ArrayList<>();
+        for (HashMap<Integer, String> map : excelRowList) {
+            String outlineId = map.get(0);
+            String brandId = map.get(1);
+            if(StringUtils.isNotBlank(outlineId)){
+                outlineIds.add(outlineId);
+            }
+            if(StringUtils.isNotBlank(brandId)){
+                brandIds.add(brandId);
+            }
+        }
+        if(outlineIds.size() >0){
+            List<HotOutline> hotOutlines = hotOutlineService.listByIds(outlineIds);
+            for (HotOutline hotOutline : hotOutlines) {
+                outlineIdsDb.add(hotOutline.getId().toString());
+            }
+        }
+        if(brandIds.size() >0){
+            List<Brand> brands = brandService.getByCdfBrandIds(brandIds);
+            for (Brand brand : brands) {
+                brandIdsDb.add(brand.getCdfBrandId().toString());
+            }
+        }
+
+        for (HashMap<Integer, String> map : excelRowList) {
+            colum ++;
+            String outlineId = map.get(0);
+            String brandId = map.get(1);
+            if(StringUtils.isBlank(outlineId) || StringUtils.isBlank(brandId)){
+                errorList.add(colum.toString());
+                continue;
+            }
+            if(!outlineIdsDb.contains(outlineId)){
+                errorList.add(colum.toString());
+                continue;
+            }
+            if(!brandIdsDb.contains(brandId)){
+                errorList.add(colum.toString());
+            }
+
+        }
+    }
+
+    private void checkUploadProduct(File file, List<String> errorList){
         List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
         List<HotUploadTemplate> list = null;
-        List<Integer> errorList = new ArrayList<>();
         Integer colum = 0;
-        List<String> pidList = new ArrayList<>();
+        HashMap<String,ProductSource> productSourceHashMap = new HashMap<>();
+        HashMap<String, List<String>> productSourceProductMap = new HashMap<>();
+        HashMap<String, List<String>> resultPMap = new HashMap<>();
+
         for (HashMap<Integer, String> map : excelRowList) {
-            String pid = map.get(3);
+            String sourceId = map.get(3);
+            if(StringUtils.isNotBlank(sourceId)){
+                ProductSource byMchId = productSourceService.getByMchId(sourceId);
+                productSourceHashMap.put(sourceId,byMchId);
+            }
+            String pid = map.get(4);
             if(StringUtils.isNotBlank(pid)){
+                List<String> pidList = productSourceProductMap.computeIfAbsent(sourceId, k -> new ArrayList<>());
                 pidList.add(pid);
             }
         }
-
+        for (String mchId : productSourceProductMap.keySet()) {
+            ProductSource productSource = productSourceHashMap.get(mchId);
+            JSONArray ids = new JSONArray();
+            ids.addAll(productSourceProductMap.get(mchId));
+            CdfProductListByIdsRequest idsRequest = new CdfProductListByIdsRequest(ids);
+            CdfProductListByIdsVo vos = cdfHKClient.getProductListByIds(productSource.getCdfHost(), productSource.getCdfMchId(), idsRequest);
+            if(vos.getProductCardList()!=null && vos.getProductCardList().size() >0){
+                for (CdfProduct cdfProduct : vos.getProductCardList()) {
+                    List<String> pidList = resultPMap.computeIfAbsent(mchId, k -> new ArrayList<>());
+                    pidList.add(cdfProduct.getId());
+                }
+            }
+        }
         for (HashMap<Integer, String> map : excelRowList) {
             colum ++;
             String sceneNum = map.get(0);
             String sid = map.get(1);
             String title = map.get(2);
-            String pid = map.get(3);
-            if(StringUtils.isBlank(sceneNum) || StringUtils.isBlank(sid) || StringUtils.isBlank(pid)){
-                errorList.add(colum);
+            String mchId = map.get(3);
+            String pid = map.get(4);
+            if(StringUtils.isBlank(sceneNum) || StringUtils.isBlank(sid) || StringUtils.isBlank(pid) || StringUtils.isBlank(mchId)){
+                errorList.add(colum.toString());
                 continue;
             }
             if(list == null){
-                list  = getHotsList(sceneNum,param.getToken());
+                list  = getHotsList(sceneNum);
             }
             if(list .isEmpty()){
-                errorList.add(colum);
+                errorList.add(colum.toString());
                 continue;
             }
             List<String> collect = list.stream().map(HotUploadTemplate::getSid).collect(Collectors.toList());
             if(!collect.contains(sid)){
-                errorList.add(colum);
+                errorList.add(colum.toString());
                 continue;
             }
+            if(!productSourceHashMap.containsKey(mchId)){
+                errorList.add(colum.toString());
+                continue;
+            }
+            List<String> cdfProductList = resultPMap.get(mchId);
+            if(cdfProductList.isEmpty()){
+                errorList.add(colum.toString());
+                continue;
+            }
+            if(!cdfProductList.contains(pid)){
+                errorList.add(colum.toString());
+            }
 
+        }
+    }
+    private void checkHot(File file, List<String> errorList) {
+        List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
+        Integer colum = 0;
+        List<HotUploadTemplate> list = null;
 
-
-
+        for (HashMap<Integer, String> map : excelRowList) {
+            colum ++;
+            String sceneNum = map.get(0);
+            String sid = map.get(1);
+            String title = map.get(2);
+            if(StringUtils.isBlank(sceneNum) || StringUtils.isBlank(sid) ){
+                errorList.add(colum.toString());
+                continue;
+            }
+            if(list == null){
+                list  = getHotsList(sceneNum);
+            }
+            if(list .isEmpty()){
+                errorList.add(colum.toString());
+                continue;
+            }
+            List<String> collect = list.stream().map(HotUploadTemplate::getSid).collect(Collectors.toList());
+            if(!collect.contains(sid)){
+                errorList.add(colum.toString());
+            }
 
         }
-
     }
 
-    private  List<HotUploadTemplate> getHotsList(String sceneNum,String token){
-        JSONObject tagList = fdkkSceneEditService.getTagList(sceneNum, token, "eshop_cn");
-        JSONArray tags =tagList.getJSONArray("tags");
+    private  List<HotUploadTemplate> getHotsList(String sceneNum){
+        JSONArray hotJson = fdkkSceneEditService.getCdfHotJson(sceneNum);
         List<HotUploadTemplate> list = new ArrayList<>();
-        for (Object obj : tags) {
+        for (Object obj : hotJson) {
             JSONObject tag = (JSONObject) obj;
             String sid = tag.getString("sid");
             String title = tag.getString("title");
@@ -167,5 +330,62 @@ public class ExcelService {
     }
 
     public void uploadExcel(UploadHotsParam param) {
+        if(StringUtils.isBlank(param.getFilePath()) || param.getType()== null){
+            throw new BusinessException(ResultCode.PARAM_MISS);
+        }
+        String awsKey = param.getFilePath().replace(queryPath, "");
+        if(!uploadToCdfOssUtil.existKey(awsKey)){
+            throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
+        }
+        String localPath = String.format(CacheUtil.localFilePath, CacheUtil.activeYaml);
+        String localFile = localPath + awsKey;
+        File file = new File(localFile);
+        if(!file.exists()){
+            throw new BusinessException(ResultCode.UPLOAD_EXCEL_CHECK_ERROR);
+        }
+        switch (param.getType()){
+            case 0:
+                uploadOutline(file);
+                break;
+            case 1:
+                uploadProduct(file);
+                break;
+            case 2 :case 3 :
+                uploadHot(file,param.getType());
+                break;
+            default:  throw new BusinessException(ResultCode.PARAM_MISS);
+        }
+
+    }
+
+    private void uploadOutline(File file) {
+        List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
+        for (HashMap<Integer, String> map : excelRowList) {
+            String outlineId = map.get(0);
+            String brandId = map.get(1);
+            if(StringUtils.isNotBlank(outlineId) && StringUtils.isNotBlank(brandId)){
+                brandService.updateBrandOutline(brandId,outlineId);
+            }
+        }
+
+    }
+
+    private void uploadProduct(File file) {
+        List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
+        for (HashMap<Integer, String> map : excelRowList) {
+            String sceneNum = map.get(0);
+            String sid = map.get(1);
+            String title = map.get(2);
+            String mchId = map.get(3);
+            String pid = map.get(4);
+        }
+    }
+
+    private void uploadHot(File file,Integer type) {
+
+        List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
+        for (HashMap<Integer, String> map : excelRowList) {
+
+        }
     }
 }