免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2142 | 回复: 0
打印 上一主题 下一主题

FileNet---javaAPI实现封闭报销流程(二) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-21 12:22 |只看该作者 |倒序浏览
少说话多做事,先把登记页面实现:
%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
%@ page contentType="text/html; charset=UTF-8" %>
html>
    head>
        title>报销登记/title>
    script type="text/javascript" src="js/common.js">/script>
    script type="text/javascript" src="js/calendar.js">/script>   
    /head>
    body>
        f:view>
        a4j:outputPanel ajaxRendered="true">
        h:messages />
        /a4j:outputPanel>
        
        h:form id="form1" enctype="multipart/form-data">
        table width="50%">
        tr>th align="left">报销人:/th>td>h:inputText value="#{fileNetManagedBean.bxPerson}" style="width:100%" id="bxr"/>/td>
        th align="left">报销时间:/th>td>h:inputText value="#{fileNetManagedBean.bxDate}" style="width:100%" id="bxsj"/>/td>
        /tr>
        th align="left">出差开始时间:/th>td>h:inputText value="#{fileNetManagedBean.startDate}" style="width:100%" id="kssj"/>/td>
        th align="left">出差结束时间:/th>td>h:inputText value="#{fileNetManagedBean.endDate}" id="jssj" style="width:100%"/>/td>
        tr>
        /tr>
        tr>th align="left">地点:/th>td colspan="3">h:inputText value="#{fileNetManagedBean.address}" style="width:100%" id="address"/>/td>/tr>
        tr>th align="left">天数:/th>td>h:inputText value="#{fileNetManagedBean.days}" id="days" onblur="calculate()"/>/td>
        th align="left">费用(一天):/th>td>h:inputText value="#{fileNetManagedBean.payPerDay}" onblur="calculate()" id="mtfy"/>/td>/tr>
        tr>th align="left">合计:/th>td>h:outputText value="#{fileNetManagedBean.totalPay}" id="total"/>/td>
        th align="left">合计金额:/th>td>h:outputText value="#{fileNetManagedBean.chineseTotal}" id="uperTotal"/>/td>/tr>
        tr>th colspan="4" align="left">出差事由:/th>/tr>
        tr>td colspan="4" >h:inputTextarea value="#{fileNetManagedBean.reason}" style="width:100%" id="reason"/>/td>/tr>
        tr>th colspan="4" align="left">备注:/th>/tr>
        tr>td colspan="4">h:inputTextarea value="#{fileNetManagedBean.remark}" style="width:100%" id="remark" />/td>/tr>
        tr>th>上传报销单:/th>td>t:inputFileUpload value="#{fileNetManagedBean.bxd_path}" id="bxdfj"/>/td>
        th>上传发票/th>td>t:inputFileUpload value="#{fileNetManagedBean.fp_path}" storage="file" id="fpfj"/>
        /td>
        /tr>
        /table>
        div align="center">
            h:commandButton action="#{fileNetManagedBean.submit}" value="提交" onclick="return checkForm();"/>
            input type="reset" value="重置"/>
        /div>
        a4j:commandButton action="#{fileNetManagedBean.sum}" value="" style="display:none" reRender="total,uperTotal" id="calculate">/a4j:commandButton>
        /h:form>
        /f:view>
    /body>   
/html>

其中a4j标签是一个Ajax实现,不了解的可以去看下.
在Bean里实现提交操作,关于附件这里还是有一点需要注意的,当我们在本地上传一个附件到CE上其实是要经过两个步骤的:先将附件上传到我们的Tomcat服务器上再推送到CE里面去,因为当用户在使用时候,Tomcat服务器是不会在用户的计算机上的,他提交的是本地的一个路径,如果我们的代码直接处理这个路径的话在服务器上是找不到这个文件的.
好了,这样我们就来实现方法:

