apzl_leasing/src_tenwa/com/tenwa/makeContract/util/MakeOneCodeAndContractModel.java

622 lines
26 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.tenwa.makeContract.util;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.jbarcode.JBarcode;
import org.jbarcode.encode.Code128Encoder;
import org.jbarcode.paint.BaseLineTextPainter;
import org.jbarcode.paint.WidthCodedPainter;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.JBOException;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.are.util.json.JSONDecoder;
import com.amarsoft.are.util.json.JSONObject;
import com.amarsoft.awe.Configure;
import com.amarsoft.dict.als.manage.NameManager;
import com.caucho.hessian.client.HessianProxyFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.tenwa.app.dao.ContractSignInfo;
import com.tenwa.channelportal.action.ContractSignAction;
import com.tenwa.channelportal.action.generativecontract.WordToPDFUtil;
import com.tenwa.comm.util.date.DateAssistant;
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
import com.tenwa.doc.action.DocListAction;
import com.tenwa.doc.util.BASE64;
import com.tenwa.lease.app.service.HttpRequestAppService;
import com.tenwa.officetempalte.util.FileOperatorUtil;
import com.tenwa.reckon.util.UUIDUtil;
import com.tenwa.util.MultiSubjectUtil;
import jbo.app.tenwa.customer.CUSTOMER_INFO;
import jbo.app.tenwa.customer.CUSTOMER_PERSON;
import jbo.app.tenwa.doc.LB_DOCATTRIBUTE;
import jbo.app.tenwa.doc.LB_DOCRELATIVE;
import jbo.app.tenwa.doc.LB_DOC_CONTRACT_LIST;
import jbo.app.tenwa.doc.LB_ONEDIMENSIONALCODE;
import jbo.com.tenwa.entity.comm.officetempalte.BF_TEMPLATE;
import jbo.com.tenwa.lease.carbrand.LB_CONTRACT_SIGN_LOG;
import jbo.com.tenwa.lease.comm.LB_CONTRACT_TEMPLATE;
import jbo.com.tenwa.lease.comm.LB_UNION_LESSEE;
public class MakeOneCodeAndContractModel {
private static Logger logger=Logger.getLogger(ContractSignAction.class);
public HessianProxyFactory factory = new HessianProxyFactory();
public HttpRequestAppService requestService;
public String MOneDimensionalCode(String contractNo,String contractId,String projectId,String diskPath,JBOTransaction tx) throws Exception{
JBarcode localJBarcode = new JBarcode(Code128Encoder.getInstance(), WidthCodedPainter.getInstance(), BaseLineTextPainter.getInstance());
localJBarcode.setEncoder(Code128Encoder.getInstance());
localJBarcode.setPainter(WidthCodedPainter.getInstance());
localJBarcode.setBarHeight(10);
localJBarcode.setTextPainter(BaseLineTextPainter.getInstance());
localJBarcode.setShowCheckDigit(false);
BufferedImage localBufferedImage = null;
localBufferedImage = localJBarcode.createBarcode(contractNo);
//<2F><>ȡ<EFBFBD><C8A1>ǰʱ<C7B0><EFBFBD><E4A3AC><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><E4B4B4>һά<D2BB><CEAC><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>·<EFBFBD><C2B7>
Calendar now = Calendar.getInstance();
String path = now.get(Calendar.YEAR)+"//"+(now.get(Calendar.MONTH) + 1) + "//"+now.get(Calendar.DAY_OF_MONTH);
File file = new File(diskPath+path);
if (!file.exists()) {
file.mkdirs();
}
path=path+"//"+contractId+".jpg";
OutputStream jos = null;
jos = new FileOutputStream(diskPath+path);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(jos);
JPEGEncodeParam jpegEP = JPEGCodec.getDefaultJPEGEncodeParam(localBufferedImage);
jpegEP.setQuality((float) 1, true);
try {
encoder.encode(localBufferedImage, jpegEP);
jos.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
jos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
BizObjectManager attrBm = JBOFactory.getBizObjectManager(LB_ONEDIMENSIONALCODE.CLASS_NAME,tx);
// BizObjectManager attrBm=JBOFactory.getBizObjectManager("jbo.app.tenwa.doc.LB_ONEDIMENSIONALCODE");
BizObject attr=attrBm.newObject();
attr.setAttributeValue("PROJECT_ID", projectId);
attr.setAttributeValue("CONTRACT_ID", contractId);
attr.setAttributeValue("CONTRACT_NO", contractNo);
attr.setAttributeValue("FileName", contractId+".jpg");
Date date= new Date(System.currentTimeMillis());
String pattern="yyyy/MM/dd HH:mm:ss";
SimpleDateFormat sdf= new SimpleDateFormat(pattern);
attr.setAttributeValue("InputTime",sdf.format(date));
attr.setAttributeValue("objectType", "OneDimensionalCode");
attr.setAttributeValue("FilePath",path);
attr.setAttributeValue("FullPath",diskPath+path);
attr.setAttributeValue("Content_Type", "jpg");
// tx.join(attrBm);
attrBm.saveObject(attr);
return diskPath+path;
}
/**
* <20><><EFBFBD><EFBFBD>word<72>ĵ<EFBFBD>
* @param sTemplateParam <20><><EFBFBD><EFBFBD>word<72>ĵ<EFBFBD><C4B5>IJ<EFBFBD><C4B2><EFBFBD>
* @param tempid ģ<><C4A3><EFBFBD><EFBFBD>id
* @param tx
* @return
* @throws Exception
*/
public String createBqWord(String sTemplateParam,String tempid,JBOTransaction tx) throws Exception{
List<String> message=new ArrayList<String>();
//<2F><><EFBFBD>ɲ<EFBFBD><C9B2><EFBFBD>
JSONObject paramJson=JSONDecoder.decode(sTemplateParam);
Map<String,String>sourceMap=FileOperatorUtil.getJsonObjectToMap(paramJson);
BqCreateOfficeService officeSer=new BqCreateOfficeService(tx);
if(tempid.length()>0){
BizObjectManager bmbt = JBOFactory.getBizObjectManager(BF_TEMPLATE.CLASS_NAME);
tx.join(bmbt);
BizObject bobt=bmbt.createQuery("id=:id").setParameter("id",tempid).getSingleResult(false);
String TWO_CLASSIFY = bobt.getAttribute("TWOCLASSIFY").toString();
String THREE_CLASSIFY = bobt.getAttribute("THREECLASSIFY").toString();
String FOUR_CLASSIFY = bobt.getAttribute("FOURCLASSIFY").toString();
String TEMPLATEVERSION = bobt.getAttribute("TEMPLATEVERSION").toString();
if(bobt==null||TWO_CLASSIFY==null||THREE_CLASSIFY==null||FOUR_CLASSIFY==null||TEMPLATEVERSION==null){
message.add(NameManager.getItemName("ProductContractTemplate", THREE_CLASSIFY)+"δ<EFBFBD>ҵ<EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>");
}else{
// <20><><EFBFBD><EFBFBD>LB_CONTRACT_TEMPLATE<54><45>
BizObjectManager bm = JBOFactory.getBizObjectManager(LB_CONTRACT_TEMPLATE.CLASS_NAME);
tx.join(bm);
BizObject bo = bm.newObject();
String id=UUIDUtil.getUUID();
bo.setAttributeValue("id", id);
bo.setAttributeValue("ONE_CLASSIFY", TWO_CLASSIFY);
bo.setAttributeValue("TWO_CLASSIFY", THREE_CLASSIFY);
bo.setAttributeValue("THREE_CLASSIFY", FOUR_CLASSIFY);
bo.setAttributeValue("FOUR_CLASSIFY", TEMPLATEVERSION);
// bo.setAttributeValue("CONTRACT_NUMBER", boc.getAttribute("CONTRACT_NUMBER").getString());
bo.setAttributeValue("CONTRACT_ID", sourceMap.get("CONTRACT_ID"));
bo.setAttributeValue("FLOWUNID", sourceMap.get("FLOW_UNID"));
bm.saveObject(bo);
bo.getKey();
sourceMap.put("TEMPLATE_ID", id);
BizObject rela=JBOFactory.createBizObjectQuery(LB_DOCRELATIVE.CLASS_NAME,"TEMPLATE_ID=:tempid").setParameter("tempid", tempid).getSingleResult(false);
if(rela!=null){
DocListAction doc=new DocListAction();
doc.setRelativeId(rela.getAttribute("id").getString());
doc.deleteRelative(tx);
}
officeSer.createOfficeByTemplateNo(bobt.getAttribute("id").getString(), sourceMap);
}
}
return message.toString();
}
//wordתpdf
public String wordTopdf(String projectId,String contractId,JBOTransaction tx) throws Exception{
String pdfPath="";
BizObjectManager contBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME, tx);
BizObjectManager attrBom = JBOFactory.getBizObjectManager(LB_DOCATTRIBUTE.CLASS_NAME, tx);
BizObjectManager lulManage = JBOFactory.getBizObjectManager(LB_UNION_LESSEE.CLASS_NAME, tx);
BizObject lul = lulManage.createQuery("project_id=:projectid").setParameter("projectid", projectId).getSingleResult(false);
String customername = null;
String telephone = null;
String ids =null;
if(lul!=null){
ids = lul.getAttribute("CUSTOMER_ID").toString();
customername = lul.getAttribute("CUSTOMER_NAME").toString();
BizObjectManager ciManage = JBOFactory.getBizObjectManager(CUSTOMER_INFO.CLASS_NAME, tx);
BizObject ci = ciManage.createQuery("customerid=:customerid").setParameter("customerid", lul.getAttribute("CUSTOMER_ID").getString()).getSingleResult(false);
BizObjectManager cpManage = JBOFactory.getBizObjectManager(CUSTOMER_PERSON.CLASS_NAME, tx);
BizObject cp = cpManage.createQuery("customerid=:customerid").setParameter("customerid", lul.getAttribute("CUSTOMER_ID").getString()).getSingleResult(false);
if(ci!=null&&"03".equals(ci.getAttribute("customertype").getString())){
telephone = (cp==null?"":cp.getAttribute("mobile").getString());
}
}
WordToPDFUtil wordTopdf = new WordToPDFUtil();
File file = null;
Boolean result = null;
List<BizObject> bo = contBom.createQuery("contract_id=:contractId and file_flag='yes' and process='1'").setParameter("contractId", contractId).getResultList(true);
if (bo != null) {
for (BizObject contBo : bo) {
String attrId = contBo.getAttribute("ATTRIBUTE_ID").toString();
BizObject attrBo = attrBom.createQuery("id='" +attrId+"'").getSingleResult(true);
String path = attrBo.getAttribute("FULLPATH").toString();
String lastFilePath = path.replace(".docx", ".pdf");
File filePath = new File(path);
if(!filePath.exists()){
logger.info("wordת<EFBFBD><EFBFBD>pdf<EFBFBD><EFBFBD>Դ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
continue;
}
String lastFilePathpdf = filePath.getParent();
try {
result = wordTopdf.Word2Pdf(path, lastFilePathpdf);
} catch (Exception e) {
result = false;
e.printStackTrace();
}
if (result) {
file =new File(lastFilePath);
contBo.setAttributeValue("FULLPATH",lastFilePath);
contBo.setAttributeValue("FILENAME",contBo.getAttribute("FILENAME").toString().replace(".docx",".pdf" ));
contBo.setAttributeValue("FILEPATH",contBo.getAttribute("FILEPATH").toString().replace(".docx", ".pdf"));
contBo.setAttributeValue("CONTENT_TYPE","application/pdf");
contBo.setAttributeValue("PROCESS","2");
contBo.setAttributeValue("PROJECT_ID",projectId);
contBo.setAttributeValue("CUSTOMERNAME",customername);
contBo.setAttributeValue("TELEPHONE",telephone);
contBo.setAttributeValue("IDS",ids);
contBom.saveObject(contBo);
pdfPath=attrBo.getAttribute("FULLPATH").toString().replace(".docx", ".pdf");
attrBo.setAttributeValue("FULLPATH",attrBo.getAttribute("FULLPATH").toString().replace(".docx", ".pdf"));
attrBo.setAttributeValue("FILENAME",attrBo.getAttribute("FILENAME").toString().replace(".docx", ".pdf"));
attrBo.setAttributeValue("FILEPATH",attrBo.getAttribute("FILEPATH").toString().replace(".docx", ".pdf"));
attrBo.setAttributeValue("FileSize",file.length());
attrBo.setAttributeValue("CONTENT_TYPE","application/pdf");
attrBom.saveObject(attrBo);
}else{
contBo.setAttributeValue("PROCESS","3");
contBom.saveObject(contBo);
}
}
}
return pdfPath;
}
/**
* <20><>pdf<64><66><EFBFBD><EFBFBD>һά<D2BB><CEAC>ͼƬ
* @param outPdfFile <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
* @param markImagePath һά<D2BB><CEAC><EFBFBD><EFBFBD>ͼƬ·<C6AC><C2B7>
* @param tx <20><><EFBFBD><EFBFBD>
* @return
* @throws Exception
*/
public String pdfAndMark(String outPdfFile, String markImagePath,String contractId,String leasform,JBOTransaction tx) throws Exception{
BizObjectManager contBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME, tx);
BizObjectManager attrBom = JBOFactory.getBizObjectManager(LB_DOCATTRIBUTE.CLASS_NAME, tx);
BizObjectManager loscBom = JBOFactory.getBizObjectManager(LB_ONEDIMENSIONALCODE.CLASS_NAME, tx);
BizObject losc = loscBom.createQuery("CONTRACT_ID=:contractId").setParameter("contractId", contractId).getSingleResult(true);
if(markImagePath.length()<=0){
if(losc!=null){
markImagePath = losc.getAttribute("FULLPATH").getString();
}
}
BizObject cont = contBom.createQuery("contract_id=:contractId and file_flag='yes'").setParameter("contractId", contractId).getSingleResult(true);
String newPath = "";
String split ="";
String InPdfFile="";
String docName="";
if(cont!=null){
InPdfFile=cont.getAttribute("fullpath").toString();
split = cont.getAttribute("filepath").toString();
docName = cont.getAttribute("doc_name").toString();
File file = new File(outPdfFile+split.substring(0,split.lastIndexOf("/")));
if (!file.exists()) {
file.mkdirs();
}
newPath=outPdfFile+split;
}else{
return "error";
}
String filename = cont.getAttribute("filename")+"";
PdfReader reader = new PdfReader(InPdfFile, "PDF".getBytes());
int pages = reader.getNumberOfPages();//<2F><>ȡpdf<64><66><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(newPath));
Image img = Image.getInstance(markImagePath);//<2F><><EFBFBD><EFBFBD>ˮӡ
if(filename.indexOf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")>=0){
//<2F><><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD>Ⱥ͸߶<CDB8>
img.scaleAbsolute(160, 18);
//<2F><><EFBFBD><EFBFBD>ͼƬˮӡ<CBAE><D3A1>λ<EFBFBD>á<EFBFBD><C3A1><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>С<EFBFBD><D0A1><EFBFBD>󡣵ڶ<F3A1A3B5><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>С<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
img.setAbsolutePosition(410, 800);
}else if(filename.indexOf("ʨ<EFBFBD><EFBFBD>")>=0){
//<2F><><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD>Ⱥ͸߶<CDB8>
img.scaleAbsolute(160, 18);
//<2F><><EFBFBD><EFBFBD>ͼƬˮӡ<CBAE><D3A1>λ<EFBFBD>á<EFBFBD>
img.setAbsolutePosition(380, 750);
}else{
int width=180,height=32,x=405,y=790;
img.scaleAbsolute(width, height);
img.setAbsolutePosition(x, y);
}
PdfContentByte under = stamp.getUnderContent(1);
under.addImage(img);
if(pages>2&&"02".equals(leasform)&&filename.indexOf("BJ90<EFBFBD><EFBFBD>ʽ<EFBFBD>ۺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")<0 && filename.indexOf("ʨ<EFBFBD><EFBFBD>")<0&& filename.indexOf("<EFBFBD>г<EFBFBD>")<0){
PdfContentByte under2 = stamp.getUnderContent(3);
if(filename.indexOf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")>=0){
//<2F><><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD>Ⱥ͸߶<CDB8>
img.setAbsolutePosition(400, 800);
}
under2.addImage(img);
}
if(pages>6&&"C<EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>".equals(docName)){
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ˮӡ
PdfContentByte under5 = stamp.getUnderContent(3);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under5.addImage(img);
//<2F><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7><EFBFBD><EFBFBD>ˮӡ
PdfContentByte under9 = stamp.getUnderContent(7);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under9.addImage(img);
}
if((pages>8&&"02".equals(leasform)&&"<EFBFBD><EFBFBD>ͬ(<28>ۺ<EFBFBD><DBBA><EFBFBD><EFBFBD><EFBFBD>)".equals(docName))
||(pages>8&&"02".equals(leasform)&&"<EFBFBD><EFBFBD>ͬ(<28>ۺ<EFBFBD><DBBA><EFBFBD><EFBFBD><EFBFBD>)-<2D><><EFBFBD>ó<EFBFBD><><C4A3>".equals(docName))){
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ˮӡ
PdfContentByte under5 = stamp.getUnderContent(5);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under5.addImage(img);
//<2F><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7><EFBFBD><EFBFBD>ˮӡ
PdfContentByte under9 = stamp.getUnderContent(9);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under9.addImage(img);
}
//<2F><><EFBFBD>ݹҿ<DDB9>Э<EFBFBD><D0AD>ˮӡ
if(pages>8&&"02".equals(leasform)&&("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޳<EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD>ͬ".equals(docName)||"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD>ͬ".equals(docName))){
PdfContentByte under10 = stamp.getUnderContent(9);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under10.addImage(img);
}
if(pages>10&&"02".equals(leasform)&&("<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD>ǩ".equals(docName)||"<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD>ǩ".equals(docName))){
//||"<22><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ǩԼ".equals(docName)||"<22><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ǩԼ".equals(docName))){
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ˮӡ
PdfContentByte under5 = stamp.getUnderContent(5);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under5.addImage(img);
PdfContentByte under7 = stamp.getUnderContent(7);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under7.addImage(img);
//<2F><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7><EFBFBD><EFBFBD>ˮӡ
PdfContentByte under9 = stamp.getUnderContent(11);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under9.addImage(img);
}
if(pages>6&&"02".equals(leasform)&&("<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩԼ".equals(docName)||"<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩԼ".equals(docName))){
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ˮӡ
PdfContentByte under5 = stamp.getUnderContent(4);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under5.addImage(img);
PdfContentByte under7 = stamp.getUnderContent(5);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under7.addImage(img);
//<2F><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7><EFBFBD><EFBFBD>ˮӡ
PdfContentByte under9 = stamp.getUnderContent(7);
img.scaleAbsolute(180, 32);
img.setAbsolutePosition(400, 800);
under9.addImage(img);
}
stamp.close();// <20>ر<EFBFBD>
File tempfile = new File(InPdfFile);
//ɾ<><C9BE>ԭ<EFBFBD>ļ<EFBFBD>
if(tempfile.exists()) {
tempfile.delete();
}
cont.setAttributeValue("FULLPATH",newPath);
contBom.saveObject(cont);
BizObject attr = attrBom.createQuery("ID=:id").setParameter("id", cont.getAttribute("attribute_id").getString()).getSingleResult(true);
if(attr!=null){
attr.setAttributeValue("FULLPATH",newPath);
attrBom.saveObject(attr);
}
return newPath;
}
//<2F><>˾<EFBFBD><CBBE><EFBFBD><EFBFBD>
public String compnySignIng(String contract_Id,String SubjectId,JBOTransaction tx) throws Exception {
if(MultiSubjectUtil.TJSUBJECTID.equals(SubjectId)){
requestService = (HttpRequestAppService) factory.create(HttpRequestAppService.class, this.getConfigRequestUrlTj());
}else if(MultiSubjectUtil.SZSUBJECTID.equals(SubjectId)){
requestService = (HttpRequestAppService) factory.create(HttpRequestAppService.class, this.getConfigRequestUrl());
}else{
return "δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}
//requestService = (HttpRequestAppService) factory.create(HttpRequestAppService.class, this.getConfigRequestUrl());
BizObjectManager contBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME, tx);
Map<String, ContractSignInfo> map = new HashMap<String, ContractSignInfo>();
ContractSignInfo con = null;
List<BizObject> bo = null;
BizObject ldclBo = null;
// <20><>ѯlb_doc_contract_list<73><74>
bo = contBom.createQuery("contract_id=:contractId and file_flag='yes' and (sendprocess='0' or sendprocess='2' ) ").setParameter("contractId", contract_Id).getResultList(true);
for (BizObject keys : bo) {
String info = keys.getAttribute("id").toString();
con = new ContractSignInfo();
con.setCustname(keys.getAttribute("DOC_NAME").toString());
con.setCustphone(keys.getAttribute("TELEPHONE").toString());
con.setFileid(keys.getAttribute("ATTRIBUTE_ID").toString());
con.setFilename(keys.getAttribute("FILENAME").toString());
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
String makefullPath = keys.getAttribute("FULLPATH").toString();
File file = new File(makefullPath);
if (!file.exists()) {
throw new RuntimeException("Ҫ<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
con.setInputfile(BASE64.encodeImgageToBase64(file));
map.put(info, con);
}
Map<String,String> fromCondtion = new HashMap<String, String>();
Map<String,String> otherProperty = new HashMap<String, String>();
Map<String, String> resultMap = requestService.compnySign(map);
if (!resultMap.containsKey("error")) {
for (String key : resultMap.keySet()) {
// <20><EFBFBD><E6B4A2>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>صĺ<D8B5>ͬid<69>ͺ<EFBFBD>ͬ<EFBFBD>ļ<EFBFBD>id
if (key.indexOf("contract_") == -1) {
fromCondtion.clear();
otherProperty.clear();
// <20><>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>
String contractId = resultMap.get("contract_" + key);
String sendProcess = resultMap.get("contract_" + contractId);
ldclBo = contBom.createQuery("ATTRIBUTE_ID='" + key + "'").getSingleResult(true);
ldclBo.setAttributeValue("DOCUMENT_ID", resultMap.get(key));
ldclBo.setAttributeValue("SINGCONTRACT_ID", contractId);
ldclBo.setAttributeValue("SIGN_TYPE", "COMPLETE");//<2F><><EFBFBD>˿ͻ<CBBF><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¸<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>״̬
ldclBo.setAttributeValue("SENDPROCESS", sendProcess);
ldclBo.setAttributeValue("PROCESS", "4");
contBom.saveObject(ldclBo);
String contractDocId = ldclBo.getAttribute("id").toString();
fromCondtion.put("id", contractDocId);
otherProperty.put("SIGNPROCESS", "0");// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩԼ
otherProperty.put("CONTRACTDOCID", contractDocId);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩԼ
otherProperty.put("INPUTTIME",DateAssistant.getTodayNow());
//<2F><><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>
DataOperatorUtil.copySingleJBO(LB_DOC_CONTRACT_LIST.CLASS_NAME, fromCondtion, LB_CONTRACT_SIGN_LOG.CLASS_NAME, null,
otherProperty, tx);
}
}
downloadDoc(contract_Id,tx);
return "success";
} else {
Boolean flag = false;
String getMessage = resultMap.get("error");
logger.info("<EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ" + getMessage);
for (String key : resultMap.keySet()) {
// <20><EFBFBD><E6B4A2>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>صĺ<D8B5>ͬid<69>ͺ<EFBFBD>ͬ<EFBFBD>ļ<EFBFBD>id
if (key.indexOf("contract_") == -1 && !"error".equals(key)) {
fromCondtion.clear();
otherProperty.clear();
// <20><>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>
String contractId = resultMap.get("contract_" + key);
String sendProcess = resultMap.get("contract_" + contractId);
ldclBo = contBom.createQuery("ATTRIBUTE_ID='" + key + "'").getSingleResult(true);
ldclBo.setAttributeValue("DOCUMENT_ID", resultMap.get(key));
ldclBo.setAttributeValue("SINGCONTRACT_ID", contractId);
ldclBo.setAttributeValue("SENDPROCESS", sendProcess);
if ("1".equals(sendProcess)) {
flag = true;
ldclBo.setAttributeValue("SIGN_TYPE", "SIGNING");
}else if("2".equals(sendProcess)){
ldclBo.setAttributeValue("MESSAGE",getMessage );
}
contBom.saveObject(ldclBo);
String contractDocId = ldclBo.getAttribute("id").toString();
fromCondtion.put("ID", contractDocId);
otherProperty.put("SIGNPROCESS", "0");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩԼ
otherProperty.put("CONTRACTDOCID",contractDocId);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩԼ
otherProperty.put("INPUTTIME",DateAssistant.getTodayNow());
DataOperatorUtil.copySingleJBO(LB_DOC_CONTRACT_LIST.CLASS_NAME, fromCondtion, LB_CONTRACT_SIGN_LOG.CLASS_NAME, null,
otherProperty, tx);
}
}
// <20>жϲ<D0B6>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><ECB3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
if (getMessage.indexOf("<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬǩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD>") != -1) {
getMessage = getMessage.substring((getMessage.indexOf("message")) + 10, (getMessage.indexOf("code")) - 3);
return flag + "@" + getMessage;
} else if (getMessage.indexOf("contractId<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>") != -1) {
return flag + "@" + getMessage;
} else {
return flag + "@" + "error";
}
}
}
/**
* <20><><EFBFBD><EFBFBD>document_id<69><64><EFBFBD>غ<EFBFBD>ͬ
*
* @param tx
* @return
* @throws Exception
* @throws Exception
* @throws MalformedURLException
*/
public String downloadDoc(String contract_id,JBOTransaction tx) throws MalformedURLException, Exception {
requestService = (HttpRequestAppService) factory.create(HttpRequestAppService.class, this.getConfigRequestUrl());
BizObjectManager contBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME, tx);
String sql = "";
sql = "contract_id=:contractid and file_flag='yes'";
try {
@SuppressWarnings("unchecked")
List<BizObject> bo = contBom.createQuery(sql).setParameter("contractid", contract_id).getResultList(true);
if (bo != null) {
Map<String, String> map = new HashMap<String, String>();
for (BizObject keys : bo) {
map.put(keys.getAttribute("DOCUMENT_ID").toString(), keys.getAttribute("FULLPATH").toString());
}
Map<String, String> result = requestService.downloadDoc(map);
if (!result.containsKey("error")) {
for (String contractId : map.keySet()) {
try {
if ("success".equals(result.get(contractId))) {
String fileString = result.get("file_" + contractId);
InputStream fileInput = BASE64.encodeFileToBase64(fileString);
OutputStream fileOut = new FileOutputStream(map.get(contractId));// TODO
byte[] buffByte = new byte[1024];
int size = 0;
while ((size = fileInput.read(buffByte)) != -1) {
fileOut.write(buffByte, 0, size);
}
fileInput.close();
fileOut.close();
} else if ("error".equals(result.get(contractId))) {
return "error";
}
} catch (Exception e) {
e.printStackTrace();
}
}
return "success";
} else {
return "error";
}
}
} catch (Exception e) {
return "error";
}
return "success";
}
@SuppressWarnings("deprecation")
public static String getConfigRequestUrl() throws Exception{
return Configure.getInstance().getConfigure("RequestHessionUrl");
}
@SuppressWarnings("deprecation")
public static String getConfigRequestUrlTj() throws Exception{
return Configure.getInstance().getConfigure("RequestHessionUrlTj");
}
public Map fileBase(String contractId){
Map<String,String> fileNameBase = new HashMap<String, String>();
try {
BizObjectManager contBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME);
BizObject cont = contBom.createQuery(" contract_id=:contractid and file_flag='yes' and (sendprocess='0' or sendprocess='2' ) ").setParameter("contractid", contractId).getSingleResult(false);
if(cont==null){
return fileNameBase;
}
String newPath = cont.getAttribute("fullpath").getString();
File file = new File(newPath);
if (!file.exists()) {
return fileNameBase;
}
// return BASE64.encodeImgageToBase64(file);
fileNameBase.put("fileName", newPath.substring(newPath.lastIndexOf("/")+1));
fileNameBase.put("outputFile", BASE64.encodeImgageToBase64(file));
} catch (JBOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return fileNameBase;
}
/**
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @throws Exception
*/
public void BqChangecontract(String contractId,JBOTransaction tx) throws Exception{
//ɾ<><C9BE>֮ǰ<D6AE><C7B0><EFBFBD>ɵ<EFBFBD><C9B5>ļ<EFBFBD>
BizObjectManager contBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME,tx);
List<BizObject> conts = contBom.createQuery(" contract_id=:contractid ").setParameter("contractid", contractId).getResultList(true);
for (BizObject cont : conts) {
cont.setAttributeValue("file_flag", "no");
contBom.saveObject(cont);
}
BizObjectManager lctBom = JBOFactory.getBizObjectManager(LB_CONTRACT_TEMPLATE.CLASS_NAME,tx);
List<BizObject> lcts = lctBom.createQuery(" contract_id=:contractid ").setParameter("contractid", contractId).getResultList(true);
for (BizObject lct : lcts) {
lctBom.deleteObject(lct);
}
}
}