编写规则以根据访问情况检测客户在商店某个部门中的位置
write a rule to detect customer location in a department in a store based on visits
我是 Drools 的新手,有一些问题。我正在努力创建规则来检测商店部门中的客户。
我的模型如下:
客户:Id,Point(x,y)
部门:Id,矩形
客户活动
我目前有客户用 x,y 位置或点表示,部门用矩形表示。
1.) 如何编写规则来检测客户是否在矩形内?
2.) 如果客户在部门内更改位置至少 2 次,则触发事件。如何编写规则来检测客户是否在某个部门并且已经两次更改位置?
请告诉我。
谢谢!
客户
public class CustomerObj {
public CustomerObj(String custId, Integer timestamp) {
super();
this.custId = custId;
this.timestamp = timestamp;
}
private String custId;
private long timestamp;
private Integer classification;
private Point location;
private Department department;
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(Integer timestamp) {
this.timestamp = timestamp;
}
public String getCustId() {
return custId;
}
public void setCustId(String custId) {
this.custId = custId;
}
public Integer getClassification() {
return classification;
}
public void setClassification(Integer classification) {
this.classification = classification;
}
public Point getLocation() {
return location;
}
public void setLocation(Point location) {
this.location = location;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
}
部门
public class部门{
public Department(Integer departmentId) {
super();
this.departmentId = departmentId;
}
private Integer departmentId;
private Rectangle deptLocation;
public Integer getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
public boolean containsCustomer(CustomerObj c) {
if (this.deptLocation.contains(c.getLocation())) return true;
else return false;
}
}
假设 Rectangle 和 Point 来自 java.awt,事情就很简单了。
rule "customer in department"
when
CustomerObj( $cid: custId, $p: point )
Department( $did: departmentId, $dloc: deptLocation,
$dloc.contains( $p ) )
then
System.out.println( "customer " + $cid + " in " + $did );
end
至于移动,您需要一个显示客户和部门 ID 以及位置的 CustomerEvent。
rule "customer moves frequently in same department"
when
CustomerEvent( $cid: custId, $did: dptmtId, $p: Point )
$dep: Department( departmentId == $did )
$cust: CustomerObj( custId == $cid, department == $dep, moves >= 1 )
then
// whatever
end
请注意,您需要额外的规则来更改客户的部门参考和注册第一次移动,并且可能计算第二次移动之后的移动。
我是 Drools 的新手,有一些问题。我正在努力创建规则来检测商店部门中的客户。
我的模型如下:
客户:Id,Point(x,y)
部门:Id,矩形
客户活动
我目前有客户用 x,y 位置或点表示,部门用矩形表示。
1.) 如何编写规则来检测客户是否在矩形内?
2.) 如果客户在部门内更改位置至少 2 次,则触发事件。如何编写规则来检测客户是否在某个部门并且已经两次更改位置?
请告诉我。
谢谢!
客户
public class CustomerObj {
public CustomerObj(String custId, Integer timestamp) {
super();
this.custId = custId;
this.timestamp = timestamp;
}
private String custId;
private long timestamp;
private Integer classification;
private Point location;
private Department department;
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(Integer timestamp) {
this.timestamp = timestamp;
}
public String getCustId() {
return custId;
}
public void setCustId(String custId) {
this.custId = custId;
}
public Integer getClassification() {
return classification;
}
public void setClassification(Integer classification) {
this.classification = classification;
}
public Point getLocation() {
return location;
}
public void setLocation(Point location) {
this.location = location;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
}
部门
public class部门{
public Department(Integer departmentId) {
super();
this.departmentId = departmentId;
}
private Integer departmentId;
private Rectangle deptLocation;
public Integer getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
public boolean containsCustomer(CustomerObj c) {
if (this.deptLocation.contains(c.getLocation())) return true;
else return false;
}
}
假设 Rectangle 和 Point 来自 java.awt,事情就很简单了。
rule "customer in department"
when
CustomerObj( $cid: custId, $p: point )
Department( $did: departmentId, $dloc: deptLocation,
$dloc.contains( $p ) )
then
System.out.println( "customer " + $cid + " in " + $did );
end
至于移动,您需要一个显示客户和部门 ID 以及位置的 CustomerEvent。
rule "customer moves frequently in same department"
when
CustomerEvent( $cid: custId, $did: dptmtId, $p: Point )
$dep: Department( departmentId == $did )
$cust: CustomerObj( custId == $cid, department == $dep, moves >= 1 )
then
// whatever
end
请注意,您需要额外的规则来更改客户的部门参考和注册第一次移动,并且可能计算第二次移动之后的移动。