经过对上次设计的代码的深思熟虑,考虑的代码的可重用行和易读性,还有xml规则文件的易维护性,将代码做了部分的调整。
xml格式如下例:
<?xml version="1.0" encoding="UTF-8"?>
<Rules>
<rule>
<pk_marbasclass>2QP5</pk_marbasclass>
<org>
<business_org>all</business_org>
<cost_org>all</cost_org>
</org>
<stock>
<martypes>
<martype01>
<stockorg>0001A11000000003ENHG</stockorg>
<martypecode>PR</martypecode>
</martype01>
<martype02>
<stockorg>others</stockorg>
<martypecode>MR</martypecode>
</martype02>
</martypes>
<wholemanaflags>
<wholemanaflag01>
<stockorg>0001A110000000000GE3</stockorg>
<wholemanaflagcode>Y</wholemanaflagcode>
</wholemanaflag01>
<wholemanaflag02>
<stockorg>others</stockorg>
<wholemanaflagcode>N</wholemanaflagcode>
</wholemanaflag02>
</wholemanaflags>
以rule作为规格类别,以pk_marbasclass区分rule,剩下的拿stock标签内为例说吧,martypes页签规则如果stockorg为all则统一设置,否则可以单独设置,如果以others为结尾规则,则除去单独设置的,其他都为others规则。
部分逻辑校验代码如下:
List<String[]> others = new ArrayList<String[]>(stocklist);
for(int i = 0; i < ruleMaps.size(); i++){
Map<String,String> rule = (Map<String, String>) ruleMaps.get(parentRule+(i+1));
String stockorg = rule.get(firstRule);
String martypecode = rule.get(secondRule);
if(stockorg!=null&&stockorg.equals("all")&&ruleMaps.size()<=1&&martypecode!=null){//全规则,只设置一种规则的情况,如果规则长度大于1,且包含all规则,则报错
for(String[] vo : stocklist){
if(vo[1]==null)
errvo.add(vo);
else if(!vo[1].equals(martypecode))
errvo.add(vo);
}
}else if(stockorg!=null&&martypecode!=null&&!stockorg.equals("others")&&ruleMaps.size() > 1){//分步规则,将库存组织分开匹配规则
List<String> orgs = Arrays.asList(stockorg.split(","));
for(String[] vo : stocklist){
if(orgs.contains(vo[0])&&(!vo[1].equals(martypecode)||vo[1] == null))
errvo.add(vo);
if(orgs.contains(vo[0]))
others.remove(vo);
}
}else if(stockorg!=null&&martypecode!=null&&stockorg.equals("others")){//others 分步剩下的组织统一设置
for(String[] vo : others){
if(!vo[1].equals(martypecode)||vo[1] == null)
errvo.add(vo);
}
}else{
MessageDialog.showErrorDlg(null, "错误!", "规则文件规则配置错误,请修改后执行!");
return;
}
}
主要设计包含以上部分,细节不做展示,后续内容下次跟进~