如何检索不存在的东西?

时间:2012-08-16 01:05:04

标签: lotusscript

我有两个观点:view1和view2。

view1包含26名员工(A-Z)的列表。

view2包含每个员工每天创建的文档列表(每个员工每天只能创建1个文档)。这些doc中的每一个都包含创建它的人员的姓名, 以及创建它的日期(不是内置注释创建日期)。这意味着,2012年1月,员工A有31个文档, 2012年2月 - 29个文档,依此类推至今天(2012年8月16日 - 2012年8月的16个文档)。

我目前的情况是,对于一些员工来说,缺少文档。例如,工作人员A在2010年7月27日缺少文件, 工作人员B在2011年5月12日和2012年4月4日缺少文档,工作人员C等等。缺少的文档因员工而异。有些人没有遗漏的文件, 有些人缺少多达10个文档。

现在我想检索缺少doc的日期并将其放在文本文件中。说上面的工作人员B缺少2个文件 所述日期所以在我的文本文件中我将显示“Staff B - 5/12 / 2011,3 / 4/2012”。但是,如果它甚至不存在,我该如何检索 在第一个地方?

到目前为止,我只考虑计算一段时间的日期范围,例如2010年1月1日至2012年8月16日。计算那里有多少天 范围,然后计算员工的总文档数。如果总文档数不等于该范围内的天数,则会丢失一些文档。 但我仍然需要在哪个日期缺少文档。

2 个答案:

答案 0 :(得分:2)

您是否了解LotusScript中的List数据类型?我在想你应该创建一份涵盖日期范围的布尔值的详尽列表。即,该范围中的每一天都有一个列表条目,其中日期为listtag,条目值指示是否已找到该文档。您从一个已初始化的列表开始,以便每个日期都为false:

Dim theDate As New NotesDateTime("1/1/2005")
dim endDate as New NotesDateTime("8/16/2012")
dim foundDates List as Boolean

While theDate.Timedifference(endDate) <= 0
  foundDates(theDate.dateOnly) = false
wend

您可能需要在函数中使用上述代码,以便可以为每个工作人员重新初始化列表。

现在,您希望代码遍历您的员工的一个成员的所有文档。从doc中读取日期项,并将相应的列表条目更改为true。

dateObj = new NotesDateTime(doc.getItemValue("dateFieldName"))
foundDates(dateObj.dateOnly) = true

在循环通过工作人员的文档之后,您有一个List,其中包含找到的每个文档的日期的true,以及每个未找到的日期的false。

现在,您现在可以使用forall输出一个未找到的日期列表,只需检查仍然为假的条目。

print #textfile, StaffName;
ForAll dateEntry in foundDates
   if dateEntry = false then
      print #textfile, listtag(dateEntry)
   end if
End ForAll
print #textfile,

将所有上述内容整合到所有工作人员的循环中,确保在处理每个工作人员的文档之前,将foundDate列表中的所有条目重新初始化为false。

答案 1 :(得分:1)

我认为解决这个问题的最佳方法是走每个工作人员的日期范围并输出缺少的日期。

假设您正在考虑使用lotusscript,那么(未经过测试,视图的索引以及存储日期的方式可能会导致问题)。

Sub Initialize
    Dim session As New NotesSession
Dim db As NotesDatabase
Dim viewStaff As NotesView
Dim viewDocs As NotesView
Dim docStaff As NotesDocument
Dim docDoc As NotesDocument
Dim keys(1) As String
Dim startDate As New NotesDateTime("1/1/2005") 'Start date of Range
Dim endDate As New NotesDateTime("1/1/2010") 'End date of Range  
Dim tempDate As NotesDateTime

'Initialise Views
Set db = session.currentDatabase
Set viewStaff = db.GetView("StaffView")
Set viewDocs = db.GetView("DocsByStaff")

'Iterate over staff to process
Set docStaff = viewStaff.Getfirstdocument()
While Not docStaff Is Nothing
    'Search for daily docs for this staff member (this will need a view indexed on the staff member name, then the date)
    keys(0) = docStaff.Fullname(0) 'Or whatever this item is called

    Set tempDate = startDate
    While tempDate.Timedifference(endDate) <= 0 'Go over each date up to and including the end date
        keys(1) = tempdate.Dateonly
        Set docDoc = viewDocs.getDocumentByKey(keys) 'Search for date using current user and date
        If docDoc Is Nothing Then 'Haven't found it
            Print "Can't find document for " + keys(0) + " on " + keys(1) ' Could output to file or something here.
        End If
        tempDate.Adjustday(1) 'Roll forward another day
    Wend

    Set docStaff = viewStaff.getNextDocument(docStaff) 'Next staff member
Wend

End Sub

可能不是最有效的方式,但如果它偶尔出现并且你没有太多的文档,这种方法就足够了。

相关问题