From d75497c7bcb8bf2a99d8d51c2a0cf26a2a5eeb7f Mon Sep 17 00:00:00 2001
From: xjs <1294405880@qq.com>
Date: Fri, 18 Mar 2022 17:23:15 +0800
Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=B1=9E=E6=80=A7=E5=88=86=E7=BB=84?=
=?UTF-8?q?=E5=85=B3=E8=81=94=E6=93=8D=E4=BD=9Ccrud=E5=AE=9E=E7=8E=B0=202?=
=?UTF-8?q?=E3=80=81=E9=94=80=E5=94=AE=E5=B1=9E=E6=80=A7=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?=E5=8F=8A=E9=A1=B5=E9=9D=A2=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ruoyi-ui/src/api/mall/product/attr-group.js | 40 ++-
ruoyi-ui/src/api/mall/product/attr.js | 14 +-
.../business/webmagic/weixincrawler/index.vue | 6 +-
.../product/attribute/attr-add-or-update.vue | 4 +-
.../product/attribute/attr-group-relation.vue | 228 ++++++++++++++++++
.../mall/product/attribute/attr-group.vue | 8 +-
.../mall/product/attribute/base-attr.vue | 16 +-
.../mall/product/attribute/sale-attr.vue | 32 +++
.../product/controller/AttrController.java | 19 +-
.../controller/AttrGroupController.java | 39 +++
.../mall/product/entity/AttrGroupEntity.java | 3 +-
.../service/AttrAttrgroupRelationService.java | 8 +
.../xjs/mall/product/service/AttrService.java | 32 ++-
.../AttrAttrgroupRelationServiceImpl.java | 14 ++
.../product/service/impl/AttrServiceImpl.java | 118 +++++++--
.../mall/product/vo/AttrGroupRelationVo.java | 23 ++
16 files changed, 554 insertions(+), 50 deletions(-)
create mode 100644 ruoyi-ui/src/views/mall/product/attribute/attr-group-relation.vue
create mode 100644 ruoyi-ui/src/views/mall/product/attribute/sale-attr.vue
create mode 100644 xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/vo/AttrGroupRelationVo.java
diff --git a/ruoyi-ui/src/api/mall/product/attr-group.js b/ruoyi-ui/src/api/mall/product/attr-group.js
index 52f6d430..ec2edfed 100644
--- a/ruoyi-ui/src/api/mall/product/attr-group.js
+++ b/ruoyi-ui/src/api/mall/product/attr-group.js
@@ -3,9 +3,9 @@ import request from '@/utils/request'
// 获取品牌分组分页数据
export function getAttrGroupList(data) {
return request({
- url: '/mall-product/product/attrgroup/list/'+data.catelogId,
+ url: '/mall-product/product/attrgroup/list/' + data.catelogId,
method: 'get',
- params:data
+ params: data
})
}
@@ -22,7 +22,7 @@ export function addAttrGroup(data) {
return request({
url: `/mall-product/product/attrgroup/save`,
method: 'post',
- data:data
+ data: data
})
}
@@ -31,7 +31,7 @@ export function editAttrGroup(data) {
return request({
url: `/mall-product/product/attrgroup/update`,
method: 'put',
- data:data
+ data: data
})
}
@@ -40,6 +40,38 @@ export function delAttrGroup(ids) {
return request({
url: '/mall-product/product/attrgroup/delete',
method: 'delete',
+ data: ids
+ })
+}
+
+// 获取属性分组关联规格参数
+export function attrRelation(attrgroupId) {
+ return request({
+ url: `/mall-product/product/attrgroup/${attrgroupId}/attr/relation`,
+ method: 'get',
+ })
+}
+
+//获取当前分组没有关联的所有属性
+export function attrNoRelation(attrgroupId,parms) {
+ return request({
+ url: `/mall-product/product/attrgroup/${attrgroupId}/noattr/relation`,
+ method: 'get',
+ parms:parms
+ })
+}
+
+//批量保存属性和属性分组关联信息
+export function addRelation(ids) {
+ return request({
+ url: `/mall-product/product/attrgroup/attr/relation`,
+ method: 'post',
data:ids
})
}
+
+
+
+
+
+
diff --git a/ruoyi-ui/src/api/mall/product/attr.js b/ruoyi-ui/src/api/mall/product/attr.js
index d60ed17e..757bc0c4 100644
--- a/ruoyi-ui/src/api/mall/product/attr.js
+++ b/ruoyi-ui/src/api/mall/product/attr.js
@@ -19,9 +19,9 @@ export function editAttr(data) {
}
// 分页获取规格参数
-export function getBaseAttrList(parms,catelogId) {
+export function getBaseAttrList(parms,catelogId,attrType) {
return request({
- url: `/mall-product/product/attr/base/list/${catelogId}`,
+ url: `/mall-product/product/attr/${attrType}/list/${catelogId}`,
method: 'get',
params:parms
})
@@ -43,3 +43,13 @@ export function getAttr(attrId) {
method: 'get',
})
}
+
+// 删除属性及分组关联
+export function deleteRelation(ids) {
+ return request({
+ url: `/mall-product/product/attr/relation/delete`,
+ method: 'delete',
+ data:ids
+ })
+}
+
diff --git a/ruoyi-ui/src/views/business/webmagic/weixincrawler/index.vue b/ruoyi-ui/src/views/business/webmagic/weixincrawler/index.vue
index f62e7ef4..ce85dd62 100644
--- a/ruoyi-ui/src/views/business/webmagic/weixincrawler/index.vue
+++ b/ruoyi-ui/src/views/business/webmagic/weixincrawler/index.vue
@@ -52,9 +52,9 @@
-
+
-
@@ -84,7 +84,7 @@ export default {
rules: {
path: [
- {required: true, message: '请输入下载图片路径路径', trigger: 'blur'}
+ {required: true, message: '请复制微信文章链接地址', trigger: 'blur'}
],
},
linkRules: {
diff --git a/ruoyi-ui/src/views/mall/product/attribute/attr-add-or-update.vue b/ruoyi-ui/src/views/mall/product/attribute/attr-add-or-update.vue
index 304b1170..8e30f920 100644
--- a/ruoyi-ui/src/views/mall/product/attribute/attr-add-or-update.vue
+++ b/ruoyi-ui/src/views/mall/product/attribute/attr-add-or-update.vue
@@ -12,8 +12,8 @@
-
-
+
+
diff --git a/ruoyi-ui/src/views/mall/product/attribute/attr-group-relation.vue b/ruoyi-ui/src/views/mall/product/attribute/attr-group-relation.vue
new file mode 100644
index 00000000..105b9f64
--- /dev/null
+++ b/ruoyi-ui/src/views/mall/product/attribute/attr-group-relation.vue
@@ -0,0 +1,228 @@
+
+
+
+
+
+
+
+
+
+
+ 查询
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ i }}
+
+ {{ scope.row.valueSelect.split(";")[0] + " ..." }}
+
+
+
+
+
+
+
+
+
+
+
+
+ 新建关联
+ 批量删除
+
+
+
+
+
+
+
+
+
+ {{i}}
+
+
+
+ {{scope.row.valueSelect.split(";")[0]+" ..."}}
+
+
+
+
+
+ 移除
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ruoyi-ui/src/views/mall/product/attribute/attr-group.vue b/ruoyi-ui/src/views/mall/product/attribute/attr-group.vue
index 7733389e..531737d3 100644
--- a/ruoyi-ui/src/views/mall/product/attribute/attr-group.vue
+++ b/ruoyi-ui/src/views/mall/product/attribute/attr-group.vue
@@ -42,7 +42,7 @@
-
+
@@ -78,7 +78,7 @@
-
+
@@ -98,10 +98,10 @@ import Category from '../../../components/mall/category'
import {getAttrGroupList, delAttrGroup} from "@/api/mall/product/attr-group";
import AddOrUpdate from "./attrgroup-add-or-update";
-// import RelationUpdate from "./attr-group-relation";
+import RelationUpdate from "./attr-group-relation";
export default {
- components: {Category, AddOrUpdate, /*RelationUpdate*/},
+ components: {Category, AddOrUpdate, RelationUpdate},
props: {},
data() {
return {
diff --git a/ruoyi-ui/src/views/mall/product/attribute/base-attr.vue b/ruoyi-ui/src/views/mall/product/attribute/base-attr.vue
index dc4f1008..854602f5 100644
--- a/ruoyi-ui/src/views/mall/product/attribute/base-attr.vue
+++ b/ruoyi-ui/src/views/mall/product/attribute/base-attr.vue
@@ -58,12 +58,12 @@
-
+
-
+
{{ i }}
@@ -180,10 +180,16 @@ export default {
key: this.dataForm.key
}
if (this.attrtype === 0) {
- // todo sale
+ let type = "sale"
+ getBaseAttrList(params, this.catId, type).then(res => {
+ this.dataList = res.page.list;
+ this.totalPage = res.page.totalCount;
+ this.dataListLoading = false;
+ })
- } else {
- getBaseAttrList(params, this.catId).then(res => {
+ } else if (this.attrtype === 1) {
+ let type = "base"
+ getBaseAttrList(params, this.catId, type).then(res => {
this.dataList = res.page.list;
this.totalPage = res.page.totalCount;
this.dataListLoading = false;
diff --git a/ruoyi-ui/src/views/mall/product/attribute/sale-attr.vue b/ruoyi-ui/src/views/mall/product/attribute/sale-attr.vue
new file mode 100644
index 00000000..e00e084c
--- /dev/null
+++ b/ruoyi-ui/src/views/mall/product/attribute/sale-attr.vue
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrController.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrController.java
index b56e6050..71e70776 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrController.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrController.java
@@ -3,6 +3,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.service.AttrService;
+import com.xjs.mall.product.vo.AttrGroupRelationVo;
import com.xjs.mall.product.vo.AttrResponseVo;
import com.xjs.mall.product.vo.AttrVo;
import com.xjs.utils.PageUtils;
@@ -16,6 +17,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
+import java.util.List;
import java.util.Map;
@@ -34,10 +36,21 @@ public class AttrController {
private AttrService attrService;
- @GetMapping("/base/list/{catelogId}")
+ @DeleteMapping("relation/delete")
+ @ApiOperation("删除属性及分组关联")
+ public R deleteRelation(@RequestBody List vos) {
+ attrService.deleteRelation(vos);
+
+ return R.ok();
+ }
+
+
+ @GetMapping("/{attrType}/list/{catelogId}")
@ApiOperation("列表")
- public R baseAttrList(@RequestParam Map params, @PathVariable("catelogId") Long catelogId) {
- PageUtils page = attrService.queryBaseAttrPage(params, catelogId);
+ public R baseAttrList(@RequestParam Map params,
+ @PathVariable("attrType") String attrType,
+ @PathVariable("catelogId") Long catelogId) {
+ PageUtils page = attrService.queryBaseAttrPage(params, catelogId, attrType);
return R.ok().put("page", page);
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrGroupController.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrGroupController.java
index 3c4e3764..20bf1bea 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrGroupController.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrGroupController.java
@@ -2,9 +2,13 @@ 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.entity.AttrGroupEntity;
+import com.xjs.mall.product.service.AttrAttrgroupRelationService;
import com.xjs.mall.product.service.AttrGroupService;
+import com.xjs.mall.product.service.AttrService;
import com.xjs.mall.product.service.CategoryService;
+import com.xjs.mall.product.vo.AttrGroupRelationVo;
import com.xjs.utils.PageUtils;
import com.xjs.utils.R;
import com.xjs.validation.group.AddGroup;
@@ -36,6 +40,41 @@ public class AttrGroupController {
private AttrGroupService attrGroupService;
@Autowired
private CategoryService categoryService;
+ @Autowired
+ private AttrService attrService;
+ @Autowired
+ private AttrAttrgroupRelationService attrAttrgroupRelationService;
+
+ /**
+ * 获取关联信息
+ *
+ * @param attrgroupId 属性分组id
+ * @return r
+ */
+ @GetMapping("/{attrgroupId}/attr/relation")
+ public R attrRelation(@PathVariable("attrgroupId") Long attrgroupId) {
+ List attrList = attrService.getRelationAttr(attrgroupId);
+ return R.ok().put("data", attrList);
+ }
+
+ /**
+ * 获取未被关联的信息
+ * @param attrgroupId 属性分组id
+ * @param params 条件
+ * @return R
+ */
+ @GetMapping("/{attrgroupId}/noattr/relation")
+ public R attrNoRelation(@PathVariable("attrgroupId") Long attrgroupId, @RequestParam Map params) {
+ PageUtils page=attrService.getAttrNoRelation(params, attrgroupId);
+ return R.ok().put("page", page);
+ }
+
+ @PostMapping("/attr/relation")
+ public R addRelation(@RequestBody List vos) {
+
+ attrAttrgroupRelationService.saveBatch(vos);
+ return R.ok();
+ }
/**
* 列表
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/AttrGroupEntity.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/AttrGroupEntity.java
index b68028e7..45bb6aa9 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/AttrGroupEntity.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/AttrGroupEntity.java
@@ -8,6 +8,7 @@ import com.xjs.validation.group.UpdateGroup;
import lombok.Data;
import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;
@@ -53,7 +54,7 @@ public class AttrGroupEntity implements Serializable {
/**
* 所属分类id
*/
- @NotBlank(message = "所属分类id不能为空", groups = {UpdateGroup.class, AddGroup.class})
+ @NotNull(message = "所属分类id不能为空", groups = {UpdateGroup.class, AddGroup.class})
private Long catelogId;
/**
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrAttrgroupRelationService.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrAttrgroupRelationService.java
index 9e785f0d..74867860 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrAttrgroupRelationService.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrAttrgroupRelationService.java
@@ -2,6 +2,9 @@ package com.xjs.mall.product.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity;
+import com.xjs.mall.product.vo.AttrGroupRelationVo;
+
+import java.util.List;
/**
* 属性&属性分组关联
@@ -12,5 +15,10 @@ import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity;
*/
public interface AttrAttrgroupRelationService extends IService {
+ /**
+ * 批量保存属性和属性分组关联信息
+ * @param vos ids
+ */
+ void saveBatch(List vos);
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrService.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrService.java
index 89a2ef2f..15e2af6a 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrService.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrService.java
@@ -1,6 +1,7 @@
package com.xjs.mall.product.service;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.xjs.mall.product.vo.AttrGroupRelationVo;
import com.xjs.mall.product.vo.AttrResponseVo;
import com.xjs.mall.product.vo.AttrVo;
import com.xjs.utils.PageUtils;
@@ -20,20 +21,24 @@ public interface AttrService extends IService {
/**
* 保存
+ *
* @param attr 商品属性vo
*/
void saveAttr(AttrVo attr);
/**
* 查询基本的规格参数分页
- * @param params 条件
+ *
+ * @param params 条件
* @param catelogId 分类id
+ * @param attrType 接口类型 base/sale
* @return pageUtils
*/
- PageUtils queryBaseAttrPage(Map params, Long catelogId);
+ PageUtils queryBaseAttrPage(Map params, Long catelogId, String attrType);
/**
* 获取attr规格参数具体信息
+ *
* @param attrId attrId
* @return vo
*/
@@ -41,14 +46,37 @@ public interface AttrService extends IService {
/**
* 修改规格参数信息
+ *
* @param attr 实体类
*/
void updateAttr(AttrVo attr);
/**
* 删除规格参数及关联信息
+ *
* @param asList ids
*/
void removeAttr(List asList);
+
+ /**
+ * 根据分组id查找关联的所有基本树形(规格参数)
+ * @param attrgroupId 属性分组id
+ * @return attrs
+ */
+ List getRelationAttr(Long attrgroupId);
+
+ /**
+ * 删除属性及属性分组关联数据
+ * @param vos 关联id
+ */
+ void deleteRelation(List vos);
+
+ /**
+ * 获取当前分组没有关联的所有属性
+ * @param params 条件查询
+ * @param attrgroupId 分组id
+ * @return page
+ */
+ PageUtils getAttrNoRelation(Map params, Long attrgroupId);
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java
index 7a185ded..2450f012 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java
@@ -4,12 +4,26 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjs.mall.product.dao.AttrAttrgroupRelationDao;
import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity;
import com.xjs.mall.product.service.AttrAttrgroupRelationService;
+import com.xjs.mall.product.vo.AttrGroupRelationVo;
import org.springframework.stereotype.Service;
+import java.util.List;
+import java.util.stream.Collectors;
+
@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl implements AttrAttrgroupRelationService {
+ @Override
+ public void saveBatch(List vos) {
+ List collect = vos.stream().map(item -> {
+ AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
+ relationEntity.setAttrId(item.getAttrId());
+ relationEntity.setAttrGroupId(item.getAttrGroupId());
+ return relationEntity;
+ }).collect(Collectors.toList());
+ super.saveBatch(collect);
+ }
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrServiceImpl.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrServiceImpl.java
index 0726fc24..386cc979 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrServiceImpl.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrServiceImpl.java
@@ -1,11 +1,12 @@
package com.xjs.mall.product.service.impl;
+import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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.consts.ProductConstant;
import com.xjs.mall.product.dao.AttrAttrgroupRelationDao;
import com.xjs.mall.product.dao.AttrDao;
import com.xjs.mall.product.dao.AttrGroupDao;
@@ -17,6 +18,7 @@ import com.xjs.mall.product.entity.CategoryEntity;
import com.xjs.mall.product.service.AttrAttrgroupRelationService;
import com.xjs.mall.product.service.AttrService;
import com.xjs.mall.product.service.CategoryService;
+import com.xjs.mall.product.vo.AttrGroupRelationVo;
import com.xjs.mall.product.vo.AttrResponseVo;
import com.xjs.mall.product.vo.AttrVo;
import com.xjs.utils.PageUtils;
@@ -27,11 +29,15 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import static com.xjs.consts.ProductConstant.AttrEnum.ATTR_TYPE_BASE;
+import static com.xjs.consts.ProductConstant.AttrEnum.ATTR_TYPE_SALE;
+
@Service("attrService")
@Transactional
@@ -56,15 +62,18 @@ public class AttrServiceImpl extends ServiceImpl implements
super.save(attrEntity);
//保存关联关系
- AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity();
- attrAttrgroupRelationEntity.setAttrGroupId(attr.getAttrGroupId());
- attrAttrgroupRelationEntity.setAttrId(attrEntity.getAttrId());
- attrAttrgroupRelationService.save(attrAttrgroupRelationEntity);
+ if (attr.getAttrType() == ATTR_TYPE_BASE.getCode()) {
+ AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity();
+ attrAttrgroupRelationEntity.setAttrGroupId(attr.getAttrGroupId());
+ attrAttrgroupRelationEntity.setAttrId(attrEntity.getAttrId());
+ attrAttrgroupRelationService.save(attrAttrgroupRelationEntity);
+ }
}
@Override
- public PageUtils queryBaseAttrPage(Map params, Long catelogId) {
+ public PageUtils queryBaseAttrPage(Map params, Long catelogId, String attrType) {
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(AttrEntity::getAttrType, "base".equalsIgnoreCase(attrType) ? ATTR_TYPE_BASE.getCode() : ATTR_TYPE_SALE.getCode());
if (catelogId != 0) {
wrapper.eq(AttrEntity::getCatelogId, catelogId);
@@ -87,12 +96,14 @@ public class AttrServiceImpl extends ServiceImpl implements
BeanUtils.copyProperties(attrEntity, attrResponseVo);
//1、设置分类和分组的数据
- AttrAttrgroupRelationEntity attrId = attrAttrgroupRelationDao.selectOne(new LambdaQueryWrapper()
- .eq(AttrAttrgroupRelationEntity::getAttrId, attrEntity.getAttrId()));
-
- if (attrId != null) {
- AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrId.getAttrGroupId());
- attrResponseVo.setGroupName(attrGroupEntity.getAttrGroupName());
+ if ("base".equalsIgnoreCase(attrType)) {
+ AttrAttrgroupRelationEntity attrId = attrAttrgroupRelationDao.selectOne(new LambdaQueryWrapper()
+ .eq(AttrAttrgroupRelationEntity::getAttrId, attrEntity.getAttrId()));
+
+ if (attrId != null) {
+ AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrId.getAttrGroupId());
+ attrResponseVo.setGroupName(attrGroupEntity.getAttrGroupName());
+ }
}
CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
@@ -114,18 +125,19 @@ public class AttrServiceImpl extends ServiceImpl implements
AttrResponseVo attrResponseVo = new AttrResponseVo();
BeanUtils.copyProperties(attrEntity, attrResponseVo);
- //设置分组信息
- AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = attrAttrgroupRelationDao.selectOne(
- new LambdaQueryWrapper().eq(AttrAttrgroupRelationEntity::getAttrId, attrId)
- );
-
- if (attrAttrgroupRelationEntity != null) {
- attrResponseVo.setAttrGroupId(attrAttrgroupRelationEntity.getAttrGroupId());
+ if (attrEntity.getAttrType() == ATTR_TYPE_BASE.getCode()) {
+ //设置分组信息
+ AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = attrAttrgroupRelationDao.selectOne(
+ new LambdaQueryWrapper().eq(AttrAttrgroupRelationEntity::getAttrId, attrId)
+ );
+ if (attrAttrgroupRelationEntity != null) {
+ attrResponseVo.setAttrGroupId(attrAttrgroupRelationEntity.getAttrGroupId());
- AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrAttrgroupRelationEntity.getAttrGroupId());
+ AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrAttrgroupRelationEntity.getAttrGroupId());
- if (attrGroupEntity != null) {
- attrResponseVo.setGroupName(attrGroupEntity.getAttrGroupName());
+ if (attrGroupEntity != null) {
+ attrResponseVo.setGroupName(attrGroupEntity.getAttrGroupName());
+ }
}
}
@@ -148,7 +160,7 @@ public class AttrServiceImpl extends ServiceImpl implements
BeanUtils.copyProperties(attr, attrEntity);
this.updateById(attrEntity);
- if (attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
+ if (attrEntity.getAttrType() == ATTR_TYPE_BASE.getCode()) {
//1、修改分组关联
AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
@@ -176,8 +188,66 @@ public class AttrServiceImpl extends ServiceImpl implements
//级联删除中间表数据
for (Long id : asList) {
attrAttrgroupRelationService.remove(new LambdaUpdateWrapper()
- .eq(AttrAttrgroupRelationEntity::getAttrId,id));
+ .eq(AttrAttrgroupRelationEntity::getAttrId, id));
+ }
+ }
+
+ @Override
+ public List getRelationAttr(Long attrgroupId) {
+ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper()
+ .eq(AttrAttrgroupRelationEntity::getAttrGroupId, attrgroupId);
+ List entityList = attrAttrgroupRelationDao.selectList(queryWrapper);
+
+ List collect = entityList.stream().map(AttrAttrgroupRelationEntity::getAttrId).collect(Collectors.toList());
+
+ List attrEntities = new ArrayList<>();
+ if (CollUtil.isNotEmpty(collect)) {
+ attrEntities = super.listByIds(collect);
}
+ return attrEntities;
+ }
+
+ @Override
+ public void deleteRelation(List vos) {
+ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
+
+ //循环拼接条件
+ for (int i = 0; i < vos.size(); i++) {
+ int finalI = i;
+ queryWrapper.eq(AttrAttrgroupRelationEntity::getAttrId, vos.get(finalI).getAttrId()).and(obj -> {
+ obj.eq(AttrAttrgroupRelationEntity::getAttrGroupId, vos.get(finalI).getAttrGroupId());
+ }).or(i != vos.size() - 1);
+ }
+
+ attrAttrgroupRelationService.remove(queryWrapper);
+ }
+
+ @Override
+ public PageUtils getAttrNoRelation(Map params, Long attrgroupId) {
+ //1、当前分组只能关联自己所属的分类里面的所有属性
+ AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrgroupId);
+ Long catelogId = attrGroupEntity.getCatelogId();
+ //2、当前分组只能关联别的分组没有引用的属性
+ //2.1)、当前分类下的其他分组
+ List group = attrGroupDao.selectList(new QueryWrapper().eq("catelog_id", catelogId));
+ List collect = group.stream().map(AttrGroupEntity::getAttrGroupId).collect(Collectors.toList());
+
+ //2.2)、这些分组关联的属性
+ List groupId = attrAttrgroupRelationDao.selectList(new QueryWrapper().in("attr_group_id", collect));
+ List attrIds = groupId.stream().map(AttrAttrgroupRelationEntity::getAttrId).collect(Collectors.toList());
+
+ //2.3)、从当前分类的所有属性中移除这些属性;
+ QueryWrapper wrapper = new QueryWrapper().eq("catelog_id", catelogId).eq("attr_type", ATTR_TYPE_BASE.getCode());
+ if (CollUtil.isNotEmpty(attrIds)) {
+ wrapper.notIn("attr_id", attrIds);
+ }
+ String key = (String) params.get("key");
+ wrapper.and(StringUtils.isNotEmpty(key), (w) -> {
+ w.like("value_select", key).or().like("attr_name", key);
+ });
+ IPage page = this.page(new Query().getPage(params), wrapper);
+
+ return new PageUtils(page);
}
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/vo/AttrGroupRelationVo.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/vo/AttrGroupRelationVo.java
new file mode 100644
index 00000000..fb2eff6c
--- /dev/null
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/vo/AttrGroupRelationVo.java
@@ -0,0 +1,23 @@
+package com.xjs.mall.product.vo;
+
+import lombok.Data;
+
+/**
+ * 属性和属性分组vo
+ * @author xiejs
+ * @since 2022-03-18
+ */
+@Data
+public class AttrGroupRelationVo {
+
+ /**
+ * 属性id
+ */
+ private Long attrId;
+
+ /**
+ * 属性分组id
+ */
+ private Long attrGroupId;
+
+}