Quintiq file version 2.0
|
#parent: #root
|
StaticMethod GenerateDispatchData (
|
Date startDate,
|
Date endDate,
|
const NewOfflinePlanTable offlinePlan,
|
RecycleBin owner
|
)
|
{
|
TextBody:
|
[*
|
// Akari Sep-4-2024 (created)
|
owner.DispatchShiftSchedulingLine( relflush );
|
macroPlan := offlinePlan.MacroPlan();
|
now := DateTime::Now();
|
|
shiftPatterns := selectset( macroPlan,ShiftPattern,object,true );
|
shiftPatternIndexTree := NamedValueTree::Create();
|
for( i := 0; i < shiftPatterns.Size(); i++){
|
shiftPattern := shiftPatterns.Element( i );
|
shiftPatternHandle := shiftPatternIndexTree.GetHandle( shiftPattern.Name() );
|
shiftPatternIndexTree.Root().AddChild( shiftPatternHandle,i );
|
}
|
|
units := selectset( macroPlan,Unit,object, true );
|
unitIndexTree := NamedValueTree::Create();
|
for( i := 0; i < units.Size(); i++){
|
unit := units.Element( i );
|
unitHandle := unitIndexTree.GetHandle( unit.Name() );
|
unitIndexTree.Root().AddChild( unitHandle,i );
|
}
|
|
lines := construct( DispatchShiftSchedulingLines );
|
lineIndexTree := NamedValueTree::Create();
|
|
products := construct( DispatchShiftSchedulingProducts );
|
productIndexTree := NamedValueTree::Create();
|
|
//productionDetails := construct( DispatchShiftSchedulingDetails );
|
//productionDetailIndexTree := NamedValueTree::Create();
|
traverse( offlinePlan,NewOfflinePlanRow,row ,not row.ProductionLine().ToUpper().LikeUserLocale( "MOMO" )){
|
line := null( DispatchShiftSchedulingLine );
|
factory := constnull( Unit );
|
unit := constnull( Unit );
|
{
|
unitHandle := unitIndexTree.GetHandle( row.ProductionLine() );
|
unitIndex := guard( unitIndexTree.Root().Child( unitHandle ), null( NamedValue ));
|
if( not isnull( unitIndex )){
|
unit := units.Element( unitIndex.GetValueAsNumber() );
|
factory := LocalTool::GetFactoryByUnit( unit );
|
}
|
}
|
|
traverse( row,NewOfflinePlanCell,cell, startDate <= cell.NewOfflinePlanColumn().StartDate() and endDate >= cell.NewOfflinePlanColumn().EndDate()){
|
product := null( DispatchShiftSchedulingProduct );
|
tips := "";
|
if( not isnull( unit )){
|
tips := ShiftPlan::CalculateRemark( unit,cell.NewOfflinePlanColumn().StartDate(),cell.NewOfflinePlanColumn().EndDate() );
|
}
|
{
|
lineKey := row.ProductionLine() + cell.NewOfflinePlanColumn().StartDate().AsQUILL();
|
lineHandle := lineIndexTree.GetHandle( lineKey );
|
lineIndex := guard( lineIndexTree.Root().Child( lineHandle ),null( NamedValue ));
|
if( isnull( lineIndex )){
|
line := owner.DispatchShiftSchedulingLine( relnew,ID := IDHolder::GetGUID(),LineName := row.ProductionLine(),ShiftDate := cell.NewOfflinePlanColumn().StartDate(),Tips := tips );
|
line.FactoryName( factory.Name() );
|
line.InterfaceTime( now );
|
line.VersionName( macroPlan.MDSMacroPlan().Description() );
|
line.ShiftName( cell.ShiftPatternName() );
|
lines.Add( line );
|
lineIndexTree.Root().AddChild( lineHandle,lines.Size() - 1 );
|
}else{
|
line := lines.Element( lineIndex.GetValueAsNumber() );
|
}
|
|
productHandle := productIndexTree.GetHandle( lineKey + row.ProductID() );
|
productIndex := guard( productIndexTree.Root().Child( productHandle ),null( NamedValue ));
|
if( isnull( productIndex )){
|
product := line.DispatchShiftSchedulingProduct( relnew,ProductID := row.ProductID() );
|
product.ProductionQuantity( cell.Quantity() );
|
products.Add( product );
|
productIndexTree.Root().AddChild( productHandle,products.Size() - 1 );
|
}else{
|
product := products.Element( productIndex.GetValueAsNumber() );
|
}
|
}
|
}
|
}
|
|
traverse( macroPlan,NewAssemblyOnlinePlanRow,row , row.ProductionLine().ToUpper().LikeUserLocale( "MOMO" )){
|
line := null( DispatchShiftSchedulingLine );
|
factory := constnull( Unit );
|
unit := constnull( Unit );
|
{
|
unitHandle := unitIndexTree.GetHandle( row.ProductionLine() );
|
unitIndex := guard( unitIndexTree.Root().Child( unitHandle ), null( NamedValue ));
|
if( not isnull( unitIndex )){
|
unit := units.Element( unitIndex.GetValueAsNumber() );
|
temp1 := unit;
|
temp2 := unit.Parent();
|
while( not isnull( temp1.Parent())){
|
temp2 := temp1;
|
temp1 := temp1.Parent();
|
}
|
factory := temp2;
|
}
|
}
|
|
traverse( row,NewAssemblyOnlinePlanCell,cell, startDate <= cell.NewAssemblyOnlinePlanColumn().StartDate() and endDate >= cell.NewAssemblyOnlinePlanColumn().EndDate()){
|
product := null( DispatchShiftSchedulingProduct );
|
tips := "";
|
if( not isnull( unit )){
|
tips := ShiftPlan::CalculateRemark( unit,cell.NewAssemblyOnlinePlanColumn().StartDate(),cell.NewAssemblyOnlinePlanColumn().EndDate() );
|
}
|
{
|
lineKey := row.ProductionLine() + cell.NewAssemblyOnlinePlanColumn().StartDate().AsQUILL();
|
lineHandle := lineIndexTree.GetHandle( lineKey );
|
lineIndex := guard( lineIndexTree.Root().Child( lineHandle ),null( NamedValue ));
|
if( isnull( lineIndex )){
|
line := owner.DispatchShiftSchedulingLine( relnew,ID := IDHolder::GetGUID(),LineName := row.ProductionLine(),ShiftDate := cell.NewAssemblyOnlinePlanColumn().StartDate(),Tips := tips );
|
line.FactoryName( factory.Name() );
|
line.InterfaceTime( now );
|
line.VersionName( macroPlan.MDSMacroPlan().Description() );
|
line.ShiftName( cell.ShiftPatternName() );
|
lines.Add( line );
|
lineIndexTree.Root().AddChild( lineHandle,lines.Size() - 1 );
|
}else{
|
line := lines.Element( lineIndex.GetValueAsNumber() );
|
}
|
|
productHandle := productIndexTree.GetHandle( lineKey + row.ProductID() );
|
productIndex := guard( productIndexTree.Root().Child( productHandle ),null( NamedValue ));
|
if( isnull( productIndex )){
|
product := line.DispatchShiftSchedulingProduct( relnew,ProductID := row.ProductID() );
|
product.ProductionQuantity( cell.Quantity() );
|
products.Add( product );
|
productIndexTree.Root().AddChild( productHandle,products.Size() - 1 );
|
}else{
|
product := products.Element( productIndex.GetValueAsNumber() );
|
}
|
}
|
}
|
}
|
|
traverse( lines,Elements,line ){
|
line.CalcLineQuantity();
|
|
unit := constnull( Unit );
|
{
|
unitHandle := unitIndexTree.GetHandle( line.LineName() );
|
unitIndex := guard( unitIndexTree.Root().Child( unitHandle ), null( NamedValue ));
|
if( not isnull( unitIndex )){
|
unit := units.Element( unitIndex.GetValueAsNumber() );
|
}
|
}
|
|
// 481
|
lineQuantity := line.LineQuantity();
|
|
tempProducts := selectsortedset( line,DispatchShiftSchedulingProduct,object,object.ProductionQuantity() );
|
|
if( line.ShiftName() = "3" ){
|
|
singleShiftVolume1 := 0.0;
|
singleShiftVolume2 := 0.0;
|
singleShiftVolume3 := 0.0;
|
|
singleShiftConfig := select( unit,SingleShiftConfig,config,config.ShiftName() = "3" );
|
if( not isnull( singleShiftConfig ) ){
|
if( line.Tips().LikeUserLocale( "保养" )){
|
singleShiftVolume1 := 0.0;
|
singleShiftVolume2 := singleShiftConfig.SecondSingleShiftQuantity();
|
singleShiftVolume3 := singleShiftConfig.ThirdSingleShiftQuantity();
|
}else{
|
singleShiftVolume1 := singleShiftConfig.FirstSingleShiftQuantity();
|
singleShiftVolume2 := singleShiftConfig.SecondSingleShiftQuantity();
|
singleShiftVolume3 := singleShiftConfig.ThirdSingleShiftQuantity();
|
}
|
}else{
|
if( line.Tips().LikeUserLocale( "保养" )){
|
singleShiftVolume1 := 0.0;
|
singleShiftVolume2 := lineQuantity / 2;
|
singleShiftVolume3 := lineQuantity / 2;
|
}else{
|
singleShiftVolume1 := lineQuantity / 3;
|
singleShiftVolume2 := lineQuantity / 3;
|
singleShiftVolume3 := lineQuantity / 3;
|
}
|
}
|
|
for( i := tempProducts.Size() - 1;i >= 0; i-- ){
|
product := tempProducts.Element( i );
|
productionQuantity := product.ProductionQuantity();
|
|
if( line.Tips().LikeUserLocale( "保养" ) and productionQuantity > 0){
|
product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := 0 ,SingleShiftName := "白班");
|
}
|
|
if( singleShiftVolume1 > 0 and productionQuantity > 0){
|
tempProductQuantity := singleShiftVolume1 - productionQuantity;
|
detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume1 ) ,SingleShiftName := "白班");
|
singleShiftVolume1 := singleShiftVolume1 - productionQuantity;
|
productionQuantity := productionQuantity - detail.ShiftVolume();
|
}
|
if(singleShiftVolume2 > 0 and productionQuantity > 0){
|
tempProductQuantity := singleShiftVolume2 - productionQuantity;
|
detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume2 ) ,SingleShiftName := "二班");
|
singleShiftVolume2 := singleShiftVolume2 - productionQuantity;
|
productionQuantity := productionQuantity - detail.ShiftVolume();
|
}
|
if(singleShiftVolume3 > 0 and productionQuantity > 0){
|
tempProductQuantity := singleShiftVolume3 - productionQuantity;
|
detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume3 ) ,SingleShiftName := "三班");
|
singleShiftVolume3 := singleShiftVolume3 - productionQuantity;
|
productionQuantity := productionQuantity - detail.ShiftVolume();
|
}
|
}
|
|
}else if( (line.ShiftName() = "2") or (line.ShiftName() = "9+9") or (line.ShiftName() = "10+10") or (line.ShiftName() = "11+11") ){
|
// 240.5
|
singleShiftVolume1 := 0.0;
|
singleShiftVolume2 := 0.0;
|
|
singleShiftConfig := select( unit,SingleShiftConfig,config,config.ShiftName() = line.ShiftName() );
|
if( not isnull( singleShiftConfig )){
|
if( line.Tips().LikeUserLocale( "保养" )){
|
singleShiftVolume1 := 0.0;
|
singleShiftVolume2 := singleShiftConfig.SecondSingleShiftQuantity();
|
}else{
|
singleShiftVolume1 := singleShiftConfig.FirstSingleShiftQuantity();
|
singleShiftVolume2 := singleShiftConfig.SecondSingleShiftQuantity();
|
}
|
}else{
|
if( line.Tips().LikeUserLocale( "保养" )){
|
singleShiftVolume1 := 0.0;
|
singleShiftVolume2 := lineQuantity;
|
}else{
|
singleShiftVolume1 := lineQuantity / 2;
|
singleShiftVolume2 := lineQuantity / 2;
|
}
|
}
|
|
for( i := tempProducts.Size() - 1;i >= 0; i-- ){
|
product := tempProducts.Element( i );
|
productionQuantity := product.ProductionQuantity();
|
|
if( line.Tips().LikeUserLocale( "保养" ) and productionQuantity > 0){
|
product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := 0 ,SingleShiftName := "白班");
|
}
|
|
if( singleShiftVolume1 > 0 and productionQuantity > 0){
|
// -47.5
|
tempProductQuantity := singleShiftVolume1 - productionQuantity;
|
detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume1 ) ,SingleShiftName := "白班");
|
singleShiftVolume1 := singleShiftVolume1 - productionQuantity;
|
productionQuantity := productionQuantity - detail.ShiftVolume();
|
}
|
if(singleShiftVolume2 > 0 and productionQuantity > 0){
|
tempProductQuantity := singleShiftVolume2 - productionQuantity;
|
detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume2 ) ,SingleShiftName := "二班");
|
singleShiftVolume2 := singleShiftVolume2 - productionQuantity;
|
productionQuantity := productionQuantity - detail.ShiftVolume();
|
}
|
}
|
|
}else if( line.ShiftName() = "1" ){
|
singleShiftVolume1 := lineQuantity;
|
|
for( i := tempProducts.Size() - 1;i >= 0; i-- ){
|
product := tempProducts.Element( i );
|
productionQuantity := product.ProductionQuantity();
|
if( singleShiftVolume1 > 0 and productionQuantity > 0){
|
tempProductQuantity := singleShiftVolume1 - productionQuantity;
|
detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume1 ) ,SingleShiftName := "白班");
|
singleShiftVolume1 := singleShiftVolume1 - productionQuantity;
|
productionQuantity := productionQuantity - detail.ShiftVolume();
|
}
|
}
|
|
}else{
|
info( "不支持的班次名称【" + line.ShiftName() + "】");
|
}
|
}
|
|
traverse( lines,Elements.DispatchShiftSchedulingProduct.DispatchShiftSchedulingDetail,detail ){
|
detail.ShiftVolume( detail.ShiftVolume() );
|
}
|
|
info( "Success" );
|
*]
|
}
|