From 5a69fb8fceef313129b4c211d34afbcbb5891e16 Mon Sep 17 00:00:00 2001 From: tangft <32189@DESKTOP-M6TAG3K> Date: Tue, 18 Dec 2018 10:56:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=97=E8=B4=A2=E6=8E=A5=E5=8F=A3=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=8F=8A=E6=8E=A5=E5=8F=A3=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebContent/WEB-INF/etc/jbo/jbo_doc.xml | 30 + WebContent/WEB-INF/web.xml | 23 + config/META-INF/xfire/services.xml | 13 + .../tenwa/makeContract/McontractService.java | 6 + .../com/tenwa/makeContract/ReturnMessage.java | 41 ++ .../tenwa/makeContract/WebServiceFilter.java | 42 ++ .../impl/McontractServiceImpl.java | 381 ++++++++++++ .../util/BqBaseWordCallBackServiceImpl.java | 145 +++++ .../util/BqCreateOfficeCallBackService.java | 136 +++++ .../util/BqCreateOfficeService.java | 171 ++++++ .../util/MakeOneCodeAndContractModel.java | 547 ++++++++++++++++++ .../util/McCalcConditionCopyService.java | 201 +++++++ 12 files changed, 1736 insertions(+) create mode 100644 config/META-INF/xfire/services.xml create mode 100644 src_tenwa/com/tenwa/makeContract/McontractService.java create mode 100644 src_tenwa/com/tenwa/makeContract/ReturnMessage.java create mode 100644 src_tenwa/com/tenwa/makeContract/WebServiceFilter.java create mode 100644 src_tenwa/com/tenwa/makeContract/impl/McontractServiceImpl.java create mode 100644 src_tenwa/com/tenwa/makeContract/util/BqBaseWordCallBackServiceImpl.java create mode 100644 src_tenwa/com/tenwa/makeContract/util/BqCreateOfficeCallBackService.java create mode 100644 src_tenwa/com/tenwa/makeContract/util/BqCreateOfficeService.java create mode 100644 src_tenwa/com/tenwa/makeContract/util/MakeOneCodeAndContractModel.java create mode 100644 src_tenwa/com/tenwa/makeContract/util/McCalcConditionCopyService.java diff --git a/WebContent/WEB-INF/etc/jbo/jbo_doc.xml b/WebContent/WEB-INF/etc/jbo/jbo_doc.xml index 20129f20f..541bf9295 100644 --- a/WebContent/WEB-INF/etc/jbo/jbo_doc.xml +++ b/WebContent/WEB-INF/etc/jbo/jbo_doc.xml @@ -165,5 +165,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index c20b734cf..654b9025b 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -54,6 +54,16 @@ RunFilter /servlet/view/* + + + WebServiceFilter + com.tenwa.makeContract.WebServiceFilter + + + WebServiceFilter + /services/* + + InitAREServlet com.amarsoft.are.InitAREServlet @@ -497,6 +507,19 @@ RestfullServlet /webapi/resf/* + + + XFireServlet + + org.codehaus.xfire.transport.http.XFireConfigurableServlet + + + + XFireServlet + /services/* + + + restfull自动扫描路径设置 RestfullScanPackage diff --git a/config/META-INF/xfire/services.xml b/config/META-INF/xfire/services.xml new file mode 100644 index 000000000..369b84603 --- /dev/null +++ b/config/META-INF/xfire/services.xml @@ -0,0 +1,13 @@ + + + + + McontractService + com.tenwa.makeContract.McontractService + com.tenwa.makeContract.impl.McontractServiceImpl + + \ No newline at end of file diff --git a/src_tenwa/com/tenwa/makeContract/McontractService.java b/src_tenwa/com/tenwa/makeContract/McontractService.java new file mode 100644 index 000000000..d4af869eb --- /dev/null +++ b/src_tenwa/com/tenwa/makeContract/McontractService.java @@ -0,0 +1,6 @@ +package com.tenwa.makeContract; + +public interface McontractService { + + public ReturnMessage Mcontract(String projectNo,String carNumber,String carNo,String Mstatus); +} diff --git a/src_tenwa/com/tenwa/makeContract/ReturnMessage.java b/src_tenwa/com/tenwa/makeContract/ReturnMessage.java new file mode 100644 index 000000000..b04bbcf74 --- /dev/null +++ b/src_tenwa/com/tenwa/makeContract/ReturnMessage.java @@ -0,0 +1,41 @@ +package com.tenwa.makeContract; + +public class ReturnMessage { + + private String contractStatus; + private String fileName; + private String outputFile; + private String male; + private String standby; + public String getContractStatus() { + return contractStatus; + } + public void setContractStatus(String contractStatus) { + this.contractStatus = contractStatus; + } + public String getFileName() { + return fileName; + } + public void setFileName(String fileName) { + this.fileName = fileName; + } + public String getOutputFile() { + return outputFile; + } + public void setOutputFile(String outputFile) { + this.outputFile = outputFile; + } + public String getMale() { + return male; + } + public void setMale(String male) { + this.male = male; + } + public String getStandby() { + return standby; + } + public void setStandby(String standby) { + this.standby = standby; + } + +} diff --git a/src_tenwa/com/tenwa/makeContract/WebServiceFilter.java b/src_tenwa/com/tenwa/makeContract/WebServiceFilter.java new file mode 100644 index 000000000..96acbd102 --- /dev/null +++ b/src_tenwa/com/tenwa/makeContract/WebServiceFilter.java @@ -0,0 +1,42 @@ +package com.tenwa.makeContract; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +public class WebServiceFilter implements Filter { + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + + @Override + public void doFilter(ServletRequest req, ServletResponse res, + FilterChain chain) throws IOException, ServletException { + // TODO Auto-generated method stub + String ips = "0:0:0:0:0:0:0:1|192.168.0.1|127.0.0.1|172.16.21.220|219.142.26.222|172.16.21.48"; + if(ips.indexOf(req.getRemoteAddr()) != -1){ + chain.doFilter(req, res); + }else{ + res.setCharacterEncoding("UTF-8"); + res.getWriter().println("error"); + } +// System.out.println(req.getRemoteAddr()); +// System.out.println("ԶIP" + req.getRemoteHost()); + + } + + @Override + public void init(FilterConfig arg0) throws ServletException { + // TODO Auto-generated method stub + + } + +} diff --git a/src_tenwa/com/tenwa/makeContract/impl/McontractServiceImpl.java b/src_tenwa/com/tenwa/makeContract/impl/McontractServiceImpl.java new file mode 100644 index 000000000..b52b10b82 --- /dev/null +++ b/src_tenwa/com/tenwa/makeContract/impl/McontractServiceImpl.java @@ -0,0 +1,381 @@ +package com.tenwa.makeContract.impl; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.activation.DataHandler; +import javax.activation.DataSource; +import javax.activation.FileDataSource; + +import jbo.app.tenwa.calc.LC_FUND_INCOME; +import jbo.app.tenwa.customer.CUSTOMER_ACCOUNT; +import jbo.app.tenwa.doc.LB_DOC_CONTRACT_LIST; +import jbo.com.tenwa.entity.comm.flow.FLOW_WORK_FLAG; +import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO; +import jbo.com.tenwa.lease.comm.LB_CONTRACT_STATUS; +import jbo.com.tenwa.lease.comm.LB_EQUIPMENT_CAR; +import jbo.com.tenwa.lease.comm.LB_PROJECT_INFO; + +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.awe.Configure; +import com.amarsoft.awe.util.ASResultSet; +import com.amarsoft.awe.util.SqlObject; +import com.amarsoft.awe.util.Transaction; +import com.tenwa.doc.util.BASE64; +import com.tenwa.makeContract.McontractService; +import com.tenwa.makeContract.ReturnMessage; +import com.tenwa.makeContract.util.MakeOneCodeAndContractModel; +import com.tenwa.makeContract.util.McCalcConditionCopyService; +import com.tenwa.util.SerialNumberUtil; + +public class McontractServiceImpl implements McontractService{ + + MakeOneCodeAndContractModel modc = new MakeOneCodeAndContractModel(); + Configure CurConfig = Configure.getInstance(); + @Override + public ReturnMessage Mcontract(String projectNo,String carNumber, String carNo,String Mstatus){ + ReturnMessage rMage = new ReturnMessage(); + if(projectNo==null||projectNo==""||projectNo.length()<=0){ + rMage.setContractStatus("error"); + rMage.setMale("ŲΪ"); + }else if (carNumber==null||carNumber==""||carNumber.length()<=0){ + rMage.setContractStatus("error"); + rMage.setMale("󣺳ܺŲΪ"); + }else if(carNo==null||carNo==""||carNo.length()<=0){ + rMage.setContractStatus("error"); + rMage.setMale("󣺷ŲΪ"); + }else if(Mstatus==null||Mstatus==""||Mstatus.length()<=0){ + rMage.setContractStatus("error"); + rMage.setMale("ʶΪ"); + }else if("NEW".equalsIgnoreCase(Mstatus)){ + String carColor = "ԳǼ֤ǼɫΪ׼"; + return makeContract(projectNo,carNumber,carNo,carColor); + }else if("UPDATE".equalsIgnoreCase(Mstatus)){ + return changeContract(projectNo,carNumber,carNo); + }else{ + rMage.setContractStatus("error"); + rMage.setMale("ʶ󣡣"); + } + return rMage; + } + + public ReturnMessage makeContract(String projectNo,String carNumber, String carNo,String carColor){ + McCalcConditionCopyService mcs = new McCalcConditionCopyService(); + ReturnMessage rMage = new ReturnMessage(); + + MakeOneCodeAndContractModel modc = new MakeOneCodeAndContractModel(); + String tempid="";//ģid + String sTemplateParam="{'CurUserId':'8006U00000003','CurOrgId':'8006003'";//wordҪIJ + JBOTransaction tx = null; + try { + tx =JBOFactory.createJBOTransaction(); + BizObjectManager lpiManage = JBOFactory.getBizObjectManager(LB_PROJECT_INFO.CLASS_NAME,tx); + BizObjectManager caManage = JBOFactory.getBizObjectManager(CUSTOMER_ACCOUNT.CLASS_NAME,tx); + BizObjectManager lciManage = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME,tx); + BizObject lpi = lpiManage.createQuery("PROJECT_NO=:projectNo ").setParameter("projectNo", projectNo).getSingleResult(false); + if(lpi==null){ + rMage.setContractStatus("error"); + rMage.setMale("ϵͳ޴ţ޷ͬ"); + return rMage; + } + /* BizObject ca = caManage.createQuery("PROJECT_ID=:projectId").setParameter("projectId", lpi.getAttribute("ID").getString()).getSingleResult(false); + if(ca==null){ + rMage.setContractStatus("error"); + rMage.setMale("ϵͳûв鵽ӦۿϢϵԱ"); + return rMage; + }else if(!"Y".equals(ca.getAttribute("SIGN_STATUS").getString())){ + rMage.setContractStatus("error"); + rMage.setMale("ûǩԼ֤ѿͻ鿴ֻţɿۿǩԼ֤"); + return rMage; + }*/ + BizObject lci = lciManage.createQuery("PROJECT_ID=:projectId").setParameter("projectId", lpi.getAttribute("ID").getString()).getSingleResult(false); + if(lci!=null){ + rMage.setContractStatus("success"); + rMage.setMale("Ѻͬ޷"); + Map fileBase = modc.fileBase(lci.getAttribute("ID").getString()); + if(fileBase.size()>0){ + rMage.setFileName(fileBase.get("fileName")); + rMage.setOutputFile(fileBase.get("outputFile")); + }else{ + rMage.setMale("ûҵļϵԱ"); + } + return rMage; + } + //ɺͬ + String area_code="0"; + String contractno=""; + String dept=""; + dept+="A"; + if(lpi.getAttribute("LEAS_FORM").toString().equals("01")){//ֱ + dept+="Z"; + tempid="ed20493a9234495f9ba9a88a040e3a26"; + }else{// + dept+="H"; + tempid="7cd0bccfc26b4a71aeb159cf36d7bc4f"; + } + contractno=SerialNumberUtil.getContractSerialNaumber(dept,area_code, tx);//ͬ + String contractId = java.util.UUID.randomUUID().toString().replaceAll("-", "");//ɺͬID + Transaction Sqlca =null; + Sqlca = Transaction.createTransaction(tx); + String projectId = lpi.getAttribute("ID").getString(); + String SQL="{call proc_contract_Making('"+projectId+"','"+contractId+"','"+contractno+"','"+carNumber+"','"+carColor+"','"+carNo+"')} "; + SqlObject asql = new SqlObject(SQL); + ASResultSet rs = null; + try { + rs = Sqlca.getASResultSet(asql); + mcs.tempToContractOne(projectId, projectNo, contractno, contractId, tx); + } catch (Exception e) { + + e.printStackTrace(); + } + finally{ + Sqlca.disConnect(); + Sqlca=null; + }; + String diskPath=CurConfig.getConfigure("OneDimensionalCode"); + //ݺͬһάͼƬ +// JBOTransaction onetx =JBOFactory.createJBOTransaction(); + String path = modc.MOneDimensionalCode(contractno, contractId, projectId,diskPath,tx); + //wordĵ + String wordPath=CurConfig.getConfigure("FileSavePath"); + sTemplateParam=sTemplateParam+",'CONTRACT_ID':'"+contractId+"','PROJ_ID':'"+projectId+"','CONTRACT_NO':'"+contractno+"','fileSavePath':'"+wordPath+"','carcolor':'"+carColor+"','carNumber':'"+carNumber+"','carNo':'"+carNo+"'}"; + modc.createBqWord(sTemplateParam, tempid, tx); + //wordתpdf +// onetx.commit(); +// JBOTransaction wordtx =JBOFactory.createJBOTransaction(); + String wordTopdf = modc.wordTopdf(projectId, contractId, tx); + //ͬ + String compnySignIng = modc.compnySignIng(contractId, tx); + //һάӵpdf +// wordtx.commit(); +// JBOTransaction pdftx =JBOFactory.createJBOTransaction(); + String outPdfFile = CurConfig.getConfigure("BQcontract"); + String newPath = modc.pdfAndMark(outPdfFile, path, contractId, tx); +// pdftx.commit(); + + String massage = outputFile(newPath); + if("error".equals(massage)){ + rMage.setContractStatus("error"); + rMage.setMale("pdfļڣ"); + tx.rollback(); + return rMage; + } + rMage.setContractStatus("success"); + rMage.setFileName(newPath.substring(newPath.lastIndexOf("/")+1)); + rMage.setOutputFile(massage); +// String upload = BASE64.encodeImgageToBase64(file); + +// System.out.println(upload); +// return "{'contractStatus':'success','fileName':'"+newPath.substring(newPath.indexOf("/")+1)+"','outputFile':'"+upload+"','male':'Ϊ"+projectNo+"Ѻͬظ'}"; + tx.commit(); + return rMage; + } catch (Exception e) { + try { + tx.rollback(); + } catch (JBOException e1) { + e1.printStackTrace(); + } + e.printStackTrace(); + System.out.println(e.toString()); + rMage.setContractStatus("error"); + rMage.setMale("ͬʧܣ·ͬ"); +// return "{'contractStatus':'error','fileName':'','outputFile':'','male':'"+e.toString()+"'}"; + return rMage; + } + + + } + + public ReturnMessage changeContract(String projectNo,String carNumber, String carNo){ + ReturnMessage rMage = new ReturnMessage(); + String tempid="";//ģid + String sTemplateParam="{'CurUserId':'8006U00000003','CurOrgId':'8006003'";//wordҪIJ + JBOTransaction tx = null; + try { + tx =JBOFactory.createJBOTransaction(); + BizObjectManager lpiManage = JBOFactory.getBizObjectManager(LB_PROJECT_INFO.CLASS_NAME,tx); + BizObjectManager lecManage = JBOFactory.getBizObjectManager(LB_EQUIPMENT_CAR.CLASS_NAME,tx); + BizObjectManager lciManage = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME,tx); + BizObject lpi = lpiManage.createQuery("PROJECT_NO=:projectNo ").setParameter("projectNo", projectNo).getSingleResult(false); + if(lpi==null){ + rMage.setContractStatus("error"); + rMage.setMale("ϵͳ޴ţ޷ͬ"); + return rMage; + } + String projectId = lpi.getAttribute("ID").getString(); + BizObject lci = lciManage.createQuery("PROJECT_ID=:projectId").setParameter("projectId", lpi.getAttribute("ID").getString()).getSingleResult(false); + if(lci==null){ + rMage.setContractStatus("error"); + rMage.setMale("ûͬȺͬ"); + return rMage; + }else if(!"21".equals(lci.getAttribute("CONTRACT_STATUS").getString())){ + BizObjectManager lcsManage = JBOFactory.getBizObjectManager(LB_CONTRACT_STATUS.CLASS_NAME,tx); + BizObject lcs = lcsManage.createQuery(" STATUS_CODE=:statuscode ").setParameter("statuscode", lci.getAttribute("CONTRACT_STATUS").getString()).getSingleResult(false); + if(lcs==null){ + rMage.setContractStatus("error"); + rMage.setMale("ͬ״̬ϵԱ"); + }else{ + rMage.setContractStatus("error"); + rMage.setMale("ͬ״̬Ϊ"+lcs.getAttribute("STATUS_NAME").getString()+"ܺͬ"); + } + return rMage; + } + String contractId = lci.getAttribute("ID").getString(); + String contractno = lci.getAttribute("contract_no").getString(); + //УͬǷڸ + BizObjectManager fwfManage = JBOFactory.getBizObjectManager(FLOW_WORK_FLAG.CLASS_NAME,tx); + BizObject fwf = fwfManage.createQuery(" mutex_key=:cotnractId and flow_name='FundPaymentCarFlow' ").setParameter("cotnractId", contractId).getSingleResult(false); + if(fwf!=null){ + rMage.setContractStatus("error"); + rMage.setMale("úͬڸУܺͬ"); + return rMage; + } + //УͬǷѾͨ + BizObjectManager lfiManage = JBOFactory.getBizObjectManager(LC_FUND_INCOME.CLASS_NAME,tx); + List lfis = lfiManage.createQuery(" contract_id=:contractid ").setParameter("contractid", contractId).getResultList(false); + if(lfis.size()>0){ + rMage.setContractStatus("error"); + rMage.setMale("úͬѾͨ룬ܺͬ"); + return rMage; + } + //УǷ + BizObject lec = lecManage.createQuery(" PROJECT_ID=:projectId and CONTRACT_ID=:contractId").setParameter("projectId", projectId).setParameter("contractId", lci.getAttribute("ID").getString()).getSingleResult(true); + if(lec==null){ + rMage.setContractStatus("error"); + rMage.setMale("ûв鵽ϢϵԱ!!!"); + return rMage; + }else if(carNumber.equals(lec.getAttribute("FRAME_NUMBER").getString())&&carNo.equals(lec.getAttribute("ENGINE_NUMBER").getString())){ + rMage.setContractStatus("error"); + rMage.setMale("ûпɱݣݣ"); + Map fileBase = modc.fileBase(lci.getAttribute("ID").getString()); + if(fileBase.size()>0){ + rMage.setFileName(fileBase.get("fileName")); + rMage.setOutputFile(fileBase.get("outputFile")); + } + return rMage; + } + lec.setAttributeValue("FRAME_NUMBER", carNumber); + lec.setAttributeValue("ENGINE_NUMBER", carNo); + lecManage.saveObject(lec); + //ȡģ + if(lpi.getAttribute("LEAS_FORM").toString().equals("01")){//ֱ + tempid="ed20493a9234495f9ba9a88a040e3a26"; + }else{// + tempid="7cd0bccfc26b4a71aeb159cf36d7bc4f"; + } + //ȡģ· + String wordPath=CurConfig.getConfigure("FileSavePath"); + sTemplateParam=sTemplateParam+",'CONTRACT_ID':'"+contractId+"','PROJ_ID':'"+projectId+"','CONTRACT_NO':'"+contractno+"','fileSavePath':'"+wordPath+"','carcolor':'"+lec.getAttribute("CAR_COLOUR").getString()+"','carNumber':'"+carNumber+"','carNo':'"+carNo+"'}"; + //ɾLB_DOC_CONTRACT_LISTǰ + modc.BqChangecontract(contractId, tx); + //wordĵ + String createBqWord = modc.createBqWord(sTemplateParam, tempid, tx); + //wordתpdfɵ· + String wordTopdf = modc.wordTopdf(projectId, contractId, tx); + //ͬ + String compnySignIng = modc.compnySignIng(contractId, tx); + //һάӵpdf + String outPdfFile = CurConfig.getConfigure("BQcontract"); + String newPath = modc.pdfAndMark(outPdfFile, "", contractId, tx); + + rMage.setContractStatus("success"); + + Map fileBase = modc.fileBase(contractId); + if(fileBase.size()>0){ + rMage.setFileName(fileBase.get("fileName")); + rMage.setOutputFile(fileBase.get("outputFile")); + rMage.setMale("ͬɹ"); + }else{ + rMage.setMale("ͬļûҵϵԱ"); + } + tx.commit(); + return rMage; + + /*String filePath = filePath(lci.getAttribute("ID").getString()); + String massage = outputFile(filePath); + if("error".equals(massage)){ + rMage.setContractStatus("success"); + rMage.setMale("pdfļڣϵԱ"); + return rMage; + } + rMage.setContractStatus("error"); + rMage.setMale("Ѻͬ޷"); + rMage.setFileName(filePath.substring(filePath.lastIndexOf("/")+1)); + rMage.setOutputFile(massage); + return rMage;*/ + + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return rMage; + } + + public String outputFile(String newPath){ + //ļתΪString + File file = new File(newPath); + if (!file.exists()) { +// throw new RuntimeException("Ҫȡļ"); + return "error"; + } + return BASE64.encodeImgageToBase64(file); + } + /*public String filePath(String contractId) throws Exception{ + BizObjectManager contBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME); + BizObject cont = contBom.createQuery(" contract_id=:contractid").setParameter("contractid", contractId).getSingleResult(false); + if(cont==null){ + return ""; + } + return cont.getAttribute("fullpath").getString(); + }*/ + /*public String upload(DataHandler handler, String fileName) { + if (fileName != null && !"".equals(fileName)) { + File file = new File(fileName); + if (handler != null) { + InputStream is = null; + FileOutputStream fos = null; + try { + is = handler.getInputStream(); + fos = new FileOutputStream(file); + byte[] buff = new byte[1024 * 8]; + int len = 0; + while ((len = is.read(buff)) > 0) { + fos.write(buff, 0, len); + } + } catch (FileNotFoundException e) { + return "fileNotFound"; + } catch (Exception e) { + return "upload File failure"; + } finally { + try { + if (fos != null) { + fos.flush(); + fos.close(); + } + if (is != null) { + is.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +// return "file absolute path:" + file.getAbsolutePath(); + return file.getAbsolutePath(); + } else { + return "handler is null"; + } + } else { + return "fileName is null"; + } + }*/ +} diff --git a/src_tenwa/com/tenwa/makeContract/util/BqBaseWordCallBackServiceImpl.java b/src_tenwa/com/tenwa/makeContract/util/BqBaseWordCallBackServiceImpl.java new file mode 100644 index 000000000..ef121dd5d --- /dev/null +++ b/src_tenwa/com/tenwa/makeContract/util/BqBaseWordCallBackServiceImpl.java @@ -0,0 +1,145 @@ +package com.tenwa.makeContract.util; + +import java.io.File; +import java.io.InputStream; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import jbo.sys.CODE_LIBRARY; + +import org.dom4j.Document; +import org.dom4j.io.SAXReader; + +import com.amarsoft.are.jbo.BizObject; +import com.amarsoft.are.jbo.JBOFactory; +import com.amarsoft.are.jbo.JBOTransaction; +import com.amarsoft.ars.zip.ZipEntry; +import com.amarsoft.ars.zip.ZipFile; +import com.tenwa.comm.exception.BusinessException; +import com.tenwa.officetempalte.service.BaseLableDataService; +import com.tenwa.officetempalte.serviceImp.BaseWordLableReplaceServiceImp; +import com.tenwa.officetempalte.util.FileOperatorUtil; +import com.tenwa.officetempalte.util.WordBookMarkXmlUtil; + +public class BqBaseWordCallBackServiceImpl extends BqCreateOfficeCallBackService{ + @Override + public void run(BizObject templateConfig, Map paramMap, + JBOTransaction tx) throws Exception { + + BaseLableDataService dataSer=new BaseLableDataService(tx); + //ȡģ + List exportConfig=dataSer.getTemplateExportConfig(templateConfig.getAttribute("id").getString()); + + Map tempModel=new HashMap(); + tempModel.putAll(paramMap); + + //ȡļʵ· + String fileName=""; + String filePath=""; + String fullPath=""; + fileName=FileOperatorUtil.getFileNameByFormual(templateConfig.getAttribute("templateshowname").getString(), tempModel); + String uuid=UUID.randomUUID().toString().replaceAll("-", ""); + fullPath=FileOperatorUtil.getuploadFileDir(paramMap.get("fileSavePath")) +uuid+"_"+fileName; + filePath=fullPath.replace(paramMap.get("fileSavePath"), ""); + //ȡģļ + String tempName=templateConfig.getAttribute("templatepath").getString(); + String rootPath=this.getClass().getResource("/").getPath(); + rootPath=rootPath.substring(0, rootPath.indexOf("WEB-INF")-1); + tempName=rootPath+"/fileTemplate/"+tempName; + String suffix = tempName.substring(tempName.lastIndexOf(".")); + File file = new File(tempName); + if (file.isFile()) { + if (suffix.indexOf("doc") > 0) { + try { + //word + this.writeDatatoTemplateWordbyBookMark(tempName, paramMap, fullPath,exportConfig,tx); + } catch (Exception e) { + e.printStackTrace(); + throw new BusinessException("дwordģʱ"+e.getMessage()); + } + } + } else { + throw new BusinessException(templateConfig.getAttribute("templateshowname").getString() + "ûģ"); + } + //ɳɹ άϵ + this.createRelative(templateConfig, paramMap, fileName, filePath, fullPath, tx); + } + + public void runBefore(BizObject templateConfig, + Map paramMap, JBOTransaction tx) throws Exception { + // TODO Auto-generated method stub + + } + + @Override + public void runAllBefore(BizObject templateConfig, + Map paramMap, JBOTransaction tx) throws Exception { + // TODO Auto-generated method stub + + } + //wordĵ + public void writeDatatoTemplateWordbyBookMark(String tempfile,Map model, String targetFile,List exportConfig,JBOTransaction tx) throws Exception{ + + BaseWordLableReplaceServiceImp wordSer=new BaseWordLableReplaceServiceImp(); + BaseLableDataService lableSer=new BaseLableDataService(tx); + + Document document = null; + File file = new File(tempfile); + ZipFile docxFile = new ZipFile(file); + ZipEntry documentXML = docxFile.getEntry("word/document.xml"); + InputStream documentXMLIS = docxFile.getInputStream(documentXML); + SAXReader saxReader = new SAXReader(); + document = saxReader.read(documentXMLIS); + Map documents=new HashMap(); + documents.put("miandocument", document); + + Map footmap=WordBookMarkXmlUtil.getfooter(docxFile); + documents.putAll(footmap); + Map operMap=new HashMap(); + operMap.put("default", wordSer); + + Map configData=new HashMap(); + + for(BizObject config:exportConfig){ + configData=lableSer.getLableDataByConfig(config, model); + Class oper=null; + Method replaceString=null; + Method replaceList=null; + Method replaceTable=null; + String operator_class=config.getAttribute("operatorclass").getString(); + if(operator_class.length()==0||operator_class.equals("word_default_class")){ + oper=operMap.get("default").getClass(); + }else if(operMap.containsKey(operator_class)){ + oper=(Class)operMap.get(operator_class); + }else{ + BizObject code=JBOFactory.getBizObjectManager(CODE_LIBRARY.CLASS_NAME).createQuery("itemno=:itemno and codeno='lable_operator_class'") + .setParameter("itemno", operator_class).getSingleResult(false); + oper=Class.forName(code.getAttribute("itemattribute").getString()); + operMap.put(operator_class, oper); + } + replaceString=oper.getMethod("replaceStringLable",Map.class,BizObject.class,Map.class); + replaceList=oper.getMethod("replaceListLable",Map.class,BizObject.class,Map.class); + replaceTable=oper.getMethod("replaceTableLable",Map.class,BizObject.class,Map.class); + if(config.getAttribute("tagtype").getString().equals("tag_type1")){//ַ + replaceString.invoke(oper.newInstance(),documents,config,configData); + }else if(config.getAttribute("tagtype").getString().equals("tag_type2")){// + replaceList.invoke(oper.newInstance(),documents,config,configData); + }else if(config.getAttribute("tagtype").getString().equals("tag_type3")){// + replaceTable.invoke(oper.newInstance(),documents,config,configData); + } + } + //ĵ + WordBookMarkXmlUtil.saveWordXML(docxFile,document,footmap,targetFile); + } + + @Override + public void runAfter(BizObject templateConfig, + Map paramMap, JBOTransaction tx) throws Exception { + // TODO Auto-generated method stub + + } + +} diff --git a/src_tenwa/com/tenwa/makeContract/util/BqCreateOfficeCallBackService.java b/src_tenwa/com/tenwa/makeContract/util/BqCreateOfficeCallBackService.java new file mode 100644 index 000000000..c18e65b14 --- /dev/null +++ b/src_tenwa/com/tenwa/makeContract/util/BqCreateOfficeCallBackService.java @@ -0,0 +1,136 @@ +package com.tenwa.makeContract.util; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import jbo.app.tenwa.doc.LB_DOCATTRIBUTE; +import jbo.app.tenwa.doc.LB_DOCCONFIG; +import jbo.app.tenwa.doc.LB_DOCLIBRARY; +import jbo.app.tenwa.doc.LB_DOCRELATIVE; +import jbo.app.tenwa.doc.LB_DOC_CONTRACT_LIST; + +import com.amarsoft.are.jbo.BizObject; +import com.amarsoft.are.jbo.BizObjectManager; +import com.amarsoft.are.jbo.BizObjectQuery; +import com.amarsoft.are.jbo.JBOFactory; +import com.amarsoft.are.jbo.JBOTransaction; +import com.amarsoft.are.util.StringFunction; +/** + * ģ崦ӿ + * + * */ +public abstract class BqCreateOfficeCallBackService { + public abstract void run(BizObject templateConfig,Map paramMap,JBOTransaction tx) throws Exception; + public abstract void runBefore(BizObject templateConfig,Map paramMap,JBOTransaction tx) throws Exception; + public abstract void runAllBefore(BizObject templateConfig,Map paramMap,JBOTransaction tx) throws Exception; + public abstract void runAfter(BizObject templateConfig,Map paramMap,JBOTransaction tx) throws Exception; + + //άϵ + public void createRelative(BizObject templateConfig,Map paramMap,String filename,String filepath,String fullpath,JBOTransaction tx) throws Exception{ + String doctype=templateConfig.getAttribute("DocType").getString(); + String one_classify= templateConfig.getAttribute("ONECLASSIFY").getString(); + Map condtionMap=new HashMap(); + String[] s=new String[]{"OBJECTTYPE","PROJ_ID","CONTRACT_ID","PLAN_NUMBER","PLAN_LIST","CUST_ID","FLOW_UNID","TEMPLATE_ID"}; + for(int i=0;i entry:condtionMap.entrySet()){ + sql+=" and rel."+entry.getKey()+"=:"+entry.getKey(); + } + BizObjectQuery query=libBm.createQuery(sql); + query.setParameter("oneclassify", one_classify); + query.setParameter("doctype", doctype); + query.setParameter("docname", templateConfig.getAttribute("TEMPLATENAME").getString()); + for(Map.Entry entry:condtionMap.entrySet()){ + query.setParameter(entry.getKey(),entry.getValue()); + } + BizObject lib=query.getSingleResult(false); + String libraryId; + if(lib==null){ + //ʼ + BizObject rela=relaBm.newObject(); + for(Map.Entry entry:condtionMap.entrySet()){ + rela.setAttributeValue(entry.getKey(), entry.getValue()); + } + relaBm.saveObject(rela); + String relativeid=rela.getAttribute("id").getString(); + //ʼ + lib=libBm.newObject(); + lib.setAttributeValue("doc_name", templateConfig.getAttribute("TEMPLATENAME").getString()); + lib.setAttributeValue("Doc_type", doctype); + lib.setAttributeValue("One_Classify", one_classify); + lib.setAttributeValue("Relative_id", relativeid); + lib.setAttributeValue("Is_File_List","0"); + libBm.saveObject(lib); + libraryId=lib.getAttribute("id").getString(); + }else{ + libraryId=lib.getAttribute("id").getString(); + } + File file=new File(fullpath); + BizObject attr=attrBm.newObject(); + attr.setAttributeValue("Library_id", libraryId); + attr.setAttributeValue("FileName", filename); + attr.setAttributeValue("InputUserId",paramMap.get("CurUserId")); + attr.setAttributeValue("InputOrgId", paramMap.get("CurOrgId")); + attr.setAttributeValue("InputTime",StringFunction.getTodayNow()); + attr.setAttributeValue("FilePath",filepath); + attr.setAttributeValue("FullPath",fullpath); + if(fullpath.endsWith(".docx")){ + attr.setAttributeValue("Content_Type","application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + }else if(fullpath.endsWith(".xlsx")){ + attr.setAttributeValue("Content_Type","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + }else if(fullpath.endsWith(".xls")){ + attr.setAttributeValue("Content_Type","application/vnd.ms-excel"); + } + attr.setAttributeValue("FileSize",file.length()); + attrBm.saveObject(attr); + + // дLB_DOC_CONTRACT_LIST + // ģȡlb_docconfigϢ + String attrId = attr.getAttribute("id").getString(); + BizObjectManager lbcontractBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME, tx); + Map contractMap = new HashMap(); + String[] ss = new String[] {"CUSTOMERNAME", "TELEPHONE", "CONTRACT_NO", "CONTRACT_ID", "PROJECT_ID", "PRODECT_ID", "IDS", + "FLOW_UNID"}; + for (int i = 0; i < ss.length; i++) { + if (paramMap.containsKey(ss[i])) { + contractMap.put(ss[i], paramMap.get(ss[i])); + } + } + BizObject contract = lbcontractBom.newObject(); + for (Map.Entry entry : contractMap.entrySet()) { + contract.setAttributeValue(entry.getKey(), entry.getValue()); + } + contract.setAttributeValue("InputUserId", paramMap.get("CurUserId")); + contract.setAttributeValue("InputOrgId", paramMap.get("CurOrgId")); + contract.setAttributeValue("FILENAME", attr.getAttribute("FILENAME").toString()); + contract.setAttributeValue("ATTRIBUTE_ID", attrId); + contract.setAttributeValue("LIBRARY_ID", libraryId); + contract.setAttributeValue("FILE_TYPE", "ɨ"); + contract.setAttributeValue("FILE_FLAG", "yes"); + contract.setAttributeValue("DOC_NAME", templateConfig.getAttribute("TEMPLATENAME").getString()); + contract.setAttributeValue("FILEPATH", attr.getAttribute("FILEPATH").toString()); + contract.setAttributeValue("FULLPATH", attr.getAttribute("FULLPATH").toString()); + contract.setAttributeValue("InputTime", StringFunction.getTodayNow()); +// contract.setAttributeValue("CONFIG_ID", templateConfig.getAttribute("CONFIG_ID").getString()); +// contract.setAttributeValue("DOC_CLASS_ITEMNO", bo.getAttribute("DOC_CLASS_ITEMNO").getString()); + if (fullpath.endsWith(".pdf")) { + contract.setAttributeValue("PROCESS", "2"); + } else if (fullpath.endsWith(".docx") || fullpath.endsWith(".doc")) { + contract.setAttributeValue("PROCESS", "1"); + } + contract.setAttributeValue("SIGN_TYPE", "DRAFT");// ǩԼ״̬ĬΪݸ + contract.setAttributeValue("SENDPROCESS", "0");// ״̬Ĭδ + lbcontractBom.saveObject(contract); + } +} diff --git a/src_tenwa/com/tenwa/makeContract/util/BqCreateOfficeService.java b/src_tenwa/com/tenwa/makeContract/util/BqCreateOfficeService.java new file mode 100644 index 000000000..27d797cad --- /dev/null +++ b/src_tenwa/com/tenwa/makeContract/util/BqCreateOfficeService.java @@ -0,0 +1,171 @@ +package com.tenwa.makeContract.util; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import jbo.com.tenwa.entity.comm.officetempalte.BF_TEMPLATE; + +import com.amarsoft.app.util.XMLDataUtil; +import com.amarsoft.are.ARE; +import com.amarsoft.are.jbo.BizObject; +import com.amarsoft.are.jbo.BizObjectManager; +import com.amarsoft.are.jbo.BizObjectQuery; +import com.amarsoft.are.jbo.JBOFactory; +import com.amarsoft.are.jbo.JBOTransaction; +import com.amarsoft.are.log.Log; +import com.amarsoft.awe.util.ASResultSet; +import com.amarsoft.awe.util.SqlObject; +import com.amarsoft.awe.util.Transaction; +import com.tenwa.comm.exception.BusinessException; +import com.tenwa.officetempalte.service.BaseParamService; +import com.tenwa.officetempalte.service.CreateOfficeCallBackService; +import com.tenwa.officetempalte.util.FileOperatorUtil; +/** + * ģ崴ļ + * ⲿ createOfficeByTemplateNo + * */ +public class BqCreateOfficeService { + public static Log logger=ARE.getLog(); + JBOTransaction tx; + Transaction Sqlca =null; + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//ڸʽ + public BqCreateOfficeService(JBOTransaction tx)throws Exception{ + this.tx=tx; + Sqlca=Transaction.createTransaction(tx); + } + /** + * ģźǰ̨ļ + * @param templateNo ģ + * @param model ǰ̨ + * + * */ + @SuppressWarnings("unchecked") + public void createOfficeByTemplateNo(String templateNo,Mapmodel) throws Exception{ + try{ + //ȡģ + BizObject templateConfig=this.getTemplateConfigByNo(templateNo); + if(templateConfig==null){ + throw new BusinessException("ģ"+templateNo+"ûҵģ"); + } + //ģźǰ̨ȡģֵ + BaseParamService paramSer=new BaseParamService(tx); + //ģ崦 + Class callback=null; + //ȡģ崦 + if(templateConfig.getAttribute("callback").getString().length()>0){ + try{ + callback=(Class) Class.forName(templateConfig.getAttribute("callback").getString()); + }catch(Exception e){ + throw new BusinessException(templateConfig.getAttribute("templatename").getString()+"ģ崦δҵ"); + } + }else if(templateConfig.getAttribute("templatetype").getString().equals("word")){//wordĬģ崦 + callback=(Class) Class.forName("com.tenwa.makeContract.util.BqBaseWordCallBackServiceImpl"); + }else if(templateConfig.getAttribute("templatetype").getString().equals("excel")){//excel Ĭģ崦 + callback=(Class) Class.forName("com.tenwa.makeContract.util.BqBaseWordCallBackServiceImpl"); + }else{ + throw new BusinessException(templateConfig.getAttribute("templatename").getString()+"ģ崦δҵ"); + } + //ȡģ崦ķ + BqCreateOfficeCallBackService ser=callback.newInstance(); + + //ǰ + ser.runAllBefore(templateConfig, model, tx); + + //ȡģ崴 + List> creatParam=this.getCreateTempalteParm(templateConfig, model); + if(creatParam==null)//ǿ Ĭϴһļ + { Map paramMap=new HashMap(); + Map pmap=paramSer.getParamValueByTemplateNo(templateConfig.getAttribute("id").getString(), model); + paramMap.putAll(model); + paramMap.putAll(pmap); + ser.runBefore(templateConfig, paramMap, tx); + ser.run(templateConfig, paramMap, tx); + ser.runAfter(templateConfig, paramMap, tx); + }else{//ݴѭļ + Map map=new HashMap(); + for(int i=0;i pmap=paramSer.getParamValueByTemplateNo(templateConfig.getAttribute("id").getString(), map); + //õݷŵ ǩȡݿɴӲػȡ + ser.runBefore(templateConfig, map, tx); + ser.run(templateConfig, map, tx); + ser.runAfter(templateConfig, map, tx); + } + } + }catch(BusinessException e){ + e.printStackTrace(); + throw e; + } + } + /** + * ȡģ + * */ + public BizObject getTemplateConfigByNo(String templateNo)throws Exception{ + BizObjectManager tempalteManger = JBOFactory.getBizObjectManager(BF_TEMPLATE.CLASS_NAME); + tx.join(tempalteManger); + BizObjectQuery tempalteMangerQuery = tempalteManger.createQuery("id=:id "); + tempalteMangerQuery.setParameter("id",templateNo); + BizObject tempalte = null; + tempalte = tempalteMangerQuery.getSingleResult(true); + return tempalte; + } + + /** + * ģúͲ ȡģ崴 + * @throws Exception + * */ + public List> getCreateTempalteParm(BizObject templateConfig,Map model) throws Exception{ + //ȡ + String sql=templateConfig.getAttribute("CreateCondition").getString(); + if(null==sql||sql.length()>10) + { + List> params=new ArrayList>(); + if(sql.indexOf(".xml")>0)//xml ȡxmlеsql + { + String xmlPath=ARE.getProperty("PRD_HOME").replace("/WEB-INF", "")+sql; + Map xmlfile=XMLDataUtil.readTableInfoFromXmlFile(xmlPath); + sql=xmlfile.get("table_sql"); + } + MapparamMap=new HashMap(); + //滻sql + sql=FileOperatorUtil.replaceSQLFixedParam(sql,model); + paramMap=FileOperatorUtil.getSqlParam(sql, model); + sql=sql.replaceAll("[{]", ""); + sql=sql.replaceAll("[}]", ""); + ASResultSet rs = null; + try { + SqlObject asql = new SqlObject(sql); + if(null!=paramMap && paramMap.keySet().size()>0){ + for(String key :paramMap.keySet()){ + asql.setParameter(key, paramMap.get(key)); + } + } + rs = Sqlca.getASResultSet(asql); + } catch (Exception e1) { + throw new BusinessException("ִ"+sql+"ʱ"); + } + while (rs.next()) { + Map dataMap=FileOperatorUtil.getASResultSetToMap(rs); + params.add(dataMap); + } + if(params.size()==0) + { + logger.info("ģ"+templateConfig.getAttribute("templatename").getString()+"ݴδĵ"); + } + + return params; + } + else + { + return null; + } + } + + + +} diff --git a/src_tenwa/com/tenwa/makeContract/util/MakeOneCodeAndContractModel.java b/src_tenwa/com/tenwa/makeContract/util/MakeOneCodeAndContractModel.java new file mode 100644 index 000000000..ccce1bd94 --- /dev/null +++ b/src_tenwa/com/tenwa/makeContract/util/MakeOneCodeAndContractModel.java @@ -0,0 +1,547 @@ +package com.tenwa.makeContract.util; + +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.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.exception.BusinessException; +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.service.CreateOfficeService; +import com.tenwa.officetempalte.util.FileOperatorUtil; +import com.tenwa.reckon.util.UUIDUtil; + +import org.apache.log4j.Logger; +import org.jbarcode.JBarcode; +import org.jbarcode.encode.Code128Encoder; +import org.jbarcode.encode.InvalidAtributeException; +import org.jbarcode.paint.BaseLineTextPainter; +import org.jbarcode.paint.WidthCodedPainter; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileNotFoundException; +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 jbo.app.tenwa.customer.CUSTOMER_FAMILY_TEMP; +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_GUARANTEE_UNIT_TEMP; +import jbo.com.tenwa.lease.comm.LB_PROJECT_INFO; +import jbo.com.tenwa.lease.comm.LB_PROJECT_INFO_TEMP; +import jbo.com.tenwa.lease.comm.LB_UNION_LESSEE; + +import com.itextpdf.text.Image; +import com.itextpdf.text.pdf.PdfContentByte; +import com.itextpdf.text.pdf.PdfReader; +import com.itextpdf.text.pdf.PdfStamper; + + +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.setTextPainter(BaseLineTextPainter.getInstance()); + localJBarcode.setShowCheckDigit(false); + + BufferedImage localBufferedImage = null; + try { + localBufferedImage = localJBarcode.createBarcode(contractNo); + } catch (InvalidAtributeException e) { + e.printStackTrace(); + } + //获取当前时间,根据时间创建一维码存放的路径 + 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; + try { + jos = new FileOutputStream(diskPath+path); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + 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("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; + } + /** + * 生成word文档 + * @param sTemplateParam 生成word文档的参数 + * @param tempid 模板的id + * @param tx + * @return + * @throws Exception + */ + public String createBqWord(String sTemplateParam,String tempid,JBOTransaction tx) throws Exception{ + List message=new ArrayList(); + //生成参数 + //String sTemplateParam=this.getTemplateParam().replaceAll("@", ","); + JSONObject paramJson=JSONDecoder.decode(sTemplateParam); + MapsourceMap=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)+"未找到模板配置!"); + }else{ + // 保存LB_CONTRACT_TEMPLATE表 + 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(); + try{ + // sourceMap.put("contract_id", bo.getAttribute("contract_number").getString()); + 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); + }catch(BusinessException e){ + message.add(e.getMessage()); + } + } + } + return message.toString(); + } + //word转pdf + public String wordTopdf(String projectId,String contractId,JBOTransaction tx){ + String pdfPath=""; + try { + 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 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转换pdf的源文件不存在"); + 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); + } + } + } + } catch (JBOException e) { + e.printStackTrace(); + } + return pdfPath; + } + /** + * 向pdf插入一维码图片 + * @param outPdfFile 插入后输出的路径 + * @param markImagePath 一维码的图片路径 + * @param tx 事务 + * @return + * @throws Exception + */ + public String pdfAndMark(String outPdfFile, String markImagePath,String contractId,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=""; + if(cont!=null){ + InPdfFile=cont.getAttribute("fullpath").toString(); + split = cont.getAttribute("filepath").toString(); + File file = new File(outPdfFile+split.substring(0,split.lastIndexOf("/"))); + if (!file.exists()) { + file.mkdirs(); + } + newPath=outPdfFile+split; + }else{ + return "error"; + } + PdfReader reader = new PdfReader(InPdfFile, "PDF".getBytes()); + PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(newPath)); + Image img = Image.getInstance(markImagePath);// 插入水印    + //设置图片水印的位置。 + img.setAbsolutePosition(370, 780); + + PdfContentByte under = stamp.getUnderContent(1); + under.addImage(img); + + + stamp.close();// 关闭           + File tempfile = new File(InPdfFile); + //删除原文件 + + 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; + } + + //公司盖章 + public String compnySignIng(String contract_Id,JBOTransaction tx) throws Exception { + requestService = (HttpRequestAppService) factory.create(HttpRequestAppService.class, this.getConfigRequestUrl()); + BizObjectManager contBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME, tx); + Map map = new HashMap(); + ContractSignInfo con = null; + List bo = null; + BizObject ldclBo = null; + try { + // 查询lb_doc_contract_list表 + 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()); + // 获取生成文件路径 + String makefullPath = keys.getAttribute("FULLPATH").toString(); + File file = new File(makefullPath); + if (!file.exists()) { + throw new RuntimeException("要读取的文件不存在"); + } + con.setInputfile(BASE64.encodeImgageToBase64(file)); + map.put(info, con); + } + Map fromCondtion = new HashMap(); + Map otherProperty = new HashMap(); + Map resultMap = requestService.compnySign(map); + if (!resultMap.containsKey("error")) { + for (String key : resultMap.keySet()) { + // 存储契约锁返回的合同id和合同文件id + if (key.indexOf("contract_") == -1) { + fromCondtion.clear(); + otherProperty.clear(); + // 契约锁合同号 + 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");//法人客户当盖完章改为完成状态 + ldclBo.setAttributeValue("SENDPROCESS", sendProcess); + contBom.saveObject(ldclBo); + + String contractDocId = ldclBo.getAttribute("id").toString(); + fromCondtion.put("id", contractDocId); + otherProperty.put("SIGNPROCESS", "0");// 发起电子签约 + otherProperty.put("CONTRACTDOCID", contractDocId);// 发起电子签约 + otherProperty.put("INPUTTIME",DateAssistant.getTodayNow()); + //拷表的方法 + 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("契约锁反馈的异常信息" + getMessage); + for (String key : resultMap.keySet()) { + // 存储契约锁返回的合同id和合同文件id + if (key.indexOf("contract_") == -1 && !"error".equals(key)) { + fromCondtion.clear(); + otherProperty.clear(); + // 契约锁合同号 + 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");//发起电子签约 + otherProperty.put("CONTRACTDOCID",contractDocId);//发起电子签约 + otherProperty.put("INPUTTIME",DateAssistant.getTodayNow()); + DataOperatorUtil.copySingleJBO(LB_DOC_CONTRACT_LIST.CLASS_NAME, fromCondtion, LB_CONTRACT_SIGN_LOG.CLASS_NAME, null, + otherProperty, tx); + } + } + // 判断不同的异常反馈给前端 + if (getMessage.indexOf("用户认证信息与合同签署方信息不匹配") != -1) { + getMessage = getMessage.substring((getMessage.indexOf("message")) + 10, (getMessage.indexOf("code")) - 3); + return flag + "@" + getMessage; + } else if (getMessage.indexOf("contractId不能为空") != -1) { + return flag + "@" + getMessage; + } else { + return flag + "@" + "error"; + } + } + } catch (Exception e) { + tx.rollback(); + e.printStackTrace(); + logger.info("法人客户生成合同盖章失败" + e.getMessage()); + return "flase@error"; + } + } + + /** + * 根据document_id下载合同 + * + * @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 bo = contBom.createQuery(sql).setParameter("contractid", contract_id).getResultList(true); + if (bo != null) { + Map map = new HashMap(); + for (BizObject keys : bo) { + map.put(keys.getAttribute("DOCUMENT_ID").toString(), keys.getAttribute("FULLPATH").toString()); + } + Map 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"); + } + + public Map fileBase(String contractId){ + Map fileNameBase = new HashMap(); + 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; + } + + + /** + * 北汽合同变更方法 + * @throws Exception + */ + public void BqChangecontract(String contractId,JBOTransaction tx) throws Exception{ + //删除之前生成的文件 + BizObjectManager contBom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME,tx); + List 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 lcts = lctBom.createQuery(" contract_id=:contractid ").setParameter("contractid", contractId).getResultList(true); + for (BizObject lct : lcts) { + lctBom.deleteObject(lct); + } + } +} diff --git a/src_tenwa/com/tenwa/makeContract/util/McCalcConditionCopyService.java b/src_tenwa/com/tenwa/makeContract/util/McCalcConditionCopyService.java new file mode 100644 index 000000000..82e008005 --- /dev/null +++ b/src_tenwa/com/tenwa/makeContract/util/McCalcConditionCopyService.java @@ -0,0 +1,201 @@ +package com.tenwa.makeContract.util; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import jbo.app.tenwa.calc.LC_CALC_CONDITION; +import jbo.app.tenwa.calc.LC_CALC_CONDITION_TEMP; +import jbo.app.tenwa.calc.LC_CALC_PERIOD; +import jbo.app.tenwa.calc.LC_CALC_RULES; +import jbo.app.tenwa.calc.LC_CALC_SUBSECTION; +import jbo.app.tenwa.calc.LC_CONTRACT_CASH_FLOW; +import jbo.app.tenwa.calc.LC_CONTRACT_CONDITION; +import jbo.app.tenwa.calc.LC_CONTRACT_FUND_PLAN; +import jbo.app.tenwa.calc.LC_CONTRACT_PERIOD; +import jbo.app.tenwa.calc.LC_CONTRACT_RENT_PLAN; +import jbo.app.tenwa.calc.LC_CONTRACT_RULES; +import jbo.app.tenwa.calc.LC_CONTRACT_SUBSECTION; +import jbo.app.tenwa.calc.LC_FUND_PLAN; +import jbo.app.tenwa.calc.LC_PAY_CASH_FLOW; +import jbo.app.tenwa.calc.LC_PAY_RENT_PLAN; +import jbo.app.tenwa.calc.LC_PROJ_CASH_FLOW; +import jbo.app.tenwa.calc.LC_PROJ_CONDITION; +import jbo.app.tenwa.calc.LC_PROJ_FUND_PLAN; +import jbo.app.tenwa.calc.LC_PROJ_PERIOD; +import jbo.app.tenwa.calc.LC_PROJ_RENT_PLAN; +import jbo.app.tenwa.calc.LC_PROJ_RULES; +import jbo.app.tenwa.calc.LC_PROJ_SUBSECTION; +import jbo.app.tenwa.calc.LC_RENT_PLAN_TEMP; +import jbo.com.tenwa.lease.comm.LC_HANDLING_APPORTION; +import jbo.com.tenwa.lease.comm.LC_PAY_CONDTION; + +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.tenwa.comm.util.jboutil.DataOperatorUtil; +import com.tenwa.reckon.constant.Scale; +import com.tenwa.reckon.util.DateTools; +import com.tenwa.util.SerialNumberUtil; + +public class McCalcConditionCopyService { + + + public void tempToContractOne(String projid,String projNo,String contractNo,String contractId,JBOTransaction tx) throws Exception{ + /** + * ͬʱIJ + * fromCondition{PROJECT_PLAN_NUMBER=A20181203000101, PROJECT_ID=1a4bed70c8f2417785f0009ef18f5eac} + otherProperty{CONTRACT_PLAN_NUMBER=BQAP(AZ)20181204000101, FLOWUNID=FBO2018120400000001} + ǰ + otherProperty{FLOWUNID=FBO2018120400000001, PLAN_NUMBER=BQAP(AZ)20181204000101} + * + * + * fromCondition{FLOWUNID=FBO2018120400000001} + toCondition{contract_id=680f113a87d74d53a6682d8ff4b4d6c0} + otherProperty{PAYMENT_NUMBER=BQAP(AZ)201812040001-01, contract_id=680f113a87d74d53a6682d8ff4b4d6c0} + + еģ + paymentNumber680f113a87d74d53a6682d8ff4b4d6c0 + contractidBQAP(AZ)201812040001-01 + */ + Map fromCondition=new HashMap(); + fromCondition.put("PROJECT_ID", projid); + List list=DataOperatorUtil.getSetJBO(LC_PROJ_CONDITION.CLASS_NAME, fromCondition, tx); + Map otherProperty=new HashMap(); + Map toCondition=new HashMap(); + String paymentNumber=""; + for (BizObject bo : list) { + String projPlanNumber=bo.getAttribute("PROJECT_PLAN_NUMBER").getString(); + + String contractPlanNumber=projPlanNumber.replace(projNo, contractNo); + fromCondition.clear(); + fromCondition.put("PROJECT_ID", projid); + fromCondition.put("PROJECT_PLAN_NUMBER", projPlanNumber); + + toCondition.put("contract_id", contractId); + + paymentNumber=SerialNumberUtil.getPlannumber(contractNo,"pay_process", tx); + otherProperty.clear(); + otherProperty.put("CONTRACT_PLAN_NUMBER", contractPlanNumber); + otherProperty.put("contract_id", contractId); + otherProperty.put("PAYMENT_NUMBER", paymentNumber); + //1 + DataOperatorUtil.copyJBOSet(LC_PROJ_CONDITION.CLASS_NAME, fromCondition,LC_CONTRACT_CONDITION.CLASS_NAME, toCondition, otherProperty, null, tx); + DataOperatorUtil.copyJBOSet(LC_PROJ_CONDITION.CLASS_NAME, fromCondition,LC_CALC_CONDITION.CLASS_NAME, toCondition, otherProperty, null, tx); + //2 + DataOperatorUtil.copyJBOSet(LC_PROJ_RULES.CLASS_NAME, fromCondition,LC_CONTRACT_RULES.CLASS_NAME, toCondition, otherProperty, null, tx); + DataOperatorUtil.copyJBOSet(LC_PROJ_RULES.CLASS_NAME, fromCondition,LC_CALC_RULES.CLASS_NAME, toCondition, otherProperty, null, tx); + //ƻ3 + DataOperatorUtil.copyJBOSet(LC_PROJ_RENT_PLAN.CLASS_NAME, fromCondition,LC_CONTRACT_RENT_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx); + DataOperatorUtil.copyJBOSet(LC_PROJ_RENT_PLAN.CLASS_NAME, fromCondition,LC_PAY_RENT_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx); + //ƻ4 + DataOperatorUtil.copyJBOSet(LC_PROJ_FUND_PLAN.CLASS_NAME, fromCondition,LC_CONTRACT_FUND_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx); + DataOperatorUtil.copyJBOSet(LC_PROJ_FUND_PLAN.CLASS_NAME, fromCondition,LC_FUND_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx); + //ֽ5 + DataOperatorUtil.copyJBOSet(LC_PROJ_CASH_FLOW.CLASS_NAME, fromCondition, LC_CONTRACT_CASH_FLOW.CLASS_NAME, toCondition, otherProperty, null, tx); + DataOperatorUtil.copyJBOSet(LC_PROJ_CASH_FLOW.CLASS_NAME, fromCondition, LC_PAY_CASH_FLOW.CLASS_NAME, toCondition, otherProperty, null, tx); + //֪6 + DataOperatorUtil.copyJBOSet(LC_PROJ_PERIOD.CLASS_NAME, fromCondition, LC_CONTRACT_PERIOD.CLASS_NAME, toCondition, otherProperty, null, tx); + DataOperatorUtil.copyJBOSet(LC_PROJ_PERIOD.CLASS_NAME, fromCondition, LC_CALC_PERIOD.CLASS_NAME, toCondition, otherProperty, null, tx); + //ֶβ7 + DataOperatorUtil.copyJBOSet(LC_PROJ_SUBSECTION.CLASS_NAME, fromCondition, LC_CONTRACT_SUBSECTION.CLASS_NAME, toCondition, otherProperty, null, tx); + DataOperatorUtil.copyJBOSet(LC_PROJ_SUBSECTION.CLASS_NAME, fromCondition, LC_CALC_SUBSECTION.CLASS_NAME, toCondition, otherProperty, null, tx); + + otherProperty.clear(); + otherProperty.put("PLAN_NUMBER", contractPlanNumber); + //ǰ8 + DataOperatorUtil.copyJBOSet(LC_PAY_CONDTION.CLASS_NAME,fromCondition,LC_PAY_CONDTION.CLASS_NAME, toCondition, otherProperty,null, tx); + } + //ͬǶе + BizObject boLCCT = JBOFactory.getBizObjectManager(LC_PROJ_CONDITION.CLASS_NAME,tx) + .createQuery("PROJECT_ID='"+projid+"'").getSingleResult(false); + // + BigDecimal handMoney = new BigDecimal(boLCCT.getAttribute("HANDLING_CHARGE_MONEY").getString()); + + BizObject boLRPT = JBOFactory.getBizObjectManager(LC_PROJ_RENT_PLAN.CLASS_NAME,tx) + .createQuery("select v.sum(interest) v.allInterest from O where PROJECT_ID='"+projid+"'").getSingleResult(false); + + //Ϣ + BigDecimal allInterest = new BigDecimal(boLRPT.getAttribute("allInterest").getString()); + + List boLRPTs = JBOFactory.getBizObjectManager(LC_PROJ_RENT_PLAN.CLASS_NAME,tx) + .createQuery("PROJECT_ID='"+projid+"' order by plan_list").getResultList(false); + + List dateList = getDateList(boLRPTs); + //ռѷ̯ + List> handMoneyList = gethandMoneyList(handMoney.toString(), dateList, boLCCT.getAttribute("START_DATE").getString(), boLCCT.getAttribute("PERIOD_TYPE").getString(), boLCCT.getAttribute("INCOME_INTERVAL_MONTH").getInt()+""); + + BizObjectManager bomLHA = JBOFactory.getBizObjectManager(LC_HANDLING_APPORTION.CLASS_NAME,tx); + bomLHA.createQuery("delete from O where payment_number='"+paymentNumber+"'").executeUpdate(); + // + int n = 0; + for(BizObject bo:boLRPTs){ + BizObject boLHA = bomLHA.newObject(); + boLHA.setAttributeValue("CONTRACT_ID",contractId); + boLHA.setAttributeValue("PLAN_LIST",bo.getAttribute("PLAN_LIST").getString()); + boLHA.setAttributeValue("PAYMENT_NUMBER",paymentNumber); + boLHA.setAttributeValue("HANDLING_APPORTION_MONEY",handMoneyList.get(n).get("money")); + boLHA.setAttributeValue("HANDLING_APPORTION_RATIO",handMoneyList.get(n).get("ratio")); + bomLHA.saveObject(boLHA); + n++; + } + } + + + public static List getDateList(List bos) throws JBOException{ + List dateList = new ArrayList(); + for(BizObject bo:bos){ + dateList.add(bo.getAttribute("PLAN_DATE").getString()); + } + return dateList; + } + + public static List> gethandMoneyList(String handMoney,List dateList,String startDate,String period_type,String incomeNumberyear){ + List> handMoneyList=new ArrayList>(); + try { + BigDecimal hmoney=new BigDecimal(handMoney); + int number=Integer.parseInt(incomeNumberyear); + if("period_type_1".equals(period_type)){ + SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); + dateList.remove(0); + Calendar enddate=Calendar.getInstance(); + enddate.setTime(sdf.parse(dateList.get(dateList.size()-1))); + enddate.add(Calendar.MONTH, number); + dateList.add(sdf.format(enddate.getTime())); + } + BigDecimal money=BigDecimal.ZERO; + BigDecimal all=BigDecimal.ZERO; + all=new BigDecimal(DateTools.getDateDiff(dateList.get(dateList.size()-1), startDate)); + for(int i=0;i hand = new HashMap(); + BigDecimal mon=BigDecimal.ZERO; + BigDecimal ratio=BigDecimal.ZERO; + long dateDiff=DateTools.getDateDiff(dateList.get(i), startDate); + if(i