北财接口配置文件及接口实现类

This commit is contained in:
tangft 2018-12-18 10:56:58 +08:00
parent f64814039c
commit 5a69fb8fce
12 changed files with 1736 additions and 0 deletions

View File

@ -165,5 +165,35 @@
</class>
<class name="LB_ONEDIMENSIONALCODE" label="一维码表" keyAttributes="ID">
<attributes>
<attribute name="ID" label="主键" type="STRING" length="32"/>
<attribute name="PROJECT_ID" label="项目ID" type="STRING" length="32"/>
<attribute name="CONTRACT_ID" label="合同ID" type="STRING" length="32"/>
<attribute name="FILEPATH" label="文档路径" type="STRING" length="500"/>
<attribute name="FULLPATH" label="文档全路径文件名" type="STRING" length="600"/>
<attribute name="FILENAME" label="文件名" type="STRING" length="250"/>
<attribute name="FILESIZE" label="文件大小" type="STRING" length="10"/>
<attribute name="INPUTUSERID" label="上传人" type="STRING" length="32"/>
<attribute name="INPUTORGID" label="上传部门" type="STRING" length="32"/>
<attribute name="INPUTTIME" label="上传时间" type="STRING" length="32"/>
<attribute name="REMARK" label="备注" type="STRING" length="200"/>
<attribute name="CONTENT_TYPE" label="文件格式" type="STRING" length="200"/>
<attribute name="DELETEED" label="是否已删除" type="STRING" length="32"/>
<attribute name="OBJECTTYPE" label="流程编号" type="STRING" length="32"/>
<attribute name="UPDATEUSERID" label="更新人" type="STRING" length="32"/>
<attribute name="UPDATEORGID" label="更新部门" type="STRING" length="32"/>
<attribute name="UPDATETIME" label="更新时间" type="STRING" length="32"/>
<attribute name="FLOWUNID" label="流程编号" type="STRING" length="40"/>
<attribute name="STANDBY" label="备用" type="STRING" length="40"/>
<attribute name="DESCRIBE" label="描述" type="STRING" length="40"/>
</attributes>
<manager>
<managerProperties>
<property name="table" value="lb_onedimensionalcode" />
<property name="createKey" value="true" />
</managerProperties>
</manager>
</class>
</package>
</jbo>

View File

@ -54,6 +54,16 @@
<filter-name>RunFilter</filter-name>
<url-pattern>/servlet/view/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>WebServiceFilter</filter-name>
<filter-class>com.tenwa.makeContract.WebServiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>WebServiceFilter</filter-name>
<url-pattern>/services/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>InitAREServlet</servlet-name>
<servlet-class>com.amarsoft.are.InitAREServlet</servlet-class>
@ -497,6 +507,19 @@
<servlet-name>RestfullServlet</servlet-name>
<url-pattern>/webapi/resf/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>
org.codehaus.xfire.transport.http.XFireConfigurableServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<context-param>
<description>restfull自动扫描路径设置</description>
<param-name>RestfullScanPackage</param-name>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- <service xmlns="http://xfire.codehaus.org/config/1.0">
<name>test</name>
<serviceClass>com.tenwa.makeContract.IHelloService</serviceClass>
<implementationClass>com.tenwa.makeContract.HelloService</implementationClass>
</service> -->
<service xmlns="http://xfire.codehaus.org/config/1.0">
<name>McontractService</name>
<serviceClass>com.tenwa.makeContract.McontractService</serviceClass>
<implementationClass>com.tenwa.makeContract.impl.McontractServiceImpl</implementationClass>
</service>
</beans>

View File

@ -0,0 +1,6 @@
package com.tenwa.makeContract;
public interface McontractService {
public ReturnMessage Mcontract(String projectNo,String carNumber,String carNo,String Mstatus);
}

View File

@ -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;
}
}

View File

@ -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
}
}

View File

@ -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需要的参数
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<String,String> 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需要的参数
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<BizObject> 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<String,String> 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<String,String> 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";
}
}*/
}

View File

