首页类目搜索

This commit is contained in:
mashuai 2024-11-22 13:04:43 +08:00
parent f83de238b6
commit 37ac0556e8
7 changed files with 225 additions and 0 deletions

View File

@ -0,0 +1,39 @@
package com.bonus.material.home.controller;
import cn.hutool.core.lang.tree.Tree;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.material.home.service.MaTypeInfoSevice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* 首页搜索分类
* @author ma_sh
*/
@Api(value = "搜索分类",tags = {"搜索分类"})
@RestController
@RequestMapping("/maType")
public class MaTypeInfoController extends BaseController {
@Resource
private MaTypeInfoSevice maTypeInfoSevice;
/**
* 搜索分类
* @return
*/
@ApiOperation("首页搜索分类树")
@GetMapping("/getEquipmentType")
public TableDataInfo getEquipmentType() {
List<Tree<Long>> list = maTypeInfoSevice.getMaTypeInfoList();
return getDataTable(list);
}
}

View File

@ -0,0 +1,69 @@
package com.bonus.material.home.domain;
import com.bonus.common.core.annotation.Excel;
import com.bonus.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.util.ArrayList;
import java.util.List;
/**
* 设备类型对象 ma_type_info
*
* @author xsheng
* @date 2023-12-02
*/
@Data
@ToString
@ApiModel("设备类型对象")
public class TypeInfo extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 类型id */
@Excel(name = "类型id")
@ApiModelProperty(value = "类型id", required = true)
private Long typeId;
/** 父级id */
@Excel(name = "父级id")
@ApiModelProperty(value = "父级id", required = true)
private Long parentId;
/** 类型名称 */
@Excel(name = "类型名称")
@ApiModelProperty(value = "类型名称", required = true)
private String typeName;
/** 计量单位 */
@Excel(name = "计量单位")
@ApiModelProperty(value = "计量单位", required = true)
private String unitName;
/** 层级 */
@Excel(name = "层级")
@ApiModelProperty(value = "层级", required = true)
private String level;
/** 排序 */
@Excel(name = "排序")
@ApiModelProperty(value = "排序", required = true)
private String sort;
/** 是否删除 */
@Excel(name = "是否删除")
@ApiModelProperty(value = "是否删除", required = true)
private String delFlag;
/** 父部门名称 */
@ApiModelProperty(value = "父部门名称", required = true)
private String parentName;
/** 子部门 */
@ApiModelProperty(value = "子部门", required = true)
private List<TypeInfo> children = new ArrayList<TypeInfo>();
}

View File

@ -0,0 +1,20 @@
package com.bonus.material.home.mapper;
import com.bonus.material.home.domain.TypeInfo;
import java.util.List;
/**
* 设备类型对象
* @author ma_sh
*/
public interface MaTypeInfoMapper {
/**
* 查询设备类型列表
* @return
*/
public List<TypeInfo> getMaTypeInfoList() ;
}

View File

@ -0,0 +1,18 @@
package com.bonus.material.home.service;
import cn.hutool.core.lang.tree.Tree;
import java.util.List;
/**
* @author ma_sh
*/
public interface MaTypeInfoSevice {
/**
* 查询分类树
* @return
*/
public List<Tree<Long>> getMaTypeInfoList();
}

View File

@ -0,0 +1,49 @@
package com.bonus.material.home.service.impl;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import com.bonus.material.home.domain.TypeInfo;
import com.bonus.material.home.mapper.MaTypeInfoMapper;
import com.bonus.material.home.service.MaTypeInfoSevice;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class MaTypeInfoServiceImpl implements MaTypeInfoSevice {
@Resource
private MaTypeInfoMapper maTypeInfoMapper;
/**
* 首页查询分类树
* @return
*/
@Override
public List<Tree<Long>> getMaTypeInfoList() {
List<TypeInfo> maTypeInfoList = maTypeInfoMapper.getMaTypeInfoList();
List<TreeNode<Long>> collect = maTypeInfoList
.stream().map(getNodeFunction()).collect(Collectors.toList());
return TreeUtil.build(collect,0L);
}
/**
* 获取节点转换函数方法抽取
* @return
*/
private Function<TypeInfo, TreeNode<Long>> getNodeFunction() {
return typeInfo -> {
TreeNode<Long> node = new TreeNode<>();
node.setId(typeInfo.getTypeId());
node.setName(typeInfo.getTypeName());
node.setParentId(typeInfo.getParentId());
node.setWeight(typeInfo.getLevel());
return node;
};
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.material.home.mapper.MaTypeInfoMapper">
<resultMap type="com.bonus.material.home.domain.TypeInfo" id="MaDevInfoResult">
<id property="typeId" column="type_id" />
<result property="parentId" column="parent_id" />
<result property="typeName" column="type_name" />
<result property="level" column="level" />
<result property="delFlag" column="del_flag" />
</resultMap>
<sql id="bmProjectInfo">
select type_id, parent_id, type_name, `level`, del_flag
from ma_type
where del_flag = '0'
</sql>
<select id="getMaTypeInfoList" resultType="com.bonus.material.home.domain.TypeInfo">
select type_id as typeId, parent_id as parentId, type_name as typeName, `level` as level, del_flag as delFlag
from ma_type
where del_flag = '0'
</select>
</mapper>