yypsybs
2023-09-09 3cb5a54def670d97301f07170fcaad213bfc54f2
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
Quintiq file version 2.0
#parent: #root
Method MappingOperationData (
  Strings businessTypes
)
{
  TextBody:
  [*
    // 获取有序的待处理记录
    toDealList := construct( MappingOperations );
    if( not isnull( businessTypes ) and businessTypes.Size() > 0 ) {
        toDealList := selectsortedset( this, MappingOperation, item, 
                                       businessTypes.Find( item.BusinessType() ) >= 0, 
                                       item.SequenceNumber() );
    } else {
        toDealList := selectsortedset( this, MappingOperation, item, 
                                       true, 
                                       item.SequenceNumber() );
    }
    // 删除原有routing
    this.IORouting( relflush );
    // 新routing
    routingIdList := selectuniquevalues( toDealList, Elements, item, item.OrganCode() + "_" + item.ProductID() );
    traverse( routingIdList, Elements, routingId ) {
      this.IORouting( relnew, 
                      ID := routingId, Name := routingId, IsEnabled := true );
    }
    // 删除原有routingStep
    this.IORoutingStep( relflush );
    // 新routingStep
    traverse( toDealList, Elements, op ) {
      routingId := op.OrganCode() + "_" + op.ProductID();
      routingStepName := op.ProcessSection() + "_" + [String]op.SequenceNumber();
      IORoutingStep::CreateIfNotExist( this, 
                                       routingId,
                                       routingStepName,
                                       op.SequenceNumber() );
    }
    // 新operation
    traverse( toDealList, Elements, op ) {
      // 汇总数据
      routingId := op.OrganCode() + "_" + op.ProductID();
      routingStepName := op.ProcessSection() + "_" + [String]op.SequenceNumber();
      opId := op.OrganCode() + "_" + op.ProductID() + "_" + op.ProcessSection();
      unitId := op.OrganCode() + "_" + op.PlantName() + "_" + op.ProcessSection();
      if( op.Line() <> "" ) {
        opId := opId + "_" + op.Line();
        unitId := unitId + "_" + op.Line();
      }
      opName := opId;
      // 新建
      ioOp := IOOperation::CreateIfNotExist( this, opId );
      ioOp.UnitID( unitId );
      ioOp.RoutingID( routingId );
      ioOp.RoutingStepName( routingStepName );
      ioOp.Name( opName );
      ioOp.UserLeadTime( Duration::Hours( op.UserLeadTime() ) );
      ioOp.Throughput( op.ActualCapacity() );
      ioOp.UserMinimumQuantity( op.MinimumQuantity() );
      ioOp.UserMaximumQuantity( op.MaximumQuantity() );
      ioOp.HasUserMaximumQuantity( op.MaximumQuantity() <> 0.0 );
    }
    // 按 OrganCode + ProductID 分组 + 排序
    keyList := selectuniquevalues( toDealList, Elements, op, 
                                   op.OrganCode() + "_" + op.ProductID() );
    keyList := selectsortedset( keyList, Elements, str, str );
    traverse( keyList, Elements, key ) {
      previousList := construct( MappingOperations );
      // 按 SequenceNumber 分组 + 排序
      subKeyList := selectuniquevalues( toDealList, Elements, op, 
                                        key = op.OrganCode() + "_" + op.ProductID(),
                                        op.SequenceNumber() );
      subKeyList := selectsortedset( subKeyList, Elements, seq, seq );
      // 遍历每个Seq,与前一个list进行连接,同时创建group
      traverse( subKeyList, Elements, seq ) {
        elementList := selectset( this, MappingOperation, op, 
                                  op.OrganCode() + "_" + op.ProductID() = key and op.SequenceNumber() = seq );
        if( not isnull( previousList ) and previousList.Size() > 0 ) {
          // 对每个目标创建inputGroup
          if( previousList.Size() > 1 ) {
            traverse( elementList, Elements, targetOp ) {
              targetOpId := targetOp.OrganCode() + "_" + targetOp.ProductID() + "_" + targetOp.ProcessSection();
              this.IOOperationInputGroup( relnew, InputGroupID := 1, OperationID := targetOpId, InputGroupQuantity := 1 );
            }
          }
          // 源与目标两两创建operationLink
          traverse( elementList, Elements, targetOp ) {
            traverse( previousList, Elements, sourceOp ) {
              sourceOpId := sourceOp.OrganCode() + "_" + sourceOp.ProductID() + "_" + sourceOp.ProcessSection();
              targetOpId := targetOp.OrganCode() + "_" + targetOp.ProductID() + "_" + targetOp.ProcessSection();
              this.IOOperationLink( relnew, 
                                    SourceOperationID := sourceOpId, DestOperationID := targetOpId, 
                                    SourceGroupID := 1, DestGroupID := 1, SourceQuantity := 1, DestQuantity := 1 / previousList.Size(), 
                                    DestHasUserQuantity := false, DestMinQuantity := 0, DestMaxQuantity := 1 );
            }  
          }
        }
        previousList := elementList;
      }
    }
  *]
}