后端编辑库存从AttrValue表取值

This commit is contained in:
xuwenbo
2020-09-08 21:02:51 +08:00
parent ef078b84ed
commit 9b0a952893
12 changed files with 93 additions and 155 deletions

View File

@ -134,6 +134,6 @@ public class YxStoreCombinationDto implements Serializable {
private List<FromatDetailDto> items;
//sku结果集
private List<Map<String,Object>> attrs;
private List<ProductFormatDto> attrs;
}

View File

@ -131,6 +131,6 @@ public class YxStoreSeckillDto implements Serializable {
private List<FromatDetailDto> items;
//sku结果集
private List<Map<String,Object>> attrs;
private List<ProductFormatDto> attrs;
}

View File

@ -58,13 +58,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
@ -290,14 +284,14 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombin
.attrHidden("")
.detail(ListUtil.toList("默认"))
.build();
List<Map<String,Object>> attrs = resources.getAttrs();
Map<String,Object> map = attrs.get(0);
map.put("value1","规格");
map.put("detail", MapUtil.of(new String[][] {
{"规格", "默认"}
}));
List<ProductFormatDto> attrs = resources.getAttrs();
ProductFormatDto productFormatDto = attrs.get(0);
productFormatDto.setValue1("规格");
Map<String,String> map = new HashMap<>();
map.put("规格","默认");
productFormatDto.setDetail(map);
yxStoreProductAttrService.insertYxStoreProductAttr(ListUtil.toList(fromatDetailDto),
ListUtil.toList(map),resources.getProductId());
ListUtil.toList(productFormatDto),resources.getProductId());
}else{
yxStoreProductAttrService.insertYxStoreProductAttr(resources.getItems(),
resources.getAttrs(),resources.getProductId());
@ -311,27 +305,27 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombin
* @param attrs attrs
* @return ProductResultDto
*/
private ProductResultDto computedProduct(List<Map<String,Object>> attrs){
private ProductResultDto computedProduct(List<ProductFormatDto> attrs){
//取最小价格
Double minPrice = ListMapToListBean(attrs)
Double minPrice = attrs
.stream()
.map(ProductFormatDto::getPinkPrice)
.min(Comparator.naturalOrder())
.orElse(0d);
Double minOtPrice = ListMapToListBean(attrs)
Double minOtPrice = attrs
.stream()
.map(ProductFormatDto::getOtPrice)
.min(Comparator.naturalOrder())
.orElse(0d);
Double minCost = ListMapToListBean(attrs)
Double minCost = attrs
.stream()
.map(ProductFormatDto::getCost)
.min(Comparator.naturalOrder())
.orElse(0d);
//计算库存
Integer stock = ListMapToListBean(attrs)
Integer stock = attrs
.stream()
.map(ProductFormatDto::getPinkStock)
.reduce(Integer::sum)

View File

@ -268,14 +268,14 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
.attrHidden("")
.detail(ListUtil.toList("默认"))
.build();
List<Map<String,Object>> attrs = resources.getAttrs();
Map<String,Object> map = attrs.get(0);
map.put("value1","规格");
map.put("detail", MapUtil.of(new String[][] {
{"规格", "默认"}
}));
List<ProductFormatDto> attrs = resources.getAttrs();
ProductFormatDto productFormatDto = attrs.get(0);
productFormatDto.setValue1("规格");
Map<String,String> map = new HashMap<>();
map.put("规格","默认");
productFormatDto.setDetail(map);
yxStoreProductAttrService.insertYxStoreProductAttr(ListUtil.toList(fromatDetailDto),
ListUtil.toList(map),resources.getProductId());
ListUtil.toList(productFormatDto),resources.getProductId());
}else{
yxStoreProductAttrService.insertYxStoreProductAttr(resources.getItems(),
resources.getAttrs(),resources.getProductId());
@ -288,27 +288,27 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
* @param attrs attrs
* @return ProductResultDto
*/
private ProductResultDto computedProduct(List<Map<String,Object>> attrs){
private ProductResultDto computedProduct(List<ProductFormatDto> attrs){
//取最小价格
Double minPrice = ListMapToListBean(attrs)
Double minPrice = attrs
.stream()
.map(ProductFormatDto::getSeckillPrice)
.min(Comparator.naturalOrder())
.orElse(0d);
Double minOtPrice = ListMapToListBean(attrs)
Double minOtPrice = attrs
.stream()
.map(ProductFormatDto::getOtPrice)
.min(Comparator.naturalOrder())
.orElse(0d);
Double minCost = ListMapToListBean(attrs)
Double minCost = attrs
.stream()
.map(ProductFormatDto::getCost)
.min(Comparator.naturalOrder())
.orElse(0d);
//计算库存
Integer stock = ListMapToListBean(attrs)
Integer stock = attrs
.stream()
.map(ProductFormatDto::getSeckillStock)
.reduce(Integer::sum)
@ -326,17 +326,4 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
.build();
}
/**
* mapTobean
* @param listMap listMap
* @return list
*/
private List<ProductFormatDto> ListMapToListBean(List<Map<String, Object>> listMap){
List<ProductFormatDto> list = new ArrayList<>();
// 循环遍历出map对象
for (Map<String, Object> m : listMap) {
list.add(BeanUtil.mapToBean(m,ProductFormatDto.class,true));
}
return list;
}
}

View File

@ -12,6 +12,7 @@ import co.yixiang.common.service.BaseService;
import co.yixiang.modules.product.domain.YxStoreProductAttr;
import co.yixiang.modules.product.domain.YxStoreProductAttrValue;
import co.yixiang.modules.product.service.dto.FromatDetailDto;
import co.yixiang.modules.product.service.dto.ProductFormatDto;
import java.util.List;
import java.util.Map;
@ -60,6 +61,6 @@ public interface YxStoreProductAttrService extends BaseService<YxStoreProductAt
* @param attrs value
* @param productId 商品id
*/
void insertYxStoreProductAttr(List<FromatDetailDto> items, List<Map<String,Object>> attrs,
void insertYxStoreProductAttr(List<FromatDetailDto> items, List<ProductFormatDto> attrs,
Long productId);
}

View File

@ -12,7 +12,7 @@ import java.util.Map;
/**
* 商品对象VO
*
*
* @author hupeng
* @date 2020-04-25
*/
@ -138,7 +138,7 @@ public class ProductDto
private List<FromatDetailDto> items;
private List<Map<String,Object>> attrs;
private List<ProductFormatDto> attrs;

View File

@ -13,7 +13,7 @@ import java.util.Map;
/**
* 商品对象DTO
*
*
* @author hupeng
* @date 2020-04-23
*/
@ -140,7 +140,7 @@ public class StoreProductDto
private List<FromatDetailDto> items;
//sku结果集
private List<Map<String,Object>> attrs;
private List<ProductFormatDto> attrs;
}

View File

@ -73,7 +73,7 @@ public class YxStoreProductAttrServiceImpl extends BaseServiceImpl<StoreProductA
*/
@Override
@Transactional
public void insertYxStoreProductAttr(List<FromatDetailDto> items, List<Map<String,Object>> attrs,
public void insertYxStoreProductAttr(List<FromatDetailDto> items, List<ProductFormatDto> attrs,
Long productId)
{
List<YxStoreProductAttr> attrGroup = new ArrayList<>();
@ -89,11 +89,8 @@ public class YxStoreProductAttrServiceImpl extends BaseServiceImpl<StoreProductA
List<YxStoreProductAttrValue> valueGroup = new ArrayList<>();
for (Map<String, Object> m : attrs) {
ProductFormatDto productFormatDto = BeanUtil.mapToBean(m,ProductFormatDto.class,true);
// List<String> stringList = productFormatDto.getDetail().values()
// .stream()
// .collect(Collectors.toList());
for (ProductFormatDto productFormatDto : attrs) {
if(productFormatDto.getPinkStock()>productFormatDto.getStock() || productFormatDto.getSeckillStock()>productFormatDto.getStock()){
throw new BadRequestException("活动商品库存不能大于原有商品库存");
}

View File

@ -534,17 +534,17 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
.attrHidden("")
.detail(ListUtil.toList("默认"))
.build();
List<Map<String,Object>> attrs = storeProductDto.getAttrs();
Map<String,Object> map = attrs.get(0);
map.put("value1","规格");
map.put("detail", MapUtil.of(new String[][] {
{"规格", "默认"}
}));
List<ProductFormatDto> attrs = storeProductDto.getAttrs();
ProductFormatDto productFormatDto = attrs.get(0);
productFormatDto.setValue1("规格");
Map<String,String> map = new HashMap<>();
map.put("规格","默认");
productFormatDto.setDetail(map);
yxStoreProductAttrService.insertYxStoreProductAttr(ListUtil.toList(fromatDetailDto),
ListUtil.toList(map),yxStoreProduct.getId());
ListUtil.toList(productFormatDto),storeProductDto.getId());
}else{
yxStoreProductAttrService.insertYxStoreProductAttr(storeProductDto.getItems(),
storeProductDto.getAttrs(),yxStoreProduct.getId());
storeProductDto.getAttrs(),storeProductDto.getId());
}
@ -688,27 +688,27 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
* @param attrs attrs
* @return ProductResultDto
*/
private ProductResultDto computedProduct(List<Map<String,Object>> attrs){
private ProductResultDto computedProduct(List<ProductFormatDto> attrs){
//取最小价格
Double minPrice = ListMapToListBean(attrs)
Double minPrice = attrs
.stream()
.map(ProductFormatDto::getPrice)
.min(Comparator.naturalOrder())
.orElse(0d);
Double minOtPrice = ListMapToListBean(attrs)
Double minOtPrice = attrs
.stream()
.map(ProductFormatDto::getOtPrice)
.min(Comparator.naturalOrder())
.orElse(0d);
Double minCost = ListMapToListBean(attrs)
Double minCost = attrs
.stream()
.map(ProductFormatDto::getCost)
.min(Comparator.naturalOrder())
.orElse(0d);
//计算库存
Integer stock = ListMapToListBean(attrs)
Integer stock = attrs
.stream()
.map(ProductFormatDto::getStock)
.reduce(Integer::sum)