修复了商品规格参数和销售属性混乱的bug

develop
ddyd 1 week ago
parent b3c35ce403
commit 7c7d2ef980

@ -11,6 +11,7 @@ import com.bookstore.bookmall.product.service.AttrAttrgroupRelationService;
import com.bookstore.bookmall.product.service.AttrService;
import com.bookstore.bookmall.product.service.CategoryService;
import com.bookstore.bookmall.product.vo.AttrGroupRelationVo;
import com.bookstore.bookmall.product.vo.AttrGroupWithAttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -40,6 +41,18 @@ public class AttrGroupController {
@Autowired
private AttrAttrgroupRelationService relationService;
// /product/categroup/{catelogId}/withattr
@GetMapping("/{catelogId}/withattr")
public R getAttrGroupWithAttrs(@PathVariable("catelogId") Long catelogId){
//查出当前分类下所有属性分组
//查出分类下所有分组的所有关联属性
List<AttrGroupWithAttrVo> vos = attrGroupService.getAttrGroupWithAttrsByCatelogId(catelogId);
return R.ok().put("data", vos);
}
//添加关联属性
///product/attrgroup/attr/relation
@PostMapping("/attr/relation")

@ -3,9 +3,13 @@ package com.bookstore.bookmall.product.controller;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bookstore.bookmall.product.entity.BrandEntity;
import com.bookstore.bookmall.product.vo.BrandVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -29,6 +33,25 @@ public class CategoryBrandRelationController {
@Autowired
private CategoryBrandRelationService categoryBrandRelationService;
//1、Controller处理请求接受和校验数据
//2、Service接受controller传来的数据业务处理
//3、Controller接受service处理完的数据封装为页面指定的vo
// /product/categorybrandrelation/brands/list
@GetMapping("/brands/list")
public R relationBrandsList(@RequestParam(value = "catId", required = true) Long catId) {
List<BrandEntity> brandEntities = categoryBrandRelationService.getBrandsByCatId(catId);
List<BrandVo> collect = brandEntities.stream().map((entity) -> {
BrandVo brandVo = new BrandVo();
brandVo.setBrandId(entity.getBrandId());
brandVo.setBrandName(entity.getName());
return brandVo;
}).collect(Collectors.toList());
return R.ok().put("data", collect);
}
/**
*
*/

@ -2,9 +2,11 @@ package com.bookstore.bookmall.product.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bookstore.bookmall.product.vo.AttrGroupRelationVo;
import com.bookstore.bookmall.product.vo.AttrGroupWithAttrVo;
import com.bookstore.common.utils.PageUtils;
import com.bookstore.bookmall.product.entity.AttrGroupEntity;
import java.util.List;
import java.util.Map;
/**
@ -21,5 +23,7 @@ public interface AttrGroupService extends IService<AttrGroupEntity> {
PageUtils querypage(Map<String, Object> params, Long catelogId);
void deleteRelation(AttrGroupRelationVo[] vos);
List<AttrGroupWithAttrVo> getAttrGroupWithAttrsByCatelogId(Long catelogId);
}

@ -1,9 +1,11 @@
package com.bookstore.bookmall.product.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bookstore.bookmall.product.entity.BrandEntity;
import com.bookstore.common.utils.PageUtils;
import com.bookstore.bookmall.product.entity.CategoryBrandRelationEntity;
import java.util.List;
import java.util.Map;
/**
@ -18,5 +20,7 @@ public interface CategoryBrandRelationService extends IService<CategoryBrandRela
PageUtils queryPage(Map<String, Object> params);
void saveDetail(CategoryBrandRelationEntity categoryBrandRelation);
List<BrandEntity> getBrandsByCatId(Long catId);
}

@ -3,12 +3,16 @@ package com.bookstore.bookmall.product.service.impl;
import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.internal.StringUtil;
import com.bookstore.bookmall.product.dao.AttrAttrgroupRelationDao;
import com.bookstore.bookmall.product.entity.AttrAttrgroupRelationEntity;
import com.bookstore.bookmall.product.entity.AttrEntity;
import com.bookstore.bookmall.product.service.AttrService;
import com.bookstore.bookmall.product.vo.AttrGroupRelationVo;
import com.bookstore.bookmall.product.vo.AttrGroupWithAttrVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -31,6 +35,9 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEnt
@Autowired
AttrAttrgroupRelationDao RelationDao;
@Autowired
AttrService attrService;
@Override
public PageUtils queryPage(Map<String, Object> params) {
@ -88,4 +95,32 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEnt
RelationDao.deleteBatchRelation(entities);// 传入AttrAttrgroupRelationEntitys
}
/*
* @Description: id
* @param:
* @return:
* @Author:
* @date:
*/
@Override
public List<AttrGroupWithAttrVo> getAttrGroupWithAttrsByCatelogId(Long catelogId) {
//查询分类下所有分组
List<AttrGroupEntity> groupEntities = this.list(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId));
//查询分组的所有属性
List<AttrGroupWithAttrVo> collect = groupEntities.stream().map((entity) -> {
//基本属性
AttrGroupWithAttrVo attrVo = new AttrGroupWithAttrVo();
BeanUtils.copyProperties(entity, attrVo);
//分组下所有属性集合
List<AttrEntity> relationAttrs = attrService.getRelationAttr(attrVo.getAttrGroupId());
relationAttrs = (relationAttrs == null) ? new ArrayList<>() : relationAttrs;
attrVo.setAttrs(relationAttrs);
return attrVo;
}).collect(Collectors.toList());
return collect;
}
}

