|
|
@@ -2,9 +2,11 @@ package com.uas.ps.product.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
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.ProductUsers;
|
|
|
import com.uas.ps.entity.Status;
|
|
|
+import com.uas.ps.kind.entity.KindInfo;
|
|
|
import com.uas.ps.product.ProductConstant;
|
|
|
import com.uas.ps.product.entity.Constant;
|
|
|
import com.uas.ps.product.entity.Prod;
|
|
|
@@ -92,77 +94,73 @@ 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);
|
|
|
-// }
|
|
|
+ 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 product
|
|
|
+ * @param enUU
|
|
|
*/
|
|
|
- private void matchOne(Product product) {
|
|
|
+ private int matchOne(Product product, Long enUU) {
|
|
|
+ BrandInfo brand;
|
|
|
+ ComponentInfo component;
|
|
|
+ List<Product> standardList;
|
|
|
// 获取品牌
|
|
|
- String brandUrl = "";
|
|
|
- BrandInfo result = restTemplate.getForEntity(brandUrl, BrandInfo.class).getBody();
|
|
|
- if (result.getUuid() != null) {
|
|
|
- String componentUrl = "";
|
|
|
- JSONObject component = restTemplate.getForEntity(componentUrl, JSONObject.class).getBody();
|
|
|
+ String brandUrl = "http://10.1.51.89:8080/platform-b2c/api/product/brand/byName/brand?name=" + product.getpBrandEn();
|
|
|
+ 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();
|
|
|
+ component = restTemplate.getForEntity(componentUrl, ComponentInfo.class).getBody();
|
|
|
if (component != null) {
|
|
|
// 更新物料信息
|
|
|
- updateProductByComponent(product, result, component);
|
|
|
+ updateProductByComponent(product, brand, component);
|
|
|
+ standardList = productDao.findProductByPcmpcodeAndPbrandenAndEnUU(product.getpCmpCode(), product.getpBrand(), enUU);
|
|
|
+ if (!CollectionUtils.isEmpty(standardList)) {
|
|
|
+ // TODO 已有标准产品,该如何处理
|
|
|
+ }
|
|
|
+ productDao.save(product);
|
|
|
+ return 1;
|
|
|
}
|
|
|
}
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
- private void updateProductByComponent(Product product, BrandInfo brandInfo, JSONObject component) {
|
|
|
- product.setCmpUuid(component.getString("uuid"));
|
|
|
+ private void updateProductByComponent(Product product, BrandInfo brandInfo, ComponentInfo component) {
|
|
|
+ product.setCmpUuid(component.getUuid());
|
|
|
+ product.setCmpImg(component.getImg());
|
|
|
+ product.setpCmpCode(component.getCode());
|
|
|
product.setpBrandId(brandInfo.getId());
|
|
|
product.setpBrand(brandInfo.getNameCn());
|
|
|
product.setpBrandEn(brandInfo.getNameEn());
|
|
|
product.setpBrandUuid(brandInfo.getUuid());
|
|
|
- product.setCmpImg(component.getString("img"));
|
|
|
- product.setKind("");
|
|
|
- product.setKindEn("");
|
|
|
- product.setKindId(2L);
|
|
|
- product.setpCmpCode("");
|
|
|
+ product.setKind(component.getKind().getNameCn());
|
|
|
+ product.setKindEn(component.getKind().getNameEn());
|
|
|
+ product.setKindId(component.getKindid());
|
|
|
product.setStandard(ProductConstant.STANDARD);
|
|
|
}
|
|
|
|