第10天-商品服务(分层领域模型及规格参数编码实现)

news/2024/3/29 13:38:50/文章来源:https://blog.csdn.net/zenggeweiss/article/details/129160088

1.分层领域模型规约

  • DO( Data Object): 此对象与数据库表结构一一对应,通过 DAO 层向上传输数据源对象。
  • DTO( Data Transfer Object):数据传输对象, Service 或 Manager 向外传输的对象。
  • BO( Business Object):业务对象, 可以由 Service 层输出的封装业务逻辑的对象。
  • Query:数据查询对象,各层接收上层的查询请求。 注意超过 2 个参数的查询封装,禁止使用 Map
    类来传输。
  • VO( View Object):显示层对象,通常是 Web 向模板渲染引擎层传输的对象。


2.规格参数-新增

前端Vue

2.1.抽取VO对象

  • AttrEntity 的属性抽取到 AttrVO 对象中,并新增四个属性
    private Long attrGroupId;
    private String catelogName;
    private String groupName;
    private Long[] catelogPath;
  • Controller层的Handler处理方法入参统一使用 VO 对象
package com.atguigu.gmall.product.vo;import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;import java.io.Serializable;/*** 规格参数(基本属性) VO 对象** @author zhangwen* @email 1466787185@qq.com* @date 2023-02-22 12:20:05*/
@Data
public class AttrVO {/*** 属性id*/private Long attrId;/*** 属性名*/private String attrName;/*** 是否需要检索[0-不需要,1-需要]*/private Integer searchType;/*** 值类型[0-为单个值,1-可以选择多个值]*/private Integer valueType;/*** 属性图标*/private String icon;/*** 可选值列表[用逗号分隔]*/private String valueSelect;/*** 属性类型[0-销售属性,1-基本属性,2-既是销售属性又是基本属性]*/private Integer attrType;/*** 启用状态[0 - 禁用,1 - 启用]*/private Long enable;/*** 所属分类*/private Long catelogId;/*** 快速展示【是否展示在介绍上;0-否 1-是】,在sku中仍然可以调整*/private Integer showDesc;/*** 属性分组Id*/private Long attrGroupId;/*** 所属分类名*/private String catelogName;/*** 所属分组名*/private String groupName;/*** 三级分类完整路径*/private Long[] catelogPath;
}


2.2.商品常量类

gmall-common 公共服务中创建商品常量类 ProductConstant

package com.atguigu.common.constant;/*** @Description:商品服务常量类* @Auther: zhangwen* @Date: 2023-02-22 10:51* @version: 1.0*/
public class ProductConstant {/*** 属性枚举*/public enum attrEnum{/*** 基本属性*/ATTR_TYPE_BASE(1,"基本属性"),/*** 销售属性*/ATTR_TYPE_SALE(0,"销售属性");private int code;private String msg;attrEnum(int code, String msg) {this.code = code;this.msg = msg;}public int getCode() {return code;}public void setCode(int code) {this.code = code;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}}
}    


2.3.API

POST /product/attr/save



2.4.后台接口实现

AttrController

 	/*** 保存规格参数*/@RequestMapping("/save")public R save(@RequestBody AttrVO attrVO){attrService.saveAttr(attrVO);return R.ok();}

