图书和营销标签、小店

This commit is contained in:
wuchunlei
2024-03-21 09:22:27 +08:00
parent c536752f14
commit b68d7201d6
22 changed files with 734 additions and 0 deletions

View File

@@ -0,0 +1,234 @@
package com.peanut.modules.book.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* 商品书和营销标签
*/
@Slf4j
@RestController
@RequestMapping("book/labelAndMarket")
public class BookLabelAndMarketController {
@Autowired
private ShopProductBookLabelService labelService;
@Autowired
private ShopProductBookMarketService marketService;
@Autowired
private ShopProductToBookLabelService toLabelService;
@Autowired
private ShopProductToBookMarketService toMarketService;
@Autowired
private ShopProductService productService;
/**
* 图书标签树
*/
@RequestMapping(path = "/labelTree")
public R labelTree() {
List<ShopProductBookLabel> labelsTree = labelService.labelTree();
return R.ok().put("result", labelsTree);
}
/**
* 获取图书标签列表
*/
@RequestMapping(path = "/getLabelListByPid")
public R getLabelListByPid(String pid) {
LambdaQueryWrapper<ShopProductBookLabel> wrapper = new LambdaQueryWrapper();
wrapper.eq(ShopProductBookLabel::getPid,pid);
wrapper.orderByAsc(ShopProductBookLabel::getSort);
wrapper.orderByAsc(ShopProductBookLabel::getCreateTime);
List<ShopProductBookLabel> labelTopList = labelService.list(wrapper);
return R.ok().put("result", labelTopList);
}
/**
* 图书营销标签树
*/
@RequestMapping(path = "/marketTree")
public R marketTree() {
List<ShopProductBookMarket> marketsTree = marketService.marketTree();
return R.ok().put("result", marketsTree);
}
/**
* 获取图书营销标签列表
*/
@RequestMapping(path = "/getMakertListByPid")
public R getMakertListByPid(String pid) {
LambdaQueryWrapper<ShopProductBookMarket> wrapper = new LambdaQueryWrapper();
wrapper.eq(ShopProductBookMarket::getPid,pid);
wrapper.orderByAsc(ShopProductBookMarket::getSort);
wrapper.orderByAsc(ShopProductBookMarket::getCreateTime);
List<ShopProductBookMarket> marketTopList = marketService.list(wrapper);
return R.ok().put("result", marketTopList);
}
@RequestMapping(path = "/getLabelById")
public R getLabelById(String id) {
return R.ok().put("result",labelService.getById(id));
}
@RequestMapping(path = "/saveOrUpdateLabel")
public R saveOrUpdateLabel(@RequestBody ShopProductBookLabel label) {
labelService.saveOrUpdate(label);
return R.ok();
}
@RequestMapping(path = "/delLabel")
public R delLabel(String id) {
labelService.removeById(id);
return R.ok();
}
@RequestMapping(path = "/getMarketById")
public R getMarketById(String id) {
return R.ok().put("result",marketService.getById(id));
}
@RequestMapping(path = "/saveOrUpdateMarket")
public R saveOrUpdateMarket(@RequestBody ShopProductBookMarket market) {
marketService.saveOrUpdate(market);
return R.ok();
}
@RequestMapping(path = "/delMarket")
public R delMarket(String id) {
marketService.removeById(id);
return R.ok();
}
/**
* 获取书标签列表
*/
@RequestMapping("/getToLabelList")
public R getToLabelList(@RequestBody Map params){
MPJLambdaWrapper<ShopProductToBookLabel> wrapper = new MPJLambdaWrapper();
wrapper.selectAll(ShopProductToBookLabel.class);
wrapper.leftJoin(ShopProduct.class,ShopProduct::getProductId,ShopProductToBookLabel::getProductId);
if (params.containsKey("productName")&&!"".equals(params.get("productName").toString())){
wrapper.like(ShopProduct::getProductName,params.get("productName").toString());
}
if (params.containsKey("productId")&&!"".equals(params.get("productId").toString())){
wrapper.eq(ShopProductToBookLabel::getProductId,params.get("productId").toString());
}
if (params.containsKey("bookLabelId")&&!"".equals(params.get("bookLabelId").toString())){
wrapper.eq(ShopProductToBookLabel::getBookLabelId,params.get("bookLabelId").toString());
}
Page<ShopProductToBookLabel> page = toLabelService.page(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
List<ShopProductToBookLabel> res = page.getRecords();
if (res.size() > 0) {
for (ShopProductToBookLabel item : res) {
item.setProduct(productService.getById(item.getProductId()));
item.setLabel(labelService.getById(item.getBookLabelId()));
}
}
page.setRecords(res);
return R.ok().put("result", page);
}
/**
* 获取营销标签列表
*/
@RequestMapping("/getToMarketList")
public R getToMarketList(@RequestBody Map params){
MPJLambdaWrapper<ShopProductToBookMarket> wrapper = new MPJLambdaWrapper();
wrapper.selectAll(ShopProductToBookMarket.class);
wrapper.leftJoin(ShopProduct.class,ShopProduct::getProductId,ShopProductToBookMarket::getProductId);
if (params.containsKey("productName")&&!"".equals(params.get("productName").toString())){
wrapper.like(ShopProduct::getProductName,params.get("productName").toString());
}
if (params.containsKey("productId")&&!"".equals(params.get("productId").toString())){
wrapper.eq(ShopProductToBookMarket::getProductId,params.get("productId").toString());
}
if (params.containsKey("bookMarketId")&&!"".equals(params.get("bookMarketId").toString())){
wrapper.eq(ShopProductToBookMarket::getBookMarketId,params.get("bookMarketId").toString());
}
Page<ShopProductToBookMarket> page = toMarketService.page(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
List<ShopProductToBookMarket> res = page.getRecords();
if (res.size() > 0) {
for (ShopProductToBookMarket item : res) {
item.setProduct(productService.getById(item.getProductId()));
item.setMarket(marketService.getById(item.getBookMarketId()));
}
}
page.setRecords(res);
return R.ok().put("result", page);
}
@RequestMapping(path = "/getToLabelById")
public R getToLabelById(String id) {
return R.ok().put("result",toLabelService.getById(id));
}
@RequestMapping(path = "/saveToLabel")
public R saveToLabel(@RequestBody ShopProductToBookLabel toLabel) {
LambdaQueryWrapper<ShopProductToBookLabel> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopProductToBookLabel::getBookLabelId,toLabel.getBookLabelId());
wrapper.eq(ShopProductToBookLabel::getProductId,toLabel.getProductId());
List list = toLabelService.list(wrapper);
if (list.size() > 0) {
return R.error("已存在");
}else {
toLabelService.save(toLabel);
return R.ok();
}
}
@RequestMapping(path = "/delToLabel")
public R delToLabel(String id) {
toLabelService.removeById(id);
return R.ok();
}
@RequestMapping(path = "/getToMarketById")
public R getToMarketById(String id) {
return R.ok().put("result",toMarketService.getById(id));
}
@RequestMapping(path = "/saveToMarket")
public R saveToMarket(@RequestBody ShopProductToBookMarket toMarket) {
LambdaQueryWrapper<ShopProductToBookMarket> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopProductToBookMarket::getBookMarketId,toMarket.getBookMarketId());
wrapper.eq(ShopProductToBookMarket::getProductId,toMarket.getProductId());
List list = toMarketService.list(wrapper);
if (list.size() > 0) {
return R.error("已存在");
}else {
toMarketService.save(toMarket);
return R.ok();
}
}
@RequestMapping(path = "/delToMarket")
public R delToMarket(String id) {
toMarketService.removeById(id);
return R.ok();
}
}

