通用型产品发布解决方案(基于分布式微服务技能栈:SpringBoot+SpringCloud+Spring CloudAlibaba+Vue+ElementUI+MyBatis-Plus+MySQL+Git+Maven+Linux+Docker+Nginx - 《03》
@
目录
Mybatis-plus 分页插件
增补:renren 的分页插件
- /**
- * 列表
- * 说明:
- * 1. 根据业务需求,增加根据分类(第3级分类) + 查询条件+ 分页的API接口/方法
- */
- @RequestMapping("/list/{categoryId}")
- //@RequiresPermissions("commodity:attrgroup:list")
- public R list(@RequestParam Map<String, Object> params, @PathVariable("categoryId") Long categoryId){
- PageUtils page = attrgroupService.queryPage(params,categoryId);
- return R.ok().put("page", page);
- }
复制代码 - /**
- * 增加根据家居分类(第三级的)+查询条件+分页 API接口
- * 可以通过 debug来查看后台的 SQL语句,一目了然
- *
- * @param params
- * @param categoryId
- * @return
- */
- @Override
- public PageUtils queryPage(Map<String, Object> params, Long categoryId) {
- // 获取用户进行查询时的关键字
- String key = (String) params.get("key");
- // QueryWrapper是 renren相关提供的,是用于封装查询条件 /参数
- QueryWrapper<AttrgroupEntity> wrapper =
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper<AttrgroupEntity>();
- //如果是带条件查询,将条件分组到 wrapper,
- //这里的 id和 name是指的 commodity_attrgroup表的字段
- // 判断 key 是否携带的有查询条件
- //if (!StringUtils.isEmpty(key)) {
- // wrapper.and((obj) -> {
- // obj.eq("id", key).or().like("name", key);
- // });
- //}
- // 判断 key 是否携带的有查询添加-希望他是一组独立检索条件。
- if (!StringUtils.isEmpty(key)) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper.and((obj) -> {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> obj.eq("id", key).or().like("name", key);
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });
- }
- // IPage是 renren提供的工具类,用于分页查询
- //categoryId为 0表示,查询分类属性组时,不加入 categoryId
- //(是我设置的业务逻辑,目前调用,传的 categoryId都不为 0)
- // 否则就加入 And categoryId = xxx
- if (categoryId != 0) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper.eq("category_id", categoryId);
- }
- IPage<AttrgroupEntity> page = this.page(
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query<AttrgroupEntity>().getPage(params),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper
- );
- return new PageUtils(page);
- }
复制代码- package com.rainbowsea.rainbowsealiving.commodity.service.impl;import com.alibaba.cloud.context.utils.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.rainbowsea.common.utils.PageUtils;import com.rainbowsea.common.utils.Query;import com.rainbowsea.rainbowsealiving.commodity.dao.AttrgroupDao;import com.rainbowsea.rainbowsealiving.commodity.entity.AttrgroupEntity;import com.rainbowsea.rainbowsealiving.commodity.service.AttrgroupService;@Service("attrgroupService")public class AttrgroupServiceImpl extends ServiceImpl implements AttrgroupService { @Override public PageUtils queryPage(Map params) { IPage page = this.page(<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query().getPage(params),<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper() ); return new PageUtils(page); } /**
- * 增加根据家居分类(第三级的)+查询条件+分页 API接口
- * 可以通过 debug来查看后台的 SQL语句,一目了然
- *
- * @param params
- * @param categoryId
- * @return
- */
- @Override
- public PageUtils queryPage(Map<String, Object> params, Long categoryId) {
- // 获取用户进行查询时的关键字
- String key = (String) params.get("key");
- // QueryWrapper是 renren相关提供的,是用于封装查询条件 /参数
- QueryWrapper<AttrgroupEntity> wrapper =
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper<AttrgroupEntity>();
- //如果是带条件查询,将条件分组到 wrapper,
- //这里的 id和 name是指的 commodity_attrgroup表的字段
- // 判断 key 是否携带的有查询条件
- //if (!StringUtils.isEmpty(key)) {
- // wrapper.and((obj) -> {
- // obj.eq("id", key).or().like("name", key);
- // });
- //}
- // 判断 key 是否携带的有查询添加-希望他是一组独立检索条件。
- if (!StringUtils.isEmpty(key)) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper.and((obj) -> {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> obj.eq("id", key).or().like("name", key);
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });
- }
- // IPage是 renren提供的工具类,用于分页查询
- //categoryId为 0表示,查询分类属性组时,不加入 categoryId
- //(是我设置的业务逻辑,目前调用,传的 categoryId都不为 0)
- // 否则就加入 And categoryId = xxx
- if (categoryId != 0) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper.eq("category_id", categoryId);
- }
- IPage<AttrgroupEntity> page = this.page(
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query<AttrgroupEntity>().getPage(params),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper
- );
- return new PageUtils(page);
- }}
复制代码 打括号的查询提供,分组,括号查询- if (!StringUtils.isEmpty(key)) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper.and((obj) -> {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> obj.eq("id", key).or().like("name", key);
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });
- }
复制代码
 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;import com.alibaba.cloud.context.utils.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.rainbowsea.common.utils.PageUtils;import com.rainbowsea.common.utils.Query;import com.rainbowsea.rainbowsealiving.commodity.dao.AttrgroupDao;import com.rainbowsea.rainbowsealiving.commodity.entity.AttrgroupEntity;import com.rainbowsea.rainbowsealiving.commodity.service.AttrgroupService;@Service("attrgroupService")public class AttrgroupServiceImpl extends ServiceImpl implements AttrgroupService { @Override public PageUtils queryPage(Map params) { IPage page = this.page(<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query().getPage(params),<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper() ); return new PageUtils(page); } /** * 增加根据家居分类(第三级的)+查询条件+分页 API接口 * 可以通过 debug来查看后台的 SQL语句,一目了然 * * @param params * @param categoryId * @return */ @Override public PageUtils queryPage(Map params, Long categoryId) { // 获取用户进行查询时的关键字 String key = (String) params.get("key"); // QueryWrapper是 renren相关提供的,是用于封装查询条件 /参数 QueryWrapper wrapper =<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper(); //如果是带条件查询,将条件分组到 wrapper, //这里的 id和 name是指的 commodity_attrgroup表的字段 // 判断 key 是否携带的有查询条件 //if (!StringUtils.isEmpty(key)) { // wrapper.and((obj) -> { // obj.eq("id", key).or().like("name", key); // }); //} if (!StringUtils.isEmpty(key)) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper.and((obj) -> {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> obj.eq("id", key).or().like("name", key);
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });
- } // IPage是 renren提供的工具类,用于分页查询 //categoryId为 0表示,查询分类属性组时,不参加 categoryId //(是我设置的业务逻辑,目前调用,传的 categoryId都不为 0) // 否则就参加 And categoryId = xxx if (categoryId != 0) {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper.eq("category_id", categoryId); } IPage page = this.page(<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query().getPage(params),<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> wrapper ); return new PageUtils(page); }}
复制代码 设置类(引入分页插件)
在对应项目,或者微服务当中的 config 设置目录下创建,MyB
atisConfig.java,MyBatis-plus 的分页插件的设置类
 - package com.rainbowsea.rainbowsealiving.commodity.config;
