mirror of
https://github.com/kirklin/kkmall.git
synced 2024-09-20 06:46:15 +08:00
商品服务API品牌管理-品牌分类关联与级联更新
This commit is contained in:
parent
519c8ab16b
commit
caaf701723
|
@ -0,0 +1,26 @@
|
|||
package name.lkk.kkmall.product.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* <p>Title: MybatisConfig</p>
|
||||
* Description:引入分页插件
|
||||
* date:2020/6/2 15:20
|
||||
*/
|
||||
@EnableTransactionManagement
|
||||
@Configuration
|
||||
public class MybatisConfig {
|
||||
|
||||
// 最新版
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
}
|
|
@ -1,19 +1,16 @@
|
|||
package name.lkk.kkmall.product.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
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 name.lkk.kkmall.product.entity.CategoryBrandRelationEntity;
|
||||
import name.lkk.kkmall.product.service.CategoryBrandRelationService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import name.lkk.common.utils.PageUtils;
|
||||
import name.lkk.common.utils.R;
|
||||
import name.lkk.kkmall.product.entity.CategoryBrandRelationEntity;
|
||||
import name.lkk.kkmall.product.service.CategoryBrandRelationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
|
@ -27,28 +24,40 @@ import name.lkk.common.utils.R;
|
|||
@RestController
|
||||
@RequestMapping("product/categorybrandrelation")
|
||||
public class CategoryBrandRelationController {
|
||||
|
||||
@Autowired
|
||||
private CategoryBrandRelationService categoryBrandRelationService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前品牌的所有分类列表
|
||||
*/
|
||||
@GetMapping("/catelog/list")
|
||||
public R list(@RequestParam("brandId") Long brandId){
|
||||
List<CategoryBrandRelationEntity> data = categoryBrandRelationService.list(
|
||||
new QueryWrapper<CategoryBrandRelationEntity>().eq("brand_id",brandId)
|
||||
);
|
||||
|
||||
return R.ok().put("data", data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
//@RequiresPermissions("product:categorybrandrelation:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = categoryBrandRelationService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
//@RequiresPermissions("product:categorybrandrelation:info")
|
||||
public R info(@PathVariable("id") Long id){
|
||||
CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);
|
||||
CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);
|
||||
|
||||
return R.ok().put("categoryBrandRelation", categoryBrandRelation);
|
||||
}
|
||||
|
@ -57,9 +66,8 @@ public class CategoryBrandRelationController {
|
|||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
//@RequiresPermissions("product:categorybrandrelation:save")
|
||||
public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
|
||||
categoryBrandRelationService.save(categoryBrandRelation);
|
||||
categoryBrandRelationService.saveDetail(categoryBrandRelation);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
@ -68,9 +76,8 @@ public class CategoryBrandRelationController {
|
|||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
//@RequiresPermissions("product:categorybrandrelation:update")
|
||||
public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
|
||||
categoryBrandRelationService.updateById(categoryBrandRelation);
|
||||
categoryBrandRelationService.updateById(categoryBrandRelation);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
@ -79,11 +86,10 @@ public class CategoryBrandRelationController {
|
|||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
//@RequiresPermissions("product:categorybrandrelation:delete")
|
||||
public R delete(@RequestBody Long[] ids){
|
||||
categoryBrandRelationService.removeByIds(Arrays.asList(ids));
|
||||
categoryBrandRelationService.removeByIds(Arrays.asList(ids));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
package name.lkk.kkmall.product.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import name.lkk.common.utils.R;
|
||||
import name.lkk.kkmall.product.entity.CategoryEntity;
|
||||
import name.lkk.kkmall.product.service.CategoryService;
|
||||
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 name.lkk.kkmall.product.entity.CategoryEntity;
|
||||
import name.lkk.kkmall.product.service.CategoryService;
|
||||
import name.lkk.common.utils.PageUtils;
|
||||
import name.lkk.common.utils.R;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
|
@ -89,7 +85,7 @@ public class CategoryController {
|
|||
@RequestMapping("/update")
|
||||
//@RequiresPermissions("product:category:update")
|
||||
public R update(@RequestBody CategoryEntity category){
|
||||
categoryService.updateById(category);
|
||||
categoryService.updateCascade(category);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package name.lkk.kkmall.product.dao;
|
||||
|
||||
import name.lkk.kkmall.product.entity.CategoryBrandRelationEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import name.lkk.kkmall.product.entity.CategoryBrandRelationEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 品牌分类关联
|
||||
|
@ -13,5 +14,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
*/
|
||||
@Mapper
|
||||
public interface CategoryBrandRelationDao extends BaseMapper<CategoryBrandRelationEntity> {
|
||||
|
||||
|
||||
void updateCategory(@Param("catId") Long catId, String name);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,5 +19,8 @@ public interface CategoryBrandRelationService extends IService<CategoryBrandRela
|
|||
|
||||
void updateBrand(Long brandId, String name);
|
||||
|
||||
void saveDetail(CategoryBrandRelationEntity categoryBrandRelation);
|
||||
|
||||
void updateCategory(Long catId, String name);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,5 +39,9 @@ public interface CategoryService extends IService<CategoryEntity> {
|
|||
*/
|
||||
Long[] findCateLogPath(Long catelogId);
|
||||
|
||||
/**
|
||||
* 级联更新所有数据
|
||||
*/
|
||||
void updateCascade(CategoryEntity category);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
package name.lkk.kkmall.product.service.impl;
|
||||
|
||||
import name.lkk.kkmall.product.service.CategoryBrandRelationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 name.lkk.common.utils.PageUtils;
|
||||
import name.lkk.common.utils.Query;
|
||||
|
||||
import name.lkk.kkmall.product.dao.BrandDao;
|
||||
import name.lkk.kkmall.product.entity.BrandEntity;
|
||||
import name.lkk.kkmall.product.service.BrandService;
|
||||
import name.lkk.kkmall.product.service.CategoryBrandRelationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service("brandService")
|
||||
|
@ -26,11 +25,15 @@ public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> impleme
|
|||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
QueryWrapper<BrandEntity> wrapper = new QueryWrapper<>();
|
||||
String key = (String) params.get("key");
|
||||
if(!ObjectUtils.isEmpty(key)){
|
||||
wrapper.eq("brand_id", key).or().like("name", key);
|
||||
}
|
||||
IPage<BrandEntity> page = this.page(
|
||||
new Query<BrandEntity>().getPage(params),
|
||||
new QueryWrapper<BrandEntity>()
|
||||
wrapper
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
@ -42,7 +45,7 @@ public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> impleme
|
|||
public void updateDetail(BrandEntity brand) {
|
||||
// 保证冗余字段的数据一致
|
||||
this.updateById(brand);
|
||||
if(!StringUtils.isEmpty(brand.getName())){
|
||||
if(!ObjectUtils.isEmpty(brand.getName())){
|
||||
// 同步更新其他关联表的数据
|
||||
categoryBrandRelationService.updateBrand(brand.getBrandId(), brand.getName());
|
||||
// TODO 更新其它关联
|
||||
|
|
|
@ -1,21 +1,31 @@
|
|||
package name.lkk.kkmall.product.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import name.lkk.common.utils.PageUtils;
|
||||
import name.lkk.common.utils.Query;
|
||||
|
||||
import name.lkk.kkmall.product.dao.BrandDao;
|
||||
import name.lkk.kkmall.product.dao.CategoryBrandRelationDao;
|
||||
import name.lkk.kkmall.product.dao.CategoryDao;
|
||||
import name.lkk.kkmall.product.entity.BrandEntity;
|
||||
import name.lkk.kkmall.product.entity.CategoryBrandRelationEntity;
|
||||
import name.lkk.kkmall.product.entity.CategoryEntity;
|
||||
import name.lkk.kkmall.product.service.CategoryBrandRelationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service("categoryBrandRelationService")
|
||||
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {
|
||||
@Autowired
|
||||
private BrandDao brandDao;
|
||||
|
||||
@Autowired
|
||||
private CategoryDao categoryDao;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
|
@ -36,4 +46,24 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandR
|
|||
this.update(entity, new UpdateWrapper<CategoryBrandRelationEntity>().eq("brand_id",brandId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCategory(Long catId, String name) {
|
||||
this.baseMapper.updateCategory(catId, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据获取品牌id 、三级分类id查询对应的名字保存到数据库
|
||||
*/
|
||||
@Override
|
||||
public void saveDetail(CategoryBrandRelationEntity categoryBrandRelation) {
|
||||
// 获取品牌id 、三级分类id
|
||||
Long brandId = categoryBrandRelation.getBrandId();
|
||||
Long catelogId = categoryBrandRelation.getCatelogId();
|
||||
// 根据id查询详细名字
|
||||
BrandEntity brandEntity = brandDao.selectById(brandId);
|
||||
CategoryEntity categoryEntity = categoryDao.selectById(catelogId);
|
||||
categoryBrandRelation.setBrandName(brandEntity.getName());
|
||||
categoryBrandRelation.setCatelogName(categoryEntity.getName());
|
||||
this.save(categoryBrandRelation);
|
||||
}
|
||||
}
|
|
@ -7,8 +7,11 @@ import name.lkk.common.utils.PageUtils;
|
|||
import name.lkk.common.utils.Query;
|
||||
import name.lkk.kkmall.product.dao.CategoryDao;
|
||||
import name.lkk.kkmall.product.entity.CategoryEntity;
|
||||
import name.lkk.kkmall.product.service.CategoryBrandRelationService;
|
||||
import name.lkk.kkmall.product.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -17,6 +20,9 @@ import java.util.stream.Collectors;
|
|||
@Service("categoryService")
|
||||
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity> implements CategoryService {
|
||||
|
||||
@Autowired
|
||||
private CategoryBrandRelationService categoryBrandRelationService;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
IPage<CategoryEntity> page = this.page(
|
||||
|
@ -35,15 +41,11 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
|
|||
public List<CategoryEntity> listWithTree() {
|
||||
List<CategoryEntity> entities = baseMapper.selectList(null);
|
||||
// 筛选出所有一级分类
|
||||
List<CategoryEntity> level1Menus = entities.stream().
|
||||
filter((categoryEntity) -> categoryEntity.getParentCid() == 0)
|
||||
.map((menu) -> {
|
||||
menu.setChildren(getChildrens(menu, entities));
|
||||
return menu;
|
||||
}).sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return level1Menus;
|
||||
return entities.stream().
|
||||
filter((categoryEntity) -> categoryEntity.getParentCid() == 0)
|
||||
.peek((menu) -> menu.setChildren(getChildrens(menu, entities))).sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort())))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,7 +57,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
|
|||
@Override
|
||||
public List<CategoryEntity> getChildrens(CategoryEntity root, List<CategoryEntity> all){
|
||||
List<CategoryEntity> children = all.stream().filter(categoryEntity ->
|
||||
categoryEntity.getParentCid() == root.getCatId()
|
||||
categoryEntity.getParentCid().equals(root.getCatId())
|
||||
).map(categoryEntity -> {
|
||||
categoryEntity.setChildren(getChildrens(categoryEntity, all));
|
||||
return categoryEntity;
|
||||
|
@ -78,6 +80,13 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
|
|||
return paths.toArray(new Long[paths.size()]);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void updateCascade(CategoryEntity category) {
|
||||
this.updateById(category);
|
||||
categoryBrandRelationService.updateCategory(category.getCatId(), category.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归收集所有节点
|
||||
*/
|
||||
|
|
|
@ -12,5 +12,8 @@
|
|||
<result property="catelogName" column="catelog_name"/>
|
||||
</resultMap>
|
||||
|
||||
<update id="updateCategory">
|
||||
UPDATE `pms_category_brand_relation` SET catelog_name = #{name} WHERE catelog_id = #{catId}
|
||||
</update>
|
||||
|
||||
</mapper>
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-upload
|
||||
action="http://mall-fire.oss-cn-shenzhen.aliyuncs.com"
|
||||
action="http://mall-kk.oss-cn-hangzhou.aliyuncs.com"
|
||||
:data="dataObj"
|
||||
:list-type="listType"
|
||||
:file-list="fileList"
|
||||
|
@ -21,8 +21,9 @@
|
|||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { policy } from "./policy";
|
||||
import { getUUID } from '@/utils'
|
||||
import {policy} from "./policy";
|
||||
import {getUUID} from '@/utils'
|
||||
|
||||
export default {
|
||||
name: "multiUpload",
|
||||
props: {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import http from '@/utils/httpRequest.js'
|
||||
|
||||
export function policy() {
|
||||
return new Promise((resolve,reject)=>{
|
||||
http({
|
||||
url: http.adornUrl("/third/party/oss/policy"),
|
||||
url: http.adornUrl("/third/server/oss/policy"),
|
||||
method: "get",
|
||||
params: http.adornParams({})
|
||||
}).then(({ data }) => {
|
||||
resolve(data);
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-upload
|
||||
action="http://mall-fire.oss-cn-shenzhen.aliyuncs.com"
|
||||
action="http://mall-kk.oss-cn-hangzhou.aliyuncs.com"
|
||||
:data="dataObj"
|
||||
list-type="picture"
|
||||
:multiple="false"
|
||||
|
@ -21,8 +21,8 @@
|
|||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { policy } from "./policy";
|
||||
import { getUUID } from "@/utils";
|
||||
import {policy} from "./policy";
|
||||
import {getUUID} from "@/utils";
|
||||
|
||||
export default {
|
||||
name: "singleUpload",
|
||||
|
|
Loading…
Reference in a new issue