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

137 lines
6.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

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

package com.tenwa.makeContract.util;
import java.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);
}
}