|
@@ -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) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|