package com.vci.server.omd.biztype.service;
|
|
import org.dom4j.Element;
|
import com.vci.corba.omd.btm.BTMService;
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.omd.attribpool.AttribItem;
|
import com.vci.common.log.ServerWithLog4j;
|
import com.vci.corba.common.VCIError;
|
import com.vci.omd.utils.OmdTools;
|
import com.vci.server.cache.OMCacheProvider;
|
import com.vci.server.omd.btm.BTMServiceImpl;
|
import com.vci.server.omd.btm.resource.BtmTool;
|
|
|
/**
|
* 对外部提供业务类型的属性列表
|
* 获取属性的数据类型, 属性: 系统属性, 属性池属性
|
*
|
*/
|
public class BtmHelper {
|
private static BTMService btmService = null;
|
|
|
/**
|
* 业务类型的系统属性
|
*/
|
private static String otherFieldBt = "\n\tOID VARCHAR2(36) not null," +
|
"\n\tREVISIONOID VARCHAR2(36),\n\tNAMEOID VARCHAR2(36),\n\tBtmName VARCHAR2(36)," +
|
"\n\tISLastR CHAR(1),\n\tISFirstR CHAR(1),\n\tISLastV CHAR(1),\n\tISFirstV CHAR(1)," +
|
"\n\tCreator VARCHAR2(36)," +
|
"\n\tCreateTime TIMESTAMP,\n\tLastModifier VARCHAR2(36),\n\tLastModifyTime TIMESTAMP," +
|
"\n\tRevisionRule VARCHAR2(36),\n\tVersionRule VARCHAR2(36),\n\tRevisionSeq NUMBER," +
|
"\n\tRevisionValue VARCHAR2(10),\n\tVersionSeq NUMBER,\n\tVersionValue VARCHAR2(10)," +
|
"\n\tLCTID VARCHAR2(36),\n\tLCStatus VARCHAR2(36),\n\tTS TIMESTAMP," +
|
"\n\tID VARCHAR2(36),\n\tNAME VARCHAR2(128),\n\tDESCRIPTION VARCHAR2(255)," +
|
"\n\tOWNER VARCHAR2(36),\n\tCHECKINBY VARCHAR2(36),\n\tCHECKINTIME TIMESTAMP," +
|
"\n\tCHECKOUTBY VARCHAR2(36),\n\tCHECKOUTTIME TIMESTAMP,\n\tCOPYFROMVERSION VARCHAR2(36),\n\t";
|
|
|
|
private BtmHelper(){
|
}
|
|
|
private static BTMService getService(){
|
try {
|
if (btmService == null) {
|
btmService = new BTMServiceImpl();
|
}
|
|
if (btmService == null)
|
{
|
ServerWithLog4j.logger.error("BtmProvider.getService, 获取【btmService】失败");
|
}
|
|
return btmService;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return btmService;
|
}
|
|
|
|
|
|
/**
|
* 获取属性other中type的值
|
* @param other
|
* @param type
|
* @return
|
*/
|
// public static String getOtherValueByType(String other, String type){
|
// String[] otherArray = other.split(";");
|
// for(int i = 0; i < otherArray.length; i++){
|
// String otherValue = otherArray[i];
|
// if(otherValue.contains(type)){
|
// return otherValue.substring(otherValue.indexOf("=") + 2, otherValue.length());
|
// }
|
// }
|
// return null;
|
//
|
// }
|
|
/**
|
* 获取属性字段的sql语句
|
* @param array
|
* @return
|
*/
|
// public static String getAbSql(AttribItem abItem){
|
// String sql = "";
|
// if(abItem == null){
|
// return sql;
|
// }
|
// String abName = abItem.name;
|
// String vtType = abItem.vtDataType;
|
// String other = abItem.other;
|
// String defValue = abItem.defValue;
|
//
|
// if(vtType.equals("VTString")){
|
// int length = 50;
|
// String lengthStr = AttributeHelper.getOtherValueByType(other, "length");
|
// if(lengthStr != null && !lengthStr.equals("")){
|
// length = Integer.valueOf(lengthStr);
|
// }
|
// sql += abName.toUpperCase() + " VARCHAR2(" + length + ")";
|
// if(!defValue.equals("")){
|
// sql += " default '" + defValue + "'";
|
// }
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTInteger") || vtType.equals("VTLong")){
|
// sql += abName.toUpperCase() + " NUMBER";
|
// if(!defValue.equals("")){
|
// sql += " default " + defValue;
|
// }
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTDouble")){
|
// int length = 20;
|
// String lengthStr = AttributeHelper.getOtherValueByType(other, "length");
|
// if(lengthStr != null && !lengthStr.equals("")){
|
// length = Integer.valueOf(lengthStr);
|
// }
|
//
|
// int accuracy = 2;
|
// String accuracyStr = AttributeHelper.getOtherValueByType(other, "accuracy");
|
// if(accuracyStr != null && !accuracyStr.equals("")){
|
// accuracy = Integer.valueOf(accuracyStr);
|
// }
|
// sql += abName.toUpperCase() + " NUMBER(" + length + ", " + accuracy +")";
|
// if(!defValue.equals("")){
|
// sql += " default " + defValue;
|
// }
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTBoolean")){
|
// sql += abName.toUpperCase() + " VARCHAR2(8)";
|
// if(!defValue.equals("")){
|
// sql += " default '" + defValue + "'";
|
// }
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTImage")){
|
// sql += abName.toUpperCase() + " VARCHAR2(255)";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTDate")){
|
// sql += abName.toUpperCase() + " DATE";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTTime")){
|
// sql += abName.toUpperCase() + " TIMESTAMP";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTDateTime")){
|
// sql += abName.toUpperCase() + " TIMESTAMP";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTNote")){
|
// sql += abName.toUpperCase() + " VARCHAR2(255)";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTFilePath")){
|
// sql += abName.toUpperCase() + " VARCHAR2(255)";
|
// sql += ",\n\t";
|
// }else if(vtType.equals("VTClob")){
|
// sql += abName.toUpperCase() + " CLOB";
|
// sql += ",\n\t";
|
// }
|
//
|
// return sql;
|
// }
|
|
/**
|
* 生成创建业务类型的DDL
|
* @param btm
|
* @return
|
*/
|
public static String getCreateBTMTableSql(BtmItem btm){
|
String btmName = btm.name;
|
String btmTableName = OmdTools.getBTMTableName(btmName);
|
String sql = "create Table " + btmTableName + "(" + otherFieldBt;
|
String[] apNames = null;
|
try {
|
apNames = getService().getBtmApNameArray(btmName, null);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
if(apNames != null && apNames.length != 0){
|
for(int k = 0; k < apNames.length; k++){
|
String abName = apNames[k];
|
AttribItem abItem = null;
|
|
abItem = OMCacheProvider.getAttribute(abName);
|
|
String abSql = BtmTool.getInstance().getAbSql(abItem);
|
sql += abSql;
|
}
|
}
|
|
sql = sql.substring(0, sql.lastIndexOf(","));
|
sql += "\n)";
|
return sql;
|
}
|
/**
|
* 将业务类型树导出为.sql文件
|
* add by caill 2015.12.21
|
* */
|
// public boolean expBtmDataSql(String dir, BtmItem[] allBtmItems) throws VCIError {
|
// new File(dir).mkdir();
|
// File file = new File(dir + "/platformBtm.sql");
|
// FileWriter w = null;;
|
// BufferedWriter bw = null;
|
// try {
|
// w = new FileWriter(file);
|
// bw = new BufferedWriter(w);
|
// } catch (IOException e) {
|
// // TODO Auto-generated catch block
|
// e.printStackTrace();
|
// }
|
//
|
// for(int i = 0; i < allBtmItems.length; i++){
|
// String sql = getBTMTableSqlByName(allBtmItems[i]);
|
// try {
|
// bw.write(sql);
|
// bw.write("\r\n");
|
// } catch (IOException e) {
|
// // TODO Auto-generated catch block
|
// e.printStackTrace();
|
// }
|
// }
|
// try {
|
// bw.flush();
|
// bw.close();
|
// return true;
|
// } catch (IOException e) {
|
// // TODO Auto-generated catch block
|
// e.printStackTrace();
|
// }
|
//
|
//
|
// return false;
|
// }
|
|
/**
|
* 生成业务类型导出为.sql文件的sql语句 add by caill 2015.12.21
|
* @param btm
|
* @return
|
*/
|
// public String getBTMTableSqlByName(BtmItem allBtmItem){
|
// String btmTableName = OmdTools.getBTMTableName(allBtmItem.name);
|
// String sql = "create Table " + btmTableName + "(" + otherFieldBt;
|
// String[] apNames = null;
|
// try {
|
// apNames = getService().getBtmApNameArray(allBtmItem.name, null);
|
// } catch (VCIError e) {
|
// e.printStackTrace();
|
// }
|
// if(apNames != null && apNames.length != 0){
|
// for(int k = 0; k < apNames.length; k++){
|
// String abName = apNames[k];
|
// AttribItem abItem = null;
|
//
|
// abItem = OMCacheProvider.getAttribute(abName);
|
//
|
// String abSql = BtmTool.getInstance().getAbSql(abItem);
|
// sql += abSql;
|
// }
|
// }
|
//
|
// sql = sql.substring(0, sql.lastIndexOf(","));
|
// sql += "\n);";
|
// sql += "\r\ncomment on table "+btmTableName+" is '"+allBtmItem.label +"';"; //添加表注释
|
// if(apNames != null && apNames.length != 0){
|
// for(int k = 0; k < apNames.length; k++){
|
// String abName = apNames[k];
|
// AttribItem abItem = null;
|
//
|
// abItem = OMCacheProvider.getAttribute(abName);
|
//
|
// sql += "\r\ncomment on column "+btmTableName+"."+abItem.name+" is '"+ abItem.label +"';";
|
// }
|
// }
|
// return sql;
|
// }
|
|
/**
|
* 获取增加主键sql
|
* @param typeName
|
* @return
|
*/
|
public static String getAddPKSql(String typeName){
|
return "alter table " + OmdTools.getBTMTableName(typeName) + " add constraint PKBTM_" + typeName + " primary key (OID)\n";
|
}
|
|
/**
|
* Array-->List
|
* @param array
|
* @return
|
*/
|
// public List<String> parseArrayToList(String[] array){
|
// List<String> list = new ArrayList<String>();
|
// for(int i = 0; i < array.length; i++){
|
// list.add(array[i]);
|
// }
|
// return list;
|
// }
|
|
/**
|
* Array-->List
|
* @param array
|
* @return
|
*/
|
// public List<Integer> parseArrayToList(int[] array){
|
// List<Integer> list = new ArrayList<Integer>();
|
// for(int i = 0; i < array.length; i++){
|
// list.add(array[i]);
|
// }
|
// return list;
|
// }
|
|
/**
|
* Array-->String
|
* @param array
|
* @return
|
*/
|
public static String arrayTOString(String[] array){
|
String str = "";
|
if(array != null && array.length > 0){
|
for(int i = 0; i < array.length; i++){
|
str += array[i];
|
str += ",";
|
}
|
str = str.substring(0, str.lastIndexOf(","));
|
}
|
return str;
|
}
|
|
/**
|
* 将bt转化成xmltext
|
* @param o
|
* @return
|
*/
|
public static String getXmlText(BtmItem o){
|
String apNameArray = arrayTOString(o.apNameArray);
|
String lifeCycles = arrayTOString(o.lifeCycles);
|
StringBuilder stb = new StringBuilder("<btm>");
|
stb.append("<name>" + o.name + "</name>");
|
stb.append("<label>" + o.label + "</label>");
|
stb.append("<description>" + o.description + "</description>");
|
stb.append("<isAbstract>" + o.isAbstract + "</isAbstract>");
|
stb.append("<shape>" + o.shape + "</shape>");
|
stb.append("<implClass>" + o.implClass + "</implClass>");
|
stb.append("<fName>" + o.fName + "</fName>");
|
stb.append("<lifeCycle>" + o.lifeCycle + "</lifeCycle>");
|
stb.append("<imageName>" + o.imageName + "</imageName>");
|
stb.append("<revLevel>" + o.revLevel + "</revLevel>");
|
stb.append("<revRuleName>" + o.revRuleName + "</revRuleName>");
|
stb.append("<revInput>" + o.revInput + "</revInput>");
|
stb.append("<delimiter>" + o.delimiter + "</delimiter>");
|
stb.append("<verRuleName>" + o.verRuleName + "</verRuleName>");
|
stb.append("<apNameArray>" + apNameArray + "</apNameArray>");
|
stb.append("<lifeCycles>" + lifeCycles + "</lifeCycles>");
|
stb.append("</btm>");
|
return stb.toString();
|
}
|
|
/**
|
* 设置EnumItem存在
|
* @param att
|
* @param element
|
*/
|
public static void setBTValueFormDoc(BtmItem bt, Element element){
|
String value = element.elementText("isAbstract");
|
bt.isAbstract = (value == null ? false : Boolean.valueOf(value));
|
value = element.elementText("fName");
|
bt.fName = (value == null ? "" : value);
|
value = element.elementText("implClass");
|
bt.implClass = (value == null ? "" : value);
|
value = element.elementText("shape");
|
bt.shape = (value == null ? "" : value);
|
value = element.elementText("lifeCycle");
|
bt.lifeCycle = (value == null ? "" : value);
|
value = element.elementText("lifeCycles");
|
if(value != null && !value.equals("")){
|
bt.lifeCycles = value.trim().split(",");
|
}else{
|
bt.lifeCycles = new String[0];
|
}
|
value = element.elementText("imageName");
|
bt.imageName = (value == null ? "" : value);
|
value = element.elementText("revLevel");
|
bt.revLevel = (value == null ? 0 : Short.valueOf(value));
|
value = element.elementText("revRuleName");
|
bt.revRuleName = (value == null ? "" : value);
|
value = element.elementText("revInput");
|
bt.revInput = (value == null ? false : Boolean.valueOf(value));
|
value = element.elementText("delimiter");
|
bt.delimiter = (value == null ? "" : value);
|
value = element.elementText("verRuleName");
|
bt.verRuleName = (value == null ? 0 : Short.valueOf(value));
|
value = element.elementText("apNameArray");
|
if(value != null && !value.equals("")){
|
bt.apNameArray = value.trim().split(",");
|
}else{
|
bt.apNameArray = new String[0];
|
}
|
}
|
|
|
/**
|
* 设置索引
|
* @param typeName
|
* @param indexAttr
|
* @return
|
*/
|
public String getAddIndex(String typeName,String[] indexAttr){
|
String sql = "create unique INDEX "+indexAttr[0]+" on " + OmdTools.getBTMTableName(typeName) + "(" + indexAttr[1] + ")\n";
|
return sql;
|
}
|
/**
|
* 修改索引
|
* @param typeName
|
* @param indexAttr
|
* @return
|
*/
|
public String getDropIndex(String typeName,String[] indexAttr){
|
String sql = "drop INDEX "+indexAttr[0]+" \n";
|
return sql;
|
}
|
}
|