Browse Source

Merge remote-tracking branch 'origin/release-201819-wangcz' into release-201819-wangcz

wangdy 7 years ago
parent
commit
acc461be98

+ 8 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/controller/ReleaseProductByBatchController.java

@@ -152,8 +152,12 @@ public class ReleaseProductByBatchController {
      */
     @RequestMapping(value = "/batchRelease", method = RequestMethod.POST)
     public String batchRelease(String batch) {
+        long l = System.currentTimeMillis();
         logger.log("批量上架模块", "批量发布指定批次:" + batch + "的上架内容");
-        return releaseProductByBatchService.publishByBatch(batch, false);
+        String byBatch = releaseProductByBatchService.publishByBatch(batch, false);
+        long l1 = System.currentTimeMillis();
+        logger.log("批量上架模块", "l1 ------------l" + (l1 - 1));
+        return byBatch;
     }
 
     /**
@@ -231,7 +235,10 @@ public class ReleaseProductByBatchController {
             } else {
                 throw new IllegalOperatorException("文件格式不正确!请上传.xls或.xlsx格式的文件");
             }
+            long l = System.currentTimeMillis();
             map = releaseProductByBatchService.releaseByWorkbook(workbook, selfSale, currency, isPerson, repeatImport, false);
+            long l1 = System.currentTimeMillis();
+            logger.log("批量上架模块", "l1 ------------l" + (l1 - 1));
         } catch (IOException e) {
             e.printStackTrace();
         }

+ 2 - 2
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ProductDao.java

@@ -35,8 +35,8 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      * @param prodNums  物料编号list
      * @return 返回物料信息。
      */
-    @Query(value = "select p from Product p where p.prodNum in (:prodNums)")
-    List<Product> findProductsByProdNums(@Param("prodNum") List<String> prodNums);
+    @Query(value = "select p from Product p where p.prodNum in :prodNums")
+    List<Product> findByProdNums(@Param("prodNums") List<String> prodNums);
 
     /**
      * 通过uu查询非标准器件进行存储

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

@@ -329,4 +329,11 @@ public interface ProductService {
      * @return 返回物料信息。
      */
     List<Product> findProductsByProdNums(List<String> prodNums);
+
+
+    /**
+     * 批量保存
+     * @param list
+     */
+    void saveByJdbcTemplate(List<ReleaseProductByBatch> list);
 }

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

@@ -103,4 +103,11 @@ public interface ReleaseProductByBatchService {
      * @return list
      */
     public List<ReleaseProductByBatch> findFailureReleaseProductByBatch(String batch);
+
+
+    /**
+     * 更新物料主键和物料编号
+     * @param list
+     */
+    void udpatePridAndRrodnum(List<ReleaseProductByBatch> list);
 }

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

@@ -72,6 +72,7 @@ import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter;
 import org.springframework.jdbc.core.StatementCallback;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
 import org.springframework.stereotype.Service;
@@ -84,6 +85,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import java.lang.reflect.Field;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -2222,10 +2224,52 @@ public class ProductServiceImpl implements ProductService {
     @Override
     public List<Product> findProductsByProdNums(List<String> prodNums) {
         if (CollectionUtils.isNotEmpty(prodNums)) {
-            return productDao.findProductsByProdNums(prodNums);
+            return productDao.findByProdNums(prodNums);
         } else {
             return new ArrayList<>();
         }
     }
+
+    /**
+     * 批量保存,通过jdbctemplate
+     *
+     * @param list
+     */
+    @Override
+    public void saveByJdbcTemplate(List<ReleaseProductByBatch> list) {
+        if (CollectionUtils.isNotEmpty(list)) {
+            jdbcTemplate.batchUpdate("insert into products(pr_code,pr_cmpimg,pr_enuu,pr_brand,pr_cmpcode,pr_cmpuuid,pr_kind,pr_kindid,pr_pcmpcode,pr_pbrand,pr_pbranden,pr_pbrandid,pr_pbranduuid,pr_standard,pr_create_time,pr_spec,pr_title,pr_issale) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
+                    list, list.size(), new ParameterizedPreparedStatementSetter<ReleaseProductByBatch>() {
+                        @Override
+                        public void setValues(PreparedStatement ps, ReleaseProductByBatch t) throws SQLException {
+                            if (StringUtilB2C.isEmpty(t.getProductNum())) {
+                                System.err.println(t.getProductNum() + "------------------");
+                            }
+
+                            ps.setObject(1, t.getProductNum());
+                            ps.setObject(2, t.getImg());
+                            ps.setObject(3, SystemSession.getUser().getEnterprise().getUu());
+                            ps.setObject(4, t.getBrandNameEn());
+                            ps.setObject(5, t.getCode());
+                            ps.setObject(6, t.getComponentUuId());
+                            ps.setObject(7, t.getKindName());
+                            ps.setObject(8, t.getKindUuid());
+                            ps.setObject(9, t.getB2cCode());
+                            ps.setObject(10, t.getB2cBrandcn());
+                            ps.setObject(11, t.getB2cBranden());
+                            ps.setObject(12, t.getBrandId());
+                            ps.setObject(13, t.getBranduuid());
+                            ps.setObject(14, (t.getComponentUuId() == null ? 0 : 1));
+                            ps.setObject(15, new Date(System.currentTimeMillis()));
+                            ps.setObject(16, t.getSpec());
+                            ps.setObject(17, t.getKindName());
+                            ps.setObject(18, ((short) 1));
+                        }
+                    });
+        } else {
+
+        }
+
+    }
 }
 

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

