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