瀏覽代碼

Merge branch 'test'

lyhzzz 1 年之前
父節點
當前提交
8242afcd34

+ 11 - 31
src/main/java/com/cdf/service/impl/ExcelService.java

@@ -17,6 +17,7 @@ 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.httpClient.response.cdf.CdfProductVo;
 import com.cdf.request.UploadHotsParam;
 import com.cdf.response.*;
 import com.cdf.exception.BusinessException;
@@ -33,6 +34,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.URLEncoder;
 import java.util.*;
@@ -236,35 +238,10 @@ public class ExcelService {
     private void checkUploadProduct(File file, List<String> errorList){
         List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
         Integer colum = 1;
-        HashMap<String, List<String>> productSourceProductMap = new HashMap<>();
-        HashMap<String, List<String>> resultPMap = new HashMap<>();
         HashMap<String, List<String>> numMap = new HashMap<>();
         HashMap<String,ProductSource> productMap = new HashMap<>();
 
         for (HashMap<Integer, String> map : excelRowList) {
-            String sourceId = map.get(3);
-            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 = productSourceService.getByMchId(mchId);
-            if(productSource !=null){
-                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);
@@ -298,12 +275,8 @@ public class ExcelService {
                 errorList.add(colum.toString());
                 continue;
             }
-            List<String> cdfProductList = resultPMap.get(mchId);
-            if(cdfProductList.isEmpty()){
-                errorList.add(colum.toString());
-                continue;
-            }
-            if(!cdfProductList.contains(pid)){
+            CdfProductVo productById = cdfHKClient.getProductById(productSource.getCdfHost(),productSource.getCdfMchId(),pid);
+            if(productById == null || productById.getId() == null || !productById.getId().equals(pid)){
                 errorList.add(colum.toString());
             }
 
@@ -377,6 +350,13 @@ public class ExcelService {
                 break;
             default:  throw new BusinessException(ResultCode.PARAM_MISS);
         }
+        try {
+            file.delete();
+            uploadToCdfOssUtil.delete(awsKey);
+        }catch (Exception e){
+            log.info("删除文件失败:",e);
+        }
+
 
     }
 

+ 9 - 4
src/main/java/com/cdf/service/impl/ProductSourceServiceImpl.java

@@ -15,6 +15,7 @@ import com.cdf.service.IHotRelationService;
 import com.cdf.service.IProductSourceService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cdf.service.ISceneSourceDataService;
+import com.cdf.util.MyStringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -51,13 +52,17 @@ public class ProductSourceServiceImpl extends ServiceImpl<IProductSourceMapper,
 
     @Override
     public Object getBySource(CdfProductListRequest param,ProductSource productSource) {
-        if(StringUtils.isNotBlank(param.getKeyword()) && param.getKeyword().contains(",")){
+        if(StringUtils.isNotBlank(param.getKeyword()) && (param.getKeyword().contains(",")  || MyStringUtils.isCdfProductId(param.getKeyword()))) {
             if(param.getPageNum() >1){
                 PageInfo pageInfo = PageInfo.PageInfo(param.getPageIndex(), 20L, 0L, new ArrayList<>());
-                return  ResultData.ok(pageInfo);
+                return  pageInfo;
             }
             JSONArray ids = new JSONArray();
-            ids.addAll(Arrays.asList(param.getKeyword().split(",")));
+            if(param.getKeyword().contains(",")){
+                ids.addAll(Arrays.asList(param.getKeyword().split(",")));
+            }else {
+                ids.add(param.getKeyword());
+            }
             CdfProductListByIdsRequest idsRequest = new CdfProductListByIdsRequest(ids);
             CdfProductListByIdsVo vos = cdfHKClient.getProductListByIds(productSource.getCdfHost(),productSource.getCdfMchId(),idsRequest);
             List<CdfProduct> productCardList = vos.getProductCardList();
@@ -65,7 +70,7 @@ public class ProductSourceServiceImpl extends ServiceImpl<IProductSourceMapper,
                 cdfProduct.setProductSource(productSource);
             }
             PageInfo pageInfo = PageInfo.PageInfo(param.getPageIndex(), (long) productCardList.size(), (long) productCardList.size(), productCardList);
-            return ResultData.ok(pageInfo);
+            return pageInfo;
         }
         CdfProductListResponse productList = cdfHKClient.getProductList(productSource.getCdfHost(),productSource.getCdfMchId(),param);
         if(productList.getSearchResult().getType() == 4 ){

+ 8 - 0
src/main/java/com/cdf/util/MyStringUtils.java

@@ -14,4 +14,12 @@ public class MyStringUtils {
         return a.equals(b);
     }
 
+
+    public static String pPattern = "p[\\d]{6,10}";
+
+    public static boolean isCdfProductId(String a){
+        return a.matches(pPattern);
+    }
+
+
 }