2017-12-12 7 views
-1

一部のタイムスロットで予約を作成しようとしていますが、そのタイムスロットが利用できるかどうかわかりません。だから私はスロットの空き状況を確認する必要があります。Groovyでタイムスロットの空き時間を達成するために使用するループ

ステップ1:現在の開始時刻と終了時刻を変数に設定します。 例:startDateTime(SDT)およびendDateTime(EDT)

ステップ2:DBのスロットの空き状況を確認します。 例えば:

def res = con.firstRow("select * from tblbookingitem where active=1 and fkItemID=$roomID and DateTimeFrom=$SDT and DateTimeTo=$EDT") 

ステップ3:スロットが利用できない場合は、次に、一時変数にstartDateTimeとendDateTimeをインクリメントし、再びDB可用性

注意を確認してください。これはループであるべきスロットまで使用可能

ステップ4 :スロットが利用可能な場合、プロパティに設定します。

すべての手順のコードを記述しましたが、ループを使用してこれをどのように達成する必要があります。

答えて

1
def isAvailable = false 
def SDT = context.expand('${#Project#StartDateTime}') 
def EDT = context.expand('${#Project#EndDateTime}') 
while(isAvailable==false) 
{ 
//Running while loop and checking slot availability. 
def res = con.firstRow("select * from tblbookingitem where active=1 and fkItemID=$roomID and DateTimeFrom='$SDT' and DateTimeTo='$EDT'") 

if(res== null) // if null that means slot is available 
    { 
     //Time slot is available." 
     isAvailable=true; // you can use even break statment here 
     context.testCase.testSuite.project.setPropertyValue('StartDateTime', SDT) 
     context.testCase.testSuite.project.setPropertyValue('EndDateTime', EDT) 
     log.info SDT 
     log.info EDT 
     break;  
    } 
else 
    { 
     //Increment Start and End Time 
     SDT=EDT 
     def slotinterval = context.expand('${#Project#SlotInterval}').toInteger() 
     log.info "Slot Interval : " + slotinterval 

     date1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(EDT) 
     use(TimeCategory) 
     { 
      def date2 = date1 + slotinterval.minutes 
      def outputDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" 
      EDT = "${date2.format(outputDateFormat)}"      
     } 

    } 

} 
1

以下の方法でforループを使用すると、達成できます。

def flag = false 

for(x=startdatetime,y=enddatetime;flag!=true ; x++ , y++) // you can change x++ and y++ for the the way you want to increase time limit each time 
{ 

// check slot available 
def res = con.firstRow("select * from tblbookingitem where active=1 and 
fkItemID=$roomID and DateTimeFrom=$SDT and DateTimeTo=$EDT") 

if(res!= null) // you can put the condition which says slot is available 
{ 
flag=true; // you can use even break statment here 
} 

} 

同様のロジックは少し異なる構文と同様に、一方ループによってアイデア

+1

おかげで実現することができます。 – rAJ

関連する問題