完善后台属性分组功能

g_develop
ddyd 3 weeks ago
parent 3598f265b2
commit 035fa8315f

@ -1,11 +1,23 @@
package com.bookstore.bookmall.product.config; package com.bookstore.bookmall.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.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
@MapperScan("com.baomidou.cloud.service.*.mapper") @MapperScan("com.bookstore.bookmall.product.dao")
public class MybatisConfig { public class MybatisConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加
// 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType
return interceptor;
}
} }

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.internal.StringUtil;
import com.bookstore.common.valid.AddGroup; import com.bookstore.common.valid.AddGroup;
import com.bookstore.common.valid.AddShowStatusGroup; import com.bookstore.common.valid.AddShowStatusGroup;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -43,6 +44,7 @@ public class BrandController {
@RequestMapping("/list") @RequestMapping("/list")
//@RequiresPermissions("product:brand:list") //@RequiresPermissions("product:brand:list")
public R list(@RequestParam Map<String, Object> params){ public R list(@RequestParam Map<String, Object> params){
PageUtils page = brandService.queryPage(params); PageUtils page = brandService.queryPage(params);
return R.ok().put("page", page); return R.ok().put("page", page);

@ -1,15 +1,13 @@
package com.bookstore.bookmall.product.controller; package com.bookstore.bookmall.product.controller;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
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 com.bookstore.bookmall.product.entity.CategoryBrandRelationEntity; import com.bookstore.bookmall.product.entity.CategoryBrandRelationEntity;
import com.bookstore.bookmall.product.service.CategoryBrandRelationService; import com.bookstore.bookmall.product.service.CategoryBrandRelationService;
@ -42,6 +40,16 @@ public class CategoryBrandRelationController {
return R.ok().put("page", page); return R.ok().put("page", page);
} }
//@RequestMapping("/catelog/list")
//@RequiresPermissions("product:categorybrandrelation:list")
@GetMapping("/catelog/list")
public R cateloglist(@RequestParam("brandId") Long brandId){
List<CategoryBrandRelationEntity> data = categoryBrandRelationService.list(
new QueryWrapper<CategoryBrandRelationEntity>().eq("brand_id", brandId));
return R.ok().put("data", data);
}
/** /**
* *
@ -60,7 +68,7 @@ public class CategoryBrandRelationController {
@RequestMapping("/save") @RequestMapping("/save")
//@RequiresPermissions("product:categorybrandrelation:save") //@RequiresPermissions("product:categorybrandrelation:save")
public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){ public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
categoryBrandRelationService.save(categoryBrandRelation); categoryBrandRelationService.saveDetail(categoryBrandRelation);
return R.ok(); return R.ok();
} }

@ -16,5 +16,7 @@ import java.util.Map;
public interface CategoryBrandRelationService extends IService<CategoryBrandRelationEntity> { public interface CategoryBrandRelationService extends IService<CategoryBrandRelationEntity> {
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
void saveDetail(CategoryBrandRelationEntity categoryBrandRelation);
} }

@ -29,23 +29,24 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEnt
@Override @Override
public PageUtils querypage(Map<String, Object> params, Long catelogId) { public PageUtils querypage(Map<String, Object> params, Long catelogId) {
//多字段模糊检索
//select * from pms_attr_group where catelog_id=? and (attr_group_id=key or attr_group_name like %key% or descript=key)
String key = (String) params.get("key");
//数据库查询 QueryWrapper
QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<AttrGroupEntity>();
if (!StringUtil.isNullOrEmpty(key)){
//将wrapper构造以后用这个查询
wrapper.and((obj)->{
obj.eq("attr_group_id",key).or().like("attr_group_name", key);
});
}
if (catelogId == 0) { if (catelogId == 0) {
IPage<AttrGroupEntity> page = this.page( IPage<AttrGroupEntity> page = this.page(
new Query<AttrGroupEntity>().getPage(params), new Query<AttrGroupEntity>().getPage(params),
new QueryWrapper<AttrGroupEntity>()); new QueryWrapper<AttrGroupEntity>());
return new PageUtils(page); return new PageUtils(page);
}else { }else {
//多字段模糊检索 wrapper.eq("catelog_id", catelogId);
//select * from pms_attr_group where catelog_id=? and (attr_group_id=key or attr_group_name like %key% or descript=key)
String key = (String) params.get("key");
//数据库查询 QueryWrapper
QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId);
if (!StringUtil.isNullOrEmpty(key)){
//将wrapper构造以后用这个查询
wrapper.and((obj)->{
obj.eq("attr_group_id",key).or().like("attr_group_name", key);
});
}
IPage<AttrGroupEntity> page = this.page( IPage<AttrGroupEntity> page = this.page(
new Query<AttrGroupEntity>().getPage(params), wrapper); new Query<AttrGroupEntity>().getPage(params), wrapper);
return new PageUtils(page); return new PageUtils(page);

@ -1,5 +1,6 @@
package com.bookstore.bookmall.product.service.impl; package com.bookstore.bookmall.product.service.impl;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -18,9 +19,16 @@ public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> impleme
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
String key = (String)params.get("key");
QueryWrapper<BrandEntity> wrapper = new QueryWrapper<BrandEntity>();
if (!StringUtils.isNullOrEmpty(key)) {
wrapper.eq("brand_id", key).or().like("name", key);
}
IPage<BrandEntity> page = this.page( IPage<BrandEntity> page = this.page(
new Query<BrandEntity>().getPage(params), new Query<BrandEntity>().getPage(params), wrapper
new QueryWrapper<BrandEntity>()
); );
return new PageUtils(page); return new PageUtils(page);

@ -1,5 +1,10 @@
package com.bookstore.bookmall.product.service.impl; package com.bookstore.bookmall.product.service.impl;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -16,6 +21,11 @@ import com.bookstore.bookmall.product.service.CategoryBrandRelationService;
@Service("categoryBrandRelationService") @Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService { public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {
@Autowired
BrandDao brandDao;
@Autowired
CategoryDao categoryDao;
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<CategoryBrandRelationEntity> page = this.page( IPage<CategoryBrandRelationEntity> page = this.page(
@ -26,4 +36,19 @@ public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandR
return new PageUtils(page); return new PageUtils(page);
} }
@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());
this.save(categoryBrandRelation);
}
} }
Loading…
Cancel
Save