Work
This commit is contained in:
parent
3b7807aba6
commit
e86dc983cb
78 changed files with 1567 additions and 2602 deletions
57
cost-calculation/src/main/java/cost/CalculatedElement.java
Normal file
57
cost-calculation/src/main/java/cost/CalculatedElement.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package cost;
|
||||
|
||||
public class CalculatedElement {
|
||||
private String key;
|
||||
private int numberValue;
|
||||
private String stringValue;
|
||||
private long longValue;
|
||||
private double doubleValue;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public int getNumberValue() {
|
||||
return numberValue;
|
||||
}
|
||||
|
||||
public void setNumberValue(int numberValue) {
|
||||
this.numberValue = numberValue;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public void setStringValue(String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public long getLongValue() {
|
||||
return longValue;
|
||||
}
|
||||
|
||||
public void setLongValue(long longValue) {
|
||||
this.longValue = longValue;
|
||||
}
|
||||
|
||||
public double getDoubleValue() {
|
||||
return doubleValue;
|
||||
}
|
||||
|
||||
public void setDoubleValue(double doubleValue) {
|
||||
this.doubleValue = doubleValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CalculatedElement [key=" + key + ", numberValue=" + numberValue + ", stringValue=" + stringValue
|
||||
+ ", longValue=" + longValue + ", doubleValue=" + doubleValue + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
30
cost-calculation/src/main/java/cost/City.java
Normal file
30
cost-calculation/src/main/java/cost/City.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package cost;
|
||||
|
||||
public class City {
|
||||
|
||||
public static String ShangaiCityName = "Shangai";
|
||||
public static String RotterdamCityName = "Rotterdam";
|
||||
public static String TournaiCityName = "Tournai";
|
||||
public static String LilleCityName = "Lille";
|
||||
private String name;
|
||||
|
||||
public City(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "City [name=" + name + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package cost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CostCalculationRequest {
|
||||
private Order order;
|
||||
|
||||
private Trip trip;
|
||||
|
||||
private List<Pallet> pallets = new ArrayList<Pallet>();
|
||||
private List<CostElement> costElements = new ArrayList<CostElement>();
|
||||
|
||||
public Order getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Order order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public Trip getTrip() {
|
||||
return trip;
|
||||
}
|
||||
|
||||
public void setTrip(Trip trip) {
|
||||
this.trip = trip;
|
||||
}
|
||||
|
||||
public List<Pallet> getPallets() {
|
||||
return pallets;
|
||||
}
|
||||
|
||||
public void setPallets(List<Pallet> pallets) {
|
||||
this.pallets = pallets;
|
||||
}
|
||||
|
||||
public List<CostElement> getCostElements() {
|
||||
return costElements;
|
||||
}
|
||||
|
||||
public void setCostElements(List<CostElement> costElements) {
|
||||
this.costElements = costElements;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
5
cost-calculation/src/main/java/cost/CostElement.java
Normal file
5
cost-calculation/src/main/java/cost/CostElement.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package cost;
|
||||
|
||||
public interface CostElement {
|
||||
|
||||
}
|
||||
6
cost-calculation/src/main/java/cost/CostItem.java
Normal file
6
cost-calculation/src/main/java/cost/CostItem.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package cost;
|
||||
|
||||
public class CostItem {
|
||||
|
||||
|
||||
}
|
||||
31
cost-calculation/src/main/java/cost/HandlingCostElement.java
Normal file
31
cost-calculation/src/main/java/cost/HandlingCostElement.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package cost;
|
||||
|
||||
public class HandlingCostElement implements CostElement {
|
||||
|
||||
private double amount;
|
||||
private City city;
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public City getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(City city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HandlingCostElement [amount=" + amount + ", city=" + city + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
53
cost-calculation/src/main/java/cost/LeftToDistribute.java
Normal file
53
cost-calculation/src/main/java/cost/LeftToDistribute.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package cost;
|
||||
|
||||
public class LeftToDistribute {
|
||||
|
||||
private OrderLine orderLine;
|
||||
private long quantityLeft;
|
||||
private double weightLeft;
|
||||
|
||||
|
||||
public LeftToDistribute(OrderLine orderLine, double weightLeft) {
|
||||
super();
|
||||
this.orderLine = orderLine;
|
||||
this.weightLeft = weightLeft;
|
||||
}
|
||||
|
||||
public LeftToDistribute(OrderLine orderLine, long quantityLeft) {
|
||||
super();
|
||||
this.orderLine = orderLine;
|
||||
this.quantityLeft = quantityLeft;
|
||||
}
|
||||
|
||||
public OrderLine getOrderLine() {
|
||||
return orderLine;
|
||||
}
|
||||
|
||||
public void setOrderLine(OrderLine orderLine) {
|
||||
this.orderLine = orderLine;
|
||||
}
|
||||
|
||||
public long getQuantityLeft() {
|
||||
return quantityLeft;
|
||||
}
|
||||
|
||||
public void setQuantityLeft(long quantityLeft) {
|
||||
this.quantityLeft = quantityLeft;
|
||||
}
|
||||
|
||||
public double getWeightLeft() {
|
||||
return weightLeft;
|
||||
}
|
||||
|
||||
public void setWeightLeft(double weightLeft) {
|
||||
this.weightLeft = weightLeft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LeftToDistribute [orderLine=" + orderLine + ", quantityLeft=" + quantityLeft + ", weightLeft="
|
||||
+ weightLeft + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
37
cost-calculation/src/main/java/cost/Order.java
Normal file
37
cost-calculation/src/main/java/cost/Order.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package cost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Order {
|
||||
private String id;
|
||||
private List<OrderLine> orderLines = new ArrayList();
|
||||
|
||||
|
||||
public Order(String id) {
|
||||
super();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public List<OrderLine> getOrderLines() {
|
||||
return orderLines;
|
||||
}
|
||||
|
||||
|
||||
public void setOrderLines(List<OrderLine> orderLines) {
|
||||
this.orderLines = orderLines;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
51
cost-calculation/src/main/java/cost/OrderLine.java
Normal file
51
cost-calculation/src/main/java/cost/OrderLine.java
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package cost;
|
||||
|
||||
public class OrderLine {
|
||||
|
||||
private int numberItems;
|
||||
private double weight;
|
||||
private Product product;
|
||||
|
||||
|
||||
public OrderLine(int numberItems, Product product) {
|
||||
super();
|
||||
this.numberItems = numberItems;
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
public OrderLine(double weight, Product product) {
|
||||
super();
|
||||
this.weight = weight;
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
public int getNumberItems() {
|
||||
return numberItems;
|
||||
}
|
||||
|
||||
public void setNumberItems(int numberItems) {
|
||||
this.numberItems = numberItems;
|
||||
}
|
||||
|
||||
public Product getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public void setProduct(Product product) {
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(double weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OrderLine [numberItems=" + numberItems + ", weight=" + weight + ", product=" + product + "]";
|
||||
}
|
||||
|
||||
}
|
||||
89
cost-calculation/src/main/java/cost/Pallet.java
Normal file
89
cost-calculation/src/main/java/cost/Pallet.java
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
package cost;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Pallet {
|
||||
private boolean isFull = false;
|
||||
private double heightLeft = 2.0;
|
||||
private double width = 0.8;
|
||||
private double depth = 1.2;
|
||||
private Map<Product, Long> contentQuantity = new HashMap<Product, Long>();
|
||||
private Map<Product, Double> contentWeight = new HashMap<Product, Double>();
|
||||
private int palletType;
|
||||
|
||||
public Map<Product, Long> getContentQuantity() {
|
||||
return contentQuantity;
|
||||
}
|
||||
|
||||
public Map<Product, Double> getContentWeight() {
|
||||
return contentWeight;
|
||||
}
|
||||
|
||||
public void addContent(Product product, Long quantity) {
|
||||
if (contentQuantity.containsKey(product) == false) {
|
||||
contentQuantity.put(product, quantity);
|
||||
} else {
|
||||
Long oldQuantity = contentQuantity.get(product);
|
||||
oldQuantity = oldQuantity + quantity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addContent(Product product, Double weight) {
|
||||
if (contentWeight.containsKey(product) == false) {
|
||||
contentWeight.put(product, weight);
|
||||
} else {
|
||||
Double oldQuantity = contentWeight.get(product);
|
||||
oldQuantity = oldQuantity + weight;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return isFull;
|
||||
}
|
||||
|
||||
public void setFull(boolean isFull) {
|
||||
this.isFull = isFull;
|
||||
}
|
||||
|
||||
public double getHeightLeft() {
|
||||
return heightLeft;
|
||||
}
|
||||
|
||||
public void setHeightLeft(double heightLeft) {
|
||||
this.heightLeft = heightLeft;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(double width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public double getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public void setDepth(double depth) {
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public int getPalletType() {
|
||||
return palletType;
|
||||
}
|
||||
|
||||
public void setPalletType(int palletType) {
|
||||
this.palletType = palletType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Pallet [isFull=" + isFull + ", heightLeft=" + heightLeft + ", width=" + width + ", depth=" + depth
|
||||
+ ", palletType=" + palletType + "]";
|
||||
}
|
||||
|
||||
}
|
||||
106
cost-calculation/src/main/java/cost/Product.java
Normal file
106
cost-calculation/src/main/java/cost/Product.java
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
package cost;
|
||||
|
||||
public class Product {
|
||||
|
||||
public static int transportType_pallet = 1;
|
||||
public static int transportType_individual = 2;
|
||||
public static int transportType_bulkt = 3;
|
||||
private String name;
|
||||
private double height;
|
||||
private double width;
|
||||
private double depth;
|
||||
private double weight;
|
||||
private int transportType;
|
||||
|
||||
|
||||
public Product(String name, double height, double width, double depth, double weight, int transportType) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
this.depth = depth;
|
||||
this.weight = weight;
|
||||
this.transportType = transportType;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(double height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(double width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public double getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public void setDepth(double depth) {
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(double weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public int getTransportType() {
|
||||
return transportType;
|
||||
}
|
||||
|
||||
public void setTransportType(int transportType) {
|
||||
this.transportType = transportType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Product other = (Product) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Product [name=" + name + ", height=" + height + ", width=" + width + ", depth=" + depth + ", weight="
|
||||
+ weight + ", transportType=" + transportType + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
61
cost-calculation/src/main/java/cost/Step.java
Normal file
61
cost-calculation/src/main/java/cost/Step.java
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package cost;
|
||||
|
||||
public class Step {
|
||||
public static int Ship_TransportType = 1;
|
||||
public static int train_TransportType = 2;
|
||||
public static int truck_TransportType = 3;
|
||||
|
||||
private City stepStart;
|
||||
private City stepEnd;
|
||||
private double distance;
|
||||
private int transportType;
|
||||
|
||||
|
||||
public Step(City stepStart, City stepEnd, double distance, int transportType) {
|
||||
super();
|
||||
this.stepStart = stepStart;
|
||||
this.stepEnd = stepEnd;
|
||||
this.distance = distance;
|
||||
this.transportType = transportType;
|
||||
}
|
||||
|
||||
public City getStepStart() {
|
||||
return stepStart;
|
||||
}
|
||||
|
||||
public void setStepStart(City stepStart) {
|
||||
this.stepStart = stepStart;
|
||||
}
|
||||
|
||||
public City getStepEnd() {
|
||||
return stepEnd;
|
||||
}
|
||||
|
||||
public void setStepEnd(City stepEnd) {
|
||||
this.stepEnd = stepEnd;
|
||||
}
|
||||
|
||||
public double getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public void setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public int getTransportType() {
|
||||
return transportType;
|
||||
}
|
||||
|
||||
public void setTransportType(int transportType) {
|
||||
this.transportType = transportType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Step [stepStart=" + stepStart + ", stepEnd=" + stepEnd + ", distance=" + distance + ", transportType="
|
||||
+ transportType + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
39
cost-calculation/src/main/java/cost/TaxesCostElement.java
Normal file
39
cost-calculation/src/main/java/cost/TaxesCostElement.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package cost;
|
||||
|
||||
public class TaxesCostElement implements CostElement {
|
||||
private double amount;
|
||||
private City city;
|
||||
|
||||
private Pallet pallet;
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public City getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(City city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public Pallet getPallet() {
|
||||
return pallet;
|
||||
}
|
||||
|
||||
public void setPallet(Pallet pallet) {
|
||||
this.pallet = pallet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaxesCostElement [amount=" + amount + ", city=" + city + ", pallet="
|
||||
+ pallet + "]";
|
||||
}
|
||||
|
||||
}
|
||||
5
cost-calculation/src/main/java/cost/TotalAmount.java
Normal file
5
cost-calculation/src/main/java/cost/TotalAmount.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package cost;
|
||||
|
||||
public class TotalAmount {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package cost;
|
||||
|
||||
public class TransportCostElement implements CostElement {
|
||||
private double amount;
|
||||
private Step step;
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Step getStep() {
|
||||
return step;
|
||||
}
|
||||
|
||||
public void setStep(Step step) {
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TransportCostElement [amount=" + amount + ", step=" + step + "]";
|
||||
}
|
||||
|
||||
}
|
||||
37
cost-calculation/src/main/java/cost/Trip.java
Normal file
37
cost-calculation/src/main/java/cost/Trip.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package cost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Trip {
|
||||
private String id;
|
||||
private List<Step> steps = new ArrayList<Step>();
|
||||
|
||||
public Trip(String id) {
|
||||
super();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<Step> getSteps() {
|
||||
return steps;
|
||||
}
|
||||
|
||||
public void setSteps(List<Step> steps) {
|
||||
this.steps = steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Trip [id=" + id + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
19
cost-calculation/src/main/java/util/DateHelper.java
Normal file
19
cost-calculation/src/main/java/util/DateHelper.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateHelper {
|
||||
public static String sFormat = "yyyy-MM-dd";
|
||||
|
||||
public static Date getDate(String sDate) throws Exception {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
|
||||
return sdf.parse(sDate);
|
||||
}
|
||||
|
||||
public static Date getDate(String sDate, String anotherFormat)
|
||||
throws Exception {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(anotherFormat);
|
||||
return sdf.parse(sDate);
|
||||
}
|
||||
}
|
||||
174
cost-calculation/src/main/java/util/KnowledgeSessionHelper.java
Normal file
174
cost-calculation/src/main/java/util/KnowledgeSessionHelper.java
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
package util;
|
||||
|
||||
import org.jbpm.workflow.instance.node.RuleSetNodeInstance;
|
||||
import org.kie.api.KieServices;
|
||||
import org.kie.api.event.process.*;
|
||||
import org.kie.api.event.rule.*;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.api.runtime.StatelessKieSession;
|
||||
|
||||
public class KnowledgeSessionHelper {
|
||||
public static KieContainer createRuleBase() {
|
||||
|
||||
KieServices ks = KieServices.Factory.get();
|
||||
KieContainer kieContainer = ks.getKieClasspathContainer();
|
||||
return kieContainer;
|
||||
}
|
||||
|
||||
public static StatelessKieSession getStatelessKnowledgeSession(KieContainer kieContainer, String sessionName) {
|
||||
StatelessKieSession kSession = kieContainer.newStatelessKieSession(sessionName);
|
||||
|
||||
return kSession;
|
||||
}
|
||||
|
||||
public static KieSession getStatefulKnowledgeSession(KieContainer kieContainer, String sessionName) {
|
||||
KieSession kSession = kieContainer.newKieSession(sessionName);
|
||||
|
||||
return kSession;
|
||||
}
|
||||
|
||||
public static KieSession getStatefulKnowledgeSessionForJBPM(
|
||||
KieContainer kieContainer, String sessionName) {
|
||||
KieSession session = getStatefulKnowledgeSessionWithCallback(kieContainer, sessionName);
|
||||
session.addEventListener(new ProcessEventListener() {
|
||||
|
||||
@Override
|
||||
public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcessStarted(ProcessStartedEvent arg0) {
|
||||
System.out.println("Process Name " + arg0.getProcessInstance().getProcessName() + " has been started");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
|
||||
if (arg0.getNodeInstance() instanceof RuleSetNodeInstance) {
|
||||
System.out.println("Node Name " + arg0.getNodeInstance().getNodeName() + " has been left");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcessStarted(ProcessStartedEvent arg0) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcessCompleted(ProcessCompletedEvent arg0) {
|
||||
System.out.println("Process Name " + arg0.getProcessInstance().getProcessName() + " has stopped");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
|
||||
if (arg0.getNodeInstance() instanceof RuleSetNodeInstance) {
|
||||
System.out.println("Node Name " + arg0.getNodeInstance().getNodeName() + " has been entered");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
|
||||
}
|
||||
});
|
||||
return session;
|
||||
}
|
||||
|
||||
public static KieSession getStatefulKnowledgeSessionWithCallback(
|
||||
KieContainer kieContainer, String sessionName) {
|
||||
KieSession session = getStatefulKnowledgeSession(kieContainer, sessionName);
|
||||
session.addEventListener(new RuleRuntimeEventListener() {
|
||||
public void objectInserted(ObjectInsertedEvent event) {
|
||||
System.out.println("Object inserted \n"
|
||||
+ event.getObject().toString());
|
||||
}
|
||||
|
||||
public void objectUpdated(ObjectUpdatedEvent event) {
|
||||
System.out.println("Object was updated \n"
|
||||
+ "new Content \n" + event.getObject().toString());
|
||||
}
|
||||
|
||||
public void objectDeleted(ObjectDeletedEvent event) {
|
||||
System.out.println("Object retracted \n"
|
||||
+ event.getOldObject().toString());
|
||||
}
|
||||
});
|
||||
|
||||
session.addEventListener(new AgendaEventListener() {
|
||||
public void matchCreated(MatchCreatedEvent event) {
|
||||
System.out.println("The rule "
|
||||
+ event.getMatch().getRule().getName()
|
||||
+ " can be fired in agenda");
|
||||
}
|
||||
|
||||
public void matchCancelled(MatchCancelledEvent event) {
|
||||
System.out.println("The rule "
|
||||
+ event.getMatch().getRule().getName()
|
||||
+ " cannot b in agenda");
|
||||
}
|
||||
|
||||
public void beforeMatchFired(BeforeMatchFiredEvent event) {
|
||||
System.out.println("The rule "
|
||||
+ event.getMatch().getRule().getName()
|
||||
+ " will be fired");
|
||||
}
|
||||
|
||||
public void afterMatchFired(AfterMatchFiredEvent event) {
|
||||
System.out.println("The rule "
|
||||
+ event.getMatch().getRule().getName()
|
||||
+ " has be fired");
|
||||
}
|
||||
|
||||
public void agendaGroupPopped(AgendaGroupPoppedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void agendaGroupPushed(AgendaGroupPushedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void beforeRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void beforeRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void afterRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return session;
|
||||
}
|
||||
}
|
||||
10
cost-calculation/src/main/java/util/OutputDisplay.java
Normal file
10
cost-calculation/src/main/java/util/OutputDisplay.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package util;
|
||||
|
||||
public class OutputDisplay {
|
||||
|
||||
public void showText(String someText) {
|
||||
long time = System.currentTimeMillis();
|
||||
System.out.println("time=" + time + "-" + someText);
|
||||
}
|
||||
|
||||
}
|
||||
7
cost-calculation/src/main/resources/META-INF/kmodule.xml
Normal file
7
cost-calculation/src/main/resources/META-INF/kmodule.xml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
|
||||
<kbase name="rules" packages="rules">
|
||||
<ksession name="ksession-rules"/>
|
||||
</kbase>
|
||||
|
||||
</kmodule>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
groupId=CostCalculation.group
|
||||
artifactId=CostCalculation.artifact
|
||||
version=1.0
|
||||
219
cost-calculation/src/main/resources/rules/CalculationRules.drl
Normal file
219
cost-calculation/src/main/resources/rules/CalculationRules.drl
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
|
||||
package cost.calculation
|
||||
|
||||
import cost.OrderLine;
|
||||
import cost.LeftToDistribute;
|
||||
import cost.Product;
|
||||
import cost.Pallet;
|
||||
import cost.CostCalculationRequest;
|
||||
import cost.CalculatedElement;
|
||||
import cost.HandlingCostElement;
|
||||
import cost.TaxesCostElement;
|
||||
import cost.TransportCostElement;
|
||||
import cost.Step;
|
||||
import cost.City;
|
||||
|
||||
import java.lang.Math;
|
||||
import java.util.ArrayList;
|
||||
|
||||
rule "boatTransportCost"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$s : Step(transportType ==Step.Ship_TransportType)
|
||||
then
|
||||
TransportCostElement t = new TransportCostElement();
|
||||
t.setStep($s);
|
||||
t.setAmount($c.getPallets().size()*$s.getDistance()*0.2);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
end
|
||||
|
||||
rule "trainTransportCost"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$s : Step(transportType ==Step.train_TransportType)
|
||||
then
|
||||
TransportCostElement t = new TransportCostElement();
|
||||
t.setStep($s);
|
||||
t.setAmount($c.getPallets().size()*$s.getDistance()*0.5);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
end
|
||||
|
||||
rule "truckTransportCost"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$s : Step(transportType ==Step.truck_TransportType)
|
||||
then
|
||||
TransportCostElement t = new TransportCostElement();
|
||||
t.setStep($s);
|
||||
t.setAmount($c.getPallets().size()*$s.getDistance()*1.0);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
end
|
||||
|
||||
rule "ShangaiTaxesCost_bulk"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$ci : City(name==City.ShangaiCityName)
|
||||
$listPallet : ArrayList( )
|
||||
from collect( Pallet(palletType == Product.transportType_bulkt) )
|
||||
then
|
||||
TaxesCostElement t = new TaxesCostElement();
|
||||
t.setCity($ci);
|
||||
double totalWeight=0;
|
||||
for (Object oo : $listPallet){
|
||||
Pallet pp = (Pallet)oo;
|
||||
for (Double d : pp.getContentWeight().values()){
|
||||
totalWeight=totalWeight+d;
|
||||
}
|
||||
}
|
||||
t.setAmount(totalWeight*0.02);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
end
|
||||
|
||||
rule "ShangaiTaxesCost_notbulk"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$ci : City(name==City.ShangaiCityName)
|
||||
$listPallet : ArrayList( )
|
||||
from collect( Pallet(palletType != Product.transportType_bulkt) )
|
||||
then
|
||||
TaxesCostElement t = new TaxesCostElement();
|
||||
t.setCity($ci);
|
||||
double totalWeight=0;
|
||||
for (Object oo : $listPallet){
|
||||
Pallet pp = (Pallet)oo;
|
||||
for (Product p : pp.getContentQuantity().keySet()){
|
||||
totalWeight=totalWeight+p.getWeight()* pp.getContentQuantity().get(p);
|
||||
}
|
||||
}
|
||||
t.setAmount(totalWeight*0.05);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
end
|
||||
|
||||
rule "RotterdamTaxesCost_bulk_weight"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$ci : City(name==City.RotterdamCityName)
|
||||
$listPallet : ArrayList( )
|
||||
from collect( Pallet(palletType == Product.transportType_bulkt) )
|
||||
then
|
||||
TaxesCostElement t = new TaxesCostElement();
|
||||
t.setCity($ci);
|
||||
double totalWeight=0;
|
||||
for (Object oo : $listPallet){
|
||||
Pallet pp = (Pallet)oo;
|
||||
for (Double d : pp.getContentWeight().values()){
|
||||
totalWeight=totalWeight+d;
|
||||
}
|
||||
}
|
||||
t.setAmount(totalWeight*0.05);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
end
|
||||
rule "RotterdamTaxesCost_notbulk_weight"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$ci : City(name==City.RotterdamCityName)
|
||||
$listPallet : ArrayList( )
|
||||
from collect( Pallet(palletType != Product.transportType_bulkt) )
|
||||
then
|
||||
TaxesCostElement t = new TaxesCostElement();
|
||||
t.setCity($ci);
|
||||
double totalWeight=0;
|
||||
for (Object oo : $listPallet){
|
||||
Pallet pp = (Pallet)oo;
|
||||
for (Product p : pp.getContentQuantity().keySet()){
|
||||
totalWeight=totalWeight+p.getWeight()* pp.getContentQuantity().get(p);
|
||||
}
|
||||
}
|
||||
t.setAmount(totalWeight*0.05);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
end
|
||||
|
||||
rule "ShangaiHandlingCost"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$ci : City(name==City.ShangaiCityName)
|
||||
then
|
||||
int n = $c.getPallets().size();
|
||||
int nbrePalletPerHour = Math.round( n/12)+1;
|
||||
int nbrePerson = Math.round( nbrePalletPerHour/13)+1;
|
||||
HandlingCostElement t = new HandlingCostElement();
|
||||
t.setCity($ci);
|
||||
t.setAmount(nbrePerson*12*20.0);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
end
|
||||
|
||||
rule "RotterdamHandlingCostAndPersonTaxes"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$ci : City(name==City.RotterdamCityName)
|
||||
then
|
||||
int n = $c.getPallets().size();
|
||||
int nbrePalletPerHour = Math.round( n/12)+1;
|
||||
int nbrePerson = Math.round( nbrePalletPerHour/60)+1;
|
||||
HandlingCostElement t = new HandlingCostElement();
|
||||
t.setCity($ci);
|
||||
t.setAmount(nbrePerson*12*45.0);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
TaxesCostElement t1 = new TaxesCostElement();
|
||||
t1.setAmount(nbrePerson*1.0);
|
||||
$c.getCostElements().add(t1);
|
||||
insert(t1);
|
||||
end
|
||||
|
||||
rule "TournaiHandlingCostAndPersonTaxes"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$ci : City(name==City.TournaiCityName)
|
||||
then
|
||||
int n = $c.getPallets().size();
|
||||
int nbrePalletPerHour = Math.round( n/12)+1;
|
||||
int nbrePerson = Math.round( nbrePalletPerHour/40)+1;
|
||||
HandlingCostElement t = new HandlingCostElement();
|
||||
t.setCity($ci);
|
||||
t.setAmount(nbrePerson*12*67.0);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
TaxesCostElement t1 = new TaxesCostElement();
|
||||
t1.setAmount(nbrePerson*2.0);
|
||||
$c.getCostElements().add(t1);
|
||||
insert(t1);
|
||||
end
|
||||
|
||||
rule "LilleHandlingCostAndPersonTaxes"
|
||||
ruleflow-group "calculate"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$ci : City(name==City.LilleCityName)
|
||||
then
|
||||
int n = $c.getPallets().size();
|
||||
int nbrePalletPerHour = Math.round( n/12)+1;
|
||||
int nbrePerson = Math.round( nbrePalletPerHour/30)+1;
|
||||
HandlingCostElement t = new HandlingCostElement();
|
||||
t.setCity($ci);
|
||||
t.setAmount(nbrePerson*12*79.0);
|
||||
$c.getCostElements().add(t);
|
||||
insert(t);
|
||||
TaxesCostElement t1 = new TaxesCostElement();
|
||||
t1.setAmount(nbrePerson*30.0);
|
||||
$c.getCostElements().add(t1);
|
||||
insert(t1);
|
||||
end
|
||||
92
cost-calculation/src/main/resources/rules/P1.bpmn2
Normal file
92
cost-calculation/src/main/resources/rules/P1.bpmn2
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<definitions id="Definition"
|
||||
targetNamespace="http://www.jboss.org/drools"
|
||||
typeLanguage="http://www.java.com/javaTypes"
|
||||
expressionLanguage="http://www.mvel.org/2.0"
|
||||
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
|
||||
xmlns:g="http://www.jboss.org/drools/flow/gpd"
|
||||
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
|
||||
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
|
||||
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
|
||||
xmlns:tns="http://www.jboss.org/drools">
|
||||
|
||||
<process processType="Private" isExecutable="true" id="P1" name="CalcuateCostProces" tns:packageName="cost.calculation" >
|
||||
|
||||
<!-- nodes -->
|
||||
<startEvent id="_1" isInterrupting="true">
|
||||
</startEvent>
|
||||
<endEvent id="_3" >
|
||||
<terminateEventDefinition />
|
||||
</endEvent>
|
||||
<businessRuleTask id="_jbpm-unique-2" name="pallet" g:ruleFlowGroup="distribution" >
|
||||
<ioSpecification>
|
||||
<inputSet>
|
||||
</inputSet>
|
||||
<outputSet>
|
||||
</outputSet>
|
||||
</ioSpecification>
|
||||
</businessRuleTask>
|
||||
<businessRuleTask id="_jbpm-unique-0" name="Amount " g:ruleFlowGroup="calculate" >
|
||||
<ioSpecification>
|
||||
<inputSet>
|
||||
</inputSet>
|
||||
<outputSet>
|
||||
</outputSet>
|
||||
</ioSpecification>
|
||||
</businessRuleTask>
|
||||
<businessRuleTask id="_jbpm-unique-1" name="Sum" g:ruleFlowGroup="total" >
|
||||
<ioSpecification>
|
||||
<inputSet>
|
||||
</inputSet>
|
||||
<outputSet>
|
||||
</outputSet>
|
||||
</ioSpecification>
|
||||
</businessRuleTask>
|
||||
|
||||
<!-- connections -->
|
||||
<sequenceFlow id="_jbpm-unique-1-_3" sourceRef="_jbpm-unique-1" targetRef="_3" />
|
||||
<sequenceFlow id="_1-_jbpm-unique-2" sourceRef="_1" targetRef="_jbpm-unique-2" />
|
||||
<sequenceFlow id="_jbpm-unique-2-_jbpm-unique-0" sourceRef="_jbpm-unique-2" targetRef="_jbpm-unique-0" />
|
||||
<sequenceFlow id="_jbpm-unique-0-_jbpm-unique-1" sourceRef="_jbpm-unique-0" targetRef="_jbpm-unique-1" />
|
||||
|
||||
</process>
|
||||
|
||||
<bpmndi:BPMNDiagram>
|
||||
<bpmndi:BPMNPlane bpmnElement="P1" >
|
||||
<bpmndi:BPMNShape bpmnElement="_1" >
|
||||
<dc:Bounds x="24" y="16" width="48" height="48" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="_3" >
|
||||
<dc:Bounds x="433" y="21" width="48" height="48" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="_jbpm-unique-2" >
|
||||
<dc:Bounds x="123" y="18" width="80" height="48" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="_jbpm-unique-0" >
|
||||
<dc:Bounds x="233" y="20" width="80" height="48" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="_jbpm-unique-1" >
|
||||
<dc:Bounds x="337" y="22" width="80" height="48" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge bpmnElement="_jbpm-unique-1-_3" >
|
||||
<di:waypoint x="377" y="46" />
|
||||
<di:waypoint x="457" y="45" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="_1-_jbpm-unique-2" >
|
||||
<di:waypoint x="48" y="40" />
|
||||
<di:waypoint x="163" y="42" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="_jbpm-unique-2-_jbpm-unique-0" >
|
||||
<di:waypoint x="163" y="42" />
|
||||
<di:waypoint x="273" y="44" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="_jbpm-unique-0-_jbpm-unique-1" >
|
||||
<di:waypoint x="273" y="44" />
|
||||
<di:waypoint x="377" y="46" />
|
||||
</bpmndi:BPMNEdge>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
|
||||
</definitions>
|
||||
134
cost-calculation/src/main/resources/rules/PalletRules.drl
Normal file
134
cost-calculation/src/main/resources/rules/PalletRules.drl
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
package cost.calculation
|
||||
|
||||
import cost.OrderLine;
|
||||
import cost.LeftToDistribute;
|
||||
import cost.Product;
|
||||
import cost.Pallet;
|
||||
import cost.CostCalculationRequest;
|
||||
import cost.CalculatedElement;
|
||||
import java.lang.Math;
|
||||
|
||||
|
||||
rule "Create Counter leftToDistribute quantity"
|
||||
ruleflow-group "distribution"
|
||||
when
|
||||
$elt : OrderLine( numberItems >0 )
|
||||
not (LeftToDistribute(orderLine==$elt))
|
||||
then
|
||||
LeftToDistribute e= new LeftToDistribute($elt,$elt.getNumberItems());
|
||||
insert(e);
|
||||
end
|
||||
rule "Create Counter leftToDistribute weight"
|
||||
ruleflow-group "distribution"
|
||||
when
|
||||
$elt : OrderLine( weight >0 )
|
||||
not (LeftToDistribute(orderLine==$elt))
|
||||
then
|
||||
LeftToDistribute e= new LeftToDistribute($elt,$elt.getWeight());
|
||||
insert(e);
|
||||
end
|
||||
rule "Create PalletForIndividual"
|
||||
ruleflow-group "distribution"
|
||||
when
|
||||
$c : CostCalculationRequest()
|
||||
$p : Product(transportType==Product.transportType_individual)
|
||||
$elt : OrderLine(product==$p )
|
||||
$l : LeftToDistribute(quantityLeft> 0,orderLine==$elt)
|
||||
then
|
||||
Pallet pp = new Pallet();
|
||||
pp.setPalletType($p.getTransportType());
|
||||
pp.addContent($p,new Long(1));
|
||||
insert(pp);
|
||||
$c.getPallets().add(pp);
|
||||
$l.setQuantityLeft($l.getQuantityLeft()-1);
|
||||
update($l);
|
||||
end
|
||||
|
||||
rule "Create PalletForBulkMore1400Kg"
|
||||
ruleflow-group "distribution"
|
||||
when
|
||||
$c : CostCalculationRequest()
|
||||
$p : Product(transportType==Product.transportType_bulkt)
|
||||
$elt : OrderLine(product==$p )
|
||||
$l : LeftToDistribute(weightLeft > 1400,orderLine==$elt)
|
||||
then
|
||||
Pallet pp = new Pallet();
|
||||
pp.setPalletType($p.getTransportType());
|
||||
pp.addContent($p,new Long(1400));
|
||||
insert(pp);
|
||||
$c.getPallets().add(pp);
|
||||
$l.setWeightLeft($l.getWeightLeft()-1400);
|
||||
update($l);
|
||||
end
|
||||
rule "Create PalletForBulkless1400Kg"
|
||||
ruleflow-group "distribution"
|
||||
when
|
||||
$c : CostCalculationRequest()
|
||||
$p : Product(transportType==Product.transportType_bulkt)
|
||||
$elt : OrderLine(product==$p )
|
||||
$l : LeftToDistribute(weightLeft <= 1400,weightLeft > 0,orderLine==$elt)
|
||||
then
|
||||
Pallet pp = new Pallet();
|
||||
pp.setPalletType($p.getTransportType());
|
||||
pp.addContent($p,$l.getWeightLeft());
|
||||
insert(pp);
|
||||
$c.getPallets().add(pp);
|
||||
$l.setWeightLeft(0);
|
||||
update($l);
|
||||
end
|
||||
|
||||
rule "Create Empty Pallet"
|
||||
ruleflow-group "distribution"
|
||||
when
|
||||
not (Pallet (palletType == Product.transportType_pallet,full ==false))
|
||||
then
|
||||
Pallet p = new Pallet();
|
||||
p.setPalletType(Product.transportType_pallet);
|
||||
insert (p);
|
||||
end
|
||||
|
||||
|
||||
|
||||
rule "Create PalletFortransportType_pallet"
|
||||
ruleflow-group "distribution"
|
||||
when
|
||||
$c : CostCalculationRequest()
|
||||
$pp : Pallet($hl : heightLeft ,full ==false,palletType == Product.transportType_pallet)
|
||||
$p : Product(height <= $hl,transportType==Product.transportType_pallet)
|
||||
$elt : OrderLine(product==$p )
|
||||
$l : LeftToDistribute(quantityLeft > 0,orderLine==$elt)
|
||||
then
|
||||
long a = (long) Math.round($pp.getWidth()/$p.getWidth());
|
||||
long b = (long) Math.round($pp.getDepth()/$p.getDepth());
|
||||
long n = Math.min(a*b,$l.getQuantityLeft());
|
||||
$pp.addContent($p,n);
|
||||
$pp.setHeightLeft($pp.getHeightLeft()-$p.getHeight());
|
||||
update($pp);
|
||||
$l.setQuantityLeft($l.getQuantityLeft()-n);
|
||||
update($l);
|
||||
end
|
||||
|
||||
rule "FillPalletIfNoProductGoesIn"
|
||||
ruleflow-group "distribution"
|
||||
when
|
||||
CalculatedElement($min : doubleValue ,key=="minValue.product")
|
||||
$p : Pallet(heightLeft!= 2.0,$hl : heightLeft < $min ,full ==false,palletType == Product.transportType_pallet)
|
||||
then
|
||||
$p.setFull(true);
|
||||
System.out.println("MinValue="+$min);
|
||||
update($p);
|
||||
end
|
||||
|
||||
rule "GetSmallestHeight"
|
||||
ruleflow-group "distribution"
|
||||
when
|
||||
accumulate( Product( $h : height ,transportType==Product.transportType_pallet );
|
||||
$min : min( $h );
|
||||
true )
|
||||
|
||||
then
|
||||
CalculatedElement elt = new CalculatedElement();
|
||||
elt.setKey("minValue.product");
|
||||
elt.setDoubleValue((Double)$min);
|
||||
insert(elt);
|
||||
end
|
||||
72
cost-calculation/src/main/resources/rules/SumRules.drl
Normal file
72
cost-calculation/src/main/resources/rules/SumRules.drl
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
|
||||
package cost.calculation
|
||||
|
||||
import cost.OrderLine;
|
||||
import cost.LeftToDistribute;
|
||||
import cost.Product;
|
||||
import cost.Pallet;
|
||||
import cost.CostCalculationRequest;
|
||||
import cost.CalculatedElement;
|
||||
import cost.HandlingCostElement;
|
||||
import cost.TaxesCostElement;
|
||||
import cost.TransportCostElement;
|
||||
import cost.Step;
|
||||
import cost.City;
|
||||
|
||||
import java.lang.Math;
|
||||
|
||||
rule "CalculateTotal"
|
||||
ruleflow-group "total"
|
||||
when
|
||||
$c : CostCalculationRequest( )
|
||||
$totalBoatTransport : Number( doubleValue > 100 )
|
||||
from accumulate( $s : Step(transportType ==Step.Ship_TransportType) &&
|
||||
TransportCostElement(step ==$s, $value : amount ),
|
||||
init( double total = 0; ),
|
||||
action( total += $value; ),
|
||||
reverse( total -= $value; ),
|
||||
result( total ) )
|
||||
$totalTrainTransport : Number( doubleValue > 100 )
|
||||
from accumulate( $s : Step(transportType ==Step.train_TransportType) &&
|
||||
TransportCostElement(step ==$s, $value : amount ),
|
||||
init( double total = 0; ),
|
||||
action( total += $value; ),
|
||||
reverse( total -= $value; ),
|
||||
result( total ) )
|
||||
$totalTruckTransport : Number( doubleValue > 100 )
|
||||
from accumulate( $s : Step(transportType ==Step.truck_TransportType) &&
|
||||
TransportCostElement(step ==$s, $value : amount ),
|
||||
init( double total = 0; ),
|
||||
action( total += $value; ),
|
||||
reverse( total -= $value; ),
|
||||
result( total ) )
|
||||
|
||||
|
||||
|
||||
$totalTransport : Number( doubleValue > 100 )
|
||||
from accumulate( TransportCostElement( $value : amount ),
|
||||
init( double total = 0; ),
|
||||
action( total += $value; ),
|
||||
reverse( total -= $value; ),
|
||||
result( total ) )
|
||||
$totalTaxes : Number( doubleValue > 100 )
|
||||
from accumulate( TaxesCostElement( $value : amount ),
|
||||
init( double total = 0; ),
|
||||
action( total += $value; ),
|
||||
reverse( total -= $value; ),
|
||||
result( total ) )
|
||||
$totalHandling : Number( doubleValue > 100 )
|
||||
from accumulate( HandlingCostElement( $value : amount ),
|
||||
init( double total = 0; ),
|
||||
action( total += $value; ),
|
||||
reverse( total -= $value; ),
|
||||
result( total ) )
|
||||
then
|
||||
System.out.println("NumberOfPallets="+$c.getPallets().size());
|
||||
System.out.println("TotalShipTransport="+$totalBoatTransport);
|
||||
System.out.println("TotalTrainTransport="+$totalTrainTransport);
|
||||
System.out.println("TotalTruckTransport="+$totalTruckTransport);
|
||||
System.out.println("TotalTransport="+$totalTransport);
|
||||
System.out.println("TotalTaxes="+$totalTaxes);
|
||||
System.out.println("TotalHandling="+$totalHandling);
|
||||
end;
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
package calculation;
|
||||
|
||||
import cost.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.api.runtime.StatelessKieSession;
|
||||
import util.KnowledgeSessionHelper;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class TestExecercice {
|
||||
|
||||
static KieContainer kieContainer;
|
||||
StatelessKieSession sessionStateless = null;
|
||||
KieSession sessionStatefull = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
kieContainer = KnowledgeSessionHelper.createRuleBase();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.out.println("------------Before------------");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.out.println("------------After------------");
|
||||
}
|
||||
|
||||
private void insertIntoSession(KieSession sessionStatefull, CostCalculationRequest request) {
|
||||
sessionStatefull.insert(request);
|
||||
if (request.getOrder() != null) {
|
||||
sessionStatefull.insert(request.getOrder());
|
||||
for (OrderLine orderLine : request.getOrder().getOrderLines()) {
|
||||
sessionStatefull.insert(orderLine);
|
||||
sessionStatefull.insert(orderLine.getProduct());
|
||||
}
|
||||
}
|
||||
if (request.getTrip() != null) {
|
||||
sessionStatefull.insert(request.getTrip());
|
||||
for (Step step : request.getTrip().getSteps()) {
|
||||
sessionStatefull.insert(step);
|
||||
sessionStatefull.insert(step.getStepStart());
|
||||
sessionStatefull.insert(step.getStepEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirstOne() {
|
||||
sessionStatefull = KnowledgeSessionHelper.getStatefulKnowledgeSessionForJBPM(kieContainer, "ksession-rules");
|
||||
City cityOfShangai = new City(City.ShangaiCityName);
|
||||
City cityOfRotterdam = new City(City.RotterdamCityName);
|
||||
City cityOfTournai = new City(City.TournaiCityName);
|
||||
City cityOfLille = new City(City.LilleCityName);
|
||||
Step step1 = new Step(cityOfShangai, cityOfRotterdam, 22000, Step.Ship_TransportType);
|
||||
Step step2 = new Step(cityOfRotterdam, cityOfTournai, 300, Step.train_TransportType);
|
||||
Step step3 = new Step(cityOfTournai, cityOfLille, 20, Step.truck_TransportType);
|
||||
Trip myTrip = new Trip("trip1");
|
||||
myTrip.getSteps().add(step1);
|
||||
myTrip.getSteps().add(step2);
|
||||
myTrip.getSteps().add(step3);
|
||||
CostCalculationRequest request = new CostCalculationRequest();
|
||||
request.setTrip(myTrip);
|
||||
Product drillProduct = new Product("Drill", 0.2, 0.4, 0.3, 2, Product.transportType_pallet);
|
||||
Product screwDriverProduct = new Product("Screwdriver", 0.03, 0.02, 0.2, 0.2, Product.transportType_pallet);
|
||||
Product sandProduct = new Product("Sand", 0.0, 0.0, 0.0, 0.0, Product.transportType_bulkt);
|
||||
Product gravelProduct = new Product("Gravel", 0.0, 0.0, 0.0, 0.0, Product.transportType_bulkt);
|
||||
Product furnitureProduct = new Product("Furniture", 0.0, 0.0, 0.0, 0.0, Product.transportType_individual);
|
||||
Order myOrder = new Order("1");
|
||||
|
||||
myOrder.getOrderLines().add(new OrderLine(1000, drillProduct));
|
||||
myOrder.getOrderLines().add(new OrderLine(1000, screwDriverProduct));
|
||||
myOrder.getOrderLines().add(new OrderLine(35000.0, sandProduct));
|
||||
myOrder.getOrderLines().add(new OrderLine(14000.0, gravelProduct));
|
||||
myOrder.getOrderLines().add(new OrderLine(500, furnitureProduct));
|
||||
request.setOrder(myOrder);
|
||||
long before = System.currentTimeMillis();
|
||||
|
||||
this.insertIntoSession(sessionStatefull, request);
|
||||
sessionStatefull.startProcess("P1");
|
||||
int i = sessionStatefull.fireAllRules();
|
||||
long after = System.currentTimeMillis();
|
||||
System.out.println("NumberRules Executed " + i);
|
||||
System.out.println("Rules executed in " + (after - before) + " ms");
|
||||
Double dd = new Double(i) / (after - before) * 1000;
|
||||
System.out.println("NbreRules/seconde=" + dd);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue