Просмотр исходного кода

增加点击确认上架的响应速度。
个人库上传产品规格字段可以不必填写

yujia 7 лет назад
Родитель
Сommit
8e8925ef14

+ 6 - 2
src/main/java/com/uas/platform/b2c/external/erp/prod/service/impl/ProdServiceImpl.java

@@ -15,6 +15,7 @@ import com.uas.platform.b2c.prod.commodity.dao.ProductPrivateDao;
 import com.uas.platform.b2c.prod.commodity.dao.V_ProductPrivateDao;
 import com.uas.platform.b2c.prod.commodity.model.Product;
 import com.uas.platform.b2c.prod.commodity.model.ProductPrivate;
+import com.uas.platform.b2c.prod.commodity.service.ProductPrivateService;
 import com.uas.platform.b2c.prod.commodity.service.ProductService;
 import com.uas.platform.b2c.prod.commodity.service.ReleaseProductByBatchService;
 import com.uas.platform.b2c.prod.store.dao.StoreInDao;
@@ -69,6 +70,9 @@ public class ProdServiceImpl implements ProdService {
     @Autowired
     private CommonDao commonDao;
 
+    @Autowired
+    private ProductPrivateService productPrivateService;
+
     @Autowired
     private ReleaseProductByBatchService releaseProductByBatchService;
 
@@ -113,7 +117,7 @@ public class ProdServiceImpl implements ProdService {
                     products.add(product);
                 }
             }
