物资类型规格排序

This commit is contained in:
syruan 2025-02-18 17:34:21 +08:00
parent a72cebcb00
commit f0ed1244d0
6 changed files with 83 additions and 34 deletions

View File

@ -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=计数")

View File

@ -85,18 +85,68 @@ public class TypeServiceImpl implements ITypeService {
@Override
public List<Type> getEquipmentType(Long typeId, String typeName) {
List<Type> maTypes = typeMapper.selectMaTypeList(typeId, typeName);
List<Type> list = new ArrayList<>();
for (Type maType : maTypes) {
if (maType.getParentId() == 0) {
list.add(maType);
List<Type> 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<Type> allNodes) {
List<Type> 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<Type> getChild(List<Type> list, Long parentId) {
List<Type> childList = new ArrayList<Type>();
for (Type maType : list) {
Long typeId = maType.getTypeId();
Long pid = maType.getParentId();
if (parentId.equals(pid)) {
List<Type> childLists = getChild(list, typeId);
maType.setChildren(childLists);
childList.add(maType);
}
}
//根据父节点获取对应的儿子节点
for (Type maType : list) {
List<Type> 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<Type> getChild(List<Type> list, Long parentId) {
List<Type> childList = new ArrayList<Type>();
for (Type maType : list) {
Long typeId = maType.getTypeId();
Long pid = maType.getParentId();
if (parentId.equals(pid)) {
List<Type> childLists = getChild(list, typeId);
maType.setChildren(childLists);
childList.add(maType);
}
}
return childList;
}
/**
* 构建前端所需要树结构

View File

@ -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;

View File

@ -19,7 +19,6 @@ public interface IwsCostPushService {
*/
List<IwsCostPushBean> findAgreement(IwsCostPushBean o);
/**
* 查询费用推送审核数据列表
*/

View File

@ -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<IwsCostPushBean> findAgreement(IwsCostPushBean o) {
return iwsCostPushMapper.findAgreement(o);
List<IwsCostPushBean> 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());
}
/**

View File

@ -495,7 +495,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectMaTypeList" resultMap="TypeResult">
select DISTINCT m.type_id, m.type_name, m.parent_id, m.unit_id, m.unit_name, m.unit_value,m.manage_type,
m.lease_price,m.eff_time, m.rent_price, m.buy_price, m.pay_price, m.level, m.rated_load, m.test_load,
m.holding_time, m.warn_num,
m.holding_time, m.warn_num, m.sort_num,
m.del_flag, m.create_by, m.create_time,
m.remark,m.type_id id , m.type_name label,
CASE m.manage_type