|
|
@@ -21,10 +21,25 @@ import com.uas.ps.product.repository.ProductMatchResultDao;
|
|
|
import com.uas.ps.product.repository.ProductPrivateDao;
|
|
|
import com.uas.ps.product.repository.ProductReplaceDao;
|
|
|
import com.uas.ps.product.repository.ProductUsersDao;
|
|
|
+import com.uas.ps.product.repository.SyncMessageDao;
|
|
|
import com.uas.ps.product.service.ProductService;
|
|
|
import com.uas.ps.product.sync.WaitSyncHelper;
|
|
|
import com.uas.ps.properties.UrlProperties;
|
|
|
+import com.uas.ps.support.CodeType;
|
|
|
+import com.uas.ps.support.ResultMap;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.sql.PreparedStatement;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import javax.persistence.Column;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.log4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
|
|
@@ -34,15 +49,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.sql.PreparedStatement;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
/**
|
|
|
* @author sunyj
|
|
|
* @since 2018/1/6 17:19
|
|
|
@@ -77,6 +83,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private ProductReplaceDao productReplaceDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SyncMessageDao syncMessageDao;
|
|
|
+
|
|
|
/**
|
|
|
* B2C物料可用属性
|
|
|
*/
|
|
|
@@ -89,6 +98,14 @@ public class ProductServiceImpl implements ProductService {
|
|
|
|
|
|
private static final Logger log = Logger.getLogger(Logger.class);
|
|
|
|
|
|
+ private final String PRODUCT_TABLE_NAME = "products";
|
|
|
+
|
|
|
+ private final String METHOD_TYPE_INSERT = "insert";
|
|
|
+
|
|
|
+ private final Integer PRIORITY = 1;
|
|
|
+
|
|
|
+ private final String PR_ID = "{\"pr_id\": }";
|
|
|
+
|
|
|
/**
|
|
|
* 保存物料
|
|
|
*
|
|
|
@@ -114,9 +131,13 @@ public class ProductServiceImpl implements ProductService {
|
|
|
product.setSpec(productInfo.getSpec());
|
|
|
}
|
|
|
String newkind = productInfo.getKind();
|
|
|
- if ((product.getStandard() == Constant.NO) && !StringUtils.isEmpty(newkind)) {
|
|
|
- product.setKind(newkind);
|
|
|
- product.setTitle(newkind);
|
|
|
+ if (!StringUtils.isEmpty(newkind)) {
|
|
|
+ if (Constant.YES == product.getStandard()) {
|
|
|
+ product.setTitle(newkind);
|
|
|
+ } else {
|
|
|
+ product.setKind(newkind);
|
|
|
+ product.setTitle(newkind);
|
|
|
+ }
|
|
|
}
|
|
|
return productDao.save(product);
|
|
|
}
|
|
|
@@ -154,16 +175,11 @@ public class ProductServiceImpl implements ProductService {
|
|
|
products.add(prod.convert());
|
|
|
} else { // 物料库上已经存在的物料,修改
|
|
|
Product product = prod.convert();
|
|
|
- // 如果已存在物料类目不为空,erp上传的类目就不用覆盖
|
|
|
+ // 如果已存在物料类目不为空且为标准物料,erp上传的类目就不覆盖kind属性
|
|
|
Product existProduct = prodResult.get(0);
|
|
|
- if (!StringUtils.isEmpty(existProduct.getKind())) {
|
|
|
- product.setTitle(existProduct.getKind());
|
|
|
+ if (!StringUtils.isEmpty(existProduct.getKind()) && Constant.YES == existProduct.getStandard()) {
|
|
|
product.setKind(existProduct.getKind());
|
|
|
}
|
|
|
- // 如果已存在物料规格不为空,erp上传的规格就不用覆盖
|
|
|
- if (!StringUtils.isEmpty(existProduct.getSpec())) {
|
|
|
- product.setSpec(existProduct.getSpec());
|
|
|
- }
|
|
|
product.setId(existProduct.getId());
|
|
|
product.setCode(existProduct.getCode());
|
|
|
products.add(product);
|
|
|
@@ -184,16 +200,11 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return (prod.convert());
|
|
|
} else { // 物料库上已经存在的物料,修改
|
|
|
Product product = prod.convert();
|
|
|
- // 如果已存在物料类目不为空,erp上传的类目就不用覆盖
|
|
|
+ // 如果已存在物料类目不为空且为标准物料,erp上传的类目就不覆盖kind属性
|
|
|
Product existProduct = prodResult.get(0);
|
|
|
- if (!StringUtils.isEmpty(existProduct.getKind())) {
|
|
|
- product.setTitle(existProduct.getKind());
|
|
|
+ if (!StringUtils.isEmpty(existProduct.getKind()) && Constant.YES == existProduct.getStandard()) {
|
|
|
product.setKind(existProduct.getKind());
|
|
|
}
|
|
|
- // 如果已存在物料规格不为空,erp上传的规格就不用覆盖
|
|
|
- if (!StringUtils.isEmpty(existProduct.getSpec())) {
|
|
|
- product.setSpec(existProduct.getSpec());
|
|
|
- }
|
|
|
product.setId(prodResult.get(0).getId());
|
|
|
product.setCode(prodResult.get(0).getCode());
|
|
|
return product;
|
|
|
@@ -295,7 +306,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
public List<Product> updateB2bProdInfo(List<Product> productInfo) {
|
|
|
List<Product> saveList = new ArrayList<>();
|
|
|
for (Product product : productInfo) {
|
|
|
- List<Product> products = productDao.findByEnUUAndCode(product.getEnUU(),product.getCode());
|
|
|
+ List<Product> products = productDao.findByEnUUAndCode(product.getEnUU(), product.getCode());
|
|
|
if (!CollectionUtils.isEmpty(products) && null == product.getId()) {
|
|
|
Product existedProd = products.get(0);
|
|
|
existedProd.setTitle(product.getTitle());
|
|
|
@@ -303,9 +314,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (!StringUtils.isEmpty(product.getSpec())) {
|
|
|
existedProd.setSpec(product.getSpec());
|
|
|
}
|
|
|
- if (!StringUtils.isEmpty(product.getTitle())) {
|
|
|
+ // 如果物料已存在,新上传物料存在类目且原物料为非标,则更新kind属性
|
|
|
+ if (!StringUtils.isEmpty(product.getTitle()) && Constant.NO == existedProd.getStandard()) {
|
|
|
existedProd.setKind(product.getTitle());
|
|
|
- existedProd.setTitle(product.getTitle());
|
|
|
}
|
|
|
existedProd.setCmpCode(product.getCmpCode());
|
|
|
existedProd.setUnit(product.getUnit());
|
|
|
@@ -741,15 +752,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
newList.add(product);
|
|
|
} else {
|
|
|
Product existProduct = productDao.findOne(product.getId());
|
|
|
- // 如果物料已存在,且新上传物料存在类目、规格信息时,更新已存在物料字段
|
|
|
- if (product != null) {
|
|
|
- if (StringUtils.isEmpty(product.getTitle()) && !StringUtils.isEmpty(existProduct.getKind())) {
|
|
|
- product.setTitle(existProduct.getKind());
|
|
|
- product.setTitle(existProduct.getKind());
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(product.getSpec()) && !StringUtils.isEmpty(existProduct.getSpec())) {
|
|
|
- product.setSpec(existProduct.getSpec());
|
|
|
+ // 如果物料已存在并为标准物料时,kind属性不更新
|
|
|
+ if (existProduct != null) {
|
|
|
+ if (StringUtils.isEmpty(product.getTitle())) {
|
|
|
+ if (Constant.YES == existProduct.getStandard()) {
|
|
|
+ product.setKind(existProduct.getKind());
|
|
|
+ }
|
|
|
}
|
|
|
updateList.add(product);
|
|
|
ids.add(product.getId());
|
|
|
@@ -976,7 +984,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
product.setKind(component.getKind().getNameCn());
|
|
|
product.setKindEn(component.getKind().getNameEn());
|
|
|
product.setKindId(component.getKindid());
|
|
|
- product.setTitle(component.getKind().getNameCn());
|
|
|
product.setStandard(ProductConstant.STANDARD);
|
|
|
}
|
|
|
|
|
|
@@ -1099,4 +1106,85 @@ public class ProductServiceImpl implements ProductService {
|
|
|
productUsersDao.delete(deleteList);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap reuploadProduct(List<Map<String, Object>> miss) {
|
|
|
+ if (!CollectionUtils.isEmpty(miss)) {
|
|
|
+ List<Long> productIds = new ArrayList<>();
|
|
|
+ for (Map<String, Object> missProduct : miss) {
|
|
|
+ try {
|
|
|
+ List<Product> products = productDao.findByEnUUAndCode(Long.valueOf(missProduct.get("enuu").toString()), missProduct.get("code").toString());
|
|
|
+ if (CollectionUtils.isNotEmpty(products)) {
|
|
|
+ for (Product product : products) {
|
|
|
+ Map<String, Object> dataMap = convertToInsertProduct(product);
|
|
|
+ try {
|
|
|
+ syncMessageDao.callSyncEnqueneMessage(dataMap.get("tableName").toString(), dataMap.get("methodType").toString(), dataMap.get("dataKey").toString(), dataMap.get("data").toString(), Integer.valueOf(dataMap.get("priority").toString()));
|
|
|
+ productIds.add(product.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultMap.success(productIds);
|
|
|
+ }
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "无有效信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回需要拼装的数据
|
|
|
+ * @param product 物料信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, Object> convertToInsertProduct(Product product) {
|
|
|
+ Map<String, Object> map = new HashedMap();
|
|
|
+ map.put("tableName", PRODUCT_TABLE_NAME);
|
|
|
+ map.put("methodType", METHOD_TYPE_INSERT);
|
|
|
+ map.put("priority", PRIORITY);
|
|
|
+
|
|
|
+ // 配置dataKey
|
|
|
+ StringBuffer sb = new StringBuffer(PR_ID);
|
|
|
+ sb.insert(9, product.getId());
|
|
|
+ map.put("dataKey", sb.toString());
|
|
|
+
|
|
|
+ // 配置data
|
|
|
+ product.setMatchResults(null);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String json = JSON.toJSONString(product);
|
|
|
+
|
|
|
+ Field [] fields = product.getClass().getDeclaredFields();
|
|
|
+ for (Field field : fields) {
|
|
|
+ Column column = field.getAnnotation(Column.class);
|
|
|
+ if (column != null && !StringUtils.isEmpty(column.name())) {
|
|
|
+ json = json.replace(field.getName(), column.name());
|
|
|
+ // 处理date类型数据
|
|
|
+ if (field.getType().equals(Date.class) && json.indexOf(column.name()) > -1) {
|
|
|
+ String value = json.substring(json.indexOf(column.name()) + column.name().length(), ordinalIndexOf(json, "\"", json.indexOf(column.name()), 2));
|
|
|
+ json = json.replace(value, "\":\"" + sdf.format(Long.valueOf(value.replaceAll("\"", "").replace(":","").replace(",", ""))) + "\",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("data", json);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取字符串在源字符串第几次出现的位置
|
|
|
+ * @param str 源字符串
|
|
|
+ * @param substr 判断字符串
|
|
|
+ * @param start 起始位置
|
|
|
+ * @param n 第几次出现
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public int ordinalIndexOf(String str, String substr, int start, int n) {
|
|
|
+ int pos = str.indexOf(substr, start);
|
|
|
+ while (--n > 0 && pos != -1)
|
|
|
+ pos = str.indexOf(substr, pos + 1);
|
|
|
+ return pos;
|
|
|
+ }
|
|
|
}
|