@ -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<String, String> paramMap,
JBOTransaction tx) throws Exception {
BaseLableDataService dataSer=new BaseLableDataService(tx);
//获取模板配置
List<BizObject> exportConfig=dataSer.getTemplateExportConfig(templateConfig.getAttribute("id").getString());
Map<String,Object> tempModel=new HashMap<String, Object>();
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<String, String> paramMap, JBOTransaction tx) throws Exception {
// TODO Auto-generated method stub
}
@Override
public void runAllBefore(BizObject templateConfig,
Map<String, String> paramMap, JBOTransaction tx) throws Exception {
// TODO Auto-generated method stub
}
//生成word文档
public void writeDatatoTemplateWordbyBookMark(String tempfile,Map<String, String> model, String targetFile,List<BizObject> 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<String,Document> documents=new HashMap<String, Document>();
documents.put("miandocument", document);
Map<String,Document> footmap=WordBookMarkXmlUtil.getfooter(docxFile);
documents.putAll(footmap);
Map<String,Object> operMap=new HashMap<String, Object>();
operMap.put("default", wordSer);
Map<String,Object> configData=new HashMap<String, Object>();
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<String, String> paramMap, JBOTransaction tx) throws Exception {
// TODO Auto-generated method stub
}
}

View File

@ -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<String,String> paramMap,JBOTransaction tx) throws Exception;
public abstract void runBefore(BizObject templateConfig,Map<String,String> paramMap,JBOTransaction tx) throws Exception;
public abstract void runAllBefore(BizObject templateConfig,Map<String,String> paramMap,JBOTransaction tx) throws Exception;
public abstract void runAfter(BizObject templateConfig,Map<String,String> paramMap,JBOTransaction tx) throws Exception;
//维护附件关系
public void createRelative(BizObject templateConfig,Map<String,String> 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<String,String> condtionMap=new HashMap<String, String>();
String[] s=new String[]{"OBJECTTYPE","PROJ_ID","CONTRACT_ID","PLAN_NUMBER","PLAN_LIST","CUST_ID","FLOW_UNID","TEMPLATE_ID"};
for(int i=0;i<s.length;i++){
if(paramMap.containsKey(s[i])){
condtionMap.put(s[i], paramMap.get(s[i]));
}
}
BizObjectManager libBm=JBOFactory.getBizObjectManager(LB_DOCLIBRARY.CLASS_NAME);
BizObjectManager relaBm=JBOFactory.getBizObjectManager(LB_DOCRELATIVE.CLASS_NAME);
BizObjectManager attrBm=JBOFactory.getBizObjectManager(LB_DOCATTRIBUTE.CLASS_NAME);
tx.join(libBm);
tx.join(relaBm);
tx.join(attrBm);
String sql="select * from O left join jbo.app.tenwa.doc.LB_DOCRELATIVE rel on O.relative_id=rel.id where O.DOC_TYPE=:doctype and O.one_classify=:oneclassify and O.doc_name=:docname ";
for(Map.Entry<String,String> 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<String,String> 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<String,String> 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<String, String> contractMap = new HashMap<String, String>();
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<String, String> 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);
}
}

View File

