From ce10f202299611b774b8e96793bde8b8b9310946 Mon Sep 17 00:00:00 2001 From: chendt <18902722133@163.com> Date: Mon, 20 Jun 2022 11:33:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BD=AE=E6=92=AD=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/IndexImgController.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/yami-shop-admin/src/main/java/com/yami/shop/admin/controller/IndexImgController.java b/yami-shop-admin/src/main/java/com/yami/shop/admin/controller/IndexImgController.java index 8b6c466..8db635a 100644 --- a/yami-shop-admin/src/main/java/com/yami/shop/admin/controller/IndexImgController.java +++ b/yami-shop-admin/src/main/java/com/yami/shop/admin/controller/IndexImgController.java @@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.yami.shop.bean.model.IndexImg; import com.yami.shop.bean.model.Product; +import com.yami.shop.common.exception.YamiShopBindException; import com.yami.shop.common.util.PageParam; import com.yami.shop.security.admin.util.SecurityUtils; import com.yami.shop.service.IndexImgService; @@ -79,6 +80,7 @@ public class IndexImgController { Long shopId = SecurityUtils.getSysUser().getShopId(); indexImg.setShopId(shopId); indexImg.setUploadTime(new Date()); + checkProdStatus(indexImg); indexImgService.save(indexImg); indexImgService.removeIndexImgCache(); return ResponseEntity.ok().build(); @@ -90,7 +92,8 @@ public class IndexImgController { @PutMapping @PreAuthorize("@pms.hasPermission('admin:indexImg:update')") public ResponseEntity update(@RequestBody @Valid IndexImg indexImg) { - indexImgService.updateById(indexImg); + checkProdStatus(indexImg); + indexImgService.saveOrUpdate(indexImg); indexImgService.removeIndexImgCache(); return ResponseEntity.ok().build(); } @@ -105,4 +108,20 @@ public class IndexImgController { indexImgService.removeIndexImgCache(); return ResponseEntity.ok().build(); } + + private void checkProdStatus(IndexImg indexImg) { + if (!Objects.equals(indexImg.getType(), 0)) { + return; + } + if (Objects.isNull(indexImg.getRelation())) { + throw new YamiShopBindException("请选择商品"); + } + Product product = productService.getById(indexImg.getRelation()); + if (Objects.isNull(product)) { + throw new YamiShopBindException("商品信息不存在"); + } + if (!Objects.equals(product.getStatus(), 1)) { + throw new YamiShopBindException("该商品未上架,请选择别的商品"); + } + } }