田源
2025-01-09 8a166a60cfd1a2e593ffa103d10c0dc224fc8628
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.vci.client.uif.engine.client.compare.comparer;
 
import java.util.List;
 
import com.vci.client.uif.engine.client.compare.attribute.Attdef;
import com.vci.client.uif.engine.client.compare.attribute.AttrType;
import com.vci.client.uif.engine.client.compare.attribute.Attributes;
import com.vci.client.uif.engine.client.compare.dialog.treenode.TreeNodeObject;
import com.vci.client.uif.engine.client.compare.enumeration.CompareState;
import com.vci.client.uif.engine.client.compare.tools.CompareTools;
 
/**
 * 通用属性比较器
 * 
 * 通过 Attributes 设置获得需要比较的属性
 * 
 * @author VCI-STGK006
 *
 */
public class DefaultTreeNodeObjectComparer implements TreeNodeObjectComparer {
 
    @Override
    public void compare(Attributes attributes, TreeNodeObject lTno, TreeNodeObject rTno) {
        
        boolean result = true;
        if(lTno.getCompareState() == CompareState.ISNULL 
                ||rTno.getCompareState() == CompareState.ISNULL) {
            return;
        }
        if(lTno.getMainObject() == null) {
            lTno.setCompareState(CompareState.ISNULL);
            result = false;
        }
        if(rTno.getMainObject() == null) {
            rTno.setCompareState(CompareState.ISNULL);
            result = false;
        }
        if(!result) {
            return;
        }
        if(lTno.getRelationObject() == null) {
            lTno.setCompareState(CompareState.ISNULL);
            result = false;
        }
        if(rTno.getRelationObject() == null) {
            rTno.setCompareState(CompareState.ISNULL);
            result = false;
        }
        if(!result) {
            return;
        }
        
        List<Attdef> attdefList = attributes.getDisplayAttributes();
        for(Attdef ad : attdefList) {
            String lValue = lTno.getAttribute(ad.getlNodeObjectAttr(),
                    ad.islIsRelationAttr() ? TreeNodeObject.RELATIONOBJECT : TreeNodeObject.MAINOBJECT);
            String rValue = rTno.getAttribute(ad.getrNodeObjectAttr(),
                    ad.isrIsRelationAttr() ? TreeNodeObject.RELATIONOBJECT : TreeNodeObject.MAINOBJECT);
            if(ad.getAttrType() == AttrType.Number) {
                if(!CompareTools.validateNumber(lValue, rValue)) {
                    lTno.setCompareState(CompareState.DIFFERENT_INFO);
                    rTno.setCompareState(CompareState.DIFFERENT_INFO);
                    return;
                }
            } else {
                if(!lValue.equals(rValue)) {
                    lTno.setCompareState(CompareState.DIFFERENT_INFO);
                    rTno.setCompareState(CompareState.DIFFERENT_INFO);
                    return;
                }
            }
        }
    }
}