|
|
@@ -283,48 +283,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return productDao.findByEnUUAndNotIsSale(enUU, switchStatus).size();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * B2B批量更新物料信息并加入个人物料库
|
|
|
- *
|
|
|
- * @param data 物料信息
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
- public ModelMap updateProdInfoAndAddToProductUser(List<Product> data) {
|
|
|
- ModelMap map = new ModelMap();
|
|
|
- List<Product> updateList = new ArrayList<>();
|
|
|
- try {
|
|
|
-// long start = System.currentTimeMillis();
|
|
|
-// List<Product> products = updateB2bProdInfo(data);
|
|
|
-// for (Product product : data) {
|
|
|
-// if (null != product.getId()) {
|
|
|
-// updateList.add(product);
|
|
|
-// } else {
|
|
|
-// List<Product> products = productDao.findByEnUUAndCode(product.getEnUU(), product.getCode());
|
|
|
-// if (CollectionUtils.isEmpty(products)) {
|
|
|
-// updateList.add(product);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// List<Product> products = productDao.save(data);
|
|
|
- waitSyncHelper.preWait("B2B", jdbcTemplate);
|
|
|
- List<Long> ids = update(data);
|
|
|
- waitSyncHelper.waitResponse();
|
|
|
- List<Product> products = productDao.findAll(ids);
|
|
|
-// System.out.println("更新完物料:" + (System.currentTimeMillis() - start));
|
|
|
-// start = System.currentTimeMillis();
|
|
|
- waitSyncHelper.preWait("B2B", jdbcTemplate);
|
|
|
- int sum = updateProductUser(products);
|
|
|
- waitSyncHelper.waitResponse();
|
|
|
-// System.out.println("保存完个人物料:" + (System.currentTimeMillis() - start));
|
|
|
- map.put("success", "true");
|
|
|
- map.put("result", sum);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- map.put("success", "false");
|
|
|
- map.put("message", e.getCause() + e.getMessage());
|
|
|
- }
|
|
|
- return map;
|
|
|
+ public List<Product> findAll(List<Long> ids) {
|
|
|
+ return productDao.findAll(ids);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -332,6 +293,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* @param data 物料资料
|
|
|
* @return 保存之后的idList
|
|
|
*/
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public List<Long> update(List<Product> data) {
|
|
|
List<Product> newList = new ArrayList<>();
|
|
|
@@ -353,12 +315,44 @@ public class ProductServiceImpl implements ProductService {
|
|
|
ids.addAll(newIds);
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(updateList)) {
|
|
|
- updateAndReturnKey(updateList);
|
|
|
+ updateExisted(updateList);
|
|
|
// System.out.println("update数据,数据量:" + updateList.size() + "耗时:" + (System.currentTimeMillis() - start));
|
|
|
}
|
|
|
return ids;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量更新已存在的物料
|
|
|
+ * @param updateList 已存在物料list
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateExisted(List<Product> updateList) {
|
|
|
+ jdbcTemplate.batchUpdate("update products set pr_enuu=?,pr_useruu=?,pr_code=?,pr_title=?,pr_spec=?,pr_cmpcode=?,pr_brand=?," +
|
|
|
+ "pr_unit=?,pr_minorder=?,pr_minpack=?,pr_leadtime=?,pr_ltinstock=?,pr_issale=?,pr_ispurchase=?,pr_sourceapp=? " +
|
|
|
+ "where pr_id=?",
|
|
|
+ updateList, updateList.size(), new ParameterizedPreparedStatementSetter<Product>() {
|
|
|
+ @Override
|
|
|
+ public void setValues(PreparedStatement ps, Product product) throws SQLException {
|
|
|
+ ps.setLong(1, product.getEnUU());
|
|
|
+ ps.setLong(2, product.getUserUU());
|
|
|
+ ps.setString(3, product.getCode());
|
|
|
+ ps.setString(4, product.getTitle());
|
|
|
+ ps.setString(5, product.getSpec());
|
|
|
+ ps.setString(6, product.getCmpCode());
|
|
|
+ ps.setString(7, product.getBrand());
|
|
|
+ ps.setString(8, product.getUnit());
|
|
|
+ ps.setObject(9, product.getMinOrder());
|
|
|
+ ps.setObject(10, product.getMinPack());
|
|
|
+ ps.setObject(11, product.getLeadTime());
|
|
|
+ ps.setObject(12, product.getLtinstock());
|
|
|
+ ps.setShort(13, product.getIsSale());
|
|
|
+ ps.setShort(14, product.getIsPurchase());
|
|
|
+ ps.setString(15, product.getSourceApp());
|
|
|
+ ps.setLong(16, product.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 批量新增物料资料
|
|
|
* @param newList 新增的物料资料
|
|
|
@@ -368,7 +362,8 @@ public class ProductServiceImpl implements ProductService {
|
|
|
public List<Long> insertAndReturnKey(final List<Product> newList) {
|
|
|
return jdbcTemplate.batchInsert("insert into products(pr_enuu,pr_useruu,pr_code,pr_title,pr_spec,pr_cmpcode,pr_brand," +
|
|
|
"pr_unit,pr_minorder,pr_minpack,pr_leadtime,pr_ltinstock,pr_issale,pr_ispurchase,pr_sourceapp) " +
|
|
|
- "select ?,?,?,?,?,?,?,?,?,?,?,?,?,?,? from dual where not exists(select pr_id from products where pr_enuu = ? and pr_code = ?)", new BatchPreparedStatementSetter() {
|
|
|
+ "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) on duplicate key update pr_useruu=?,pr_title=?,pr_spec=?,pr_cmpcode=?,pr_brand=?," +
|
|
|
+ "pr_unit=?,pr_minorder=?,pr_minpack=?,pr_leadtime=?,pr_ltinstock=?,pr_issale=?,pr_ispurchase=?,pr_sourceapp=?", new BatchPreparedStatementSetter() {
|
|
|
@Override
|
|
|
public void setValues(PreparedStatement ps, int i) throws SQLException {
|
|
|
Product product = newList.get(i);
|
|
|
@@ -387,8 +382,19 @@ public class ProductServiceImpl implements ProductService {
|
|
|
ps.setShort(13, product.getIsSale());
|
|
|
ps.setShort(14, product.getIsPurchase());
|
|
|
ps.setString(15, product.getSourceApp());
|
|
|
- ps.setLong(16, product.getEnUU());
|
|
|
- ps.setString(17, product.getCode());
|
|
|
+ ps.setLong(16, product.getUserUU());
|
|
|
+ ps.setString(17, product.getTitle());
|
|
|
+ ps.setString(18, product.getSpec());
|
|
|
+ ps.setString(19, product.getCmpCode());
|
|
|
+ ps.setString(20, product.getBrand());
|
|
|
+ ps.setString(21, product.getUnit());
|
|
|
+ ps.setObject(22, product.getMinOrder());
|
|
|
+ ps.setObject(23, product.getMinPack());
|
|
|
+ ps.setObject(24, product.getLeadTime());
|
|
|
+ ps.setObject(25, product.getLtinstock());
|
|
|
+ ps.setShort(26, product.getIsSale());
|
|
|
+ ps.setShort(27, product.getIsPurchase());
|
|
|
+ ps.setString(28, product.getSourceApp());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -398,43 +404,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 批量更新物料资料
|
|
|
- * @param updateList 更新的物料资料
|
|
|
- * @return 更新之后的idList
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<Long> updateAndReturnKey(final List<Product> updateList) {
|
|
|
- return jdbcTemplate.batchInsert("update products set pr_enuu=?,pr_useruu=?,pr_code=?,pr_title=?,pr_spec=?,pr_cmpcode=?," +
|
|
|
- "pr_brand=?,pr_unit=?,pr_minorder=?,pr_minpack=?,pr_leadtime=?,pr_ltinstock=?,pr_issale=?,pr_ispurchase=?,pr_sourceapp=? " +
|
|
|
- "where pr_id=?", new BatchPreparedStatementSetter() {
|
|
|
- @Override
|
|
|
- public void setValues(PreparedStatement ps, int i) throws SQLException {
|
|
|
- Product product = updateList.get(i);
|
|
|
- ps.setLong(1, product.getEnUU());
|
|
|
- ps.setLong(2, product.getUserUU());
|
|
|
- ps.setString(3, product.getCode());
|
|
|
- ps.setString(4, product.getTitle());
|
|
|
- ps.setString(5, product.getSpec());
|
|
|
- ps.setString(6, product.getCmpCode());
|
|
|
- ps.setString(7, product.getBrand());
|
|
|
- ps.setString(8, product.getUnit());
|
|
|
- ps.setObject(9, product.getMinOrder());
|
|
|
- ps.setObject(10, product.getMinPack());
|
|
|
- ps.setObject(11, product.getLeadTime());
|
|
|
- ps.setObject(12, product.getLtinstock());
|
|
|
- ps.setShort(13, product.getIsSale());
|
|
|
- ps.setShort(14, product.getIsPurchase());
|
|
|
- ps.setString(15, product.getSourceApp());
|
|
|
- ps.setLong(16, product.getId());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getBatchSize() {
|
|
|
- return updateList.size();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
// /**
|
|
|
// * 新增物料上传 -- 只能返回保存数量,得不到已保存物料信息,无法满足个人库新增需要
|
|
|
@@ -475,20 +444,19 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* 更新个人产品库
|
|
|
* @param products 物料信息
|
|
|
*/
|
|
|
- private int updateProductUser(List<Product> products) {
|
|
|
- int[][] result = jdbcTemplate.batchUpdate("INSERT INTO product$users(pu_date,pu_enuu,pu_erpid,pu_prid,pu_useruu) SELECT ?,?,?,?,? FROM DUAL " +
|
|
|
- "WHERE NOT EXISTS(SELECT pu_id FROM product$users WHERE pu_enuu = ? and pu_prid = ? and pu_useruu = ?);",
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public int updateProductUser(List<Product> products) {
|
|
|
+ final Date now = new Date();
|
|
|
+ int[][] result = jdbcTemplate.batchUpdate("REPLACE INTO product$users(pu_date,pu_enuu,pu_erpid,pu_prid,pu_useruu) values(?,?,?,?,?)",
|
|
|
products, products.size(), new ParameterizedPreparedStatementSetter<Product>() {
|
|
|
@Override
|
|
|
public void setValues(PreparedStatement ps, Product t) throws SQLException {
|
|
|
- ps.setObject(1, new Date());
|
|
|
+ ps.setObject(1, now);
|
|
|
ps.setObject(2, t.getEnUU());
|
|
|
ps.setObject(3, t.getSourceId());
|
|
|
ps.setObject(4, t.getId());
|
|
|
ps.setObject(5, t.getUserUU());
|
|
|
- ps.setObject(6, t.getEnUU());
|
|
|
- ps.setObject(7, t.getId());
|
|
|
- ps.setObject(8, t.getUserUU());
|
|
|
}
|
|
|
});
|
|
|
int sum = 0;
|