Java编写统计代理
import java.util.List;
import lotus.domino.*;
public class ReceiveCount extends AgentBase
{
public void NotesMain()
{
try
{
//定义发文单位和部门对象数组
List utilAndDeptList = new ArrayList();
//发文单位数组
List utilList = new ArrayList();
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
//当前数据库
Database currentDB = agentContext.getCurrentDatabase();
//获得签收视图
View view = currentDB.getView("viewReceiveCount");
//定义发文单位名称和发文部门
String utilName = "";
String deptName = "";
// 获得所有发文单位
boolean isExist = false;
Document doc = view.getFirstDocument();
while (doc != null)
{
//获得文档中的单位名称
utilName = doc.getItemValueString("DraftUnit");
//若不在发文单位数组中,则表示未添加过,则添加到发文单位数组
isExist = false;
for (int i = 0; i < utilList.size(); i++)
{
if (utilName.equals(utilList.get(i)))
{
isExist = true;
break;
}
}
if (!isExist)
{
utilList.add(utilName);
}
doc = view.getNextDocument(doc);
}
// 获得所有发文单位和部门的类
for (int i = 0; i < utilList.size(); i++)
{
//创建发文单位及部门名称的对象数组
UnitAndDept ud = new UnitAndDept();
//发文部门数组
List deptList = new ArrayList();
doc = view.getFirstDocument();
while (doc != null)
{
//获得文档中的发文单位和发文部门
utilName = doc.getItemValueString("DraftUnit");
deptName = doc.getItemValueString("DraftDepartment");
//若发文部门在数组中不存在,则添加
if (utilName.equals(utilList.get(i)))
{
isExist = false;
for (int j = 0; j < deptList.size(); j++)
{
if (deptName.equals(deptList.get(j)))
{
isExist = true;
break;
}
}
if (!isExist)
{
deptList.add(deptName);
}
}
doc = view.getNextDocument(doc);
}
//设置保存发文单位和单位下部门的数组的对象属性
ud.setUnitName((String) utilList.get(i));
ud.setDeptNameList(deptList);
//将发文单位和部门对象添加到数组中
utilAndDeptList.add(ud);
}
//定义输出的HTML表格头
String htmlString = "";
htmlString = htmlString + "<table cellpadding=3 cellspacing=1 class='tbbg' width=100% align=center>";
htmlString = htmlString + "<tr align='center' class='toptrbg'>";
htmlString = htmlString + "<td>No.</td>";
htmlString = htmlString + "<td>发文单位</td>";
htmlString = htmlString + "<td>发文部门</td>";
htmlString = htmlString + "<td>文件数</td>";
htmlString = htmlString + "<td>待签收</td>";
htmlString = htmlString + "<td>已签收</td>";
htmlString = htmlString + "<td>拒签收</td>";
htmlString = htmlString + "</tr>";
//以下变量用于输出
int no = 0;//序号
String utilNameInList = "";//单位名称
String deptNameInList = "";//部门名称
//定义部门名数组,用于在对象中读取
List deptNameList = null;
//循环所有单位名称及单位名称下的部门名,符合条件的记录全部统计输出
for (int i = 0; i < utilAndDeptList.size(); i++)
{
int totalCount = 0;//总文件数
int waitedFileCount = 0;//待签收的文件数
int receivedFileCount = 0;//已签收的文件数
int refusedFileCount = 0;//拒收的文件数
//在对象中获取单位名称和单位名称包括的部门名数组
utilNameInList = ((UnitAndDept) utilAndDeptList.get(i)).getUnitName();
deptNameList = ((UnitAndDept) utilAndDeptList.get(i)).getDeptNameList();
//循环部门名数组,找出符合条件的进行统计
for (int j = 0; j < deptNameList.size(); j++)
{
//获得数组中的一个部门名称
deptNameInList = (String)deptNameList.get(j);
//找出视图中单位名称和部门名称对应的记录
doc = view.getFirstDocument();
while (doc != null)
{
utilName = doc.getItemValueString("DraftUnit");
deptName = doc.getItemValueString("DraftDepartment");
//统计待签收、已签收、拒收的文档
if (utilName.equals(utilNameInList) && deptName.equals(deptNameInList))
{
if(doc.getItemValueString("RemoteStauts").equals("<font color=blue>待签收</font>"))
{
waitedFileCount++;
}
else if(doc.getItemValueString("RemoteStauts").equals("已签收"))
{
receivedFileCount++;
}
else
{
refusedFileCount++;
}
}
doc = view.getNextDocument(doc);
}
no++;//序号自增
//计算总文件数
totalCount = waitedFileCount + receivedFileCount + refusedFileCount;
//将统计后的结果输出
htmlString = htmlString + "<tr bgcolor=f8f8f8 align='center'>";
htmlString = htmlString + "<td>"+no+"</td>";
htmlString = htmlString + "<td>" + utilNameInList + "</td>";
htmlString = htmlString + "<td>"+deptNameInList+"</td>";
htmlString = htmlString + "<td>"+totalCount+"</td>";
htmlString = htmlString + "<td>"+waitedFileCount+"</td>";
htmlString = htmlString + "<td>"+receivedFileCount+"</td>";
htmlString = htmlString + "<td>"+refusedFileCount+"</td>";
htmlString = htmlString + "</tr>";
}
}
htmlString = htmlString + "</table>";
//将输出结果显示在表单中
Document currentDoc = agentContext.getDocumentContext();
currentDoc.replaceItemValue("htmlstr", htmlString);
}
catch (Exception e)
{
e.printStackTrace();
}
}
} 导入的类文件 import java.util.List;
public class UnitAndDept
{
String unitName;
List deptNameList;
public String getUnitName()
{
return unitName;
}
public void setUnitName(String unitName)
{
this.unitName = unitName;
}
public List getDeptNameList()
{
return deptNameList;
}
public void setDeptNameList(List deptNameList)
{
this.deptNameList = deptNameList;
}
}