2019-08-09 18:46:16 +08:00

278 lines
11 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.app.baseFileTemplate.handle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jbo.app.tenwa.doc.LB_DOCRELATIVE;
import jbo.app.tenwa.doc.LB_DOC_CONTRACT_LIST;
import jbo.com.tenwa.entity.comm.officetempalte.BF_TEMPLATE;
import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO;
import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO_TEMP;
import jbo.com.tenwa.lease.comm.LB_CONTRACT_TEMPLATE;
import jbo.com.tenwa.lease.comm.LB_EQUIPMENT_CAR_TEMP;
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.util.ASResultSet;
import com.amarsoft.awe.util.SqlObject;
import com.amarsoft.awe.util.Transaction;
import com.amarsoft.dict.als.manage.NameManager;
import com.tenwa.comm.exception.BusinessException;
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
import com.tenwa.doc.action.DocListAction;
import com.tenwa.officetempalte.service.CreateOfficeService;
import com.tenwa.officetempalte.util.FileOperatorUtil;
import com.tenwa.reckon.util.UUIDUtil;
public class FileTemplateUtil {
public String templateCalss;//模板文件分类
public String templateNo;//模板编号
public String templateParam; //模板参数
public String templateIds;//要生成的合同模板
public String flowunid;//用于查询已经生成的合同
public String leasform;//用判断租赁方式
public String contractId;
public String contractNo;
public String isNetCar;//用于判断是否是网约车
public String operationType;//用于判断是否是北汽产品
public String getTemplateCalss() {return templateCalss;}
public void setTemplateCalss(String templateCalss) {this.templateCalss = templateCalss;}
public String getTemplateNo() {
return templateNo;
}
public void setTemplateNo(String templateNo) {
this.templateNo = templateNo;
}
public String getTemplateParam() {
return templateParam;
}
public void setTemplateParam(String templateParam) {
this.templateParam = templateParam;
}
public String getTemplateIds() {
return templateIds;
}
public void setTemplateIds(String templateIds) {
this.templateIds = templateIds;
}
public String getFlowunid() {
return flowunid;
}
public void setFlowunid(String flowunid) {
this.flowunid = flowunid;
}
public String getLeasform() {
return leasform;
}
public void setLeasform(String leasform) {
this.leasform = leasform;
}
public String getContractId() {
return contractId;
}
public void setContractId(String contractId) {
this.contractId = contractId;
}
public String getIsNetCar() {
return isNetCar;
}
public void setIsNetCar(String isNetCar) {
this.isNetCar = isNetCar;
}
public String getContractNo() {
return contractNo;
}
public void setContractNo(String contractNo) {
this.contractNo = contractNo;
}
public String getOperationType() {
return operationType;
}
public void setOperationType(String operationType) {
this.operationType = operationType;
}
public String getTemplateClass(Transaction Sqlca) throws Exception{
String fileClass=templateCalss.replaceAll("@", ",");
List<String>tempFiles=new ArrayList<String>();
JSONObject classJson=JSONDecoder.decode(fileClass);
Map<String,String>sercharMap=FileOperatorUtil.getJsonObjectToMap(classJson);
String ONECLASSIFY=sercharMap.get("oneclassify");
if (ONECLASSIFY==null || ONECLASSIFY.length()<=0){
sercharMap.put("ONECLASSIFY", "invalid");// 在此人为加上该标记,以防一级分类没有选择的情况下加载所有模板,而导致不同产品之间可以相互生成合同
}
Map<String,String> sercharMapD=new HashMap<String,String>();
String value=null;
for(String key:sercharMap.keySet()){
value=sercharMap.get(key);
if(value !=null && value.length()>0){
sercharMapD.put(key, value);
}
}
String sql="SELECT id,TEMPLATENAME FROM BF_TEMPLATE WHERE ";
sql=sql+DataOperatorUtil.getQuerySql(sercharMapD)+"";
ASResultSet rs = null;
SqlObject asql = new SqlObject(sql);
asql = new SqlObject(sql);
for(String key:sercharMapD.keySet()){
asql.setParameter(key, sercharMapD.get(key));
}
rs = Sqlca.getASResultSet(asql);
while (rs.next()){
tempFiles.add("{'text':'"+rs.getString("templatename")+"','value':'"+rs.getString("id")+"'}");
}
String sReturn="[{'fileTemplate':\""+tempFiles.toString()+"\"}]";
// String sReturn="[{'fileTemplate':\""+"[{'text':'融资租赁合同-C端回租','value':'641c55a1168f4a488a5028ee68870156'}]"+"\"}]";
return sReturn;
}
public String getContractClass(Transaction Sqlca){
if("BAIC_MOTOR".equals(operationType)){//北汽财务
if("01".equals(leasform)){
return "[{'fileTemplate':\""+"[{'text':'合同(直租)','value':'b20b919c6144480b9466e4ea9b0da142'}]"+"\"}]";
}else{
return "[{'fileTemplate':\""+"[{'text':'合同(售后回租)','value':'115905186577406ea5414dd14e592e7d'}]"+"\"}]";
}
}else if ("DYCD".equals(operationType)){//第一车贷
return "[{'fileTemplate':\""+"[{'text':'合同(售后回租)','value':'8d4232a5423e491ca905e77c54105a85'}]"+"\"}]";
}else if ("ZYC".equals(operationType)){//专用车产品
return "[{'fileTemplate':\""+"[{'text':'合同(售后回租)','value':'35aab6dbac5f4ba292cd67a0914eae2e'}]"+"\"}]";
}else if ("KJZL".equals(operationType)){//凯捷租赁
return "[{'fileTemplate':\""+"[{'text':'合同售后回租_凯捷','value':'a4fcbd2990d1479a9ba8ce440155f2f0'}]"+"\"}]";
}else if ("BZZL".equals(operationType)){//保值租赁
return "[{'fileTemplate':\""+"[{'text':'保值租赁','value':'91c7718aa925428ca312e343d1f5149f'}]"+"\"}]";
}else if ("WYC".equals(operationType)){//网约车
return "[{'fileTemplate':\""+"[{'text':'合同(售后回租)和抵押合同','value':'c8d5b729a0954482877c26a1293b766b'}]"+"\"}]";
}else{
if("01".equals(leasform)){
return "[{'fileTemplate':\""+"[{'text':'合同(直租)','value':'24aba365e2794a018814ae81341486bf'}]"+"\"}]";
}else{
return "[{'fileTemplate':\""+"[{'text':'合同(售后回租)','value':'641c55a1168f4a488a5028ee68870156'}]"+"\"}]";
}
}
}
public String createContractTemplate(JBOTransaction tx) throws Exception{
List<String> message=new ArrayList<String>();
String[] tempids=this.getTemplateIds().split("&");
//生成参数
String sTemplateParam=this.getTemplateParam().replaceAll("@", ",");
JSONObject paramJson=JSONDecoder.decode(sTemplateParam);
Map<String,String>sourceMap=FileOperatorUtil.getJsonObjectToMap(paramJson);
CreateOfficeService officeSer=new CreateOfficeService(tx);
for(int i=0;i<tempids.length;i++){
BizObjectManager bmbt = JBOFactory.getBizObjectManager(BF_TEMPLATE.CLASS_NAME);
tx.join(bmbt);
BizObject bobt=bmbt.createQuery("id=:id").setParameter("id",tempids[i]).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", tempids[i]).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());
}
}
}
tx.commit();
return message.toString();
}
public String CheckCar(JBOTransaction tx) throws Exception{
String message = "";
BizObjectManager lrct = JBOFactory.getBizObjectManager(LB_EQUIPMENT_CAR_TEMP.CLASS_NAME);
BizObject lrc = lrct.createQuery("FLOWUNID=:flowunid").setParameter("flowunid", flowunid).getSingleResult(false);
if(lrc!= null){
int length = lrc.getAttribute("FRAME_NUMBER").toString().length();
if(lrc.getAttribute("FRAME_NUMBER").toString().length()==0){
message = "车架号、";
}
if(lrc.getAttribute("CAR_COLOUR").toString().length()==0){
message = message+"车辆颜色、";
}
if(lrc.getAttribute("ENGINE_NUMBER").toString().length()==0){
message = message+ "发动机号、";
}
/*if("DYCD".equals(operationType)&&lrc.getAttribute("MEMO").toString().length()==0){
message = message+ "其他配置说明、";
}*/
}
if(message.length()>0){
return "请先填写:"+message.substring(0,message.length() - 1)+"!";
}
String docName="";
String[] bfids = templateIds.split("&");
BizObjectManager btManager = JBOFactory.getBizObjectManager(BF_TEMPLATE.CLASS_NAME);
BizObjectManager ldclManager = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME);
List<BizObject> ldcls = ldclManager.createQuery("select * from O where file_flag='yes' and ( flow_unid=:flowunid or contract_id=:contractid ) ").setParameter("flowunid", flowunid).setParameter("contractid", contractId).getResultList(false);
for(int i=0;i<bfids.length;i++){
BizObject templatename = btManager.createQuery("select templatename from O where id=:id").setParameter("id", bfids[i]).getSingleResult(false);
for(BizObject ldcl:ldcls){
if((templatename.getAttribute("templatename").toString()).equals(ldcl.getAttribute("doc_name").getString())){
docName=docName+templatename.getAttribute("templatename").toString()+";";
}
}
}
if(docName.length()>0){
docName=docName+"已存在,请先删除后再生成!";
}
tx.commit();
return docName;
}
public String CheckContractNo(JBOTransaction tx) throws Exception{
BizObjectManager lciManager = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME);
BizObjectManager lciTManager = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO_TEMP.CLASS_NAME);
BizObject lci = lciManager.createQuery("contract_no=:contractNo").setParameter("contractNo", contractNo).getSingleResult(false);
BizObject lcit = lciTManager.createQuery("contract_no=:contractNo").setParameter("contractNo", contractNo).getSingleResult(false);
if(lci==null){
if(lcit!=null&&lcit.getAttribute("id").getString().equals(contractId)){
return "success";
}else{
return "error";
}
}else{
return "error";
}
}
}