|
|
@@ -1,12 +1,11 @@
|
|
|
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.account.service.EnterpriseService;
|
|
|
import com.uas.platform.b2c.common.base.dao.CommonDao;
|
|
|
import com.uas.platform.b2c.core.config.SysConf;
|
|
|
import com.uas.platform.b2c.core.constant.IntegerConstant;
|
|
|
import com.uas.platform.b2c.core.constant.ReleaseStatus;
|
|
|
+import com.uas.platform.b2c.core.constant.SplitChar;
|
|
|
import com.uas.platform.b2c.core.constant.Status;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.NumberUtil;
|
|
|
@@ -16,12 +15,15 @@ import com.uas.platform.b2c.prod.commodity.constant.*;
|
|
|
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;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandInfoDao;
|
|
|
import com.uas.platform.b2c.prod.product.brand.modal.BrandInfo;
|
|
|
import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
|
|
|
+import com.uas.platform.b2c.prod.product.common.service.impl.CreateNumberServiceImpl;
|
|
|
import com.uas.platform.b2c.prod.product.kind.dao.KindInfoDao;
|
|
|
import com.uas.platform.b2c.prod.product.kind.model.KindInfo;
|
|
|
import com.uas.platform.b2c.prod.product.property.dao.PropertyDao;
|
|
|
@@ -30,6 +32,7 @@ import com.uas.platform.b2c.prod.store.model.StoreStatus;
|
|
|
import com.uas.platform.b2c.prod.store.service.StoreInService;
|
|
|
import com.uas.platform.b2c.trade.order.StringConstant.Currency;
|
|
|
import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
+import com.uas.platform.b2c.trade.util.BoundedExecutor;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.persistence.criteria.CriterionExpression;
|
|
|
@@ -37,6 +40,7 @@ import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
@@ -47,6 +51,7 @@ 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;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
@@ -63,6 +68,8 @@ import java.sql.Statement;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@@ -92,9 +99,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
@Autowired
|
|
|
private SysConf SysConf;
|
|
|
|
|
|
- @Autowired
|
|
|
- private EnterpriseService enterpriseService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@@ -125,9 +129,21 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
@Autowired
|
|
|
private V_ProductPrivateDao v_productPrivateDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProductService productService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 控制任务提交速度的线程池
|
|
|
+ */
|
|
|
+ private final BoundedExecutor executor;
|
|
|
+
|
|
|
+ private final NamedParameterJdbcTemplate namedJdbcTemplate;
|
|
|
+
|
|
|
@Autowired
|
|
|
private BrandInfoDao brandInfoDao;
|
|
|
|
|
|
+ private final ProductPrivateService productPrivateService;
|
|
|
+
|
|
|
private static final String SIZE = "尺寸";
|
|
|
private static final String COLOR = "颜色";
|
|
|
private static final String THICKCOPPER = "铜厚";
|
|
|
@@ -136,6 +152,16 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
@Value("#{sys.productServiceIp}")
|
|
|
private String productServiceIp;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ public ReleaseProductByBatchServiceImpl(NamedParameterJdbcTemplate namedJdbcTemplate, ProductPrivateService productPrivateService) {
|
|
|
+ this.namedJdbcTemplate = namedJdbcTemplate;
|
|
|
+ this.productPrivateService = productPrivateService;
|
|
|
+ ExecutorService executorService = Executors.newCachedThreadPool();
|
|
|
+ executor = new BoundedExecutor(executorService, 1600);
|
|
|
+ }
|
|
|
+
|
|
|
+ private final Logger logger = Logger.getLogger(getClass());
|
|
|
+
|
|
|
@Override
|
|
|
public ReleaseProductByBatch save(ReleaseProductByBatch releaseProductByBatch) {
|
|
|
return releaseProductByBatch;
|
|
|
@@ -182,6 +208,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
Row headerRow = sheet.getRow(0);
|
|
|
int total = 0;
|
|
|
int blankNum = 0;
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
if (headerRow != null) {
|
|
|
// 验证模板是否为商城模板
|
|
|
validateTemplate(headerRow, colNum, currency, isAPerson, isPcb);
|
|
|
@@ -221,15 +248,43 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- Long userUU = SystemSession.getUser().getUserUU();
|
|
|
+ System.out.println("获取订单信息缺失");
|
|
|
+ long l1 = System.currentTimeMillis();
|
|
|
+ System.err.println("l1--------------l testyuj" + (l1 - l));
|
|
|
Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- List<ReleaseProductByBatch> addList = new ArrayList<>(releaseProductByBatchs.size());
|
|
|
- addList.addAll(releaseProductByBatchs);
|
|
|
- commonDao.save(addList, ReleaseProductByBatch.class);
|
|
|
+ if (!isAPerson) {
|
|
|
+ //1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
|
|
|
+ for(int i = releaseProductByBatchs.size() - 1; i > -1; i--) {
|
|
|
+ ReleaseProductByBatch releaseProductByBatch = releaseProductByBatchs.get(i);
|
|
|
+ for(int j = i - 1; j > -1; j--) {
|
|
|
+ ReleaseProductByBatch byBatch = releaseProductByBatchs.get(j);
|
|
|
+ if(releaseProductByBatch.compareSameProductTagInfo(byBatch)) {
|
|
|
+ releaseProductByBatch.setTag("");
|
|
|
+ releaseProductByBatch.setTagstr("");
|
|
|
+ if (releaseProductByBatch.compareSameProductSixEle(byBatch)) {
|
|
|
+ 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 l3 = System.currentTimeMillis();
|
|
|
+ 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 : addList) {
|
|
|
+ for (ReleaseProductByBatch releaseProductByBatch : releaseProductByBatchs) {
|
|
|
Long productid = releaseProductByBatch.getProductid();
|
|
|
if (productid != null) {
|
|
|
List<ProductPerson> productPersonList = productPersonDao.findByProductId(productid);
|
|
|
@@ -242,16 +297,47 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ Long l5 = 0l;
|
|
|
+ String strCount = "";
|
|
|
if (isPcb) {
|
|
|
- releaseProductByBatchDao.callValidProcedurePcb(enUU, batch);
|
|
|
+ strCount = releaseProductByBatchDao.callValidProcedurePcb(enUU, batch);
|
|
|
} else {
|
|
|
- releaseProductByBatchDao.callValidProcedure(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);
|
|
|
+ strCount = jdbcTemplate.execute(new StatementCallback<String>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
|
|
|
+ stmt.executeQuery(updateSql);
|
|
|
+ ResultSet rs = stmt.getResultSet();
|
|
|
+ if (null != rs) {
|
|
|
+ rs.next();
|
|
|
+ System.err.println("测试结果---------" + rs.getString(1));
|
|
|
+ return rs.getString(1);
|
|
|
+ }
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ });
|
|
|
+ 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);
|
|
|
+ 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());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- Integer filter = releaseProductByBatchDao.getCountOfImportFail(userUU, batch, failCode);
|
|
|
- Integer failure = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.failure.value());
|
|
|
- Integer success = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.success.value());
|
|
|
modelMap.put("total", total);
|
|
|
modelMap.put("success", success);
|
|
|
modelMap.put("failure", failure);
|
|
|
@@ -1617,137 +1703,98 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
|
|
|
@Override
|
|
|
public String publishByBatch(String batch, boolean isPcb) {
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
List<ReleaseProductByBatch> releaseProductByBatchList =
|
|
|
releaseProductByBatchDao.findByRelbatchid(batch);
|
|
|
- List<Long> productIds = null;
|
|
|
- List<ProductPrivate> productPrivateList = null;
|
|
|
- if (!CollectionUtils.isEmpty(releaseProductByBatchList)) {
|
|
|
- Map<String, Object> map = convertProduct(releaseProductByBatchList, false, isPcb);
|
|
|
- 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();
|
|
|
- productIds = JSON.parseArray(result, Long.class);
|
|
|
- Set<Long> idSet = new HashSet<>(productIds);
|
|
|
- List<ProductPrivate> productPrivates = new ArrayList<>();
|
|
|
- for (Long prId : idSet) {
|
|
|
- ProductPrivate productPrivate = findByPrId(prId);
|
|
|
- if (null == productPrivate) {
|
|
|
- productPrivate = new ProductPrivate();
|
|
|
- productPrivate.setPrId(prId);
|
|
|
- }
|
|
|
- productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
|
|
|
- productPrivates.add(productPrivate);
|
|
|
- }
|
|
|
- productPrivateList = productPrivateDao.save(productPrivates);
|
|
|
-
|
|
|
- //根据更新的规格信息,更新在售产品的信息
|
|
|
- List<V_ProductPrivate> v_productPrivates = v_productPrivateDao.findProductInIdAndSpecIsNotNull(productIds);
|
|
|
- List<Goods> goodses = goodsDao.findByProductIds(productIds);
|
|
|
- goodsService.updateSpecByProducts(v_productPrivates, goodses);
|
|
|
-
|
|
|
- if (isPcb) {
|
|
|
- List<PCB> pcbList = new ArrayList<>();
|
|
|
- List<PCBPropertyValue> propertyValueList = new ArrayList<>();
|
|
|
-
|
|
|
- for (Long prId : idSet) {
|
|
|
- Product product = productDao.findOne(prId);
|
|
|
- if (product != null) {
|
|
|
- List<PCB> pcbs = pcbDao.findByProductid(prId);
|
|
|
- if (CollectionUtils.isEmpty(pcbs)) {
|
|
|
- PCB pcb = new PCB();
|
|
|
- pcb.setProductid(prId);
|
|
|
- pcb.setBrandid(product.getPbrandid());
|
|
|
- pcb.setKindid(product.getKindid());
|
|
|
- pcb.setCreatetime(new Date());
|
|
|
- pcbList.add(pcb);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- List<PCBPropertyValue> propertyValues = (List<PCBPropertyValue>) map.get(product.getEnUU().toString().concat(product.getProdNum()));
|
|
|
- if (CollectionUtils.isNotEmpty(propertyValues)) {
|
|
|
- for (PCBPropertyValue propertyValue : propertyValues) {
|
|
|
- propertyValue.setProductid(prId);
|
|
|
- propertyValueList.add(propertyValue);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (CollectionUtils.isNotEmpty(pcbList)) {
|
|
|
- pcbDao.save(pcbList);
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(propertyValueList)) {
|
|
|
- pcbPropertyvalueDao.save(propertyValueList);
|
|
|
- }
|
|
|
- }
|
|
|
+ long l1 = System.currentTimeMillis();
|
|
|
+ System.err.println("l1 -------------------l " + (l1 - l));
|
|
|
+ if (CollectionUtils.isEmpty(releaseProductByBatchList)) {
|
|
|
+ return String.valueOf(IntegerConstant.NO_SHORT);
|
|
|
}
|
|
|
+ Map<String, Object> map = convertProduct(releaseProductByBatchList, false, isPcb);
|
|
|
+ long l2 = System.currentTimeMillis();
|
|
|
+ System.err.println("l2 -------------------l1 " + (l2 - l1));
|
|
|
+ Set<Long> idSet = (Set<Long>) map.get("prIds");
|
|
|
+ if (isPcb) {
|
|
|
+ savePcbInfo(idSet, map);
|
|
|
+ }
|
|
|
+ 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";
|
|
|
- final String updateSql = String.format(sql, obj);
|
|
|
- String num = jdbcTemplate.execute(new StatementCallback<String>() {
|
|
|
+ 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_V4(@enuu, @enName, @batch, @out); select @out";
|
|
|
+ final String updateSql = String.format(sql, obj);
|
|
|
+ String num = jdbcTemplate.execute(new StatementCallback<String>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
|
|
|
+ stmt.executeUpdate(updateSql);
|
|
|
+ ResultSet rs = stmt.getResultSet();
|
|
|
+ if (null != rs) {
|
|
|
+ rs.next();
|
|
|
+ return rs.getString(1);
|
|
|
+ }
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ });
|
|
|
+ long l9 = System.currentTimeMillis();
|
|
|
+ System.err.println("l9 -------------------l8 " + (l9 - l8));
|
|
|
+ ArrayList<Long> list = new ArrayList<>();
|
|
|
+ list.addAll((Set<Long>)map.get("prIds"));
|
|
|
+ afterPublishToGoodsDo(list, (Set<Long>)map.get("reIds"));
|
|
|
+ return StringUtilB2C.getStr(num);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
|
|
|
- stmt.executeQuery(updateSql);
|
|
|
- ResultSet rs = stmt.getResultSet();
|
|
|
- if (null != rs) {
|
|
|
- rs.next();
|
|
|
- return rs.getString(1);
|
|
|
+ /**
|
|
|
+ * 批量保存pcb的信息
|
|
|
+ * @param idSet id
|
|
|
+ */
|
|
|
+ public void savePcbInfo(Set<Long> idSet, Map<String, Object> map) {
|
|
|
+ if (idSet == null || idSet.size() < 1) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ List<PCB> pcbList = new ArrayList<>();
|
|
|
+ List<PCBPropertyValue> propertyValueList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Long prId : idSet) {
|
|
|
+ Product product = productDao.findOne(prId);
|
|
|
+ if (product != null) {
|
|
|
+ List<PCB> pcbs = pcbDao.findByProductid(prId);
|
|
|
+ if (CollectionUtils.isEmpty(pcbs)) {
|
|
|
+ PCB pcb = new PCB();
|
|
|
+ pcb.setProductid(prId);
|
|
|
+ pcb.setBrandid(product.getPbrandid());
|
|
|
+ pcb.setKindid(product.getKindid());
|
|
|
+ pcb.setCreatetime(new Date());
|
|
|
+ pcbList.add(pcb);
|
|
|
}
|
|
|
- return "0";
|
|
|
}
|
|
|
- });
|
|
|
|
|
|
- if (null != productIds) {
|
|
|
- for (ProductPrivate productPrivate : productPrivateList) {
|
|
|
- // 统计现在有多少在售信息
|
|
|
- int batchCount = goodsDao.findCountByProductid(productPrivate.getPrId());
|
|
|
- productPrivate.setBatchCount(batchCount);
|
|
|
+ List<PCBPropertyValue> propertyValues = (List<PCBPropertyValue>) map.get(product.getEnUU().toString().concat(product.getProdNum()));
|
|
|
+ if (CollectionUtils.isNotEmpty(propertyValues)) {
|
|
|
+ for (PCBPropertyValue propertyValue : propertyValues) {
|
|
|
+ propertyValue.setProductid(prId);
|
|
|
+ propertyValueList.add(propertyValue);
|
|
|
+ }
|
|
|
}
|
|
|
- productPrivateDao.save(productPrivateList);
|
|
|
}
|
|
|
|
|
|
-// 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_PRODUCT_V1(@enuu, @enName, @batch, @out); select @out";
|
|
|
-// final String updateSql = String.format(sql, obj);
|
|
|
-// String num = jdbcTemplate.execute(new StatementCallback<String>() {
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
|
|
|
-// stmt.executeQuery(updateSql);
|
|
|
-// ResultSet rs = stmt.getResultSet();
|
|
|
-// if (null != rs) {
|
|
|
-// rs.next();
|
|
|
-// return rs.getString(1);
|
|
|
-// }
|
|
|
-// return "0";
|
|
|
-// }
|
|
|
-// });
|
|
|
-// if (!"0".equals(num)) {
|
|
|
-// List<Goods> goodsList = goodsDao.findByBatchid(batch);
|
|
|
-// Set<String> uuids = new HashSet<String>();
|
|
|
-// for (Goods goods : goodsList) {
|
|
|
-// if (goods.getUuid() != null) {
|
|
|
-// uuids.add(goods.getUuid());
|
|
|
-//// goodsService.saveOrUpdatePriceInfos(goods, "NORMAL");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // TODO 之后删除
|
|
|
-// for (String uuid : uuids) {
|
|
|
-// goodsService.updateComponentTradeInfos(uuid);
|
|
|
-// }
|
|
|
-// }
|
|
|
- return StringUtilB2C.getStr(num);
|
|
|
+ if (CollectionUtils.isNotEmpty(pcbList)) {
|
|
|
+ pcbDao.save(pcbList);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(propertyValueList)) {
|
|
|
+ pcbPropertyvalueDao.save(propertyValueList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private Map<String, Object> convertProduct (List<ReleaseProductByBatch> releaseProductByBatchList, boolean isAPerson , boolean isPcb) {
|
|
|
if (CollectionUtils.isEmpty(releaseProductByBatchList)) {
|
|
|
return null;
|
|
|
}
|
|
|
Map<String, Object> map = new HashedMap();
|
|
|
- List<com.uas.ps.entity.Product> products = new ArrayList<>();
|
|
|
+ List<Product> products = new ArrayList<>();
|
|
|
+ List<ProductPrivate> productPrivates = new ArrayList<>();
|
|
|
+ Set<Long> prIds = new HashSet<>();
|
|
|
+ Set<Long> reIds = new HashSet<>();
|
|
|
Map<String, List<PCBPropertyValue>> propertyMap = new HashedMap();
|
|
|
|
|
|
Long sizeProId = null;
|
|
|
@@ -1760,33 +1807,30 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
thickCopperProId = propertyDao.findIdByLabelCn(THICKCOPPER);
|
|
|
thickProId = propertyDao.findIdByLabelCn(THICK);
|
|
|
}
|
|
|
-
|
|
|
+ String importNum = createNumberService.getTimeNumber("trade$product_import_num", 8, releaseProductByBatchList.size());
|
|
|
+ if (StringUtils.isEmpty(importNum)) {
|
|
|
+ throw new IllegalOperatorException("生成批次号失败");
|
|
|
+ }
|
|
|
+ String time = importNum.substring(IntegerConstant.NO_SHORT, (IntegerConstant.TIME_LENGTH));
|
|
|
+ Integer num = Integer.valueOf(importNum.substring(IntegerConstant.TIME_LENGTH));
|
|
|
+ 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);
|
|
|
- String batchCode = "PNUM" + createNumberService.getTimeNumber("trade$product_import_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<>();
|
|
|
@@ -1807,14 +1851,31 @@ 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);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
+ if (products.size() != 0) {
|
|
|
+ List<Product> productes = productDao.save(products);
|
|
|
+ for (Product producte : productes) {
|
|
|
+ ProductPrivate productPrivate = new ProductPrivate();
|
|
|
+ productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
|
|
|
+ productPrivate.setPrId(producte.getId());
|
|
|
+ productPrivate.setBatchCount(IntegerConstant.NO_SHORT);
|
|
|
+ productPrivates.add(productPrivate);
|
|
|
|
|
|
- map.put("products", products);
|
|
|
+ prIds.add(producte.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(productPrivates)) {
|
|
|
+ productPrivateService.saveProductPrivate(productPrivates);
|
|
|
+ }
|
|
|
+ if (reIds.size() > 0) {
|
|
|
+ map.put("reIds", reIds);
|
|
|
+ }
|
|
|
+ map.put("prIds", prIds);
|
|
|
map.put("propertyvalues", propertyMap);
|
|
|
return map;
|
|
|
}
|
|
|
@@ -1825,30 +1886,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 = 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};
|
|
|
@@ -1867,17 +1913,44 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
// return "0";
|
|
|
// }
|
|
|
// });
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ProductPrivate findByPrId(Long prId) {
|
|
|
- List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(prId);
|
|
|
- if (!CollectionUtils.isEmpty(productPrivates)) {
|
|
|
- ProductPrivate productPrivate = productPrivates.get(0);
|
|
|
- return productPrivate;
|
|
|
- } else {
|
|
|
- return null;
|
|
|
+ /**
|
|
|
+ * 批量发布之后,需要做的事情,内部使用线程,不需要让用户等结果
|
|
|
+ */
|
|
|
+ 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() {
|
|
|
+ //创建物料的私有信息
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Goods> goodses = goodsDao.findByProductIds(prIds);
|
|
|
+ goodsService.updateSpecByProducts(products, goodses);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ executor.submitTask(afterPublishToGoodsRunnable);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|