更新北汽接口方法

This commit is contained in:
tangft 2018-12-29 11:36:03 +08:00
parent 72c0e6f998
commit 194a77a851
3 changed files with 168 additions and 184 deletions

View File

@ -16,6 +16,7 @@ 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.BizObjectKey;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.JBOException;
import com.amarsoft.are.jbo.JBOFactory;
@ -66,6 +67,7 @@ public class McontractServiceImpl implements McontractService{
ReturnMessage rMage = new ReturnMessage();
MakeOneCodeAndContractModel modc = new MakeOneCodeAndContractModel();
String projectId=null;
String tempid="";//模板id
String sTemplateParam="{'CurUserId':'8006U00000003','CurOrgId':'8006003'";//生成word需要的参数
JBOTransaction tx = null;
@ -119,7 +121,7 @@ public class McontractServiceImpl implements McontractService{
String contractId = java.util.UUID.randomUUID().toString().replaceAll("-", "");//生成合同ID
Transaction Sqlca =null;
Sqlca = Transaction.createTransaction(tx);
String projectId = lpi.getAttribute("ID").getString();
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;
@ -174,6 +176,11 @@ public class McontractServiceImpl implements McontractService{
} catch (Exception e) {
try {
tx.rollback();
JBOTransaction back =JBOFactory.createJBOTransaction();
BizObjectManager lcibom = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME,back);
BizObject lci = lcibom.createQuery("project_id=:projectid").setParameter("projectid", projectId).getSingleResult(true);
lcibom.deleteObject(lci);
back.commit();
} catch (JBOException e1) {
e1.printStackTrace();
}

View File

@ -84,11 +84,7 @@ public class MakeOneCodeAndContractModel {
localJBarcode.setShowCheckDigit(false);
BufferedImage localBufferedImage = null;
try {
localBufferedImage = localJBarcode.createBarcode(contractNo);
} catch (InvalidAtributeException e) {
e.printStackTrace();
}
localBufferedImage = localJBarcode.createBarcode(contractNo);
//获取当前时间根据时间创建一维码存放的路径
Calendar now = Calendar.getInstance();
String path = now.get(Calendar.YEAR)+"//"+(now.get(Calendar.MONTH) + 1) + "//"+now.get(Calendar.DAY_OF_MONTH);
@ -98,11 +94,7 @@ public class MakeOneCodeAndContractModel {
}
path=path+"//"+contractId+".jpg";
OutputStream jos = null;
try {
jos = new FileOutputStream(diskPath+path);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
jos = new FileOutputStream(diskPath+path);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(jos);
JPEGEncodeParam jpegEP = JPEGCodec.getDefaultJPEGEncodeParam(localBufferedImage);
jpegEP.setQuality((float) 1, true);
@ -178,95 +170,86 @@ public class MakeOneCodeAndContractModel {
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());
sourceMap.put("TEMPLATE_ID", id);
BizObject rela=JBOFactory.createBizObjectQuery(LB_DOCRELATIVE.CLASS_NAME,"TEMPLATE_ID=:tempid").setParameter("tempid", tempid).getSingleResult(false);
if(rela!=null){
DocListAction doc=new DocListAction();
doc.setRelativeId(rela.getAttribute("id").getString());
doc.deleteRelative(tx);
}
officeSer.createOfficeByTemplateNo(bobt.getAttribute("id").getString(), sourceMap);
}
}
return message.toString();
}
//word转pdf
public String wordTopdf(String projectId,String contractId,JBOTransaction tx){
public String wordTopdf(String projectId,String contractId,JBOTransaction tx) throws Exception{
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());
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);
}
}
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;
}
@ -340,104 +323,98 @@ public class MakeOneCodeAndContractModel {
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);
// 查询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("要读取的文件不存在");
}
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);
}
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);
}
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";
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);
}
}
} catch (Exception e) {
tx.rollback();
e.printStackTrace();
logger.info("法人客户生成合同盖章失败" + e.getMessage());
return "flase@error";
// 判断不同的异常反馈给前端
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";
}
}
}