View File

@@ -0,0 +1,54 @@
package com.peanut.modules.book.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.ShopStore;
import com.peanut.modules.book.service.ShopStoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("book/shopStore")
public class ShopStoreController {
@Autowired
private ShopStoreService shopStoreService;
/**
* 获取小店列表
*/
@RequestMapping("/getStoreList")
public R getStoreList(@RequestBody Map params){
MPJLambdaWrapper<ShopStore> wrapper = new MPJLambdaWrapper();
if (params.containsKey("name")&&!"".equals(params.get("name").toString())){
wrapper.like(ShopStore::getName,params.get("name").toString());
}
Page<ShopStore> page = shopStoreService.page(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
return R.ok().put("result", page);
}
@RequestMapping(path = "/getStoreById")
public R getStoreById(String id) {
return R.ok().put("result",shopStoreService.getById(id));
}
@RequestMapping(path = "/saveOrUpdateStore")
public R saveOrUpdateStore(@RequestBody ShopStore store) {
shopStoreService.saveOrUpdate(store);
return R.ok();
}
@RequestMapping(path = "/delStore")
public R delStore(String id) {
shopStoreService.removeById(id);
return R.ok();
}
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.book.entity.ShopProductBookLabel;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ShopProductBookLabelDao extends BaseMapper<ShopProductBookLabel> {
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.book.entity.ShopProductBookMarket;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ShopProductBookMarketDao extends BaseMapper<ShopProductBookMarket> {
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.book.entity.ShopProductToBookLabel;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ShopProductToBookLabelDao extends BaseMapper<ShopProductToBookLabel> {
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.book.entity.ShopProductToBookMarket;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ShopProductToBookMarketDao extends BaseMapper<ShopProductToBookMarket> {
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.book.entity.ShopStore;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ShopStoreDao extends BaseMapper<ShopStore> {
}

View File

@@ -0,0 +1,53 @@
package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
@TableName("shop_product_book_label")
public class ShopProductBookLabel implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
/**
* 父id
*/
private Integer pid;
/**
* 标题
*/
private String title;
/**
* 0否1是
*/
private Integer isLast;
/**
* 权重
*/
private Integer sort;
/**
* 创建时间
*/
private Date createTime;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private List<ShopProductBookLabel> children;
}

View File

@@ -0,0 +1,55 @@
package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
@TableName("shop_product_book_market")
public class ShopProductBookMarket implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
/**
* 父id
*/
private Integer pid;
/**
* 标题
*/
private String title;
/**
* 0否1是
*/
private Integer isLast;
/**
* 权重
*/
private Integer sort;
/**
* 创建时间
*/
private Date createTime;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private List<ShopProductBookMarket> children;
}

View File

@@ -0,0 +1,41 @@
package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
@TableName("shop_product_to_book_label")
public class ShopProductToBookLabel implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
private Integer productId;
private Integer bookLabelId;
/**
* 创建时间
*/
private Date createTime;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private ShopProduct product;
@TableField(exist = false)
private ShopProductBookLabel label;
}

View File

@@ -0,0 +1,40 @@
package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName("shop_product_to_book_market")
public class ShopProductToBookMarket implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
private Integer productId;
private Integer bookMarketId;
/**
* 创建时间
*/
private Date createTime;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private ShopProduct product;
@TableField(exist = false)
private ShopProductBookMarket market;
}

View File

@@ -0,0 +1,34 @@
package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName("shop_store")
public class ShopStore implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
/**
* 店名
*/
private String name;
/**
* 介绍图片
*/
private String images;
/**
* 创建时间
*/
private Date createTime;
@TableLogic
private Integer delFlag;
}

View File

@@ -0,0 +1,11 @@
package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.book.entity.ShopProductBookLabel;
import java.util.List;
public interface ShopProductBookLabelService extends IService<ShopProductBookLabel> {
List<ShopProductBookLabel> labelTree();
}

View File

@@ -0,0 +1,12 @@
package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.book.entity.ShopProductBookMarket;
import java.util.List;
public interface ShopProductBookMarketService extends IService<ShopProductBookMarket> {
List<ShopProductBookMarket> marketTree();
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.book.entity.ShopProductToBookLabel;
public interface ShopProductToBookLabelService extends IService<ShopProductToBookLabel> {
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.book.entity.ShopProductToBookMarket;
public interface ShopProductToBookMarketService extends IService<ShopProductToBookMarket> {
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.book.entity.ShopStore;
public interface ShopStoreService extends IService<ShopStore> {
}

View File

@@ -0,0 +1,47 @@
package com.peanut.modules.book.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.book.dao.ShopProductBookLabelDao;
import com.peanut.modules.book.entity.ShopProductBookLabel;
import com.peanut.modules.book.service.ShopProductBookLabelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service("shopProductBookLabelService")
public class ShopProductBookLabelServiceImpl extends ServiceImpl<ShopProductBookLabelDao, ShopProductBookLabel> implements ShopProductBookLabelService {
@Autowired
private ShopProductBookLabelDao labelDao;
@Override
public List<ShopProductBookLabel> labelTree() {
List<ShopProductBookLabel> labels = labelDao.selectList(new QueryWrapper<>());
List<ShopProductBookLabel> labelsTree = labels.stream().filter((shopProductBookLabel) ->
shopProductBookLabel.getPid() == 0
).map((label)->{
label.setChildren(getLabelChildrens(label,labels));
return label;
}).sorted((label1,label2)->{
return (label1.getSort() == null? 0 : label1.getSort()) - (label2.getSort()==null?0:label2.getSort());
}).collect(Collectors.toList());
return labelsTree;
}
private List<ShopProductBookLabel> getLabelChildrens(ShopProductBookLabel root,List<ShopProductBookLabel> all){
List<ShopProductBookLabel> children = all.stream().filter(shopProductBookLabel -> {
return root.getId().equals(shopProductBookLabel.getPid());
}).map(shopProductBookLabel -> {
shopProductBookLabel.setChildren(getLabelChildrens(shopProductBookLabel, all));
return shopProductBookLabel;
}).sorted((label1,label2)->{
return (label1.getSort()==null?0:label1.getSort()) - (label2.getSort()==null?0:label2.getSort());
}).collect(Collectors.toList());
return children;
}
}

View File

@@ -0,0 +1,48 @@
package com.peanut.modules.book.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.utils.R;
import com.peanut.modules.book.dao.ShopProductBookMarketDao;
import com.peanut.modules.book.entity.ShopProductBookMarket;
import com.peanut.modules.book.service.ShopProductBookMarketService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service("shopProductBookMarketService")
public class ShopProductBookMarketServiceImpl extends ServiceImpl<ShopProductBookMarketDao, ShopProductBookMarket> implements ShopProductBookMarketService {
@Autowired
private ShopProductBookMarketDao marketDao;
@Override
public List<ShopProductBookMarket> marketTree() {
List<ShopProductBookMarket> markets = marketDao.selectList(new QueryWrapper<>());
List<ShopProductBookMarket> marketsTree = markets.stream().filter((shopProductBookMarket) ->
shopProductBookMarket.getPid() == 0
).map((market)->{
market.setChildren(getMarketChildrens(market,markets));
return market;
}).sorted((sort1,sort2)->{
return (sort1.getSort() == null? 0 : sort1.getSort()) - (sort2.getSort()==null?0:sort2.getSort());
}).collect(Collectors.toList());
return marketsTree;
}
private List<ShopProductBookMarket> getMarketChildrens(ShopProductBookMarket root,List<ShopProductBookMarket> all){
List<ShopProductBookMarket> children = all.stream().filter(shopProductBookMarket -> {
return root.getId().equals(shopProductBookMarket.getPid());
}).map(shopProductBookMarket -> {
shopProductBookMarket.setChildren(getMarketChildrens(shopProductBookMarket, all));
return shopProductBookMarket;
}).sorted((sort1,sort2)->{
return (sort1.getSort()==null?0:sort1.getSort()) - (sort2.getSort()==null?0:sort2.getSort());
}).collect(Collectors.toList());
return children;
}
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.book.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.book.dao.ShopProductToBookLabelDao;
import com.peanut.modules.book.entity.ShopProductToBookLabel;
import com.peanut.modules.book.service.ShopProductToBookLabelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("shopProductToBookLabelService")
public class ShopProductToBookLabelServiceImpl extends ServiceImpl<ShopProductToBookLabelDao, ShopProductToBookLabel> implements ShopProductToBookLabelService {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.book.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.book.dao.ShopProductToBookMarketDao;
import com.peanut.modules.book.entity.ShopProductToBookMarket;
import com.peanut.modules.book.service.ShopProductToBookMarketService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("shopProductToBookMarketService")
public class ShopProductToBookMarketServiceImpl extends ServiceImpl<ShopProductToBookMarketDao, ShopProductToBookMarket> implements ShopProductToBookMarketService {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.book.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.book.dao.ShopStoreDao;
import com.peanut.modules.book.entity.ShopStore;
import com.peanut.modules.book.service.ShopStoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("shopStore")
public class ShopStoreServiceImpl extends ServiceImpl<ShopStoreDao, ShopStore> implements ShopStoreService {
}