@@ -49,6 +49,7 @@ 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.BatchPreparedStatementSetter;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.StatementCallback;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -62,6 +63,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import java.math.BigDecimal;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -1797,7 +1799,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			return null;
 		}
 		Map<String, Object> map = new HashedMap();
-		List<Product> products = new ArrayList<>();
+		List<ReleaseProductByBatch> productsfromRelease = new ArrayList<>();
 		List<ProductPrivate> productPrivates = new ArrayList<>();
 		Set<Long> prIds = new HashSet<>();
 		Set<Long> reIds = new HashSet<>();
@@ -1828,14 +1830,11 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		    if (releaseProductByBatch.getReleaseCode().equals(ReleaseStatus.failure.value()) ||
                     releaseProductByBatch.getReleaseCode().equals(ReleaseStatus.success.value())) {
 				if (releaseProductByBatch.getProductid() == null) {
-					Product product = new Product();
-					product.setReleaseByBatch(releaseProductByBatch);
 					// releaseProductByBatch.getCode(); 在公有库生成
 					prodNum = "PNUM" + time + CreateNumberServiceImpl.formatIntToStr(++num, 8);
-					product.setProdNum(prodNum);
 					releaseProductByBatch.setProductNum(prodNum);
                     proNums.add(prodNum);
-					products.add(product);
+                    productsfromRelease.add(releaseProductByBatch);
 				} else {
 					//对于已经存在于物料库的信息,如果规格信息已存在,则做更新,如果是
 					prIds.add(releaseProductByBatch.getProductid());
@@ -1866,15 +1865,14 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 						propertyMap.put(SystemSession.getUser().getEnterprise().getUu().toString().concat(prodNum), propertyValues);
 					}
 				}
-
             }
 		}
         long l2 = System.currentTimeMillis();
         System.err.println("打印l2 ----------- l1" + (l2 - l1));
 		List<ReleaseProductByBatch> reList = new ArrayList<>();
-		if (products.size() != 0) {
-            List<Product> productes = productDao.save(products);
-			//List<Product> productes = productService.findProductsByProdNums(proNums);
+		if (productsfromRelease.size() != 0) {
+            productService.saveByJdbcTemplate(productsfromRelease);
+			List<Product> productes = productService.findProductsByProdNums(proNums);
 			for (Product producte : productes) {
 				ProductPrivate productPrivate = new ProductPrivate();
 				productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
@@ -1896,7 +1894,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
         long l3 = System.currentTimeMillis();
         System.err.println("打印l3 ----------- l2" + (l3 - l2));
 		if (CollectionUtils.isNotEmpty(reList)) {
-			releaseProductByBatchDao.save(reList);
+            udpatePridAndRrodnum(reList);
 		}
         long l4 = System.currentTimeMillis();
         System.err.println("打印l4 ----------- l3" + (l4 - l3));
@@ -1987,4 +1985,32 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			e.printStackTrace();
 		}
 	}
+
+
+    /**
+     * 更新物料主键和物料编号
+     *
+     * @param list
+     */
+    @Override
+    public void udpatePridAndRrodnum(List<ReleaseProductByBatch> list) {
+        if (CollectionUtils.isNotEmpty(list)) {
+            jdbcTemplate.batchUpdate("update trade$releasebybatch set rel_productid=?,rel_pronum=? where rel_id=?", new BatchPreparedStatementSetter() {
+                @Override
+                public void setValues(PreparedStatement ps, int i) throws SQLException {
+                    ReleaseProductByBatch releaseProductByBatch = list.get(i);
+                    ps.setLong(1, releaseProductByBatch.getProductid());
+                    ps.setString(2, releaseProductByBatch.getProductNum());
+                    ps.setLong(3, releaseProductByBatch.getId());
+                }
+
+                @Override
+                public int getBatchSize() {
+                    return list.size();
+                }
+            });
+        } else {
+            return ;
+        }
+    }
 }

+ 2 - 2
src/main/webapp/resources/js/common/controllers/commonCtrls.js

@@ -358,11 +358,11 @@ define([ 'app/app' ], function(app) {
 				if(event.keyCode == 40) { //监听到按下键
 					$scope.selectIndex ++;
 					if($scope.selectIndex >= $scope.associates.length) $scope.selectIndex = 0;
-					$scope.keyword = $scope.associates[$scope.selectIndex];
+					$scope.keyword = $scope.associates[$scope.selectIndex].code || $scope.associates[$scope.selectIndex].nameCn || $scope.associates[$scope.selectIndex].name ||$scope.associates[$scope.selectIndex];
 				} else if(event.keyCode == 38) { //监听到按上键
 					$scope.selectIndex --;
 					if($scope.selectIndex < 0) $scope.selectIndex = $scope.associates.length - 1;
-					$scope.keyword = $scope.keyword = $scope.associates[$scope.selectIndex];
+          $scope.keyword = $scope.associates[$scope.selectIndex].code || $scope.associates[$scope.selectIndex].nameCn || $scope.associates[$scope.selectIndex].name ||$scope.associates[$scope.selectIndex];
 				} else if(event.keyCode == 13) { //确定键
 					$scope.search();
 				}