From 09c8b9f1010b23ce8ac39f4d4bb0d980722b6d41 Mon Sep 17 00:00:00 2001 From: syruan <321359594@qq.com> Date: Mon, 14 Oct 2024 18:07:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E8=B5=84=E7=B1=BB=E5=9E=8B=E7=AE=A1?= =?UTF-8?q?=E7=90=86--=E4=BC=98=E5=8C=96=E9=80=92=E5=BD=92=E9=80=BB?= =?UTF-8?q?=E8=BE=91,=E6=96=B0=E5=A2=9Evo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bonus/common/biz}/domain/TreeSelect.java | 16 +++++----- .../ma/controller/TypeController.java | 6 ++-- .../material/ma/service/ITypeService.java | 2 +- .../ma/service/impl/TypeServiceImpl.java | 31 ++++++++++++++----- .../bonus/material/ma/vo/MaTypeListVo.java | 26 ++++++++++++++++ .../mapper/material/ma/TypeMapper.xml | 6 ++-- 6 files changed, 63 insertions(+), 24 deletions(-) rename {bonus-modules/bonus-material/src/main/java/com/bonus/material/ma => bonus-common-biz/src/main/java/com/bonus/common/biz}/domain/TreeSelect.java (60%) create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/vo/MaTypeListVo.java diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/TreeSelect.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/TreeSelect.java similarity index 60% rename from bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/TreeSelect.java rename to bonus-common-biz/src/main/java/com/bonus/common/biz/domain/TreeSelect.java index e3c3a14c..31c0eaad 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/TreeSelect.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/TreeSelect.java @@ -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 children) { + this.id = id; + this.label = label; + this.level = level; + this.parentId = parentId; + this.children = children; } } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java index 8b18c1aa..ff9b3886 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java @@ -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; /** diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java index 5b1fd50f..6bf2a072 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java @@ -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; /** diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java index 08038f88..9503c198 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java @@ -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 selectTypeList(Type type) - { + public List 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 getMaTypeTree(String typeName, String parentId) { List maTypes = typeMapper.selectMaTypeTree(TYPE_MIN_LEVEL); List 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 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 getChildList(List list, Type t) { - List tlist = new ArrayList(); + List tlist = new ArrayList<>(); for (Type n : list) { if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getTypeId().longValue()) { tlist.add(n); diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/vo/MaTypeListVo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/vo/MaTypeListVo.java new file mode 100644 index 00000000..377c8c22 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/vo/MaTypeListVo.java @@ -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; + +} diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml index 88d537fa..094ed06d 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml @@ -58,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and rent_price = #{rentPrice} and buy_price = #{buyPrice} and pay_ratio = #{payRatio} - and level = #{level} + and `level` = #{level} and rated_load = #{ratedLoad} and test_load = #{testLoad} and holding_time = #{holdingTime} @@ -91,7 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" rent_price, buy_price, pay_ratio, - level, + `level`, rated_load, test_load, holding_time, @@ -151,7 +151,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" rent_price = #{rentPrice}, buy_price = #{buyPrice}, pay_ratio = #{payRatio}, - level = #{level}, + `level` = #{level}, rated_load = #{ratedLoad}, test_load = #{testLoad}, holding_time = #{holdingTime},