@ -18,9 +18,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -77,9 +79,9 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
//后台管理,查询基本内容和关联分组和关联属性
@Override
public PageUtils queryBasePage(Map<String, Object> params, Long cateLogId, String attrType) {
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>();
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>().eq("attr_type", "base".equalsIgnoreCase(attrType)?1:0);
if (cateLogId != 0) {
wrapper.eq("catelog_id", cateLogId).eq("attr_name", "base".equalsIgnoreCase(attrType)?1:0);
wrapper.eq("catelog_id", cateLogId);
}
String key = (String)params.get("key");
if (!StringUtils.isNullOrEmpty(key)) {
@ -127,15 +129,14 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
// log.info("查询属性attrId: {}", attrId);
AttrRespVo respVo = new AttrRespVo();
AttrEntity attrEntity = this.getById(attrId);
BeanUtils.copyProperties(attrEntity, respVo);
//如果是base
if (attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
//设置分组id
BeanUtils.copyProperties(attrEntity, respVo);
// log.info("beanutilzhengchang");
AttrAttrgroupRelationEntity RelationEntity = RelationDao.selectOne(
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrId));
if (RelationEntity!=null) {
// log.info("查询属性relation正常");
respVo.setAttrGroupId(RelationEntity.getAttrGroupId());
@ -234,7 +235,11 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
}).collect(Collectors.toList());
//这些分组的属性
List<AttrAttrgroupRelationEntity> relationEntities = RelationDao.selectList(
new QueryWrapper<AttrAttrgroupRelationEntity>().in("attr_group_id", collect));
new QueryWrapper<AttrAttrgroupRelationEntity>()
.in("attr_group_id", collect.isEmpty() ?
Collections.singletonList(attrgroupId) :
Stream.concat(collect.stream(), Stream.of(attrgroupId)).collect(Collectors.toList())));
List<Long> attrIds = relationEntities.stream().map((entity) -> {
return entity.getAttrId();
}).collect(Collectors.toList());
@ -243,6 +248,9 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
//条件
QueryWrapper<AttrEntity> queryWrapper = new QueryWrapper<AttrEntity>().eq("catelog_id", catelogId).eq(
"attr_type",ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode() );
if (attrIds !=null && attrIds.size() > 0) {
queryWrapper.notIn("attr_id", attrIds);
}
//关键字查找
String key = (String) params.get("key");
if (!StringUtils.isNullOrEmpty(key)) {
@ -250,9 +258,7 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
wrapper.eq("attr_id", key).or().like("attr_name", key);
});
}
if (attrIds !=null && attrIds.size() > 0) {
queryWrapper.notIn("attr_id", attrIds);
}
//分页查询
IPage<AttrEntity> page = this.page(new Query<AttrEntity>().getPage(params), queryWrapper);

