当前位置: 首页 > news >正文

014 属性分组

文章目录

    • 后端
      • AttrGroupEntity.java
      • CategoryEntity.java
      • AttrGroupController.java
      • CategoryServiceImpl.java
    • 前端
      • attrgroup-add-or-update.vue

https://element.eleme.cn/#/zh-CN/component/cascader

后端

AttrGroupEntity.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_attr_group")
public class AttrGroupEntity implements Serializable {private static final long serialVersionUID = 1L;/*** 自增ID*/@TableIdprivate Long id;/*** 名称*/private String name;/*** 排序*/private Integer sort;/*** 描述*/private String descript;/*** 图表*/private String icon;/*** 分类ID*/private Integer categoryId;/*** 完整的categoryID的路径*/@TableField(exist = false)private Long[] categoryPath;
}

CategoryEntity.java

package com.xd.cubemall.product.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 java.io.Serializable;
import java.util.Date;
import java.util.List;import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;/*** 商品类目* * @author xuedong* @email email@gmail.com* @date 2024-08-13 01:36:04*/
@Data
@TableName("tb_category")
public class CategoryEntity implements Serializable {private static final long serialVersionUID = 1L;/*** 子分类*/@JsonInclude(JsonInclude.Include.NON_EMPTY)@TableField(exist = false)private List<CategoryEntity> childrens;/*** 分类ID*/@TableIdprivate Integer id;/*** 分类名称*/private String name;/*** 商品数量*/private Integer goodsNum;/*** 是否显示*/@TableLogic(value = "1",delval = "0")private String isShow;/*** 是否导航*/private String isMenu;/*** 排序*/private Integer seq;/*** 上级ID*/private Integer parentId;/*** 模板ID*/private Integer templateId;}

AttrGroupController.java

