1、sku管理功能实现

pull/254/head
xjs 4 years ago
parent 0a234db339
commit fcd49fcc1c

@ -0,0 +1,10 @@
import request from '@/utils/request'
// 获取分页列表
export function getSkuList(data) {
return request({
url: '/mall-product/product/skuinfo/list',
method: 'get',
params: data
})
}

@ -5,7 +5,7 @@
<div>
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item>
<el-input v-model="dataForm.key" placeholder="请输入属性名、可选值等" clearable></el-input>
<el-input v-model="dataForm.key" maxlength="100" placeholder="请输入属性名、可选值等" clearable></el-input>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()"></el-button>

@ -8,7 +8,7 @@
<div class="mod-config">
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item>
<el-input v-model="dataForm.key" placeholder="请输入组名、描述、分类id等" style="width: 300px" clearable></el-input>
<el-input v-model="dataForm.key" maxlength="100" placeholder="请输入组名、描述、分类id等" style="width: 300px" clearable></el-input>
</el-form-item>
<el-form-item>
<el-button-group>

@ -9,14 +9,17 @@
<brand-select style="width:160px"></brand-select>
</el-form-item>
<el-form-item label="价格">
<el-input-number style="width:160px" v-model="dataForm.price.min" :min="0"></el-input-number>-
<el-input-number style="width:160px" v-model="dataForm.price.max" :min="0"></el-input-number>
<el-input-number style="width:140px" v-model="dataForm.price.min" :min="0"></el-input-number>
-
<el-input-number style="width:140px" v-model="dataForm.price.max" :min="0"></el-input-number>
</el-form-item>
<el-form-item label="检索">
<el-input style="width:160px" v-model="dataForm.key" clearable></el-input>
<el-input maxlength="100" style="width:300px" v-model="dataForm.key" clearable
placeholder="请输入sku名称或描述、标题、副标题等"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="searchSkuInfo"></el-button>
<el-button size="mini" type="primary" @click="searchSkuInfo"></el-button>
<el-button size="mini" icon="el-icon-refresh" @click="resetQuery"></el-button>
</el-form-item>
</el-form>
</el-form>
@ -30,26 +33,50 @@
>
<el-table-column type="expand">
<template slot-scope="scope">
商品标题{{scope.row.skuTitle}}
<br />
商品副标题{{scope.row.skuSubtitle}}
<br />
商品描述{{scope.row.skuDesc}}
<br />
分类ID{{scope.row.catalogId}}
<br />
SpuID{{scope.row.spuId}}
<br />
品牌ID{{scope.row.brandId}}
<br />
<el-form label-position="left" class="demo-table-expand">
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="商品标题">
<span>{{ scope.row.skuTitle }}</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="商品副标题">
<span>{{ scope.row.skuSubtitle }}</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="商品描述">
<span>{{ scope.row.skuDesc }}</span>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="分类名称">
<span>{{ scope.row.catalogName }}</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="spu名称">
<span>{{ scope.row.spuName }}</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="品牌名称">
<span>{{ scope.row.brandName }}</span>
</el-form-item>
</el-col>
</el-row>
</el-form>
</template>
</el-table-column>
<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
<el-table-column prop="skuId" header-align="center" align="center" label="skuId"></el-table-column>
<el-table-column prop="skuName" header-align="center" align="center" label="名称"></el-table-column>
<el-table-column prop="skuDefaultImg" header-align="center" align="center" label="默认图片">
<template slot-scope="scope">
<img :src="scope.row.skuDefaultImg" style="width:80px;height:80px;" />
<img :src="scope.row.skuDefaultImg" style="width:80px;height:80px;"/>
</template>
</el-table-column>
<el-table-column prop="price" header-align="center" align="center" label="价格"></el-table-column>
@ -93,6 +120,8 @@
<script>
import CategoryCascader from '../../../components/mall/category-cascader'
import BrandSelect from "../../../components/mall/brand-select";
import {getSkuList} from "@/api/mall/product/sku-info";
export default {
data() {
return {
@ -121,7 +150,7 @@ export default {
CategoryCascader,
BrandSelect
},
activated() {
created() {
this.getDataList();
},
methods: {
@ -132,7 +161,7 @@ export default {
//
handleCommand(row, command) {
if ("stockSettings" === command) {
this.$router.push({ path: "/ware-sku", query: { skuId: row.skuId } });
this.$router.push({path: "/ware-sku", query: {skuId: row.skuId}});
}
},
@ -142,10 +171,7 @@ export default {
//
getDataList() {
this.dataListLoading = true;
this.$http({
url: this.$http.adornUrl("/product/skuinfo/list"),
method: "get",
params: this.$http.adornParams({
let params = {
page: this.pageIndex,
limit: this.pageSize,
key: this.dataForm.key,
@ -153,34 +179,49 @@ export default {
brandId: this.dataForm.brandId,
min: this.dataForm.price.min,
max: this.dataForm.price.max
})
}).then(({ data }) => {
if (data && data.code === 0) {
this.dataList = data.page.list;
this.totalPage = data.page.totalCount;
} else {
this.dataList = [];
this.totalPage = 0;
}
getSkuList(params).then(res => {
this.dataList = res.page.list;
this.totalPage = res.page.totalCount;
this.dataListLoading = false;
});
})
},
//
sizeChangeHandle(val) {
this.pageSize = val;
this.pageIndex = 1;
this.getDataList();
},
//
currentChangeHandle(val) {
this.pageIndex = val;
this.getDataList();
},
//
selectionChangeHandle(val) {
this.dataListSelections = val;
},
/** 重置按钮操作 */
resetQuery() {
this.dataForm = {
price: {
min: 0,
max: 0
}
}
this.$bus.$emit('clearCategoryCascader', [])
this.$bus.$emit('clearBrandSelect', [])
this.pageIndex = 1
this.getDataList()
},
},
mounted() {
this.catPathSub = PubSub.subscribe("catPath", (msg, val) => {
this.dataForm.catelogId = val[val.length - 1];

@ -17,7 +17,8 @@
</el-select>
</el-form-item>
<el-form-item label="检索">
<el-input style="width:200px" v-model="dataForm.key" clearable placeholder="请输入spu名称或描述"></el-input>
<el-input style="width:200px" maxlength="100" v-model="dataForm.key" clearable
placeholder="请输入spu名称或描述"></el-input>
</el-form-item>
<el-form-item>
<el-button-group>
@ -70,10 +71,10 @@ export default {
/** 重置按钮操作 */
resetQuery() {
this.dataForm={}
this.dataForm = {}
// this.catelogPath= []
this.$bus.$emit('clearCategoryCascader',[])
this.$bus.$emit('clearBrandSelect',[])
this.$bus.$emit('clearCategoryCascader', [])
this.$bus.$emit('clearBrandSelect', [])
},

@ -7,6 +7,9 @@ import com.ruoyi.common.core.utils.sql.SqlUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableSupport;
import com.xjs.utils.Query;
import java.util.Map;
/**
* controller
@ -45,4 +48,18 @@ public class MyBaseController<T> extends BaseController {
return page;
}
/**
*
* @param params
*/
protected void checkParams(Map<String, Object> params) {
String key = (String) params.get(Query.KEY_NAME);
if (StringUtils.isNotEmpty(key)) {
if (key.length() > 100) {
throw new IllegalArgumentException("key长度超过 100 ");
}
}
}
}

@ -2,6 +2,7 @@ package com.xjs.mall.product.controller;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.xjs.mall.product.entity.AttrEntity;
import com.xjs.mall.product.service.AttrService;
import com.xjs.mall.product.vo.AttrGroupRelationVo;
import com.xjs.mall.product.vo.AttrResponseVo;
@ -10,6 +11,7 @@ import com.xjs.utils.PageUtils;
import com.xjs.mall.other.R;
import com.xjs.validation.group.AddGroup;
import com.xjs.validation.group.UpdateGroup;
import com.xjs.web.MyBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,7 +33,7 @@ import java.util.Map;
@RestController
@RequestMapping("product/attr")
@Api(tags = "商城-商品-规格参数")
public class AttrController {
public class AttrController extends MyBaseController<AttrEntity> {
@Autowired
private AttrService attrService;
@ -50,6 +52,7 @@ public class AttrController {
public R baseAttrList(@RequestParam Map<String, Object> params,
@PathVariable("attrType") String attrType,
@PathVariable("catelogId") Long catelogId) {
super.checkParams(params);
PageUtils page = attrService.queryBaseAttrPage(params, catelogId, attrType);
return R.ok().put("page", page);
}

@ -14,6 +14,7 @@ import com.xjs.utils.PageUtils;
import com.xjs.mall.other.R;
import com.xjs.validation.group.AddGroup;
import com.xjs.validation.group.UpdateGroup;
import com.xjs.web.MyBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -36,7 +37,7 @@ import java.util.stream.Collectors;
@RestController
@RequestMapping("product/attrgroup")
@Api(tags = "商城-商品-属性分组")
public class AttrGroupController {
public class AttrGroupController extends MyBaseController<AttrGroupEntity> {
@Autowired
private AttrGroupService attrGroupService;
@Autowired
@ -95,7 +96,7 @@ public class AttrGroupController {
@GetMapping("/list/{catelogId}")
@ApiOperation("列表")
public R list(@RequestParam Map<String, Object> params, Long catelogId) {
super.checkParams(params);
PageUtils page = attrGroupService.queryPage(params, catelogId);
return R.ok().put("page", page);

@ -9,6 +9,7 @@ import com.xjs.mall.other.R;
import com.xjs.validation.group.AddGroup;
import com.xjs.validation.group.SelectGroup;
import com.xjs.validation.group.UpdateGroup;
import com.xjs.web.MyBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -30,7 +31,7 @@ import java.util.Map;
@RestController
@RequestMapping("product/brand")
@Api(tags = "商城-商品-品牌")
public class BrandController {
public class BrandController extends MyBaseController<BrandEntity> {
@Autowired
private BrandService brandService;
@ -40,6 +41,7 @@ public class BrandController {
@GetMapping("/list")
@ApiOperation("列表")
public R list(@Validated(SelectGroup.class) @RequestParam Map<String, Object> params){
super.checkParams(params);
PageUtils page = brandService.queryPage(params);
return R.ok().put("page", page);

@ -4,7 +4,9 @@ import com.xjs.mall.product.entity.SkuInfoEntity;
import com.xjs.mall.product.service.SkuInfoService;
import com.xjs.utils.PageUtils;
import com.xjs.mall.other.R;
import com.xjs.web.MyBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -23,7 +25,7 @@ import java.util.Map;
@RestController
@RequestMapping("product/skuinfo")
@Api(tags = "商城-商品-SKU信息")
public class SkuInfoController {
public class SkuInfoController extends MyBaseController<SkuInfoEntity> {
@Autowired
private SkuInfoService skuInfoService;
@ -31,8 +33,10 @@ public class SkuInfoController {
*
*/
@RequestMapping("/list")
@ApiOperation("列表")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = skuInfoService.queryPage(params);
super.checkParams(params);
PageUtils page = skuInfoService.queryPageByCondition(params);
return R.ok().put("page", page);
}

@ -6,6 +6,7 @@ import com.xjs.mall.product.service.SpuInfoService;
import com.xjs.mall.product.vo.spu.SpuSaveVo;
import com.xjs.utils.PageUtils;
import com.xjs.validation.group.AddGroup;
import com.xjs.web.MyBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -26,7 +27,7 @@ import java.util.Map;
@RestController
@RequestMapping("product/spuinfo")
@Api(tags = "商城-商品-SPU信息")
public class SpuInfoController {
public class SpuInfoController extends MyBaseController<SpuInfoEntity> {
@Autowired
private SpuInfoService spuInfoService;
@ -36,6 +37,7 @@ public class SpuInfoController {
@RequestMapping("/list")
@ApiOperation("列表")
public R list(@RequestParam Map<String, Object> params) {
super.checkParams(params);
PageUtils page = spuInfoService.queryPageByCondition(params);
return R.ok().put("page", page);

@ -15,12 +15,18 @@ import java.util.Map;
*/
public interface SkuInfoService extends IService<SkuInfoEntity> {
PageUtils queryPage(Map<String, Object> params);
/**
* sku
* @param skuInfoEntity sku
*/
void saveSkuInfo(SkuInfoEntity skuInfoEntity);
/**
*
* @param params
* @return page
*/
PageUtils queryPageByCondition(Map<String, Object> params);
}

@ -1,34 +1,93 @@
package com.xjs.mall.product.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.StringUtils;
import com.xjs.mall.product.dao.SkuInfoDao;
import com.xjs.mall.product.entity.BrandEntity;
import com.xjs.mall.product.entity.CategoryEntity;
import com.xjs.mall.product.entity.SkuInfoEntity;
import com.xjs.mall.product.entity.SpuInfoEntity;
import com.xjs.mall.product.service.BrandService;
import com.xjs.mall.product.service.CategoryService;
import com.xjs.mall.product.service.SkuInfoService;
import com.xjs.mall.product.service.SpuInfoService;
import com.xjs.mall.product.vo.spu.SkuInfoVo;
import com.xjs.utils.PageUtils;
import com.xjs.utils.Query;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service("skuInfoService")
public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> implements SkuInfoService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<SkuInfoEntity> page = this.page(
new Query<SkuInfoEntity>().getPage(params),
new QueryWrapper<SkuInfoEntity>()
);
return new PageUtils(page);
}
@Autowired
private SpuInfoService spuInfoService;
@Autowired
private CategoryService categoryService;
@Autowired
private BrandService brandService;
@Override
public void saveSkuInfo(SkuInfoEntity skuInfoEntity) {
super.baseMapper.insert(skuInfoEntity);
}
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
LambdaQueryWrapper<SkuInfoEntity> wrapper = new LambdaQueryWrapper<>();
String key = (String) params.get(Query.KEY_NAME);
String brandId = (String) params.get("brandId");
String catelogId = (String) params.get("catelogId");
String min = (String) params.get("min");
String max = (String) params.get("max");
wrapper.and(StringUtils.isNotEmpty(key), wr -> {
wr.like(SkuInfoEntity::getSkuName, key).or()
.like(SkuInfoEntity::getSkuDesc, key).or()
.like(SkuInfoEntity::getSkuTitle, key).or()
.like(SkuInfoEntity::getSkuSubtitle, key);
})
.eq(StringUtils.isNotEmpty(brandId) && !"0".equalsIgnoreCase(brandId), SkuInfoEntity::getBrandId, brandId)
.eq(StringUtils.isNotEmpty(catelogId) && !"0".equalsIgnoreCase(catelogId), SkuInfoEntity::getCatalogId, catelogId)
.ge(StringUtils.isNotEmpty(min) && !"0".equalsIgnoreCase(min), SkuInfoEntity::getPrice, min)
.le(StringUtils.isNotEmpty(max) && !"0".equalsIgnoreCase(max), SkuInfoEntity::getPrice, max)
.orderByDesc(SkuInfoEntity::getSkuId);
IPage<SkuInfoEntity> page = this.page(new Query<SkuInfoEntity>().getPage(params), wrapper);
List<SkuInfoEntity> records = page.getRecords();
List<SkuInfoVo> collect = records.stream().map(skuInfoEntity -> {
SkuInfoVo skuInfoVo = new SkuInfoVo();
BeanUtils.copyProperties(skuInfoEntity, skuInfoVo);
//获取spu信息
SpuInfoEntity spuInfoEntity = spuInfoService.getById(skuInfoVo.getSpuId());
skuInfoVo.setSpuName(spuInfoEntity.getSpuName());
//获取三级分类信息
CategoryEntity categoryEntity = categoryService.getById(skuInfoVo.getCatalogId());
skuInfoVo.setCatalogName(categoryEntity.getName());
//获取品牌信息
BrandEntity brandEntity = brandService.getById(skuInfoVo.getBrandId());
skuInfoVo.setBrandName(brandEntity.getName());
return skuInfoVo;
}).collect(Collectors.toList());
PageUtils pageUtils = new PageUtils(page);
pageUtils.setList(collect);
return pageUtils;
}
}

@ -107,6 +107,7 @@ public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> i
skuInfoEntity.setSaleCount(0L); //销量默认0
skuInfoEntity.setSpuId(spuInfoEntity.getId());
skuInfoEntity.setSkuDefaultImg(defaultImg);
skuInfoEntity.setSkuDesc(spuInfoEntity.getSpuDescription());
skuInfoService.saveSkuInfo(skuInfoEntity);
//---------------------------------------------------------------------------------------------------------

@ -0,0 +1,70 @@
package com.xjs.mall.product.vo.spu;
import lombok.Data;
import java.math.BigDecimal;
/**
* skuvo
* @author xiejs
* @since 2022-03-21
*/
@Data
public class SkuInfoVo {
private Long skuId;
/**
* spuId
*/
private Long spuId;
/**
* sku
*/
private String skuName;
/**
* sku
*/
private String skuDesc;
/**
* id
*/
private Long catalogId;
/**
* id
*/
private Long brandId;
/**
*
*/
private String skuDefaultImg;
/**
*
*/
private String skuTitle;
/**
*
*/
private String skuSubtitle;
/**
*
*/
private BigDecimal price;
/**
*
*/
private Long saleCount;
/**
*
*/
private String catalogName;
/**
* spu
*/
private String spuName;
/**
*
*/
private String brandName;
}
Loading…
Cancel
Save