@ -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,Map<String,String>model) throws Exception{
try{
//获取模板配置
BizObject templateConfig=this.getTemplateConfigByNo(templateNo);
if(templateConfig==null){
throw new BusinessException("根据模板编号"+templateNo+"没有找到模板");
}
//根据模板号和前台参数获取模板参数值
BaseParamService paramSer=new BaseParamService(tx);
//模板处理类
Class<BqCreateOfficeCallBackService> callback=null;
//获取模板处理类
if(templateConfig.getAttribute("callback").getString().length()>0){
try{
callback=(Class<BqCreateOfficeCallBackService>) 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<BqCreateOfficeCallBackService>) Class.forName("com.tenwa.makeContract.util.BqBaseWordCallBackServiceImpl");
}else if(templateConfig.getAttribute("templatetype").getString().equals("excel")){//excel 默认模板处理类
callback=(Class<BqCreateOfficeCallBackService>) 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<Map<String,String>> creatParam=this.getCreateTempalteParm(templateConfig, model);
if(creatParam==null)//创建条件是空 默认创建一个文件
{ Map<String,String> paramMap=new HashMap<String, String>();
Map<String,String> 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<String,String> map=new HashMap<String, String>();
for(int i=0;i<creatParam.size();i++){
map.clear();
map.putAll(model);
map.putAll(creatParam.get(i));
//Map<String,String> 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<Map<String,String>> getCreateTempalteParm(BizObject templateConfig,Map<String,String> model) throws Exception{
//获取创建条件
String sql=templateConfig.getAttribute("CreateCondition").getString();
if(null==sql||sql.length()>10)
{
List<Map<String,String>> params=new ArrayList<Map<String,String>>();
if(sql.indexOf(".xml")>0)//创建条件是xml 获取xml中的sql
{
String xmlPath=ARE.getProperty("PRD_HOME").replace("/WEB-INF", "")+sql;
Map<String,String> xmlfile=XMLDataUtil.readTableInfoFromXmlFile(xmlPath);
sql=xmlfile.get("table_sql");
}
Map<String,String>paramMap=new HashMap<String,String>();
//替换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<String,String> dataMap=FileOperatorUtil.getASResultSetToMap(rs);
params.add(dataMap);
}
if(params.size()==0)
{
logger.info("模板"+templateConfig.getAttribute("templatename").getString()+"根据创建条件未生成文档");
}
return params;
}
else
{
return null;
}
}
}

View File

@ -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<String> message=new ArrayList<String>();
//生成参数
//String sTemplateParam=this.getTemplateParam().replaceAll("@", ",");
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)+"未找到模板配置!");
}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<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转换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<String, ContractSignInfo> map = new HashMap<String, ContractSignInfo>();
ContractSignInfo con = null;
List<BizObject> 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<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()) {
// 存储契约锁返回的合同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<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");
}
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;
}
/**
* 北汽合同变更方法
* @throws Exception
*/
public void BqChangecontract(String contractId,JBOTransaction tx) throws Exception{
//删除之前生成的文件
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);
}
}
}

View File

@ -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{
/**
* 合同发起时的参数
* 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<String,String> fromCondition=new HashMap<String, String>();
fromCondition.put("PROJECT_ID", projid);
List<BizObject> list=DataOperatorUtil.getSetJBO(LC_PROJ_CONDITION.CLASS_NAME, fromCondition, tx);
Map<String,String> otherProperty=new HashMap<String, String>();
Map<String,String> toCondition=new HashMap<String, String>();
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<BizObject> boLRPTs = JBOFactory.getBizObjectManager(LC_PROJ_RENT_PLAN.CLASS_NAME,tx)
.createQuery("PROJECT_ID='"+projid+"' order by plan_list").getResultList(false);
List<String> dateList = getDateList(boLRPTs);
//按日计算手续费分摊
List<Map<String,BigDecimal>> 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<String> getDateList(List<BizObject> bos) throws JBOException{
List<String> dateList = new ArrayList<String>();
for(BizObject bo:bos){
dateList.add(bo.getAttribute("PLAN_DATE").getString());
}
return dateList;
}
public static List<Map<String,BigDecimal>> gethandMoneyList(String handMoney,List<String> dateList,String startDate,String period_type,String incomeNumberyear){
List<Map<String,BigDecimal>> handMoneyList=new ArrayList<Map<String,BigDecimal>>();
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<dateList.size();i++){
Map<String,BigDecimal> hand = new HashMap<String,BigDecimal>();
BigDecimal mon=BigDecimal.ZERO;
BigDecimal ratio=BigDecimal.ZERO;
long dateDiff=DateTools.getDateDiff(dateList.get(i), startDate);
if(i<dateList.size()-1){
BigDecimal cur=new BigDecimal(dateDiff);
ratio=cur.divide(all,Scale.GENERAL_RATE,BigDecimal.ROUND_HALF_UP);
mon=hmoney.multiply(cur).divide(all,Scale.CORPUS_SCALE,BigDecimal.ROUND_HALF_UP);
money=money.add(mon);
}else{
mon=hmoney.subtract(money);
if(hmoney.compareTo(BigDecimal.ZERO) != 0){
ratio=mon.divide(hmoney,Scale.GENERAL_RATE,BigDecimal.ROUND_HALF_UP);
}
}
hand.put("ratio", ratio);
hand.put("money", mon);
handMoneyList.add(hand);
startDate=dateList.get(i);
}
}catch (Exception e) {
e.printStackTrace();
}
return handMoneyList;
}
}