import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import cn.org.bjca.seal.esspdf.client.message.ChannelMessage;
import cn.org.bjca.seal.esspdf.client.tools.ESSPDFClientTool;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
public class EntInfoAction extends ECPageAction{
/**
*
*/
private static final long serialVersionUID = 1L;
private DealSimpleService dealSimpleService = null;
private String entId;
private Map<String,Object> entInfoMap;
private List<Map<String,Object>> entInvMapList;
public String queryEntInfoView(){
if(StringUtils.isNotBlank(entId)){
entInfoMap = (Map<String,Object>)dealSimpleService.getObject("entinfo.findByIdQueryEntInfoNnj", entId);
if(entInfoMap != null && !entInfoMap.isEmpty()){
entInfoMap.put("ENT_STATE", StandardCodeTable.getName("DFCA12", (String)entInfoMap.get("ENT_STATE")));
if(entInfoMap.get("FIELD_NAME") == null || "".equals(entInfoMap.get("FIELD_NAME"))){
entInfoMap.put("FIELD_NAME","负责人");
}
entInvMapList = (List<Map<String,Object>>)dealSimpleService.getList("entinfo.findRegBusInvByEntID", entId);
}
}
return "queryEntInfoView";
}
public void downloadPdf() throws Exception{
try{
if(StringUtils.isNotBlank(entId)){
entInfoMap = (Map<String,Object>)dealSimpleService.getObject("entinfo.findByIdQueryEntInfoNnj", entId);
if(entInfoMap != null && !entInfoMap.isEmpty()){
entInfoMap.put("ENT_STATE", StandardCodeTable.getName("DFCA12", (String)entInfoMap.get("ENT_STATE")));
if(entInfoMap.get("FIELD_NAME") == null || "".equals(entInfoMap.get("FIELD_NAME"))){
entInfoMap.put("FIELD_NAME","负责人");
}
entInvMapList = (List<Map<String,Object>>)dealSimpleService.getList("entinfo.findRegBusInvByEntID", entId);
}
}
String fileName = entInfoMap.get("ENT_NAME").toString();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Document document = new Document(PageSize.A4, 20, 20, 100, 50);
PdfWriter writer = PdfWriter.getInstance(document, out);
document.open();
BaseFont bfChinese = BaseFont.createFont( "STSongStd-Light" , "UniGB-UCS2-H" , false );
Font fontChinese = new Font(bfChinese , 12 , Font.NORMAL, BaseColor.BLACK);
System.out.println(ServletActionContext.getServletContext().getRealPath(""));
Image jpeg = Image.getInstance(ServletActionContext.getServletContext().getRealPath("")+Constans.PATH_GSBJT);
jpeg.setAlignment(Image.UNDERLYING);
jpeg.setAbsolutePosition(0, 0);
jpeg.scaleAbsolute(595, 842);
document.add(jpeg);
Paragraph pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("ENT_NAME").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
document.add(pf);
PdfPTable table = new PdfPTable(2);
table.setSpacingBefore(20);
table.getDefaultCell().setPadding(5);
float[] width = {250,750};
table.setWidths(width);
pf = new Paragraph("");
pf.add(new Paragraph("注册号:",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
PdfPCell cell = new PdfPCell(pf);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
cell.setPadding(5);
cell.setBorder(0);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(entInfoMap.get("REG_NO").toString()));
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph("类型:",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("ENT_TYPE").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph("住所:",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph((String)entInfoMap.get("DOM"),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("FIELD_NAME").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("CORP_RPT").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
if(entInfoMap.get("FIELD_NAME").toString().equals("负责人")){
pf = new Paragraph("");
pf.add(new Paragraph("注册资 本:",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
String zczb= entInfoMap.get("REG_CAP").toString();
if(entInfoMap.get("ENT_SORT").toString().equals("GT")){
zczb+="元";
}else zczb+="万元";
pf = new Paragraph("");
pf.add(new Paragraph(zczb,fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
}
pf = new Paragraph("");
pf.add(new Paragraph("成立日期:",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(entInfoMap.get("EST_DATE").toString()));
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph("营业期限:",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("OP_FROM").toString()+"至"+entInfoMap.get("OP_TO").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph("经营范围 :",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("PT_BUS_SCOPE").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph("状态 :",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("ENT_STATE").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
if(entInfoMap.get("ENT_STATE").toString().equals("吊销")){
pf = new Paragraph("");
pf.add(new Paragraph("吊销日期: ",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("CANCEL_DATE").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
}
if(entInfoMap.get("ENT_STATE").toString().equals("吊销")){
pf = new Paragraph("");
pf.add(new Paragraph("吊销日期: ",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("REVOKE_DATE").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
}
if(entInfoMap.get("ENT_STATE").toString().equals("注销")){
pf = new Paragraph("");
pf.add(new Paragraph("注销日期: ",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("CANCEL_DATE").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
}
pf = new Paragraph("");
pf.add(new Paragraph("登记机关: ",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("REG_ORGMC").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
if(entInfoMap.get("ENT_NAME_CHANGED") != null && entInfoMap.get("ENT_NAME_CHANGED") != ""){
pf = new Paragraph("");
pf.add(new Paragraph("历史名称: ",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
pf.add(new Paragraph(entInfoMap.get("ENT_NAME_CHANGED").toString(),fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
}
if(entInvMapList != null && entInvMapList.size() > 0){
pf = new Paragraph("");
pf.add(new Paragraph("投资人(共"+entInvMapList.size()+"个): ",fontChinese));
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
table.addCell(cell);
pf = new Paragraph("");
for(int i=0;i<entInvMapList.size();i++){
Map<String,Object> map = entInvMapList.get(i);
pf.add(new Paragraph(map.get("INV").toString(),fontChinese));
//if(i<entInvMapList.size()-1)pf.add(",");
}
pf.setAlignment(PdfContentByte.ALIGN_CENTER);
cell = new PdfPCell(pf);
cell.setPadding(5);
cell.setBorder(0);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
table.addCell(cell);
}
document.add(table);
document.close();
byte[] pdfBty = out.toByteArray();
ESSPDFClientTool essPDFClientTool = new ESSPDFClientTool(Constans.IP_PDFSIGN, Integer.valueOf(Constans.PORT_IP_PDFSIGN));
essPDFClientTool.setTimeout(10000);
essPDFClientTool.setRespTimeout(30000);
ChannelMessage message = essPDFClientTool.pdfSign(Constans.RULENUM_IP_PDFSIGN, pdfBty);
if("200".equals(message.getStatusCode())){
ServletActionContext.getResponse().setContentType("application/pdf,charset=UTF-8");
ServletActionContext.getResponse().setHeader("Content-Disposition","attachment;filename=\""+ java.net.URLEncoder.encode(fileName+".pdf", "UTF-8")+"\"");
OutputStream outClient = ServletActionContext.getResponse().getOutputStream();
outClient.write(message.getBody());
outClient.flush();
outClient.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
public Map<String, Object> getEntInfoMap() {
return entInfoMap;
}
public void setEntInfoMap(Map<String, Object> entInfoMap) {
this.entInfoMap = entInfoMap;
}
public List<Map<String, Object>> getEntInvMapList() {
return entInvMapList;
}
public void setEntInvMapList(List<Map<String, Object>> entInvMapList) {
this.entInvMapList = entInvMapList;
}
public DealSimpleService getDealSimpleService() {
return dealSimpleService;
}
public void setDealSimpleService(DealSimpleService dealSimpleService) {
this.dealSimpleService = dealSimpleService;
}
public String getEntId() {
return entId;
}
public void setEntId(String entId) {
this.entId = entId;
}
}