|
@@ -1,6 +1,7 @@
|
|
|
package com.txz.mall.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.txz.mall.core.AbstractService;
|
|
@@ -24,6 +25,7 @@ import tk.mybatis.mapper.entity.Example;
|
|
|
import vo.FlashActivityVO;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -36,13 +38,16 @@ import java.util.stream.Collectors;
|
|
|
@Transactional
|
|
|
@AllArgsConstructor
|
|
|
public class StoreCombinationServiceImpl extends AbstractService<StoreCombination> implements StoreCombinationService {
|
|
|
-
|
|
|
+
|
|
|
private final StoreProductService storeProductService;
|
|
|
private final StoreFlashActivityService storeFlashActivityService;
|
|
|
private final StorePinkService storePinkService;
|
|
|
-
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private StoreCombinationMapper storeCombinationMapper;
|
|
|
+
|
|
|
@Override
|
|
|
- public void addActivityProduct(List<StoreCombination> list, Long activityId) {
|
|
|
+ public String addActivityProduct(List<StoreCombination> list, Long activityId) {
|
|
|
StoreFlashActivity flashActivity = storeFlashActivityService.findById(activityId);
|
|
|
if (flashActivity == null || flashActivity.getIsDelete().equals(1)) {
|
|
|
throw new ServiceException(I18nUtil.get("cannot.find.the.corresponding.activity"));
|
|
@@ -51,6 +56,43 @@ public class StoreCombinationServiceImpl extends AbstractService<StoreCombinatio
|
|
|
String idsStr = list.stream()
|
|
|
.map(storeCombination -> storeCombination.getProductId().toString())
|
|
|
.collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ String duplicateIdStr = "";
|
|
|
+
|
|
|
+ List<Long> acSpuId = storeCombinationMapper.getAcSpuId(idsStr, activityId);
|
|
|
+ if (CollectionUtils.isNotEmpty(acSpuId)) {
|
|
|
+ List<Long> reqIds = Arrays.stream(idsStr.split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(StrUtil::isNotBlank)
|
|
|
+ .map(Long::valueOf)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 找出重复的ID
|
|
|
+ List<Long> duplicateIds = reqIds.stream()
|
|
|
+ .filter(acSpuId::contains)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ duplicateIdStr = duplicateIds.stream()
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ // 从reqIds中删除重复项
|
|
|
+ reqIds.removeAll(duplicateIds);
|
|
|
+
|
|
|
+ // 重新生成idsStr
|
|
|
+ idsStr = reqIds.stream()
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ // 从list中删除重复的元素
|
|
|
+ list.removeIf(storeCombination ->
|
|
|
+ duplicateIds.contains(storeCombination.getProductId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StrUtil.isBlank(idsStr)) {
|
|
|
+ return duplicateIdStr;
|
|
|
+ }
|
|
|
+
|
|
|
List<StoreProduct> productList = storeProductService.findByIds(idsStr);
|
|
|
for (StoreCombination storeCombination : list) {
|
|
|
List<StoreProduct> productCollect = productList.stream()
|
|
@@ -94,9 +136,11 @@ public class StoreCombinationServiceImpl extends AbstractService<StoreCombinatio
|
|
|
});
|
|
|
}
|
|
|
save(list);
|
|
|
+
|
|
|
+ return duplicateIdStr;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public List<StoreCombination> getMore(Integer comId) {
|
|
|
Condition condition = new Condition(StoreCombination.class);
|
|
@@ -112,7 +156,7 @@ public class StoreCombinationServiceImpl extends AbstractService<StoreCombinatio
|
|
|
condition.setOrderByClause("sort DESC, id DESC");
|
|
|
return findByCondition(condition);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public StoreCombination getByIdException(Long combinationId) {
|
|
|
Condition condition = new Condition(StoreCombination.class);
|
|
@@ -126,84 +170,81 @@ public class StoreCombinationServiceImpl extends AbstractService<StoreCombinatio
|
|
|
}
|
|
|
return combinationList.get(0);
|
|
|
}
|
|
|
-
|
|
|
- @Resource
|
|
|
- private StoreCombinationMapper storeCombinationMapper;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public synchronized void operationStock(Long id, Integer num, String type) {
|
|
|
StoreCombination combination = findById(id);
|
|
|
- if(ObjectUtils.isEmpty(combination)){
|
|
|
- throw new ServiceException(I18nUtil.get("group.buying.activity.does.not.exist.id") + id);
|
|
|
- }
|
|
|
-
|
|
|
+ if (ObjectUtils.isEmpty(combination)) {
|
|
|
+ throw new ServiceException(I18nUtil.get("group.buying.activity.does.not.exist.id") + id);
|
|
|
+ }
|
|
|
+
|
|
|
StoreCombination storeCombinationForUpdate = new StoreCombination();
|
|
|
if ("add".equals(type)) {
|
|
|
-
|
|
|
+
|
|
|
int sales = combination.getSales() - num;
|
|
|
int stock = combination.getStock() + num;
|
|
|
int quota = combination.getQuota() + num;
|
|
|
- if(sales<0){
|
|
|
- throw new ServiceException(I18nUtil.get("the.sales.deduction.of.group.buying.activity.m_store_combination.is.negative.id")+id);
|
|
|
+ if (sales < 0) {
|
|
|
+ throw new ServiceException(I18nUtil.get("the.sales.deduction.of.group.buying.activity.m_store_combination.is.negative.id") + id);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
storeCombinationForUpdate.setSales(sales);
|
|
|
storeCombinationForUpdate.setStock(stock);
|
|
|
storeCombinationForUpdate.setQuota(quota);
|
|
|
}
|
|
|
if ("sub".equals(type)) {
|
|
|
-
|
|
|
+
|
|
|
int sales = combination.getSales() + num;
|
|
|
int stock = combination.getStock() - num;
|
|
|
int quota = combination.getQuota() - num;
|
|
|
- if(stock<0){
|
|
|
- throw new ServiceException(I18nUtil.get("the.stock.deduction.of.group.buying.activity.m_store_combination.is.negative.id")+id);
|
|
|
+ if (stock < 0) {
|
|
|
+ throw new ServiceException(I18nUtil.get("the.stock.deduction.of.group.buying.activity.m_store_combination.is.negative.id") + id);
|
|
|
}
|
|
|
- if(quota<0){
|
|
|
- throw new ServiceException(I18nUtil.get("the.quota.deduction.of.group.buying.activity.m_store_combination.is.negative.id")+id);
|
|
|
+ if (quota < 0) {
|
|
|
+ throw new ServiceException(I18nUtil.get("the.quota.deduction.of.group.buying.activity.m_store_combination.is.negative.id") + id);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
storeCombinationForUpdate.setSales(sales);
|
|
|
storeCombinationForUpdate.setStock(stock);
|
|
|
storeCombinationForUpdate.setQuota(quota);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
- storeCombinationForUpdate.setVersion(combination.getVersion()+1);
|
|
|
+ storeCombinationForUpdate.setVersion(combination.getVersion() + 1);
|
|
|
Example example = new Example(StoreCombination.class);
|
|
|
- example.createCriteria().andEqualTo("id",id).andEqualTo("version",combination.getVersion());
|
|
|
+ example.createCriteria().andEqualTo("id", id).andEqualTo("version", combination.getVersion());
|
|
|
int i = storeCombinationMapper.updateByConditionSelective(storeCombinationForUpdate, example);
|
|
|
- if(!(i==1)){
|
|
|
- throw new ServiceException(I18nUtil.get("storecombination.inventory.operation.failed.id")+id);
|
|
|
+ if (!(i == 1)) {
|
|
|
+ throw new ServiceException(I18nUtil.get("storecombination.inventory.operation.failed.id") + id);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-// @Override
|
|
|
-// public synchronized void operationStock(Long id, Integer num, String type) {
|
|
|
-// StoreCombination combination = findById(id);
|
|
|
-// UpdateWrapper<StoreCombination> updateWrapper = new UpdateWrapper<>();
|
|
|
-// if ("add".equals(type)) {
|
|
|
-// combination.setSales(combination.getNum() - num);
|
|
|
-// combination.setStock(combination.getStock() + num);
|
|
|
-// combination.setQuota(combination.getQuota() + num);
|
|
|
-// }
|
|
|
-// if ("sub".equals(type)) {
|
|
|
-// combination.setSales(combination.getSales() + num);
|
|
|
-// combination.setStock(combination.getStock() - num);
|
|
|
-// combination.setQuota(combination.getQuota() - num);
|
|
|
-//
|
|
|
-// Condition condition = new Condition(StoreCombination.class);
|
|
|
-// Example.Criteria criteria = condition.createCriteria();
|
|
|
-// criteria.andEqualTo("id", id);
|
|
|
-// criteria.andGreaterThanOrEqualTo("quota", num);
|
|
|
-// criteria.andEqualTo("isDelete", 0);
|
|
|
-// criteria.andGreaterThanOrEqualTo("stock", num);
|
|
|
-// List<StoreCombination> combinationList = findByCondition(condition);
|
|
|
-// if (CollectionUtils.isEmpty(combinationList)) {
|
|
|
-// throw new ServiceException("更新拼团商品库存失败,商品id = " + id + ",库存不足");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// update(combination);
|
|
|
-// }
|
|
|
+
|
|
|
+
|
|
|
+ // @Override
|
|
|
+ // public synchronized void operationStock(Long id, Integer num, String type) {
|
|
|
+ // StoreCombination combination = findById(id);
|
|
|
+ // UpdateWrapper<StoreCombination> updateWrapper = new UpdateWrapper<>();
|
|
|
+ // if ("add".equals(type)) {
|
|
|
+ // combination.setSales(combination.getNum() - num);
|
|
|
+ // combination.setStock(combination.getStock() + num);
|
|
|
+ // combination.setQuota(combination.getQuota() + num);
|
|
|
+ // }
|
|
|
+ // if ("sub".equals(type)) {
|
|
|
+ // combination.setSales(combination.getSales() + num);
|
|
|
+ // combination.setStock(combination.getStock() - num);
|
|
|
+ // combination.setQuota(combination.getQuota() - num);
|
|
|
+ //
|
|
|
+ // Condition condition = new Condition(StoreCombination.class);
|
|
|
+ // Example.Criteria criteria = condition.createCriteria();
|
|
|
+ // criteria.andEqualTo("id", id);
|
|
|
+ // criteria.andGreaterThanOrEqualTo("quota", num);
|
|
|
+ // criteria.andEqualTo("isDelete", 0);
|
|
|
+ // criteria.andGreaterThanOrEqualTo("stock", num);
|
|
|
+ // List<StoreCombination> combinationList = findByCondition(condition);
|
|
|
+ // if (CollectionUtils.isEmpty(combinationList)) {
|
|
|
+ // throw new ServiceException("更新拼团商品库存失败,商品id = " + id + ",库存不足");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // update(combination);
|
|
|
+ // }
|
|
|
}
|