物资类型管理--优化递归逻辑,新增vo

This commit is contained in:
syruan 2024-10-14 18:07:00 +08:00
parent 40cb13324d
commit 09c8b9f101
6 changed files with 63 additions and 24 deletions

View File

@ -1,11 +1,10 @@
package com.bonus.material.ma.domain;
package com.bonus.common.biz.domain;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
/**
* TreeSelect树结构实体类
@ -39,13 +38,12 @@ public class TreeSelect implements Serializable {
}
public TreeSelect(Type maType) {
this.parentId = maType.getParentId();
this.level = Integer.valueOf(maType.getLevel());
this.id = maType.getTypeId();
this.label = maType.getTypeName();
this.companyId = String.valueOf(maType.getUnitId());
this.children = maType.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
public TreeSelect(Long id, String label, Integer level, Long parentId, List<TreeSelect> children) {
this.id = id;
this.label = label;
this.level = level;
this.parentId = parentId;
this.children = children;
}
}

View File

@ -1,13 +1,13 @@
package com.bonus.material.ma.controller;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.material.ma.domain.TreeSelect;
import com.bonus.common.biz.domain.TreeSelect;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.security.annotation.RequiresPermissions;
@ -27,7 +27,7 @@ import com.bonus.common.core.web.page.TableDataInfo;
@RequestMapping("/ma_type")
public class TypeController extends BaseController {
@Autowired
@Resource
private ITypeService typeService;
/**

View File

@ -2,7 +2,7 @@ package com.bonus.material.ma.service;
import java.util.List;
import com.bonus.material.ma.domain.TreeSelect;
import com.bonus.common.biz.domain.TreeSelect;
import com.bonus.material.ma.domain.Type;
/**

View File

@ -2,9 +2,10 @@ package com.bonus.material.ma.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import com.bonus.material.ma.domain.TreeSelect;
import com.bonus.common.biz.domain.TreeSelect;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.StringUtils;
import org.springframework.stereotype.Service;
@ -46,8 +47,11 @@ public class TypeServiceImpl implements ITypeService {
* @return 物资类型管理
*/
@Override
public List<Type> selectTypeList(Type type)
{
public List<Type> selectTypeList(Type type) {
// 如果是顶级节点则查询所有子节点
if (type != null && "0".equals(type.getLevel())) {
type.setLevel(null);
}
return typeMapper.selectTypeList(type);
}
@ -82,8 +86,7 @@ public class TypeServiceImpl implements ITypeService {
* @return 结果
*/
@Override
public int deleteTypeByTypeIds(Long[] typeIds)
{
public int deleteTypeByTypeIds(Long[] typeIds) {
return typeMapper.logicDeleteTypeByTypeIds(typeIds);
}
@ -103,8 +106,20 @@ public class TypeServiceImpl implements ITypeService {
public List<TreeSelect> getMaTypeTree(String typeName, String parentId) {
List<Type> maTypes = typeMapper.selectMaTypeTree(TYPE_MIN_LEVEL);
List<Type> treeSelectList = buildMaTypeTree(maTypes);
//如果没有查询到那么返回空
return treeSelectList.stream().map(TreeSelect::new).collect(Collectors.toList());
// 如果没有查询到那么返回空
return treeSelectList.stream()
.filter(Objects::nonNull)
.map(this::convertToTreeSelect)
.collect(Collectors.toList());
}
private TreeSelect convertToTreeSelect(Type type) {
List<TreeSelect> children = type.getChildren().stream()
.filter(Objects::nonNull)
.map(this::convertToTreeSelect)
.collect(Collectors.toList());
return new TreeSelect(type.getTypeId(), type.getTypeName(),Integer.valueOf(type.getLevel()),type.getParentId(), children);
}
/**
@ -148,7 +163,7 @@ public class TypeServiceImpl implements ITypeService {
* 得到子节点列表
*/
private List<Type> getChildList(List<Type> list, Type t) {
List<Type> tlist = new ArrayList<Type>();
List<Type> tlist = new ArrayList<>();
for (Type n : list) {
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getTypeId().longValue()) {
tlist.add(n);

View File

@ -0,0 +1,26 @@
package com.bonus.material.ma.vo;
import com.bonus.material.ma.domain.Type;
import lombok.Getter;
import lombok.Setter;
/**
* @author : 阮世耀
* @version : 1.0
* @PackagePath: com.bonus.material.ma.vo
* @CreateTime: 2024-10-14 17:47
* @Description: 物资类型列表展示VO
*/
@Getter
@Setter
public class MaTypeListVo extends Type {
private String parentOneLevelName;
private String parentTwoLevelName;
private String parentThreeLevelName;
private String parentFourLevelName;
}

View File

@ -58,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="rentPrice != null "> and rent_price = #{rentPrice}</if>
<if test="buyPrice != null "> and buy_price = #{buyPrice}</if>
<if test="payRatio != null "> and pay_ratio = #{payRatio}</if>
<if test="level != null and level != ''"> and level = #{level}</if>
<if test="level != null and level != ''"> and `level` = #{level}</if>
<if test="ratedLoad != null and ratedLoad != ''"> and rated_load = #{ratedLoad}</if>
<if test="testLoad != null and testLoad != ''"> and test_load = #{testLoad}</if>
<if test="holdingTime != null "> and holding_time = #{holdingTime}</if>
@ -91,7 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="rentPrice != null">rent_price,</if>
<if test="buyPrice != null">buy_price,</if>
<if test="payRatio != null">pay_ratio,</if>
<if test="level != null">level,</if>
<if test="level != null">`level`,</if>
<if test="ratedLoad != null">rated_load,</if>
<if test="testLoad != null">test_load,</if>
<if test="holdingTime != null">holding_time,</if>
@ -151,7 +151,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="rentPrice != null">rent_price = #{rentPrice},</if>
<if test="buyPrice != null">buy_price = #{buyPrice},</if>
<if test="payRatio != null">pay_ratio = #{payRatio},</if>
<if test="level != null">level = #{level},</if>
<if test="level != null">`level` = #{level},</if>
<if test="ratedLoad != null">rated_load = #{ratedLoad},</if>
<if test="testLoad != null">test_load = #{testLoad},</if>
<if test="holdingTime != null">holding_time = #{holdingTime},</if>