|
|
@@ -24,6 +24,7 @@ import com.uas.ps.support.ResultMap;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.log4j.Logger;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
@@ -1209,8 +1210,62 @@ public class ProductServiceImpl implements ProductService {
|
|
|
*/
|
|
|
public int ordinalIndexOf(String str, String substr, int start, int n) {
|
|
|
int pos = str.indexOf(substr, start);
|
|
|
- while (--n > 0 && pos != -1)
|
|
|
+ while (--n > 0 && pos != -1) {
|
|
|
pos = str.indexOf(substr, pos + 1);
|
|
|
+ }
|
|
|
return pos;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量校验导入物料信息
|
|
|
+ *
|
|
|
+ * @param products 物料
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> checkImportProductList(List<ProductInfo> products) {
|
|
|
+ int success = 0;
|
|
|
+ for (ProductInfo productInfo : products) {
|
|
|
+ if (null != productInfo.getCode()) {
|
|
|
+ List<Long> idList = productDao.findIdByEnUUAndCode(productInfo.getEnUU(), productInfo.getCode());
|
|
|
+ if (!CollectionUtils.isEmpty(idList)) {
|
|
|
+ productInfo.setId(idList.get(0));
|
|
|
+ success++;
|
|
|
+ } else {
|
|
|
+ List<Product> productList = new ArrayList<>();
|
|
|
+ Product product = new Product();
|
|
|
+ BeanUtils.copyProperties(productInfo, product, Product.class);
|
|
|
+ productList.add(product);
|
|
|
+ productList = updateB2bProdInfo(productList);
|
|
|
+ productInfo.setId(productList.get(0).getId());
|
|
|
+ success++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ PageInfo pageInfo = new PageInfo(1, 1);
|
|
|
+ List<Object[]> objects = productDao.findIdAndCodeByEnUUAndTitle(productInfo.getEnUU(), productInfo.getTitle(), pageInfo);
|
|
|
+ if (!CollectionUtils.isEmpty(objects)) {
|
|
|
+ Object[] object = objects.get(0);
|
|
|
+ productInfo.setId(Long.valueOf(object[0].toString()));
|
|
|
+ productInfo.setCode(object[1].toString());
|
|
|
+ success++;
|
|
|
+ } else {
|
|
|
+ //生成随机编码
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yymmddhhmm_sss");
|
|
|
+ productInfo.setCode("prod" + sdf.format(new Date()));
|
|
|
+ List<Product> productList = new ArrayList<>();
|
|
|
+ Product product = new Product();
|
|
|
+ BeanUtils.copyProperties(productInfo, product, Product.class);
|
|
|
+ productList.add(product);
|
|
|
+ productList = updateB2bProdInfo(productList);
|
|
|
+ productInfo.setCode(productList.get(0).getCode());
|
|
|
+ productInfo.setId(productList.get(0).getId());
|
|
|
+ success++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashedMap();
|
|
|
+ map.put("products", products);
|
|
|
+ map.put("success", success);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|