扫码点餐部分 商品循环数据问题
This commit is contained in:
parent
4c71d54ec4
commit
ae5bc911fa
|
|
@ -135,212 +135,21 @@ public class ProductService {
|
|||
Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null;
|
||||
//招牌菜
|
||||
List<TbProduct> tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId));
|
||||
if (ObjectUtil.isNotEmpty(tbProducts) && tbProducts.size() > 0) {
|
||||
tbProducts.parallelStream().forEach(it -> {
|
||||
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
|
||||
it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
|
||||
it.setCartNumber("0");
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||
|
||||
// 上下架对应的sku
|
||||
HashSet<String> specSet = new HashSet<>();
|
||||
AtomicDouble sum = new AtomicDouble(0.0);
|
||||
BigDecimal lowerPrice = null;
|
||||
for (TbProductSku item : tbProductSkus) {
|
||||
if (item.getRealSalesNumber() != null) {
|
||||
sum.addAndGet(item.getRealSalesNumber());
|
||||
}
|
||||
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
||||
lowerPrice = item.getSalePrice();
|
||||
}
|
||||
|
||||
String specSnap = item.getSpecSnap();
|
||||
if (specSnap != null) {
|
||||
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||
}
|
||||
}
|
||||
it.setStockNumber(sum.intValue());
|
||||
if (lowerPrice == null) {
|
||||
lowerPrice = BigDecimal.ZERO;
|
||||
}
|
||||
it.setLowPrice(lowerPrice);
|
||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||
if (tagSnap != null) {
|
||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||
JSONObject snapJSON;
|
||||
JSONArray finalSnap = new JSONArray();
|
||||
for (Object snap : tagSnaps) {
|
||||
snapJSON = (JSONObject) snap;
|
||||
String values = snapJSON.getString("value");
|
||||
String finalValues = "";
|
||||
if (StrUtil.isNotBlank(values)) {
|
||||
String[] valueList = values.split(",");
|
||||
for (String value : valueList) {
|
||||
if (specSet.contains(value)) {
|
||||
finalValues = finalValues + (value) + ",";
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(finalValues)) {
|
||||
finalValues = StrUtil.removeSuffix(finalValues, ",");
|
||||
snapJSON.put("value", finalValues);
|
||||
finalSnap.add(snapJSON);
|
||||
}
|
||||
}
|
||||
}
|
||||
skuResult.setTagSnap(finalSnap.toJSONString());
|
||||
}
|
||||
it.setProductSkuResult(skuResult);
|
||||
});
|
||||
}
|
||||
concurrentMap.put("hots", tbProducts);
|
||||
concurrentMap.put("hots", handleDate(tbProducts));
|
||||
List<TbProductGroup> groupList = tbProductGroupMapper.selectByShopId(shopId, id);
|
||||
if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) {
|
||||
//热销
|
||||
TbProductGroup hot = new TbProductGroup();
|
||||
hot.setName("热销");
|
||||
List<TbProduct> hots = tbProductMapper.selectHot(shopId);
|
||||
hots.parallelStream().forEach(it -> {
|
||||
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
|
||||
it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
|
||||
it.setCartNumber("0");
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||
|
||||
// 上下架对应的sku
|
||||
HashSet<String> specSet = new HashSet<>();
|
||||
AtomicDouble sum = new AtomicDouble(0.0);
|
||||
BigDecimal lowerPrice = null;
|
||||
for (TbProductSku item : tbProductSkus) {
|
||||
if (item.getRealSalesNumber() != null) {
|
||||
sum.addAndGet(item.getRealSalesNumber());
|
||||
}
|
||||
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
||||
lowerPrice = item.getSalePrice();
|
||||
}
|
||||
|
||||
String specSnap = item.getSpecSnap();
|
||||
if (specSnap != null) {
|
||||
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||
}
|
||||
}
|
||||
it.setStockNumber(sum.intValue());
|
||||
if (lowerPrice == null) {
|
||||
lowerPrice = BigDecimal.ZERO;
|
||||
}
|
||||
it.setLowPrice(lowerPrice);
|
||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||
if (tagSnap != null) {
|
||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||
JSONObject snapJSON;
|
||||
|
||||
JSONArray finalSnap = new JSONArray();
|
||||
|
||||
for (Object snap : tagSnaps) {
|
||||
snapJSON = (JSONObject) snap;
|
||||
String values = snapJSON.getString("value");
|
||||
String finalValues = "";
|
||||
|
||||
if (StrUtil.isNotBlank(values)) {
|
||||
String[] valueList = values.split(",");
|
||||
for (String value : valueList) {
|
||||
if (specSet.contains(value)) {
|
||||
finalValues = finalValues + (value) + ",";
|
||||
}
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(finalValues)) {
|
||||
finalValues = StrUtil.removeSuffix(finalValues, ",");
|
||||
snapJSON.put("value", finalValues);
|
||||
finalSnap.add(snapJSON);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
skuResult.setTagSnap(finalSnap.toJSONString());
|
||||
}
|
||||
|
||||
it.setProductSkuResult(skuResult);
|
||||
});
|
||||
hot.setProducts(hots);
|
||||
hot.setProducts(handleDate(hots));
|
||||
//商品
|
||||
groupList.parallelStream().forEach(g -> {
|
||||
String in = g.getProductIds().substring(1, g.getProductIds().length() - 1);
|
||||
|
||||
|
||||
if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) {
|
||||
// List<TbProduct> products = tbProductMapper.selectByIdIn(in);
|
||||
List<TbProduct> products = tbProductMapper.selectByIdInAndCheck(in);
|
||||
if (ObjectUtil.isNotEmpty(products) && products.size() > 0) {
|
||||
products.parallelStream().forEach(it -> {
|
||||
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
|
||||
it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
|
||||
it.setCartNumber("0");
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||
|
||||
// 上下架对应的sku
|
||||
HashSet<String> specSet = new HashSet<>();
|
||||
AtomicDouble sum = new AtomicDouble(0.0);
|
||||
BigDecimal lowerPrice = null;
|
||||
for (TbProductSku item : tbProductSkus) {
|
||||
if (item.getRealSalesNumber() != null) {
|
||||
sum.addAndGet(item.getRealSalesNumber());
|
||||
}
|
||||
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
||||
lowerPrice = item.getSalePrice();
|
||||
}
|
||||
|
||||
String specSnap = item.getSpecSnap();
|
||||
if (specSnap != null) {
|
||||
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||
}
|
||||
}
|
||||
it.setStockNumber(sum.intValue());
|
||||
if (lowerPrice == null) {
|
||||
lowerPrice = BigDecimal.ZERO;
|
||||
}
|
||||
it.setLowPrice(lowerPrice);
|
||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||
if (tagSnap != null) {
|
||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||
JSONObject snapJSON;
|
||||
|
||||
JSONArray finalSnap = new JSONArray();
|
||||
|
||||
for (Object snap : tagSnaps) {
|
||||
snapJSON = (JSONObject) snap;
|
||||
String values = snapJSON.getString("value");
|
||||
String finalValues = "";
|
||||
|
||||
if (StrUtil.isNotBlank(values)) {
|
||||
String[] valueList = values.split(",");
|
||||
for (String value : valueList) {
|
||||
if (specSet.contains(value)) {
|
||||
finalValues = finalValues + (value) + ",";
|
||||
}
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(finalValues)) {
|
||||
finalValues = StrUtil.removeSuffix(finalValues, ",");
|
||||
snapJSON.put("value", finalValues);
|
||||
finalSnap.add(snapJSON);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
skuResult.setTagSnap(finalSnap.toJSONString());
|
||||
}
|
||||
|
||||
it.setProductSkuResult(skuResult);
|
||||
});
|
||||
g.setProducts(products);
|
||||
} else {
|
||||
g.setProducts(new ArrayList<>());
|
||||
}
|
||||
|
||||
g.setProducts(handleDate(products));
|
||||
} else {
|
||||
g.setProducts(new ArrayList<>());
|
||||
}
|
||||
|
|
@ -353,6 +162,75 @@ public class ProductService {
|
|||
}
|
||||
|
||||
|
||||
public List<TbProduct> handleDate(List<TbProduct> products){
|
||||
if (!CollectionUtils.isEmpty(products)) {
|
||||
products.parallelStream().forEach(it -> {
|
||||
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
|
||||
it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
|
||||
//购物车数量
|
||||
it.setCartNumber("0");
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||
|
||||
// 上下架对应的sku
|
||||
HashSet<String> specSet = new HashSet<>();
|
||||
AtomicDouble sum = new AtomicDouble(0.0);
|
||||
BigDecimal lowerPrice = null;
|
||||
for (TbProductSku item : tbProductSkus) {
|
||||
if (item.getRealSalesNumber() != null) {
|
||||
sum.addAndGet(item.getRealSalesNumber());
|
||||
}
|
||||
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
||||
lowerPrice = item.getSalePrice();
|
||||
}
|
||||
|
||||
String specSnap = item.getSpecSnap();
|
||||
if (specSnap != null) {
|
||||
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||
}
|
||||
}
|
||||
//销量
|
||||
it.setStockNumber(sum.intValue());
|
||||
if (lowerPrice == null) {
|
||||
lowerPrice = BigDecimal.ZERO;
|
||||
}
|
||||
//售价
|
||||
it.setLowPrice(lowerPrice);
|
||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||
if (tagSnap != null) {
|
||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||
JSONObject snapJSON;
|
||||
JSONArray finalSnap = new JSONArray();
|
||||
for (Object snap : tagSnaps) {
|
||||
snapJSON = (JSONObject) snap;
|
||||
String values = snapJSON.getString("value");
|
||||
String finalValues = "";
|
||||
if (StrUtil.isNotBlank(values)) {
|
||||
String[] valueList = values.split(",");
|
||||
for (String value : valueList) {
|
||||
if (specSet.contains(value)) {
|
||||
finalValues = finalValues + (value) + ",";
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(finalValues)) {
|
||||
finalValues = StrUtil.removeSuffix(finalValues, ",");
|
||||
snapJSON.put("value", finalValues);
|
||||
finalSnap.add(snapJSON);
|
||||
}
|
||||
}
|
||||
}
|
||||
//sku Result
|
||||
skuResult.setTagSnap(finalSnap.toJSONString());
|
||||
}
|
||||
it.setProductSkuResult(skuResult);
|
||||
});
|
||||
return products;
|
||||
}else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Result queryProductSku(String code, String shopId, String productId, String spec_tag) {
|
||||
if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) {
|
||||
return Result.fail("参数错误");
|
||||
|
|
|
|||
Loading…
Reference in New Issue