添加商品 填充预警值字段
This commit is contained in:
@@ -58,4 +58,8 @@ public interface TbProductRepository extends JpaRepository<TbProduct, Integer>,
|
||||
|
||||
@Query("select product from TbProduct product where product.id=:id and product.shopId=:shopId")
|
||||
TbProduct selectByShopIdAndId(Integer id, String shopId);
|
||||
|
||||
@Query("select product from TbProduct product where product.shopId=:shopId")
|
||||
List<TbProduct> selectByShopId(String shopId);
|
||||
|
||||
}
|
||||
|
||||
@@ -373,6 +373,7 @@ public class TbProductServiceImpl implements TbProductService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TbProduct save = tbProductRepository.save(product);
|
||||
if (save.getId() == null) {
|
||||
throw new BadRequestException("添加商品失败");
|
||||
@@ -381,6 +382,16 @@ public class TbProductServiceImpl implements TbProductService {
|
||||
tbProductRepository.save(save);
|
||||
//sku
|
||||
if (resources.getSkuList() != null) {
|
||||
Integer warnLine = 0;
|
||||
List<TbProduct> productList = tbProductRepository.selectByShopId(resources.getShopId());
|
||||
if (!productList.isEmpty()) {
|
||||
TbProduct p = productList.get(0);
|
||||
List<TbProductSku> productSkus = tbProductSkuRepository.searchSku(p.getId().toString());
|
||||
if (!productSkus.isEmpty()) {
|
||||
warnLine = productSkus.get(0).getWarnLine();
|
||||
}
|
||||
}
|
||||
|
||||
List<TbProductSku> skuList = new ArrayList<>();
|
||||
for (TbProductSku sku : resources.getSkuList()) {
|
||||
sku.setProductId(String.valueOf(save.getId()));
|
||||
@@ -388,6 +399,7 @@ public class TbProductServiceImpl implements TbProductService {
|
||||
sku.setCreatedAt(Instant.now().toEpochMilli());
|
||||
sku.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
sku.setIsGrounding(1);
|
||||
sku.setWarnLine(warnLine);
|
||||
skuList.add(sku);
|
||||
}
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuRepository.saveAll(skuList);
|
||||
|
||||
Reference in New Issue
Block a user