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 二、思考 可以通过指定别名,来指向一个或多个索引,…...
使用AI编码,这些安全风险你真的了解吗?
前言 随着AI技术的飞速发展与普及,企业开发人员对AI编码助手工具如Copilot的依赖度日益增强,使用AI编码助手工具虽然能显著提升编程效率与质量,但同时也存在一系列的潜在风险。 许多开发人员可能未意识到,如果他们的现有代码库中…...
计算机网络实验一:组建对等网络
实验一 组建对等网络 实验要求: 1. 组建对等网络,会在命令行使用ipconfig,两网络能够相互ping通,尝试netstat 命令 2. 建立局域网共享文件夹 3. 安装packet tracer,模拟组建对等网并测试对等网 1、组建对等网络 连…...
R语言绘制折线图
折线图是实用的数据可视化工具,通过连接数据点的线段展示数据随时间或变量的变化趋势。在经济、科学、销售及天气预报等领域广泛应用,为决策和分析提供依据。它能清晰呈现经济数据动态、助力科学研究、反映企业销售情况、预告天气变化,以简洁…...
基于组合模型的公交交通客流预测研究
摘 要 本研究致力于解决公交客流预测问题,旨在通过融合多种机器学习模型的强大能力,提升预测准确性,为城市公交系统的优化运营和交通管理提供科学依据。研究首先回顾了公交客流预测领域的相关文献,分析了传统统计方法在处理大规…...
docker环境redis启动失败
现象: 查看日志错误为 Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename> 经查询为aof文件损坏导致,修复aof即可 解决方法: 1.查看执行的docker命令&…...
Pandas库详细学习要点
Pandas库是一个基于Python的数据分析库,它提供了丰富的数据结构和数据分析工具,非常适合数据科学和数据分析领域的工作。以下是Pandas库详细学习的一些要点: 1. 数据结构 - Series:一维带标签数组,类似于NumPy中的一…...
光路科技TSN交换机:驱动自动驾驶技术革新,保障高精度实时数据传输
自动驾驶技术正快速演进,对实时数据处理能力的需求激增。光路科技推出的TSN(时间敏感网络)交换机,在比亚迪最新车型中的成功应用,显著推动了这一领域的技术进步。 自动驾驶技术面临的挑战 自动驾驶系统需整合来自雷达…...
【含开题报告+文档+PPT+源码】基于SpringBoot的社区家政服务预约系统设计与实现【包运行成功】
开题报告 社区家政服务是满足居民日常生活需求的重要组成部分,在现代社会中发挥着越来越重要的作用。随着城市化进程的不断加速,社区家政服务需求量呈现持续增长的趋势。然而,传统的家政服务模式存在一些问题,如预约流程繁琐、信…...
2024最新【Pycharm】史上最全PyCharm安装教程,图文教程(超详细)
1. PyCharm下载安装 完整安装包下载(包含Python和Pycharm专业版注册码):点击这里 1)访问官网 https://www.jetbrains.com/pycharm/download/#sectionwindows 下载「社区版 Community」 安装包。 2)下载完成后&#…...
llama3 implemented from scratch 笔记
github地址: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…...
照片在线转成二维码展示,更方便分享图片的好办法
怎么能把照片生成二维码后,分享给其他人展示呢?现在很多人为了能够更方便的将自己的图片展现给其他人会使用生成二维码的方式,将图片存储到云空间,通过扫码调取图片查看内容。与其他方式相比,这样会更加的方便…...
『网络游戏』登陆协议制定客户端发送账号密码CMD【19】
修改服务器脚本:ServerSession 修改服务器脚本:GameMsg 修改客户端脚本:ClientSession.cs 修改客户端脚本:NetSvc.cs 修改客户端脚本:WindowRoot.cs 修改客户端脚本:SystemRoot.cs 修改客户端脚本ÿ…...
独享动态IP是什么?它有什么独特优势吗?
在网络世界中,IP地址扮演着连接互联网的关键角色。随着互联网的发展,不同类型的IP地址也应运而生,其中独享动态ip作为一种新型IP地址,备受关注。本文将围绕它的定义及其独特优势展开探讨,以帮助读者更好地理解和利用这…...
gaussdb hccdp认证模拟题(单选)
1.在GaussDB逻辑架构中,由以下选项中的哪一个组件来负责提供集群日常运维、配置管理的管理接口、工具?(1 分) A. CN B. DN C. GTM D. OM --D 2.在以下命令中,使用以下哪一个选项中的命令可以以自定义归档形式导出表t1的定义…...
【斯坦福CS144】Lab1
一、实验目的 1.实现一个流重组器——一个将字节流的小块 (称为子串或段 )按正确顺序组装成连续的字节流的模块; 2.深入理解 TCP 协议的工作方式。 二、实验内容 编写一个名为"StreamReassembler"的数据结构,它负责…...
药箱里的药及其常见药的作用
药箱里有常备药,经常买药,但是忘了自己有什么药。容易之间弄混,以此作为更新存储的媒介。 1、阿莫西林胶囊 处方药 是指需要由医师或者医疗人员开局处方才能购买的药物(常见的OTC是非处方药的意思)。 截止时间 2024 10/10 药品资料汇总&am…...
Android屏幕旋转流程(2)
(1)疑问 (1)settings put system user_rotation 1是什么意思? 答:设置用户期望的屏幕转向,0代表:Surface.ROTATION_0竖屏;1代表:Surface.ROTATION_90横屏&a…...
gaussdb hccdp认证模拟题(判断)
1.在事务ACID特性中,原子性指的是事务必须始终保持系统处于一致的状态。(1 分) 错。 2.某IT公司在开发软件时,需要使用GaussDB数据库,因此需要实现软件和数据的链接,而DBeaver是一个通用的数据库管理工具和 SQL 客户端ÿ…...
(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)
题目:3442. 奇偶频次间的最大差值 I 思路 :哈希,时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况,哈希表这里用数组即可实现。 C版本: class Solution { public:int maxDifference(string s) {int a[26]…...
【人工智能】神经网络的优化器optimizer(二):Adagrad自适应学习率优化器
一.自适应梯度算法Adagrad概述 Adagrad(Adaptive Gradient Algorithm)是一种自适应学习率的优化算法,由Duchi等人在2011年提出。其核心思想是针对不同参数自动调整学习率,适合处理稀疏数据和不同参数梯度差异较大的场景。Adagrad通…...
IoT/HCIP实验-3/LiteOS操作系统内核实验(任务、内存、信号量、CMSIS..)
文章目录 概述HelloWorld 工程C/C配置编译器主配置Makefile脚本烧录器主配置运行结果程序调用栈 任务管理实验实验结果osal 系统适配层osal_task_create 其他实验实验源码内存管理实验互斥锁实验信号量实验 CMISIS接口实验还是得JlINKCMSIS 简介LiteOS->CMSIS任务间消息交互…...
以光量子为例,详解量子获取方式
光量子技术获取量子比特可在室温下进行。该方式有望通过与名为硅光子学(silicon photonics)的光波导(optical waveguide)芯片制造技术和光纤等光通信技术相结合来实现量子计算机。量子力学中,光既是波又是粒子。光子本…...
【Android】Android 开发 ADB 常用指令
查看当前连接的设备 adb devices 连接设备 adb connect 设备IP 断开已连接的设备 adb disconnect 设备IP 安装应用 adb install 安装包的路径 卸载应用 adb uninstall 应用包名 查看已安装的应用包名 adb shell pm list packages 查看已安装的第三方应用包名 adb shell pm list…...
C# 表达式和运算符(求值顺序)
求值顺序 表达式可以由许多嵌套的子表达式构成。子表达式的求值顺序可以使表达式的最终值发生 变化。 例如,已知表达式3*52,依照子表达式的求值顺序,有两种可能的结果,如图9-3所示。 如果乘法先执行,结果是17。如果5…...
Web后端基础(基础知识)
BS架构:Browser/Server,浏览器/服务器架构模式。客户端只需要浏览器,应用程序的逻辑和数据都存储在服务端。 优点:维护方便缺点:体验一般 CS架构:Client/Server,客户端/服务器架构模式。需要单独…...
python爬虫——气象数据爬取
一、导入库与全局配置 python 运行 import json import datetime import time import requests from sqlalchemy import create_engine import csv import pandas as pd作用: 引入数据解析、网络请求、时间处理、数据库操作等所需库。requests:发送 …...
Linux中《基础IO》详细介绍
目录 理解"文件"狭义理解广义理解文件操作的归类认知系统角度文件类别 回顾C文件接口打开文件写文件读文件稍作修改,实现简单cat命令 输出信息到显示器,你有哪些方法stdin & stdout & stderr打开文件的方式 系统⽂件I/O⼀种传递标志位…...
第一篇:Liunx环境下搭建PaddlePaddle 3.0基础环境(Liunx Centos8.5安装Python3.10+pip3.10)
第一篇:Liunx环境下搭建PaddlePaddle 3.0基础环境(Liunx Centos8.5安装Python3.10pip3.10) 一:前言二:安装编译依赖二:安装Python3.10三:安装PIP3.10四:安装Paddlepaddle基础框架4.1…...
