Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method MappingOperationData ( 
 | 
  Strings businessTypes, 
 | 
  GlobalOTDTable globalOTDTable, 
 | 
  Strings organcodelist 
 | 
) 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // yypsybs Aug-18-2023 (created) 
 | 
    // 获取有序的待处理记录 
 | 
    toDealList := construct( Global_MappingOperations ) ; 
 | 
    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; 
 | 
    } 
 | 
  *] 
 | 
} 
 |