Commit e76b86c2 by yubin

Merge remote-tracking branch 'origin/master'

parents 9a9aa266 dec88768
......@@ -42,3 +42,11 @@ export function delMaterials_category(id) {
method: 'delete'
})
}
// 查询部门下拉树结构
export function categoryTreeSelect() {
return request({
url: '/inventory/materials_category/categoryTree',
method: 'get'
})
}
\ No newline at end of file
<template>
<div class="tree-container" :style="containerStyle">
<!-- 搜索框 -->
<div class="tree-header" v-if="showSearch">
<el-input
v-model="searchText"
:placeholder="searchPlaceholder"
clearable
size="small"
prefix-icon="el-icon-search"
@input="handleSearch"
style="width: 100%; margin-bottom: 10px;"
/>
</div>
<!-- 树组件 -->
<div class="tree-body" :style="treeBodyStyle">
<el-tree
v-if="treeData && treeData.length > 0"
ref="treeRef"
:data="filteredTreeData"
:props="treeProps"
:node-key="nodeKey"
:default-expand-all="defaultExpandAll"
:expand-on-click-node="expandOnClickNode"
:highlight-current="highlightCurrent"
:filter-node-method="filterNodeMethod"
:empty-text="emptyText"
:style="treeStyle"
@node-click="handleNodeClick"
@node-expand="handleNodeExpand"
@node-collapse="handleNodeCollapse"
@current-change="handleCurrentChange"
>
<!-- 自定义节点内容插槽 -->
<template #default="{ node, data }">
<slot name="node-content" :node="node" :data="data">
<span class="custom-tree-node">
<span>{{ node.label }}</span>
</span>
</slot>
</template>
</el-tree>
<!-- 空状态 -->
<div v-else class="tree-empty">
<slot name="empty">
<div style="padding: 20px; text-align: center; color: #999;">
{{ loading ? '加载中...' : '暂无数据' }}
</div>
</slot>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'TreeComponent',
props: {
// 树数据
treeData: {
type: Array,
default: () => []
},
// 树配置
treeProps: {
type: Object,
default: () => ({
children: 'children',
label: 'label',
value: 'sid'
})
},
// 节点key
nodeKey: {
type: String,
default: 'sid'
},
// 是否显示搜索框
showSearch: {
type: Boolean,
default: true
},
// 搜索框占位符
searchPlaceholder: {
type: String,
default: '请输入搜索内容'
},
// 是否默认展开所有节点
defaultExpandAll: {
type: Boolean,
default: true
},
// 是否点击节点时展开
expandOnClickNode: {
type: Boolean,
default: false
},
// 是否高亮当前选中节点
highlightCurrent: {
type: Boolean,
default: true
},
// 容器样式
containerStyle: {
type: Object,
default: () => ({
height: '100%',
padding: '10px'
})
},
// 树容器样式
treeBodyStyle: {
type: Object,
default: () => ({
height: 'calc(100% - 50px)',
overflow: 'auto'
})
},
// 树样式
treeStyle: {
type: Object,
default: () => ({})
},
// 空状态文本
emptyText: {
type: String,
default: '暂无数据'
},
// 加载状态
loading: {
type: Boolean,
default: false
},
// 初始选中的节点key
defaultSelectedKey: {
type: [String, Number],
default: null
}
},
data() {
return {
searchText: '',
filteredTreeData: [],
selectedNode: null
}
},
watch: {
treeData: {
immediate: true,
handler(newData) {
this.filteredTreeData = newData
this.$nextTick(() => {
if (this.defaultSelectedKey && this.$refs.treeRef) {
this.$refs.treeRef.setCurrentKey(this.defaultSelectedKey)
}
})
}
},
defaultSelectedKey: {
immediate: true,
handler(newKey) {
if (newKey && this.$refs.treeRef) {
this.$refs.treeRef.setCurrentKey(newKey)
}
}
}
},
methods: {
/**
* 过滤节点方法
*/
filterNodeMethod(value, data, node) {
if (!value) return true
const label = data[this.treeProps.label] || ''
return label.toLowerCase().includes(value.toLowerCase())
},
/**
* 处理搜索
*/
handleSearch(value) {
this.$refs.treeRef.filter(value)
},
/**
* 节点点击事件
*/
handleNodeClick(data, node, component) {
this.selectedNode = { data, node, component }
this.$emit('node-click', data, node, component)
},
/**
* 节点展开事件
*/
handleNodeExpand(data, node, component) {
this.$emit('node-expand', data, node, component)
},
/**
* 节点折叠事件
*/
handleNodeCollapse(data, node, component) {
this.$emit('node-collapse', data, node, component)
},
/**
* 当前节点变化事件
*/
handleCurrentChange(data, node) {
this.$emit('current-change', data, node)
},
/**
* 重置树结构
*/
resetTree() {
// 修复:使用正确的 ref 名称 treeRef
if (this.$refs.treeRef) {
this.$refs.treeRef.setCurrentKey(null);
this.searchText = '';
this.$refs.treeRef.filter(''); // 清空搜索
}
},
/**
* 设置当前选中的节点
*/
setCurrentNode(node) {
this.$refs.treeRef.setCurrentNode(node)
},
/**
* 设置当前选中的节点key
*/
setCurrentKey(key) {
this.$refs.treeRef.setCurrentKey(key)
},
/**
* 获取当前选中的节点
*/
getCurrentNode() {
return this.$refs.treeRef.getCurrentNode()
},
/**
* 获取当前选中的节点key
*/
getCurrentKey() {
return this.$refs.treeRef.getCurrentKey()
},
/**
* 展开指定节点
*/
expandNode(node) {
this.$refs.treeRef.expandNode(node)
},
/**
* 折叠指定节点
*/
collapseNode(node) {
this.$refs.treeRef.collapseNode(node)
},
/**
* 展开所有节点
*/
expandAll() {
this.$refs.treeRef.expandAll()
},
/**
* 折叠所有节点
*/
collapseAll() {
this.$refs.treeRef.collapseAll()
},
/**
* 更新节点数据
*/
updateKeyChildren(key, data) {
this.$refs.treeRef.updateKeyChildren(key, data)
},
/**
* 获取节点信息
*/
getNode(key) {
return this.$refs.treeRef.getNode(key)
},
/**
* 移除节点
*/
remove(key) {
this.$refs.treeRef.remove(key)
},
/**
* 追加节点数据
*/
append(data, parentNode) {
this.$refs.treeRef.append(data, parentNode)
},
/**
* 插入节点数据
*/
insertBefore(data, refNode) {
this.$refs.treeRef.insertBefore(data, refNode)
},
/**
* 插入节点数据后
*/
insertAfter(data, refNode) {
this.$refs.treeRef.insertAfter(data, refNode)
}
}
}
</script>
<style scoped>
.tree-container {
height: 100%;
display: flex;
flex-direction: column;
}
.tree-header {
flex-shrink: 0;
}
.tree-body {
flex: 1;
overflow: auto;
}
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
.tree-empty {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: #999;
}
</style>
\ No newline at end of file
......@@ -9,7 +9,16 @@
<el-input v-model="deptName" placeholder="请输入部门名称" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" />
</div>
<div class="head-container">
<el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current @node-click="handleNodeClick" />
<el-tree
:data="deptOptions"
:props="defaultProps"
:expand-on-click-node="false"
:filter-node-method="filterNode"
ref="tree"
node-key="id"
default-expand-all
highlight-current
@node-click="handleNodeClick" />
</div>
</el-col>
</pane>
......
......@@ -3,6 +3,7 @@ package com.ruoyi.web.controller.inventory;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.uuid.UUID;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -18,7 +19,7 @@ import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.inventory.domain.MaterialsCategory;
import com.ruoyi.common.core.domain.entity.MaterialsCategory;
import com.ruoyi.inventory.service.IMaterialsCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
......@@ -72,6 +73,16 @@ public class MaterialsCategoryController extends BaseController
}
/**
* 获取分类树结构
*/
@PreAuthorize("@ss.hasPermi('inventory:materials_category:list')")
@GetMapping("/categoryTree")
public AjaxResult categoryTree(MaterialsCategory materialsCategory)
{
return success(materialsCategoryService.selectMaterialsCategoryTreeList(materialsCategory));
}
/**
* 新增物料分类
*/
@PreAuthorize("@ss.hasPermi('inventory:materials_category:add')")
......
......@@ -63,6 +63,7 @@ public class UserConstants
/** InnerLink组件标识 */
public final static String INNER_LINK = "InnerLink";
/** 校验是否唯一的返回标识 */
public final static boolean UNIQUE = true;
public final static boolean NOT_UNIQUE = false;
......
......@@ -5,6 +5,7 @@ import java.util.List;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.MaterialsCategory;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.utils.StringUtils;
......@@ -21,6 +22,8 @@ public class TreeSelect implements Serializable
/** 节点ID */
private String id;
/** String节点ID */
private String sid;
/** 节点名称 */
private String label;
......@@ -43,7 +46,12 @@ public class TreeSelect implements Serializable
this.disabled = StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus());
this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public TreeSelect(MaterialsCategory materialsCategory){
this.sid = materialsCategory.getId();
this.label = materialsCategory.getCategoryName();
this.disabled = StringUtils.equals(String.valueOf(0), String.valueOf(materialsCategory.getIsUsed()));
this.children = materialsCategory.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public TreeSelect(SysMenu menu)
{
this.id = String.valueOf(menu.getMenuId());
......@@ -90,4 +98,12 @@ public class TreeSelect implements Serializable
{
this.children = children;
}
public String getSid() {
return sid;
}
public void setSid(String sid) {
this.sid = sid;
}
}
package com.ruoyi.inventory.domain;
package com.ruoyi.common.core.domain.entity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import java.util.ArrayList;
import java.util.List;
/**
* 物料分类对象 materials_category
*
......@@ -31,6 +34,15 @@ public class MaterialsCategory extends BaseEntity
@Excel(name = "排序")
private Long sortNo;
@Excel(name = "父级Code")
private String parentId;
@Excel(name = "使用状态")
private int isUsed;
private String parentName;
private List<MaterialsCategory> children = new ArrayList<MaterialsCategory>();
/** 创建日期 */
private String createUserCode;
......@@ -97,6 +109,38 @@ public class MaterialsCategory extends BaseEntity
return updateUserCode;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public int getIsUsed() {
return isUsed;
}
public void setIsUsed(int isUsed) {
this.isUsed = isUsed;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
public List<MaterialsCategory> getChildren() {
return children;
}
public void setChildren(List<MaterialsCategory> children) {
this.children = children;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
......@@ -108,6 +152,10 @@ public class MaterialsCategory extends BaseEntity
.append("createUserCode", getCreateUserCode())
.append("updateTime", getUpdateTime())
.append("updateUserCode", getUpdateUserCode())
.append("parentId", getParentId())
.append("isUsed", getIsUsed())
.append("parentName", getParentName())
.append("children", getChildren())
.toString();
}
}
......@@ -22,5 +22,6 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.ruoyi.inventory.mapper;
import java.util.List;
import com.ruoyi.inventory.domain.MaterialsCategory;
import com.ruoyi.common.core.domain.entity.MaterialsCategory;
/**
* 物料分类Mapper接口
......@@ -18,7 +18,6 @@ public interface MaterialsCategoryMapper
* @return 物料分类
*/
public MaterialsCategory selectMaterialsCategoryById(String id);
/**
* 查询物料分类列表
*
......
......@@ -61,7 +61,12 @@ public interface MaterialsMapper
* @return 结果
*/
public int deleteMaterialsByIds(String[] ids);
/**
* 批量删除,修改物料的使用状态
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int updateMaterialsIsUsedByIds(String[] ids);
}
package com.ruoyi.inventory.service;
import java.util.List;
import com.ruoyi.inventory.domain.MaterialsCategory;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.entity.MaterialsCategory;
/**
* 物料分类Service接口
......@@ -28,6 +30,30 @@ public interface IMaterialsCategoryService
public List<MaterialsCategory> selectMaterialsCategoryList(MaterialsCategory materialsCategory);
/**
* 查询分类树结构
*
* @param materialsCategory 物料分类
* @return 结果
*/
public List<TreeSelect> selectMaterialsCategoryTreeList(MaterialsCategory materialsCategory);
/**
* 构建前端所需要树结构
*
* @param materialsCategorys 物料分类
* @return 结果
*/
public List<MaterialsCategory> buildMaterialsCategoryTree(List<MaterialsCategory> materialsCategorys);
/**
* 构建前端所需要下拉树结构
*
* @param materialsCategorys 物料分类
* @return 结果
*/
public List<TreeSelect> buildTreeSelect(List<MaterialsCategory> materialsCategorys);
/**
* 新增物料分类
*
* @param materialsCategory 物料分类
......
package com.ruoyi.inventory.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.inventory.mapper.MaterialsCategoryMapper;
import com.ruoyi.inventory.domain.MaterialsCategory;
import com.ruoyi.common.core.domain.entity.MaterialsCategory;
import com.ruoyi.inventory.service.IMaterialsCategoryService;
/**
......@@ -43,6 +51,86 @@ public class MaterialsCategoryServiceImpl implements IMaterialsCategoryService
{
return materialsCategoryMapper.selectMaterialsCategoryList(materialsCategory);
}
/**
* 查询分类树结构
*
* @param materialsCategory 物料分类
* @return 结果
*/
@Override
public List<TreeSelect> selectMaterialsCategoryTreeList(MaterialsCategory materialsCategory)
{
List<MaterialsCategory> materialsCategorys = SpringUtils.getAopProxy(this).selectMaterialsCategoryList(materialsCategory);
return buildTreeSelect(materialsCategorys);
}
/**
* 构建前端所需要树结构
*
* @param materialsCategorys 物料分类
* @return 结果
*/
@Override
public List<MaterialsCategory> buildMaterialsCategoryTree(List<MaterialsCategory> materialsCategorys) {
List<MaterialsCategory> returnList = new ArrayList<MaterialsCategory>();
// List<String> tempList = materialsCategorys.stream().map(MaterialsCategory::getId).collect(Collectors.toList());
for (MaterialsCategory materialsCategory : materialsCategorys) {
// 如果是顶级节点, 遍历该父节点的所有子节点
if (StringUtils.isNull(materialsCategory.getParentId()) || materialsCategory.getParentId().isEmpty()){
recursionFn(materialsCategorys, materialsCategory);
returnList.add(materialsCategory);
}
}
if (returnList.isEmpty()){
returnList = materialsCategorys;
}
return returnList;
}
/**
* 递归列表
*/
private void recursionFn(List<MaterialsCategory> materialsCategoryList, MaterialsCategory materialsCategory) {
// 得到子节点列表
List<MaterialsCategory> childList = getChildList(materialsCategoryList, materialsCategory);
materialsCategory.setChildren(childList);
// 如果有子节点,递归处理
if (!childList.isEmpty()) {
for (MaterialsCategory child : childList) {
recursionFn(materialsCategoryList, child);
}
}
}
/**
* 得到子节点列表
*/
private List<MaterialsCategory> getChildList(List<MaterialsCategory> list, MaterialsCategory materialsCategory){
List<MaterialsCategory> childList = new ArrayList<>();
Iterator<MaterialsCategory> iterator = list.iterator();
while (iterator.hasNext()){
MaterialsCategory m = (MaterialsCategory) iterator.next();
if (StringUtils.equals(m.getParentId(), materialsCategory.getId())){
childList.add(m);
}
}
return childList;
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<MaterialsCategory> list, MaterialsCategory m){
return getChildList(list, m).size() > 0;
}
/**
* 构建前端所需要下拉树结构
*
* @param materialsCategorys 物料分类
* @return 结果
*/
@Override
public List<TreeSelect> buildTreeSelect(List<MaterialsCategory> materialsCategorys) {
List<MaterialsCategory> materialsCategories = buildMaterialsCategoryTree(materialsCategorys);
return materialsCategories.stream().map(TreeSelect::new).collect(Collectors.toList());
}
/**
* 新增物料分类
......
......@@ -13,20 +13,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createUserCode" column="create_user_code" />
<result property="updateTime" column="update_time" />
<result property="updateUserCode" column="update_user_code" />
<result property="parentId" column="parent_id" />
<result property="isUsed" column="is_used" />
</resultMap>
<sql id="selectMaterialsCategoryVo">
select id, category_code, category_name, sort_no, create_time, create_user_code, update_time, update_user_code from materials_category
select id, category_code, category_name, sort_no, create_time, create_user_code, update_time, update_user_code, parent_id, is_used from materials_category
</sql>
<select id="selectMaterialsCategoryList" parameterType="MaterialsCategory" resultMap="MaterialsCategoryResult">
<include refid="selectMaterialsCategoryVo"/>
<where>
<if test="id != null and id != ''"> and id = #{id}</if>
<if test="categoryCode != null and categoryCode != ''"> and category_code like concat('%', #{categoryCode}, '%')</if>
<if test="categoryName != null and categoryName != ''"> and category_name like concat('%', #{categoryName}, '%')</if>
<if test="sortNo != null "> and sort_no = #{sortNo}</if>
<if test="createTime != null "> and create_time like concat('%', #{createTime}, '%')</if>
<if test="updateTime != null "> and update_time like concat('%', #{updateTime}, '%')</if>
<if test="parentId != null "> and parent_id = #{parentId}</if>
</where>
order by sort_no asc
</select>
......@@ -48,6 +52,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createUserCode != null">create_user_code,</if>
<if test="updateTime != null">update_time,</if>
<if test="updateUserCode != null">update_user_code,</if>
<if test="parentId != null">parent_id,</if>
<if test="isUsed != null">is_used,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
......@@ -58,6 +64,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createUserCode != null">#{createUserCode},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="updateUserCode != null">#{updateUserCode},</if>
<if test="parentId != null">#{parentId},</if>
<if test="isUsed != null">#{isUsed},</if>
</trim>
</insert>
......@@ -71,6 +79,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createUserCode != null">create_user_code = #{createUserCode},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="updateUserCode != null">update_user_code = #{updateUserCode},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="isUsed != null">is_used = #{isUsed},</if>
</trim>
where id = #{id}
</update>
......
......@@ -46,7 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="materialName != null and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
<if test="sapNo != null and sapNo != ''"> and sap_no like concat('%', #{sapNo}, '%')</if>
<if test="tsCode != null and tsCode != ''"> and ts_code like concat('%', #{tsCode}, '%')</if>
<if test="categoryCode != null and categoryCode != ''"> and category_code like concat('%', #{categoryCode}, '%')</if>
<if test="categoryCode != null and categoryCode != ''"> and category_code = #{categoryCode}</if>
<if test="hazardId != null and hazardId != ''"> and hazard_id like concat('%', #{hazardId}, '%')</if>
<if test="specification != null and specification != ''"> and specification like concat('%', #{specification}, '%')</if>
<if test="materialUnit != null and materialUnit != ''"> and material_unit like concat('%', #{materialUnit}, '%')</if>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论