Skip to content

Commit

Permalink
优化轮播图
Browse files Browse the repository at this point in the history
  • Loading branch information
Brother-Dragon committed Jun 20, 2022
1 parent 4007093 commit ce10f20
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -79,6 +80,7 @@ public ResponseEntity<Void> save(@RequestBody @Valid IndexImg indexImg) {
Long shopId = SecurityUtils.getSysUser().getShopId();
indexImg.setShopId(shopId);
indexImg.setUploadTime(new Date());
checkProdStatus(indexImg);
indexImgService.save(indexImg);
indexImgService.removeIndexImgCache();
return ResponseEntity.ok().build();
Expand All @@ -90,7 +92,8 @@ public ResponseEntity<Void> save(@RequestBody @Valid IndexImg indexImg) {
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:update')")
public ResponseEntity<Void> update(@RequestBody @Valid IndexImg indexImg) {
indexImgService.updateById(indexImg);
checkProdStatus(indexImg);
indexImgService.saveOrUpdate(indexImg);
indexImgService.removeIndexImgCache();
return ResponseEntity.ok().build();
}
Expand All @@ -105,4 +108,20 @@ public ResponseEntity<Void> delete(@RequestBody Long[] ids) {
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("该商品未上架,请选择别的商品");
}
}
}

0 comments on commit ce10f20

Please sign in to comment.