015 品牌关联分类

发布于:2024-10-12 ⋅ 阅读:(115) ⋅ 点赞:(0)

npm install pubsub-js
npm install --save pubsub-js
这个错误是由于在尝试安装 pubsub-js 时,npm 发现了项目中存在依赖冲突。具体来说,是 sass-loader@6.0.6 需要 node-sass@^4.0.0(即 4.x 版本),但你的项目中实际安装的是 node-sass@1.77.8,这是一个较新的版本,不兼容 sass-loader@6.0.6。

要解决这个问题,你有几个选项:

更新 sass-loader: 检查是否有新版本的 sass-loader 兼容你当前安装的 node-sass 版本。如果有,更新 sass-loader 到这个版本。你可以在 npm 或者 GitHub 上查看 sass-loader 的最新版本和兼容性信息。
降级 node-sass: 如果没有可用的 sass-loader 更新,你可能需要将 node-sass 降级到 4.x 版本。你可以通过修改 package.json 文件中的依赖版本,然后运行 npm install 来实现。
使用 --legacy-peer-deps: 如果你不想改动依赖版本,可以在安装命令中添加 --legacy-peer-deps 选项,这将忽略 peer 依赖冲突。例如:
npm install pubsub-js --legacy-peer-deps
使用 --force: 这是一个更激进的选择,它将强制 npm 忽略所有冲突并继续安装。但这可能会导致不可预见的问题,因此建议谨慎使用:
npm install pubsub-js --force
清理 node_modules 和缓存: 有时候,清理现有的 node_modules 目录和 npm 缓存可以解决依赖问题。你可以尝试以下命令:
rm -rf node_modules  
npm cache clean --force  
npm install
建议首先尝试更新 sass-loader 或降级 node-sass,因为这些方法更可能保持项目的稳定性和兼容性。如果这些方法不可行,再考虑使用 --legacy-peer-deps 或 --force 选项。
命令 npm install --save pubsub-js 在 Node.js 和 npm (Node Package Manager) 环境中用于安装一个名为 pubsub-js 的包,并将其作为依赖项保存到项目的 package.json 文件中。下面是对这个命令的详细解释:

npm install: 这是 npm 的主要命令之一,用于安装 Node.js 包。这个命令会从 npm 仓库(或指定的其他源)下载包及其依赖,并将它们安装到当前项目的 node_modules 目录中。
--save: 这个选项告诉 npm 将安装的包作为一个依赖项添加到项目的 package.json 文件的 dependencies 部分。这样做的好处是,其他人(或你自己在其他地方)可以通过运行 npm install(不带任何参数)来自动安装所有列出的依赖项,从而更容易地复制和设置项目环境。在较新的 npm 版本中,--save 是默认行为,因此通常可以省略。
pubsub-js: 这是你要安装的包的名称。pubsub-js 是一个 JavaScript 的发布/订阅(Pub/Sub)模式的实现库,允许你在应用中实现松耦合的消息传递。
总结起来,运行 npm install --save pubsub-js 后,pubsub-js 包会被安装到你项目的 node_modules 目录下,并且你的 package.json 文件会被更新,包含对 pubsub-js 的依赖。这样,无论何时何人克隆你的项目或在其他环境中设置它,只需运行 npm install 就可以确保所有必要的依赖都被正确安装。

品牌分类关联

后端

CategoryBrandEntity.java

package com.xd.cubemall.product.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Date;
import lombok.Data;

/**
 * 分类品牌关系表
 * 
 * @author xuedong
 * @email email@gmail.com
 * @date 2024-08-13 01:36:04
 */
@Data
@TableName("tb_category_brand")
public class CategoryBrandEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 主键ID
	 */
	@TableId
	private Integer id;
	/**
	 * 分类ID
	 */
	private Integer categoryId;
	/**
	 * 品牌ID
	 */
	private Integer brandId;

	@TableField(exist = false)
	private String categoryName;

	@TableField(exist = false)
	private String brandName;

}

CategoryBrandController.java

package com.xd.cubemall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xd.cubemall.common.utils.PageUtils;
import com.xd.cubemall.common.utils.R;
import com.xd.cubemall.product.service.BrandService;
import com.xd.cubemall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xd.cubemall.product.entity.CategoryBrandEntity;
import com.xd.cubemall.product.service.CategoryBrandService;




/**
 * 分类品牌关系表
 *
 * @author xuedong
 * @email email@gmail.com
 * @date 2024-08-13 07:57:20
 */
