From 3924f2d12918e843c837196307122a9d2e164a20 Mon Sep 17 00:00:00 2001 From: XinYi Song <2037158277@qq.com> Date: Mon, 20 Dec 2021 09:23:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=B8=8B=E6=9E=B6=E7=9A=84=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/ProductController.java | 19 +++++++++++++++++++ src/main/java/com/xkrs/dao/ProductDao.java | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/com/xkrs/controller/ProductController.java b/src/main/java/com/xkrs/controller/ProductController.java index e3d6a26..b516850 100644 --- a/src/main/java/com/xkrs/controller/ProductController.java +++ b/src/main/java/com/xkrs/controller/ProductController.java @@ -2,11 +2,13 @@ package com.xkrs.controller; import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.common.tool.TokenUtil; +import com.xkrs.dao.ProductDao; import com.xkrs.dao.SysUserDao; import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.qo.ProductQo; import com.xkrs.service.ProductService; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; @@ -31,6 +33,9 @@ public class ProductController { @Resource private SysUserDao sysUserDao; + @Resource + private ProductDao productDao; + /** * 添加商品信息 * @param productQo @@ -103,4 +108,18 @@ public class ProductController { String reviewType = (String) map.get("reviewType"); return productService.updateReviewType(productId,reviewType); } + + /** + * 商品下架 + * @param map + * @return + */ + @Transactional(rollbackFor=Exception.class) + @PostMapping("/updateOffShelf") + public String updateOffShelf(@RequestBody Map map){ + Locale locale = LocaleContextHolder.getLocale(); + Integer productId = (Integer) map.get("productId"); + productDao.updateShelfTypeById(productId,"2"); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"商品下架成功!",locale); + } } diff --git a/src/main/java/com/xkrs/dao/ProductDao.java b/src/main/java/com/xkrs/dao/ProductDao.java index f56cd23..845388d 100644 --- a/src/main/java/com/xkrs/dao/ProductDao.java +++ b/src/main/java/com/xkrs/dao/ProductDao.java @@ -46,4 +46,13 @@ public interface ProductDao extends JpaRepository, JpaSpecif * @return */ ProductEntity findById(Integer id); + + /** + * 商品下架 + * @param productId + * @param shelfType + */ + @Modifying(clearAutomatically=true) + @Query(value = "update product set shelf_type = ?2 where id = ?1",nativeQuery = true) + void updateShelfTypeById(Integer productId,String shelfType); }