package com.xd.cubemall.product.controller;import java.util.Arrays;
import java.util.Map;import com.xd.cubemall.common.utils.PageUtils;
import com.xd.cubemall.common.utils.R;
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.AttrGroupEntity;
import com.xd.cubemall.product.service.AttrGroupService;/*** 属性分组表** @author xuedong* @email email@gmail.com* @date 2024-08-13 07:57:20*/
@RestController
@RequestMapping("product/attrgroup")
public class AttrGroupController {@Autowiredprivate AttrGroupService attrGroupService;@Autowiredprivate CategoryService categoryService;/*** 列表*/@RequestMapping("/list/{categoryId}")//@RequiresPermissions("product:attrgroup:list")public R list(@RequestParam Map<String, Object> params, @PathVariable("categoryId") Long categoryId){//PageUtils page = attrGroupService.queryPage(params);PageUtils page = attrGroupService.queryPage(params, categoryId);return R.ok().put("page", page);}/*** 信息*/@RequestMapping("/info/{id}")//@RequiresPermissions("product:attrgroup:info")public R info(@PathVariable("id") Long id){AttrGroupEntity attrGroup = attrGroupService.getById(id);//查询出categoryPath的路径//当前分类IDInteger categoryId = attrGroup.getCategoryId();//查询出当前分类ID的 祖宗IDLong[] path = categoryService.findCategoryPath(categoryId);attrGroup.setCategoryPath(path);return R.ok().put("attrGroup", attrGroup);}/*** 保存*/@RequestMapping("/save")//@RequiresPermissions("product:attrgroup:save")public R save(@RequestBody AttrGroupEntity attrGroup){attrGroupService.save(attrGroup);return R.ok();}/*** 修改*/@RequestMapping("/update")//@RequiresPermissions("product:attrgroup:update")public R update(@RequestBody AttrGroupEntity attrGroup){attrGroupService.updateById(attrGroup);return R.ok();}/*** 删除*/@RequestMapping("/delete")//@RequiresPermissions("product:attrgroup:delete")public R delete(@RequestBody Long[] ids){attrGroupService.removeByIds(Arrays.asList(ids));return R.ok();}}

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

前端

attrgroup-add-or-update.vue


<template><el-dialog:title="!dataForm.id ? '新增' : '修改'":close-on-click-modal="false":visible.sync="visible"><el-form:model="dataForm":rules="dataRule"ref="dataForm"@keyup.enter.native="dataFormSubmit()"label-width="130px"><el-form-item label="名称" prop="name"><el-input v-model="dataForm.name" placeholder="名称"></el-input></el-form-item><el-form-item label="排序" prop="sort"><el-input v-model="dataForm.sort" placeholder="排序"></el-input></el-form-item><el-form-item label="描述" prop="descript"><el-input v-model="dataForm.descript" placeholder="描述"></el-input></el-form-item><el-form-item label="图表" prop="icon"><el-input v-model="dataForm.icon" placeholder="图表"></el-input></el-form-item><el-form-item label="分类ID" prop="categoryId"><!-- <el-input v-model="dataForm.categoryId" placeholder="分类ID"></el-input> --><el-cascaderv-model="dataForm.categoryPath":options="categorys":props="props"></el-cascader></el-form-item></el-form><span slot="footer" class="dialog-footer"><el-button @click="visible = false">取消</el-button><el-button type="primary" @click="dataFormSubmit()">确定</el-button></span></el-dialog>
</template><script>
export default {data() {return {props:{value: "id",label: "name",children: "childrens"},categorys: [],visible: false,dataForm: {id: 0,name: "",sort: "",descript: "",icon: "",categoryPath: [],categoryId: 0,},dataRule: {name: [{ required: true, message: "名称不能为空", trigger: "blur" }],sort: [{ required: true, message: "排序不能为空", trigger: "blur" }],descript: [{ required: true, message: "描述不能为空", trigger: "blur" },],icon: [{ required: true, message: "图表不能为空", trigger: "blur" }],categoryId: [{ required: true, message: "分类ID不能为空", trigger: "blur" },],},};},created(){this.getCategorys()},methods: {// 查询分类菜单getCategorys() {this.$http({url: this.$http.adornUrl("/product/category/list/tree"),method: "get",}).then(({ data }) => {console.log("成功获取到了菜单数据...", data);this.categorys = data.data;});},init(id) {this.dataForm.id = id || 0;this.visible = true;this.$nextTick(() => {this.$refs["dataForm"].resetFields();if (this.dataForm.id) {this.$http({url: this.$http.adornUrl(`/product/attrgroup/info/${this.dataForm.id}`),method: "get",params: this.$http.adornParams(),}).then(({ data }) => {if (data && data.code === 0) {this.dataForm.name = data.attrGroup.name;this.dataForm.sort = data.attrGroup.sort;this.dataForm.descript = data.attrGroup.descript;this.dataForm.icon = data.attrGroup.icon;this.dataForm.categoryId = data.attrGroup.categoryId;//查询categoryID的完整菜单this.dataForm.categoryPath = data.attrGroup.categoryPath}});}});},// 表单提交dataFormSubmit() {this.$refs["dataForm"].validate((valid) => {if (valid) {this.$http({url: this.$http.adornUrl(`/product/attrgroup/${!this.dataForm.id ? "save" : "update"}`),method: "post",data: this.$http.adornData({id: this.dataForm.id || undefined,name: this.dataForm.name,sort: this.dataForm.sort,descript: this.dataForm.descript,icon: this.dataForm.icon,categoryId: this.dataForm.categoryPath[this.dataForm.categoryPath.length-1],}),}).then(({ data }) => {if (data && data.code === 0) {this.$message({message: "操作成功",type: "success",duration: 1500,onClose: () => {this.visible = false;this.$emit("refreshDataList");},});} else {this.$message.error(data.msg);}});}});},},
};
</script>

相关文章:

014 属性分组

文章目录 后端AttrGroupEntity.javaCategoryEntity.javaAttrGroupController.javaCategoryServiceImpl.java 前端attrgroup-add-or-update.vue https://element.eleme.cn/#/zh-CN/component/cascader 后端 AttrGroupEntity.java package com.xd.cubemall.product.entity;impo…...

ElasticSearch备考 -- Alias

一、题目 1) Create the alias hamlet that maps both hamlet-1 and hamlet-2 Verify that the documents grouped by hamlet are 8 2) Configure hamlet-3 to be the write index of the hamlet alias 二、思考 可以通过指定别名&#xff0c;来指向一个或多个索引&#xff0c…...

使用AI编码,这些安全风险你真的了解吗?

前言 随着AI技术的飞速发展与普及&#xff0c;企业开发人员对AI编码助手工具如Copilot的依赖度日益增强&#xff0c;使用AI编码助手工具虽然能显著提升编程效率与质量&#xff0c;但同时也存在一系列的潜在风险。 许多开发人员可能未意识到&#xff0c;如果他们的现有代码库中…...

计算机网络实验一:组建对等网络

实验一 组建对等网络 实验要求&#xff1a; 1. 组建对等网络&#xff0c;会在命令行使用ipconfig&#xff0c;两网络能够相互ping通&#xff0c;尝试netstat 命令 2. 建立局域网共享文件夹 3. 安装packet tracer&#xff0c;模拟组建对等网并测试对等网 1、组建对等网络 连…...

R语言绘制折线图

折线图是实用的数据可视化工具&#xff0c;通过连接数据点的线段展示数据随时间或变量的变化趋势。在经济、科学、销售及天气预报等领域广泛应用&#xff0c;为决策和分析提供依据。它能清晰呈现经济数据动态、助力科学研究、反映企业销售情况、预告天气变化&#xff0c;以简洁…...

基于组合模型的公交交通客流预测研究

