package com.sinosoft.lz.emergency.print;
import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.ws.rs.core.Context;
import org.apache.log4j.Logger;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
import com.persistence.service.PersistenceFactory;
import com.persistence.service.SysPersistence;
import com.sinosoft.lz.emergency.dao.FloodDao;
import com.sinosoft.lz.emergency.service.EmergencyEventImp;
import com.sinosoft.lz.emergency.service.EquipmentNumImp;
import com.sinosoft.lz.emergency.service.MaterialNumImp;
import com.sinosoft.lz.emergency.service.SelectedExpertServiceImp;
import com.sinosoft.lz.emergency.vo.Command;
import com.sinosoft.lz.emergency.vo.Commands;
import com.sinosoft.lz.emergency.vo.EquipmentNum;
import com.sinosoft.lz.emergency.vo.EquipmentNums;
import com.sinosoft.lz.emergency.vo.ExpertInfo;
import com.sinosoft.lz.emergency.vo.ExpertInfos;
import com.sinosoft.lz.emergency.vo.FloodContinueInfo;
import com.sinosoft.lz.emergency.vo.FloodEventInfo;
import com.sinosoft.lz.emergency.vo.FloodFirstInfo;
import com.sinosoft.lz.emergency.vo.MaterialNum;
import com.sinosoft.lz.emergency.vo.MaterialNums;
import com.sysmodel.datamodel.xmlmodel.ModelFactory;
import com.sysmodel.datamodel.xmlmodel.able.SysModel;
public class CreateWord{
private final Logger log = Logger.getLogger(getClass());
private SysModel sysmodel = ModelFactory.getSysmodel();
private SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
public void createDocContext(String file,String contentTempPath,String PREPARATION_PRIJECT_Code,String FD_OBJECTID,String classId,
String sessionID,String userID) throws Exception{
EmergencyEventImp emergencyEventImp = new EmergencyEventImp();
FloodDao floodDao=new FloodDao();
//根据应急事件ID获取事件首报和续报信息
FloodEventInfo floodEventInfo=floodDao.getFloodFCInfo(FD_OBJECTID);
FloodFirstInfo firstInfo=floodEventInfo.getFirstInfo();
ArrayList<FloodContinueInfo> continueInfo=(ArrayList<FloodContinueInfo>)floodEventInfo.getContinueInf();
Iterator<FloodContinueInfo> continueInf= continueInfo.iterator();
// 设置纸张大小
Document document = new Document(PageSize.A4);
// 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中
RtfWriter2.getInstance(document, new FileOutputStream(file));
document.open();
// 设置中文字体
BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// 标题字体风格
Font titleFont = new Font(bfChinese, 12, Font.BOLD);
// 正文字体风格
//Font contextFont = new Font(bfChinese, 10, Font.NORMAL);
Paragraph title = new Paragraph("应急报告",FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 18, Font.BOLD,
new Color(0,0,0)));
// 设置标题格式对齐方式
title.setAlignment(Element.ALIGN_CENTER);
title.setFont(titleFont);
document.add(title);
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
String time1=df.format(new Date());
String contextString = "报告时间:"+time1;
Paragraph context = new Paragraph(contextString);
// 正文格式左对齐
context.setAlignment(Element.ALIGN_LEFT);
// 离上一段落(标题)空的行数
context.setSpacingBefore(5);
// 设置第一行空的列数
context.setFirstLineIndent(20);
document.add(context);
//利用类FontFactory结合Font和Color可以设置各种各样字体样式
/**
* Font.UNDERLINE 下划线,Font.BOLD 粗体
*/
Paragraph underline = new Paragraph("一、应急首报信息", FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 13, Font.BOLD,
new Color(0,0,0)));
document.add(underline);
// 设置 Table 表格
Table aTable = new Table(6);
int width[] = {20,20,20,20,20,20};
aTable.setWidths(width);//设置每列所占比例
aTable.setWidth(90); // 占页面宽度 90%
aTable.setAlignment(Element.ALIGN_CENTER);//居中显示
aTable.setAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
aTable.setAutoFillEmptyCells(true); //自动填满
aTable.setBorderWidth(5); //边框宽度
aTable.setBorderColor(new Color(0, 125, 255)); //边框颜色
aTable.setPadding(5);//衬距,看效果就知道什么意思了
aTable.setSpacing(0);//即单元格之间的间距
aTable.setBorder(5);//边框
aTable.getDefaultCell().setBorder(0);//无边框
//设置表头
/**
* cell.setHeader(true);是将该单元格作为表头信息显示;
* cell.setColspan(3);指定了该单元格占3列;
* 为表格添加表头信息时,要注意的是一旦表头信息添加完了之后,
* 必须调用 endHeaders()方法,否则当表格跨页后,表头信息不会再显示
*/
aTable.addCell(new Cell("路线编号"));
aTable.addCell(new Cell(firstInfo.getRoadcode()));
aTable.addCell(new Cell("路线名称"));
aTable.addCell(new Cell(firstInfo.getRoadname()));
aTable.addCell(new Cell("事件所在位置"));
aTable.addCell(new Cell(firstInfo.getRoadpos()));
aTable.addCell(new Cell("起点桩号"));
aTable.addCell(new Cell(firstInfo.getStartpileno()));
aTable.addCell(new Cell("止点桩号"));
aTable.addCell(new Cell(firstInfo.getEndpileno()));
aTable.addCell(new Cell("填报人"));
aTable.addCell(new Cell(firstInfo.getReoprtperson()));
aTable.addCell(new Cell("行政区划"));
aTable.addCell(new Cell(firstInfo.getAreacode()));
aTable.addCell(new Cell("路线管理单位"));
aTable.addCell(new Cell(firstInfo.getDept()));
aTable.addCell(new Cell("联系电话"));
aTable.addCell(new Cell(firstInfo.getTel()));
aTable.addCell(new Cell("事件类型"));
aTable.addCell(new Cell(firstInfo.getEventtype()));
aTable.addCell(new Cell("经度"));
aTable.addCell(new Cell(firstInfo.getLongitude()));
aTable.addCell(new Cell("纬度"));
aTable.addCell(new Cell(firstInfo.getLatitude()));
aTable.addCell(new Cell("事件级别"));
aTable.addCell(new Cell(firstInfo.getEventlevel()));
aTable.addCell(new Cell("发现时间"));
Cell cell3 = new Cell(new Phrase(firstInfo.getFindtime()));
cell3.setColspan(3);
cell3.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell3);
aTable.addCell(new Cell("现场情况描述"));
Cell cell4 = new Cell(new Phrase(firstInfo.getDescription()));
cell4.setColspan(5);
cell4.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell4);
aTable.addCell(new Cell("车道数"));
aTable.addCell(new Cell(firstInfo.getDrivewaynum()));
aTable.addCell(new Cell("占用车道数"));
Cell cell5 = new Cell(new Phrase(firstInfo.getBlockdrivewaynum()));
cell5.setColspan(3);
cell5.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell5);
aTable.addCell(new Cell("阻断类型"));
aTable.addCell(new Cell(firstInfo.getBlocktype()));
aTable.addCell(new Cell("所属单位"));
Cell cell6 = new Cell(new Phrase(firstInfo.getDept_id()));
cell6.setColspan(3);
cell6.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell6);
document.add(aTable);
document.add(new Paragraph("\n"));
Paragraph pacti = new Paragraph("二、首报图片信息", FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 13, Font.BOLD,
new Color(0,0,0)));
document.add(pacti);
synchronized (this) {
List<String> string = getPicStr(FD_OBJECTID,contentTempPath);//图片路径
for(String str:string){
//添加图片
Image img=Image.getInstance(str);
img.setAbsolutePosition(0, 0);
img.setAlignment(Image.LEFT);//设置图片显示位置
img.scaleAbsolute(12,35);//直接设定显示尺寸
img.scalePercent(50);//表示显示的大小为原尺寸的50%
img.scalePercent(25, 12);//图像高宽的显示比例
img.setRotation(30);//图像旋转一定角度
document.add(img);
}
System.out.println("图片路径:"+string);
/*
* 删除图片
* */
deletePic(string);
}
document.add(new Paragraph("\n"));
Paragraph underxubao = new Paragraph("三、应急续报信息", FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 13, Font.BOLD,
new Color(0,0,0)));
document.add(underxubao);
// 设置 Table 表格
if(continueInf.hasNext()){
for(FloodContinueInfo fci:continueInfo){
Table xubao = new Table(4);
int xb[] = {20,20,20,20};
xubao.setWidths(xb);//设置每列所占比例
xubao.setWidth(90); // 占页面宽度 90%
xubao.setAlignment(Element.ALIGN_CENTER);//居中显示
xubao.setAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
xubao.setAutoFillEmptyCells(true); //自动填满
xubao.setBorderWidth(5); //边框宽度
xubao.setBorderColor(new Color(0, 125, 255)); //边框颜色
xubao.setPadding(5);//衬距,看效果就知道什么意思了
xubao.setSpacing(0);//即单元格之间的间距
xubao.setBorder(5);//边框
xubao.addCell(new Cell("上报单位"));
xubao.addCell(new Cell(fci.getReportdept()));
xubao.addCell(new Cell("上报时间"));
xubao.addCell(new Cell(fci.getReporttime()));
xubao.addCell(new Cell("降水情况"));
xubao.addCell(new Cell(fci.getPrecipitationlevel()));
xubao.addCell(new Cell("巡查投入人数"));
xubao.addCell(new Cell(fci.getPatrol_personnum()));
xubao.addCell(new Cell("巡查投入车辆数"));
xubao.addCell(new Cell(fci.getPatrol_carnum()));
xubao.addCell(new Cell("抢险投入人数"));
xubao.addCell(new Cell(fci.getEmergency_pernum()));
xubao.addCell(new Cell("机械设备总数"));
xubao.addCell(new Cell(fci.getEmergency_equipmentnum()));
xubao.addCell(new Cell("运输车"));
xubao.addCell(new Cell(fci.getEmergency_transportcar()));
xubao.addCell(new Cell("铲吊车"));
xubao.addCell(new Cell(fci.getEmergency_crane()));
xubao.addCell(new Cell("发电机"));
xubao.addCell(new Cell(fci.getEmergency_dynam()));
xubao.addCell(new Cell("水泵"));
xubao.addCell(new Cell(fci.getEmergency_waterpump()));
xubao.addCell(new Cell("草袋"));
xubao.addCell(new Cell(fci.getEmergency_strawbag()));
xubao.addCell(new Cell("麻袋"));
xubao.addCell(new Cell(fci.getEmergency_jutebag()));
xubao.addCell(new Cell("编织袋"));
xubao.addCell(new Cell(fci.getEmergency_braidedbag()));
xubao.addCell(new Cell("无纺布"));
xubao.addCell(new Cell(fci.getEmergency_nonwoven()));
xubao.addCell(new Cell("铅丝(螺纹钢)"));
xubao.addCell(new Cell(fci.getEmergency_wire()));
xubao.addCell(new Cell("桩木"));
xubao.addCell(new Cell(fci.getEmergency_pile()));
xubao.addCell(new Cell("砂石料"));
xubao.addCell(new Cell(fci.getEmergency_ballast()));
xubao.addCell(new Cell("大型作业灯"));
xubao.addCell(new Cell(fci.getEmergency_workinglight()));
xubao.addCell(new Cell("路面塌陷线路名称"));
xubao.addCell(new Cell(fci.getSubside_roadname()));
xubao.addCell(new Cell("路线编号"));
xubao.addCell(new Cell(fci.getSubside_roadcode()));
xubao.addCell(new Cell("位置(桩号)"));
xubao.addCell(new Cell(fci.getSubside_roadpos()));
xubao.addCell(new Cell("阻断情况"));
xubao.addCell(new Cell(fci.getSubside_blocktype()));
xubao.addCell(new Cell("占车道数"));
xubao.addCell(new Cell(fci.getSubside_blocknum()));
xubao.addCell(new Cell("塌方线路名称"));
xubao.addCell(new Cell(fci.getLandslide_roadname()));
xubao.addCell(new Cell("路线编号"));
xubao.addCell(new Cell(fci.getLandslide_roadcode()));
xubao.addCell(new Cell("位置(桩号)"));
xubao.addCell(new Cell(fci.getLandslide_roadpos()));
xubao.addCell(new Cell("面积"));
xubao.addCell(new Cell(fci.getLandslide_area()));
xubao.addCell(new Cell("方向"));
xubao.addCell(new Cell(fci.getLandslide_direction()));
xubao.addCell(new Cell("阻断情况"));
xubao.addCell(new Cell(fci.getLandslide_blocktype()));
xubao.addCell(new Cell("占车道数"));
xubao.addCell(new Cell(fci.getLandslide_blocknum()));
xubao.addCell(new Cell("路基水毁线路名称"));
xubao.addCell(new Cell(fci.getDamage_roadname()));
xubao.addCell(new Cell("线路编号"));
xubao.addCell(new Cell(fci.getDamage_roadcode()));
xubao.addCell(new Cell("位置(桩号)"));
xubao.addCell(new Cell(fci.getDamage_roadpos()));
xubao.addCell(new Cell("面积"));
xubao.addCell(new Cell(fci.getDamage_area()));
xubao.addCell(new Cell("阻断情况"));
xubao.addCell(new Cell(fci.getDamage_blocktype()));
xubao.addCell(new Cell("占车道数"));
xubao.addCell(new Cell(fci.getDamage_blocknum()));
xubao.addCell(new Cell("路面积水线路名称"));
xubao.addCell(new Cell(fci.getSeeper_roadname()));
xubao.addCell(new Cell("线路编号"));
xubao.addCell(new Cell(fci.getSeeper_roadcode()));
xubao.addCell(new Cell("位置(桩号)"));
xubao.addCell(new Cell(fci.getSeeper_roadpos()));
xubao.addCell(new Cell("面积"));
xubao.addCell(new Cell(fci.getSeeper_area()));
xubao.addCell(new Cell("路基水毁线路名称"));
xubao.addCell(new Cell(fci.getSeeper_depth()));
xubao.addCell(new Cell("路面积水阻断情况"));
xubao.addCell(new Cell(fci.getSeeper_blocktype()));
xubao.addCell(new Cell("路面积水占车道数"));
xubao.addCell(new Cell(fci.getSeeper_blocknum()));
xubao.addCell(new Cell("上报人"));
xubao.addCell(new Cell(fci.getReporter()));
xubao.addCell(new Cell("联系电话"));
xubao.addCell(new Cell(fci.getReporttel()));
xubao.addCell(new Cell("其它需要说明的问题备注"));
Cell cell7 = new Cell(new Phrase(fci.getRemark()));
cell7.setColspan(3);
cell7.setVerticalAlignment(Element.ALIGN_CENTER);
xubao.addCell(cell7);
document.add(xubao);
}
}else{
Table xubao = new Table(4);
int xb[] = {20,20,20,20};
xubao.setWidths(xb);//设置每列所占比例
xubao.setWidth(90); // 占页面宽度 90%
xubao.setAlignment(Element.ALIGN_CENTER);//居中显示
xubao.setAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
xubao.setAutoFillEmptyCells(true); //自动填满
xubao.setBorderWidth(5); //边框宽度
xubao.setBorderColor(new Color(0, 125, 255)); //边框颜色
xubao.setPadding(5);//衬距,看效果就知道什么意思了
xubao.setSpacing(0);//即单元格之间的间距
xubao.setBorder(5);//边框
xubao.addCell(new Cell("上报单位"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("上报时间"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("降水情况"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("巡查投入人数"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("巡查投入车辆数"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("抢险投入人数"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("机械设备总数"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("运输车"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("铲吊车"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("发电机"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("水泵"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("草袋"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("麻袋"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("编织袋"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("无纺布"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("铅丝(螺纹钢)"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("桩木"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("砂石料"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("大型作业灯"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("路面塌陷线路名称"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("路线编号"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("位置(桩号)"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("阻断情况"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("占车道数"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("塌方线路名称"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("路线编号"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("位置(桩号)"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("面积"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("方向"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("阻断情况"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("占车道数"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("路基水毁线路名称"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("线路编号"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("位置(桩号)"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("面积"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("阻断情况"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("占车道数"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("路面积水线路名称"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("线路编号"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("位置(桩号)"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("面积"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("路基水毁线路名称"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("路面积水阻断情况"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("路面积水占车道数"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("上报人"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("联系电话"));
xubao.addCell(new Cell());
xubao.addCell(new Cell("其它需要说明的问题备注"));
Cell cell7 = new Cell(new Phrase());
cell7.setColspan(3);
cell7.setVerticalAlignment(Element.ALIGN_CENTER);
xubao.addCell(cell7);
document.add(xubao);
}
document.add(new Paragraph("\n"));
Paragraph chuli = new Paragraph("四、处理步骤", FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 13, Font.BOLD,
new Color(0,0,0)));
document.add(chuli);
// 设置 Table 表格
Table cl = new Table(1);
int chul[] = {20};
cl.setWidths(chul);//设置每列所占比例
cl.setWidth(90); // 占页面宽度 90%
cl.setAlignment(Element.ALIGN_CENTER);//居中显示
cl.setAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
cl.setAutoFillEmptyCells(true); //自动填满
cl.setBorderWidth(5); //边框宽度
cl.setBorderColor(new Color(0, 125, 255)); //边框颜色
cl.setPadding(5);//衬距,看效果就知道什么意思了
cl.setSpacing(0);//即单元格之间的间距
cl.setBorder(5);//边框
String FindTime=firstInfo.getFindtime();
String RoadCode=firstInfo.getRoadcode();
String Startpileno1=firstInfo.getStartpileno();
String Endpileno1=firstInfo.getEndpileno();
String contextString1="1、"+FindTime+"在"+RoadCode+"("+Startpileno1+"-"+Endpileno1+")"+"发生应急事件";
String contextString2 = "2、" + firstInfo.getMatchingTime() + " 匹配" + firstInfo.getPreparationid()
+ "预案,确认人" + firstInfo.getMatchingConfirmPerson() + "!";
String contextString3 = "3、" + firstInfo.getStartPPTime() + " 启动" + firstInfo.getPreparationid()
+ "预案,确认人" + firstInfo.getStartOperatePerson() + "!";
String contextString5 = "";
String allString=contextString1+"\n"+contextString2+"\n"+contextString3;
//printInfo[60]=allString;
// 获取指令登记对象集合
Commands commands = emergencyEventImp.getCommandList(FD_OBJECTID);
// -------------获得下发指令---------------------------
ArrayList<Command> listcommand = (ArrayList<Command>) commands.getCommands();
Iterator<Command> itcommand = listcommand.iterator();
int i=4;
if (itcommand.hasNext()) {
while (itcommand.hasNext()) {
Command command = (Command) itcommand.next();
String comandStr="";
comandStr=i+"、在" + command.getIssuedDate() + "下发指令" + command.getRemark()
+ ",由" + command.getConfirmor() + "下发给" + command.getAcceptPer() + "!";
contextString5+=comandStr+"\n";
i++;
}
cl.addCell(new Cell(allString+"\n"+contextString5+"\n"));
document.add(cl);
} else {
contextString5 = " "+i+".无下发指令信息!";
//printInfo[68]=allString+contextString5;
cl.addCell(new Cell(allString+contextString5));
document.add(cl);
}
document.add(new Paragraph("\n"));
Paragraph material = new Paragraph("五、物资调用", FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 13, Font.BOLD,
new Color(0,0,0)));
document.add(material);
// 设置 Table 表格
Table mater = new Table(4);
int ma[] = {20,20,20,20};
mater.setWidths(ma);//设置每列所占比例
mater.setWidth(90); // 占页面宽度 90%
mater.setAlignment(Element.ALIGN_CENTER);//居中显示
mater.setAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
mater.setAutoFillEmptyCells(true); //自动填满
mater.setBorderWidth(5); //边框宽度
mater.setBorderColor(new Color(0, 125, 255)); //边框颜色
mater.setPadding(5);//衬距,看效果就知道什么意思了
mater.setSpacing(0);//即单元格之间的间距
mater.setBorder(5);//边框
mater.addCell(new Cell("物资类型"));
mater.addCell(new Cell("已有数量"));
mater.addCell(new Cell("预案设置数量"));
mater.addCell(new Cell("调用数量"));
MaterialNumImp materialNumImp=new MaterialNumImp();
String parames="PREPARATION_PRIJECT_Code="+PREPARATION_PRIJECT_Code+"&eventId="+FD_OBJECTID;
MaterialNums materialNums=materialNumImp.getMaterialListBus(parames);
ArrayList<MaterialNum> listmaterial=(ArrayList<MaterialNum>)materialNums.getMaterialNum();
Iterator<MaterialNum> itmaterial =listmaterial.iterator();
//int index=69;
if(listmaterial.size()==0){
mater.addCell(new Cell(""));
mater.addCell(new Cell(""));
mater.addCell(new Cell(""));
mater.addCell(new Cell(""));
}
while(itmaterial.hasNext()){
MaterialNum materialNum=(MaterialNum)itmaterial.next();
String Fd_description=materialNum.getFD_DESCRIPTION();
String MATERIAL_Num=materialNum.getMATERIAL_NUM();
log.info("设备表中设备数量: "+MATERIAL_Num);
String MATERIAL_Number=materialNum.getMATERIAL_NUNMBER();
log.info("设置数量: "+MATERIAL_Number);
String MATERIAL_NumSum=materialNum.getMATERIAL_NUMSUM();
log.info("===: "+MATERIAL_NumSum);
mater.addCell(new Cell(Fd_description));
mater.addCell(new Cell(MATERIAL_Num));
mater.addCell(new Cell(MATERIAL_Number));
mater.addCell(new Cell(MATERIAL_NumSum));
}
document.add(mater);
document.add(new Paragraph("\n"));
Paragraph equment = new Paragraph("六、设备调用", FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 13, Font.BOLD,
new Color(0,0,0)));
document.add(equment);
// 设置 Table 表格
Table equ = new Table(4);
int eq[] = {20,20,20,20};
equ.setWidths(eq);//设置每列所占比例
equ.setWidth(90); // 占页面宽度 90%
equ.setAlignment(Element.ALIGN_CENTER);//居中显示
equ.setAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
equ.setAutoFillEmptyCells(true); //自动填满
equ.setBorderWidth(5); //边框宽度
equ.setBorderColor(new Color(0, 125, 255)); //边框颜色
equ.setPadding(5);//衬距,看效果就知道什么意思了
equ.setSpacing(0);//即单元格之间的间距
equ.setBorder(5);//边框
equ.addCell(new Cell("物资类型"));
equ.addCell(new Cell("已有数量"));
equ.addCell(new Cell("预案设置数量"));
equ.addCell(new Cell("调用数量"));
EquipmentNumImp equipmentNumImp = new EquipmentNumImp();
String params = "PREPARATION_PRIJECT_Code=" + PREPARATION_PRIJECT_Code + "&eventId=" + FD_OBJECTID;
EquipmentNums equipmentNums = equipmentNumImp.getEquipmentListBus(params);
ArrayList<EquipmentNum> listequment = (ArrayList<EquipmentNum>) equipmentNums
.getEquipmentNum();
Iterator<EquipmentNum> itequment = listequment.iterator();
if(listequment.size()==0){
equ.addCell(new Cell(""));
equ.addCell(new Cell(""));
equ.addCell(new Cell(""));
equ.addCell(new Cell(""));
}
while (itequment.hasNext()) {
EquipmentNum equipmentNum = (EquipmentNum) itequment.next();
String Fd_description=equipmentNum.getFD_DESCRIPTION();
String EQUIPMENT_Num = equipmentNum.getEQUIPMENT_NUM();
String EQUIPMENT_Number = equipmentNum.getEQUIPMENT_NUMBER();
String EQUIPMENT_NumSum = equipmentNum.getEQUIPMENT_NUMSUM();
equ.addCell(new Cell(Fd_description));
equ.addCell(new Cell(EQUIPMENT_Num));
equ.addCell(new Cell(EQUIPMENT_Number));
equ.addCell(new Cell(EQUIPMENT_NumSum));
}
document.add(equ);
document.add(new Paragraph("\n"));
Paragraph zhuanjia = new Paragraph("七、到场专家", FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 13, Font.BOLD,
new Color(0,0,0)));
document.add(zhuanjia);
// 设置 Table 表格
Table zhuanj = new Table(1);
int zj[] = {20};
zhuanj.setWidths(zj);//设置每列所占比例
zhuanj.setWidth(90); // 占页面宽度 90%
zhuanj.setAlignment(Element.ALIGN_CENTER);//居中显示
zhuanj.setAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
zhuanj.setAutoFillEmptyCells(true); //自动填满
zhuanj.setBorderWidth(5); //边框宽度
zhuanj.setBorderColor(new Color(0, 125, 255)); //边框颜色
zhuanj.setPadding(5);//衬距,看效果就知道什么意思了
zhuanj.setSpacing(0);//即单元格之间的间距
zhuanj.setBorder(5);//边框
SelectedExpertServiceImp selectedExpertServiceImp = new SelectedExpertServiceImp();
ExpertInfos expertInfos = selectedExpertServiceImp.getSelectedExpert(FD_OBJECTID, sessionID, userID);
ArrayList<ExpertInfo> listexpert = (ArrayList<ExpertInfo>) expertInfos.getExpertInfo();
Iterator<ExpertInfo> itexpert = listexpert.iterator();
String contextexpertString = "";
String chainstring="";
int a=1;
if (itexpert.hasNext()) {
while (itexpert.hasNext()) {
contextexpertString = "";
ExpertInfo expertInfo = (ExpertInfo) itexpert.next();
contextexpertString += a+"."+expertInfo.getEXPERT_NAME()
+ " (电话:" + expertInfo.getEXPERT_PHONE() +" "+"手机:"+expertInfo.getEXPERT_TEL()+ ")"+"\n"+" ";
chainstring+=contextexpertString;
a++;
}
log.info("到场专家:"+chainstring);
zhuanj.addCell(new Cell(chainstring));
} else {
contextexpertString = "无到场专家!";
zhuanj.addCell(new Cell(contextexpertString));
}
document.add(zhuanj);
document.add(new Paragraph("\n"));
document.close();
}
/*
* 根据事件id返回转为base64编码的字符串
* @param FD_OBJECTID 事件id
* @return 二进制图片转为base64编码格式后的字符串
*/
public List<String> getPicStr(String FD_OBJECTID,String contentTempPath){
//获取图片信息
Connection myconn = persistence.getConnection();
Statement stmt = null;
InputStream is = null;
ResultSet rs = null;
String str = "";
List<String> list = new ArrayList<String>();
byte[] Buffer = new byte[1024*300];
try {
String sql = "select FILECONTENTS,name,FILEEXT from SysComm_FileImg where mainid='"+FD_OBJECTID+"'";
stmt = myconn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
is = rs.getBinaryStream("FILECONTENTS");
java.io.FileOutputStream long_file = new java.io.FileOutputStream(contentTempPath+"\\"+rs.getString("name")+"."+rs.getString("FILEEXT"));
int size = 0;
while ((size = is.read(Buffer)) != -1) {
long_file.write(Buffer,0,size);
long_file.close();
is.close();
}
str = contentTempPath+"\\"+rs.getString("name")+"."+rs.getString("FILEEXT");
list.add(str);
}
} catch (Exception e) {
log.error("从数据库取图片发生异常",e);
} finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (myconn != null) myconn.close();
if (is != null) is.close();
} catch (Exception e) {
log.error("关闭数据库连接发生异常",e);
}
}
return list;
}
public void deletePic(List<String> string){
System.out.println("==============="+string);
for(String str:string){
File file = new File(str);
file.delete();
}
}
// public static void main(String[] args) throws Exception {
// CreateWord word = new CreateWord();
// String file = "c:/demo1.doc";
// try {
// word.createDocContext(file);
// } catch (DocumentException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
}