admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Quintiq file version 2.0
#parent: #root
StaticMethod Compared (
  RecycleBin recycleBin,
  const MacroPlan mactoPlan,
  String baseVersionPath,
  String compareVersionPath,
  String baseVersionName,
  String compareVersionName
) as LocalTable
{
  TextBody:
  [*
    // rislai Jun-20-2024 (created)
    localTable := recycleBin.LocalTable( relnew,Name := baseVersionName + "__" + compareVersionName );
    
    products := selectset( mactoPlan,Product_MP,product,not product.IsSystem() and product.IsUsed() );
    productIndexTree := NamedValueTree::Create();
    try{
      for( i := 0; i < products.Size(); i++){
        product := products.Element( i );
        productHandle := productIndexTree.GetHandle( product.Notes() );
        productIndexTree.Root().AddChild( productHandle,i )
      }
    }onerror{}
    
    
    baseVersionFile := OSFile::Construct();
    compareVersionFile := OSFile::Construct();
    
    try {
      baseVersionFile.Open( baseVersionPath, "Read", false );
      baseVersionDataSource := GeneralExcelImportAndExportDataSource::Upload( recycleBin, baseVersionFile.ReadBinary(), baseVersionPath );
      baseVersionDataSource.ReadStructure();
      
      compareVersionFile.Open( compareVersionPath, "Read", false );
      compareVersionDataSource := GeneralExcelImportAndExportDataSource::Upload( recycleBin, compareVersionFile.ReadBinary(), compareVersionPath );
      compareVersionDataSource.ReadStructure();
      
      baseVersionTable := select( baseVersionDataSource, GeneralExcelImportAndExportDataTable, tempGEIAEDT, true );
      compareVersionTable := select( compareVersionDataSource, GeneralExcelImportAndExportDataTable, tempGEIAEDT, true );
      
      if( not isnull( baseVersionTable ) and not isnull( compareVersionTable )){
        
        //生成行数据
        rowKeys := construct( Strings );
        rowKeyIndexTree := NamedValueTree::Create();
        
        baseVersionRowTree := NamedValueTree::Create();
        baseVersionRows := construct( GeneralExcelImportAndExportDataRows ,constcontent);
        compareVersionRowTree := NamedValueTree::Create();
        compareVersionRows := construct( GeneralExcelImportAndExportDataRows ,constcontent);
        LocalCell_DemandComparison::FillRows( baseVersionTable,rowKeys,rowKeyIndexTree,baseVersionRowTree,baseVersionRows );
        LocalCell_DemandComparison::FillRows( compareVersionTable,rowKeys,rowKeyIndexTree,compareVersionRowTree,compareVersionRows );
        
        // 生成列数据
        columnTree := NamedValueTree::Create();
        columns := construct( LocalColumns );
        LocalCell_DemandComparison::GenerateColumnIndex( baseVersionTable,localTable,columnTree,columns );
        LocalCell_DemandComparison::GenerateColumnIndex( compareVersionTable,localTable,columnTree,columns );
        columnNames := selectvalues( columns,Elements,column,true,column.CustomName());
        
        // 生成数据
        for ( rowIndex := 0; rowIndex < rowKeys.Size(); rowIndex++ ) {
          rowKey := rowKeys.Element( rowIndex );
          
          baseVersionCellTree := NamedValueTree::Create();
          baseVersionCells := construct( GeneralExcelImportAndExportDataCells ,constcontent);
          
          compareVersionCellTree := NamedValueTree::Create();
          compareVersionCells := construct( GeneralExcelImportAndExportDataCells ,constcontent);
          
          LocalCell_DemandComparison::FillCells( rowKey,baseVersionRowTree,baseVersionRows,baseVersionCellTree,baseVersionCells );
          LocalCell_DemandComparison::FillCells( rowKey,compareVersionRowTree,compareVersionRows,compareVersionCellTree,compareVersionCells );
          
          row := localTable.LocalRow( relnew,Index := localTable.GetRowIndexCache()  );
          
          traverse( columnNames,Elements,columnName ,columnName <> "" ){
            columnHandle := columnTree.GetHandle( columnName );
            columnIndex := guard( columnTree.Root().Child( columnHandle ) , null( NamedValue ));
            column := null( LocalColumn );
            if( not isnull( columnIndex )){
              column := columns.Element( columnIndex.GetValueAsNumber() );
            }
            if( isnull( column )){
              error( columnName + " is null." ); 
            }
            
            baseVersionCell := constnull( GeneralExcelImportAndExportDataCell );
            baseVersionCellHandle := baseVersionCellTree.GetHandle( columnName );
            baseVersionCellIndex := guard( baseVersionCellTree.Root().Child( baseVersionCellHandle ),null( NamedValue ));
            if( not isnull( baseVersionCellIndex )){
              baseVersionCell := baseVersionCells.Element( baseVersionCellIndex.GetValueAsNumber() );
            }
            
            compareVersionCell := constnull( GeneralExcelImportAndExportDataCell );
            compareVersionCellHandle := compareVersionCellTree.GetHandle( columnName );
            compareVersionCellIndex := guard( compareVersionCellTree.Root().Child( compareVersionCellHandle ),null( NamedValue ));
            if( not isnull( compareVersionCellIndex )){
              compareVersionCell := compareVersionCells.Element( compareVersionCellIndex.GetValueAsNumber() );
            }
            
            if( columnName = "产地" or columnName = "车型" or columnName = "发动机零件号" or columnName = "发动机四位码" ){
              row.LocalCell( relnew,LocalCell_DemandComparison,LocalColumn := column,
                             BaseVersionValue := ifexpr( isnull( baseVersionCell ), "空", baseVersionCell.Value()),
                             CompareVersionValue := ifexpr( isnull( compareVersionCell ),"空",compareVersionCell.Value()));
              column.IsAttrbuteColumn( true );
              if( columnName = "发动机零件号" ){
                productID := ifexpr( isnull( baseVersionCell ), ifexpr( isnull( compareVersionCell ),"空",compareVersionCell.Value()), baseVersionCell.Value());
                
                productHanlde := productIndexTree.GetHandle( productID );
                productIndex := guard( productIndexTree.Root().Child( productHanlde ), null( NamedValue ));
                if( not isnull( productIndex )){
                  product := products.Element( productIndex.GetValueAsNumber() );
                  productID := product.ID();
                }
                
                row.ProductID( productID );
                
              }
              if( columnName = "车型" ){
                row.CustomName( " > " + ifexpr( isnull( baseVersionCell ), ifexpr( isnull( compareVersionCell ),"空",compareVersionCell.Value()), baseVersionCell.Value()) );
              }
            }else{
              row.LocalCell( relnew,LocalCell_DemandComparison,LocalColumn := column,
                             BaseVersion := ifexpr( isnull( baseVersionCell ),0,[Real]baseVersionCell.Value()),
                             CompareVersion := ifexpr( isnull( compareVersionCell ), 0 ,[Real]compareVersionCell.Value() ));
            }
          }
          row.CustomName( row.ProductID() + row.CustomName() );
        }
      }
      // 后续删除
      baseVersionDataSource.Delete();
      compareVersionDataSource.Delete();
      
      baseVersionFile.Close();
      compareVersionFile.Close();
    } onerror {
      if( not isnull( baseVersionFile )){
        baseVersionFile.Close(); 
      }
      if( not isnull( compareVersionFile )){
        compareVersionFile.Close(); 
      }
      error( e.GeneralInformation() );
    }
    
    return localTable;
  *]
}