摘 要 本研究致力于解决公交客流预测问题&#xff0c;旨在通过融合多种机器学习模型的强大能力&#xff0c;提升预测准确性&#xff0c;为城市公交系统的优化运营和交通管理提供科学依据。研究首先回顾了公交客流预测领域的相关文献&#xff0c;分析了传统统计方法在处理大规…...

docker环境redis启动失败

现象&#xff1a; 查看日志错误为 Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename> 经查询为aof文件损坏导致&#xff0c;修复aof即可 解决方法&#xff1a; 1.查看执行的docker命令&…...

Pandas库详细学习要点

Pandas库是一个基于Python的数据分析库&#xff0c;它提供了丰富的数据结构和数据分析工具&#xff0c;非常适合数据科学和数据分析领域的工作。以下是Pandas库详细学习的一些要点&#xff1a; 1. 数据结构 - Series&#xff1a;一维带标签数组&#xff0c;类似于NumPy中的一…...

光路科技TSN交换机:驱动自动驾驶技术革新,保障高精度实时数据传输

自动驾驶技术正快速演进&#xff0c;对实时数据处理能力的需求激增。光路科技推出的TSN&#xff08;时间敏感网络&#xff09;交换机&#xff0c;在比亚迪最新车型中的成功应用&#xff0c;显著推动了这一领域的技术进步。 自动驾驶技术面临的挑战 自动驾驶系统需整合来自雷达…...

【含开题报告+文档+PPT+源码】基于SpringBoot的社区家政服务预约系统设计与实现【包运行成功】

开题报告 社区家政服务是满足居民日常生活需求的重要组成部分&#xff0c;在现代社会中发挥着越来越重要的作用。随着城市化进程的不断加速&#xff0c;社区家政服务需求量呈现持续增长的趋势。然而&#xff0c;传统的家政服务模式存在一些问题&#xff0c;如预约流程繁琐、信…...

2024最新【Pycharm】史上最全PyCharm安装教程,图文教程(超详细)

1. PyCharm下载安装 完整安装包下载&#xff08;包含Python和Pycharm专业版注册码&#xff09;&#xff1a;点击这里 1&#xff09;访问官网 https://www.jetbrains.com/pycharm/download/#sectionwindows 下载「社区版 Community」 安装包。 2&#xff09;下载完成后&#…...

llama3 implemented from scratch 笔记

github地址&#xff1a;https://github.com/naklecha/llama3-from-scratch?tabreadme-ov-file 分词器的实现 from pathlib import Path import tiktoken from tiktoken.load import load_tiktoken_bpe import torch import json import matplotlib.pyplot as plttokenizer_p…...

照片在线转成二维码展示,更方便分享图片的好办法

怎么能把照片生成二维码后&#xff0c;分享给其他人展示呢&#xff1f;现在很多人为了能够更方便的将自己的图片展现给其他人会使用生成二维码的方式&#xff0c;将图片存储到云空间&#xff0c;通过扫码调取图片查看内容。与其他方式相比&#xff0c;这样会更加的方便&#xf…...

『网络游戏』登陆协议制定客户端发送账号密码CMD【19】

修改服务器脚本&#xff1a;ServerSession 修改服务器脚本&#xff1a;GameMsg 修改客户端脚本&#xff1a;ClientSession.cs 修改客户端脚本&#xff1a;NetSvc.cs 修改客户端脚本&#xff1a;WindowRoot.cs 修改客户端脚本&#xff1a;SystemRoot.cs 修改客户端脚本&#xff…...

独享动态IP是什么?它有什么独特优势吗?

在网络世界中&#xff0c;IP地址扮演着连接互联网的关键角色。随着互联网的发展&#xff0c;不同类型的IP地址也应运而生&#xff0c;其中独享动态ip作为一种新型IP地址&#xff0c;备受关注。本文将围绕它的定义及其独特优势展开探讨&#xff0c;以帮助读者更好地理解和利用这…...

gaussdb hccdp认证模拟题(单选)

1.在GaussDB逻辑架构中&#xff0c;由以下选项中的哪一个组件来负责提供集群日常运维、配置管理的管理接口、工具&#xff1f;(1 分) A. CN B. DN C. GTM D. OM --D 2.在以下命令中&#xff0c;使用以下哪一个选项中的命令可以以自定义归档形式导出表t1的定义&#xf…...

【斯坦福CS144】Lab1

一、实验目的 1.实现一个流重组器——一个将字节流的小块 &#xff08;称为子串或段 &#xff09;按正确顺序组装成连续的字节流的模块&#xff1b; 2.深入理解 TCP 协议的工作方式。 二、实验内容 编写一个名为"StreamReassembler"的数据结构&#xff0c;它负责…...

药箱里的药及其常见药的作用