@RestController
@RequestMapping("product/categorybrand")
public class CategoryBrandController {
    @Autowired
    private CategoryBrandService categoryBrandService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @RequestMapping("/category/list")
    //@RequiresPermissions("product:categorybrand:list")
    public R list(@RequestParam("brandId") Long brandid){
        List<CategoryBrandEntity> data = categoryBrandService.list(
                new QueryWrapper<CategoryBrandEntity>().eq("brand_id", brandid)
        );
        data.forEach(categoryBrandEntity -> {
            categoryBrandEntity.setCategoryName(categoryService.getById(categoryBrandEntity.getCategoryId()).getName());
            categoryBrandEntity.setBrandName(brandService.getById(categoryBrandEntity.getBrandId()).getName());
        });

        return R.ok().put("data", data);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:categorybrand:info")
    public R info(@PathVariable("id") Integer id){
		CategoryBrandEntity categoryBrand = categoryBrandService.getById(id);

        return R.ok().put("categoryBrand", categoryBrand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:categorybrand:save")
    public R save(@RequestBody CategoryBrandEntity categoryBrand){
		categoryBrandService.save(categoryBrand);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:categorybrand:update")
    public R update(@RequestBody CategoryBrandEntity categoryBrand){
		categoryBrandService.updateById(categoryBrand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:categorybrand:delete")
    public R delete(@RequestBody Integer[] ids){
		categoryBrandService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}

CategoryBrandServiceImpl.java

package com.xd.cubemall.product.service.impl;

import com.xd.cubemall.common.utils.PageUtils;
import com.xd.cubemall.common.utils.Query;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.xd.cubemall.product.dao.CategoryBrandDao;
import com.xd.cubemall.product.entity.CategoryBrandEntity;
import com.xd.cubemall.product.service.CategoryBrandService;


@Service("categoryBrandService")
public class CategoryBrandServiceImpl extends ServiceImpl<CategoryBrandDao, CategoryBrandEntity> implements CategoryBrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CategoryBrandEntity> page = this.page(
                new Query<CategoryBrandEntity>().getPage(params),
                new QueryWrapper<CategoryBrandEntity>()
        );

        return new PageUtils(page);
    }

}

CategoryServiceImpl.java

package com.xd.cubemall.product.service.impl;

import com.xd.cubemall.common.utils.PageUtils;
import com.xd.cubemall.common.utils.Query;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.xd.cubemall.product.dao.CategoryDao;
import com.xd.cubemall.product.entity.CategoryEntity;
import com.xd.cubemall.product.service.CategoryService;


@Service("categoryService")
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity> implements CategoryService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CategoryEntity> page = this.page(
                new Query<CategoryEntity>().getPage(params),
                new QueryWrapper<CategoryEntity>()
        );

        return new PageUtils(page);
    }


    /**
     * 查询所有分类
     * @return
     */
    @Override
    public List<CategoryEntity> listWithTree() {
        //1.查询所有分类
        List<CategoryEntity> entities = baseMapper.selectList(null);

        //2.组装成父子的树形结构
        //2.1 找到所有的一级分类
        List<CategoryEntity> levelOneMenus = entities.stream().filter(
            //过滤出一级分类,parentId==0,根据这个条件构建出所有一级分类的数据
                categoryEntity -> categoryEntity.getParentId() == 0

        ).map((menu)->{
            //出现递归操作,关联出子分类(2,3级分类)
            menu.setChildrens(getChildrens(menu,entities));
            return menu;
        }).collect(Collectors.toList());
        return levelOneMenus;
    }

    /**
     * 递归查找指定分类的所有子分类(所有菜单的子菜单)
     * @param currentMenu
     * @param entities
     * @return
     */
    private List<CategoryEntity> getChildrens(CategoryEntity currentMenu, List<CategoryEntity> entities) {
        List<CategoryEntity> childrens = entities.stream().filter(
            //过滤出 当前菜单的所有匹配的子菜单 currentMenu.id == categoryEntity.parentId
                categoryEntity -> currentMenu.getId().equals(categoryEntity.getParentId())

        ).map((menu)->{
            //找到子分类
            menu.setChildrens(getChildrens(menu,entities));
            return menu;
        }).collect(Collectors.toList());

        return childrens;
    }

    /**
     * 逻辑删除菜单
     * @param asList
     */
    @Override
    public void removeMenuByIds(List<Integer> asList) {
        //TODO 检查当前要删除的菜单是否被别的地方引用
        //逻辑删除
        baseMapper.deleteBatchIds(asList);
    }

    /**
     * 收集三级菜单id
     * @param categoryId
     * @return [558, 559, 560]
     */
    @Override
    public Long[] findCategoryPath(Integer categoryId) {
        List<Long> paths = new ArrayList<>();
        //通过递归查询到 把当前分类id与父分类id 添加到paths集合中
        List<Long> parentPath = findParentPath(categoryId, paths);

        Collections.reverse(parentPath);
        return parentPath.toArray(new Long[parentPath.size()]);
    }


    /**
     * 递归收集菜单id
     * @param categoryId
     * @param paths
     * @return [560, 559, 558]
     */
    private List<Long> findParentPath(Integer categoryId, List<Long> paths) {
        //收集当前分类id到集合中
        paths.add(categoryId.longValue());
        CategoryEntity categoryEntity = this.getById(categoryId);
        if (categoryEntity.getParentId() != 0){
            findParentPath(categoryEntity.getParentId(), paths);
        }
        return paths;
    }
}

BrandServiceImpl.java

package com.xd.cubemall.product.service.impl;

import com.xd.cubemall.common.utils.PageUtils;
import com.xd.cubemall.common.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.xd.cubemall.product.dao.BrandDao;
import com.xd.cubemall.product.entity.BrandEntity;
import com.xd.cubemall.product.service.BrandService;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        //编写条件查询的条件
        String key = (String) params.get("key");
        QueryWrapper<BrandEntity> queryWrapper = new QueryWrapper<>();
        //封装查询条件
        if(!StringUtils.isEmpty(key)) {
            queryWrapper.eq("id",key).or().like("name",key);
        }

        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}

删除

CategoryBrandController

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:categorybrand:delete")
    public R delete(@RequestBody CategoryBrandEntity categoryBrandEntity){
		//categoryBrandService.removeByIds(Arrays.asList(ids));

        categoryBrandService.remove(
                new QueryWrapper<CategoryBrandEntity>().eq("brand_id",categoryBrandEntity.getBrandId()).eq("category_id",categoryBrandEntity.getCategoryId())
        );
        return R.ok();
    }

网站公告

今日签到

点亮在社区的每一天
去签到