|
|
@@ -1,8 +1,13 @@
|
|
|
package com.uas.ps.product.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.uas.ps.brand.entity.BrandInfo;
|
|
|
+import com.uas.ps.component.entity.ComponentInfo;
|
|
|
import com.uas.ps.entity.Product;
|
|
|
+import com.uas.ps.entity.ProductMatchResult;
|
|
|
import com.uas.ps.entity.ProductUsers;
|
|
|
import com.uas.ps.entity.Status;
|
|
|
+import com.uas.ps.product.ProductConstant;
|
|
|
import com.uas.ps.product.entity.Constant;
|
|
|
import com.uas.ps.product.entity.Prod;
|
|
|
import com.uas.ps.product.entity.ProductSaler;
|
|
|
@@ -11,6 +16,7 @@ import com.uas.ps.product.repository.ProductMatchResultDao;
|
|
|
import com.uas.ps.product.repository.ProductStoreStatusDao;
|
|
|
import com.uas.ps.product.repository.ProductUsersDao;
|
|
|
import com.uas.ps.product.service.ProductService;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
@@ -18,12 +24,10 @@ import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author sunyj
|
|
|
@@ -44,6 +48,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private ProductStoreStatusDao productStoreStatusDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
/**
|
|
|
* 保存物料
|
|
|
*
|
|
|
@@ -85,48 +92,131 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Override
|
|
|
public ModelMap match(Long enUU, Long userUU, String matchtype) {
|
|
|
ModelMap map = new ModelMap();
|
|
|
- //TODO
|
|
|
-// boolean flag = true;
|
|
|
-// ProductStoreStatus status = productStoreStatusDao.findByEnuu(enUU);
|
|
|
-// if (status != null) {
|
|
|
-// if (status.getStatus().equals(Status.RUNNING.value())) {// 有人正在操作这张单据,不能进行操作
|
|
|
-// map.put("error", "当前有人正在进行匹配操作,无法进行匹配");
|
|
|
-// flag = false;
|
|
|
-// } else {
|
|
|
-// status.setStatus(Status.RUNNING.value());
|
|
|
-// status = productStoreStatusDao.save(status);
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// ProductStoreStatus stroestatus = new ProductStoreStatus();
|
|
|
-// stroestatus.setDate(new Date());
|
|
|
-// stroestatus.setEnuu(enUU);
|
|
|
-// stroestatus.setUseruu(userUU);
|
|
|
-// stroestatus.setStatus(Status.RUNNING.value());
|
|
|
-// status = productStoreStatusDao.save(stroestatus);
|
|
|
-// }
|
|
|
-// String num = null;
|
|
|
-// if (flag) {
|
|
|
-// if (matchtype.equals("sale")) {
|
|
|
-// num = productDao.updateResultByEnuuForSale(enUU);
|
|
|
-//// logger.log("产品匹配", "一键匹配了产品信息", "大小" + num);
|
|
|
-// } else if (matchtype.equals("purc")) {
|
|
|
-// num = productDao.updateResultByEnuuForPurc(enUU);
|
|
|
-//// logger.log("物料匹配", "一键匹配了物料信息", "大小" + num);
|
|
|
-// } else if (matchtype.equals("all")) {
|
|
|
-// num = productDao.updateResultByEnuu(enUU);
|
|
|
-//// logger.log("物料匹配", "一键匹配了产品(物料)信息", "大小" + num);
|
|
|
-// }
|
|
|
-// if (null == num) {
|
|
|
-// map.put("size", 0);
|
|
|
-// } else {
|
|
|
-// map.put("size", num);
|
|
|
-// }
|
|
|
-// status.setStatus(Status.FINISH.value());
|
|
|
-// productStoreStatusDao.save(status);
|
|
|
-// }
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ModelMap matchB2cAll(Long enUU, Long userUU) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ int success = 0;
|
|
|
+ List<Product> nonStandardList = productDao.findByEnUUAndStandard(enUU, ProductConstant.NON_STANDARD);
|
|
|
+ for (Product product : nonStandardList) {
|
|
|
+ success += matchOne(product, enUU);
|
|
|
+ }
|
|
|
+ map.put("success", success);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量匹配
|
|
|
+ * @param enUU
|
|
|
+ * @param idList
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap batchMatch(Long enUU, List<Long> idList) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ int success = 0;
|
|
|
+ for (Long id : idList) {
|
|
|
+ Product product = productDao.findOne(id);
|
|
|
+ success += matchOne(product, enUU);
|
|
|
+ }
|
|
|
+ map.put("success", success);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单个物料匹配
|
|
|
+ * @param product
|
|
|
+ * @param enUU
|
|
|
+ */
|
|
|
+ private int matchOne(Product product, Long enUU) {
|
|
|
+ // 获取品牌
|
|
|
+ String brandUrl = "http://10.1.51.89:8080/platform-b2c/api/product/brand/byName/brand?name=" + product.getpBrandEn();
|
|
|
+ BrandInfo brand = restTemplate.getForEntity(brandUrl, BrandInfo.class).getBody();
|
|
|
+ if (brand.getUuid() != null) {
|
|
|
+ String componentUrl = "http://10.1.51.89:8080/platform-b2c/api/product/component/codeAndBrand/info?brandId="
|
|
|
+ + brand.getId() + "&cmpCode=" + product.getpCmpCode();
|
|
|
+ ComponentInfo component = restTemplate.getForEntity(componentUrl, ComponentInfo.class).getBody();
|
|
|
+ if (component != null) {
|
|
|
+ // 更新物料信息
|
|
|
+ updateProductByComponent(product, component);
|
|
|
+ List<Product> standardList = productDao.findProductByPcmpcodeAndPbrandenAndEnUU(product.getpCmpCode(), product.getpBrand(), enUU);
|
|
|
+ if (CollectionUtils.isNotEmpty(standardList)) {
|
|
|
+ // TODO 已有标准产品,该如何处理
|
|
|
+ }
|
|
|
+ productDao.save(product);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 根据型号匹配
|
|
|
+ String codeUrl = "http://10.1.51.89:8080/platform-b2c/api/product/component/byCode?code=" + product.getpCmpCode();
|
|
|
+ String componentJson = restTemplate.getForEntity(codeUrl, String.class).getBody();
|
|
|
+ List<ComponentInfo> componentInfoList = JSON.parseArray(componentJson, ComponentInfo.class);
|
|
|
+ Set<ProductMatchResult> productMatchResults = convertComponentToResult(componentInfoList, enUU);
|
|
|
+ if (CollectionUtils.isNotEmpty(productMatchResults)) {
|
|
|
+ product.setMatchResults(productMatchResults);
|
|
|
+ productDao.save(product);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 器件转化为ProductMatchResult list
|
|
|
+ * @param componentInfoList 器件list
|
|
|
+ * @param enUU 企业uu
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Set<ProductMatchResult> convertComponentToResult(List<ComponentInfo> componentInfoList, Long enUU) {
|
|
|
+ Set<ProductMatchResult> resultSet = new HashSet<>(componentInfoList.size());
|
|
|
+ for (ComponentInfo info : componentInfoList) {
|
|
|
+ ProductMatchResult result = convertOneInfoToResult(info, enUU);
|
|
|
+ resultSet.add(result);
|
|
|
+ }
|
|
|
+ return resultSet;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将单个器件转化为ProductMatchResult实体
|
|
|
+ * @param info 单个器件
|
|
|
+ * @param enUU 企业uu
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ProductMatchResult convertOneInfoToResult(ComponentInfo info, Long enUU) {
|
|
|
+ ProductMatchResult result = new ProductMatchResult();
|
|
|
+ result.setBrandCn(info.getBrand().getNameCn());
|
|
|
+ result.setBrandEn(info.getBrand().getNameEn());
|
|
|
+ result.setBrandId(info.getBrand().getId());
|
|
|
+ result.setpBrandUuid(info.getBrand().getUuid());
|
|
|
+ result.setCmpCode(info.getCode());
|
|
|
+ result.setCmpId(info.getId());
|
|
|
+ result.setKindId(info.getKind().getId());
|
|
|
+ result.setKindCn(info.getKind().getNameCn());
|
|
|
+ result.setKindEn(info.getKind().getNameEn());
|
|
|
+ result.setUuid(info.getUuid());
|
|
|
+ result.setCmpImg(info.getImg());
|
|
|
+ result.setEnUU(enUU);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 匹配成标准后更新product信息
|
|
|
+ * @param product 物料
|
|
|
+ * @param component 器件
|
|
|
+ */
|
|
|
+ private void updateProductByComponent(Product product, ComponentInfo component) {
|
|
|
+ product.setCmpUuid(component.getUuid());
|
|
|
+ product.setCmpImg(component.getImg());
|
|
|
+ product.setpCmpCode(component.getCode());
|
|
|
+ product.setpBrandId(component.getBrand().getId());
|
|
|
+ product.setpBrand(component.getBrand().getNameCn());
|
|
|
+ product.setpBrandEn(component.getBrand().getNameEn());
|
|
|
+ product.setpBrandUuid(component.getBrand().getUuid());
|
|
|
+ product.setKind(component.getKind().getNameCn());
|
|
|
+ product.setKindEn(component.getKind().getNameEn());
|
|
|
+ product.setKindId(component.getKindid());
|
|
|
+ product.setStandard(ProductConstant.STANDARD);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ModelMap assignPersonalProduct(Long userUU, Long productId) {
|
|
|
ModelMap map = new ModelMap();
|