|
|
@@ -12,6 +12,7 @@ import com.uas.platform.b2c.common.account.dao.EnterpriseDao;
|
|
|
import com.uas.platform.b2c.common.account.model.Enterprise;
|
|
|
import com.uas.platform.b2c.common.account.model.User;
|
|
|
import com.uas.platform.b2c.common.account.service.EnterpriseService;
|
|
|
+import com.uas.platform.b2c.common.base.dao.CommonDao;
|
|
|
import com.uas.platform.b2c.common.search.service.SearcherService;
|
|
|
import com.uas.platform.b2c.core.config.SysConf;
|
|
|
import com.uas.platform.b2c.core.constant.ShortConstant;
|
|
|
@@ -75,6 +76,8 @@ import com.uas.platform.b2c.prod.product.kind.model.Kind;
|
|
|
import com.uas.platform.b2c.prod.product.kind.model.KindInfo;
|
|
|
import com.uas.platform.b2c.prod.product.kind.service.KindService;
|
|
|
import com.uas.platform.b2c.prod.store.dao.StoreInDao;
|
|
|
+import com.uas.platform.b2c.prod.store.model.BrandCount;
|
|
|
+import com.uas.platform.b2c.prod.store.model.KindHierarchicalCount;
|
|
|
import com.uas.platform.b2c.prod.store.model.StoreIn;
|
|
|
import com.uas.platform.b2c.prod.store.model.StoreStatus;
|
|
|
import com.uas.platform.b2c.prod.store.service.StoreInService;
|
|
|
@@ -144,6 +147,7 @@ import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
@@ -161,8 +165,11 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
+import java.util.concurrent.Callable;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.Future;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@@ -272,8 +279,8 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
@Autowired
|
|
|
private FloorsService floorsService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ProductDetailDao productDetailDao;
|
|
|
+ @Autowired
|
|
|
+ private ProductDetailDao productDetailDao;
|
|
|
|
|
|
@Autowired
|
|
|
private OrderDetailService orderDetailService;
|
|
|
@@ -297,6 +304,9 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
@Autowired
|
|
|
private EnterpriseService enterpriseService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CommonDao commonDao;
|
|
|
+
|
|
|
private final Logger logger = LoggerFactory.getLogger(GoodsServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
@@ -325,8 +335,8 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
throw new IllegalOperatorException("商品信息Goods不能为空");
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(goods.getSpec())) {
|
|
|
- String spec = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutStringIgnoreEncode(goods.getSpec().toString(), UploadConstant.SPEC_MAX_BYTE);
|
|
|
- goods.setSpec(spec);
|
|
|
+ String spec = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutStringIgnoreEncode(goods.getSpec().toString(), UploadConstant.SPEC_MAX_BYTE);
|
|
|
+ goods.setSpec(spec);
|
|
|
}
|
|
|
if (goods.getCurrencyName() == null) {
|
|
|
throw new IllegalOperatorException("必须选择一种币别");
|
|
|
@@ -544,24 +554,24 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
}
|
|
|
Double reserve = goods.getReserve() - number;
|
|
|
|
|
|
- goods.setReserve(reserve);
|
|
|
- // 检查是否小于最小发货量
|
|
|
- if (reserve.doubleValue() < goods.getMinBuyQty().doubleValue()) {
|
|
|
- goods.setStatus(Status.UNAVAILABLE.value());
|
|
|
- }
|
|
|
- goodsDao.modifyReserve(goods.getBatchCode(), goods.getUuid(), goods.getReserve(), goods.getStatus().intValue());
|
|
|
- // 每次批次保存同时保存一遍历史信息
|
|
|
- GoodsHistory goodsHistory = goodsHistoryService.converTGoodsHist(goods, GoodsHistory.OperateType.DeductReserve.getPhrase(), false);
|
|
|
- goodsHistoryService.save(goodsHistory);
|
|
|
- // 更新器件属性的库存
|
|
|
- updateComponentTradeInfos(goods.getUuid());
|
|
|
-
|
|
|
- // 扣除库存时,同步产品推荐的信息
|
|
|
- if (Status.UNAVAILABLE.value() == goods.getStatus()) {
|
|
|
+ goods.setReserve(reserve);
|
|
|
+ // 检查是否小于最小发货量
|
|
|
+ if (reserve.doubleValue() < goods.getMinBuyQty().doubleValue()) {
|
|
|
+ goods.setStatus(Status.UNAVAILABLE.value());
|
|
|
+ }
|
|
|
+ goodsDao.modifyReserve(goods.getBatchCode(), goods.getUuid(), goods.getReserve(), goods.getStatus().intValue());
|
|
|
+ // 每次批次保存同时保存一遍历史信息
|
|
|
+ GoodsHistory goodsHistory = goodsHistoryService.converTGoodsHist(goods, GoodsHistory.OperateType.DeductReserve.getPhrase(), false);
|
|
|
+ goodsHistoryService.save(goodsHistory);
|
|
|
+ // 更新器件属性的库存
|
|
|
+ updateComponentTradeInfos(goods.getUuid());
|
|
|
+
|
|
|
+ // 扣除库存时,同步产品推荐的信息
|
|
|
+ if (Status.UNAVAILABLE.value() == goods.getStatus()) {
|
|
|
recommendProductService.updateRecommendProductInfo(goods);
|
|
|
- }
|
|
|
- return ResultMap.success(null);
|
|
|
- }
|
|
|
+ }
|
|
|
+ return ResultMap.success(null);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 释放库存
|
|
|
@@ -746,37 +756,37 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
return backGoods;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public Goods publish(Goods goods, String deviceInfo, Product product) {
|
|
|
- ProductDetail productDetail = productDetailDao.findByProductId(product.getId());
|
|
|
- if (productDetail == null) {
|
|
|
- productDetail = new ProductDetail();
|
|
|
- } else if (product.getErpReserve() != null) {
|
|
|
- ProductDetail newProductDetail = productService.findByProductId(product.getId());
|
|
|
- if (product.getErpReserve() < goods.getReserve() + newProductDetail.getB2cReserve()) {
|
|
|
- throw new IllegalOperatorException("本次上架数量和已上架数量之和不可超过ERP空闲库存数量");
|
|
|
- }
|
|
|
- }
|
|
|
- productDetail.convertFromGoods(goods, product);
|
|
|
- productDetailDao.save(productDetail);
|
|
|
- Goods saveGoods = publish(goods, deviceInfo);
|
|
|
- return saveGoods;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public List<Goods> publish(List<Goods> goodses, String deviceInfo) {
|
|
|
- Set<String> uuids = new HashSet<String>();
|
|
|
- List<Goods> list = new ArrayList<Goods>();
|
|
|
- System.out.println("执行了publishByBatch-------start");
|
|
|
- publishByBatch(goodses, uuids, list);
|
|
|
- System.out.println("执行了publishByBatch-----end");
|
|
|
- for (String uuid : uuids) {
|
|
|
- updateComponentTradeInfos(uuid);
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Goods publish(Goods goods, String deviceInfo, Product product) {
|
|
|
+ ProductDetail productDetail = productDetailDao.findByProductId(product.getId());
|
|
|
+ if (productDetail == null) {
|
|
|
+ productDetail = new ProductDetail();
|
|
|
+ } else if (product.getErpReserve() != null) {
|
|
|
+ ProductDetail newProductDetail = productService.findByProductId(product.getId());
|
|
|
+ if (product.getErpReserve() < goods.getReserve() + newProductDetail.getB2cReserve()) {
|
|
|
+ throw new IllegalOperatorException("本次上架数量和已上架数量之和不可超过ERP空闲库存数量");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ productDetail.convertFromGoods(goods, product);
|
|
|
+ productDetailDao.save(productDetail);
|
|
|
+ Goods saveGoods = publish(goods, deviceInfo);
|
|
|
+ return saveGoods;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public List<Goods> publish(List<Goods> goodses, String deviceInfo) {
|
|
|
+ Set<String> uuids = new HashSet<String>();
|
|
|
+ List<Goods> list = new ArrayList<Goods>();
|
|
|
+ System.out.println("执行了publishByBatch-------start");
|
|
|
+ publishByBatch(goodses, uuids, list);
|
|
|
+ System.out.println("执行了publishByBatch-----end");
|
|
|
+ for (String uuid : uuids) {
|
|
|
+ updateComponentTradeInfos(uuid);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 批量更新库存信息 辅助方法
|
|
|
@@ -927,37 +937,37 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
public void updateComponentTradeInfos(final String uuid) {
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 导入Excel发布产品
|
|
|
- *
|
|
|
- * @author hejq
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ModelMap publishByWorkbook(Workbook workbook) {
|
|
|
- ModelMap modelMap = new ModelMap();
|
|
|
- List<String> alters = new ArrayList<String>();
|
|
|
- List<Goods> goodses = new ArrayList<Goods>();
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
- int rowNum = sheet.getLastRowNum();
|
|
|
- if(rowNum > 2000) {
|
|
|
- throw new IllegalOperatorException
|
|
|
- ("信息超过2000条,请拆分成2000条以内");
|
|
|
- }
|
|
|
- Row headerRow = sheet.getRow(0);
|
|
|
- try {
|
|
|
- if (headerRow != null) {
|
|
|
- for (int r = 1; r <= rowNum; r++) {
|
|
|
- Row row = sheet.getRow(r);
|
|
|
- if (row != null && row.getCell(3) != null) {
|
|
|
- Goods goods = new Goods();
|
|
|
- if (row.getCell(3) == null) {
|
|
|
- throw new IllegalOperatorException("请上传从第一步操作中下载的发布模板");
|
|
|
- }
|
|
|
- String uuid = row.getCell(3).getStringCellValue();
|
|
|
- if (StringUtils.isEmpty(uuid)) {
|
|
|
- throw new IllegalOperatorException("请上传从商城下载的批量发布模板");
|
|
|
- }
|
|
|
- goods.setUuid(uuid);
|
|
|
+ /**
|
|
|
+ * 导入Excel发布产品
|
|
|
+ *
|
|
|
+ * @author hejq
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap publishByWorkbook(Workbook workbook) {
|
|
|
+ ModelMap modelMap = new ModelMap();
|
|
|
+ List<String> alters = new ArrayList<String>();
|
|
|
+ List<Goods> goodses = new ArrayList<Goods>();
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ if(rowNum > 2000) {
|
|
|
+ throw new IllegalOperatorException
|
|
|
+ ("信息超过2000条,请拆分成2000条以内");
|
|
|
+ }
|
|
|
+ Row headerRow = sheet.getRow(0);
|
|
|
+ try {
|
|
|
+ if (headerRow != null) {
|
|
|
+ for (int r = 1; r <= rowNum; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+ if (row != null && row.getCell(3) != null) {
|
|
|
+ Goods goods = new Goods();
|
|
|
+ if (row.getCell(3) == null) {
|
|
|
+ throw new IllegalOperatorException("请上传从第一步操作中下载的发布模板");
|
|
|
+ }
|
|
|
+ String uuid = row.getCell(3).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(uuid)) {
|
|
|
+ throw new IllegalOperatorException("请上传从商城下载的批量发布模板");
|
|
|
+ }
|
|
|
+ goods.setUuid(uuid);
|
|
|
|
|
|
// 产品uuid
|
|
|
String cmpCode = row.getCell(2).getStringCellValue();
|
|
|
@@ -1568,16 +1578,16 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
List<GoodsBrowsingHistory> browsingHistories = browsingHistoryService.updateGoodsBrowsingHistoryByGoods(nowGoods);
|
|
|
updateGoodsRelateInfo(orders, cartList, browsingHistories, null, history, nowGoods);
|
|
|
|
|
|
- //更新店铺推荐的信息
|
|
|
- if(isChangeSaleType) { // 如果切换了销售方式
|
|
|
- Set<String> uuids = new HashSet<>();
|
|
|
- uuids.add(nowGoods.getBatchCode());
|
|
|
- recommendProductService.deleteProductsWhenSellerUpdateReserve(storeuuid, uuids);
|
|
|
- } else {
|
|
|
+ //更新店铺推荐的信息
|
|
|
+ if(isChangeSaleType) { // 如果切换了销售方式
|
|
|
+ Set<String> uuids = new HashSet<>();
|
|
|
+ uuids.add(nowGoods.getBatchCode());
|
|
|
+ recommendProductService.deleteProductsWhenSellerUpdateReserve(storeuuid, uuids);
|
|
|
+ } else {
|
|
|
recommendProductService.updateRecommendProductInfo(nowGoods);
|
|
|
}
|
|
|
- return nowGoods;
|
|
|
- }
|
|
|
+ return nowGoods;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 用户更新在售产品的信息, 设置店铺名称
|
|
|
@@ -2362,17 +2372,17 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
return ResultMap.success(commodity);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ResultMap offShelfGoodsByProvider(String batchCodes, String downMsg, Boolean isERP) {
|
|
|
- if (StringUtils.isEmpty(batchCodes)) {
|
|
|
- return new ResultMap(CodeType.NO_INFO.code(), "待下架批次号字符串不能为空");
|
|
|
- }
|
|
|
- String[] batchCodeArr = batchCodes.split(",");
|
|
|
- if (batchCodeArr.length == 0) {
|
|
|
- return new ResultMap(CodeType.NO_INFO.code(), "待下架批次号不能为空");
|
|
|
- }
|
|
|
- Set<String> uuids = new HashSet<>();
|
|
|
- List<String> batchCodeList = new ArrayList<>();
|
|
|
+ @Override
|
|
|
+ public ResultMap offShelfGoodsByProvider(String batchCodes, String downMsg, Boolean isERP) {
|
|
|
+ if (StringUtils.isEmpty(batchCodes)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO.code(), "待下架批次号字符串不能为空");
|
|
|
+ }
|
|
|
+ String[] batchCodeArr = batchCodes.split(",");
|
|
|
+ if (batchCodeArr.length == 0) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO.code(), "待下架批次号不能为空");
|
|
|
+ }
|
|
|
+ Set<String> uuids = new HashSet<>();
|
|
|
+ List<String> batchCodeList = new ArrayList<>();
|
|
|
|
|
|
List<Goods> list = new ArrayList<>();
|
|
|
for (String batchCode : batchCodeArr) {
|
|
|
@@ -2484,11 +2494,11 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
goodsHistoryService.save(goodsHist);
|
|
|
|
|
|
Goods updateGoods = goodsDao.save(goods);
|
|
|
- //下架对应的批次 目前确定下架之后不做删除动作。
|
|
|
- // goodsDao.deleteByBatchCode(goods.getBatchCode());
|
|
|
- // 需要替换首页的信息。
|
|
|
- return ResultMap.success(updateGoods);
|
|
|
- }
|
|
|
+ //下架对应的批次 目前确定下架之后不做删除动作。
|
|
|
+ // goodsDao.deleteByBatchCode(goods.getBatchCode());
|
|
|
+ // 需要替换首页的信息。
|
|
|
+ return ResultMap.success(updateGoods);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public Page<Goods> findGoodsPage(final PageInfo info) {
|
|
|
@@ -3006,7 +3016,7 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
uuids.add(goods.getUuid());
|
|
|
}
|
|
|
|
|
|
- goodsDao.save(goodsUpdate);
|
|
|
+ goodsDao.save(goodsUpdate);
|
|
|
goodsHistoryDao.save(histories);
|
|
|
for (String uuid : uuids) {
|
|
|
updateComponentTradeInfos(uuid);
|
|
|
@@ -3052,29 +3062,29 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
return ResultMap.success(goods);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 更新库存的相关信息
|
|
|
- *
|
|
|
- * @param orders 订单
|
|
|
- * @param carts 购物车信息
|
|
|
- * @param browsingHistoryList 浏览历史
|
|
|
- * @param product 产品
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public ResultMap updateGoodsRelateInfo(List<Order> orders, List<Cart> carts, List<GoodsBrowsingHistory> browsingHistoryList, Product product, GoodsHistory goodsHistory, Goods goods) {
|
|
|
- goodsDao.save(goods);
|
|
|
- orderDao.save(orders);
|
|
|
- orderService.save(orders);
|
|
|
- cartService.saveCart(carts);
|
|
|
- browsingHistoryService.saveGoodsBrowsingHistoryList(browsingHistoryList);
|
|
|
- goodsHistoryService.save(goodsHistory);
|
|
|
- return ResultMap.success(null);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void addVisitCount(String batchCode) {
|
|
|
+ /**
|
|
|
+ * 更新库存的相关信息
|
|
|
+ *
|
|
|
+ * @param orders 订单
|
|
|
+ * @param carts 购物车信息
|
|
|
+ * @param browsingHistoryList 浏览历史
|
|
|
+ * @param product 产品
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public ResultMap updateGoodsRelateInfo(List<Order> orders, List<Cart> carts, List<GoodsBrowsingHistory> browsingHistoryList, Product product, GoodsHistory goodsHistory, Goods goods) {
|
|
|
+ goodsDao.save(goods);
|
|
|
+ orderDao.save(orders);
|
|
|
+ orderService.save(orders);
|
|
|
+ cartService.saveCart(carts);
|
|
|
+ browsingHistoryService.saveGoodsBrowsingHistoryList(browsingHistoryList);
|
|
|
+ goodsHistoryService.save(goodsHistory);
|
|
|
+ return ResultMap.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addVisitCount(String batchCode) {
|
|
|
goodsDao.addVisitCount(batchCode);
|
|
|
}
|
|
|
|
|
|
@@ -3262,6 +3272,7 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
@Override
|
|
|
public void deleteGoods(List<Goods> goodses) {
|
|
|
try {
|
|
|
+ final Long userUU = SystemSession.getUser().getUserUU();
|
|
|
executor.submitTask(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
@@ -3272,11 +3283,13 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
if (goodse.getStatus().equals(Status.AVAILABLE.value()) || goodse.getStatus().equals(Status.UNAVAILABLE.value())) {
|
|
|
goodse.setStatus(Status.REMOVED.value());
|
|
|
GoodsHistory goodsHistoryRemoved = goodsHistoryService.converTGoodsHist(goodse, OperateType.Down.getPhrase(), false);
|
|
|
+ goodsHistoryRemoved.setOperateUU(userUU);
|
|
|
histories.add(goodsHistoryRemoved);
|
|
|
}
|
|
|
//删除库存信息
|
|
|
goodse.setStatus(Status.DELETED.value());
|
|
|
GoodsHistory goodsHistoryDelete = goodsHistoryService.converTGoodsHist(goodse, OperateType.DELETE.getPhrase(),false);
|
|
|
+ goodsHistoryDelete.setOperateUU(userUU);
|
|
|
histories.add(goodsHistoryDelete);
|
|
|
goodses1.add(goodse);
|
|
|
}
|
|
|
@@ -3437,13 +3450,25 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
public Goods getGoodsById(Long id) {
|
|
|
Goods goods = goodsDao.findOne(id);
|
|
|
if (goods != null) {
|
|
|
- if (sysConf.getStoreid().equals(goods.getStoreid())) {
|
|
|
- goods.setSelfSale("寄售");
|
|
|
- } else {
|
|
|
- goods.setSelfSale("自营");
|
|
|
- }
|
|
|
- goods.setFrozen(getFrozenCount(goods.getBatchCode()));
|
|
|
+ goods = covertGoodsInfo(goods);
|
|
|
}
|
|
|
+ return goods;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 封装goods信息
|
|
|
+ *
|
|
|
+ * @param goods goods
|
|
|
+ * @return Goods
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Goods covertGoodsInfo(Goods goods) {
|
|
|
+ if (sysConf.getStoreid().equals(goods.getStoreid())) {
|
|
|
+ goods.setSelfSale("寄售");
|
|
|
+ } else {
|
|
|
+ goods.setSelfSale("自营");
|
|
|
+ }
|
|
|
+ goods.setFrozen(getFrozenCount(goods.getBatchCode()));
|
|
|
if (StringUtils.isEmpty(goods.getAttach()) && goods.getUuid() != null) {
|
|
|
Component component = componentDao.findByUuid(goods.getUuid());
|
|
|
if (component != null) {
|
|
|
@@ -3499,33 +3524,56 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
return String.valueOf(goodses.size());
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Page<Goods> getPageDataOfBackground(final PageInfo info, GoodsFilter goodsFilter) {
|
|
|
- if (info == null) {
|
|
|
- throw new IllegalOperatorException("分页参数丢失");
|
|
|
- }
|
|
|
- if (goodsFilter != null) {
|
|
|
- convertPageInfo(info, goodsFilter);
|
|
|
- }
|
|
|
- Page<Goods> page = goodsDao.findAll(new Specification<Goods>() {
|
|
|
- @Override
|
|
|
- public Predicate toPredicate(Root<Goods> root, CriteriaQuery<?> query,
|
|
|
- CriteriaBuilder builder) {
|
|
|
- query.where(info.getPredicates(root, query, builder));
|
|
|
- return null;
|
|
|
- }
|
|
|
- }, info);
|
|
|
+ @Override
|
|
|
+ public Page<Goods> getPageDataOfBackground(final PageInfo info, GoodsFilter goodsFilter) {
|
|
|
+ if (info == null) {
|
|
|
+ throw new IllegalOperatorException("分页参数丢失");
|
|
|
+ }
|
|
|
+ if (goodsFilter != null) {
|
|
|
+ convertPageInfo(info, goodsFilter);
|
|
|
+ }
|
|
|
+ Page<Goods> page = goodsDao.findAll((Root<Goods> root, CriteriaQuery<?> query, CriteriaBuilder builder)
|
|
|
+ -> query.where(info.getPredicates(root, query, builder)).getRestriction(), info);
|
|
|
List<Goods> goodsList = page.getContent();
|
|
|
for (Goods goods : goodsList) {
|
|
|
- if (sysConf.getStoreid().equals(goods.getStoreid())) {
|
|
|
- goods.setSelfSale(StringConstant.CONSIGNMENT);
|
|
|
- } else {
|
|
|
- goods.setSelfSale(StringConstant.SALE_SELF);
|
|
|
+ defineGoodsInfo(goods);
|
|
|
+ }
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 给goods赋值
|
|
|
+ *
|
|
|
+ * @param goods goods
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void defineGoodsInfo(Goods goods) {
|
|
|
+ if (sysConf.getStoreid().equals(goods.getStoreid())) {
|
|
|
+ goods.setSelfSale(StringConstant.CONSIGNMENT);
|
|
|
+ } else {
|
|
|
+ goods.setSelfSale(StringConstant.SALE_SELF);
|
|
|
+ }
|
|
|
+ goods.setFrozen(getFrozenCount(goods.getBatchCode()));
|
|
|
+ List<GoodsQtyPrice> prices = goods.getPrices();
|
|
|
+ if (CollectionUtils.isNotEmpty(prices)) {
|
|
|
+ int size = prices.size();
|
|
|
+ StringBuffer gradeBuffer = new StringBuffer();
|
|
|
+ StringBuffer priceBuffer = new StringBuffer();
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ if (gradeBuffer.length() > 0) {
|
|
|
+ gradeBuffer.append("\n");
|
|
|
+ priceBuffer.append("\n");
|
|
|
+ }
|
|
|
+ String priceEnd = i + 1 == size ? "以上" : prices.get(i).getEnd().toString();
|
|
|
+ gradeBuffer.append(prices.get(i).getStart()).append("-").append(priceEnd);
|
|
|
+ String currencyName = StringConstant.RMB.equals(goods.getCurrencyName()) ? "¥" : "$";
|
|
|
+ Double price = StringConstant.RMB.equals(goods.getCurrencyName()) ? prices.get(i).getRMBPrice() : prices.get(i).getUSDPrice();
|
|
|
+ priceBuffer.append(currencyName).append(price);
|
|
|
}
|
|
|
- goods.setFrozen(getFrozenCount(goods.getBatchCode()));
|
|
|
+ goods.setPriceGradeStr(gradeBuffer.toString());
|
|
|
+ goods.setPriceStr(priceBuffer.toString());
|
|
|
}
|
|
|
- return page;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 根据店铺id查找店铺所属企业enUU
|
|
|
@@ -3606,7 +3654,9 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
|
|
|
return goodsPage;
|
|
|
}
|
|
|
- private int getFrozenCount(String batchCode) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getFrozenCount(String batchCode) {
|
|
|
String statusStr = OrderStatus.TOBEPAID.getCodes() + SplitChar.HYPHEN + OrderStatus.TOBEDELIVER.getCodes();
|
|
|
List<Integer> statusList = new ArrayList<>();
|
|
|
for (String str : statusStr.split(SplitChar.HYPHEN)) {
|
|
|
@@ -3620,17 +3670,32 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
return stock;
|
|
|
}
|
|
|
|
|
|
- private void convertPageInfo(PageInfo info, GoodsFilter goodsFilter) {
|
|
|
- if (!StringUtils.isEmpty(goodsFilter.getCode())) {
|
|
|
- info.filter("code", goodsFilter.getCode());
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(goodsFilter.getBrand())) {
|
|
|
- SimpleExpression[] brandExpression = new SimpleExpression[2];
|
|
|
- brandExpression[0] = PredicateUtils.like("brandNameCn", goodsFilter.getBrand(), false, true);
|
|
|
- brandExpression[1] = PredicateUtils.like("brandNameEn", goodsFilter.getBrand(), false, true);
|
|
|
- info.expression(PredicateUtils.or((CriterionExpression[]) brandExpression));
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(goodsFilter.getStore())) {
|
|
|
+ /**
|
|
|
+ * 封装分页过滤条件
|
|
|
+ *
|
|
|
+ * @param info 分页信息
|
|
|
+ * @param goodsFilter 筛选条件
|
|
|
+ */
|
|
|
+ private void convertPageInfo(PageInfo info, GoodsFilter goodsFilter) {
|
|
|
+ if (!StringUtils.isEmpty(goodsFilter.getStartTime())) {
|
|
|
+ java.sql.Date startDate = new java.sql.Date(goodsFilter.getStartTime());
|
|
|
+ info.expression(PredicateUtils.gte("createdDate", startDate, true));
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(goodsFilter.getEndTime())) {
|
|
|
+ // 截止日期是到当天23:59:59,java.sql.Date精确到天,这里采用加一天小于的方法设置截止日期判断
|
|
|
+ java.sql.Date endDate = new java.sql.Date(goodsFilter.getEndTime() + IntegerConstant.ONE_DAY_MILLISECONDS);
|
|
|
+ info.expression(PredicateUtils.lt("createdDate", endDate, true));
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(goodsFilter.getCode())) {
|
|
|
+ info.filter("code", goodsFilter.getCode());
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(goodsFilter.getBrand())) {
|
|
|
+ SimpleExpression[] brandExpression = new SimpleExpression[2];
|
|
|
+ brandExpression[0] = PredicateUtils.like("brandNameCn", goodsFilter.getBrand(), false, true);
|
|
|
+ brandExpression[1] = PredicateUtils.like("brandNameEn", goodsFilter.getBrand(), false, true);
|
|
|
+ info.expression(PredicateUtils.or((CriterionExpression[]) brandExpression));
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(goodsFilter.getStore())) {
|
|
|
if (RegexConstant.onlyHaveNumber(goodsFilter.getStore())) {
|
|
|
SimpleExpression[] storeExpression = new SimpleExpression[2];
|
|
|
storeExpression[0] = PredicateUtils.eq("enUU", goodsFilter.getStore(), true);
|
|
|
@@ -3639,8 +3704,8 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
} else {
|
|
|
info.filter("storeName", goodsFilter.getStore());
|
|
|
}
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(goodsFilter.getKindUuid())) {
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(goodsFilter.getKindUuid())) {
|
|
|
// 如果包含多个叶子类目ID,则获取所有的叶子类目对应的商品信息
|
|
|
if (goodsFilter.getKindUuid().contains(SplitChar.COMMA)) {
|
|
|
String[] kindIds = goodsFilter.getKindUuid().split(SplitChar.COMMA);
|
|
|
@@ -3649,21 +3714,21 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
info.expression(PredicateUtils.eq("kindUuid", goodsFilter.getKindUuid(), false));
|
|
|
}
|
|
|
}
|
|
|
- if (!StringUtils.isEmpty(goodsFilter.getCurrency())) {
|
|
|
- info.expression(PredicateUtils.eq("currencyName", goodsFilter.getCurrency(), false));
|
|
|
- }
|
|
|
- if (goodsFilter.getSaleSelf() != null) {
|
|
|
- if (goodsFilter.getSaleSelf()) {
|
|
|
- info.expression(PredicateUtils.ne("storeid", sysConf.getStoreid(), false));
|
|
|
- } else {
|
|
|
- info.expression(PredicateUtils.eq("storeid", sysConf.getStoreid(), false));
|
|
|
- }
|
|
|
- }
|
|
|
- if (goodsFilter.getBreakUp() != null) {
|
|
|
+ if (!StringUtils.isEmpty(goodsFilter.getCurrency())) {
|
|
|
+ info.expression(PredicateUtils.eq("currencyName", goodsFilter.getCurrency(), false));
|
|
|
+ }
|
|
|
+ if (goodsFilter.getSaleSelf() != null) {
|
|
|
+ if (goodsFilter.getSaleSelf()) {
|
|
|
+ info.expression(PredicateUtils.ne("storeid", sysConf.getStoreid(), false));
|
|
|
+ } else {
|
|
|
+ info.expression(PredicateUtils.eq("storeid", sysConf.getStoreid(), false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (goodsFilter.getBreakUp() != null) {
|
|
|
int breakUp = goodsFilter.getBreakUp() ? 1 : 0;
|
|
|
- info.filter("breakUp", breakUp, false);
|
|
|
- }
|
|
|
- if (goodsFilter.getHaveImg() != null) {
|
|
|
+ info.filter("breakUp", breakUp, false);
|
|
|
+ }
|
|
|
+ if (goodsFilter.getHaveImg() != null) {
|
|
|
if (goodsFilter.getHaveImg()) {
|
|
|
info.expression(PredicateUtils.isNotNull("img"));
|
|
|
} else {
|
|
|
@@ -3672,9 +3737,11 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
}
|
|
|
if (goodsFilter.getStandard() != null) {
|
|
|
if (goodsFilter.getStandard()) {
|
|
|
- info.expression(PredicateUtils.isNotNull("uuid"));
|
|
|
+ info.expression(PredicateUtils.and(PredicateUtils.isNotNull("uuid"),
|
|
|
+ PredicateUtils.ne("uuid", StringConstant.BLANK, true)));
|
|
|
} else {
|
|
|
- info.expression(PredicateUtils.isNull("uuid"));
|
|
|
+ info.expression(PredicateUtils.or(PredicateUtils.isNull("uuid"),
|
|
|
+ PredicateUtils.eq("uuid", StringConstant.BLANK, true)));
|
|
|
}
|
|
|
}
|
|
|
if (goodsFilter.getAudited() != null) {
|
|
|
@@ -3692,7 +3759,7 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
statusSet.add(goodsFilter.getSaleStatus());
|
|
|
}
|
|
|
}
|
|
|
- if (goodsFilter.getSaleNum() != null && 603 != goodsFilter.getSaleNum()) {
|
|
|
+ if (goodsFilter.getSaleNum() != null && Status.HAS_NO_INVENTORY.value() != goodsFilter.getSaleNum()) {
|
|
|
statusSet.add(goodsFilter.getSaleNum());
|
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(statusSet)) {
|
|
|
@@ -3704,10 +3771,10 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
info.expression(PredicateUtils.or((CriterionExpression[]) statusExpression));
|
|
|
}
|
|
|
}
|
|
|
- if (goodsFilter.getSaleNum() != null && 603 == goodsFilter.getSaleNum()) {
|
|
|
+ if (goodsFilter.getSaleNum() != null && Status.HAS_NO_INVENTORY.value() == goodsFilter.getSaleNum()) {
|
|
|
info.expression(PredicateUtils.eq("reserve", 0, true));
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public Map<String, List<Goods>> getCmsPcb() {
|
|
|
@@ -4033,4 +4100,175 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
}
|
|
|
return product;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过分成参数获取品牌数量
|
|
|
+ *
|
|
|
+ * @param pageable 分页信息
|
|
|
+ * @param endTime 截止时间
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @return Page<BrandCount>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public com.uas.sso.support.Page<BrandCount> getBrandProductsCount(Pageable pageable, Date startTime, Date endTime) {
|
|
|
+ StringBuffer sql = new StringBuffer("select pr_brand as brand, count(1) as count from products where pr_brand is not null ");
|
|
|
+ if (null != startTime) {
|
|
|
+ sql.append(" and pr_create_time >= '").append(new java.sql.Date(startTime.getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (null != endTime) {
|
|
|
+ sql.append(" and pr_create_time < '").append(new java.sql.Date(endTime.getTime() + IntegerConstant.ONE_DAY_MILLISECONDS) ).append("' ");
|
|
|
+ }
|
|
|
+ sql.append("group by pr_brand");
|
|
|
+ StringBuffer countSql = new StringBuffer("select count(1) from (").append(sql).append(") as a");
|
|
|
+ Integer count = commonDao.queryForObject(countSql.toString(), Integer.class);
|
|
|
+ // 分页参数
|
|
|
+ Integer offset = (pageable.getPageNumber() - 1) * pageable.getPageSize();
|
|
|
+ sql.append(" limit ? offset ?");
|
|
|
+ List<BrandCount> brandCountList = commonDao.query(sql.toString(), BrandCount.class, pageable.getPageSize(), offset);
|
|
|
+ return new com.uas.sso.support.Page<>(pageable.getPageNumber(), pageable.getPageSize(), brandCountList, count);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过分页参数获取类目数量
|
|
|
+ *
|
|
|
+ * @param pageable 分页参数
|
|
|
+ * @param endTime 截止时间
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @return Page<KindHierarchicalCount>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public com.uas.sso.support.Page<KindHierarchicalCount> getKindProductsCount(Pageable pageable, Date startTime, Date endTime) {
|
|
|
+ // 查询一段时间内类目数量,按类目分组查询统计数量
|
|
|
+ StringBuffer sql = new StringBuffer("select pr_kind as thirdKind, pr_kindid as kindId, count(1) as count from products where pr_kind is not null ");
|
|
|
+
|
|
|
+ // 根据物料创建时间筛选
|
|
|
+ if (null != startTime) {
|
|
|
+ sql.append(" and pr_create_time >= '").append(new java.sql.Date(startTime.getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (null != endTime) {
|
|
|
+ sql.append(" and pr_create_time < '").append(new java.sql.Date(endTime.getTime() + IntegerConstant.ONE_DAY_MILLISECONDS)).append("' ");
|
|
|
+ }
|
|
|
+ sql.append("group by pr_kind, pr_kindid");
|
|
|
+
|
|
|
+ // 统计数量
|
|
|
+ StringBuffer countSql = new StringBuffer("select count(1) from (").append(sql).append(") as a");
|
|
|
+ Integer count = commonDao.queryForObject(countSql.toString(), Integer.class);
|
|
|
+
|
|
|
+ // 分页参数
|
|
|
+ Integer offset = (pageable.getPageNumber() - 1) * pageable.getPageSize();
|
|
|
+ sql.append(" limit ? offset ?");
|
|
|
+ List<KindHierarchicalCount> kindList = commonDao.query(sql.toString(), KindHierarchicalCount.class, pageable.getPageSize(), offset);
|
|
|
+
|
|
|
+ // 根据父级类目id一层层判断是否存在
|
|
|
+ if (CollectionUtils.isNotEmpty(kindList)) {
|
|
|
+ kindList.stream().filter(kind -> null != kind.getKindId())
|
|
|
+ .forEach(kind -> {
|
|
|
+ KindInfo kindInfo = kindInfoDao.findOne(kind.getKindId());
|
|
|
+ if (null != kindInfo && null != kindInfo.getParentid() && 0 != kindInfo.getParentid()) {
|
|
|
+ KindInfo parentKind = kindInfoDao.findOne(kindInfo.getParentid());
|
|
|
+ if (null != parentKind) {
|
|
|
+ kind.setSecondKind(parentKind.getNameCn());
|
|
|
+ if (null != parentKind.getParentid() && 0 != parentKind.getParentid()) {
|
|
|
+ KindInfo firstKind = kindInfoDao.findOne(parentKind.getParentid());
|
|
|
+ if (null != firstKind) {
|
|
|
+ kind.setFirstKind(firstKind.getNameCn());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return new com.uas.sso.support.Page<>(pageable.getPageNumber(), pageable.getPageSize(), kindList, count);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导出数据
|
|
|
+ * TODO 后续提成公共方法,暂时没写好
|
|
|
+ *
|
|
|
+ * @param info 分页信息
|
|
|
+ * @param goodsFilter 过滤条件
|
|
|
+ * @return List<Goods>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Goods> multiSearch(PageInfo info, GoodsFilter goodsFilter) {
|
|
|
+ List<Goods> goodsList = new ArrayList<>();
|
|
|
+ List<Future<List<Goods>>> futureList = new ArrayList<>();
|
|
|
+ BigDecimal pageSize = new BigDecimal(info.getPageSize());
|
|
|
+ BigDecimal pageCount = new BigDecimal(com.uas.platform.b2c.core.constant.IntegerConstant.PAGE_COUNT);
|
|
|
+ int maxPoolSize = (int) Math.ceil(pageSize.divide(pageCount).doubleValue());
|
|
|
+ ExecutorService exs = Executors.newFixedThreadPool(maxPoolSize);
|
|
|
+ for (int i = 0; i < maxPoolSize; i++) {
|
|
|
+ futureList.add(exs.submit(new CallableTask(i + 1, goodsFilter, info.getPageSize())));
|
|
|
+ }
|
|
|
+ for (Future<List<Goods>> future : futureList) {
|
|
|
+ while (true) {
|
|
|
+ if (future.isDone() && !future.isCancelled()) {
|
|
|
+ List<Goods> goods = null;
|
|
|
+ try {
|
|
|
+ goods = future.get();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ goodsList.addAll(goods);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return goodsList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private class CallableTask implements Callable<List<Goods>> {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 线程序号
|
|
|
+ */
|
|
|
+ Integer i;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 过滤条件
|
|
|
+ */
|
|
|
+ GoodsFilter goodsFilter;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页大小
|
|
|
+ */
|
|
|
+ Integer pageSize;
|
|
|
+
|
|
|
+ public CallableTask(int i, GoodsFilter goodsFilter, int pageSize) {
|
|
|
+ super();
|
|
|
+ this.i = i;
|
|
|
+ this.goodsFilter = goodsFilter;
|
|
|
+ this.pageSize = pageSize;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Computes a result, or throws an exception if unable to do so.
|
|
|
+ *
|
|
|
+ * @return computed result
|
|
|
+ * @throws Exception if unable to compute a result
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Goods> call() throws Exception {
|
|
|
+ int count = pageSize > com.uas.platform.b2c.core.constant.IntegerConstant.PAGE_COUNT ?
|
|
|
+ com.uas.platform.b2c.core.constant.IntegerConstant.PAGE_COUNT : pageSize;
|
|
|
+ PageInfo info = new PageInfo(i, count);
|
|
|
+ List<Goods> goods = getPageDataOfBackground(info, goodsFilter).getContent();
|
|
|
+ return goods;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过goods id查询goods信息
|
|
|
+ *
|
|
|
+ * @param idList goods idList
|
|
|
+ * @return List<Goods>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Goods> findByIds(List<Long> idList) {
|
|
|
+ List<Goods> goodsList = goodsDao.findAll(idList);
|
|
|
+ goodsList.forEach(goods -> defineGoodsInfo(goods));
|
|
|
+ return goodsList;
|
|
|
+ }
|
|
|
}
|