-            ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(prod.getPr_id());
+            ProductPrivate productPrivate = productPrivateService.findByPrId(prod.getPr_id());
             if (null == productPrivate) {
                 productPrivate = new ProductPrivate();
                 productPrivate.setPrId(prod.getPr_id());
@@ -185,7 +189,7 @@ public class ProdServiceImpl implements ProdService {
         List<Product> productList = productDao.getProductByEnUUAndProdNum(SystemSession.getUser().getEnterprise().getUu(),pr_code);
         if (!CollectionUtils.isEmpty(productList)) {
             for (Product product : productList) {
-                ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
+                ProductPrivate productPrivate = productPrivateService.findByPrId(product.getId());
                 if (null == productPrivate) {
                     productPrivate = new ProductPrivate();
                     productPrivate.setPrId(product.getId());

+ 1 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ReleaseProductByBatchDao.java

@@ -98,7 +98,7 @@ public interface ReleaseProductByBatchDao
 	 * @param isPersonal 是否是个人
 	 * @param enuu 公司enuu
 	 */
-	@Procedure(procedureName = "PRODUCT_RELEASE_EXIST_VALID_V2")
+	@Procedure(procedureName = "PRODUCT_RELEASE_EXIST_VALID_V3")
 	void callReleaseExistValidProcedure(String batch, Boolean isPersonal, Long enuu);
 
 	/**

+ 23 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/Product.java

@@ -1,6 +1,7 @@
 package com.uas.platform.b2c.prod.commodity.model;
 
 import com.uas.platform.b2c.common.account.model.Enterprise;
+import com.uas.platform.b2c.core.support.SystemSession;
 import com.uas.platform.core.persistence.EnterpriseUU;
 import com.uas.platform.core.persistence.Logger;
 import com.uas.platform.core.persistence.UserUU;
@@ -997,4 +998,26 @@ public class Product {
 		this.erpDown = erpDown;
 		return this;
 	}
+
+	public void setReleaseByBatch(ReleaseProductByBatch releaseProductByBatch) {
+		this.minPackQty = releaseProductByBatch.getMinPackage();
+		this.cmpImg = releaseProductByBatch.getImg();
+		this.enUU = SystemSession.getUser().getEnterprise().getUu();
+		this.brand = releaseProductByBatch.getBrandNameEn();
+		this.cmpCode = releaseProductByBatch.getCode();
+		this.cmpUuId = releaseProductByBatch.getComponentUuId();
+		this.kind = releaseProductByBatch.getKindName();
+		this.kindid = releaseProductByBatch.getKindUuid();
+		this.pcmpcode = releaseProductByBatch.getB2cCode();
+		this.pbrand = releaseProductByBatch.getB2cBrandcn();
+		this.pbranden = releaseProductByBatch.getB2cBranden();
+		this.pbrandid = releaseProductByBatch.getBrandId();
+		this.pbranduuid = releaseProductByBatch.getBranduuid();
+		this.standard = (releaseProductByBatch.getComponentUuId() == null ? 0 : 1);
+		this.createTime = new Date(System.currentTimeMillis());
+		this.spec = releaseProductByBatch.getSpec();
+		this.prodName = releaseProductByBatch.getKindName();
+		// 产品导入默认可销售
+		this.isSale = ((short) 1);
+	}
 }

+ 18 - 2
src/main/java/com/uas/platform/b2c/prod/commodity/model/ReleaseProductByBatch.java

@@ -548,6 +548,12 @@ public class ReleaseProductByBatch implements Serializable {
 	@Column(name = "rel_productid")
 	private Long productid;
 
+	/**
+	 * 物料id信息
+	 */
+	@Column(name = "rel_pronum", length = 100)
+	private String productNum;
+
 	/**
 	 * 规格书信息
 	 */
@@ -719,9 +725,10 @@ public class ReleaseProductByBatch implements Serializable {
 		} else {
 			if (!isAPerson) {
 				addErrmsg(ErrorInfoConstant.PACKAGE_EMPTY_INFO.getInfo());
-			} else {
-				addErrmsg(ErrorInfoConstant.PERSON_PACKAGE_EMPTY_INFO.getInfo());
 			}
+//			else {
+//				addErrmsg(ErrorInfoConstant.PERSON_PACKAGE_EMPTY_INFO.getInfo());
+//			}
 		}
 		String packagingData = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(value));
 		if (isAPerson) {
@@ -1839,6 +1846,15 @@ public class ReleaseProductByBatch implements Serializable {
 		return this;
 	}
 
+	public String getProductNum() {
+		return productNum;
+	}
+
+	public ReleaseProductByBatch setProductNum(String productNum) {
+		this.productNum = productNum;
+		return this;
+	}
+
 	@Override
 	public String toString() {
 		return "ReleaseProductByBatch{" +

+ 2 - 2
src/main/java/com/uas/platform/b2c/prod/commodity/service/GoodsService.java

@@ -744,10 +744,10 @@ public interface GoodsService {
     /**
      * 更新货物的有效期
      *
-     * @param privateList the operate type 操作的记录
+     * @param products the operate type 操作的记录
      * @param goodses       the param
      */
-    void updateSpecByProducts(List<V_ProductPrivate> privateList, List<Goods> goodses);
+    void updateSpecByProducts(List<Product> products, List<Goods> goodses);
 
     /**
      * 获取pcb推荐物料

+ 7 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductPrivateService.java

@@ -33,4 +33,11 @@ public interface ProductPrivateService {
      * @return  List<ProductPrivate>
      */
     List<ProductPrivate> saveProductPrivate(List<ProductPrivate> productPrivates);
+
+    /**
+     * 根据给定的物料主键,创建私有信息
+     * @param prIds 物料主键
+     * @return
+     */
+    List<ProductPrivate> newProductPrivateIfNotExist(List<Long> prIds);
 }

+ 7 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductService.java

@@ -232,6 +232,13 @@ public interface ProductService {
      */
     ProductDetail findByProductId(Long id);
 
+    /**
+     * 批量获物料信息
+     * @param ids
+     * @return
+     */
+    List<Product> findByProductId(List<Long> ids);
+
     /**
      * 验证物料申请是否为标准物料
      * @return

+ 11 - 13
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java

@@ -83,14 +83,13 @@ import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataAccessException;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.ResultSetExtractor;
+import org.springframework.jdbc.core.RowCallbackHandler;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -4140,18 +4139,18 @@ public class GoodsServiceImpl implements GoodsService {
     /**
      * 更新货物的有效期
      *
-     * @param privateList the operate type 操作的记录
+     * @param products the operate type 操作的记录
      * @param goodses     the param
      */
     @Override
-    public void updateSpecByProducts(List<V_ProductPrivate> privateList, List<Goods> goodses) {
+    public void updateSpecByProducts(List<Product> products, List<Goods> goodses) {
         List<Goods> goods = new ArrayList<>();
         List<GoodsHistory> goodsHistories = new ArrayList<>();
-        if (CollectionUtils.isNotEmpty(privateList) && CollectionUtils.isNotEmpty(goodses)) {
-            for (V_ProductPrivate v_productPrivate : privateList) {
+        if (CollectionUtils.isNotEmpty(products) && CollectionUtils.isNotEmpty(goodses)) {
+            for (Product product : products) {
                 for (Goods goodse : goodses) {
-                    if (goodse.getProductid() != null && (goodse.getProductid().longValue() ==  v_productPrivate.getId().longValue()) && (!StringUtils.isEmpty(v_productPrivate.getSpec())) && (!v_productPrivate.getSpec().equals(goodse.getSpec()))) {
-                        goodse.setSpec(v_productPrivate.getSpec());
+                    if (goodse.getProductid() != null && (goodse.getProductid().longValue() ==  product.getId().longValue()) && (!StringUtils.isEmpty(product.getSpec())) && (!product.getSpec().equals(goodse.getSpec()))) {
+                        goodse.setSpec(product.getSpec());
                         goods.add(goodse);
                         GoodsHistory history = goodsHistoryService.converTGoodsHist(goodse, OperateType.Update.getPhrase(), false);
                         goodsHistories.add(history);
@@ -4294,17 +4293,16 @@ public class GoodsServiceImpl implements GoodsService {
             String sql = "select go_productid, count(go_id) num from trade$goods where go_productid in (:prids) group by go_productid";
             Map<String,Object> parameters = new HashMap<String,Object>();
             parameters.put("prids", prIds);
-            Map<Long, Integer> map = namedParameterJdbcTemplate.query(sql, parameters, new ResultSetExtractor<Map<Long, Integer>>() {
+            final Map<Long, Integer> resultMap = new HashedMap();
+            namedParameterJdbcTemplate.query(sql, parameters, new RowCallbackHandler() {
                 @Override
-                public Map<Long, Integer> extractData(ResultSet rs) throws SQLException, DataAccessException {
-                    Map<Long, Integer> resultMap = new HashedMap();
+                public void processRow(ResultSet rs) throws SQLException {
                     long productid = rs.getLong("go_productid");
                     int num = rs.getInt("num");
                     resultMap.put(productid, num);
-                    return resultMap;
                 }
             });
-            return map;
+            return resultMap;
         }
     }
 }

+ 54 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductPrivateServiceImpl.java

@@ -1,14 +1,18 @@
 package com.uas.platform.b2c.prod.commodity.service.impl;
 
+import com.uas.platform.b2c.core.constant.IntegerConstant;
 import com.uas.platform.b2c.prod.commodity.dao.ProductPrivateDao;
 import com.uas.platform.b2c.prod.commodity.model.ProductPrivate;
+import com.uas.platform.b2c.prod.commodity.service.GoodsService;
 import com.uas.platform.b2c.prod.commodity.service.ProductPrivateService;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 商城私有字段的服务层
@@ -20,9 +24,12 @@ public class ProductPrivateServiceImpl implements ProductPrivateService {
 
     private final ProductPrivateDao productPrivateDao;
 
+    private final GoodsService goodsService;
+
     @Autowired
-    public ProductPrivateServiceImpl(ProductPrivateDao productPrivateDao) {
+    public ProductPrivateServiceImpl(ProductPrivateDao productPrivateDao, GoodsService goodsService) {
         this.productPrivateDao = productPrivateDao;
+        this.goodsService = goodsService;
     }
 
 
@@ -66,4 +73,50 @@ public class ProductPrivateServiceImpl implements ProductPrivateService {
         }
         return Collections.emptyList();
     }
+
+    /**
+     * 根据给定的物料主键,创建私有信息
+     *
+     * @param prIds 物料主键
+     * @return
+     */
+    @Override
+    public List<ProductPrivate> newProductPrivateIfNotExist(List<Long> prIds) {
+        List<ProductPrivate> productPrivates = new ArrayList<ProductPrivate>();
+        List<ProductPrivate> privateList = findByPrIds(prIds);
+        Boolean isExist = false;
+        ProductPrivate productPrivate = null;
+        int batchCount = 0;
+        Map<Long, Integer> goodsCountByProductId = goodsService.batchGetCountByProductId(prIds);
+        for (Long productId : prIds) {
+            isExist = false;
+            batchCount = 0;
+            if ((goodsCountByProductId != null) && (goodsCountByProductId.size() != 0)) {
+                batchCount = goodsCountByProductId.get(productId);
+            }
+            for (ProductPrivate productPri : privateList) {
+                if (productPri.getPrId().longValue() == productId.longValue()) {
+                    isExist = true;
+                    if ((productPri.getB2cEnabled() == null) || (productPri.getB2cEnabled().intValue() != IntegerConstant.YES_SHORT.intValue()) || (productPri.getBatchCount() == null) || (productPri.getBatchCount().intValue() != batchCount)) {
+                        productPri.setB2cEnabled(IntegerConstant.YES_SHORT);
+                        productPri.setBatchCount(batchCount);
+                        productPrivates.add(productPri);
+                    }
+                }
+            }
+            if (!isExist) {
+                productPrivate = new ProductPrivate();
+                productPrivate.setPrId(productId);
+                productPrivate.setBatchCount(batchCount);
+                productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
+                productPrivates.add(productPrivate);
+            }
+        }
+        if (CollectionUtils.isNotEmpty(productPrivates)) {
+            List<ProductPrivate> productPrivates1 = saveProductPrivate(productPrivates);
+            return productPrivates1;
+        } else {
+            return Collections.emptyList();
+        }
+    }
 }

+ 15 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java

@@ -1500,6 +1500,21 @@ public class ProductServiceImpl implements ProductService {
         return productDetail;
     }
 
+    /**
+     * 批量获物料信息
+     *
+     * @param ids
+     * @return
+     */
+    @Override
+    public List<Product> findByProductId(List<Long> ids) {
+        if (CollectionUtils.isNotEmpty(ids)) {
+            return productDao.findAll(ids);
+        } else {
+            return Collections.emptyList();
+        }
+    }
+
     @Override
     public ResultMap validitonStandard(JSONObject jsonObject) {
         Component component = (Component)jsonObject.get("component");

+ 91 - 110
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ReleaseProductByBatchServiceImpl.java

@@ -1,6 +1,5 @@
 package com.uas.platform.b2c.prod.commodity.service.impl;
 
-import com.alibaba.fastjson.JSON;
 import com.uas.platform.b2c.common.account.model.Enterprise;
 import com.uas.platform.b2c.common.base.dao.CommonDao;
 import com.uas.platform.b2c.core.config.SysConf;
@@ -17,6 +16,7 @@ import com.uas.platform.b2c.prod.commodity.dao.*;
 import com.uas.platform.b2c.prod.commodity.model.*;
 import com.uas.platform.b2c.prod.commodity.service.GoodsService;
 import com.uas.platform.b2c.prod.commodity.service.ProductPrivateService;
+import com.uas.platform.b2c.prod.commodity.service.ProductService;
 import com.uas.platform.b2c.prod.commodity.service.ReleaseProductByBatchService;
 import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
 import com.uas.platform.b2c.prod.commodity.util.SheetUtil;
@@ -46,8 +46,11 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 import org.apache.poi.ss.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.dao.DataAccessException;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.StatementCallback;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.ModelMap;
@@ -59,6 +62,9 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import java.math.BigDecimal;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -123,6 +129,9 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	@Autowired
 	private V_ProductPrivateDao v_productPrivateDao;
 
+	@Autowired
+	private  ProductService productService;
+
 	/**
 	 * 控制任务提交速度的线程池
 	 */
@@ -143,6 +152,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	@Value("#{sys.productServiceIp}")
 	private String productServiceIp;
 
+    @Autowired
 	public ReleaseProductByBatchServiceImpl(NamedParameterJdbcTemplate namedJdbcTemplate, ProductPrivateService productPrivateService) {
 		this.namedJdbcTemplate = namedJdbcTemplate;
 		this.productPrivateService = productPrivateService;
@@ -241,13 +251,12 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		System.out.println("获取订单信息缺失");
 		long l1 = System.currentTimeMillis();
 		System.err.println("l1--------------l testyuj" + (l1 - l));
-		Long userUU = SystemSession.getUser().getUserUU();
 		Long enUU = SystemSession.getUser().getEnterprise().getUu();
 		if (!isAPerson) {
 			//1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
 			for(int i = releaseProductByBatchs.size() - 1; i > -1; i--) {
 				ReleaseProductByBatch releaseProductByBatch = releaseProductByBatchs.get(i);
-				for(int j = i - 1; j > 0; j--) {
+				for(int j = i - 1; j > -1; j--) {
 					ReleaseProductByBatch byBatch = releaseProductByBatchs.get(j);
 					if(releaseProductByBatch.compareSameProductTagInfo(byBatch)) {
 						releaseProductByBatch.setTag("");
@@ -256,17 +265,24 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 							releaseProductByBatch.addErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
 							releaseProductByBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
 							releaseProductByBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+                            if (!StringUtilB2C.isEmpty(releaseProductByBatch.getErrmsg())) {
+                                if (releaseProductByBatch.getErrmsg().substring(0, 1).equals(",")) {
+                                    releaseProductByBatch.setErrmsg(releaseProductByBatch.getErrmsg().substring(1));
+                                }
+                            }
 						}
 					}
 				}
 			}
 		}
+        long l2 = System.currentTimeMillis();
+        System.err.println("l2--------------l1 testyuj" + (l2 - l1));
 		commonDao.save(releaseProductByBatchs, ReleaseProductByBatch.class);
-		long l2 = System.currentTimeMillis();
-		System.err.println("l2--------------l1 testyuj" + (l2 - l1));
-        releaseProductByBatchDao.callReleaseExistValidProcedure(batch, isAPerson, enUU);
 		long l3 = System.currentTimeMillis();
-		System.err.println("l3--------------l2 testyuj" + (l3 - l2));
+        System.err.println("l3--------------l2 testyuj" + (l3 - l2));
+        releaseProductByBatchDao.callReleaseExistValidProcedure(batch, isAPerson, enUU);
+		long l4 = System.currentTimeMillis();
+		System.err.println("l4--------------l3 testyuj" + (l4 - l3));
 		if (isAPerson) {
 			for (ReleaseProductByBatch releaseProductByBatch : releaseProductByBatchs) {
                 Long productid = releaseProductByBatch.getProductid();
@@ -281,13 +297,11 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
                 }
 			}
 		}
-		Long l4 = 0l;
+		Long l5 = 0l;
 		String strCount = "";
 		if (isPcb) {
 			strCount = releaseProductByBatchDao.callValidProcedurePcb(enUU, batch);
 		} else {
-			// final Object[] obj = new Object[]{enUU, batch};
-//			final Object[] obj = new Object[]{enUU, batch};
 			final Object[] obj = new Object[]{enUU, batch};
 			String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @batch = '%s'; call PRODUCT_RELEASE_VALID_V5(@enuu, @batch, @out); select @out";
 			final String updateSql = String.format(sql, obj);
@@ -305,15 +319,23 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 					return "0";
 				}
 			});
-			l4 = System.currentTimeMillis();
-			System.err.println("l4--------------l3 testyuj" + (l4 - l3));
+			l5 = System.currentTimeMillis();
+			System.err.println("l5--------------l4 testyuj" + (l5 - l4));
 		}
 		Integer filter = 0, failure = 0, success = 0;
 		if (!StringUtilB2C.isEmpty(strCount)) {
 			String[] split = strCount.split(SplitChar.HYPHEN);
-			filter = Integer.valueOf(split[0]);
-			failure = Integer.valueOf(split[1]);
-			success = Integer.valueOf(split[2]);
+            if (split.length == 3) {
+                filter = Integer.valueOf(split[0]);
+                failure = Integer.valueOf(split[1]);
+                success = Integer.valueOf(split[2]);
+            } else {
+                //便于测试上执行
+                Long userUU = SystemSession.getUser().getUserUU();
+                filter = releaseProductByBatchDao.getCountOfImportFail(userUU, batch, failCode);
+                failure = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.failure.value());
+                success = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.success.value());
+            }
 		}
 
 		modelMap.put("total", total);
@@ -1692,22 +1714,14 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		Map<String, Object> map = convertProduct(releaseProductByBatchList, false, isPcb);
 		long l2 = System.currentTimeMillis();
 		System.err.println("l2 -------------------l1 " + (l2 - l1));
-		List<com.uas.ps.entity.Product> products = (List<com.uas.ps.entity.Product>) map.get("products");
-		// TODO 什么接口
-		String result = restTemplate.postForEntity(productServiceIp + "/product/update", products, String.class).getBody();
-		long l3 = System.currentTimeMillis();
-		System.err.println("l3 -------------------l2 " + (l3 - l2));
-		List<Long> productIds = JSON.parseArray(result, Long.class);
-		Set<Long> idSet = new HashSet<>(productIds);
+		Set<Long> idSet = (Set<Long>) map.get("prIds");
 		if (isPcb) {
 			savePcbInfo(idSet, map);
 		}
 		long l8 = System.currentTimeMillis();
 		Enterprise enterprise = SystemSession.getUser().getEnterprise();
-        long l8 = System.currentTimeMillis();
-        Enterprise enterprise = SystemSession.getUser().getEnterprise();
         final Object[] obj = new Object[]{enterprise.getUu(), enterprise.getEnName(), batch};
-        String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @enName = '%s'; set @batch = '%s'; call RELEASE_TO_GOODS_V3(@enuu, @enName, @batch, @out); select @out";
+        String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @enName = '%s'; set @batch = '%s'; call RELEASE_TO_GOODS_V4(@enuu, @enName, @batch, @out); select @out";
         final String updateSql = String.format(sql, obj);
         String num = jdbcTemplate.execute(new StatementCallback<String>() {
 
@@ -1724,7 +1738,9 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
         });
 		long l9 = System.currentTimeMillis();
 		System.err.println("l9 -------------------l8 " + (l9 - l8));
-		afterPublishToGoodsDo(productIds);
+		ArrayList<Long> list = new ArrayList<>();
+		list.addAll((Set<Long>)map.get("prIds"));
+		afterPublishToGoodsDo(list, (Set<Long>)map.get("reIds"));
 		return StringUtilB2C.getStr(num);
 	}
 
@@ -1775,7 +1791,9 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			return null;
 		}
 		Map<String, Object> map = new HashedMap();
-		List<com.uas.ps.entity.Product> products = new ArrayList<>();
+		List<Product> products = new ArrayList<>();
+		Set<Long> prIds = new HashSet<>();
+		Set<Long> reIds = new HashSet<>();
 		Map<String, List<PCBPropertyValue>> propertyMap = new HashedMap();
 
 		Long sizeProId = null;
@@ -1794,34 +1812,24 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		}
 		String time = importNum.substring(IntegerConstant.NO_SHORT, (IntegerConstant.TIME_LENGTH - 1));
 		Integer num = Integer.valueOf(importNum.substring(IntegerConstant.TIME_LENGTH));
-		String batchCode = null;
+		String prodNum = null;
 		for (ReleaseProductByBatch releaseProductByBatch : releaseProductByBatchList) {
 		    if (releaseProductByBatch.getReleaseCode().equals(ReleaseStatus.failure.value()) ||
                     releaseProductByBatch.getReleaseCode().equals(ReleaseStatus.success.value())) {
-                com.uas.ps.entity.Product product = new com.uas.ps.entity.Product();
-                // releaseProductByBatch.getCode(); 在公有库生成
-                product.setMinPack(releaseProductByBatch.getMinPackage());
-                product.setCmpImg(releaseProductByBatch.getImg());
-                product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
-                product.setBrand(releaseProductByBatch.getBrandNameEn());
-                product.setCmpCode(releaseProductByBatch.getCode());
-                product.setCmpUuid(releaseProductByBatch.getComponentUuId());
-                product.setKind(releaseProductByBatch.getKindName());
-                product.setKindId(releaseProductByBatch.getKindUuid());
-                product.setpCmpCode(releaseProductByBatch.getB2cCode());
-                product.setpBrand(releaseProductByBatch.getB2cBrandcn());
-                product.setpBrandEn(releaseProductByBatch.getB2cBranden());
-                product.setpBrandId(releaseProductByBatch.getBrandId());
-                product.setpBrandUuid(releaseProductByBatch.getBranduuid());
-                product.setStandard(releaseProductByBatch.getComponentUuId() == null ? (short)0 : (short)1);
-                product.setCmpUuid(releaseProductByBatch.getComponentUuId());
-                product.setCreateTime(new Date(System.currentTimeMillis()));
-				product.setSpec(releaseProductByBatch.getSpec());
-                // 产品导入默认可销售
-                product.setIsSale((short) 1);
-
-                batchCode = "PNUM" + time + CreateNumberServiceImpl.formatIntToStr(num++, 8);
-                product.setCode(batchCode);
+				if (releaseProductByBatch.getProductid() == null) {
+					Product product = new Product();
+					product.setReleaseByBatch(releaseProductByBatch);
+					// releaseProductByBatch.getCode(); 在公有库生成
+					prodNum = "PNUM" + time + CreateNumberServiceImpl.formatIntToStr(num++, 8);
+					product.setProdNum(prodNum);
+					products.add(product);
+				} else {
+					//对于已经存在于物料库的信息,如果规格信息已存在,则做更新,如果是
+					prIds.add(releaseProductByBatch.getProductid());
+					if (!StringUtilB2C.isEmpty(releaseProductByBatch.getSpec())) {
+						reIds.add(releaseProductByBatch.getId());
+					}
+				}
 
 				if (isPcb) {
 					List<PCBPropertyValue> propertyValues = new ArrayList<>();
@@ -1842,14 +1850,21 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 						propertyValues.add(propertyValue);
 					}
 					if (CollectionUtils.isNotEmpty(propertyValues)) {
-						propertyMap.put(product.getEnUU().toString().concat(product.getCode()), propertyValues);
+						propertyMap.put(SystemSession.getUser().getEnterprise().getUu().toString().concat(prodNum), propertyValues);
 					}
 				}
-                products.add(product);
+
             }
 		}
 
-		map.put("products", products);
+		List<Product> products1 = productDao.save(products);
+		for (Product product : products1) {
+			prIds.add(product.getId());
+		}
+		if (reIds.size() < 1) {
+			map.put("reIds", prIds);
+		}
+		map.put("prIds", prIds);
 		map.put("propertyvalues", propertyMap);
 		return map;
 	}
@@ -1860,30 +1875,15 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
                 releaseProductByBatchDao.findByRelbatchid(batch);
         if (!CollectionUtils.isEmpty(releaseProductByBatchList)) {
 			Map<String, Object> map = convertProduct(releaseProductByBatchList,false, false);
-			List<com.uas.ps.entity.Product> products = (List<com.uas.ps.entity.Product>) map.get("products");
-            // TODO 什么接口
-			String result = restTemplate.postForEntity(productServiceIp + "/product/update", products, String.class).getBody();
-            List<Long> productIds = JSON.parseArray(result, Long.class);
+			Set<Long> prIds = (Set<Long>) map.get("prIds");
+            List<Long> productIds = new ArrayList<>();
+			productIds.addAll(prIds);
             //添加个人关系
             String res  = restTemplate.postForEntity(productServiceIp + "/product/assign/batch?userUU=" + SystemSession.getUser().getUserUU(), productIds, String.class).getBody();
             // 默认为b2c Enable开启
-            List<ProductPrivate> productPrivates = new ArrayList<>();
-			Set<Long> idSet = new HashSet<>(productIds);
-            for (Long prId : idSet) {
-                ProductPrivate productPrivate = productPrivateService.findByPrId(prId);
-                if (null == productPrivate) {
-                    productPrivate = new ProductPrivate();
-					productPrivate.setPrId(prId);
-                }
-                productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
-                // 统计现在有多少在售信息
-                int batchCount = goodsDao.findCountByProductid(prId);
-                productPrivate.setBatchCount(batchCount);
-				productPrivates.add(productPrivate);
-            }
-            productPrivateDao.save(productPrivates);
+			productPrivateService.newProductPrivateIfNotExist(productIds);
         }
-
+		return "sucesss";
 //		User user = SystemSession.getUser();
 //		Enterprise enterprise = SystemSession.getUser().getEnterprise();
 //		final Object[] obj = new Object[]{enterprise.getUu(), user.getUserUU(), enterprise.getEnName(), batch};
@@ -1902,57 +1902,38 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 //				return "0";
 //			}
 //		});
-		return null;
 	}
 
 	/**
 	 * 批量发布之后,需要做的事情,内部使用线程,不需要让用户等结果
 	 */
-	public void afterPublishToGoodsDo(final List<Long> productIds) {
+	public void afterPublishToGoodsDo(final List<Long> productIds, final Set<Long> reIds) {
 		if (CollectionUtils.isEmpty(productIds)) {
 			return ;
 		}
 		final Runnable afterPublishToGoodsRunnable = new Runnable() {
 			@Override
 			public void run() {
-				List<ProductPrivate> productPrivates = new ArrayList<ProductPrivate>();
-				List<ProductPrivate> privateList = productPrivateService.findByPrIds(productIds);
-				Boolean isExist = false;
-				ProductPrivate productPrivate = null;
-				int batchCount = 0;
-				Map<Long, Integer> goodsCountByProductId = goodsService.batchGetCountByProductId(productIds);
-				for (Long productId : productIds) {
-					isExist = false;
-					batchCount = 0;
-					if (goodsCountByProductId != null) {
-						batchCount = goodsCountByProductId.get(productId);
+				//创建物料的私有信息
+				productPrivateService.newProductPrivateIfNotExist(productIds);
+
+				if ((reIds != null) && (reIds.size() != 0)) {
+					List<ReleaseProductByBatch> productByBatches = releaseProductByBatchDao.findAll(reIds);
+					List<Long> prIds = new ArrayList<>();
+					for (ReleaseProductByBatch productByBatch : productByBatches) {
+						prIds.add(productByBatch.getProductid());
 					}
-					for (ProductPrivate productPri : privateList) {
-						if (productPri.getPrId().longValue() == productId.longValue()) {
-							isExist = true;
-							if ((productPri.getB2cEnabled() == null) || (productPri.getB2cEnabled().intValue() != IntegerConstant.YES_SHORT.intValue()) || (productPri.getBatchCount() == null) || (productPri.getBatchCount().intValue() != batchCount)) {
-								productPri.setB2cEnabled(IntegerConstant.YES_SHORT);
-								productPri.setBatchCount(batchCount);
-								productPrivates.add(productPri);
+					List<Product> products = productService.findByProductId(prIds);
+					for (Product product : products) {
+						for (ReleaseProductByBatch productByBatch : productByBatches) {
+							if ((productByBatch.getProductid() != null ) && (product.getId().longValue() == productByBatch.getProductid().longValue())) {
+								product.setSpec(productByBatch.getSpec());
 							}
 						}
 					}
-					if (!isExist) {
-						productPrivate = new ProductPrivate();
-						productPrivate.setPrId(productId);
-						productPrivate.setBatchCount(batchCount);
-						productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
-						productPrivates.add(productPrivate);
-					}
+					List<Goods> goodses = goodsDao.findByProductIds(prIds);
+					goodsService.updateSpecByProducts(products, goodses);
 				}
-				if (CollectionUtils.isNotEmpty(productPrivates)) {
-					productPrivateService.saveProductPrivate(productPrivates);
-				}
-
-				//根据更新的规格信息,更新在售产品的信息
-				List<V_ProductPrivate> v_productPrivates = v_productPrivateDao.findProductInIdAndSpecIsNotNull(productIds);
-				List<Goods> goodses = goodsDao.findByProductIds(productIds);
-				goodsService.updateSpecByProducts(v_productPrivates, goodses);
 			}
 		};
 		try {

BIN
src/main/resources/jxls-tpl/trade/releaseByBatch-person.xls


BIN
src/main/resources/jxls-tpl/trade/releaseByBatchError-person.xls