|
|
@@ -1,7 +1,5 @@
|
|
|
package com.uas.platform.b2c.prod.product.component.service.impl;
|
|
|
|
|
|
-import com.google.common.collect.ImmutableSet;
|
|
|
-import com.google.common.collect.Iterables;
|
|
|
import com.uas.platform.b2c.common.account.dao.UserBaseInfoDao;
|
|
|
import com.uas.platform.b2c.common.base.service.SendMessageService;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
@@ -34,6 +32,7 @@ import com.uas.platform.core.persistence.criteria.LogicalExpression;
|
|
|
import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
@@ -724,27 +723,195 @@ public class ComponentSubmitServiceImpl implements ComponentSubmitService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ComponentCrawl> uploadComponentCrawl(List<Map<String, Object>> maps) {
|
|
|
- // 验证表头信息是否一致
|
|
|
- Map<String, Object> firstRow = maps.get(0);
|
|
|
- Set<String> theads = ImmutableSet.copyOf(Iterables.limit(firstRow.keySet(), 8));
|
|
|
-
|
|
|
- // 模板表头
|
|
|
- Set<String> expectHeads = new HashSet<String>();
|
|
|
- expectHeads.add("型号");
|
|
|
- expectHeads.add("商城类目");
|
|
|
- expectHeads.add("目标类目");
|
|
|
- expectHeads.add("商城品牌");
|
|
|
- expectHeads.add("来源网址");
|
|
|
- expectHeads.add("规格书");
|
|
|
- expectHeads.add("图片");
|
|
|
- expectHeads.add("描述");
|
|
|
-
|
|
|
- if (!expectHeads.containsAll(theads)) {
|
|
|
- throw new IllegalOperatorException("表格表头内容不对,请重新确认模板");
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
+ public List<ComponentCrawl> uploadComponentCrawl(List<List<Object>> rows, String fileName) {
|
|
|
+ List<ComponentCrawl> components = new ArrayList<ComponentCrawl>();
|
|
|
+
|
|
|
+ // 提取公共数据
|
|
|
+ List<Object> firstRow = rows.get(1);
|
|
|
+ Map<String, Object> commonData = validateCommonData(firstRow);
|
|
|
+ // 商城类目
|
|
|
+ Kind b2cKind = (Kind)commonData.get("b2cKind");
|
|
|
+ // 目标类目
|
|
|
+ String kindName = commonData.get("kindName").toString();
|
|
|
+ // 商城品牌
|
|
|
+ Brand b2cBrand = (Brand)commonData.get("b2cBrand");
|
|
|
+ // url
|
|
|
+ String url = commonData.get("url").toString();
|
|
|
+
|
|
|
+ // 如果参数参数对应关系出现重复返回前台提示是否新增参数对应关系
|
|
|
+ List<KindCrawl> existKindCrawls = kindContrastDao.findByKindNameAndB2cKiIdAndResourceAndB2cBrIdAndUrl(kindName, b2cKind.getId(), b2cBrand.getNameEn(), b2cBrand.getId(), url);
|
|
|
+ if (CollectionUtils.isNotEmpty(existKindCrawls)) {
|
|
|
+ ComponentCrawl isRepeated = new ComponentCrawl();
|
|
|
+ isRepeated.setB2cKiId(existKindCrawls.get(0).getId());
|
|
|
+ isRepeated.setVersion((short) -1);
|
|
|
+ components.add(isRepeated);
|
|
|
+ return components;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成参数对应关系
|
|
|
+ KindCrawl kindCrawl = initKindCrawl(b2cKind.getId(), b2cBrand, kindName, url, fileName);
|
|
|
+
|
|
|
+ // 生成数据解析任务
|
|
|
+ ComponentCrawlTask task = initComponentCrawlTask(kindCrawl, fileName);
|
|
|
+
|
|
|
+ // 取表头信息
|
|
|
+ List<String> propertyNames = (List<String>)(List)rows.get(0);
|
|
|
+ int maxSize = propertyNames.size();
|
|
|
+
|
|
|
+ for (int i = 1; i < rows.size(); i++) {
|
|
|
+ List<Object> row = rows.get(i);
|
|
|
+ ComponentCrawl component = new ComponentCrawl();
|
|
|
+
|
|
|
+ // 型号
|
|
|
+ Object code = row.get(0);
|
|
|
+ if (code != null && StringUtils.hasText(code.toString())) {
|
|
|
+ component.setCode(code.toString().trim());
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException(String.format("第%s行型号为空", (i + 1)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 规格书
|
|
|
+ Object attach = row.get(5);
|
|
|
+ if (attach != null && StringUtils.hasText(attach.toString())) {
|
|
|
+ component.setAttach(attach.toString().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 图片
|
|
|
+ Object img = row.get(6);
|
|
|
+ if (img != null && StringUtils.hasText(img.toString())) {
|
|
|
+ component.setImg(img.toString().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 描述
|
|
|
+ Object description = row.get(7);
|
|
|
+ if (description != null && StringUtils.hasText(description.toString())) {
|
|
|
+ component.setDescription(description.toString().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 参数值
|
|
|
+ Set<PropertyValueCrawl> propertyValues = new HashSet<PropertyValueCrawl>();
|
|
|
+ for (int j = 8; j < maxSize && j < row.size(); j++) {
|
|
|
+ Object property = row.get(j);
|
|
|
+ if (property != null && StringUtils.hasText(property.toString())) {
|
|
|
+ PropertyValueCrawl propertyValue = new PropertyValueCrawl();
|
|
|
+ propertyValue.setValue(property.toString().trim());
|
|
|
+ propertyValue.setPropertyName(propertyNames.get(j));
|
|
|
+ propertyValues.add(propertyValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ component.setProperties(propertyValues);
|
|
|
+ // 设置基本参数
|
|
|
+ component.setB2cBrId(b2cBrand.getId());
|
|
|
+ component.setB2cKiId(b2cKind.getId());
|
|
|
+ component.setKindName(kindName);
|
|
|
+ component.setTask(task.getId());
|
|
|
+
|
|
|
+ components.add(component);
|
|
|
+ }
|
|
|
+ return componentCrawlDao.save(components);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化数据解析任务
|
|
|
+ * @param kindCrawl 参数对应关系
|
|
|
+ * @param fileName 上传文件名
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ComponentCrawlTask initComponentCrawlTask(KindCrawl kindCrawl, String fileName) {
|
|
|
+ // 生成数据解析任务
|
|
|
+ ComponentCrawlTask task = new ComponentCrawlTask();
|
|
|
+ task.setContrastId(kindCrawl.getId());
|
|
|
+ task.setContrast(FastjsonUtils.toJson(kindCrawl));
|
|
|
+ task.setCreateDate(new Date());
|
|
|
+ task.setCreaterUu(SystemSession.getUser().getUserUU());
|
|
|
+ task.setStatus(Status.TO_CROWL.value());
|
|
|
+ task.setFile(fileName);
|
|
|
+ task.setTaskId(EncodingRulesConstant.COMPONENT_CRAWL_TASK.replaceFirst("_TIMESTAP_NUMBER", createNumberService.getTimeNumber("product$component_crawl_task", 8)));
|
|
|
+
|
|
|
+ kindCrawl.setTaskid(task.getTaskId());// 将数据解析任务号回写到参数对应关系中
|
|
|
+ kindContrastDao.save(kindCrawl);
|
|
|
+
|
|
|
+ return componentCrawlTaskDao.save(task);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化标准参数对应关系
|
|
|
+ * @param b2cKindId 商城类目id
|
|
|
+ * @param b2cBrand 商城品牌
|
|
|
+ * @param kindName 目标类目
|
|
|
+ * @param url 官网地址
|
|
|
+ * @param fileName 上传文件名
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private KindCrawl initKindCrawl(Long b2cKindId, Brand b2cBrand, String kindName, String url, String fileName) {
|
|
|
+ Date date = new Date();
|
|
|
+ KindCrawl kindCrawl = new KindCrawl();
|
|
|
+ kindCrawl.setResource(b2cBrand.getNameEn());
|
|
|
+ kindCrawl.setB2cBrId(b2cBrand.getId());
|
|
|
+ kindCrawl.setKindName(kindName);
|
|
|
+ kindCrawl.setB2cKiId(b2cKindId);
|
|
|
+ kindCrawl.setUrl(url);
|
|
|
+ kindCrawl.setCreateDate(date);
|
|
|
+ kindCrawl.setCreaterUu(SystemSession.getUser().getUserUU());
|
|
|
+ kindCrawl.setInTask((short) 1);// 参数对应关系直接设置为已提交
|
|
|
+ kindCrawl.setUpdateDate(date);
|
|
|
+ kindCrawl.setUpdaterUu(SystemSession.getUser().getUserUU());
|
|
|
+ kindCrawl.setFile(fileName);// 设置上传文件名
|
|
|
+
|
|
|
+ kindCrawl = kindContrastDao.save(kindCrawl);
|
|
|
+ return kindContrastDao.findOne(kindCrawl.getId());// 因为save返回的对象没有关联的实体信息只有id,所以需要重新查询一次,为后续生成json存入任务做准备
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证公共数据
|
|
|
+ * @param firstRow
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, Object> validateCommonData(List<Object> firstRow) {
|
|
|
+ if (CollectionUtils.isNotEmpty(firstRow)) {
|
|
|
+ Map<String, Object> commonData = new HashedMap();
|
|
|
+
|
|
|
+ // 商城类目
|
|
|
+ Object b2cKindName = firstRow.get(1);
|
|
|
+ if (b2cKindName != null && StringUtils.hasText(b2cKindName.toString())) {
|
|
|
+ List<Kind> kinds = kindDao.findByNameCn(b2cKindName.toString().trim());
|
|
|
+ if (CollectionUtils.isEmpty(kinds)) {
|
|
|
+ throw new IllegalOperatorException("商城类目不存在");
|
|
|
+ }
|
|
|
+ commonData.put("b2cKind", kinds.get(0));
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("商城类目为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 目标类目
|
|
|
+ Object kindName = firstRow.get(2);
|
|
|
+ if (kindName != null && StringUtils.hasText(kindName.toString())) {
|
|
|
+ commonData.put("kindName", kindName.toString().trim());
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("目标类目为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 商城品牌
|
|
|
+ Object brandName = firstRow.get(3);
|
|
|
+ if (brandName != null && StringUtils.hasText(brandName.toString())) {
|
|
|
+ List<Brand> brands = brandDao.findByUpperNameEn(brandName.toString().trim());
|
|
|
+ if (CollectionUtils.isEmpty(brands)) {
|
|
|
+ throw new IllegalOperatorException("商城品牌不存在");
|
|
|
+ }
|
|
|
+ commonData.put("b2cBrand", brands.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ // url
|
|
|
+ Object url = firstRow.get(4);
|
|
|
+ if (url != null && StringUtils.hasText(url.toString())) {
|
|
|
+ commonData.put("url", url.toString().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ return commonData;
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("第二列数据不存在");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|