✨ 根据id查询详情
This commit is contained in:
parent
86104b6bdf
commit
b9ce4ea6dc
|
@ -16,6 +16,7 @@ public class VmsGeneratorPathHelper {
|
|||
"mapper", "Mapper",
|
||||
"resourceMapper", "Mapper",
|
||||
"dto", "Dto",
|
||||
"entity", "Entity",
|
||||
"vo", "Vo"
|
||||
);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.mall</groupId>
|
||||
<artifactId>mall-cloud</artifactId>
|
||||
<artifactId>mall-modules</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.mall</groupId>
|
||||
<artifactId>mall-cloud</artifactId>
|
||||
<artifactId>mall-modules</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -46,6 +46,13 @@ public class AttrGroupController {
|
|||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据id查询详情", description = "根据id查询详情")
|
||||
@GetMapping("info/{attrGroupId}")
|
||||
public Result<AttrGroupVo> getAttrGroupById(@PathVariable("attrGroupId") Long attrGroupId) {
|
||||
AttrGroupVo attrGroupEntity = attrGroupService.getAttrGroupById(attrGroupId);
|
||||
return Result.success(attrGroupEntity);
|
||||
}
|
||||
|
||||
@Operation(summary = "添加属性分组", description = "添加属性分组")
|
||||
@PostMapping()
|
||||
public Result<String> addAttrGroup(@Valid @RequestBody AttrGroupDto dto) {
|
||||
|
|
|
@ -31,4 +31,7 @@ public class AttrGroupDto {
|
|||
@Schema(name = "catelogId", title = "所属分类id")
|
||||
private Long catelogId;
|
||||
|
||||
@Schema(name = "key", description = "查询关键字key")
|
||||
private String key;
|
||||
|
||||
}
|
|
@ -2,7 +2,6 @@ package com.mall.product.domain.vo;
|
|||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
@ -30,5 +29,8 @@ public class AttrGroupVo {
|
|||
@Schema(name = "catelogId", title = "所属分类id")
|
||||
private Long catelogId;
|
||||
|
||||
@Schema(name = "catelogPaths", title = "分类路径")
|
||||
private Long[] catelogPaths;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -46,4 +46,12 @@ public interface AttrGroupService extends IService<AttrGroupEntity> {
|
|||
* @param ids 删除id列表
|
||||
*/
|
||||
void deleteAttrGroup(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据id查询详情
|
||||
*
|
||||
* @param attrGroupId 分组id
|
||||
* @return 属性分组
|
||||
*/
|
||||
AttrGroupVo getAttrGroupById(Long attrGroupId);
|
||||
}
|
||||
|
|
|
@ -54,4 +54,11 @@ public interface CategoryService extends IService<CategoryEntity> {
|
|||
*/
|
||||
List<CategoryEntity> getCategoryTreeList();
|
||||
|
||||
/**
|
||||
* 找到后代所有的路径
|
||||
*
|
||||
* @param catelogId 分类id
|
||||
* @return 后端所有的id
|
||||
*/
|
||||
List<Long> findCatelogPath(Long catelogId);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,43 @@
|
|||
package com.mall.product.service.ext;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mall.product.domain.entity.CategoryEntity;
|
||||
import com.mall.product.mapper.CategoryMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryServiceImplExt {
|
||||
@Service
|
||||
public class CategoryServiceImplExt extends ServiceImpl<CategoryMapper, CategoryEntity> {
|
||||
|
||||
/**
|
||||
* 递归组装树型结构
|
||||
*
|
||||
* @param categoryEntity 商品三级分类
|
||||
* @param categoryEntityList 商品三级分类列表
|
||||
* @return 树型结构菜单
|
||||
*/
|
||||
public static List<CategoryEntity> getCategoryTreeChildrenList(CategoryEntity categoryEntity, List<CategoryEntity> categoryEntityList) {
|
||||
return categoryEntityList.stream()
|
||||
.filter(item -> item.getParentCid().equals(categoryEntity.getCatId()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查询父级路径
|
||||
*
|
||||
* @param catelogId 分类id
|
||||
* @param paths 当前组装的路径
|
||||
* @return 后代所有的路径
|
||||
*/
|
||||
public List<Long> findParentPath(Long catelogId, List<Long> paths) {
|
||||
paths.add(catelogId);
|
||||
CategoryEntity categoryEntity = getById(catelogId);
|
||||
if (!categoryEntity.getParentCid().equals(0L)) {
|
||||
findParentPath(categoryEntity.getParentCid(), paths);
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import com.mall.product.domain.entity.AttrGroupEntity;
|
|||
import com.mall.product.domain.vo.AttrGroupVo;
|
||||
import com.mall.product.mapper.AttrGroupMapper;
|
||||
import com.mall.product.service.AttrGroupService;
|
||||
import com.mall.product.service.CategoryService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -25,8 +27,11 @@ import java.util.List;
|
|||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
@RequiredArgsConstructor
|
||||
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroupEntity> implements AttrGroupService {
|
||||
|
||||
private final CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* * 属性分组 服务实现类
|
||||
*
|
||||
|
@ -79,4 +84,19 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup
|
|||
public void deleteAttrGroup(List<Long> ids) {
|
||||
removeByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询详情
|
||||
*
|
||||
* @param attrGroupId 分组id
|
||||
* @return 属性分组
|
||||
*/
|
||||
@Override
|
||||
public AttrGroupVo getAttrGroupById(Long attrGroupId) {
|
||||
AttrGroupEntity attrGroupEntity = getById(attrGroupId);
|
||||
Long catelogId = attrGroupEntity.getCatelogId();
|
||||
|
||||
List<Long> catelogIds = categoryService.findCatelogPath(catelogId);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -9,10 +9,14 @@ import com.mall.product.domain.entity.CategoryEntity;
|
|||
import com.mall.product.domain.vo.CategoryVo;
|
||||
import com.mall.product.mapper.CategoryMapper;
|
||||
import com.mall.product.service.CategoryService;
|
||||
import com.mall.product.service.ext.CategoryServiceImplExt;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -28,8 +32,11 @@ import static com.mall.product.service.ext.CategoryServiceImplExt.getCategoryTre
|
|||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
@RequiredArgsConstructor
|
||||
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEntity> implements CategoryService {
|
||||
|
||||
private final CategoryServiceImplExt categoryServiceImplExt;
|
||||
|
||||
/**
|
||||
* * 商品三级分类 服务实现类
|
||||
*
|
||||
|
@ -98,4 +105,21 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEnt
|
|||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 找到后代所有的路径
|
||||
*
|
||||
* @param catelogId 分类id
|
||||
* @return 后端所有的id
|
||||
*/
|
||||
@Override
|
||||
public List<Long> findCatelogPath(Long catelogId) {
|
||||
List<Long> paths = new ArrayList<>();
|
||||
List<Long> longList = categoryServiceImplExt.findParentPath(catelogId, paths);
|
||||
|
||||
// 饭庄当前数组
|
||||
Collections.reverse(longList);
|
||||
|
||||
return longList;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,13 +24,13 @@
|
|||
from pms_attr_group
|
||||
<where>
|
||||
<if test="dto.attrGroupId != null and dto.attrGroupId != ''">
|
||||
and attr_group_id like CONCAT('%',#{dto.attrGroupId},'%')
|
||||
and attr_group_id = #{dto.attrGroupId}
|
||||
</if>
|
||||
<if test="dto.attrGroupName != null and dto.attrGroupName != ''">
|
||||
and attr_group_name like CONCAT('%',#{dto.attrGroupName},'%')
|
||||
</if>
|
||||
<if test="dto.sort != null and dto.sort != ''">
|
||||
and sort like CONCAT('%',#{dto.sort},'%')
|
||||
and sort = #{dto.sort}
|
||||
</if>
|
||||
<if test="dto.descript != null and dto.descript != ''">
|
||||
and descript like CONCAT('%',#{dto.descript},'%')
|
||||
|
@ -39,7 +39,11 @@
|
|||
and icon like CONCAT('%',#{dto.icon},'%')
|
||||
</if>
|
||||
<if test="dto.catelogId != null and dto.catelogId != ''">
|
||||
and catelog_id like CONCAT('%',#{dto.catelogId},'%')
|
||||
and catelog_id = #{dto.catelogId}
|
||||
</if>
|
||||
<!-- 使用 key 进行综合查询 -->
|
||||
<if test="(dto.key != null and dto.key != '')">
|
||||
and (catelog_id = #{dto.key} or attr_group_name like CONCAT('%',#{dto.key},'%'))
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.mall.product.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.mall.product.service.CategoryService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
class CategoryServiceImplTest {
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
List<Long> catelogPath = categoryService.findCatelogPath(225L);
|
||||
System.out.println(JSON.toJSONString(catelogPath));
|
||||
}
|
||||
|
||||
}
|
|
@ -78,6 +78,11 @@
|
|||
<!-- <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 前端美化相关 -->
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
|
|
Loading…
Reference in New Issue