Commit f1c62211 authored by shiyu's avatar shiyu

交换商品后扣减库存

parent bc3fcaff
...@@ -11,4 +11,6 @@ public interface ExchangeOrderSnapshotDao { ...@@ -11,4 +11,6 @@ public interface ExchangeOrderSnapshotDao {
boolean update(ExchangeOrderSnapshot exchangeOrderSnapshot); boolean update(ExchangeOrderSnapshot exchangeOrderSnapshot);
List<ExchangeOrderSnapshot> findByOrderId(String orderId); List<ExchangeOrderSnapshot> findByOrderId(String orderId);
List<ExchangeOrderSnapshot> findByUserId(long userId);
} }
...@@ -34,6 +34,16 @@ public class ExchangeOrderSnapshotDaoImpl implements ExchangeOrderSnapshotDao { ...@@ -34,6 +34,16 @@ public class ExchangeOrderSnapshotDaoImpl implements ExchangeOrderSnapshotDao {
ExchangeOrderSnapshotExample example = new ExchangeOrderSnapshotExample(); ExchangeOrderSnapshotExample example = new ExchangeOrderSnapshotExample();
ExchangeOrderSnapshotExample.Criteria criteria = example.createCriteria(); ExchangeOrderSnapshotExample.Criteria criteria = example.createCriteria();
criteria.andDistributionOrderIdEqualTo(orderId); criteria.andDistributionOrderIdEqualTo(orderId);
criteria.andIsValidEqualTo(true);
return exchangeOrderSnapshotMapper.selectByExampleWithBLOBs(example);
}
@Override
public List<ExchangeOrderSnapshot> findByUserId(long userId) {
ExchangeOrderSnapshotExample example = new ExchangeOrderSnapshotExample();
ExchangeOrderSnapshotExample.Criteria criteria = example.createCriteria();
criteria.andCreatorIdEqualTo(userId);
criteria.andIsValidEqualTo(true);
return exchangeOrderSnapshotMapper.selectByExampleWithBLOBs(example); return exchangeOrderSnapshotMapper.selectByExampleWithBLOBs(example);
} }
} }
...@@ -33,6 +33,7 @@ public class SupplierItemDaoImpl implements SupplierItemDao { ...@@ -33,6 +33,7 @@ public class SupplierItemDaoImpl implements SupplierItemDao {
SupplierItemExample.Criteria criteria = supplierItemExample.createCriteria(); SupplierItemExample.Criteria criteria = supplierItemExample.createCriteria();
JdbcHelper.ifPresent(dto.getId(), criteria::andIdEqualTo); JdbcHelper.ifPresent(dto.getId(), criteria::andIdEqualTo);
JdbcHelper.ifPresent(dto.getIds(), criteria::andIdIn); JdbcHelper.ifPresent(dto.getIds(), criteria::andIdIn);
JdbcHelper.ifPresent(dto.getFilterIds(), criteria::andIdNotIn);
if (StringUtils.hasLength(dto.getName())) { if (StringUtils.hasLength(dto.getName())) {
criteria.andNameLike("%" + dto.getName() + "%"); criteria.andNameLike("%" + dto.getName() + "%");
} }
......
...@@ -17,6 +17,7 @@ import com.wwdz.ch.wx.constant.CollectionBookConstants; ...@@ -17,6 +17,7 @@ import com.wwdz.ch.wx.constant.CollectionBookConstants;
import com.wwdz.ch.wx.entity.request.ExchangeRequestDto; import com.wwdz.ch.wx.entity.request.ExchangeRequestDto;
import com.wwdz.ch.wx.entity.request.ItemSimpleDto; import com.wwdz.ch.wx.entity.request.ItemSimpleDto;
import com.wwdz.ch.wx.service.distribution.ExchangeService; import com.wwdz.ch.wx.service.distribution.ExchangeService;
import com.wwdz.ch.wx.service.distribution.SupplierItemService;
import com.xxdxxs.utils.EntityMapper; import com.xxdxxs.utils.EntityMapper;
import com.xxdxxs.utils.StringUtils; import com.xxdxxs.utils.StringUtils;
import org.junit.Test; import org.junit.Test;
...@@ -54,6 +55,9 @@ public class ExchangeServiceImpl implements ExchangeService { ...@@ -54,6 +55,9 @@ public class ExchangeServiceImpl implements ExchangeService {
@Autowired @Autowired
ExchangeOrderSnapshotDao exchangeOrderSnapshotDao; ExchangeOrderSnapshotDao exchangeOrderSnapshotDao;
@Autowired
SupplierItemService supplierItemService;
@Override @Override
public Result checkEnoughItem(ExchangeRequestDto dto) { public Result checkEnoughItem(ExchangeRequestDto dto) {
try { try {
...@@ -87,8 +91,9 @@ public class ExchangeServiceImpl implements ExchangeService { ...@@ -87,8 +91,9 @@ public class ExchangeServiceImpl implements ExchangeService {
Long targetUserId = dto.getUserId(); Long targetUserId = dto.getUserId();
//查询用户已经交换的商品,在列表中去除 //查询用户已经交换的商品,在列表中去除
// List<ExchangeOrderSnapshot> exchangeOrderSnapshotList = exchangeOrderSnapshotDao.findByOrderId(); List<ExchangeOrderSnapshot> exchangeOrderSnapshotList = exchangeOrderSnapshotDao.findByUserId(dto.getUserId());
List<Long> filterItemList = exchangeOrderSnapshotList.stream().map(ExchangeOrderSnapshot::getItemId).distinct().collect(Collectors.toList());
supplierItemRequestDto.setFilterIds(filterItemList);
//标签id为空则查询所有的藏品 //标签id为空则查询所有的藏品
if (dto.getCollectionBookId() == null) { if (dto.getCollectionBookId() == null) {
...@@ -218,6 +223,9 @@ public class ExchangeServiceImpl implements ExchangeService { ...@@ -218,6 +223,9 @@ public class ExchangeServiceImpl implements ExchangeService {
long exchangeItemId = dto.getExchangeItemId(); long exchangeItemId = dto.getExchangeItemId();
//查询交换的商品价值 //查询交换的商品价值
SupplierItem supplierItem = supplierItemDao.findById(exchangeItemId); SupplierItem supplierItem = supplierItemDao.findById(exchangeItemId);
if (supplierItem.getStock() < dto.getExchangeItemNum()) {
return Result.failed("库存不足");
}
long exchangeItemPrice = supplierItem.getOfficialEstimatedPrice() * dto.getExchangeItemNum(); long exchangeItemPrice = supplierItem.getOfficialEstimatedPrice() * dto.getExchangeItemNum();
List<ItemSimpleDto> itemSimpleDtoList = dto.getItemList(); List<ItemSimpleDto> itemSimpleDtoList = dto.getItemList();
//查询用户藏品的价值 //查询用户藏品的价值
...@@ -266,6 +274,9 @@ public class ExchangeServiceImpl implements ExchangeService { ...@@ -266,6 +274,9 @@ public class ExchangeServiceImpl implements ExchangeService {
exchangeOrderSnapshot.setUpdateTime(new Date()); exchangeOrderSnapshot.setUpdateTime(new Date());
exchangeOrderSnapshotDao.insert(exchangeOrderSnapshot); exchangeOrderSnapshotDao.insert(exchangeOrderSnapshot);
} }
//减少库存
supplierItemService.reduceStock(exchangeItemId, dto.getExchangeItemNum());
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("distributionOrderId", distributionOrderId); map.put("distributionOrderId", distributionOrderId);
return Result.success(map); return Result.success(map);
......
...@@ -212,6 +212,12 @@ public class SupplierItemServiceImpl implements SupplierItemService { ...@@ -212,6 +212,12 @@ public class SupplierItemServiceImpl implements SupplierItemService {
public Result findItemList(SupplierItemRequestDto dto) { public Result findItemList(SupplierItemRequestDto dto) {
try { try {
List<SupplierItemVo> supplierItemVos = new ArrayList<>(); List<SupplierItemVo> supplierItemVos = new ArrayList<>();
if (dto.getType() != null && dto.getType() == DistributionEnum.DistributionTypeEnum.EXCHANGE.getCode()) {
//库存要大于0
dto.setStock(0);
//必须要有官方估价才能展示在交换列表
dto.setOfficialEstimatedPriceNotNull(true);
}
List<SupplierItem> supplierItemList = supplierItemDao.findListForSort(dto); List<SupplierItem> supplierItemList = supplierItemDao.findListForSort(dto);
PageInfo pageInfo = new PageInfo(supplierItemList); PageInfo pageInfo = new PageInfo(supplierItemList);
for (SupplierItem supplierItem : supplierItemList) { for (SupplierItem supplierItem : supplierItemList) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment