微服务实战——平台属性

devtools/2024/10/18 3:12:40/

平台属性

中间表复杂业务

/*** 获取分类规格参数(模糊查询)** @param params* @param catelogId* @param type type="base"时查询基础属性,type="sale"时查询销售属性* @return*/
@Override
public PageUtils listByCatelogId(Map<String, Object> params, Long catelogId, String type) {String key = (String) params.get("key");QueryWrapper<AttrEntity> wrapper = new QueryWrapper<>();// 1.判断参数中是否存在检索关键字keyif(!StringUtils.isEmpty(key)){wrapper.and((obj) -> {obj.eq("attr_id", key).or().like("attr_name", key).or().like("value_select", key);});}// 2.判断参数中是否存在catelogId// 2.1.查询全部if(catelogId != 0){wrapper.eq("catelog_id", catelogId);}IPage<AttrEntity> page = this.page(new Query<AttrEntity>().getPage(params),wrapper.eq("attr_type", "base".equalsIgnoreCase(type) ? 1 : 0));PageUtils pageUtils = new PageUtils(page);// 3.封装成AttrRespVOList<AttrRespVo> respVos = page.getRecords().stream().map((attrEntity) -> {AttrRespVo attrRespVo = new AttrRespVo();BeanUtils.copyProperties(attrEntity, attrRespVo);// 3.1.得到所属分类名CategoryEntity categoryEntity = categoryService.getById(attrEntity.getCatelogId());if(categoryEntity != null){attrRespVo.setCatelogName(categoryEntity.getName());}// 3.2.得到所属分组名if (ATTR_TYPE_BASE.getMsg().equalsIgnoreCase(type)) {AttrAttrgroupRelationEntity relationEntity = relationService.query().eq("attr_id", attrEntity.getAttrId()).one();if(relationEntity != null){AttrGroupEntity attrGroupEntity = attrGroupService.getById(relationEntity.getAttrGroupId());attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());}}return attrRespVo;}).collect(Collectors.toList());pageUtils.setList(respVos);return pageUtils;
}

批量删除

/*** 删除属性与分组的关联关系 * DELETE FROM pms_attr_attrgroup_relation * WHERE (( attr_id = 1 and attr_group_id = 1) OR ( attr_id = 2 and attr_group_id = 3))*/
@Override
public void deleteRelation(List<AttrGroupRelationVo> voList) {// 1.获取List<AttrAttrgroupRelationEntity> relationEntities = voList.stream().map(attrGroupRelationVo -> {AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();relationEntity.setAttrId(attrGroupRelationVo.getAttrId());relationEntity.setAttrGroupId(attrGroupRelationVo.getAttrGroupId());return relationEntity;}).collect(Collectors.toList());// 2.批量删除relationDao.deleteBatchRelation(relationEntities);
}
<!--    DELETE FROM pms_attr_attrgroup_relation
WHERE (( attr_id = 1 and attr_group_id = 1) OR ( attr_id = 2 and attr_group_id = 3))-->
<delete id="deleteBatchRelation">DELETE FROM `pms_attr_attrgroup_relation` WHERE<foreach collection="relationEntities" item="item" separator=" OR ">( attr_id = #{item.attrId} AND attr_group_id = #{item.attrGroupId})</foreach>
</delete>

中间表复杂业务

/*** 获取属性分组没有关联的其他属性*/
@Override
public PageUtils listNoRelationAttr(Map<String, Object> params, Long attrgroupId) {// 1.获取分类idLong catelogId = this.query().eq("attr_group_id", attrgroupId).one().getCatelogId();// 2.获取当前分类下的其他分组id集合List<Long> groupIds = this.list(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId)).stream().map(AttrGroupEntity::getAttrGroupId).collect(Collectors.toList());;// 3.获取其他分组关联的属性id集合List<Long> attrIds = relationService.list(new QueryWrapper<AttrAttrgroupRelationEntity>().in("attr_group_id", groupIds)).stream().map(AttrAttrgroupRelationEntity::getAttrId).collect(Collectors.toList());// 4.剔除其他分组关联的属性QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>().eq("catelog_id", catelogId).ne("value_type", ATTR_TYPE_BASE.getCode());if(attrIds != null && attrIds.size() > 0){wrapper.notIn("attr_id", attrIds);}// 5.判断keyString key = (String) params.get("key");if(!StringUtils.isEmpty(key)){wrapper.and((obj) -> {obj.eq("attr_id", key).or().like("attr_name", key).or().like("value_select", key);});}IPage<AttrEntity> page = attrService.page(new Query<AttrEntity>().getPage(params), wrapper);return new PageUtils(page);
}

http://www.ppmy.cn/devtools/120983.html

相关文章

基于无人机图像的洪水灾害受损评估分割数据集,共4494张高清无人机图像,10个类别,共22GB数据量,主要关注道路,建筑的受损情况。洪水应急救援

洪水应急救援&#xff0c;基于无人机图像的洪水灾害受损评估分割数据集&#xff0c;共4494张高清无人机图像&#xff0c;10个类别&#xff0c;共22GB数据量&#xff0c;主要关注道路&#xff0c;建筑的受损情况。 洪水应急救援&#xff0c;基于无人机图像的洪水灾害受损评估分…

SpringCloud-Netflix第一代微服务快速入门

1.springCloud常用组件 Netflix Eureka 当我们的微服务过多的时候&#xff0c;管理服务的通信地址是一个非常麻烦的事情&#xff0c;Eureka就是用来管理微服务的通信地址清单的&#xff0c;有了Eureka之后我们通过服务的名字就能实现服务的调用。 Netflix Ribbon\Feign : 客…

华硕天选笔记本外接音箱没有声音

系列文章目录 文章目录 系列文章目录一.前言二.解决方法第一种方法第二种方法 一.前言 华硕天选笔记本外接音箱没有声音&#xff0c;在插上外接音箱时&#xff0c;系统会自动弹出下图窗口 二.解决方法 第一种方法 在我的电脑上选择 Headphone Speaker Out Headset 这三个选项…

PHP 基础语法详解

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;Java Fans的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏…

c语言基础作业

选择题 1.1、以下选项中,不能作为合法常量的是 __________ A&#xff09;1.234e04 B&#xff09;1.234e0.4C&#xff09;1.234e4 D&#xff09;1.234e0 1.2、以下定义变量并初始化错误的是_____________。 A) char c1 ‘H’ &#xff1b; B) char c1 9…

C++ 游戏开发:奠定高性能游戏的基础

C 被广泛认为是游戏开发的首选语言之一。其独特的性能优势、底层驱动能力和丰富的库支持&#xff0c;推动了众多经典游戏和游戏引擎的产生。本文将深入探讨C在游戏开发中的应用以及相关技术要点。更多内容&#xff0c;请查阅 为什么选择C进行游戏开发 高性能&#xff1a;C 是一…

MFC工控项目实例二十一型号选择界面删除参数按钮禁用切换

承接专栏《MFC工控项目实例二十手动测试界面模拟量输入实时显示》 对于禁止使用的删除、参数按钮&#xff0c;在选中列表控件选项时切换为能够使用。 1、在TypDlg.h文件中添加代码 #include "ShadeButtonST.h" #include "BtnST.h" class CTypDlg : publi…