Kevin Kok Khah Whey
2023-10-18 d5e46a7a9f2cb9123b9aafb39a20e14059faa2e4
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
Quintiq file version 2.0
#parent: #root
Method DoASyncMappingOperationData (
  Strings businessTypes,
  const GlobalOTDTable globalOTDTable,
  Strings organcodelist
)
{
  TextBody:
  [*
    // yypsybs Aug-18-2023 (created)
    // 获取有序的待处理记录
    toDealList := construct( Global_MappingOperations, constcontent ) ;
    if( not isnull( businessTypes ) and businessTypes.Size() > 0 ) {
        toDealList := selectsortedset( globalOTDTable, Global_MappingOperation, item, 
                                       ( businessTypes.Find( item.BusinessType() ) >= 0 ) and 
                                       ( organcodelist.Find( item.OrganCode() ) >= 0 ), 
    //                                   businessTypes.Difference( businessTypes.Difference( item.BusinessType().Tokenize( ", " ) ) ).Size() > 0, 
                                       item.SequenceNumber() );
    } else {
        toDealList := selectsortedset( globalOTDTable, Global_MappingOperation, item, 
                                       true, 
                                       item.SequenceNumber() );
    }
    // 逐条处理,首次处理时删除steps
    dealtRoutingIds := construct( Strings );
    routingList := construct( Routings );
    traverse( toDealList, Elements, item ) {
        routingId := item.OrganCode() + "_" + item.ProductID();
        unitId := item.OrganCode() + "_" + item.PlantName() + "_" + item.ProcessSection();
        routingStepName := item.ProcessSection() + "_" + [String]item.SequenceNumber();
        operationId := item.OrganCode() + "_" + item.ProductID() + "_" + item.ProcessSection()+"_" + [String]item.SequenceNumber();
    //    info( "========" )
    //    info( "routingId:" + routingId );
    //    info( "unitId:" + unitId );
    //    info( "routingStepName:" + routingStepName );
    //    info( "operationId:" + operationId );
        if( guard( item.Line(), "" ).Length() > 0 ) {
            unitId := unitId + "_" + item.Line();
            operationId := operationId + "_" + item.Line()
        }
        routing := Routing::CreateOrUpdate( this, routingId );
        if( routingList.Find( routing ) < 0 ) {
            routingList.Add( routing );  
        }
        // 删除steps(units关系、operations也会删除)
        if( dealtRoutingIds.Find( routingId ) < 0 ) {
            toDeleteSteps := selectset( routing, RoutingStep, routingStep, true );
            RoutingStep::Delete( toDeleteSteps );
            dealtRoutingIds.Add( routingId );
        }
        // RoutingStep
        routingStep := RoutingStep::FindByName( routing, routingStepName );
        if( isnull( routingStep ) ) {
            routingStep := RoutingStep::Create( routing, routingStepName, "", true );
        }
        
        // Unit
        unit := Unit::FindById( this, unitId );
        if( isnull( unit ) ) {
          // UnitOfMeasure
        unitOfMeasure := UnitOfMeasure_MP::FindByName( this, item.UnitOfMeasureName() );
          if( isnull( unitOfMeasure ) ) {
              info( "unit of measure [" + item.UnitOfMeasureName() + "] not found for routing [" + routingId + "]" );
          }
           unit := this.Unit( relnew, 
                              ID := unitId, Name := unitId, CapacityType := "Infinite",
                              DefaultGridX := 0, DefaultGridY := 0,
                              IsManuallyConfigured := false,
                              Currency_MP := this.BaseCurrency(), UnitOfMeasure_MP := unitOfMeasure );
        }
        // Operation
        haveMaxQty := item.MaximumQuantity() <> 0.0;
        op := Operation::FindOperationTypeIndex( operationId );
        if( isnull( op)){
          op := Operation::Create( operationId, unit, operationId, routingStep, 
                                        Duration::Days( item.UserLeadTime() ), Duration::Zero(), item.ActualCapacity(), false, 
                                        [Real]item.MinimumQuantity(), haveMaxQty, guard( [Real]item.MaximumQuantity(), Real::MaxReal() ), 
                                        0.0, 0.0, false, true );
        }
        
    //    ManufactureLTProcessSection::CreateOrUpdate( op );
    }
    info( "========" )
    // 遍历routing,进行link
    lastStep := null( RoutingStep );
    traverse( routingList, Elements.RoutingStep, step ) {
        // 同工艺路线时连接
        if( not isnull( lastStep ) and lastStep.Routing() = step.Routing() ) {
            toLink := construct( RoutingSteps );
            toLink.Add( lastStep );
            // todo 存疑
            step.LinkOperations( toLink );
        }
        lastStep := step;
    }
  *]
}