Untitled
unknown
plain_text
2 years ago
4.7 kB
9
Indexable
import java.util.ArrayList;
import java.util.List;
class E090hrpComGer {
E090pes e090pes;
Integer comSup;
E090hrpComGer repSup;
E070fil e070fil;
}
class E090pes {
Integer id;
E001pes e001pes;
}
class E001pes {
Integer codPes;
String apePes;
}
class E070fil {
Integer id;
}
class HierarchicalTreeNode {
Representative representative;
Integer superiorCommissionPercentage;
List<HierarchicalTreeNode> subordinates = new ArrayList<>();
}
class Representative {
Integer id;
Integer code;
String description;
}
public class HierarchicalTreeBuilder {
public List<HierarchicalTreeNode> buildHierarchy(Integer representativeId, Integer branchId) {
// Retrieve root representative based on input representativeId and branchId
E090hrpComGer rootRecord = retrieveRepresentative(representativeId, branchId);
// Build hierarchical tree
List<HierarchicalTreeNode> hierarchy = new ArrayList<>();
buildSubordinates(rootRecord, hierarchy);
return hierarchy;
}
private void buildSubordinates(E090hrpComGer representativeRecord, List<HierarchicalTreeNode> hierarchy) {
HierarchicalTreeNode node = new HierarchicalTreeNode();
node.representative = new Representative();
node.representative.id = representativeRecord.e090pes.id;
node.representative.code = representativeRecord.e090pes.e001pes.codPes;
node.representative.description = representativeRecord.e090pes.e001pes.apePes;
node.superiorCommissionPercentage = representativeRecord.comSup;
// Retrieve and add subordinates
List<E090hrpComGer> subordinatesRecords = retrieveSubordinates(representativeRecord.e090pes.id, representativeRecord.e070fil.id);
for (E090hrpComGer subRecord : subordinatesRecords) {
buildSubordinates(subRecord, node.subordinates);
}
hierarchy.add(node);
// If representative has a superior, add its representation
if (representativeRecord.repSup != null) {
HierarchicalTreeNode superiorNode = new HierarchicalTreeNode();
superiorNode.representative = new Representative();
superiorNode.representative.id = representativeRecord.repSup.e090pes.id;
superiorNode.representative.code = representativeRecord.repSup.e090pes.e001pes.codPes;
superiorNode.representative.description = representativeRecord.repSup.e090pes.e001pes.apePes;
superiorNode.superiorCommissionPercentage = representativeRecord.repSup.comSup;
superiorNode.subordinates.add(node);
hierarchy.add(superiorNode);
// Build superior's superiors
buildSuperiors(representativeRecord.repSup, superiorNode.subordinates);
}
}
private void buildSuperiors(E090hrpComGer representativeRecord, List<HierarchicalTreeNode> hierarchy) {
if (representativeRecord.repSup != null) {
HierarchicalTreeNode node = new HierarchicalTreeNode();
node.representative = new Representative();
node.representative.id = representativeRecord.repSup.e090pes.id;
node.representative.code = representativeRecord.repSup.e090pes.e001pes.codPes;
node.representative.description = representativeRecord.repSup.e090pes.e001pes.apePes;
node.superiorCommissionPercentage = representativeRecord.repSup.comSup;
node.subordinates.addAll(hierarchy);
hierarchy.clear();
hierarchy.add(node);
buildSuperiors(representativeRecord.repSup, node.subordinates);
}
}
private E090hrpComGer retrieveRepresentative(Integer representativeId, Integer branchId) {
// Code to retrieve the representative based on representativeId and branchId
// Replace this with your actual data retrieval logic
return new E090hrpComGer(); // Placeholder
}
private List<E090hrpComGer> retrieveSubordinates(Integer representativeId, Integer branchId) {
// Code to retrieve the list of subordinates based on representativeId and branchId
// Replace this with your actual data retrieval logic
return new ArrayList<>(); // Placeholder
}
public static void main(String[] args) {
HierarchicalTreeBuilder builder = new HierarchicalTreeBuilder();
List<HierarchicalTreeNode> hierarchy = builder.buildHierarchy(123, 456); // Provide representativeId and branchId
// Print or manipulate the hierarchical tree as needed
}
}
Editor is loading...