public String submit(){
        VWSession vss = this.credential.getVWSession();
        //Connection connection = this.credential.getConnection();
        
        Domain domain = Factory.Domain.fetchInstance(this.logonCE(this.CONFIG_BUNDLE), "p8domain", null);
        ObjectStore objectStore = Factory.ObjectStore.fetchInstance(domain, "OStore", null);
        VWStepElement launchStep;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            launchStep = vss.createWorkflow("报销流程");
            //设置参数
            launchStep.setParameterValue("报销人", this.bxPerson, true);
            launchStep.setParameterValue("报销日期", format.parse(this.bxDate), true);
            launchStep.setParameterValue("出差开始时间", format.parse(this.startDate), true);
            launchStep.setParameterValue("出差结束时间", format.parse(this.endDate), true);
            launchStep.setParameterValue("地点", this.address, true);
            launchStep.setParameterValue("天数", this.days, true);
            launchStep.setParameterValue("每天费用", this.payPerDay, true);
            launchStep.setParameterValue("合计", this.totalPay, true);
            launchStep.setParameterValue("金额大写", this.chineseTotal, true);
            launchStep.setParameterValue("出差事由", this.reason, true);
            launchStep.setParameterValue("备注", this.remark, true);
            
            //报销单附件设置
            Folder folder = Factory.Folder.fetchInstance(objectStore, "/FileNet小组/高扬/2009/9月/报销单", null);
            
            String bxd_filePath = this.uploadFileToServer(this.bxd_path);//上传到服务器
            //推送到CE里面去
            this.uploadFile(folder,objectStore, this.systemClassPath+"/"+bxd_filePath, "cq_bxd","报销单");
            DocumentSet documentSet = folder.get_ContainedDocuments();
            IteratorDocument> it = documentSet.iterator();
            while(it.hasNext()){
                Document document = it.next();
                if (document.getClassName().equalsIgnoreCase("cq_bxd")) {
                    VWAttachment attachment = new VWAttachment();
                    attachment.setId(document.get_VersionSeries().get_Id().toString());
                    attachment.setVersion("-1");
                    attachment.setType(3);
                    attachment.setLibraryName("OStore");
                    
                    attachment.setLibraryType(3);
                    attachment.setAttachmentDescription(document.getProperties()
                            .getStringValue("DocumentTitle"));
                    attachment.setAttachmentName(document.getProperties()
                            .getStringValue("DocumentTitle"));
                    launchStep.setParameterValue("报销单", attachment, false);
                }
            }
            //发票附件设置
            Folder fp_folder = Factory.Folder.fetchInstance(objectStore, "/FileNet小组/高扬/2009/9月/发票", null);
            String fp_filePath = this.uploadFileToServer(this.fp_path);
            this.uploadFile(fp_folder, objectStore, this.systemClassPath+"/"+fp_filePath, "cq_fp","发票");
            DocumentSet fp_documentSet = fp_folder.get_ContainedDocuments();
            IteratorDocument> iterator = fp_documentSet.iterator();
            while(iterator.hasNext()){
                Document document = iterator.next();
                //System.out.println("_____________________"+document.getClassName());
                if (document.getClassName().equalsIgnoreCase("cq_fp")) {
                    VWAttachment attachment = new VWAttachment();
                    attachment.setId(document.get_VersionSeries().get_Id().toString());
                    attachment.setVersion("-1");
                    attachment.setType(3);
                    attachment.setLibraryName("OStore");
                    
                    attachment.setLibraryType(3);
                    attachment.setAttachmentDescription(document.getProperties()
                            .getStringValue("DocumentTitle"));
                    attachment.setAttachmentName(document.getProperties()
                            .getStringValue("DocumentTitle"));
                    launchStep.setParameterValue("发票", attachment, false);
                }
            }
            //启动流程
            launchStep.doDispatch();
            return "suc";
        }catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

将文件上传到Tomcat服务器方法很简单,这里不做描述,只写下推送到CE的方法:

* 从本地选择一个文件上传到CE目录中
     * @param folder
     * @param edFileuploadedFile
     * @param documentClass
     * @author 高扬 2009-9-17
     * @param string
     * @param objectStore
     */
    private String uploadFile(Folder folder,ObjectStore os, String filePath,String documentClass, String flag){
        Document doc = Factory.Document.createInstance(os, documentClass);
        ContentElementList contentList = Factory.ContentElement.createList();
        ContentTransfer transfer = Factory.ContentTransfer.createInstance();
        System.out.println(filePath+"++++++++++++++++++0");
        try {
            transfer.setCaptureSource(new FileInputStream(filePath));
        } catch (IOException e) {
            e.printStackTrace();
        }
     String fileType = "";
     if (filePath.indexOf(".jpg") != -1 || filePath.indexOf(".jpeg") != -1
                || filePath.indexOf(".JPG") != -1
                || filePath.indexOf(".JPEG") != -1) {
            fileType = "image/jpeg";
        } else if (filePath.indexOf(".gif") != -1
                || filePath.indexOf(".GIF") != -1) {
            fileType = "image/gif";
        } else if (filePath.indexOf(".bmp") != -1
                || filePath.indexOf(".BMP") != -1) {
            fileType = "image/bmp";
        } else if (filePath.indexOf(".dwg") != -1
                || filePath.indexOf(".DWG") != -1) {
            fileType = "application/x-dwg";
        } else if (filePath.indexOf(".doc") != -1) {
            fileType = "application/msword";
        } else if (filePath.indexOf(".mpg") != -1) {
            fileType = "video/x-mpg; charset=gb2312";
        }else if(filePath.indexOf(".txt")!= -1){
            fileType="text/plain";
        }
        transfer.set_ContentType(fileType);
        contentList.add(transfer);
        doc.set_ContentElements(contentList);
        doc.checkin(AutoClassify.AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
        Properties props = doc.getProperties();
        props.putValue("DocumentTitle", this.bxPerson+this.address+flag);
        doc.set_MimeType("text/xml");
        doc.save(RefreshMode.REFRESH);
        
        ReferentialContainmentRelationship rcr = folder.file(doc,
                AutoUniqueName.AUTO_UNIQUE, "Log4jConfigSample",
                DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
        rcr.save(RefreshMode.NO_REFRESH);
        
        String id=doc.get_Id().toString();
        String vsid=doc.get_VersionSeries().get_Id().toString();
        String desc=doc.get_Name();//描述信息
        int type=VWAttachmentType.ATTACHMENT_TYPE_DOCUMENT;
        String libraryName="OStore";
        int libraryType=type;
        String title=doc.get_Name().toString();
        System.out.println("========="+id+"========"+vsid+"========"+title);
        return vsid;
    }
   
放了这么久终于写完了.文中的不妥的地方还请各位指出.一起学习.

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103735/showart_2056702.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP