博客
关于我
四十一.属性分组新建关联-查询出分组未关联的属性
阅读量:246 次
发布时间:2019-02-28

本文共 2221 字,大约阅读时间需要 7 分钟。

属性分组下的新建关联功能如下:

在这里插入图片描述
在这里插入图片描述

接下来需要查询出分组未关联的属性。

AttrGroupController类添加如下接口:

/**     * 查询分组未关联的属性     *     * @param attrgroupId     * @param params     * @return     */    @GetMapping("/{attrgroupId}/noattr/relation")    public R attrNoRelation(@PathVariable("attrgroupId") Long attrgroupId,                            @RequestParam Map
params) { PageUtils page = attrService.getNoRelationAttr(params, attrgroupId); return R.ok().put("page", page); }

AttrService类添加如下方法:

/**     * 查询出分组未关联的属性     *     * @param params     * @param attrgroupId     * @return     */    PageUtils getNoRelationAttr(Map
params, Long attrgroupId);

AttrServiceImpl类添加getNoRelationAttr()方法相关实现:

@Override    public PageUtils getNoRelationAttr(Map
params, Long attrgroupId) { //1、当前分组只能关联自己所属的分类里面的所有属性 AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrgroupId); Long catelogId = attrGroupEntity.getCatelogId(); //2、当前分组只能关联别的分组没有引用的属性 //2-1.查询当前分类下的其他分组 List
attrGroupEntities = attrGroupDao.selectList(new QueryWrapper
().eq("catelog_id", catelogId)); List
collect = attrGroupEntities.stream().map(item -> { return item.getAttrGroupId(); }).collect(Collectors.toList()); //2-2、查询分组关联的属性 List
attrgroupRelationEntities = relationDao.selectList(new QueryWrapper
().in("attr_group_id", collect)); List
attrIds = attrgroupRelationEntities.stream().map(item -> { return item.getAttrId(); }).collect(Collectors.toList()); //2-3、从当前分类的所有属性中移除这些属性 QueryWrapper
wrapper = new QueryWrapper
().eq("catelog_id", catelogId).eq("attr_type", ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()); if (attrIds != null && attrIds.size() > 0) { wrapper.notIn("attr_id", attrIds); } //支持模糊查询 String key = (String) params.get("key"); if (!StringUtils.isEmpty(key)) { wrapper.and((w) -> { w.eq("attr_id", key).or().like("attr_name", key); }); } IPage
page = this.page(new Query
().getPage(params), wrapper); PageUtils pageUtils = new PageUtils(page); return pageUtils; }

测试效果:

影视分类有如下两个属性:

在这里插入图片描述
影视相关分组已经关联了一个属性,如下:
在这里插入图片描述
在这里插入图片描述

点击新建关联,会查询出分组未关联的属性,如下:

在这里插入图片描述

查询出分组未关联的属性完成。

转载地址:http://sxjp.baihongyu.com/

你可能感兴趣的文章
MySQL 深度分页性能急剧下降,该如何优化?
查看>>
MySQL 深度分页性能急剧下降,该如何优化?
查看>>
MySQL 添加列,修改列,删除列
查看>>
mysql 添加索引
查看>>
MySQL 添加索引,删除索引及其用法
查看>>
MySQL 用 limit 为什么会影响性能?
查看>>
MySQL 用 limit 为什么会影响性能?有什么优化方案?
查看>>
MySQL 用户权限管理:授权、撤销、密码更新和用户删除(图文解析)
查看>>
mysql 用户管理和权限设置
查看>>
MySQL 的 varchar 水真的太深了!
查看>>
mysql 的GROUP_CONCAT函数的使用(group_by 如何显示分组之前的数据)
查看>>
MySQL 的instr函数
查看>>
MySQL 的mysql_secure_installation安全脚本执行过程介绍
查看>>
MySQL 的Rename Table语句
查看>>
MySQL 的全局锁、表锁和行锁
查看>>
mysql 的存储引擎介绍
查看>>
MySQL 的存储引擎有哪些?为什么常用InnoDB?
查看>>
mysql 索引
查看>>
MySQL 索引失效的 15 种场景!
查看>>
MySQL 索引深入解析及优化策略
查看>>