AttrServiceImpl

	/*** 保存规则参数* @param attrVO*/@Transactional(rollbackFor = Exception.class)@Overridepublic void saveAttr(AttrVO attrVO) {//保存基本属性AttrEntity attrEntity = new AttrEntity();//属性拷贝BeanUtils.copyProperties(attrVO, attrEntity);this.save(attrEntity);//保存关联关系 - 基本属性(只有规格参数需要和属性分组建立关系,销售属性不建立关系)if (attrVO.getAttrType() == ProductConstant.attrEnum.ATTR_TYPE_BASE.getCode()) {AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();relationEntity.setAttrId(attrEntity.getAttrId());relationEntity.setAttrGroupId(attrVO.getAttrGroupId());relationDao.insert(relationEntity);}}


3.规格参数-列表查询



3.1.API

GET /product/attr/base/list/{catelogId}//请求参数
{page: 1, //当前页码limit: 10, //每页记录数sidx: 'id', //排序字段order: 'asc', //排序方式key: '华为' //检索关键字
}//响应数据
{"msg": "success","code": 0,"page": {"totalCount": 0,"pageSize": 10,"totalPage": 0,"currPage": 1,"list": [{"attrId": 0, //属性id"attrName": "string", //属性名"attrType": 0, //属性类型,0-销售属性,1-基本属性"catelogName": "手机/数码/手机", //所属分类名字"groupName": "主体", //所属分组名字"enable": 0, //是否启用"icon": "string", //图标"searchType": 0, //是否需要检索[0-不需要,1-需要]"showDesc": 0, //是否展示在介绍上;0-否 1-是"valueSelect": "string", //可选值列表[用逗号分隔]"valueType": 0 //值类型[0-为单个值,1-可以选择多个值]}]}
}


3.2.后台接口实现

AttrController

	/*** 查询规格参数和销售属性列表* @param params 分页信息和查询关键字key* @param catelogId 三级分类ID* @param attrType 属性类型* @return*/@GetMapping("/{attrType}/list/{catelogId}")public R listAttr(@RequestParam Map<String, Object> params,@PathVariable("catelogId") Long catelogId, @PathVariable("attrType") String attrType) {PageUtils page = attrService.queryBaseAttrPage(params, catelogId, attrType);return R.ok().put("page", page);}

AttrServiceImpl

	/*** 查询规格参数和销售属性列表* @param params 分页信息和查询关键字key* @param catelogId 三级分类ID* @param attrType 属性类型* @return*/@Overridepublic PageUtils queryBaseAttrPage(Map<String, Object> params, Long catelogId, String attrType) {QueryWrapper<AttrEntity> queryWrapper = new QueryWrapper<AttrEntity>().eq("attr_type","base".equalsIgnoreCase(attrType)? ProductConstant.attrEnum.ATTR_TYPE_BASE.getCode(): ProductConstant.attrEnum.ATTR_TYPE_SALE.getCode());if(catelogId != 0){queryWrapper.eq("catelog_id",catelogId);}String key = (String)params.get("key");if(!StringUtils.isEmpty(key)){queryWrapper.and(wrapper ->{wrapper.eq("attr_id",key).or().like("attr_name",key);});}IPage<AttrEntity> page = this.page(new Query<AttrEntity>().getPage(params), queryWrapper);PageUtils pageUtils = new PageUtils(page);//从分页对象中获取查询记录集List<AttrEntity> records = page.getRecords();List<AttrVO> attrVoList = records.stream().map(attrEntity -> {AttrVO attrVO = new AttrVO();BeanUtils.copyProperties(attrEntity, attrVO);//查询并设置分组名 groupName,基本属性需要显示分组,销售属性没有属性分组if ("base".equalsIgnoreCase(attrType)) {AttrAttrgroupRelationEntity relationEntity = relationDao.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrEntity.getAttrId()));if(relationEntity != null && relationEntity.getAttrGroupId() != null ){AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(relationEntity.getAttrGroupId());attrVO.setGroupName(attrGroupEntity.getAttrGroupName());}}//查询并设置分类名 catelogNameCategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());if(categoryEntity != null){attrVO.setCatelogName(categoryEntity.getName());}return attrVO;}).collect(Collectors.toList());pageUtils.setList(attrVoList);return  pageUtils;}

运行结果如下:

在这里插入图片描述



4.规格参数-修改



4.1.所属分类及分组数据回显

在这里插入图片描述

4.1.1API

GET /product/attr/info/{attrId}
//响应数据
{
"msg": "success",
"code": 0,
"attr": {"attrId": 1,"attrName": "入网型号","searchType": 1,"valueType": 1,"icon": "icon-1","valueSelect": "v;q;w","attrType": 1,"enable": 1,"showDesc": 1,"attrGroupId": 1, //分组id"catelogId": 225, //分类id"catelogPath": [2, 34, 225] //分类完整路径}
}

4.1.2后台接口实现

AttrController

	/*** 获取规格参数*/@RequestMapping("/info/{attrId}")public R info(@PathVariable("attrId") Long attrId){AttrVO attrVO = attrService.getAttrInfo(attrId);return R.ok().put("attr", attrVO);}

AttrServiceImpl

	/*** 获取规格参数* @param attrId 属性id* @return 规格参数VO对象*/@Overridepublic AttrVO getAttrInfo(Long attrId) {AttrVO attrVO = new AttrVO();AttrEntity attrEntity = this.getById(attrId);BeanUtils.copyProperties(attrEntity,attrVO);//查询并设置分组名 groupName,基本属性需要显示分组,销售属性没有属性分组if (attrVO.getAttrType() == ProductConstant.attrEnum.ATTR_TYPE_BASE.getCode()) {AttrAttrgroupRelationEntity relationEntity = relationDao.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrEntity.getAttrId()));if (relationEntity != null && relationEntity.getAttrGroupId() != null) {AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(relationEntity.getAttrGroupId());attrVO.setAttrGroupId(attrGroupEntity.getAttrGroupId());if (attrGroupEntity != null) {attrVO.setGroupName(attrGroupEntity.getAttrGroupName());}}}//查询并设置所属分类信息//一个微服务内部,service之间调用没有问题,考虑到开发便捷性和代码重用//对于是否违背设计原则,高内聚低耦合,本身微服务划分从根本上就已经做到了高内聚低耦合CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());if(categoryEntity != null){attrVO.setCatelogName(categoryEntity.getName());}Long[] categoryPath = categoryService.findCategoryPath(attrEntity.getCatelogId());attrVO.setCatelogPath(categoryPath);return attrVO;}

运行结果:

在这里插入图片描述



4.2.修改规格参数


4.2.1.API

POST /product/attr/update


4.2.2.后台接口实现

AttrController

	/*** 修改规格参数*/@RequestMapping("/update")public R update(@RequestBody AttrVO attrVO){attrService.updateAttr(attrVO);return R.ok();}

AttrServiceImpl

	/*** 修改规格参数* @param attrVO  规格参数VO对象*/@Overridepublic void updateAttr(AttrVO attrVO) {//修改基本信息AttrEntity attrEntity = new AttrEntity();BeanUtils.copyProperties(attrVO,attrEntity);this.updateById(attrEntity);//修改分组关联 - 基本属性if (attrVO.getAttrType() == ProductConstant.attrEnum.ATTR_TYPE_BASE.getCode()) {AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();relationEntity.setAttrGroupId(attrVO.getAttrGroupId());relationEntity.setAttrId(attrVO.getAttrId());Integer count = relationDao.selectCount(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrVO.getAttrId()));if (count > 0) {//修改关联关系relationDao.update(relationEntity,new UpdateWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrVO.getAttrId()));}else{//新增关联关系relationDao.insert(relationEntity);}}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_72863.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Python】PaddleHub图像分类

目录 一、环境配置&#xff1a; 二、问题需求 三、实验内容 1、准备数据集 2、拆分数据集 3、载入数据集 4、生成数据读取器 5、配置策略 6、组建Finetune Task 7、开始Finetune 8、预测 四、总结&#xff1a; 一、环境配置&#xff1a; 线上环境&#xff1a; 飞桨…

JAVA线程入门简介

线程入门简介什么是程序?什么是进程?什么是线程&#xff1f;单线程与多线程并发与并行线程的使用用java查看有多少个cpu创建线程的两种方式继承Thread类&#xff0c;重写run方法实现Runnable接口&#xff0c;重写run方法多线程机制为社么是start?源码解析什么是程序? 是为完…

字符串转换为二进制-课后程序(JAVA基础案例教程-黑马程序员编著-第五章-课后作业)

【案例5-4】 字符串转换为二进制 【案例介绍】 1.任务描述 本例要求编写一个程序&#xff0c;从键盘录入一个字符串&#xff0c;将字符串转换为二进制数。在转换时&#xff0c;将字符串中的每个字符单独转换为一个二进制数&#xff0c;将所有二进制数连接起来进行输出。 案…

win10下 WSL2安装及配置

目录 一. Windows中WSL2&#xff08;子系统&#xff09;安装前提条件 二. Windows中WSL2&#xff08;子系统&#xff09;安装步骤&#xff08;默认安装C盘&#xff09; 选择包安装模式(选择到其他盘安装) 三. Windows中WSL2&#xff08;子系统&#xff09;设置默认root用户登…

35-Golang中的方法

Golang中的方法方法的介绍和使用方法的声明和调用方法的调用和传参机制原理方法的声明(定义)方法注意事项和细节讨论方法和函数的区别方法的介绍和使用 在某些情况下&#xff0c;我们需要声明(定义)方法。比如person结构体&#xff0c;除了有一些字段外(年龄&#xff0c;姓名……

Apollo规划模块代码学习(1): 算法架构原理、运行机制一文详解

文章目录 1、Apllo算法框架原理2、Apollo规划模块概述3、规划模块代码框架1、重要数据结构2、运行机制1、Apllo算法框架原理 Apollo开源自动驾驶平台中,高清地图模块提供了每个在线模块都可以访问的高清地图。感知和定位模块提供了必要的动态环境信息,可以在预测模块中进一步…

优思学院:六西格玛管理的优势有哪些?

六西格玛的优势有哪些呢&#xff1f;以下我们来探讨一下。 一・降低企业整体成本 对企业而言&#xff0c;不良品要么被废弃&#xff0c;要么需要重新加工&#xff0c;或者需要在客户现场维修或更换&#xff0c;这些都会增加企业成本。根据美国的统计数据&#xff0c;执行3σ管…

Socket编程 | TCP服务器 之 并发阻塞模型(多进程实现)

TCP服务器IO模型 之 并发阻塞 1. 引言 在 Linux 环境下多进程的应用很多,其中最主要的就是网络/客户服务器。多进程服务器是当客户有请求时,服务器用一个子进程来处理客户请求。父进程继续等待其它客户的请求。这种方法的优点是当客户有请求时,服务器能及时处理客户,特别是…

docker 部署centos7.9并打包成docker

下载centos基础镜像 docker pull centos:centos7 运行镜像 docker run -itd --name centos-test -p 60001:22 --privileged centos:centos7 /usr/sbin/init 进入容器 docker exec -it ebec90068696 /bin/bash 配置容器信息 安装ssh服务和网络必须软件 yum install net-to…

MongoDB在Windows、Linux、Docker环境下的安装

MongoDB在Windows、Linux、Docker环境下的安装DockerDocker安装远程连接WindowsWindows安装服务相关命令压缩包形式安装Mac、Ubuntu、Centos一键安装MacUbuntucentos源码安装使用Atlas免费MongoDB云数据库申请云数据库连接测试Docker Docker安装 拉取镜像 docker pull mongo…

洛谷P5736 【深基7.例2】质数筛 C语言/C++

【深基7.例2】质数筛 题目描述 输入 nnn 个不大于 10510^5105 的正整数。要求全部储存在数组中&#xff0c;去除掉不是质数的数字&#xff0c;依次输出剩余的质数。 输入格式 第一行输入一个正整数 nnn&#xff0c;表示整数个数。 第二行输入 nnn 个正整数 aia_iai​&…

数据结构与算法(二)(Python版)

数据结构与算法&#xff08;一&#xff09;&#xff08;Python版&#xff09; 文章目录递归动规初识递归&#xff1a;数列求和递归三定律递归的应用&#xff1a;任意进制转换递归的应用&#xff1a;斐波那契数列递归调用的实现分治策略与递归优化问题和贪心策略找零兑换问题贪心…

系列四、多表查询

一、多表关系 项目开发中&#xff0c;在进行数据库表结构设计时&#xff0c;会根据业务需求及业务模块之间的关系&#xff0c;分析并设计表结 构&#xff0c;由于业务之间相互关联&#xff0c;所以各个表结构之间也存在着各种联系&#xff0c;基本上分为三种&#xff1a;一对多…

Sprng依赖注入(二):setter注入是如何工作的?

文章示例环境配置信息jdk版本:1.8开发工具&#xff1a;Intellij iDEA 2020.1springboot:2.3.9.RELEASE前言在Spring依赖注入&#xff08;一&#xff09;&#xff1a;字段注入的方式是如何工作的&#xff1f;中主要分享了Spring bean依赖注入方式中的字段注入方式及其工作过程&a…

基于Pytorch,从头开始实现Transformer(编码器部分)

Transformer理论部分参考知乎上的这篇文章 Transformer的Attention和Masked Attention部分参考知乎上的这篇文章 Transformer代码实现参考这篇文章&#xff0c;不过这篇文章多头注意力实现部分是错误的&#xff0c;需要注意。 完整代码放到github上了&#xff0c;链接 Trans…

联想小新 Air-14 2019IML电脑 Hackintosh 黑苹果efi引导文件

原文来源于黑果魏叔官网&#xff0c;转载需注明出处。硬件型号驱动情况主板Lenovo LNVNB161216处理器Intel Core i5-10210U / i7-10510U已驱动内存8GB DDR4 2666已驱动硬盘康佳KAK0500B128(128 GB/固志硬盘)已驱动显卡Intel UHD 620Nvidia GeForce MX250(屏蔽)无法驱动声卡Cone…

轮播图、阅读注册协议、网页时钟、随机点名、小米搜索框、轮播图点击切换——web APIs练习

目录 一、获取元素&#xff08;DOM&#xff09; 1. 随机轮播图案例 2. 阅读注册协议&#xff08;定时器间歇函数的应用&#xff09; 3. 轮播图定时器版 4. 网页时钟 二、事件基础&#xff08;DOM&#xff09; 1. 随机点名案例 2. 轮播图点击切换&#xff08;重点&#…

【计算机网络 -- 期末复习】

例题讲解 IP地址&#xff08;必考知识点&#xff09; 子网掩码 子网划分 第一栗&#xff1a; 子网划分题目的答案一般不唯一&#xff0c;我们主要采用下方的写法&#xff1a; 第二栗&#xff1a; 路由跳转 数据传输 CSMA/CD数据传输 2、比特率与波特率转换 四相位表示&am…

ElasticSearch 学习笔记总结(一)

文章目录一、 数据的 分类二、 ElasticSearch 介绍三、 ElasticSearch 搭建四、正排索引 和 倒排索引五、ES HTTP 索引 操作六、ES HTTP 文档 操作七、ES HTTP 查询数据1. 条件查询2. 分页查询3. 排序查询4. 多条件查询5. 全文检索 完全匹配 高亮显示6. 聚合查询八、 ES HTTP 映…

Scalable but Wasteful: Current State of Replication in the Cloud

文章目录ABSTRACT1 INTRODUCTION2 REPLICATION IN THE WILD3 CURRENT APPROACHES TO SCALING STATE MACHINE REPLICATION4 EFFICIENCY METRIC5 INEFFECTIVENESS OF CURRENT APPROACHES PER NEW METRIC6 CONCLUSION AND FUTURE DIRECTIONSABSTRACT 共识协议是部署在基于云的存储…