From 561024a5717533eb6664e07291c0d18ad351bfca Mon Sep 17 00:00:00 2001
From: xjs <1294405880@qq.com>
Date: Thu, 17 Mar 2022 11:05:02 +0800
Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=93=81=E7=89=8C=E5=92=8C=E5=88=86?=
=?UTF-8?q?=E7=B1=BB=E5=85=B3=E8=81=94=E5=AE=9E=E7=8E=B0=202=E3=80=81?=
=?UTF-8?q?=E7=BB=B4=E6=8A=A4=E5=93=81=E7=89=8C=E5=8F=8A=E5=88=86=E7=B1=BB?=
=?UTF-8?q?=E7=BA=A7=E8=81=94=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE=E4=B8=80=E8=87=B4=E6=80=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/api/mall/product/category-relation.js | 32 ++++++++
ruoyi-ui/src/views/mall/product/brand.vue | 79 ++++++++++---------
ruoyi-ui/src/views/mall/product/category.vue | 32 +++++++-
.../product/controller/BrandController.java | 2 +-
.../CategoryBrandRelationController.java | 71 ++++++++---------
.../controller/CategoryController.java | 2 +-
.../entity/CategoryBrandRelationEntity.java | 18 +++--
.../mall/product/service/BrandService.java | 6 ++
.../service/CategoryBrandRelationService.java | 26 ++++--
.../mall/product/service/CategoryService.java | 6 ++
.../service/impl/AttrGroupServiceImpl.java | 2 +
.../service/impl/BrandServiceImpl.java | 20 +++++
.../CategoryBrandRelationServiceImpl.java | 61 ++++++++++----
.../service/impl/CategoryServiceImpl.java | 18 ++++-
14 files changed, 268 insertions(+), 107 deletions(-)
create mode 100644 ruoyi-ui/src/api/mall/product/category-relation.js
diff --git a/ruoyi-ui/src/api/mall/product/category-relation.js b/ruoyi-ui/src/api/mall/product/category-relation.js
new file mode 100644
index 00000000..cd12a7e3
--- /dev/null
+++ b/ruoyi-ui/src/api/mall/product/category-relation.js
@@ -0,0 +1,32 @@
+import request from '@/utils/request'
+
+
+//添加品牌关联
+export function addCategoryBrandRelation(data) {
+ return request({
+ url: '/mall-product/product/categorybrandrelation/save',
+ method: 'post',
+ data:data
+ })
+}
+
+
+//删除品牌关联
+export function delCategoryBrandRelation(ids) {
+ return request({
+ url: '/mall-product/product/categorybrandrelation/delete',
+ method: 'delete',
+ data:ids
+ })
+}
+
+
+//获取品牌关联
+export function categoryBrandRelationList(data) {
+ return request({
+ url: '/mall-product/product/categorybrandrelation/catelog/list',
+ method: 'get',
+ params:data
+ })
+}
+
diff --git a/ruoyi-ui/src/views/mall/product/brand.vue b/ruoyi-ui/src/views/mall/product/brand.vue
index 95c8611d..2ca6dfe9 100644
--- a/ruoyi-ui/src/views/mall/product/brand.vue
+++ b/ruoyi-ui/src/views/mall/product/brand.vue
@@ -74,17 +74,18 @@
-
-
-
-
- 取消
- 确定
-
- 新增关联
-
+
+
+
+
+
+ 取消
+ 确定
+
+ 新增关联
+
+
-
@@ -109,7 +110,13 @@
diff --git a/ruoyi-ui/src/views/mall/product/category.vue b/ruoyi-ui/src/views/mall/product/category.vue
index b61e6756..8dd44f0d 100644
--- a/ruoyi-ui/src/views/mall/product/category.vue
+++ b/ruoyi-ui/src/views/mall/product/category.vue
@@ -10,7 +10,17 @@
+
+
+
params){
- PageUtils page = categoryBrandRelationService.queryPage(params);
-
- return R.ok().put("page", page);
- }
+ @GetMapping("/catelog/list")
+ @ApiOperation("列表")
+ public R list(@RequestParam Long brandId) {
+ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(CategoryBrandRelationEntity::getBrandId, brandId);
- /**
- * 信息
- */
- @RequestMapping("/info/{id}")
- public R info(@PathVariable("id") Long id){
- CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);
+ List list = categoryBrandRelationService.list(wrapper);
- return R.ok().put("categoryBrandRelation", categoryBrandRelation);
+ return R.ok().put("page", list);
}
+
/**
* 保存
*/
- @RequestMapping("/save")
- public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
- categoryBrandRelationService.save(categoryBrandRelation);
+ @PostMapping("/save")
+ @ApiOperation("保存")
+ @Log(title = "品牌分类关联", businessType = BusinessType.INSERT)
+ public R save(@Validated(AddGroup.class) @RequestBody CategoryBrandRelationEntity categoryBrandRelation) {
+ categoryBrandRelationService.saveDetail(categoryBrandRelation);
return R.ok();
}
- /**
- * 修改
- */
- @RequestMapping("/update")
- public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
- categoryBrandRelationService.updateById(categoryBrandRelation);
-
- return R.ok();
- }
/**
* 删除
*/
- @RequestMapping("/delete")
- public R delete(@RequestBody Long[] ids){
- categoryBrandRelationService.removeByIds(Arrays.asList(ids));
+ @DeleteMapping("/delete")
+ @ApiOperation("删除")
+ @Log(title = "品牌分类关联", businessType = BusinessType.DELETE)
+ public R delete(@RequestBody Long[] ids) {
+ categoryBrandRelationService.removeByIds(Arrays.asList(ids));
return R.ok();
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/CategoryController.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/CategoryController.java
index cf87f1ad..69db1ecd 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/CategoryController.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/CategoryController.java
@@ -74,7 +74,7 @@ public class CategoryController {
@ApiOperation("修改")
@Log(title = "商品分类", businessType = BusinessType.UPDATE)
public R update(@Validated(UpdateGroup.class) @RequestBody CategoryEntity category) {
- categoryService.updateById(category);
+ categoryService.updateCascade(category);
return R.ok();
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/CategoryBrandRelationEntity.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/CategoryBrandRelationEntity.java
index 5fbae0c6..e7fd6a3d 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/CategoryBrandRelationEntity.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/CategoryBrandRelationEntity.java
@@ -2,14 +2,16 @@ package com.xjs.mall.product.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
+import com.xjs.validation.group.AddGroup;
+import com.xjs.validation.group.UpdateGroup;
+import lombok.Data;
+import javax.validation.constraints.NotNull;
import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
/**
* 品牌分类关联
- *
+ *
* @author xiejs
* @email 1294405880@qq.com
* @date 2022-03-15 10:16:53
@@ -20,24 +22,28 @@ public class CategoryBrandRelationEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
- *
+ *
*/
@TableId
private Long id;
/**
* 品牌id
*/
+ @NotNull(groups = {AddGroup.class, UpdateGroup.class})
private Long brandId;
/**
* 分类id
*/
+ @NotNull(groups = {AddGroup.class, UpdateGroup.class})
private Long catelogId;
+
/**
- *
+ * 品牌名称
*/
private String brandName;
+
/**
- *
+ *分类名称
*/
private String catelogName;
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/BrandService.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/BrandService.java
index d3628f82..d4fabf7b 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/BrandService.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/BrandService.java
@@ -16,5 +16,11 @@ import java.util.Map;
public interface BrandService extends IService {
PageUtils queryPage(Map params);
+
+ /**
+ * 更新所有细节
+ * @param brand 品牌实体类
+ */
+ void updateDetail(BrandEntity brand);
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/CategoryBrandRelationService.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/CategoryBrandRelationService.java
index 842b70ff..9208e3ef 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/CategoryBrandRelationService.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/CategoryBrandRelationService.java
@@ -1,20 +1,36 @@
package com.xjs.mall.product.service;
import com.baomidou.mybatisplus.extension.service.IService;
-import com.xjs.utils.PageUtils;
import com.xjs.mall.product.entity.CategoryBrandRelationEntity;
-import java.util.Map;
-
/**
* 品牌分类关联
*
* @author xiejs
* @email 1294405880@qq.com
- * @date 2022-03-15 10:16:53
+ * @since 2022-03-15 10:16:53
*/
public interface CategoryBrandRelationService extends IService {
- PageUtils queryPage(Map params);
+
+ /**
+ * 保存详情
+ * @param categoryBrandRelation entity
+ */
+ void saveDetail(CategoryBrandRelationEntity categoryBrandRelation);
+
+ /**
+ * 更新
+ * @param brandId 品牌id
+ * @param name 品牌名称
+ */
+ void updateBrand(Long brandId, String name);
+
+ /**
+ * 更新
+ * @param catId 分类id
+ * @param name 分类名称
+ */
+ void updateCategory(Long catId, String name);
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/CategoryService.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/CategoryService.java
index ff16048f..9f3eb579 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/CategoryService.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/CategoryService.java
@@ -36,5 +36,11 @@ public interface CategoryService extends IService {
* @return long s
*/
Long[] finCatelogPath(Long catelogId);
+
+ /**
+ * 级联更新
+ * @param category 分类实体类
+ */
+ void updateCascade(CategoryEntity category);
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrGroupServiceImpl.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrGroupServiceImpl.java
index cc76c208..1c379fd0 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrGroupServiceImpl.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrGroupServiceImpl.java
@@ -11,11 +11,13 @@ import com.xjs.utils.PageUtils;
import com.xjs.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
@Service("attrGroupService")
+@Transactional
public class AttrGroupServiceImpl extends ServiceImpl implements AttrGroupService {
@Override
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/BrandServiceImpl.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/BrandServiceImpl.java
index 599b80ad..8b7ea7f3 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/BrandServiceImpl.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/BrandServiceImpl.java
@@ -6,17 +6,24 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjs.mall.product.dao.BrandDao;
import com.xjs.mall.product.entity.BrandEntity;
import com.xjs.mall.product.service.BrandService;
+import com.xjs.mall.product.service.CategoryBrandRelationService;
import com.xjs.utils.PageUtils;
import com.xjs.utils.Query;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
@Service("brandService")
+@Transactional
public class BrandServiceImpl extends ServiceImpl implements BrandService {
+ @Autowired
+ private CategoryBrandRelationService categoryBrandRelationService;
+
@Override
public PageUtils queryPage(Map params) {
String key = (String) params.get(Query.KEY_NAME);
@@ -36,4 +43,17 @@ public class BrandServiceImpl extends ServiceImpl impleme
return new PageUtils(page);
}
+ @Override
+ public void updateDetail(BrandEntity brand) {
+ //保证冗余字段的数据一致性
+ super.updateById(brand);
+
+ if (StringUtils.isNotEmpty(brand.getName())) {
+ //同步更新其他表
+ categoryBrandRelationService.updateBrand(brand.getBrandId(), brand.getName());
+
+ // todo 更新其他关联信息
+ }
+ }
+
}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/CategoryBrandRelationServiceImpl.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/CategoryBrandRelationServiceImpl.java
index 3bc63c77..06e79898 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/CategoryBrandRelationServiceImpl.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/CategoryBrandRelationServiceImpl.java
@@ -1,29 +1,62 @@
package com.xjs.mall.product.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.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.xjs.utils.PageUtils;
-import com.xjs.utils.Query;
-
+import com.xjs.mall.product.dao.BrandDao;
import com.xjs.mall.product.dao.CategoryBrandRelationDao;
+import com.xjs.mall.product.dao.CategoryDao;
+import com.xjs.mall.product.entity.BrandEntity;
import com.xjs.mall.product.entity.CategoryBrandRelationEntity;
+import com.xjs.mall.product.entity.CategoryEntity;
import com.xjs.mall.product.service.CategoryBrandRelationService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
@Service("categoryBrandRelationService")
+@Transactional
public class CategoryBrandRelationServiceImpl extends ServiceImpl implements CategoryBrandRelationService {
+ @Resource
+ private BrandDao brandDao;
+
+ @Resource
+ private CategoryDao categoryDao;
+
+
+ @Override
+ public void saveDetail(CategoryBrandRelationEntity categoryBrandRelation) {
+ Long brandId = categoryBrandRelation.getBrandId();
+ Long catelogId = categoryBrandRelation.getCatelogId();
+
+ BrandEntity brandEntity = brandDao.selectById(brandId);
+ CategoryEntity categoryEntity = categoryDao.selectById(catelogId);
+
+ categoryBrandRelation.setBrandName(brandEntity.getName());
+ categoryBrandRelation.setCatelogName(categoryEntity.getName());
+
+ super.save(categoryBrandRelation);
+ }
+
@Override
- public PageUtils queryPage(Map params) {
- IPage page = this.page(
- new Query().getPage(params),
- new QueryWrapper()
- );
+ public void updateBrand(Long brandId, String name) {
+ CategoryBrandRelationEntity entity = new CategoryBrandRelationEntity();
+ entity.setBrandId(brandId);
+ entity.setBrandName(name);
- return new PageUtils(page);
+ super.update(entity, new LambdaUpdateWrapper()
+ .eq(CategoryBrandRelationEntity::getBrandId, brandId));
}
-}
\ No newline at end of file
+ @Override
+ public void updateCategory(Long catId, String name) {
+ CategoryBrandRelationEntity entity = new CategoryBrandRelationEntity();
+ entity.setCatelogId(catId);
+ entity.setCatelogName(name);
+
+ super.update(entity, new LambdaUpdateWrapper()
+ .eq(CategoryBrandRelationEntity::getCatelogId, catId));
+ }
+}
diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/CategoryServiceImpl.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/CategoryServiceImpl.java
index 692b2166..77d9a668 100644
--- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/CategoryServiceImpl.java
+++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/CategoryServiceImpl.java
@@ -5,10 +5,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjs.mall.product.dao.CategoryDao;
import com.xjs.mall.product.entity.CategoryEntity;
+import com.xjs.mall.product.service.CategoryBrandRelationService;
import com.xjs.mall.product.service.CategoryService;
import com.xjs.utils.PageUtils;
import com.xjs.utils.Query;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
@@ -16,11 +19,15 @@ import java.util.stream.Collectors;
@Service("categoryService")
+@Transactional
public class CategoryServiceImpl extends ServiceImpl implements CategoryService {
@Resource
private CategoryDao categoryDao;
+ @Autowired
+ private CategoryBrandRelationService categoryBrandRelationService;
+
@Override
public PageUtils queryPage(Map params) {
IPage page = this.page(
@@ -63,6 +70,15 @@ public class CategoryServiceImpl extends ServiceImpl findParentPath(Long catelogId, List paths) {
//1、收集当前节点id
@@ -95,4 +111,4 @@ public class CategoryServiceImpl extends ServiceImpl