|
|
@@ -51,6 +51,7 @@ import com.uas.platform.b2c.trade.presale.model.GoodsBrowsingHistory;
|
|
|
import com.uas.platform.b2c.trade.presale.service.CartService;
|
|
|
import com.uas.platform.b2c.trade.support.CodeType;
|
|
|
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.Constant;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
@@ -91,6 +92,8 @@ import java.sql.Statement;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
* Created by wangyc on 2017/5/26.
|
|
|
@@ -208,6 +211,11 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private UserDao userDao;
|
|
|
|
|
|
+ /**
|
|
|
+ * 控制任务提交速度的线程池
|
|
|
+ */
|
|
|
+ private final BoundedExecutor executor;
|
|
|
+
|
|
|
@Autowired
|
|
|
private SearchService searchService;
|
|
|
|
|
|
@@ -220,12 +228,18 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private ProductPrivateService productPrivateService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private CommonDao commonDao;
|
|
|
+ private final CommonDao commonDao;
|
|
|
|
|
|
@Autowired
|
|
|
private InOutboundDetailService inOutboundDetailService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ public ProductServiceImpl(CommonDao commonDao) {
|
|
|
+ this.commonDao = commonDao;
|
|
|
+ ExecutorService executorService = Executors.newCachedThreadPool();
|
|
|
+ executor = new BoundedExecutor(executorService, 1600);
|
|
|
+ }
|
|
|
+
|
|
|
private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
|
|
|
|
|
|
@Override
|
|
|
@@ -1973,11 +1987,8 @@ public class ProductServiceImpl implements ProductService {
|
|
|
productPrivate.setAttach(component.getAttach());
|
|
|
productPrivateDao.save(productPrivate);
|
|
|
} else {
|
|
|
- ProductPrivate productPrivate = new ProductPrivate();
|
|
|
+ ProductPrivate productPrivate = new ProductPrivate(product.getId());
|
|
|
productPrivate.setAttach(component.getAttach());
|
|
|
- productPrivate.setPrId(product.getId());
|
|
|
- productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
|
|
|
- productPrivate.setBatchCount(IntegerConstant.NO_SHORT);
|
|
|
productPrivateDao.save(productPrivate);
|
|
|
}
|
|
|
}
|
|
|
@@ -1999,39 +2010,59 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return new ResultMap(CodeType.OK, "");
|
|
|
} else {
|
|
|
if ((!StringUtils.isEmpty(component.getSpec())) || (!StringUtils.isEmpty(component.getAttach()))) {
|
|
|
- List<Product> productList = productDao.findByCmpUuId(component.getUuid());
|
|
|
- List<ProductPrivate> productPrivatelist = new ArrayList<>();
|
|
|
- List<Product> list = new ArrayList<>();
|
|
|
- for (Product product : productList) {
|
|
|
- if (!StringUtils.isEmpty(component.getAttach())) {
|
|
|
- List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(product.getId());
|
|
|
- if (CollectionUtils.isNotEmpty(productPrivates)) {
|
|
|
- ProductPrivate productPrivate = productPrivates.get(0);
|
|
|
- productPrivate.setAttach(component.getAttach());
|
|
|
- productPrivatelist.add(productPrivate);
|
|
|
- } else {
|
|
|
- ProductPrivate productPrivate = new ProductPrivate();
|
|
|
- productPrivate.setAttach(component.getAttach());
|
|
|
- productPrivate.setPrId(product.getId());
|
|
|
- productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
|
|
|
- productPrivate.setBatchCount(IntegerConstant.NO_SHORT);
|
|
|
- productPrivatelist.add(productPrivate);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- if (StringUtils.isEmpty(product.getSpec()) && !StringUtils.isEmpty(component.getSpec())) {
|
|
|
- product.setSpec(component.getSpec());
|
|
|
- list.add(product);
|
|
|
+ final Runnable runnable = new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ List<Product> productList = productDao.findByCmpUuId(component.getUuid());
|
|
|
+ List<Product> list = new ArrayList<>();
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ for (Product product : productList) {
|
|
|
+ if (!StringUtils.isEmpty(component.getAttach())) {
|
|
|
+ ids.add(product.getId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(product.getSpec()) && !StringUtils.isEmpty(component.getSpec())) {
|
|
|
+ product.setSpec(component.getSpec());
|
|
|
+ list.add(product);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(ids)) {
|
|
|
+ List<ProductPrivate> productPrivates = productPrivateDao.findByPrIds(ids);
|
|
|
+ boolean isExist = false;
|
|
|
+ List<ProductPrivate> productPrivatelist = new ArrayList<>();
|
|
|
+ for (Long id : ids) {
|
|
|
+ isExist = false;
|
|
|
+ for (ProductPrivate productPrivate : productPrivates) {
|
|
|
+ if (id.longValue() == productPrivate.getPrId().longValue()) {
|
|
|
+ productPrivate.setAttach(component.getAttach());
|
|
|
+ productPrivatelist.add(productPrivate);
|
|
|
+ isExist = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!isExist) {
|
|
|
+ ProductPrivate productPrivate = new ProductPrivate(id);
|
|
|
+ productPrivate.setAttach(component.getAttach());
|
|
|
+ productPrivatelist.add(productPrivate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(productPrivatelist)) {
|
|
|
+ productPrivateDao.save(productPrivatelist);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ productDao.save(list);
|
|
|
+ }
|
|
|
+ goodsService.updateGoodsByComponent(component);
|
|
|
}
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ executor.submitTask(runnable);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- if (CollectionUtils.isNotEmpty(productPrivatelist)) {
|
|
|
- productPrivateDao.save(productPrivatelist);
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(list)) {
|
|
|
- productDao.save(list);
|
|
|
- }
|
|
|
|
|
|
- goodsService.updateGoodsByComponent(component);
|
|
|
+
|
|
|
return ResultMap.success("");
|
|
|
} else {
|
|
|
return ResultMap.success("");
|