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); }