药箱里有常备药&#xff0c;经常买药&#xff0c;但是忘了自己有什么药。容易之间弄混&#xff0c;以此作为更新存储的媒介。 1、阿莫西林胶囊 处方药 是指需要由医师或者医疗人员开局处方才能购买的药物(常见的OTC是非处方药的意思)。 截止时间 2024 10/10 药品资料汇总&am…...

Android屏幕旋转流程(2)

&#xff08;1&#xff09;疑问 &#xff08;1&#xff09;settings put system user_rotation 1是什么意思&#xff1f; 答&#xff1a;设置用户期望的屏幕转向&#xff0c;0代表&#xff1a;Surface.ROTATION_0竖屏&#xff1b;1代表&#xff1a;Surface.ROTATION_90横屏&a…...

gaussdb hccdp认证模拟题(判断)

1.在事务ACID特性中&#xff0c;原子性指的是事务必须始终保持系统处于一致的状态。(1 分) 错。 2.某IT公司在开发软件时&#xff0c;需要使用GaussDB数据库&#xff0c;因此需要实现软件和数据的链接&#xff0c;而DBeaver是一个通用的数据库管理工具和 SQL 客户端&#xff…...

VB.net复制Ntag213卡写入UID

本示例使用的发卡器&#xff1a;https://item.taobao.com/item.htm?ftt&id615391857885 一、读取旧Ntag卡的UID和数据 Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click轻松读卡技术支持:网站:Dim i, j As IntegerDim cardidhex, …...

【磁盘】每天掌握一个Linux命令 - iostat

目录 【磁盘】每天掌握一个Linux命令 - iostat工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景 注意事项 【磁盘】每天掌握一个Linux命令 - iostat 工具概述 iostat&#xff08;I/O Statistics&#xff09;是Linux系统下用于监视系统输入输出设备和CPU使…...

TRS收益互换:跨境资本流动的金融创新工具与系统化解决方案

一、TRS收益互换的本质与业务逻辑 &#xff08;一&#xff09;概念解析 TRS&#xff08;Total Return Swap&#xff09;收益互换是一种金融衍生工具&#xff0c;指交易双方约定在未来一定期限内&#xff0c;基于特定资产或指数的表现进行现金流交换的协议。其核心特征包括&am…...

解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错

出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上&#xff0c;所以报错&#xff0c;到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本&#xff0c;cu、torch、cp 的版本一定要对…...

【JavaSE】绘图与事件入门学习笔记

-Java绘图坐标体系 坐标体系-介绍 坐标原点位于左上角&#xff0c;以像素为单位。 在Java坐标系中,第一个是x坐标,表示当前位置为水平方向&#xff0c;距离坐标原点x个像素;第二个是y坐标&#xff0c;表示当前位置为垂直方向&#xff0c;距离坐标原点y个像素。 坐标体系-像素 …...

在web-view 加载的本地及远程HTML中调用uniapp的API及网页和vue页面是如何通讯的?

uni-app 中 Web-view 与 Vue 页面的通讯机制详解 一、Web-view 简介 Web-view 是 uni-app 提供的一个重要组件&#xff0c;用于在原生应用中加载 HTML 页面&#xff1a; 支持加载本地 HTML 文件支持加载远程 HTML 页面实现 Web 与原生的双向通讯可用于嵌入第三方网页或 H5 应…...

算法笔记2

1.字符串拼接最好用StringBuilder&#xff0c;不用String 2.创建List<>类型的数组并创建内存 List arr[] new ArrayList[26]; Arrays.setAll(arr, i -> new ArrayList<>()); 3.去掉首尾空格...

脑机新手指南(七):OpenBCI_GUI:从环境搭建到数据可视化(上)

一、OpenBCI_GUI 项目概述 &#xff08;一&#xff09;项目背景与目标 OpenBCI 是一个开源的脑电信号采集硬件平台&#xff0c;其配套的 OpenBCI_GUI 则是专为该硬件设计的图形化界面工具。对于研究人员、开发者和学生而言&#xff0c;首次接触 OpenBCI 设备时&#xff0c;往…...

HubSpot推出与ChatGPT的深度集成引发兴奋与担忧

上周三&#xff0c;HubSpot宣布已构建与ChatGPT的深度集成&#xff0c;这一消息在HubSpot用户和营销技术观察者中引发了极大的兴奋&#xff0c;但同时也存在一些关于数据安全的担忧。 许多网络声音声称&#xff0c;这对SaaS应用程序和人工智能而言是一场范式转变。 但向任何技…...

华为OD机试-最短木板长度-二分法(A卷,100分)

此题是一个最大化最小值的典型例题&#xff0c; 因为搜索范围是有界的&#xff0c;上界最大木板长度补充的全部木料长度&#xff0c;下界最小木板长度&#xff1b; 即left0,right10^6; 我们可以设置一个候选值x(mid)&#xff0c;将木板的长度全部都补充到x&#xff0c;如果成功…...