015 品牌关联分类

ops/2024/10/9 4:17:33/

文章目录

    • 后端
      • CategoryBrandEntity.java
      • CategoryBrandController.java
      • CategoryBrandServiceImpl.java
      • CategoryServiceImpl.java
      • BrandServiceImpl.java
      • 删除

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*/@TableIdprivate 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 {@Autowiredprivate CategoryBrandService categoryBrandService;@Autowiredprivate CategoryService categoryService;@Autowiredprivate 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 {@Overridepublic 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 {@Overridepublic PageUtils queryPage(Map<String, Object> params) {IPage<CategoryEntity> page = this.page(new Query<CategoryEntity>().getPage(params),new QueryWrapper<CategoryEntity>());return new PageUtils(page);}/*** 查询所有分类* @return*/@Overridepublic 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.parentIdcategoryEntity -> currentMenu.getId().equals(categoryEntity.getParentId())).map((menu)->{//找到子分类menu.setChildrens(getChildrens(menu,entities));return menu;}).collect(Collectors.toList());return childrens;}/*** 逻辑删除菜单* @param asList*/@Overridepublic void removeMenuByIds(List<Integer> asList) {//TODO 检查当前要删除的菜单是否被别的地方引用//逻辑删除baseMapper.deleteBatchIds(asList);}/*** 收集三级菜单id* @param categoryId* @return [558, 559, 560]*/@Overridepublic 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 {@Overridepublic 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();}

http://www.ppmy.cn/ops/122979.html

相关文章

netty之Netty集群部署实现跨服务端通信的落地方案

前言 在一些小型用户体量的socket服务内&#xff0c;仅部署单台机器就可以满足业务需求。但当遇到一些中大型用户体量的服务时&#xff0c;就需要考虑讲Netty按照集群方式部署&#xff0c;以更好的满足业务诉求。但Netty部署集群后都会遇到跨服务端怎么通信&#xff0c;也就是有…

MKV转MP4丨FFmpeg的简单命令使用——视频格式转换

MKV是一种视频封装格式&#xff0c;很好用&#xff0c;也是OBS的默认推荐录制格式&#xff0c;因为不会突然断电关机而导致整个视频录制文件丢失。 但是MKV无法直接导入PR中剪辑&#xff0c;最直接的方法是将MKV转换为MP4格式&#xff0c;最方便且安全无损的转换方法便是用FFmp…

面试(十)

目录 一. 单元测试 二. FreeRTOS和裸机哪个实时性好&#xff1f; 三. 怎么判断某个程序的运行时间 四. 函数指针 五. 全局变量被线程使用冲突 5.1 使用互斥锁 5.2 使用读写锁 5.3 使用原子操作 六. 局部变量没有初始化是什么值 七. uint_8 n 255 , n等于多少 八. …

【Linux第五课-进程概念下】环境变量、程序地址空间

目录 环境变量main参数 --- 命令行参数环境变量环境变量特性 --- 命令行操作main函数的参数获取环境变量environ获取环境变量getenv()获取环境变量unset移除本地变量或环境变量set显示本地变量 代码获取和设置环境变量 本地变量 程序地址空间什么是进程地址空间为什么有地址空间…

C++学习笔记----8、掌握类与对象(六)---- 操作符重载(1)

经常在对象上执行如相加&#xff0c;比较&#xff0c;文件传输等操作。例如&#xff0c;spreadsheet只有在可以在上面执行自述运算才有用&#xff0c;比如对整行的单元格求和。所有这些都可以通过重载操作符来完成。 许多人发现操作符重载的语法复杂而令人迷惑。至少一开始是这…

Dev-C++ 安装与使用(dev c++官网)(已解决)

1.Dev-C的安装 ①打开Dev-C的官网(https://sourceforge.net/projects/orwelldevcpp/ )&#xff1b;点击Download(下载)&#xff0c;等待5秒后开始下载。 ②点开下载好的EXE文件&#xff0c;等待加载完成(如图)。 右键&#xff0c;以管理员身份 运行安装包。 选择English(英语),…

银河麒麟,apt 安装软件报错640Unknown Status

今天把银行麒麟的机器恢复出厂了&#xff0c;然后apt install 安装极其不稳定&#xff0c;故障现象如下图所示&#xff1a; 错误提示里面有&#xff1a; 640 Unknown Status [IP: 106.116.184.122 80] E: 无法下载 http://archive.kylinos.cn/kylin/KYLIN-ALL/pool/universe/f…

论文速读:基于渐进式转移的无监督域自适应舰船检测

这篇文章的标题是《Unsupervised Domain Adaptation Based on Progressive Transfer for Ship Detection: From Optical to SAR Images》基于渐进式转移的无监督域自适应舰船检测:从光学图像到SAR图像&#xff0c;作者是Yu Shi等人。文章发表在IEEE Transactions on Geoscience…