重构一下

This commit is contained in:
zhulh 2019-08-23 11:11:13 +08:00
parent ba23be23ec
commit 7e34391848
2 changed files with 134 additions and 82 deletions

View File

@ -1,6 +1,7 @@
package com.tenwa.comm.util.jboutil;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -29,8 +30,8 @@ import com.tenwa.officetempalte.util.FileOperatorUtil;
public class DataOperatorUtil {
/**
* 从A表拷贝单条记录到B表到返回B中的id字段
* @param fromClassName A表 .class
* @param fromCondtion A表中的查询条件
* @param fromClassName A表 .class
* @param fromCondtion A表中的查询条件
* @param toClassName B表 .class
* @param toCondtion B表中的查询条件
* @param otherProperty 追加到B中的其他属性Map类属性
@ -43,7 +44,7 @@ public class DataOperatorUtil {
BizObjectManager bmToObject = JBOFactory.getBizObjectManager(toClassName);
tx.join(bmFromObject);
tx.join(bmToObject);
// 源JBO
BizObject fromObject = null;
// 目标JBO
@ -59,8 +60,8 @@ public class DataOperatorUtil {
}
toObject = bqDest.getSingleResult(true);// 目标JBO需要做更新操作
if (null == toObject) {
toObject = bmToObject.newObject();
}
toObject = bmToObject.newObject();
}
}
String querySql = getQuerySql(fromCondtion);
BizObjectQuery bqDest = bmFromObject.createQuery(querySql);
@ -72,7 +73,7 @@ public class DataOperatorUtil {
return "";
}else{
//进行对象拷贝
coptyJBOPropertyNoKey(fromObject,toObject);
coptyJBOPropertyNoKey(fromObject,toObject);
if(null!=otherProperty){
for (String key : otherProperty.keySet()) {
toObject.setAttributeValue(key, otherProperty.get(key));
@ -90,13 +91,13 @@ public class DataOperatorUtil {
bmToObject.saveObject(toObject);
return toObject.getAttribute(toObject.getKey().getAttribute(0).getName()).toString();
}
}
/**
* 从A表拷贝单条记录到B表到返回B中的id字段
* @param fromClassName A表 .class
* @param fromCondtion A表中的查询条件
* @param fromClassName A表 .class
* @param fromCondtion A表中的查询条件
* @param toClassName B表 .class
* @param toCondtion B表中的查询条件
* @param otherProperty 追加到B中的其他属性Map类属性
@ -109,7 +110,7 @@ public class DataOperatorUtil {
BizObjectManager bmToObject = JBOFactory.getBizObjectManager(toClassName);
tx.join(bmFromObject);
tx.join(bmToObject);
// 源JBO
BizObject fromObject = null;
// 目标JBO
@ -126,8 +127,8 @@ public class DataOperatorUtil {
toObject = bqDest.getSingleResult(true);// 目标JBO需要做更新操作
if (null == toObject) {
toObject = bmToObject.newObject();
}
}
}
String querySql = getQuerySql(fromCondtion);
BizObjectQuery bqDest = bmFromObject.createQuery(querySql);
@ -148,23 +149,23 @@ public class DataOperatorUtil {
bmToObject.saveObject(toObject);
return toObject.getAttribute(toObject.getKey().getAttribute(0).getName()).toString();
}
}
public static void copyJBOSetByProduct(String fromClassName,Map<String, String> fromCondtion, String toClassName,Map<String, String> toCondtion,
Map<String,String>otherProperty,JBOTransaction tx)throws JBOException, RecordNotFoundException,Exception {
Map<String,String>otherProperty,JBOTransaction tx)throws JBOException, RecordNotFoundException,Exception {
//删除源数据
if(null!=toCondtion&&toCondtion.keySet().size()>0){
deleteJBOByCondtion(toClassName,toCondtion,tx);
}
TenwaALSBizObjectManager bom=(TenwaALSBizObjectManager)JBOFactory.getBizObjectManager(toClassName,tx);
String insertSql=getJBOCopyBatchSql(fromClassName,fromCondtion,toClassName, otherProperty,bom, tx);
bom.saveBatchObjectBySQL(insertSql, fromCondtion);
}
}
public static String getJBOCopyBatchSql(String fromClassName,Map<String, String> fromCondtion, String toClassName, Map<String,String>other,TenwaALSBizObjectManager bom,JBOTransaction tx)throws JBOException, RecordNotFoundException,Exception {
Map<String,String> otherProperty=new HashMap<String, String>();
if(other!=null){
otherProperty.putAll(other);
@ -187,7 +188,7 @@ public class DataOperatorUtil {
if(sExceludeColumn.length()>0){sExceludeColumn+=",";}
sExceludeColumn+="''"+key+"''";
}
String otherPropertyColumn=otherProperty.keySet().toString().replace("[", "").replace("]", "");
String otherPropertyValue="";
for(String key:otherProperty.keySet()){
@ -207,7 +208,7 @@ public class DataOperatorUtil {
sql="select B.COLUMN_NAME TALBECOLUMN from user_tab_columns B WHERE B.table_name='"+fromTable+"' AND EXISTS(SELECT 1 FROM user_tab_columns A WHERE A.table_name='"+toTable+"' AND B.column_name=A.column_name )";
}
TenwaALSBizObjectManager bomt=(TenwaALSBizObjectManager)JBOFactory.getBizObjectManager(fromClassName,tx);
List<JSONObject> rs=bomt.QueryResultBySQL(sql, null);
StringBuffer columns=new StringBuffer();
if(rs.size()==0){throw new Exception("没有找到对应的表数据");}
@ -220,7 +221,7 @@ public class DataOperatorUtil {
columns.append(",");
}
columns.append(tempColumn);
}
}
String insertSql="insert into "+toTable+" ("+columns.toString()+","+otherPropertyColumn+") select "+columns.toString() +","+otherPropertyValue+" from "+fromTable;
@ -231,7 +232,7 @@ public class DataOperatorUtil {
/**
* 从A表拷贝多条记录到B表到返回拷贝到B之后结果集
* 先更新插入然后删除B中多于的字段
* @param fromClassName A表 .class
* @param fromClassName A表 .class
* @param fromCondtion A表中的查询条件 Map类属性
* @param toClassName B表 .class
* @param toCondtion B表中的查询条件Map类属性
@ -255,7 +256,7 @@ public class DataOperatorUtil {
tx.join(bmToObject);
String querySql = getQuerySql(fromCondtion);
BizObjectQuery frombqDest = bmFromObject.createQuery(querySql);
for (String key : fromCondtion.keySet()) {
if(fromCondtion.get(key).length()>0){
frombqDest.setParameter(key, fromCondtion.get(key).toString());
@ -263,7 +264,7 @@ public class DataOperatorUtil {
}
List<BizObject> bofromList=frombqDest.getResultList(true);
List<BizObject> botoList=new ArrayList<BizObject>();
if(null!=toCondtion&&toCondtion.keySet().size()>0){
querySql = getQuerySql(toCondtion);
BizObjectQuery bqDest = bmToObject.createQuery(querySql);
@ -280,7 +281,7 @@ public class DataOperatorUtil {
}
}
if(bofromList==null || bofromList.size()==0){
}else{
//进行对象拷贝,循环处理源JBO列表
for (int i=0;i<bofromList.size();i++) {
@ -290,7 +291,7 @@ public class DataOperatorUtil {
if(objectCompare.ObjectCompare(bofromList.get(i),botoList.get(j))){
toObject=botoList.get(j);
botoList.remove(j);
break;
break;
}
}
}
@ -307,17 +308,17 @@ public class DataOperatorUtil {
}
if(botoList.size()>0){
for(int m=0;m<botoList.size();m++){
bmToObject.deleteObject(botoList.get(m));
bmToObject.deleteObject(botoList.get(m));
}
}
}
return blist;
}
}
}
/**
* 从A表中查出单条记录
* @param className A表 .class
* @param searchCondtion A表中的查询条件 Map类属性
* @param className A表 .class
* @param searchCondtion A表中的查询条件 Map类属性
* @param tx
* @return 返回单条记录
* @throws JBOException
@ -336,12 +337,12 @@ public class DataOperatorUtil {
return Object;
}
/**
* 根据SQL语句查出A表单条记录
* 根据SQL语句查出A表单条记录
* @param sql
* SELECT sum(fact_money) as v.factmoneys, sum(fee_adjust) as v.feeadjusts FROM O WHERE contract_id=:contract_id AND fee_type=:fee_type
* @param className A表 .class
* @param searchCondtion 查询条件 Map占位符
* @param tx
* @param className A表 .class
* @param searchCondtion 查询条件 Map占位符
* @param tx
* @return
* @throws JBOException
* @throws RecordNotFoundException
@ -356,7 +357,7 @@ public class DataOperatorUtil {
return boTemp;
}
/**
* 根据SQL语句查出A表多条记录
* 根据SQL语句查出A表多条记录
* @param sql
* @param className
* @param searchCondtion
@ -374,11 +375,11 @@ public class DataOperatorUtil {
List<BizObject> boTemp=null;
boTemp=bqDest.getResultList(false);
return boTemp;
}
}
/**
* 查询出A表中的一组数据
* @param className A表 .class
* @param searchCondtion A表中的查询条件 Map类属性
* @param className A表 .class
* @param searchCondtion A表中的查询条件 Map类属性
* @param tx
* @return 返回List
* @throws JBOException
@ -397,7 +398,7 @@ public class DataOperatorUtil {
return boSrcList;
}
/**
* 根据条件Map 返回 查询的条件
* 根据条件Map 返回 查询的条件
* @param Condtion
* @return
*/
@ -417,8 +418,8 @@ public class DataOperatorUtil {
}
/**
* 删除A中的多条记录
* @param className A表 .class
* @param condtion A表中的查询条件 Map类属性
* @param className A表 .class
* @param condtion A表中的查询条件 Map类属性
* @param tx
* @throws JBOException
*/
@ -434,8 +435,8 @@ public class DataOperatorUtil {
}
/**
* 删除A中的多条记录
* @param className A表 .class
* @param condtion A表中的查询条件 Map类属性
* @param className A表 .class
* @param condtion A表中的查询条件 Map类属性
* @param tx
* @throws JBOException
*/
@ -477,7 +478,7 @@ public class DataOperatorUtil {
if(bo.indexOfAttribute("InputOrgID")>0){
bo.setAttributeValue("InputOrgID", user.getOrgID());
}
}else{
if(bo.indexOfAttribute("UpdateUserID")>0){
bo.setAttributeValue("UpdateUserID",user.getUserID());
@ -488,27 +489,79 @@ public class DataOperatorUtil {
bo.setAttributeValue("UpdateOrgID", user.getOrgID());
}
}
}
}
}
public static List<Map<String,String>> getDataBySql(JBOTransaction tx,String sql,Map<String,String> params) throws Exception{
List<Map<String,String>> data=new ArrayList<Map<String,String>>();
Transaction Sqlca =null;
Sqlca = Transaction.createTransaction(tx);
ASResultSet rs = null;
SqlObject asql = new SqlObject(sql);
if(params!=null){
for(Map.Entry<String,String> entry:params.entrySet()){
asql.setParameter(entry.getKey(), entry.getValue());
}
}
rs = Sqlca.getASResultSet(asql);
while (rs.next()) {
data.add( FileOperatorUtil.getASResultSetToMap(rs));
// public static List<Map<String,String>> getDataBySql(JBOTransaction tx,String sql,Map<String,String> params) throws Exception{
// List<Map<String,String>> data=new ArrayList<Map<String,String>>();
// Transaction Sqlca =null;
// Sqlca = Transaction.createTransaction(tx);
// ASResultSet rs = null;
// SqlObject asql = new SqlObject(sql);
// if(params!=null){
// for(Map.Entry<String,String> entry:params.entrySet()){
// asql.setParameter(entry.getKey(), entry.getValue());
// }
// }
// rs = Sqlca.getASResultSet(asql);
// while (rs.next()) {
// data.add( FileOperatorUtil.getASResultSetToMap(rs));
// }
// return data;
// }
/**
* 重写逗比getDataBySql方法如果需要相同事务则取事务对象读取信息
* 如果没有则自行关闭事务
* @param tx
* @param sql
* @param params
* @return
* @throws Exception
*/
public static List<Map<String,String>> getDataBySql( JBOTransaction tx, String sql, Map<String,String> params ) throws Exception {
List<Map<String, String>> resultData = new ArrayList<>();
Boolean transFlag = false;
if ( tx == null ) {
transFlag = true;
tx = JBOFactory.createJBOTransaction();
}
return data;
Transaction trans = null;
ASResultSet rs = null;
try {
trans = Transaction.createTransaction( tx );
SqlObject sqlObject = new SqlObject( sql );
if ( params != null && !params.isEmpty() ) {
for ( Map.Entry<String, String> param : params.entrySet() ) {
sqlObject.setParameter( param.getKey(), param.getValue() );
}
}
rs = trans.getASResultSet( sqlObject );
while (rs.next() ) {
resultData.add( FileOperatorUtil.getASResultSetToMap( rs ) );
}
} catch ( Exception e ) {
e.printStackTrace();
throw e;
} finally {
if ( rs != null ) rs.close();
if ( transFlag && trans != null ) trans.disConnect();
}
return resultData;
}
/**
* 重构一个简便调用
* @param sql
* @param params
* @return
* @throws Exception
*/
public static List<Map<String,String>> getDataBySql( String sql, Map<String,String> params ) throws Exception {
return getDataBySql( null, sql, params );
}
}

View File

@ -42,7 +42,7 @@ import com.tenwa.officetempalte.util.FileOperatorUtil;
public class DocListInitAction {
/**
*
*
* @param param
* LB_DOCRELATIVE 表里的字段参数
* @param docno
@ -99,8 +99,8 @@ public class DocListInitAction {
List<BizObject> configList = configBm.createQuery(
"doc_Class_Itemno in (" + docno + ")").getResultList(false);
ARE.getLog().info("size:"+configList.size());
for (BizObject config : configList) {
BizObject lib = libBm
.createQuery("Relative_Id=:relaid and config_id=:configid")
@ -210,8 +210,8 @@ public class DocListInitAction {
List<BizObject> configList = configBm.createQuery(
"doc_Class_Itemno in (" + docno + ")").getResultList(false);
ARE.getLog().info("size:"+configList.size());
for (BizObject config : configList) {
BizObject lib = libBm
.createQuery("Relative_Id=:relaid and config_id=:configid")
@ -246,7 +246,7 @@ public class DocListInitAction {
BizObjectManager lmdBm = JBOFactory.getBizObjectManager(LM_MAILONLINE_DOC.CLASS_NAME);
BizObject lmdBo = lmdBm.createQuery("LIBRARYID='"+libid+"'").getSingleResult(false);
BizObject lmdtBo = lmdtBm.createQuery("LIBRARYID='"+libid+"' and flowunid = '"+param.get("flow_unid")+"'").getSingleResult(false);
if(lmdtBo==null){
if(lmdtBo==null){
if(lmdBo!=null){
Map<String,String> fromCondtion = new HashMap<String, String>();
Map<String,String>otherProperty=new HashMap<String, String>();
@ -308,7 +308,7 @@ public class DocListInitAction {
}
/**
* 获取关联的sql
*
*
* @param param
* @param docno
* @return
@ -339,7 +339,7 @@ public class DocListInitAction {
/**
* 获取要复制的附件 sql
*
*
* @param param
* @return
*/
@ -367,7 +367,7 @@ public class DocListInitAction {
}
/**
*
*
* @param lib
* 关联这个对象下的附件
* @param libid
@ -406,7 +406,7 @@ public class DocListInitAction {
/**
* 复制单个文件
*
*
* @param oldPath
* String 原文件路径 c:/fqf.txt
* @param newPath
@ -470,7 +470,7 @@ public class DocListInitAction {
/**
* 校验附件一览类型 附件一览分2种可上传类型 1与项目或合同绑定的附件多次发起流程将会累计附件 2与流程本身绑定仅在本次流程中可见
* 3与流程与项目合同都绑定在流程中只能看见本次上传的附件其它次附件在别处根据项目编号可查看
*
*
* @return
* @throws Exception
* @throws JBOException
@ -478,8 +478,7 @@ public class DocListInitAction {
public static String getDocType(String flowName) throws Exception {
String sql = "SELECT FLOWNO FROM flow_catalog WHERE flowname='"
+ flowName + "'";
List<Map<String, String>> ds = DataOperatorUtil.getDataBySql(
JBOFactory.createJBOTransaction(), sql, null);
List<Map<String, String>> ds = DataOperatorUtil.getDataBySql( sql, null);
String flowno = GetValueByKey("docpreview.properties",
ds.get(0).get("FLOWNO"));
// 根据要求拖车申请是
@ -557,7 +556,7 @@ public class DocListInitAction {
}
}
}
}
}
if(boListLDR!=null){
String docClassItemnov= "";
for(BizObject bolr:boListLDR){
@ -595,18 +594,18 @@ public class DocListInitAction {
public static List<String> nextImageForMailDoc(String contract_id) throws Exception{
List<String> list = new ArrayList<String>();
String sql = "select lda.id attrid from lb_docrelative ldr left join lb_doclibrary ldl on ldl.RELATIVE_ID = ldr.id left join lb_docattribute lda on lda.LIBRARY_ID = ldl.ID where ldr.OBJECTTYPE = 'MortgageFileMailFlow' and contract_id = '"+contract_id+"' and lda.id is not null";
List<Map<String, String>> ds = DataOperatorUtil.getDataBySql(JBOFactory.createJBOTransaction(), sql, null);
List<Map<String, String>> ds = DataOperatorUtil.getDataBySql( sql, null );
for(Map<String, String> map:ds){
list.add(map.get("attrid"));
list.add(map.get("attrid"));
}
return list;
}
public static List<String> nextImageForMailHisDoc(String contract_id) throws Exception{
List<String> list = new ArrayList<String>();
String sql = "select lda.id attrid from lb_docrelative ldr left join lb_doclibrary ldl on ldl.RELATIVE_ID = ldr.id left join lb_docattribute lda on lda.LIBRARY_ID = ldl.ID where ldr.OBJECTTYPE IN ('BusinessApplyFlow','FundPaymentCarFlow','MortgageFileFlow') and proj_id = '"+contract_id+"' and lda.id is not null";
List<Map<String, String>> ds = DataOperatorUtil.getDataBySql(JBOFactory.createJBOTransaction(), sql, null);
List<Map<String, String>> ds = DataOperatorUtil.getDataBySql( sql, null );
for(Map<String, String> map:ds){
list.add(map.get("attrid"));
list.add(map.get("attrid"));
}
return list;
}