- import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
- import org.mybatis.spring.annotation.MapperScan;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.transaction.annotation.EnableTransactionManagement;
- @Configuration // 标识是一个配置类
- @EnableTransactionManagement //开启事务
- @MapperScan("com.rainbowsea.rainbowsealiving.commodity.dao") // 扫描的 dao 目录包位置
- public class MyBatisConfig {
- // 引入分页插件
- @Bean
- public PaginationInterceptor paginationInterceptor() {
- PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
- // 设置请求的页面大于最大页后操作,
- // true 调回到首页,false 继续请求 默认 false
- paginationInterceptor.setOverflow(true);
- //设置最大单页限制数量,默认 500条,-1不受限制
- paginationInterceptor.setLimit(100);
- return paginationInterceptor;
- }
- }
复制代码 层级定位
可以省略
前端搜索检索功能
可以省略
关联表-而不是使用外键
写
BeanUtils 的使用
- BeanUtils.copyProperties(test1,test2); // 将 test1对象属性拷贝大宋 test2 当中
复制代码 SPU 和 SKU 的概念和实现
SPU 的概述
- SPU((Stock keeping Unit):标准化产品单元
- 用简单的话来说就是一类商品,比如:手机里的一种牌子,如:小米,苹果,都是一类。然后,参加具体的类型,如:小米 15,苹果 16 等等。那么它就是一个 spu
SKU 的概述:
- SKU(Stock keeping Unit):库存保有单位。
- SKU 简单的来说就是在 spu 原有的基础上参加具体的类型,如(小米 15,白色,8+252G) 。组合起来就是一个完整地 SKU,所以 SKU 就是一类商品的各种样式的组合。
- SKU 的组合会影响该商品的代价。
SPU 和 SKU 的关系:
- SPU 和 SKU 就是上下级关系,没有 SPU 就没有 SKU,因为假如没有这一类商品,就没法谈这件商品具体的颜色尺寸。
- 如下图:假如没有选择任何类型那么他就是一个单独的 SPU,但是当它选择了具体的颜色,版本,购买方式等等,那么他就是一个 SKU。
- 保存商品 spu 信息
- 1 个 spu 信息可能对于多个 sku
- 1 个 spu + 1 个 sku 就是一个商品的组合关系()
JSON 转换为 Java 实体类
写,特别的
P550
P564
- 当目前的实体类/对象,格式不能满足我们的需求时,可以使用上 VO**View Object**** 对象。VO 可以根据需求组合已有**的实体类的字段,或者增加,或者删除一些字段。
- 如果返回的 JSON 数据的当前实体类,不能满足需求,则定义一个 VO(View Object) 对象,在该对象,可以根据需求组合实体类字段,或者增加,或者删除一些字段。
- submitSkus() {
- console.log("要提交保存的商品信息(spu=) " , JSON.stringify(this.spu)); //将 json 对象转
- 成字符串输出
- this.$confirm("将要提交商品数据, 是否继续?", "提示", {
- confirmButtonText: "确定", cancelButtonText: "取消",
- type: "warning"
- })//其它
复制代码 - <el-button type="success" @click="submitSkus">下一步:保存商品信息</el-button>
- submitSkus() {
- console.log("要提交保存的商品信息(spu=) " , JSON.stringify(this.spu))
- this.$confirm("将要提交商品数据,需要一小段时间,是否继续?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- })
- .then(() => {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>this.$http({
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> //url: "http://localhost:9090/commodity/spuinfo/save",
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> url: this.$http.adornUrl("/commodity/spuinfo/save"),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> method: "post",
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> data: this.$http.adornData(this.spu, false)
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>}).then(({data}) => {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> if (data.code == 0) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> this.$message({
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> type: "success",
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> message: "新增商品成功!"
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> this.step = 4;
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> } else {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> this.$message({
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> type: "error",
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> message: "保存失败,原因【" + data.msg + "】"
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>});
- })
- .catch(e => {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>console.log(e);
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>this.$message({
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> type: "info",
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> message: "已取消"
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>});
- });
- },
复制代码 分析一个 JSON 格式内容,将 console 输出的 json 字符串,格式化一下好看: https://www.json.cn/
为了可以或许在服务端接收提交的数据,我们使用 json 在线工具,转成 entity 对象(实际是一组),作为 VO实体类。
- 点击 JSON 天生 Java 实体
- 把 console 输出的 JSON 字符串拷贝到左侧。
把天生好的 VO 实体类(我已经改好了, 可以直接使用(在资料文件夹))
留意:编写对应的 Cotroller 当中的编码信息。
分 析 一 下 json 格 式 内 容 , 将 console 输 出 的 json 字 符 串 , 格 式 化 一 下 好 看 https://www.json.cn/
- 为了可以或许在服务端接收提交的数据,我们使用 json 在线工具,转成 entity 对象(实际是 一组), 作为 VO 实体类
- 点击 JSON 天生 JAVA 实体
对天生好的 VO 实体类进行简化和定制,比如 int 改成 Long , double 改成 BigDecimal
如许更符合我们的要求, 我已经改好了, 可以直接使用(在资料文件夹),并增加了两个 VO
类 , Images.java 和 MemberPrice.java, 直接替换一下即可
- 增加 Images.java 和 MemberPrice.java
- 修改 int —> long,double ——>BigDecimal
- 使用 @Data 注解 简化 entity 类
梳理 VO 实体类和提交的 Json 数据关系
- 保存商品 spu 信息
- 1 个 spu 信息可能对于多个 sku
- 1 个 spu + 1 个 sku 就是一个商品的组合关系()
保存商品信息,涉及到的表非常多,不是一个 SpulnfoEntityh 实体类能包括的,将 SpulnfoEntity 改成我们前面天生的 SpuSaveVo 包罗了 JSON 提交全部信息。
我们这里是通过一个定制的方法 saveSpulnfo 来完成。
保存 SKU 的图片信息表的设置
- package com.rainbowsea.rainbowsealiving.commodity.entity;
- import com.baomidou.mybatisplus.annotation.IdType;
- import com.baomidou.mybatisplus.annotation.TableId;
- import com.baomidou.mybatisplus.annotation.TableName;
- import java.io.Serializable;
- import java.util.Date;
- import lombok.Data;
- /**
- * 商品 spu 信息介绍
- *
- * @author rainbowsea
- * @email rainbowsea@gmail.com
- * @date 2025-03-24 20:46:13
- */
- @Data
- @TableName("commodity_spu_info_desc")
- public class SpuInfoDescEntity implements Serializable {
- private static final long serialVersionUID = 1L;
- /**
- * 商品 id
- * 因为 commodity_spu_info_desc 表的 id 不是自增长的,而是我们指定的
- * 因此,我们这里给 spuId 标识上 @TableId(type = IdType.INPUT)
- * , 否则底层的 sql 语句时不会生成添加 supId 的 sql 语句(可以通过日志输出看看)
- */
- @TableId(type = IdType.INPUT)
- private Long spuId;
- /**
- * 商品介绍图片
- */
- private String decript;
- }
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service;
- import com.baomidou.mybatisplus.extension.service.IService;
- import com.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoEntity;
- import com.rainbowsea.rainbowsealiving.commodity.vo.SpuSaveVO;
- import java.util.Map;
- /**
- * 商品 spu 信息
- *
- * @author rainbowsea
- * @email rainbowsea@gmail.com
- * @date 2025-03-24 20:31:43
- */
- public interface SpuInfoService extends IService<SpuInfoEntity> {
- PageUtils queryPage(Map<String, Object> params);
- void saveSpuInfo(SpuSaveVO spuSaveVO);
- void saveBaseSpuInfo(SpuInfoEntity spuInfoEntity);
- }
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;
- 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.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.common.utils.Query;
- import com.rainbowsea.rainbowsealiving.commodity.dao.SpuInfoDescDao;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoDescEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoDescService;
- @Service("spuInfoDescService")
- public class SpuInfoDescServiceImpl extends ServiceImpl<SpuInfoDescDao, SpuInfoDescEntity> implements SpuInfoDescService {
- @Override
- public void saveSpuInfoDesc(SpuInfoDescEntity spuInfoDescEntity) {
- this.baseMapper.insert(spuInfoDescEntity);
- }
- @Override
- public PageUtils queryPage(Map<String, Object> params) {
- IPage<SpuInfoDescEntity> page = this.page(
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query<SpuInfoDescEntity>().getPage(params),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper<SpuInfoDescEntity>()
- );
- return new PageUtils(page);
- }
- }
复制代码
 - package com.rainbowsea.rainbowsealiving.commodity.controller;
- import java.util.Arrays;
- import java.util.Map;
- //import org.apache.shiro.authz.annotation.RequiresPermissions;
- 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.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoDescEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoDescService;
- import com.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.common.utils.R;
- /**
- * 商品 spu 信息介绍
- *
- * @author rainbowsea
- * @email rainbowsea@gmail.com
- * @date 2025-03-24 20:46:13
- */
- @RestController
- @RequestMapping("commodity/spuinfodesc")
- public class SpuInfoDescController {
- @Autowired
- private SpuInfoDescService spuInfoDescService;
- /**
- * 列表
- */
- @RequestMapping("/list")
- //@RequiresPermissions("commodity:spuinfodesc:list")
- public R list(@RequestParam Map<String, Object> params){
- PageUtils page = spuInfoDescService.queryPage(params);
- return R.ok().put("page", page);
- }
- /**
- * 信息
- */
- @RequestMapping("/info/{spuId}")
- //@RequiresPermissions("commodity:spuinfodesc:info")
- public R info(@PathVariable("spuId") Long spuId){
- SpuInfoDescEntity spuInfoDesc = spuInfoDescService.getById(spuId);
- return R.ok().put("spuInfoDesc", spuInfoDesc);
- }
- /**
- * 保存
- */
- @RequestMapping("/save")
- //@RequiresPermissions("commodity:spuinfodesc:save")
- public R save(@RequestBody SpuInfoDescEntity spuInfoDesc){
- spuInfoDescService.save(spuInfoDesc);
- return R.ok();
- }
- /**
- * 修改
- */
- @RequestMapping("/update")
- //@RequiresPermissions("commodity:spuinfodesc:update")
- public R update(@RequestBody SpuInfoDescEntity spuInfoDesc){
- spuInfoDescService.updateById(spuInfoDesc);
- return R.ok();
- }
- /**
- * 删除
- */
- @RequestMapping("/delete")
- //@RequiresPermissions("commodity:spuinfodesc:delete")
- public R delete(@RequestBody Long[] spuIds){
- spuInfoDescService.removeByIds(Arrays.asList(spuIds));
- return R.ok();
- }
- }
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoDescEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoDescService;
- import com.rainbowsea.rainbowsealiving.commodity.vo.SpuSaveVO;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- import java.util.List;
- 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.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.common.utils.Query;
- import com.rainbowsea.rainbowsealiving.commodity.dao.SpuInfoDao;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoService;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- @Service("spuInfoService")
- public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
- @Resource
- SpuInfoDescService spuInfoDescService;
- //因为有多个添加操作,使用事务控制
- @Transactional
- @Override
- public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- //1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);
- spuInfoEntity.setCreateTime(new Date());
- spuInfoEntity.setUpdateTime(new Date());
- //SpuInfoEntity 信息保存到 commodity_spu_info
- this.saveBaseSpuInfo(spuInfoEntity);
- //2、保存 Spu 的描述图片路径 commodity_spu_info_desc
- List<String> decript = spuSaveVO.getDecript();
- SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
- //获取到刚刚保存的 spu 基本信息对应的 id
- spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
- //注意:这里有可能没有图片, 可以设置一个默认图片
- if(decript.size() == 0) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");
- }else {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));
- }
- //保存到 commodity_spu_info_desc, 这个方法时我们完成
- spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);
- }
- @Override
- public PageUtils queryPage(Map<String, Object> params) {
- IPage<SpuInfoEntity> page = this.page(
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query<SpuInfoEntity>().getPage(params),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper<SpuInfoEntity>()
- );
- return new PageUtils(page);
- }
- /**
- * 保存 spu 的基本信息到 commodity_spu_info
- * @param spuInfoEntity
- */
- @Override
- public void saveBaseSpuInfo(SpuInfoEntity spuInfoEntity) {
- this.baseMapper.insert(spuInfoEntity);
- }
- // @Override
- // public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- ////1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- // SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- // BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);
- // spuInfoEntity.setCreateTime(new Date());
- // spuInfoEntity.setUpdateTime(new Date());
- ////2. 将 SpuInfoEntity 信息保存到 commodity_spu_info
- // this.saveBaseSpuInfo(spuInfoEntity);
- // }
- }
复制代码 完成功能说明: 提示: 这里我们先临时不选择图片, 紧张测试 保存默认图片信息
是否能记录到 commodity_spu_images 表(后面操作批量保存图片到阿里云)
保存到阿里云操作:具体代码实现:- /*======================================================*/
- /* 1. 保存商品 spu 的介绍图片集, 就是商品最前面的按一组图片来展示图片的集合 , 点
- 击可以切换图片
- /*======================================================*/
- USE hspliving_commodity
- CREATE TABLE commodity_spu_images
- (
- id BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id', spu_id BIGINT COMMENT 'spu_id',
- img_name VARCHAR(200) COMMENT '图片名',
- img_url VARCHAR(255) COMMENT '图片地址',
- img_sort INT COMMENT '顺序', default_img TINYINT COMMENT '是否默认图', PRIMARY KEY (id)
- )CHARSET=utf8mb4 COMMENT='spu 图片集';
- SELECT * FROM commodity_spu_images
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoDescEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuImagesService;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoDescService;
- import com.rainbowsea.rainbowsealiving.commodity.vo.SpuSaveVO;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- import java.util.List;
- 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.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.common.utils.Query;
- import com.rainbowsea.rainbowsealiving.commodity.dao.SpuInfoDao;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoService;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- @Service("spuInfoService")
- public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
- @Resource
- SpuImagesService imagesService;
- @Resource
- SpuInfoDescService spuInfoDescService;
- //因为有多个添加操作,使用事务控制
- @Transactional
- @Override
- public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- //1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);
- spuInfoEntity.setCreateTime(new Date());
- spuInfoEntity.setUpdateTime(new Date());
- //SpuInfoEntity 信息保存到 commodity_spu_info
- this.saveBaseSpuInfo(spuInfoEntity);
- //2、保存 Spu 的描述图片路径 commodity_spu_info_desc
- List<String> decript = spuSaveVO.getDecript();
- SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
- //获取到刚刚保存的 spu 基本信息对应的 id
- spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
- //注意:这里有可能没有图片, 可以设置一个默认图片
- if(decript.size() == 0) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");
- }else {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));
- }
- //保存到 commodity_spu_info_desc, 这个方法时我们完成
- spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);
- //3、保存 spu 的图片集 commodity_spu_images
- List<String> images = spuSaveVO.getImages();
- //获取到刚刚保存的 spu 基本信息对应的 id
- imagesService.saveImages(spuInfoEntity.getId(), images);
- }
- @Override
- public PageUtils queryPage(Map<String, Object> params) {
- IPage<SpuInfoEntity> page = this.page(
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query<SpuInfoEntity>().getPage(params),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper<SpuInfoEntity>()
- );
- return new PageUtils(page);
- }
- /**
- * 保存 spu 的基本信息到 commodity_spu_info
- * @param spuInfoEntity
- */
- @Override
- public void saveBaseSpuInfo(SpuInfoEntity spuInfoEntity) {
- this.baseMapper.insert(spuInfoEntity);
- }
- }
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service;
- import com.baomidou.mybatisplus.extension.service.IService;
- import com.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuImagesEntity;
- import java.util.List;
- import java.util.Map;
- /**
- * spu 图片集
- *
- * @author rainbowsea
- * @email rainbowsea@gmail.com
- * @date 2025-03-24 21:02:53
- */
- public interface SpuImagesService extends IService<SpuImagesEntity> {
- PageUtils queryPage(Map<String, Object> params);
- void saveImages(Long id, List<String> images);
- }
复制代码 保存 spu 的基本属性/规格参数
创建保存 spu 的基本属性/规格参数的表- /*====================================================*/
- /* 1. 保存商品 spu 基本属性值, 有多个
- /*====================================================*/
- USE hspliving_commodity
- CREATE TABLE commodity_product_attr_value
- (
- id BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id',
- spu_id BIGINT COMMENT '商品 id',
- attr_id BIGINT COMMENT '属性 id',
- attr_name VARCHAR(200) COMMENT '属性名',
- attr_value VARCHAR(200) COMMENT '属性值',
- attr_sort INT COMMENT '顺序',
- quick_show TINYINT COMMENT '快速展示【是否展示在介绍上;0-否 1-是】',
- PRIMARY KEY (id)
- )CHARSET=utf8mb4 COMMENT='spu 基本属性值';
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service;
- import com.baomidou.mybatisplus.extension.service.IService;
- import com.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.rainbowsealiving.commodity.entity.ProductAttrValueEntity;
- import java.util.List;
- import java.util.Map;
- /**
- * spu 基本属性值
- *
- * @author rainbowsea
- * @email rainbowsea@gmail.com
- * @date 2025-03-24 21:40:59
- */
- public interface ProductAttrValueService extends IService<ProductAttrValueEntity> {
- PageUtils queryPage(Map<String, Object> params);
- void saveProductAttr(List<ProductAttrValueEntity> collect);
- }
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.entity;
- import com.baomidou.mybatisplus.annotation.TableId;
- import com.baomidou.mybatisplus.annotation.TableName;
- import java.io.Serializable;
- import java.util.Date;
- import lombok.Data;
- /**
- * spu 基本属性值
- *
- * @author rainbowsea
- * @email rainbowsea@gmail.com
- * @date 2025-03-24 21:40:59
- */
- @Data
- @TableName("commodity_product_attr_value")
- public class ProductAttrValueEntity implements Serializable {
- private static final long serialVersionUID = 1L;
- /**
- * id
- */
- @TableId
- private Long id;
- /**
- * 商品 id
- */
- private Long spuId;
- /**
- * 属性 id
- */
- private Long attrId;
- /**
- * 属性名
- */
- private String attrName;
- /**
- * 属性值
- */
- private String attrValue;
- /**
- * 顺序
- */
- private Integer attrSort;
- /**
- * 快速展示【是否展示在介绍上;0-否 1-是】
- */
- private Integer quickShow;
- }
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;
- import org.springframework.stereotype.Service;
- import java.util.List;
- 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.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.common.utils.Query;
- import com.rainbowsea.rainbowsealiving.commodity.dao.ProductAttrValueDao;
- import com.rainbowsea.rainbowsealiving.commodity.entity.ProductAttrValueEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.ProductAttrValueService;
- @Service("productAttrValueService")
- public class ProductAttrValueServiceImpl extends ServiceImpl<ProductAttrValueDao, ProductAttrValueEntity> implements ProductAttrValueService {
- @Override
- public void saveProductAttr(List<ProductAttrValueEntity> collect) {
- this.saveBatch(collect);
- }
- @Override
- public PageUtils queryPage(Map<String, Object> params) {
- IPage<ProductAttrValueEntity> page = this.page(
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query<ProductAttrValueEntity>().getPage(params),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper<ProductAttrValueEntity>()
- );
- return new PageUtils(page);
- }
- }
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;
- import com.rainbowsea.rainbowsealiving.commodity.entity.AttrEntity;
- import com.rainbowsea.rainbowsealiving.commodity.entity.ProductAttrValueEntity;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoDescEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.AttrService;
- import com.rainbowsea.rainbowsealiving.commodity.service.ProductAttrValueService;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuImagesService;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoDescService;
- import com.rainbowsea.rainbowsealiving.commodity.vo.BaseAttrs;
- import com.rainbowsea.rainbowsealiving.commodity.vo.SpuSaveVO;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- 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.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.common.utils.Query;
- import com.rainbowsea.rainbowsealiving.commodity.dao.SpuInfoDao;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoService;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- @Service("spuInfoService")
- public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
- @Resource
- AttrService attrService;
- @Resource
- ProductAttrValueService productAttrValueService;
- @Transactional
- @Override
- public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- //1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- BeanUtils.copyProperties(spuSaveVO, spuInfoEntity);
- spuInfoEntity.setCreateTime(new Date());
- spuInfoEntity.setUpdateTime(new Date());
- //SpuInfoEntity 信息保存到 commodity_spu_info
- this.saveBaseSpuInfo(spuInfoEntity);
- //2、保存 Spu 的描述图片路径 commodity_spu_info_desc
- List<String> decript = spuSaveVO.getDecript();
- SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
- //获取到刚刚保存的 spu 基本信息对应的 id
- spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
- //注意:这里有可能没有图片, 可以设置一个默认图片
- if (decript.size() == 0) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");
- } else {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));
- }
- //保存到 commodity_spu_info_desc, 这个方法时我们完成
- spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);
- //3、保存 spu 的图片集 commodity_spu_images
- List<String> images = spuSaveVO.getImages();
- //获取到刚刚保存的 spu 基本信息对应的 id
- imagesService.saveImages(spuInfoEntity.getId(), images);
- //4、保存 spu 的基本属性(一个 spu 可以有多个基本属性/规格参数):
- // commodity_product_attr_value
- List<BaseAttrs> baseAttrs = spuSaveVO.getBaseAttrs();
- List<ProductAttrValueEntity> collect = baseAttrs.stream().map(attr -> {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity;
- }).collect(Collectors.toList());
- productAttrValueService.saveProductAttr(collect);
- }
- @Resource
- SpuImagesService imagesService;
- @Resource
- SpuInfoDescService spuInfoDescService;
- //因为有多个添加操作,使用事务控制
- // @Transactional
- // @Override
- // public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- ////1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- // SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- // BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);
- // spuInfoEntity.setCreateTime(new Date());
- // spuInfoEntity.setUpdateTime(new Date());
- ////SpuInfoEntity 信息保存到 commodity_spu_info
- // this.saveBaseSpuInfo(spuInfoEntity);
- ////2、保存 Spu 的描述图片路径 commodity_spu_info_desc
- // List<String> decript = spuSaveVO.getDecript();
- // SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
- ////获取到刚刚保存的 spu 基本信息对应的 id
- // spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
- ////注意:这里有可能没有图片, 可以设置一个默认图片
- // if(decript.size() == 0) {
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");
- // }else {
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));
- // }
- ////保存到 commodity_spu_info_desc, 这个方法时我们完成
- // spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);
- //
- // //3、保存 spu 的图片集 commodity_spu_images
- // List<String> images = spuSaveVO.getImages();
- ////获取到刚刚保存的 spu 基本信息对应的 id
- // imagesService.saveImages(spuInfoEntity.getId(), images);
- // }
- @Override
- public PageUtils queryPage(Map<String, Object> params) {
- IPage<SpuInfoEntity> page = this.page(
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query<SpuInfoEntity>().getPage(params),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper<SpuInfoEntity>()
- );
- return new PageUtils(page);
- }
- /**
- * 保存 spu 的基本信息到 commodity_spu_info
- * @param spuInfoEntity
- */
- @Override
- public void saveBaseSpuInfo(SpuInfoEntity spuInfoEntity) {
- this.baseMapper.insert(spuInfoEntity);
- }
- // @Override
- // public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- ////1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- // SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- // BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);
- // spuInfoEntity.setCreateTime(new Date());
- // spuInfoEntity.setUpdateTime(new Date());
- ////2. 将 SpuInfoEntity 信息保存到 commodity_spu_info
- // this.saveBaseSpuInfo(spuInfoEntity);
- // }
- }
复制代码 保存 SKU 的基本信息
完成保存商品信息功能-有难度-比较综合-涉及解决方案
解决方案分析:
- 因为在保存商品信息时,涉及到的信息很多。
- 可以通过拆解,创建多个 VO 层的 JavaBean,将商品信息保存到对应的各个表中。
- 梳理下(紧张!开发中,前端和后端是配合的,有时我们后端职员必要根据前端的业务需求来设计程序)
整理上面的图:
分析前端发送的 JSON(很复杂)—> 创建 VO 对象/类(多个,可能还有组合/包罗关系)——> 创建对应的数据表,保存数据(入库)。
- 可以理解成是一种通用的设计和解决方案。
- 这个功能的业务相对比较繁琐,这个必要耐心。
先分析要提交的 json 数据
创建数据表-根据自己的业务设计[考虑前端的要求] - USE hspliving_commodity
- CREATE TABLE commodity_sku_info
- (
- sku_id BIGINT NOT NULL AUTO_INCREMENT COMMENT 'skuId',
- spu_id BIGINT COMMENT 'spuId',
- sku_name VARCHAR(255) COMMENT 'sku 名称',
- sku_desc VARCHAR(2000) COMMENT 'sku 介绍描述',
- catalog_id BIGINT COMMENT '所属分类 id',
- brand_id BIGINT COMMENT '品牌 id',
- sku_default_img VARCHAR(255) COMMENT '默认图片',
- sku_title VARCHAR(255) COMMENT '标题',
- sku_subtitle VARCHAR(2000) COMMENT '副标题',
- price DECIMAL(18,4) COMMENT '价格',
- sale_count BIGINT COMMENT '销量', PRIMARY KEY (sku_id)
- )CHARSET=utf8mb4 COMMENT='sku 信息';
- SELECT * FROM commodity_sku_info
复制代码 仍 然 使 用 renren-generator 逆 向 工 程 生 成 对 应 的 代 码 (CRUD) , 并 拷 贝 到
hspliving-commodity, 这个我们已经做过好频频了,请自己完成
- package com.rainbowsea.rainbowsealiving.commodity.service;
- import com.baomidou.mybatisplus.extension.service.IService;
- import com.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SkuInfoEntity;
- import java.util.Map;
- /**
- * sku 信息
- *
- * @author rainbowsea
- * @email rainbowsea@gmail.com
- * @date 2025-03-24 22:01:45
- */
- public interface SkuInfoService extends IService<SkuInfoEntity> {
- PageUtils queryPage(Map<String, Object> params);
- void saveSkuInfo(SkuInfoEntity skuInfoEntity);
- }
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;
- 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.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.common.utils.Query;
- import com.rainbowsea.rainbowsealiving.commodity.dao.SkuInfoDao;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SkuInfoEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.SkuInfoService;
- @Service("skuInfoService")
- public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> implements SkuInfoService {
- @Override
- public void saveSkuInfo(SkuInfoEntity skuInfoEntity) {
- this.baseMapper.insert(skuInfoEntity);
- }
- @Override
- public PageUtils queryPage(Map<String, Object> params) {
- IPage<SkuInfoEntity> page = this.page(
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query<SkuInfoEntity>().getPage(params),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper<SkuInfoEntity>()
- );
- return new PageUtils(page);
- }
- }
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;
- import com.rainbowsea.rainbowsealiving.commodity.entity.AttrEntity;
- import com.rainbowsea.rainbowsealiving.commodity.entity.ProductAttrValueEntity;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SkuInfoEntity;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoDescEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.AttrService;
- import com.rainbowsea.rainbowsealiving.commodity.service.ProductAttrValueService;
- import com.rainbowsea.rainbowsealiving.commodity.service.SkuInfoService;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuImagesService;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoDescService;
- import com.rainbowsea.rainbowsealiving.commodity.vo.BaseAttrs;
- import com.rainbowsea.rainbowsealiving.commodity.vo.Images;
- import com.rainbowsea.rainbowsealiving.commodity.vo.Skus;
- import com.rainbowsea.rainbowsealiving.commodity.vo.SpuSaveVO;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- 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.rainbowsea.common.utils.PageUtils;
- import com.rainbowsea.common.utils.Query;
- import com.rainbowsea.rainbowsealiving.commodity.dao.SpuInfoDao;
- import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoEntity;
- import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoService;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- @Service("spuInfoService")
- public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
- @Resource
- AttrService attrService;
- @Resource
- ProductAttrValueService productAttrValueService;
- @Resource
- SkuInfoService skuInfoService;
- @Transactional
- @Override
- public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- //1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- BeanUtils.copyProperties(spuSaveVO, spuInfoEntity);
- spuInfoEntity.setCreateTime(new Date());
- spuInfoEntity.setUpdateTime(new Date());
- //SpuInfoEntity 信息保存到 commodity_spu_info
- this.saveBaseSpuInfo(spuInfoEntity);
- //2、保存 Spu 的描述图片路径 commodity_spu_info_desc
- List<String> decript = spuSaveVO.getDecript();
- SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
- //获取到刚刚保存的 spu 基本信息对应的 id
- spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
- //注意:这里有可能没有图片, 可以设置一个默认图片
- if (decript.size() == 0) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");
- } else {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));
- }
- //保存到 commodity_spu_info_desc, 这个方法时我们完成
- spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);
- //3、保存 spu 的图片集 commodity_spu_images
- List<String> images = spuSaveVO.getImages();
- //获取到刚刚保存的 spu 基本信息对应的 id
- imagesService.saveImages(spuInfoEntity.getId(), images);
- //4、保存 spu 的基本属性(一个 spu 可以有多个基本属性/规格参数):
- // commodity_product_attr_value
- List<BaseAttrs> baseAttrs = spuSaveVO.getBaseAttrs();
- List<ProductAttrValueEntity> collect = baseAttrs.stream().map(attr -> {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity;
- }).collect(Collectors.toList());
- productAttrValueService.saveProductAttr(collect);
- //5、保存当前 spu 对应的所有 sku 信息;一个 spu 可以 对应多个 sku,
- // 组成一个可以销售的商品信息
- //注意 Images 类在 vo 包下, 确保有@Data 修饰
- List<Skus> skus = spuSaveVO.getSkus();
- if(skus!=null && skus.size()>0){
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skus.forEach(item->{
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> String defaultImg = "default.jpg";
- //json 会提交很多图片,如果是当前这个 sku 的默认图片就先保存下 url
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> for (Images image : item.getImages()) {
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>if(image.getDefaultImg() == 1){
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> defaultImg = image.getImgUrl();
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>}
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuInfoEntity skuInfoEntity = new SkuInfoEntity();
- //把 item 中的信息拷贝给 skuInfoEntity
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> BeanUtils.copyProperties(item,skuInfoEntity);
- //item 中没有信息,但是 skuInfoEntity 需要的信息,
- //可以从 spuInfoEntity 中获取
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setBrandId(spuInfoEntity.getBrandId());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setCatalogId(spuInfoEntity.getCatalogId());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSaleCount(0L);//初始化销量为 0
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSpuId(spuInfoEntity.getId());
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSkuDefaultImg(defaultImg);
- //1)、保存 sku 的基本信息;到 commodity_sku_info
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoService.saveSkuInfo(skuInfoEntity);
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });
- }
- }
- // @Transactional
- // @Override
- // public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- // //1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- // SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- // BeanUtils.copyProperties(spuSaveVO, spuInfoEntity);
- // spuInfoEntity.setCreateTime(new Date());
- // spuInfoEntity.setUpdateTime(new Date());
- ////SpuInfoEntity 信息保存到 commodity_spu_info
- // this.saveBaseSpuInfo(spuInfoEntity);
- ////2、保存 Spu 的描述图片路径 commodity_spu_info_desc
- // List<String> decript = spuSaveVO.getDecript();
- // SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
- ////获取到刚刚保存的 spu 基本信息对应的 id
- // spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
- ////注意:这里有可能没有图片, 可以设置一个默认图片
- // if (decript.size() == 0) {
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");
- // } else {
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));
- // }
- ////保存到 commodity_spu_info_desc, 这个方法时我们完成
- // spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);
- // //3、保存 spu 的图片集 commodity_spu_images
- // List<String> images = spuSaveVO.getImages();
- ////获取到刚刚保存的 spu 基本信息对应的 id
- // imagesService.saveImages(spuInfoEntity.getId(), images);
- ////4、保存 spu 的基本属性(一个 spu 可以有多个基本属性/规格参数):
- //// commodity_product_attr_value
- // List<BaseAttrs> baseAttrs = spuSaveVO.getBaseAttrs();
- // List<ProductAttrValueEntity> collect = baseAttrs.stream().map(attr -> {
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity;
- // }).collect(Collectors.toList());
- // productAttrValueService.saveProductAttr(collect);
- // }
- @Resource
- SpuImagesService imagesService;
- @Resource
- SpuInfoDescService spuInfoDescService;
- //因为有多个添加操作,使用事务控制
- // @Transactional
- // @Override
- // public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- ////1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- // SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- // BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);
- // spuInfoEntity.setCreateTime(new Date());
- // spuInfoEntity.setUpdateTime(new Date());
- ////SpuInfoEntity 信息保存到 commodity_spu_info
- // this.saveBaseSpuInfo(spuInfoEntity);
- ////2、保存 Spu 的描述图片路径 commodity_spu_info_desc
- // List<String> decript = spuSaveVO.getDecript();
- // SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
- ////获取到刚刚保存的 spu 基本信息对应的 id
- // spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
- ////注意:这里有可能没有图片, 可以设置一个默认图片
- // if(decript.size() == 0) {
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");
- // }else {
- //<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));
- // }
- ////保存到 commodity_spu_info_desc, 这个方法时我们完成
- // spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);
- //
- // //3、保存 spu 的图片集 commodity_spu_images
- // List<String> images = spuSaveVO.getImages();
- ////获取到刚刚保存的 spu 基本信息对应的 id
- // imagesService.saveImages(spuInfoEntity.getId(), images);
- // }
- @Override
- public PageUtils queryPage(Map<String, Object> params) {
- IPage<SpuInfoEntity> page = this.page(
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query<SpuInfoEntity>().getPage(params),
- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper<SpuInfoEntity>()
- );
- return new PageUtils(page);
- }
- /**
- * 保存 spu 的基本信息到 commodity_spu_info
- * @param spuInfoEntity
- */
- @Override
- public void saveBaseSpuInfo(SpuInfoEntity spuInfoEntity) {
- this.baseMapper.insert(spuInfoEntity);
- }
- // @Override
- // public void saveSpuInfo(SpuSaveVO spuSaveVO) {
- ////1、保存 spu 基本信息 , 对应的表 commodity_spu_info
- // SpuInfoEntity spuInfoEntity = new SpuInfoEntity();
- // BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);
- // spuInfoEntity.setCreateTime(new Date());
- // spuInfoEntity.setUpdateTime(new Date());
- ////2. 将 SpuInfoEntity 信息保存到 commodity_spu_info
- // this.saveBaseSpuInfo(spuInfoEntity);
- // }
- }
复制代码 保存 spu 和 sku 的 图片信息
可 以 添 加 spu 和 sku 图 片 信 息 保 存 到 了 对 应 的 表 中 , 比 如 :
commodity_sku_images(一步一步来)
完成功能: 只测试是否可以添加 spu 的基本信息到 commodity_spu_info (一步一步来****),
提示****: 如果运行过程中, 提示找不到 VO, Rebuild Project 即可- /*==============================================================*/
- /* 1. 保存 某一个 sku 对应的图片[1 个 sku 可能有多个图片]
- /*=====================================================*/
- USE hspliving_commodity
- CREATE TABLE commodity_sku_images
- (
- id BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id',
- sku_id BIGINT COMMENT 'sku_id',
- img_url VARCHAR(255) COMMENT '图片地址',
- img_sort INT COMMENT '排序',
- default_img INT COMMENT '默认图[0 - 不是默认图,1 - 是默认图]',
- PRIMARY KEY (id)
- )CHARSET=utf8mb4 COMMENT='sku 图片';
- SELECT * FROM commodity_sku_images
复制代码- <el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;import com.rainbowsea.rainbowsealiving.commodity.entity.AttrEntity;import com.rainbowsea.rainbowsealiving.commodity.entity.ProductAttrValueEntity;import com.rainbowsea.rainbowsealiving.commodity.entity.SkuImagesEntity;import com.rainbowsea.rainbowsealiving.commodity.entity.SkuInfoEntity;import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoDescEntity;import com.rainbowsea.rainbowsealiving.commodity.service.AttrService;import com.rainbowsea.rainbowsealiving.commodity.service.ProductAttrValueService;import com.rainbowsea.rainbowsealiving.commodity.service.SkuImagesService;import com.rainbowsea.rainbowsealiving.commodity.service.SkuInfoService;import com.rainbowsea.rainbowsealiving.commodity.service.SpuImagesService;import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoDescService;import com.rainbowsea.rainbowsealiving.commodity.vo.BaseAttrs;import com.rainbowsea.rainbowsealiving.commodity.vo.Images;import com.rainbowsea.rainbowsealiving.commodity.vo.Skus;import com.rainbowsea.rainbowsealiving.commodity.vo.SpuSaveVO;import org.apache.commons.lang.StringUtils;import org.springframework.beans.BeanUtils;import org.springframework.stereotype.Service;import java.util.Date;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.rainbowsea.common.utils.PageUtils;import com.rainbowsea.common.utils.Query;import com.rainbowsea.rainbowsealiving.commodity.dao.SpuInfoDao;import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoEntity;import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoService;import org.springframework.transaction.annotation.Transactional;import javax.annotation.Resource;@Service("spuInfoService")public class SpuInfoServiceImpl extends ServiceImpl implements SpuInfoService { @Resource AttrService attrService; @Resource ProductAttrValueService productAttrValueService; @Resource SkuInfoService skuInfoService; @Resource SkuImagesService skuImagesService; @Resource SpuImagesService imagesService; @Resource SpuInfoDescService spuInfoDescService; @Transactional @Override public void saveSpuInfo(SpuSaveVO spuSaveVO) { //1、保存 spu 基本信息 , 对应的表 commodity_spu_info SpuInfoEntity spuInfoEntity = new SpuInfoEntity(); BeanUtils.copyProperties(spuSaveVO, spuInfoEntity); spuInfoEntity.setCreateTime(new Date()); spuInfoEntity.setUpdateTime(new Date());//SpuInfoEntity 信息保存到 commodity_spu_info this.saveBaseSpuInfo(spuInfoEntity);//2、保存 Spu 的描述图片路径 commodity_spu_info_desc List decript = spuSaveVO.getDecript(); SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();//获取到刚刚保存的 spu 基本信息对应的 id spuInfoDescEntity.setSpuId(spuInfoEntity.getId());//留意:这里有可能没有图片, 可以设置一个默认图片 if (decript.size() == 0) {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg"); } else {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript)); }//保存到 commodity_spu_info_desc, 这个方法时我们完成 spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity); //3、保存 spu 的图片集 commodity_spu_images List images = spuSaveVO.getImages();//获取到刚刚保存的 spu 基本信息对应的 id imagesService.saveImages(spuInfoEntity.getId(), images);//4 、 保 存 spu 的 基 本 属 性 ( 一 个 spu 可 以 有 多 个 基 本 属 性 / 规 格 参 数 ):commodity_product_attr_value List baseAttrs = spuSaveVO.getBaseAttrs(); List collect = baseAttrs.stream().map(attr -> {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity; }).collect(Collectors.toList()); productAttrValueService.saveProductAttr(collect); //5、保存当前 spu 对应的全部 sku 信息;一个 spu 可以 对应多个 sku, 组成一个可以销售的商品信息. List skus = spuSaveVO.getSkus(); if (skus != null && skus.size() > 0) {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skus.forEach(item -> {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> String defaultImg = "default.jpg";//json 会提交很多图片,如果是当前这个 sku 的默认图片就先保存下 url<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> for (Images image : item.getImages()) {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>if (image.getDefaultImg() == 1) {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> defaultImg = image.getImgUrl();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>}<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }//保存 sku 的基本信息;到 commodity_sku_info start<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuInfoEntity skuInfoEntity = new SkuInfoEntity();//把 item 中的信息拷贝给 skuInfoEntity<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> BeanUtils.copyProperties(item, skuInfoEntity);//item 中没有信息,但是 skuInfoEntity 必要的信息,可以从 spuInfoEntity 中获取<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setBrandId(spuInfoEntity.getBrandId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setCatalogId(spuInfoEntity.getCatalogId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSaleCount(0L);//初始化销量为 0<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSpuId(spuInfoEntity.getId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSkuDefaultImg(defaultImg);<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoService.saveSkuInfo(skuInfoEntity);//保存 sku 的基本信息;到 commodity_sku_info end//保存 sku 的图片信息;到 commodity_sku_images start//一个 sku 可以有多张图片<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> Long skuId = skuInfoEntity.getSkuId();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> List imagesEntities =<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> item.getImages().stream().map(img -> {//取出当前 item (就是一个 spk)的信息,组装成 一个 SkuImagesEntity, 进行保存<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuImagesEntity skuImagesEntity = new SkuImagesEntity();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuImagesEntity.setSkuId(skuId);<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuImagesEntity.setImgUrl(img.getImgUrl());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuImagesEntity.setDefaultImg(img.getDefaultImg());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return skuImagesEntity;<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }).filter(entity -> {//如果 image 为 empty ,就不过滤掉, 返回 true 就是必要,false 就是剔除<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return !StringUtils.isEmpty(entity.getImgUrl());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }).collect(Collectors.toList());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuImagesService.saveBatch(imagesEntities);//保存 sku 的图片信息;到 commodity_sku_images end<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }); } }// @Transactional// @Override// public void saveSpuInfo(SpuSaveVO spuSaveVO) {// //1、保存 spu 基本信息 , 对应的表 commodity_spu_info// SpuInfoEntity spuInfoEntity = new SpuInfoEntity();// BeanUtils.copyProperties(spuSaveVO, spuInfoEntity);// spuInfoEntity.setCreateTime(new Date());// spuInfoEntity.setUpdateTime(new Date());////SpuInfoEntity 信息保存到 commodity_spu_info// this.saveBaseSpuInfo(spuInfoEntity);////2、保存 Spu 的描述图片路径 commodity_spu_info_desc// List decript = spuSaveVO.getDecript();// SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();////获取到刚刚保存的 spu 基本信息对应的 id// spuInfoDescEntity.setSpuId(spuInfoEntity.getId());////留意:这里有可能没有图片, 可以设置一个默认图片// if (decript.size() == 0) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");// } else {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));// }////保存到 commodity_spu_info_desc, 这个方法时我们完成// spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);//// //3、保存 spu 的图片集 commodity_spu_images// List images = spuSaveVO.getImages();////获取到刚刚保存的 spu 基本信息对应的 id// imagesService.saveImages(spuInfoEntity.getId(), images);////4、保存 spu 的基本属性(一个 spu 可以有多个基本属性/规格参数)://// commodity_product_attr_value// List baseAttrs = spuSaveVO.getBaseAttrs();// List collect = baseAttrs.stream().map(attr -> {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity;// }).collect(Collectors.toList());// productAttrValueService.saveProductAttr(collect);//// //5、保存当前 spu 对应的全部 sku 信息;一个 spu 可以 对应多个 sku,//// 组成一个可以销售的商品信息////留意 Images 类在 vo 包下, 确保有@Data 修饰// List skus = spuSaveVO.getSkus();// if(skus!=null && skus.size()>0){//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skus.forEach(item->{//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> String defaultImg = "default.jpg";////json 会提交很多图片,如果是当前这个 sku 的默认图片就先保存下 url//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> for (Images image : item.getImages()) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>if(image.getDefaultImg() == 1){//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> defaultImg = image.getImgUrl();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>}//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuInfoEntity skuInfoEntity = new SkuInfoEntity();////把 item 中的信息拷贝给 skuInfoEntity//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> BeanUtils.copyProperties(item,skuInfoEntity);////item 中没有信息,但是 skuInfoEntity 必要的信息,////可以从 spuInfoEntity 中获取//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setBrandId(spuInfoEntity.getBrandId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setCatalogId(spuInfoEntity.getCatalogId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSaleCount(0L);//初始化销量为 0//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSpuId(spuInfoEntity.getId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSkuDefaultImg(defaultImg);////1)、保存 sku 的基本信息;到 commodity_sku_info//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoService.saveSkuInfo(skuInfoEntity);//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });// }// }// @Transactional// @Override// public void saveSpuInfo(SpuSaveVO spuSaveVO) {// //1、保存 spu 基本信息 , 对应的表 commodity_spu_info// SpuInfoEntity spuInfoEntity = new SpuInfoEntity();// BeanUtils.copyProperties(spuSaveVO, spuInfoEntity);// spuInfoEntity.setCreateTime(new Date());// spuInfoEntity.setUpdateTime(new Date());////SpuInfoEntity 信息保存到 commodity_spu_info// this.saveBaseSpuInfo(spuInfoEntity);////2、保存 Spu 的描述图片路径 commodity_spu_info_desc// List decript = spuSaveVO.getDecript();// SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();////获取到刚刚保存的 spu 基本信息对应的 id// spuInfoDescEntity.setSpuId(spuInfoEntity.getId());////留意:这里有可能没有图片, 可以设置一个默认图片// if (decript.size() == 0) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");// } else {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));// }////保存到 commodity_spu_info_desc, 这个方法时我们完成// spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);// //3、保存 spu 的图片集 commodity_spu_images// List images = spuSaveVO.getImages();////获取到刚刚保存的 spu 基本信息对应的 id// imagesService.saveImages(spuInfoEntity.getId(), images);////4、保存 spu 的基本属性(一个 spu 可以有多个基本属性/规格参数)://// commodity_product_attr_value// List baseAttrs = spuSaveVO.getBaseAttrs();// List collect = baseAttrs.stream().map(attr -> {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity;// }).collect(Collectors.toList());// productAttrValueService.saveProductAttr(collect);// } //因为有多个添加操作,使用事务控制// @Transactional// @Override// public void saveSpuInfo(SpuSaveVO spuSaveVO) {////1、保存 spu 基本信息 , 对应的表 commodity_spu_info// SpuInfoEntity spuInfoEntity = new SpuInfoEntity();// BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);// spuInfoEntity.setCreateTime(new Date());// spuInfoEntity.setUpdateTime(new Date());////SpuInfoEntity 信息保存到 commodity_spu_info// this.saveBaseSpuInfo(spuInfoEntity);////2、保存 Spu 的描述图片路径 commodity_spu_info_desc// List decript = spuSaveVO.getDecript();// SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();////获取到刚刚保存的 spu 基本信息对应的 id// spuInfoDescEntity.setSpuId(spuInfoEntity.getId());////留意:这里有可能没有图片, 可以设置一个默认图片// if(decript.size() == 0) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");// }else {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));// }////保存到 commodity_spu_info_desc, 这个方法时我们完成// spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);//// //3、保存 spu 的图片集 commodity_spu_images// List images = spuSaveVO.getImages();////获取到刚刚保存的 spu 基本信息对应的 id// imagesService.saveImages(spuInfoEntity.getId(), images);// } @Override public PageUtils queryPage(Map params) { IPage page = this.page(<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new Query().getPage(params),<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> new QueryWrapper() ); return new PageUtils(page); } /** * 保存 spu 的基本信息到 commodity_spu_info * * @param spuInfoEntity */ @Override public void saveBaseSpuInfo(SpuInfoEntity spuInfoEntity) { this.baseMapper.insert(spuInfoEntity); }// @Override// public void saveSpuInfo(SpuSaveVO spuSaveVO) {////1、保存 spu 基本信息 , 对应的表 commodity_spu_info// SpuInfoEntity spuInfoEntity = new SpuInfoEntity();// BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);// spuInfoEntity.setCreateTime(new Date());// spuInfoEntity.setUpdateTime(new Date());////2. 将 SpuInfoEntity 信息保存到 commodity_spu_info// this.saveBaseSpuInfo(spuInfoEntity);// }}
复制代码

保存 sku 的销售属性
对照 JSON 数据分析
- # 创建保存 sku 的销售属性表
- /*====================================================*/
- /* 1.保存 sku 的销售属性/值, 一个 sku 可以有多个销售属性/值
- /* 2.比如 1 个 sku 有颜色(黑色)和尺寸(100*300)两个销售属性
- /*=====================================================*/
- USE hspliving_commodity
- CREATE TABLE commodity_sku_sale_attr_value
- (
- id BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id',
- sku_id BIGINT COMMENT 'sku_id',
- attr_id BIGINT COMMENT 'attr_id',
- attr_name VARCHAR(200) COMMENT '销售属性名',
- attr_value VARCHAR(200) COMMENT '销售属性值',
- attr_sort INT COMMENT '顺序', PRIMARY KEY (id)
- )CHARSET=utf8mb4 COMMENT='sku 的销售属性/值表';
- SELECT * FROM commodity_sku_sale_attr_value
复制代码 - package com.rainbowsea.rainbowsealiving.commodity.service.impl;import com.rainbowsea.rainbowsealiving.commodity.entity.AttrEntity;import com.rainbowsea.rainbowsealiving.commodity.entity.ProductAttrValueEntity;import com.rainbowsea.rainbowsealiving.commodity.entity.SkuImagesEntity;import com.rainbowsea.rainbowsealiving.commodity.entity.SkuInfoEntity;import com.rainbowsea.rainbowsealiving.commodity.entity.SkuSaleAttrValueEntity;import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoDescEntity;import com.rainbowsea.rainbowsealiving.commodity.service.AttrService;import com.rainbowsea.rainbowsealiving.commodity.service.ProductAttrValueService;import com.rainbowsea.rainbowsealiving.commodity.service.SkuImagesService;import com.rainbowsea.rainbowsealiving.commodity.service.SkuInfoService;import com.rainbowsea.rainbowsealiving.commodity.service.SkuSaleAttrValueService;import com.rainbowsea.rainbowsealiving.commodity.service.SpuImagesService;import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoDescService;import com.rainbowsea.rainbowsealiving.commodity.vo.Attr;import com.rainbowsea.rainbowsealiving.commodity.vo.BaseAttrs;import com.rainbowsea.rainbowsealiving.commodity.vo.Images;import com.rainbowsea.rainbowsealiving.commodity.vo.Skus;import com.rainbowsea.rainbowsealiving.commodity.vo.SpuSaveVO;import org.apache.commons.lang.StringUtils;import org.springframework.beans.BeanUtils;import org.springframework.stereotype.Service;import java.util.Date;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.rainbowsea.common.utils.PageUtils;import com.rainbowsea.common.utils.Query;import com.rainbowsea.rainbowsealiving.commodity.dao.SpuInfoDao;import com.rainbowsea.rainbowsealiving.commodity.entity.SpuInfoEntity;import com.rainbowsea.rainbowsealiving.commodity.service.SpuInfoService;import org.springframework.transaction.annotation.Transactional;import javax.annotation.Resource;@Service("spuInfoService")public class SpuInfoServiceImpl extends ServiceImpl implements SpuInfoService { @Resource AttrService attrService; @Resource ProductAttrValueService productAttrValueService; @Resource SkuInfoService skuInfoService; @Resource SkuImagesService skuImagesService; @Resource SpuImagesService imagesService; @Resource SpuInfoDescService spuInfoDescService; @Resource SkuSaleAttrValueService skuSaleAttrValueService; @Transactional @Override public void saveSpuInfo(SpuSaveVO spuSaveVO) { //1、保存 spu 基本信息 , 对应的表 commodity_spu_info SpuInfoEntity spuInfoEntity = new SpuInfoEntity(); BeanUtils.copyProperties(spuSaveVO, spuInfoEntity); spuInfoEntity.setCreateTime(new Date()); spuInfoEntity.setUpdateTime(new Date());//SpuInfoEntity 信息保存到 commodity_spu_info this.saveBaseSpuInfo(spuInfoEntity); //2、保存 Spu 的描述图片路径 commodity_spu_info_desc List decript = spuSaveVO.getDecript(); SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();//获取到刚刚保存的 spu 基本信息对应的 id spuInfoDescEntity.setSpuId(spuInfoEntity.getId());//留意:这里有可能没有图片, 可以设置一个默认图片 if (decript.size() == 0) {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg"); } else {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript)); }//保存到 commodity_spu_info_desc, 这个方法时我们完成 spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);//3、保存 spu 的图片集 commodity_spu_images List images = spuSaveVO.getImages();//获取到刚刚保存的 spu 基本信息对应的 id imagesService.saveImages(spuInfoEntity.getId(), images);//4 、 保 存 spu 的 基 本 属 性 ( 一 个 spu 可 以 有 多 个 基 本 属 性 / 规 格 参 数 ):commodity_product_attr_value List baseAttrs = spuSaveVO.getBaseAttrs(); List collect = baseAttrs.stream().map(attr -> {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity; }).collect(Collectors.toList()); productAttrValueService.saveProductAttr(collect); //5、保存当前 spu 对应的全部 sku 信息;一个 spu 可以 对应多个 sku, 组成一个可以销售的商品信息 List skus = spuSaveVO.getSkus(); if (skus != null && skus.size() > 0) {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skus.forEach(item -> {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> String defaultImg = "default.jpg";<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> //json 会提交很多图片,如果是当前这个 sku 的默认图片就先保存下 url<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> for (Images image : item.getImages()) {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>if (image.getDefaultImg() == 1) {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> defaultImg = image.getImgUrl();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>}<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }//保存 sku 的基本信息;到 commodity_sku_info start<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuInfoEntity skuInfoEntity = new SkuInfoEntity();//把 item 中的信息拷贝给 skuInfoEntity<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> BeanUtils.copyProperties(item, skuInfoEntity);//item 中没有信息,但是 skuInfoEntity 必要的信息,可以从 spuInfoEntity 中获取<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setBrandId(spuInfoEntity.getBrandId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setCatalogId(spuInfoEntity.getCatalogId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSaleCount(0L);//初始化销量为 0<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSpuId(spuInfoEntity.getId());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSkuDefaultImg(defaultImg);<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoService.saveSkuInfo(skuInfoEntity);//保存 sku 的基本信息;到 commodity_sku_info end<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> //保存 sku 的图片信息;到 commodity_sku_images start//一个 sku 可以有多张图片<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> Long skuId = skuInfoEntity.getSkuId();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> List imagesEntities = item.getImages().stream().map(img -><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> {//取出当前 item (就是一个 spk)的信息,组装成 一个 SkuImagesEntity, 进行保存<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>SkuImagesEntity skuImagesEntity = new SkuImagesEntity();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>skuImagesEntity.setSkuId(skuId);<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>skuImagesEntity.setImgUrl(img.getImgUrl());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>skuImagesEntity.setDefaultImg(img.getDefaultImg());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>return skuImagesEntity;<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }).filter(entity -> {//如果 image 为 empty ,就不过滤掉, 返回 true 就是必要,false 就是剔除<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>return !StringUtils.isEmpty(entity.getImgUrl());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }).collect(Collectors.toList());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuImagesService.saveBatch(imagesEntities);//保存 sku 的图片信息;到 commodity_sku_images end//保存 sku 的销售属性-值到 commodity_sku_sale_attr_value start<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> List attr = item.getAttr();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> List skuSaleAttrValueEntities =<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> attr.stream().map(a -> {<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuSaleAttrValueEntity attrValueEntity = new<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuSaleAttrValueEntity();<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> BeanUtils.copyProperties(a, attrValueEntity);<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> attrValueEntity.setSkuId(skuId);<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return attrValueEntity;<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }).collect(Collectors.toList());<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);//保存 sku 的销售属性-值到 commodity_sku_sale_attr_value end<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }); } }// @Transactional// @Override// public void saveSpuInfo(SpuSaveVO spuSaveVO) {// //1、保存 spu 基本信息 , 对应的表 commodity_spu_info// SpuInfoEntity spuInfoEntity = new SpuInfoEntity();// BeanUtils.copyProperties(spuSaveVO, spuInfoEntity);// spuInfoEntity.setCreateTime(new Date());// spuInfoEntity.setUpdateTime(new Date());////SpuInfoEntity 信息保存到 commodity_spu_info// this.saveBaseSpuInfo(spuInfoEntity);////2、保存 Spu 的描述图片路径 commodity_spu_info_desc// List decript = spuSaveVO.getDecript();// SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();////获取到刚刚保存的 spu 基本信息对应的 id// spuInfoDescEntity.setSpuId(spuInfoEntity.getId());////留意:这里有可能没有图片, 可以设置一个默认图片// if (decript.size() == 0) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");// } else {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));// }////保存到 commodity_spu_info_desc, 这个方法时我们完成// spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);// //3、保存 spu 的图片集 commodity_spu_images// List images = spuSaveVO.getImages();////获取到刚刚保存的 spu 基本信息对应的 id// imagesService.saveImages(spuInfoEntity.getId(), images);////4 、 保 存 spu 的 基 本 属 性 ( 一 个 spu 可 以 有 多 个 基 本 属 性 / 规 格 参 数 ):commodity_product_attr_value// List baseAttrs = spuSaveVO.getBaseAttrs();// List collect = baseAttrs.stream().map(attr -> {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity;// }).collect(Collectors.toList());// productAttrValueService.saveProductAttr(collect);//// //5、保存当前 spu 对应的全部 sku 信息;一个 spu 可以 对应多个 sku, 组成一个可以销售的商品信息.// List skus = spuSaveVO.getSkus();// if (skus != null && skus.size() > 0) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skus.forEach(item -> {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> String defaultImg = "default.jpg";////json 会提交很多图片,如果是当前这个 sku 的默认图片就先保存下 url//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> for (Images image : item.getImages()) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>if (image.getDefaultImg() == 1) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> defaultImg = image.getImgUrl();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>}//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }////保存 sku 的基本信息;到 commodity_sku_info start//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuInfoEntity skuInfoEntity = new SkuInfoEntity();////把 item 中的信息拷贝给 skuInfoEntity//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> BeanUtils.copyProperties(item, skuInfoEntity);////item 中没有信息,但是 skuInfoEntity 必要的信息,可以从 spuInfoEntity 中获取//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setBrandId(spuInfoEntity.getBrandId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setCatalogId(spuInfoEntity.getCatalogId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSaleCount(0L);//初始化销量为 0//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSpuId(spuInfoEntity.getId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSkuDefaultImg(defaultImg);//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoService.saveSkuInfo(skuInfoEntity);////保存 sku 的基本信息;到 commodity_sku_info end////保存 sku 的图片信息;到 commodity_sku_images start////一个 sku 可以有多张图片//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> Long skuId = skuInfoEntity.getSkuId();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> List imagesEntities =//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> item.getImages().stream().map(img -> {////取出当前 item (就是一个 spk)的信息,组装成 一个 SkuImagesEntity, 进行保存////<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuImagesEntity skuImagesEntity = new SkuImagesEntity();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuImagesEntity.setSkuId(skuId);//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuImagesEntity.setImgUrl(img.getImgUrl());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuImagesEntity.setDefaultImg(img.getDefaultImg());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return skuImagesEntity;//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }).filter(entity -> {////如果 image 为 empty ,就不过滤掉, 返回 true 就是必要,false 就是剔除//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return !StringUtils.isEmpty(entity.getImgUrl());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }).collect(Collectors.toList());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuImagesService.saveBatch(imagesEntities);////保存 sku 的图片信息;到 commodity_sku_images end//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });// }// }//// @Transactional// @Override// public void saveSpuInfo(SpuSaveVO spuSaveVO) {// //1、保存 spu 基本信息 , 对应的表 commodity_spu_info// SpuInfoEntity spuInfoEntity = new SpuInfoEntity();// BeanUtils.copyProperties(spuSaveVO, spuInfoEntity);// spuInfoEntity.setCreateTime(new Date());// spuInfoEntity.setUpdateTime(new Date());////SpuInfoEntity 信息保存到 commodity_spu_info// this.saveBaseSpuInfo(spuInfoEntity);////2、保存 Spu 的描述图片路径 commodity_spu_info_desc// List decript = spuSaveVO.getDecript();// SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();////获取到刚刚保存的 spu 基本信息对应的 id// spuInfoDescEntity.setSpuId(spuInfoEntity.getId());////留意:这里有可能没有图片, 可以设置一个默认图片// if (decript.size() == 0) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");// } else {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));// }////保存到 commodity_spu_info_desc, 这个方法时我们完成// spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);//// //3、保存 spu 的图片集 commodity_spu_images// List images = spuSaveVO.getImages();////获取到刚刚保存的 spu 基本信息对应的 id// imagesService.saveImages(spuInfoEntity.getId(), images);////4、保存 spu 的基本属性(一个 spu 可以有多个基本属性/规格参数)://// commodity_product_attr_value// List baseAttrs = spuSaveVO.getBaseAttrs();// List collect = baseAttrs.stream().map(attr -> {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity;// }).collect(Collectors.toList());// productAttrValueService.saveProductAttr(collect);//// //5、保存当前 spu 对应的全部 sku 信息;一个 spu 可以 对应多个 sku,//// 组成一个可以销售的商品信息////留意 Images 类在 vo 包下, 确保有@Data 修饰// List skus = spuSaveVO.getSkus();// if(skus!=null && skus.size()>0){//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skus.forEach(item->{//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> String defaultImg = "default.jpg";////json 会提交很多图片,如果是当前这个 sku 的默认图片就先保存下 url//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> for (Images image : item.getImages()) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>if(image.getDefaultImg() == 1){//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> defaultImg = image.getImgUrl();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>}//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> }//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> SkuInfoEntity skuInfoEntity = new SkuInfoEntity();////把 item 中的信息拷贝给 skuInfoEntity//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> BeanUtils.copyProperties(item,skuInfoEntity);////item 中没有信息,但是 skuInfoEntity 必要的信息,////可以从 spuInfoEntity 中获取//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setBrandId(spuInfoEntity.getBrandId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setCatalogId(spuInfoEntity.getCatalogId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSaleCount(0L);//初始化销量为 0//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSpuId(spuInfoEntity.getId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoEntity.setSkuDefaultImg(defaultImg);////1)、保存 sku 的基本信息;到 commodity_sku_info//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> skuInfoService.saveSkuInfo(skuInfoEntity);//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> });// }// }// @Transactional// @Override// public void saveSpuInfo(SpuSaveVO spuSaveVO) {// //1、保存 spu 基本信息 , 对应的表 commodity_spu_info// SpuInfoEntity spuInfoEntity = new SpuInfoEntity();// BeanUtils.copyProperties(spuSaveVO, spuInfoEntity);// spuInfoEntity.setCreateTime(new Date());// spuInfoEntity.setUpdateTime(new Date());////SpuInfoEntity 信息保存到 commodity_spu_info// this.saveBaseSpuInfo(spuInfoEntity);////2、保存 Spu 的描述图片路径 commodity_spu_info_desc// List decript = spuSaveVO.getDecript();// SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();////获取到刚刚保存的 spu 基本信息对应的 id// spuInfoDescEntity.setSpuId(spuInfoEntity.getId());////留意:这里有可能没有图片, 可以设置一个默认图片// if (decript.size() == 0) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");// } else {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));// }////保存到 commodity_spu_info_desc, 这个方法时我们完成// spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);// //3、保存 spu 的图片集 commodity_spu_images// List images = spuSaveVO.getImages();////获取到刚刚保存的 spu 基本信息对应的 id// imagesService.saveImages(spuInfoEntity.getId(), images);////4、保存 spu 的基本属性(一个 spu 可以有多个基本属性/规格参数)://// commodity_product_attr_value// List baseAttrs = spuSaveVO.getBaseAttrs();// List collect = baseAttrs.stream().map(attr -> {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrId(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> AttrEntity id = attrService.getById(attr.getAttrId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrName(id.getAttrName());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setAttrValue(attr.getAttrValues());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setQuickShow(attr.getShowDesc());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> valueEntity.setSpuId(spuInfoEntity.getId());//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return valueEntity;// }).collect(Collectors.toList());// productAttrValueService.saveProductAttr(collect);// } //因为有多个添加操作,使用事务控制// @Transactional// @Override// public void saveSpuInfo(SpuSaveVO spuSaveVO) {////1、保存 spu 基本信息 , 对应的表 commodity_spu_info// SpuInfoEntity spuInfoEntity = new SpuInfoEntity();// BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);// spuInfoEntity.setCreateTime(new Date());// spuInfoEntity.setUpdateTime(new Date());////SpuInfoEntity 信息保存到 commodity_spu_info// this.saveBaseSpuInfo(spuInfoEntity);////2、保存 Spu 的描述图片路径 commodity_spu_info_desc// List decript = spuSaveVO.getDecript();// SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();////获取到刚刚保存的 spu 基本信息对应的 id// spuInfoDescEntity.setSpuId(spuInfoEntity.getId());////留意:这里有可能没有图片, 可以设置一个默认图片// if(decript.size() == 0) {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript("default.jpg");// }else {//<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> spuInfoDescEntity.setDecript(String.join(",", decript));// }////保存到 commodity_spu_info_desc, 这个方法时我们完成// spuInfoDescService.saveSpuInfoDesc(spuInfoDescEntity);//// //3、保存 spu 的图片集 commodity_spu_images// List images = spuSaveVO.getImages();////获取到刚刚保存的 spu 基本信息对应的 id// imagesService.saveImages(spuInfoEntity.getId(), images);// } @Override public PageUtils queryPage (Map < String, Object > params){<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> IPage page = this.page(<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>new Query().getPage(params),<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload><el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload>new QueryWrapper()<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> );<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> return new PageUtils(page); } /** * 保存 spu 的基本信息到 commodity_spu_info * * @param spuInfoEntity */ @Override public void saveBaseSpuInfo (SpuInfoEntity spuInfoEntity){<el-upload
- action="http://hspliving-10000.oss-cn-beijing.aliyuncs.com"
- :data="dataObj"
- :list-type="listType"
- :file-list="fileList"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :on-success="handleUploadSuccess"
- :on-preview="handlePreview"
- :limit="maxCount"
- :on-exceed="handleExceed"
- :show-file-list="showFile"
- >
- <i ></i>
- </el-upload> this.baseMapper.insert(spuInfoEntity); }// @Override// public void saveSpuInfo(SpuSaveVO spuSaveVO) {////1、保存 spu 基本信息 , 对应的表 commodity_spu_info// SpuInfoEntity spuInfoEntity = new SpuInfoEntity();// BeanUtils.copyProperties(spuSaveVO,spuInfoEntity);// spuInfoEntity.setCreateTime(new Date());// spuInfoEntity.setUpdateTime(new Date());////2. 将 SpuInfoEntity 信息保存到 commodity_spu_info// this.saveBaseSpuInfo(spuInfoEntity);// } }
复制代码 使用订阅发布功能的实现
因为要使用到订阅发布功能,所以我们必要做如下操作.
使用 npm 添加依赖:npm install --save pubsub-js(失败的话使用此下令:cnpm install --save pubsub-js)
- E:\Java\project\RainbowSealiving\renren-fast-vue>npm install --save pubsub-js
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |