关于doc文档和docx文档的处理

public IPage savePage(IRequestCycle cycle) {
IPage reslutPage = null;
FileInputStream fis = null;
try {
SysInforPage sysInforPage = this.getSysInforPage();
GG_FJGHWD fjghwd = (GG_FJGHWD)this.getMyVisit().getSession().get("gg_fjghwd");
if(fjghwd!=null && cgwth.getFbbz() == Constants_wt.WT_CGWTD_FBBZ_BFB){
if(wt_fbxq.getWdbh()==null){
fjghwd.setPath(FilePathUtils.addFilePath(fjghwd.getPath()));
}
String wdpath = fjghwd.getPath()+fjghwd.getRealname();
log.info("文档路径为:" + wdpath);
File file = new File(wdpath);
fis = new FileInputStream(file);
// HWPFDocument doc = new HWPFDocument(fis);
String fileType = FileUtil.getTypePart(wdpath);
if ("doc".equalsIgnoreCase(fileType)) {
try {
// 如果是doc格式文档,按照doc文档格式进行处理
log.info("开始解析word2003格式文件:" + wdpath);
HWPFDocument doc = new HWPFDocument(fis);
String doc1 = doc.getRange().text();
//禁止词列表
List<Map> jzcList = this.getWtdsqFacade().getJzcList();
String jzc = "";
for (Map mapjzc : jzcList) {
if(doc1.indexOf(StringUtils.convertStr(mapjzc.get("MGC"))) != -1){
jzc +=StringUtils.convertStr(mapjzc.get("MGC"))+",";
}
fis.close();
}
if(jzc != ""){
ShowJzctsPage page = getShowJzctsPage();
return page;
}
log.info("解析word2003格式文件结束:" + wdpath);
} catch (Exception e) {
// 如果doc文档获取书签出现异常,尝试使用docx格式进行解析
log.info("开始解析word2007以上doc格式文件:" + wdpath);
String doc1 = "";
OPCPackage oPCPackage = POIXMLDocument.openPackage(wdpath);
XWPFDocument xwpf = new XWPFDocument(oPCPackage);
POIXMLTextExtractor ex = new XWPFWordExtractor(xwpf);
doc1 = ex.getText();
//禁止词列表
List<Map> jzcList = this.getWtdsqFacade().getJzcList();
String jzc = "";
for (Map mapjzc : jzcList) {
if(doc1.indexOf(StringUtils.convertStr(mapjzc.get("MGC"))) != -1){
jzc +=StringUtils.convertStr(mapjzc.get("MGC"))+",";
}
fis.close();
}
if(jzc != ""){
ShowJzctsPage page = getShowJzctsPage();
return page;
}
log.info("解析解析word2007以上doc格式文件结束:" + wdpath);
}
} else if("docx".equalsIgnoreCase(fileType)) {
// 如果是doc格式文档,按照doc文档格式进行处理
// 如果doc文档获取书签出现异常,尝试使用docx格式进行解析
log.info("开始解析word2007以上docx格式文件:" + wdpath);
String doc1 = "";
OPCPackage oPCPackage = POIXMLDocument.openPackage(wdpath);
XWPFDocument xwpf = new XWPFDocument(oPCPackage);
POIXMLTextExtractor ex = new XWPFWordExtractor(xwpf);
doc1 = ex.getText();
//禁止词列表
List<Map> jzcList = this.getWtdsqFacade().getJzcList();
String jzc = "";
for (Map mapjzc : jzcList) {
if(doc1.indexOf(StringUtils.convertStr(mapjzc.get("MGC"))) != -1){
jzc +=StringUtils.convertStr(mapjzc.get("MGC"))+",";
}
fis.close();
}
if(jzc != ""){
ShowJzctsPage page = getShowJzctsPage();
return page;
}
log.info("解析解析word2007以上docx格式文件结束:" + wdpath);
} else {
log.info("不是word类型文档格式,不做检查:" + wdpath);
}
}
sysInforPage.setCode(SysInforPage.CODE_SUCC);
this.cgwth.setCgbmslsj(DateUtil.getLongCurrDateTime14());
this.cgwth.setWtlb(2);//1-大项目,2-普通项目
this.cgwth.setXmgs(this.getStrDisplayFbxq());
this.cgwth.setCgpmmc(this.getRequestCycle().getParameter("pmmc"));//采购品目名称
if(this.cgwth.getFbbz()==Constants_wt.WT_CGWTD_FBBZ_FB){
this.cgwth.setXmgs(this.getStrDisplayFbxq());
this.getWtdsqSJBQFacade().execWth(cgwth,this.getQzgys());
this.getMyVisit().getSession().clear();
}
if(this.cgwth.getFbbz()==Constants_wt.WT_CGWTD_FBBZ_BFB){
this.gg_fjghwd = (GG_FJGHWD) this.getMyVisit().getSession().get("gg_fjghwd");
this.getMyVisit().getSession().remove("gg_fjghwd");
if(this.gg_fjghwd != null && this.gg_fjghwd.getId() != null){
this.gg_fjghwd.setScr(this.getMyVisit().getCzy().getId());
this.gg_fjghwd.setShowname("需求分包文档");
this.getWtdsqSJBQFacade().execGg_fjghwd(this.gg_fjghwd);
}
this.wt_fbxq.setBmc("A");
this.wt_fbxq.setJycgfs(cgwth.getCgfs());
this.wt_fbxq.setSxh(1);
this.wt_fbxq.setWT_CGWTD(cgwth);
this.wt_fbxq.setWdbh(this.gg_fjghwd.getId());
this.wt_fbxq.setZfsqh(ZFSQHs); //设置支付申请号
// this.wt_fbxq.setTbrzz(wt_fbxq.getTbrzz()); //设置投标人资质要求
// this.wt_fbxq.setBms(wt_fbxq.getBms()); //设置采购内容
// this.wt_fbxq.setFjwd(wt_fbxq.getFjwd()); //设置附件文档
this.cgwth.setXmgs("");
this.cgwth.setFbbz(Constants_wt.WT_CGWTD_FBBZ_BFB);
//存入不分包资金来源以及总金额
List listWtzjInfo= new ArrayList<WT_WTZJ>();
Double ysje =0.0;
String [] ids = this.getRequestCycle().getParameters("dmnrid");
for(int i=0;i<ids.length;i++){
WT_WTZJ wt_wtzj = new WT_WTZJ();
if(this.getRequestCycle().getParameter("je"+ids[i])!=""){
wt_wtzj.setJine(Double.parseDouble(this.getRequestCycle().getParameter("je"+ids[i])));
ysje+=Double.parseDouble(this.getRequestCycle().getParameter("je"+ids[i]));
wt_wtzj.setZjytsm(this.getRequestCycle().getParameter("sm"+ids[i]));
wt_wtzj.setZjxz(ids[i]);
wt_wtzj.setWT_FBXQ(this.wt_fbxq);
listWtzjInfo.add(wt_wtzj);
}
}
this.cgwth.setYsje(ysje);
this.wt_fbxq.setYs(ysje);
this.wt_fbxq.setFjwd(cgwth.getId());
this.getWtdsqSJBQFacade().execWdwtd(cgwth, wt_fbxq,listWtzjInfo,this.getQzgys());
//多附件上传处理
SWFUploaderUtils.processUploadFiles(cycle.getInfrastructure().getRequest(), "fj");
this.getMyVisit().getSession().clear();
}
sysInforPage.setMsInfo("委托单数据操作成功!");
sysInforPage.setAutoScript("top.PopDialog1.refresh();top.MainWorkArea.refresh();top.PopDialog2.closeX();");
reslutPage = sysInforPage;
} catch (MisException e) {
e.printStackTrace();
SysInforPage sysInforPage = this.getSysInforPage();
sysInforPage.setCode(SysInforPage.CODE_FAIL);
sysInforPage.setMsInfo(e.getMessage());
reslutPage = sysInforPage;
} catch (Exception e) {
e.printStackTrace();
SysInforPage sysInforPage = this.getSysInforPage();
sysInforPage.setCode(SysInforPage.CODE_ERR);
sysInforPage.setMsInfo("发生未知异常,请与管理员联系!");
reslutPage = sysInforPage;
}
return reslutPage;
}

posted @ 2019-05-10 17:03  凉生未央  阅读(661)  评论(0编辑  收藏  举报