From ec10376492ab4dc8b5e4b3bc930785ec222ef08e Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Wed, 3 Jan 2024 16:43:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E5=AE=A2=E8=AE=BF=E9=97=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/peanut/config/ShiroConfig.java | 1 + .../sys/controller/VisitorController.java | 169 ++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 src/main/java/com/peanut/modules/sys/controller/VisitorController.java diff --git a/src/main/java/com/peanut/config/ShiroConfig.java b/src/main/java/com/peanut/config/ShiroConfig.java index 030239bb..1e6887bf 100644 --- a/src/main/java/com/peanut/config/ShiroConfig.java +++ b/src/main/java/com/peanut/config/ShiroConfig.java @@ -75,6 +75,7 @@ public class ShiroConfig { filterMap.put("/aaa.txt", "anon"); filterMap.put("/**", "oauth2"); filterMap.put("/cent/**","anon"); + filterMap.put("/visitor/**","anon");//游客访问接口 //todo 过滤 用户隐私协议未生效 // filterMap.put("sys/agreement/list","anon"); diff --git a/src/main/java/com/peanut/modules/sys/controller/VisitorController.java b/src/main/java/com/peanut/modules/sys/controller/VisitorController.java new file mode 100644 index 00000000..947763ae --- /dev/null +++ b/src/main/java/com/peanut/modules/sys/controller/VisitorController.java @@ -0,0 +1,169 @@ +package com.peanut.modules.sys.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.peanut.common.utils.PageUtils; +import com.peanut.common.utils.R; +import com.peanut.modules.book.dao.ShopProductToLabelDao; +import com.peanut.modules.book.entity.*; +import com.peanut.modules.book.service.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import java.util.*; + +@Slf4j +@RestController +@RequestMapping("/visitor") +public class VisitorController { + + @Autowired + private ShopProductService shopProductService; + @Autowired + private ShopProductToLabelDao shopProductToLabelDao; + @Autowired + private ShopProductLabelService shopProductLabelService; + @Autowired + private ShopCategoryService shopCategoryService; + @Autowired + private BookService bookService; + @Autowired + private ShopProductBookService shopProductBookService; + @Autowired + private ShopProductToLabelService shopProductToLabelService; + @Autowired + private UserRecordService userRecordService; + @Autowired + private MyUserService myUserService; + @Autowired + private UserFollowUpService userFollowUpService; + + //新书 + @RequestMapping("/getNewBook") + public R getNewBook(@RequestParam Map params) { + PageUtils page = shopProductService.getNewBook(params); + return R.ok().put("page", page); + } + + /** + * 获取商品列表通过标签 + * @return + */ + @RequestMapping("/getProductsByLabel") + public R getProductsByLabel(@RequestParam Integer splId,@RequestParam Integer limit,@RequestParam Integer page){ + MPJLambdaWrapper shopProductEntityMPJLambdaWrapper = new MPJLambdaWrapper(); + shopProductEntityMPJLambdaWrapper.selectAll(ShopProduct.class); + shopProductEntityMPJLambdaWrapper.leftJoin(ShopProduct.class, ShopProduct::getProductId,ShopProductToLabelEntity::getProductId); + shopProductEntityMPJLambdaWrapper.eq(ShopProductToLabelEntity::getSplId,splId); + shopProductEntityMPJLambdaWrapper.eq(ShopProductToLabelEntity::getDelFlag,0); + shopProductEntityMPJLambdaWrapper.eq(ShopProduct::getDelFlag,0); + shopProductEntityMPJLambdaWrapper.gt(ShopProduct::getProductStock,0); + Page shopProductEntityPage = shopProductToLabelDao.selectJoinPage(new Page(page, limit), ShopProduct.class, shopProductEntityMPJLambdaWrapper); + return R.ok().put("page",shopProductEntityPage); + } + + @RequestMapping("/getLabels") + public R getLabels(){ + List shopProductLabelEntities = shopProductLabelService.getBaseMapper().selectList(new QueryWrapper() + .eq("del_flag",0)); + Map re = new HashMap(); + re.put("labels",shopProductLabelEntities); + return R.ok().put("result",re); + } + + /** + * 信息 + * + * @param productId + * @return + */ + @RequestMapping("/info/{productId}") + public R info(@PathVariable("productId") Integer productId) { + ShopProduct shopProduct = shopProductService.getBaseMapper().selectOne(new QueryWrapper().eq("product_id", productId).eq("del_flag", 0)); + if (shopProduct == null) { + return R.error("该商品已下架,看看其他商品吧"); + } + ArrayList> imagesUrl = new ArrayList>(); + Integer poid = shopProduct.getProductPid(); + Integer productId1 = shopProduct.getProductId(); + List poids = shopCategoryService.findPoid(poid); + shopProduct.setPoids(poids); + List list = new ArrayList<>(); + List bookIdlist = new ArrayList<>(); + ArrayList booklist = new ArrayList<>(); + List product = shopProductBookService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id", productId1)); + for (ShopProductBookEntity shopProductBookEntity : product) { + Integer id = shopProductBookEntity.getId(); + Integer bookId = shopProductBookEntity.getBookId(); + + BookEntity byId = bookService.getById(bookId); + bookIdlist.add(id); + booklist.add(String.valueOf(bookId)); + list.add(byId); + } + //添加获取标签逻辑 + List shopProductToLabelEntities = shopProductToLabelService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id", productId).eq("del_flag", 0)); + List labelList = new ArrayList(); + for (ShopProductToLabelEntity sp : shopProductToLabelEntities) { + labelList.add(sp.getSplId()); + } + shopProduct.setBookidsimages(list); + shopProduct.setBookids(booklist); + shopProduct.setShoproudIds(bookIdlist); + return R.ok().put("shopProduct", shopProduct).put("labels", labelList); + } + + /** + * 查看全部评价 + */ + @RequestMapping("/All") + public R All(@RequestBody UserRecord userRecordEntity) { + List list = new ArrayList<>(); + //此处bookid实际传的是商品id + List bookid = userRecordService.getBaseMapper().selectList(new QueryWrapper().eq("bookid", userRecordEntity.getBookid()).orderByDesc("create_date")); + if (bookid != null) { + for (UserRecord userRecord : bookid) { + HashMap map = new HashMap<>(); + Integer bookid1 = userRecord.getBookid(); + Integer userid1 = userRecord.getUserid(); + Integer id1 = userRecord.getId(); + List id = myUserService.getBaseMapper().selectList(new QueryWrapper().eq("id", userid1)); + String usser = ""; + String name = ""; + for (MyUserEntity user : id) { + usser = user.getAvatar(); + name = user.getNickname(); + } + List followUpEntity = userFollowUpService.getBaseMapper().selectList(new QueryWrapper() + .eq("oid", id1) + .eq("userId", userid1) + .orderByDesc("create_date")); + String conTent = ""; + Date date = null; + for (UserFollowUpEntity followUp : followUpEntity) { + conTent = followUp.getConTent(); + date = followUp.getCreateDate(); + } + map.put("followUpdate", date); + map.put("followUpcontent", conTent); + map.put("avatar", usser); + map.put("name", name); + map.put("bookid", bookid1); + map.put("orderSn", userRecord.getOrderSn()); + map.put("userid", userid1); + map.put("content", userRecord.getContent()); + map.put("images", userRecord.getImages()); + map.put("starlevel", userRecord.getStarLevel()); + map.put("createdate", userRecord.getCreateDate()); + list.add(map); + } + return R.ok().put("list", list); + } + return R.error("该商品暂无评论"); + + } + +}