@ -4,9 +4,14 @@ import com.bookstore.bookmall.product.dao.BrandDao;
import com.bookstore.bookmall.product.dao.CategoryDao;
import com.bookstore.bookmall.product.entity.BrandEntity;
import com.bookstore.bookmall.product.entity.CategoryEntity;
import com.bookstore.bookmall.product.service.BrandService;
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;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -25,6 +30,12 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandR
BrandDao brandDao;
@Autowired
CategoryDao categoryDao;
@Autowired
CategoryBrandRelationDao RelationDao;
//别的业务用sevice
@Autowired
BrandService brandService;
@Override
public PageUtils queryPage(Map<String, Object> params) {
@ -51,4 +62,16 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandR
this.save(categoryBrandRelation);
}
@Override
public List<BrandEntity> getBrandsByCatId(Long catId) {
List<CategoryBrandRelationEntity> catelogId = RelationDao.selectList(new QueryWrapper<CategoryBrandRelationEntity>().eq("catelog_id", catId));
List<BrandEntity> collect = catelogId.stream().map((item) -> {
Long brandId = item.getBrandId();
BrandEntity byId = brandService.getById(brandId);
return byId;
}).collect(Collectors.toList());
return collect;
}
}

@ -0,0 +1,45 @@
package com.bookstore.bookmall.product.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.bookstore.bookmall.product.entity.AttrEntity;
import lombok.Data;
import java.util.List;
@Data
public class AttrGroupWithAttrVo {
/**
* id
*/
@TableId
private Long attrGroupId;
/**
*
*/
private String attrGroupName;
/**
*
*/
private Integer sort;
/**
*
*/
private String descript;
/**
*
*/
private String icon;
/**
* id
*/
private Long catelogId;
private Long[] catelogPath;
private List<AttrEntity> attrs;
}

@ -0,0 +1,14 @@
package com.bookstore.bookmall.product.vo;
import lombok.Data;
@Data
public class BrandVo {
/*
"brandId": 0,
"brandName": "string"
* */
private Long brandId;
private String brandName;
}

@ -16831,6 +16831,11 @@
"safe-buffer": "^5.1.2"
}
},
"pubsub-js": {
"version": "1.9.5",
"resolved": "https://registry.npmjs.org/pubsub-js/-/pubsub-js-1.9.5.tgz",
"integrity": "sha512-5MZ0I9i5JWVO7SizvOviKvZU2qaBbl2KQX150FAA+fJBwYpwOUId7aNygURWSdPzlsA/xZ/InUKXqBbzM0czTA=="
},
"pump": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/pump/-/pump-2.0.1.tgz",

@ -26,6 +26,7 @@
"lodash": "4.17.5",
"node-sass": "^6.0.1",
"npm": "^6.9.0",
"pubsub-js": "^1.9.5",
"sass-loader": "6.0.6",
"svg-sprite-loader": "3.7.3",
"vue": "2.5.16",

@ -1,7 +1,7 @@
<template>
<div>
<el-upload
action="http://gulimall-hello.oss-cn-beijing.aliyuncs.com"
action="https://huishuohuademao-mall.oss-cn-wuhan-lr.aliyuncs.com"
:data="dataObj"
:list-type="listType"
:file-list="fileList"

@ -10,7 +10,9 @@ import '@/assets/scss/index.scss'
import httpRequest from '@/utils/httpRequest' // api: https://github.com/axios/axios
import { isAuth } from '@/utils'
import cloneDeep from 'lodash/cloneDeep'
import PubSub from 'pubsub-js'
Vue.prototype.PubSub = PubSub
Vue.use(VueCookie)
Vue.config.productionTip = false

@ -127,9 +127,10 @@
type="hidden"
v-show="false"
></el-input>
<el-checkbox-group v-model="dataResp.tempSaleAttrs[aidx].attrValues">
<el-checkbox-group
v-model="dataResp.tempSaleAttrs[aidx].attrValues"
v-if="dataResp.saleAttrs[aidx].valueSelect != ''">
<el-checkbox
v-if="dataResp.saleAttrs[aidx].valueSelect != ''"
:label="val"
v-for="val in dataResp.saleAttrs[aidx].valueSelect.split(';')"
:key="val"
@ -676,6 +677,7 @@ export default {
//baseAttrs
data.data.forEach(item => {
let attrArray = [];
const attrs = Array.isArray(item.attrs) ? item.attrs : [];
item.attrs.forEach(attr => {
attrArray.push({
attrId: attr.attrId,
@ -802,6 +804,4 @@ export default {
destroyed() {}, // - 
activated() {} //keep-alive
};
</script>
<style scoped>
</style>
</script>
Loading…
Cancel
Save