|
|
|
@ -10,21 +10,11 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class RuleModel {
|
|
|
|
|
private String TAG = "RuleModel";
|
|
|
|
|
private Long id;
|
|
|
|
|
public static final String FILED_TRANSPOND_ALL = "transpond_all";
|
|
|
|
|
public static final String FILED_PHONE_NUM = "phone_num";
|
|
|
|
|
public static final String FILED_MSG_CONTENT = "msg_content";
|
|
|
|
|
public static final String FILED_MULTI_MATCH="multi_match";
|
|
|
|
|
public static final String FILED_MULTI_MATCH = "multi_match";
|
|
|
|
|
public static final Map<String, String> FILED_MAP = new HashMap<String, String>();
|
|
|
|
|
static{
|
|
|
|
|
FILED_MAP.put("transpond_all", "转发全部");
|
|
|
|
|
FILED_MAP.put("phone_num", "手机号");
|
|
|
|
|
FILED_MAP.put("msg_content", "内容");
|
|
|
|
|
FILED_MAP.put("multi_match", "多重匹配");
|
|
|
|
|
}
|
|
|
|
|
private String filed;
|
|
|
|
|
|
|
|
|
|
public static final String CHECK_IS = "is";
|
|
|
|
|
public static final String CHECK_CONTAIN = "contain";
|
|
|
|
|
public static final String CHECK_START_WITH = "startwith";
|
|
|
|
@ -32,6 +22,13 @@ public class RuleModel {
|
|
|
|
|
public static final String CHECK_NOT_IS = "notis";
|
|
|
|
|
public static final Map<String, String> CHECK_MAP = new HashMap<String, String>();
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
FILED_MAP.put("transpond_all", "转发全部");
|
|
|
|
|
FILED_MAP.put("phone_num", "手机号");
|
|
|
|
|
FILED_MAP.put("msg_content", "内容");
|
|
|
|
|
FILED_MAP.put("multi_match", "多重匹配");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
CHECK_MAP.put("is", "是");
|
|
|
|
|
CHECK_MAP.put("contain", "包含");
|
|
|
|
@ -39,6 +36,10 @@ public class RuleModel {
|
|
|
|
|
CHECK_MAP.put("endwith", "结尾是");
|
|
|
|
|
CHECK_MAP.put("notis", "不是");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String TAG = "RuleModel";
|
|
|
|
|
private Long id;
|
|
|
|
|
private String filed;
|
|
|
|
|
private String check;
|
|
|
|
|
|
|
|
|
|
private String value;
|
|
|
|
@ -46,25 +47,64 @@ public class RuleModel {
|
|
|
|
|
private Long senderId;
|
|
|
|
|
private Long time;
|
|
|
|
|
|
|
|
|
|
public static String getRuleMatch(String filed, String check, String value) {
|
|
|
|
|
switch (filed) {
|
|
|
|
|
case FILED_TRANSPOND_ALL:
|
|
|
|
|
return "全部转发到 ";
|
|
|
|
|
default:
|
|
|
|
|
return "当 " + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 ";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getRuleFiledFromCheckId(int id) {
|
|
|
|
|
switch (id) {
|
|
|
|
|
case R.id.btnContent:
|
|
|
|
|
return FILED_MSG_CONTENT;
|
|
|
|
|
case R.id.btnPhone:
|
|
|
|
|
return FILED_PHONE_NUM;
|
|
|
|
|
case R.id.btnMultiMatch:
|
|
|
|
|
return FILED_MULTI_MATCH;
|
|
|
|
|
default:
|
|
|
|
|
return FILED_TRANSPOND_ALL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getRuleCheckFromCheckId(int id) {
|
|
|
|
|
switch (id) {
|
|
|
|
|
case R.id.btnContain:
|
|
|
|
|
return CHECK_CONTAIN;
|
|
|
|
|
case R.id.btnStartWith:
|
|
|
|
|
return CHECK_START_WITH;
|
|
|
|
|
case R.id.btnEndWith:
|
|
|
|
|
return CHECK_END_WITH;
|
|
|
|
|
case R.id.btnNotIs:
|
|
|
|
|
return CHECK_NOT_IS;
|
|
|
|
|
default:
|
|
|
|
|
return CHECK_IS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//字段分支
|
|
|
|
|
public boolean checkMsg(SmsVo msg) throws Exception {
|
|
|
|
|
|
|
|
|
|
//检查这一行和上一行合并的结果是否命中
|
|
|
|
|
boolean mixChecked=false;
|
|
|
|
|
if(msg!=null){
|
|
|
|
|
boolean mixChecked = false;
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
//先检查规则是否命中
|
|
|
|
|
switch (this.filed){
|
|
|
|
|
switch (this.filed) {
|
|
|
|
|
case FILED_TRANSPOND_ALL:
|
|
|
|
|
mixChecked= true;
|
|
|
|
|
mixChecked = true;
|
|
|
|
|
break;
|
|
|
|
|
case FILED_PHONE_NUM:
|
|
|
|
|
mixChecked= checkValue(msg.getMobile());
|
|
|
|
|
mixChecked = checkValue(msg.getMobile());
|
|
|
|
|
break;
|
|
|
|
|
case FILED_MSG_CONTENT:
|
|
|
|
|
mixChecked= checkValue(msg.getContent());
|
|
|
|
|
mixChecked = checkValue(msg.getContent());
|
|
|
|
|
break;
|
|
|
|
|
case FILED_MULTI_MATCH:
|
|
|
|
|
mixChecked= RuleLineUtils.checkRuleLines(msg,this.value);
|
|
|
|
|
mixChecked = RuleLineUtils.checkRuleLines(msg, this.value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
@ -73,33 +113,33 @@ public class RuleModel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "rule:"+this+" checkMsg:"+msg+" checked:"+mixChecked);
|
|
|
|
|
Log.i(TAG, "rule:" + this + " checkMsg:" + msg + " checked:" + mixChecked);
|
|
|
|
|
return mixChecked;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//内容分支
|
|
|
|
|
public boolean checkValue(String msgValue){
|
|
|
|
|
boolean checked=false;
|
|
|
|
|
public boolean checkValue(String msgValue) {
|
|
|
|
|
boolean checked = false;
|
|
|
|
|
|
|
|
|
|
if(this.value!=null){
|
|
|
|
|
switch (this.check){
|
|
|
|
|
if (this.value != null) {
|
|
|
|
|
switch (this.check) {
|
|
|
|
|
case CHECK_IS:
|
|
|
|
|
checked=this.value.equals(msgValue);
|
|
|
|
|
checked = this.value.equals(msgValue);
|
|
|
|
|
break;
|
|
|
|
|
case CHECK_CONTAIN:
|
|
|
|
|
if(msgValue!=null){
|
|
|
|
|
checked=msgValue.contains(this.value);
|
|
|
|
|
if (msgValue != null) {
|
|
|
|
|
checked = msgValue.contains(this.value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case CHECK_START_WITH:
|
|
|
|
|
if(msgValue!=null){
|
|
|
|
|
checked=msgValue.startsWith(this.value);
|
|
|
|
|
if (msgValue != null) {
|
|
|
|
|
checked = msgValue.startsWith(this.value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case CHECK_END_WITH:
|
|
|
|
|
if(msgValue!=null){
|
|
|
|
|
checked=msgValue.endsWith(this.value);
|
|
|
|
|
if (msgValue != null) {
|
|
|
|
|
checked = msgValue.endsWith(this.value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
@ -107,29 +147,18 @@ public class RuleModel {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "checkValue "+msgValue+" "+this.check+" "+this.value+" checked:"+checked);
|
|
|
|
|
Log.i(TAG, "checkValue " + msgValue + " " + this.check + " " + this.value + " checked:" + checked);
|
|
|
|
|
|
|
|
|
|
return checked;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getRuleMatch() {
|
|
|
|
|
switch (filed){
|
|
|
|
|
case FILED_TRANSPOND_ALL:
|
|
|
|
|
return "全部转发到 ";
|
|
|
|
|
default:
|
|
|
|
|
return "当 "+FILED_MAP.get(filed)+" "+CHECK_MAP.get(check)+" "+value+" 转发到 ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public static String getRuleMatch(String filed, String check, String value) {
|
|
|
|
|
switch (filed) {
|
|
|
|
|
case FILED_TRANSPOND_ALL:
|
|
|
|
|
return "全部转发到 ";
|
|
|
|
|
default:
|
|
|
|
|
return "当 " + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 ";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -138,8 +167,8 @@ public class RuleModel {
|
|
|
|
|
return senderId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getRuleFiledCheckId(){
|
|
|
|
|
switch (filed){
|
|
|
|
|
public int getRuleFiledCheckId() {
|
|
|
|
|
switch (filed) {
|
|
|
|
|
case FILED_MSG_CONTENT:
|
|
|
|
|
return R.id.btnContent;
|
|
|
|
|
case FILED_PHONE_NUM:
|
|
|
|
@ -151,21 +180,8 @@ public class RuleModel {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getRuleFiledFromCheckId(int id){
|
|
|
|
|
switch (id){
|
|
|
|
|
case R.id.btnContent:
|
|
|
|
|
return FILED_MSG_CONTENT;
|
|
|
|
|
case R.id.btnPhone:
|
|
|
|
|
return FILED_PHONE_NUM;
|
|
|
|
|
case R.id.btnMultiMatch:
|
|
|
|
|
return FILED_MULTI_MATCH;
|
|
|
|
|
default:
|
|
|
|
|
return FILED_TRANSPOND_ALL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getRuleCheckCheckId(){
|
|
|
|
|
switch (check){
|
|
|
|
|
public int getRuleCheckCheckId() {
|
|
|
|
|
switch (check) {
|
|
|
|
|
case CHECK_CONTAIN:
|
|
|
|
|
return R.id.btnContain;
|
|
|
|
|
case CHECK_START_WITH:
|
|
|
|
@ -179,21 +195,6 @@ public class RuleModel {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getRuleCheckFromCheckId(int id){
|
|
|
|
|
switch (id){
|
|
|
|
|
case R.id.btnContain:
|
|
|
|
|
return CHECK_CONTAIN;
|
|
|
|
|
case R.id.btnStartWith:
|
|
|
|
|
return CHECK_START_WITH;
|
|
|
|
|
case R.id.btnEndWith:
|
|
|
|
|
return CHECK_END_WITH;
|
|
|
|
|
case R.id.btnNotIs:
|
|
|
|
|
return CHECK_NOT_IS;
|
|
|
|
|
default:
|
|
|
|
|
return CHECK_IS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Long getId() {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|