|
|
@ -45,6 +45,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Api(tags = "商品列表、商品发布管理") |
|
|
|
@Api(tags = "商品列表、商品发布管理") |
|
|
@ -125,11 +126,11 @@ public class ProductController { |
|
|
|
@PostMapping("/save") |
|
|
|
@PostMapping("/save") |
|
|
|
@ApiOperation(value = "保存商品信息") |
|
|
|
@ApiOperation(value = "保存商品信息") |
|
|
|
public ServerResponseEntity<String> save(@Valid @RequestBody ProductParam productParam,HttpServletRequest request) { |
|
|
|
public ServerResponseEntity<String> save(@Valid @RequestBody ProductParam productParam,HttpServletRequest request) { |
|
|
|
|
|
|
|
productParam.setShopId(TokenUtils.getShopIdByJwtToken(request)); |
|
|
|
checkParam(productParam); |
|
|
|
checkParam(productParam); |
|
|
|
|
|
|
|
|
|
|
|
Product product = BeanUtil.copyProperties(productParam, Product.class); |
|
|
|
Product product = BeanUtil.copyProperties(productParam, Product.class); |
|
|
|
// product.setDeliveryMode(Json.toJsonString(productParam.getDeliveryModeVo()));
|
|
|
|
|
|
|
|
product.setShopId(TokenUtils.getShopIdByJwtToken(request)); |
|
|
|
product.setShopId(TokenUtils.getShopIdByJwtToken(request)); |
|
|
|
|
|
|
|
// product.setDeliveryMode(Json.toJsonString(productParam.getDeliveryModeVo()));
|
|
|
|
product.setUpdateTime(new Date()); |
|
|
|
product.setUpdateTime(new Date()); |
|
|
|
if (product.getStatus() == 1) { |
|
|
|
if (product.getStatus() == 1) { |
|
|
|
product.setPutawayTime(new Date()); |
|
|
|
product.setPutawayTime(new Date()); |
|
|
@ -143,6 +144,7 @@ public class ProductController { |
|
|
|
@PostMapping("/update") |
|
|
|
@PostMapping("/update") |
|
|
|
@ApiOperation(value = "修改商品信息") |
|
|
|
@ApiOperation(value = "修改商品信息") |
|
|
|
public ServerResponseEntity<String> update(@Valid @RequestBody ProductParam productParam,HttpServletRequest request) { |
|
|
|
public ServerResponseEntity<String> update(@Valid @RequestBody ProductParam productParam,HttpServletRequest request) { |
|
|
|
|
|
|
|
productParam.setShopId(TokenUtils.getShopIdByJwtToken(request)); |
|
|
|
checkParam(productParam); |
|
|
|
checkParam(productParam); |
|
|
|
Product dbProduct = productService.getProductByProdId(productParam.getProdId()); |
|
|
|
Product dbProduct = productService.getProductByProdId(productParam.getProdId()); |
|
|
|
if (!Objects.equals(dbProduct.getShopId(), TokenUtils.getShopIdByJwtToken(request))) { |
|
|
|
if (!Objects.equals(dbProduct.getShopId(), TokenUtils.getShopIdByJwtToken(request))) { |
|
|
@ -233,6 +235,15 @@ public class ProductController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkParam(ProductParam productParam) { |
|
|
|
private void checkParam(ProductParam productParam) { |
|
|
|
|
|
|
|
QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
|
|
productQueryWrapper.eq("prod_name",productParam.getProdName()); |
|
|
|
|
|
|
|
if (productParam.getProdId()!= null){ |
|
|
|
|
|
|
|
productQueryWrapper.notIn("prod_id",productParam.getProdId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Product one = productService.getOne(productQueryWrapper); |
|
|
|
|
|
|
|
if (one != null){ |
|
|
|
|
|
|
|
throw new YamiShopBindException("商品名称已存在"); |
|
|
|
|
|
|
|
} |
|
|
|
// if (CollectionUtil.isEmpty(productParam.getTagList())) {
|
|
|
|
// if (CollectionUtil.isEmpty(productParam.getTagList())) {
|
|
|
|
// throw new YamiShopBindException("请选择产品分组");
|
|
|
|
// throw new YamiShopBindException("请选择产品分组");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
@ -244,14 +255,20 @@ public class ProductController { |
|
|
|
// throw new YamiShopBindException("请选择配送方式");
|
|
|
|
// throw new YamiShopBindException("请选择配送方式");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
List<Sku> skuList = productParam.getSkuList(); |
|
|
|
List<Sku> skuList = productParam.getSkuList(); |
|
|
|
boolean isAllUnUse = true; |
|
|
|
List<String> stringList = skuList.stream().map(Sku::getSkuName) |
|
|
|
for (Sku sku : skuList) { |
|
|
|
.collect(Collectors.toList()); |
|
|
|
if (sku.getStatus() == 1) { |
|
|
|
long count = stringList.stream().distinct().count(); |
|
|
|
isAllUnUse = false; |
|
|
|
if (stringList.size() != count) { |
|
|
|
} |
|
|
|
throw new YamiShopBindException("商品规格名称重复"); |
|
|
|
} |
|
|
|
|
|
|
|
if (isAllUnUse) { |
|
|
|
|
|
|
|
throw new YamiShopBindException("至少要启用一种商品规格"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// boolean isAllUnUse = true;
|
|
|
|
|
|
|
|
// for (Sku sku : skuList) {
|
|
|
|
|
|
|
|
// if (sku.getStatus() == 1) {
|
|
|
|
|
|
|
|
// isAllUnUse = false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (isAllUnUse) {
|
|
|
|
|
|
|
|
// throw new YamiShopBindException("至少要启用一种商品规格");
|
|
|
|
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|