diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java index c77a98e2..d525f2fd 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java @@ -116,6 +116,8 @@ public class Type extends BaseEntity { @Excel(name = "排序") private int sortNum; + @ApiModelProperty(value = "最大排序,用于Tree排序") + private transient int maxSortPriority; /** 管理方式(0编号 1计数) */ @Excel(name = "管理方式(0编号 1计数)", readConverterExp = "0=编号,1=计数") 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 56c2f956..efcec795 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 @@ -85,18 +85,68 @@ public class TypeServiceImpl implements ITypeService { @Override public List getEquipmentType(Long typeId, String typeName) { List maTypes = typeMapper.selectMaTypeList(typeId, typeName); - List list = new ArrayList<>(); - for (Type maType : maTypes) { - if (maType.getParentId() == 0) { - list.add(maType); + List roots = maTypes.stream() + .filter(t -> t.getParentId() == 0) + .collect(Collectors.toList()); + + // 构建树并计算优先级 + roots.forEach(root -> buildTreeWithPriority(root, maTypes)); + + // 对根节点排序(含0值处理) + roots.sort(this::compareNodes); + return roots; + } + + /** + * 递归构建树结构并计算排序优先级 + */ + private void buildTreeWithPriority(Type node, List allNodes) { + List children = allNodes.stream() + .filter(n -> node.getTypeId().equals(n.getParentId())) + .collect(Collectors.toList()); + + // 递归处理子节点 + children.forEach(child -> buildTreeWithPriority(child, allNodes)); + + // 计算当前节点优先级 + if ("4".equals(node.getLevel())) { + node.setMaxSortPriority(node.getSortNum() > 0 ? node.getSortNum() : 0); + } else { + node.setMaxSortPriority(children.stream() + .mapToInt(Type::getMaxSortPriority) + .max() + .orElse(0)); + } + + // 对子节点排序(含0值处理) + children.sort(this::compareNodes); + node.setChildren(children); + } + + /** + * 自定义节点比较器(保证0值最后) + */ + private int compareNodes(Type a, Type b) { + return Integer.compare(b.getMaxSortPriority(), a.getMaxSortPriority()); + } + + /** + * 递归调用获取子级 + * @param list 集合 + * @param parentId 父级id + */ + public List getChild(List list, Long parentId) { + List childList = new ArrayList(); + for (Type maType : list) { + Long typeId = maType.getTypeId(); + Long pid = maType.getParentId(); + if (parentId.equals(pid)) { + List childLists = getChild(list, typeId); + maType.setChildren(childLists); + childList.add(maType); } } - //根据父节点获取对应的儿子节点 - for (Type maType : list) { - List child = getChild(maTypes, maType.getTypeId()); - maType.setChildren(child); - } - return list; + return childList; } @Override @@ -564,24 +614,7 @@ public class TypeServiceImpl implements ITypeService { return new TreeSelect(type.getTypeId(), type.getTypeName(), type.getHouseId(), Integer.valueOf(type.getLevel()),type.getParentId(), children); } - /** - * 递归调用获取子级 - * @param list 集合 - * @param parentId 父级id - */ - public List getChild(List list, Long parentId) { - List childList = new ArrayList(); - for (Type maType : list) { - Long typeId = maType.getTypeId(); - Long pid = maType.getParentId(); - if (parentId.equals(pid)) { - List childLists = getChild(list, typeId); - maType.setChildren(childLists); - childList.add(maType); - } - } - return childList; - } + /** * 构建前端所需要树结构 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java index 2d64295e..4da58e34 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java @@ -97,18 +97,21 @@ public class IwsCostPushBean implements Serializable { private String type; - // 原值 + /** + * 原值 + */ private String buyPrice; - // 是否推送 @Excel(name = "是否推送", readConverterExp = "0=未推送,1=已推送") private String isPush; private String money; + /** + * 年 yyyy + */ private String year; - // 是否结算 @Excel(name = "是否结算", readConverterExp = "0=未结算,1=已结算", sort = 6) private Byte isSettlement = 0; diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/IwsCostPushService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/IwsCostPushService.java index 56432a4a..f0c8938d 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/IwsCostPushService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/IwsCostPushService.java @@ -19,7 +19,6 @@ public interface IwsCostPushService { */ List findAgreement(IwsCostPushBean o); - /** * 查询费用推送审核数据列表 */ diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java index 1e4fc380..80f7a95a 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java @@ -21,6 +21,8 @@ import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAdjusters; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @author : 阮世耀 @@ -47,7 +49,17 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { */ @Override public List findAgreement(IwsCostPushBean o) { - return iwsCostPushMapper.findAgreement(o); + List pushBeanList = iwsCostPushMapper.findAgreement(o); + + // 使用流式操作过滤掉null值,并设置isMatch属性 + return pushBeanList.stream() + .filter(Objects::nonNull) + .peek(bean -> { + if (StringUtils.isNotBlank(bean.getProjectId()) && StringUtils.isNotBlank(bean.getProjectCode())) { + bean.setIsMatch((byte) 1); + } + }) + .collect(Collectors.toList()); } /** 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 f216dc96..48329534 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 @@ -495,7 +495,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"